Hotfix Release 2017-02-19c "Frusterick Manners"
[dokuwiki.git] / inc / pluginutils.php
blob60f79869fa3a62633e15a7c58d070f81d3868963
1 <?php
2 /**
3 * Utilities for handling plugins
5 * @license GPL 2 (http://www.gnu.org/licenses/gpl.html)
6 * @author Andreas Gohr <andi@splitbrain.org>
7 */
9 // plugin related constants
10 if(!defined('DOKU_PLUGIN')) define('DOKU_PLUGIN',DOKU_INC.'lib/plugins/');
11 // note that only [a-z0-9]+ is officially supported, this is only to support plugins that don't follow these conventions, too
12 if(!defined('DOKU_PLUGIN_NAME_REGEX')) define('DOKU_PLUGIN_NAME_REGEX', '[a-zA-Z0-9\x7f-\xff]+');
14 /**
15 * Original plugin functions, remain for backwards compatibility
18 /**
19 * Return list of available plugins
21 * @param string $type type of plugins; empty string for all
22 * @param bool $all; true to retrieve all, false to retrieve only enabled plugins
23 * @return array with plugin names or plugin component names
25 function plugin_list($type='',$all=false) {
26 /** @var $plugin_controller Doku_Plugin_Controller */
27 global $plugin_controller;
28 return $plugin_controller->getList($type,$all);
31 /**
32 * Returns plugin object
33 * Returns only new instances of a plugin when $new is true or if plugin is not Singleton,
34 * otherwise an already loaded instance.
36 * @param $type string type of plugin to load
37 * @param $name string name of the plugin to load
38 * @param $new bool true to return a new instance of the plugin, false to use an already loaded instance
39 * @param $disabled bool true to load even disabled plugins
40 * @return DokuWiki_Plugin|null the plugin object or null on failure
42 function plugin_load($type,$name,$new=false,$disabled=false) {
43 /** @var $plugin_controller Doku_Plugin_Controller */
44 global $plugin_controller;
45 return $plugin_controller->load($type,$name,$new,$disabled);
48 /**
49 * Whether plugin is disabled
51 * @param string $plugin name of plugin
52 * @return bool true disabled, false enabled
54 function plugin_isdisabled($plugin) {
55 /** @var $plugin_controller Doku_Plugin_Controller */
56 global $plugin_controller;
57 return $plugin_controller->isdisabled($plugin);
60 /**
61 * Enable the plugin
63 * @param string $plugin name of plugin
64 * @return bool true saving succeed, false saving failed
66 function plugin_enable($plugin) {
67 /** @var $plugin_controller Doku_Plugin_Controller */
68 global $plugin_controller;
69 return $plugin_controller->enable($plugin);
72 /**
73 * Disable the plugin
75 * @param string $plugin name of plugin
76 * @return bool true saving succeed, false saving failed
78 function plugin_disable($plugin) {
79 /** @var $plugin_controller Doku_Plugin_Controller */
80 global $plugin_controller;
81 return $plugin_controller->disable($plugin);
84 /**
85 * Returns directory name of plugin
87 * @param string $plugin name of plugin
88 * @return string name of directory
90 function plugin_directory($plugin) {
91 /** @var $plugin_controller Doku_Plugin_Controller */
92 global $plugin_controller;
93 return $plugin_controller->get_directory($plugin);
96 /**
97 * Returns cascade of the config files
99 * @return array with arrays of plugin configs
101 function plugin_getcascade() {
102 /** @var $plugin_controller Doku_Plugin_Controller */
103 global $plugin_controller;
104 return $plugin_controller->getCascade();
109 * Return the currently operating admin plugin or null
110 * if not on an admin plugin page
112 * @return Doku_Plugin_Admin
114 function plugin_getRequestAdminPlugin(){
115 static $admin_plugin = false;
116 global $ACT,$INPUT,$INFO;
118 if ($admin_plugin === false) {
119 if (($ACT == 'admin') && ($page = $INPUT->str('page', '', true)) != '') {
120 $pluginlist = plugin_list('admin');
121 if (in_array($page, $pluginlist)) {
122 // attempt to load the plugin
123 /** @var $admin_plugin DokuWiki_Admin_Plugin */
124 $admin_plugin = plugin_load('admin', $page);
125 // verify
126 if ($admin_plugin && $admin_plugin->forAdminOnly() && !$INFO['isadmin']) {
127 $admin_plugin = null;
128 $INPUT->remove('page');
129 msg('For admins only',-1);
135 return $admin_plugin;