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