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