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/** 103600bd52SAndreas Gohr * prints needed HTML to include plugin CSS and JS files 114b15e09dSAndreas Gohr */ 123600bd52SAndreas 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 } 253600bd52SAndreas Gohr if(@file_exists(DOKU_INC.$dir.'script.js')){ 26e2e0a40fSchris print ' <script type="text/javascript" language="javascript" charset="utf-8" src="'.DOKU_BASE.$dir.'script.js"></script>'."\n"; 273600bd52SAndreas 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)) { 41*7fb56887Schris while (false !== ($plugin = readdir($dh))) { 42*7fb56887Schris if ($plugin == '.' || $plugin == '..') continue; 43*7fb56887Schris if (is_file(DOKU_PLUGIN.$plugin)) continue; 44ee20e7d1Sandi 45*7fb56887Schris if ($type=='' || @file_exists(DOKU_PLUGIN."$plugin/$type.php")){ 46*7fb56887Schris $plugins[] = $plugin; 47*7fb56887Schris } else { 48*7fb56887Schris if ($dp = @opendir(DOKU_PLUGIN."$plugin/$type/")) { 49*7fb56887Schris while (false !== ($component = readdir($dp))) { 50*7fb56887Schris if ($component == '.' || $component == '..' || strtolower(substr($component, -4)) != ".php") continue; 51*7fb56887Schris if (is_file(DOKU_PLUGIN."$plugin/$type/$component")) { 52*7fb56887Schris $plugins[] = $plugin.'_'.substr($component, 0, -4); 53*7fb56887Schris } 54*7fb56887Schris } 55*7fb56887Schris } 56*7fb56887Schris closedir($dp); 57ee20e7d1Sandi } 58ee20e7d1Sandi } 59ee20e7d1Sandi closedir($dh); 60ee20e7d1Sandi } 61ee20e7d1Sandi return $plugins; 62ee20e7d1Sandi} 63ee20e7d1Sandi 64ee20e7d1Sandi/** 65ee20e7d1Sandi * Loads the given plugin and creates an object of it 66ee20e7d1Sandi * 67ee20e7d1Sandi * @author Andreas Gohr <andi@splitbrain.org> 68ee20e7d1Sandi * 69ee20e7d1Sandi * @param $type string type of plugin to load 70ee20e7d1Sandi * @param $name string name of the plugin to load 71a46d0d65SAndreas Gohr * @return object the plugin object or null on failure 72ee20e7d1Sandi */ 73a46d0d65SAndreas Gohrfunction &plugin_load($type,$name){ 74ee20e7d1Sandi //we keep all loaded plugins available in global scope for reuse 75ee20e7d1Sandi global $DOKU_PLUGINS; 76ee20e7d1Sandi 77ee20e7d1Sandi //plugin already loaded? 78ee20e7d1Sandi if($DOKU_PLUGINS[$type][$name] != null){ 79a46d0d65SAndreas Gohr return $DOKU_PLUGINS[$type][$name]; 80ee20e7d1Sandi } 81ee20e7d1Sandi 82ee20e7d1Sandi //try to load the wanted plugin file 83*7fb56887Schris if(!@include_once(DOKU_PLUGIN."$name/$type.php")){ 84*7fb56887Schris list($plugin, $component) = preg_split("/_/",$name, 2); 85*7fb56887Schris if (!$component || !@include_once(DOKU_PLUGIN."$plugin/$type/$component.php")) { 86a46d0d65SAndreas Gohr return null; 87ee20e7d1Sandi } 88*7fb56887Schris } 89*7fb56887Schris 90*7fb56887Schris global $plugin_investigate_pluginorder; 91*7fb56887Schris if (!isset($plugin_investigate_pluginorder)) $plugin_investigate_pluginorder = array(); 92*7fb56887Schris $plugin_investigate_pluginorder[] = $name; 93ee20e7d1Sandi 94ee20e7d1Sandi //construct class and instanciate 95ee20e7d1Sandi $class = $type.'_plugin_'.$name; 96ee20e7d1Sandi $DOKU_PLUGINS[$type][$name] = new $class; 97a46d0d65SAndreas Gohr return $DOKU_PLUGINS[$type][$name]; 98ee20e7d1Sandi} 99