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
685
17ebe24cdf85
Rebranded as 1.1.5 (Caoineag alpha 5) and fixed a couple bugs related to CDN support in template_nodb and installerUI. Updated readme.
Dan
diff
changeset
+ − 5
* Version 1.1.5 (Caoineag alpha 5)
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
+ − 45
$perms =& $session;
+ − 46
322
+ − 47
if ( $page_id != $paths->page_id || $namespace != $paths->namespace )
1
+ − 48
{
+ − 49
unset($perms);
+ − 50
unset($perms); // PHP <5.1.5 Zend bug
+ − 51
$perms = $session->fetch_page_acl($page_id, $namespace);
+ − 52
}
+ − 53
+ − 54
if(!$perms->get_permissions('read'))
+ − 55
return 'Access denied ('.$paths->nslist[$namespace].$page_id.')';
+ − 56
457
d823e49e2e4e
Fixed: RenderMan::getPage() failing with access denial when fetching template and view_source results in deny
Dan
diff
changeset
+ − 57
if($namespace != 'Template' && ($wiki == 0 || $render == false))
1
+ − 58
{
+ − 59
if(!$perms->get_permissions('view_source'))
+ − 60
{
+ − 61
return 'Access denied ('.$paths->nslist[$namespace].$page_id.')';
+ − 62
}
+ − 63
}
+ − 64
+ − 65
$q = $db->sql_query('SELECT page_text,char_tag FROM '.table_prefix.'page_text WHERE page_id=\''.$db->escape($page_id).'\' AND namespace=\''.$db->escape($namespace).'\';');
+ − 66
if ( !$q )
+ − 67
{
+ − 68
$db->_die('Method called was: RenderMan::getPage(\''.$page_id.'\', \''.$namespace.'\');.');
+ − 69
}
+ − 70
if ( $db->numrows() < 1 )
+ − 71
{
+ − 72
return false;
+ − 73
}
+ − 74
$row = $db->fetchrow();
+ − 75
$db->free_result();
+ − 76
+ − 77
$message = $row['page_text'];
+ − 78
$chartag = $row['char_tag'];
+ − 79
unset($row); // Free some memory
+ − 80
133
af0f6ec48de3
Fully implemented password complexity enforcement; added encryption for passwords on registration form; some baby steps taken towards supporting international usernames - this is not working very well, we might need a hackish fix; TODO: implement password strength meter into installer UI and get international usernames 100% working
Dan
diff
changeset
+ − 81
if ( preg_match("#^\#redirect \[\[([^\]\r\n\a\t]+?)\]\]#", $message, $m) && $redir && ( !isset($_GET['redirect']) || ( isset($_GET['redirect']) && $_GET['redirect'] != 'no' ) ) )
1
+ − 82
{
+ − 83
$old = $paths->cpage;
+ − 84
$a = RenderMan::strToPageID($m[1]);
+ − 85
$a[0] = str_replace(' ', '_', $a[0]);
+ − 86
+ − 87
$pageid = str_replace(' ', '_', $paths->nslist[$a[1]] . $a[0]);
+ − 88
$paths->page = $pageid;
+ − 89
$paths->cpage = $paths->pages[$pageid];
+ − 90
//die('<pre>'.print_r($paths->cpage,true).'</pre>');
+ − 91
+ − 92
unset($template);
+ − 93
unset($GLOBALS['template']);
+ − 94
+ − 95
$GLOBALS['template'] = new template();
+ − 96
global $template;
+ − 97
+ − 98
$template->template(); // Tear down and rebuild the template parser
+ − 99
$template->load_theme($session->theme, $session->style);
+ − 100
+ − 101
$data = '<div><small>(Redirected from <a href="'.makeUrlNS($old['namespace'], $old['urlname_nons'], 'redirect=no', true).'">'.$old['name'].'</a>)</small></div>'.RenderMan::getPage($a[0], $a[1], $wiki, $smilies, $filter_links, false /* Enforces a maximum of one redirect */);
+ − 102
+ − 103
return $data;
+ − 104
}
+ − 105
else if(preg_match('#^\#redirect \[\[(.+?)\]\]#', $message, $m) && isset($_GET['redirect']) && $_GET['redirect'] == 'no')
+ − 106
{
+ − 107
preg_match('#^\#redirect \[\[(.+)\]\]#', $message, $m);
+ − 108
$m[1] = str_replace(' ', '_', $m[1]);
+ − 109
$message = preg_replace('#\#redirect \[\[(.+)\]\]#', '<nowiki><div class="mdg-infobox"><table border="0" width="100%" cellspacing="0" cellpadding="0"><tr><td valign="top"><img alt="Cute wet-floor icon" src="'.scriptPath.'/images/redirector.png" /></td><td valign="top" style="padding-left: 10px;"><b>This page is a <i>redirector</i>.</b><br />This means that this page will not show its own content by default. Instead it will display the contents of the page it redirects to.<br /><br />To create a redirect page, make the <i>first characters</i> in the page content <tt>#redirect [[Page_ID]]</tt>. For more information, see the Enano <a href="http://enanocms.org/Help:Wiki_formatting">Wiki formatting guide</a>.<br /><br />This page redirects to <a href="'.makeUrl($m[1]).'">'.$paths->pages[$m[1]]['name'].'</a>.</td></tr></table></div><br /><hr style="margin-left: 1em; width: 200px;" /></nowiki>', $message);
+ − 110
}
+ − 111
$session->disallow_password_grab();
+ − 112
return ($render) ? RenderMan::render($message, $wiki, $smilies, $filter_links) : $message;
+ − 113
}
+ − 114
371
dc6026376919
Improved compatibility with PostgreSQL and fixed a number of installer bugs; fixed missing "meta" category declaration in language files
Dan
diff
changeset
+ − 115
public static function getTemplate($id, $parms)
1
+ − 116
{
+ − 117
global $db, $session, $paths, $template, $plugins; // Common objects
+ − 118
if(!isset($paths->pages[$paths->nslist['Template'].$id]))
+ − 119
{
+ − 120
return '[['.$paths->nslist['Template'].$id.']]';
+ − 121
}
+ − 122
if(isset($paths->template_cache[$id]))
+ − 123
{
+ − 124
$text = $paths->template_cache[$id];
+ − 125
}
+ − 126
else
+ − 127
{
+ − 128
$text = RenderMan::getPage($id, 'Template', 0, true, true, 0);
+ − 129
$paths->template_cache[$id] = $text;
+ − 130
}
+ − 131
+ − 132
$text = preg_replace('/<noinclude>(.*?)<\/noinclude>/is', '', $text);
+ − 133
$text = preg_replace('/<nodisplay>(.*?)<\/nodisplay>/is', '\\1', $text);
+ − 134
+ − 135
preg_match_all('#\(_([0-9]+)_\)#', $text, $matchlist);
+ − 136
+ − 137
foreach($matchlist[1] as $m)
+ − 138
{
+ − 139
if(isset($parms[((int)$m)+1]))
+ − 140
{
+ − 141
$p = $parms[((int)$m)+1];
+ − 142
}
+ − 143
else
+ − 144
{
+ − 145
$p = '<b>Notice:</b> RenderMan::getTemplate(): Parameter '.$m.' is not set';
+ − 146
}
+ − 147
$text = str_replace('(_'.$m.'_)', $p, $text);
717
+ − 148
$text = str_replace('{{' . ( $m + 1 ) . '}}', $p, $text);
1
+ − 149
}
+ − 150
$text = RenderMan::include_templates($text);
+ − 151
return $text;
+ − 152
}
+ − 153
371
dc6026376919
Improved compatibility with PostgreSQL and fixed a number of installer bugs; fixed missing "meta" category declaration in language files
Dan
diff
changeset
+ − 154
public static function fetch_template_text($id)
1
+ − 155
{
+ − 156
global $db, $session, $paths, $template, $plugins; // Common objects
745
+ − 157
$fetch_ns = 'Template';
1
+ − 158
if(!isset($paths->pages[$paths->nslist['Template'].$id]))
+ − 159
{
745
+ − 160
// Transclusion of another page
+ − 161
// 1.1.5: Now You, Too, Can Be A Template, Even If You're Just A Plain Old Article! (TM)
+ − 162
$nssep = substr($paths->nslist['Special'], -1);
+ − 163
$nslist = $paths->nslist;
+ − 164
foreach ( $nslist as &$ns )
+ − 165
{
+ − 166
if ( $ns == '' )
+ − 167
$ns = $nssep;
+ − 168
}
+ − 169
$prefixlist = array_flip($nslist);
+ − 170
foreach ( $nslist as &$ns )
+ − 171
{
+ − 172
$ns = preg_quote($ns);
+ − 173
}
+ − 174
$nslist = implode('|', $nslist);
+ − 175
if ( preg_match("/^($nslist)(.*?)$/", $id, $match) )
+ − 176
{
+ − 177
// in practice this should always be true but just to be safe...
+ − 178
if ( isset($prefixlist[$match[1]]) )
+ − 179
{
+ − 180
$new_id = $paths->nslist[ $prefixlist[$match[1]] ] . sanitize_page_id($match[2]);
+ − 181
if ( !isset($paths->pages[$new_id]) )
+ − 182
{
+ − 183
return "[[$new_id]]";
+ − 184
}
+ − 185
$fetch_ns = $prefixlist[$match[1]];
+ − 186
$id = sanitize_page_id($match[2]);
+ − 187
}
+ − 188
}
+ − 189
else
+ − 190
{
+ − 191
return '[['.$paths->nslist['Template'].$id.']]';
+ − 192
}
1
+ − 193
}
+ − 194
if(isset($paths->template_cache[$id]))
+ − 195
{
+ − 196
$text = $paths->template_cache[$id];
+ − 197
}
+ − 198
else
+ − 199
{
745
+ − 200
$text = RenderMan::getPage($id, $fetch_ns, 0, false, false, false, false);
1
+ − 201
$paths->template_cache[$id] = $text;
+ − 202
}
+ − 203
+ − 204
if ( is_string($text) )
+ − 205
{
+ − 206
$text = preg_replace('/<noinclude>(.*?)<\/noinclude>/is', '', $text);
+ − 207
$text = preg_replace('/<nodisplay>(.*?)<\/nodisplay>/is', '\\1', $text);
+ − 208
}
+ − 209
+ − 210
return $text;
+ − 211
}
+ − 212
371
dc6026376919
Improved compatibility with PostgreSQL and fixed a number of installer bugs; fixed missing "meta" category declaration in language files
Dan
diff
changeset
+ − 213
public static function render($text, $wiki = 1, $smilies = true, $filter_links = true)
1
+ − 214
{
+ − 215
global $db, $session, $paths, $template, $plugins; // Common objects
+ − 216
if($smilies)
+ − 217
{
+ − 218
$text = RenderMan::smilieyize($text);
+ − 219
}
+ − 220
if($wiki == 1)
+ − 221
{
+ − 222
$text = RenderMan::next_gen_wiki_format($text);
+ − 223
}
+ − 224
elseif($wiki == 2)
+ − 225
{
+ − 226
$text = $template->tplWikiFormat($text);
+ − 227
}
+ − 228
return $text;
+ − 229
}
+ − 230
371
dc6026376919
Improved compatibility with PostgreSQL and fixed a number of installer bugs; fixed missing "meta" category declaration in language files
Dan
diff
changeset
+ − 231
public static function PlainTextRender($text, $wiki = 1, $smilies = false, $filter_links = true)
1
+ − 232
{
+ − 233
global $db, $session, $paths, $template, $plugins; // Common objects
+ − 234
if($smilies)
+ − 235
{
+ − 236
$text = RenderMan::smilieyize($text);
+ − 237
}
+ − 238
if($wiki == 1)
+ − 239
{
+ − 240
$text = RenderMan::next_gen_wiki_format($text, true);
+ − 241
}
+ − 242
elseif($wiki == 2)
+ − 243
{
+ − 244
$text = $template->tplWikiFormat($text);
+ − 245
}
+ − 246
return $text;
+ − 247
}
+ − 248
371
dc6026376919
Improved compatibility with PostgreSQL and fixed a number of installer bugs; fixed missing "meta" category declaration in language files
Dan
diff
changeset
+ − 249
public static function next_gen_wiki_format($text, $plaintext = false, $filter_links = true, $do_params = false)
1
+ − 250
{
+ − 251
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
+ − 252
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
+ − 253
592
+ − 254
require_once(ENANO_ROOT.'/includes/wikiformat.php');
+ − 255
require_once(ENANO_ROOT.'/includes/wikiengine/Tables.php');
+ − 256
382
2ccb55995aef
Profiling enabled for RenderMan's wikiformat routine; [minor] made HTML from profiler more pretty
Dan
diff
changeset
+ − 257
profiler_log("RenderMan: starting wikitext render");
2ccb55995aef
Profiling enabled for RenderMan's wikiformat routine; [minor] made HTML from profiler more pretty
Dan
diff
changeset
+ − 258
1
+ − 259
$random_id = md5( time() . mt_rand() );
+ − 260
+ − 261
// Strip out <nowiki> sections and PHP code
+ − 262
407
+ − 263
$nw = preg_match_all('#<nowiki>(.*?)<\/nowiki>#is', $text, $nowiki);
+ − 264
+ − 265
for($i=0;$i<sizeof($nowiki[1]);$i++)
+ − 266
{
+ − 267
$text = str_replace('<nowiki>'.$nowiki[1][$i].'</nowiki>', '{NOWIKI:'.$random_id.':'.$i.'}', $text);
+ − 268
}
+ − 269
+ − 270
$code = $plugins->setHook('render_wikiformat_veryearly');
+ − 271
foreach ( $code as $cmd )
+ − 272
{
+ − 273
eval($cmd);
+ − 274
}
+ − 275
1
+ − 276
$php = preg_match_all('#<\?php(.*?)\?>#is', $text, $phpsec);
+ − 277
+ − 278
for($i=0;$i<sizeof($phpsec[1]);$i++)
+ − 279
{
+ − 280
$text = str_replace('<?php'.$phpsec[1][$i].'?>', '{PHP:'.$random_id.':'.$i.'}', $text);
+ − 281
}
+ − 282
+ − 283
$text = preg_replace('/<noinclude>(.*?)<\/noinclude>/is', '\\1', $text);
+ − 284
if ( $paths->namespace == 'Template' )
+ − 285
{
+ − 286
$text = preg_replace('/<nodisplay>(.*?)<\/nodisplay>/is', '', $text);
+ − 287
}
+ − 288
798
+ − 289
preg_match_all('/<lang (?:code|id)="([a-z0-9_-]+)">([\w\W]+?)<\/lang>/', $text, $langmatch);
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
+ − 290
foreach ( $langmatch[0] as $i => $match )
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
+ − 291
{
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
+ − 292
if ( $langmatch[1][$i] == $lang->lang_code )
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
+ − 293
{
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
+ − 294
$text = str_replace_once($match, $langmatch[2][$i], $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
+ − 295
}
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
+ − 296
else
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
+ − 297
{
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
+ − 298
$text = str_replace_once($match, '', $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
+ − 299
}
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
+ − 300
}
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
+ − 301
163
+ − 302
$code = $plugins->setHook('render_wikiformat_pre');
+ − 303
foreach ( $code as $cmd )
+ − 304
{
+ − 305
eval($cmd);
+ − 306
}
+ − 307
715
+ − 308
//$template_regex = "/\{\{([^\]]+?)((\n([ ]*?)[A-z0-9]+([ ]*?)=([ ]*?)(.+?))*)\}\}/is";
+ − 309
$template_regex = "/\{\{(.+)((\n|\|[ ]*([A-z0-9]+)[ ]*=[ ]*(.+))*)\}\}/isU";
+ − 310
$i = 0;
+ − 311
while ( preg_match($template_regex, $text) )
+ − 312
{
+ − 313
$i++;
+ − 314
if ( $i == 5 )
+ − 315
break;
+ − 316
$text = RenderMan::include_templates($text);
+ − 317
}
+ − 318
798
+ − 319
$code = $plugins->setHook('render_wikiformat_posttemplates');
+ − 320
foreach ( $code as $cmd )
+ − 321
{
+ − 322
eval($cmd);
+ − 323
}
+ − 324
1
+ − 325
if ( !$plaintext )
+ − 326
{
+ − 327
// Process images
142
ca9118d9c0f2
Rebrand as 1.0.2 (Coblynau); internal links are now parsed by RenderMan::parse_internal_links()
Dan
diff
changeset
+ − 328
$text = RenderMan::process_image_tags($text, $taglist);
66
+ − 329
$text = RenderMan::process_imgtags_stage2($text, $taglist);
1
+ − 330
}
+ − 331
+ − 332
if($do_params)
+ − 333
{
+ − 334
preg_match_all('#\(_([0-9]+)_\)#', $text, $matchlist);
+ − 335
foreach($matchlist[1] as $m)
+ − 336
{
+ − 337
$text = str_replace('(_'.$m.'_)', $paths->getParam((int)$m), $text);
+ − 338
}
+ − 339
}
+ − 340
335
67bd3121a12e
Replaced TinyMCE 2.x with 3.0 beta 3. Supports everything but IE. Also rewrote the editor interface completely from the ground up.
Dan
diff
changeset
+ − 341
// Before shipping it out to the renderer, replace spaces in between headings and paragraphs:
67bd3121a12e
Replaced TinyMCE 2.x with 3.0 beta 3. Supports everything but IE. Also rewrote the editor interface completely from the ground up.
Dan
diff
changeset
+ − 342
$text = preg_replace('/<\/(h[0-9]|div|p)>([\s]+)<(h[0-9]|div|p)( .+?)?>/i', '</\\1><\\3\\4>', $text);
67bd3121a12e
Replaced TinyMCE 2.x with 3.0 beta 3. Supports everything but IE. Also rewrote the editor interface completely from the ground up.
Dan
diff
changeset
+ − 343
1
+ − 344
$text = process_tables($text);
142
ca9118d9c0f2
Rebrand as 1.0.2 (Coblynau); internal links are now parsed by RenderMan::parse_internal_links()
Dan
diff
changeset
+ − 345
$text = RenderMan::parse_internal_links($text);
1
+ − 346
371
dc6026376919
Improved compatibility with PostgreSQL and fixed a number of installer bugs; fixed missing "meta" category declaration in language files
Dan
diff
changeset
+ − 347
$wiki = Text_Wiki::singleton('Mediawiki');
1
+ − 348
if($plaintext)
+ − 349
{
+ − 350
$wiki->setRenderConf('Plain', 'wikilink', 'view_url', contentPath);
+ − 351
$result = $wiki->transform($text, 'Plain');
+ − 352
}
+ − 353
else
+ − 354
{
+ − 355
$wiki->setRenderConf('Xhtml', 'wikilink', 'view_url', contentPath);
+ − 356
$wiki->setRenderConf('Xhtml', 'Url', 'css_descr', 'external');
+ − 357
$result = $wiki->transform($text, 'Xhtml');
+ − 358
}
+ − 359
163
+ − 360
// HTML fixes
+ − 361
$result = preg_replace('#<tr>([\s]*?)<\/tr>#is', '', $result);
+ − 362
$result = preg_replace('#<p>([\s]*?)<\/p>#is', '', $result);
+ − 363
$result = preg_replace('#<br />([\s]*?)<table#is', '<table', $result);
+ − 364
$result = str_replace("<pre><code>\n", "<pre><code>", $result);
+ − 365
$result = preg_replace("/<p><table([^>]*?)><\/p>/", "<table\\1>", $result);
+ − 366
$result = str_replace("<br />\n</td>", "\n</td>", $result);
+ − 367
$result = str_replace("<p><tr>", "<tr>", $result);
+ − 368
$result = str_replace("<tr><br />", "<tr>", $result);
+ − 369
$result = str_replace("</tr><br />", "</tr>", $result);
+ − 370
$result = str_replace("</table><br />", "</table>", $result);
+ − 371
$result = preg_replace('/<\/table>$/', "</table><br /><br />", $result);
+ − 372
$result = str_replace("<p></div></p>", "</div>", $result);
+ − 373
$result = str_replace("<p></table></p>", "</table>", $result);
+ − 374
+ − 375
$code = $plugins->setHook('render_wikiformat_post');
+ − 376
foreach ( $code as $cmd )
+ − 377
{
+ − 378
eval($cmd);
+ − 379
}
37
+ − 380
1
+ − 381
// Reinsert <nowiki> sections
+ − 382
for($i=0;$i<$nw;$i++)
+ − 383
{
+ − 384
$result = str_replace('{NOWIKI:'.$random_id.':'.$i.'}', $nowiki[1][$i], $result);
+ − 385
}
+ − 386
+ − 387
// Reinsert PHP
+ − 388
for($i=0;$i<$php;$i++)
+ − 389
{
+ − 390
$result = str_replace('{PHP:'.$random_id.':'.$i.'}', '<?php'.$phpsec[1][$i].'?>', $result);
+ − 391
}
+ − 392
382
2ccb55995aef
Profiling enabled for RenderMan's wikiformat routine; [minor] made HTML from profiler more pretty
Dan
diff
changeset
+ − 393
profiler_log("RenderMan: finished wikitext render");
2ccb55995aef
Profiling enabled for RenderMan's wikiformat routine; [minor] made HTML from profiler more pretty
Dan
diff
changeset
+ − 394
1
+ − 395
return $result;
+ − 396
+ − 397
}
+ − 398
371
dc6026376919
Improved compatibility with PostgreSQL and fixed a number of installer bugs; fixed missing "meta" category declaration in language files
Dan
diff
changeset
+ − 399
public static function wikiFormat($message, $filter_links = true, $do_params = false, $plaintext = false)
163
+ − 400
{
1
+ − 401
global $db, $session, $paths, $template, $plugins; // Common objects
+ − 402
+ − 403
return RenderMan::next_gen_wiki_format($message, $plaintext, $filter_links, $do_params);
+ − 404
+ − 405
$random_id = md5( time() . mt_rand() );
+ − 406
+ − 407
// Strip out <nowiki> sections
+ − 408
$nw = preg_match_all('#<nowiki>(.*?)<\/nowiki>#is', $message, $nowiki);
+ − 409
+ − 410
if(!$plaintext)
+ − 411
{
+ − 412
+ − 413
//return '<pre>'.print_r($nowiki,true).'</pre>';
+ − 414
+ − 415
for($i=0;$i<sizeof($nowiki[1]);$i++)
+ − 416
{
+ − 417
$message = str_replace('<nowiki>'.$nowiki[1][$i].'</nowiki>', '{NOWIKI:'.$random_id.':'.$i.'}', $message);
+ − 418
}
+ − 419
+ − 420
$message = preg_replace('/<noinclude>(.*?)<\/noinclude>/is', '\\1', $message);
+ − 421
+ − 422
//return '<pre>'.htmlspecialchars($message).'</pre>';
+ − 423
35
+ − 424
$message = RenderMan::process_image_tags($message);
1
+ − 425
+ − 426
}
+ − 427
+ − 428
if($do_params)
+ − 429
{
+ − 430
preg_match_all('#\(_([0-9]+)_\)#', $message, $matchlist);
+ − 431
foreach($matchlist[1] as $m)
+ − 432
{
+ − 433
$message = str_replace('(_'.$m.'_)', $paths->getParam((int)$m), $message);
+ − 434
}
+ − 435
}
+ − 436
+ − 437
$message = RenderMan::include_templates($message);
+ − 438
+ − 439
// Reinsert <nowiki> sections
+ − 440
for($i=0;$i<$nw;$i++)
+ − 441
{
+ − 442
$message = str_replace('{NOWIKI:'.$random_id.':'.$i.'}', '<nowiki>'.$nowiki[1][$i].'</nowiki>', $message);
+ − 443
}
+ − 444
+ − 445
$message = process_tables($message);
+ − 446
//if($message2 != $message) return '<pre>'.htmlspecialchars($message2).'</pre>';
+ − 447
//$message = str_replace(array('<table>', '</table>'), array('<nowiki><table>', '</table></nowiki>'), $message);
+ − 448
+ − 449
$wiki =& Text_Wiki::singleton('Mediawiki');
+ − 450
if($plaintext)
+ − 451
{
+ − 452
$wiki->setRenderConf('Plain', 'wikilink', 'view_url', contentPath);
+ − 453
$result = $wiki->transform($message, 'Plain');
+ − 454
} else {
+ − 455
$wiki->setRenderConf('Xhtml', 'wikilink', 'view_url', contentPath);
+ − 456
$wiki->setRenderConf('Xhtml', 'Url', 'css_descr', 'external');
+ − 457
$result = $wiki->transform($message, 'Xhtml');
+ − 458
}
+ − 459
+ − 460
// HTML fixes
+ − 461
$result = preg_replace('#<tr>([\s]*?)<\/tr>#is', '', $result);
+ − 462
$result = preg_replace('#<p>([\s]*?)<\/p>#is', '', $result);
+ − 463
$result = preg_replace('#<br />([\s]*?)<table#is', '<table', $result);
+ − 464
$result = str_replace("<pre><code>\n", "<pre><code>", $result);
+ − 465
$result = preg_replace("/<p><table([^>]*?)><\/p>/", "<table\\1>", $result);
+ − 466
$result = str_replace("<br />\n</td>", "\n</td>", $result);
+ − 467
$result = str_replace("<p><tr>", "<tr>", $result);
+ − 468
$result = str_replace("<tr><br />", "<tr>", $result);
+ − 469
$result = str_replace("</tr><br />", "</tr>", $result);
+ − 470
$result = str_replace("</table></p>", "</table>", $result);
+ − 471
$result = str_replace("</table><br />", "</table>", $result);
+ − 472
$result = preg_replace('/<\/table>$/', "</table><br /><br />", $result);
163
+ − 473
$result = str_replace("<p></div></p>", "</div>", $result);
+ − 474
$result = str_replace("<p></table></p>", "</table>", $result);
1
+ − 475
+ − 476
$result = str_replace('<nowiki>', '<nowiki>', $result);
+ − 477
$result = str_replace('</nowiki>', '</nowiki>', $result);
+ − 478
+ − 479
return $result;
+ − 480
}
+ − 481
371
dc6026376919
Improved compatibility with PostgreSQL and fixed a number of installer bugs; fixed missing "meta" category declaration in language files
Dan
diff
changeset
+ − 482
public static function destroy_javascript($message, $_php = false)
1
+ − 483
{
+ − 484
$message = preg_replace('#<(script|object|applet|embed|iframe|frame|form|input|select)(.*?)>#is', '<\\1\\2>', $message);
+ − 485
$message = preg_replace('#</(script|object|applet|embed|iframe|frame|form|input|select)(.*?)>#is', '</\\1\\2>', $message);
+ − 486
$message = preg_replace('#(javascript|script|activex|chrome|about|applet):#is', '\\1:', $message);
+ − 487
if ( $_php )
+ − 488
{
+ − 489
// Left in only for compatibility
+ − 490
$message = preg_replace('#<(.*?)>#is', '<\\1>', $message);
+ − 491
$message = preg_replace('#<(.*?)>#is', '<\\1>', $message);
+ − 492
$message = preg_replace('#<(\?|\?php|%)(.*?)(\?|%)>#is', '<\\1\\2\\3>', $message);
+ − 493
// strip <a href="foo" onclick="bar();">-type attacks
+ − 494
$message = preg_replace('#<([a-zA-Z:\-]+) (.*?)on([A-Za-z]*)=(.*?)>#is', '<\\1\\2on\\3=\\4>', $message);
+ − 495
}
+ − 496
return $message;
+ − 497
}
+ − 498
371
dc6026376919
Improved compatibility with PostgreSQL and fixed a number of installer bugs; fixed missing "meta" category declaration in language files
Dan
diff
changeset
+ − 499
public static function strip_php($message)
1
+ − 500
{
+ − 501
return RenderMan::destroy_javascript($message, true);
+ − 502
}
+ − 503
371
dc6026376919
Improved compatibility with PostgreSQL and fixed a number of installer bugs; fixed missing "meta" category declaration in language files
Dan
diff
changeset
+ − 504
public static function sanitize_html($text)
1
+ − 505
{
+ − 506
$text = htmlspecialchars($text);
91
+ − 507
$allowed_tags = Array('b', 'i', 'u', 'pre', 'code', 'tt', 'br', 'p', 'nowiki', '!--([\w\W]+)--');
1
+ − 508
foreach($allowed_tags as $t)
+ − 509
{
+ − 510
$text = preg_replace('#<'.$t.'>(.*?)</'.$t.'>#is', '<'.$t.'>\\1</'.$t.'>', $text);
+ − 511
$text = preg_replace('#<'.$t.' />#is', '<'.$t.' />', $text);
+ − 512
$text = preg_replace('#<'.$t.'>#is', '<'.$t.'>', $text);
+ − 513
}
+ − 514
return $text;
+ − 515
}
+ − 516
91
+ − 517
/**
+ − 518
* Parses internal links (wikilinks) in a block of text.
+ − 519
* @param string Text to process
592
+ − 520
* @param string Optional. If included will be used as a template instead of using the default syntax.
91
+ − 521
* @return string
+ − 522
*/
+ − 523
592
+ − 524
public static function parse_internal_links($text, $tplcode = false)
91
+ − 525
{
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
+ − 526
global $db, $session, $paths, $template, $plugins; // Common objects
91
+ − 527
592
+ − 528
if ( is_string($tplcode) )
+ − 529
{
+ − 530
$parser = $template->makeParserText($tplcode);
+ − 531
}
+ − 532
91
+ − 533
// stage 1 - links with alternate text
+ − 534
preg_match_all('/\[\[([^\[\]<>\{\}\|]+)\|(.+?)\]\]/', $text, $matches);
+ − 535
foreach ( $matches[0] as $i => $match )
+ − 536
{
+ − 537
list($page_id, $namespace) = RenderMan::strToPageID($matches[1][$i]);
715
+ − 538
if ( ($pos = strrpos($page_id, '#')) !== false )
+ − 539
{
+ − 540
$hash = substr($page_id, $pos);
+ − 541
$page_id = substr($page_id, 0, $pos);
+ − 542
}
+ − 543
else
+ − 544
{
+ − 545
$hash = '';
+ − 546
}
91
+ − 547
$pid_clean = $paths->nslist[$namespace] . sanitize_page_id($page_id);
+ − 548
715
+ − 549
$url = makeUrl($pid_clean, false, true) . $hash;
91
+ − 550
$inner_text = $matches[2][$i];
+ − 551
$quot = '"';
+ − 552
$exists = ( isPage($pid_clean) ) ? '' : ' class="wikilink-nonexistent"';
+ − 553
592
+ − 554
if ( $tplcode )
+ − 555
{
+ − 556
$parser->assign_vars(array(
+ − 557
'HREF' => $url,
+ − 558
'FLAGS' => $exists,
+ − 559
'TEXT' => $inner_text
+ − 560
));
+ − 561
$link = $parser->run();
+ − 562
}
+ − 563
else
+ − 564
{
+ − 565
$link = "<a href={$quot}{$url}{$quot}{$exists}>{$inner_text}</a>";
+ − 566
}
91
+ − 567
+ − 568
$text = str_replace($match, $link, $text);
+ − 569
}
+ − 570
+ − 571
// stage 2 - links with no alternate text
+ − 572
preg_match_all('/\[\[([^\[\]<>\{\}\|]+)\]\]/', $text, $matches);
+ − 573
foreach ( $matches[0] as $i => $match )
+ − 574
{
+ − 575
list($page_id, $namespace) = RenderMan::strToPageID($matches[1][$i]);
+ − 576
$pid_clean = $paths->nslist[$namespace] . sanitize_page_id($page_id);
+ − 577
159
f7e83b6db3be
Fixed: RenderMan::parse_internal_links() problems with prepending Project: instead of Site_name: to project page alias-namespace links
Dan
diff
changeset
+ − 578
$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
+ − 579
$inner_text = ( isPage($pid_clean) ) ? htmlspecialchars(get_page_title($pid_clean)) : htmlspecialchars($matches[1][$i]);
91
+ − 580
$quot = '"';
+ − 581
$exists = ( isPage($pid_clean) ) ? '' : ' class="wikilink-nonexistent"';
+ − 582
592
+ − 583
if ( $tplcode )
+ − 584
{
+ − 585
$parser->assign_vars(array(
+ − 586
'HREF' => $url,
+ − 587
'FLAGS' => $exists,
+ − 588
'TEXT' => $inner_text
+ − 589
));
+ − 590
$link = $parser->run();
+ − 591
}
+ − 592
else
+ − 593
{
+ − 594
$link = "<a href={$quot}{$url}{$quot}{$exists}>{$inner_text}</a>";
+ − 595
}
91
+ − 596
+ − 597
$text = str_replace($match, $link, $text);
+ − 598
}
+ − 599
+ − 600
return $text;
+ − 601
}
+ − 602
1
+ − 603
/**
+ − 604
* Parses a partial template tag in wikitext, and return an array with the parameters.
63
+ − 605
* @param string The portion of the template tag that contains the parameters.
+ − 606
* @example
1
+ − 607
* <code>
63
+ − 608
foo = lorem ipsum
+ − 609
bar = dolor sit amet
1
+ − 610
* </code>
+ − 611
* @return array Example:
+ − 612
* [foo] => lorem ipsum
+ − 613
* [bar] => dolor sit amet
+ − 614
*/
+ − 615
717
+ − 616
public static function parse_template_vars($input, $newlinemode = true)
1
+ − 617
{
717
+ − 618
$parms = array();
+ − 619
$input = trim($input);
+ − 620
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
+ − 621
{
717
+ − 622
$result = preg_match_all('/
+ − 623
(?:^|[\s]*)\|? # start of parameter - string start or series of spaces
+ − 624
[ ]*
+ − 625
(?:
+ − 626
([A-z0-9_]+) # variable name
+ − 627
[ ]* = [ ]* # assignment
+ − 628
)? # this is optional - if the parameter name is not given, a numerical index is assigned
+ − 629
(.+) # value
+ − 630
/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
+ − 631
}
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
+ − 632
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
+ − 633
{
717
+ − 634
$result = preg_match_all('/
+ − 635
(?:^|[ ]*)\| # start of parameter - string start or series of spaces
+ − 636
[ ]*
+ − 637
(?:
+ − 638
([A-z0-9_]+) # variable name
+ − 639
[ ]* = [ ]* # assignment
+ − 640
)? # name section is optional - if the parameter name is not given, a numerical index is assigned
+ − 641
([^\|]+|.+?\n[ ]*\|) # value
+ − 642
/x', trim($input), $matches);
+ − 643
}
+ − 644
if ( $result )
1
+ − 645
{
717
+ − 646
$pi = 0;
+ − 647
for ( $i = 0; $i < count($matches[0]); $i++ )
1
+ − 648
{
717
+ − 649
$matches[1][$i] = trim($matches[1][$i]);
+ − 650
$parmname = !empty($matches[1][$i]) ? $matches[1][$i] : strval(++$pi);
+ − 651
$parms[ $parmname ] = $matches[2][$i];
1
+ − 652
}
+ − 653
}
+ − 654
return $parms;
+ − 655
}
+ − 656
+ − 657
/**
+ − 658
* 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
+ − 659
* Updated in 1.0.2 to also parse template tags in the format of {{Foo |a = b |b = c |c = therefore, a}}
1
+ − 660
* @param string The text to process
+ − 661
* @return string Formatted text
+ − 662
* @example
+ − 663
* <code>
+ − 664
$text = '{{Template
717
+ − 665
| parm1 = Foo
+ − 666
| parm2 = Bar
1
+ − 667
}}';
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
+ − 668
$text = RenderMan::include_templates($text);
1
+ − 669
* </code>
+ − 670
*/
+ − 671
371
dc6026376919
Improved compatibility with PostgreSQL and fixed a number of installer bugs; fixed missing "meta" category declaration in language files
Dan
diff
changeset
+ − 672
public static function include_templates($text)
1
+ − 673
{
+ − 674
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
+ − 675
// $template_regex = "/\{\{([^\]]+?)((\n([ ]*?)[A-z0-9]+([ ]*?)=([ ]*?)(.+?))*)\}\}/is";
717
+ − 676
// matches:
+ − 677
// 1 - template name
+ − 678
// 2 - parameter section
+ − 679
$template_regex = "/
+ − 680
\{\{ # opening
+ − 681
([^\n\t\a\r]+) # template name
+ − 682
((?:(?:[\s]+\|?)[ ]*(?:[A-z0-9_]+)[ ]*=[ ]*?(?:.+))*) # parameters
+ − 683
\}\} # closing
+ − 684
/isxU";
1
+ − 685
if ( $count = preg_match_all($template_regex, $text, $matches) )
+ − 686
{
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
+ − 687
//die('<pre>' . print_r($matches, true) . '</pre>');
1
+ − 688
for ( $i = 0; $i < $count; $i++ )
+ − 689
{
63
+ − 690
$matches[1][$i] = sanitize_page_id($matches[1][$i]);
717
+ − 691
$newlinemode = ( substr($matches[2][$i], 0, 1) == "\n" );
1
+ − 692
$parmsection = trim($matches[2][$i]);
+ − 693
if ( !empty($parmsection) )
+ − 694
{
717
+ − 695
$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
+ − 696
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
+ − 697
// 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
+ − 698
$parms = array();
1
+ − 699
}
+ − 700
else
+ − 701
{
+ − 702
$parms = Array();
+ − 703
}
+ − 704
if ( $tpl_code = RenderMan::fetch_template_text($matches[1][$i]) )
+ − 705
{
+ − 706
$parser = $template->makeParserText($tpl_code);
+ − 707
$parser->assign_vars($parms);
+ − 708
$text = str_replace($matches[0][$i], $parser->run(), $text);
+ − 709
}
+ − 710
}
+ − 711
}
+ − 712
return $text;
+ − 713
}
+ − 714
+ − 715
/**
+ − 716
* Preprocesses an HTML text string prior to being sent to MySQL.
+ − 717
* @param string $text
+ − 718
* @param bool $strip_all_php - if true, strips all PHP regardless of user permissions. Else, strips PHP only if user level < USER_LEVEL_ADMIN.
+ − 719
*/
371
dc6026376919
Improved compatibility with PostgreSQL and fixed a number of installer bugs; fixed missing "meta" category declaration in language files
Dan
diff
changeset
+ − 720
public static function preprocess_text($text, $strip_all_php = true, $sqlescape = true)
1
+ − 721
{
+ − 722
global $db, $session, $paths, $template, $plugins; // Common objects
+ − 723
$random_id = md5( time() . mt_rand() );
+ − 724
407
+ − 725
$code = $plugins->setHook('render_sanitize_pre');
+ − 726
foreach ( $code as $cmd )
+ − 727
{
+ − 728
eval($cmd);
+ − 729
}
1
+ − 730
+ − 731
$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
+ − 732
$can_do_html = $session->get_permissions('html_in_pages');
1
+ − 733
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
+ − 734
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
+ − 735
{
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
+ − 736
$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
+ − 737
}
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
+ − 738
else if ( !$can_do_html && !$can_do_php )
1
+ − 739
{
24
+ − 740
$text = sanitize_html($text, true);
1
+ − 741
// If we can't do PHP, we can't do Javascript either.
+ − 742
$text = RenderMan::destroy_javascript($text);
+ − 743
}
+ − 744
+ − 745
// Strip out <nowiki> sections and PHP code
+ − 746
+ − 747
$php = preg_match_all('#(<|<)\?php(.*?)\?(>|>)#is', $text, $phpsec);
+ − 748
+ − 749
//die('<pre>'.htmlspecialchars(print_r($phpsec, true))."\n".htmlspecialchars(print_r($text, true)).'</pre>');
+ − 750
+ − 751
for($i=0;$i<sizeof($phpsec[1]);$i++)
+ − 752
{
+ − 753
$text = str_replace($phpsec[0][$i], '{PHP:'.$random_id.':'.$i.'}', $text);
+ − 754
}
+ − 755
+ − 756
$nw = preg_match_all('#<nowiki>(.*?)<\/nowiki>#is', $text, $nowiki);
+ − 757
+ − 758
for($i=0;$i<sizeof($nowiki[1]);$i++)
+ − 759
{
+ − 760
$text = str_replace('<nowiki>'.$nowiki[1][$i].'</nowiki>', '{NOWIKI:'.$random_id.':'.$i.'}', $text);
+ − 761
}
+ − 762
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
+ − 763
$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
+ − 764
$text = str_replace('~~~~', "[[User:$session->username|$session->username]] ".enano_date('G:i, j F Y (T)'), $text);
1
+ − 765
$text = str_replace('~~~', "[[User:$session->username|$session->username]] ", $text);
+ − 766
407
+ − 767
$code = $plugins->setHook('render_sanitize_post');
+ − 768
foreach ( $code as $cmd )
+ − 769
{
+ − 770
eval($cmd);
+ − 771
}
+ − 772
1
+ − 773
// Reinsert <nowiki> sections
+ − 774
for($i=0;$i<$nw;$i++)
+ − 775
{
+ − 776
$text = str_replace('{NOWIKI:'.$random_id.':'.$i.'}', '<nowiki>'.$nowiki[1][$i].'</nowiki>', $text);
+ − 777
}
+ − 778
// Reinsert PHP
+ − 779
for($i=0;$i<$php;$i++)
+ − 780
{
+ − 781
$phsec = ''.$phpsec[1][$i].'?php'.$phpsec[2][$i].'?'.$phpsec[3][$i].'';
+ − 782
if ( $strip_all_php )
+ − 783
$phsec = htmlspecialchars($phsec);
+ − 784
$text = str_replace('{PHP:'.$random_id.':'.$i.'}', $phsec, $text);
+ − 785
}
+ − 786
+ − 787
$text = ( $sqlescape ) ? $db->escape($text) : $text;
+ − 788
+ − 789
return $text;
+ − 790
}
+ − 791
371
dc6026376919
Improved compatibility with PostgreSQL and fixed a number of installer bugs; fixed missing "meta" category declaration in language files
Dan
diff
changeset
+ − 792
public static function smilieyize($text, $complete_urls = false)
1
+ − 793
{
+ − 794
+ − 795
$random_id = md5( time() . mt_rand() );
+ − 796
+ − 797
// Smileys array - eventually this will be fetched from the database by
+ − 798
// RenderMan::initSmileys during initialization, but it will all be hardcoded for beta 2
+ − 799
+ − 800
$smileys = Array(
+ − 801
'O:-)' => 'face-angel.png',
+ − 802
'O:)' => 'face-angel.png',
+ − 803
'O=)' => 'face-angel.png',
+ − 804
':-)' => 'face-smile.png',
+ − 805
':)' => 'face-smile.png',
+ − 806
'=)' => 'face-smile-big.png',
+ − 807
':-(' => 'face-sad.png',
+ − 808
':(' => 'face-sad.png',
+ − 809
';(' => 'face-sad.png',
+ − 810
':-O' => 'face-surprise.png',
+ − 811
';-)' => 'face-wink.png',
+ − 812
';)' => 'face-wink.png',
+ − 813
'8-)' => 'face-glasses.png',
+ − 814
'8)' => 'face-glasses.png',
+ − 815
':-D' => 'face-grin.png',
+ − 816
':D' => 'face-grin.png',
+ − 817
'=D' => 'face-grin.png',
+ − 818
':-*' => 'face-kiss.png',
+ − 819
':*' => 'face-kiss.png',
+ − 820
'=*' => 'face-kiss.png',
+ − 821
':\'(' => 'face-crying.png',
+ − 822
':-|' => 'face-plain.png',
+ − 823
':-\\' => 'face-plain.png',
+ − 824
':-/' => 'face-plain.png',
+ − 825
':joke:' => 'face-plain.png',
+ − 826
']:->' => '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
+ − 827
']:->' => 'face-devil-grin.png',
1
+ − 828
':kiss:' => 'face-kiss.png',
+ − 829
':-P' => 'face-tongue-out.png',
+ − 830
':P' => 'face-tongue-out.png',
+ − 831
':-p' => 'face-tongue-out.png',
+ − 832
':p' => 'face-tongue-out.png',
+ − 833
':-X' => 'face-sick.png',
+ − 834
':X' => 'face-sick.png',
+ − 835
':sick:' => 'face-sick.png',
+ − 836
':-]' => 'face-oops.png',
+ − 837
':]' => 'face-oops.png',
+ − 838
':oops:' => 'face-oops.png',
+ − 839
':-[' => 'face-embarassed.png',
+ − 840
':[' => 'face-embarassed.png'
+ − 841
);
+ − 842
/*
+ − 843
$keys = array_keys($smileys);
+ − 844
foreach($keys as $k)
+ − 845
{
+ − 846
$regex1 = '#([\W]+)'.preg_quote($k).'([\s\n\r\.]+)#s';
+ − 847
$regex2 = '\\1<img alt="'.$k.'" title="'.$k.'" src="'.scriptPath.'/images/smilies/'.$smileys[$k].'" style="border: 0;" />\\2';
+ − 848
$text = preg_replace($regex1, $regex2, $text);
+ − 849
}
+ − 850
*/
+ − 851
+ − 852
// Strip out <nowiki> sections
+ − 853
//return '<pre>'.htmlspecialchars($text).'</pre>';
+ − 854
$nw = preg_match_all('#<nowiki>(.*?)<\/nowiki>#is', $text, $nowiki);
+ − 855
+ − 856
for($i=0;$i<sizeof($nowiki[1]);$i++)
+ − 857
{
+ − 858
$text = str_replace('<nowiki>'.$nowiki[1][$i].'</nowiki>', '{NOWIKI:'.$random_id.':'.$i.'}', $text);
+ − 859
}
+ − 860
+ − 861
$keys = array_keys($smileys);
+ − 862
foreach($keys as $k)
+ − 863
{
391
85f91037cd4f
Localization is FINISHED, DAMN IT HELLAH YEAH! OVER WITH! Man, it feels to get that off my chest. Release is in under 48 hours, folks. And we're ready for it.
Dan
diff
changeset
+ − 864
$t = hexencode($k, ' ', '');
85f91037cd4f
Localization is FINISHED, DAMN IT HELLAH YEAH! OVER WITH! Man, it feels to get that off my chest. Release is in under 48 hours, folks. And we're ready for it.
Dan
diff
changeset
+ − 865
$t = trim($t);
1
+ − 866
$t = explode(' ', $t);
+ − 867
$s = '';
+ − 868
foreach($t as $b)
+ − 869
{
+ − 870
$s.='&#x'.$b.';';
+ − 871
}
+ − 872
$pfx = ( $complete_urls ) ? 'http' . ( isset($_SERVER['HTTPS']) ? 's' : '' ) . '://'.$_SERVER['HTTP_HOST'] : '';
+ − 873
$text = str_replace(' '.$k, ' <nowiki><img title="'.$s.'" alt="'.$s.'" src="'.$pfx.scriptPath.'/images/smilies/'.$smileys[$k].'" style="border: 0;" /></nowiki>', $text);
+ − 874
}
+ − 875
//*/
+ − 876
+ − 877
// Reinsert <nowiki> sections
+ − 878
for($i=0;$i<$nw;$i++)
+ − 879
{
+ − 880
$text = str_replace('{NOWIKI:'.$random_id.':'.$i.'}', '<nowiki>'.$nowiki[1][$i].'</nowiki>', $text);
+ − 881
}
+ − 882
+ − 883
return $text;
+ − 884
}
+ − 885
+ − 886
/*
+ − 887
* **** DEPRECATED ****
+ − 888
* Replaces some critical characters in a string with MySQL-safe equivalents
+ − 889
* @param $text string the text to escape
+ − 890
* @return array key 0 is the escaped text, key 1 is the character tag
+ − 891
* /
+ − 892
371
dc6026376919
Improved compatibility with PostgreSQL and fixed a number of installer bugs; fixed missing "meta" category declaration in language files
Dan
diff
changeset
+ − 893
public static function escape_page_text($text)
1
+ − 894
{
+ − 895
$char_tag = md5(microtime() . mt_rand());
+ − 896
$text = str_replace("'", "{APOS:$char_tag}", $text);
+ − 897
$text = str_replace('"', "{QUOT:$char_tag}", $text);
+ − 898
$text = str_replace("\\", "{SLASH:$char_tag}", $text);
+ − 899
return Array($text, $char_tag);
+ − 900
}
+ − 901
*/
+ − 902
+ − 903
/* **** DEPRECATED ****
+ − 904
* Reverses the result of RenderMan::escape_page_text().
+ − 905
* @param $text string the text to unescape
+ − 906
* @param $char_tag string the character tag
+ − 907
* @return string
+ − 908
* /
+ − 909
371
dc6026376919
Improved compatibility with PostgreSQL and fixed a number of installer bugs; fixed missing "meta" category declaration in language files
Dan
diff
changeset
+ − 910
public static function unescape_page_text($text, $char_tag)
1
+ − 911
{
+ − 912
$text = str_replace("{APOS:$char_tag}", "'", $text);
+ − 913
$text = str_replace("{QUOT:$char_tag}", '"', $text);
+ − 914
$text = str_replace("{SLASH:$char_tag}", "\\", $text);
+ − 915
return $text;
+ − 916
}
+ − 917
*/
+ − 918
+ − 919
/**
+ − 920
* Generates a summary of the differences between two texts, and formats it as XHTML.
+ − 921
* @param $str1 string the first block of text
+ − 922
* @param $str2 string the second block of text
+ − 923
* @return string
+ − 924
*/
371
dc6026376919
Improved compatibility with PostgreSQL and fixed a number of installer bugs; fixed missing "meta" category declaration in language files
Dan
diff
changeset
+ − 925
public static function diff($str1, $str2)
1
+ − 926
{
+ − 927
global $db, $session, $paths, $template, $plugins; // Common objects
592
+ − 928
require_once(ENANO_ROOT.'/includes/diff.php');
1
+ − 929
$str1 = explode("\n", $str1);
+ − 930
$str2 = explode("\n", $str2);
+ − 931
$diff = new Diff($str1, $str2);
+ − 932
$renderer = new TableDiffFormatter();
+ − 933
return '<table class="diff">'.$renderer->format($diff).'</table>';
+ − 934
}
+ − 935
35
+ − 936
/**
+ − 937
* Changes wikitext image tags to HTML.
+ − 938
* @param string The wikitext to process
37
+ − 939
* @param array Will be overwritten with the list of HTML tags (the system uses tokens for TextWiki compatibility)
35
+ − 940
* @return string
+ − 941
*/
+ − 942
371
dc6026376919
Improved compatibility with PostgreSQL and fixed a number of installer bugs; fixed missing "meta" category declaration in language files
Dan
diff
changeset
+ − 943
public static function process_image_tags($text, &$taglist)
35
+ − 944
{
+ − 945
global $db, $session, $paths, $template, $plugins; // Common objects
+ − 946
37
+ − 947
$s_delim = "\xFF";
+ − 948
$f_delim = "\xFF";
+ − 949
$taglist = array();
+ − 950
35
+ − 951
// 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
+ − 952
$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
+ − 953
$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
+ − 954
\[\[ # 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
+ − 955
:' . $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
+ − 956
(?:(?:\|(?:.+?))*) # 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
+ − 957
\]\] # 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
+ − 958
/ix';
35
+ − 959
+ − 960
preg_match_all($regex, $text, $matches);
+ − 961
+ − 962
foreach ( $matches[0] as $i => $match )
+ − 963
{
+ − 964
+ − 965
$full_tag =& $matches[0][$i];
+ − 966
$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
+ − 967
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
+ − 968
// 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
+ − 969
$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
+ − 970
$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
+ − 971
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
+ − 972
{
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
+ − 973
$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
+ − 974
$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
+ − 975
}
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
+ − 976
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
+ − 977
{
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
+ − 978
// 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
+ − 979
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
+ − 980
}
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
+ − 981
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
+ − 982
// 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
+ − 983
$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
+ − 984
$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
+ − 985
$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
+ − 986
$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
+ − 987
$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
+ − 988
$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
+ − 989
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
+ − 990
// 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
+ − 991
$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
+ − 992
// 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
+ − 993
$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
+ − 994
$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
+ − 995
// 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
+ − 996
$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
+ − 997
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
+ − 998
// 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
+ − 999
// 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
+ − 1000
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
+ − 1001
{
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
+ − 1002
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
+ − 1003
{
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
+ − 1004
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
+ − 1005
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
+ − 1006
$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
+ − 1007
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
+ − 1008
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
+ − 1009
$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
+ − 1010
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
+ − 1011
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
+ − 1012
$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
+ − 1013
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
+ − 1014
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
+ − 1015
// 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
+ − 1016
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
+ − 1017
{
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
$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
+ − 1019
$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
+ − 1020
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
+ − 1021
}
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
// not the height, so see if a plugin took this over
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
// this hook requires plugins to return true if they modified anythin
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
+ − 1024
$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
+ − 1025
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
+ − 1026
{
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
+ − 1027
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
+ − 1028
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
+ − 1029
}
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
+ − 1030
// 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
+ − 1031
// 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
+ − 1032
$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
+ − 1033
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
+ − 1034
}
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
}
35
+ − 1036
+ − 1037
if ( !isPage( $paths->nslist['File'] . $filename ) )
+ − 1038
{
66
+ − 1039
$text = str_replace($full_tag, '[[' . makeUrlNS('File', $filename) . ']]', $text);
35
+ − 1040
continue;
+ − 1041
}
+ − 1042
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
+ − 1043
if ( $scale_type == 'thumb' )
35
+ − 1044
{
+ − 1045
$r_width = 225;
+ − 1046
$r_height = 225;
+ − 1047
+ − 1048
$url = makeUrlNS('Special', 'DownloadFile/' . $filename, 'preview&width=' . $r_width . '&height=' . $r_height, true);
+ − 1049
}
+ − 1050
else if ( !empty($width) && !empty($height) )
+ − 1051
{
+ − 1052
$r_width = $width;
+ − 1053
$r_height = $height;
+ − 1054
+ − 1055
$url = makeUrlNS('Special', 'DownloadFile/' . $filename, 'preview&width=' . $r_width . '&height=' . $r_height, true);
+ − 1056
}
+ − 1057
else
+ − 1058
{
+ − 1059
$url = makeUrlNS('Special', 'DownloadFile/' . $filename);
+ − 1060
}
+ − 1061
+ − 1062
$img_tag = '<img src="' . $url . '" ';
+ − 1063
65
+ − 1064
// if ( isset($r_width) && isset($r_height) && $scale_type != '|thumb' )
+ − 1065
// {
66
+ − 1066
// $img_tag .= 'width="' . $r_width . '" height="' . $r_height . '" ';
65
+ − 1067
// }
35
+ − 1068
66
+ − 1069
$img_tag .= 'style="border-width: 0px; /* background-color: white; */" ';
35
+ − 1070
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
+ − 1071
$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
+ − 1072
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
+ − 1073
{
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
+ − 1074
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
+ − 1075
}
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
+ − 1076
35
+ − 1077
$img_tag .= '/>';
+ − 1078
+ − 1079
$complete_tag = '';
+ − 1080
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
+ − 1081
if ( !empty($scale_type) && !$raw_display )
35
+ − 1082
{
+ − 1083
$complete_tag .= '<div class="thumbnail" ';
+ − 1084
$clear_text = '';
+ − 1085
if ( !empty($clear) )
+ − 1086
{
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
+ − 1087
$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
+ − 1088
$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
+ − 1089
$clear_text .= "float: $side; margin-$opposite: 20px; width: {$r_width}px;";
35
+ − 1090
$complete_tag .= 'style="' . $clear_text . '" ';
+ − 1091
}
+ − 1092
$complete_tag .= '>';
+ − 1093
+ − 1094
$complete_tag .= '<a href="' . makeUrlNS('File', $filename) . '" style="display: block;">';
+ − 1095
$complete_tag .= $img_tag;
+ − 1096
$complete_tag .= '</a>';
+ − 1097
+ − 1098
$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>';
+ − 1099
+ − 1100
if ( !empty($caption) )
+ − 1101
{
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
+ − 1102
$complete_tag .= $mag_button . $caption;
35
+ − 1103
}
+ − 1104
+ − 1105
$complete_tag .= '</div>';
+ − 1106
}
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
+ − 1107
else if ( $raw_display )
66
+ − 1108
{
67
+ − 1109
$complete_tag .= "$img_tag";
+ − 1110
$taglist[$i] = $complete_tag;
+ − 1111
+ − 1112
$repl = "{$s_delim}e_img_{$i}{$f_delim}";
+ − 1113
$text = str_replace($full_tag, $repl, $text);
+ − 1114
continue;
66
+ − 1115
}
35
+ − 1116
else
+ − 1117
{
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
+ − 1118
$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
+ − 1119
$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
+ − 1120
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
+ − 1121
{
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
+ − 1122
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
+ − 1123
}
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
+ − 1124
$complete_tag .= '>';
35
+ − 1125
$complete_tag .= $img_tag;
+ − 1126
$complete_tag .= '</a>';
+ − 1127
}
+ − 1128
37
+ − 1129
$complete_tag .= "\n\n";
+ − 1130
$taglist[$i] = $complete_tag;
35
+ − 1131
37
+ − 1132
$pos = strpos($text, $full_tag);
35
+ − 1133
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
+ − 1134
/*
35
+ − 1135
while(true)
+ − 1136
{
+ − 1137
$check1 = substr($text, $pos, 3);
+ − 1138
$check2 = substr($text, $pos, 1);
+ − 1139
if ( $check1 == '<p>' || $pos == 0 || $check2 == "\n" )
+ − 1140
{
+ − 1141
// die('found at pos '.$pos);
+ − 1142
break;
+ − 1143
}
+ − 1144
$pos--;
+ − 1145
}
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
+ − 1146
*/
35
+ − 1147
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
+ − 1148
/*
37
+ − 1149
$repl = "{$s_delim}e_img_{$i}{$f_delim}";
+ − 1150
$text = substr($text, 0, $pos) . $repl . substr($text, $pos);
35
+ − 1151
+ − 1152
$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
+ − 1153
*/
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
$text = str_replace_once($full_tag, $complete_tag, $text);
35
+ − 1155
+ − 1156
unset($full_tag, $filename, $scale_type, $width, $height, $clear, $caption, $r_width, $r_height);
+ − 1157
+ − 1158
}
+ − 1159
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
+ − 1160
// 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
+ − 1161
// 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
+ − 1162
35
+ − 1163
return $text;
+ − 1164
}
+ − 1165
37
+ − 1166
/**
+ − 1167
* Finalizes processing of image tags.
+ − 1168
* @param string The preprocessed text
+ − 1169
* @param array The list of image tags created by RenderMan::process_image_tags()
+ − 1170
*/
+ − 1171
371
dc6026376919
Improved compatibility with PostgreSQL and fixed a number of installer bugs; fixed missing "meta" category declaration in language files
Dan
diff
changeset
+ − 1172
public static function process_imgtags_stage2($text, $taglist)
37
+ − 1173
{
+ − 1174
$s_delim = "\xFF";
+ − 1175
$f_delim = "\xFF";
+ − 1176
foreach ( $taglist as $i => $tag )
+ − 1177
{
+ − 1178
$repl = "{$s_delim}e_img_{$i}{$f_delim}";
+ − 1179
$text = str_replace($repl, $tag, $text);
+ − 1180
}
+ − 1181
return $text;
+ − 1182
}
+ − 1183
1
+ − 1184
}
+ − 1185
+ − 1186
?>