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