1<?php
2/**
3 * DokuWiki Action Plugin minical
4 *
5 * @author Alexandre Bastien <alexandre.bastien@fsaa.ulaval.ca>
6 * Forked from WikiCalendar (Michael Klier <chi@chimeric.de>)
7 */
8// must be run within Dokuwiki
9if(!defined('DOKU_INC')) die();
10
11if(!defined('DOKU_PLUGIN')) define('DOKU_PLUGIN', DOKU_INC.'lib/plugins/');
12if(!defined('DOKU_LF')) define('DOKU_LF', "\n");
13
14require_once(DOKU_PLUGIN.'action.php');
15
16 // All DokuWiki plugins to extend the admin function
17 // need to inherit from this class
18class action_plugin_minical extends DokuWiki_Action_Plugin {
19
20    function getInfo() {
21        return array(
22                'author' => 'Alexandre Bastien',
23                'email'  => 'alexandre.bastien@fsaa.ulaval.ca',
24                'date'   => @file_get_contents(DOKU_PLUGIN.'minical/VERSION'),
25                'name'   => 'MiniCal Plugin (action component)',
26                'desc'   => 'Implements a simple Calendar with links to wikipages. Forked from minical.',
27                'url'    => 'http://dokuwiki.org/plugin:minical',
28            );
29    }
30
31    // register hook
32    function register(Doku_Event_Handler $controller) {
33        $controller->register_hook('ACTION_SHOW_REDIRECT', 'BEFORE', $this, 'handle_redirect');
34        $controller->register_hook('HTML_EDITFORM_OUTPUT', 'BEFORE', $this, 'handle_form');
35        $controller->register_hook('FORM_EDIT_OUTPUT', 'BEFORE', $this, 'handle_form');
36        $controller->register_hook('DOKUWIKI_STARTED', 'BEFORE', $this, 'handle_started');
37    }
38
39     // Checks for calendar values for proper redirects
40    function handle_started(Doku_Event $event, $param) {
41        if(is_array($_SESSION[DOKU_COOKIE])) {
42            if(array_key_exists('plugin_minical_month', $_SESSION[DOKU_COOKIE])) {
43                $_REQUEST['plugin_minical_month'] = $_SESSION[DOKU_COOKIE]['plugin_minical_month'];
44                $_REQUEST['plugin_minical_year']  = $_SESSION[DOKU_COOKIE]['plugin_minical_year'];
45                unset($_SESSION[DOKU_COOKIE]['plugin_minical_month']);
46                unset($_SESSION[DOKU_COOKIE]['plugin_minical_year']);
47            }
48        }
49    }
50
51     // Inserts the hidden redirect id field into edit form
52    function handle_form(Doku_Event $event, $param) {
53        if(array_key_exists('plugin_minical_redirect_id', $_REQUEST)) {
54            $form = $event->data;
55            if(is_a($form, \dokuwiki\Form\Form::class)) {
56                $form->setHiddenField('plugin_minical_redirect_id', cleanID($_REQUEST['plugin_minical_redirect_id']));
57                $form->setHiddenField('plugin_minical_month', cleanID($_REQUEST['plugin_minical_month']));
58                $form->setHiddenField('plugin_minical_year', cleanID($_REQUEST['plugin_minical_year']));
59            } else {
60                $form->addHidden('plugin_minical_redirect_id', cleanID($_REQUEST['plugin_minical_redirect_id']));
61                $form->addHidden('plugin_minical_month', cleanID($_REQUEST['plugin_minical_month']));
62                $form->addHidden('plugin_minical_year', cleanID($_REQUEST['plugin_minical_year']));
63            }
64        }
65    }
66
67     // Redirects to the calendar page
68    function handle_redirect(Doku_Event $event, $param) {
69        if(array_key_exists('plugin_minical_redirect_id', $_REQUEST)) {
70            @session_start();
71            $_SESSION[DOKU_COOKIE]['plugin_minical_month'] = $_REQUEST['plugin_minical_month'];
72            $_SESSION[DOKU_COOKIE]['plugin_minical_year']  = $_REQUEST['plugin_minical_year'];
73            @session_write_close();
74            $event->data['id'] = cleanID($_REQUEST['plugin_minical_redirect_id']);
75            $event->data['title'] = '';
76        }
77    }
78}
79
80