1<?php 2/** 3 * BBCode plugin: allows BBCode markup familiar from forum software 4 * 5 * @license GPL 2 (http://www.gnu.org/licenses/gpl.html) 6 * @author Esther Brunner <esther@kaffeehaus.ch> 7 */ 8 9if(!defined('DOKU_INC')) define('DOKU_INC',realpath(dirname(__FILE__).'/../../').'/'); 10if(!defined('DOKU_PLUGIN')) define('DOKU_PLUGIN',DOKU_INC.'lib/plugins/'); 11require_once(DOKU_PLUGIN.'syntax.php'); 12 13/** 14 * All DokuWiki plugins to extend the parser/rendering mechanism 15 * need to inherit from this class 16 */ 17class syntax_plugin_bbcode_quote extends DokuWiki_Syntax_Plugin { 18 19 function getType() { return 'container'; } 20 function getPType() { return 'block'; } 21 function getAllowedTypes() { return array('formatting', 'substition', 'disabled', 'protected'); } 22 function getSort() { return 105; } 23 function connectTo($mode) { $this->Lexer->addEntryPattern('\[quote.*?\](?=.*?\x5B/quote\x5D)',$mode,'plugin_bbcode_quote'); } 24 function postConnect() { $this->Lexer->addExitPattern('\[/quote\]','plugin_bbcode_quote'); } 25 26 /** 27 * Handle the match 28 */ 29 function handle($match, $state, $pos, Doku_Handler $handler) { 30 switch ($state) { 31 case DOKU_LEXER_ENTER : 32 $match = explode('"',substr($match, 6, -1)); 33 return array($state, $match[1]); 34 35 case DOKU_LEXER_UNMATCHED : 36 return array($state, $match); 37 38 case DOKU_LEXER_EXIT : 39 return array($state, ''); 40 41 } 42 return array(); 43 } 44 45 /** 46 * Create output 47 */ 48 function render($mode, Doku_Renderer $renderer, $data) { 49 if($mode == 'xhtml') { 50 list($state, $match) = $data; 51 switch ($state) { 52 case DOKU_LEXER_ENTER : 53 if ($match !== '') $renderer->doc .= '<p><sub>'.$match.':</sub></p>'; 54 $renderer->doc .= '<blockquote>'; 55 break; 56 57 case DOKU_LEXER_UNMATCHED : 58 $match = $renderer->_xmlEntities($match); 59 $renderer->doc .= str_replace("\n",'<br />',$match); 60 break; 61 62 case DOKU_LEXER_EXIT : 63 $renderer->doc .= '</blockquote>'; 64 break; 65 66 } 67 return true; 68 } 69 return false; 70 } 71 72} 73// vim:ts=4:sw=4:et:enc=utf-8: 74