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