aboutsummaryrefslogtreecommitdiff
path: root/engine/lib/plugins.php
diff options
context:
space:
mode:
Diffstat (limited to 'engine/lib/plugins.php')
-rw-r--r--engine/lib/plugins.php69
1 files changed, 31 insertions, 38 deletions
diff --git a/engine/lib/plugins.php b/engine/lib/plugins.php
index 127d4bf8e..ca4a957f4 100644
--- a/engine/lib/plugins.php
+++ b/engine/lib/plugins.php
@@ -107,7 +107,6 @@ function elgg_generate_plugin_entities() {
$old_access = access_get_show_hidden_status();
access_show_hidden_entities(true);
$known_plugins = elgg_get_entities_from_relationship($options);
- _elgg_add_plugin_ids_mapping($known_plugins);
if (!$known_plugins) {
$known_plugins = array();
@@ -152,7 +151,6 @@ function elgg_generate_plugin_entities() {
// priority is force to last in save() if not set.
$plugin = new ElggPlugin($plugin_id);
$plugin->save();
- _elgg_add_plugin_ids_mapping(array($plugin));
}
}
@@ -178,22 +176,16 @@ function elgg_generate_plugin_entities() {
}
/**
- * Registers given plugins in plugin_id to entity mapping data structure
+ * Cache a reference to this plugin by its ID
*
- * @param array $plugins ElggPlugin instances to be registered
+ * @param ElggPlugin $plugin
*
* @access private
*/
-function _elgg_add_plugin_ids_mapping($plugins) {
- global $CONFIG;
- if (!is_array($CONFIG->plugin_ids_mapping)) {
- $CONFIG->plugin_ids_mapping = array();
- }
- foreach ($plugins as $plugin) {
- if ($plugin instanceof ElggPlugin) {
- $CONFIG->plugin_ids_mapping[$plugin->getID()] = $plugin;
- }
- }
+function _elgg_cache_plugin_by_id(ElggPlugin $plugin) {
+ $map = (array) elgg_get_config('plugins_by_id_map');
+ $map[$plugin->getID()] = $plugin;
+ elgg_set_config('plugins_by_id_map', $map);
}
/**
@@ -204,30 +196,29 @@ function _elgg_add_plugin_ids_mapping($plugins) {
* @since 1.8.0
*/
function elgg_get_plugin_from_id($plugin_id) {
- global $CONFIG;
- if (isset($CONFIG->plugin_ids_mapping[$plugin_id])) {
- return $CONFIG->plugin_ids_mapping[$plugin_id];
- } else {
- $plugin_id = sanitize_string($plugin_id);
- $db_prefix = get_config('dbprefix');
-
- $options = array(
- 'type' => 'object',
- 'subtype' => 'plugin',
- 'joins' => array("JOIN {$db_prefix}objects_entity oe on oe.guid = e.guid"),
- 'wheres' => array("oe.title = '$plugin_id'"),
- 'limit' => 1
- );
-
- $plugins = elgg_get_entities($options);
-
- if ($plugins) {
- _elgg_add_plugin_ids_mapping($plugins);
- return $plugins[0];
- }
-
- return false;
+ $map = (array) elgg_get_config('plugins_by_id_map');
+ if (isset($map[$plugin_id])) {
+ return $map[$plugin_id];
+ }
+
+ $plugin_id = sanitize_string($plugin_id);
+ $db_prefix = get_config('dbprefix');
+
+ $options = array(
+ 'type' => 'object',
+ 'subtype' => 'plugin',
+ 'joins' => array("JOIN {$db_prefix}objects_entity oe on oe.guid = e.guid"),
+ 'wheres' => array("oe.title = '$plugin_id'"),
+ 'limit' => 1
+ );
+
+ $plugins = elgg_get_entities($options);
+
+ if ($plugins) {
+ return $plugins[0];
}
+
+ return false;
}
/**
@@ -417,7 +408,6 @@ function elgg_get_plugins($status = 'active', $site_guid = null) {
$old_ia = elgg_set_ignore_access(true);
$plugins = elgg_get_entities_from_relationship($options);
- _elgg_add_plugin_ids_mapping($plugins);
elgg_set_ignore_access($old_ia);
return $plugins;
@@ -540,6 +530,8 @@ function elgg_namespace_plugin_private_setting($type, $name, $id = null) {
* @return string|false Plugin name, or false if no plugin name was called
* @since 1.8.0
* @access private
+ *
+ * @todo get rid of this
*/
function elgg_get_calling_plugin_id($mainfilename = false) {
if (!$mainfilename) {
@@ -948,6 +940,7 @@ function elgg_set_plugin_setting($name, $value, $plugin_id = null) {
*
* @return mixed
* @since 1.8.0
+ * @todo make $plugin_id required in future version
*/
function elgg_get_plugin_setting($name, $plugin_id = null) {
if ($plugin_id) {