3 * Renderer output base class
5 * @author Harry Fuecks <hfuecks@gmail.com>
6 * @author Andreas Gohr <andi@splitbrain.org>
8 if(!defined('DOKU_INC')) die('meh.');
9 require_once DOKU_INC . 'inc/plugin.php';
10 require_once DOKU_INC . 'inc/pluginutils.php';
13 * An empty renderer, produces no output
15 * Inherits from DokuWiki_Plugin for giving additional functions to render plugins
17 class Doku_Renderer extends DokuWiki_Plugin {
19 'cache' => true, // may the rendered result cached?
20 'toc' => true, // render the TOC?
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();
32 // allows renderer to be used again, clean out any per-use values
37 $this->info['cache'] = false;
41 $this->info['toc'] = false;
45 * Returns the format produced by this renderer.
47 * Has to be overidden by decendend classes
50 trigger_error('getFormat() not implemented in '.get_class($this), E_USER_WARNING);
54 * Allow the plugin to prevent DokuWiki from reusing an instance
56 * @return bool false if the plugin has to be instantiated
58 function isSingleton() {
63 //handle plugin rendering
64 function plugin($name,$data){
65 $plugin =& plugin_load('syntax',$name);
67 $plugin->render($this->getFormat(),$this,$data);
72 * handle nested render instructions
73 * this method (and nest_close method) should not be overloaded in actual renderer output classes
75 function nest($instructions) {
77 foreach ( $instructions as $instruction ) {
78 // execute the callback against ourself
79 if (method_exists($this,$instruction[0])) {
80 call_user_func_array(array($this, $instruction[0]), $instruction[1] ? $instruction[1] : array());
85 // dummy closing instruction issued by Doku_Handler_Nest, normally the syntax mode should
86 // override this instruction when instantiating Doku_Handler_Nest - however plugins will not
87 // be able to - as their instructions require data.
88 function nest_close() {}
90 function document_start() {}
92 function document_end() {}
94 function render_TOC() { return ''; }
96 function toc_additem($id, $text, $level) {}
98 function header($text, $level, $pos) {}
100 function section_open($level) {}
102 function section_close() {}
104 function cdata($text) {}
108 function p_close() {}
110 function linebreak() {}
114 function strong_open() {}
116 function strong_close() {}
118 function emphasis_open() {}
120 function emphasis_close() {}
122 function underline_open() {}
124 function underline_close() {}
126 function monospace_open() {}
128 function monospace_close() {}
130 function subscript_open() {}
132 function subscript_close() {}
134 function superscript_open() {}
136 function superscript_close() {}
138 function deleted_open() {}
140 function deleted_close() {}
142 function footnote_open() {}
144 function footnote_close() {}
146 function listu_open() {}
148 function listu_close() {}
150 function listo_open() {}
152 function listo_close() {}
154 function listitem_open($level) {}
156 function listitem_close() {}
158 function listcontent_open() {}
160 function listcontent_close() {}
162 function unformatted($text) {}
164 function php($text) {}
166 function phpblock($text) {}
168 function html($text) {}
170 function htmlblock($text) {}
172 function preformatted($text) {}
174 function quote_open() {}
176 function quote_close() {}
178 function file($text, $lang = null, $file = null ) {}
180 function code($text, $lang = null, $file = null ) {}
182 function acronym($acronym) {}
184 function smiley($smiley) {}
186 function wordblock($word) {}
188 function entity($entity) {}
190 // 640x480 ($x=640, $y=480)
191 function multiplyentity($x, $y) {}
193 function singlequoteopening() {}
195 function singlequoteclosing() {}
197 function apostrophe() {}
199 function doublequoteopening() {}
201 function doublequoteclosing() {}
203 // $link like 'SomePage'
204 function camelcaselink($link) {}
206 function locallink($hash, $name = NULL) {}
208 // $link like 'wiki:syntax', $title could be an array (media)
209 function internallink($link, $title = NULL) {}
211 // $link is full URL with scheme, $title could be an array (media)
212 function externallink($link, $title = NULL) {}
214 function rss ($url,$params) {}
216 // $link is the original link - probably not much use
217 // $wikiName is an indentifier for the wiki
218 // $wikiUri is the URL fragment to append to some known URL
219 function interwikilink($link, $title = NULL, $wikiName, $wikiUri) {}
221 // Link to file on users OS, $title could be an array (media)
222 function filelink($link, $title = NULL) {}
224 // Link to a Windows share, , $title could be an array (media)
225 function windowssharelink($link, $title = NULL) {}
227 // function email($address, $title = NULL) {}
228 function emaillink($address, $name = NULL) {}
230 function internalmedia ($src, $title=NULL, $align=NULL, $width=NULL,
231 $height=NULL, $cache=NULL, $linking=NULL) {}
233 function externalmedia ($src, $title=NULL, $align=NULL, $width=NULL,
234 $height=NULL, $cache=NULL, $linking=NULL) {}
236 function internalmedialink (
237 $src,$title=NULL,$align=NULL,$width=NULL,$height=NULL,$cache=NULL
240 function externalmedialink(
241 $src,$title=NULL,$align=NULL,$width=NULL,$height=NULL,$cache=NULL
244 function table_open($maxcols = null, $numrows = null, $pos = null){}
246 function table_close($pos = null){}
248 function tablerow_open(){}
250 function tablerow_close(){}
252 function tableheader_open($colspan = 1, $align = NULL, $rowspan = 1){}
254 function tableheader_close(){}
256 function tablecell_open($colspan = 1, $align = NULL, $rowspan = 1){}
258 function tablecell_close(){}
261 // util functions follow, you probably won't need to reimplement them
265 * Removes any Namespace from the given name but keeps
266 * casing and special chars
268 * @author Andreas Gohr <andi@splitbrain.org>
270 function _simpleTitle($name){
273 //if there is a hash we use the ancor name only
274 list($name,$hash) = explode('#',$name,2);
275 if($hash) return $hash;
277 $name = strtr($name,';',':');
278 if($conf['useslash']){
279 $name = strtr($name,'/',':');
282 return noNSorNS($name);
286 * Resolve an interwikilink
288 function _resolveInterWiki(&$shortcut,$reference){
290 if ( isset($this->interwiki[$shortcut]) ) {
291 $url = $this->interwiki[$shortcut];
293 // Default to Google I'm feeling lucky
294 $url = 'http://www.google.com/search?q={URL}&btnI=lucky';
298 //split into hash and url part
299 list($reference,$hash) = explode('#',$reference,2);
301 //replace placeholder
302 if(preg_match('#\{(URL|NAME|SCHEME|HOST|PORT|PATH|QUERY)\}#',$url)){
304 $url = str_replace('{URL}',rawurlencode($reference),$url);
305 $url = str_replace('{NAME}',$reference,$url);
306 $parsed = parse_url($reference);
307 if(!$parsed['port']) $parsed['port'] = 80;
308 $url = str_replace('{SCHEME}',$parsed['scheme'],$url);
309 $url = str_replace('{HOST}',$parsed['host'],$url);
310 $url = str_replace('{PORT}',$parsed['port'],$url);
311 $url = str_replace('{PATH}',$parsed['path'],$url);
312 $url = str_replace('{QUERY}',$parsed['query'],$url);
315 $url = $url.rawurlencode($reference);
317 if($hash) $url .= '#'.rawurlencode($hash);
324 //Setup VIM: ex: et ts=4 :