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 9087b3a7fSchris// plugin related constants 1003c4aec3Schrisif(!defined('DOKU_PLUGIN')) define('DOKU_PLUGIN',DOKU_INC.'lib/plugins/'); 117521090bSMichael Hamann// note that only [a-z0-9]+ is officially supported, this is only to support plugins that don't follow these conventions, too 127521090bSMichael Hamannif(!defined('DOKU_PLUGIN_NAME_REGEX')) define('DOKU_PLUGIN_NAME_REGEX', '[a-zA-Z0-9\x7f-\xff]+'); 1310e43949SChris Smith 1410e43949SChris Smith/** 1510e43949SChris Smith * Original plugin functions, remain for backwards compatibility 1610e43949SChris Smith */ 17143ff0f8SGerrit Uitslag 18143ff0f8SGerrit Uitslag/** 19143ff0f8SGerrit Uitslag * Return list of available plugins 20143ff0f8SGerrit Uitslag * 21143ff0f8SGerrit Uitslag * @param string $type type of plugins; empty string for all 22143ff0f8SGerrit Uitslag * @param bool $all; true to retrieve all, false to retrieve only enabled plugins 23143ff0f8SGerrit Uitslag * @return array with plugin names or plugin component names 24143ff0f8SGerrit Uitslag */ 25db959ae3SAndreas Gohrfunction plugin_list($type='',$all=false) { 26143ff0f8SGerrit Uitslag /** @var $plugin_controller Doku_Plugin_Controller */ 27db959ae3SAndreas Gohr global $plugin_controller; 28db959ae3SAndreas Gohr return $plugin_controller->getList($type,$all); 29db959ae3SAndreas Gohr} 30143ff0f8SGerrit Uitslag 31143ff0f8SGerrit Uitslag/** 32143ff0f8SGerrit Uitslag * Returns plugin object 33143ff0f8SGerrit Uitslag * Returns only new instances of a plugin when $new is true or if plugin is not Singleton, 34143ff0f8SGerrit Uitslag * otherwise an already loaded instance. 35143ff0f8SGerrit Uitslag * 36143ff0f8SGerrit Uitslag * @param $type string type of plugin to load 37143ff0f8SGerrit Uitslag * @param $name string name of the plugin to load 38143ff0f8SGerrit Uitslag * @param $new bool true to return a new instance of the plugin, false to use an already loaded instance 39143ff0f8SGerrit Uitslag * @param $disabled bool true to load even disabled plugins 40*39bceb98SAndreas Gohr * @return DokuWiki_PluginInterface|null the plugin object or null on failure 41143ff0f8SGerrit Uitslag */ 42b838050eSPiyush Mishrafunction plugin_load($type,$name,$new=false,$disabled=false) { 43143ff0f8SGerrit Uitslag /** @var $plugin_controller Doku_Plugin_Controller */ 44db959ae3SAndreas Gohr global $plugin_controller; 45db6f7eaeSAndreas Gohr return $plugin_controller->load($type,$name,$new,$disabled); 46db959ae3SAndreas Gohr} 47143ff0f8SGerrit Uitslag 48143ff0f8SGerrit Uitslag/** 49143ff0f8SGerrit Uitslag * Whether plugin is disabled 50143ff0f8SGerrit Uitslag * 51143ff0f8SGerrit Uitslag * @param string $plugin name of plugin 52e3710957SGerrit Uitslag * @return bool true disabled, false enabled 53143ff0f8SGerrit Uitslag */ 54db959ae3SAndreas Gohrfunction plugin_isdisabled($plugin) { 55143ff0f8SGerrit Uitslag /** @var $plugin_controller Doku_Plugin_Controller */ 56db959ae3SAndreas Gohr global $plugin_controller; 57db959ae3SAndreas Gohr return $plugin_controller->isdisabled($plugin); 58db959ae3SAndreas Gohr} 59143ff0f8SGerrit Uitslag 60143ff0f8SGerrit Uitslag/** 61143ff0f8SGerrit Uitslag * Enable the plugin 62143ff0f8SGerrit Uitslag * 63143ff0f8SGerrit Uitslag * @param string $plugin name of plugin 64e3710957SGerrit Uitslag * @return bool true saving succeed, false saving failed 65143ff0f8SGerrit Uitslag */ 66db959ae3SAndreas Gohrfunction plugin_enable($plugin) { 67143ff0f8SGerrit Uitslag /** @var $plugin_controller Doku_Plugin_Controller */ 68db959ae3SAndreas Gohr global $plugin_controller; 69db959ae3SAndreas Gohr return $plugin_controller->enable($plugin); 70db959ae3SAndreas Gohr} 71143ff0f8SGerrit Uitslag 72143ff0f8SGerrit Uitslag/** 73143ff0f8SGerrit Uitslag * Disable the plugin 74143ff0f8SGerrit Uitslag * 75143ff0f8SGerrit Uitslag * @param string $plugin name of plugin 76e3710957SGerrit Uitslag * @return bool true saving succeed, false saving failed 77143ff0f8SGerrit Uitslag */ 78db959ae3SAndreas Gohrfunction plugin_disable($plugin) { 79143ff0f8SGerrit Uitslag /** @var $plugin_controller Doku_Plugin_Controller */ 80db959ae3SAndreas Gohr global $plugin_controller; 81db959ae3SAndreas Gohr return $plugin_controller->disable($plugin); 82db959ae3SAndreas Gohr} 83143ff0f8SGerrit Uitslag 84143ff0f8SGerrit Uitslag/** 85143ff0f8SGerrit Uitslag * Returns directory name of plugin 86143ff0f8SGerrit Uitslag * 87143ff0f8SGerrit Uitslag * @param string $plugin name of plugin 88143ff0f8SGerrit Uitslag * @return string name of directory 89143ff0f8SGerrit Uitslag */ 90db959ae3SAndreas Gohrfunction plugin_directory($plugin) { 91143ff0f8SGerrit Uitslag /** @var $plugin_controller Doku_Plugin_Controller */ 92db959ae3SAndreas Gohr global $plugin_controller; 93db959ae3SAndreas Gohr return $plugin_controller->get_directory($plugin); 94db959ae3SAndreas Gohr} 95143ff0f8SGerrit Uitslag 96143ff0f8SGerrit Uitslag/** 97143ff0f8SGerrit Uitslag * Returns cascade of the config files 98143ff0f8SGerrit Uitslag * 99143ff0f8SGerrit Uitslag * @return array with arrays of plugin configs 100143ff0f8SGerrit Uitslag */ 101b838050eSPiyush Mishrafunction plugin_getcascade() { 102143ff0f8SGerrit Uitslag /** @var $plugin_controller Doku_Plugin_Controller */ 103b838050eSPiyush Mishra global $plugin_controller; 104b838050eSPiyush Mishra return $plugin_controller->getCascade(); 105b838050eSPiyush Mishra} 106a61966c5SChristopher Smith 107a61966c5SChristopher Smith 108a61966c5SChristopher Smith/** 109a61966c5SChristopher Smith * Return the currently operating admin plugin or null 110a61966c5SChristopher Smith * if not on an admin plugin page 111a61966c5SChristopher Smith * 112a61966c5SChristopher Smith * @return Doku_Plugin_Admin 113a61966c5SChristopher Smith */ 114a61966c5SChristopher Smithfunction plugin_getRequestAdminPlugin(){ 115a61966c5SChristopher Smith static $admin_plugin = false; 116a61966c5SChristopher Smith global $ACT,$INPUT,$INFO; 117a61966c5SChristopher Smith 118a61966c5SChristopher Smith if ($admin_plugin === false) { 119a61966c5SChristopher Smith if (($ACT == 'admin') && ($page = $INPUT->str('page', '', true)) != '') { 120a61966c5SChristopher Smith $pluginlist = plugin_list('admin'); 121a61966c5SChristopher Smith if (in_array($page, $pluginlist)) { 122a61966c5SChristopher Smith // attempt to load the plugin 123a61966c5SChristopher Smith /** @var $admin_plugin DokuWiki_Admin_Plugin */ 124a61966c5SChristopher Smith $admin_plugin = plugin_load('admin', $page); 125a61966c5SChristopher Smith // verify 126a61966c5SChristopher Smith if ($admin_plugin && $admin_plugin->forAdminOnly() && !$INFO['isadmin']) { 127a61966c5SChristopher Smith $admin_plugin = null; 128a61966c5SChristopher Smith $INPUT->remove('page'); 129a61966c5SChristopher Smith msg('For admins only',-1); 130a61966c5SChristopher Smith } 131a61966c5SChristopher Smith } 132a61966c5SChristopher Smith } 133a61966c5SChristopher Smith } 134a61966c5SChristopher Smith 135a61966c5SChristopher Smith return $admin_plugin; 136a61966c5SChristopher Smith} 137