From 37c03d68a82fb978d46d3a9e7c9051983de38b3d Mon Sep 17 00:00:00 2001 From: Luke Shumaker Date: Fri, 24 Dec 2010 23:43:10 -0700 Subject: Add a more robust plugin config system. 2010-11-20: Luke Shumaker Add a more robust (but backward compatible) plugin config system * lib/util.php: add common_config_section($main), as a companion to common_config($main,$sub) * lib/statusnet.php: Functions for other Places: - add public static pluginFiles($name) which returns a list of all possible filenames a plugin with $name could be defined in. - addPlugin(...): use self::pluginFiles(...) instead of a hard-coded list. Actual Functionality: - add public static getPlugins() which returns array_merge( common_config('plugins','default'), common_config_section('plugin-list') ) - use self::getPlugins() instead of common_config('plugins','default') Robustness: - handle plugins that have a type other than "array" or "null" for parameters without bugging out * actions/pluginenable.php: (in order of in the file): - use StatusNet::getPlugins() instead of common_config('plugins','default') - check if a plugin exists, not whether it is loaded (uses newly added StatusNet::pluginFiles(...)) - Also save to 'plugin-list' (the new plugin system), in addition to 'plugins' (the old plugin system) --- lib/statusnet.php | 53 ++++++++++++++++++++++++++++++++++++++++++----------- 1 file changed, 42 insertions(+), 11 deletions(-) (limited to 'lib/statusnet.php') diff --git a/lib/statusnet.php b/lib/statusnet.php index 4c2aacd8f..099894455 100644 --- a/lib/statusnet.php +++ b/lib/statusnet.php @@ -33,6 +33,25 @@ class StatusNet protected static $is_api; protected static $plugins = array(); + /** + * Return a list of possible filenames that plugin $name can be in. + * + * @param string $name class name & plugin file/subdir name + */ + public static function pluginFiles($name) { + $name = ucfirst($name); + $pluginclass = "{$name}Plugin"; + + $files = array("local/plugins/{$pluginclass}.php", + "local/plugins/{$name}/{$pluginclass}.php", + "local/{$pluginclass}.php", + "local/{$name}/{$pluginclass}.php", + "plugins/{$pluginclass}.php", + "plugins/{$name}/{$pluginclass}.php"); + + return $files; + } + /** * Configure and instantiate a plugin into the current configuration. * Class definitions will be loaded from standard paths if necessary. @@ -50,12 +69,7 @@ class StatusNet if (!class_exists($pluginclass)) { - $files = array("local/plugins/{$pluginclass}.php", - "local/plugins/{$name}/{$pluginclass}.php", - "local/{$pluginclass}.php", - "local/{$name}/{$pluginclass}.php", - "plugins/{$pluginclass}.php", - "plugins/{$name}/{$pluginclass}.php"); + $files = self::pluginFiles($name); foreach ($files as $file) { $fullpath = INSTALLDIR.'/'.$file; @@ -168,22 +182,37 @@ class StatusNet } return $sites; } + /** + * Return a list of plugins that are currently in the system. + * + * This means default plugins, plugins that are explicitly enabled, or + * plugins that are explicitly disabled. + */ + + public static function getPlugins() { + // Default plugins + $pluginlist = common_config('plugins', 'default'); + // Enabled plugins + $enabled=common_config_section('plugin-list'); + if ($enabled) { + $pluginlist = array_merge($pluginlist,$enabled); + } + return $pluginlist; + } /** * Fire initialization events for all instantiated plugins. */ protected static function initPlugins() { - // Load default plugins - foreach (common_config('plugins', 'default') as $name => $params) { + // Load plugins + foreach (self::getPlugins() as $name => $params) { $key = 'disable-' . $name; if (common_config('plugins', $key)) { continue; } - if (is_null($params)) { - addPlugin($name); - } else if (is_array($params)) { + if (is_array($params)) { if (count($params) == 0) { addPlugin($name); } else { @@ -196,6 +225,8 @@ class StatusNet } } } + } else { + addPlugin($name); } } -- cgit v1.2.3-54-g00ecf