1<?php
2
3/**
4 * DokuWiki Plugin submgr (Action Component)
5 *
6 * @license GPL 2 http://www.gnu.org/licenses/gpl-2.0.html
7 * @author  Andreas Gohr <dokuwiki@cosmocode.de>
8 */
9class action_plugin_submgr extends DokuWiki_Action_Plugin
10{
11
12    /**
13     * Registers a callback function for a given event
14     *
15     * @param Doku_Event_Handler $controller DokuWiki's event controller object
16     * @return void
17     */
18    public function register(Doku_Event_Handler $controller)
19    {
20
21        $controller->register_hook('AUTH_USER_CHANGE', 'BEFORE', $this, 'handle_auth_user_change');
22
23        if ($this->getConf('applyonlogin')) {
24            $controller->register_hook('AUTH_LOGIN_CHECK', 'AFTER', $this, 'handle_login');
25        }
26    }
27
28    /**
29     * Apply rules on a newly created user
30     *
31     * @param Doku_Event $event event object by reference
32     * @param mixed $param not used
33     * @return void
34     * @throws Exception
35     */
36    public function handle_auth_user_change(Doku_Event $event, $param)
37    {
38        if ($event->data['type'] != 'create') return;
39
40        /** @var helper_plugin_submgr $hlp */
41        $hlp = plugin_load('helper', 'submgr');
42        $hlp->runRules($event->data['params'][0], $event->data['params'][4]);
43    }
44
45    /**
46     * Apply rules on a successful user login (only once per session)
47     *
48     * @param Doku_Event $event event object by reference
49     * @param mixed $param not used
50     * @return void
51     * @throws Exception
52     */
53    public function handle_login(Doku_Event $event, $param)
54    {
55        global $INPUT;
56
57        if (!$event->result) return;
58        if (isset($_SESSION[DOKU_COOKIE]['submgr'])) return;
59        if (!$INPUT->server->str('REMOTE_USER')) return;
60        global $USERINFO;
61
62        /** @var helper_plugin_submgr $hlp */
63        $hlp = plugin_load('helper', 'submgr');
64        $hlp->runRules($INPUT->server->str('REMOTE_USER'), $USERINFO['grps']);
65        $_SESSION[DOKU_COOKIE]['submgr'] = 1;
66    }
67
68}
69