diff options
author | brettp <brettp@36083f99-b078-4883-b0ff-0f9b5a30f544> | 2010-05-05 19:14:48 +0000 |
---|---|---|
committer | brettp <brettp@36083f99-b078-4883-b0ff-0f9b5a30f544> | 2010-05-05 19:14:48 +0000 |
commit | ff31226fdeb972aac2f37f0098240cb366a9bb26 (patch) | |
tree | 1f0caa75c9a340cf28ce9a81a4cbe3230d13abf3 /engine/lib/plugins.php | |
parent | 81ffac29fabc175eebdbf95578da046f4f00611b (diff) | |
download | elgg-ff31226fdeb972aac2f37f0098240cb366a9bb26.tar.gz elgg-ff31226fdeb972aac2f37f0098240cb366a9bb26.tar.bz2 |
Merged 18_new_admin branch to trunk.
git-svn-id: http://code.elgg.org/elgg/trunk@5977 36083f99-b078-4883-b0ff-0f9b5a30f544
Diffstat (limited to 'engine/lib/plugins.php')
-rw-r--r-- | engine/lib/plugins.php | 80 |
1 files changed, 77 insertions, 3 deletions
diff --git a/engine/lib/plugins.php b/engine/lib/plugins.php index 0e62914e2..b365585c8 100644 --- a/engine/lib/plugins.php +++ b/engine/lib/plugins.php @@ -354,6 +354,11 @@ function load_plugin_manifest($plugin) { } } + // handle plugins that don't define a name + if (!isset($elements['name'])) { + $elements['name'] = ucwords($plugin); + } + return $elements; } @@ -677,6 +682,10 @@ function enable_plugin($plugin, $site_guid = 0) { throw new InvalidClassException(sprintf(elgg_echo('InvalidClassException:NotValidElggStar'), $site_guid, "ElggSite")); } + if (!$plugin_info = load_plugin_manifest($plugin)) { + return FALSE; + } + // getMetadata() doesn't return an array if only one plugin is enabled if ($enabled = $site->enabled_plugins) { if (!is_array($enabled)) { @@ -689,8 +698,42 @@ function enable_plugin($plugin, $site_guid = 0) { $enabled[] = $plugin; $enabled = array_unique($enabled); - $return = $site->setMetaData('enabled_plugins', $enabled); - $ENABLED_PLUGINS_CACHE = $enabled; + if ($return = $site->setMetaData('enabled_plugins', $enabled)) { + + // for other plugins that want to hook into this. + if ($return && !trigger_elgg_event('enable', 'plugin', array('plugin' => $plugin, 'manifest' => $plugin_info))) { + $return = FALSE; + } + + // for this plugin's on_enable + if ($return && isset($plugin_info['on_enable'])) { + // pull in the actual plugin's start so the on_enable function is callabe + // NB: this will not run re-run the init hooks! + $start = "{$CONFIG->pluginspath}$plugin/start.php"; + if (!file_exists($start) || !include($start)) { + $return = FALSE; + } + + // need language files for the messages + $translations = "{$CONFIG->pluginspath}$plugin/languages/"; + register_translations($translations); + if (!is_callable($plugin_info['on_enable'])) { + $return = FALSE; + } else { + $on_enable = call_user_func($plugin_info['on_enable']); + // allow null to mean "I don't care" like other subsystems + $return = ($on_disable === FALSE) ? FALSE : TRUE; + } + } + + // disable the plugin if the on_enable or trigger results failed + if (!$return) { + array_pop($enabled); + $site->setMetaData('enabled_plugins', $enabled); + } + + $ENABLED_PLUGINS_CACHE = $enabled; + } return $return; } @@ -721,6 +764,10 @@ function disable_plugin($plugin, $site_guid = 0) { throw new InvalidClassException(sprintf(elgg_echo('InvalidClassException:NotValidElggStar'), $site_guid, "ElggSite")); } + if (!$plugin_info = load_plugin_manifest($plugin)) { + return FALSE; + } + // getMetadata() doesn't return an array if only one plugin is enabled if ($enabled = $site->enabled_plugins) { if (!is_array($enabled)) { @@ -730,6 +777,8 @@ function disable_plugin($plugin, $site_guid = 0) { $enabled = array(); } + $old_enabled = $enabled; + // remove the disabled plugin from the array if (FALSE !== $i = array_search($plugin, $enabled)) { unset($enabled[$i]); @@ -738,7 +787,32 @@ function disable_plugin($plugin, $site_guid = 0) { // if we're unsetting all the plugins, this will return an empty array. // it will fail with FALSE, though. $return = (FALSE === $site->enabled_plugins = $enabled) ? FALSE : TRUE; - $ENABLED_PLUGINS_CACHE = $enabled; + + if ($return) { + // for other plugins that want to hook into this. + if ($return && !trigger_elgg_event('disable', 'plugin', array('plugin' => $plugin, 'manifest' => $plugin_info))) { + $return = FALSE; + } + + // for this plugin's on_disable + if ($return && isset($plugin_info['on_disable'])) { + if (!is_callable($plugin_info['on_disable'])) { + $return = FALSE; + } else { + $on_disable = call_user_func($plugin_info['on_disable']); + // allow null to mean "I don't care" like other subsystems + $return = ($on_disable === FALSE) ? FALSE : TRUE; + } + } + + // disable the plugin if the on_enable or trigger results failed + if (!$return) { + $site->enabled_plugins = $old_enabled; + $ENABLED_PLUGINS_CACHE = $old_enabled; + } else { + $ENABLED_PLUGINS_CACHE = $enabled; + } + } return $return; } |