1<?php
2/**
3 * DokuWiki Plugin farmer (Action Component)
4 *
5 * @license GPL 2 http://www.gnu.org/licenses/gpl-2.0.html
6 * @author  Michael Große <grosse@cosmocode.de>
7 * @author  Andreas Gohr <gohr@cosmocode.de>
8 */
9
10if(!defined('DOKU_INC')) die();
11
12/**
13 * Disable Plugins on install
14 */
15class action_plugin_farmer_disable extends DokuWiki_Action_Plugin {
16
17    /**
18     * plugin should use this method to register its handlers with the DokuWiki's event controller
19     *
20     * @param Doku_Event_Handler $controller DokuWiki's event controller object. Also available as global $EVENT_HANDLER
21     *
22     */
23    public function register(Doku_Event_Handler $controller) {
24        /** @var helper_plugin_farmer $farmer */
25        $farmer = plugin_load('helper', 'farmer');
26        if($farmer->getAnimal()) return;
27
28        if($this->getConf('disable_new_plugins')) {
29            $controller->register_hook('PLUGIN_EXTENSION_CHANGE', 'AFTER', $this, 'handle_install');
30        }
31    }
32
33    /**
34     * handle install of new plugin
35     *
36     * @param Doku_Event $event
37     * @param $param
38     */
39    public function handle_install(Doku_Event $event, $param) {
40        if($event->data['action'] != 'install') return;
41
42        /* @var Doku_Plugin_Controller $plugin_controller */
43        global $plugin_controller;
44        $plugin_controller = new Doku_Plugin_Controller(); // we need to refresh the status
45
46        /** @var helper_plugin_extension_extension $ext */
47        $ext = $event->data['extension'];
48        $disabled = $ext->disable();
49        if($disabled === true) {
50            msg($this->getLang('disable_new_plugins'));
51        } else {
52            msg(hsc($disabled), -1);
53        }
54    }
55}
56
57