1<?php
2
3// must be run from within DokuWiki
4if (!defined('DOKU_INC')) die();
5
6class Kiwiki_Functions {
7
8
9    /**
10     * Edit icon button
11     */
12    public static function _edit_icon($what){
13        global $ACT;
14        global $INFO;
15        $rev = ($INFO['rev']) ? '&rev='.$INFO['rev'] : '';
16        if ($ACT == 'show'){
17            $editicon = (new \dokuwiki\Menu\KiwikiEdit())->getListItems('kiwiki-',true);
18            if (!empty($what)){
19                $editicon = preg_replace('/<a(.*)href="([^"]*)"(.*)>/','<a$1href="'.DOKU_BASE.'doku.php?id='.$what.'&do=edit"$3 role="button">',$editicon);
20            }else{
21                $editicon = preg_replace('/<a(.*)href="([^"]*)"(.*)>/','<a$1href="'.DOKU_BASE.'doku.php?id='.$INFO['id'].'&do=edit'.$rev.'"$3 role="button">',$editicon);
22            }
23            return $editicon;
24        }
25    }
26
27
28    /**
29     * Go bottom button
30     */
31
32    public static function html_bottombtn() {
33        global $lang;
34
35        return '<a class="nolink" href="#dokuwiki__bottom" role="button" aria-label="' . $lang['btn_bottom'] . '" title="' . $lang['btn_bottom'] . '">'
36            .'<button class="button" onclick="window.scrollTo(0, 0)" title="'. $lang['btn_bottom'] .'">'
37            . $lang['btn_bottom']
38            .'</button></a>';
39    }
40
41    /**
42     * Custom ACL Informations in footer
43     * Original code from Chris75
44     * https://forum.dokuwiki.org/d/21636-acl-deny-a-user-group-to-a-namespace/13
45     */
46
47     public static function tpl_aclinfo() {
48        global $ID, $AUTH_ACL, $INFO;
49
50        if ((auth_quickaclcheck($ID) == 0) ||(!$INFO['editable']))
51            return; // no rights to view, no rights to get this info
52
53        $page_acls = array();
54        $namespaces = array();
55
56        $ns = getNS($ID);
57        while ($ns) {
58        array_unshift($namespaces,$ns . ':*');
59        $ns = getNS($ns);
60        }
61        array_unshift($namespaces,'*'); // root
62
63        $namespaces[] = $ID;
64
65        // check matches
66        foreach ($namespaces as $level) {
67            $matches = preg_grep('/^'.preg_quote($level,'/').'\s+\S+\s+\d+\s*$/',$AUTH_ACL);
68            $this_acls = array();
69            foreach($matches as $match){
70            $match = preg_replace('/#.*$/','',$match); //ignore comments
71            $acl   = preg_split('/\s+/',$match);
72            $this_acls[urldecode($acl[1])] = $acl[2];
73            if ($acl[1] == "@ALL")  // overwrites stuff from upper level
74                $page_acls = array();
75            }
76            $page_acls =  array_merge($page_acls,$this_acls);
77        }
78
79        // check if visible to everyone:
80        /*if (($page_acls['@ALL'] !== false) && $page_acls['@ALL'] > 0)
81        return; // page is visible to everyone*/
82
83        $list = array();
84        foreach ($page_acls as $user => $right) {
85            if ($right > 0 && $user != "@admin" ) // admins can see everything
86                array_push($list,$user);
87        }
88        if (count($list)) {
89            sort($list);
90            print tpl_getLang('Visible to');
91            print join(', ',$list);
92        }
93
94        // Uncomment this, if you want to display users/groups who cannot access this page, too:
95        $list = array();
96        foreach ($page_acls as $user => $right) {
97            if ($right == 0)
98                array_push($list,$user);
99        }
100        if (count($list)) {
101            sort($list);
102            print " • ";
103            print tpl_getLang('Hidden to');
104            print join(', ',$list);
105        }
106    }
107}
108