xref: /dokuwiki/lib/plugins/acl/action.php (revision d4e2226677c742531e589ebd2b45fdd4553322ad)
1<?php
2/**
3 * AJAX call handler for ACL plugin
4 *
5 * @license    GPL 2 (http://www.gnu.org/licenses/gpl.html)
6 * @author     Andreas Gohr <andi@splitbrain.org>
7 */
8
9// must be run within Dokuwiki
10if(!defined('DOKU_INC')) die();
11
12/**
13 * Register handler
14 */
15class action_plugin_acl extends DokuWiki_Action_Plugin {
16
17    /**
18     * Registers a callback function for a given event
19     *
20     * @param Doku_Event_Handler $controller DokuWiki's event controller object
21     * @return void
22     */
23    public function register(Doku_Event_Handler &$controller) {
24
25        $controller->register_hook('AJAX_CALL_UNKNOWN', 'BEFORE', $this, 'handle_ajax_call_acl');
26
27    }
28
29    /**
30     * AJAX call handler for ACL plugin
31     *
32     * @param Doku_Event $event  event object by reference
33     * @param mixed      $param  empty
34     * @return void
35     */
36
37    public function handle_ajax_call_acl(Doku_Event &$event, $param) {
38        if ($event->data !== 'plugin_acl') {
39            return;
40        }
41        $event->stopPropagation();
42        $event->preventDefault();
43
44
45        //close session
46        session_write_close();
47
48        global $conf;
49        global $ID;
50        global $INPUT;
51
52        //fix for Opera XMLHttpRequests
53        $postData = http_get_raw_post_data();
54        if(!count($_POST) && !empty($postData)){
55            parse_str($postData, $_POST);
56        }
57
58        if(!auth_isadmin()) die('for admins only');
59        if(!checkSecurityToken()) die('CRSF Attack');
60
61        $ID    = getID();
62
63        /** @var $acl admin_plugin_acl */
64        $acl = plugin_load('admin','acl');
65        $acl->handle();
66
67        $ajax = $INPUT->str('ajax');
68        header('Content-Type: text/html; charset=utf-8');
69
70        if($ajax == 'info'){
71            $acl->_html_info();
72        }elseif($ajax == 'tree'){
73
74            $ns  = $INPUT->str('ns');
75            if($ns == '*'){
76                $ns ='';
77            }
78            $ns  = cleanID($ns);
79            $lvl = count(explode(':',$ns));
80            $ns  = utf8_encodeFN(str_replace(':','/',$ns));
81
82            $data = $acl->_get_tree($ns,$ns);
83
84            foreach(array_keys($data) as $item){
85                $data[$item]['level'] = $lvl+1;
86            }
87            echo html_buildlist($data, 'acl', array($acl, '_html_list_acl'),
88                                array($acl, '_html_li_acl'));
89        }
90    }
91}