From 1d067acf070549c4edcb662252edd03907b1d9a3 Mon Sep 17 00:00:00 2001 From: marcus Date: Tue, 24 Jun 2008 10:53:50 +0000 Subject: Refs #76: User settings page (to Elgg Classic standard) git-svn-id: https://code.elgg.org/elgg/trunk@1092 36083f99-b078-4883-b0ff-0f9b5a30f544 --- actions/plugins/usersettings/save.php | 36 ++++++++++ engine/lib/plugins.php | 85 +++++++++++++++-------- languages/en.php | 4 +- settings/plugins/index.php | 2 +- views/default/object/plugin.php | 2 +- views/default/usersettings/plugins.php | 2 +- views/default/usersettings/plugins_opt/plugin.php | 4 ++ 7 files changed, 103 insertions(+), 32 deletions(-) create mode 100644 actions/plugins/usersettings/save.php diff --git a/actions/plugins/usersettings/save.php b/actions/plugins/usersettings/save.php new file mode 100644 index 000000000..9dfda8a90 --- /dev/null +++ b/actions/plugins/usersettings/save.php @@ -0,0 +1,36 @@ + $v) + { + // Save + $result = set_plugin_usersetting($k, $v, $_SESSION['user']->guid, $plugin); + + // Error? + if (!$result) + { + system_message(sprintf(elgg_echo('plugins:usersettings:save:fail'), $plugin)); + + forward($_SERVER['HTTP_REFERER']); + + exit; + } + } + + system_message(sprintf(elgg_echo('plugins:usersettings:save:ok'), $plugin)); + forward($_SERVER['HTTP_REFERER']); +?> \ No newline at end of file diff --git a/engine/lib/plugins.php b/engine/lib/plugins.php index cf3252ffd..d68ce98ab 100644 --- a/engine/lib/plugins.php +++ b/engine/lib/plugins.php @@ -177,6 +177,7 @@ * * @param string $plugin_name Plugin name. * @param int $user_guid The guid who's settings to retrieve. + * @return array of settings in an associative array minus prefix. */ function find_plugin_usersettings($plugin_name = "", $user_guid = 0) { @@ -188,22 +189,24 @@ if ($user_guid == 0) $user_guid = $_SESSION['user']->guid; - - - - - - - - - - - - - - - - + // Get metadata for user + $all_metadata = get_metadata_for_entity($user_guid); + if ($all_metadata) + { + $prefix = "plugin:settings:$plugin_name:"; + $return = new stdClass; + + foreach ($all_metadata as $meta) + { + $name = substr($meta->name, strlen($prefix)); + $value = $meta->value; + + if (strpos($meta->name, $prefix) === 0) + $return->$name = $value; + } + + return $return; + } return false; } @@ -213,11 +216,31 @@ * * @param string $name The name - note, can't be "title". * @param mixed $value The value. + * @param int $user_guid Optional user. * @param string $plugin_name Optional plugin name, if not specified then it is detected from where you are calling from. */ - function set_plugin_usersetting($name, $value, $plugin_name = "") + function set_plugin_usersetting($name, $value, $user_guid = 0, $plugin_name = "") { + $plugin_name = sanitise_string($plugin_name); + $user_guid = (int)$user_guid; + $name = sanitise_string($name); + + if (!$plugin_name) + $plugin_name = get_plugin_name(); + + if ($user_guid == 0) $user_guid = $_SESSION['user']->guid; + + $user = get_entity($user_guid); + if (($user) && ($user instanceof ElggUser)) + { + $prefix = "plugin:settings:$plugin_name:$name"; + $user->$prefix = $value; + $user->save(); + + return true; + } + return false; } /** @@ -226,20 +249,25 @@ * @param string $name The name. * @param string $plugin_name Optional plugin name, if not specified then it is detected from where you are calling from. */ - function get_plugin_usersetting($name, $plugin_name = "") + function get_plugin_usersetting($name, $user_guid = 0, $plugin_name = "") { + $plugin_name = sanitise_string($plugin_name); + $user_guid = (int)$user_guid; + $name = sanitise_string($name); - } - - /** - * Clear a user specific plugin setting. - * - * @param string $name The name. - * @param string $plugin_name Optional plugin name, if not specified then it is detected from where you are calling from. - */ - function clear_plugin_usersetting($name, $plugin_name = "") - { + if (!$plugin_name) + $plugin_name = get_plugin_name(); + + if ($user_guid == 0) $user_guid = $_SESSION['user']->guid; + + $user = get_entity($user_guid); + if (($user) && ($user instanceof ElggUser)) + { + $prefix = "plugin:settings:$plugin_name:$name"; + return $user->$prefix; + } + return false; } /** @@ -466,6 +494,7 @@ // Register some actions register_action("plugins/settings/save", false, "", true); + register_action("plugins/usersettings/save"); register_action('admin/plugins/enable', false, "", true); // Enable register_action('admin/plugins/disable', false, "", true); // Disable diff --git a/languages/en.php b/languages/en.php index d79e5806a..dd4679893 100644 --- a/languages/en.php +++ b/languages/en.php @@ -205,7 +205,9 @@ * Plugins */ 'plugins:settings:save:ok' => "Settings for the %s plugin were saved successfully.", - 'plugins:settings:save:fail' => "There was a problem saving settings for the %s plugin.", + 'plugins:settings:save:fail' => "There was a problem saving settings for the %s plugin.", + 'plugins:usersettings:save:ok' => "User settings for the %s plugin were saved successfully.", + 'plugins:usersettings:save:fail' => "There was a problem saving user settings for the %s plugin.", /** * Search diff --git a/settings/plugins/index.php b/settings/plugins/index.php index d9c5de6fb..d45fbd334 100644 --- a/settings/plugins/index.php +++ b/settings/plugins/index.php @@ -18,5 +18,5 @@ // Display main admin menu - page_draw(elgg_echo("usersettings:plugins"),elgg_view_layout("one_column",elgg_view("usersettings/plugins"))); + page_draw(elgg_echo("usersettings:plugins"),elgg_view_layout("one_column",elgg_view("usersettings/plugins", array('installed_plugins' => get_installed_plugins())))); ?> \ No newline at end of file diff --git a/views/default/object/plugin.php b/views/default/object/plugin.php index 12e22bd15..2372c1a83 100644 --- a/views/default/object/plugin.php +++ b/views/default/object/plugin.php @@ -16,7 +16,7 @@ ?>
-
+ $data) { if (($n>=$offset) && ($n < $offset+$limit)) - echo elgg_view("settings/plugins_opt/plugin", array('plugin' => $plugin, 'details' => $data)); + echo elgg_view("usersettings/plugins_opt/plugin", array('plugin' => $plugin, 'details' => $data)); $n++; } diff --git a/views/default/usersettings/plugins_opt/plugin.php b/views/default/usersettings/plugins_opt/plugin.php index 228245efd..ca9b11191 100644 --- a/views/default/usersettings/plugins_opt/plugin.php +++ b/views/default/usersettings/plugins_opt/plugin.php @@ -28,6 +28,10 @@
+
+
+
+
-- cgit v1.2.3