xref: /plugin/dwtimeline/syntax/timeline.php (revision c78eb03925bf98f51131d1ba7addb13013f043fd)
185220f43Ssaggi-dw<?php
285220f43Ssaggi-dw/**
385220f43Ssaggi-dw * DokuWiki Plugin dwtimeline (Syntax Component)
485220f43Ssaggi-dw *
585220f43Ssaggi-dw * @license GPL 2 http://www.gnu.org/licenses/gpl-2.0.html
685220f43Ssaggi-dw * @author  saggi <saggi@gmx.de>
785220f43Ssaggi-dw */
84ff971beSsaggi-dw
9*c78eb039Ssaggi-dwclass syntax_plugin_dwtimeline_timeline extends syntax_plugin_dwtimeline_dwtimeline
1085220f43Ssaggi-dw{
1185220f43Ssaggi-dw
1285220f43Ssaggi-dw    /**
1385220f43Ssaggi-dw     * @return array Things that may be inside the syntax
1485220f43Ssaggi-dw     */
1585220f43Ssaggi-dw    function getAllowedTypes() {
162ddb0813SSteffen Sagert        return array('plugin_dwtimeline_milestone');
1785220f43Ssaggi-dw    }
1885220f43Ssaggi-dw
1985220f43Ssaggi-dw    /**
2085220f43Ssaggi-dw     * Set the EntryPattern
214fa647deSsaggi-dw     * @param string $mode
2285220f43Ssaggi-dw     */
2385220f43Ssaggi-dw    public function connectTo($mode)
2485220f43Ssaggi-dw    {
252ddb0813SSteffen Sagert        $this->Lexer->addEntryPattern('<dwtimeline\b.*?>(?=.*?</dwtimeline\b.*?>)',$mode,'plugin_dwtimeline_timeline');
2685220f43Ssaggi-dw    }
2785220f43Ssaggi-dw
2885220f43Ssaggi-dw    /**
2985220f43Ssaggi-dw     * Set the ExitPattern
3085220f43Ssaggi-dw     */
3185220f43Ssaggi-dw    public function postConnect()
3285220f43Ssaggi-dw    {
3385220f43Ssaggi-dw        $this->Lexer->addExitPattern('</dwtimeline\b.*?>', 'plugin_dwtimeline_timeline');
3485220f43Ssaggi-dw    }
3585220f43Ssaggi-dw
3685220f43Ssaggi-dw    /**
3785220f43Ssaggi-dw     * Handle the match
384fa647deSsaggi-dw     * @param string $match The match of the syntax
394fa647deSsaggi-dw     * @param int $state The state of the handler
404fa647deSsaggi-dw     * @param int $pos The position in the document
414fa647deSsaggi-dw     * @param Doku_Handler $handler The handler
424fa647deSsaggi-dw     * @return array Data for the renderer
4385220f43Ssaggi-dw     */
4485220f43Ssaggi-dw    public function handle($match, $state, $pos, Doku_Handler $handler)
4585220f43Ssaggi-dw    {
4685220f43Ssaggi-dw        switch ($state) {
4785220f43Ssaggi-dw            case DOKU_LEXER_ENTER :
48*c78eb039Ssaggi-dw                parent::$align = $this->getConf('align');
4985220f43Ssaggi-dw                $match = trim(substr($match, 11,-1));// returns match between <dwtimeline(11) and >(-1)
50*c78eb039Ssaggi-dw                $data = $this->getTitleMatches($match);
51*c78eb039Ssaggi-dw                parent::$align = $data['align'];
5285220f43Ssaggi-dw                return array($state,$data);
5385220f43Ssaggi-dw            case DOKU_LEXER_UNMATCHED :
5485220f43Ssaggi-dw                return array ($state,$match);
5585220f43Ssaggi-dw            case DOKU_LEXER_EXIT :
5685220f43Ssaggi-dw                $match = trim(substr($match, 12,-1));//returns match between </dwtimeline(12) and >(-1)
57*c78eb039Ssaggi-dw                $data = $this->getTitleMatches($match);
5885220f43Ssaggi-dw                return array($state,$data);
5985220f43Ssaggi-dw        }
6085220f43Ssaggi-dw        return array();
6185220f43Ssaggi-dw    }
6285220f43Ssaggi-dw
6385220f43Ssaggi-dw    /**
644fa647deSsaggi-dw     * Create output
654fa647deSsaggi-dw     *
664fa647deSsaggi-dw     * @param string $mode string     output format being rendered
674fa647deSsaggi-dw     * @param Doku_Renderer $renderer the current renderer object
684fa647deSsaggi-dw     * @param array $data data created by handler()
694fa647deSsaggi-dw     * @return  boolean                 rendered correctly?
7085220f43Ssaggi-dw     */
7185220f43Ssaggi-dw    public function render($mode, Doku_Renderer $renderer, $data)
7285220f43Ssaggi-dw    {
7385220f43Ssaggi-dw        if ($mode == 'xhtml') {
74*c78eb039Ssaggi-dw            if (!parent::$direction) {parent::$direction = $this->GetDirection();}
7585220f43Ssaggi-dw            list($state,$indata) = $data;
7685220f43Ssaggi-dw            switch ($state) {
7785220f43Ssaggi-dw                case DOKU_LEXER_ENTER :
782ddb0813SSteffen Sagert                    $renderer->doc .= '<div class="dwtimeline">' . DOKU_LF;
79*c78eb039Ssaggi-dw                    if ($indata['align'] === 'horz') {$renderer->doc .= '<div class="timeline-' . $indata['align'] . '-line"></div>' . DOKU_LF;}
804ff971beSsaggi-dw                    $renderer->doc .= '<div class="timeline-' . $indata['align'] . '">' . DOKU_LF;
814ff971beSsaggi-dw                    if (isset($indata['title']) or isset($indata['description'])) {
8208c5c745SSteffen Sagert                        $renderer->doc .= '<div class="container-' . $indata['align'] . ' tl-top">' . DOKU_LF;
8308c5c745SSteffen Sagert                        $renderer->doc .= '<div class="tlcontent">' . DOKU_LF;
844ff971beSsaggi-dw                        if (isset($indata['title'])) {$renderer->doc .= '<div class="tltitle">' . $indata['title'] . '</div>' . DOKU_LF;}
852ddb0813SSteffen Sagert                        if (isset($indata['description'])) {$renderer->doc .= '<p>' . DOKU_LF.$indata['description'] . DOKU_LF . '</p>' .  DOKU_LF;}
8685220f43Ssaggi-dw                        $renderer->doc .= '</div>' . DOKU_LF;
8785220f43Ssaggi-dw                        $renderer->doc .= '</div>' . DOKU_LF;
8885220f43Ssaggi-dw                    }
8985220f43Ssaggi-dw                    break;
9085220f43Ssaggi-dw                case DOKU_LEXER_UNMATCHED :
914ff971beSsaggi-dw                    $renderer->doc .= $renderer->cdata($indata);
9285220f43Ssaggi-dw                    break;
9385220f43Ssaggi-dw                case DOKU_LEXER_EXIT :
944ff971beSsaggi-dw                    if (isset($indata['title']) or isset($indata['description'])) {
9508c5c745SSteffen Sagert                        $renderer->doc .= '<div class="container-' . $indata['align'] .' tl-bottom">' . DOKU_LF;
9608c5c745SSteffen Sagert                        $renderer->doc .= '<div class="tlcontent">' . DOKU_LF;
974ff971beSsaggi-dw                        if (isset($indata['title'])) {$renderer->doc .= '<div class="tltitle">' . $indata['title'] . '</div>' . DOKU_LF;}
984ff971beSsaggi-dw                        if (isset($indata['description'])) {$renderer->doc .= '<p>' . $indata['description'] . '</p>'. DOKU_LF;}
9985220f43Ssaggi-dw                        $renderer->doc .= '</div>' . DOKU_LF;
10085220f43Ssaggi-dw                        $renderer->doc .= '</div>' . DOKU_LF;
1012ddb0813SSteffen Sagert                        $renderer->doc .= '</div>' . DOKU_LF;
10285220f43Ssaggi-dw                    }
10385220f43Ssaggi-dw                    $renderer->doc .= '</div>' . DOKU_LF;
104*c78eb039Ssaggi-dw                    parent::$direction = 'tl-' . $this->getConf('direction');//Reset direction
10585220f43Ssaggi-dw                    break;
10685220f43Ssaggi-dw            }
10785220f43Ssaggi-dw            return true;
10885220f43Ssaggi-dw        }
10985220f43Ssaggi-dw        return false;
11085220f43Ssaggi-dw    }
11185220f43Ssaggi-dw
11285220f43Ssaggi-dw}
11385220f43Ssaggi-dw
114