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