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