1<?php
2/**
3 * DokuWiki Plugin scrollticker (Syntax Component)
4 *
5 * @license GPL 2 http://www.gnu.org/licenses/gpl-2.0.html
6 * @author  medmen <med-men@gmx.net>
7 * @author Michael Bohn <mjbohn@gmail.com>
8 */
9
10// must be run within Dokuwiki
11if (!defined('DOKU_INC')) die();
12
13class syntax_plugin_scrollticker extends DokuWiki_Syntax_Plugin {
14    /**
15     * @return string Syntax mode type
16     */
17    public function getType() {
18        return 'protected';
19    }
20
21    function getAllowedTypes() {
22        return array('container','substition','protected','disabled','formatting','paragraphs');
23    }
24
25    /**
26     * @return string Paragraph type
27     */
28    public function getPType() {
29        return 'block';
30    }
31    /**
32     * @return int Sort order - Low numbers go before high numbers
33     */
34    public function getSort() {
35        return 201;
36    }
37
38    /**
39     * Connect lookup pattern to lexer.
40     *
41     * @param string $mode Parser mode
42     */
43    public function connectTo($mode) {
44        $this->Lexer->addEntryPattern('<scrollticker>(?=.*?</scrollticker>)',$mode,'plugin_scrollticker');
45    }
46
47    public function postConnect() {
48        $this->Lexer->addExitPattern('</scrollticker>','plugin_scrollticker');
49    }
50
51
52    /**
53     * Handle matches of the scrollticker syntax
54     *
55     * @param string          $match   The match of the syntax
56     * @param int             $state   The state of the handler
57     * @param int             $pos     The position in the document
58     * @param Doku_Handler    $handler The handler
59     * @return array Data for the renderer
60     */
61    public function handle($match, $state, $pos, Doku_Handler $handler){
62        return array($state, $match);
63    }
64
65    /**
66     * Render xhtml output or metadata
67     *
68     * @param string         $mode      Renderer mode (supported modes: xhtml)
69     * @param Doku_Renderer  $renderer  The renderer
70     * @param array          $data      The data from the handler() function
71     * @return bool If rendering was successful.
72     */
73    public function render($mode, Doku_Renderer $renderer, $data) {
74        if($mode != 'xhtml') return false;
75        list($state, $match) = $data;
76        switch ($state) {
77            case DOKU_LEXER_ENTER :
78                $renderer->doc .= '<div class="ui-newsticker">';
79                break;
80            case DOKU_LEXER_UNMATCHED :
81                $renderer->doc .= $renderer->_xmlEntities($match);
82                break;
83            case DOKU_LEXER_EXIT :
84                $renderer->doc .= '</div>';
85                break;
86            default:
87                $renderer->doc.= 'MATCH: '.$renderer->_xmlEntities($match);
88                $renderer->doc.= 'STATE: '.$renderer->_xmlEntities($state);
89        }
90
91        // $renderer->doc .= var_export($data, true); // might be helpful when debugging
92        return true;
93    }
94}
95
96// vim:ts=4:sw=4:et: