xref: /plugin/authskautis/action.php (revision 9c725b9fbdbbd1ed92bc6d66f126f33a0c2902e0)
1<?php
2
3if (!defined('DOKU_INC')) die();
4
5require_once 'vendor/autoload.php';
6
7
8class action_plugin_authskautis extends DokuWiki_Action_Plugin {
9
10    protected $url;
11    protected $testUrl;
12
13    /**
14     * Registers the event handlers.
15     */
16    function register(Doku_Event_Handler $controller)
17    {
18        $controller->register_hook('FORM_LOGIN_OUTPUT', 'BEFORE',  $this, 'hook_html_loginform_output', array());
19        $controller->register_hook('HTML_UPDATEPROFILEFORM_OUTPUT', 'BEFORE', $this, 'hook_updateprofileform_output', array());
20    }
21
22    function hook_updateprofileform_output(&$event, $param) {
23        global $USERINFO;
24
25        if ($USERINFO['is_skautis']) {
26            $elem = $event->data->getElementAt(2);
27            $elem['disabled'] = 'disabled';
28            $event->data->replaceElement(2, $elem);
29
30            $elem = $event->data->getElementAt(3);
31            $elem['disabled'] = 'disabled';
32            $event->data->replaceElement(3, $elem);
33
34            $event->data->replaceElement(10, null);
35            $event->data->replaceElement(9, null);
36            $event->data->replaceElement(8, null);
37            $event->data->replaceElement(7, null);
38            $event->data->replaceElement(6, null);
39            $event->data->replaceElement(5, null);
40            $event->data->replaceElement(4, null);
41        }
42    }
43
44    /**
45     * Handles the login form rendering.
46     */
47    function hook_html_loginform_output(&$event, $param) {
48
49        $this->url = Skautis\Config::URL_PRODUCTION . 'Login/?appid=';
50        $this->testUrl = Skautis\Config::URL_TEST . 'Login/?appid=';
51
52        $skautIsAppId = $this->getConf('skautis_app_id');
53        if($skautIsAppId!=''){
54            $skautIsTestmode = $this->getConf('skautis_test_mode');
55            $baseUrl = $skautIsTestmode ? $this->testUrl : $this->url;
56            $authUrl = sprintf('%s%s', $baseUrl, $skautIsAppId);
57
58            $a_style = "width: 200px;margin:0 auto;color: #666666;cursor: pointer;text-decoration: none !important;display: block;padding-bottom:1.4em;";//-moz-linear-gradient(center top , #F8F8F8, #ECECEC)
59            $div_style = "float:left;line-height: 30px;background-color: #F8F8F8;border: 1px solid #C6C6C6;border-radius: 2px 2px 2px 2px;padding: 0px 5px 0px 5px;position: relative;";
60            echo "<a href='$authUrl' style='$a_style' title='".$this->getLang('enter_skautis')."'><div style=\"$div_style\">".$this->getLang('enter_skautis')."</div>";
61            echo "<div style='clear: both;'></div></a>";
62        }
63    }
64}
65?>
66