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
9class syntax_plugin_dwtimeline_milestone extends syntax_plugin_dwtimeline_dwtimeline
10{
11    /** @inheritDoc */
12    public function getType()
13    {
14        return 'plugin_dwtimeline_milestone';
15    }
16
17    function accepts($mode) {
18        if ($mode == "plugin_dwtimeline_timeline") return true;
19        return parent::accepts($mode);
20    }
21
22    /**
23     * @return array Things that may be inside the syntax
24     */
25    function getAllowedTypes() {
26        return array('container', 'formatting', 'substition', 'protected', 'disabled', 'paragraphs');
27    }
28
29    /**
30     * Set the EntryPattern
31     * @param string $mode
32     */
33    public function connectTo($mode)
34    {
35        $this->Lexer->addEntryPattern('<milestone\b.*?>(?=.*?</milestone>)',$mode,'plugin_dwtimeline_milestone');
36    }
37
38    /**
39     * Set the ExitPattern
40     */
41    public function postConnect()
42    {
43        $this->Lexer->addExitPattern('</milestone>', 'plugin_dwtimeline_milestone');
44    }
45
46    /**
47     * Handle the match
48     * @param string $match The match of the syntax
49     * @param int $state The state of the handler
50     * @param int $pos The position in the document
51     * @param Doku_Handler $handler The handler
52     * @return array Data for the renderer
53     */
54    public function handle($match, $state, $pos, Doku_Handler $handler)
55    {
56        switch ($state) {
57            case DOKU_LEXER_ENTER :
58                $match = trim(substr($match, 10,-1));// returns match between <milestone(10) and >(-1)
59                $data = $this->getTitleMatches($match);
60                $data['align'] = parent::$align;
61                return array($state,$data);
62            case DOKU_LEXER_UNMATCHED :
63                return array($state,$match);
64            case DOKU_LEXER_EXIT :
65                return array($state,'');
66        }
67        return array();
68    }
69
70    /**
71     * Create output
72     *
73     * @param string $mode string     output format being rendered
74     * @param Doku_Renderer $renderer the current renderer object
75     * @param array $data data created by handler()
76     * @return  boolean                 rendered correctly?
77     */
78    public function render($mode, Doku_Renderer $renderer, $data)
79    {
80        if ($mode == 'xhtml') {
81            if (!parent::$direction) {parent::$direction = $this->GetDirection();}
82            list($state,$indata) = $data;
83            switch ($state) {
84                case DOKU_LEXER_ENTER :
85                    $renderer->doc .= '<div class="container-' . $indata['align'] . ' ' . parent::$direction . '"' . $indata['data'] . $indata['style'] . '>' . DOKU_LF;
86                    $renderer->doc .= '<div class="tlcontent">'. DOKU_LF;
87                    if (isset($indata['title'])) {
88                        if (isset($indata['link'])) {
89                            $renderer->doc .= '<div class="mstitle">' . $this->render_text('[[' . $indata['link'] . '|' . $indata['title'] . ']]') . '</div>' . DOKU_LF;
90                        } else {
91                            $renderer->doc .= '<div class="mstitle">' . $indata['title'] . '</div>' . DOKU_LF;
92                        }
93                    }
94                    if (isset($indata['description'])) {$renderer->doc .= '<div class="msdesc">'  .$indata['description'] . '</div>' . DOKU_LF;}
95                    break;
96                case DOKU_LEXER_UNMATCHED :
97                    $renderer->doc .= $renderer->cdata($indata);
98                    break;
99                case DOKU_LEXER_EXIT :
100                    $renderer->doc .= '</div>' . DOKU_LF;
101                    $renderer->doc .= '</div>' . DOKU_LF;
102                    parent::$direction = $this->ChangeDirection(parent::$direction);
103                    break;
104            }
105            return true;
106        }
107        return false;
108    }
109
110}
111
112