1<?php 2/** 3 * Renderer output base class 4 * 5 * @author Harry Fuecks <hfuecks@gmail.com> 6 * @author Andreas Gohr <andi@splitbrain.org> 7 */ 8if(!defined('DOKU_INC')) die('meh.'); 9require_once DOKU_INC . 'inc/pluginutils.php'; 10 11/** 12 * An empty renderer, produces no output 13 * 14 * Inherits from DokuWiki_Plugin for giving additional functions to render plugins 15 */ 16class Doku_Renderer extends DokuWiki_Plugin { 17 var $info = array( 18 'cache' => true, // may the rendered result cached? 19 'toc' => true, // render the TOC? 20 ); 21 22 var $doc = ''; 23 24 // keep some config options 25 var $acronyms = array(); 26 var $smileys = array(); 27 var $badwords = array(); 28 var $entities = array(); 29 var $interwiki = array(); 30 31 // allows renderer to be used again, clean out any per-use values 32 function reset() { 33 } 34 35 function nocache() { 36 $this->info['cache'] = false; 37 } 38 39 function notoc() { 40 $this->info['toc'] = false; 41 } 42 43 /** 44 * Returns the format produced by this renderer. 45 * 46 * Has to be overidden by decendend classes 47 */ 48 function getFormat(){ 49 trigger_error('getFormat() not implemented in '.get_class($this), E_USER_WARNING); 50 } 51 52 /** 53 * Allow the plugin to prevent DokuWiki from reusing an instance 54 * 55 * @return bool false if the plugin has to be instantiated 56 */ 57 function isSingleton() { 58 return false; 59 } 60 61 /** 62 * handle plugin rendering 63 * 64 * @param string $name Plugin name 65 * @param mixed $data custom data set by handler 66 * @param string $state matched state if any 67 * @param string $match raw matched syntax 68 */ 69 function plugin($name,$data,$state='',$match=''){ 70 $plugin = plugin_load('syntax',$name); 71 if($plugin != null){ 72 $plugin->render($this->getFormat(),$this,$data); 73 } 74 } 75 76 /** 77 * handle nested render instructions 78 * this method (and nest_close method) should not be overloaded in actual renderer output classes 79 */ 80 function nest($instructions) { 81 82 foreach ( $instructions as $instruction ) { 83 // execute the callback against ourself 84 if (method_exists($this,$instruction[0])) { 85 call_user_func_array(array($this, $instruction[0]), $instruction[1] ? $instruction[1] : array()); 86 } 87 } 88 } 89 90 // dummy closing instruction issued by Doku_Handler_Nest, normally the syntax mode should 91 // override this instruction when instantiating Doku_Handler_Nest - however plugins will not 92 // be able to - as their instructions require data. 93 function nest_close() {} 94 95 function document_start() {} 96 97 function document_end() {} 98 99 function render_TOC() { return ''; } 100 101 function toc_additem($id, $text, $level) {} 102 103 function header($text, $level, $pos) {} 104 105 function section_open($level) {} 106 107 function section_close() {} 108 109 function cdata($text) {} 110 111 function p_open() {} 112 113 function p_close() {} 114 115 function linebreak() {} 116 117 function hr() {} 118 119 function strong_open() {} 120 121 function strong_close() {} 122 123 function emphasis_open() {} 124 125 function emphasis_close() {} 126 127 function underline_open() {} 128 129 function underline_close() {} 130 131 function monospace_open() {} 132 133 function monospace_close() {} 134 135 function subscript_open() {} 136 137 function subscript_close() {} 138 139 function superscript_open() {} 140 141 function superscript_close() {} 142 143 function deleted_open() {} 144 145 function deleted_close() {} 146 147 function footnote_open() {} 148 149 function footnote_close() {} 150 151 function listu_open() {} 152 153 function listu_close() {} 154 155 function listo_open() {} 156 157 function listo_close() {} 158 159 function listitem_open($level) {} 160 161 function listitem_close() {} 162 163 function listcontent_open() {} 164 165 function listcontent_close() {} 166 167 function unformatted($text) {} 168 169 function php($text) {} 170 171 function phpblock($text) {} 172 173 function html($text) {} 174 175 function htmlblock($text) {} 176 177 function preformatted($text) {} 178 179 function quote_open() {} 180 181 function quote_close() {} 182 183 function file($text, $lang = null, $file = null ) {} 184 185 function code($text, $lang = null, $file = null ) {} 186 187 function acronym($acronym) {} 188 189 function smiley($smiley) {} 190 191 function wordblock($word) {} 192 193 function entity($entity) {} 194 195 // 640x480 ($x=640, $y=480) 196 function multiplyentity($x, $y) {} 197 198 function singlequoteopening() {} 199 200 function singlequoteclosing() {} 201 202 function apostrophe() {} 203 204 function doublequoteopening() {} 205 206 function doublequoteclosing() {} 207 208 // $link like 'SomePage' 209 function camelcaselink($link) {} 210 211 function locallink($hash, $name = null) {} 212 213 // $link like 'wiki:syntax', $title could be an array (media) 214 function internallink($link, $title = null) {} 215 216 // $link is full URL with scheme, $title could be an array (media) 217 function externallink($link, $title = null) {} 218 219 function rss ($url,$params) {} 220 221 // $link is the original link - probably not much use 222 // $wikiName is an indentifier for the wiki 223 // $wikiUri is the URL fragment to append to some known URL 224 function interwikilink($link, $title = null, $wikiName, $wikiUri) {} 225 226 // Link to file on users OS, $title could be an array (media) 227 function filelink($link, $title = null) {} 228 229 // Link to a Windows share, , $title could be an array (media) 230 function windowssharelink($link, $title = null) {} 231 232// function email($address, $title = null) {} 233 function emaillink($address, $name = null) {} 234 235 function internalmedia ($src, $title=null, $align=null, $width=null, 236 $height=null, $cache=null, $linking=null) {} 237 238 function externalmedia ($src, $title=null, $align=null, $width=null, 239 $height=null, $cache=null, $linking=null) {} 240 241 function internalmedialink ( 242 $src,$title=null,$align=null,$width=null,$height=null,$cache=null 243 ) {} 244 245 function externalmedialink( 246 $src,$title=null,$align=null,$width=null,$height=null,$cache=null 247 ) {} 248 249 function table_open($maxcols = null, $numrows = null, $pos = null){} 250 251 function table_close($pos = null){} 252 253 function tablerow_open(){} 254 255 function tablerow_close(){} 256 257 function tableheader_open($colspan = 1, $align = null, $rowspan = 1){} 258 259 function tableheader_close(){} 260 261 function tablecell_open($colspan = 1, $align = null, $rowspan = 1){} 262 263 function tablecell_close(){} 264 265 266 // util functions follow, you probably won't need to reimplement them 267 268 269 /** 270 * Removes any Namespace from the given name but keeps 271 * casing and special chars 272 * 273 * @author Andreas Gohr <andi@splitbrain.org> 274 */ 275 function _simpleTitle($name){ 276 global $conf; 277 278 //if there is a hash we use the ancor name only 279 list($name,$hash) = explode('#',$name,2); 280 if($hash) return $hash; 281 282 if($conf['useslash']){ 283 $name = strtr($name,';/',';:'); 284 }else{ 285 $name = strtr($name,';',':'); 286 } 287 288 return noNSorNS($name); 289 } 290 291 /** 292 * Resolve an interwikilink 293 */ 294 function _resolveInterWiki(&$shortcut,$reference){ 295 //get interwiki URL 296 if ( isset($this->interwiki[$shortcut]) ) { 297 $url = $this->interwiki[$shortcut]; 298 } else { 299 // Default to Google I'm feeling lucky 300 $url = 'http://www.google.com/search?q={URL}&btnI=lucky'; 301 $shortcut = 'go'; 302 } 303 304 //split into hash and url part 305 list($reference,$hash) = explode('#',$reference,2); 306 307 //replace placeholder 308 if(preg_match('#\{(URL|NAME|SCHEME|HOST|PORT|PATH|QUERY)\}#',$url)){ 309 //use placeholders 310 $url = str_replace('{URL}',rawurlencode($reference),$url); 311 $url = str_replace('{NAME}',$reference,$url); 312 $parsed = parse_url($reference); 313 if(!$parsed['port']) $parsed['port'] = 80; 314 $url = str_replace('{SCHEME}',$parsed['scheme'],$url); 315 $url = str_replace('{HOST}',$parsed['host'],$url); 316 $url = str_replace('{PORT}',$parsed['port'],$url); 317 $url = str_replace('{PATH}',$parsed['path'],$url); 318 $url = str_replace('{QUERY}',$parsed['query'],$url); 319 }else{ 320 //default 321 $url = $url.rawurlencode($reference); 322 } 323 if($hash) $url .= '#'.rawurlencode($hash); 324 325 return $url; 326 } 327} 328 329 330//Setup VIM: ex: et ts=4 : 331