summaryrefslogtreecommitdiff
path: root/lib/statusnet.php
diff options
context:
space:
mode:
authorLuke Shumaker <LukeShu@sbcglobal.net>2010-12-24 23:43:10 -0700
committerLuke Shumaker <LukeShu@sbcglobal.net>2010-12-24 23:43:10 -0700
commit37c03d68a82fb978d46d3a9e7c9051983de38b3d (patch)
tree0aa9066fb5f0f68e3c48ec28ba3db5acb329846f /lib/statusnet.php
parent26baad63f2e7d5cd0f783aacdb9eb2a65a638656 (diff)
Add a more robust plugin config system.
2010-11-20: Luke Shumaker <lukeshu@sbcglobal.net> 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)
Diffstat (limited to 'lib/statusnet.php')
-rw-r--r--lib/statusnet.php53
1 files changed, 42 insertions, 11 deletions
diff --git a/lib/statusnet.php b/lib/statusnet.php
index 4c2aacd8f..099894455 100644
--- a/lib/statusnet.php
+++ b/lib/statusnet.php
@@ -34,6 +34,25 @@ class StatusNet
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.
* Note that initialization events won't be fired until later.
@@ -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);
}
}