From 3a336843e1cdd340dd3630747b3e6265b6effa39 Mon Sep 17 00:00:00 2001 From: Luke Shumaker Date: Sat, 20 Nov 2010 22:02:31 -0500 Subject: Add more robust (but backward-compatible) plugin config system. util.php: add common_config_section($main), as a companion to common_config($main,sub) statusnet.php: * 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') * handle plugins that have a type other than "array" or "null" for parameters pluginenable: * use StatusNet::getPlugins() instead of common_config('plugins,'default') * set $config['plugin-list'][$plugin_name] = 1 pluginsadminpanel: use StatusNet::getPlugins() instead of common_config('plugins,'default') --- actions/pluginenable.php | 5 +++-- actions/pluginsadminpanel.php | 2 +- lib/statusnet.php | 23 ++++++++++++++++++----- lib/util.php | 6 ++++++ 4 files changed, 28 insertions(+), 8 deletions(-) diff --git a/actions/pluginenable.php b/actions/pluginenable.php index 2dbb3e395..826874ae5 100644 --- a/actions/pluginenable.php +++ b/actions/pluginenable.php @@ -104,8 +104,8 @@ class PluginEnableAction extends Action } $this->plugin = $this->arg('plugin'); - $defaultPlugins = common_config('plugins', 'default'); - if (!array_key_exists($this->plugin, $defaultPlugins)) { + $pluginList = StatusNet::getPlugins(); + if (!array_key_exists($this->plugin, $pluginList)) { $this->clientError(_('No such plugin.')); return false; } @@ -127,6 +127,7 @@ class PluginEnableAction extends Action { $key = 'disable-' . $this->plugin; Config::save('plugins', $key, $this->overrideValue()); + Config::save('plugin-list', $this->plugin, 1); // @fixme this is a pretty common pattern and should be refactored down if ($this->boolean('ajax')) { diff --git a/actions/pluginsadminpanel.php b/actions/pluginsadminpanel.php index bc400bd51..c1f4fe253 100644 --- a/actions/pluginsadminpanel.php +++ b/actions/pluginsadminpanel.php @@ -95,7 +95,7 @@ class PluginsadminpanelAction extends AdminPanelAction */ protected function showDefaultPlugins() { - $plugins = array_keys(common_config('plugins', 'default')); + $plugins = array_keys(StatusNet::getPlugins()); natsort($plugins); if ($plugins) { diff --git a/lib/statusnet.php b/lib/statusnet.php index ff0502915..f8bf87960 100644 --- a/lib/statusnet.php +++ b/lib/statusnet.php @@ -169,22 +169,33 @@ class StatusNet return $sites; } + /** + * Return a list of plugins + */ + 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 { @@ -197,6 +208,8 @@ class StatusNet } } } + } else { + addPlugin($name); } } diff --git a/lib/util.php b/lib/util.php index f187926b5..a9ed91870 100644 --- a/lib/util.php +++ b/lib/util.php @@ -1650,6 +1650,12 @@ function common_config($main, $sub) array_key_exists($sub, $config[$main])) ? $config[$main][$sub] : false; } +function common_config_section($main) +{ + global $config; + return array_key_exists($main, $config) ? $config[$main] : false; +} + function common_copy_args($from) { $to = array(); -- cgit v1.2.3-54-g00ecf