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_cite 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('<cite.*?>(?=.*?</cite>)', $mode, 'plugin_blockquote_cite');
48    }
49
50    function postConnect() {
51        $this->Lexer->addExitPattern('</cite>', 'plugin_blockquote_cite');
52    }
53
54    function handle($match, $state, $pos, Doku_Handler $handler) {
55
56        switch ($state) {
57
58            case DOKU_LEXER_ENTER :
59                $source = trim(substr($match, 5, -1));
60                return array (
61                    $state,
62                    $source
63                );
64
65            case DOKU_LEXER_UNMATCHED :
66                return array (
67                    $state,
68                    $match
69                );
70
71            default :
72                return array (
73                    $state,
74                    ''
75                );
76        }
77    }
78
79    function render($mode, Doku_Renderer $renderer, $indata) {
80        if ($mode == 'xhtml') {
81
82            list ($state, $data) = $indata;
83
84            switch ($state) {
85                case DOKU_LEXER_ENTER :
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 .= '<cite '.$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 .= "</cite>";
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