From 3048db0f3f1ade31d6f3a2cdd3268e978a3e3cf3 Mon Sep 17 00:00:00 2001 From: Steve Clay Date: Mon, 17 Sep 2012 17:41:15 -0400 Subject: Fixes #4861: allow lazy-loading for static method callbacks, allow more callables --- engine/classes/ElggPAM.php | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) (limited to 'engine/classes') diff --git a/engine/classes/ElggPAM.php b/engine/classes/ElggPAM.php index 0681a909b..f07095fc1 100644 --- a/engine/classes/ElggPAM.php +++ b/engine/classes/ElggPAM.php @@ -53,11 +53,17 @@ class ElggPAM { foreach ($_PAM_HANDLERS[$this->policy] as $k => $v) { $handler = $v->handler; + if (!is_callable($handler)) { + continue; + } + /* @var callable $handler */ + $importance = $v->importance; try { // Execute the handler - $result = $handler($credentials); + // @todo don't assume $handler is a global function + $result = call_user_func($handler, $credentials); if ($result) { $authenticated = true; } elseif ($result === false) { -- cgit v1.2.3 From 937119200300ebc2b09df4354fb7cd547535ecfb Mon Sep 17 00:00:00 2001 From: Steve Clay Date: Mon, 26 Nov 2012 17:31:53 -0500 Subject: Refs #4933: cache in plugin constructor, remove $CONFIG --- engine/classes/ElggPlugin.php | 7 +++-- engine/lib/plugins.php | 69 +++++++++++++++++++------------------------ 2 files changed, 36 insertions(+), 40 deletions(-) (limited to 'engine/classes') diff --git a/engine/classes/ElggPlugin.php b/engine/classes/ElggPlugin.php index 3e43c8e81..c6ce2905f 100644 --- a/engine/classes/ElggPlugin.php +++ b/engine/classes/ElggPlugin.php @@ -36,8 +36,9 @@ class ElggPlugin extends ElggObject { * @warning Unlike other ElggEntity objects, you cannot null instantiate * ElggPlugin. You must point it to an actual plugin GUID or location. * - * @param mixed $plugin The GUID of the ElggPlugin object or the path of - * the plugin to load. + * @param mixed $plugin The GUID of the ElggPlugin object or the path of the plugin to load. + * + * @throws PluginException */ public function __construct($plugin) { if (!$plugin) { @@ -76,6 +77,8 @@ class ElggPlugin extends ElggObject { // load the rest of the plugin parent::__construct($existing_guid); } + + _elgg_cache_plugin_by_id($this); } /** 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) { -- cgit v1.2.3 From 9168cf7df39e404516c45f77bd64b47b3c61c75d Mon Sep 17 00:00:00 2001 From: Steve Clay Date: Sat, 1 Dec 2012 20:09:11 -0500 Subject: Make metadata prefetch respect access --- engine/classes/ElggVolatileMetadataCache.php | 3 +++ mod/profile/views/default/profile/details.php | 2 +- 2 files changed, 4 insertions(+), 1 deletion(-) (limited to 'engine/classes') diff --git a/engine/classes/ElggVolatileMetadataCache.php b/engine/classes/ElggVolatileMetadataCache.php index 24ae58d42..8a33c198d 100644 --- a/engine/classes/ElggVolatileMetadataCache.php +++ b/engine/classes/ElggVolatileMetadataCache.php @@ -279,6 +279,9 @@ class ElggVolatileMetadataCache { ), 'selects' => array('n.string AS name', 'v.string AS value'), 'order_by' => 'n_table.entity_guid, n_table.time_created ASC', + + // @todo don't know why this is necessary + 'wheres' => array(get_access_sql_suffix('n_table')), ); $data = elgg_get_metadata($options); diff --git a/mod/profile/views/default/profile/details.php b/mod/profile/views/default/profile/details.php index 3af5cb756..7b05b0e15 100644 --- a/mod/profile/views/default/profile/details.php +++ b/mod/profile/views/default/profile/details.php @@ -28,7 +28,7 @@ if (is_array($profile_fields) && sizeof($profile_fields) > 0) {
: $user->$shortname)); + echo elgg_view("output/{$valtype}", array('value' => $value)); ?>