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