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