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 */
8
9// must be run within Dokuwiki
10if(!defined('DOKU_INC')) die();
11
12class syntax_plugin_dwtimeline_milestone extends \dokuwiki\Extension\SyntaxPlugin
13{
14    /** @inheritDoc */
15    public function getType()
16    {
17        return 'plugin_dwtimeline_milestone';
18    }
19
20    /** @inheritDoc */
21    public function getPType()
22    {
23        return 'stack';
24    }
25
26    /** @inheritDoc */
27    public function getSort()
28    {
29        return 400;
30    }
31
32    function accepts($mode) {
33        if ($mode == "plugin_dwtimeline_timeline") return true;
34        return parent::accepts($mode);
35    }
36
37    /**
38     * @return array Things that may be inside the syntax
39     */
40    function getAllowedTypes() {
41        return array('container', 'formatting', 'substition', 'protected', 'disabled', 'paragraphs');
42    }
43
44    /**
45     * Set the EntryPattern
46     * @param type $mode
47     */
48    public function connectTo($mode)
49    {
50        $this->Lexer->addEntryPattern('<milestone\b.*?>(?=.*?</milestone>)',$mode,'plugin_dwtimeline_milestone');
51    }
52
53    /**
54     * Set the ExitPattern
55     */
56    public function postConnect()
57    {
58        $this->Lexer->addExitPattern('</milestone>', 'plugin_dwtimeline_milestone');
59    }
60
61    /**
62     * Handle the match
63     * @param type $match
64     * @param type $state
65     * @param type $pos
66     * @param Doku_Handler $handler
67     * @return type
68     */
69    public function handle($match, $state, $pos, Doku_Handler $handler)
70    {
71        $data = [];
72        switch ($state) {
73            case DOKU_LEXER_ENTER :
74                $match = trim(substr($match, 10,-1));// returns match between <milestone(10) and >(-1)
75                $data = helper_plugin_dwtimeline::getTitleMatches($match, 'title');
76                global $align;
77                $data['align'] = $align;
78                return array($state,$data);
79            case DOKU_LEXER_UNMATCHED :
80                return array($state,$match);
81            case DOKU_LEXER_EXIT :
82                return array($state,'');
83        }
84        return array();
85    }
86
87    /**
88     * Render Function
89     * @param type $mode
90     * @param Doku_Renderer $renderer
91     * @param type $data
92     * @return boolean
93     */
94    public function render($mode, Doku_Renderer $renderer, $data)
95    {
96        if ($mode == 'xhtml') {
97            global $direction;
98            if (!$direction) {$direction='tl-'.$this->getConf('direction');}
99            list($state,$indata) = $data;
100            switch ($state) {
101                case DOKU_LEXER_ENTER :
102                    $renderer->doc .= '<div class="container-'.$indata['align'].' '.$direction.'"'.$indata['data'].$indata['backcolor'].'>'. DOKU_LF;
103                    $renderer->doc .= '<div class="tlcontent">'. DOKU_LF;
104                    if (isset($indata['title'])) {
105                        if (isset($indata['link'])) {
106                            $renderer->doc .= '<div class="mstitle">'.$this->render_text('[['.$indata['link'].'|'.$indata['title'].']]').'</div>'. DOKU_LF;
107                        } else {
108                            $renderer->doc .= '<div class="mstitle">'.$indata['title'].'</div>'. DOKU_LF;
109                        }
110                    }
111                    if (isset($indata['description'])) {$renderer->doc .= '<div class="msdesc">'.$indata['description'].'</div>'. DOKU_LF;}
112                    break;
113                case DOKU_LEXER_UNMATCHED :
114                    $renderer->doc .= $renderer->cdata($indata);
115                    break;
116                case DOKU_LEXER_EXIT :
117                    $renderer->doc .= '</div>'. DOKU_LF;
118                    $renderer->doc .= '</div>'. DOKU_LF;
119                    $direction = helper_plugin_dwtimeline::getDirection($direction);
120                    break;
121            }
122            return true;
123        }
124        return false;
125    }
126
127}
128
129