Elgg  Version 2.2
 All Classes Namespaces Files Functions Variables Pages
save.php
Go to the documentation of this file.
1 <?php
16 $params = get_input('params');
17 $plugin_id = get_input('plugin_id');
21 
22 if (!($plugin instanceof ElggPlugin)) {
23  register_error(elgg_echo('plugins:usersettings:save:fail', array($plugin_id)));
25 }
26 
27 if (!($user instanceof ElggUser)) {
28  register_error(elgg_echo('plugins:usersettings:save:fail', array($plugin_id)));
30 }
31 
32 $plugin_name = $plugin->getManifest()->getName();
33 
34 // make sure we're admin or the user
35 if (!$user->canEdit()) {
36  register_error(elgg_echo('plugins:usersettings:save:fail', array($plugin_name)));
38 }
39 
40 $result = false;
41 
42 if (elgg_action_exists("$plugin_id/usersettings/save")) {
43  action("$plugin_id/usersettings/save");
44 } else {
45  foreach ($params as $k => $v) {
46  // Save
47  $result = $plugin->setUserSetting($k, $v, $user->guid);
48 
49  // Error?
50  if (!$result) {
51  register_error(elgg_echo('plugins:usersettings:save:fail', array($plugin_name)));
53  }
54  }
55 }
56 
57 system_message(elgg_echo('plugins:usersettings:save:ok', array($plugin_name)));
action($action, $forwarder="")
Perform an action.
Definition: actions.php:47
$params
Definition: save.php:15
elgg_echo($message_key, $args=array(), $language="")
Given a message key, returns an appropriately translated full-text string.
Definition: languages.php:21
elgg_action_exists($action)
Check if an action is registered and its script exists.
Definition: actions.php:216
$result
Definition: save.php:26
register_error($error)
Display an error on next page load.
Definition: elgglib.php:452
if(!$entity) $user
Definition: save.php:54
get_input($variable, $default=null, $filter_result=true)
Get some input from variables passed submitted through GET or POST.
Definition: input.php:27
const REFERER
Definition: elgglib.php:2029
$plugin_id
Definition: save.php:16
forward($location="", $reason= 'system')
Forward to $location.
Definition: elgglib.php:93
$plugin
Definition: save.php:17
$user_guid
Definition: save.php:18
system_message($message)
Display a system message on next page load.
Definition: elgglib.php:438
elgg_get_logged_in_user_guid()
Return the current logged in user by guid.
Definition: sessions.php:42
elgg_get_plugin_from_id($plugin_id)
Returns an object with the path $path.
Definition: plugins.php:82
get_entity($guid)
Loads and returns an entity object from a guid.
Definition: entities.php:204
if(!($plugin instanceof ElggPlugin)) $plugin_name
Definition: save.php:24