xref: /dokuwiki/inc/parser/renderer.php (revision 6d58f7821f530c90900d3cda301f9e22026c5fcb)
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/plugin.php';
10require_once DOKU_INC . 'inc/pluginutils.php';
11
12/**
13 * An empty renderer, produces no output
14 *
15 * Inherits from DokuWiki_Plugin for giving additional functions to render plugins
16 */
17class Doku_Renderer extends DokuWiki_Plugin {
18    var $info = array(
19        'cache' => true, // may the rendered result cached?
20        'toc'   => true, // render the TOC?
21    );
22
23    // keep some config options
24    var $acronyms = array();
25    var $smileys = array();
26    var $badwords = array();
27    var $entities = array();
28    var $interwiki = array();
29
30    // allows renderer to be used again, clean out any per-use values
31    function reset() {
32    }
33
34    function nocache() {
35        $this->info['cache'] = false;
36    }
37
38    function notoc() {
39        $this->info['toc'] = false;
40    }
41
42    /**
43     * Returns the format produced by this renderer.
44     *
45     * Has to be overidden by decendend classes
46     */
47    function getFormat(){
48        trigger_error('getFormat() not implemented in '.get_class($this), E_USER_WARNING);
49    }
50
51    /**
52     * Allow the plugin to prevent DokuWiki from reusing an instance
53     *
54     * @return bool   false if the plugin has to be instantiated
55     */
56    function isSingleton() {
57        return false;
58    }
59
60
61    //handle plugin rendering
62    function plugin($name,$data){
63        $plugin =& plugin_load('syntax',$name);
64        if($plugin != null){
65            $plugin->render($this->getFormat(),$this,$data);
66        }
67    }
68
69    /**
70     * handle nested render instructions
71     * this method (and nest_close method) should not be overloaded in actual renderer output classes
72     */
73    function nest($instructions) {
74
75      foreach ( $instructions as $instruction ) {
76        // execute the callback against ourself
77        call_user_func_array(array(&$this, $instruction[0]),$instruction[1]);
78      }
79    }
80
81    // dummy closing instruction issued by Doku_Handler_Nest, normally the syntax mode should
82    // override this instruction when instantiating Doku_Handler_Nest - however plugins will not
83    // be able to - as their instructions require data.
84    function nest_close() {}
85
86    function document_start() {}
87
88    function document_end() {}
89
90    function render_TOC() { return ''; }
91
92    function toc_additem($id, $text, $level) {}
93
94    function header($text, $level, $pos) {}
95
96    function section_open($level) {}
97
98    function section_close() {}
99
100    function cdata($text) {}
101
102    function p_open() {}
103
104    function p_close() {}
105
106    function linebreak() {}
107
108    function hr() {}
109
110    function strong_open() {}
111
112    function strong_close() {}
113
114    function emphasis_open() {}
115
116    function emphasis_close() {}
117
118    function underline_open() {}
119
120    function underline_close() {}
121
122    function monospace_open() {}
123
124    function monospace_close() {}
125
126    function subscript_open() {}
127
128    function subscript_close() {}
129
130    function superscript_open() {}
131
132    function superscript_close() {}
133
134    function deleted_open() {}
135
136    function deleted_close() {}
137
138    function footnote_open() {}
139
140    function footnote_close() {}
141
142    function listu_open() {}
143
144    function listu_close() {}
145
146    function listo_open() {}
147
148    function listo_close() {}
149
150    function listitem_open($level) {}
151
152    function listitem_close() {}
153
154    function listcontent_open() {}
155
156    function listcontent_close() {}
157
158    function unformatted($text) {}
159
160    function php($text) {}
161
162    function phpblock($text) {}
163
164    function html($text) {}
165
166    function htmlblock($text) {}
167
168    function preformatted($text) {}
169
170    function quote_open() {}
171
172    function quote_close() {}
173
174    function file($text, $lang = null, $file = null ) {}
175
176    function code($text, $lang = null, $file = null ) {}
177
178    function acronym($acronym) {}
179
180    function smiley($smiley) {}
181
182    function wordblock($word) {}
183
184    function entity($entity) {}
185
186    // 640x480 ($x=640, $y=480)
187    function multiplyentity($x, $y) {}
188
189    function singlequoteopening() {}
190
191    function singlequoteclosing() {}
192
193    function apostrophe() {}
194
195    function doublequoteopening() {}
196
197    function doublequoteclosing() {}
198
199    // $link like 'SomePage'
200    function camelcaselink($link) {}
201
202    function locallink($hash, $name = NULL) {}
203
204    // $link like 'wiki:syntax', $title could be an array (media)
205    function internallink($link, $title = NULL) {}
206
207    // $link is full URL with scheme, $title could be an array (media)
208    function externallink($link, $title = NULL) {}
209
210    function rss ($url,$params) {}
211
212    // $link is the original link - probably not much use
213    // $wikiName is an indentifier for the wiki
214    // $wikiUri is the URL fragment to append to some known URL
215    function interwikilink($link, $title = NULL, $wikiName, $wikiUri) {}
216
217    // Link to file on users OS, $title could be an array (media)
218    function filelink($link, $title = NULL) {}
219
220    // Link to a Windows share, , $title could be an array (media)
221    function windowssharelink($link, $title = NULL) {}
222
223//  function email($address, $title = NULL) {}
224    function emaillink($address, $name = NULL) {}
225
226    function internalmedia ($src, $title=NULL, $align=NULL, $width=NULL,
227                            $height=NULL, $cache=NULL, $linking=NULL) {}
228
229    function externalmedia ($src, $title=NULL, $align=NULL, $width=NULL,
230                            $height=NULL, $cache=NULL, $linking=NULL) {}
231
232    function internalmedialink (
233        $src,$title=NULL,$align=NULL,$width=NULL,$height=NULL,$cache=NULL
234        ) {}
235
236    function externalmedialink(
237        $src,$title=NULL,$align=NULL,$width=NULL,$height=NULL,$cache=NULL
238        ) {}
239
240    function table_open($maxcols = NULL, $numrows = NULL, $pos){}
241
242    function table_close($pos){}
243
244    function tablerow_open(){}
245
246    function tablerow_close(){}
247
248    function tableheader_open($colspan = 1, $align = NULL, $rowspan = 1){}
249
250    function tableheader_close(){}
251
252    function tablecell_open($colspan = 1, $align = NULL, $rowspan = 1){}
253
254    function tablecell_close(){}
255
256
257    // util functions follow, you probably won't need to reimplement them
258
259
260    /**
261     * Removes any Namespace from the given name but keeps
262     * casing and special chars
263     *
264     * @author Andreas Gohr <andi@splitbrain.org>
265     */
266    function _simpleTitle($name){
267        global $conf;
268
269        //if there is a hash we use the ancor name only
270        list($name,$hash) = explode('#',$name,2);
271        if($hash) return $hash;
272
273        $name = strtr($name,';',':');
274        if($conf['useslash']){
275            $name = strtr($name,'/',':');
276        }
277
278        return noNSorNS($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($reference,$hash) = explode('#',$reference,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