1<?php
2/**
3 * csstimeline Plugin - Create a CSS-only timeline
4 *
5 * Usage:
6 *
7 * <csstimeline>
8 * <entry>
9 * date: 04.12.2014
10 * title: My first timeline entry
11 * description: Within the description, you can even use Wiki markup
12 * </entry>
13 * <entry>
14 * date: 06.01.2015
15 * title: My second timeline entry
16 * description: This one is rendered at the other side of the timeline
17 * </entry>
18 * </csstimeline>
19 *
20 *
21 * @license    GPL 2 (http://www.gnu.org/licenses/gpl.html)
22 * @author     Andreas Böhler <dev@aboehler.at>
23 */
24
25if(!defined('DOKU_INC')) define('DOKU_INC',realpath(dirname(__FILE__).'/../../').'/');
26if(!defined('DOKU_PLUGIN')) define('DOKU_PLUGIN',DOKU_INC.'lib/plugins/');
27require_once(DOKU_PLUGIN.'syntax.php');
28
29/**
30 * All DokuWiki plugins to extend the parser/rendering mechanism
31 * need to inherit from this class
32 */
33class syntax_plugin_csstimeline extends DokuWiki_Syntax_Plugin {
34
35    protected $_helper = null;
36
37    // Load the helper plugin
38    public function syntax_plugin_csstimeline() {
39        $this->_helper =& plugin_load('helper', 'csstimeline');
40    }
41
42
43    function getType() {
44        return 'substition';
45    }
46
47    function getPType() {
48        return 'normal';
49    }
50
51    function getAllowedTypes() {
52        return array('container','substition','protected','disabled','paragraphs','formatting');
53    }
54
55    function getSort() {
56        return 777;
57    }
58
59    function connectTo($mode) {
60        $this->Lexer->addSpecialPattern($this->_helper->specialPattern,$mode,'plugin_csstimeline');
61    }
62
63   /**
64    * Handle the match. Use either the standard linking mechanism or, when enabled,
65    * pass the title through the parser
66    */
67    function handle($match, $state, $pos, Doku_Handler $handler) {
68        $data = $this->_helper->handleMatch($match);
69
70        return $data;
71    }
72
73   /**
74    * Create output. This is largely based on the internal linking mechanism.
75    */
76    function render($mode, Doku_Renderer $renderer, $data) {
77        if (empty($data)) return false;
78
79
80        if($mode == 'xhtml') {
81            $direction = 'r';
82            $renderer->doc .= '<div class="clearer"></div><div><ul class="timeline">';
83            foreach($data['entries'] as $entry)
84            {
85                $renderer->doc .= '<li>';
86                $renderer->doc .= '<div class="direction-'.$direction.'">';
87                $renderer->doc .= '<div class="flag-wrapper">';
88                $renderer->doc .= '<span class="flag">'.$entry['title'].'</span>';
89                $renderer->doc .= '<span class="time-wrapper"><span class="time">'.$entry['date'].'</span></span>';
90                $renderer->doc .= '</div>';
91                $renderer->doc .= '<div class="desc">'.$entry['description'].'</div>';
92                $renderer->doc .= '</li>';
93                if($direction === 'r')
94                    $direction = 'l';
95                else
96                    $direction = 'r';
97            }
98            $renderer->doc .= '</ul></div>';
99
100        }
101        return false;
102    }
103}
104