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*3600bd52SAndreas Gohr * prints needed HTML to include plugin CSS and JS files 114b15e09dSAndreas Gohr */ 12*3600bd52SAndreas Gohrfunction plugin_printCSSJS(){ 134b15e09dSAndreas Gohr $plugins = plugin_list(); 144b15e09dSAndreas Gohr foreach ($plugins as $p){ 154b15e09dSAndreas Gohr $dir = "lib/plugins/$p/"; 164b15e09dSAndreas Gohr if(@file_exists(DOKU_INC.$dir.'style.css')){ 174b15e09dSAndreas Gohr print ' <link rel="stylesheet" type="text/css" href="'.DOKU_BASE.$dir.'style.css" />'."\n"; 184b15e09dSAndreas Gohr } 194b15e09dSAndreas Gohr if(@file_exists(DOKU_INC.$dir.'screen.css')){ 204b15e09dSAndreas Gohr print ' <link rel="stylesheet" media="screen" type="text/css" href="'.DOKU_BASE.$dir.'screen.css" />'."\n"; 214b15e09dSAndreas Gohr } 224b15e09dSAndreas Gohr if(@file_exists(DOKU_INC.$dir.'print.css')){ 234b15e09dSAndreas Gohr print ' <link rel="stylesheet" media="print" type="text/css" href="'.DOKU_BASE.$dir.'print.css" />'."\n"; 244b15e09dSAndreas Gohr } 25*3600bd52SAndreas Gohr if(@file_exists(DOKU_INC.$dir.'script.js')){ 26*3600bd52SAndreas Gohr print ' <script type="text/javascript" language="javascript" charset="utf-8" src="'.DOKU_BASE.$dir.'print.css"></script>'."\n"; 27*3600bd52SAndreas Gohr } 284b15e09dSAndreas Gohr } 294b15e09dSAndreas Gohr} 304b15e09dSAndreas Gohr 314b15e09dSAndreas Gohr/** 32ee20e7d1Sandi * Returns a list of available plugins of given type 33ee20e7d1Sandi * 344b15e09dSAndreas Gohr * Returns all plugins if no type given 354b15e09dSAndreas Gohr * 36ee20e7d1Sandi * @author Andreas Gohr <andi@splitbrain.org> 37ee20e7d1Sandi */ 384b15e09dSAndreas Gohrfunction plugin_list($type=''){ 39ee20e7d1Sandi $plugins = array(); 40ee20e7d1Sandi if ($dh = opendir(DOKU_PLUGIN)) { 41ee20e7d1Sandi while (false !== ($file = readdir($dh))) { 42ee20e7d1Sandi if ($file == '.' || $file == '..') continue; 43ee20e7d1Sandi if (is_file(DOKU_PLUGIN.$file)) continue; 44ee20e7d1Sandi 454b15e09dSAndreas Gohr if ($type=='' || @file_exists(DOKU_PLUGIN.$file.'/'.$type.'.php')){ 46ee20e7d1Sandi $plugins[] = $file; 47ee20e7d1Sandi } 48ee20e7d1Sandi } 49ee20e7d1Sandi closedir($dh); 50ee20e7d1Sandi } 51ee20e7d1Sandi return $plugins; 52ee20e7d1Sandi} 53ee20e7d1Sandi 54ee20e7d1Sandi/** 55ee20e7d1Sandi * Loads the given plugin and creates an object of it 56ee20e7d1Sandi * 57ee20e7d1Sandi * @author Andreas Gohr <andi@splitbrain.org> 58ee20e7d1Sandi * 59ee20e7d1Sandi * @param $type string type of plugin to load 60ee20e7d1Sandi * @param $name string name of the plugin to load 61a46d0d65SAndreas Gohr * @return object the plugin object or null on failure 62ee20e7d1Sandi */ 63a46d0d65SAndreas Gohrfunction &plugin_load($type,$name){ 64ee20e7d1Sandi //we keep all loaded plugins available in global scope for reuse 65ee20e7d1Sandi global $DOKU_PLUGINS; 66ee20e7d1Sandi 67ee20e7d1Sandi //plugin already loaded? 68ee20e7d1Sandi if($DOKU_PLUGINS[$type][$name] != null){ 69a46d0d65SAndreas Gohr return $DOKU_PLUGINS[$type][$name]; 70ee20e7d1Sandi } 71ee20e7d1Sandi 72ee20e7d1Sandi //try to load the wanted plugin file 73107b01d6Sandi if(!include_once(DOKU_PLUGIN.$name.'/'.$type.'.php')){ 74a46d0d65SAndreas Gohr return null; 75ee20e7d1Sandi } 76ee20e7d1Sandi 77ee20e7d1Sandi //construct class and instanciate 78ee20e7d1Sandi $class = $type.'_plugin_'.$name; 79ee20e7d1Sandi $DOKU_PLUGINS[$type][$name] = new $class; 80a46d0d65SAndreas Gohr return $DOKU_PLUGINS[$type][$name]; 81ee20e7d1Sandi} 82ee20e7d1Sandi 83ee20e7d1Sandi 84