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 * @param $ref ref will contain the plugin object 38 * @return boolean plugin loading successful? 39 */ 40function plugin_load($type,$name,&$ref){ 41 //we keep all loaded plugins available in global scope for reuse 42 global $DOKU_PLUGINS; 43 44 //plugin already loaded? 45 if($DOKU_PLUGINS[$type][$name] != null){ 46 $ref = $DOKU_PLUGINS[$type][$name]; 47 return true; 48 } 49 50 //try to load the wanted plugin file 51 if(!include_once(DOKU_PLUGIN.$name.'/'.$type.'.php')){ 52 return false; 53 } 54 55 //construct class and instanciate 56 $class = $type.'_plugin_'.$name; 57 $DOKU_PLUGINS[$type][$name] = new $class; 58 $ref = $DOKU_PLUGINS[$type][$name]; 59 return true; 60} 61 62 63