1<?php
2/**
3 * Plugin for a nicer Admin main page with some layout
4 *
5 * @license    GPL 2 (http://www.gnu.org/licenses/gpl.html)
6 * @author     H�kan Sandell <hakan.sandell@home.se>
7 */
8
9// must be run within Dokuwiki
10if (!defined('DOKU_INC'))
11    die();
12
13if (!defined('DOKU_PLUGIN'))
14    define('DOKU_PLUGIN', DOKU_INC . 'lib/plugins/');
15
16require_once (DOKU_PLUGIN . 'action.php');
17
18class action_plugin_adminhomepage extends DokuWiki_Action_Plugin {
19
20    /**
21     * return some info
22     */
23    function getInfo() {
24    return array (
25            'author' => 'H&aring;kan Sandell',
26            'email'  => 'hakan.sandell@home.se',
27            'date'   => @file_get_contents(DOKU_PLUGIN.'adminhomepage/VERSION'),
28            'name'   => 'AdminHomePage',
29            'desc'   => 'Replacement for "Admin" page with better usability',
30            'url'    => 'http://www.dokuwiki.org/plugin:adminhomepage'
31        );
32    }
33
34    /**
35     * register the eventhandlers
36     */
37    function register(& $controller) {
38        $controller->register_hook('ACTION_ACT_PREPROCESS', 'BEFORE', $this, 'handle_act_preprocess');
39        $controller->register_hook('TPL_ACT_UNKNOWN', 'BEFORE', $this, 'handle_act_unknown');
40    }
41
42    /**
43     * Looks for admin action, if found the name is changed so TPL_ACT_UNKNOWN is raised
44     */
45    function handle_act_preprocess(& $event, $param) {
46        if (($event->data == 'admin') && empty($_REQUEST['page']) && (act_permcheck($event->data) == 'admin')) {
47            $event->data = 'adminhomepage';
48            $event->stopPropagation();
49            $event->preventDefault();
50        }
51    }
52
53    /**
54     * Catches the "unknown" event "adminhomepage" and outputs the alternative admin main page
55     */
56    function handle_act_unknown(& $event, $param) {
57        if ($event->data == 'adminhomepage') {
58            $this->_html_admin();
59            $event->stopPropagation();
60            $event->preventDefault();
61        }
62    }
63
64    function _html_admin(){
65        global $ID;
66        global $INFO;
67        global $lang;
68        global $conf;
69        global $auth;
70
71        // build menu of admin functions from the plugins that handle them
72        $pluginlist = plugin_list('admin');
73        $menu = array();
74        foreach ($pluginlist as $p) {
75            if($obj =& plugin_load('admin',$p) === NULL) continue;
76
77            // check permissions
78            if($obj->forAdminOnly() && !$INFO['isadmin']) continue;
79
80            $menu[$p] = array('plugin' => $p,
81                                'prompt' => $obj->getMenuText($conf['lang']),
82                                'sort' => $obj->getMenuSort()
83                            );
84        }
85
86        // check if UserManager available
87        $usermanageravailable = true;
88        if (!isset($auth)) {
89          $usermanageravailable = false;
90        } else if (!$auth->canDo('getUsers')) {
91          $usermanageravailable = false;
92        }
93
94        // output main tasks
95        ptln('<h1>'.$this->getLang('pageheader').'</h1>');
96        ptln('<div id="admin__maintable">');
97        ptln('  <div id="admin__tasks">');
98        if ($INFO['isadmin']) {
99            if ($usermanageravailable) {
100                ptln('    <div id="admin__usermanager"><a href="'.wl($ID, 'do=admin&amp;page=usermanager').'">'.$menu[usermanager]['prompt'].'</a></div>');
101            }
102            ptln('    <div id="admin__acl"><a href="'.wl($ID, 'do=admin&amp;page=acl').'">'.$menu['acl']['prompt'].'</a></div>');
103            ptln('    <div id="admin__plugin"><a href="'.wl($ID, 'do=admin&amp;page=plugin').'">'.$menu['plugin']['prompt'].'</a></div>');
104            ptln('    <div id="admin__config"><a href="'.wl($ID, 'do=admin&amp;page=config').'">'.$menu['config']['prompt'].'</a></div>');
105        }else{
106            ptln('&nbsp');
107        }
108        ptln('  </div>');
109        ptln('  <div id="admin__version">');
110        ptln('    <div><b>'.$this->getLang('wiki_version').'</b><br/>'.getVersion().'</div>');
111        ptln('    <div><b>'.$this->getLang('php_version').'</b><br/>'.phpversion().'</div>');
112        ptln('  </div>');
113        ptln('</div>');
114
115        // remove the four main plugins
116        unset($menu['acl']);
117        if ($usermanageravailable) unset($menu['usermanager']);
118        unset($menu['config']);
119        unset($menu['plugin']);
120
121        // output the remaining menu
122        usort($menu, 'p_sort_modes');
123        ptln('<h2>'.$this->getLang('more_adminheader').'</h2>');
124        ptln('<div class="level2">');
125        echo $this->render($this->getLang('more_admintext'));
126        ptln('<ul id="admin__pluginlist">');
127        foreach ($menu as $item) {
128          if (!$item['prompt']) continue;
129          ptln('  <li class="level1"><div class="li"><a href="'.wl($ID, 'do=admin&amp;page='.$item['plugin']).'">'.$item['prompt'].'</a></div></li>');
130        }
131        ptln('</ul></div>');
132    }
133
134}
135