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 * prints needed HTML to include plugin CSS and JS files 11 */ 12function plugin_printCSSJS(){ 13 $plugins = plugin_list(); 14 foreach ($plugins as $p){ 15 $dir = "lib/plugins/$p/"; 16 if(@file_exists(DOKU_INC.$dir.'style.css')){ 17 print ' <link rel="stylesheet" type="text/css" href="'.DOKU_BASE.$dir.'style.css" />'."\n"; 18 } 19 if(@file_exists(DOKU_INC.$dir.'screen.css')){ 20 print ' <link rel="stylesheet" media="screen" type="text/css" href="'.DOKU_BASE.$dir.'screen.css" />'."\n"; 21 } 22 if(@file_exists(DOKU_INC.$dir.'print.css')){ 23 print ' <link rel="stylesheet" media="print" type="text/css" href="'.DOKU_BASE.$dir.'print.css" />'."\n"; 24 } 25 if(@file_exists(DOKU_INC.$dir.'script.js')){ 26 print ' <script type="text/javascript" language="javascript" charset="utf-8" src="'.DOKU_BASE.$dir.'script.js"></script>'."\n"; 27 } 28 } 29} 30 31/** 32 * Returns a list of available plugins of given type 33 * 34 * Returns all plugins if no type given 35 * 36 * @author Andreas Gohr <andi@splitbrain.org> 37 */ 38function plugin_list($type=''){ 39 $plugins = array(); 40 if ($dh = opendir(DOKU_PLUGIN)) { 41 while (false !== ($file = readdir($dh))) { 42 if ($file == '.' || $file == '..') continue; 43 if (is_file(DOKU_PLUGIN.$file)) continue; 44 45 if ($type=='' || @file_exists(DOKU_PLUGIN.$file.'/'.$type.'.php')){ 46 $plugins[] = $file; 47 } 48 } 49 closedir($dh); 50 } 51 return $plugins; 52} 53 54/** 55 * Loads the given plugin and creates an object of it 56 * 57 * @author Andreas Gohr <andi@splitbrain.org> 58 * 59 * @param $type string type of plugin to load 60 * @param $name string name of the plugin to load 61 * @return object the plugin object or null on failure 62 */ 63function &plugin_load($type,$name){ 64 //we keep all loaded plugins available in global scope for reuse 65 global $DOKU_PLUGINS; 66 67 //plugin already loaded? 68 if($DOKU_PLUGINS[$type][$name] != null){ 69 return $DOKU_PLUGINS[$type][$name]; 70 } 71 72 //try to load the wanted plugin file 73 if(!include_once(DOKU_PLUGIN.$name.'/'.$type.'.php')){ 74 return null; 75 } 76 77 //construct class and instanciate 78 $class = $type.'_plugin_'.$name; 79 $DOKU_PLUGINS[$type][$name] = new $class; 80 return $DOKU_PLUGINS[$type][$name]; 81} 82 83 84