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