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