forked from danny0838/dokuwiki-plugin-xml
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathrenderer.php
More file actions
471 lines (385 loc) · 14.2 KB
/
Copy pathrenderer.php
File metadata and controls
471 lines (385 loc) · 14.2 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
<?php
/**
* DokuWiki Plugin xml
*
* Original:
* @author Patrick Bueker <Patrick@patrickbueker.de>
* @license GPLv2 or later (http://www.gnu.org/licenses/gpl.html)
*
* Reworked:
* @author Danny Lin <danny0838@pchome.com.tw>
*
*/
// must be run within Dokuwiki
if(!defined('DOKU_INC')) die();
if (!defined('DOKU_LF')) define('DOKU_LF', "\n");
if (!defined('DOKU_TAB')) define('DOKU_TAB', "\t");
require_once DOKU_INC . 'inc/parser/renderer.php';
class renderer_plugin_xml extends Doku_Renderer {
function __construct() {
$this->reset();
}
// allows renderer to be used again, clean out any per-use values
function reset() {
$this->info = array(
'cache' => true, // may the rendered result cached?
'toc' => false, // render the TOC?
);
$this->precedinglevel = array();
$this->nextHeader = "";
$this->helper = &plugin_load('helper','xml');
$this->doc = '';
}
/**
* Returns the format produced by this renderer.
*
* Has to be overidden by decendend classes
*/
function getFormat(){return 'xml';}
/**
* handle plugin rendering
*/
function plugin($name,$data){
$plugin =& plugin_load('syntax',$name);
if ($plugin == null) return;
if ($this->helper->_xml_extension($this,$name,$data)) return;
$plugin->render($this->getFormat(),$this,$data);
}
/**
* Handles instructions
*
* @Stack: add post-start linefeed and post-end linefeed
* @Stack content: add post-start tab and post-end linefeed
* @Block: add post-end linefeed
*
* ~~SOMETHING>params~~ treated as <macro type="something" params />
*/
function document_start() {
global $ID;
global $INFO;
$this->doc = '<?xml version="1.0" encoding="UTF-8"?>'.DOKU_LF;
$this->doc .= '<document domain="' . DOKU_URL .'" id="' . cleanID($ID) . '" revision="' . $INFO['rev'] . '" lastmod="' . $INFO['lastmod'] . '">'.DOKU_LF;
// store the content type headers in metadata
$output_filename = str_replace(':','-',$ID).".xml";
$headers = array(
'Content-Type' => 'text/xml; charset=utf-8;',
'Content-Disposition' => 'attachment; filename="'.$output_filename.'";',
);
p_set_metadata($ID,array('format' => array('xml' => $headers) ));
}
function document_end() {
while(count($this->precedinglevel)>0)
{
$this->doc .= '</section>'.'<!--' . array_pop($this->precedinglevel) . '-->'.DOKU_LF;
}
$this->doc .= '</document>'.DOKU_LF;
}
function header($text, $level, $pos) {
if (!$text) return; //skip empty headlines
$this->nextHeader = '<header level="' . $level . '" pos="' . $pos . '">'.
$this->nextHeader .= $this->_xmlEntities($text);
$this->nextHeader .= '</header>'.DOKU_LF;
}
function section_open($level) {
while(end($this->precedinglevel) >= $level)
{
$this->doc .= '</section>'.'<!--' . array_pop($this->precedinglevel) . '-->'.DOKU_LF;
}
$this->doc .= '<section level="' . $level . '">'.DOKU_LF;
$this->doc .= $this->nextHeader;
$this->nextHeader = "";
array_push($this->precedinglevel,$level);
}
function section_close() {
#$this->doc .= '</section>'.DOKU_LF;
}
function nocache() {
$this->info['cache'] = false;
$this->doc .= '<macro name="nocache" />'.DOKU_LF;
}
function notoc() {
$this->info['toc'] = false;
$this->doc .= '<macro name="notoc" />'.DOKU_LF;
}
function cdata($text) {
$this->doc .= $this->_xmlEntities($text);
}
function p_open() {
$this->doc .= '<p>';
}
function p_close() {
$this->doc .= '</p>'.DOKU_LF;
}
function linebreak() {
$this->doc .= '<linebreak/>';
}
function hr() {
$this->doc .= '<hr/>'.DOKU_LF;
}
function strong_open() {
$this->doc .= '<strong>';
}
function strong_close() {
$this->doc .= '</strong>';
}
function emphasis_open() {
$this->doc .= '<emphasis>';
}
function emphasis_close() {
$this->doc .= '</emphasis>';
}
function underline_open() {
$this->doc .= '<underline>';
}
function underline_close() {
$this->doc .= '</underline>';
}
function monospace_open() {
$this->doc .= '<monospace>';
}
function monospace_close() {
$this->doc .= '</monospace>';
}
function subscript_open() {
$this->doc .= '<subscript>';
}
function subscript_close() {
$this->doc .= '</subscript>';
}
function superscript_open() {
$this->doc .= '<superscript>';
}
function superscript_close() {
$this->doc .= '</superscript>';
}
function deleted_open() {
$this->doc .= '<delete>';
}
function deleted_close() {
$this->doc .= '</delete>';
}
function footnote_open() {
$this->doc .= '<footnote>';
}
function footnote_close() {
$this->doc .= '</footnote>';
}
function listu_open() {
$this->doc .= '<listu>'.DOKU_LF;
}
function listu_close() {
$this->doc .= '</listu>'.DOKU_LF;
}
function listo_open() {
$this->doc .= '<listo>'.DOKU_LF;
}
function listo_close() {
$this->doc .= '</listo>'.DOKU_LF;
}
function listitem_open($level) {
$this->doc .= DOKU_TAB.'<listitem level="' . $level . '">';
}
function listitem_close() {
$this->doc .= '</listitem>'.DOKU_LF;
}
function listcontent_open() {
$this->doc .= '<listcontent>';
}
function listcontent_close() {
$this->doc .= '</listcontent>';
}
function unformatted($text) {
$this->doc .= '<unformatted>';
$this->doc .= $this->_xmlEntities($text);
$this->doc .= '</unformatted>';
}
function php($text) {
$this->doc .= '<php>';
$this->doc .= $this->_xmlEntities($text);
$this->doc .= '</php>';
}
function phpblock($text) {
$this->doc .= '<phpblock>';
$this->doc .= $this->_xmlEntities($text);
$this->doc .= '</phpblock>'.DOKU_LF;
}
function html($text) {
$this->doc .= '<html>';
$this->doc .= $this->_xmlEntities($text);
$this->doc .= '</html>';
}
function htmlblock($text) {
$this->doc .= '<htmlblock>';
$this->doc .= $this->_xmlEntities($text);
$this->doc .= '</htmlblock>'.DOKU_LF;
}
function preformatted($text) {
$this->doc .= '<preformatted>';
$this->doc .= $this->_xmlEntities($text);
$this->doc .= '</preformatted>'.DOKU_LF;
}
function quote_open() {
$this->doc .= '<quote>';
}
function quote_close() {
$this->doc .= '</quote>'.DOKU_LF;
}
function code($text, $lang = NULL, $file = NULL) {
$this->doc .= '<code lang="' . $lang . '" file="' . $file . '">';
$this->doc .= $this->_xmlEntities($text);
$this->doc .= '</code>'.DOKU_LF;
}
function file($text, $lang = NULL, $file = NULL) {
$this->doc .= '<file lang="' . $lang . '" file="' . $file . '">';
$this->doc .= $this->_xmlEntities($text);
$this->doc .= '</file>'.DOKU_LF;
}
function acronym($acronym) {
$this->doc .= '<acronym>';
$this->doc .= $this->_xmlEntities($acronym);
$this->doc .= '</acronym>';
}
function smiley($smiley) {
$this->doc .= '<smiley>';
$this->doc .= $this->_xmlEntities($smiley);
$this->doc .= '</smiley>';
}
function entity($entity) {
$this->doc .= '<entity>';
$this->doc .= $this->_xmlEntities($entity);
$this->doc .= '</entity>';
}
// 640x480 ($x=640, $y=480)
function multiplyentity($x, $y) {
$this->doc .= '<multiplyentity>';
$this->doc .= '<x>'.$this->_xmlEntities($x).'</x>';
$this->doc .= '<y>'.$this->_xmlEntities($y).'</y>';
$this->doc .= '</multiplyentity>';
}
function singlequoteopening() {
$this->doc .= '<singlequote>';
}
function singlequoteclosing() {
$this->doc .= '</singlequote>';
}
function apostrophe() {
$this->doc .= '<apostrophe/>';
}
function doublequoteopening() {
$this->doc .= '<doublequote>';
}
function doublequoteclosing() {
$this->doc .= '</doublequote>';
}
// $link like 'SomePage'
function camelcaselink($link) {
$this->doc .= '<link type="camelcase" href="' . $this->_xmlEntities($link) . '">';
$this->doc .= $this->_xmlEntities($link);
$this->doc .= '</link>';
}
function locallink($hash, $name = NULL) {
$this->doc .= '<link type="locallink" href="' . $this->_xmlEntities($hash) . '">';
$this->doc .= $this->_getLinkTitle($name, $hash);
$this->doc .= '</link>';
}
// $link like 'wiki:syntax', $title could be an array (media)
function internallink($link, $title = NULL) {
$this->doc .= '<link type="internal" href="' . $this->_xmlEntities($link) . '">';
$this->doc .= $this->_getLinkTitle($title, $link);
$this->doc .= '</link>';
}
// $link is full URL with scheme, $title could be an array (media)
function externallink($link, $title = NULL) {
$this->doc .= '<link type="external" href="' . $this->_xmlEntities($link) . '">';
$this->doc .= $this->_getLinkTitle($title, $link);
$this->doc .= '</link>';
}
// $link is the original link - probably not much use
// $wikiName is an indentifier for the wiki
// $wikiUri is the URL fragment to append to some known URL
function interwikilink($link, $title = NULL, $wikiname, $wikiuri) {
$this->doc .= '<link type="interwiki" href="' . $this->_xmlEntities($link) . '" wikiname="' . $this->_xmlEntities($wikiname) . '" wikiuri="' . $this->_xmlEntities($wikiuri) . '">';
$this->doc .= $this->_getLinkTitle($title, $link);
$this->doc .= '</link>';
}
// Link to file on users OS, $title could be an array (media)
function filelink($link, $title = NULL) {
$this->doc .= '<link type="filelink" href="' . $this->_xmlEntities($link) . '">';
$this->doc .= $this->_getLinkTitle($title, $link);
$this->doc .= '</link>';
}
// Link to a Windows share, , $title could be an array (media)
function windowssharelink($link, $title = NULL) {
$this->doc .= '<link type="windowssharelink" href="' . $this->_xmlEntities($link) . '">';
$this->doc .= $this->_getLinkTitle($title, $link);
$this->doc .= '</link>';
}
// function email($address, $title = NULL) {}
function emaillink($address, $name = NULL) {
$this->doc .= '<link type="emaillink" href="' . $this->_xmlEntities($address) . '">';
$this->doc .= $this->_getLinkTitle($name, $address);
$this->doc .= '</link>';
}
function internalmedia ($src, $title=NULL, $align=NULL, $width=NULL, $height=NULL, $cache=NULL, $linking=NULL) {
$this->doc .= '<media type="internalmedia" src="' . $this->_xmlEntities($src) . '" align="' . $align . '" width="' . $width . '" height="' . $height . '" cache="' . $cache . '" linking="' . $linking . '">'.DOKU_LF;
$this->doc .= $this->_xmlEntities($title, $src);
$this->doc .= '</media>';
}
function externalmedia ($src, $title=NULL, $align=NULL, $width=NULL, $height=NULL, $cache=NULL, $linking=NULL) {
$this->doc .= '<media type="externalmedia" src="' . $this->_xmlEntities($src) . '" align="' . $align . '" width="' . $width . '" height="' . $height . '" cache="' . $cache . '" linking="' . $linking . '">';
$this->doc .= $this->_xmlEntities($title, $src);
$this->doc .= '</media>';
}
function internalmedialink ($src, $title=NULL, $align=NULL, $width=NULL, $height=NULL, $cache=NULL) {
$this->doc .= '<link type="internalmedialink" href="' . $this->_xmlEntities($src) . '" align="' . $align . '" width="' . $width . '" height="' . $height . '" cache="' . $cache . '">';
$this->doc .= $this->_xmlEntities($title, $src);
$this->doc .= '</link>';
}
function externalmedialink($src, $title=NULL, $align=NULL, $width=NULL, $height=NULL, $cache=NULL) {
$this->doc .= '<link type="externalmedialink" href="' . $this->_xmlEntities($src) . '" align="' . $align . '" width="' . $width . '" height="' . $height . '" cache="' . $cache . '">';
$this->doc .= $this->_xmlEntities($title, $src);
$this->doc .= '</externalmedialink>';
}
function table_open($maxcols = NULL, $numrows = NULL){
$this->doc .= '<table maxcols="' . $maxcols . '" numrows="' . $numrows . '">'.DOKU_LF;
}
function table_close(){
$this->doc .= '</table>'.DOKU_LF;
}
function tablerow_open(){
$this->doc .= DOKU_TAB.'<tablerow>';
}
function tablerow_close(){
$this->doc .= '</tablerow>'.DOKU_LF;
}
function tableheader_open($colspan = 1, $align = NULL){
$this->doc .= '<tableheader colspan="' . $colspan . '" align="' . $align . '">';
}
function tableheader_close(){
$this->doc .= '</tableheader>';
}
function tablecell_open($colspan = 1, $align = NULL){
$this->doc .= '<tablecell colspan="' . $colspan . '" align="' . $align . '">';
}
function tablecell_close(){
$this->doc .= '</tablecell>';
}
/**
* Private functions for internal handling
*/
function _xmlEntities($text){
return htmlspecialchars($text,ENT_COMPAT,'UTF-8');
}
function _getLinkTitle($title, $default){
if ( is_array($title) ) return $this->_imageTitle($title);
if ( is_null($title) || trim($title)=='' ) $title = $default;
return $this->_xmlEntities($title);
}
function _imageTitle($img) {
extract($img);
$out .= '<media type="' . $type . '" src="' . $this->_xmlEntities($src) . '" align="' . $align . '" width="' . $width . '" height="' . $height . '" cache="' . $cache . '" linking="' . $linking . '">';
$out .= $this->_xmlEntities($title);
$out .= '</media>';
return $out;
}
}