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_edit($start, $end, $level, $name) {} 89 90 function section_open($level) {} 91 92 function section_close() {} 93 94 function cdata($text) {} 95 96 function p_open() {} 97 98 function p_close() {} 99 100 function linebreak() {} 101 102 function hr() {} 103 104 function strong_open() {} 105 106 function strong_close() {} 107 108 function emphasis_open() {} 109 110 function emphasis_close() {} 111 112 function underline_open() {} 113 114 function underline_close() {} 115 116 function monospace_open() {} 117 118 function monospace_close() {} 119 120 function subscript_open() {} 121 122 function subscript_close() {} 123 124 function superscript_open() {} 125 126 function superscript_close() {} 127 128 function deleted_open() {} 129 130 function deleted_close() {} 131 132 function footnote_open() {} 133 134 function footnote_close() {} 135 136 function listu_open() {} 137 138 function listu_close() {} 139 140 function listo_open() {} 141 142 function listo_close() {} 143 144 function listitem_open($level) {} 145 146 function listitem_close() {} 147 148 function listcontent_open() {} 149 150 function listcontent_close() {} 151 152 function unformatted($text) {} 153 154 function php($text) {} 155 156 function phpblock($text) {} 157 158 function html($text) {} 159 160 function htmlblock($text) {} 161 162 function preformatted($text) {} 163 164 function quote_open() {} 165 166 function quote_close() {} 167 168 function file($text, $lang = null, $file = null ) {} 169 170 function code($text, $lang = null, $file = null ) {} 171 172 function acronym($acronym) {} 173 174 function smiley($smiley) {} 175 176 function wordblock($word) {} 177 178 function entity($entity) {} 179 180 // 640x480 ($x=640, $y=480) 181 function multiplyentity($x, $y) {} 182 183 function singlequoteopening() {} 184 185 function singlequoteclosing() {} 186 187 function apostrophe() {} 188 189 function doublequoteopening() {} 190 191 function doublequoteclosing() {} 192 193 // $link like 'SomePage' 194 function camelcaselink($link) {} 195 196 function locallink($hash, $name = NULL) {} 197 198 // $link like 'wiki:syntax', $title could be an array (media) 199 function internallink($link, $title = NULL) {} 200 201 // $link is full URL with scheme, $title could be an array (media) 202 function externallink($link, $title = NULL) {} 203 204 function rss ($url,$params) {} 205 206 // $link is the original link - probably not much use 207 // $wikiName is an indentifier for the wiki 208 // $wikiUri is the URL fragment to append to some known URL 209 function interwikilink($link, $title = NULL, $wikiName, $wikiUri) {} 210 211 // Link to file on users OS, $title could be an array (media) 212 function filelink($link, $title = NULL) {} 213 214 // Link to a Windows share, , $title could be an array (media) 215 function windowssharelink($link, $title = NULL) {} 216 217// function email($address, $title = NULL) {} 218 function emaillink($address, $name = NULL) {} 219 220 function internalmedia ($src, $title=NULL, $align=NULL, $width=NULL, 221 $height=NULL, $cache=NULL, $linking=NULL) {} 222 223 function externalmedia ($src, $title=NULL, $align=NULL, $width=NULL, 224 $height=NULL, $cache=NULL, $linking=NULL) {} 225 226 function internalmedialink ( 227 $src,$title=NULL,$align=NULL,$width=NULL,$height=NULL,$cache=NULL 228 ) {} 229 230 function externalmedialink( 231 $src,$title=NULL,$align=NULL,$width=NULL,$height=NULL,$cache=NULL 232 ) {} 233 234 function table_open($maxcols = NULL, $numrows = NULL){} 235 236 function table_close($begin, $end){} 237 238 function tablerow_open(){} 239 240 function tablerow_close(){} 241 242 function tableheader_open($colspan = 1, $align = NULL, $rowspan = 1){} 243 244 function tableheader_close(){} 245 246 function tablecell_open($colspan = 1, $align = NULL, $rowspan = 1){} 247 248 function tablecell_close(){} 249 250 251 // util functions follow, you probably won't need to reimplement them 252 253 254 /** 255 * Removes any Namespace from the given name but keeps 256 * casing and special chars 257 * 258 * @author Andreas Gohr <andi@splitbrain.org> 259 */ 260 function _simpleTitle($name){ 261 global $conf; 262 263 //if there is a hash we use the ancor name only 264 list($name,$hash) = explode('#',$name,2); 265 if($hash) return $hash; 266 267 //trim colons or slash of a namespace link 268 $name = rtrim($name,':'); 269 if($conf['useslash']) 270 $name = rtrim($name,'/'); 271 272 if($conf['useslash']){ 273 $nssep = '[:;/]'; 274 }else{ 275 $nssep = '[:;]'; 276 } 277 $name = preg_replace('!.*'.$nssep.'!','',$name); 278 279 if(!$name) return $this->_simpleTitle($conf['start']); 280 return $name; 281 } 282 283 /** 284 * Resolve an interwikilink 285 */ 286 function _resolveInterWiki(&$shortcut,$reference){ 287 //get interwiki URL 288 if ( isset($this->interwiki[$shortcut]) ) { 289 $url = $this->interwiki[$shortcut]; 290 } else { 291 // Default to Google I'm feeling lucky 292 $url = 'http://www.google.com/search?q={URL}&btnI=lucky'; 293 $shortcut = 'go'; 294 } 295 296 //split into hash and url part 297 list($reference,$hash) = explode('#',$reference,2); 298 299 //replace placeholder 300 if(preg_match('#\{(URL|NAME|SCHEME|HOST|PORT|PATH|QUERY)\}#',$url)){ 301 //use placeholders 302 $url = str_replace('{URL}',rawurlencode($reference),$url); 303 $url = str_replace('{NAME}',$reference,$url); 304 $parsed = parse_url($reference); 305 if(!$parsed['port']) $parsed['port'] = 80; 306 $url = str_replace('{SCHEME}',$parsed['scheme'],$url); 307 $url = str_replace('{HOST}',$parsed['host'],$url); 308 $url = str_replace('{PORT}',$parsed['port'],$url); 309 $url = str_replace('{PATH}',$parsed['path'],$url); 310 $url = str_replace('{QUERY}',$parsed['query'],$url); 311 }else{ 312 //default 313 $url = $url.rawurlencode($reference); 314 } 315 if($hash) $url .= '#'.rawurlencode($hash); 316 317 return $url; 318 } 319} 320 321 322//Setup VIM: ex: et ts=4 enc=utf-8 : 323