Elgg  Version 1.9
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)));
get_input($variable, $default=null, $filter_result=true)
Get some input from variables passed submitted through GET or POST.
Definition: input.php:27
$params
Definition: save.php:15
elgg_action_exists($action)
Check if an action is registered and its script exists.
Definition: actions.php:227
$result
Definition: save.php:26
elgg forward
Meant to mimic the php forward() function by simply redirecting the user to another page...
Definition: elgglib.js:419
if(!$entity) $user
Definition: save.php:46
elgg_echo($message_key, $args=array(), $language="")
Given a message key, returns an appropriately translated full-text string.
Definition: languages.php:21
const REFERER
Definition: elgglib.php:2162
$plugin_id
Definition: save.php:16
elgg system_message
Wrapper function for system_messages.
Definition: elgglib.js:374
elgg register_error
Wrapper function for system_messages.
Definition: elgglib.js:383
$plugin
Definition: save.php:17
$user_guid
Definition: save.php:18
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 ElggPlugin object with the path $path.
Definition: plugins.php:204
get_entity($guid)
Loads and returns an entity object from a guid.
Definition: entities.php:604
elgg action
Definition: ajax.js:178
if(!($plugin instanceof ElggPlugin)) $plugin_name
Definition: save.php:24