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