summaryrefslogtreecommitdiff
path: root/platform/www/inc/Extension/AdminPlugin.php
blob: 7900a1ec42a7a204af587aafa96d93e23cf38eeb (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
<?php

namespace dokuwiki\Extension;

/**
 * Admin Plugin Prototype
 *
 * Implements an admin interface in a plugin
 *
 * @license    GPL 2 (http://www.gnu.org/licenses/gpl.html)
 * @author     Christopher Smith <chris@jalakai.co.uk>
 */
abstract class AdminPlugin extends Plugin
{

    /**
     * Return the text that is displayed at the main admin menu
     * (Default localized language string 'menu' is returned, override this function for setting another name)
     *
     * @param string $language language code
     * @return string menu string
     */
    public function getMenuText($language)
    {
        $menutext = $this->getLang('menu');
        if (!$menutext) {
            $info = $this->getInfo();
            $menutext = $info['name'] . ' ...';
        }
        return $menutext;
    }

    /**
     * Return the path to the icon being displayed in the main admin menu.
     * By default it tries to find an 'admin.svg' file in the plugin directory.
     * (Override this function for setting another image)
     *
     * Important: you have to return a single path, monochrome SVG icon! It has to be
     * under 2 Kilobytes!
     *
     * We recommend icons from https://materialdesignicons.com/ or to use a matching
     * style.
     *
     * @return string full path to the icon file
     */
    public function getMenuIcon()
    {
        $plugin = $this->getPluginName();
        return DOKU_PLUGIN . $plugin . '/admin.svg';
    }

    /**
     * Determine position in list in admin window
     * Lower values are sorted up
     *
     * @return int
     */
    public function getMenuSort()
    {
        return 1000;
    }

    /**
     * Carry out required processing
     */
    public function handle()
    {
        // some plugins might not need this
    }

    /**
     * Output html of the admin page
     */
    abstract public function html();

    /**
     * Checks if access should be granted to this admin plugin
     *
     * @return bool true if the current user may access this admin plugin
     */
    public function isAccessibleByCurrentUser() {
        $data = [];
        $data['instance'] = $this;
        $data['hasAccess'] = false;

        $event = new Event('ADMINPLUGIN_ACCESS_CHECK', $data);
        if($event->advise_before()) {
            if ($this->forAdminOnly()) {
                $data['hasAccess'] = auth_isadmin();
            } else {
                $data['hasAccess'] = auth_ismanager();
            }
        }
        $event->advise_after();

        return $data['hasAccess'];
    }

    /**
     * Return true for access only by admins (config:superuser) or false if managers are allowed as well
     *
     * @return bool
     */
    public function forAdminOnly()
    {
        return true;
    }

    /**
     * Return array with ToC items. Items can be created with the html_mktocitem()
     *
     * @see html_mktocitem()
     * @see tpl_toc()
     *
     * @return array
     */
    public function getTOC()
    {
        return array();
    }

}