function MyBBCode_php_second_pass($text, $uid)
{
    global $lang;
    $templates = load_bbcode_template();
    /* Below code taken from bbencode_second_pass() */
    // [CODE] and [/CODE] for posting code (HTML, PHP, C etc etc) in your posts.
    $code_start_html = str_replace('{L_CODE}', 'PHP ' . $lang['Code'], $templates['code_open']);
    $code_end_html = $templates['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("#\\[php:1:{$uid}\\](.*?)\\[/php: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 "&nbsp; " so non-tabbed code indents without making huge long lines.
        $after_replace = str_replace("  ", "&nbsp; ", MyBBCode_Highlight_PHP_string($after_replace));
        // now Replace 2 spaces with " &nbsp;" to catch odd #s of spaces.
        $after_replace = str_replace("  ", " &nbsp;", $after_replace);
        // 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);
        // now Replace space occurring at the beginning of a line
        $after_replace = preg_replace("/^ {1}/m", '&nbsp;', $after_replace);
        $str_to_match = "[php:1:{$uid}]" . $before_replace . "[/php:1:{$uid}]";
        $replacement = $code_start_html;
        $replacement .= $after_replace;
        $replacement .= $code_end_html;
        $text = str_replace($str_to_match, $replacement, $text);
    }
    preg_match_all("/\\[php:{$uid}\\](.*)\\[\\/php:{$uid}\\]/si", $text, $matches);
    for ($i = 0; $i < count($matches[1]); $i++) {
        $highlight = MyBBCode_Highlight_PHP_string($matches[1][$i]);
        $text = str_replace("[php:{$uid}]" . $matches[1][$i] . "[/php:{$uid}]", $code_start_html . $highlight . $code_end_html, $text);
    }
    return $text;
}
Пример #2
0
/**
 * 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
 * correct UID as used in first-pass encoding.
 */
function bbencode_second_pass($text, $uid)
{
    global $lang, $bbcode_tpl;
    $text = preg_replace('#(script|about|applet|activex|chrome):#is', "\\1&#058;", $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;
    }
    // Only load the templates ONCE..
    if (!defined("BBCODE_TPL_READY")) {
        // load templates from file into array.
        $bbcode_tpl = load_bbcode_template();
        // prepare array for use in regexps.
        $bbcode_tpl = prepare_bbcode_template($bbcode_tpl);
    }
    // [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}\\]([^?](?:[^\\[]+|\\[(?!url))*?)\\[/img:{$uid}\\]#i";
    $replacements[] = $bbcode_tpl['img'];
    // matches a [url]xxxx://www.phpbb.com[/url] code..
    $patterns[] = "#\\[url\\]([\\w]+?://([\\w\\#\$%&~/.\\-;:=,?@\\]+]+|\\[(?!url=))*?)\\[/url\\]#is";
    $replacements[] = $bbcode_tpl['url1'];
    // [url]www.phpbb.com[/url] code.. (no xxxx:// prefix).
    $patterns[] = "#\\[url\\]((www|ftp)\\.([\\w\\#\$%&~/.\\-;:=,?@\\]+]+|\\[(?!url=))*?)\\[/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]user@domain.tld[/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;
}
Пример #3
0
<?php

if (!defined('IN_PHPBB')) {
    die("Hacking attempt");
}
// global that holds loaded-and-prepared bbcode templates, so we only have to do
// that stuff once.
global $bbcode_tpl;
$bbcode_tpl = prepare_bbcode_template(load_bbcode_template());
/**
 * Loads bbcode templates from the bbcode.tpl file of the current template set.
 * Creates an array, keys are bbcode names like "b_open" or "url", values
 * are the associated template.
 * Probably pukes all over the place if there's something really screwed
 * with the bbcode.tpl file.
 *
 * Nathan Codding, Sept 26 2001.
 */
function load_bbcode_template()
{
    $codes = MyBBCode_GetCodes();
    for ($i = 0; $i < count($codes); $i++) {
        $bbcode_tpl[($codes[$i]['tag'] ? $codes[$i]['tag'] : $codes[$i]['open_tag']) . '_open'] = $codes[$i]['tag_open'];
        $bbcode_tpl[($codes[$i]['tag'] ? $codes[$i]['tag'] : $codes[$i]['open_tag']) . '_close'] = $codes[$i]['tag_close'];
    }
    return $bbcode_tpl;
}
/**
 * Prepares the loaded bbcode templates for insertion into preg_replace()
 * or str_replace() calls in the bbencode_second_pass functions. This
 * means replacing template placeholders with the appropriate preg backrefs
Пример #4
0
/**
 * 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 
 * correct UID as used in first-pass encoding.
 */
