הנה הפתרון שהגעתי אליו:
תעתיק את שתי הפונק' הללו:
קוד: בחר הכל
function bbencode_second_pass_code($text, $uid, $bbcode_tpl)
{
$code_start_html = $bbcode_tpl['code_open'];
$code_end_html = $bbcode_tpl['code_close'];
// First, do all the 1st-level matches. These need an htmlspecialchars() run,
// so they have to be handled differently.
$match_count = preg_match_all("#\[code:1:$uid\](.*?)\[/code:1:$uid\]#si", $text, $matches);
for ($i = 0; $i < $match_count; $i++)
{
$before_replace = $matches[1][$i];
$after_replace = $matches[1][$i];
// Replace 2 spaces with " " so non-tabbed code indents without making huge long lines.
$after_replace = str_replace(" ", " ", $after_replace);
// now Replace 2 spaces with " " to catch odd #s of spaces.
$after_replace = str_replace(" ", " ", $after_replace);
// Replace tabs with " " so tabbed code indents sorta right without making huge long lines.
$after_replace = str_replace("\t", " ", $after_replace);
// now Replace space occurring at the beginning of a line
$after_replace = preg_replace("/^ {1}/m", ' ', $after_replace);
$str_to_match = "[code:1:$uid]" . $before_replace . "[/code:1:$uid]";
$replacement = $code_start_html;
$replacement .= $after_replace;
$replacement .= $code_end_html;
$text = str_replace($str_to_match, $replacement, $text);
}
// Now, do all the non-first-level matches. These are simple.
$text = str_replace("[code:$uid]", $code_start_html, $text);
$text = str_replace("[/code:$uid]", $code_end_html, $text);
return $text;
}
function bbencode_second_pass($text, $uid)
{
$text = preg_replace('#(script|about|applet|activex|chrome):#is', "\\1:", $text);
// 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.
$text = " " . $text;
// First: If there isn't a "[" and a "]" in the message, don't bother.
if (! (strpos($text, "[") && strpos($text, "]")) )
{
// Remove padding, return.
$text = substr($text, 1);
return $text;
}
$bbcode_tpl['quote_open'] = '</div><div class="quote"><b>ציטוט:</b><br/>';
$bbcode_tpl['quote_close'] = '</div><div>';
$bbcode_tpl['quote_username_open'] = '</div><div class="quote"><b>\\1 כתב:</b><br/>';
$bbcode_tpl['ulist_open'] = '<ul class="help">';
$bbcode_tpl['listitem'] = '<li>';
$bbcode_tpl['ulist_close'] = '</ul>';
$bbcode_tpl['olist_close'] = '</ol>';
$bbcode_tpl['olist_open'] = '<ol type="\\1" class="help">';
$bbcode_tpl['color_open'] = '<span style="color: \\1">';
$bbcode_tpl['color_close'] = '</span>';
$bbcode_tpl['size_open'] = '<span style="font-size: \\1px; line-height: normal">';
$bbcode_tpl['size_close'] = '</span>';
$bbcode_tpl['b_open'] = '<span style="font-weight: bold">';
$bbcode_tpl['b_close'] = '</span>';
$bbcode_tpl['u_open'] = '<span style="text-decoration: underline">';
$bbcode_tpl['u_close'] = '</span>';
$bbcode_tpl['i_open'] = '<span style="font-style: italic">';
$bbcode_tpl['i_close'] = '</span>';
$bbcode_tpl['img'] = '<img src="\\1" border="0" alt=""/>';
$bbcode_tpl['url'] = '<a href="{URL}" target="_blank">{DESCRIPTION}</a>';
$bbcode_tpl['url1'] = str_replace('{URL}', '\\1', $bbcode_tpl['url']);
$bbcode_tpl['url1'] = str_replace('{DESCRIPTION}', '\\1', $bbcode_tpl['url1']);
$bbcode_tpl['url2'] = str_replace('{URL}', 'http://\\1', $bbcode_tpl['url']);
$bbcode_tpl['url2'] = str_replace('{DESCRIPTION}', '\\1', $bbcode_tpl['url2']);
$bbcode_tpl['url3'] = str_replace('{URL}', '\\1', $bbcode_tpl['url']);
$bbcode_tpl['url3'] = str_replace('{DESCRIPTION}', '\\2', $bbcode_tpl['url3']);
$bbcode_tpl['url4'] = str_replace('{URL}', 'http://\\1', $bbcode_tpl['url']);
$bbcode_tpl['url4'] = str_replace('{DESCRIPTION}', '\\3', $bbcode_tpl['url4']);
$bbcode_tpl['email'] = '<a href="mailto:\\1">\\1</a>';
$bbcode_tpl['code_open'] = '</div><div class="code">';
$bbcode_tpl['code_close'] = '</div><div>';
// [code] and [/code] for posting code (HTML, PHP, C etc etc) in your posts.
$text = bbencode_second_pass_code($text, $uid, $bbcode_tpl);
// [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_close'], $text);
// New one liner to deal with opening quotes with usernames...
// replaces the two line version that I had here before..
$text = preg_replace("/\[quote:$uid=\"(.*?)\"\]/si", $bbcode_tpl['quote_username_open'], $text);
// [list] and [list=x] for (un)ordered lists.
// unordered lists
$text = str_replace("[list:$uid]", $bbcode_tpl['ulist_open'], $text);
// li tags
$text = str_replace("[*:$uid]", $bbcode_tpl['listitem'], $text);
// ending tags
$text = str_replace("[/list:u:$uid]", $bbcode_tpl['ulist_close'], $text);
$text = str_replace("[/list:o:$uid]", $bbcode_tpl['olist_close'], $text);
// Ordered lists
$text = preg_replace("/\[list=([a1]):$uid\]/si", $bbcode_tpl['olist_open'], $text);
// colours
$text = preg_replace("/\[color=(\#[0-9A-F]{6}|[a-z]+):$uid\]/si", $bbcode_tpl['color_open'], $text);
$text = str_replace("[/color:$uid]", $bbcode_tpl['color_close'], $text);
// size
$text = preg_replace("/\[size=([1-2]?[0-9]):$uid\]/si", $bbcode_tpl['size_open'], $text);
$text = str_replace("[/size:$uid]", $bbcode_tpl['size_close'], $text);
// [b] and [/b] for bolding text.
$text = str_replace("[b:$uid]", $bbcode_tpl['b_open'], $text);
$text = str_replace("[/b:$uid]", $bbcode_tpl['b_close'], $text);
// [u] and [/u] for underlining text.
$text = str_replace("[u:$uid]", $bbcode_tpl['u_open'], $text);
$text = str_replace("[/u:$uid]", $bbcode_tpl['u_close'], $text);
// [i] and [/i] for italicizing text.
$text = str_replace("[i:$uid]", $bbcode_tpl['i_open'], $text);
$text = str_replace("[/i:$uid]", $bbcode_tpl['i_close'], $text);
// Patterns and replacements for URL and email tags..
$patterns = array();
$replacements = array();
// [img]image_url_here[/img] code..
// This one gets first-passed..
$patterns[] = "#\[img:$uid\]([^?].*?)\[/img:$uid\]#i";
$replacements[] = $bbcode_tpl['img'];
// matches a [url]xxxx://www.phpbb.com[/url] code..
$patterns[] = "#\[url\]([\w]+?://[\w\#$%&~/.\-;:=,?@\[\]+]*?)\[/url\]#is";
$replacements[] = $bbcode_tpl['url1'];
// [url]www.phpbb.com[/url] code.. (no xxxx:// prefix).
$patterns[] = "#\[url\]((www|ftp)\.[\w\#$%&~/.\-;:=,?@\[\]+]*?)\[/url\]#is";
$replacements[] = $bbcode_tpl['url2'];
// [url=xxxx://www.phpbb.com]phpBB[/url] code..
$patterns[] = "#\[url=([\w]+?://[\w\#$%&~/.\-;:=,?@\[\]+]*?)\]([^?\n\r\t].*?)\[/url\]#is";
$replacements[] = $bbcode_tpl['url3'];
// [url=www.phpbb.com]phpBB[/url] code.. (no xxxx:// prefix).
$patterns[] = "#\[url=((www|ftp)\.[\w\#$%&~/.\-;:=,?@\[\]+]*?)\]([^?\n\r\t].*?)\[/url\]#is";
$replacements[] = $bbcode_tpl['url4'];
// [email][email protected][/email] code..
$patterns[] = "#\[email\]([a-z0-9&\-_.]+?@[\w\-]+\.([\w\-\.]+\.)?[\w]+)\[/email\]#si";
$replacements[] = $bbcode_tpl['email'];
$text = preg_replace($patterns, $replacements, $text);
// Remove our padding from the string..
$text = substr($text, 1);
return $text;
}
ואחר כך תעביר את הטקסט דרך הפונ' באופן הבא:
קוד: בחר הכל
bbencode_second_pass($text, $data['bbcode_uid']);
(שים לב שאתה צריך לשלוף ממסד הנתונים את ה-bbcode_uid של ההודעה בנוסף לטקסט של ההודעה).
אצלי זה עבד, מקווה שגם אצלך זה יעבוד.
בהצלחה