1<?php
2/**
3 * DokuWiki Plugin grouphome (Action Component)
4 *
5 * @license GPL 2 http://www.gnu.org/licenses/gpl-2.0.html
6 * @author  Andreas Gohr <gohr@cosmocode.de>
7 */
8
9use dokuwiki\Extension\ActionPlugin;
10
11// must be run within Dokuwiki
12if (!defined('DOKU_INC')) die();
13
14if (!defined('DOKU_LF')) define('DOKU_LF', "\n");
15if (!defined('DOKU_TAB')) define('DOKU_TAB', "\t");
16if (!defined('DOKU_PLUGIN')) define('DOKU_PLUGIN',DOKU_INC.'lib/plugins/');
17
18class action_plugin_grouphome extends ActionPlugin
19{
20
21    public function register(Doku_Event_Handler $controller)
22    {
23       $controller->register_hook('ACTION_ACT_PREPROCESS', 'BEFORE', $this, 'handleHook');
24    }
25
26    public function handleHook(Doku_Event $event)
27    {
28        global $INFO;
29        global $ID;
30        global $conf;
31
32        if (!isset($INFO['userinfo']['grps'])) return;
33
34        if ($ID != $conf['start']) return;
35        if( act_clean($event->data) != 'show') return;
36
37        $grps = (array) $INFO['userinfo']['grps'];
38        if (!count($grps)) return;
39
40        $pages = $this->getConf('grouppages');
41
42        foreach ($grps as $grp) {
43            $page = cleanID(sprintf($pages,$grp));
44            if (page_exists($page)) {
45                send_redirect(wl($page,'',true));
46            }
47        }
48    }
49}
50
51// vim:ts=4:sw=4:et:
52