diff options
author | marcus <marcus@36083f99-b078-4883-b0ff-0f9b5a30f544> | 2008-06-24 10:53:50 +0000 |
---|---|---|
committer | marcus <marcus@36083f99-b078-4883-b0ff-0f9b5a30f544> | 2008-06-24 10:53:50 +0000 |
commit | 1d067acf070549c4edcb662252edd03907b1d9a3 (patch) | |
tree | 77c584fa73a45c792679d2f0a2ad10514ede9b92 | |
parent | f84af9231b1038f56c98a6f0bf7fb7a5fa2f042e (diff) | |
download | elgg-1d067acf070549c4edcb662252edd03907b1d9a3.tar.gz elgg-1d067acf070549c4edcb662252edd03907b1d9a3.tar.bz2 |
Refs #76: User settings page (to Elgg Classic standard)
git-svn-id: https://code.elgg.org/elgg/trunk@1092 36083f99-b078-4883-b0ff-0f9b5a30f544
-rw-r--r-- | actions/plugins/usersettings/save.php | 36 | ||||
-rw-r--r-- | engine/lib/plugins.php | 85 | ||||
-rw-r--r-- | languages/en.php | 4 | ||||
-rw-r--r-- | settings/plugins/index.php | 2 | ||||
-rw-r--r-- | views/default/object/plugin.php | 2 | ||||
-rw-r--r-- | views/default/usersettings/plugins.php | 2 | ||||
-rw-r--r-- | views/default/usersettings/plugins_opt/plugin.php | 4 |
7 files changed, 103 insertions, 32 deletions
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 @@ +<?php + /** + * Elgg plugin user settings save action. + * + * @package Elgg + * @subpackage Core + * @license http://www.gnu.org/licenses/old-licenses/gpl-2.0.html GNU Public License version 2 + * @author Marcus Povey + * @copyright Curverider Ltd 2008 + * @link http://elgg.org/ + */ + + $params = get_input('params'); + $plugin = get_input('plugin'); + + $result = false; + + foreach ($params as $k => $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 @@ ?> <div> - <form action="<?php echo $vars['url']; ?>action/plugins/settings/save" method="post"> + <form action="<?php echo $vars['url']; ?>action/plugins/<?php echo $prefix; ?>settings/save" method="post"> <?php echo elgg_view("{$prefix}settings/{$plugin}/edit",$vars); diff --git a/views/default/usersettings/plugins.php b/views/default/usersettings/plugins.php index 580a81029..730950178 100644 --- a/views/default/usersettings/plugins.php +++ b/views/default/usersettings/plugins.php @@ -26,7 +26,7 @@ foreach ($installed_plugins as $plugin => $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 @@ <?php if ($manifest) { ?> <div><?php echo $manifest['description'] ?></div> + <div><?php echo elgg_echo('admin:plugins:label:author') . ": ". $manifest['author'] ?></div> + <div><?php echo elgg_echo('admin:plugins:label:copyright') . ": ". $manifest['copyright'] ?></div> + <div><?php echo elgg_echo('admin:plugins:label:licence') . ": ". $manifest['licence'] ?></div> + <div><?php echo elgg_echo('admin:plugins:label:website') . ": "; ?><a href="<?php echo $manifest['website']; ?>"><?php echo $manifest['website']; ?></a></div> <?php } ?> <?php if (elgg_view("usersettings/{$plugin}/edit")) { ?> |