diff options
author | brettp <brettp@36083f99-b078-4883-b0ff-0f9b5a30f544> | 2011-02-09 21:44:12 +0000 |
---|---|---|
committer | brettp <brettp@36083f99-b078-4883-b0ff-0f9b5a30f544> | 2011-02-09 21:44:12 +0000 |
commit | 6f41511034886224e0888d2f886c7d7ccc48636d (patch) | |
tree | c7cdb8a103ce8202fa4568da5c91377d2dea418e /actions | |
parent | 3da61eb88485680eb9480c24d56b05d08c218f1b (diff) | |
download | elgg-6f41511034886224e0888d2f886c7d7ccc48636d.tar.gz elgg-6f41511034886224e0888d2f886c7d7ccc48636d.tar.bz2 |
Refs #2874: More removal of deprecated function user in plugins systems.
git-svn-id: http://code.elgg.org/elgg/trunk@8089 36083f99-b078-4883-b0ff-0f9b5a30f544
Diffstat (limited to 'actions')
-rw-r--r-- | actions/plugins/settings/save.php | 54 | ||||
-rw-r--r-- | actions/plugins/usersettings/save.php | 57 |
2 files changed, 64 insertions, 47 deletions
diff --git a/actions/plugins/settings/save.php b/actions/plugins/settings/save.php index 3fa45e0c1..d768d3604 100644 --- a/actions/plugins/settings/save.php +++ b/actions/plugins/settings/save.php @@ -1,34 +1,37 @@ <?php /** - * Elgg plugin settings save action. + * Saves global plugin settings. * - * @package Elgg - * @subpackage Core + * This action can be overriden for a specific plugin by creating the + * settings/<plugin_id>/save action in that plugin. + * + * @uses array $_REQUEST['params'] A set of key/value pairs to save to the ElggPlugin entity + * @uses int $_REQUEST['plugin_id'] The ID of the plugin + * + * @package Elgg.Core + * @subpackage Plugins.Settings */ $params = get_input('params'); -$plugin = get_input('plugin'); -if (!$plugin_info = load_plugin_manifest($plugin)) { - register_error(elgg_echo('plugins:settings:save:fail', array($plugin))); +$plugin_id = get_input('plugin_id'); +$plugin = elgg_get_plugin_from_id($plugin_id); + +if (!($plugin instanceof ElggPlugin)) { + register_error(elgg_echo('plugins:settings:save:fail', array($plugin_id))); forward(REFERER); } -$plugin_name = $plugin_info['name']; +$plugin_name = $plugin->manifest->getName(); $result = false; -$options = array( - 'plugin' => $plugin, - 'manifest' => $plugin_info, - 'settings' => $params -); - // allow a plugin to override the save action for their settings -if (elgg_action_exist("settings/$plugin/save")) { - action("settings/$plugin/save"); +if (elgg_action_exist("settings/$plugin_id/save")) { + action("settings/$plugin_id/save"); } else { foreach ($params as $k => $v) { - if (!$result = set_plugin_setting($k, $v, $plugin)) { + $result = $plugin->setSetting($k, $v); + if (!$result) { register_error(elgg_echo('plugins:settings:save:fail', array($plugin_name))); forward(REFERER); exit; @@ -37,21 +40,4 @@ if (elgg_action_exist("settings/$plugin/save")) { } system_message(elgg_echo('plugins:settings:save:ok', array($plugin_name))); -forward(REFERER); -// -//$trigger = elgg_trigger_plugin_hook('plugin:save_settings', $plugin, $options, NULL); -//if ($trigger === NULL) { -// foreach ($params as $k => $v) { -// if (!$result = set_plugin_setting($k, $v, $plugin)) { -// register_error(elgg_echo('plugins:settings:save:fail', array($plugin_name))); -// forward(REFERER); -// exit; -// } -// } -//} elseif ($trigger === FALSE) { -// register_error(elgg_echo('plugins:settings:save:fail', array($plugin_name))); -// forward(REFERER); -//} -// -//system_message(elgg_echo('plugins:settings:save:ok', array($plugin_name))); -//forward(REFERER);
\ No newline at end of file +forward(REFERER);
\ No newline at end of file diff --git a/actions/plugins/usersettings/save.php b/actions/plugins/usersettings/save.php index a54df627a..794ce4046 100644 --- a/actions/plugins/usersettings/save.php +++ b/actions/plugins/usersettings/save.php @@ -1,27 +1,58 @@ <?php /** - * Elgg plugin user settings save action. + * Saves user-specific plugin settings. * - * @package Elgg - * @subpackage Core + * This action can be overriden for a specific plugin by creating the + * settings/<plugin_id>/save action in that plugin. + * + * @uses array $_REQUEST['params'] A set of key/value pairs to save to the ElggPlugin entity + * @uses int $_REQUEST['plugin_id'] The id of the plugin + * @uses int $_REQUEST['user_guid'] The GUID of the user to save settings for. + * + * @package Elgg.Core + * @subpackage Plugins.Settings */ $params = get_input('params'); -$plugin = get_input('plugin'); +$plugin_id = get_input('plugin_id'); +$user_guid = get_input('user_guid', elgg_get_logged_in_user_guid()); +$plugin = elgg_get_plugin_from_id($plugin_id); +$user = get_entity($user_guid); + +if (!($plugin instanceof ElggPlugin)) { + register_error(elgg_echo('plugins:usersettings:save:fail', array($plugin_id))); + forward(REFERER); +} + +if (!($user instanceof ElggUser)) { + register_error(elgg_echo('plugins:usersettings:save:fail', array($plugin_id))); + forward(REFERER); +} + +$plugin_name = $plugin->manifest->getName(); + +// make sure we're admin or the user +if (!$user->canEdit()) { + register_error(elgg_echo('plugins:usersettings:save:fail', array($plugin_name))); + forward(REFERER); +} $result = false; -foreach ($params as $k => $v) { - // Save - $result = set_plugin_usersetting($k, $v, elgg_get_logged_in_user_guid(), $plugin); +if (elgg_action_exist("usersettings/$plugin_id/save")) { + action("usersettings/$plugin_id/save"); +} else { + foreach ($params as $k => $v) { + // Save + $result = $plugin->setUserSetting($k, $v, $user->guid); - // Error? - if (!$result) { - register_error(elgg_echo('plugins:usersettings:save:fail', array($plugin))); - forward(REFERER); - exit; + // Error? + if (!$result) { + register_error(elgg_echo('plugins:usersettings:save:fail', array($plugin_name))); + forward(REFERER); + } } } -system_message(elgg_echo('plugins:usersettings:save:ok', array($plugin))); +system_message(elgg_echo('plugins:usersettings:save:ok', array($plugin_name))); forward(REFERER); |