1<?php 2/** 3 * Utilities for handling plugins 4 * 5 * @license GPL 2 (http://www.gnu.org/licenses/gpl.html) 6 * @author Andreas Gohr <andi@splitbrain.org> 7 */ 8 9/** 10 * Returns a list of available plugins of given type 11 * 12 * @author Andreas Gohr <andi@splitbrain.org> 13 */ 14function plugin_list($type){ 15 $plugins = array(); 16 if ($dh = opendir(DOKU_PLUGIN)) { 17 while (false !== ($file = readdir($dh))) { 18 if ($file == '.' || $file == '..') continue; 19 if (is_file(DOKU_PLUGIN.$file)) continue; 20 21 if (@file_exists(DOKU_PLUGIN.$file.'/'.$type.'.php')){ 22 $plugins[] = $file; 23 } 24 } 25 closedir($dh); 26 } 27 return $plugins; 28} 29 30/** 31 * Loads the given plugin and creates an object of it 32 * 33 * @author Andreas Gohr <andi@splitbrain.org> 34 * 35 * @param $type string type of plugin to load 36 * @param $name string name of the plugin to load 37 * @return object the plugin object or null on failure 38 */ 39function &plugin_load($type,$name){ 40 //we keep all loaded plugins available in global scope for reuse 41 global $DOKU_PLUGINS; 42 43 //plugin already loaded? 44 if($DOKU_PLUGINS[$type][$name] != null){ 45 return $DOKU_PLUGINS[$type][$name]; 46 } 47 48 //try to load the wanted plugin file 49 if(!include_once(DOKU_PLUGIN.$name.'/'.$type.'.php')){ 50 return null; 51 } 52 53 //construct class and instanciate 54 $class = $type.'_plugin_'.$name; 55 $DOKU_PLUGINS[$type][$name] = new $class; 56 return $DOKU_PLUGINS[$type][$name]; 57} 58 59 60