1<?php
2/**
3 * plugin gcalendar
4 *
5 * Syntax <gcal par1=val1 par2=val2 .... > => space delimited list of parameters
6 *
7 * @license    GNU_GPL_v2
8 * @author     Frank Hinkel<Frank [at] hi-sys [dot] de>
9 */
10
11global $lang;
12global $conf;
13
14require_once(DOKU_PLUGIN.'syntax.php');
15
16if(!defined('DOKU_GCAL')) define('DOKU_GCAL',dirname(__FILE__)."/");
17include_once(DOKU_GCAL.'inc/conf.php');          # load common-settings
18include_once(DOKU_GCAL.'user/local_conf.php');   # load user-settings
19include_once(DOKU_GCAL.'lang/en/lang.php');      # the localisation is loaded in the renderer
20
21
22/**
23 *  class syntax_plugin_gcalendar
24 *
25 *  @author     Frank Hinkel<Frank [at] hi-sys [dot] de>
26 */
27class syntax_plugin_gcalendar extends DokuWiki_Syntax_Plugin {
28
29    function getInfo(){
30        $lcDate = substr('$LastChangedDate: 2006-12-19 22:42:04 +0100 (Di, 19 Dez 2006) $',18,10);
31        $rev    = substr('$LastChangedRevision: 89 $',22);
32        $rev    = trim(substr($rev,0,-1));
33
34        return array(
35            'author' => 'Frank Hinkel',
36            'email'  => 'frank.hinkel@hi-sys.de',
37            'date'   => $lcDate.' Rev '.$rev,
38            'name'   => 'gcalendar',
39            'desc'   => 'Transforms unordered lists of dates in different wiki-pages into a group-calendar',
40            'url'    => 'http://wiki.splitbrain.org/plugin:gcalendar',
41            'revision' => $rev
42        );
43    }
44    function getType(){ return 'substition'; }
45    function getPType(){ return 'normal'; }
46    function getAllowedTypes() {
47        return array('substition','protected','disabled');
48    }
49    function getSort(){ return 333; } # really dont know what to put here !?!
50    function connectTo($mode) {
51        $this->Lexer->addSpecialPattern('<gcal>|<gcal .*?>',$mode,'plugin_gcalendar');
52    }
53    function handle($match, $state, $pos, &$handler){
54
55        switch ($state) {
56          case DOKU_LEXER_SPECIAL :
57            return array($state, $match);
58
59          default:
60            return array($state);
61        }
62    }
63
64    function render($mode, &$renderer, $indata) {
65    global $lang;
66    global $conf;
67
68        if($mode == 'xhtml'){
69          list($state, $data) = $indata;
70
71          switch ($state) {
72            case DOKU_LEXER_SPECIAL :
73              # remove leading "<gcal " and trailing ">"
74              $data = trim(substr($data,6,strlen($data)-7));
75              $data = html_entity_decode($data);
76
77              # read parameters into options-array for better access
78              $options_arr = explode(' ',$data);
79              if(!is_array($options_arr)) return false;
80
81              $options = array();
82              foreach($options_arr as $values) {
83                list($k,$v)=split('=',$values);
84                if(!isset($v)) $v=$k;
85                $options[$k]=$v;
86              }
87
88              # possibility to switch language.
89              if(!isset($options['lang'])) $options['lang'] = $conf['lang'];
90              include(DOKU_GCAL.'lang/'.$options['lang'].'/lang.php');
91
92              # caching disabled, because calendar needs to be up-to-date
93              $renderer->info['cache'] = isset($options['cache']);
94
95              # sometimes the table-of-contents (toc) is not wished. The option "notoc" turns it off.
96              if(isset($options['notoc'])) $renderer->info['toc'] = false;
97
98              ob_start();
99
100              # first check the debug-option. If set echo complete command to user page.
101              if(isset($options['debug'])) {
102                echo "<font color='red'><b>&lt;gcal ".$data."></b></font><br/>";
103              }
104
105              require_once('inc/gcal_main.php'); // once - so we can use the plugin more than once at a wiki-page
106              render_gcal($options);  // show the group-calendar
107
108              $content = ob_get_contents();
109              ob_end_clean();
110
111              $renderer->doc .= $content;
112
113              break;
114          }
115          return true;
116        }
117
118        return false; //  unsupported mode
119    }
120}
121
122