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 apostrophe() {} 181 182 function doublequoteopening() {} 183 184 function doublequoteclosing() {} 185 186 // $link like 'SomePage' 187 function camelcaselink($link) {} 188 189 function locallink($hash, $name = NULL) {} 190 191 // $link like 'wiki:syntax', $title could be an array (media) 192 function internallink($link, $title = NULL) {} 193 194 // $link is full URL with scheme, $title could be an array (media) 195 function externallink($link, $title = NULL) {} 196 197 // $link is the original link - probably not much use 198 // $wikiName is an indentifier for the wiki 199 // $wikiUri is the URL fragment to append to some known URL 200 function interwikilink($link, $title = NULL, $wikiName, $wikiUri) {} 201 202 // Link to file on users OS, $title could be an array (media) 203 function filelink($link, $title = NULL) {} 204 205 // Link to a Windows share, , $title could be an array (media) 206 function windowssharelink($link, $title = NULL) {} 207 208// function email($address, $title = NULL) {} 209 function emaillink($address, $name = NULL) {} 210 211 function internalmedia ($src, $title=NULL, $align=NULL, $width=NULL, 212 $height=NULL, $cache=NULL, $linking=NULL) {} 213 214 function externalmedia ($src, $title=NULL, $align=NULL, $width=NULL, 215 $height=NULL, $cache=NULL, $linking=NULL) {} 216 217 function internalmedialink ( 218 $src,$title=NULL,$align=NULL,$width=NULL,$height=NULL,$cache=NULL 219 ) {} 220 221 function externalmedialink( 222 $src,$title=NULL,$align=NULL,$width=NULL,$height=NULL,$cache=NULL 223 ) {} 224 225 function table_open($maxcols = NULL, $numrows = NULL){} 226 227 function table_close(){} 228 229 function tablerow_open(){} 230 231 function tablerow_close(){} 232 233 function tableheader_open($colspan = 1, $align = NULL){} 234 235 function tableheader_close(){} 236 237 function tablecell_open($colspan = 1, $align = NULL){} 238 239 function tablecell_close(){} 240 241 242 // util functions follow, you probably won't need to reimplement them 243 244 245 /** 246 * Removes any Namespace from the given name but keeps 247 * casing and special chars 248 * 249 * @author Andreas Gohr <andi@splitbrain.org> 250 */ 251 function _simpleTitle($name){ 252 global $conf; 253 254 //if there is a hash we use the ancor name only 255 list($name,$hash) = explode('#',$name,2); 256 if($hash) return $hash; 257 258 //trim colons or slash of a namespace link 259 $name = rtrim($name,':'); 260 if($conf['useslash']) 261 $name = rtrim($name,'/'); 262 263 if($conf['useslash']){ 264 $nssep = '[:;/]'; 265 }else{ 266 $nssep = '[:;]'; 267 } 268 $name = preg_replace('!.*'.$nssep.'!','',$name); 269 270 if(!$name) return $this->_simpleTitle($conf['start']); 271 return $name; 272 } 273 274 /** 275 * Resolve an interwikilink 276 */ 277 function _resolveInterWiki(&$shortcut,$reference){ 278 //get interwiki URL 279 if ( isset($this->interwiki[$shortcut]) ) { 280 $url = $this->interwiki[$shortcut]; 281 } else { 282 // Default to Google I'm feeling lucky 283 $url = 'http://www.google.com/search?q={URL}&btnI=lucky'; 284 $shortcut = 'go'; 285 } 286 287 //split into hash and url part 288 list($wikiUri,$hash) = explode('#',$wikiUri,2); 289 290 //replace placeholder 291 if(preg_match('#\{(URL|NAME|SCHEME|HOST|PORT|PATH|QUERY)\}#',$url)){ 292 //use placeholders 293 $url = str_replace('{URL}',rawurlencode($reference),$url); 294 $url = str_replace('{NAME}',$reference,$url); 295 $parsed = parse_url($reference); 296 if(!$parsed['port']) $parsed['port'] = 80; 297 $url = str_replace('{SCHEME}',$parsed['scheme'],$url); 298 $url = str_replace('{HOST}',$parsed['host'],$url); 299 $url = str_replace('{PORT}',$parsed['port'],$url); 300 $url = str_replace('{PATH}',$parsed['path'],$url); 301 $url = str_replace('{QUERY}',$parsed['query'],$url); 302 }else{ 303 //default 304 $url = $url.rawurlencode($reference); 305 } 306 if($hash) $url .= '#'.rawurlencode($hash); 307 308 return $url; 309 } 310} 311 312 313//Setup VIM: ex: et ts=4 enc=utf-8 : 314