xref: /template/kiwiki/classes/kiwiki_functions.php (revision cc57aeb6f1eea287e74df6ae674ba08b7803eeef)
1<?php
2
3class Kiwiki_Functions {
4
5    public static function _edit_icon($what, $usergroup, $action){
6        $output = "";
7        if (isset($usergroup)){
8            if (in_array('admin',$usergroup) && $action == 'show'){
9                $output = '<a class="edit-this" href="doku.php?id=' . $what . '&do=edit">' . inlineSVG(KIWIKI_IMAGES_PATH . 'edit.svg') .'</a>';
10            }
11        }
12        return $output;
13    }
14
15
16    /**
17     * Go bottom button
18     */
19
20    public static function html_bottombtn() {
21        global $lang;
22
23        return '<a class="nolink" href="#dokuwiki__bottom">'
24            .'<button class="button" onclick="window.scrollTo(0, 0)" title="'. $lang['btn_bottom'] .'">'
25            . $lang['btn_bottom']
26            .'</button></a>';
27    }
28
29
30    public static function tpl_aclinfo() {
31        global $ID, $AUTH_ACL;
32
33        if (auth_quickaclcheck($ID) == 0)
34            return; // no rights to view, no rights to get this info
35
36        $page_acls = array();
37        $namespaces = array();
38
39        $ns = getNS($ID);
40        while ($ns) {
41           array_unshift($namespaces,$ns . ':*');
42           $ns = getNS($ns);
43        }
44        array_unshift($namespaces,'*'); // root
45
46        $namespaces[] = $ID;
47
48        // check matches
49        foreach ($namespaces as $level) {
50            $matches = preg_grep('/^'.preg_quote($level,'/').'\s+\S+\s+\d+\s*$/',$AUTH_ACL);
51            $this_acls = array();
52            foreach($matches as $match){
53              $match = preg_replace('/#.*$/','',$match); //ignore comments
54              $acl   = preg_split('/\s+/',$match);
55              $this_acls[urldecode($acl[1])] = $acl[2];
56              if ($acl[1] == "@ALL")  // overwrites stuff from upper level
57                $page_acls = array();
58            }
59            $page_acls =  array_merge($page_acls,$this_acls);
60        }
61
62        // check if visible to everyone:
63        if (($page_acls['@ALL'] !== false) && $page_acls['@ALL'] > 0)
64          return; // page is visible to everyone
65
66        $return = "";
67
68        $list = array();
69        foreach ($page_acls as $user => $right) {
70            if ($right > 0 && $user != "@admin" ) // admins can see everything
71                array_push($list,$user);
72        }
73        if (count($list)) {
74            sort($list);
75            $return = "(page visible to: ";
76            $return .= join(', ',$list);
77            $return .= ")";
78        }
79
80        // Uncomment this, if you want to display users/groups who cannot access this page, too:
81        $list = array();
82        foreach ($page_acls as $user => $right) {
83            if ($right == 0)
84                array_push($list,$user);
85        }
86        if (count($list)) {
87            sort($list);
88            $return .= "(page hidden to: ";
89            $return .= join(', ',$list);
90            $return .= ")";
91        }
92
93        return $return;
94    }
95}
96