xref: /plugin/dwtimeline/syntax/timeline.php (revision 2ddb08133455a704c2504f3e47df3918c5412eaf)
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
94ff971beSsaggi-dw// must be run within Dokuwiki
104ff971beSsaggi-dwif(!defined('DOKU_INC')) die();
114ff971beSsaggi-dw
1285220f43Ssaggi-dwclass syntax_plugin_dwtimeline_timeline extends \dokuwiki\Extension\SyntaxPlugin
1385220f43Ssaggi-dw{
1485220f43Ssaggi-dw
1585220f43Ssaggi-dw    /** @inheritDoc */
1685220f43Ssaggi-dw    public function getType()
1785220f43Ssaggi-dw    {
1885220f43Ssaggi-dw        return 'substition';
1985220f43Ssaggi-dw    }
2085220f43Ssaggi-dw
2185220f43Ssaggi-dw    /** @inheritDoc */
2285220f43Ssaggi-dw    public function getPType()
2385220f43Ssaggi-dw    {
2485220f43Ssaggi-dw        return 'stack';
2585220f43Ssaggi-dw    }
2685220f43Ssaggi-dw
2785220f43Ssaggi-dw    /** @inheritDoc */
2885220f43Ssaggi-dw    public function getSort()
2985220f43Ssaggi-dw    {
30*2ddb0813SSteffen Sagert        return 400;
3185220f43Ssaggi-dw    }
3285220f43Ssaggi-dw
33*2ddb0813SSteffen Sagert
3485220f43Ssaggi-dw    /**
3585220f43Ssaggi-dw     * @return array Things that may be inside the syntax
3685220f43Ssaggi-dw     */
3785220f43Ssaggi-dw    function getAllowedTypes() {
38*2ddb0813SSteffen Sagert        return array('plugin_dwtimeline_milestone');
3985220f43Ssaggi-dw    }
4085220f43Ssaggi-dw
4185220f43Ssaggi-dw    /**
4285220f43Ssaggi-dw     * Set the EntryPattern
4385220f43Ssaggi-dw     * @param type $mode
4485220f43Ssaggi-dw     */
4585220f43Ssaggi-dw    public function connectTo($mode)
4685220f43Ssaggi-dw    {
47*2ddb0813SSteffen Sagert        $this->Lexer->addEntryPattern('<dwtimeline\b.*?>(?=.*?</dwtimeline\b.*?>)',$mode,'plugin_dwtimeline_timeline');
4885220f43Ssaggi-dw    }
4985220f43Ssaggi-dw
5085220f43Ssaggi-dw    /**
5185220f43Ssaggi-dw     * Set the ExitPattern
5285220f43Ssaggi-dw     */
5385220f43Ssaggi-dw    public function postConnect()
5485220f43Ssaggi-dw    {
5585220f43Ssaggi-dw        $this->Lexer->addExitPattern('</dwtimeline\b.*?>', 'plugin_dwtimeline_timeline');
5685220f43Ssaggi-dw    }
5785220f43Ssaggi-dw
5885220f43Ssaggi-dw    /**
5985220f43Ssaggi-dw     * Handle the match
6085220f43Ssaggi-dw     * @param type $match
6185220f43Ssaggi-dw     * @param type $state
6285220f43Ssaggi-dw     * @param type $pos
6385220f43Ssaggi-dw     * @param Doku_Handler $handler
6485220f43Ssaggi-dw     * @return type
6585220f43Ssaggi-dw     */
6685220f43Ssaggi-dw    public function handle($match, $state, $pos, Doku_Handler $handler)
6785220f43Ssaggi-dw    {
6885220f43Ssaggi-dw        $data = [];
6985220f43Ssaggi-dw        switch ($state) {
7085220f43Ssaggi-dw            case DOKU_LEXER_ENTER :
714ff971beSsaggi-dw                global $align;
724ff971beSsaggi-dw                $align = $this->getConf('align');
7385220f43Ssaggi-dw                $match = trim(substr($match, 11,-1));// returns match between <dwtimeline(11) and >(-1)
7485220f43Ssaggi-dw                $data = helper_plugin_dwtimeline::getTitleMatches($match);
75*2ddb0813SSteffen Sagert                $align = $data['align'];
7685220f43Ssaggi-dw                return array($state,$data);
7785220f43Ssaggi-dw            case DOKU_LEXER_UNMATCHED :
7885220f43Ssaggi-dw                return array ($state,$match);
7985220f43Ssaggi-dw            case DOKU_LEXER_EXIT :
8085220f43Ssaggi-dw                $match = trim(substr($match, 12,-1));//returns match between </dwtimeline(12) and >(-1)
8185220f43Ssaggi-dw                $data = helper_plugin_dwtimeline::getTitleMatches($match);
8285220f43Ssaggi-dw                return array($state,$data);
8385220f43Ssaggi-dw        }
8485220f43Ssaggi-dw        return array();
8585220f43Ssaggi-dw    }
8685220f43Ssaggi-dw
8785220f43Ssaggi-dw    /**
8885220f43Ssaggi-dw     * Render Function
8985220f43Ssaggi-dw     * @param type $mode
9085220f43Ssaggi-dw     * @param Doku_Renderer $renderer
9185220f43Ssaggi-dw     * @param type $data
9285220f43Ssaggi-dw     * @return boolean
9385220f43Ssaggi-dw     */
9485220f43Ssaggi-dw    public function render($mode, Doku_Renderer $renderer, $data)
9585220f43Ssaggi-dw    {
9685220f43Ssaggi-dw        if ($mode == 'xhtml') {
9785220f43Ssaggi-dw            global $direction;
9808c5c745SSteffen Sagert            if (!$direction) {$direction='tl-'.$this->getConf('direction');}
9985220f43Ssaggi-dw            list($state,$indata) = $data;
10085220f43Ssaggi-dw            switch ($state) {
10185220f43Ssaggi-dw                case DOKU_LEXER_ENTER :
102*2ddb0813SSteffen Sagert                    $renderer->doc .= '<div class="dwtimeline">'. DOKU_LF;
1034ff971beSsaggi-dw                    if ($indata['align'] === 'horz'){$renderer->doc .= '<div class="timeline-'.$indata['align'].'-line"></div>'. DOKU_LF;};
1044ff971beSsaggi-dw                    $renderer->doc .= '<div class="timeline-'.$indata['align'].'">'. DOKU_LF;
1054ff971beSsaggi-dw                    if (isset($indata['title']) or isset($indata['description'])) {
10608c5c745SSteffen Sagert                        $renderer->doc .= '<div class="container-'.$indata['align'].' tl-top">'. DOKU_LF;
10708c5c745SSteffen Sagert                        $renderer->doc .= '<div class="tlcontent">'. DOKU_LF;
1084ff971beSsaggi-dw                        if (isset($indata['title'])) {$renderer->doc .= '<div class="tltitle">'.$indata['title'].'</div>'. DOKU_LF;}
109*2ddb0813SSteffen Sagert                        if (isset($indata['description'])) {$renderer->doc .= '<p>'. DOKU_LF.$indata['description']. DOKU_LF.'</p>'. DOKU_LF;}
11085220f43Ssaggi-dw                        $renderer->doc .= '</div>'. DOKU_LF;
11185220f43Ssaggi-dw                        $renderer->doc .= '</div>'. DOKU_LF;
11285220f43Ssaggi-dw                    }
11385220f43Ssaggi-dw                    break;
11485220f43Ssaggi-dw                case DOKU_LEXER_UNMATCHED :
1154ff971beSsaggi-dw                    $renderer->doc .= $renderer->cdata($indata);
11685220f43Ssaggi-dw                    break;
11785220f43Ssaggi-dw                case DOKU_LEXER_EXIT :
1184ff971beSsaggi-dw                    if (isset($indata['title']) or isset($indata['description'])) {
11908c5c745SSteffen Sagert                        $renderer->doc .= '<div class="container-'.$indata['align'].' tl-bottom">'. DOKU_LF;
12008c5c745SSteffen Sagert                        $renderer->doc .= '<div class="tlcontent">'. DOKU_LF;
1214ff971beSsaggi-dw                        if (isset($indata['title'])) {$renderer->doc .= '<div class="tltitle">'.$indata['title'].'</div>'. DOKU_LF;}
1224ff971beSsaggi-dw                        if (isset($indata['description'])) {$renderer->doc .= '<p>'.$indata['description'].'</p>'. DOKU_LF;}
12385220f43Ssaggi-dw                        $renderer->doc .= '</div>'. DOKU_LF;
12485220f43Ssaggi-dw                        $renderer->doc .= '</div>'. DOKU_LF;
125*2ddb0813SSteffen Sagert                        $renderer->doc .= '</div>'. DOKU_LF;
12685220f43Ssaggi-dw                    }
12785220f43Ssaggi-dw                    $renderer->doc .= '</div>'. DOKU_LF;
12808c5c745SSteffen Sagert                    $direction='tl-'.$this->getConf('direction');//Reset direction
12985220f43Ssaggi-dw                    break;
13085220f43Ssaggi-dw            }
13185220f43Ssaggi-dw            return true;
13285220f43Ssaggi-dw        }
13385220f43Ssaggi-dw        return false;
13485220f43Ssaggi-dw    }
13585220f43Ssaggi-dw
13685220f43Ssaggi-dw}
13785220f43Ssaggi-dw
138