xref: /dokuwiki/inc/pluginutils.php (revision 143ff0f836341ddd83dbb087ea227ca90eb1aea3)
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 */
17*143ff0f8SGerrit Uitslag
18*143ff0f8SGerrit Uitslag/**
19*143ff0f8SGerrit Uitslag * Return list of available plugins
20*143ff0f8SGerrit Uitslag *
21*143ff0f8SGerrit Uitslag * @param string $type type of plugins; empty string for all
22*143ff0f8SGerrit Uitslag * @param bool $all; true to retrieve all, false to retrieve only enabled plugins
23*143ff0f8SGerrit Uitslag * @return array with plugin names or plugin component names
24*143ff0f8SGerrit Uitslag */
25db959ae3SAndreas Gohrfunction plugin_list($type='',$all=false) {
26*143ff0f8SGerrit Uitslag    /** @var $plugin_controller Doku_Plugin_Controller */
27db959ae3SAndreas Gohr    global $plugin_controller;
28db959ae3SAndreas Gohr    return $plugin_controller->getList($type,$all);
29db959ae3SAndreas Gohr}
30*143ff0f8SGerrit Uitslag
31*143ff0f8SGerrit Uitslag/**
32*143ff0f8SGerrit Uitslag * Returns plugin object
33*143ff0f8SGerrit Uitslag * Returns only new instances of a plugin when $new is true or if plugin is not Singleton,
34*143ff0f8SGerrit Uitslag * otherwise an already loaded instance.
35*143ff0f8SGerrit Uitslag *
36*143ff0f8SGerrit Uitslag * @param  $type     string type of plugin to load
37*143ff0f8SGerrit Uitslag * @param  $name     string name of the plugin to load
38*143ff0f8SGerrit Uitslag * @param  $new      bool   true to return a new instance of the plugin, false to use an already loaded instance
39*143ff0f8SGerrit Uitslag * @param  $disabled bool   true to load even disabled plugins
40*143ff0f8SGerrit Uitslag * @return DokuWiki_Plugin|DokuWiki_Syntax_Plugin  the plugin object or null on failure
41*143ff0f8SGerrit Uitslag */
42b838050eSPiyush Mishrafunction plugin_load($type,$name,$new=false,$disabled=false) {
43*143ff0f8SGerrit Uitslag    /** @var $plugin_controller Doku_Plugin_Controller */
44db959ae3SAndreas Gohr    global $plugin_controller;
45db6f7eaeSAndreas Gohr    return $plugin_controller->load($type,$name,$new,$disabled);
46db959ae3SAndreas Gohr}
47*143ff0f8SGerrit Uitslag
48*143ff0f8SGerrit Uitslag/**
49*143ff0f8SGerrit Uitslag * Whether plugin is disabled
50*143ff0f8SGerrit Uitslag *
51*143ff0f8SGerrit Uitslag * @param string $plugin name of plugin
52*143ff0f8SGerrit Uitslag * @return bool; true disabled, false enabled
53*143ff0f8SGerrit Uitslag */
54db959ae3SAndreas Gohrfunction plugin_isdisabled($plugin) {
55*143ff0f8SGerrit Uitslag    /** @var $plugin_controller Doku_Plugin_Controller */
56db959ae3SAndreas Gohr    global $plugin_controller;
57db959ae3SAndreas Gohr    return $plugin_controller->isdisabled($plugin);
58db959ae3SAndreas Gohr}
59*143ff0f8SGerrit Uitslag
60*143ff0f8SGerrit Uitslag/**
61*143ff0f8SGerrit Uitslag * Enable the plugin
62*143ff0f8SGerrit Uitslag *
63*143ff0f8SGerrit Uitslag * @param string $plugin name of plugin
64*143ff0f8SGerrit Uitslag * @return bool; true saving succeed, false saving failed
65*143ff0f8SGerrit Uitslag */
66db959ae3SAndreas Gohrfunction plugin_enable($plugin) {
67*143ff0f8SGerrit Uitslag    /** @var $plugin_controller Doku_Plugin_Controller */
68db959ae3SAndreas Gohr    global $plugin_controller;
69db959ae3SAndreas Gohr    return $plugin_controller->enable($plugin);
70db959ae3SAndreas Gohr}
71*143ff0f8SGerrit Uitslag
72*143ff0f8SGerrit Uitslag/**
73*143ff0f8SGerrit Uitslag * Disable the plugin
74*143ff0f8SGerrit Uitslag *
75*143ff0f8SGerrit Uitslag * @param string $plugin name of plugin
76*143ff0f8SGerrit Uitslag * @return bool; true saving succeed, false saving failed
77*143ff0f8SGerrit Uitslag */
78db959ae3SAndreas Gohrfunction plugin_disable($plugin) {
79*143ff0f8SGerrit Uitslag    /** @var $plugin_controller Doku_Plugin_Controller */
80db959ae3SAndreas Gohr    global $plugin_controller;
81db959ae3SAndreas Gohr    return $plugin_controller->disable($plugin);
82db959ae3SAndreas Gohr}
83*143ff0f8SGerrit Uitslag
84*143ff0f8SGerrit Uitslag/**
85*143ff0f8SGerrit Uitslag * Returns directory name of plugin
86*143ff0f8SGerrit Uitslag *
87*143ff0f8SGerrit Uitslag * @param string $plugin name of plugin
88*143ff0f8SGerrit Uitslag * @return string name of directory
89*143ff0f8SGerrit Uitslag */
90db959ae3SAndreas Gohrfunction plugin_directory($plugin) {
91*143ff0f8SGerrit Uitslag    /** @var $plugin_controller Doku_Plugin_Controller */
92db959ae3SAndreas Gohr    global $plugin_controller;
93db959ae3SAndreas Gohr    return $plugin_controller->get_directory($plugin);
94db959ae3SAndreas Gohr}
95*143ff0f8SGerrit Uitslag
96*143ff0f8SGerrit Uitslag/**
97*143ff0f8SGerrit Uitslag * Returns cascade of the config files
98*143ff0f8SGerrit Uitslag *
99*143ff0f8SGerrit Uitslag * @return array with arrays of plugin configs
100*143ff0f8SGerrit Uitslag */
101b838050eSPiyush Mishrafunction plugin_getcascade() {
102*143ff0f8SGerrit Uitslag    /** @var $plugin_controller Doku_Plugin_Controller */
103b838050eSPiyush Mishra    global $plugin_controller;
104b838050eSPiyush Mishra    return $plugin_controller->getCascade();
105b838050eSPiyush Mishra}
106