1<?php
2/*
3 * XXX
4 */
5
6if(!defined('DOKU_INC')) die();
7if(!defined('DOKU_PLUGIN')) define('DOKU_PLUGIN',DOKU_INC.'lib/plugins/');
8require_once(DOKU_PLUGIN.'syntax.php');
9require_once(DOKU_PLUGIN.'calendoku/helper.php');
10
11    // start end duration contact summary url uid created last-modified
12    // sequence x-calendoku-version prodid tzname description organizer
13    // location class
14
15class syntax_plugin_calendoku_showicalendar extends DokuWiki_Syntax_Plugin {
16
17    function getType()  { return 'substition'; }
18    function getPType() { return 'block'; }
19    function getSort()  { return 42; }
20
21    function connectTo($mode) {
22        $this->Lexer->addSpecialPattern(
23            '^[\n\s]*BEGIN:VCALENDAR\n.*\nEND:VCALENDAR[\n\s]*$',
24            $mode,
25            'plugin_calendoku_showicalendar');
26    }
27
28    function handle($match, $state, $pos, &$handler) {
29        global $INFO;
30
31        /* Check if we handle this page at all. */
32        $dohandle = false;
33
34        $INFO = pageinfo();
35        $namespaces = preg_split('/\s/', $this->getConf('icalnamespaces'));
36        foreach ($namespaces as $namespace) {
37            if (!strcmp($namespace, $INFO['namespace'])) {
38                $dohandle = true;
39                break;
40            }
41        }
42        if (!$dohandle) {
43            $handler->_addCall('cdata', array($match), $pos);
44            return false;
45        }
46
47        /* Get the template. */
48        $templates = preg_split('/\s/', $this->getConf('icaltemplates'));
49        foreach ($templates as $template)
50            if (!strcmp($template, $INFO['id'])) {
51                $handler->_addCall('cdata', array($match), $pos);
52                return false;
53            }
54        foreach ($templates as $template) {
55            if (!strcmp('', getNS($template))) {
56                $mytemplate = $INFO['namespace'].':'.$template;
57            } else if (!strcmp(getNS($template), $INFO['namespace'])) {
58                $mytemplate = $template;
59                break;
60            }
61        }
62
63        if (!isset($mytemplate)) {
64            $handler->_addCall('cdata', array($match), $pos);
65            return false;
66        }
67
68        /* Create the calendar object. */
69        $object = new CalenDoku_CalendarObject($this, $match);
70        $mytemplate = rawWiki($mytemplate);
71        if (!preg_match('/@@/', $mytemplate)) {
72            $handler->_addCall('cdata', array($match), $pos);
73            return false;
74        }
75        foreach ($object->components as $component) {
76            $componenttext = $mytemplate;
77            $componenttext = preg_replace('/@@DOKUWIKIICAL@@/', $INFO['id'].'?do=ical', $componenttext);
78            foreach ($component->renderfields as $field => $value) {
79                $componenttext = preg_replace('/@@'.$field.'@@/', $value, $componenttext);
80            }
81
82            reHandleText($componenttext, $pos, $handler);
83        }
84
85        return true;
86    }
87
88    function render($mode, &$renderer, $data) {
89        return true;
90    }
91}
92//Setup VIM: ex: et ts=4 enc=utf-8 :
93