xref: /dokuwiki/inc/pluginutils.php (revision b838050e5828b5cbf32b9e82ce11c9cc54592809)
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/');
1110e43949SChris Smith
1210e43949SChris Smith/**
1310e43949SChris Smith * Original plugin functions, remain for backwards compatibility
1410e43949SChris Smith */
15db959ae3SAndreas Gohrfunction plugin_list($type='',$all=false) {
16db959ae3SAndreas Gohr    global $plugin_controller;
17db959ae3SAndreas Gohr    return $plugin_controller->getList($type,$all);
18db959ae3SAndreas Gohr}
19*b838050eSPiyush Mishrafunction plugin_load($type,$name,$new=false,$disabled=false) {
20db959ae3SAndreas Gohr    global $plugin_controller;
21db6f7eaeSAndreas Gohr    return $plugin_controller->load($type,$name,$new,$disabled);
22db959ae3SAndreas Gohr}
23db959ae3SAndreas Gohrfunction plugin_isdisabled($plugin) {
24db959ae3SAndreas Gohr    global $plugin_controller;
25db959ae3SAndreas Gohr    return $plugin_controller->isdisabled($plugin);
26db959ae3SAndreas Gohr}
27db959ae3SAndreas Gohrfunction plugin_enable($plugin) {
28db959ae3SAndreas Gohr    global $plugin_controller;
29db959ae3SAndreas Gohr    return $plugin_controller->enable($plugin);
30db959ae3SAndreas Gohr}
31db959ae3SAndreas Gohrfunction plugin_disable($plugin) {
32db959ae3SAndreas Gohr    global $plugin_controller;
33db959ae3SAndreas Gohr    return $plugin_controller->disable($plugin);
34db959ae3SAndreas Gohr}
35db959ae3SAndreas Gohrfunction plugin_directory($plugin) {
36db959ae3SAndreas Gohr    global $plugin_controller;
37db959ae3SAndreas Gohr    return $plugin_controller->get_directory($plugin);
38db959ae3SAndreas Gohr}
39*b838050eSPiyush Mishrafunction plugin_getcascade() {
40*b838050eSPiyush Mishra    global $plugin_controller;
41*b838050eSPiyush Mishra    return $plugin_controller->getCascade();
42*b838050eSPiyush Mishra}
43*b838050eSPiyush Mishra/**
44*b838050eSPiyush Mishra * return a list (name & type) of all the component plugins that make up this plugin
45*b838050eSPiyush Mishra *
46*b838050eSPiyush Mishra */
47*b838050eSPiyush Mishrafunction get_plugin_components($plugin) {
48*b838050eSPiyush Mishra    global $plugin_types;
49*b838050eSPiyush Mishra    static $plugins;
50*b838050eSPiyush Mishra    if(empty($plugins[$plugin])) {
51*b838050eSPiyush Mishra        $components = array();
52*b838050eSPiyush Mishra        $path = DOKU_PLUGIN.plugin_directory($plugin).'/';
53*b838050eSPiyush Mishra
54*b838050eSPiyush Mishra        foreach ($plugin_types as $type) {
55*b838050eSPiyush Mishra            if (@file_exists($path.$type.'.php')) { $components[] = array('name'=>$plugin, 'type'=>$type); continue; }
56*b838050eSPiyush Mishra
57*b838050eSPiyush Mishra            if ($dh = @opendir($path.$type.'/')) {
58*b838050eSPiyush Mishra                while (false !== ($cp = readdir($dh))) {
59*b838050eSPiyush Mishra                    if ($cp == '.' || $cp == '..' || strtolower(substr($cp,-4)) != '.php') continue;
60*b838050eSPiyush Mishra
61*b838050eSPiyush Mishra                    $components[] = array('name'=>$plugin.'_'.substr($cp, 0, -4), 'type'=>$type);
62*b838050eSPiyush Mishra                }
63*b838050eSPiyush Mishra                closedir($dh);
64*b838050eSPiyush Mishra            }
65*b838050eSPiyush Mishra        }
66*b838050eSPiyush Mishra        $plugins[$plugin] = $components;
67*b838050eSPiyush Mishra    }
68*b838050eSPiyush Mishra    return $plugins[$plugin];
69*b838050eSPiyush Mishra}
70