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