xref: /dokuwiki/lib/plugins/extension/action.php (revision da5f0eee25838368de375eb14d345b70ae3cbc7a)
172dda0b4SAndreas Gohr<?php
272dda0b4SAndreas Gohr/** DokuWiki Plugin extension (Action Component)
372dda0b4SAndreas Gohr *
472dda0b4SAndreas Gohr * @license GPL 2 http://www.gnu.org/licenses/gpl-2.0.html
572dda0b4SAndreas Gohr * @author  Andreas Gohr <andi@splitbrain.org>
672dda0b4SAndreas Gohr */
772dda0b4SAndreas Gohr
872dda0b4SAndreas Gohr// must be run within Dokuwiki
972dda0b4SAndreas Gohrif(!defined('DOKU_INC')) die();
1072dda0b4SAndreas Gohr
1172dda0b4SAndreas Gohrclass action_plugin_extension extends DokuWiki_Action_Plugin {
1272dda0b4SAndreas Gohr
1372dda0b4SAndreas Gohr    /**
1472dda0b4SAndreas Gohr     * Registers a callback function for a given event
1572dda0b4SAndreas Gohr     *
1672dda0b4SAndreas Gohr     * @param Doku_Event_Handler $controller DokuWiki's event controller object
1772dda0b4SAndreas Gohr     * @return void
1872dda0b4SAndreas Gohr     */
194c005e3fSAndreas Gohr    public function register(Doku_Event_Handler $controller) {
2072dda0b4SAndreas Gohr
2172dda0b4SAndreas Gohr        $controller->register_hook('AJAX_CALL_UNKNOWN', 'BEFORE', $this, 'info');
2272dda0b4SAndreas Gohr
2372dda0b4SAndreas Gohr    }
2472dda0b4SAndreas Gohr
254c005e3fSAndreas Gohr    /**
264c005e3fSAndreas Gohr     * Create the detail info for a single plugin
274c005e3fSAndreas Gohr     *
284c005e3fSAndreas Gohr     * @param Doku_Event $event
294c005e3fSAndreas Gohr     * @param            $param
304c005e3fSAndreas Gohr     */
3172dda0b4SAndreas Gohr    public function info(Doku_Event &$event, $param){
32*da5f0eeeSAndreas Gohr        global $USERINFO;
3372dda0b4SAndreas Gohr        global $INPUT;
34*da5f0eeeSAndreas Gohr
35*da5f0eeeSAndreas Gohr        if(empty($_SERVER['REMOTE_USER']) || !auth_isadmin($_SERVER['REMOTE_USER'], $USERINFO['grps'])){
36*da5f0eeeSAndreas Gohr            http_status(403);
37*da5f0eeeSAndreas Gohr            echo 'Forbidden';
38*da5f0eeeSAndreas Gohr            exit;
39*da5f0eeeSAndreas Gohr        }
40*da5f0eeeSAndreas Gohr
4172dda0b4SAndreas Gohr        if($event->data != 'plugin_extension') return;
4272dda0b4SAndreas Gohr        $event->preventDefault();
4372dda0b4SAndreas Gohr        $event->stopPropagation();
4472dda0b4SAndreas Gohr
4572dda0b4SAndreas Gohr        header('Content-Type: text/html; charset=utf-8');
4672dda0b4SAndreas Gohr
4772dda0b4SAndreas Gohr        $ext = $INPUT->str('ext');
4872dda0b4SAndreas Gohr        if(!$ext) {
4972dda0b4SAndreas Gohr            echo 'no extension given';
5072dda0b4SAndreas Gohr            return;
5172dda0b4SAndreas Gohr        }
5272dda0b4SAndreas Gohr
5372dda0b4SAndreas Gohr        /** @var helper_plugin_extension_extension $extension */
5472dda0b4SAndreas Gohr        $extension = plugin_load('helper', 'extension_extension');
5572dda0b4SAndreas Gohr        $extension->setExtension($ext);
5672dda0b4SAndreas Gohr
5772dda0b4SAndreas Gohr        /** @var helper_plugin_extension_list $list */
5872dda0b4SAndreas Gohr        $list = plugin_load('helper', 'extension_list');
5972dda0b4SAndreas Gohr
6072dda0b4SAndreas Gohr
6172dda0b4SAndreas Gohr        echo $list->make_info($extension);
6272dda0b4SAndreas Gohr    }
6372dda0b4SAndreas Gohr
6472dda0b4SAndreas Gohr}
6572dda0b4SAndreas Gohr
66