function bbencode_second_pass($text, $uid)
{
	global $lang, $bbcode_tpl;

	// 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;
	}
	
	// Only load the templates ONCE..
	if (!defined("BBCODE_TPL_READY"))
	{
		// load templates from file into array.
		$bbcode_tpl = load_bbcode_template();
		
		// prepare array for use in regexps.
		$bbcode_tpl = prepare_bbcode_template($bbcode_tpl);
	}

	// [CODE] and [/CODE] for posting code (HTML, PHP, C etc etc) in your posts.
	$text = bbencode_second_pass_code($text, $uid, $bbcode_tpl);

	// [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);

	// [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);

	// [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[0] = "#\[img:$uid\](.*?)\[/img:$uid\]#si";
	$replacements[0] = $bbcode_tpl['img'];
	
	// [url]xxxx://www.phpbb.com[/url] code..
	$patterns[1] = "#\[url\]([a-z]+?://){1}([a-z0-9\-\.,\?!%\*_\#:;~\\&$@\/=\+\(\)]+)\[/url\]#si";
	$replacements[1] = $bbcode_tpl['url1'];

	// [url]www.phpbb.com[/url] code.. (no xxxx:// prefix).
	$patterns[2] = "#\[url\]([a-z0-9\-\.,\?!%\*_\#:;~\\&$@\/=\+\(\)]+)\[/url\]#si";
	$replacements[2] = $bbcode_tpl['url2'];

	// [url=xxxx://www.phpbb.com]phpBB[/url] code..
	$patterns[3] = "#\[url=([a-z]+?://){1}([a-z0-9\-\.,\?!%\*_\#:;~\\&$@\/=\+\(\)]+)\](.*?)\[/url\]#si";
	$replacements[3] = $bbcode_tpl['url3'];

	// [url=www.phpbb.com]phpBB[/url] code.. (no xxxx:// prefix).
	$patterns[4] = "#\[url=([a-z0-9\-\.,\?!%\*_\#:;~\\&$@\/=\+\(\)]+)\](.*?)\[/url\]#si";
	$replacements[4] = $bbcode_tpl['url4'];

	// [email]user@domain.tld[/email] code..
	$patterns[5] = "#\[email\]([a-z0-9\-_.]+?@[\w\-]+\.([\w\-\.]+\.)?[\w]+)\[/email\]#si";
	$replacements[5] = $bbcode_tpl['email'];

	$text = preg_replace($patterns, $replacements, $text);

	// Remove our padding from the string..
	$text = substr($text, 1);

	return $text;

} // bbencode_second_pass()
Пример #5
0
/**
 * 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
 * correct UID as used in first-pass encoding.
 */
