Failed Conditions
Pull Request — psr2 (#2426)
by Andreas
09:22 queued 06:07
created

action_plugin_acl::register()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 5

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
nc 1
nop 1
dl 0
loc 5
rs 10
c 0
b 0
f 0
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 <[email protected]>
7
 */
8
9
/**
10
 * Register handler
11
 */
12
class action_plugin_acl extends DokuWiki_Action_Plugin
13
{
14
15
    /**
16
     * Registers a callback function for a given event
17
     *
18
     * @param Doku_Event_Handler $controller DokuWiki's event controller object
19
     * @return void
20
     */
21
    public function register(Doku_Event_Handler $controller)
22
    {
23
24
        $controller->register_hook('AJAX_CALL_UNKNOWN', 'BEFORE', $this, 'handleAjaxCallAcl');
25
    }
26
27
    /**
28
     * AJAX call handler for ACL plugin
29
     *
30
     * @param Doku_Event $event  event object by reference
31
     * @param mixed $param  empty
32
     * @return void
33
     */
34
35
    public function handleAjaxCallAcl(Doku_Event $event, $param)
36
    {
37
        if ($event->data !== 'plugin_acl') {
38
            return;
39
        }
40
        $event->stopPropagation();
41
        $event->preventDefault();
42
43
        global $ID;
44
        global $INPUT;
45
46
        if (!auth_isadmin()) {
47
            echo 'for admins only';
48
            return;
49
        }
50
        if (!checkSecurityToken()) {
51
            echo 'CRSF Attack';
52
            return;
53
        }
54
55
        $ID = getID();
56
57
        /** @var $acl admin_plugin_acl */
58
        $acl = plugin_load('admin', 'acl');
0 ignored issues
show
Deprecated Code introduced by
The function plugin_load() has been deprecated with message: 2018-07-20 we will probably keep this around for a long time though

This function has been deprecated. The supplier of the file has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the function will be removed from the class and what other function to use instead.

Loading history...
59
        $acl->handle();
60
61
        $ajax = $INPUT->str('ajax');
62
        header('Content-Type: text/html; charset=utf-8');
63
64
        if ($ajax == 'info') {
65
            $acl->printInfo();
66
        } elseif ($ajax == 'tree') {
67
            $ns = $INPUT->str('ns');
68
            if ($ns == '*') {
69
                $ns = '';
70
            }
71
            $ns = cleanID($ns);
72
            $lvl = count(explode(':', $ns));
73
            $ns = utf8_encodeFN(str_replace(':', '/', $ns));
74
75
            $data = $acl->makeTree($ns, $ns);
76
77
            foreach (array_keys($data) as $item) {
78
                $data[$item]['level'] = $lvl + 1;
79
            }
80
            echo html_buildlist(
81
                $data,
82
                'acl',
83
                array($acl, 'makeTreeItem'),
84
                array($acl, 'makeListItem')
85
            );
86
        }
87
    }
88
}
89