3 * Utilities for handling plugins
5 * @license GPL 2 (http://www.gnu.org/licenses/gpl.html)
6 * @author Andreas Gohr <andi@splitbrain.org>
9 // plugin related constants
10 use dokuwiki\Extension\AdminPlugin
;
11 use dokuwiki\Extension\PluginController
;
12 use dokuwiki\Extension\PluginInterface
;
14 if(!defined('DOKU_PLUGIN')) define('DOKU_PLUGIN',DOKU_INC
.'lib/plugins/');
15 // note that only [a-z0-9]+ is officially supported,
16 // this is only to support plugins that don't follow these conventions, too
17 if(!defined('DOKU_PLUGIN_NAME_REGEX')) define('DOKU_PLUGIN_NAME_REGEX', '[a-zA-Z0-9\x7f-\xff]+');
20 * Original plugin functions, remain for backwards compatibility
24 * Return list of available plugins
26 * @param string $type type of plugins; empty string for all
27 * @param bool $all; true to retrieve all, false to retrieve only enabled plugins
28 * @return array with plugin names or plugin component names
30 function plugin_list($type='',$all=false)
32 /** @var $plugin_controller PluginController */
33 global $plugin_controller;
34 $plugins = $plugin_controller->getList($type,$all);
35 sort($plugins, SORT_NATURAL|SORT_FLAG_CASE
);
40 * Returns plugin object
41 * Returns only new instances of a plugin when $new is true or if plugin is not Singleton,
42 * otherwise an already loaded instance.
44 * @param $type string type of plugin to load
45 * @param $name string name of the plugin to load
46 * @param $new bool true to return a new instance of the plugin, false to use an already loaded instance
47 * @param $disabled bool true to load even disabled plugins
48 * @return PluginInterface|null the plugin object or null on failure
50 function plugin_load($type,$name,$new=false,$disabled=false)
52 /** @var $plugin_controller PluginController */
53 global $plugin_controller;
54 return $plugin_controller->load($type,$name,$new,$disabled);
58 * Whether plugin is disabled
60 * @param string $plugin name of plugin
61 * @return bool true disabled, false enabled
63 function plugin_isdisabled($plugin)
65 /** @var $plugin_controller PluginController */
66 global $plugin_controller;
67 return !$plugin_controller->isEnabled($plugin);
73 * @param string $plugin name of plugin
74 * @return bool true saving succeed, false saving failed
76 function plugin_enable($plugin)
78 /** @var $plugin_controller PluginController */
79 global $plugin_controller;
80 return $plugin_controller->enable($plugin);
86 * @param string $plugin name of plugin
87 * @return bool true saving succeed, false saving failed
89 function plugin_disable($plugin)
91 /** @var $plugin_controller PluginController */
92 global $plugin_controller;
93 return $plugin_controller->disable($plugin);
97 * Returns directory name of plugin
99 * @param string $plugin name of plugin
100 * @return string name of directory
101 * @deprecated 2018-07-20
103 function plugin_directory($plugin)
105 dbg_deprecated('$plugin directly');
110 * Returns cascade of the config files
112 * @return array with arrays of plugin configs
114 function plugin_getcascade()
116 /** @var $plugin_controller PluginController */
117 global $plugin_controller;
118 return $plugin_controller->getCascade();
123 * Return the currently operating admin plugin or null
124 * if not on an admin plugin page
126 * @return Doku_Plugin_Admin
128 function plugin_getRequestAdminPlugin()
130 static $admin_plugin = false;
131 global $ACT,$INPUT,$INFO;
133 if ($admin_plugin === false) {
134 if (($ACT == 'admin') && ($page = $INPUT->str('page', '', true)) != '') {
135 $pluginlist = plugin_list('admin');
136 if (in_array($page, $pluginlist)) {
137 // attempt to load the plugin
138 /** @var $admin_plugin AdminPlugin */
139 $admin_plugin = plugin_load('admin', $page);
141 if ($admin_plugin && !$admin_plugin->isAccessibleByCurrentUser()) {
142 $admin_plugin = null;
143 $INPUT->remove('page');
144 msg('For admins only',-1);
150 return $admin_plugin;