diff options
author | Andreas Gohr <andi@splitbrain.org> | 2009-10-20 23:23:38 +0200 |
---|---|---|
committer | Andreas Gohr <andi@splitbrain.org> | 2009-10-20 23:23:38 +0200 |
commit | db959ae30700e3924a73350a3a43a2c36b431de7 (patch) | |
tree | f89b3fb0609abb72cf93fa8060f7fc27f4c15f40 /inc/plugincontroller.class.php | |
parent | 8ec3f7bdbf7a5f702a3022332a6f6cb424d0981a (diff) | |
download | rpg-db959ae30700e3924a73350a3a43a2c36b431de7.tar.gz rpg-db959ae30700e3924a73350a3a43a2c36b431de7.tar.bz2 |
Coding Standard Cleanup
Ignore-this: 259cb5773c3144c6c706d87298dcf674
darcs-hash:20091020212338-7ad00-6bf1c5c403491f136a1c02af5ecd9f84d7227107.gz
Diffstat (limited to 'inc/plugincontroller.class.php')
-rw-r--r-- | inc/plugincontroller.class.php | 268 |
1 files changed, 134 insertions, 134 deletions
diff --git a/inc/plugincontroller.class.php b/inc/plugincontroller.class.php index 707d90856..4400a4187 100644 --- a/inc/plugincontroller.class.php +++ b/inc/plugincontroller.class.php @@ -11,162 +11,162 @@ if(!defined('DOKU_PLUGIN')) define('DOKU_PLUGIN',DOKU_INC.'lib/plugins/'); class Doku_Plugin_Controller { - var $list_enabled = array(); - var $list_disabled = array(); - var $list_bytype = array(); - - function Doku_Plugin_Controller() { - $this->_populateMasterList(); - } - - /** - * Returns a list of available plugins of given type - * - * @param $type string, plugin_type name; - * the type of plugin to return, - * use empty string for all types - * @param $all bool; - * false to only return enabled plugins, - * true to return both enabled and disabled plugins - * - * @return array of plugin names - * - * @author Andreas Gohr <andi@splitbrain.org> - */ - function getList($type='',$all=false){ - - // request the complete list - if (!$type) { - return $all ? array_merge($this->list_enabled,$this->list_disabled) : $this->list_enabled; - } + var $list_enabled = array(); + var $list_disabled = array(); + var $list_bytype = array(); - if (!isset($this->list_bytype[$type]['enabled'])) { - $this->list_bytype[$type]['enabled'] = $this->_getListByType($type,true); - } - if ($all && !isset($this->list_bytype[$type]['disabled'])) { - $this->list_bytype[$type]['disabled'] = $this->_getListByType($type,false); + function Doku_Plugin_Controller() { + $this->_populateMasterList(); } - return $all ? array_merge($this->list_bytype[$type]['enabled'],$this->list_bytype[$type]['disabled']) : $this->list_bytype[$type]['enabled']; - } - - /** - * Loads the given plugin and creates an object of it - * - * @author Andreas Gohr <andi@splitbrain.org> - * - * @param $type string type of plugin to load - * @param $name string name of the plugin to load - * @param $new bool true to return a new instance of the plugin, false to use an already loaded instance - * @return objectreference the plugin object or null on failure - */ - function &load($type,$name,$new=false){ - //we keep all loaded plugins available in global scope for reuse - global $DOKU_PLUGINS; - - //plugin already loaded? - if(!empty($DOKU_PLUGINS[$type][$name])){ - if ($new && !$DOKU_PLUGINS[$type][$name]->isSingleton()) { - $class = $type.'_plugin_'.$name; - return class_exists($class) ? new $class : null; - } else { - return $DOKU_PLUGINS[$type][$name]; - } - } + /** + * Returns a list of available plugins of given type + * + * @param $type string, plugin_type name; + * the type of plugin to return, + * use empty string for all types + * @param $all bool; + * false to only return enabled plugins, + * true to return both enabled and disabled plugins + * + * @return array of plugin names + * + * @author Andreas Gohr <andi@splitbrain.org> + */ + function getList($type='',$all=false){ + + // request the complete list + if (!$type) { + return $all ? array_merge($this->list_enabled,$this->list_disabled) : $this->list_enabled; + } - //try to load the wanted plugin file - list($plugin,$component) = $this->_splitName($name); - $dir = $this->get_directory($plugin); - $file = $component ? "$type/$component.php" : "$type.php"; + if (!isset($this->list_bytype[$type]['enabled'])) { + $this->list_bytype[$type]['enabled'] = $this->_getListByType($type,true); + } + if ($all && !isset($this->list_bytype[$type]['disabled'])) { + $this->list_bytype[$type]['disabled'] = $this->_getListByType($type,false); + } - if(!is_file(DOKU_PLUGIN."$dir/$file")){ - return null; + return $all ? array_merge($this->list_bytype[$type]['enabled'],$this->list_bytype[$type]['disabled']) : $this->list_bytype[$type]['enabled']; } - if (!include_once(DOKU_PLUGIN."$dir/$file")) { - return null; - } + /** + * Loads the given plugin and creates an object of it + * + * @author Andreas Gohr <andi@splitbrain.org> + * + * @param $type string type of plugin to load + * @param $name string name of the plugin to load + * @param $new bool true to return a new instance of the plugin, false to use an already loaded instance + * @return objectreference the plugin object or null on failure + */ + function &load($type,$name,$new=false){ + //we keep all loaded plugins available in global scope for reuse + global $DOKU_PLUGINS; + + //plugin already loaded? + if(!empty($DOKU_PLUGINS[$type][$name])){ + if ($new && !$DOKU_PLUGINS[$type][$name]->isSingleton()) { + $class = $type.'_plugin_'.$name; + return class_exists($class) ? new $class : null; + } else { + return $DOKU_PLUGINS[$type][$name]; + } + } + + //try to load the wanted plugin file + list($plugin,$component) = $this->_splitName($name); + $dir = $this->get_directory($plugin); + $file = $component ? "$type/$component.php" : "$type.php"; + + if(!is_file(DOKU_PLUGIN."$dir/$file")){ + return null; + } - //construct class and instantiate - $class = $type.'_plugin_'.$name; - if (!class_exists($class)) return null; + if (!include_once(DOKU_PLUGIN."$dir/$file")) { + return null; + } - $DOKU_PLUGINS[$type][$name] = new $class; - return $DOKU_PLUGINS[$type][$name]; - } + //construct class and instantiate + $class = $type.'_plugin_'.$name; + if (!class_exists($class)) return null; - function isdisabled($plugin) { - return (array_search($plugin, $this->list_enabled) === false); - } + $DOKU_PLUGINS[$type][$name] = new $class; + return $DOKU_PLUGINS[$type][$name]; + } - function enable($plugin) { - if (array_search($plugin, $this->list_disabled) !== false) { - return @unlink(DOKU_PLUGIN.$plugin.'/disabled'); + function isdisabled($plugin) { + return (array_search($plugin, $this->list_enabled) === false); } - return false; - } - function disable($plugin) { - if (array_search($plugin, $this->list_enabled) !== false) { - return @touch(DOKU_PLUGIN.$plugin.'/disabled'); + function enable($plugin) { + if (array_search($plugin, $this->list_disabled) !== false) { + return @unlink(DOKU_PLUGIN.$plugin.'/disabled'); + } + return false; } - return false; - } - - function get_directory($plugin) { - return $plugin; - } - - function _populateMasterList() { - if ($dh = opendir(DOKU_PLUGIN)) { - while (false !== ($plugin = readdir($dh))) { - if ($plugin == '.' || $plugin == '..' || $plugin == 'tmp') continue; - if (is_file(DOKU_PLUGIN.$plugin)) continue; - - if (substr($plugin,-9) == '.disabled') { - // the plugin was disabled by rc2009-01-26 - // disabling mechanism was changed back very soon again - // to keep everything simple we just skip the plugin completely - }elseif(@file_exists(DOKU_PLUGIN.$plugin.'/disabled')){ - $this->list_disabled[] = $plugin; - } else { - $this->list_enabled[] = $plugin; + + function disable($plugin) { + if (array_search($plugin, $this->list_enabled) !== false) { + return @touch(DOKU_PLUGIN.$plugin.'/disabled'); } - } + return false; + } + + function get_directory($plugin) { + return $plugin; } - } - - function _getListByType($type, $enabled) { - $master_list = $enabled ? $this->list_enabled : $this->list_disabled; - - $plugins = array(); - foreach ($master_list as $plugin) { - $dir = $this->get_directory($plugin); - - if (@file_exists(DOKU_PLUGIN."$dir/$type.php")){ - $plugins[] = $plugin; - } else { - if ($dp = @opendir(DOKU_PLUGIN."$dir/$type/")) { - while (false !== ($component = readdir($dp))) { - if (substr($component,0,1) == '.' || strtolower(substr($component, -4)) != ".php") continue; - if (is_file(DOKU_PLUGIN."$dir/$type/$component")) { - $plugins[] = $plugin.'_'.substr($component, 0, -4); + + function _populateMasterList() { + if ($dh = opendir(DOKU_PLUGIN)) { + while (false !== ($plugin = readdir($dh))) { + if ($plugin == '.' || $plugin == '..' || $plugin == 'tmp') continue; + if (is_file(DOKU_PLUGIN.$plugin)) continue; + + if (substr($plugin,-9) == '.disabled') { + // the plugin was disabled by rc2009-01-26 + // disabling mechanism was changed back very soon again + // to keep everything simple we just skip the plugin completely + }elseif(@file_exists(DOKU_PLUGIN.$plugin.'/disabled')){ + $this->list_disabled[] = $plugin; + } else { + $this->list_enabled[] = $plugin; + } } - } - closedir($dp); } - } } - return $plugins; - } + function _getListByType($type, $enabled) { + $master_list = $enabled ? $this->list_enabled : $this->list_disabled; + + $plugins = array(); + foreach ($master_list as $plugin) { + $dir = $this->get_directory($plugin); + + if (@file_exists(DOKU_PLUGIN."$dir/$type.php")){ + $plugins[] = $plugin; + } else { + if ($dp = @opendir(DOKU_PLUGIN."$dir/$type/")) { + while (false !== ($component = readdir($dp))) { + if (substr($component,0,1) == '.' || strtolower(substr($component, -4)) != ".php") continue; + if (is_file(DOKU_PLUGIN."$dir/$type/$component")) { + $plugins[] = $plugin.'_'.substr($component, 0, -4); + } + } + closedir($dp); + } + } + } - function _splitName($name) { - if (array_search($name, $this->list_enabled + $this->list_disabled) === false) { - return explode('_',$name,2); + return $plugins; } - return array($name,''); - } + function _splitName($name) { + if (array_search($name, $this->list_enabled + $this->list_disabled) === false) { + return explode('_',$name,2); + } + + return array($name,''); + } } |