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