1<?php
2/**
3 * Display Fortune cookies
4 *
5 * @license    GPL 2 (http://www.gnu.org/licenses/gpl.html)
6 * @author     Andreas Gohr <andi@splitbrain.org>
7 */
8
9class action_plugin_xfortune extends DokuWiki_Action_Plugin {
10
11    /** @inheritdoc */
12    function register(Doku_Event_Handler $controller) {
13        $controller->register_hook('AJAX_CALL_UNKNOWN', 'BEFORE', $this, 'handle_ajax_call_unknown');
14        $controller->register_hook('DOKUWIKI_STARTED', 'BEFORE', $this, 'handle_claim');
15    }
16
17    /**
18     * Handle the ajax call
19     *
20     * @param Doku_Event $event
21     * @param $param
22     */
23    function handle_ajax_call_unknown(Doku_Event $event, $param) {
24        if($event->data != 'plugin_xfortune') return;
25        $event->preventDefault();
26        $event->stopPropagation();
27        global $INPUT;
28        echo helper_plugin_xfortune::getCookieHTML($INPUT->str('cookie'));
29    }
30
31    /**
32     * Set a small cookie as tagline
33     *
34     * @param Doku_Event $event
35     * @param $param
36     */
37    function handle_claim(Doku_Event $event, $param) {
38        if($this->getConf('claim') === '') return;
39        global $conf;
40
41        $cookie = helper_plugin_xfortune::getCookieHTML($this->getConf('claim'), 2, 130);
42        $conf['tagline'] = $cookie;
43
44    }
45}
46