diff options
author | andi <andi@splitbrain.org> | 2005-05-19 22:10:09 +0200 |
---|---|---|
committer | andi <andi@splitbrain.org> | 2005-05-19 22:10:09 +0200 |
commit | ee20e7d16637625e900f518b6b46a61bfa30fe6e (patch) | |
tree | f621ec424429d9dc9732a059ec0ca4bf83aab566 /inc/pluginutils.php | |
parent | 64f50cdbe21d0b9ca2165749301e6f553f9b8f02 (diff) | |
download | rpg-ee20e7d16637625e900f518b6b46a61bfa30fe6e.tar.gz rpg-ee20e7d16637625e900f518b6b46a61bfa30fe6e.tar.bz2 |
first attempt of syntax plugins
The first version of the new plugin system. Syntax plugins only yet. A very simple
example plugin called info (doing nothig useful yet) is included.
Missing Features
- Doku_Block_Handler needs work (doesn't honur plugins yet)
- there is no way to specify the order of plugins and other modes yet
- useful output from the info plugin
- bug testing and fixing
- code cleanup
- documentation
darcs-hash:20050519201009-9977f-f793dbfc6a39d8a9643b610927d93cd3288bdd6b.gz
Diffstat (limited to 'inc/pluginutils.php')
-rw-r--r-- | inc/pluginutils.php | 62 |
1 files changed, 62 insertions, 0 deletions
diff --git a/inc/pluginutils.php b/inc/pluginutils.php new file mode 100644 index 000000000..3be57f2d7 --- /dev/null +++ b/inc/pluginutils.php @@ -0,0 +1,62 @@ +<?php +/** + * Utilities for handling plugins + * + * @license GPL 2 (http://www.gnu.org/licenses/gpl.html) + * @author Andreas Gohr <andi@splitbrain.org> + */ + +/** + * Returns a list of available plugins of given type + * + * @author Andreas Gohr <andi@splitbrain.org> + */ +function plugin_list($type){ + $plugins = array(); + if ($dh = opendir(DOKU_PLUGIN)) { + while (false !== ($file = readdir($dh))) { + if ($file == '.' || $file == '..') continue; + if (is_file(DOKU_PLUGIN.$file)) continue; + + if (@file_exists(DOKU_PLUGIN.$file.'/'.$type.'.php')){ + $plugins[] = $file; + } + } + closedir($dh); + } + return $plugins; +} + +/** + * 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 $ref ref will contain the plugin object + * @return boolean plugin loading successful? + */ +function plugin_load($type,$name,&$ref){ + //we keep all loaded plugins available in global scope for reuse + global $DOKU_PLUGINS; + + //plugin already loaded? + if($DOKU_PLUGINS[$type][$name] != null){ + $ref = $DOKU_PLUGINS[$type][$name]; + return true; + } + + //try to load the wanted plugin file + if(!@include_once(DOKU_PLUGIN.$name.'/'.$type.'.php')){ + return false; + } + + //construct class and instanciate + $class = $type.'_plugin_'.$name; + $DOKU_PLUGINS[$type][$name] = new $class; + $ref = $DOKU_PLUGINS[$type][$name]; + return true; +} + + |