xref: /plugin/dwtimeline/syntax/timeline.php (revision 85220f43f5299277b3c21bbeb11f3fc72000c7a9)
1<?php
2/**
3 * DokuWiki Plugin dwtimeline (Syntax Component)
4 *
5 * @license GPL 2 http://www.gnu.org/licenses/gpl-2.0.html
6 * @author  saggi <saggi@gmx.de>
7 */
8class syntax_plugin_dwtimeline_timeline extends \dokuwiki\Extension\SyntaxPlugin
9{
10    protected $box_open = false;
11
12    /** @inheritDoc */
13    public function getType()
14    {
15        return 'substition';
16    }
17
18    /** @inheritDoc */
19    public function getPType()
20    {
21        return 'stack';
22    }
23
24    /** @inheritDoc */
25    public function getSort()
26    {
27        return 180;
28    }
29
30    /**
31     * @return array Things that may be inside the syntax
32     */
33    function getAllowedTypes() {
34        return array('container', 'formatting', 'substition', 'protected', 'disabled', 'paragraphs');
35    }
36
37    /**
38     * Set the EntryPattern
39     * @param type $mode
40     */
41    public function connectTo($mode)
42    {
43        $this->Lexer->addEntryPattern('<dwtimeline\b.*?>',$mode,'plugin_dwtimeline_timeline');/* (?=.*?</dwtimeline\b.*?>) */
44    }
45
46    /**
47     * Set the ExitPattern
48     */
49    public function postConnect()
50    {
51        $this->Lexer->addExitPattern('</dwtimeline\b.*?>', 'plugin_dwtimeline_timeline');
52    }
53
54    /**
55     * Handle the match
56     * @param type $match
57     * @param type $state
58     * @param type $pos
59     * @param Doku_Handler $handler
60     * @return type
61     */
62    public function handle($match, $state, $pos, Doku_Handler $handler)
63    {
64        $data = [];
65        switch ($state) {
66            case DOKU_LEXER_ENTER :
67                $match = trim(substr($match, 11,-1));// returns match between <dwtimeline(11) and >(-1)
68                $data = helper_plugin_dwtimeline::getTitleMatches($match);
69                return array($state,$data);
70
71            case DOKU_LEXER_UNMATCHED :
72                return array ($state,$match);
73            case DOKU_LEXER_EXIT :
74                $match = trim(substr($match, 12,-1));//returns match between </dwtimeline(12) and >(-1)
75                $data = helper_plugin_dwtimeline::getTitleMatches($match);
76                return array($state,$data);
77        }
78        return array();
79    }
80
81    /**
82     * Render Function
83     * @param type $mode
84     * @param Doku_Renderer $renderer
85     * @param type $data
86     * @return boolean
87     */
88    public function render($mode, Doku_Renderer $renderer, $data)
89    {
90        if ($mode == 'xhtml') {
91            global $direction;
92            if (!$direction) {$direction=$this->getConf('direction');}
93            list($state,$indata) = $data;
94            switch ($state) {
95                case DOKU_LEXER_ENTER :
96                    $renderer->doc .= '<div class="timeline">'. DOKU_LF;
97                    if ($indata['title'] or $indata['description']) {
98                        $renderer->doc .= '<div class="container top">'. DOKU_LF;
99                        $renderer->doc .= '<div class="content">'. DOKU_LF;
100                        if ($indata['title']) {$renderer->doc .= '<h2>'.$indata['title'].'</h2>'. DOKU_LF;}
101                        if ($indata['description']) {$renderer->doc .= '<p>'.$indata['description'].'</p>'. DOKU_LF;}
102                         $renderer->doc .= '</div>'. DOKU_LF;
103                        $renderer->doc .= '</div>'. DOKU_LF;
104                    }
105                    break;
106                case DOKU_LEXER_UNMATCHED :
107                    $renderer->doc .= $renderer->_xmlEntities($indata);
108                    break;
109                case DOKU_LEXER_EXIT :
110                    if ($indata['title'] or $indata['description']) {
111                        $renderer->doc .= '<div class="container bottom">'. DOKU_LF;
112                        $renderer->doc .= '<div class="content">'. DOKU_LF;
113                        if ($indata['title']) {$renderer->doc .= '<h2>'.$indata['title'].'</h2>'. DOKU_LF;}
114                        if ($indata['description']) {$renderer->doc .= '<p>'.$indata['description'].'</p>'. DOKU_LF;}
115                        $renderer->doc .= '</div>'. DOKU_LF;
116                        $renderer->doc .= '</div>'. DOKU_LF;
117                    }
118                    $renderer->doc .= '</div>'. DOKU_LF;
119                    $direction=$this->getConf('direction');//Reset direction
120                    break;
121            }
122            return true;
123        }
124        return false;
125    }
126
127}
128
129