aboutsummaryrefslogtreecommitdiff
path: root/engine/lib
diff options
context:
space:
mode:
authorbrettp <brettp@36083f99-b078-4883-b0ff-0f9b5a30f544>2011-02-08 20:30:06 +0000
committerbrettp <brettp@36083f99-b078-4883-b0ff-0f9b5a30f544>2011-02-08 20:30:06 +0000
commitcf13bfcc6ca27f5a73de1542e17cdba3e512b615 (patch)
tree902ba1602850a5cc0da8cbbaee51cc8ef6d1aa9b /engine/lib
parentccb6d625239b59b283b4d3fc00da704ab743d74c (diff)
downloadelgg-cf13bfcc6ca27f5a73de1542e17cdba3e512b615.tar.gz
elgg-cf13bfcc6ca27f5a73de1542e17cdba3e512b615.tar.bz2
Fixes #2869: User settings for plugins work again.
git-svn-id: http://code.elgg.org/elgg/trunk@8080 36083f99-b078-4883-b0ff-0f9b5a30f544
Diffstat (limited to 'engine/lib')
-rw-r--r--engine/lib/plugins.php79
1 files changed, 23 insertions, 56 deletions
diff --git a/engine/lib/plugins.php b/engine/lib/plugins.php
index 85f821315..f8177a5f7 100644
--- a/engine/lib/plugins.php
+++ b/engine/lib/plugins.php
@@ -761,7 +761,7 @@ function elgg_get_calling_plugin_entity() {
* @param string $plugin_id Plugin name.
* @param int $user_guid The guid who's settings to retrieve.
*
- * @return array of settings in an associative array minus prefix.
+ * @return StdClass Object with all user settings.
*/
function find_plugin_usersettings($plugin_id = null, $user_guid = 0) {
$plugin_id = sanitise_string($plugin_id);
@@ -815,34 +815,17 @@ function find_plugin_usersettings($plugin_id = null, $user_guid = 0) {
* @return bool
*/
function set_plugin_usersetting($name, $value, $user_guid = 0, $plugin_id = "") {
- $plugin_id = sanitise_string($plugin_id);
- $user_guid = (int)$user_guid;
- $name = sanitise_string($name);
-
- if (!$plugin_id) {
- $plugin_id = elgg_get_calling_plugin_id();
- }
-
- $user = get_entity($user_guid);
- if (!$user) {
- $user = elgg_get_logged_in_user_entity();
+ if ($plugin_id) {
+ $plugin = elgg_get_plugin_from_id($plugin_id);
+ } else {
+ $plugin = elgg_get_calling_plugin_entity();
}
- if (($user) && ($user instanceof ElggUser)) {
- $name = elgg_namespace_plugin_private_setting('user_setting', "$plugin_id:$name");
-
- // Hook to validate setting
- $value = elgg_trigger_plugin_hook('plugin:usersetting', 'user', array(
- 'user' => $user,
- 'plugin' => $plugin_id,
- 'name' => $name,
- 'value' => $value
- ), $value);
-
- return set_private_setting($user->guid, $name, $value);
+ if (!$plugin) {
+ return false;
}
- return false;
+ return $plugin->setUserSetting($name, $value, $user_guid);
}
/**
@@ -855,25 +838,17 @@ function set_plugin_usersetting($name, $value, $user_guid = 0, $plugin_id = "")
* @return bool Success
*/
function clear_plugin_usersetting($name, $user_guid = 0, $plugin_id = '') {
- $plugin_id = sanitise_string($plugin_id);
- $name = sanitise_string($name);
-
- if (!$plugin_id) {
- $plugin_id = elgg_get_calling_plugin_id();
- }
-
- $user = get_entity((int) $user_guid);
- if (!$user) {
- $user = elgg_get_logged_in_user_entity();
+ if ($plugin_id) {
+ $plugin = elgg_get_plugin_from_id($plugin_id);
+ } else {
+ $plugin = elgg_get_calling_plugin_entity();
}
- if (($user) && ($user instanceof ElggUser)) {
- $prefix = elgg_namespace_plugin_private_setting('user_setting', "$plugin_id:$name");
-
- return remove_private_setting($user->getGUID(), $prefix);
+ if (!$plugin) {
+ return false;
}
- return FALSE;
+ return $plugin->removeUserSetting($user_guid, $name);
}
/**
@@ -882,30 +857,22 @@ function clear_plugin_usersetting($name, $user_guid = 0, $plugin_id = '') {
* @param string $name The name.
* @param int $user_guid Guid of owning user
* @param string $plugin_id Optional plugin name, if not specified
- * then it is detected from where you are calling from.
+ * it is detected from where you are calling.
*
* @return mixed
*/
function get_plugin_usersetting($name, $user_guid = 0, $plugin_id = "") {
- $plugin_id = sanitise_string($plugin_id);
- $user_guid = (int)$user_guid;
- $name = sanitise_string($name);
-
- if (!$plugin_id) {
- $plugin_id = elgg_get_calling_plugin_id();
- }
-
- $user = get_entity($user_guid);
- if (!$user) {
- $user = elgg_get_logged_in_user_entity();
+ if ($plugin_id) {
+ $plugin = elgg_get_plugin_from_id($plugin_id);
+ } else {
+ $plugin = elgg_get_calling_plugin_entity();
}
- if (($user) && ($user instanceof ElggUser)) {
- $name = elgg_namespace_plugin_private_setting('user_setting', "$plugin_id:$name");
- return get_private_setting($user->guid, $name);
+ if (!$plugin) {
+ return false;
}
- return false;
+ return $plugin->getUserSetting($name, $user_guid);
}
/**