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(is_array($_SESSION[DOKU_COOKIE])) { 45 if(array_key_exists('plugin_wikicalendar_month', $_SESSION[DOKU_COOKIE])) { 46 $_REQUEST['plugin_wikicalendar_month'] = $_SESSION[DOKU_COOKIE]['plugin_wikicalendar_month']; 47 $_REQUEST['plugin_wikicalendar_year'] = $_SESSION[DOKU_COOKIE]['plugin_wikicalendar_year']; 48 unset($_SESSION[DOKU_COOKIE]['plugin_wikicalendar_month']); 49 unset($_SESSION[DOKU_COOKIE]['plugin_wikicalendar_year']); 50 } 51 } 52 } 53 54 /** 55 * Inserts the hidden redirect id field into edit form 56 */ 57 function handle_form(&$event, $param) { 58 if(array_key_exists('plugin_wikicalendar_redirect_id', $_REQUEST)) { 59 $event->data->addHidden('plugin_wikicalendar_redirect_id', cleanID($_REQUEST['plugin_wikicalendar_redirect_id'])); 60 $event->data->addHidden('plugin_wikicalendar_month', cleanID($_REQUEST['plugin_wikicalendar_month'])); 61 $event->data->addHidden('plugin_wikicalendar_year', cleanID($_REQUEST['plugin_wikicalendar_year'])); 62 } 63 } 64 65 /** 66 * Redirects to the calendar page 67 */ 68 function handle_redirect(&$event, $param) { 69 if(array_key_exists('plugin_wikicalendar_redirect_id', $_REQUEST)) { 70 @session_start(); 71 $_SESSION[DOKU_COOKIE]['plugin_wikicalendar_month'] = $_REQUEST['plugin_wikicalendar_month']; 72 $_SESSION[DOKU_COOKIE]['plugin_wikicalendar_year'] = $_REQUEST['plugin_wikicalendar_year']; 73 @session_write_close(); 74 $event->data['id'] = cleanID($_REQUEST['plugin_wikicalendar_redirect_id']); 75 $event->data['title'] = ''; 76 } 77 } 78} 79 80// vim:ts=4:sw=4:et:enc=utf-8: 81