xref: /plugin/dwtimeline/syntax/milestone.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_milestone extends syntax_plugin_dwtimeline_dwtimeline
1085220f43Ssaggi-dw{
1185220f43Ssaggi-dw    /** @inheritDoc */
1285220f43Ssaggi-dw    public function getType()
1385220f43Ssaggi-dw    {
142ddb0813SSteffen Sagert        return 'plugin_dwtimeline_milestone';
1585220f43Ssaggi-dw    }
1685220f43Ssaggi-dw
172ddb0813SSteffen Sagert    function accepts($mode) {
182ddb0813SSteffen Sagert        if ($mode == "plugin_dwtimeline_timeline") return true;
192ddb0813SSteffen Sagert        return parent::accepts($mode);
2085220f43Ssaggi-dw    }
2185220f43Ssaggi-dw
2285220f43Ssaggi-dw    /**
2385220f43Ssaggi-dw     * @return array Things that may be inside the syntax
2485220f43Ssaggi-dw     */
2585220f43Ssaggi-dw    function getAllowedTypes() {
2685220f43Ssaggi-dw        return array('container', 'formatting', 'substition', 'protected', 'disabled', 'paragraphs');
2785220f43Ssaggi-dw    }
2885220f43Ssaggi-dw
2985220f43Ssaggi-dw    /**
3085220f43Ssaggi-dw     * Set the EntryPattern
314fa647deSsaggi-dw     * @param string $mode
3285220f43Ssaggi-dw     */
3385220f43Ssaggi-dw    public function connectTo($mode)
3485220f43Ssaggi-dw    {
352ddb0813SSteffen Sagert        $this->Lexer->addEntryPattern('<milestone\b.*?>(?=.*?</milestone>)',$mode,'plugin_dwtimeline_milestone');
3608c5c745SSteffen Sagert    }
3785220f43Ssaggi-dw
3885220f43Ssaggi-dw    /**
3985220f43Ssaggi-dw     * Set the ExitPattern
4085220f43Ssaggi-dw     */
4185220f43Ssaggi-dw    public function postConnect()
4285220f43Ssaggi-dw    {
4385220f43Ssaggi-dw        $this->Lexer->addExitPattern('</milestone>', 'plugin_dwtimeline_milestone');
4485220f43Ssaggi-dw    }
4585220f43Ssaggi-dw
4685220f43Ssaggi-dw    /**
4785220f43Ssaggi-dw     * Handle the match
484fa647deSsaggi-dw     * @param string $match The match of the syntax
494fa647deSsaggi-dw     * @param int $state The state of the handler
504fa647deSsaggi-dw     * @param int $pos The position in the document
514fa647deSsaggi-dw     * @param Doku_Handler $handler The handler
524fa647deSsaggi-dw     * @return array Data for the renderer
5385220f43Ssaggi-dw     */
5485220f43Ssaggi-dw    public function handle($match, $state, $pos, Doku_Handler $handler)
5585220f43Ssaggi-dw    {
5685220f43Ssaggi-dw        switch ($state) {
5785220f43Ssaggi-dw            case DOKU_LEXER_ENTER :
5885220f43Ssaggi-dw                $match = trim(substr($match, 10,-1));// returns match between <milestone(10) and >(-1)
59*c78eb039Ssaggi-dw                $data = $this->getTitleMatches($match);
60*c78eb039Ssaggi-dw                $data['align'] = parent::$align;
6185220f43Ssaggi-dw                return array($state,$data);
6285220f43Ssaggi-dw            case DOKU_LEXER_UNMATCHED :
6385220f43Ssaggi-dw                return array($state,$match);
6485220f43Ssaggi-dw            case DOKU_LEXER_EXIT :
6585220f43Ssaggi-dw                return array($state,'');
6685220f43Ssaggi-dw        }
6785220f43Ssaggi-dw        return array();
6885220f43Ssaggi-dw    }
6985220f43Ssaggi-dw
7085220f43Ssaggi-dw    /**
714fa647deSsaggi-dw     * Create output
724fa647deSsaggi-dw     *
734fa647deSsaggi-dw     * @param string $mode string     output format being rendered
744fa647deSsaggi-dw     * @param Doku_Renderer $renderer the current renderer object
754fa647deSsaggi-dw     * @param array $data data created by handler()
764fa647deSsaggi-dw     * @return  boolean                 rendered correctly?
7785220f43Ssaggi-dw     */
7885220f43Ssaggi-dw    public function render($mode, Doku_Renderer $renderer, $data)
7985220f43Ssaggi-dw    {
8085220f43Ssaggi-dw        if ($mode == 'xhtml') {
81*c78eb039Ssaggi-dw            if (!parent::$direction) {parent::$direction = $this->GetDirection();}
8285220f43Ssaggi-dw            list($state,$indata) = $data;
8385220f43Ssaggi-dw            switch ($state) {
8485220f43Ssaggi-dw                case DOKU_LEXER_ENTER :
85*c78eb039Ssaggi-dw                    $renderer->doc .= '<div class="container-' . $indata['align'] . ' ' . parent::$direction . '"' . $indata['data'] . $indata['style'] . '>' . DOKU_LF;
8608c5c745SSteffen Sagert                    $renderer->doc .= '<div class="tlcontent">'. DOKU_LF;
874ff971beSsaggi-dw                    if (isset($indata['title'])) {
884ff971beSsaggi-dw                        if (isset($indata['link'])) {
894ff971beSsaggi-dw                            $renderer->doc .= '<div class="mstitle">' . $this->render_text('[[' . $indata['link'] . '|' . $indata['title'] . ']]') . '</div>' . DOKU_LF;
9085220f43Ssaggi-dw                        } else {
914ff971beSsaggi-dw                            $renderer->doc .= '<div class="mstitle">' . $indata['title'] . '</div>' . DOKU_LF;
9285220f43Ssaggi-dw                        }
9385220f43Ssaggi-dw                    }
944ff971beSsaggi-dw                    if (isset($indata['description'])) {$renderer->doc .= '<div class="msdesc">'  .$indata['description'] . '</div>' . DOKU_LF;}
9585220f43Ssaggi-dw                    break;
9685220f43Ssaggi-dw                case DOKU_LEXER_UNMATCHED :
974ff971beSsaggi-dw                    $renderer->doc .= $renderer->cdata($indata);
9885220f43Ssaggi-dw                    break;
9985220f43Ssaggi-dw                case DOKU_LEXER_EXIT :
10085220f43Ssaggi-dw                    $renderer->doc .= '</div>' . DOKU_LF;
10185220f43Ssaggi-dw                    $renderer->doc .= '</div>' . DOKU_LF;
102*c78eb039Ssaggi-dw                    parent::$direction = $this->ChangeDirection(parent::$direction);
10385220f43Ssaggi-dw                    break;
10485220f43Ssaggi-dw            }
10585220f43Ssaggi-dw            return true;
10685220f43Ssaggi-dw        }
10785220f43Ssaggi-dw        return false;
10885220f43Ssaggi-dw    }
10985220f43Ssaggi-dw
11085220f43Ssaggi-dw}
11185220f43Ssaggi-dw
112