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
|
<?php
/**
*
* @todo maybe wrap in class
* @todo rename to helper
*/
if(!defined('DOKU_INC')) define('DOKU_INC',realpath(dirname(__FILE__).'/../../').'/');
require_once(DOKU_INC.'inc/utils.php');
function parse_to_instructions($text){
global $conf;
require_once DOKU_INC . 'inc/parser/parser.php';
// Create the parser
$Parser = & new Doku_Parser();
// Add the Handler
$Parser->Handler = & new Doku_Handler();
// Load all the modes
$Parser->addMode('listblock',new Doku_Parser_Mode_ListBlock());
$Parser->addMode('preformatted',new Doku_Parser_Mode_Preformatted());
$Parser->addMode('notoc',new Doku_Parser_Mode_NoToc());
$Parser->addMode('header',new Doku_Parser_Mode_Header());
$Parser->addMode('table',new Doku_Parser_Mode_Table());
$formats = array (
'strong', 'emphasis', 'underline', 'monospace',
'subscript', 'superscript', 'deleted',
);
foreach ( $formats as $format ) {
$Parser->addMode($format,new Doku_Parser_Mode_Formatting($format));
}
$Parser->addMode('linebreak',new Doku_Parser_Mode_Linebreak());
$Parser->addMode('footnote',new Doku_Parser_Mode_Footnote());
$Parser->addMode('hr',new Doku_Parser_Mode_HR());
$Parser->addMode('unformatted',new Doku_Parser_Mode_Unformatted());
$Parser->addMode('php',new Doku_Parser_Mode_PHP());
$Parser->addMode('html',new Doku_Parser_Mode_HTML());
$Parser->addMode('code',new Doku_Parser_Mode_Code());
$Parser->addMode('file',new Doku_Parser_Mode_File());
$Parser->addMode('quote',new Doku_Parser_Mode_Quote());
// FIXME These need data files...
$Parser->addMode('smiley',new Doku_Parser_Mode_Smiley(array_keys(getSmileys())));
$Parser->addMode('acronym',new Doku_Parser_Mode_Acronym(array_keys(getAcronyms())));
#$Parser->addMode('wordblock',new Doku_Parser_Mode_Wordblock(getBadWords()));
$Parser->addMode('entity',new Doku_Parser_Mode_Entity(array_keys(getEntities())));
$Parser->addMode('multiplyentity',new Doku_Parser_Mode_MultiplyEntity());
$Parser->addMode('quotes',new Doku_Parser_Mode_Quotes());
if($conf['camelcase']){
$Parser->addMode('camelcaselink',new Doku_Parser_Mode_CamelCaseLink());
}
$Parser->addMode('internallink',new Doku_Parser_Mode_InternalLink());
$Parser->addMode('media',new Doku_Parser_Mode_Media());
$Parser->addMode('externallink',new Doku_Parser_Mode_ExternalLink());
$Parser->addMode('email',new Doku_Parser_Mode_Email());
$Parser->addMode('windowssharelink',new Doku_Parser_Mode_WindowsShareLink());
//$Parser->addMode('filelink',new Doku_Parser_Mode_FileLink()); //FIXME ???
$Parser->addMode('eol',new Doku_Parser_Mode_Eol());
// Do the parsing
return $Parser->parse($text);
}
function render_as_xhtml($instructions){
#dbg($instructions);
// Create the renderer
require_once DOKU_INC . 'inc/parser/xhtml.php';
$Renderer = & new Doku_Renderer_XHTML();
//FIXME add data
$Renderer->smileys = getSmileys();
$Renderer->entities = getEntities();
$Renderer->acronyms = getAcronyms();
$Renderer->interwiki = getInterwiki();
#$Renderer->badwords = getBadWords();
// Loop through the instructions
foreach ( $instructions as $instruction ) {
// Execute the callback against the Renderer
call_user_func_array(array(&$Renderer, $instruction[0]),$instruction[1]);
}
// Return the output
return $Renderer->doc;
}
/**
* Returns a full page id
*
* @todo move to renderer?
*/
function resolve_pageid(&$page,&$exists){
global $ID;
global $conf;
$ns = getNS($ID);
//if links starts with . add current namespace
if($page{0} == '.'){
$page = $ns.':'.substr($page,1);
}
//if link contains no namespace. add current namespace (if any)
if($ns !== false && strpos($page,':') === false){
$page = $ns.':'.$page;
}
//keep hashlink if exists then clean both parts
list($page,$hash) = split('#',$page,2);
$page = cleanID($page);
$hash = cleanID($hash);
$file = wikiFN($page);
$exists = false;
//check alternative plural/nonplural form
if(!@file_exists($file)){
if( $conf['autoplural'] ){
if(substr($page,-1) == 's'){
$try = substr($page,0,-1);
}else{
$try = $page.'s';
}
if(@file_exists(wikiFN($try))){
$page = $try;
$exists = true;
}
}
}else{
$exists = true;
}
//add hash if any
if(!empty($hash)) $page.'#'.$hash;
}
?>
|