aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authormarcus <marcus@36083f99-b078-4883-b0ff-0f9b5a30f544>2008-11-20 12:36:28 +0000
committermarcus <marcus@36083f99-b078-4883-b0ff-0f9b5a30f544>2008-11-20 12:36:28 +0000
commitfdb8894ca1d0ae7ba9595160465aa5ac6dc75e9b (patch)
treed551bd8be87b5483d46ab76f2ec690d5661671d0
parent1d89455f5546d5fc6507fdd7319ac2387bc59615 (diff)
downloadelgg-fdb8894ca1d0ae7ba9595160465aa5ac6dc75e9b.tar.gz
elgg-fdb8894ca1d0ae7ba9595160465aa5ac6dc75e9b.tar.bz2
Refs #571. Fixes #569, #570:
* Plugin functions set to use private data store. * Fixed some db queries * Modified plugin class overriding get/set functions git-svn-id: https://code.elgg.org/elgg/trunk@2475 36083f99-b078-4883-b0ff-0f9b5a30f544
-rw-r--r--engine/lib/entities.php13
-rw-r--r--engine/lib/plugins.php69
2 files changed, 60 insertions, 22 deletions
diff --git a/engine/lib/entities.php b/engine/lib/entities.php
index 3604574e3..0cfceb7a0 100644
--- a/engine/lib/entities.php
+++ b/engine/lib/entities.php
@@ -2164,7 +2164,8 @@
global $CONFIG;
$entity_guid = (int) $entity_guid;
- $name = mysql_real_escape_string($name);
+ $name = sanitise_string($name);
+
if ($setting = get_data_row("SELECT value from {$CONFIG->dbprefix}private_settings where name = '{$name}' and entity_guid = {$entity_guid}")) {
return $setting->value;
}
@@ -2188,7 +2189,7 @@
$return = array();
foreach ($result as $r)
$return[$r->name] = $r->value;
-
+
return $return;
}
@@ -2207,9 +2208,9 @@
global $CONFIG;
$entity_guid = (int) $entity_guid;
- $name = mysql_real_escape_string($name);
- $value = mysql_real_escape_string($value);
-
+ $name = sanitise_string($name);
+ $value = sanitise_string($value);
+
return insert_data("INSERT into {$CONFIG->dbprefix}private_settings (entity_guid, name, value) VALUES ($entity_guid, '{$name}', '{$value}') ON DUPLICATE KEY UPDATE value='$value'");
}
@@ -2226,7 +2227,7 @@
global $CONFIG;
$entity_guid = (int) $entity_guid;
- $name = mysql_real_escape_string($name);
+ $name = sanitise_string($name);
return delete_data("DELETE from {$CONFIG->dbprefix}private_settings where name = '{$name}' and entity_guid = {$entity_guid}");
}
diff --git a/engine/lib/plugins.php b/engine/lib/plugins.php
index d2381db40..2f6519f0a 100644
--- a/engine/lib/plugins.php
+++ b/engine/lib/plugins.php
@@ -44,6 +44,44 @@
{
parent::__construct($guid);
}
+
+ /**
+ * Override entity get and sets in order to save data to private data store.
+ */
+ public function get($name)
+ {
+ // See if its in our base attribute
+ if (isset($this->attributes[$name])) {
+ return $this->attributes[$name];
+ }
+
+ // No, so see if its in the private data store.
+ $meta = get_private_setting($this->guid, $name);
+ if ($meta)
+ return $meta;
+
+ // Can't find it, so return null
+ return null;
+ }
+
+ /**
+ * Override entity get and sets in order to save data to private data store.
+ */
+ public function set($name, $value)
+ {
+ if (array_key_exists($name, $this->attributes))
+ {
+ // Check that we're not trying to change the guid!
+ if ((array_key_exists('guid', $this->attributes)) && ($name=='guid'))
+ return false;
+
+ $this->attributes[$name] = $value;
+ }
+ else
+ return set_private_setting($this->guid, $name, $value);
+
+ return true;
+ }
}
/**
@@ -294,10 +332,10 @@
$plugin_name = sanitise_string($plugin_name);
if (!$plugin_name)
$plugin_name = get_plugin_name();
-
+
if ($plugins)
{
- foreach ($plugins as $plugin)
+ foreach ($plugins as $plugin)
if (strcmp($plugin->title, $plugin_name)==0)
return $plugin;
}
@@ -323,18 +361,18 @@
if ($user_guid == 0) $user_guid = get_loggedin_userid();
// Get metadata for user
- $all_metadata = get_metadata_for_entity($user_guid);
+ $all_metadata = get_all_private_settings($user_guid); //get_metadata_for_entity($user_guid);
if ($all_metadata)
{
$prefix = "plugin:settings:$plugin_name:";
$return = new stdClass;
- foreach ($all_metadata as $meta)
+ foreach ($all_metadata as $key => $meta)
{
- $name = substr($meta->name, strlen($prefix));
- $value = $meta->value;
+ $name = substr($key, strlen($prefix));
+ $value = $meta;
- if (strpos($meta->name, $prefix) === 0)
+ if (strpos($key, $prefix) === 0)
$return->$name = $value;
}
@@ -367,10 +405,9 @@
if (($user) && ($user instanceof ElggUser))
{
$prefix = "plugin:settings:$plugin_name:$name";
- $user->$prefix = $value;
- $user->save();
-
- return true;
+ //$user->$prefix = $value;
+ //$user->save();
+ return set_private_setting($user->guid, $prefix, $value);
}
return false;
@@ -397,7 +434,7 @@
if (($user) && ($user instanceof ElggUser))
{
$prefix = "plugin:settings:$plugin_name:$name";
- return $user->$prefix;
+ return get_private_setting($user->guid, $prefix); //$user->$prefix;
}
return false;
@@ -411,7 +448,7 @@
* @param string $plugin_name Optional plugin name, if not specified then it is detected from where you are calling from.
*/
function set_plugin_setting($name, $value, $plugin_name = "")
- {
+ {
$plugin = find_plugin_settings($plugin_name);
if (!$plugin)
@@ -421,8 +458,8 @@
{
$plugin->title = $plugin_name;
$plugin->access_id = 2;
- $plugin->$name = $value;
$plugin->save();
+ $plugin->$name = $value;
return $plugin->getGUID();
}
@@ -439,7 +476,7 @@
function get_plugin_setting($name, $plugin_name = "")
{
$plugin = find_plugin_settings($plugin_name);
-
+
if ($plugin)
return $plugin->$name;
@@ -457,7 +494,7 @@
$plugin = find_plugin_settings($plugin_name);
if ($plugin)
- return $plugin->clearMetaData($name);
+ return remove_all_private_settings($plugin->guid); //$plugin->clearMetaData($name);
return false;
}