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
801
eb8b23f11744
Two big commits in one day I know, but redid password storage to use HMAC-SHA1. Consolidated much AES processing to three core methods in session that should handle everything automagically. Installation works; upgrades should. Rebranded as 1.1.6.
Dan
diff
changeset
+ − 5
* Version 1.1.6 (Caoineag beta 1)
536
+ − 6
* Copyright (C) 2006-2008 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
371
dc6026376919
Improved compatibility with PostgreSQL and fixed a number of installer bugs; fixed missing "meta" category declaration in language files
Dan
diff
changeset
+ − 18
public static function strToPageID($string)
1
+ − 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
371
dc6026376919
Improved compatibility with PostgreSQL and fixed a number of installer bugs; fixed missing "meta" category declaration in language files
Dan
diff
changeset
+ − 41
public static function getPage($page_id, $namespace, $wiki = 1, $smilies = true, $filter_links = true, $redir = true, $render = true)
1
+ − 42
{
+ − 43
global $db, $session, $paths, $template, $plugins; // Common objects
+ − 44
832
7152ca0a0ce9
Major redesign of rendering pipeline that separates pages saved with MCE from pages saved with the plaintext editor (full description in long commit message)
Dan
diff
changeset
+ − 45
$page = new PageProcessor($page_id, $namespace);
7152ca0a0ce9
Major redesign of rendering pipeline that separates pages saved with MCE from pages saved with the plaintext editor (full description in long commit message)
Dan
diff
changeset
+ − 46
$text = $page->fetch_text();
1
+ − 47
832
7152ca0a0ce9
Major redesign of rendering pipeline that separates pages saved with MCE from pages saved with the plaintext editor (full description in long commit message)
Dan
diff
changeset
+ − 48
if ( !$render )
7152ca0a0ce9
Major redesign of rendering pipeline that separates pages saved with MCE from pages saved with the plaintext editor (full description in long commit message)
Dan
diff
changeset
+ − 49
return $text;
1
+ − 50
832
7152ca0a0ce9
Major redesign of rendering pipeline that separates pages saved with MCE from pages saved with the plaintext editor (full description in long commit message)
Dan
diff
changeset
+ − 51
$text = self::render($text, $wiki, $smilies, $filter_links);
7152ca0a0ce9
Major redesign of rendering pipeline that separates pages saved with MCE from pages saved with the plaintext editor (full description in long commit message)
Dan
diff
changeset
+ − 52
return $text;
1
+ − 53
}
+ − 54
371
dc6026376919
Improved compatibility with PostgreSQL and fixed a number of installer bugs; fixed missing "meta" category declaration in language files
Dan
diff
changeset
+ − 55
public static function getTemplate($id, $parms)
1
+ − 56
{
+ − 57
global $db, $session, $paths, $template, $plugins; // Common objects
953
323c4cd1aa37
Made some more changes to the way namespaces are handled, for optimization purposes. This is a bit of a structural reorganization: $paths->pages is obsoleted in its entirety; calculating page existence and metadata is now the job of the Namespace_* backend class. There are many things in PageProcessor that should be reorganized, and page actions in general should really be rethought. This is probably the beginning of a long process that will be taking place over the course of the betas.
Dan
diff
changeset
+ − 58
if ( !isPage($paths->get_pathskey($id, 'Template')) )
1
+ − 59
{
+ − 60
return '[['.$paths->nslist['Template'].$id.']]';
+ − 61
}
+ − 62
if(isset($paths->template_cache[$id]))
+ − 63
{
+ − 64
$text = $paths->template_cache[$id];
+ − 65
}
+ − 66
else
+ − 67
{
953
323c4cd1aa37
Made some more changes to the way namespaces are handled, for optimization purposes. This is a bit of a structural reorganization: $paths->pages is obsoleted in its entirety; calculating page existence and metadata is now the job of the Namespace_* backend class. There are many things in PageProcessor that should be reorganized, and page actions in general should really be rethought. This is probably the beginning of a long process that will be taking place over the course of the betas.
Dan
diff
changeset
+ − 68
$page = new PageProcessor($id, 'Template');
323c4cd1aa37
Made some more changes to the way namespaces are handled, for optimization purposes. This is a bit of a structural reorganization: $paths->pages is obsoleted in its entirety; calculating page existence and metadata is now the job of the Namespace_* backend class. There are many things in PageProcessor that should be reorganized, and page actions in general should really be rethought. This is probably the beginning of a long process that will be taking place over the course of the betas.
Dan
diff
changeset
+ − 69
$text = $page->fetch_text();
1
+ − 70
$paths->template_cache[$id] = $text;
+ − 71
}
+ − 72
+ − 73
$text = preg_replace('/<noinclude>(.*?)<\/noinclude>/is', '', $text);
+ − 74
$text = preg_replace('/<nodisplay>(.*?)<\/nodisplay>/is', '\\1', $text);
+ − 75
+ − 76
preg_match_all('#\(_([0-9]+)_\)#', $text, $matchlist);
+ − 77
+ − 78
foreach($matchlist[1] as $m)
+ − 79
{
+ − 80
if(isset($parms[((int)$m)+1]))
+ − 81
{
+ − 82
$p = $parms[((int)$m)+1];
+ − 83
}
+ − 84
else
+ − 85
{
+ − 86
$p = '<b>Notice:</b> RenderMan::getTemplate(): Parameter '.$m.' is not set';
+ − 87
}
+ − 88
$text = str_replace('(_'.$m.'_)', $p, $text);
717
+ − 89
$text = str_replace('{{' . ( $m + 1 ) . '}}', $p, $text);
1
+ − 90
}
+ − 91
$text = RenderMan::include_templates($text);
+ − 92
return $text;
+ − 93
}
+ − 94
371
dc6026376919
Improved compatibility with PostgreSQL and fixed a number of installer bugs; fixed missing "meta" category declaration in language files
Dan
diff
changeset
+ − 95
public static function fetch_template_text($id)
1
+ − 96
{
+ − 97
global $db, $session, $paths, $template, $plugins; // Common objects
745
+ − 98
$fetch_ns = 'Template';
953
323c4cd1aa37
Made some more changes to the way namespaces are handled, for optimization purposes. This is a bit of a structural reorganization: $paths->pages is obsoleted in its entirety; calculating page existence and metadata is now the job of the Namespace_* backend class. There are many things in PageProcessor that should be reorganized, and page actions in general should really be rethought. This is probably the beginning of a long process that will be taking place over the course of the betas.
Dan
diff
changeset
+ − 99
if ( !isPage($paths->get_pathskey($id, 'Template')) )
1
+ − 100
{
745
+ − 101
// Transclusion of another page
+ − 102
// 1.1.5: Now You, Too, Can Be A Template, Even If You're Just A Plain Old Article! (TM)
+ − 103
$nssep = substr($paths->nslist['Special'], -1);
+ − 104
$nslist = $paths->nslist;
+ − 105
foreach ( $nslist as &$ns )
+ − 106
{
+ − 107
if ( $ns == '' )
+ − 108
$ns = $nssep;
+ − 109
}
+ − 110
$prefixlist = array_flip($nslist);
+ − 111
foreach ( $nslist as &$ns )
+ − 112
{
+ − 113
$ns = preg_quote($ns);
+ − 114
}
+ − 115
$nslist = implode('|', $nslist);
+ − 116
if ( preg_match("/^($nslist)(.*?)$/", $id, $match) )
+ − 117
{
+ − 118
// in practice this should always be true but just to be safe...
+ − 119
if ( isset($prefixlist[$match[1]]) )
+ − 120
{
+ − 121
$new_id = $paths->nslist[ $prefixlist[$match[1]] ] . sanitize_page_id($match[2]);
832
7152ca0a0ce9
Major redesign of rendering pipeline that separates pages saved with MCE from pages saved with the plaintext editor (full description in long commit message)
Dan
diff
changeset
+ − 122
if ( !isPage($new_id) )
745
+ − 123
{
+ − 124
return "[[$new_id]]";
+ − 125
}
+ − 126
$fetch_ns = $prefixlist[$match[1]];
+ − 127
$id = sanitize_page_id($match[2]);
+ − 128
}
+ − 129
}
+ − 130
else
+ − 131
{
+ − 132
return '[['.$paths->nslist['Template'].$id.']]';
+ − 133
}
1
+ − 134
}
+ − 135
if(isset($paths->template_cache[$id]))
+ − 136
{
+ − 137
$text = $paths->template_cache[$id];
+ − 138
}
+ − 139
else
+ − 140
{
745
+ − 141
$text = RenderMan::getPage($id, $fetch_ns, 0, false, false, false, false);
1
+ − 142
$paths->template_cache[$id] = $text;
+ − 143
}
+ − 144
+ − 145
if ( is_string($text) )
+ − 146
{
+ − 147
$text = preg_replace('/<noinclude>(.*?)<\/noinclude>/is', '', $text);
+ − 148
$text = preg_replace('/<nodisplay>(.*?)<\/nodisplay>/is', '\\1', $text);
+ − 149
}
+ − 150
+ − 151
return $text;
+ − 152
}
+ − 153
832
7152ca0a0ce9
Major redesign of rendering pipeline that separates pages saved with MCE from pages saved with the plaintext editor (full description in long commit message)
Dan
diff
changeset
+ − 154
/**
7152ca0a0ce9
Major redesign of rendering pipeline that separates pages saved with MCE from pages saved with the plaintext editor (full description in long commit message)
Dan
diff
changeset
+ − 155
* Renders a glob of text. Note that this is PHP-safe, so if returned text (or rather, "?>" . $returned) has PHP it can be eval'ed.
7152ca0a0ce9
Major redesign of rendering pipeline that separates pages saved with MCE from pages saved with the plaintext editor (full description in long commit message)
Dan
diff
changeset
+ − 156
* @param string Text to render
7152ca0a0ce9
Major redesign of rendering pipeline that separates pages saved with MCE from pages saved with the plaintext editor (full description in long commit message)
Dan
diff
changeset
+ − 157
* @param int Render parameters - see constants.php
7152ca0a0ce9
Major redesign of rendering pipeline that separates pages saved with MCE from pages saved with the plaintext editor (full description in long commit message)
Dan
diff
changeset
+ − 158
* @return string Rendered text
7152ca0a0ce9
Major redesign of rendering pipeline that separates pages saved with MCE from pages saved with the plaintext editor (full description in long commit message)
Dan
diff
changeset
+ − 159
*/
7152ca0a0ce9
Major redesign of rendering pipeline that separates pages saved with MCE from pages saved with the plaintext editor (full description in long commit message)
Dan
diff
changeset
+ − 160
7152ca0a0ce9
Major redesign of rendering pipeline that separates pages saved with MCE from pages saved with the plaintext editor (full description in long commit message)
Dan
diff
changeset
+ − 161
public static function render($text, $flags = RENDER_WIKI_DEFAULT, $smilies = true)
1
+ − 162
{
+ − 163
global $db, $session, $paths, $template, $plugins; // Common objects
832
7152ca0a0ce9
Major redesign of rendering pipeline that separates pages saved with MCE from pages saved with the plaintext editor (full description in long commit message)
Dan
diff
changeset
+ − 164
7152ca0a0ce9
Major redesign of rendering pipeline that separates pages saved with MCE from pages saved with the plaintext editor (full description in long commit message)
Dan
diff
changeset
+ − 165
if ( !$smilies )
7152ca0a0ce9
Major redesign of rendering pipeline that separates pages saved with MCE from pages saved with the plaintext editor (full description in long commit message)
Dan
diff
changeset
+ − 166
$flags |= RENDER_NOSMILIES;
7152ca0a0ce9
Major redesign of rendering pipeline that separates pages saved with MCE from pages saved with the plaintext editor (full description in long commit message)
Dan
diff
changeset
+ − 167
7152ca0a0ce9
Major redesign of rendering pipeline that separates pages saved with MCE from pages saved with the plaintext editor (full description in long commit message)
Dan
diff
changeset
+ − 168
if ( $flags & ~RENDER_NOSMILIES )
1
+ − 169
{
+ − 170
$text = RenderMan::smilieyize($text);
+ − 171
}
832
7152ca0a0ce9
Major redesign of rendering pipeline that separates pages saved with MCE from pages saved with the plaintext editor (full description in long commit message)
Dan
diff
changeset
+ − 172
if ( $flags & RENDER_WIKI_DEFAULT )
1
+ − 173
{
832
7152ca0a0ce9
Major redesign of rendering pipeline that separates pages saved with MCE from pages saved with the plaintext editor (full description in long commit message)
Dan
diff
changeset
+ − 174
$text = RenderMan::next_gen_wiki_format($text, $flags);
1
+ − 175
}
832
7152ca0a0ce9
Major redesign of rendering pipeline that separates pages saved with MCE from pages saved with the plaintext editor (full description in long commit message)
Dan
diff
changeset
+ − 176
else if ( $flags & RENDER_WIKI_TEMPLATE )
1
+ − 177
{
+ − 178
$text = $template->tplWikiFormat($text);
832
7152ca0a0ce9
Major redesign of rendering pipeline that separates pages saved with MCE from pages saved with the plaintext editor (full description in long commit message)
Dan
diff
changeset
+ − 179
}
1
+ − 180
return $text;
+ − 181
}
+ − 182
832
7152ca0a0ce9
Major redesign of rendering pipeline that separates pages saved with MCE from pages saved with the plaintext editor (full description in long commit message)
Dan
diff
changeset
+ − 183
private static function next_gen_wiki_format($text, $flags = 0)
1
+ − 184
{
+ − 185
global $db, $session, $paths, $template, $plugins; // Common objects
377
bb3e6c3bd4f4
Removed stray debugging info from ACL editor success notification; added ability for guests to set language on URI (?lang=eng); added html_in_pages ACL type and separated from php_in_pages so HTML can be embedded but not PHP; rewote portions of the path manager to better abstract URL input; added Zend Framework into list of BSD-licensed libraries; localized some remaining strings; got the migration script working, but just barely; fixed display bug in Special:Contributions; localized Main Page button in admin panel
Dan
diff
changeset
+ − 186
global $lang;
bb3e6c3bd4f4
Removed stray debugging info from ACL editor success notification; added ability for guests to set language on URI (?lang=eng); added html_in_pages ACL type and separated from php_in_pages so HTML can be embedded but not PHP; rewote portions of the path manager to better abstract URL input; added Zend Framework into list of BSD-licensed libraries; localized some remaining strings; got the migration script working, but just barely; fixed display bug in Special:Contributions; localized Main Page button in admin panel
Dan
diff
changeset
+ − 187
1027
+ − 188
profiler_log("RenderMan: starting wikitext render");
+ − 189
require_once( ENANO_ROOT . '/includes/wikiformat.php' );
+ − 190
require_once( ENANO_ROOT . '/includes/wikiengine/TagSanitizer.php' );
+ − 191
require_once( ENANO_ROOT . '/includes/wikiengine/Tables.php' );
592
+ − 192
1027
+ − 193
// this is still needed by parser plugins
1
+ − 194
$random_id = md5( time() . mt_rand() );
+ − 195
+ − 196
// Strip out <nowiki> sections and PHP code
+ − 197
1027
+ − 198
self::nowiki_strip($text, $nowiki_stripped);
407
+ − 199
+ − 200
$code = $plugins->setHook('render_wikiformat_veryearly');
+ − 201
foreach ( $code as $cmd )
+ − 202
{
+ − 203
eval($cmd);
+ − 204
}
+ − 205
1027
+ − 206
self::php_strip($text, $php_stripped);
1
+ − 207
1027
+ − 208
$carpenter = new Carpenter();
+ − 209
$carpenter->flags = $flags;
+ − 210
$carpenter->hook(array(__CLASS__, 'hook_pre'), PO_AFTER, 'lang');
+ − 211
$carpenter->hook(array(__CLASS__, 'hook_posttemplates'), PO_AFTER, 'templates');
+ − 212
if ( $flags & RENDER_WIKI_TEMPLATE )
1
+ − 213
{
1027
+ − 214
// FIXME: process noinclude/nodisplay
+ − 215
}
+ − 216
$text = $carpenter->render($text);
+ − 217
+ − 218
// For plugin compat
+ − 219
$result =& $text;
+ − 220
+ − 221
$code = $plugins->setHook('render_wikiformat_post');
+ − 222
foreach ( $code as $cmd )
+ − 223
{
+ − 224
eval($cmd);
1
+ − 225
}
+ − 226
1027
+ − 227
/*
1
+ − 228
$text = preg_replace('/<noinclude>(.*?)<\/noinclude>/is', '\\1', $text);
+ − 229
if ( $paths->namespace == 'Template' )
+ − 230
{
+ − 231
$text = preg_replace('/<nodisplay>(.*?)<\/nodisplay>/is', '', $text);
+ − 232
}
+ − 233
+ − 234
$text = process_tables($text);
1027
+ − 235
*/
1
+ − 236
1027
+ − 237
self::nowiki_unstrip($text, $nowiki_stripped);
+ − 238
self::php_unstrip($text, $php_stripped);
1
+ − 239
382
2ccb55995aef
Profiling enabled for RenderMan's wikiformat routine; [minor] made HTML from profiler more pretty
Dan
diff
changeset
+ − 240
profiler_log("RenderMan: finished wikitext render");
2ccb55995aef
Profiling enabled for RenderMan's wikiformat routine; [minor] made HTML from profiler more pretty
Dan
diff
changeset
+ − 241
1027
+ − 242
return $text;
+ − 243
}
+ − 244
+ − 245
public static function hook_pre($text)
+ − 246
{
+ − 247
global $db, $session, $paths, $template, $plugins; // Common objects
+ − 248
+ − 249
$code = $plugins->setHook('render_wikiformat_pre');
+ − 250
foreach ( $code as $cmd )
+ − 251
{
+ − 252
eval($cmd);
+ − 253
}
+ − 254
+ − 255
return $text;
+ − 256
}
+ − 257
+ − 258
public static function hook_posttemplates($text)
+ − 259
{
+ − 260
global $db, $session, $paths, $template, $plugins; // Common objects
+ − 261
+ − 262
$code = $plugins->setHook('render_wikiformat_posttemplates');
+ − 263
foreach ( $code as $cmd )
+ − 264
{
+ − 265
eval($cmd);
+ − 266
}
+ − 267
+ − 268
return $text;
+ − 269
}
+ − 270
+ − 271
/**
+ − 272
* Strip out <nowiki> tags (to bypass parsing on them)
+ − 273
* @access private
+ − 274
*/
+ − 275
+ − 276
private static function nowiki_strip(&$text, &$stripdata)
+ − 277
{
+ − 278
self::tag_strip('nowiki', $text, $stripdata);
+ − 279
}
+ − 280
+ − 281
/**
+ − 282
* Restore stripped <nowiki> tags.
+ − 283
* @access private
+ − 284
*/
+ − 285
+ − 286
public static function nowiki_unstrip(&$text, &$stripdata)
+ − 287
{
+ − 288
self::tag_unstrip('nowiki', $text, $stripdata);
+ − 289
}
+ − 290
+ − 291
/**
+ − 292
* Strip out an arbitrary HTML tag.
+ − 293
* @access private
+ − 294
*/
+ − 295
+ − 296
public static function tag_strip($tag, &$text, &$stripdata)
+ − 297
{
+ − 298
$random_id = md5( time() . mt_rand() );
+ − 299
+ − 300
preg_match_all("#<$tag>(.*?)</$tag>#is", $text, $blocks);
+ − 301
+ − 302
foreach ( $blocks[0] as $i => $match )
+ − 303
{
+ − 304
$text = str_replace($match, "{{$tag}:{$random_id}:{$i}}", $text);
+ − 305
}
1
+ − 306
1027
+ − 307
$stripdata = array(
+ − 308
'random_id' => $random_id,
+ − 309
'blocks' => $blocks[1]
+ − 310
);
1
+ − 311
}
+ − 312
1027
+ − 313
/**
+ − 314
* Restore stripped <nowiki> tags.
+ − 315
* @access private
+ − 316
*/
+ − 317
+ − 318
public static function tag_unstrip($tag, &$text, &$stripdata)
+ − 319
{
+ − 320
$random_id = $stripdata['random_id'];
+ − 321
+ − 322
foreach ( $stripdata['blocks'] as $i => $block )
+ − 323
{
+ − 324
$text = str_replace("{{$tag}:{$random_id}:{$i}}", $block, $text);
+ − 325
}
+ − 326
+ − 327
$stripdata = array();
+ − 328
}
+ − 329
+ − 330
/**
+ − 331
* Strip out PHP code (to prevent it from being sent through the parser). Private because it does not do what you think it does. (The method you are looking for is strip_php.)
+ − 332
* @access private
+ − 333
*/
+ − 334
+ − 335
private static function php_strip(&$text, &$stripdata)
+ − 336
{
+ − 337
$random_id = md5( time() . mt_rand() );
+ − 338
+ − 339
preg_match_all('#<\?(?:php)?[\s=].+?\?>#is', $text, $blocks);
+ − 340
+ − 341
foreach ( $blocks[0] as $i => $match )
+ − 342
{
+ − 343
$text = str_replace($match, "{PHP:$random_id:$i}", $text);
+ − 344
}
+ − 345
+ − 346
$stripdata = array(
+ − 347
'random_id' => $random_id,
+ − 348
'blocks' => $blocks[0]
+ − 349
);
+ − 350
}
+ − 351
+ − 352
/**
+ − 353
* Restore stripped PHP code
+ − 354
* @access private
+ − 355
*/
+ − 356
+ − 357
private static function php_unstrip(&$text, &$stripdata)
+ − 358
{
+ − 359
$random_id = $stripdata['random_id'];
+ − 360
+ − 361
foreach ( $stripdata['blocks'] as $i => $block )
+ − 362
{
+ − 363
$text = str_replace("{PHP:$random_id:$i}", $block, $text);
+ − 364
}
+ − 365
+ − 366
$stripdata = array();
+ − 367
}
+ − 368
+ − 369
/**
+ − 370
* Deprecated.
+ − 371
*/
+ − 372
371
dc6026376919
Improved compatibility with PostgreSQL and fixed a number of installer bugs; fixed missing "meta" category declaration in language files
Dan
diff
changeset
+ − 373
public static function wikiFormat($message, $filter_links = true, $do_params = false, $plaintext = false)
163
+ − 374
{
1
+ − 375
global $db, $session, $paths, $template, $plugins; // Common objects
+ − 376
+ − 377
return RenderMan::next_gen_wiki_format($message, $plaintext, $filter_links, $do_params);
+ − 378
}
+ − 379
371
dc6026376919
Improved compatibility with PostgreSQL and fixed a number of installer bugs; fixed missing "meta" category declaration in language files
Dan
diff
changeset
+ − 380
public static function destroy_javascript($message, $_php = false)
1
+ − 381
{
+ − 382
$message = preg_replace('#<(script|object|applet|embed|iframe|frame|form|input|select)(.*?)>#is', '<\\1\\2>', $message);
+ − 383
$message = preg_replace('#</(script|object|applet|embed|iframe|frame|form|input|select)(.*?)>#is', '</\\1\\2>', $message);
+ − 384
$message = preg_replace('#(javascript|script|activex|chrome|about|applet):#is', '\\1:', $message);
+ − 385
if ( $_php )
+ − 386
{
+ − 387
// Left in only for compatibility
+ − 388
$message = preg_replace('#<(.*?)>#is', '<\\1>', $message);
+ − 389
$message = preg_replace('#<(.*?)>#is', '<\\1>', $message);
+ − 390
$message = preg_replace('#<(\?|\?php|%)(.*?)(\?|%)>#is', '<\\1\\2\\3>', $message);
+ − 391
// strip <a href="foo" onclick="bar();">-type attacks
+ − 392
$message = preg_replace('#<([a-zA-Z:\-]+) (.*?)on([A-Za-z]*)=(.*?)>#is', '<\\1\\2on\\3=\\4>', $message);
+ − 393
}
+ − 394
return $message;
+ − 395
}
+ − 396
371
dc6026376919
Improved compatibility with PostgreSQL and fixed a number of installer bugs; fixed missing "meta" category declaration in language files
Dan
diff
changeset
+ − 397
public static function strip_php($message)
1
+ − 398
{
+ − 399
return RenderMan::destroy_javascript($message, true);
+ − 400
}
+ − 401
371
dc6026376919
Improved compatibility with PostgreSQL and fixed a number of installer bugs; fixed missing "meta" category declaration in language files
Dan
diff
changeset
+ − 402
public static function sanitize_html($text)
1
+ − 403
{
+ − 404
$text = htmlspecialchars($text);
91
+ − 405
$allowed_tags = Array('b', 'i', 'u', 'pre', 'code', 'tt', 'br', 'p', 'nowiki', '!--([\w\W]+)--');
1
+ − 406
foreach($allowed_tags as $t)
+ − 407
{
+ − 408
$text = preg_replace('#<'.$t.'>(.*?)</'.$t.'>#is', '<'.$t.'>\\1</'.$t.'>', $text);
+ − 409
$text = preg_replace('#<'.$t.' />#is', '<'.$t.' />', $text);
+ − 410
$text = preg_replace('#<'.$t.'>#is', '<'.$t.'>', $text);
+ − 411
}
+ − 412
return $text;
+ − 413
}
+ − 414
91
+ − 415
/**
832
7152ca0a0ce9
Major redesign of rendering pipeline that separates pages saved with MCE from pages saved with the plaintext editor (full description in long commit message)
Dan
diff
changeset
+ − 416
* Reverse-renders a blob of text (converts it from XHTML back to wikitext) by using parser hints and educated guesses.
7152ca0a0ce9
Major redesign of rendering pipeline that separates pages saved with MCE from pages saved with the plaintext editor (full description in long commit message)
Dan
diff
changeset
+ − 417
* @param string XHTML
7152ca0a0ce9
Major redesign of rendering pipeline that separates pages saved with MCE from pages saved with the plaintext editor (full description in long commit message)
Dan
diff
changeset
+ − 418
* @return string Wikitext
7152ca0a0ce9
Major redesign of rendering pipeline that separates pages saved with MCE from pages saved with the plaintext editor (full description in long commit message)
Dan
diff
changeset
+ − 419
*/
7152ca0a0ce9
Major redesign of rendering pipeline that separates pages saved with MCE from pages saved with the plaintext editor (full description in long commit message)
Dan
diff
changeset
+ − 420
7152ca0a0ce9
Major redesign of rendering pipeline that separates pages saved with MCE from pages saved with the plaintext editor (full description in long commit message)
Dan
diff
changeset
+ − 421
public static function reverse_render($text)
7152ca0a0ce9
Major redesign of rendering pipeline that separates pages saved with MCE from pages saved with the plaintext editor (full description in long commit message)
Dan
diff
changeset
+ − 422
{
7152ca0a0ce9
Major redesign of rendering pipeline that separates pages saved with MCE from pages saved with the plaintext editor (full description in long commit message)
Dan
diff
changeset
+ − 423
// convert \r\n to \n
7152ca0a0ce9
Major redesign of rendering pipeline that separates pages saved with MCE from pages saved with the plaintext editor (full description in long commit message)
Dan
diff
changeset
+ − 424
$text = str_replace("\r\n", "\n", $text);
7152ca0a0ce9
Major redesign of rendering pipeline that separates pages saved with MCE from pages saved with the plaintext editor (full description in long commit message)
Dan
diff
changeset
+ − 425
7152ca0a0ce9
Major redesign of rendering pipeline that separates pages saved with MCE from pages saved with the plaintext editor (full description in long commit message)
Dan
diff
changeset
+ − 426
// Separate certain block level elements onto their own lines. This tidies up the tag
7152ca0a0ce9
Major redesign of rendering pipeline that separates pages saved with MCE from pages saved with the plaintext editor (full description in long commit message)
Dan
diff
changeset
+ − 427
// soup that TinyMCE sometimes produces.
7152ca0a0ce9
Major redesign of rendering pipeline that separates pages saved with MCE from pages saved with the plaintext editor (full description in long commit message)
Dan
diff
changeset
+ − 428
$block_elements = array('h1', 'h2', 'h3', 'h4', 'h5', 'h6', 'p', 'div', 'table', 'ul', 'pre');
7152ca0a0ce9
Major redesign of rendering pipeline that separates pages saved with MCE from pages saved with the plaintext editor (full description in long commit message)
Dan
diff
changeset
+ − 429
$block_elements = implode('|', $block_elements);
7152ca0a0ce9
Major redesign of rendering pipeline that separates pages saved with MCE from pages saved with the plaintext editor (full description in long commit message)
Dan
diff
changeset
+ − 430
$regex = "#(</(?:$block_elements)>)\n?<($block_elements)(>| .+?>)#i";
7152ca0a0ce9
Major redesign of rendering pipeline that separates pages saved with MCE from pages saved with the plaintext editor (full description in long commit message)
Dan
diff
changeset
+ − 431
$text = preg_replace($regex, "$1\n\n<$2$3", $text);
7152ca0a0ce9
Major redesign of rendering pipeline that separates pages saved with MCE from pages saved with the plaintext editor (full description in long commit message)
Dan
diff
changeset
+ − 432
7152ca0a0ce9
Major redesign of rendering pipeline that separates pages saved with MCE from pages saved with the plaintext editor (full description in long commit message)
Dan
diff
changeset
+ − 433
$text = self::reverse_process_parser_hints($text);
7152ca0a0ce9
Major redesign of rendering pipeline that separates pages saved with MCE from pages saved with the plaintext editor (full description in long commit message)
Dan
diff
changeset
+ − 434
$text = self::reverse_process_headings($text);
7152ca0a0ce9
Major redesign of rendering pipeline that separates pages saved with MCE from pages saved with the plaintext editor (full description in long commit message)
Dan
diff
changeset
+ − 435
$text = self::reverse_process_lists($text);
7152ca0a0ce9
Major redesign of rendering pipeline that separates pages saved with MCE from pages saved with the plaintext editor (full description in long commit message)
Dan
diff
changeset
+ − 436
$text = self::reverse_process_tables($text);
7152ca0a0ce9
Major redesign of rendering pipeline that separates pages saved with MCE from pages saved with the plaintext editor (full description in long commit message)
Dan
diff
changeset
+ − 437
7152ca0a0ce9
Major redesign of rendering pipeline that separates pages saved with MCE from pages saved with the plaintext editor (full description in long commit message)
Dan
diff
changeset
+ − 438
// Lastly, strip out paragraph tags.
7152ca0a0ce9
Major redesign of rendering pipeline that separates pages saved with MCE from pages saved with the plaintext editor (full description in long commit message)
Dan
diff
changeset
+ − 439
$text = preg_replace('|^ *<p>(.+?)</p> *$|m', "\\1", $text);
7152ca0a0ce9
Major redesign of rendering pipeline that separates pages saved with MCE from pages saved with the plaintext editor (full description in long commit message)
Dan
diff
changeset
+ − 440
7152ca0a0ce9
Major redesign of rendering pipeline that separates pages saved with MCE from pages saved with the plaintext editor (full description in long commit message)
Dan
diff
changeset
+ − 441
return $text;
7152ca0a0ce9
Major redesign of rendering pipeline that separates pages saved with MCE from pages saved with the plaintext editor (full description in long commit message)
Dan
diff
changeset
+ − 442
}
7152ca0a0ce9
Major redesign of rendering pipeline that separates pages saved with MCE from pages saved with the plaintext editor (full description in long commit message)
Dan
diff
changeset
+ − 443
7152ca0a0ce9
Major redesign of rendering pipeline that separates pages saved with MCE from pages saved with the plaintext editor (full description in long commit message)
Dan
diff
changeset
+ − 444
public static function reverse_process_parser_hints($text)
7152ca0a0ce9
Major redesign of rendering pipeline that separates pages saved with MCE from pages saved with the plaintext editor (full description in long commit message)
Dan
diff
changeset
+ − 445
{
7152ca0a0ce9
Major redesign of rendering pipeline that separates pages saved with MCE from pages saved with the plaintext editor (full description in long commit message)
Dan
diff
changeset
+ − 446
global $db, $session, $paths, $template, $plugins; // Common objects
7152ca0a0ce9
Major redesign of rendering pipeline that separates pages saved with MCE from pages saved with the plaintext editor (full description in long commit message)
Dan
diff
changeset
+ − 447
7152ca0a0ce9
Major redesign of rendering pipeline that separates pages saved with MCE from pages saved with the plaintext editor (full description in long commit message)
Dan
diff
changeset
+ − 448
if ( !preg_match_all('|<!--#([a-z0-9_]+)(?: (.+?))?-->([\w\W]*?)<!--#/\\1-->|s', $text, $matches) )
7152ca0a0ce9
Major redesign of rendering pipeline that separates pages saved with MCE from pages saved with the plaintext editor (full description in long commit message)
Dan
diff
changeset
+ − 449
return $text;
7152ca0a0ce9
Major redesign of rendering pipeline that separates pages saved with MCE from pages saved with the plaintext editor (full description in long commit message)
Dan
diff
changeset
+ − 450
7152ca0a0ce9
Major redesign of rendering pipeline that separates pages saved with MCE from pages saved with the plaintext editor (full description in long commit message)
Dan
diff
changeset
+ − 451
foreach ( $matches[0] as $i => $match )
7152ca0a0ce9
Major redesign of rendering pipeline that separates pages saved with MCE from pages saved with the plaintext editor (full description in long commit message)
Dan
diff
changeset
+ − 452
{
7152ca0a0ce9
Major redesign of rendering pipeline that separates pages saved with MCE from pages saved with the plaintext editor (full description in long commit message)
Dan
diff
changeset
+ − 453
$tag =& $matches[1][$i];
7152ca0a0ce9
Major redesign of rendering pipeline that separates pages saved with MCE from pages saved with the plaintext editor (full description in long commit message)
Dan
diff
changeset
+ − 454
$attribs =& $matches[2][$i];
7152ca0a0ce9
Major redesign of rendering pipeline that separates pages saved with MCE from pages saved with the plaintext editor (full description in long commit message)
Dan
diff
changeset
+ − 455
$inner =& $matches[3][$i];
7152ca0a0ce9
Major redesign of rendering pipeline that separates pages saved with MCE from pages saved with the plaintext editor (full description in long commit message)
Dan
diff
changeset
+ − 456
7152ca0a0ce9
Major redesign of rendering pipeline that separates pages saved with MCE from pages saved with the plaintext editor (full description in long commit message)
Dan
diff
changeset
+ − 457
$attribs = self::reverse_process_hint_attribs($attribs);
7152ca0a0ce9
Major redesign of rendering pipeline that separates pages saved with MCE from pages saved with the plaintext editor (full description in long commit message)
Dan
diff
changeset
+ − 458
switch($tag)
7152ca0a0ce9
Major redesign of rendering pipeline that separates pages saved with MCE from pages saved with the plaintext editor (full description in long commit message)
Dan
diff
changeset
+ − 459
{
7152ca0a0ce9
Major redesign of rendering pipeline that separates pages saved with MCE from pages saved with the plaintext editor (full description in long commit message)
Dan
diff
changeset
+ − 460
case 'smiley':
7152ca0a0ce9
Major redesign of rendering pipeline that separates pages saved with MCE from pages saved with the plaintext editor (full description in long commit message)
Dan
diff
changeset
+ − 461
case 'internallink':
7152ca0a0ce9
Major redesign of rendering pipeline that separates pages saved with MCE from pages saved with the plaintext editor (full description in long commit message)
Dan
diff
changeset
+ − 462
case 'imagelink':
7152ca0a0ce9
Major redesign of rendering pipeline that separates pages saved with MCE from pages saved with the plaintext editor (full description in long commit message)
Dan
diff
changeset
+ − 463
if ( isset($attribs['code']) )
7152ca0a0ce9
Major redesign of rendering pipeline that separates pages saved with MCE from pages saved with the plaintext editor (full description in long commit message)
Dan
diff
changeset
+ − 464
{
7152ca0a0ce9
Major redesign of rendering pipeline that separates pages saved with MCE from pages saved with the plaintext editor (full description in long commit message)
Dan
diff
changeset
+ − 465
$text = str_replace($match, $attribs['code'], $text);
7152ca0a0ce9
Major redesign of rendering pipeline that separates pages saved with MCE from pages saved with the plaintext editor (full description in long commit message)
Dan
diff
changeset
+ − 466
}
7152ca0a0ce9
Major redesign of rendering pipeline that separates pages saved with MCE from pages saved with the plaintext editor (full description in long commit message)
Dan
diff
changeset
+ − 467
else if ( isset($attribs['src']) )
7152ca0a0ce9
Major redesign of rendering pipeline that separates pages saved with MCE from pages saved with the plaintext editor (full description in long commit message)
Dan
diff
changeset
+ − 468
{
7152ca0a0ce9
Major redesign of rendering pipeline that separates pages saved with MCE from pages saved with the plaintext editor (full description in long commit message)
Dan
diff
changeset
+ − 469
$text = str_replace($match, $attribs['src'], $text);
7152ca0a0ce9
Major redesign of rendering pipeline that separates pages saved with MCE from pages saved with the plaintext editor (full description in long commit message)
Dan
diff
changeset
+ − 470
}
7152ca0a0ce9
Major redesign of rendering pipeline that separates pages saved with MCE from pages saved with the plaintext editor (full description in long commit message)
Dan
diff
changeset
+ − 471
break;
7152ca0a0ce9
Major redesign of rendering pipeline that separates pages saved with MCE from pages saved with the plaintext editor (full description in long commit message)
Dan
diff
changeset
+ − 472
}
7152ca0a0ce9
Major redesign of rendering pipeline that separates pages saved with MCE from pages saved with the plaintext editor (full description in long commit message)
Dan
diff
changeset
+ − 473
}
7152ca0a0ce9
Major redesign of rendering pipeline that separates pages saved with MCE from pages saved with the plaintext editor (full description in long commit message)
Dan
diff
changeset
+ − 474
7152ca0a0ce9
Major redesign of rendering pipeline that separates pages saved with MCE from pages saved with the plaintext editor (full description in long commit message)
Dan
diff
changeset
+ − 475
return $text;
7152ca0a0ce9
Major redesign of rendering pipeline that separates pages saved with MCE from pages saved with the plaintext editor (full description in long commit message)
Dan
diff
changeset
+ − 476
}
7152ca0a0ce9
Major redesign of rendering pipeline that separates pages saved with MCE from pages saved with the plaintext editor (full description in long commit message)
Dan
diff
changeset
+ − 477
7152ca0a0ce9
Major redesign of rendering pipeline that separates pages saved with MCE from pages saved with the plaintext editor (full description in long commit message)
Dan
diff
changeset
+ − 478
public static function reverse_process_hint_attribs($attribs)
7152ca0a0ce9
Major redesign of rendering pipeline that separates pages saved with MCE from pages saved with the plaintext editor (full description in long commit message)
Dan
diff
changeset
+ − 479
{
7152ca0a0ce9
Major redesign of rendering pipeline that separates pages saved with MCE from pages saved with the plaintext editor (full description in long commit message)
Dan
diff
changeset
+ − 480
$return = array();
7152ca0a0ce9
Major redesign of rendering pipeline that separates pages saved with MCE from pages saved with the plaintext editor (full description in long commit message)
Dan
diff
changeset
+ − 481
if ( !preg_match_all('/([a-z0-9_-]+)="([^"]+?)"/', $attribs, $matches) )
7152ca0a0ce9
Major redesign of rendering pipeline that separates pages saved with MCE from pages saved with the plaintext editor (full description in long commit message)
Dan
diff
changeset
+ − 482
return array();
7152ca0a0ce9
Major redesign of rendering pipeline that separates pages saved with MCE from pages saved with the plaintext editor (full description in long commit message)
Dan
diff
changeset
+ − 483
7152ca0a0ce9
Major redesign of rendering pipeline that separates pages saved with MCE from pages saved with the plaintext editor (full description in long commit message)
Dan
diff
changeset
+ − 484
foreach ( $matches[0] as $i => $match )
7152ca0a0ce9
Major redesign of rendering pipeline that separates pages saved with MCE from pages saved with the plaintext editor (full description in long commit message)
Dan
diff
changeset
+ − 485
{
7152ca0a0ce9
Major redesign of rendering pipeline that separates pages saved with MCE from pages saved with the plaintext editor (full description in long commit message)
Dan
diff
changeset
+ − 486
$name =& $matches[1][$i];
7152ca0a0ce9
Major redesign of rendering pipeline that separates pages saved with MCE from pages saved with the plaintext editor (full description in long commit message)
Dan
diff
changeset
+ − 487
$value =& $matches[2][$i];
7152ca0a0ce9
Major redesign of rendering pipeline that separates pages saved with MCE from pages saved with the plaintext editor (full description in long commit message)
Dan
diff
changeset
+ − 488
7152ca0a0ce9
Major redesign of rendering pipeline that separates pages saved with MCE from pages saved with the plaintext editor (full description in long commit message)
Dan
diff
changeset
+ − 489
$value = base64_decode($value);
7152ca0a0ce9
Major redesign of rendering pipeline that separates pages saved with MCE from pages saved with the plaintext editor (full description in long commit message)
Dan
diff
changeset
+ − 490
7152ca0a0ce9
Major redesign of rendering pipeline that separates pages saved with MCE from pages saved with the plaintext editor (full description in long commit message)
Dan
diff
changeset
+ − 491
$return[$name] = $value;
7152ca0a0ce9
Major redesign of rendering pipeline that separates pages saved with MCE from pages saved with the plaintext editor (full description in long commit message)
Dan
diff
changeset
+ − 492
}
7152ca0a0ce9
Major redesign of rendering pipeline that separates pages saved with MCE from pages saved with the plaintext editor (full description in long commit message)
Dan
diff
changeset
+ − 493
7152ca0a0ce9
Major redesign of rendering pipeline that separates pages saved with MCE from pages saved with the plaintext editor (full description in long commit message)
Dan
diff
changeset
+ − 494
return $return;
7152ca0a0ce9
Major redesign of rendering pipeline that separates pages saved with MCE from pages saved with the plaintext editor (full description in long commit message)
Dan
diff
changeset
+ − 495
}
7152ca0a0ce9
Major redesign of rendering pipeline that separates pages saved with MCE from pages saved with the plaintext editor (full description in long commit message)
Dan
diff
changeset
+ − 496
7152ca0a0ce9
Major redesign of rendering pipeline that separates pages saved with MCE from pages saved with the plaintext editor (full description in long commit message)
Dan
diff
changeset
+ − 497
/**
7152ca0a0ce9
Major redesign of rendering pipeline that separates pages saved with MCE from pages saved with the plaintext editor (full description in long commit message)
Dan
diff
changeset
+ − 498
* Escapes a string so that it's safe to use as an attribute in a parser hint.
7152ca0a0ce9
Major redesign of rendering pipeline that separates pages saved with MCE from pages saved with the plaintext editor (full description in long commit message)
Dan
diff
changeset
+ − 499
* @param string
7152ca0a0ce9
Major redesign of rendering pipeline that separates pages saved with MCE from pages saved with the plaintext editor (full description in long commit message)
Dan
diff
changeset
+ − 500
* @return string
7152ca0a0ce9
Major redesign of rendering pipeline that separates pages saved with MCE from pages saved with the plaintext editor (full description in long commit message)
Dan
diff
changeset
+ − 501
*/
7152ca0a0ce9
Major redesign of rendering pipeline that separates pages saved with MCE from pages saved with the plaintext editor (full description in long commit message)
Dan
diff
changeset
+ − 502
7152ca0a0ce9
Major redesign of rendering pipeline that separates pages saved with MCE from pages saved with the plaintext editor (full description in long commit message)
Dan
diff
changeset
+ − 503
public static function escape_parser_hint_attrib($text)
7152ca0a0ce9
Major redesign of rendering pipeline that separates pages saved with MCE from pages saved with the plaintext editor (full description in long commit message)
Dan
diff
changeset
+ − 504
{
7152ca0a0ce9
Major redesign of rendering pipeline that separates pages saved with MCE from pages saved with the plaintext editor (full description in long commit message)
Dan
diff
changeset
+ − 505
return base64_encode($text);
7152ca0a0ce9
Major redesign of rendering pipeline that separates pages saved with MCE from pages saved with the plaintext editor (full description in long commit message)
Dan
diff
changeset
+ − 506
}
7152ca0a0ce9
Major redesign of rendering pipeline that separates pages saved with MCE from pages saved with the plaintext editor (full description in long commit message)
Dan
diff
changeset
+ − 507
7152ca0a0ce9
Major redesign of rendering pipeline that separates pages saved with MCE from pages saved with the plaintext editor (full description in long commit message)
Dan
diff
changeset
+ − 508
public static function reverse_process_headings($text)
7152ca0a0ce9
Major redesign of rendering pipeline that separates pages saved with MCE from pages saved with the plaintext editor (full description in long commit message)
Dan
diff
changeset
+ − 509
{
7152ca0a0ce9
Major redesign of rendering pipeline that separates pages saved with MCE from pages saved with the plaintext editor (full description in long commit message)
Dan
diff
changeset
+ − 510
if ( !preg_match_all('|^<h([1-6])(?: id="toc[0-9]+")?>(.*?)</h\\1>$|m', $text, $matches) )
7152ca0a0ce9
Major redesign of rendering pipeline that separates pages saved with MCE from pages saved with the plaintext editor (full description in long commit message)
Dan
diff
changeset
+ − 511
return $text;
7152ca0a0ce9
Major redesign of rendering pipeline that separates pages saved with MCE from pages saved with the plaintext editor (full description in long commit message)
Dan
diff
changeset
+ − 512
7152ca0a0ce9
Major redesign of rendering pipeline that separates pages saved with MCE from pages saved with the plaintext editor (full description in long commit message)
Dan
diff
changeset
+ − 513
foreach ( $matches[0] as $i => $match )
7152ca0a0ce9
Major redesign of rendering pipeline that separates pages saved with MCE from pages saved with the plaintext editor (full description in long commit message)
Dan
diff
changeset
+ − 514
{
7152ca0a0ce9
Major redesign of rendering pipeline that separates pages saved with MCE from pages saved with the plaintext editor (full description in long commit message)
Dan
diff
changeset
+ − 515
// generate heading tag
7152ca0a0ce9
Major redesign of rendering pipeline that separates pages saved with MCE from pages saved with the plaintext editor (full description in long commit message)
Dan
diff
changeset
+ − 516
$heading_size = intval($matches[1][$i]);
7152ca0a0ce9
Major redesign of rendering pipeline that separates pages saved with MCE from pages saved with the plaintext editor (full description in long commit message)
Dan
diff
changeset
+ − 517
$eq = '';
7152ca0a0ce9
Major redesign of rendering pipeline that separates pages saved with MCE from pages saved with the plaintext editor (full description in long commit message)
Dan
diff
changeset
+ − 518
for ( $j = 0; $j < $heading_size; $j++ )
7152ca0a0ce9
Major redesign of rendering pipeline that separates pages saved with MCE from pages saved with the plaintext editor (full description in long commit message)
Dan
diff
changeset
+ − 519
$eq .= '=';
7152ca0a0ce9
Major redesign of rendering pipeline that separates pages saved with MCE from pages saved with the plaintext editor (full description in long commit message)
Dan
diff
changeset
+ − 520
7152ca0a0ce9
Major redesign of rendering pipeline that separates pages saved with MCE from pages saved with the plaintext editor (full description in long commit message)
Dan
diff
changeset
+ − 521
$heading =& $matches[2][$i];
7152ca0a0ce9
Major redesign of rendering pipeline that separates pages saved with MCE from pages saved with the plaintext editor (full description in long commit message)
Dan
diff
changeset
+ − 522
7152ca0a0ce9
Major redesign of rendering pipeline that separates pages saved with MCE from pages saved with the plaintext editor (full description in long commit message)
Dan
diff
changeset
+ − 523
$tag = "$eq $heading $eq";
7152ca0a0ce9
Major redesign of rendering pipeline that separates pages saved with MCE from pages saved with the plaintext editor (full description in long commit message)
Dan
diff
changeset
+ − 524
$text = str_replace($match, $tag, $text);
7152ca0a0ce9
Major redesign of rendering pipeline that separates pages saved with MCE from pages saved with the plaintext editor (full description in long commit message)
Dan
diff
changeset
+ − 525
}
7152ca0a0ce9
Major redesign of rendering pipeline that separates pages saved with MCE from pages saved with the plaintext editor (full description in long commit message)
Dan
diff
changeset
+ − 526
7152ca0a0ce9
Major redesign of rendering pipeline that separates pages saved with MCE from pages saved with the plaintext editor (full description in long commit message)
Dan
diff
changeset
+ − 527
return $text;
7152ca0a0ce9
Major redesign of rendering pipeline that separates pages saved with MCE from pages saved with the plaintext editor (full description in long commit message)
Dan
diff
changeset
+ − 528
}
7152ca0a0ce9
Major redesign of rendering pipeline that separates pages saved with MCE from pages saved with the plaintext editor (full description in long commit message)
Dan
diff
changeset
+ − 529
7152ca0a0ce9
Major redesign of rendering pipeline that separates pages saved with MCE from pages saved with the plaintext editor (full description in long commit message)
Dan
diff
changeset
+ − 530
public static function reverse_process_lists($text)
7152ca0a0ce9
Major redesign of rendering pipeline that separates pages saved with MCE from pages saved with the plaintext editor (full description in long commit message)
Dan
diff
changeset
+ − 531
{
7152ca0a0ce9
Major redesign of rendering pipeline that separates pages saved with MCE from pages saved with the plaintext editor (full description in long commit message)
Dan
diff
changeset
+ − 532
if ( !preg_match('!(</?(?:ul|ol|li)>)!', $text) )
7152ca0a0ce9
Major redesign of rendering pipeline that separates pages saved with MCE from pages saved with the plaintext editor (full description in long commit message)
Dan
diff
changeset
+ − 533
return $text;
7152ca0a0ce9
Major redesign of rendering pipeline that separates pages saved with MCE from pages saved with the plaintext editor (full description in long commit message)
Dan
diff
changeset
+ − 534
7152ca0a0ce9
Major redesign of rendering pipeline that separates pages saved with MCE from pages saved with the plaintext editor (full description in long commit message)
Dan
diff
changeset
+ − 535
$split = preg_split('!(</?(?:ul|ol|li)>)!', $text, -1, PREG_SPLIT_DELIM_CAPTURE);
7152ca0a0ce9
Major redesign of rendering pipeline that separates pages saved with MCE from pages saved with the plaintext editor (full description in long commit message)
Dan
diff
changeset
+ − 536
7152ca0a0ce9
Major redesign of rendering pipeline that separates pages saved with MCE from pages saved with the plaintext editor (full description in long commit message)
Dan
diff
changeset
+ − 537
$stack_height = 0;
7152ca0a0ce9
Major redesign of rendering pipeline that separates pages saved with MCE from pages saved with the plaintext editor (full description in long commit message)
Dan
diff
changeset
+ − 538
$current_list = '';
7152ca0a0ce9
Major redesign of rendering pipeline that separates pages saved with MCE from pages saved with the plaintext editor (full description in long commit message)
Dan
diff
changeset
+ − 539
$old_current_list = '';
7152ca0a0ce9
Major redesign of rendering pipeline that separates pages saved with MCE from pages saved with the plaintext editor (full description in long commit message)
Dan
diff
changeset
+ − 540
$spaces = '';
7152ca0a0ce9
Major redesign of rendering pipeline that separates pages saved with MCE from pages saved with the plaintext editor (full description in long commit message)
Dan
diff
changeset
+ − 541
$marker = '*';
7152ca0a0ce9
Major redesign of rendering pipeline that separates pages saved with MCE from pages saved with the plaintext editor (full description in long commit message)
Dan
diff
changeset
+ − 542
$list_id = 0;
7152ca0a0ce9
Major redesign of rendering pipeline that separates pages saved with MCE from pages saved with the plaintext editor (full description in long commit message)
Dan
diff
changeset
+ − 543
$just_terminated = false;
7152ca0a0ce9
Major redesign of rendering pipeline that separates pages saved with MCE from pages saved with the plaintext editor (full description in long commit message)
Dan
diff
changeset
+ − 544
foreach ( $split as $tag )
7152ca0a0ce9
Major redesign of rendering pipeline that separates pages saved with MCE from pages saved with the plaintext editor (full description in long commit message)
Dan
diff
changeset
+ − 545
{
7152ca0a0ce9
Major redesign of rendering pipeline that separates pages saved with MCE from pages saved with the plaintext editor (full description in long commit message)
Dan
diff
changeset
+ − 546
switch($tag)
7152ca0a0ce9
Major redesign of rendering pipeline that separates pages saved with MCE from pages saved with the plaintext editor (full description in long commit message)
Dan
diff
changeset
+ − 547
{
7152ca0a0ce9
Major redesign of rendering pipeline that separates pages saved with MCE from pages saved with the plaintext editor (full description in long commit message)
Dan
diff
changeset
+ − 548
case '<ul>':
7152ca0a0ce9
Major redesign of rendering pipeline that separates pages saved with MCE from pages saved with the plaintext editor (full description in long commit message)
Dan
diff
changeset
+ − 549
case '<ol>':
7152ca0a0ce9
Major redesign of rendering pipeline that separates pages saved with MCE from pages saved with the plaintext editor (full description in long commit message)
Dan
diff
changeset
+ − 550
$stack_height++;
7152ca0a0ce9
Major redesign of rendering pipeline that separates pages saved with MCE from pages saved with the plaintext editor (full description in long commit message)
Dan
diff
changeset
+ − 551
$just_terminated = false;
7152ca0a0ce9
Major redesign of rendering pipeline that separates pages saved with MCE from pages saved with the plaintext editor (full description in long commit message)
Dan
diff
changeset
+ − 552
if ( $stack_height > 1 )
7152ca0a0ce9
Major redesign of rendering pipeline that separates pages saved with MCE from pages saved with the plaintext editor (full description in long commit message)
Dan
diff
changeset
+ − 553
$spaces .= $marker;
7152ca0a0ce9
Major redesign of rendering pipeline that separates pages saved with MCE from pages saved with the plaintext editor (full description in long commit message)
Dan
diff
changeset
+ − 554
7152ca0a0ce9
Major redesign of rendering pipeline that separates pages saved with MCE from pages saved with the plaintext editor (full description in long commit message)
Dan
diff
changeset
+ − 555
$marker = ( $tag == 'ol' ) ? '#' : '*';
7152ca0a0ce9
Major redesign of rendering pipeline that separates pages saved with MCE from pages saved with the plaintext editor (full description in long commit message)
Dan
diff
changeset
+ − 556
if ( $stack_height > 1 )
7152ca0a0ce9
Major redesign of rendering pipeline that separates pages saved with MCE from pages saved with the plaintext editor (full description in long commit message)
Dan
diff
changeset
+ − 557
$current_list .= "\n";
7152ca0a0ce9
Major redesign of rendering pipeline that separates pages saved with MCE from pages saved with the plaintext editor (full description in long commit message)
Dan
diff
changeset
+ − 558
7152ca0a0ce9
Major redesign of rendering pipeline that separates pages saved with MCE from pages saved with the plaintext editor (full description in long commit message)
Dan
diff
changeset
+ − 559
break;
7152ca0a0ce9
Major redesign of rendering pipeline that separates pages saved with MCE from pages saved with the plaintext editor (full description in long commit message)
Dan
diff
changeset
+ − 560
case '</ul>':
7152ca0a0ce9
Major redesign of rendering pipeline that separates pages saved with MCE from pages saved with the plaintext editor (full description in long commit message)
Dan
diff
changeset
+ − 561
case '</ol>':
7152ca0a0ce9
Major redesign of rendering pipeline that separates pages saved with MCE from pages saved with the plaintext editor (full description in long commit message)
Dan
diff
changeset
+ − 562
$stack_height--;
7152ca0a0ce9
Major redesign of rendering pipeline that separates pages saved with MCE from pages saved with the plaintext editor (full description in long commit message)
Dan
diff
changeset
+ − 563
$spaces = substr($spaces, 1);
7152ca0a0ce9
Major redesign of rendering pipeline that separates pages saved with MCE from pages saved with the plaintext editor (full description in long commit message)
Dan
diff
changeset
+ − 564
7152ca0a0ce9
Major redesign of rendering pipeline that separates pages saved with MCE from pages saved with the plaintext editor (full description in long commit message)
Dan
diff
changeset
+ − 565
if ( $stack_height == 0 )
7152ca0a0ce9
Major redesign of rendering pipeline that separates pages saved with MCE from pages saved with the plaintext editor (full description in long commit message)
Dan
diff
changeset
+ − 566
{
7152ca0a0ce9
Major redesign of rendering pipeline that separates pages saved with MCE from pages saved with the plaintext editor (full description in long commit message)
Dan
diff
changeset
+ − 567
// rotate
7152ca0a0ce9
Major redesign of rendering pipeline that separates pages saved with MCE from pages saved with the plaintext editor (full description in long commit message)
Dan
diff
changeset
+ − 568
$text = str_replace_once("{$old_current_list}{$tag}", trim($current_list), $text);
7152ca0a0ce9
Major redesign of rendering pipeline that separates pages saved with MCE from pages saved with the plaintext editor (full description in long commit message)
Dan
diff
changeset
+ − 569
$current_list = '';
7152ca0a0ce9
Major redesign of rendering pipeline that separates pages saved with MCE from pages saved with the plaintext editor (full description in long commit message)
Dan
diff
changeset
+ − 570
$old_current_list = '';
7152ca0a0ce9
Major redesign of rendering pipeline that separates pages saved with MCE from pages saved with the plaintext editor (full description in long commit message)
Dan
diff
changeset
+ − 571
}
7152ca0a0ce9
Major redesign of rendering pipeline that separates pages saved with MCE from pages saved with the plaintext editor (full description in long commit message)
Dan
diff
changeset
+ − 572
$just_terminated = true;
7152ca0a0ce9
Major redesign of rendering pipeline that separates pages saved with MCE from pages saved with the plaintext editor (full description in long commit message)
Dan
diff
changeset
+ − 573
break;
7152ca0a0ce9
Major redesign of rendering pipeline that separates pages saved with MCE from pages saved with the plaintext editor (full description in long commit message)
Dan
diff
changeset
+ − 574
case '<li>':
7152ca0a0ce9
Major redesign of rendering pipeline that separates pages saved with MCE from pages saved with the plaintext editor (full description in long commit message)
Dan
diff
changeset
+ − 575
if ( $stack_height < 1 )
7152ca0a0ce9
Major redesign of rendering pipeline that separates pages saved with MCE from pages saved with the plaintext editor (full description in long commit message)
Dan
diff
changeset
+ − 576
break;
7152ca0a0ce9
Major redesign of rendering pipeline that separates pages saved with MCE from pages saved with the plaintext editor (full description in long commit message)
Dan
diff
changeset
+ − 577
7152ca0a0ce9
Major redesign of rendering pipeline that separates pages saved with MCE from pages saved with the plaintext editor (full description in long commit message)
Dan
diff
changeset
+ − 578
$current_list .= "{$spaces}{$marker} ";
7152ca0a0ce9
Major redesign of rendering pipeline that separates pages saved with MCE from pages saved with the plaintext editor (full description in long commit message)
Dan
diff
changeset
+ − 579
break;
7152ca0a0ce9
Major redesign of rendering pipeline that separates pages saved with MCE from pages saved with the plaintext editor (full description in long commit message)
Dan
diff
changeset
+ − 580
case '</li>':
7152ca0a0ce9
Major redesign of rendering pipeline that separates pages saved with MCE from pages saved with the plaintext editor (full description in long commit message)
Dan
diff
changeset
+ − 581
if ( $stack_height < 1 )
7152ca0a0ce9
Major redesign of rendering pipeline that separates pages saved with MCE from pages saved with the plaintext editor (full description in long commit message)
Dan
diff
changeset
+ − 582
break;
7152ca0a0ce9
Major redesign of rendering pipeline that separates pages saved with MCE from pages saved with the plaintext editor (full description in long commit message)
Dan
diff
changeset
+ − 583
7152ca0a0ce9
Major redesign of rendering pipeline that separates pages saved with MCE from pages saved with the plaintext editor (full description in long commit message)
Dan
diff
changeset
+ − 584
if ( !$just_terminated )
7152ca0a0ce9
Major redesign of rendering pipeline that separates pages saved with MCE from pages saved with the plaintext editor (full description in long commit message)
Dan
diff
changeset
+ − 585
$current_list .= "\n";
7152ca0a0ce9
Major redesign of rendering pipeline that separates pages saved with MCE from pages saved with the plaintext editor (full description in long commit message)
Dan
diff
changeset
+ − 586
7152ca0a0ce9
Major redesign of rendering pipeline that separates pages saved with MCE from pages saved with the plaintext editor (full description in long commit message)
Dan
diff
changeset
+ − 587
$just_terminated = false;
7152ca0a0ce9
Major redesign of rendering pipeline that separates pages saved with MCE from pages saved with the plaintext editor (full description in long commit message)
Dan
diff
changeset
+ − 588
break;
7152ca0a0ce9
Major redesign of rendering pipeline that separates pages saved with MCE from pages saved with the plaintext editor (full description in long commit message)
Dan
diff
changeset
+ − 589
default:
7152ca0a0ce9
Major redesign of rendering pipeline that separates pages saved with MCE from pages saved with the plaintext editor (full description in long commit message)
Dan
diff
changeset
+ − 590
if ( $stack_height > 0 )
7152ca0a0ce9
Major redesign of rendering pipeline that separates pages saved with MCE from pages saved with the plaintext editor (full description in long commit message)
Dan
diff
changeset
+ − 591
{
7152ca0a0ce9
Major redesign of rendering pipeline that separates pages saved with MCE from pages saved with the plaintext editor (full description in long commit message)
Dan
diff
changeset
+ − 592
$current_list .= trim($tag);
7152ca0a0ce9
Major redesign of rendering pipeline that separates pages saved with MCE from pages saved with the plaintext editor (full description in long commit message)
Dan
diff
changeset
+ − 593
}
7152ca0a0ce9
Major redesign of rendering pipeline that separates pages saved with MCE from pages saved with the plaintext editor (full description in long commit message)
Dan
diff
changeset
+ − 594
break;
7152ca0a0ce9
Major redesign of rendering pipeline that separates pages saved with MCE from pages saved with the plaintext editor (full description in long commit message)
Dan
diff
changeset
+ − 595
}
7152ca0a0ce9
Major redesign of rendering pipeline that separates pages saved with MCE from pages saved with the plaintext editor (full description in long commit message)
Dan
diff
changeset
+ − 596
if ( $stack_height > 0 )
7152ca0a0ce9
Major redesign of rendering pipeline that separates pages saved with MCE from pages saved with the plaintext editor (full description in long commit message)
Dan
diff
changeset
+ − 597
{
7152ca0a0ce9
Major redesign of rendering pipeline that separates pages saved with MCE from pages saved with the plaintext editor (full description in long commit message)
Dan
diff
changeset
+ − 598
$old_current_list .= $tag;
7152ca0a0ce9
Major redesign of rendering pipeline that separates pages saved with MCE from pages saved with the plaintext editor (full description in long commit message)
Dan
diff
changeset
+ − 599
}
7152ca0a0ce9
Major redesign of rendering pipeline that separates pages saved with MCE from pages saved with the plaintext editor (full description in long commit message)
Dan
diff
changeset
+ − 600
}
7152ca0a0ce9
Major redesign of rendering pipeline that separates pages saved with MCE from pages saved with the plaintext editor (full description in long commit message)
Dan
diff
changeset
+ − 601
7152ca0a0ce9
Major redesign of rendering pipeline that separates pages saved with MCE from pages saved with the plaintext editor (full description in long commit message)
Dan
diff
changeset
+ − 602
return $text;
7152ca0a0ce9
Major redesign of rendering pipeline that separates pages saved with MCE from pages saved with the plaintext editor (full description in long commit message)
Dan
diff
changeset
+ − 603
}
7152ca0a0ce9
Major redesign of rendering pipeline that separates pages saved with MCE from pages saved with the plaintext editor (full description in long commit message)
Dan
diff
changeset
+ − 604
7152ca0a0ce9
Major redesign of rendering pipeline that separates pages saved with MCE from pages saved with the plaintext editor (full description in long commit message)
Dan
diff
changeset
+ − 605
public static function reverse_process_tables($text)
7152ca0a0ce9
Major redesign of rendering pipeline that separates pages saved with MCE from pages saved with the plaintext editor (full description in long commit message)
Dan
diff
changeset
+ − 606
{
7152ca0a0ce9
Major redesign of rendering pipeline that separates pages saved with MCE from pages saved with the plaintext editor (full description in long commit message)
Dan
diff
changeset
+ − 607
return $text;
7152ca0a0ce9
Major redesign of rendering pipeline that separates pages saved with MCE from pages saved with the plaintext editor (full description in long commit message)
Dan
diff
changeset
+ − 608
}
7152ca0a0ce9
Major redesign of rendering pipeline that separates pages saved with MCE from pages saved with the plaintext editor (full description in long commit message)
Dan
diff
changeset
+ − 609
7152ca0a0ce9
Major redesign of rendering pipeline that separates pages saved with MCE from pages saved with the plaintext editor (full description in long commit message)
Dan
diff
changeset
+ − 610
/**
91
+ − 611
* Parses internal links (wikilinks) in a block of text.
+ − 612
* @param string Text to process
592
+ − 613
* @param string Optional. If included will be used as a template instead of using the default syntax.
971
+ − 614
* @param bool If false, does not add wikilink-nonexistent or check for exsistence of pages. Can reduce DB queries; defualts to true.
1003
28e2f75d66fd
Class "currentpage" is now added to all internal links, including sidebar buttons, if the link points to the current page.
Dan
diff
changeset
+ − 615
* @param string Page ID. If specified, class="currentpage" will be added to links if they match the given page ID and namespace
28e2f75d66fd
Class "currentpage" is now added to all internal links, including sidebar buttons, if the link points to the current page.
Dan
diff
changeset
+ − 616
* @param string Namespace. If specified, class="currentpage" will be added to links if they match the given page ID and namespace
91
+ − 617
* @return string
+ − 618
*/
+ − 619
1003
28e2f75d66fd
Class "currentpage" is now added to all internal links, including sidebar buttons, if the link points to the current page.
Dan
diff
changeset
+ − 620
public static function parse_internal_links($text, $tplcode = false, $do_exist_check = true, $match_page_id = false, $match_namespace = false)
91
+ − 621
{
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
+ − 622
global $db, $session, $paths, $template, $plugins; // Common objects
91
+ − 623
592
+ − 624
if ( is_string($tplcode) )
+ − 625
{
+ − 626
$parser = $template->makeParserText($tplcode);
+ − 627
}
+ − 628
91
+ − 629
// stage 1 - links with alternate text
+ − 630
preg_match_all('/\[\[([^\[\]<>\{\}\|]+)\|(.+?)\]\]/', $text, $matches);
+ − 631
foreach ( $matches[0] as $i => $match )
+ − 632
{
+ − 633
list($page_id, $namespace) = RenderMan::strToPageID($matches[1][$i]);
715
+ − 634
if ( ($pos = strrpos($page_id, '#')) !== false )
+ − 635
{
+ − 636
$hash = substr($page_id, $pos);
+ − 637
$page_id = substr($page_id, 0, $pos);
+ − 638
}
+ − 639
else
+ − 640
{
+ − 641
$hash = '';
+ − 642
}
91
+ − 643
$pid_clean = $paths->nslist[$namespace] . sanitize_page_id($page_id);
+ − 644
715
+ − 645
$url = makeUrl($pid_clean, false, true) . $hash;
91
+ − 646
$inner_text = $matches[2][$i];
+ − 647
$quot = '"';
971
+ − 648
$exists = ( ($do_exist_check && isPage($pid_clean)) || !$do_exist_check ) ? '' : ' class="wikilink-nonexistent"';
91
+ − 649
1003
28e2f75d66fd
Class "currentpage" is now added to all internal links, including sidebar buttons, if the link points to the current page.
Dan
diff
changeset
+ − 650
if ( $match_page_id && $match_namespace && $pid_clean === $paths->get_pathskey($match_page_id, $match_namespace) )
28e2f75d66fd
Class "currentpage" is now added to all internal links, including sidebar buttons, if the link points to the current page.
Dan
diff
changeset
+ − 651
$exists .= ' class="currentpage"';
28e2f75d66fd
Class "currentpage" is now added to all internal links, including sidebar buttons, if the link points to the current page.
Dan
diff
changeset
+ − 652
592
+ − 653
if ( $tplcode )
+ − 654
{
+ − 655
$parser->assign_vars(array(
+ − 656
'HREF' => $url,
+ − 657
'FLAGS' => $exists,
+ − 658
'TEXT' => $inner_text
+ − 659
));
+ − 660
$link = $parser->run();
+ − 661
}
+ − 662
else
+ − 663
{
832
7152ca0a0ce9
Major redesign of rendering pipeline that separates pages saved with MCE from pages saved with the plaintext editor (full description in long commit message)
Dan
diff
changeset
+ − 664
$omatch = self::escape_parser_hint_attrib($match);
7152ca0a0ce9
Major redesign of rendering pipeline that separates pages saved with MCE from pages saved with the plaintext editor (full description in long commit message)
Dan
diff
changeset
+ − 665
$link = "<!--#internallink src=\"$omatch\" --><a href={$quot}{$url}{$quot}{$exists}>{$inner_text}</a><!--#/internallink-->";
592
+ − 666
}
91
+ − 667
+ − 668
$text = str_replace($match, $link, $text);
+ − 669
}
+ − 670
+ − 671
// stage 2 - links with no alternate text
+ − 672
preg_match_all('/\[\[([^\[\]<>\{\}\|]+)\]\]/', $text, $matches);
+ − 673
foreach ( $matches[0] as $i => $match )
+ − 674
{
+ − 675
list($page_id, $namespace) = RenderMan::strToPageID($matches[1][$i]);
+ − 676
$pid_clean = $paths->nslist[$namespace] . sanitize_page_id($page_id);
+ − 677
159
f7e83b6db3be
Fixed: RenderMan::parse_internal_links() problems with prepending Project: instead of Site_name: to project page alias-namespace links
Dan
diff
changeset
+ − 678
$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
+ − 679
$inner_text = ( isPage($pid_clean) ) ? htmlspecialchars(get_page_title($pid_clean)) : htmlspecialchars($matches[1][$i]);
91
+ − 680
$quot = '"';
971
+ − 681
$exists = ( ($do_exist_check && isPage($pid_clean)) || !$do_exist_check ) ? '' : ' class="wikilink-nonexistent"';
91
+ − 682
1003
28e2f75d66fd
Class "currentpage" is now added to all internal links, including sidebar buttons, if the link points to the current page.
Dan
diff
changeset
+ − 683
if ( $match_page_id && $match_namespace && $pid_clean === $paths->get_pathskey($match_page_id, $match_namespace) )
28e2f75d66fd
Class "currentpage" is now added to all internal links, including sidebar buttons, if the link points to the current page.
Dan
diff
changeset
+ − 684
$exists .= ' class="currentpage"';
28e2f75d66fd
Class "currentpage" is now added to all internal links, including sidebar buttons, if the link points to the current page.
Dan
diff
changeset
+ − 685
592
+ − 686
if ( $tplcode )
+ − 687
{
+ − 688
$parser->assign_vars(array(
+ − 689
'HREF' => $url,
+ − 690
'FLAGS' => $exists,
+ − 691
'TEXT' => $inner_text
+ − 692
));
+ − 693
$link = $parser->run();
+ − 694
}
+ − 695
else
+ − 696
{
832
7152ca0a0ce9
Major redesign of rendering pipeline that separates pages saved with MCE from pages saved with the plaintext editor (full description in long commit message)
Dan
diff
changeset
+ − 697
$omatch = self::escape_parser_hint_attrib($match);
7152ca0a0ce9
Major redesign of rendering pipeline that separates pages saved with MCE from pages saved with the plaintext editor (full description in long commit message)
Dan
diff
changeset
+ − 698
$link = "<!--#internallink src=\"$omatch\" --><a href={$quot}{$url}{$quot}{$exists}>{$inner_text}</a><!--#/internallink-->";
592
+ − 699
}
91
+ − 700
+ − 701
$text = str_replace($match, $link, $text);
+ − 702
}
+ − 703
+ − 704
return $text;
+ − 705
}
+ − 706
1
+ − 707
/**
+ − 708
* Parses a partial template tag in wikitext, and return an array with the parameters.
63
+ − 709
* @param string The portion of the template tag that contains the parameters.
+ − 710
* @example
1
+ − 711
* <code>
63
+ − 712
foo = lorem ipsum
+ − 713
bar = dolor sit amet
1
+ − 714
* </code>
+ − 715
* @return array Example:
+ − 716
* [foo] => lorem ipsum
+ − 717
* [bar] => dolor sit amet
+ − 718
*/
+ − 719
717
+ − 720
public static function parse_template_vars($input, $newlinemode = true)
1
+ − 721
{
717
+ − 722
$parms = array();
+ − 723
$input = trim($input);
+ − 724
if ( $newlinemode )
174
4c5c2b66a34d
SECURITY: remove debug message in session manager; implemented alternate MediaWiki syntax for template embedding; added Adobe Spry for "shake" effect on unsuccessful login
Dan
diff
changeset
+ − 725
{
717
+ − 726
$result = preg_match_all('/
+ − 727
(?:^|[\s]*)\|? # start of parameter - string start or series of spaces
+ − 728
[ ]*
+ − 729
(?:
+ − 730
([A-z0-9_]+) # variable name
+ − 731
[ ]* = [ ]* # assignment
+ − 732
)? # this is optional - if the parameter name is not given, a numerical index is assigned
+ − 733
(.+) # value
+ − 734
/x', trim($input), $matches);
174
4c5c2b66a34d
SECURITY: remove debug message in session manager; implemented alternate MediaWiki syntax for template embedding; added Adobe Spry for "shake" effect on unsuccessful login
Dan
diff
changeset
+ − 735
}
4c5c2b66a34d
SECURITY: remove debug message in session manager; implemented alternate MediaWiki syntax for template embedding; added Adobe Spry for "shake" effect on unsuccessful login
Dan
diff
changeset
+ − 736
else
4c5c2b66a34d
SECURITY: remove debug message in session manager; implemented alternate MediaWiki syntax for template embedding; added Adobe Spry for "shake" effect on unsuccessful login
Dan
diff
changeset
+ − 737
{
717
+ − 738
$result = preg_match_all('/
+ − 739
(?:^|[ ]*)\| # start of parameter - string start or series of spaces
+ − 740
[ ]*
+ − 741
(?:
+ − 742
([A-z0-9_]+) # variable name
+ − 743
[ ]* = [ ]* # assignment
+ − 744
)? # name section is optional - if the parameter name is not given, a numerical index is assigned
+ − 745
([^\|]+|.+?\n[ ]*\|) # value
+ − 746
/x', trim($input), $matches);
+ − 747
}
+ − 748
if ( $result )
1
+ − 749
{
717
+ − 750
$pi = 0;
+ − 751
for ( $i = 0; $i < count($matches[0]); $i++ )
1
+ − 752
{
717
+ − 753
$matches[1][$i] = trim($matches[1][$i]);
+ − 754
$parmname = !empty($matches[1][$i]) ? $matches[1][$i] : strval(++$pi);
+ − 755
$parms[ $parmname ] = $matches[2][$i];
1
+ − 756
}
+ − 757
}
+ − 758
return $parms;
+ − 759
}
+ − 760
+ − 761
/**
+ − 762
* Processes all template tags within a block of wikitext.
174
4c5c2b66a34d
SECURITY: remove debug message in session manager; implemented alternate MediaWiki syntax for template embedding; added Adobe Spry for "shake" effect on unsuccessful login
Dan
diff
changeset
+ − 763
* Updated in 1.0.2 to also parse template tags in the format of {{Foo |a = b |b = c |c = therefore, a}}
1
+ − 764
* @param string The text to process
+ − 765
* @return string Formatted text
+ − 766
* @example
+ − 767
* <code>
+ − 768
$text = '{{Template
717
+ − 769
| parm1 = Foo
+ − 770
| parm2 = Bar
1
+ − 771
}}';
174
4c5c2b66a34d
SECURITY: remove debug message in session manager; implemented alternate MediaWiki syntax for template embedding; added Adobe Spry for "shake" effect on unsuccessful login
Dan
diff
changeset
+ − 772
$text = RenderMan::include_templates($text);
1
+ − 773
* </code>
+ − 774
*/
+ − 775
371
dc6026376919
Improved compatibility with PostgreSQL and fixed a number of installer bugs; fixed missing "meta" category declaration in language files
Dan
diff
changeset
+ − 776
public static function include_templates($text)
1
+ − 777
{
+ − 778
global $db, $session, $paths, $template, $plugins; // Common objects
174
4c5c2b66a34d
SECURITY: remove debug message in session manager; implemented alternate MediaWiki syntax for template embedding; added Adobe Spry for "shake" effect on unsuccessful login
Dan
diff
changeset
+ − 779
// $template_regex = "/\{\{([^\]]+?)((\n([ ]*?)[A-z0-9]+([ ]*?)=([ ]*?)(.+?))*)\}\}/is";
717
+ − 780
// matches:
+ − 781
// 1 - template name
+ − 782
// 2 - parameter section
+ − 783
$template_regex = "/
+ − 784
\{\{ # opening
+ − 785
([^\n\t\a\r]+) # template name
+ − 786
((?:(?:[\s]+\|?)[ ]*(?:[A-z0-9_]+)[ ]*=[ ]*?(?:.+))*) # parameters
+ − 787
\}\} # closing
+ − 788
/isxU";
1
+ − 789
if ( $count = preg_match_all($template_regex, $text, $matches) )
+ − 790
{
174
4c5c2b66a34d
SECURITY: remove debug message in session manager; implemented alternate MediaWiki syntax for template embedding; added Adobe Spry for "shake" effect on unsuccessful login
Dan
diff
changeset
+ − 791
//die('<pre>' . print_r($matches, true) . '</pre>');
1
+ − 792
for ( $i = 0; $i < $count; $i++ )
+ − 793
{
63
+ − 794
$matches[1][$i] = sanitize_page_id($matches[1][$i]);
717
+ − 795
$newlinemode = ( substr($matches[2][$i], 0, 1) == "\n" );
1
+ − 796
$parmsection = trim($matches[2][$i]);
+ − 797
if ( !empty($parmsection) )
+ − 798
{
717
+ − 799
$parms = RenderMan::parse_template_vars($parmsection, $newlinemode);
174
4c5c2b66a34d
SECURITY: remove debug message in session manager; implemented alternate MediaWiki syntax for template embedding; added Adobe Spry for "shake" effect on unsuccessful login
Dan
diff
changeset
+ − 800
if ( !is_array($parms) )
4c5c2b66a34d
SECURITY: remove debug message in session manager; implemented alternate MediaWiki syntax for template embedding; added Adobe Spry for "shake" effect on unsuccessful login
Dan
diff
changeset
+ − 801
// Syntax error
4c5c2b66a34d
SECURITY: remove debug message in session manager; implemented alternate MediaWiki syntax for template embedding; added Adobe Spry for "shake" effect on unsuccessful login
Dan
diff
changeset
+ − 802
$parms = array();
1
+ − 803
}
+ − 804
else
+ − 805
{
+ − 806
$parms = Array();
+ − 807
}
+ − 808
if ( $tpl_code = RenderMan::fetch_template_text($matches[1][$i]) )
+ − 809
{
+ − 810
$parser = $template->makeParserText($tpl_code);
+ − 811
$parser->assign_vars($parms);
+ − 812
$text = str_replace($matches[0][$i], $parser->run(), $text);
+ − 813
}
+ − 814
}
+ − 815
}
+ − 816
return $text;
+ − 817
}
+ − 818
+ − 819
/**
+ − 820
* Preprocesses an HTML text string prior to being sent to MySQL.
+ − 821
* @param string $text
1027
+ − 822
* @param bool $strip_all_php - if true, strips all PHP regardless of user permissions. Else, strips PHP only if user level < USER_LEVEL_ADMIN. Defaults to true.
+ − 823
* @param bool $sqlescape - if true, sends text through $db->escape(). Otherwise returns unescaped text. Defaults to true.
+ − 824
* @param bool $reduceheadings - if true, finds HTML headings and replaces them with wikitext. Else, does not touch headings. Defaults to true.
1
+ − 825
*/
1027
+ − 826
public static function preprocess_text($text, $strip_all_php = true, $sqlescape = true, $reduceheadings = true)
1
+ − 827
{
+ − 828
global $db, $session, $paths, $template, $plugins; // Common objects
+ − 829
$random_id = md5( time() . mt_rand() );
+ − 830
407
+ − 831
$code = $plugins->setHook('render_sanitize_pre');
+ − 832
foreach ( $code as $cmd )
+ − 833
{
+ − 834
eval($cmd);
+ − 835
}
1
+ − 836
+ − 837
$can_do_php = ( $session->get_permissions('php_in_pages') && !$strip_all_php );
377
bb3e6c3bd4f4
Removed stray debugging info from ACL editor success notification; added ability for guests to set language on URI (?lang=eng); added html_in_pages ACL type and separated from php_in_pages so HTML can be embedded but not PHP; rewote portions of the path manager to better abstract URL input; added Zend Framework into list of BSD-licensed libraries; localized some remaining strings; got the migration script working, but just barely; fixed display bug in Special:Contributions; localized Main Page button in admin panel
Dan
diff
changeset
+ − 838
$can_do_html = $session->get_permissions('html_in_pages');
1
+ − 839
377
bb3e6c3bd4f4
Removed stray debugging info from ACL editor success notification; added ability for guests to set language on URI (?lang=eng); added html_in_pages ACL type and separated from php_in_pages so HTML can be embedded but not PHP; rewote portions of the path manager to better abstract URL input; added Zend Framework into list of BSD-licensed libraries; localized some remaining strings; got the migration script working, but just barely; fixed display bug in Special:Contributions; localized Main Page button in admin panel
Dan
diff
changeset
+ − 840
if ( $can_do_html && !$can_do_php )
bb3e6c3bd4f4
Removed stray debugging info from ACL editor success notification; added ability for guests to set language on URI (?lang=eng); added html_in_pages ACL type and separated from php_in_pages so HTML can be embedded but not PHP; rewote portions of the path manager to better abstract URL input; added Zend Framework into list of BSD-licensed libraries; localized some remaining strings; got the migration script working, but just barely; fixed display bug in Special:Contributions; localized Main Page button in admin panel
Dan
diff
changeset
+ − 841
{
bb3e6c3bd4f4
Removed stray debugging info from ACL editor success notification; added ability for guests to set language on URI (?lang=eng); added html_in_pages ACL type and separated from php_in_pages so HTML can be embedded but not PHP; rewote portions of the path manager to better abstract URL input; added Zend Framework into list of BSD-licensed libraries; localized some remaining strings; got the migration script working, but just barely; fixed display bug in Special:Contributions; localized Main Page button in admin panel
Dan
diff
changeset
+ − 842
$text = preg_replace('#<(\?|\?php|%)(.*?)(\?|%)>#is', '<\\1\\2\\3>', $text);
bb3e6c3bd4f4
Removed stray debugging info from ACL editor success notification; added ability for guests to set language on URI (?lang=eng); added html_in_pages ACL type and separated from php_in_pages so HTML can be embedded but not PHP; rewote portions of the path manager to better abstract URL input; added Zend Framework into list of BSD-licensed libraries; localized some remaining strings; got the migration script working, but just barely; fixed display bug in Special:Contributions; localized Main Page button in admin panel
Dan
diff
changeset
+ − 843
}
bb3e6c3bd4f4
Removed stray debugging info from ACL editor success notification; added ability for guests to set language on URI (?lang=eng); added html_in_pages ACL type and separated from php_in_pages so HTML can be embedded but not PHP; rewote portions of the path manager to better abstract URL input; added Zend Framework into list of BSD-licensed libraries; localized some remaining strings; got the migration script working, but just barely; fixed display bug in Special:Contributions; localized Main Page button in admin panel
Dan
diff
changeset
+ − 844
else if ( !$can_do_html && !$can_do_php )
1
+ − 845
{
24
+ − 846
$text = sanitize_html($text, true);
1
+ − 847
// If we can't do PHP, we can't do Javascript either.
+ − 848
$text = RenderMan::destroy_javascript($text);
+ − 849
}
+ − 850
+ − 851
// Strip out <nowiki> sections and PHP code
+ − 852
+ − 853
$php = preg_match_all('#(<|<)\?php(.*?)\?(>|>)#is', $text, $phpsec);
+ − 854
+ − 855
//die('<pre>'.htmlspecialchars(print_r($phpsec, true))."\n".htmlspecialchars(print_r($text, true)).'</pre>');
+ − 856
+ − 857
for($i=0;$i<sizeof($phpsec[1]);$i++)
+ − 858
{
+ − 859
$text = str_replace($phpsec[0][$i], '{PHP:'.$random_id.':'.$i.'}', $text);
+ − 860
}
+ − 861
+ − 862
$nw = preg_match_all('#<nowiki>(.*?)<\/nowiki>#is', $text, $nowiki);
+ − 863
+ − 864
for($i=0;$i<sizeof($nowiki[1]);$i++)
+ − 865
{
+ − 866
$text = str_replace('<nowiki>'.$nowiki[1][$i].'</nowiki>', '{NOWIKI:'.$random_id.':'.$i.'}', $text);
+ − 867
}
+ − 868
345
4ccdfeee9a11
WiP commit for admin panel localization. All modules up to Admin:UserManager (working down the list) are localized except Admin:ThemeManager, which is due for a rewrite
Dan
diff
changeset
+ − 869
$text = str_replace('~~~~~', enano_date('G:i, j F Y (T)'), $text);
4ccdfeee9a11
WiP commit for admin panel localization. All modules up to Admin:UserManager (working down the list) are localized except Admin:ThemeManager, which is due for a rewrite
Dan
diff
changeset
+ − 870
$text = str_replace('~~~~', "[[User:$session->username|$session->username]] ".enano_date('G:i, j F Y (T)'), $text);
1
+ − 871
$text = str_replace('~~~', "[[User:$session->username|$session->username]] ", $text);
+ − 872
407
+ − 873
$code = $plugins->setHook('render_sanitize_post');
+ − 874
foreach ( $code as $cmd )
+ − 875
{
+ − 876
eval($cmd);
+ − 877
}
+ − 878
1027
+ − 879
// gently apply some reverse-processing to allow the parser to do magic with TOCs and stuff
+ − 880
if ( $reduceheadings )
+ − 881
$text = self::reverse_process_headings($text);
832
7152ca0a0ce9
Major redesign of rendering pipeline that separates pages saved with MCE from pages saved with the plaintext editor (full description in long commit message)
Dan
diff
changeset
+ − 882
1
+ − 883
// Reinsert <nowiki> sections
+ − 884
for($i=0;$i<$nw;$i++)
+ − 885
{
+ − 886
$text = str_replace('{NOWIKI:'.$random_id.':'.$i.'}', '<nowiki>'.$nowiki[1][$i].'</nowiki>', $text);
+ − 887
}
+ − 888
// Reinsert PHP
+ − 889
for($i=0;$i<$php;$i++)
+ − 890
{
+ − 891
$phsec = ''.$phpsec[1][$i].'?php'.$phpsec[2][$i].'?'.$phpsec[3][$i].'';
+ − 892
if ( $strip_all_php )
+ − 893
$phsec = htmlspecialchars($phsec);
+ − 894
$text = str_replace('{PHP:'.$random_id.':'.$i.'}', $phsec, $text);
+ − 895
}
+ − 896
+ − 897
$text = ( $sqlescape ) ? $db->escape($text) : $text;
+ − 898
+ − 899
return $text;
+ − 900
}
+ − 901
371
dc6026376919
Improved compatibility with PostgreSQL and fixed a number of installer bugs; fixed missing "meta" category declaration in language files
Dan
diff
changeset
+ − 902
public static function smilieyize($text, $complete_urls = false)
1
+ − 903
{
+ − 904
+ − 905
$random_id = md5( time() . mt_rand() );
+ − 906
+ − 907
// Smileys array - eventually this will be fetched from the database by
+ − 908
// RenderMan::initSmileys during initialization, but it will all be hardcoded for beta 2
+ − 909
+ − 910
$smileys = Array(
+ − 911
'O:-)' => 'face-angel.png',
+ − 912
'O:)' => 'face-angel.png',
+ − 913
'O=)' => 'face-angel.png',
+ − 914
':-)' => 'face-smile.png',
+ − 915
':)' => 'face-smile.png',
+ − 916
'=)' => 'face-smile-big.png',
+ − 917
':-(' => 'face-sad.png',
+ − 918
':(' => 'face-sad.png',
+ − 919
';(' => 'face-sad.png',
+ − 920
':-O' => 'face-surprise.png',
+ − 921
';-)' => 'face-wink.png',
+ − 922
';)' => 'face-wink.png',
+ − 923
'8-)' => 'face-glasses.png',
+ − 924
'8)' => 'face-glasses.png',
+ − 925
':-D' => 'face-grin.png',
+ − 926
':D' => 'face-grin.png',
+ − 927
'=D' => 'face-grin.png',
+ − 928
':-*' => 'face-kiss.png',
+ − 929
':*' => 'face-kiss.png',
+ − 930
'=*' => 'face-kiss.png',
+ − 931
':\'(' => 'face-crying.png',
+ − 932
':-|' => 'face-plain.png',
+ − 933
':-\\' => 'face-plain.png',
+ − 934
':-/' => 'face-plain.png',
+ − 935
':joke:' => 'face-plain.png',
+ − 936
']:->' => 'face-devil-grin.png',
189
fd0e9c7a7b28
Automatic set of state on Oxygen sidebar portlets should work now; reimplemented parts of the template parser (again) to workaround some PHP/PCRE issues and add support for parser plugins
Dan
diff
changeset
+ − 937
']:->' => 'face-devil-grin.png',
1
+ − 938
':kiss:' => 'face-kiss.png',
+ − 939
':-P' => 'face-tongue-out.png',
+ − 940
':P' => 'face-tongue-out.png',
+ − 941
':-p' => 'face-tongue-out.png',
+ − 942
':p' => 'face-tongue-out.png',
+ − 943
':-X' => 'face-sick.png',
+ − 944
':X' => 'face-sick.png',
+ − 945
':sick:' => 'face-sick.png',
+ − 946
':-]' => 'face-oops.png',
+ − 947
':]' => 'face-oops.png',
+ − 948
':oops:' => 'face-oops.png',
+ − 949
':-[' => 'face-embarassed.png',
+ − 950
':[' => 'face-embarassed.png'
+ − 951
);
+ − 952
+ − 953
// Strip out <nowiki> sections
+ − 954
//return '<pre>'.htmlspecialchars($text).'</pre>';
+ − 955
$nw = preg_match_all('#<nowiki>(.*?)<\/nowiki>#is', $text, $nowiki);
+ − 956
832
7152ca0a0ce9
Major redesign of rendering pipeline that separates pages saved with MCE from pages saved with the plaintext editor (full description in long commit message)
Dan
diff
changeset
+ − 957
for ( $i = 0; $i < count($nowiki[1]); $i++ )
1
+ − 958
{
832
7152ca0a0ce9
Major redesign of rendering pipeline that separates pages saved with MCE from pages saved with the plaintext editor (full description in long commit message)
Dan
diff
changeset
+ − 959
$text = str_replace('<nowiki>' . $nowiki[1][$i] . '</nowiki>', '{NOWIKI:'.$random_id.':'.$i.'}', $text);
1
+ − 960
}
+ − 961
832
7152ca0a0ce9
Major redesign of rendering pipeline that separates pages saved with MCE from pages saved with the plaintext editor (full description in long commit message)
Dan
diff
changeset
+ − 962
foreach ( $smileys as $smiley => $smiley_path )
1
+ − 963
{
832
7152ca0a0ce9
Major redesign of rendering pipeline that separates pages saved with MCE from pages saved with the plaintext editor (full description in long commit message)
Dan
diff
changeset
+ − 964
$hex_smiley = hexencode($smiley, '&#x', ';');
7152ca0a0ce9
Major redesign of rendering pipeline that separates pages saved with MCE from pages saved with the plaintext editor (full description in long commit message)
Dan
diff
changeset
+ − 965
$pfx = ( $complete_urls ) ? get_server_url() : '';
7152ca0a0ce9
Major redesign of rendering pipeline that separates pages saved with MCE from pages saved with the plaintext editor (full description in long commit message)
Dan
diff
changeset
+ − 966
$text = str_replace(' ' . $smiley,
7152ca0a0ce9
Major redesign of rendering pipeline that separates pages saved with MCE from pages saved with the plaintext editor (full description in long commit message)
Dan
diff
changeset
+ − 967
' <!--#smiley code="' . self::escape_parser_hint_attrib($smiley) . '"--><nowiki>
7152ca0a0ce9
Major redesign of rendering pipeline that separates pages saved with MCE from pages saved with the plaintext editor (full description in long commit message)
Dan
diff
changeset
+ − 968
<!-- The above is a reverse-parser hint -->
7152ca0a0ce9
Major redesign of rendering pipeline that separates pages saved with MCE from pages saved with the plaintext editor (full description in long commit message)
Dan
diff
changeset
+ − 969
<img title="' . $hex_smiley . '" alt="' . $hex_smiley . '" src="' . $pfx . scriptPath . '/images/smilies/' . $smiley_path . '"
7152ca0a0ce9
Major redesign of rendering pipeline that separates pages saved with MCE from pages saved with the plaintext editor (full description in long commit message)
Dan
diff
changeset
+ − 970
style="border: 0;" />
7152ca0a0ce9
Major redesign of rendering pipeline that separates pages saved with MCE from pages saved with the plaintext editor (full description in long commit message)
Dan
diff
changeset
+ − 971
</nowiki><!--#/smiley-->', $text);
1
+ − 972
}
+ − 973
//*/
+ − 974
+ − 975
// Reinsert <nowiki> sections
832
7152ca0a0ce9
Major redesign of rendering pipeline that separates pages saved with MCE from pages saved with the plaintext editor (full description in long commit message)
Dan
diff
changeset
+ − 976
for ( $i = 0; $i < $nw; $i++ )
1
+ − 977
{
+ − 978
$text = str_replace('{NOWIKI:'.$random_id.':'.$i.'}', '<nowiki>'.$nowiki[1][$i].'</nowiki>', $text);
+ − 979
}
+ − 980
+ − 981
return $text;
+ − 982
}
+ − 983
+ − 984
/**
+ − 985
* Generates a summary of the differences between two texts, and formats it as XHTML.
+ − 986
* @param $str1 string the first block of text
+ − 987
* @param $str2 string the second block of text
+ − 988
* @return string
+ − 989
*/
371
dc6026376919
Improved compatibility with PostgreSQL and fixed a number of installer bugs; fixed missing "meta" category declaration in language files
Dan
diff
changeset
+ − 990
public static function diff($str1, $str2)
1
+ − 991
{
+ − 992
global $db, $session, $paths, $template, $plugins; // Common objects
592
+ − 993
require_once(ENANO_ROOT.'/includes/diff.php');
1
+ − 994
$str1 = explode("\n", $str1);
+ − 995
$str2 = explode("\n", $str2);
+ − 996
$diff = new Diff($str1, $str2);
+ − 997
$renderer = new TableDiffFormatter();
+ − 998
return '<table class="diff">'.$renderer->format($diff).'</table>';
+ − 999
}
+ − 1000
35
+ − 1001
/**
+ − 1002
* Changes wikitext image tags to HTML.
+ − 1003
* @param string The wikitext to process
37
+ − 1004
* @param array Will be overwritten with the list of HTML tags (the system uses tokens for TextWiki compatibility)
35
+ − 1005
* @return string
+ − 1006
*/
+ − 1007
371
dc6026376919
Improved compatibility with PostgreSQL and fixed a number of installer bugs; fixed missing "meta" category declaration in language files
Dan
diff
changeset
+ − 1008
public static function process_image_tags($text, &$taglist)
35
+ − 1009
{
+ − 1010
global $db, $session, $paths, $template, $plugins; // Common objects
+ − 1011
37
+ − 1012
$s_delim = "\xFF";
+ − 1013
$f_delim = "\xFF";
+ − 1014
$taglist = array();
+ − 1015
35
+ − 1016
// Wicked huh?
569
6ba792bc9071
Updated image tag parser a bit. Handles recursion of brackets properly now, allows custom parameters from plugins, and takes parameters in any order due to new keyword-based parser
Dan
diff
changeset
+ − 1017
$ns_file = str_replace('/', '\\/', preg_quote($paths->nslist['File']));
6ba792bc9071
Updated image tag parser a bit. Handles recursion of brackets properly now, allows custom parameters from plugins, and takes parameters in any order due to new keyword-based parser
Dan
diff
changeset
+ − 1018
$regex = '/
6ba792bc9071
Updated image tag parser a bit. Handles recursion of brackets properly now, allows custom parameters from plugins, and takes parameters in any order due to new keyword-based parser
Dan
diff
changeset
+ − 1019
\[\[ # starting delimiter
6ba792bc9071
Updated image tag parser a bit. Handles recursion of brackets properly now, allows custom parameters from plugins, and takes parameters in any order due to new keyword-based parser
Dan
diff
changeset
+ − 1020
:' . $ns_file . '([\w\s0-9_\(\)!@%\^\+\|\.-]+?\.(?:png|gif|jpg|jpeg)) # image filename
6ba792bc9071
Updated image tag parser a bit. Handles recursion of brackets properly now, allows custom parameters from plugins, and takes parameters in any order due to new keyword-based parser
Dan
diff
changeset
+ − 1021
(?:(?:\|(?:.+?))*) # parameters
6ba792bc9071
Updated image tag parser a bit. Handles recursion of brackets properly now, allows custom parameters from plugins, and takes parameters in any order due to new keyword-based parser
Dan
diff
changeset
+ − 1022
\]\] # ending delimiter
6ba792bc9071
Updated image tag parser a bit. Handles recursion of brackets properly now, allows custom parameters from plugins, and takes parameters in any order due to new keyword-based parser
Dan
diff
changeset
+ − 1023
/ix';
35
+ − 1024
+ − 1025
preg_match_all($regex, $text, $matches);
+ − 1026
+ − 1027
foreach ( $matches[0] as $i => $match )
+ − 1028
{
+ − 1029
+ − 1030
$full_tag =& $matches[0][$i];
+ − 1031
$filename =& $matches[1][$i];
569
6ba792bc9071
Updated image tag parser a bit. Handles recursion of brackets properly now, allows custom parameters from plugins, and takes parameters in any order due to new keyword-based parser
Dan
diff
changeset
+ − 1032
6ba792bc9071
Updated image tag parser a bit. Handles recursion of brackets properly now, allows custom parameters from plugins, and takes parameters in any order due to new keyword-based parser
Dan
diff
changeset
+ − 1033
// apply recursion (hack? @todo could this be done with (?R) in PCRE?)
6ba792bc9071
Updated image tag parser a bit. Handles recursion of brackets properly now, allows custom parameters from plugins, and takes parameters in any order due to new keyword-based parser
Dan
diff
changeset
+ − 1034
$tag_pos = strpos($text, $full_tag);
6ba792bc9071
Updated image tag parser a bit. Handles recursion of brackets properly now, allows custom parameters from plugins, and takes parameters in any order due to new keyword-based parser
Dan
diff
changeset
+ − 1035
$tag_end_pos = $tag_pos + strlen($full_tag);
6ba792bc9071
Updated image tag parser a bit. Handles recursion of brackets properly now, allows custom parameters from plugins, and takes parameters in any order due to new keyword-based parser
Dan
diff
changeset
+ − 1036
while ( get_char_count($full_tag, ']') < get_char_count($full_tag, '[') && $tag_end_pos < strlen($text) )
6ba792bc9071
Updated image tag parser a bit. Handles recursion of brackets properly now, allows custom parameters from plugins, and takes parameters in any order due to new keyword-based parser
Dan
diff
changeset
+ − 1037
{
6ba792bc9071
Updated image tag parser a bit. Handles recursion of brackets properly now, allows custom parameters from plugins, and takes parameters in any order due to new keyword-based parser
Dan
diff
changeset
+ − 1038
$full_tag .= substr($text, $tag_end_pos, 1);
6ba792bc9071
Updated image tag parser a bit. Handles recursion of brackets properly now, allows custom parameters from plugins, and takes parameters in any order due to new keyword-based parser
Dan
diff
changeset
+ − 1039
$tag_end_pos++;
6ba792bc9071
Updated image tag parser a bit. Handles recursion of brackets properly now, allows custom parameters from plugins, and takes parameters in any order due to new keyword-based parser
Dan
diff
changeset
+ − 1040
}
6ba792bc9071
Updated image tag parser a bit. Handles recursion of brackets properly now, allows custom parameters from plugins, and takes parameters in any order due to new keyword-based parser
Dan
diff
changeset
+ − 1041
if ( $tag_end_pos > strlen($text) )
6ba792bc9071
Updated image tag parser a bit. Handles recursion of brackets properly now, allows custom parameters from plugins, and takes parameters in any order due to new keyword-based parser
Dan
diff
changeset
+ − 1042
{
6ba792bc9071
Updated image tag parser a bit. Handles recursion of brackets properly now, allows custom parameters from plugins, and takes parameters in any order due to new keyword-based parser
Dan
diff
changeset
+ − 1043
// discard tag, not closed fully
6ba792bc9071
Updated image tag parser a bit. Handles recursion of brackets properly now, allows custom parameters from plugins, and takes parameters in any order due to new keyword-based parser
Dan
diff
changeset
+ − 1044
continue;
6ba792bc9071
Updated image tag parser a bit. Handles recursion of brackets properly now, allows custom parameters from plugins, and takes parameters in any order due to new keyword-based parser
Dan
diff
changeset
+ − 1045
}
6ba792bc9071
Updated image tag parser a bit. Handles recursion of brackets properly now, allows custom parameters from plugins, and takes parameters in any order due to new keyword-based parser
Dan
diff
changeset
+ − 1046
6ba792bc9071
Updated image tag parser a bit. Handles recursion of brackets properly now, allows custom parameters from plugins, and takes parameters in any order due to new keyword-based parser
Dan
diff
changeset
+ − 1047
// init the various image parameters
6ba792bc9071
Updated image tag parser a bit. Handles recursion of brackets properly now, allows custom parameters from plugins, and takes parameters in any order due to new keyword-based parser
Dan
diff
changeset
+ − 1048
$width = null;
6ba792bc9071
Updated image tag parser a bit. Handles recursion of brackets properly now, allows custom parameters from plugins, and takes parameters in any order due to new keyword-based parser
Dan
diff
changeset
+ − 1049
$height = null;
6ba792bc9071
Updated image tag parser a bit. Handles recursion of brackets properly now, allows custom parameters from plugins, and takes parameters in any order due to new keyword-based parser
Dan
diff
changeset
+ − 1050
$scale_type = null;
6ba792bc9071
Updated image tag parser a bit. Handles recursion of brackets properly now, allows custom parameters from plugins, and takes parameters in any order due to new keyword-based parser
Dan
diff
changeset
+ − 1051
$raw_display = false;
6ba792bc9071
Updated image tag parser a bit. Handles recursion of brackets properly now, allows custom parameters from plugins, and takes parameters in any order due to new keyword-based parser
Dan
diff
changeset
+ − 1052
$clear = null;
6ba792bc9071
Updated image tag parser a bit. Handles recursion of brackets properly now, allows custom parameters from plugins, and takes parameters in any order due to new keyword-based parser
Dan
diff
changeset
+ − 1053
$caption = null;
6ba792bc9071
Updated image tag parser a bit. Handles recursion of brackets properly now, allows custom parameters from plugins, and takes parameters in any order due to new keyword-based parser
Dan
diff
changeset
+ − 1054
6ba792bc9071
Updated image tag parser a bit. Handles recursion of brackets properly now, allows custom parameters from plugins, and takes parameters in any order due to new keyword-based parser
Dan
diff
changeset
+ − 1055
// trim tag and parse particles
6ba792bc9071
Updated image tag parser a bit. Handles recursion of brackets properly now, allows custom parameters from plugins, and takes parameters in any order due to new keyword-based parser
Dan
diff
changeset
+ − 1056
$tag_trim = rtrim(ltrim($full_tag, '['), ']');
6ba792bc9071
Updated image tag parser a bit. Handles recursion of brackets properly now, allows custom parameters from plugins, and takes parameters in any order due to new keyword-based parser
Dan
diff
changeset
+ − 1057
// trim off the filename from the start of the tag
6ba792bc9071
Updated image tag parser a bit. Handles recursion of brackets properly now, allows custom parameters from plugins, and takes parameters in any order due to new keyword-based parser
Dan
diff
changeset
+ − 1058
$filepart_len = 1 + strlen($paths->nslist['File']) + strlen($filename) + 1;
6ba792bc9071
Updated image tag parser a bit. Handles recursion of brackets properly now, allows custom parameters from plugins, and takes parameters in any order due to new keyword-based parser
Dan
diff
changeset
+ − 1059
$tag_trim = substr($tag_trim, $filepart_len);
6ba792bc9071
Updated image tag parser a bit. Handles recursion of brackets properly now, allows custom parameters from plugins, and takes parameters in any order due to new keyword-based parser
Dan
diff
changeset
+ − 1060
// explode and we should have parameters
6ba792bc9071
Updated image tag parser a bit. Handles recursion of brackets properly now, allows custom parameters from plugins, and takes parameters in any order due to new keyword-based parser
Dan
diff
changeset
+ − 1061
$tag_parts = explode('|', $tag_trim);
6ba792bc9071
Updated image tag parser a bit. Handles recursion of brackets properly now, allows custom parameters from plugins, and takes parameters in any order due to new keyword-based parser
Dan
diff
changeset
+ − 1062
6ba792bc9071
Updated image tag parser a bit. Handles recursion of brackets properly now, allows custom parameters from plugins, and takes parameters in any order due to new keyword-based parser
Dan
diff
changeset
+ − 1063
// for each of the parameters, see if it matches a known option. If so, apply it;
6ba792bc9071
Updated image tag parser a bit. Handles recursion of brackets properly now, allows custom parameters from plugins, and takes parameters in any order due to new keyword-based parser
Dan
diff
changeset
+ − 1064
// otherwise, see if a plugin reserved that parameter and if not treat it as the caption
6ba792bc9071
Updated image tag parser a bit. Handles recursion of brackets properly now, allows custom parameters from plugins, and takes parameters in any order due to new keyword-based parser
Dan
diff
changeset
+ − 1065
foreach ( $tag_parts as $param )
6ba792bc9071
Updated image tag parser a bit. Handles recursion of brackets properly now, allows custom parameters from plugins, and takes parameters in any order due to new keyword-based parser
Dan
diff
changeset
+ − 1066
{
6ba792bc9071
Updated image tag parser a bit. Handles recursion of brackets properly now, allows custom parameters from plugins, and takes parameters in any order due to new keyword-based parser
Dan
diff
changeset
+ − 1067
switch($param)
6ba792bc9071
Updated image tag parser a bit. Handles recursion of brackets properly now, allows custom parameters from plugins, and takes parameters in any order due to new keyword-based parser
Dan
diff
changeset
+ − 1068
{
6ba792bc9071
Updated image tag parser a bit. Handles recursion of brackets properly now, allows custom parameters from plugins, and takes parameters in any order due to new keyword-based parser
Dan
diff
changeset
+ − 1069
case 'left':
6ba792bc9071
Updated image tag parser a bit. Handles recursion of brackets properly now, allows custom parameters from plugins, and takes parameters in any order due to new keyword-based parser
Dan
diff
changeset
+ − 1070
case 'right':
6ba792bc9071
Updated image tag parser a bit. Handles recursion of brackets properly now, allows custom parameters from plugins, and takes parameters in any order due to new keyword-based parser
Dan
diff
changeset
+ − 1071
$clear = $param;
6ba792bc9071
Updated image tag parser a bit. Handles recursion of brackets properly now, allows custom parameters from plugins, and takes parameters in any order due to new keyword-based parser
Dan
diff
changeset
+ − 1072
break;
6ba792bc9071
Updated image tag parser a bit. Handles recursion of brackets properly now, allows custom parameters from plugins, and takes parameters in any order due to new keyword-based parser
Dan
diff
changeset
+ − 1073
case 'thumb':
6ba792bc9071
Updated image tag parser a bit. Handles recursion of brackets properly now, allows custom parameters from plugins, and takes parameters in any order due to new keyword-based parser
Dan
diff
changeset
+ − 1074
$scale_type = 'thumb';
6ba792bc9071
Updated image tag parser a bit. Handles recursion of brackets properly now, allows custom parameters from plugins, and takes parameters in any order due to new keyword-based parser
Dan
diff
changeset
+ − 1075
break;
6ba792bc9071
Updated image tag parser a bit. Handles recursion of brackets properly now, allows custom parameters from plugins, and takes parameters in any order due to new keyword-based parser
Dan
diff
changeset
+ − 1076
case 'raw':
6ba792bc9071
Updated image tag parser a bit. Handles recursion of brackets properly now, allows custom parameters from plugins, and takes parameters in any order due to new keyword-based parser
Dan
diff
changeset
+ − 1077
$raw_display = true;
6ba792bc9071
Updated image tag parser a bit. Handles recursion of brackets properly now, allows custom parameters from plugins, and takes parameters in any order due to new keyword-based parser
Dan
diff
changeset
+ − 1078
break;
6ba792bc9071
Updated image tag parser a bit. Handles recursion of brackets properly now, allows custom parameters from plugins, and takes parameters in any order due to new keyword-based parser
Dan
diff
changeset
+ − 1079
default:
6ba792bc9071
Updated image tag parser a bit. Handles recursion of brackets properly now, allows custom parameters from plugins, and takes parameters in any order due to new keyword-based parser
Dan
diff
changeset
+ − 1080
// height specification
6ba792bc9071
Updated image tag parser a bit. Handles recursion of brackets properly now, allows custom parameters from plugins, and takes parameters in any order due to new keyword-based parser
Dan
diff
changeset
+ − 1081
if ( preg_match('/^([0-9]+)x([0-9]+)$/', $param, $dims) )
6ba792bc9071
Updated image tag parser a bit. Handles recursion of brackets properly now, allows custom parameters from plugins, and takes parameters in any order due to new keyword-based parser
Dan
diff
changeset
+ − 1082
{
6ba792bc9071
Updated image tag parser a bit. Handles recursion of brackets properly now, allows custom parameters from plugins, and takes parameters in any order due to new keyword-based parser
Dan
diff
changeset
+ − 1083
$width = intval($dims[1]);
6ba792bc9071
Updated image tag parser a bit. Handles recursion of brackets properly now, allows custom parameters from plugins, and takes parameters in any order due to new keyword-based parser
Dan
diff
changeset
+ − 1084
$height = intval($dims[2]);
6ba792bc9071
Updated image tag parser a bit. Handles recursion of brackets properly now, allows custom parameters from plugins, and takes parameters in any order due to new keyword-based parser
Dan
diff
changeset
+ − 1085
break;
6ba792bc9071
Updated image tag parser a bit. Handles recursion of brackets properly now, allows custom parameters from plugins, and takes parameters in any order due to new keyword-based parser
Dan
diff
changeset
+ − 1086
}
6ba792bc9071
Updated image tag parser a bit. Handles recursion of brackets properly now, allows custom parameters from plugins, and takes parameters in any order due to new keyword-based parser
Dan
diff
changeset
+ − 1087
// not the height, so see if a plugin took this over
832
7152ca0a0ce9
Major redesign of rendering pipeline that separates pages saved with MCE from pages saved with the plaintext editor (full description in long commit message)
Dan
diff
changeset
+ − 1088
// this hook requires plugins to return true if they modified anything
569
6ba792bc9071
Updated image tag parser a bit. Handles recursion of brackets properly now, allows custom parameters from plugins, and takes parameters in any order due to new keyword-based parser
Dan
diff
changeset
+ − 1089
$code = $plugins->setHook('img_tag_parse_params');
6ba792bc9071
Updated image tag parser a bit. Handles recursion of brackets properly now, allows custom parameters from plugins, and takes parameters in any order due to new keyword-based parser
Dan
diff
changeset
+ − 1090
foreach ( $code as $cmd )
6ba792bc9071
Updated image tag parser a bit. Handles recursion of brackets properly now, allows custom parameters from plugins, and takes parameters in any order due to new keyword-based parser
Dan
diff
changeset
+ − 1091
{
6ba792bc9071
Updated image tag parser a bit. Handles recursion of brackets properly now, allows custom parameters from plugins, and takes parameters in any order due to new keyword-based parser
Dan
diff
changeset
+ − 1092
if ( eval($cmd) )
6ba792bc9071
Updated image tag parser a bit. Handles recursion of brackets properly now, allows custom parameters from plugins, and takes parameters in any order due to new keyword-based parser
Dan
diff
changeset
+ − 1093
break 2;
6ba792bc9071
Updated image tag parser a bit. Handles recursion of brackets properly now, allows custom parameters from plugins, and takes parameters in any order due to new keyword-based parser
Dan
diff
changeset
+ − 1094
}
6ba792bc9071
Updated image tag parser a bit. Handles recursion of brackets properly now, allows custom parameters from plugins, and takes parameters in any order due to new keyword-based parser
Dan
diff
changeset
+ − 1095
// we would have broken out by now if a plugin properly handled this,
6ba792bc9071
Updated image tag parser a bit. Handles recursion of brackets properly now, allows custom parameters from plugins, and takes parameters in any order due to new keyword-based parser
Dan
diff
changeset
+ − 1096
// so just set the caption now.
6ba792bc9071
Updated image tag parser a bit. Handles recursion of brackets properly now, allows custom parameters from plugins, and takes parameters in any order due to new keyword-based parser
Dan
diff
changeset
+ − 1097
$caption = $param;
6ba792bc9071
Updated image tag parser a bit. Handles recursion of brackets properly now, allows custom parameters from plugins, and takes parameters in any order due to new keyword-based parser
Dan
diff
changeset
+ − 1098
break;
6ba792bc9071
Updated image tag parser a bit. Handles recursion of brackets properly now, allows custom parameters from plugins, and takes parameters in any order due to new keyword-based parser
Dan
diff
changeset
+ − 1099
}
6ba792bc9071
Updated image tag parser a bit. Handles recursion of brackets properly now, allows custom parameters from plugins, and takes parameters in any order due to new keyword-based parser
Dan
diff
changeset
+ − 1100
}
35
+ − 1101
+ − 1102
if ( !isPage( $paths->nslist['File'] . $filename ) )
+ − 1103
{
832
7152ca0a0ce9
Major redesign of rendering pipeline that separates pages saved with MCE from pages saved with the plaintext editor (full description in long commit message)
Dan
diff
changeset
+ − 1104
$text = str_replace($full_tag, '[[' . $paths->nslist['File'] . $filename . ']]', $text);
35
+ − 1105
continue;
+ − 1106
}
+ − 1107
569
6ba792bc9071
Updated image tag parser a bit. Handles recursion of brackets properly now, allows custom parameters from plugins, and takes parameters in any order due to new keyword-based parser
Dan
diff
changeset
+ − 1108
if ( $scale_type == 'thumb' )
35
+ − 1109
{
+ − 1110
$r_width = 225;
+ − 1111
$r_height = 225;
+ − 1112
+ − 1113
$url = makeUrlNS('Special', 'DownloadFile/' . $filename, 'preview&width=' . $r_width . '&height=' . $r_height, true);
+ − 1114
}
+ − 1115
else if ( !empty($width) && !empty($height) )
+ − 1116
{
+ − 1117
$r_width = $width;
+ − 1118
$r_height = $height;
+ − 1119
+ − 1120
$url = makeUrlNS('Special', 'DownloadFile/' . $filename, 'preview&width=' . $r_width . '&height=' . $r_height, true);
+ − 1121
}
+ − 1122
else
+ − 1123
{
+ − 1124
$url = makeUrlNS('Special', 'DownloadFile/' . $filename);
+ − 1125
}
+ − 1126
+ − 1127
$img_tag = '<img src="' . $url . '" ';
+ − 1128
65
+ − 1129
// if ( isset($r_width) && isset($r_height) && $scale_type != '|thumb' )
+ − 1130
// {
66
+ − 1131
// $img_tag .= 'width="' . $r_width . '" height="' . $r_height . '" ';
65
+ − 1132
// }
35
+ − 1133
66
+ − 1134
$img_tag .= 'style="border-width: 0px; /* background-color: white; */" ';
35
+ − 1135
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
+ − 1136
$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
+ − 1137
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
+ − 1138
{
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
+ − 1139
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
+ − 1140
}
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
+ − 1141
35
+ − 1142
$img_tag .= '/>';
+ − 1143
832
7152ca0a0ce9
Major redesign of rendering pipeline that separates pages saved with MCE from pages saved with the plaintext editor (full description in long commit message)
Dan
diff
changeset
+ − 1144
$s_full_tag = self::escape_parser_hint_attrib($full_tag);
7152ca0a0ce9
Major redesign of rendering pipeline that separates pages saved with MCE from pages saved with the plaintext editor (full description in long commit message)
Dan
diff
changeset
+ − 1145
$complete_tag = '<!--#imagelink src="' . $s_full_tag . '" -->';
35
+ − 1146
569
6ba792bc9071
Updated image tag parser a bit. Handles recursion of brackets properly now, allows custom parameters from plugins, and takes parameters in any order due to new keyword-based parser
Dan
diff
changeset
+ − 1147
if ( !empty($scale_type) && !$raw_display )
35
+ − 1148
{
+ − 1149
$complete_tag .= '<div class="thumbnail" ';
+ − 1150
$clear_text = '';
+ − 1151
if ( !empty($clear) )
+ − 1152
{
569
6ba792bc9071
Updated image tag parser a bit. Handles recursion of brackets properly now, allows custom parameters from plugins, and takes parameters in any order due to new keyword-based parser
Dan
diff
changeset
+ − 1153
$side = ( $clear == 'left' ) ? 'left' : 'right';
6ba792bc9071
Updated image tag parser a bit. Handles recursion of brackets properly now, allows custom parameters from plugins, and takes parameters in any order due to new keyword-based parser
Dan
diff
changeset
+ − 1154
$opposite = ( $clear == 'left' ) ? 'right' : 'left';
320
112debff64bd
SURPRISE! Preliminary PostgreSQL support added. The required schema file is not present in this commit and will be included at a later date. No installer support is implemented. Also in this commit: several fixes including <!-- SYSMSG ... --> was broken in template compiler; set fixed width on included images to prevent the thumbnail box from getting huge; added a much more friendly interface to AJAX responses that are invalid JSON
Dan
diff
changeset
+ − 1155
$clear_text .= "float: $side; margin-$opposite: 20px; width: {$r_width}px;";
35
+ − 1156
$complete_tag .= 'style="' . $clear_text . '" ';
+ − 1157
}
+ − 1158
$complete_tag .= '>';
+ − 1159
+ − 1160
$complete_tag .= '<a href="' . makeUrlNS('File', $filename) . '" style="display: block;">';
+ − 1161
$complete_tag .= $img_tag;
+ − 1162
$complete_tag .= '</a>';
+ − 1163
+ − 1164
$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>';
+ − 1165
+ − 1166
if ( !empty($caption) )
+ − 1167
{
569
6ba792bc9071
Updated image tag parser a bit. Handles recursion of brackets properly now, allows custom parameters from plugins, and takes parameters in any order due to new keyword-based parser
Dan
diff
changeset
+ − 1168
$complete_tag .= $mag_button . $caption;
35
+ − 1169
}
+ − 1170
+ − 1171
$complete_tag .= '</div>';
+ − 1172
}
569
6ba792bc9071
Updated image tag parser a bit. Handles recursion of brackets properly now, allows custom parameters from plugins, and takes parameters in any order due to new keyword-based parser
Dan
diff
changeset
+ − 1173
else if ( $raw_display )
66
+ − 1174
{
67
+ − 1175
$complete_tag .= "$img_tag";
+ − 1176
$taglist[$i] = $complete_tag;
+ − 1177
+ − 1178
$repl = "{$s_delim}e_img_{$i}{$f_delim}";
+ − 1179
$text = str_replace($full_tag, $repl, $text);
+ − 1180
continue;
66
+ − 1181
}
35
+ − 1182
else
+ − 1183
{
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
+ − 1184
$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
+ − 1185
$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
+ − 1186
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
+ − 1187
{
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
+ − 1188
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
+ − 1189
}
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
+ − 1190
$complete_tag .= '>';
35
+ − 1191
$complete_tag .= $img_tag;
+ − 1192
$complete_tag .= '</a>';
+ − 1193
}
+ − 1194
832
7152ca0a0ce9
Major redesign of rendering pipeline that separates pages saved with MCE from pages saved with the plaintext editor (full description in long commit message)
Dan
diff
changeset
+ − 1195
$complete_tag .= "<!--#/imagelink-->";
37
+ − 1196
$taglist[$i] = $complete_tag;
35
+ − 1197
832
7152ca0a0ce9
Major redesign of rendering pipeline that separates pages saved with MCE from pages saved with the plaintext editor (full description in long commit message)
Dan
diff
changeset
+ − 1198
/*
37
+ − 1199
$pos = strpos($text, $full_tag);
35
+ − 1200
+ − 1201
while(true)
+ − 1202
{
+ − 1203
$check1 = substr($text, $pos, 3);
+ − 1204
$check2 = substr($text, $pos, 1);
+ − 1205
if ( $check1 == '<p>' || $pos == 0 || $check2 == "\n" )
+ − 1206
{
+ − 1207
// die('found at pos '.$pos);
+ − 1208
break;
+ − 1209
}
+ − 1210
$pos--;
+ − 1211
}
569
6ba792bc9071
Updated image tag parser a bit. Handles recursion of brackets properly now, allows custom parameters from plugins, and takes parameters in any order due to new keyword-based parser
Dan
diff
changeset
+ − 1212
*/
35
+ − 1213
569
6ba792bc9071
Updated image tag parser a bit. Handles recursion of brackets properly now, allows custom parameters from plugins, and takes parameters in any order due to new keyword-based parser
Dan
diff
changeset
+ − 1214
/*
37
+ − 1215
$repl = "{$s_delim}e_img_{$i}{$f_delim}";
+ − 1216
$text = substr($text, 0, $pos) . $repl . substr($text, $pos);
35
+ − 1217
+ − 1218
$text = str_replace($full_tag, '', $text);
569
6ba792bc9071
Updated image tag parser a bit. Handles recursion of brackets properly now, allows custom parameters from plugins, and takes parameters in any order due to new keyword-based parser
Dan
diff
changeset
+ − 1219
*/
6ba792bc9071
Updated image tag parser a bit. Handles recursion of brackets properly now, allows custom parameters from plugins, and takes parameters in any order due to new keyword-based parser
Dan
diff
changeset
+ − 1220
$text = str_replace_once($full_tag, $complete_tag, $text);
35
+ − 1221
+ − 1222
unset($full_tag, $filename, $scale_type, $width, $height, $clear, $caption, $r_width, $r_height);
+ − 1223
+ − 1224
}
+ − 1225
569
6ba792bc9071
Updated image tag parser a bit. Handles recursion of brackets properly now, allows custom parameters from plugins, and takes parameters in any order due to new keyword-based parser
Dan
diff
changeset
+ − 1226
// if ( count($matches[0]) > 0 )
6ba792bc9071
Updated image tag parser a bit. Handles recursion of brackets properly now, allows custom parameters from plugins, and takes parameters in any order due to new keyword-based parser
Dan
diff
changeset
+ − 1227
// die('<pre>' . htmlspecialchars($text) . '</pre>');
6ba792bc9071
Updated image tag parser a bit. Handles recursion of brackets properly now, allows custom parameters from plugins, and takes parameters in any order due to new keyword-based parser
Dan
diff
changeset
+ − 1228
35
+ − 1229
return $text;
+ − 1230
}
+ − 1231
37
+ − 1232
/**
+ − 1233
* Finalizes processing of image tags.
+ − 1234
* @param string The preprocessed text
+ − 1235
* @param array The list of image tags created by RenderMan::process_image_tags()
+ − 1236
*/
+ − 1237
371
dc6026376919
Improved compatibility with PostgreSQL and fixed a number of installer bugs; fixed missing "meta" category declaration in language files
Dan
diff
changeset
+ − 1238
public static function process_imgtags_stage2($text, $taglist)
37
+ − 1239
{
+ − 1240
$s_delim = "\xFF";
+ − 1241
$f_delim = "\xFF";
+ − 1242
foreach ( $taglist as $i => $tag )
+ − 1243
{
+ − 1244
$repl = "{$s_delim}e_img_{$i}{$f_delim}";
+ − 1245
$text = str_replace($repl, $tag, $text);
+ − 1246
}
+ − 1247
return $text;
+ − 1248
}
+ − 1249
1
+ − 1250
}
+ − 1251
+ − 1252
?>