aboutsummaryrefslogtreecommitdiff
path: root/engine/lib
diff options
context:
space:
mode:
Diffstat (limited to 'engine/lib')
-rw-r--r--engine/lib/elgglib.php2
-rw-r--r--engine/lib/plugins.php70
-rw-r--r--engine/lib/private_settings.php13
3 files changed, 81 insertions, 4 deletions
diff --git a/engine/lib/elgglib.php b/engine/lib/elgglib.php
index cd746b3d8..12560308e 100644
--- a/engine/lib/elgglib.php
+++ b/engine/lib/elgglib.php
@@ -1618,7 +1618,7 @@ function js_page_handler($page) {
$return = elgg_view('js/' . $js);
header('Content-type: text/javascript');
-
+
// @todo should js be cached when simple cache turned off
//header('Expires: ' . date('r', time() + 864000));
//header("Pragma: public");
diff --git a/engine/lib/plugins.php b/engine/lib/plugins.php
index 2ac49e8df..b8fd321a8 100644
--- a/engine/lib/plugins.php
+++ b/engine/lib/plugins.php
@@ -979,6 +979,76 @@ function elgg_unset_all_plugin_settings($plugin_id = null) {
}
/**
+ * Returns entities based upon plugin settings.
+ * Takes all the options for {@see elgg_get_entities_from_private_settings()}
+ * in addition to the ones below.
+ *
+ * @param array $options Array in the format:
+ *
+ * plugin_name => NULL|STR The plugin name. Defaults to calling plugin
+ *
+ * plugin_user_setting_names => NULL|ARR private setting names
+ *
+ * plugin_user_setting_values => NULL|ARR metadata values
+ *
+ * plugin_user_setting_name_value_pairs => NULL|ARR (
+ * name => 'name',
+ * value => 'value',
+ * 'operand' => '=',
+ * )
+ * Currently if multiple values are sent via
+ * an array (value => array('value1', 'value2')
+ * the pair's operand will be forced to "IN".
+ *
+ * plugin_user_setting_name_value_pairs_operator => NULL|STR The operator to use for combining
+ * (name = value) OPERATOR (name = value); default AND
+ *
+ * @return mixed
+ */
+function elgg_get_entities_from_plugin_user_settings(array $options = array()) {
+ // if they're passing it don't bother
+ if (!isset($options['plugin_name'])) {
+ $options['plugin_name'] = elgg_get_calling_plugin_id();
+ }
+
+ $singulars = array('plugin_user_setting_name', 'plugin_user_setting_value',
+ 'plugin_user_setting_name_value_pair');
+
+ $options = elgg_normalise_plural_options_array($options, $singulars);
+
+ // rewrite plugin_user_setting_name_* to the right PS ones.
+ $map = array(
+ 'plugin_user_setting_names' => 'private_setting_names',
+ 'plugin_user_setting_values' => 'private_setting_values',
+ 'plugin_user_setting_name_value_pairs' => 'private_setting_name_value_pairs',
+ 'plugin_user_setting_name_value_pairs_operator' => 'private_setting_name_value_pairs_operator'
+ );
+
+ foreach ($map as $plugin => $private) {
+ if (!isset($options[$plugin])) {
+ continue;
+ }
+
+ if (isset($options[$private])) {
+ if (!is_array($options[$private])) {
+ $options[$private] = array($options[$private]);
+ }
+
+ $options[$private] = array_merge($options[$private], $options[$plugin]);
+ } else {
+ $options[$private] = $options[$plugin];
+ }
+ }
+
+
+ $plugin_id = $options['plugin_name'];
+ $prefix = elgg_namespace_plugin_private_setting('user_setting', '', $plugin_id);
+ $options['private_setting_name_prefix'] = $prefix;
+
+ return elgg_get_entities_from_private_settings($options);
+}
+
+/**
* Register object, plugin entities as ElggPlugin classes
*
* @return void
diff --git a/engine/lib/private_settings.php b/engine/lib/private_settings.php
index 77641e122..e5e7b2213 100644
--- a/engine/lib/private_settings.php
+++ b/engine/lib/private_settings.php
@@ -33,6 +33,10 @@
* private_setting_name_value_pairs_operator => NULL|STR The operator to use for combining
* (name = value) OPERATOR (name = value); default AND
*
+ * private_setting_name_prefix => STR A prefix to apply to all private settings. Used to
+ * namespace plugin user settings or by plugins to namespace
+ * their own settings.
+ *
*
* @return array
* @since 1.8.0
@@ -43,6 +47,7 @@ function elgg_get_entities_from_private_settings(array $options = array()) {
'private_setting_values' => ELGG_ENTITIES_ANY_VALUE,
'private_setting_name_value_pairs' => ELGG_ENTITIES_ANY_VALUE,
'private_setting_name_value_pairs_operator' => 'AND',
+ 'private_setting_name_prefix' => '',
);
$options = array_merge($defaults, $options);
@@ -54,7 +59,7 @@ function elgg_get_entities_from_private_settings(array $options = array()) {
$clauses = elgg_get_entity_private_settings_where_sql('e', $options['private_setting_names'],
$options['private_setting_values'], $options['private_setting_name_value_pairs'],
- $options['private_setting_name_value_pairs_operator']);
+ $options['private_setting_name_value_pairs_operator'], $options['private_setting_name_prefix']);
if ($clauses) {
// merge wheres to pass to get_entities()
@@ -87,11 +92,12 @@ function elgg_get_entities_from_private_settings(array $options = array()) {
* @param array|null $values Array of values
* @param array|null $pairs Array of names / values / operands
* @param string $pair_operator Operator for joining pairs where clauses
+ * @param string $name_prefix A string to prefix all names with
* @return array
* @since 1.8.0
*/
function elgg_get_entity_private_settings_where_sql($table, $names = NULL, $values = NULL,
-$pairs = NULL, $pair_operator = 'AND') {
+$pairs = NULL, $pair_operator = 'AND', $name_prefix = '') {
global $CONFIG;
@@ -116,6 +122,7 @@ $pairs = NULL, $pair_operator = 'AND') {
$sanitised_names = array();
foreach ($names as $name) {
+ $name = $name_prefix . $name;
$sanitised_names[] = '\'' . sanitise_string($name) . '\'';
}
@@ -220,7 +227,7 @@ $pairs = NULL, $pair_operator = 'AND') {
$value = "'" . sanitise_string($pair['value']) . "'";
}
- $name = sanitise_string($pair['name']);
+ $name = sanitise_string($name_prefix . $pair['name']);
// @todo The multiple joins are only needed when the operator is AND
$return['joins'][] = "JOIN {$CONFIG->dbprefix}private_settings ps{$i}