1<?php
2if(!defined('DOKU_INC')) define('DOKU_INC',realpath(dirname(__FILE__).'/../../').'/');
3if(!defined('DOKU_PLUGIN')) define('DOKU_PLUGIN',DOKU_INC.'lib/plugins/');
4require_once(DOKU_PLUGIN.'syntax.php');
5
6class syntax_plugin_bbcodeextensions_q extends DokuWiki_Syntax_Plugin {
7
8    function getType() { return 'formatting'; }
9    function getPType() { return 'normal'; }
10    function getAllowedTypes() { return array('formatting', 'disabled'); }
11    function getSort() { return 220; }
12    function connectTo($mode){
13        $this->Lexer->addSpecialPattern('\[q.+?\[/q\]', $mode, 'plugin_bbcodeextensions_q');
14    }
15
16    function handle($match, $state, $pos, Doku_Handler $handler) {
17		$match= trim(substr($match, 2, -4));
18		$arr= explode(']', $match, 2);
19		foreach ($arr as &$a) { $a= trim($a); }
20		if (preg_match('/^cite=".+?"/', $arr[0])) {
21			//$arr[0]= substr($arr[0], 5,-1);
22		} else $arr[0]= '';
23		$match= $arr;
24        switch ($state) {
25          case DOKU_LEXER_ENTER :
26            return array($state, $match);
27
28          case DOKU_LEXER_UNMATCHED :
29            return array($state, $match);
30
31          case DOKU_LEXER_EXIT :
32            return array($state, '');
33
34           case DOKU_LEXER_SPECIAL :
35			return array($state, $match);
36
37        }
38        return array();
39    }
40
41	function render($mode, Doku_Renderer $renderer, $data) {
42		list ($state, $match) = $data;
43		switch ($state) {
44			case DOKU_LEXER_ENTER :
45			break;
46
47			//case DOKU_LEXER_UNMATCHED :
48			case DOKU_LEXER_SPECIAL :
49			if(in_array($mode, ['xhtml', 's5'], true)) {
50				//$match= $renderer->_xmlEntities($match);
51				//$renderer->doc .= print_r($match,true);
52				$match[1]= $renderer->_xmlEntities($match[1]);
53				$renderer->doc.= <<<EOF
54<q {$match[0]}> {$match[1]} </q>
55EOF
56;
57			} else {
58				$renderer->doc .= $match;
59			}
60
61			break;
62
63			case DOKU_LEXER_EXIT:
64			break;
65
66		}
67        return false;
68    }
69}
70