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