From 6f41511034886224e0888d2f886c7d7ccc48636d Mon Sep 17 00:00:00 2001 From: brettp Date: Wed, 9 Feb 2011 21:44:12 +0000 Subject: 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 --- actions/plugins/settings/save.php | 54 ++++++++------------ actions/plugins/usersettings/save.php | 57 +++++++++++++++++----- engine/lib/admin.php | 4 +- engine/lib/deprecated-1.8.php | 14 +----- engine/lib/plugins.php | 22 +++++++-- views/default/admin/components/plugin_settings.php | 35 +++++++------ views/default/core/settings/tools.php | 6 ++- views/default/core/settings/tools/plugin.php | 14 ++++-- views/default/object/plugin.php | 27 +++++++--- 9 files changed, 136 insertions(+), 97 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 @@ /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 @@ /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); diff --git a/engine/lib/admin.php b/engine/lib/admin.php index d076bbd3d..0ec02cded 100644 --- a/engine/lib/admin.php +++ b/engine/lib/admin.php @@ -202,8 +202,8 @@ function admin_settings_page_handler($page) { && elgg_view_exists("settings/{$page[1]}/edit")) { $view = '/admin/components/plugin_settings'; - $vars['plugin'] = $page[1]; - $vars['entity'] = find_plugin_settings($page[1]); + $plugin = elgg_get_plugin_from_id($page[1]); + $vars['plugin'] = $plugin; $title = elgg_echo("admin:plugin_settings:{$page[1]}"); $title = elgg_echo("admin:{$page[0]}"); } else { diff --git a/engine/lib/deprecated-1.8.php b/engine/lib/deprecated-1.8.php index 684e8f9b3..ee3265a12 100644 --- a/engine/lib/deprecated-1.8.php +++ b/engine/lib/deprecated-1.8.php @@ -2972,19 +2972,7 @@ function load_plugins() { */ function find_plugin_usersettings($plugin_id = null, $user_guid = 0) { elgg_deprecated_notice('find_plugin_usersettings() is deprecated by elgg_get_all_plugin_user_settings()', 1.8); - - $settings = elgg_get_all_plugin_user_settings($user_guid, $plugin_id); - $return = false; - - if ($settings) { - $return = new stdClass; - - foreach ($settings as $k => $v) { - $return->$k = $v; - } - } - - return $return; + return elgg_get_all_plugin_user_settings($user_guid, $plugin_id, true); } /** diff --git a/engine/lib/plugins.php b/engine/lib/plugins.php index fc3dc8006..b33b8d0ac 100644 --- a/engine/lib/plugins.php +++ b/engine/lib/plugins.php @@ -772,13 +772,15 @@ function elgg_get_calling_plugin_entity() { /** * Returns an array of all plugin settings for a user. * - * @param mixed $user_guid The user GUID or null for the currently logged in user. - * @param string $plugin_id The plugin ID + * @param mixed $user_guid The user GUID or null for the currently logged in user. + * @param string $plugin_id The plugin ID + * @param bool $return_obj Return settings as an object? This can be used to in reusable + * views where the settings are passed as $vars['entity']. * @return array * * @since 1.8 */ -function elgg_get_all_plugin_user_settings($user_guid = null, $plugin_id = null) { +function elgg_get_all_plugin_user_settings($user_guid = null, $plugin_id = null, $return_obj = false) { if ($plugin_id) { $plugin = elgg_get_plugin_from_id($plugin_id); } else { @@ -789,7 +791,19 @@ function elgg_get_all_plugin_user_settings($user_guid = null, $plugin_id = null) return false; } - return $plugin->getAllUserSettings($user_guid); + $settings = $plugin->getAllUserSettings($user_guid); + + if ($settings && $return_obj) { + $return = new stdClass; + + foreach ($settings as $k => $v) { + $return->$k = $v; + } + + return $return; + } else { + return $settings; + } } /** diff --git a/views/default/admin/components/plugin_settings.php b/views/default/admin/components/plugin_settings.php index d5e25b4c1..8179728ed 100644 --- a/views/default/admin/components/plugin_settings.php +++ b/views/default/admin/components/plugin_settings.php @@ -2,30 +2,33 @@ /** * Elgg plugin settings * - * @package Elgg - * @subpackage Core + * @uses ElggPlugin $vars['plugin'] The plugin object to display settings for. + * + * @package Elgg.Core + * @subpackage Plugins.Settings */ $plugin = $vars['plugin']; -$plugin_info = load_plugin_manifest($plugin); - -$form_body = elgg_view("settings/{$plugin}/edit", $vars); -$form_body .= elgg_view('input/hidden', array('internalname' => 'plugin', 'value' => $plugin)); -$form_body .= elgg_view('input/submit', array('value' => elgg_echo('save'))); -//$form_body .= elgg_view('input/reset', array('value' => elgg_echo('reset'))); +$plugin_id = $plugin->getID(); +if (elgg_view("settings/$plugin_id/edit")) { ?> -
+ +
-

+

manifest->getName(); ?>

- $form_body, - 'internalid' => 'plugin_settings', - 'action' => "action/plugins/settings/save", +
+ $plugin, + // in for backward compatibility + 'entity' => $plugin, + 'type' => 'admin' )); - ?> + ?> +
+getID(); -$user_guid = $details['user_guid']; +$user_guid = $vars['user_guid']; + if (!$user_guid) { $user_guid = elgg_get_logged_in_user_guid(); } if (elgg_view("usersettings/$plugin_id/edit")) { ?> +

manifest->getName(); ?>

-
+
$plugin, 'entity' => find_plugin_usersettings($plugin_id, $user_guid), - 'prefix' => 'user' + 'type' => 'user' )); ?>
diff --git a/views/default/object/plugin.php b/views/default/object/plugin.php index 054931a38..b3bb6eb93 100644 --- a/views/default/object/plugin.php +++ b/views/default/object/plugin.php @@ -1,21 +1,32 @@ getID(); -$prefix = $vars['prefix']; // Do we want to show admin settings (default) or user settings +$user_guid = elgg_get_array_value('user_guid', $vars, elgg_get_logged_in_user_guid()); -$form_body = elgg_view("{$prefix}settings/{$plugin_id}/edit", $vars) - . "

" . elgg_view('input/hidden', array('internalname' => 'plugin', 'value' => $plugin_id)) +// Do we want to show admin settings or user settings +$type = elgg_get_array_value('type', $vars, ''); + +if ($type == 'user') { + $view = "{$type}settings/{$plugin_id}/edit"; + $action = "action/plugins/usersettings/save"; +} else { + $view = "settings/{$plugin_id}/edit"; + $action = "action/plugins/settings/save"; +} + +$form_body = elgg_view($view, $vars) + . "

" . elgg_view('input/hidden', array('internalname' => 'plugin_id', 'value' => $plugin_id)) + . elgg_view('input/hidden', array('internalname' => 'user_guid', 'value' => $user_guid)) . elgg_view('input/submit', array('value' => elgg_echo('save'))) . "

"; ?>
- $form_body, 'action' => "action/plugins/{$prefix}settings/save")); ?> + $form_body, 'action' => $action)); ?>
\ No newline at end of file -- cgit v1.2.3