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