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
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
+ − 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
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
+ − 247
$text = RenderMan::process_image_tags($text, $taglist);
+ − 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
+ − 260
$template_regex = "/\{\{([^\]]+?)((\n([ ]*?)[A-z0-9]+([ ]*?)=([ ]*?)(.+?))*)\}\}/is";
+ − 261
$i = 0;
+ − 262
while ( preg_match($template_regex, $text) )
+ − 263
{
+ − 264
$i++;
+ − 265
if ( $i == 5 )
+ − 266
break;
+ − 267
$text = RenderMan::include_templates($text);
+ − 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
+ − 285
// if ( !$plaintext )
+ − 286
// {
+ − 287
// $result = RenderMan::process_imgtags_stage2($result, $taglist);
+ − 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);
91
+ − 411
$allowed_tags = Array('b', 'i', 'u', 'pre', 'code', 'tt', 'br', 'p', 'nowiki', '!--([\w\W]+)--');
1
+ − 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
91
+ − 421
/**
+ − 422
* Parses internal links (wikilinks) in a block of text.
+ − 423
* @param string Text to process
+ − 424
* @return string
+ − 425
*/
+ − 426
+ − 427
function parse_internal_links($text)
+ − 428
{
+ − 429
+ − 430
// stage 1 - links with alternate text
+ − 431
preg_match_all('/\[\[([^\[\]<>\{\}\|]+)\|(.+?)\]\]/', $text, $matches);
+ − 432
foreach ( $matches[0] as $i => $match )
+ − 433
{
+ − 434
list($page_id, $namespace) = RenderMan::strToPageID($matches[1][$i]);
+ − 435
$pid_clean = $paths->nslist[$namespace] . sanitize_page_id($page_id);
+ − 436
+ − 437
$url = makeUrl($pid_clean, false, true);
+ − 438
$inner_text = $matches[2][$i];
+ − 439
$quot = '"';
+ − 440
$exists = ( isPage($pid_clean) ) ? '' : ' class="wikilink-nonexistent"';
+ − 441
+ − 442
$link = "<a href={$quot}{$url}{$quot}{$exists}>{$inner_text}</a>";
+ − 443
+ − 444
$text = str_replace($match, $link, $text);
+ − 445
}
+ − 446
+ − 447
// stage 2 - links with no alternate text
+ − 448
preg_match_all('/\[\[([^\[\]<>\{\}\|]+)\]\]/', $text, $matches);
+ − 449
foreach ( $matches[0] as $i => $match )
+ − 450
{
+ − 451
list($page_id, $namespace) = RenderMan::strToPageID($matches[1][$i]);
+ − 452
$pid_clean = $paths->nslist[$namespace] . sanitize_page_id($page_id);
+ − 453
+ − 454
$url = makeUrl($matches[1][$i], false, true);
+ − 455
$inner_text = htmlspecialchars(get_page_title($pid_clean));
+ − 456
$quot = '"';
+ − 457
$exists = ( isPage($pid_clean) ) ? '' : ' class="wikilink-nonexistent"';
+ − 458
+ − 459
$link = "<a href={$quot}{$url}{$quot}{$exists}>{$inner_text}</a>";
+ − 460
+ − 461
$text = str_replace($match, $link, $text);
+ − 462
}
+ − 463
+ − 464
return $text;
+ − 465
}
+ − 466
1
+ − 467
/* *
+ − 468
* Replaces template inclusions with the templates
+ − 469
* @param string $message The text to format
+ − 470
* @return string
+ − 471
* /
+ − 472
+ − 473
function old_include_templates($message)
+ − 474
{
+ − 475
$random_id = md5( time() . mt_rand() );
+ − 476
preg_match_all('#\{\{(.+?)\}\}#s', $message, $matchlist);
+ − 477
foreach($matchlist[1] as $m)
+ − 478
{
+ − 479
$mn = $m;
+ − 480
// Strip out wikilinks and re-add them after the explosion (because of the "|")
+ − 481
preg_match_all('#\[\[(.+?)\]\]#i', $m, $linklist);
+ − 482
//echo '<pre>'.print_r($linklist, true).'</pre>';
+ − 483
for($i=0;$i<sizeof($linklist[1]);$i++)
+ − 484
{
+ − 485
$mn = str_replace('[['.$linklist[1][$i].']]', '{WIKILINK:'.$random_id.':'.$i.'}', $mn);
+ − 486
}
+ − 487
+ − 488
$ar = explode('|', $mn);
+ − 489
+ − 490
for($j=0;$j<sizeof($ar);$j++)
+ − 491
{
+ − 492
for($i=0;$i<sizeof($linklist[1]);$i++)
+ − 493
{
+ − 494
$ar[$j] = str_replace('{WIKILINK:'.$random_id.':'.$i.'}', '[['.$linklist[1][$i].']]', $ar[$j]);
+ − 495
}
+ − 496
}
+ − 497
+ − 498
$tp = $ar[0];
+ − 499
unset($ar[0]);
+ − 500
$tp = str_replace(' ', '_', $tp);
+ − 501
$message = str_replace('{{'.$m.'}}', RenderMan::getTemplate($tp, $ar), $message);
+ − 502
}
+ − 503
return $message;
+ − 504
}
+ − 505
*/
+ − 506
+ − 507
/**
+ − 508
* Parses a partial template tag in wikitext, and return an array with the parameters.
63
+ − 509
* @param string The portion of the template tag that contains the parameters.
+ − 510
* @example
1
+ − 511
* <code>
63
+ − 512
foo = lorem ipsum
+ − 513
bar = dolor sit amet
1
+ − 514
* </code>
+ − 515
* @return array Example:
+ − 516
* [foo] => lorem ipsum
+ − 517
* [bar] => dolor sit amet
+ − 518
*/
+ − 519
+ − 520
function parse_template_vars($input)
+ − 521
{
+ − 522
$input = explode("\n", trim( $input ));
+ − 523
$parms = Array();
+ − 524
$current_line = '';
+ − 525
$current_parm = '';
+ − 526
foreach ( $input as $num => $line )
+ − 527
{
+ − 528
if ( preg_match('/^([ ]*?)([A-z0-9_]+?)([ ]*?)=([ ]*?)(.+?)$/i', $line, $matches) )
+ − 529
{
+ − 530
$parm =& $matches[2];
+ − 531
$text =& $matches[5];
+ − 532
if ( $parm == $current_parm )
+ − 533
{
+ − 534
$current_line .= $text;
+ − 535
}
+ − 536
else
+ − 537
{
+ − 538
// New parameter
+ − 539
if ( $current_parm != '' )
+ − 540
$parms[$current_parm] = $current_line;
+ − 541
$current_line = $text;
+ − 542
$current_parm = $parm;
+ − 543
}
+ − 544
}
+ − 545
else if ( $num == 0 )
+ − 546
{
+ − 547
// Syntax error
+ − 548
return false;
+ − 549
}
+ − 550
else
+ − 551
{
+ − 552
$current_line .= "\n$line";
+ − 553
}
+ − 554
}
+ − 555
if ( !empty($current_parm) && !empty($current_line) )
+ − 556
{
+ − 557
$parms[$current_parm] = $current_line;
+ − 558
}
+ − 559
return $parms;
+ − 560
}
+ − 561
+ − 562
/**
+ − 563
* Processes all template tags within a block of wikitext.
+ − 564
* @param string The text to process
+ − 565
* @return string Formatted text
+ − 566
* @example
+ − 567
* <code>
+ − 568
$text = '{{Template
+ − 569
parm1 = Foo
+ − 570
parm2 = Bar
+ − 571
}}';
+ − 572
$text = include_templates($text);
+ − 573
* </code>
+ − 574
*/
+ − 575
+ − 576
function include_templates($text)
+ − 577
{
+ − 578
global $db, $session, $paths, $template, $plugins; // Common objects
63
+ − 579
$template_regex = "/\{\{([^\]]+?)((\n([ ]*?)[A-z0-9]+([ ]*?)=([ ]*?)(.+?))*)\}\}/is";
1
+ − 580
if ( $count = preg_match_all($template_regex, $text, $matches) )
+ − 581
{
+ − 582
for ( $i = 0; $i < $count; $i++ )
+ − 583
{
63
+ − 584
$matches[1][$i] = sanitize_page_id($matches[1][$i]);
1
+ − 585
$parmsection = trim($matches[2][$i]);
+ − 586
if ( !empty($parmsection) )
+ − 587
{
+ − 588
$parms = RenderMan::parse_template_vars($parmsection);
+ − 589
foreach ( $parms as $j => $parm )
+ − 590
{
+ − 591
$parms[$j] = $parm;
+ − 592
}
+ − 593
}
+ − 594
else
+ − 595
{
+ − 596
$parms = Array();
+ − 597
}
+ − 598
if ( $tpl_code = RenderMan::fetch_template_text($matches[1][$i]) )
+ − 599
{
+ − 600
$parser = $template->makeParserText($tpl_code);
+ − 601
$parser->assign_vars($parms);
+ − 602
$text = str_replace($matches[0][$i], $parser->run(), $text);
+ − 603
}
+ − 604
}
+ − 605
}
+ − 606
return $text;
+ − 607
}
+ − 608
+ − 609
/**
+ − 610
* Preprocesses an HTML text string prior to being sent to MySQL.
+ − 611
* @param string $text
+ − 612
* @param bool $strip_all_php - if true, strips all PHP regardless of user permissions. Else, strips PHP only if user level < USER_LEVEL_ADMIN.
+ − 613
*/
+ − 614
function preprocess_text($text, $strip_all_php = true, $sqlescape = true)
+ − 615
{
+ − 616
global $db, $session, $paths, $template, $plugins; // Common objects
+ − 617
$random_id = md5( time() . mt_rand() );
+ − 618
+ − 619
$can_do_php = ( $session->get_permissions('php_in_pages') && !$strip_all_php );
+ − 620
+ − 621
if ( !$can_do_php )
+ − 622
{
24
+ − 623
$text = sanitize_html($text, true);
1
+ − 624
// If we can't do PHP, we can't do Javascript either.
+ − 625
$text = RenderMan::destroy_javascript($text);
+ − 626
}
+ − 627
+ − 628
// Strip out <nowiki> sections and PHP code
+ − 629
+ − 630
$php = preg_match_all('#(<|<)\?php(.*?)\?(>|>)#is', $text, $phpsec);
+ − 631
+ − 632
//die('<pre>'.htmlspecialchars(print_r($phpsec, true))."\n".htmlspecialchars(print_r($text, true)).'</pre>');
+ − 633
+ − 634
for($i=0;$i<sizeof($phpsec[1]);$i++)
+ − 635
{
+ − 636
$text = str_replace($phpsec[0][$i], '{PHP:'.$random_id.':'.$i.'}', $text);
+ − 637
}
+ − 638
+ − 639
$nw = preg_match_all('#<nowiki>(.*?)<\/nowiki>#is', $text, $nowiki);
+ − 640
+ − 641
for($i=0;$i<sizeof($nowiki[1]);$i++)
+ − 642
{
+ − 643
$text = str_replace('<nowiki>'.$nowiki[1][$i].'</nowiki>', '{NOWIKI:'.$random_id.':'.$i.'}', $text);
+ − 644
}
+ − 645
+ − 646
$text = str_replace('~~~~~', date('G:i, j F Y (T)'), $text);
+ − 647
$text = str_replace('~~~~', "[[User:$session->username|$session->username]] ".date('G:i, j F Y (T)'), $text);
+ − 648
$text = str_replace('~~~', "[[User:$session->username|$session->username]] ", $text);
+ − 649
+ − 650
// Reinsert <nowiki> sections
+ − 651
for($i=0;$i<$nw;$i++)
+ − 652
{
+ − 653
$text = str_replace('{NOWIKI:'.$random_id.':'.$i.'}', '<nowiki>'.$nowiki[1][$i].'</nowiki>', $text);
+ − 654
}
+ − 655
// Reinsert PHP
+ − 656
for($i=0;$i<$php;$i++)
+ − 657
{
+ − 658
$phsec = ''.$phpsec[1][$i].'?php'.$phpsec[2][$i].'?'.$phpsec[3][$i].'';
+ − 659
if ( $strip_all_php )
+ − 660
$phsec = htmlspecialchars($phsec);
+ − 661
$text = str_replace('{PHP:'.$random_id.':'.$i.'}', $phsec, $text);
+ − 662
}
+ − 663
+ − 664
$text = ( $sqlescape ) ? $db->escape($text) : $text;
+ − 665
+ − 666
return $text;
+ − 667
}
+ − 668
+ − 669
function smilieyize($text, $complete_urls = false)
+ − 670
{
+ − 671
+ − 672
$random_id = md5( time() . mt_rand() );
+ − 673
+ − 674
// Smileys array - eventually this will be fetched from the database by
+ − 675
// RenderMan::initSmileys during initialization, but it will all be hardcoded for beta 2
+ − 676
+ − 677
$smileys = Array(
+ − 678
'O:-)' => 'face-angel.png',
+ − 679
'O:)' => 'face-angel.png',
+ − 680
'O=)' => 'face-angel.png',
+ − 681
':-)' => 'face-smile.png',
+ − 682
':)' => 'face-smile.png',
+ − 683
'=)' => 'face-smile-big.png',
+ − 684
':-(' => 'face-sad.png',
+ − 685
':(' => 'face-sad.png',
+ − 686
';(' => 'face-sad.png',
+ − 687
':-O' => 'face-surprise.png',
+ − 688
';-)' => 'face-wink.png',
+ − 689
';)' => 'face-wink.png',
+ − 690
'8-)' => 'face-glasses.png',
+ − 691
'8)' => 'face-glasses.png',
+ − 692
':-D' => 'face-grin.png',
+ − 693
':D' => 'face-grin.png',
+ − 694
'=D' => 'face-grin.png',
+ − 695
':-*' => 'face-kiss.png',
+ − 696
':*' => 'face-kiss.png',
+ − 697
'=*' => 'face-kiss.png',
+ − 698
':\'(' => 'face-crying.png',
+ − 699
':-|' => 'face-plain.png',
+ − 700
':-\\' => 'face-plain.png',
+ − 701
':-/' => 'face-plain.png',
+ − 702
':joke:' => 'face-plain.png',
+ − 703
']:->' => 'face-devil-grin.png',
+ − 704
':kiss:' => 'face-kiss.png',
+ − 705
':-P' => 'face-tongue-out.png',
+ − 706
':P' => 'face-tongue-out.png',
+ − 707
':-p' => 'face-tongue-out.png',
+ − 708
':p' => 'face-tongue-out.png',
+ − 709
':-X' => 'face-sick.png',
+ − 710
':X' => 'face-sick.png',
+ − 711
':sick:' => 'face-sick.png',
+ − 712
':-]' => 'face-oops.png',
+ − 713
':]' => 'face-oops.png',
+ − 714
':oops:' => 'face-oops.png',
+ − 715
':-[' => 'face-embarassed.png',
+ − 716
':[' => 'face-embarassed.png'
+ − 717
);
+ − 718
/*
+ − 719
$keys = array_keys($smileys);
+ − 720
foreach($keys as $k)
+ − 721
{
+ − 722
$regex1 = '#([\W]+)'.preg_quote($k).'([\s\n\r\.]+)#s';
+ − 723
$regex2 = '\\1<img alt="'.$k.'" title="'.$k.'" src="'.scriptPath.'/images/smilies/'.$smileys[$k].'" style="border: 0;" />\\2';
+ − 724
$text = preg_replace($regex1, $regex2, $text);
+ − 725
}
+ − 726
*/
+ − 727
+ − 728
// Strip out <nowiki> sections
+ − 729
//return '<pre>'.htmlspecialchars($text).'</pre>';
+ − 730
$nw = preg_match_all('#<nowiki>(.*?)<\/nowiki>#is', $text, $nowiki);
+ − 731
+ − 732
for($i=0;$i<sizeof($nowiki[1]);$i++)
+ − 733
{
+ − 734
$text = str_replace('<nowiki>'.$nowiki[1][$i].'</nowiki>', '{NOWIKI:'.$random_id.':'.$i.'}', $text);
+ − 735
}
+ − 736
+ − 737
$keys = array_keys($smileys);
+ − 738
foreach($keys as $k)
+ − 739
{
+ − 740
$t = str_hex($k);
+ − 741
$t = explode(' ', $t);
+ − 742
$s = '';
+ − 743
foreach($t as $b)
+ − 744
{
+ − 745
$s.='&#x'.$b.';';
+ − 746
}
+ − 747
$pfx = ( $complete_urls ) ? 'http' . ( isset($_SERVER['HTTPS']) ? 's' : '' ) . '://'.$_SERVER['HTTP_HOST'] : '';
+ − 748
$text = str_replace(' '.$k, ' <nowiki><img title="'.$s.'" alt="'.$s.'" src="'.$pfx.scriptPath.'/images/smilies/'.$smileys[$k].'" style="border: 0;" /></nowiki>', $text);
+ − 749
}
+ − 750
//*/
+ − 751
+ − 752
// Reinsert <nowiki> sections
+ − 753
for($i=0;$i<$nw;$i++)
+ − 754
{
+ − 755
$text = str_replace('{NOWIKI:'.$random_id.':'.$i.'}', '<nowiki>'.$nowiki[1][$i].'</nowiki>', $text);
+ − 756
}
+ − 757
+ − 758
return $text;
+ − 759
}
+ − 760
+ − 761
/*
+ − 762
* **** DEPRECATED ****
+ − 763
* Replaces some critical characters in a string with MySQL-safe equivalents
+ − 764
* @param $text string the text to escape
+ − 765
* @return array key 0 is the escaped text, key 1 is the character tag
+ − 766
* /
+ − 767
+ − 768
function escape_page_text($text)
+ − 769
{
+ − 770
$char_tag = md5(microtime() . mt_rand());
+ − 771
$text = str_replace("'", "{APOS:$char_tag}", $text);
+ − 772
$text = str_replace('"', "{QUOT:$char_tag}", $text);
+ − 773
$text = str_replace("\\", "{SLASH:$char_tag}", $text);
+ − 774
return Array($text, $char_tag);
+ − 775
}
+ − 776
*/
+ − 777
+ − 778
/* **** DEPRECATED ****
+ − 779
* Reverses the result of RenderMan::escape_page_text().
+ − 780
* @param $text string the text to unescape
+ − 781
* @param $char_tag string the character tag
+ − 782
* @return string
+ − 783
* /
+ − 784
+ − 785
function unescape_page_text($text, $char_tag)
+ − 786
{
+ − 787
$text = str_replace("{APOS:$char_tag}", "'", $text);
+ − 788
$text = str_replace("{QUOT:$char_tag}", '"', $text);
+ − 789
$text = str_replace("{SLASH:$char_tag}", "\\", $text);
+ − 790
return $text;
+ − 791
}
+ − 792
*/
+ − 793
+ − 794
/**
+ − 795
* Generates a summary of the differences between two texts, and formats it as XHTML.
+ − 796
* @param $str1 string the first block of text
+ − 797
* @param $str2 string the second block of text
+ − 798
* @return string
+ − 799
*/
+ − 800
function diff($str1, $str2)
+ − 801
{
+ − 802
global $db, $session, $paths, $template, $plugins; // Common objects
+ − 803
$str1 = explode("\n", $str1);
+ − 804
$str2 = explode("\n", $str2);
+ − 805
$diff = new Diff($str1, $str2);
+ − 806
$renderer = new TableDiffFormatter();
+ − 807
return '<table class="diff">'.$renderer->format($diff).'</table>';
+ − 808
}
+ − 809
35
+ − 810
/**
+ − 811
* Changes wikitext image tags to HTML.
+ − 812
* @param string The wikitext to process
37
+ − 813
* @param array Will be overwritten with the list of HTML tags (the system uses tokens for TextWiki compatibility)
35
+ − 814
* @return string
+ − 815
*/
+ − 816
37
+ − 817
function process_image_tags($text, &$taglist)
35
+ − 818
{
+ − 819
global $db, $session, $paths, $template, $plugins; // Common objects
+ − 820
37
+ − 821
$s_delim = "\xFF";
+ − 822
$f_delim = "\xFF";
+ − 823
$taglist = array();
+ − 824
35
+ − 825
// Wicked huh?
66
+ − 826
$regex = '/\[\[:' . $paths->nslist['File'] . '([\w\s0-9_\(\)!@%\^\+\|\.-]+?)((\|thumb)|(\|([0-9]+)x([0-9]+)))?(\|left|\|right)?(\|raw|\|(.+))?\]\]/i';
35
+ − 827
+ − 828
preg_match_all($regex, $text, $matches);
+ − 829
+ − 830
foreach ( $matches[0] as $i => $match )
+ − 831
{
+ − 832
+ − 833
$full_tag =& $matches[0][$i];
+ − 834
$filename =& $matches[1][$i];
+ − 835
$scale_type =& $matches[2][$i];
+ − 836
$width =& $matches[5][$i];
+ − 837
$height =& $matches[6][$i];
+ − 838
$clear =& $matches[7][$i];
+ − 839
$caption =& $matches[8][$i];
+ − 840
+ − 841
if ( !isPage( $paths->nslist['File'] . $filename ) )
+ − 842
{
66
+ − 843
$text = str_replace($full_tag, '[[' . makeUrlNS('File', $filename) . ']]', $text);
35
+ − 844
continue;
+ − 845
}
+ − 846
+ − 847
if ( $scale_type == '|thumb' )
+ − 848
{
+ − 849
$r_width = 225;
+ − 850
$r_height = 225;
+ − 851
+ − 852
$url = makeUrlNS('Special', 'DownloadFile/' . $filename, 'preview&width=' . $r_width . '&height=' . $r_height, true);
+ − 853
}
+ − 854
else if ( !empty($width) && !empty($height) )
+ − 855
{
+ − 856
$r_width = $width;
+ − 857
$r_height = $height;
+ − 858
+ − 859
$url = makeUrlNS('Special', 'DownloadFile/' . $filename, 'preview&width=' . $r_width . '&height=' . $r_height, true);
+ − 860
}
+ − 861
else
+ − 862
{
+ − 863
$url = makeUrlNS('Special', 'DownloadFile/' . $filename);
+ − 864
}
+ − 865
+ − 866
$img_tag = '<img src="' . $url . '" ';
+ − 867
65
+ − 868
// if ( isset($r_width) && isset($r_height) && $scale_type != '|thumb' )
+ − 869
// {
66
+ − 870
// $img_tag .= 'width="' . $r_width . '" height="' . $r_height . '" ';
65
+ − 871
// }
35
+ − 872
66
+ − 873
$img_tag .= 'style="border-width: 0px; /* background-color: white; */" ';
35
+ − 874
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
+ − 875
$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
+ − 876
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
+ − 877
{
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
+ − 878
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
+ − 879
}
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
+ − 880
35
+ − 881
$img_tag .= '/>';
+ − 882
+ − 883
$complete_tag = '';
+ − 884
66
+ − 885
if ( !empty($scale_type) && $caption != '|raw' )
35
+ − 886
{
+ − 887
$complete_tag .= '<div class="thumbnail" ';
+ − 888
$clear_text = '';
+ − 889
if ( !empty($clear) )
+ − 890
{
+ − 891
$side = ( $clear == '|left' ) ? 'left' : 'right';
+ − 892
$opposite = ( $clear == '|left' ) ? 'right' : 'left';
37
+ − 893
$clear_text .= "float: $side; margin-$opposite: 20px;";
35
+ − 894
$complete_tag .= 'style="' . $clear_text . '" ';
+ − 895
}
+ − 896
$complete_tag .= '>';
+ − 897
+ − 898
$complete_tag .= '<a href="' . makeUrlNS('File', $filename) . '" style="display: block;">';
+ − 899
$complete_tag .= $img_tag;
+ − 900
$complete_tag .= '</a>';
+ − 901
+ − 902
$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>';
+ − 903
+ − 904
if ( !empty($caption) )
+ − 905
{
+ − 906
$cap = substr($caption, 1);
+ − 907
$complete_tag .= $mag_button . $cap;
+ − 908
}
+ − 909
+ − 910
$complete_tag .= '</div>';
+ − 911
}
66
+ − 912
else if ( $caption == '|raw' )
+ − 913
{
67
+ − 914
$complete_tag .= "$img_tag";
+ − 915
$taglist[$i] = $complete_tag;
+ − 916
+ − 917
$repl = "{$s_delim}e_img_{$i}{$f_delim}";
+ − 918
$text = str_replace($full_tag, $repl, $text);
+ − 919
continue;
66
+ − 920
}
35
+ − 921
else
+ − 922
{
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
+ − 923
$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
+ − 924
$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
+ − 925
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
+ − 926
{
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
+ − 927
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
+ − 928
}
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
+ − 929
$complete_tag .= '>';
35
+ − 930
$complete_tag .= $img_tag;
+ − 931
$complete_tag .= '</a>';
+ − 932
}
+ − 933
37
+ − 934
$complete_tag .= "\n\n";
+ − 935
$taglist[$i] = $complete_tag;
35
+ − 936
37
+ − 937
$pos = strpos($text, $full_tag);
35
+ − 938
+ − 939
while(true)
+ − 940
{
+ − 941
$check1 = substr($text, $pos, 3);
+ − 942
$check2 = substr($text, $pos, 1);
+ − 943
if ( $check1 == '<p>' || $pos == 0 || $check2 == "\n" )
+ − 944
{
+ − 945
// die('found at pos '.$pos);
+ − 946
break;
+ − 947
}
+ − 948
$pos--;
+ − 949
}
+ − 950
37
+ − 951
$repl = "{$s_delim}e_img_{$i}{$f_delim}";
+ − 952
$text = substr($text, 0, $pos) . $repl . substr($text, $pos);
35
+ − 953
+ − 954
$text = str_replace($full_tag, '', $text);
+ − 955
+ − 956
unset($full_tag, $filename, $scale_type, $width, $height, $clear, $caption, $r_width, $r_height);
+ − 957
+ − 958
}
+ − 959
+ − 960
return $text;
+ − 961
}
+ − 962
37
+ − 963
/**
+ − 964
* Finalizes processing of image tags.
+ − 965
* @param string The preprocessed text
+ − 966
* @param array The list of image tags created by RenderMan::process_image_tags()
+ − 967
*/
+ − 968
+ − 969
function process_imgtags_stage2($text, $taglist)
+ − 970
{
+ − 971
$s_delim = "\xFF";
+ − 972
$f_delim = "\xFF";
+ − 973
foreach ( $taglist as $i => $tag )
+ − 974
{
+ − 975
$repl = "{$s_delim}e_img_{$i}{$f_delim}";
+ − 976
$text = str_replace($repl, $tag, $text);
+ − 977
}
+ − 978
return $text;
+ − 979
}
+ − 980
1
+ − 981
}
+ − 982
+ − 983
?>