1
0
mirror of https://github.com/phpbb/phpbb.git synced 2025-05-06 15:45:34 +02:00

Various updates and alterations

git-svn-id: file:///svn/phpbb/trunk@2669 89ea8834-ac86-4346-8a33-228a782c2dd0
This commit is contained in:
Paul S. Owen 2002-07-14 14:41:12 +00:00
parent f212a877c4
commit 044f82dbd7

View File

@ -21,10 +21,10 @@
if ( !defined('IN_PHPBB') ) if ( !defined('IN_PHPBB') )
{ {
die("Hacking attempt"); die('Hacking attempt');
} }
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.
@ -43,7 +43,7 @@ $bbcode_tpl = null;
function load_bbcode_template() function load_bbcode_template()
{ {
global $template; global $template;
$tpl_filename = $template->make_filename('bbcode.tpl'); $tpl_filename = $template->make_filename('bbcode.html');
$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 \'.
@ -109,7 +109,7 @@ function prepare_bbcode_template($bbcode_tpl)
$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;
} }
@ -120,16 +120,16 @@ function prepare_bbcode_template($bbcode_tpl)
* 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, $enable_img = true)
{ {
global $lang, $bbcode_tpl; global $acl, $board_config, $lang, $bbcode_tpl;
// pad it with a space so we can distinguish between FALSE and matching the 1st char (index 0). // pad it with a space so we can distinguish between FALSE and matching the 1st char (index 0).
// This is important; bbencode_quote(), bbencode_list(), and bbencode_code() all depend on it. // This is important; bbencode_quote(), bbencode_list(), and bbencode_code() all depend on it.
$text = " " . $text; $text = ' ' . $text;
// First: If there isn't a "[" and a "]" in the message, don't bother. // First: If there isn't a "[" and a "]" in the message, don't bother.
if (! (strpos($text, "[") && strpos($text, "]")) ) if (! (strpos($text, '[') && strpos($text, ']')) )
{ {
// Remove padding, return. // Remove padding, return.
$text = substr($text, 1); $text = substr($text, 1);
@ -137,7 +137,7 @@ function bbencode_second_pass($text, $uid)
} }
// 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();
@ -194,8 +194,11 @@ 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..
if ( $enable_img )
{
$patterns[0] = "#\[img:$uid\](.*?)\[/img:$uid\]#si"; $patterns[0] = "#\[img:$uid\](.*?)\[/img:$uid\]#si";
$replacements[0] = $bbcode_tpl['img']; $replacements[0] = $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[1] = "#\[url\]([a-z]+?://){1}([a-z0-9\-\.,\?!%\*_\#:;~\\&$@\/=\+]+)\[/url\]#si";
@ -226,13 +229,13 @@ function bbencode_second_pass($text, $uid)
} // bbencode_second_pass() } // bbencode_second_pass()
// Need to initialize the random numbers only ONCE
mt_srand( (double) microtime() * 1000000);
function make_bbcode_uid() function make_bbcode_uid()
{ {
// Unique ID for this message.. // Need to initialize the random numbers only ONCE
mt_srand( (double) microtime() * 1000000);
// Unique ID for this message..
$uid = md5(mt_rand()); $uid = md5(mt_rand());
$uid = substr($uid, 0, BBCODE_UID_LEN); $uid = substr($uid, 0, BBCODE_UID_LEN);
@ -243,7 +246,7 @@ function bbencode_first_pass($text, $uid)
{ {
// pad it with a space so we can distinguish between FALSE and matching the 1st char (index 0). // pad it with a space so we can distinguish between FALSE and matching the 1st char (index 0).
// This is important; bbencode_quote(), bbencode_list(), and bbencode_code() all depend on it. // This is important; bbencode_quote(), bbencode_list(), and bbencode_code() all depend on it.
$text = " " . $text; $text = ' ' . $text;
// [CODE] and [/CODE] for posting code (HTML, PHP, C etc etc) in your posts. // [CODE] and [/CODE] for posting code (HTML, PHP, C etc etc) in your posts.
$text = bbencode_first_pass_pda($text, $uid, '[code]', '[/code]', '', true, ''); $text = bbencode_first_pass_pda($text, $uid, '[code]', '[/code]', '', true, '');
@ -255,16 +258,16 @@ function bbencode_first_pass($text, $uid)
// [list] and [list=x] for (un)ordered lists. // [list] and [list=x] for (un)ordered lists.
$open_tag = array(); $open_tag = array();
$open_tag[0] = "[list]"; $open_tag[0] = '[list]';
// unordered.. // unordered..
$text = bbencode_first_pass_pda($text, $uid, $open_tag, "[/list]", "[/list:u]", false, 'replace_listitems'); $text = bbencode_first_pass_pda($text, $uid, $open_tag, '[/list]', '[/list:u]', false, 'replace_listitems');
$open_tag[0] = "[list=1]"; $open_tag[0] = '[list=1]';
$open_tag[1] = "[list=a]"; $open_tag[1] = '[list=a]';
// ordered. // ordered.
$text = bbencode_first_pass_pda($text, $uid, $open_tag, "[/list]", "[/list:o]", false, 'replace_listitems'); $text = bbencode_first_pass_pda($text, $uid, $open_tag, '[/list]', '[/list:o]', false, 'replace_listitems');
// [color] and [/color] for setting text color // [color] and [/color] for setting text color
$text = preg_replace("#\[color=(\#[0-9A-F]{6}|[a-z\-]+)\](.*?)\[/color\]#si", "[color=\\1:$uid]\\2[/color:$uid]", $text); $text = preg_replace("#\[color=(\#[0-9A-F]{6}|[a-z\-]+)\](.*?)\[/color\]#si", "[color=\\1:$uid]\\2[/color:$uid]", $text);
@ -287,7 +290,6 @@ function bbencode_first_pass($text, $uid)
// Remove our padding from the string.. // Remove our padding from the string..
$text = substr($text, 1); $text = substr($text, 1);
return $text; return $text;
} // bbencode_first_pass() } // bbencode_first_pass()
@ -745,24 +747,20 @@ function smilies_pass($message)
{ {
$sql = "SELECT code, smile_url $sql = "SELECT code, smile_url
FROM " . SMILIES_TABLE; FROM " . SMILIES_TABLE;
if( !$result = $db->sql_query($sql) ) $result = $db->sql_query($sql);
{
message_die(GENERAL_ERROR, "Couldn't obtain smilies data", "", __LINE__, __FILE__, $sql);
}
if( !$db->sql_numrows($result) ) if ( !($smilies = $db->sql_fetchrowset($result)) )
{ {
return $message; return $message;
} }
$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)' . 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'] . '" width="' . $smilies[$i]['smile_width'] . '" height="' . $smilies[$i]['smile_height'] . '" alt="' . $smilies[$i]['smile_url'] . '" title="' . $smilies[$i]['smile_url'] . '" border="0" />';
} }
if ( $i > 0 ) if ( $i > 0 )
@ -784,5 +782,4 @@ function smiley_sort($a, $b)
return ( strlen($a['code']) > strlen($b['code']) ) ? - 1 : 1; return ( strlen($a['code']) > strlen($b['code']) ) ? - 1 : 1;
} }
?> ?>