1<?php
2/**
3 * Blockquote Plugin
4 *
5 * Allows correctly formatted blockquotes
6 *
7 * @license GPL 2 (http://www.gnu.org/licenses/gpl.html)
8 * @author  Gina Haeussge <osd@foosel.net>
9 * @author  Anika Henke <anika@selfthinker.org>
10 */
11
12class syntax_plugin_blockquote_blockquote extends DokuWiki_Syntax_Plugin {
13
14    function getType() {
15        return 'container';
16    }
17
18    function getPType() {
19        return 'stack';
20    }
21
22    function getAllowedTypes() {
23        return array (
24            'container',
25            'substition',
26            'protected',
27            'disabled',
28            'formatting',
29            'paragraphs'
30        );
31    }
32
33    function getSort() {
34        return 123;
35    }
36
37    function accepts($mode) {
38        if ($mode == substr(get_class($this), 7))
39            return true;
40        return parent :: accepts($mode);
41    }
42
43    function connectTo($mode) {
44        $this->Lexer->addEntryPattern('<blockquote.*?>(?=.*?</blockquote>)', $mode, 'plugin_blockquote_blockquote');
45        $this->Lexer->addEntryPattern('<QUOTE.*?>(?=.*?</QUOTE>)', $mode, 'plugin_blockquote_blockquote');
46    }
47
48    function postConnect() {
49        $this->Lexer->addExitPattern('</blockquote>', 'plugin_blockquote_blockquote');
50        $this->Lexer->addExitPattern('</QUOTE>', 'plugin_blockquote_blockquote');
51    }
52
53    function handle($match, $state, $pos, Doku_Handler $handler) {
54
55        switch ($state) {
56
57            case DOKU_LEXER_ENTER :
58                $source = trim(substr($match,strpos($match,' '),-1));
59                return array (
60                    $state,
61                    $source
62                );
63
64            case DOKU_LEXER_UNMATCHED :
65                return array (
66                    $state,
67                    $match
68                );
69
70            default :
71                return array (
72                    $state,
73                    ''
74                );
75        }
76    }
77
78    function render($mode, Doku_Renderer $renderer, $indata) {
79        if ($mode == 'xhtml') {
80
81            list ($state, $data) = $indata;
82
83            switch ($state) {
84                case DOKU_LEXER_ENTER :
85
86                    $pluginClass = ($this->getConf('addStyling')) ? 'blockquote-plugin' : '';
87                    $attr = '';
88                    if (($data && strlen($data) > 0) && !plugin_isdisabled('wrap')) {
89                        // get attributes from wrap helper plugin (if installed)
90                        $wrap =& plugin_load('helper', 'wrap');
91                        $attr = $wrap->buildAttributes($data, $pluginClass);
92                    } else if ($pluginClass) {
93                        $attr = 'class="'.$pluginClass.'"';
94                    }
95
96                    $renderer->doc .= '<blockquote '.$attr.'>';
97                    break;
98
99                case DOKU_LEXER_UNMATCHED :
100                    $renderer->doc .= $renderer->_xmlEntities($data);
101                    break;
102
103                case DOKU_LEXER_EXIT :
104                    $renderer->doc .= "\n</blockquote>";
105                    break;
106            }
107            return true;
108        }
109
110        // unsupported $mode
111        return false;
112    }
113}
114
115//Setup VIM: ex: et ts=4 enc=utf-8 :
116