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_q 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('<q.*?>(?=.*?</q>)', $mode, 'plugin_blockquote_q'); 42 $this->Lexer->addEntryPattern('<quote.*?>(?=.*?</quote>)', $mode, 'plugin_blockquote_q'); 43 } 44 45 function postConnect() { 46 $this->Lexer->addExitPattern('</q>', 'plugin_blockquote_q'); 47 $this->Lexer->addExitPattern('</quote>', 'plugin_blockquote_q'); 48 } 49 50 function handle($match, $state, $pos, Doku_Handler $handler) { 51 52 switch ($state) { 53 54 case DOKU_LEXER_ENTER : 55 $source = trim(substr($match,strpos($match,' '),-1)); 56 return array ( 57 $state, 58 $source 59 ); 60 61 case DOKU_LEXER_UNMATCHED : 62 return array ( 63 $state, 64 $match 65 ); 66 67 default : 68 return array ( 69 $state, 70 '' 71 ); 72 } 73 } 74 75 function render($mode, Doku_Renderer $renderer, $indata) { 76 if ($mode == 'xhtml') { 77 78 list ($state, $data) = $indata; 79 80 switch ($state) { 81 case DOKU_LEXER_ENTER : 82 $pluginClass = ($this->getConf('addStyling')) ? 'blockquote-plugin' : ''; 83 $attr = ''; 84 if (($data && strlen($data) > 0) && !plugin_isdisabled('wrap')) { 85 // get attributes from wrap helper plugin (if installed) 86 $wrap =& plugin_load('helper', 'wrap'); 87 $attr = $wrap->buildAttributes($data, $pluginClass); 88 } else if ($pluginClass) { 89 $attr = 'class="'.$pluginClass.'"'; 90 } 91 92 $renderer->doc .= '<q '.$attr.'>'; 93 break; 94 95 case DOKU_LEXER_UNMATCHED : 96 $renderer->doc .= $renderer->_xmlEntities($data); 97 break; 98 99 case DOKU_LEXER_EXIT : 100 $renderer->doc .= "</q>"; 101 break; 102 } 103 return true; 104 } 105 106 // unsupported $mode 107 return false; 108 } 109} 110 111//Setup VIM: ex: et ts=4 enc=utf-8 : 112