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