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