xref: /plugin/wikicalendar-ng/action.php (revision de76d2a46ade03f1dbc98f6bb632260b9440e5e9)
1<?php
2/**
3 * DokuWiki Action Plugin WikiCalendar
4 *
5 * @license    GPL 2 (http://www.gnu.org/licenses/gpl.html)
6 * @author     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/**
17 * All DokuWiki plugins to extend the admin function
18 * need to inherit from this class
19 */
20class action_plugin_wikicalendar extends DokuWiki_Action_Plugin {
21
22    function getInfo() {
23        return array(
24                'author' => 'Michael Klier',
25                'email'  => 'chi@chimeric.de',
26                'date'   => @file_get_contents(DOKU_PLUGIN.'wikicalendar/VERSION'),
27                'name'   => 'WikiCalendar Plugin (action component)',
28                'desc'   => 'Implements a simple Calendar with links to wikipages.',
29                'url'    => 'http://dokuwiki.org/plugin:wikicalendar',
30            );
31    }
32
33    // register hook
34    function register(&$controller) {
35        $controller->register_hook('ACTION_SHOW_REDIRECT', 'BEFORE', $this, 'handle_redirect');
36        $controller->register_hook('HTML_EDITFORM_OUTPUT', 'BEFORE', $this, 'handle_form');
37        $controller->register_hook('DOKUWIKI_STARTED', 'BEFORE', $this, 'handle_started');
38    }
39
40    /**
41     * Checks for calendar values for proper redirects
42     */
43    function handle_started(&$event, $param) {
44        if(array_key_exists('plugin_wikicalendar_month', $_SESSION[DOKU_COOKIE])) {
45            $_REQUEST['plugin_wikicalendar_month'] = $_SESSION[DOKU_COOKIE]['plugin_wikicalendar_month'];
46            $_REQUEST['plugin_wikicalendar_year']  = $_SESSION[DOKU_COOKIE]['plugin_wikicalendar_year'];
47            unset($_SESSION[DOKU_COOKIE]['plugin_wikicalendar_month']);
48            unset($_SESSION[DOKU_COOKIE]['plugin_wikicalendar_year']);
49        }
50    }
51
52    /**
53     * Inserts the hidden redirect id field into edit form
54     */
55    function handle_form(&$event, $param) {
56        if(array_key_exists('plugin_wikicalendar_redirect_id', $_REQUEST)) {
57            $event->data->addHidden('plugin_wikicalendar_redirect_id', cleanID($_REQUEST['plugin_wikicalendar_redirect_id']));
58            $event->data->addHidden('plugin_wikicalendar_month', cleanID($_REQUEST['plugin_wikicalendar_month']));
59            $event->data->addHidden('plugin_wikicalendar_year', cleanID($_REQUEST['plugin_wikicalendar_year']));
60        }
61    }
62
63    /**
64     * Redirects to the calendar page
65     */
66    function handle_redirect(&$event, $param) {
67        if(array_key_exists('plugin_wikicalendar_redirect_id', $_REQUEST)) {
68            @session_start();
69            $_SESSION[DOKU_COOKIE]['plugin_wikicalendar_month'] = $_REQUEST['plugin_wikicalendar_month'];
70            $_SESSION[DOKU_COOKIE]['plugin_wikicalendar_year']  = $_REQUEST['plugin_wikicalendar_year'];
71            @session_write_close();
72            $event->data['id'] = cleanID($_REQUEST['plugin_wikicalendar_redirect_id']);
73            $event->data['title'] = '';
74        }
75    }
76}
77
78// vim:ts=4:sw=4:et:enc=utf-8:
79