function bbencode_second_pass($text, $uid)
{
    global $lang, $bbcode_tpl;
    // 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;
    }
    // Only load the templates ONCE..
    if (!defined('BBCODE_TPL_READY')) {
        // load templates from file into array.
        $bbcode_tpl = load_bbcode_template();
        // prepare array for use in regexps.
        $bbcode_tpl = prepare_bbcode_template($bbcode_tpl);
    }
    // [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);
    // opening a quote with an pre-defined post entry
    $text = preg_replace("/\\[quote:{$uid}=p=\"([0-9]+)\"\\]/si", $bbcode_tpl['quote_post_open'], $text);
    // opening a username quote with an pre-defined post entry
    $text = preg_replace("/\\[quote:{$uid}=(?:\"?([^\"]*)\"?);p=(?:\"?([0-9]+)\"?)\\]/si", $bbcode_tpl['quote_username_post_open'], $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);
    /* BEGIN CMX ACRONYM MOD */
    // acronym
    $text = preg_replace("/\\[acronym:{$uid}=\"(.*?)\"\\]/si", $bbcode_tpl['acronym_open'], $text);
    $text = str_replace("[/acronym:{$uid}]", $bbcode_tpl['acronym_close'], $text);
    /* END CMX ACRONYM MOD */
    // [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);
    // Table-cell start
    $text = str_replace("[table:{$uid}]", $bbcode_tpl['table_open'], $text);
    $text = str_replace("[/table:{$uid}]", $bbcode_tpl['table_close'], $text);
    // Table-cell end
    // 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);
    // font (note: The font=(.*?) is needed for Non-Western font names)
    $text = preg_replace("/\\[font=(.*?):{$uid}\\]/si", $bbcode_tpl['font_open'], $text);
    $text = str_replace("[/font:{$uid}]", $bbcode_tpl['font_close'], $text);
    // BEGIN Align BBcode MOD
    $text = preg_replace("/\\[align=(left|right|center|justify):{$uid}\\]/si", $bbcode_tpl['align_open'], $text);
    $text = str_replace("[/align:{$uid}]", $bbcode_tpl['align_close'], $text);
    // END Align BBcode MOD
    // [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);
    // [tab] for inserting tabs.
    $text = str_replace("[tab:{$uid}]", $bbcode_tpl['tab'], $text);
    // [break] for breaking news headline from full details.
    // $text = str_replace("[break:$uid]", $bbcode_tpl['break'], $text);
    // [strike] and [/strike] for barring text.
    $text = str_replace("[strike:{$uid}]", $bbcode_tpl['strike_open'], $text);
    $text = str_replace("[/strike:{$uid}]", $bbcode_tpl['strike_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);
    // [spoiler] and [/spoiler] for spoiler-text
    $text = str_replace("[spoiler:{$uid}]", $bbcode_tpl['spoiler_open'], $text);
    $text = str_replace("[/spoiler:{$uid}]", $bbcode_tpl['spoiler_close'], $text);
    // Patterns and replacements for URL and email tags..
    $patterns = array();
    $replacements = array();
    // MOD LOCAL URL BEGIN
    $server_name = preg_replace('#^\\/?(.*?)\\/?$#', '\\1', trim($GLOBALS['board_config']['server_name']));
    // do any local urls first...
    // [url]xxxx://www.phpbb.com[/url] code..
    $local_patterns[1] = "#\\[url\\]([a-z]+?://){1}(" . $server_name . ")([a-z0-9\\-\\.,\\?!%\\*_\\#:;~\\&\$@\\/=\\+]*)\\[/url\\]#si";
    $local_replacements[1] = $bbcode_tpl['url_local1'];
    // [url]www.phpbb.com[/url] code.. (no xxxx:// prefix).
    $local_patterns[2] = "#\\[url\\](" . $server_name . ")([a-z0-9\\-\\.,\\?!%\\*_\\#:;~\\&\$@\\/=\\+]*)\\[/url\\]#si";
    $local_replacements[2] = $bbcode_tpl['url_local2'];
    // [url=xxxx://www.phpbb.com]phpBB[/url] code..
    $local_patterns[3] = "#\\[url=([a-z]+?://){1}(" . $server_name . ")([a-z0-9\\-\\.,\\?!%\\*_\\#:;~\\&\$@\\/=\\+]*)\\](.*?)\\[/url\\]#si";
    $local_replacements[3] = $bbcode_tpl['url_local3'];
    // [url=www.phpbb.com]phpBB[/url] code.. (no xxxx:// prefix).
    $local_patterns[4] = "#\\[url=(" . $server_name . ")([a-z0-9\\-\\.,\\?!%\\*_\\#:;~\\&\$@\\/=\\+]*)\\](.*?)\\[/url\\]#si";
    $local_replacements[4] = $bbcode_tpl['url_local4'];
    $text = preg_replace($local_patterns, $local_replacements, $text);
    // now with the local urls done, it's safe to do any external urls
    // MOD LOCAL URL END
    // [img]image_url_here[/img] code..
    // This one gets first-passed..
    $patterns[] = "#\\[img:{$uid}\\](.*?)\\[/img:{$uid}\\]#si";
    $replacements[] = $bbcode_tpl['img'];
    // Table-cell start
    $patterns[] = "#\\[([0-9]{1,2}):{$uid}\\](.*?)(\\[\\;\\])#si";
    $replacements[] = $bbcode_tpl['cell'];
    // Table-cell end
    // matches a [url]xxxx://www.phpbb.com[/url] code..
    $patterns[] = "#\\[url\\]([\\w]+?://[^ \"\n\r\t<]*?)\\[/url\\]#is";
    $replacements[] = $bbcode_tpl['url1'];
    // [url]www.phpbb.com[/url] code.. (no xxxx:// prefix).
    $patterns[] = "#\\[url\\]((www|ftp)\\.[^ \"\n\r\t<]*?)\\[/url\\]#is";
    $replacements[] = $bbcode_tpl['url2'];
    // [url=xxxx://www.phpbb.com]phpBB[/url] code..
    $patterns[] = "#\\[url=([\\w]+?://[^ \"\n\r\t<]*?)\\](.*?)\\[/url\\]#is";
    $replacements[] = $bbcode_tpl['url3'];
    // [url=www.phpbb.com]phpBB[/url] code.. (no xxxx:// prefix).
    $patterns[] = "#\\[url=((www|ftp)\\.[^ \"\n\r\t<]*?)\\](.*?)\\[/url\\]#is";
    $replacements[] = $bbcode_tpl['url4'];
    // [email]user@domain.tld[/email] code..
    $patterns[] = "#\\[email\\]([a-z0-9&\\-_.]+?@[\\w\\-]+\\.([\\w\\-\\.]+\\.)?[\\w]+)\\[/email\\]#si";
    $replacements[] = $bbcode_tpl['email'];
    // [google]string for search[/google] code..
    $patterns[] = "#\\[google\\](.*?)\\[/google\\]#ise";
    $replacements[] = $bbcode_tpl['google'];
    // Custom BBCodes Mod
    static $bbcodes, $replaces;
    if (!isset($bbcodes) || !isset($replaces)) {
        global $db;
        $sql = 'SELECT bbcode_params, bbcode_code, bbcode_replace FROM ' . BBCODES_TABLE;
        if ($result = $db->sql_query($sql)) {
            if ($db->sql_numrows($result) >= 1) {
                while ($bbcode = $db->sql_fetchrow($result)) {
                    if ($bbcode['bbcode_params'] == '=') {
                        $tag = '/\\[' . $bbcode['bbcode_code'] . '=(.*?):' . $uid . '\\](.*?)\\[\\/' . $bbcode['bbcode_code'] . ':' . $uid . '\\]/si';
                    } else {
                        $params = explode(',', $bbcode['bbcode_params']);
                        for ($x = 0, $tag = '/\\[' . $bbcode['bbcode_code']; $x < count($params); $x++) {
                            if (empty($params[$x])) {
                                break;
                            }
                            $tag .= ' ' . $params[$x] . '=(.*?)';
                        }
                        $tag .= ':' . $uid . '\\](.*?)\\[\\/' . $bbcode['bbcode_code'] . ':' . $uid . '\\]/si';
                    }
                    $bbcodes[] = str_replace($uid, '%s', $tag);
                    $replaces[] = $bbcode['bbcode_replace'];
                    $text = preg_replace($tag, $bbcode['bbcode_replace'], $text);
                }
            }
        }
    } else {
        if (isset($bbcodes) && isset($replaces)) {
            for ($x = 0, $max = count($bbcodes); $x < $max; $x++) {
                $text = preg_replace(sprintf($bbcodes[$x], $uid, $uid), $replaces[$x], $text);
            }
        }
    }
    // End - Custom BBCode
    $text = preg_replace($patterns, $replacements, $text);
    // Remove our padding from the string..
    $text = substr($text, 1);
    return $text;
}
Пример #6
0
/**
 * 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
 * correct UID as used in first-pass encoding.
 */
function bbencode_second_pass($text, $uid)
{
    global $lang, $bbcode_tpl;
    //
    // Begin Syntax Highlighting Mod
    //
    global $board_config;
    //
    // End Syntax Highlighting Mod
    //
    $text = preg_replace('#(script|about|applet|activex|chrome):#is', "\\1&#058;", $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;
    }
    // Only load the templates ONCE..
    if (!defined("BBCODE_TPL_READY")) {
        // load templates from file into array.
        $bbcode_tpl = load_bbcode_template();
        // prepare array for use in regexps.
        $bbcode_tpl = prepare_bbcode_template($bbcode_tpl);
    }
    // [CODE] and [/CODE] for posting code (HTML, PHP, C etc etc) in your posts.
    $text = bbencode_second_pass_code($text, $uid, $bbcode_tpl);
    //
    // Begin Syntax Highlighting Mod
    //
    // [SYNTAX="language"] and [/SYNTAX] for posting syntax highlighted code
    // @todo Take into account user preferences
    // @todo Maybe use U modifier to prevent nesting problems?
    // @todo Maybe problem with geshi_highlight function name?
    // @todo Take into account the parse as code possibility?
    if ($board_config['syntax_status'] != SYNTAX_NO_PARSE) {
        $text = preg_replace("/\\[syntax:{$uid}=\"?([a-zA-Z0-9\\-_\\+\\#\$\\%]+)\"?\\](.*?)\\[\\/syntax:{$uid}\\]/sie", "'{$bbcode_tpl['syntax_open']}' . geshi_highlight('\\2', '\\1', '{$uid}') . '{$bbcode_tpl['syntax_close']}'", $text);
    } else {
        $text = preg_replace("/\\[syntax:{$uid}=(\"?[a-zA-Z0-9\\-_\\+\\#\$\\%]+\"?)\\](.*?)\\[\\/syntax:{$uid}\\]/si", "[syntax=\\1]\\2[/syntax]", $text);
    }
    //
    // End Syntax Highlighting Mod
    //
    // [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]user@domain.tld[/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;
}