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