author | Dan |
Sat, 03 Nov 2007 07:43:35 -0400 | |
changeset 229 | 97ae8e9d5e29 |
parent 228 | b0a4d179be85 |
child 313 | 854eecfada20 |
permissions | -rw-r--r-- |
1 | 1 |
<?php |
73
0a74676a2f2f
Made the move to Loch Ness, and got some basic page grouping functionality working. TODO: fix some UI issues in Javascript ACL editor and change non-JS ACL editor to work with page groups too
Dan
parents:
67
diff
changeset
|
2 |
|
1 | 3 |
/* |
4 |
* Enano - an open-source CMS capable of wiki functions, Drupal-like sidebar blocks, and everything in between |
|
142
ca9118d9c0f2
Rebrand as 1.0.2 (Coblynau); internal links are now parsed by RenderMan::parse_internal_links()
Dan
parents:
136
diff
changeset
|
5 |
* Version 1.0.2 (Coblynau) |
73
0a74676a2f2f
Made the move to Loch Ness, and got some basic page grouping functionality working. TODO: fix some UI issues in Javascript ACL editor and change non-JS ACL editor to work with page groups too
Dan
parents:
67
diff
changeset
|
6 |
* Copyright (C) 2006-2007 Dan Fuhry |
1 | 7 |
* render.php - handles fetching pages and parsing them into HTML |
8 |
* |
|
9 |
* This program is Free Software; you can redistribute and/or modify it under the terms of the GNU General Public License |
|
10 |
* as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. |
|
11 |
* |
|
12 |
* This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied |
|
13 |
* warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for details. |
|
14 |
*/ |
|
15 |
||
16 |
class RenderMan { |
|
17 |
||
18 |
function strToPageID($string) |
|
19 |
{ |
|
20 |
global $db, $session, $paths, $template, $plugins; // Common objects |
|
21 |
$k = array_keys($paths->nslist); |
|
136
f2ee42f026f7
Fix: internal links parsed with RenderMan::parse_internal_links() did not get namespaces prepended; added Project: alias namespace for internal links
Dan
parents:
133
diff
changeset
|
22 |
$proj_alt = 'Project:'; |
f2ee42f026f7
Fix: internal links parsed with RenderMan::parse_internal_links() did not get namespaces prepended; added Project: alias namespace for internal links
Dan
parents:
133
diff
changeset
|
23 |
if ( substr($string, 0, (strlen($proj_alt))) == $proj_alt ) |
f2ee42f026f7
Fix: internal links parsed with RenderMan::parse_internal_links() did not get namespaces prepended; added Project: alias namespace for internal links
Dan
parents:
133
diff
changeset
|
24 |
{ |
f2ee42f026f7
Fix: internal links parsed with RenderMan::parse_internal_links() did not get namespaces prepended; added Project: alias namespace for internal links
Dan
parents:
133
diff
changeset
|
25 |
$ns = 'Project'; |
f2ee42f026f7
Fix: internal links parsed with RenderMan::parse_internal_links() did not get namespaces prepended; added Project: alias namespace for internal links
Dan
parents:
133
diff
changeset
|
26 |
$pg = substr($string, strlen($proj_alt), strlen($string)); |
f2ee42f026f7
Fix: internal links parsed with RenderMan::parse_internal_links() did not get namespaces prepended; added Project: alias namespace for internal links
Dan
parents:
133
diff
changeset
|
27 |
return Array($pg, $ns); |
f2ee42f026f7
Fix: internal links parsed with RenderMan::parse_internal_links() did not get namespaces prepended; added Project: alias namespace for internal links
Dan
parents:
133
diff
changeset
|
28 |
} |
1 | 29 |
for($i=0;$i<sizeof($paths->nslist);$i++) |
30 |
{ |
|
31 |
$ln = strlen($paths->nslist[$k[$i]]); |
|
32 |
if(substr($string, 0, $ln) == $paths->nslist[$k[$i]]) |
|
33 |
{ |
|
34 |
$ns = $k[$i]; |
|
35 |
$pg = substr($string, strlen($paths->nslist[$ns]), strlen($string)); |
|
36 |
} |
|
37 |
} |
|
38 |
return Array($pg, $ns); |
|
39 |
} |
|
40 |
||
41 |
function getPage($page_id, $namespace, $wiki = 1, $smilies = true, $filter_links = true, $redir = true, $render = true) |
|
42 |
{ |
|
43 |
global $db, $session, $paths, $template, $plugins; // Common objects |
|
44 |
dc_here('render: page requested<br />ID/namespace: '."$page_id, $namespace<br />Wiki mode: $wiki<br />Smilies: ".(string)$smilies."<br />Allow redirects: ".(string)$redir); |
|
45 |
||
46 |
$perms =& $session; |
|
47 |
||
48 |
if ( $page_id != $paths->cpage['urlname_nons'] || $namespace != $paths->namespace ) |
|
49 |
{ |
|
50 |
unset($perms); |
|
51 |
unset($perms); // PHP <5.1.5 Zend bug |
|
52 |
$perms = $session->fetch_page_acl($page_id, $namespace); |
|
53 |
} |
|
54 |
||
55 |
if(!$perms->get_permissions('read')) |
|
56 |
return 'Access denied ('.$paths->nslist[$namespace].$page_id.')'; |
|
57 |
||
58 |
if($wiki == 0 || $render == false) |
|
59 |
{ |
|
60 |
if(!$perms->get_permissions('view_source')) |
|
61 |
{ |
|
62 |
return 'Access denied ('.$paths->nslist[$namespace].$page_id.')'; |
|
63 |
} |
|
64 |
} |
|
65 |
||
66 |
$q = $db->sql_query('SELECT page_text,char_tag FROM '.table_prefix.'page_text WHERE page_id=\''.$db->escape($page_id).'\' AND namespace=\''.$db->escape($namespace).'\';'); |
|
67 |
if ( !$q ) |
|
68 |
{ |
|
69 |
$db->_die('Method called was: RenderMan::getPage(\''.$page_id.'\', \''.$namespace.'\');.'); |
|
70 |
} |
|
71 |
if ( $db->numrows() < 1 ) |
|
72 |
{ |
|
73 |
return false; |
|
74 |
} |
|
75 |
$row = $db->fetchrow(); |
|
76 |
$db->free_result(); |
|
77 |
||
78 |
$message = $row['page_text']; |
|
79 |
$chartag = $row['char_tag']; |
|
80 |
unset($row); // Free some memory |
|
81 |
||
133
af0f6ec48de3
Fully implemented password complexity enforcement; added encryption for passwords on registration form; some baby steps taken towards supporting international usernames - this is not working very well, we might need a hackish fix; TODO: implement password strength meter into installer UI and get international usernames 100% working
Dan
parents:
91
diff
changeset
|
82 |
if ( preg_match("#^\#redirect \[\[([^\]\r\n\a\t]+?)\]\]#", $message, $m) && $redir && ( !isset($_GET['redirect']) || ( isset($_GET['redirect']) && $_GET['redirect'] != 'no' ) ) ) |
1 | 83 |
{ |
84 |
dc_here('render: looks like a redirect page to me...'); |
|
85 |
$old = $paths->cpage; |
|
86 |
$a = RenderMan::strToPageID($m[1]); |
|
87 |
$a[0] = str_replace(' ', '_', $a[0]); |
|
88 |
||
89 |
$pageid = str_replace(' ', '_', $paths->nslist[$a[1]] . $a[0]); |
|
90 |
$paths->page = $pageid; |
|
91 |
$paths->cpage = $paths->pages[$pageid]; |
|
92 |
//die('<pre>'.print_r($paths->cpage,true).'</pre>'); |
|
93 |
||
94 |
dc_here('render: wreckin\' $template, and reloading the theme vars to match the new page<br />This might get messy!'); |
|
95 |
||
96 |
unset($template); |
|
97 |
unset($GLOBALS['template']); |
|
98 |
||
99 |
$GLOBALS['template'] = new template(); |
|
100 |
global $template; |
|
101 |
||
102 |
$template->template(); // Tear down and rebuild the template parser |
|
103 |
$template->load_theme($session->theme, $session->style); |
|
104 |
||
105 |
$data = '<div><small>(Redirected from <a href="'.makeUrlNS($old['namespace'], $old['urlname_nons'], 'redirect=no', true).'">'.$old['name'].'</a>)</small></div>'.RenderMan::getPage($a[0], $a[1], $wiki, $smilies, $filter_links, false /* Enforces a maximum of one redirect */); |
|
106 |
||
107 |
return $data; |
|
108 |
} |
|
109 |
else if(preg_match('#^\#redirect \[\[(.+?)\]\]#', $message, $m) && isset($_GET['redirect']) && $_GET['redirect'] == 'no') |
|
110 |
{ |
|
111 |
dc_here('render: looks like a redirect page to me...'); |
|
112 |
dc_here('render: skipping redirect as requested on URI'); |
|
113 |
preg_match('#^\#redirect \[\[(.+)\]\]#', $message, $m); |
|
114 |
$m[1] = str_replace(' ', '_', $m[1]); |
|
115 |
$message = preg_replace('#\#redirect \[\[(.+)\]\]#', '<nowiki><div class="mdg-infobox"><table border="0" width="100%" cellspacing="0" cellpadding="0"><tr><td valign="top"><img alt="Cute wet-floor icon" src="'.scriptPath.'/images/redirector.png" /></td><td valign="top" style="padding-left: 10px;"><b>This page is a <i>redirector</i>.</b><br />This means that this page will not show its own content by default. Instead it will display the contents of the page it redirects to.<br /><br />To create a redirect page, make the <i>first characters</i> in the page content <tt>#redirect [[Page_ID]]</tt>. For more information, see the Enano <a href="http://enanocms.org/Help:Wiki_formatting">Wiki formatting guide</a>.<br /><br />This page redirects to <a href="'.makeUrl($m[1]).'">'.$paths->pages[$m[1]]['name'].'</a>.</td></tr></table></div><br /><hr style="margin-left: 1em; width: 200px;" /></nowiki>', $message); |
|
116 |
} |
|
117 |
$session->disallow_password_grab(); |
|
118 |
dc_here('render: alright, got the text, formatting...'); |
|
119 |
return ($render) ? RenderMan::render($message, $wiki, $smilies, $filter_links) : $message; |
|
120 |
} |
|
121 |
||
122 |
function getTemplate($id, $parms) |
|
123 |
{ |
|
124 |
global $db, $session, $paths, $template, $plugins; // Common objects |
|
125 |
dc_here('render: template requested: '.$id); |
|
126 |
if(!isset($paths->pages[$paths->nslist['Template'].$id])) |
|
127 |
{ |
|
128 |
return '[['.$paths->nslist['Template'].$id.']]'; |
|
129 |
} |
|
130 |
if(isset($paths->template_cache[$id])) |
|
131 |
{ |
|
132 |
$text = $paths->template_cache[$id]; |
|
133 |
} |
|
134 |
else |
|
135 |
{ |
|
136 |
$text = RenderMan::getPage($id, 'Template', 0, true, true, 0); |
|
137 |
$paths->template_cache[$id] = $text; |
|
138 |
} |
|
139 |
||
140 |
$text = preg_replace('/<noinclude>(.*?)<\/noinclude>/is', '', $text); |
|
141 |
$text = preg_replace('/<nodisplay>(.*?)<\/nodisplay>/is', '\\1', $text); |
|
142 |
||
143 |
preg_match_all('#\(_([0-9]+)_\)#', $text, $matchlist); |
|
144 |
||
145 |
foreach($matchlist[1] as $m) |
|
146 |
{ |
|
147 |
if(isset($parms[((int)$m)+1])) |
|
148 |
{ |
|
149 |
$p = $parms[((int)$m)+1]; |
|
150 |
} |
|
151 |
else |
|
152 |
{ |
|
153 |
$p = '<b>Notice:</b> RenderMan::getTemplate(): Parameter '.$m.' is not set'; |
|
154 |
} |
|
155 |
$text = str_replace('(_'.$m.'_)', $p, $text); |
|
156 |
} |
|
157 |
$text = RenderMan::include_templates($text); |
|
158 |
return $text; |
|
159 |
} |
|
160 |
||
161 |
function fetch_template_text($id) |
|
162 |
{ |
|
163 |
global $db, $session, $paths, $template, $plugins; // Common objects |
|
164 |
dc_here('render: template raw data requested: '.$id); |
|
165 |
if(!isset($paths->pages[$paths->nslist['Template'].$id])) |
|
166 |
{ |
|
167 |
return '[['.$paths->nslist['Template'].$id.']]'; |
|
168 |
} |
|
169 |
if(isset($paths->template_cache[$id])) |
|
170 |
{ |
|
171 |
$text = $paths->template_cache[$id]; |
|
172 |
} |
|
173 |
else |
|
174 |
{ |
|
175 |
$text = RenderMan::getPage($id, 'Template', 0, false, false, false, false); |
|
176 |
$paths->template_cache[$id] = $text; |
|
177 |
} |
|
178 |
||
179 |
if ( is_string($text) ) |
|
180 |
{ |
|
181 |
$text = preg_replace('/<noinclude>(.*?)<\/noinclude>/is', '', $text); |
|
182 |
$text = preg_replace('/<nodisplay>(.*?)<\/nodisplay>/is', '\\1', $text); |
|
183 |
} |
|
184 |
||
185 |
return $text; |
|
186 |
} |
|
187 |
||
188 |
function render($text, $wiki = 1, $smilies = true, $filter_links = true) |
|
189 |
{ |
|
190 |
global $db, $session, $paths, $template, $plugins; // Common objects |
|
191 |
if($smilies) |
|
192 |
{ |
|
193 |
$text = RenderMan::smilieyize($text); |
|
194 |
} |
|
195 |
if($wiki == 1) |
|
196 |
{ |
|
197 |
$text = RenderMan::next_gen_wiki_format($text); |
|
198 |
} |
|
199 |
elseif($wiki == 2) |
|
200 |
{ |
|
201 |
$text = $template->tplWikiFormat($text); |
|
202 |
} |
|
203 |
return $text; |
|
204 |
} |
|
205 |
||
206 |
function PlainTextRender($text, $wiki = 1, $smilies = false, $filter_links = true) |
|
207 |
{ |
|
208 |
global $db, $session, $paths, $template, $plugins; // Common objects |
|
209 |
if($smilies) |
|
210 |
{ |
|
211 |
$text = RenderMan::smilieyize($text); |
|
212 |
} |
|
213 |
if($wiki == 1) |
|
214 |
{ |
|
215 |
$text = RenderMan::next_gen_wiki_format($text, true); |
|
216 |
} |
|
217 |
elseif($wiki == 2) |
|
218 |
{ |
|
219 |
$text = $template->tplWikiFormat($text); |
|
220 |
} |
|
221 |
return $text; |
|
222 |
} |
|
223 |
||
224 |
function next_gen_wiki_format($text, $plaintext = false, $filter_links = true, $do_params = false) |
|
225 |
{ |
|
226 |
global $db, $session, $paths, $template, $plugins; // Common objects |
|
227 |
$random_id = md5( time() . mt_rand() ); |
|
228 |
||
229 |
// Strip out <nowiki> sections and PHP code |
|
230 |
||
231 |
$php = preg_match_all('#<\?php(.*?)\?>#is', $text, $phpsec); |
|
232 |
||
233 |
for($i=0;$i<sizeof($phpsec[1]);$i++) |
|
234 |
{ |
|
235 |
$text = str_replace('<?php'.$phpsec[1][$i].'?>', '{PHP:'.$random_id.':'.$i.'}', $text); |
|
236 |
} |
|
237 |
||
238 |
$nw = preg_match_all('#<nowiki>(.*?)<\/nowiki>#is', $text, $nowiki); |
|
239 |
||
240 |
for($i=0;$i<sizeof($nowiki[1]);$i++) |
|
241 |
{ |
|
242 |
$text = str_replace('<nowiki>'.$nowiki[1][$i].'</nowiki>', '{NOWIKI:'.$random_id.':'.$i.'}', $text); |
|
243 |
} |
|
244 |
||
245 |
$text = preg_replace('/<noinclude>(.*?)<\/noinclude>/is', '\\1', $text); |
|
246 |
if ( $paths->namespace == 'Template' ) |
|
247 |
{ |
|
248 |
$text = preg_replace('/<nodisplay>(.*?)<\/nodisplay>/is', '', $text); |
|
249 |
} |
|
250 |
||
163 | 251 |
$code = $plugins->setHook('render_wikiformat_pre'); |
252 |
foreach ( $code as $cmd ) |
|
253 |
{ |
|
254 |
eval($cmd); |
|
255 |
} |
|
256 |
||
1 | 257 |
if ( !$plaintext ) |
258 |
{ |
|
259 |
// Process images |
|
142
ca9118d9c0f2
Rebrand as 1.0.2 (Coblynau); internal links are now parsed by RenderMan::parse_internal_links()
Dan
parents:
136
diff
changeset
|
260 |
$text = RenderMan::process_image_tags($text, $taglist); |
66
52017732bc20
Added "raw" option to embedded images to make complex clickables easier
Dan
parents:
65
diff
changeset
|
261 |
$text = RenderMan::process_imgtags_stage2($text, $taglist); |
1 | 262 |
} |
263 |
||
264 |
if($do_params) |
|
265 |
{ |
|
266 |
preg_match_all('#\(_([0-9]+)_\)#', $text, $matchlist); |
|
267 |
foreach($matchlist[1] as $m) |
|
268 |
{ |
|
269 |
$text = str_replace('(_'.$m.'_)', $paths->getParam((int)$m), $text); |
|
270 |
} |
|
271 |
} |
|
272 |
||
174
4c5c2b66a34d
SECURITY: remove debug message in session manager; implemented alternate MediaWiki syntax for template embedding; added Adobe Spry for "shake" effect on unsuccessful login
Dan
parents:
163
diff
changeset
|
273 |
//$template_regex = "/\{\{([^\]]+?)((\n([ ]*?)[A-z0-9]+([ ]*?)=([ ]*?)(.+?))*)\}\}/is"; |
4c5c2b66a34d
SECURITY: remove debug message in session manager; implemented alternate MediaWiki syntax for template embedding; added Adobe Spry for "shake" effect on unsuccessful login
Dan
parents:
163
diff
changeset
|
274 |
$template_regex = "/\{\{(.+)((\n|\|[ ]*([A-z0-9]+)[ ]*=[ ]*(.+))*)\}\}/isU"; |
63
2c57d3018a88
Fixed recursive template inclusion and spaces in template tags ({{Foo template}})
Dan
parents:
37
diff
changeset
|
275 |
$i = 0; |
2c57d3018a88
Fixed recursive template inclusion and spaces in template tags ({{Foo template}})
Dan
parents:
37
diff
changeset
|
276 |
while ( preg_match($template_regex, $text) ) |
2c57d3018a88
Fixed recursive template inclusion and spaces in template tags ({{Foo template}})
Dan
parents:
37
diff
changeset
|
277 |
{ |
2c57d3018a88
Fixed recursive template inclusion and spaces in template tags ({{Foo template}})
Dan
parents:
37
diff
changeset
|
278 |
$i++; |
2c57d3018a88
Fixed recursive template inclusion and spaces in template tags ({{Foo template}})
Dan
parents:
37
diff
changeset
|
279 |
if ( $i == 5 ) |
2c57d3018a88
Fixed recursive template inclusion and spaces in template tags ({{Foo template}})
Dan
parents:
37
diff
changeset
|
280 |
break; |
2c57d3018a88
Fixed recursive template inclusion and spaces in template tags ({{Foo template}})
Dan
parents:
37
diff
changeset
|
281 |
$text = RenderMan::include_templates($text); |
2c57d3018a88
Fixed recursive template inclusion and spaces in template tags ({{Foo template}})
Dan
parents:
37
diff
changeset
|
282 |
} |
1 | 283 |
|
284 |
$text = process_tables($text); |
|
142
ca9118d9c0f2
Rebrand as 1.0.2 (Coblynau); internal links are now parsed by RenderMan::parse_internal_links()
Dan
parents:
136
diff
changeset
|
285 |
$text = RenderMan::parse_internal_links($text); |
1 | 286 |
|
287 |
$wiki =& Text_Wiki::singleton('Mediawiki'); |
|
288 |
if($plaintext) |
|
289 |
{ |
|
290 |
$wiki->setRenderConf('Plain', 'wikilink', 'view_url', contentPath); |
|
291 |
$result = $wiki->transform($text, 'Plain'); |
|
292 |
} |
|
293 |
else |
|
294 |
{ |
|
295 |
$wiki->setRenderConf('Xhtml', 'wikilink', 'view_url', contentPath); |
|
296 |
$wiki->setRenderConf('Xhtml', 'Url', 'css_descr', 'external'); |
|
297 |
$result = $wiki->transform($text, 'Xhtml'); |
|
298 |
} |
|
299 |
||
163 | 300 |
// HTML fixes |
301 |
$result = preg_replace('#<tr>([\s]*?)<\/tr>#is', '', $result); |
|
302 |
$result = preg_replace('#<p>([\s]*?)<\/p>#is', '', $result); |
|
303 |
$result = preg_replace('#<br />([\s]*?)<table#is', '<table', $result); |
|
304 |
$result = str_replace("<pre><code>\n", "<pre><code>", $result); |
|
305 |
$result = preg_replace("/<p><table([^>]*?)><\/p>/", "<table\\1>", $result); |
|
306 |
$result = str_replace("<br />\n</td>", "\n</td>", $result); |
|
307 |
$result = str_replace("<p><tr>", "<tr>", $result); |
|
308 |
$result = str_replace("<tr><br />", "<tr>", $result); |
|
309 |
$result = str_replace("</tr><br />", "</tr>", $result); |
|
310 |
$result = str_replace("</table><br />", "</table>", $result); |
|
311 |
$result = preg_replace('/<\/table>$/', "</table><br /><br />", $result); |
|
312 |
$result = str_replace("<p></div></p>", "</div>", $result); |
|
313 |
$result = str_replace("<p></table></p>", "</table>", $result); |
|
314 |
||
315 |
$code = $plugins->setHook('render_wikiformat_post'); |
|
316 |
foreach ( $code as $cmd ) |
|
317 |
{ |
|
318 |
eval($cmd); |
|
319 |
} |
|
37 | 320 |
|
1 | 321 |
// Reinsert <nowiki> sections |
322 |
for($i=0;$i<$nw;$i++) |
|
323 |
{ |
|
324 |
$result = str_replace('{NOWIKI:'.$random_id.':'.$i.'}', $nowiki[1][$i], $result); |
|
325 |
} |
|
326 |
||
327 |
// Reinsert PHP |
|
328 |
for($i=0;$i<$php;$i++) |
|
329 |
{ |
|
330 |
$result = str_replace('{PHP:'.$random_id.':'.$i.'}', '<?php'.$phpsec[1][$i].'?>', $result); |
|
331 |
} |
|
332 |
||
333 |
return $result; |
|
334 |
||
335 |
} |
|
336 |
||
163 | 337 |
function wikiFormat($message, $filter_links = true, $do_params = false, $plaintext = false) |
338 |
{ |
|
1 | 339 |
global $db, $session, $paths, $template, $plugins; // Common objects |
340 |
||
341 |
return RenderMan::next_gen_wiki_format($message, $plaintext, $filter_links, $do_params); |
|
342 |
||
343 |
$random_id = md5( time() . mt_rand() ); |
|
344 |
||
345 |
// Strip out <nowiki> sections |
|
346 |
$nw = preg_match_all('#<nowiki>(.*?)<\/nowiki>#is', $message, $nowiki); |
|
347 |
||
348 |
if(!$plaintext) |
|
349 |
{ |
|
350 |
||
351 |
//return '<pre>'.print_r($nowiki,true).'</pre>'; |
|
352 |
||
353 |
for($i=0;$i<sizeof($nowiki[1]);$i++) |
|
354 |
{ |
|
355 |
$message = str_replace('<nowiki>'.$nowiki[1][$i].'</nowiki>', '{NOWIKI:'.$random_id.':'.$i.'}', $message); |
|
356 |
} |
|
357 |
||
358 |
$message = preg_replace('/<noinclude>(.*?)<\/noinclude>/is', '\\1', $message); |
|
359 |
||
360 |
//return '<pre>'.htmlspecialchars($message).'</pre>'; |
|
361 |
||
35 | 362 |
$message = RenderMan::process_image_tags($message); |
1 | 363 |
|
364 |
} |
|
365 |
||
366 |
if($do_params) |
|
367 |
{ |
|
368 |
preg_match_all('#\(_([0-9]+)_\)#', $message, $matchlist); |
|
369 |
foreach($matchlist[1] as $m) |
|
370 |
{ |
|
371 |
$message = str_replace('(_'.$m.'_)', $paths->getParam((int)$m), $message); |
|
372 |
} |
|
373 |
} |
|
374 |
||
375 |
$message = RenderMan::include_templates($message); |
|
376 |
||
377 |
// Reinsert <nowiki> sections |
|
378 |
for($i=0;$i<$nw;$i++) |
|
379 |
{ |
|
380 |
$message = str_replace('{NOWIKI:'.$random_id.':'.$i.'}', '<nowiki>'.$nowiki[1][$i].'</nowiki>', $message); |
|
381 |
} |
|
382 |
||
383 |
$message = process_tables($message); |
|
384 |
//if($message2 != $message) return '<pre>'.htmlspecialchars($message2).'</pre>'; |
|
385 |
//$message = str_replace(array('<table>', '</table>'), array('<nowiki><table>', '</table></nowiki>'), $message); |
|
386 |
||
387 |
$wiki =& Text_Wiki::singleton('Mediawiki'); |
|
388 |
if($plaintext) |
|
389 |
{ |
|
390 |
$wiki->setRenderConf('Plain', 'wikilink', 'view_url', contentPath); |
|
391 |
$result = $wiki->transform($message, 'Plain'); |
|
392 |
} else { |
|
393 |
$wiki->setRenderConf('Xhtml', 'wikilink', 'view_url', contentPath); |
|
394 |
$wiki->setRenderConf('Xhtml', 'Url', 'css_descr', 'external'); |
|
395 |
$result = $wiki->transform($message, 'Xhtml'); |
|
396 |
} |
|
397 |
||
398 |
// HTML fixes |
|
399 |
$result = preg_replace('#<tr>([\s]*?)<\/tr>#is', '', $result); |
|
400 |
$result = preg_replace('#<p>([\s]*?)<\/p>#is', '', $result); |
|
401 |
$result = preg_replace('#<br />([\s]*?)<table#is', '<table', $result); |
|
402 |
$result = str_replace("<pre><code>\n", "<pre><code>", $result); |
|
403 |
$result = preg_replace("/<p><table([^>]*?)><\/p>/", "<table\\1>", $result); |
|
404 |
$result = str_replace("<br />\n</td>", "\n</td>", $result); |
|
405 |
$result = str_replace("<p><tr>", "<tr>", $result); |
|
406 |
$result = str_replace("<tr><br />", "<tr>", $result); |
|
407 |
$result = str_replace("</tr><br />", "</tr>", $result); |
|
408 |
$result = str_replace("</table></p>", "</table>", $result); |
|
409 |
$result = str_replace("</table><br />", "</table>", $result); |
|
410 |
$result = preg_replace('/<\/table>$/', "</table><br /><br />", $result); |
|
163 | 411 |
$result = str_replace("<p></div></p>", "</div>", $result); |
412 |
$result = str_replace("<p></table></p>", "</table>", $result); |
|
1 | 413 |
|
414 |
$result = str_replace('<nowiki>', '<nowiki>', $result); |
|
415 |
$result = str_replace('</nowiki>', '</nowiki>', $result); |
|
416 |
||
417 |
return $result; |
|
418 |
} |
|
419 |
||
420 |
function destroy_javascript($message, $_php = false) |
|
421 |
{ |
|
422 |
$message = preg_replace('#<(script|object|applet|embed|iframe|frame|form|input|select)(.*?)>#is', '<\\1\\2>', $message); |
|
423 |
$message = preg_replace('#</(script|object|applet|embed|iframe|frame|form|input|select)(.*?)>#is', '</\\1\\2>', $message); |
|
424 |
$message = preg_replace('#(javascript|script|activex|chrome|about|applet):#is', '\\1:', $message); |
|
425 |
if ( $_php ) |
|
426 |
{ |
|
427 |
// Left in only for compatibility |
|
428 |
$message = preg_replace('#<(.*?)>#is', '<\\1>', $message); |
|
429 |
$message = preg_replace('#<(.*?)>#is', '<\\1>', $message); |
|
430 |
$message = preg_replace('#<(\?|\?php|%)(.*?)(\?|%)>#is', '<\\1\\2\\3>', $message); |
|
431 |
// strip <a href="foo" onclick="bar();">-type attacks |
|
432 |
$message = preg_replace('#<([a-zA-Z:\-]+) (.*?)on([A-Za-z]*)=(.*?)>#is', '<\\1\\2on\\3=\\4>', $message); |
|
433 |
} |
|
434 |
return $message; |
|
435 |
} |
|
436 |
||
437 |
function strip_php($message) |
|
438 |
{ |
|
439 |
return RenderMan::destroy_javascript($message, true); |
|
440 |
} |
|
441 |
||
442 |
function sanitize_html($text) |
|
443 |
{ |
|
444 |
$text = htmlspecialchars($text); |
|
91 | 445 |
$allowed_tags = Array('b', 'i', 'u', 'pre', 'code', 'tt', 'br', 'p', 'nowiki', '!--([\w\W]+)--'); |
1 | 446 |
foreach($allowed_tags as $t) |
447 |
{ |
|
448 |
$text = preg_replace('#<'.$t.'>(.*?)</'.$t.'>#is', '<'.$t.'>\\1</'.$t.'>', $text); |
|
449 |
$text = preg_replace('#<'.$t.' />#is', '<'.$t.' />', $text); |
|
450 |
$text = preg_replace('#<'.$t.'>#is', '<'.$t.'>', $text); |
|
451 |
} |
|
452 |
return $text; |
|
453 |
} |
|
454 |
||
91 | 455 |
/** |
456 |
* Parses internal links (wikilinks) in a block of text. |
|
457 |
* @param string Text to process |
|
458 |
* @return string |
|
459 |
*/ |
|
460 |
||
461 |
function parse_internal_links($text) |
|
462 |
{ |
|
136
f2ee42f026f7
Fix: internal links parsed with RenderMan::parse_internal_links() did not get namespaces prepended; added Project: alias namespace for internal links
Dan
parents:
133
diff
changeset
|
463 |
global $db, $session, $paths, $template, $plugins; // Common objects |
91 | 464 |
|
465 |
// stage 1 - links with alternate text |
|
466 |
preg_match_all('/\[\[([^\[\]<>\{\}\|]+)\|(.+?)\]\]/', $text, $matches); |
|
467 |
foreach ( $matches[0] as $i => $match ) |
|
468 |
{ |
|
469 |
list($page_id, $namespace) = RenderMan::strToPageID($matches[1][$i]); |
|
470 |
$pid_clean = $paths->nslist[$namespace] . sanitize_page_id($page_id); |
|
471 |
||
472 |
$url = makeUrl($pid_clean, false, true); |
|
473 |
$inner_text = $matches[2][$i]; |
|
474 |
$quot = '"'; |
|
475 |
$exists = ( isPage($pid_clean) ) ? '' : ' class="wikilink-nonexistent"'; |
|
476 |
||
477 |
$link = "<a href={$quot}{$url}{$quot}{$exists}>{$inner_text}</a>"; |
|
478 |
||
479 |
$text = str_replace($match, $link, $text); |
|
480 |
} |
|
481 |
||
482 |
// stage 2 - links with no alternate text |
|
483 |
preg_match_all('/\[\[([^\[\]<>\{\}\|]+)\]\]/', $text, $matches); |
|
484 |
foreach ( $matches[0] as $i => $match ) |
|
485 |
{ |
|
486 |
list($page_id, $namespace) = RenderMan::strToPageID($matches[1][$i]); |
|
487 |
$pid_clean = $paths->nslist[$namespace] . sanitize_page_id($page_id); |
|
488 |
||
159
f7e83b6db3be
Fixed: RenderMan::parse_internal_links() problems with prepending Project: instead of Site_name: to project page alias-namespace links
Dan
parents:
142
diff
changeset
|
489 |
$url = makeUrl($pid_clean, false, true); |
f7e83b6db3be
Fixed: RenderMan::parse_internal_links() problems with prepending Project: instead of Site_name: to project page alias-namespace links
Dan
parents:
142
diff
changeset
|
490 |
$inner_text = ( isPage($pid_clean) ) ? htmlspecialchars(get_page_title($pid_clean)) : htmlspecialchars($matches[1][$i]); |
91 | 491 |
$quot = '"'; |
492 |
$exists = ( isPage($pid_clean) ) ? '' : ' class="wikilink-nonexistent"'; |
|
493 |
||
494 |
$link = "<a href={$quot}{$url}{$quot}{$exists}>{$inner_text}</a>"; |
|
495 |
||
496 |
$text = str_replace($match, $link, $text); |
|
497 |
} |
|
498 |
||
499 |
return $text; |
|
500 |
} |
|
501 |
||
1 | 502 |
/** |
503 |
* Parses a partial template tag in wikitext, and return an array with the parameters. |
|
63
2c57d3018a88
Fixed recursive template inclusion and spaces in template tags ({{Foo template}})
Dan
parents:
37
diff
changeset
|
504 |
* @param string The portion of the template tag that contains the parameters. |
2c57d3018a88
Fixed recursive template inclusion and spaces in template tags ({{Foo template}})
Dan
parents:
37
diff
changeset
|
505 |
* @example |
1 | 506 |
* <code> |
63
2c57d3018a88
Fixed recursive template inclusion and spaces in template tags ({{Foo template}})
Dan
parents:
37
diff
changeset
|
507 |
foo = lorem ipsum |
2c57d3018a88
Fixed recursive template inclusion and spaces in template tags ({{Foo template}})
Dan
parents:
37
diff
changeset
|
508 |
bar = dolor sit amet |
1 | 509 |
* </code> |
510 |
* @return array Example: |
|
511 |
* [foo] => lorem ipsum |
|
512 |
* [bar] => dolor sit amet |
|
513 |
*/ |
|
514 |
||
515 |
function parse_template_vars($input) |
|
516 |
{ |
|
174
4c5c2b66a34d
SECURITY: remove debug message in session manager; implemented alternate MediaWiki syntax for template embedding; added Adobe Spry for "shake" effect on unsuccessful login
Dan
parents:
163
diff
changeset
|
517 |
if ( !preg_match('/^(\|[ ]*([A-z0-9_]+)([ ]*)=([ ]*)(.+?))*$/is', trim($input)) ) |
4c5c2b66a34d
SECURITY: remove debug message in session manager; implemented alternate MediaWiki syntax for template embedding; added Adobe Spry for "shake" effect on unsuccessful login
Dan
parents:
163
diff
changeset
|
518 |
{ |
4c5c2b66a34d
SECURITY: remove debug message in session manager; implemented alternate MediaWiki syntax for template embedding; added Adobe Spry for "shake" effect on unsuccessful login
Dan
parents:
163
diff
changeset
|
519 |
$using_pipes = false; |
4c5c2b66a34d
SECURITY: remove debug message in session manager; implemented alternate MediaWiki syntax for template embedding; added Adobe Spry for "shake" effect on unsuccessful login
Dan
parents:
163
diff
changeset
|
520 |
$input = explode("\n", trim( $input )); |
4c5c2b66a34d
SECURITY: remove debug message in session manager; implemented alternate MediaWiki syntax for template embedding; added Adobe Spry for "shake" effect on unsuccessful login
Dan
parents:
163
diff
changeset
|
521 |
} |
4c5c2b66a34d
SECURITY: remove debug message in session manager; implemented alternate MediaWiki syntax for template embedding; added Adobe Spry for "shake" effect on unsuccessful login
Dan
parents:
163
diff
changeset
|
522 |
else |
4c5c2b66a34d
SECURITY: remove debug message in session manager; implemented alternate MediaWiki syntax for template embedding; added Adobe Spry for "shake" effect on unsuccessful login
Dan
parents:
163
diff
changeset
|
523 |
{ |
4c5c2b66a34d
SECURITY: remove debug message in session manager; implemented alternate MediaWiki syntax for template embedding; added Adobe Spry for "shake" effect on unsuccessful login
Dan
parents:
163
diff
changeset
|
524 |
$using_pipes = true; |
4c5c2b66a34d
SECURITY: remove debug message in session manager; implemented alternate MediaWiki syntax for template embedding; added Adobe Spry for "shake" effect on unsuccessful login
Dan
parents:
163
diff
changeset
|
525 |
$input = substr($input, 1); |
4c5c2b66a34d
SECURITY: remove debug message in session manager; implemented alternate MediaWiki syntax for template embedding; added Adobe Spry for "shake" effect on unsuccessful login
Dan
parents:
163
diff
changeset
|
526 |
$input = explode("|", trim( $input )); |
4c5c2b66a34d
SECURITY: remove debug message in session manager; implemented alternate MediaWiki syntax for template embedding; added Adobe Spry for "shake" effect on unsuccessful login
Dan
parents:
163
diff
changeset
|
527 |
} |
1 | 528 |
$parms = Array(); |
529 |
$current_line = ''; |
|
530 |
$current_parm = ''; |
|
531 |
foreach ( $input as $num => $line ) |
|
532 |
{ |
|
174
4c5c2b66a34d
SECURITY: remove debug message in session manager; implemented alternate MediaWiki syntax for template embedding; added Adobe Spry for "shake" effect on unsuccessful login
Dan
parents:
163
diff
changeset
|
533 |
if ( preg_match('/^[ ]*([A-z0-9_]+)([ ]*)=([ ]*)(.+?)$/is', $line, $matches) ) |
1 | 534 |
{ |
174
4c5c2b66a34d
SECURITY: remove debug message in session manager; implemented alternate MediaWiki syntax for template embedding; added Adobe Spry for "shake" effect on unsuccessful login
Dan
parents:
163
diff
changeset
|
535 |
$parm =& $matches[1]; |
4c5c2b66a34d
SECURITY: remove debug message in session manager; implemented alternate MediaWiki syntax for template embedding; added Adobe Spry for "shake" effect on unsuccessful login
Dan
parents:
163
diff
changeset
|
536 |
$text =& $matches[4]; |
1 | 537 |
if ( $parm == $current_parm ) |
538 |
{ |
|
539 |
$current_line .= $text; |
|
540 |
} |
|
541 |
else |
|
542 |
{ |
|
543 |
// New parameter |
|
544 |
if ( $current_parm != '' ) |
|
545 |
$parms[$current_parm] = $current_line; |
|
546 |
$current_line = $text; |
|
547 |
$current_parm = $parm; |
|
548 |
} |
|
549 |
} |
|
550 |
else if ( $num == 0 ) |
|
551 |
{ |
|
552 |
// Syntax error |
|
553 |
return false; |
|
554 |
} |
|
555 |
else |
|
556 |
{ |
|
557 |
$current_line .= "\n$line"; |
|
558 |
} |
|
559 |
} |
|
560 |
if ( !empty($current_parm) && !empty($current_line) ) |
|
561 |
{ |
|
562 |
$parms[$current_parm] = $current_line; |
|
563 |
} |
|
564 |
return $parms; |
|
565 |
} |
|
566 |
||
567 |
/** |
|
568 |
* Processes all template tags within a block of wikitext. |
|
174
4c5c2b66a34d
SECURITY: remove debug message in session manager; implemented alternate MediaWiki syntax for template embedding; added Adobe Spry for "shake" effect on unsuccessful login
Dan
parents:
163
diff
changeset
|
569 |
* Updated in 1.0.2 to also parse template tags in the format of {{Foo |a = b |b = c |c = therefore, a}} |
1 | 570 |
* @param string The text to process |
571 |
* @return string Formatted text |
|
572 |
* @example |
|
573 |
* <code> |
|
574 |
$text = '{{Template |
|
575 |
parm1 = Foo |
|
576 |
parm2 = Bar |
|
577 |
}}'; |
|
174
4c5c2b66a34d
SECURITY: remove debug message in session manager; implemented alternate MediaWiki syntax for template embedding; added Adobe Spry for "shake" effect on unsuccessful login
Dan
parents:
163
diff
changeset
|
578 |
$text = RenderMan::include_templates($text); |
1 | 579 |
* </code> |
580 |
*/ |
|
581 |
||
582 |
function include_templates($text) |
|
583 |
{ |
|
584 |
global $db, $session, $paths, $template, $plugins; // Common objects |
|
174
4c5c2b66a34d
SECURITY: remove debug message in session manager; implemented alternate MediaWiki syntax for template embedding; added Adobe Spry for "shake" effect on unsuccessful login
Dan
parents:
163
diff
changeset
|
585 |
// $template_regex = "/\{\{([^\]]+?)((\n([ ]*?)[A-z0-9]+([ ]*?)=([ ]*?)(.+?))*)\}\}/is"; |
4c5c2b66a34d
SECURITY: remove debug message in session manager; implemented alternate MediaWiki syntax for template embedding; added Adobe Spry for "shake" effect on unsuccessful login
Dan
parents:
163
diff
changeset
|
586 |
$template_regex = "/\{\{(.+)(((\n|[ ]*\|)[ ]*([A-z0-9]+)[ ]*=[ ]*(.+))*)\}\}/isU"; |
1 | 587 |
if ( $count = preg_match_all($template_regex, $text, $matches) ) |
588 |
{ |
|
174
4c5c2b66a34d
SECURITY: remove debug message in session manager; implemented alternate MediaWiki syntax for template embedding; added Adobe Spry for "shake" effect on unsuccessful login
Dan
parents:
163
diff
changeset
|
589 |
//die('<pre>' . print_r($matches, true) . '</pre>'); |
1 | 590 |
for ( $i = 0; $i < $count; $i++ ) |
591 |
{ |
|
63
2c57d3018a88
Fixed recursive template inclusion and spaces in template tags ({{Foo template}})
Dan
parents:
37
diff
changeset
|
592 |
$matches[1][$i] = sanitize_page_id($matches[1][$i]); |
1 | 593 |
$parmsection = trim($matches[2][$i]); |
594 |
if ( !empty($parmsection) ) |
|
595 |
{ |
|
596 |
$parms = RenderMan::parse_template_vars($parmsection); |
|
174
4c5c2b66a34d
SECURITY: remove debug message in session manager; implemented alternate MediaWiki syntax for template embedding; added Adobe Spry for "shake" effect on unsuccessful login
Dan
parents:
163
diff
changeset
|
597 |
if ( !is_array($parms) ) |
4c5c2b66a34d
SECURITY: remove debug message in session manager; implemented alternate MediaWiki syntax for template embedding; added Adobe Spry for "shake" effect on unsuccessful login
Dan
parents:
163
diff
changeset
|
598 |
// Syntax error |
4c5c2b66a34d
SECURITY: remove debug message in session manager; implemented alternate MediaWiki syntax for template embedding; added Adobe Spry for "shake" effect on unsuccessful login
Dan
parents:
163
diff
changeset
|
599 |
$parms = array(); |
1 | 600 |
} |
601 |
else |
|
602 |
{ |
|
603 |
$parms = Array(); |
|
604 |
} |
|
605 |
if ( $tpl_code = RenderMan::fetch_template_text($matches[1][$i]) ) |
|
606 |
{ |
|
607 |
$parser = $template->makeParserText($tpl_code); |
|
608 |
$parser->assign_vars($parms); |
|
609 |
$text = str_replace($matches[0][$i], $parser->run(), $text); |
|
610 |
} |
|
611 |
} |
|
612 |
} |
|
613 |
return $text; |
|
614 |
} |
|
615 |
||
616 |
/** |
|
617 |
* Preprocesses an HTML text string prior to being sent to MySQL. |
|
618 |
* @param string $text |
|
619 |
* @param bool $strip_all_php - if true, strips all PHP regardless of user permissions. Else, strips PHP only if user level < USER_LEVEL_ADMIN. |
|
620 |
*/ |
|
621 |
function preprocess_text($text, $strip_all_php = true, $sqlescape = true) |
|
622 |
{ |
|
623 |
global $db, $session, $paths, $template, $plugins; // Common objects |
|
624 |
$random_id = md5( time() . mt_rand() ); |
|
625 |
||
626 |
$can_do_php = ( $session->get_permissions('php_in_pages') && !$strip_all_php ); |
|
627 |
||
628 |
if ( !$can_do_php ) |
|
629 |
{ |
|
24 | 630 |
$text = sanitize_html($text, true); |
1 | 631 |
// If we can't do PHP, we can't do Javascript either. |
632 |
$text = RenderMan::destroy_javascript($text); |
|
633 |
} |
|
634 |
||
635 |
// Strip out <nowiki> sections and PHP code |
|
636 |
||
637 |
$php = preg_match_all('#(<|<)\?php(.*?)\?(>|>)#is', $text, $phpsec); |
|
638 |
||
639 |
//die('<pre>'.htmlspecialchars(print_r($phpsec, true))."\n".htmlspecialchars(print_r($text, true)).'</pre>'); |
|
640 |
||
641 |
for($i=0;$i<sizeof($phpsec[1]);$i++) |
|
642 |
{ |
|
643 |
$text = str_replace($phpsec[0][$i], '{PHP:'.$random_id.':'.$i.'}', $text); |
|
644 |
} |
|
645 |
||
646 |
$nw = preg_match_all('#<nowiki>(.*?)<\/nowiki>#is', $text, $nowiki); |
|
647 |
||
648 |
for($i=0;$i<sizeof($nowiki[1]);$i++) |
|
649 |
{ |
|
650 |
$text = str_replace('<nowiki>'.$nowiki[1][$i].'</nowiki>', '{NOWIKI:'.$random_id.':'.$i.'}', $text); |
|
651 |
} |
|
652 |
||
653 |
$text = str_replace('~~~~~', date('G:i, j F Y (T)'), $text); |
|
654 |
$text = str_replace('~~~~', "[[User:$session->username|$session->username]] ".date('G:i, j F Y (T)'), $text); |
|
655 |
$text = str_replace('~~~', "[[User:$session->username|$session->username]] ", $text); |
|
656 |
||
657 |
// Reinsert <nowiki> sections |
|
658 |
for($i=0;$i<$nw;$i++) |
|
659 |
{ |
|
660 |
$text = str_replace('{NOWIKI:'.$random_id.':'.$i.'}', '<nowiki>'.$nowiki[1][$i].'</nowiki>', $text); |
|
661 |
} |
|
662 |
// Reinsert PHP |
|
663 |
for($i=0;$i<$php;$i++) |
|
664 |
{ |
|
665 |
$phsec = ''.$phpsec[1][$i].'?php'.$phpsec[2][$i].'?'.$phpsec[3][$i].''; |
|
666 |
if ( $strip_all_php ) |
|
667 |
$phsec = htmlspecialchars($phsec); |
|
668 |
$text = str_replace('{PHP:'.$random_id.':'.$i.'}', $phsec, $text); |
|
669 |
} |
|
670 |
||
671 |
$text = ( $sqlescape ) ? $db->escape($text) : $text; |
|
672 |
||
673 |
return $text; |
|
674 |
} |
|
675 |
||
676 |
function smilieyize($text, $complete_urls = false) |
|
677 |
{ |
|
678 |
||
679 |
$random_id = md5( time() . mt_rand() ); |
|
680 |
||
681 |
// Smileys array - eventually this will be fetched from the database by |
|
682 |
// RenderMan::initSmileys during initialization, but it will all be hardcoded for beta 2 |
|
683 |
||
684 |
$smileys = Array( |
|
685 |
'O:-)' => 'face-angel.png', |
|
686 |
'O:)' => 'face-angel.png', |
|
687 |
'O=)' => 'face-angel.png', |
|
688 |
':-)' => 'face-smile.png', |
|
689 |
':)' => 'face-smile.png', |
|
690 |
'=)' => 'face-smile-big.png', |
|
691 |
':-(' => 'face-sad.png', |
|
692 |
':(' => 'face-sad.png', |
|
693 |
';(' => 'face-sad.png', |
|
694 |
':-O' => 'face-surprise.png', |
|
695 |
';-)' => 'face-wink.png', |
|
696 |
';)' => 'face-wink.png', |
|
697 |
'8-)' => 'face-glasses.png', |
|
698 |
'8)' => 'face-glasses.png', |
|
699 |
':-D' => 'face-grin.png', |
|
700 |
':D' => 'face-grin.png', |
|
701 |
'=D' => 'face-grin.png', |
|
702 |
':-*' => 'face-kiss.png', |
|
703 |
':*' => 'face-kiss.png', |
|
704 |
'=*' => 'face-kiss.png', |
|
705 |
':\'(' => 'face-crying.png', |
|
706 |
':-|' => 'face-plain.png', |
|
707 |
':-\\' => 'face-plain.png', |
|
708 |
':-/' => 'face-plain.png', |
|
709 |
':joke:' => 'face-plain.png', |
|
710 |
']:->' => 'face-devil-grin.png', |
|
189
fd0e9c7a7b28
Automatic set of state on Oxygen sidebar portlets should work now; reimplemented parts of the template parser (again) to workaround some PHP/PCRE issues and add support for parser plugins
Dan
parents:
174
diff
changeset
|
711 |
']:->' => 'face-devil-grin.png', |
1 | 712 |
':kiss:' => 'face-kiss.png', |
713 |
':-P' => 'face-tongue-out.png', |
|
714 |
':P' => 'face-tongue-out.png', |
|
715 |
':-p' => 'face-tongue-out.png', |
|
716 |
':p' => 'face-tongue-out.png', |
|
717 |
':-X' => 'face-sick.png', |
|
718 |
':X' => 'face-sick.png', |
|
719 |
':sick:' => 'face-sick.png', |
|
720 |
':-]' => 'face-oops.png', |
|
721 |
':]' => 'face-oops.png', |
|
722 |
':oops:' => 'face-oops.png', |
|
723 |
':-[' => 'face-embarassed.png', |
|
724 |
':[' => 'face-embarassed.png' |
|
725 |
); |
|
726 |
/* |
|
727 |
$keys = array_keys($smileys); |
|
728 |
foreach($keys as $k) |
|
729 |
{ |
|
730 |
$regex1 = '#([\W]+)'.preg_quote($k).'([\s\n\r\.]+)#s'; |
|
731 |
$regex2 = '\\1<img alt="'.$k.'" title="'.$k.'" src="'.scriptPath.'/images/smilies/'.$smileys[$k].'" style="border: 0;" />\\2'; |
|
732 |
$text = preg_replace($regex1, $regex2, $text); |
|
733 |
} |
|
734 |
*/ |
|
735 |
||
736 |
// Strip out <nowiki> sections |
|
737 |
//return '<pre>'.htmlspecialchars($text).'</pre>'; |
|
738 |
$nw = preg_match_all('#<nowiki>(.*?)<\/nowiki>#is', $text, $nowiki); |
|
739 |
||
740 |
for($i=0;$i<sizeof($nowiki[1]);$i++) |
|
741 |
{ |
|
742 |
$text = str_replace('<nowiki>'.$nowiki[1][$i].'</nowiki>', '{NOWIKI:'.$random_id.':'.$i.'}', $text); |
|
743 |
} |
|
744 |
||
745 |
$keys = array_keys($smileys); |
|
746 |
foreach($keys as $k) |
|
747 |
{ |
|
748 |
$t = str_hex($k); |
|
749 |
$t = explode(' ', $t); |
|
750 |
$s = ''; |
|
751 |
foreach($t as $b) |
|
752 |
{ |
|
753 |
$s.='&#x'.$b.';'; |
|
754 |
} |
|
755 |
$pfx = ( $complete_urls ) ? 'http' . ( isset($_SERVER['HTTPS']) ? 's' : '' ) . '://'.$_SERVER['HTTP_HOST'] : ''; |
|
756 |
$text = str_replace(' '.$k, ' <nowiki><img title="'.$s.'" alt="'.$s.'" src="'.$pfx.scriptPath.'/images/smilies/'.$smileys[$k].'" style="border: 0;" /></nowiki>', $text); |
|
757 |
} |
|
758 |
//*/ |
|
759 |
||
760 |
// Reinsert <nowiki> sections |
|
761 |
for($i=0;$i<$nw;$i++) |
|
762 |
{ |
|
763 |
$text = str_replace('{NOWIKI:'.$random_id.':'.$i.'}', '<nowiki>'.$nowiki[1][$i].'</nowiki>', $text); |
|
764 |
} |
|
765 |
||
766 |
return $text; |
|
767 |
} |
|
768 |
||
769 |
/* |
|
770 |
* **** DEPRECATED **** |
|
771 |
* Replaces some critical characters in a string with MySQL-safe equivalents |
|
772 |
* @param $text string the text to escape |
|
773 |
* @return array key 0 is the escaped text, key 1 is the character tag |
|
774 |
* / |
|
775 |
||
776 |
function escape_page_text($text) |
|
777 |
{ |
|
778 |
$char_tag = md5(microtime() . mt_rand()); |
|
779 |
$text = str_replace("'", "{APOS:$char_tag}", $text); |
|
780 |
$text = str_replace('"', "{QUOT:$char_tag}", $text); |
|
781 |
$text = str_replace("\\", "{SLASH:$char_tag}", $text); |
|
782 |
return Array($text, $char_tag); |
|
783 |
} |
|
784 |
*/ |
|
785 |
||
786 |
/* **** DEPRECATED **** |
|
787 |
* Reverses the result of RenderMan::escape_page_text(). |
|
788 |
* @param $text string the text to unescape |
|
789 |
* @param $char_tag string the character tag |
|
790 |
* @return string |
|
791 |
* / |
|
792 |
||
793 |
function unescape_page_text($text, $char_tag) |
|
794 |
{ |
|
795 |
$text = str_replace("{APOS:$char_tag}", "'", $text); |
|
796 |
$text = str_replace("{QUOT:$char_tag}", '"', $text); |
|
797 |
$text = str_replace("{SLASH:$char_tag}", "\\", $text); |
|
798 |
return $text; |
|
799 |
} |
|
800 |
*/ |
|
801 |
||
802 |
/** |
|
803 |
* Generates a summary of the differences between two texts, and formats it as XHTML. |
|
804 |
* @param $str1 string the first block of text |
|
805 |
* @param $str2 string the second block of text |
|
806 |
* @return string |
|
807 |
*/ |
|
808 |
function diff($str1, $str2) |
|
809 |
{ |
|
810 |
global $db, $session, $paths, $template, $plugins; // Common objects |
|
811 |
$str1 = explode("\n", $str1); |
|
812 |
$str2 = explode("\n", $str2); |
|
813 |
$diff = new Diff($str1, $str2); |
|
814 |
$renderer = new TableDiffFormatter(); |
|
815 |
return '<table class="diff">'.$renderer->format($diff).'</table>'; |
|
816 |
} |
|
817 |
||
35 | 818 |
/** |
819 |
* Changes wikitext image tags to HTML. |
|
820 |
* @param string The wikitext to process |
|
37 | 821 |
* @param array Will be overwritten with the list of HTML tags (the system uses tokens for TextWiki compatibility) |
35 | 822 |
* @return string |
823 |
*/ |
|
824 |
||
37 | 825 |
function process_image_tags($text, &$taglist) |
35 | 826 |
{ |
827 |
global $db, $session, $paths, $template, $plugins; // Common objects |
|
828 |
||
37 | 829 |
$s_delim = "\xFF"; |
830 |
$f_delim = "\xFF"; |
|
831 |
$taglist = array(); |
|
832 |
||
35 | 833 |
// Wicked huh? |
66
52017732bc20
Added "raw" option to embedded images to make complex clickables easier
Dan
parents:
65
diff
changeset
|
834 |
$regex = '/\[\[:' . $paths->nslist['File'] . '([\w\s0-9_\(\)!@%\^\+\|\.-]+?)((\|thumb)|(\|([0-9]+)x([0-9]+)))?(\|left|\|right)?(\|raw|\|(.+))?\]\]/i'; |
35 | 835 |
|
836 |
preg_match_all($regex, $text, $matches); |
|
837 |
||
838 |
foreach ( $matches[0] as $i => $match ) |
|
839 |
{ |
|
840 |
||
841 |
$full_tag =& $matches[0][$i]; |
|
842 |
$filename =& $matches[1][$i]; |
|
843 |
$scale_type =& $matches[2][$i]; |
|
844 |
$width =& $matches[5][$i]; |
|
845 |
$height =& $matches[6][$i]; |
|
846 |
$clear =& $matches[7][$i]; |
|
847 |
$caption =& $matches[8][$i]; |
|
848 |
||
849 |
if ( !isPage( $paths->nslist['File'] . $filename ) ) |
|
850 |
{ |
|
66
52017732bc20
Added "raw" option to embedded images to make complex clickables easier
Dan
parents:
65
diff
changeset
|
851 |
$text = str_replace($full_tag, '[[' . makeUrlNS('File', $filename) . ']]', $text); |
35 | 852 |
continue; |
853 |
} |
|
854 |
||
855 |
if ( $scale_type == '|thumb' ) |
|
856 |
{ |
|
857 |
$r_width = 225; |
|
858 |
$r_height = 225; |
|
859 |
||
860 |
$url = makeUrlNS('Special', 'DownloadFile/' . $filename, 'preview&width=' . $r_width . '&height=' . $r_height, true); |
|
861 |
} |
|
862 |
else if ( !empty($width) && !empty($height) ) |
|
863 |
{ |
|
864 |
$r_width = $width; |
|
865 |
$r_height = $height; |
|
866 |
||
867 |
$url = makeUrlNS('Special', 'DownloadFile/' . $filename, 'preview&width=' . $r_width . '&height=' . $r_height, true); |
|
868 |
} |
|
869 |
else |
|
870 |
{ |
|
871 |
$url = makeUrlNS('Special', 'DownloadFile/' . $filename); |
|
872 |
} |
|
873 |
||
874 |
$img_tag = '<img src="' . $url . '" '; |
|
875 |
||
65 | 876 |
// if ( isset($r_width) && isset($r_height) && $scale_type != '|thumb' ) |
877 |
// { |
|
66
52017732bc20
Added "raw" option to embedded images to make complex clickables easier
Dan
parents:
65
diff
changeset
|
878 |
// $img_tag .= 'width="' . $r_width . '" height="' . $r_height . '" '; |
65 | 879 |
// } |
35 | 880 |
|
66
52017732bc20
Added "raw" option to embedded images to make complex clickables easier
Dan
parents:
65
diff
changeset
|
881 |
$img_tag .= 'style="border-width: 0px; /* background-color: white; */" '; |
35 | 882 |
|
85
7c68a18a27be
AJAX comments are now paginated; plugin manager can now show system plugins; typo in installer corrected; links in oxygen/stpatty/admin footers changed to "About Enano" page; 1.0.1 release candidate
Dan
parents:
73
diff
changeset
|
883 |
$code = $plugins->setHook('img_tag_parse_img'); |
7c68a18a27be
AJAX comments are now paginated; plugin manager can now show system plugins; typo in installer corrected; links in oxygen/stpatty/admin footers changed to "About Enano" page; 1.0.1 release candidate
Dan
parents:
73
diff
changeset
|
884 |
foreach ( $code as $cmd ) |
7c68a18a27be
AJAX comments are now paginated; plugin manager can now show system plugins; typo in installer corrected; links in oxygen/stpatty/admin footers changed to "About Enano" page; 1.0.1 release candidate
Dan
parents:
73
diff
changeset
|
885 |
{ |
7c68a18a27be
AJAX comments are now paginated; plugin manager can now show system plugins; typo in installer corrected; links in oxygen/stpatty/admin footers changed to "About Enano" page; 1.0.1 release candidate
Dan
parents:
73
diff
changeset
|
886 |
eval($cmd); |
7c68a18a27be
AJAX comments are now paginated; plugin manager can now show system plugins; typo in installer corrected; links in oxygen/stpatty/admin footers changed to "About Enano" page; 1.0.1 release candidate
Dan
parents:
73
diff
changeset
|
887 |
} |
7c68a18a27be
AJAX comments are now paginated; plugin manager can now show system plugins; typo in installer corrected; links in oxygen/stpatty/admin footers changed to "About Enano" page; 1.0.1 release candidate
Dan
parents:
73
diff
changeset
|
888 |
|
35 | 889 |
$img_tag .= '/>'; |
890 |
||
891 |
$complete_tag = ''; |
|
892 |
||
66
52017732bc20
Added "raw" option to embedded images to make complex clickables easier
Dan
parents:
65
diff
changeset
|
893 |
if ( !empty($scale_type) && $caption != '|raw' ) |
35 | 894 |
{ |
895 |
$complete_tag .= '<div class="thumbnail" '; |
|
896 |
$clear_text = ''; |
|
897 |
if ( !empty($clear) ) |
|
898 |
{ |
|
899 |
$side = ( $clear == '|left' ) ? 'left' : 'right'; |
|
900 |
$opposite = ( $clear == '|left' ) ? 'right' : 'left'; |
|
37 | 901 |
$clear_text .= "float: $side; margin-$opposite: 20px;"; |
35 | 902 |
$complete_tag .= 'style="' . $clear_text . '" '; |
903 |
} |
|
904 |
$complete_tag .= '>'; |
|
905 |
||
906 |
$complete_tag .= '<a href="' . makeUrlNS('File', $filename) . '" style="display: block;">'; |
|
907 |
$complete_tag .= $img_tag; |
|
908 |
$complete_tag .= '</a>'; |
|
909 |
||
910 |
$mag_button = '<a href="' . makeUrlNS('File', $filename) . '" style="display: block; float: right; clear: right; margin: 0 0 10px 10px;"><img alt="[ + ]" src="' . scriptPath . '/images/thumbnail.png" style="border-width: 0px;" /></a>'; |
|
911 |
||
912 |
if ( !empty($caption) ) |
|
913 |
{ |
|
914 |
$cap = substr($caption, 1); |
|
915 |
$complete_tag .= $mag_button . $cap; |
|
916 |
} |
|
917 |
||
918 |
$complete_tag .= '</div>'; |
|
919 |
} |
|
66
52017732bc20
Added "raw" option to embedded images to make complex clickables easier
Dan
parents:
65
diff
changeset
|
920 |
else if ( $caption == '|raw' ) |
52017732bc20
Added "raw" option to embedded images to make complex clickables easier
Dan
parents:
65
diff
changeset
|
921 |
{ |
67 | 922 |
$complete_tag .= "$img_tag"; |
923 |
$taglist[$i] = $complete_tag; |
|
924 |
||
925 |
$repl = "{$s_delim}e_img_{$i}{$f_delim}"; |
|
926 |
$text = str_replace($full_tag, $repl, $text); |
|
927 |
continue; |
|
66
52017732bc20
Added "raw" option to embedded images to make complex clickables easier
Dan
parents:
65
diff
changeset
|
928 |
} |
35 | 929 |
else |
930 |
{ |
|
85
7c68a18a27be
AJAX comments are now paginated; plugin manager can now show system plugins; typo in installer corrected; links in oxygen/stpatty/admin footers changed to "About Enano" page; 1.0.1 release candidate
Dan
parents:
73
diff
changeset
|
931 |
$complete_tag .= '<a href="' . makeUrlNS('File', $filename) . '" style="display: block;"'; |
7c68a18a27be
AJAX comments are now paginated; plugin manager can now show system plugins; typo in installer corrected; links in oxygen/stpatty/admin footers changed to "About Enano" page; 1.0.1 release candidate
Dan
parents:
73
diff
changeset
|
932 |
$code = $plugins->setHook('img_tag_parse_link'); |
7c68a18a27be
AJAX comments are now paginated; plugin manager can now show system plugins; typo in installer corrected; links in oxygen/stpatty/admin footers changed to "About Enano" page; 1.0.1 release candidate
Dan
parents:
73
diff
changeset
|
933 |
foreach ( $code as $cmd ) |
7c68a18a27be
AJAX comments are now paginated; plugin manager can now show system plugins; typo in installer corrected; links in oxygen/stpatty/admin footers changed to "About Enano" page; 1.0.1 release candidate
Dan
parents:
73
diff
changeset
|
934 |
{ |
7c68a18a27be
AJAX comments are now paginated; plugin manager can now show system plugins; typo in installer corrected; links in oxygen/stpatty/admin footers changed to "About Enano" page; 1.0.1 release candidate
Dan
parents:
73
diff
changeset
|
935 |
eval($cmd); |
7c68a18a27be
AJAX comments are now paginated; plugin manager can now show system plugins; typo in installer corrected; links in oxygen/stpatty/admin footers changed to "About Enano" page; 1.0.1 release candidate
Dan
parents:
73
diff
changeset
|
936 |
} |
7c68a18a27be
AJAX comments are now paginated; plugin manager can now show system plugins; typo in installer corrected; links in oxygen/stpatty/admin footers changed to "About Enano" page; 1.0.1 release candidate
Dan
parents:
73
diff
changeset
|
937 |
$complete_tag .= '>'; |
35 | 938 |
$complete_tag .= $img_tag; |
939 |
$complete_tag .= '</a>'; |
|
940 |
} |
|
941 |
||
37 | 942 |
$complete_tag .= "\n\n"; |
943 |
$taglist[$i] = $complete_tag; |
|
35 | 944 |
|
37 | 945 |
$pos = strpos($text, $full_tag); |
35 | 946 |
|
947 |
while(true) |
|
948 |
{ |
|
949 |
$check1 = substr($text, $pos, 3); |
|
950 |
$check2 = substr($text, $pos, 1); |
|
951 |
if ( $check1 == '<p>' || $pos == 0 || $check2 == "\n" ) |
|
952 |
{ |
|
953 |
// die('found at pos '.$pos); |
|
954 |
break; |
|
955 |
} |
|
956 |
$pos--; |
|
957 |
} |
|
958 |
||
37 | 959 |
$repl = "{$s_delim}e_img_{$i}{$f_delim}"; |
960 |
$text = substr($text, 0, $pos) . $repl . substr($text, $pos); |
|
35 | 961 |
|
962 |
$text = str_replace($full_tag, '', $text); |
|
963 |
||
964 |
unset($full_tag, $filename, $scale_type, $width, $height, $clear, $caption, $r_width, $r_height); |
|
965 |
||
966 |
} |
|
967 |
||
968 |
return $text; |
|
969 |
} |
|
970 |
||
37 | 971 |
/** |
972 |
* Finalizes processing of image tags. |
|
973 |
* @param string The preprocessed text |
|
974 |
* @param array The list of image tags created by RenderMan::process_image_tags() |
|
975 |
*/ |
|
976 |
||
977 |
function process_imgtags_stage2($text, $taglist) |
|
978 |
{ |
|
979 |
$s_delim = "\xFF"; |
|
980 |
$f_delim = "\xFF"; |
|
981 |
foreach ( $taglist as $i => $tag ) |
|
982 |
{ |
|
983 |
$repl = "{$s_delim}e_img_{$i}{$f_delim}"; |
|
984 |
$text = str_replace($repl, $tag, $text); |
|
985 |
} |
|
986 |
return $text; |
|
987 |
} |
|
988 |
||
1 | 989 |
} |
990 |
||
991 |
?> |