first commit. dokuwiki.
[h2N7SspZmY.git] / inc / parser / renderer.php
blob6082e935d8c52897eb364d94a2d4f27d2a7aab78
1 <?php
2 /**
3 * Renderer output base class
5 * @author Harry Fuecks <hfuecks@gmail.com>
6 * @author Andreas Gohr <andi@splitbrain.org>
7 */
8 if(!defined('DOKU_INC')) die('meh.');
9 require_once DOKU_INC . 'inc/parser/renderer.php';
10 require_once DOKU_INC . 'inc/plugin.php';
11 require_once DOKU_INC . 'inc/pluginutils.php';
13 /**
14 * An empty renderer, produces no output
16 * Inherits from DokuWiki_Plugin for giving additional functions to render plugins
18 class Doku_Renderer extends DokuWiki_Plugin {
19 var $info = array(
20 'cache' => true, // may the rendered result cached?
21 'toc' => true, // render the TOC?
24 // keep some config options
25 var $acronyms = array();
26 var $smileys = array();
27 var $badwords = array();
28 var $entities = array();
29 var $interwiki = array();
31 // allows renderer to be used again, clean out any per-use values
32 function reset() {
35 function nocache() {
36 $this->info['cache'] = false;
39 function notoc() {
40 $this->info['toc'] = false;
43 /**
44 * Returns the format produced by this renderer.
46 * Has to be overidden by decendend classes
48 function getFormat(){
49 trigger_error('getFormat() not implemented in '.get_class($this), E_USER_WARNING);
53 //handle plugin rendering
54 function plugin($name,$data){
55 $plugin =& plugin_load('syntax',$name);
56 if($plugin != null){
57 $plugin->render($this->getFormat(),$this,$data);
61 /**
62 * handle nested render instructions
63 * this method (and nest_close method) should not be overloaded in actual renderer output classes
65 function nest($instructions) {
67 foreach ( $instructions as $instruction ) {
68 // execute the callback against ourself
69 call_user_func_array(array(&$this, $instruction[0]),$instruction[1]);
73 // dummy closing instruction issued by Doku_Handler_Nest, normally the syntax mode should
74 // override this instruction when instantiating Doku_Handler_Nest - however plugins will not
75 // be able to - as their instructions require data.
76 function nest_close() {}
78 function document_start() {}
80 function document_end() {}
82 function render_TOC() { return ''; }
84 function toc_additem($id, $text, $level) {}
86 function header($text, $level, $pos) {}
88 function section_edit($start, $end, $level, $name) {}
90 function section_open($level) {}
92 function section_close() {}
94 function cdata($text) {}
96 function p_open() {}
98 function p_close() {}
100 function linebreak() {}
102 function hr() {}
104 function strong_open() {}
106 function strong_close() {}
108 function emphasis_open() {}
110 function emphasis_close() {}
112 function underline_open() {}
114 function underline_close() {}
116 function monospace_open() {}
118 function monospace_close() {}
120 function subscript_open() {}
122 function subscript_close() {}
124 function superscript_open() {}
126 function superscript_close() {}
128 function deleted_open() {}
130 function deleted_close() {}
132 function footnote_open() {}
134 function footnote_close() {}
136 function listu_open() {}
138 function listu_close() {}
140 function listo_open() {}
142 function listo_close() {}
144 function listitem_open($level) {}
146 function listitem_close() {}
148 function listcontent_open() {}
150 function listcontent_close() {}
152 function unformatted($text) {}
154 function php($text) {}
156 function phpblock($text) {}
158 function html($text) {}
160 function htmlblock($text) {}
162 function preformatted($text) {}
164 function quote_open() {}
166 function quote_close() {}
168 function file($text, $lang = null, $file = null ) {}
170 function code($text, $lang = null, $file = null ) {}
172 function acronym($acronym) {}
174 function smiley($smiley) {}
176 function wordblock($word) {}
178 function entity($entity) {}
180 // 640x480 ($x=640, $y=480)
181 function multiplyentity($x, $y) {}
183 function singlequoteopening() {}
185 function singlequoteclosing() {}
187 function apostrophe() {}
189 function doublequoteopening() {}
191 function doublequoteclosing() {}
193 // $link like 'SomePage'
194 function camelcaselink($link) {}
196 function locallink($hash, $name = NULL) {}
198 // $link like 'wiki:syntax', $title could be an array (media)
199 function internallink($link, $title = NULL) {}
201 // $link is full URL with scheme, $title could be an array (media)
202 function externallink($link, $title = NULL) {}
204 function rss ($url,$params) {}
206 // $link is the original link - probably not much use
207 // $wikiName is an indentifier for the wiki
208 // $wikiUri is the URL fragment to append to some known URL
209 function interwikilink($link, $title = NULL, $wikiName, $wikiUri) {}
211 // Link to file on users OS, $title could be an array (media)
212 function filelink($link, $title = NULL) {}
214 // Link to a Windows share, , $title could be an array (media)
215 function windowssharelink($link, $title = NULL) {}
217 // function email($address, $title = NULL) {}
218 function emaillink($address, $name = NULL) {}
220 function internalmedia ($src, $title=NULL, $align=NULL, $width=NULL,
221 $height=NULL, $cache=NULL, $linking=NULL) {}
223 function externalmedia ($src, $title=NULL, $align=NULL, $width=NULL,
224 $height=NULL, $cache=NULL, $linking=NULL) {}
226 function internalmedialink (
227 $src,$title=NULL,$align=NULL,$width=NULL,$height=NULL,$cache=NULL
228 ) {}
230 function externalmedialink(
231 $src,$title=NULL,$align=NULL,$width=NULL,$height=NULL,$cache=NULL
232 ) {}
234 function table_open($maxcols = NULL, $numrows = NULL){}
236 function table_close(){}
238 function tablerow_open(){}
240 function tablerow_close(){}
242 function tableheader_open($colspan = 1, $align = NULL, $rowspan = 1){}
244 function tableheader_close(){}
246 function tablecell_open($colspan = 1, $align = NULL, $rowspan = 1){}
248 function tablecell_close(){}
251 // util functions follow, you probably won't need to reimplement them
255 * Removes any Namespace from the given name but keeps
256 * casing and special chars
258 * @author Andreas Gohr <andi@splitbrain.org>
260 function _simpleTitle($name){
261 global $conf;
263 //if there is a hash we use the ancor name only
264 list($name,$hash) = explode('#',$name,2);
265 if($hash) return $hash;
267 //trim colons or slash of a namespace link
268 $name = rtrim($name,':');
269 if($conf['useslash'])
270 $name = rtrim($name,'/');
272 if($conf['useslash']){
273 $nssep = '[:;/]';
274 }else{
275 $nssep = '[:;]';
277 $name = preg_replace('!.*'.$nssep.'!','',$name);
279 if(!$name) return $this->_simpleTitle($conf['start']);
280 return $name;
284 * Resolve an interwikilink
286 function _resolveInterWiki(&$shortcut,$reference){
287 //get interwiki URL
288 if ( isset($this->interwiki[$shortcut]) ) {
289 $url = $this->interwiki[$shortcut];
290 } else {
291 // Default to Google I'm feeling lucky
292 $url = 'http://www.google.com/search?q={URL}&amp;btnI=lucky';
293 $shortcut = 'go';
296 //split into hash and url part
297 list($reference,$hash) = explode('#',$reference,2);
299 //replace placeholder
300 if(preg_match('#\{(URL|NAME|SCHEME|HOST|PORT|PATH|QUERY)\}#',$url)){
301 //use placeholders
302 $url = str_replace('{URL}',rawurlencode($reference),$url);
303 $url = str_replace('{NAME}',$reference,$url);
304 $parsed = parse_url($reference);
305 if(!$parsed['port']) $parsed['port'] = 80;
306 $url = str_replace('{SCHEME}',$parsed['scheme'],$url);
307 $url = str_replace('{HOST}',$parsed['host'],$url);
308 $url = str_replace('{PORT}',$parsed['port'],$url);
309 $url = str_replace('{PATH}',$parsed['path'],$url);
310 $url = str_replace('{QUERY}',$parsed['query'],$url);
311 }else{
312 //default
313 $url = $url.rawurlencode($reference);
315 if($hash) $url .= '#'.rawurlencode($hash);
317 return $url;
322 //Setup VIM: ex: et ts=4 enc=utf-8 :