1<?php
2/**
3 * DokuWiki Plugin simplexml (Renderer Component)
4 *
5 * @author   Patrick Bueker <Patrick@patrickbueker.de>
6 * @license  GPLv2 or later (http://www.gnu.org/licenses/gpl.html)
7 * @version  $Rev: 12 $
8 *
9 */
10
11// must be run within Dokuwiki
12if(!defined('DOKU_INC')) die();
13
14if (!defined('DOKU_LF')) define('DOKU_LF', "\n");
15if (!defined('DOKU_TAB')) define('DOKU_TAB', "\t");
16require_once DOKU_INC . 'inc/parser/renderer.php';
17
18/**
19 *  Renderer for simple XML is a simple renderer to
20 *  render DokuWiki as XML. It uses XML elements mostly
21 *  the way the DokuWiki renderer works internally.
22 *  Be aware that the output may not be sanitized,
23 *  so be careful.
24 */
25class renderer_plugin_simplexml extends Doku_Renderer {
26    var $info = array(
27        'cache' => false, // may the rendered result cached?
28        'toc'   => false, // render the TOC?
29    );
30    var $precedinglevel = array();
31    var $nextHeader     = "";
32
33    function nocache() {
34        $this->info['cache'] = false;
35    }
36
37    function notoc() {
38        $this->info['toc'] = false;
39    }
40
41    /**
42     * Returns the format produced by this renderer.
43     *
44     * Has to be overidden by decendend classes
45     */
46
47    function getFormat(){
48        return 'simplexml';
49    }
50
51    /**
52     * Return some info for the dokuwiki plugin manager.
53     */
54    function getInfo(){
55        $ver = '$Date: 2010-03-15 21:01:52 +0100 (Mo, 15. Mär 2010) $';
56        $ver = substr($ver, 7, 10);
57        return array(
58            'base'   => 'simplexml',
59            'author' => 'Patrick',
60            'email'  => 'Patrick@PatrickBueker.de',
61            'date'   => "$ver",
62            'name'   => 'Simple XML Renderer Plugin',
63            'desc'   => 'Renders dokuwiki as simple XML output. Read comments in source.',
64            'url'    => 'http://www.patrickbueker.de/dokuwiki/simplexml.tgz',
65        );
66    }
67
68    function document_start() {
69        global $ID;
70        global $INFO;
71        $this->doc  = '<?xml version="1.0" encoding="UTF-8"?>'.DOKU_LF;
72        $this->doc .= '<document namespace="' . $INFO['namespace'] . '"  revision="' . $INFO['rev'] . '" id="' . cleanID($ID) . '" lastmod="' . $INFO['lastmod'] . '">'.DOKU_LF;
73    }
74
75    function document_end() {
76        while(count($this->precedinglevel)>0)
77        {
78            $this->doc .= '</section>'.DOKU_LF;
79            $this->doc .= '<!--' . array_pop($this->precedinglevel) .  '-->'.DOKU_LF;
80        }
81        $this->doc .= '</document>'.DOKU_LF;
82    }
83
84    function render_TOC() {
85        $this->doc .= '<render_TOC/>'.DOKU_LF;
86    }
87
88    function toc_additem($id, $text, $level) {}
89
90    function header($text, $level, $pos) {
91        $this->nextHeader  = '<header level="' . $level . '" pos="' . $pos . '">'.DOKU_LF;
92        $this->nextHeader .= htmlspecialchars($text,ENT_COMPAT,'UTF-8',false);
93        $this->nextHeader .= '</header>'.DOKU_LF;
94    }
95
96    function section_edit($start, $end, $level, $name) {
97            $this->doc .= '<section_edit start="' . $start . '" end="' . $end . '" level="' . $level . '" name="' . $name . '"/>'.DOKU_LF;
98    }
99
100    function section_open($level) {
101        while(end($this->precedinglevel) >= $level)
102        {
103            $this->doc .= '</section>'.DOKU_LF;
104            $this->doc .= '<!--' . array_pop($this->precedinglevel) .  '-->'.DOKU_LF;
105        }
106
107        $this->doc .= '<section level="' . $level . '" >'.DOKU_LF;
108        $this->doc .= $this->nextHeader;
109	$this->nextHeader = "";
110        array_push($this->precedinglevel,$level);
111    }
112
113    function section_close() {
114        #$this->doc .= '</section>'.DOKU_LF;
115    }
116
117    function cdata($text) {
118        $this->doc .= htmlspecialchars($text,ENT_COMPAT,'UTF-8',false);
119    }
120
121    function p_open() {
122        $this->doc .= '<p>'.DOKU_LF;
123    }
124
125    function p_close() {
126        $this->doc .= '</p>'.DOKU_LF;
127    }
128
129    function linebreak() {
130        $this->doc .= '<linebreak/>'.DOKU_LF;
131    }
132
133    function hr() {
134        $this->doc .= '<hr/>'.DOKU_LF;
135    }
136
137    function strong_open() {
138        $this->doc .= '<strong>'.DOKU_LF;
139    }
140
141    function strong_close() {
142        $this->doc .= '</strong>'.DOKU_LF;
143    }
144
145    function emphasis_open() {
146        $this->doc .= '<emphasis>'.DOKU_LF;
147    }
148
149    function emphasis_close() {
150        $this->doc .= '</emphasis>'.DOKU_LF;
151    }
152
153    function underline_open() {
154        $this->doc .= '<underline>'.DOKU_LF;
155    }
156
157    function underline_close() {
158        $this->doc .= '</underline>'.DOKU_LF;
159    }
160
161    function monospace_open() {
162        $this->doc .= '<monospace>'.DOKU_LF;
163    }
164
165    function monospace_close() {
166        $this->doc .= '</monospace>'.DOKU_LF;
167    }
168
169    function subscript_open() {
170        $this->doc .= '<subscript>'.DOKU_LF;
171    }
172
173    function subscript_close() {
174        $this->doc .= '</subscript>'.DOKU_LF;
175    }
176
177    function superscript_open() {
178        $this->doc .= '<superscript>'.DOKU_LF;
179    }
180
181    function superscript_close() {
182        $this->doc .= '</superscript>'.DOKU_LF;
183    }
184
185    function deleted_open() {
186        $this->doc .= '<deleted>'.DOKU_LF;
187    }
188
189    function deleted_close() {
190        $this->doc .= '</deleted>'.DOKU_LF;
191    }
192
193    function footnote_open() {
194        $this->doc .= '<footnote>'.DOKU_LF;
195    }
196
197    function footnote_close() {
198        $this->doc .= '</footnote>'.DOKU_LF;
199    }
200
201    function listu_open() {
202        $this->doc .= '<listu>'.DOKU_LF;
203    }
204
205    function listu_close() {
206        $this->doc .= '</listu>'.DOKU_LF;
207    }
208
209    function listo_open() {
210        $this->doc .= '<listo>'.DOKU_LF;
211    }
212
213    function listo_close() {
214        $this->doc .= '</listo>'.DOKU_LF;
215    }
216
217    function listitem_open($level) {
218        $this->doc .= '<listitem level="' . $level . '">'.DOKU_LF;
219    }
220
221    function listitem_close() {
222        $this->doc .= '</listitem>'.DOKU_LF;
223    }
224
225    function listcontent_open() {
226        $this->doc .= '<listcontent>'.DOKU_LF;
227    }
228
229    function listcontent_close() {
230        $this->doc .= '</listcontent>'.DOKU_LF;
231    }
232
233    function unformatted($text) {
234        $this->doc .= '<unformatted>'.DOKU_LF;
235        $this->doc .= htmlspecialchars($text,ENT_COMPAT,'UTF-8',false);
236        $this->doc .= '</unformatted>'.DOKU_LF;
237    }
238
239    function php($text) {
240        $this->doc .= '</php>'.DOKU_LF;
241        $this->doc .= htmlspecialchars($text,ENT_COMPAT,'UTF-8',false);
242        $this->doc .= '</php>'.DOKU_LF;
243    }
244
245    function html($text) {
246        $this->doc .= '<html>'.DOKU_LF;
247        $this->doc .= htmlspecialchars($text,ENT_COMPAT,'UTF-8',false);
248        $this->doc .= '</html>'.DOKU_LF;
249    }
250
251    function preformatted($text) {
252        $this->doc .= '<preformatted>'.DOKU_LF;
253        $this->doc .= htmlspecialchars($text,ENT_COMPAT,'UTF-8',false);
254        $this->doc .= '</preformatted>'.DOKU_LF;
255    }
256
257    function file($text) {
258        $this->doc .= '<file>'.DOKU_LF;
259        $this->doc .= htmlspecialchars($text,ENT_COMPAT,'UTF-8',false);
260        $this->doc .= '</file>'.DOKU_LF;
261    }
262
263    function quote_open() {
264        $this->doc .= '<quote>'.DOKU_LF;
265    }
266
267    function quote_close() {
268        $this->doc .= '</quote>'.DOKU_LF;
269    }
270
271    function code($text, $lang = NULL) {
272        $this->doc .= '<code lang="' . $lang . '">'.DOKU_LF;
273        $this->doc .= htmlspecialchars($text,ENT_COMPAT,'UTF-8',false);
274        $this->doc .= '</code>'.DOKU_LF;
275    }
276
277    function acronym($acronym) {
278        $this->doc .= '<acronym>'.DOKU_LF;
279        $this->doc .= htmlspecialchars($acronym,ENT_COMPAT,'UTF-8',false);
280        $this->doc .= '</acronym>'.DOKU_LF;
281    }
282
283    function smiley($smiley) {
284        $this->doc .= '<smiley>'.DOKU_LF;
285        $this->doc .= htmlspecialchars($smiley,ENT_COMPAT,'UTF-8',false);
286        $this->doc .= '</smiley>'.DOKU_LF;
287    }
288
289    function wordblock($word) {
290        $this->doc .= '<wordblock>'.DOKU_LF;
291        $this->doc .= htmlspecialchars($word,ENT_COMPAT,'UTF-8',false);
292        $this->doc .= '</wordblock>'.DOKU_LF;
293    }
294
295    function entity($entity) {
296        $this->doc .= '<entity>'.DOKU_LF;
297        $this->doc .= htmlspecialchars($entety,ENT_COMPAT,'UTF-8',false);
298        $this->doc .= '</entity>'.DOKU_LF;
299    }
300
301    // 640x480 ($x=640, $y=480)
302    function multiplyentity($x, $y) {
303        $this->doc .= '<multiplyentity>'.DOKU_LF;
304        $this->doc .= '<x>'.DOKU_LF;
305        $this->doc .= htmlspecialchars($x,ENT_COMPAT,'UTF-8',false);
306        $this->doc .= '</x>'.DOKU_LF;
307        $this->doc .= '<y>'.DOKU_LF;
308        $this->doc .= htmlspecialchars($y,ENT_COMPAT,'UTF-8',false);
309        $this->doc .= '</y>'.DOKU_LF;
310        $this->doc .= '</multiplyentity>'.DOKU_LF;
311    }
312
313    function singlequoteopening() {
314        $this->doc .= '<singlequote>'.DOKU_LF;
315    }
316
317    function singlequoteclosing() {
318        $this->doc .= '</singlequote>'.DOKU_LF;
319    }
320
321    function apostrophe() {
322        $this->doc .= '<apostrophe/>'.DOKU_LF;
323    }
324
325    function doublequoteopening() {
326        $this->doc .= '<doublequote>'.DOKU_LF;
327    }
328
329    function doublequoteclosing() {
330        $this->doc .= '</doublequote>'.DOKU_LF;
331    }
332
333    // $link like 'SomePage'
334    function camelcaselink($link) {
335        $this->doc .= '<camelcaselink>'.DOKU_LF;
336        $this->doc .= htmlspecialchars($link,ENT_COMPAT,'UTF-8',false);
337        $this->doc .= '</camelcaselink>'.DOKU_LF;
338    }
339
340    function locallink($hash, $name = NULL) {
341        $this->doc .= '<locallink>'.DOKU_LF;
342        $this->doc .= '<hash>'.DOKU_LF;
343        $this->doc .= htmlspecialchars($hash,ENT_COMPAT,'UTF-8',false);
344        $this->doc .= '</hash>'.DOKU_LF;
345        $this->doc .= '<name>'.DOKU_LF;
346        $this->doc .= htmlspecialchars($name,ENT_COMPAT,'UTF-8',false);
347        $this->doc .= '</name>'.DOKU_LF;
348        $this->doc .= '</locallink>'.DOKU_LF;
349    }
350
351    // $link like 'wiki:syntax', $title could be an array (media)
352    function internallink($link, $title = NULL) {
353        $this->doc .= '<internallink>'.DOKU_LF;
354        $this->doc .= '<link>'.DOKU_LF;
355        $this->doc .= htmlspecialchars($link,ENT_COMPAT,'UTF-8',false);
356        $this->doc .= '</link>'.DOKU_LF;
357        $this->doc .= '<title>'.DOKU_LF;
358        $this->doc .= htmlspecialchars($title,ENT_COMPAT,'UTF-8',false);
359        $this->doc .= '</title>'.DOKU_LF;
360        $this->doc .= '</internallink>'.DOKU_LF;
361    }
362
363    // $link is full URL with scheme, $title could be an array (media)
364    function externallink($link, $title = NULL) {
365        $this->doc .= '<externallink>'.DOKU_LF;
366        $this->doc .= '<link>'.DOKU_LF;
367        $this->doc .= htmlspecialchars($link,ENT_COMPAT,'UTF-8',false);
368        $this->doc .= '</link>'.DOKU_LF;
369        $this->doc .= '<title>'.DOKU_LF;
370        $this->doc .= htmlspecialchars($title,ENT_COMPAT,'UTF-8',false); // FIXME: could be an array
371        $this->doc .= '</title>'.DOKU_LF;
372        $this->doc .= '</externallink>'.DOKU_LF;
373    }
374
375    // $link is the original link - probably not much use
376    // $wikiName is an indentifier for the wiki
377    // $wikiUri is the URL fragment to append to some known URL
378    function interwikilink($link, $title = NULL, $wikiName, $wikiUri) {
379        $this->doc .= '<interwikilink>'.DOKU_LF;
380        $this->doc .= '<link>'.DOKU_LF;
381        $this->doc .= htmlspecialchars($link,ENT_COMPAT,'UTF-8',false);
382        $this->doc .= '</link>'.DOKU_LF;
383        $this->doc .= '<title>'.DOKU_LF;
384        $this->doc .= htmlspecialchars($title,ENT_COMPAT,'UTF-8',false);
385        $this->doc .= '</title>'.DOKU_LF;
386        $this->doc .= '<wikiName>'.DOKU_LF;
387        $this->doc .= htmlspecialchars($wikiName,ENT_COMPAT,'UTF-8',false);
388        $this->doc .= '</wikiName>'.DOKU_LF;
389        $this->doc .= '<wikiUri>'.DOKU_LF;
390        $this->doc .= htmlspecialchars($wikiUri,ENT_COMPAT,'UTF-8',false);
391        $this->doc .= '</wikiUri>'.DOKU_LF;
392        $this->doc .= '</interwikilink>'.DOKU_LF;
393    }
394
395    // Link to file on users OS, $title could be an array (media)
396    function filelink($link, $title = NULL) {
397        $this->doc .= '<filelink>'.DOKU_LF;
398        $this->doc .= '<link>'.DOKU_LF;
399        $this->doc .= htmlspecialchars($link,ENT_COMPAT,'UTF-8',false);
400        $this->doc .= '</link>'.DOKU_LF;
401        $this->doc .= '<title>'.DOKU_LF;
402        $this->doc .= htmlspecialchars($title,ENT_COMPAT,'UTF-8',false);
403        $this->doc .= '</title>'.DOKU_LF;
404        $this->doc .= '</filelink>'.DOKU_LF;
405    }
406
407    // Link to a Windows share, , $title could be an array (media)
408    function windowssharelink($link, $title = NULL) {
409        $this->doc .= '<windowssharelink>'.DOKU_LF;
410        $this->doc .= '<link>'.DOKU_LF;
411        $this->doc .= htmlspecialchars($link,ENT_COMPAT,'UTF-8',false);
412        $this->doc .= '</link>'.DOKU_LF;
413        $this->doc .= '<title>'.DOKU_LF;
414        $this->doc .= htmlspecialchars($title,ENT_COMPAT,'UTF-8',false);
415        $this->doc .= '</title>'.DOKU_LF;
416        $this->doc .= '</windowssharelink>'.DOKU_LF;
417    }
418
419//  function email($address, $title = NULL) {}
420    function emaillink($address, $name = NULL) {
421        $this->doc .= '<emaillink>'.DOKU_LF;
422        $this->doc .= '<address>'.DOKU_LF;
423        $this->doc .= htmlspecialchars($address,ENT_COMPAT,'UTF-8',false);
424        $this->doc .= '</address>'.DOKU_LF;
425        $this->doc .= '<name>'.DOKU_LF;
426        $this->doc .= htmlspecialchars($name,ENT_COMPAT,'UTF-8',false);
427        $this->doc .= '</name>'.DOKU_LF;
428        $this->doc .= '</emaillink>'.DOKU_LF;
429}
430
431    function internalmedia ($src, $title=NULL, $align=NULL, $width=NULL,
432                            $height=NULL, $cache=NULL, $linking=NULL) {
433        $this->doc .= '<internalmedia align="' . $align . '" width="' . $width . '" height="' . $height . '" cache="' . $cache . '" linking="' . $linking . '">'.DOKU_LF;
434        $this->doc .= '<src>'.DOKU_LF;
435        $this->doc .= htmlspecialchars($src,ENT_COMPAT,'UTF-8',false);
436        $this->doc .= '</src>'.DOKU_LF;
437        $this->doc .= '<title>'.DOKU_LF;
438        $this->doc .= htmlspecialchars($title,ENT_COMPAT,'UTF-8',false);
439        $this->doc .= '</title>'.DOKU_LF;
440        $this->doc .= '</internalmedia>'.DOKU_LF;
441    }
442
443    function externalmedia ($src, $title=NULL, $align=NULL, $width=NULL,
444                            $height=NULL, $cache=NULL, $linking=NULL) {
445        $this->doc .= '<externalmedia align="' . $align . '" width="' . $width . '" height="' . $height . '" cache="' . $cache . '" linking="' . $linking . '">'.DOKU_LF;
446        $this->doc .= '<src>'.DOKU_LF;
447        $this->doc .= htmlspecialchars($src,ENT_COMPAT,'UTF-8',false);
448        $this->doc .= '</src>'.DOKU_LF;
449        $this->doc .= '<title>'.DOKU_LF;
450        $this->doc .= htmlspecialchars($title,ENT_COMPAT,'UTF-8',false);
451        $this->doc .= '</title>'.DOKU_LF;
452        $this->doc .= '</externalmedia>'.DOKU_LF;
453    }
454
455    function internalmedialink (
456        $src,$title=NULL,$align=NULL,$width=NULL,$height=NULL,$cache=NULL
457        ) {
458        $this->doc .= '<internalmedialink align="' . $align . '" width="' . $width . '" height="' . $height . '" cache="' . $cache . '">'.DOKU_LF;
459        $this->doc .= '<src>'.DOKU_LF;
460        $this->doc .= htmlspecialchars($src,ENT_COMPAT,'UTF-8',false);
461        $this->doc .= '</src>'.DOKU_LF;
462        $this->doc .= '<title>'.DOKU_LF;
463        $this->doc .= htmlspecialchars($title,ENT_COMPAT,'UTF-8',false);
464        $this->doc .= '</title>'.DOKU_LF;
465        $this->doc .= '</internalmedialink>'.DOKU_LF;
466    }
467
468    function externalmedialink(
469        $src,$title=NULL,$align=NULL,$width=NULL,$height=NULL,$cache=NULL
470        ) {
471        $this->doc .= '<externalmedialink align="' . $align . '" width="' . $width . '" height="' . $height . '" cache="' . $cache . '">'.DOKU_LF;
472        $this->doc .= '<src>'.DOKU_LF;
473        $this->doc .= htmlspecialchars($src,ENT_COMPAT,'UTF-8',false);
474        $this->doc .= '</src>'.DOKU_LF;
475        $this->doc .= '<title>'.DOKU_LF;
476        $this->doc .= htmlspecialchars($title,ENT_COMPAT,'UTF-8',false);
477        $this->doc .= '</title>'.DOKU_LF;
478        $this->doc .= '</externalmedialink>'.DOKU_LF;
479    }
480
481    function table_open($maxcols = NULL, $numrows = NULL){
482        $this->doc .= '<table maxcols="' . $maxcols . '" numrows="' . $numrows . '">'.DOKU_LF;
483    }
484
485    function table_close(){
486        $this->doc .= '</table>'.DOKU_LF;
487    }
488
489    function tablerow_open(){
490        $this->doc .= '<tablerow>'.DOKU_LF;
491    }
492
493    function tablerow_close(){
494        $this->doc .= '</tablerow>'.DOKU_LF;
495    }
496
497    function tableheader_open($colspan = 1, $align = NULL){
498        $this->doc .= '<tableheader colspan="' . $colspan . '" align="' . $align . '">'.DOKU_LF;
499    }
500
501    function tableheader_close(){
502        $this->doc .= '</tableheader>'.DOKU_LF;
503    }
504
505    function tablecell_open($colspan = 1, $align = NULL){
506        $this->doc .= '<tablecell colspan="' . $colspan . '" align="' . $align . '">'.DOKU_LF;
507    }
508
509    function tablecell_close(){
510        $this->doc .= '</tablecell>'.DOKU_LF;
511    }
512
513}
514
515
516//Setup VIM: ex: et ts=4 enc=utf-8 :
517