Remove array indexes for easymod

git-svn-id: file:///svn/phpbb/branches/phpBB-2_0_0@2940 89ea8834-ac86-4346-8a33-228a782c2dd0
This commit is contained in:
Paul S. Owen 2002-10-07 22:42:43 +00:00
parent 6913351af7
commit c28993a5cf

View file

@ -26,7 +26,7 @@ if ( !defined('IN_PHPBB') )
define("BBCODE_UID_LEN", 10); define("BBCODE_UID_LEN", 10);
// global that holds loaded-and-prepared bbcode templates, so we only have to do // global that holds loaded-and-prepared bbcode templates, so we only have to do
// that stuff once. // that stuff once.
$bbcode_tpl = null; $bbcode_tpl = null;
@ -45,21 +45,21 @@ function load_bbcode_template()
global $template; global $template;
$tpl_filename = $template->make_filename('bbcode.tpl'); $tpl_filename = $template->make_filename('bbcode.tpl');
$tpl = fread(fopen($tpl_filename, 'r'), filesize($tpl_filename)); $tpl = fread(fopen($tpl_filename, 'r'), filesize($tpl_filename));
// replace \ with \\ and then ' with \'. // replace \ with \\ and then ' with \'.
$tpl = str_replace('\\', '\\\\', $tpl); $tpl = str_replace('\\', '\\\\', $tpl);
$tpl = str_replace('\'', '\\\'', $tpl); $tpl = str_replace('\'', '\\\'', $tpl);
// strip newlines. // strip newlines.
$tpl = str_replace("\n", '', $tpl); $tpl = str_replace("\n", '', $tpl);
// Turn template blocks into PHP assignment statements for the values of $bbcode_tpls.. // Turn template blocks into PHP assignment statements for the values of $bbcode_tpls..
$tpl = preg_replace('#<!-- BEGIN (.*?) -->(.*?)<!-- END (.*?) -->#', "\n" . '$bbcode_tpls[\'\\1\'] = \'\\2\';', $tpl); $tpl = preg_replace('#<!-- BEGIN (.*?) -->(.*?)<!-- END (.*?) -->#', "\n" . '$bbcode_tpls[\'\\1\'] = \'\\2\';', $tpl);
$bbcode_tpls = array(); $bbcode_tpls = array();
eval($tpl); eval($tpl);
return $bbcode_tpls; return $bbcode_tpls;
} }
@ -68,7 +68,7 @@ function load_bbcode_template()
* Prepares the loaded bbcode templates for insertion into preg_replace() * Prepares the loaded bbcode templates for insertion into preg_replace()
* or str_replace() calls in the bbencode_second_pass functions. This * or str_replace() calls in the bbencode_second_pass functions. This
* means replacing template placeholders with the appropriate preg backrefs * means replacing template placeholders with the appropriate preg backrefs
* or with language vars. NOTE: If you change how the regexps work in * or with language vars. NOTE: If you change how the regexps work in
* bbencode_second_pass(), you MUST change this function. * bbencode_second_pass(), you MUST change this function.
* *
* Nathan Codding, Sept 26 2001 * Nathan Codding, Sept 26 2001
@ -77,47 +77,47 @@ function load_bbcode_template()
function prepare_bbcode_template($bbcode_tpl) function prepare_bbcode_template($bbcode_tpl)
{ {
global $lang; global $lang;
$bbcode_tpl['olist_open'] = str_replace('{LIST_TYPE}', '\\1', $bbcode_tpl['olist_open']); $bbcode_tpl['olist_open'] = str_replace('{LIST_TYPE}', '\\1', $bbcode_tpl['olist_open']);
$bbcode_tpl['color_open'] = str_replace('{COLOR}', '\\1', $bbcode_tpl['color_open']); $bbcode_tpl['color_open'] = str_replace('{COLOR}', '\\1', $bbcode_tpl['color_open']);
$bbcode_tpl['size_open'] = str_replace('{SIZE}', '\\1', $bbcode_tpl['size_open']); $bbcode_tpl['size_open'] = str_replace('{SIZE}', '\\1', $bbcode_tpl['size_open']);
$bbcode_tpl['quote_open'] = str_replace('{L_QUOTE}', $lang['Quote'], $bbcode_tpl['quote_open']); $bbcode_tpl['quote_open'] = str_replace('{L_QUOTE}', $lang['Quote'], $bbcode_tpl['quote_open']);
$bbcode_tpl['quote_username_open'] = str_replace('{L_QUOTE}', $lang['Quote'], $bbcode_tpl['quote_username_open']); $bbcode_tpl['quote_username_open'] = str_replace('{L_QUOTE}', $lang['Quote'], $bbcode_tpl['quote_username_open']);
$bbcode_tpl['quote_username_open'] = str_replace('{L_WROTE}', $lang['wrote'], $bbcode_tpl['quote_username_open']); $bbcode_tpl['quote_username_open'] = str_replace('{L_WROTE}', $lang['wrote'], $bbcode_tpl['quote_username_open']);
$bbcode_tpl['quote_username_open'] = str_replace('{USERNAME}', '\\1', $bbcode_tpl['quote_username_open']); $bbcode_tpl['quote_username_open'] = str_replace('{USERNAME}', '\\1', $bbcode_tpl['quote_username_open']);
$bbcode_tpl['code_open'] = str_replace('{L_CODE}', $lang['Code'], $bbcode_tpl['code_open']); $bbcode_tpl['code_open'] = str_replace('{L_CODE}', $lang['Code'], $bbcode_tpl['code_open']);
$bbcode_tpl['img'] = str_replace('{URL}', '\\1', $bbcode_tpl['img']); $bbcode_tpl['img'] = str_replace('{URL}', '\\1', $bbcode_tpl['img']);
// We do URLs in several different ways.. // We do URLs in several different ways..
$bbcode_tpl['url1'] = str_replace('{URL}', '\\1\\2', $bbcode_tpl['url']); $bbcode_tpl['url1'] = str_replace('{URL}', '\\1\\2', $bbcode_tpl['url']);
$bbcode_tpl['url1'] = str_replace('{DESCRIPTION}', '\\1\\2', $bbcode_tpl['url1']); $bbcode_tpl['url1'] = str_replace('{DESCRIPTION}', '\\1\\2', $bbcode_tpl['url1']);
$bbcode_tpl['url2'] = str_replace('{URL}', 'http://\\1', $bbcode_tpl['url']); $bbcode_tpl['url2'] = str_replace('{URL}', 'http://\\1', $bbcode_tpl['url']);
$bbcode_tpl['url2'] = str_replace('{DESCRIPTION}', '\\1', $bbcode_tpl['url2']); $bbcode_tpl['url2'] = str_replace('{DESCRIPTION}', '\\1', $bbcode_tpl['url2']);
$bbcode_tpl['url3'] = str_replace('{URL}', '\\1\\2', $bbcode_tpl['url']); $bbcode_tpl['url3'] = str_replace('{URL}', '\\1\\2', $bbcode_tpl['url']);
$bbcode_tpl['url3'] = str_replace('{DESCRIPTION}', '\\3', $bbcode_tpl['url3']); $bbcode_tpl['url3'] = str_replace('{DESCRIPTION}', '\\3', $bbcode_tpl['url3']);
$bbcode_tpl['url4'] = str_replace('{URL}', 'http://\\1', $bbcode_tpl['url']); $bbcode_tpl['url4'] = str_replace('{URL}', 'http://\\1', $bbcode_tpl['url']);
$bbcode_tpl['url4'] = str_replace('{DESCRIPTION}', '\\2', $bbcode_tpl['url4']); $bbcode_tpl['url4'] = str_replace('{DESCRIPTION}', '\\2', $bbcode_tpl['url4']);
$bbcode_tpl['email'] = str_replace('{EMAIL}', '\\1', $bbcode_tpl['email']); $bbcode_tpl['email'] = str_replace('{EMAIL}', '\\1', $bbcode_tpl['email']);
define("BBCODE_TPL_READY", true); define("BBCODE_TPL_READY", true);
return $bbcode_tpl; return $bbcode_tpl;
} }
/** /**
* Does second-pass bbencoding. This should be used before displaying the message in * Does second-pass bbencoding. This should be used before displaying the message in
* a thread. Assumes the message is already first-pass encoded, and we are given the * a thread. Assumes the message is already first-pass encoded, and we are given the
* correct UID as used in first-pass encoding. * correct UID as used in first-pass encoding.
*/ */
function bbencode_second_pass($text, $uid) function bbencode_second_pass($text, $uid)
@ -135,13 +135,13 @@ function bbencode_second_pass($text, $uid)
$text = substr($text, 1); $text = substr($text, 1);
return $text; return $text;
} }
// Only load the templates ONCE.. // Only load the templates ONCE..
if (!defined("BBCODE_TPL_READY")) if (!defined("BBCODE_TPL_READY"))
{ {
// load templates from file into array. // load templates from file into array.
$bbcode_tpl = load_bbcode_template(); $bbcode_tpl = load_bbcode_template();
// prepare array for use in regexps. // prepare array for use in regexps.
$bbcode_tpl = prepare_bbcode_template($bbcode_tpl); $bbcode_tpl = prepare_bbcode_template($bbcode_tpl);
} }
@ -171,7 +171,7 @@ function bbencode_second_pass($text, $uid)
// [QUOTE] and [/QUOTE] for posting replies with quote, or just for quoting stuff. // [QUOTE] and [/QUOTE] for posting replies with quote, or just for quoting stuff.
$text = str_replace("[quote:$uid]", $bbcode_tpl['quote_open'], $text); $text = str_replace("[quote:$uid]", $bbcode_tpl['quote_open'], $text);
$text = str_replace("[/quote:$uid]", $bbcode_tpl['quote_close'], $text); $text = str_replace("[/quote:$uid]", $bbcode_tpl['quote_close'], $text);
// New one liner to deal with opening quotes with usernames... // New one liner to deal with opening quotes with usernames...
// replaces the two line version that I had here before.. // replaces the two line version that I had here before..
$text = preg_replace("/\[quote:$uid=(?:\"?([^\"]*)\"?)\]/si", $bbcode_tpl['quote_username_open'], $text); $text = preg_replace("/\[quote:$uid=(?:\"?([^\"]*)\"?)\]/si", $bbcode_tpl['quote_username_open'], $text);
@ -194,28 +194,28 @@ function bbencode_second_pass($text, $uid)
// [img]image_url_here[/img] code.. // [img]image_url_here[/img] code..
// This one gets first-passed.. // This one gets first-passed..
$patterns[0] = "#\[img:$uid\](.*?)\[/img:$uid\]#si"; $patterns[] = "#\[img:$uid\](.*?)\[/img:$uid\]#si";
$replacements[0] = $bbcode_tpl['img']; $replacements[] = $bbcode_tpl['img'];
// [url]xxxx://www.phpbb.com[/url] code.. // [url]xxxx://www.phpbb.com[/url] code..
$patterns[1] = "#\[url\]([a-z]+?://){1}([a-z0-9\-\.,\?!%\*_\#:;~\\&$@\/=\+\(\)]+)\[/url\]#si"; $patterns[] = "#\[url\]([a-z]+?://){1}([a-z0-9\-\.,\?!%\*_\#:;~\\&$@\/=\+\(\)]+)\[/url\]#si";
$replacements[1] = $bbcode_tpl['url1']; $replacements[] = $bbcode_tpl['url1'];
// [url]www.phpbb.com[/url] code.. (no xxxx:// prefix). // [url]www.phpbb.com[/url] code.. (no xxxx:// prefix).
$patterns[2] = "#\[url\]([a-z0-9\-\.,\?!%\*_\#:;~\\&$@\/=\+\(\)]+)\[/url\]#si"; $patterns[] = "#\[url\]([a-z0-9\-\.,\?!%\*_\#:;~\\&$@\/=\+\(\)]+)\[/url\]#si";
$replacements[2] = $bbcode_tpl['url2']; $replacements[] = $bbcode_tpl['url2'];
// [url=xxxx://www.phpbb.com]phpBB[/url] code.. // [url=xxxx://www.phpbb.com]phpBB[/url] code..
$patterns[3] = "#\[url=([a-z]+?://){1}([a-z0-9\-\.,\?!%\*_\#:;~\\&$@\/=\+\(\)]+)\](.*?)\[/url\]#si"; $patterns[] = "#\[url=([a-z]+?://){1}([a-z0-9\-\.,\?!%\*_\#:;~\\&$@\/=\+\(\)]+)\](.*?)\[/url\]#si";
$replacements[3] = $bbcode_tpl['url3']; $replacements[] = $bbcode_tpl['url3'];
// [url=www.phpbb.com]phpBB[/url] code.. (no xxxx:// prefix). // [url=www.phpbb.com]phpBB[/url] code.. (no xxxx:// prefix).
$patterns[4] = "#\[url=([a-z0-9\-\.,\?!%\*_\#:;~\\&$@\/=\+\(\)]+)\](.*?)\[/url\]#si"; $patterns[] = "#\[url=([a-z0-9\-\.,\?!%\*_\#:;~\\&$@\/=\+\(\)]+)\](.*?)\[/url\]#si";
$replacements[4] = $bbcode_tpl['url4']; $replacements[] = $bbcode_tpl['url4'];
// [email]user@domain.tld[/email] code.. // [email]user@domain.tld[/email] code..
$patterns[5] = "#\[email\]([a-z0-9\-_.]+?@[\w\-]+\.([\w\-\.]+\.)?[\w]+)\[/email\]#si"; $patterns[] = "#\[email\]([a-z0-9\-_.]+?@[\w\-]+\.([\w\-\.]+\.)?[\w]+)\[/email\]#si";
$replacements[5] = $bbcode_tpl['email']; $replacements[] = $bbcode_tpl['email'];
$text = preg_replace($patterns, $replacements, $text); $text = preg_replace($patterns, $replacements, $text);
@ -250,7 +250,7 @@ function bbencode_first_pass($text, $uid)
// [QUOTE] and [/QUOTE] for posting replies with quote, or just for quoting stuff. // [QUOTE] and [/QUOTE] for posting replies with quote, or just for quoting stuff.
$text = bbencode_first_pass_pda($text, $uid, '[quote]', '[/quote]', '', false, ''); $text = bbencode_first_pass_pda($text, $uid, '[quote]', '[/quote]', '', false, '');
$text = bbencode_first_pass_pda($text, $uid, '/\[quote=(\\\\"[^"]*?\\\\")\]/is', '[/quote]', '', false, '', "[quote:$uid=\\1]"); $text = bbencode_first_pass_pda($text, $uid, '/\[quote=(\\\\"[^"]*?\\\\")\]/is', '[/quote]', '', false, '', "[quote:$uid=\\1]");
// [list] and [list=x] for (un)ordered lists. // [list] and [list=x] for (un)ordered lists.
@ -349,9 +349,9 @@ function bbencode_first_pass_pda($text, $uid, $open_tag, $close_tag, $close_tag_
$open_tag[0] = $open_tag_temp; $open_tag[0] = $open_tag_temp;
$open_tag_count = 1; $open_tag_count = 1;
} }
$open_is_regexp = false; $open_is_regexp = false;
if ($open_regexp_replace) if ($open_regexp_replace)
{ {
$open_is_regexp = true; $open_is_regexp = true;
@ -362,12 +362,12 @@ function bbencode_first_pass_pda($text, $uid, $open_tag, $close_tag, $close_tag_
$open_regexp_replace[0] = $open_regexp_temp; $open_regexp_replace[0] = $open_regexp_temp;
} }
} }
if ($mark_lowest_level && $open_is_regexp) if ($mark_lowest_level && $open_is_regexp)
{ {
message_die(GENERAL_ERROR, "Unsupported operation for bbcode_first_pass_pda()."); message_die(GENERAL_ERROR, "Unsupported operation for bbcode_first_pass_pda().");
} }
// Start at the 2nd char of the string, looking for opening tags. // Start at the 2nd char of the string, looking for opening tags.
$curr_pos = 1; $curr_pos = 1;
@ -396,12 +396,12 @@ function bbencode_first_pass_pda($text, $uid, $open_tag, $close_tag, $close_tag_
// //
// OK we are in a quote tag that probably contains a ] bracket. // OK we are in a quote tag that probably contains a ] bracket.
// Grab a bit more of the string to hopefully get all of it.. // Grab a bit more of the string to hopefully get all of it..
// //
$possible_start = substr($text, $curr_pos, strpos($text, "\"]", $curr_pos + 1) - $curr_pos + 2); $possible_start = substr($text, $curr_pos, strpos($text, "\"]", $curr_pos + 1) - $curr_pos + 2);
} }
// //
// Now compare, either using regexp or not. // Now compare, either using regexp or not.
if ($open_is_regexp) if ($open_is_regexp)
{ {
$match_result = array(); $match_result = array();
@ -439,7 +439,7 @@ function bbencode_first_pass_pda($text, $uid, $open_tag, $close_tag, $close_tag_
// Keeps error in nested tag from breaking out // Keeps error in nested tag from breaking out
// of table structure.. // of table structure..
// //
$curr_pos = $curr_pos + strlen($possible_start); $curr_pos = $curr_pos + strlen($possible_start);
} }
else else
{ {
@ -572,12 +572,12 @@ function bbencode_second_pass_code($text, $uid, $bbcode_tpl)
{ {
$before_replace = $matches[1][$i]; $before_replace = $matches[1][$i];
$after_replace = $matches[1][$i]; $after_replace = $matches[1][$i];
// Replace 2 spaces with "&nbsp; " so non-tabbed code indents without making huge long lines. // Replace 2 spaces with "&nbsp; " so non-tabbed code indents without making huge long lines.
$after_replace = str_replace(" ", "&nbsp; ", $after_replace); $after_replace = str_replace(" ", "&nbsp; ", $after_replace);
// now Replace 2 spaces with " &nbsp;" to catch odd #s of spaces. // now Replace 2 spaces with " &nbsp;" to catch odd #s of spaces.
$after_replace = str_replace(" ", " &nbsp;", $after_replace); $after_replace = str_replace(" ", " &nbsp;", $after_replace);
// Replace tabs with "&nbsp; &nbsp;" so tabbed code indents sorta right without making huge long lines. // Replace tabs with "&nbsp; &nbsp;" so tabbed code indents sorta right without making huge long lines.
$after_replace = str_replace("\t", "&nbsp; &nbsp;", $after_replace); $after_replace = str_replace("\t", "&nbsp; &nbsp;", $after_replace);
@ -736,36 +736,36 @@ function bbcode_array_pop(&$stack)
// Smilies code ... would this be better tagged on to the end of bbcode.php? // Smilies code ... would this be better tagged on to the end of bbcode.php?
// Probably so and I'll move it before B2 // Probably so and I'll move it before B2
// //
function smilies_pass($message) function smilies_pass($message)
{ {
static $orig, $repl; static $orig, $repl;
if (!isset($orig)) if (!isset($orig))
{ {
global $db, $board_config; global $db, $board_config;
$orig = $repl = array(); $orig = $repl = array();
$sql = 'SELECT code, smile_url FROM ' . SMILIES_TABLE; $sql = 'SELECT code, smile_url FROM ' . SMILIES_TABLE;
if( !$result = $db->sql_query($sql) ) if( !$result = $db->sql_query($sql) )
{ {
message_die(GENERAL_ERROR, "Couldn't obtain smilies data", "", __LINE__, __FILE__, $sql); message_die(GENERAL_ERROR, "Couldn't obtain smilies data", "", __LINE__, __FILE__, $sql);
} }
$smilies = $db->sql_fetchrowset($result); $smilies = $db->sql_fetchrowset($result);
usort($smilies, 'smiley_sort'); usort($smilies, 'smiley_sort');
for($i = 0; $i < count($smilies); $i++) for($i = 0; $i < count($smilies); $i++)
{ {
$orig[] = "/(?<=.\W|\W.|^\W)" . phpbb_preg_quote($smilies[$i]['code'], "/") . "(?=.\W|\W.|\W$)/"; $orig[] = "/(?<=.\W|\W.|^\W)" . phpbb_preg_quote($smilies[$i]['code'], "/") . "(?=.\W|\W.|\W$)/";
$repl[] = '<img src="'. $board_config['smilies_path'] . '/' . $smilies[$i]['smile_url'] . '" alt="' . $smilies[$i]['smile_url'] . '" border="0" />'; $repl[] = '<img src="'. $board_config['smilies_path'] . '/' . $smilies[$i]['smile_url'] . '" alt="' . $smilies[$i]['smile_url'] . '" border="0" />';
} }
} }
if (count($orig)) if (count($orig))
{ {
$message = preg_replace($orig, $repl, ' ' . $message . ' '); $message = preg_replace($orig, $repl, ' ' . $message . ' ');
$message = substr($message, 1, -1); $message = substr($message, 1, -1);
} }
return $message; return $message;
} }
function smiley_sort($a, $b) function smiley_sort($a, $b)