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
12// must be run within Dokuwiki
13if(!defined('DOKU_INC')) die();
14
15if(!defined('DOKU_PLUGIN')) define('DOKU_PLUGIN',DOKU_INC.'lib/plugins/');
16require_once (DOKU_PLUGIN . 'syntax.php');
17
18class syntax_plugin_blockquote_q extends DokuWiki_Syntax_Plugin {
19
20    function getType() {
21        return 'formatting';
22    }
23
24    function getPType() {
25        return 'normal';
26    }
27
28    function getAllowedTypes() {
29        return array (
30            'substition',
31            'formatting',
32            'disabled',
33        );
34    }
35
36    function getSort() {
37        return 123;
38    }
39
40    function accepts($mode) {
41        if ($mode == substr(get_class($this), 7))
42            return true;
43        return parent :: accepts($mode);
44    }
45
46    function connectTo($mode) {
47        $this->Lexer->addEntryPattern('<q.*?>(?=.*?</q>)', $mode, 'plugin_blockquote_q');
48        $this->Lexer->addEntryPattern('<quote.*?>(?=.*?</quote>)', $mode, 'plugin_blockquote_q');
49    }
50
51    function postConnect() {
52        $this->Lexer->addExitPattern('</q>', 'plugin_blockquote_q');
53        $this->Lexer->addExitPattern('</quote>', 'plugin_blockquote_q');
54    }
55
56    function handle($match, $state, $pos, Doku_Handler $handler) {
57
58        switch ($state) {
59
60            case DOKU_LEXER_ENTER :
61                $source = trim(substr($match,strpos($match,' '),-1));
62                return array (
63                    $state,
64                    $source
65                );
66
67            case DOKU_LEXER_UNMATCHED :
68                return array (
69                    $state,
70                    $match
71                );
72
73            default :
74                return array (
75                    $state,
76                    ''
77                );
78        }
79    }
80
81    function render($mode, Doku_Renderer $renderer, $indata) {
82        if ($mode == 'xhtml') {
83
84            list ($state, $data) = $indata;
85
86            switch ($state) {
87                case DOKU_LEXER_ENTER :
88                    $pluginClass = ($this->getConf('addStyling')) ? 'blockquote-plugin' : '';
89                    $attr = '';
90                    if (($data && strlen($data) > 0) && !plugin_isdisabled('wrap')) {
91                        // get attributes from wrap helper plugin (if installed)
92                        $wrap =& plugin_load('helper', 'wrap');
93                        $attr = $wrap->buildAttributes($data, $pluginClass);
94                    } else if ($pluginClass) {
95                        $attr = 'class="'.$pluginClass.'"';
96                    }
97
98                    $renderer->doc .= '<q '.$attr.'>';
99                    break;
100
101                case DOKU_LEXER_UNMATCHED :
102                    $renderer->doc .= $renderer->_xmlEntities($data);
103                    break;
104
105                case DOKU_LEXER_EXIT :
106                    $renderer->doc .= "</q>";
107                    break;
108            }
109            return true;
110        }
111
112        // unsupported $mode
113        return false;
114    }
115}
116
117//Setup VIM: ex: et ts=4 enc=utf-8 :
118