/** * 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_id => NULL|STR The plugin id. 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 int If count, int. If not count, array. false on errors. */ function elgg_get_entities_from_plugin_user_settings(array $options = array()) { // if they're passing it don't bother if (!isset($options['plugin_id'])) { $options['plugin_id'] = 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_id']; $prefix = elgg_namespace_plugin_private_setting('user_setting', '', $plugin_id); $options['private_setting_name_prefix'] = $prefix; return elgg_get_entities_from_private_settings($options); }
function subsite_manager_get_plugin_order() { if (is_memcache_available()) { $memcache = new ElggMemcache('subsite_manager'); } if (isset($memcache)) { if ($plugin_order = $memcache->load('plugin_order')) { return $plugin_order; } } $db_prefix = get_config('dbprefix'); $priority = elgg_namespace_plugin_private_setting('internal', 'priority'); $options = array('type' => 'object', 'subtype' => 'plugin', 'limit' => ELGG_ENTITIES_NO_VALUE, 'selects' => array('plugin_oe.*'), 'joins' => array("JOIN {$db_prefix}private_settings ps on ps.entity_guid = e.guid", "JOIN {$db_prefix}objects_entity plugin_oe on plugin_oe.guid = e.guid"), 'wheres' => array("ps.name = '{$priority}'"), 'order_by' => "CAST(ps.value as unsigned), e.guid", 'site_guids' => array(1)); $plugins = elgg_get_entities_from_relationship($options); $plugin_order = array(); foreach ($plugins as $i => $plugin) { $plugin_order[$plugin->title] = $i; } if (isset($memcache)) { $memcache->save('plugin_order', $plugin_order); } return $plugin_order; }
/** * Get a value from private settings. * * @param string $name Name * * @return mixed */ public function get($name) { // rewrite for old and inaccurate plugin:setting if (strstr($name, 'plugin:setting:')) { $msg = 'Direct access of user settings is deprecated. Use ElggPlugin->getUserSetting()'; elgg_deprecated_notice($msg, 1.8); $name = str_replace('plugin:setting:', '', $name); $name = elgg_namespace_plugin_private_setting('user_setting', $name); } // See if its in our base attribute if (array_key_exists($name, $this->attributes)) { return $this->attributes[$name]; } // No, so see if its in the private data store. // get_private_setting() returns false if it doesn't exist $meta = $this->getPrivateSetting($name); if ($meta === false) { // Can't find it, so return null return NULL; } return $meta; }
} else { // add new plugins // priority is force to last in save() if not set. $plugin = new ElggPlugin($plugin_id); $plugin->save(); } } // everything remaining in $known_plugins needs to be disabled // because they are entities, but their dirs were removed. // don't delete the entities because they hold settings. foreach ($known_plugins as $plugin) { if ($plugin->isActive()) { $plugin->deactivate(); } // remove the priority. $name = elgg_namespace_plugin_private_setting('internal', 'priority'); remove_private_setting($plugin->guid, $name); $plugin->disable(); } // get old enabled plugins $enabled_plugin_options["guids"] = array($subsite->getGUID()); $old_enabled_plugins = elgg_get_metadata($enabled_plugin_options); if (!empty($old_enabled_plugins)) { $old_enabled_plugins = metadata_array_to_values($old_enabled_plugins); $old_enabled_plugins = array_unique($old_enabled_plugins); foreach ($old_enabled_plugins as $plugin_id) { if ($plugin = elgg_get_plugin_from_id($plugin_id)) { if (!check_entity_relationship($plugin->getGUID(), 'active_plugin', $subsite->getGUID())) { add_entity_relationship($plugin->getGUID(), 'active_plugin', $subsite->getGUID()); } }
/** * Removes all settings for this plugin. * * @todo Should be a better way to do this without dropping to raw SQL. * @todo If we could namespace the plugin settings this would be cleaner. * @todo this shouldn't work because ps_prefix will be empty string * @return bool */ public function unsetAllSettings() { $db_prefix = get_config('dbprefix'); $us_prefix = elgg_namespace_plugin_private_setting('user_setting', '', $this->getID()); $is_prefix = elgg_namespace_plugin_private_setting('internal', '', $this->getID()); $q = "DELETE FROM {$db_prefix}private_settings\n\t\t\tWHERE entity_guid = {$this->guid}\n\t\t\tAND name NOT LIKE '{$us_prefix}%'\n\t\t\tAND name NOT LIKE '{$is_prefix}%'"; return $this->getDatabase()->deleteData($q); }
/** * Sets the priority of the plugin * * @param mixed $priority The priority to set. One of +1, -1, first, last, or a number. * If given a number, this will displace all plugins at that number * and set their priorities +1 * @param mixed $site_guid Optional site GUID. * @return bool */ public function setPriority($priority, $site_guid = null) { if (!$this->guid) { return false; } $db_prefix = get_config('dbprefix'); $name = elgg_namespace_plugin_private_setting('internal', 'priority'); $plugin_subtype_id = get_subtype_id("object", "plugin"); // if no priority assume a priority of 1 $old_priority = (int) $this->getPriority(); $old_priority = !$old_priority ? 1 : $old_priority; $max_priority = elgg_get_max_plugin_priority(); // can't use switch here because it's not strict and // php evaluates +1 == 1 if ($priority === '+1') { $priority = $old_priority + 1; } elseif ($priority === '-1') { $priority = $old_priority - 1; } elseif ($priority === 'first') { $priority = 1; } elseif ($priority === 'last') { $priority = $max_priority; } // should be a number by now if ($priority > 0) { if (!is_numeric($priority)) { return false; } // there's nothing above the max. if ($priority > $max_priority) { $priority = $max_priority; } // there's nothing below 1. if ($priority < 1) { $priority = 1; } if ($priority > $old_priority) { $op = '-'; $where = "CAST(value as unsigned) BETWEEN {$old_priority} AND {$priority}"; } else { $op = '+'; $where = "CAST(value as unsigned) BETWEEN {$priority} AND {$old_priority}"; } // displace the ones affected by this change $q = "UPDATE {$db_prefix}private_settings"; $q .= " SET value = CAST(value as unsigned) {$op} 1"; $q .= " WHERE entity_guid != {$this->guid}"; $q .= " AND name = '{$name}'"; $q .= " AND entity_guid IN ("; $q .= " SELECT guid"; $q .= " FROM {$db_prefix}entities"; $q .= " WHERE (type = 'object' AND subtype = {$plugin_subtype_id})"; $q .= " AND site_guid = {$this->site_guid}"; $q .= ")"; $q .= " AND {$where}"; if (!update_data($q)) { return false; } // set this priority if ($this->set($name, $priority)) { return true; } else { return false; } } return false; }
function subsite_manager_user_support_admins_hook($hook, $type, $return_value, $params) { $result = $return_value; if (!empty($params) && is_array($params)) { $ticket = elgg_extract("entity", $params); $subsite_admin_guids = array(); $site = elgg_get_site_entity($ticket->site_guid); if (elgg_instanceof($site, "site", Subsite::SUBTYPE, "Subsite")) { if ($admin_guids = $site->getAdminGuids()) { $subsite_admin_guids = $admin_guids; } } $plugin_setting_name = elgg_namespace_plugin_private_setting("user_setting", "admin_notify", "user_support"); if (!subsite_manager_check_global_plugin_setting("user_support", "use_global_usersettings")) { $plugin_setting_name = str_replace(ELGG_PLUGIN_USER_SETTING_PREFIX . "user_support:", ELGG_PLUGIN_USER_SETTING_PREFIX . "user_support:" . $site->getGUID() . ":", $plugin_setting_name); } $subsite_admin_query = ""; if (!empty($subsite_admin_guids)) { $subsite_admin_query = " OR e.guid IN (" . implode(",", $subsite_admin_guids) . ")"; } $options = array("type" => "user", "limit" => false, "site_guids" => false, "relationship" => "member_of_site", "relationship_guid" => $site->getGUID(), "inverse_relationship" => true, "joins" => array("JOIN " . get_config("dbprefix") . "private_settings ps ON e.guid = ps.entity_guid", "JOIN " . get_config("dbprefix") . "users_entity ue ON e.guid = ue.guid"), "wheres" => array("(ps.name = '" . $plugin_setting_name . "' AND ps.value = 'yes')", "(ue.admin = 'yes' " . $subsite_admin_query . ")", "(e.guid <> " . $ticket->getOwnerGUID() . ")")); if ($new_admins = elgg_get_entities_from_relationship($options)) { if (!empty($result)) { if (!is_array($result)) { $result = array($result); } $admin_guids = array(); foreach ($result as $old_admin) { $admin_guids[] = $old_admin->getGUID(); } foreach ($new_admins as $admin) { if (!in_array($admin->getGUID(), $admin_guids)) { $result[] = $admin; } } } else { // haven't found anything yet, so overrule with new value $result = $new_admins; } } } return $result; }