xref: /dokuwiki/lib/plugins/acl/action.php (revision 219fe1dcb7250b332a77278fd31f20e5da10846c)
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        //close session
45        session_write_close();
46
47        global $ID;
48        global $INPUT;
49
50        //fix for Opera XMLHttpRequests
51        $postData = http_get_raw_post_data();
52        if(!count($_POST) && !empty($postData)) {
53            parse_str($postData, $_POST);
54        }
55
56        if(!auth_isadmin()) die('for admins only');
57        if(!checkSecurityToken()) die('CRSF Attack');
58
59        $ID = getID();
60
61        /** @var $acl admin_plugin_acl */
62        $acl = plugin_load('admin', 'acl');
63        $acl->handle();
64
65        $ajax = $INPUT->str('ajax');
66        header('Content-Type: text/html; charset=utf-8');
67
68        if($ajax == 'info') {
69            $acl->_html_info();
70        } elseif($ajax == 'tree') {
71
72            $ns = $INPUT->str('ns');
73            if($ns == '*') {
74                $ns = '';
75            }
76            $ns = cleanID($ns);
77            $lvl = count(explode(':', $ns));
78            $ns = utf8_encodeFN(str_replace(':', '/', $ns));
79
80            $data = $acl->_get_tree($ns, $ns);
81
82            foreach(array_keys($data) as $item) {
83                $data[$item]['level'] = $lvl + 1;
84            }
85            echo html_buildlist(
86                $data, 'acl', array($acl, '_html_list_acl'),
87                array($acl, '_html_li_acl')
88            );
89        }
90    }
91}