Example #1
0
function bbencode_first_pass($text, $uid)
{
    // 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;
    // [CODE] and [/CODE] for posting code (HTML, PHP, C etc etc) in your posts.
    $text = bbencode_first_pass_pda($text, $uid, '[code]', '[/code]', '', true, '');
    // [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=\\\\"(.*?)\\\\"\\]/is', '[/quote]', '', false, '', "[quote:{$uid}=\\\"\\1\\\"]");
    // [list] and [list=x] for (un)ordered lists.
    $open_tag = array();
    $open_tag[0] = "[list]";
    // unordered..
    $text = bbencode_first_pass_pda($text, $uid, $open_tag, "[/list]", "[/list:u]", false, 'replace_listitems');
    $open_tag[0] = "[list=1]";
    $open_tag[1] = "[list=a]";
    // ordered.
    $text = bbencode_first_pass_pda($text, $uid, $open_tag, "[/list]", "[/list:o]", false, 'replace_listitems');
    // [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);
    // [size] and [/size] for setting text size
    $text = preg_replace("#\\[size=([1-2]?[0-9])\\](.*?)\\[/size\\]#si", "[size=\\1:{$uid}]\\2[/size:{$uid}]", $text);
    // [b] and [/b] for bolding text.
    $text = preg_replace("#\\[b\\](.*?)\\[/b\\]#si", "[b:{$uid}]\\1[/b:{$uid}]", $text);
    // [u] and [/u] for underlining text.
    $text = preg_replace("#\\[u\\](.*?)\\[/u\\]#si", "[u:{$uid}]\\1[/u:{$uid}]", $text);
    // [i] and [/i] for italicizing text.
    $text = preg_replace("#\\[i\\](.*?)\\[/i\\]#si", "[i:{$uid}]\\1[/i:{$uid}]", $text);
    // [img]image_url_here[/img] code..
    // Begin PNphpBB2 Module
    //	$text = preg_replace("#\[img\]((http|ftp|https|ftps)://)([^ \?&=\#\"\n\r\t<]*?(\.(jpg|jpeg|gif|png)))\[/img\]#sie", "'[img:$uid]\\1' . str_replace(' ', '%20', '\\3') . '[/img:$uid]'", $text);
    $text = preg_replace("#\\[img\\]((http|ftp|https|ftps)://)([^ \\?&=\\#\"\n\r\t<]*?(\\.(jpe|jpg|jpeg|gif|png)))\\[/img\\]#sie", "'[img:{$uid}]\\1' . str_replace(' ', '%20', '\\3') . '[/img:{$uid}]'", $text);
    // End PNphpBB2 Module
    // Remove our padding from the string..
    return substr($text, 1);
}
Example #2
0
function bbencode_first_pass($text, $uid)
{
    // 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;
    // [CODE] and [/CODE] for posting code (HTML, PHP, C etc etc) in your posts.
    $text = bbencode_first_pass_pda($text, $uid, '[code]', '[/code]', '', true, '');
    // [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=(\\\\".*?\\\\")\\]/is', '[/quote]', '', false, '', "[quote:{$uid}=\\1]");
    // [SPOILER]
    $text = bbencode_first_pass_pda($text, $uid, '[spoiler]', '[/spoiler]', '', false, '');
    $text = bbencode_first_pass_pda($text, $uid, '/\\[spoiler=(.*?)\\]/is', '[/spoiler]', '', false, '', "[spoiler:{$uid}=\\1]");
    // [list] and [list=x] for (un)ordered lists.
    $open_tag = array();
    $open_tag[0] = "[list]";
    // unordered..
    $text = bbencode_first_pass_pda($text, $uid, $open_tag, "[/list]", "[/list:u]", false, 'replace_listitems');
    $open_tag[0] = "[list=1]";
    $open_tag[1] = "[list=a]";
    // ordered.
    $text = bbencode_first_pass_pda($text, $uid, $open_tag, "[/list]", "[/list:o]", false, 'replace_listitems');
    // [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);
    // [size] and [/size] for setting text size
    $text = preg_replace("#\\[size=([1-2]?[0-9])\\](.*?)\\[/size\\]#si", "[size=\\1:{$uid}]\\2[/size:{$uid}]", $text);
    // [align] and [/align] for text align
    $text = preg_replace("#\\[align=(left|right|center|justify)\\](.*?)\\[/align\\]#si", "[align=\\1:{$uid}]\\2[/align:{$uid}]", $text);
    // [font] and [/font] for setting font style
    $text = bbencode_first_pass_pda($text, $uid, '#\\[font=(\\\\"(.*?)\\\\")\\]#is', '[/font]', '', false, '', "[font:{$uid}=\\1]");
    // [b] and [/b] for bolding text.
    $text = preg_replace("#\\[b\\](.*?)\\[/b\\]#si", "[b:{$uid}]\\1[/b:{$uid}]", $text);
    // [u] and [/u] for underlining text.
    $text = preg_replace("#\\[u\\](.*?)\\[/u\\]#si", "[u:{$uid}]\\1[/u:{$uid}]", $text);
    // [i] and [/i] for italicizing text.
    $text = preg_replace("#\\[i\\](.*?)\\[/i\\]#si", "[i:{$uid}]\\1[/i:{$uid}]", $text);
    // [img]image_url_here[/img] code..
    $text = preg_replace("#\\[img\\]((http|ftp|https|ftps)://)([^ \\?&=\\#\"\n\r\t<]*?(\\.(jpg|jpeg|gif|png)))\\[/img\\]#sie", "'[img:{$uid}]\\1' . str_replace(' ', '%20', '\\3') . '[/img:{$uid}]'", $text);
    // LEFT-RIGHT-start
    $text = preg_replace("#\\[img=left\\]((ht|f)tp://)([^\r\n\t<\"]*?)\\[/img\\]#sie", "'[img=left:{$uid}]\\1' . str_replace(' ', '%20', '\\3') . '[/img:{$uid}]'", $text);
    $text = preg_replace("#\\[img=right\\]((ht|f)tp://)([^\r\n\t<\"]*?)\\[/img\\]#sie", "'[img=right:{$uid}]\\1' . str_replace(' ', '%20', '\\3') . '[/img:{$uid}]'", $text);
    // LEFT-RIGHT-end
    // [img=left]image_url_here[/img] code.. and [img=right]image_url_here[/img] code..
    $text = preg_replace("#\\[img=(left|right)\\]((http|ftp|https|ftps)://)([^\\s\\?&=\\#\"<>]+?(\\.(jpg|jpeg|gif|png)))\\[/img\\]#i", "[img=\\1:{$uid}]\\2\\4[/img:{$uid}]", $text);
    // Remove our padding from the string..
    return substr($text, 1);
}
Example #3
0
function bbencode_first_pass($text, $uid)
{
    // 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;
    // [CODE] and [/CODE] for posting code (HTML, PHP, C etc etc) in your posts.
    $text = bbencode_first_pass_pda($text, $uid, '[code]', '[/code]', '', true, '');
    // [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=(\\\\"[^"]*?\\\\")\\]/is', '[/quote]', '', false, '', "[quote:{$uid}=\\1]");
    // [list] and [list=x] for (un)ordered lists.
    $open_tag = array();
    $open_tag[0] = "[list]";
    // unordered..
    $text = bbencode_first_pass_pda($text, $uid, $open_tag, "[/list]", "[/list:u]", false, 'replace_listitems');
    $open_tag[0] = "[list=1]";
    $open_tag[1] = "[list=a]";
    // ordered.
    $text = bbencode_first_pass_pda($text, $uid, $open_tag, "[/list]", "[/list:o]", false, 'replace_listitems');
    // [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);
    // [size] and [/size] for setting text size
    $text = preg_replace("#\\[size=([\\-\\+]?[1-2]?[0-9])\\](.*?)\\[/size\\]#si", "[size=\\1:{$uid}]\\2[/size:{$uid}]", $text);
    // [b] and [/b] for bolding text.
    $text = preg_replace("#\\[b\\](.*?)\\[/b\\]#si", "[b:{$uid}]\\1[/b:{$uid}]", $text);
    // [u] and [/u] for underlining text.
    $text = preg_replace("#\\[u\\](.*?)\\[/u\\]#si", "[u:{$uid}]\\1[/u:{$uid}]", $text);
    // [i] and [/i] for italicizing text.
    $text = preg_replace("#\\[i\\](.*?)\\[/i\\]#si", "[i:{$uid}]\\1[/i:{$uid}]", $text);
    // [img]image_url_here[/img] code..
    $text = preg_replace("#\\[img\\](http(s)?://)([a-z0-9\\-\\.,\\?!%\\*_\\#:;~\\&\$@\\/=\\+]+)\\[/img\\]#si", "[img:{$uid}]\\1\\3[/img:{$uid}]", $text);
    // Remove our padding from the string..
    $text = substr($text, 1);
    return $text;
}
Example #4
0
function bbencode_first_pass($text, $uid)
{
    // 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;
    // [CODE] and [/CODE] for posting code (HTML, PHP, C etc etc) in your posts.
    $text = bbencode_first_pass_pda($text, $uid, '[code]', '[/code]', '', true, '');
    // [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=(\\\\".*?\\\\")\\]/is', '[/quote]', '', false, '', "[quote:{$uid}=\\1]");
    // [QUOTE] and [/QUOTE] for posting replies with quote, or just for quoting stuff with an pre-defined post entry
    $text = bbencode_first_pass_pda($text, $uid, '/\\[quote=p=(\\\\"[0-9]+\\\\")\\]/is', '[/quote]', '', false, '', "[quote:{$uid}=p=\\1]");
    $text = bbencode_first_pass_pda($text, $uid, '/\\[quote=(\\\\"[^"]*?\\\\");p=(\\\\"[0-9]+\\\\")\\]/is', '[/quote]', '', false, '', "[quote:{$uid}=\\1;p=\\2]");
    /* BEGIN CMX ACRONYM MOD */
    // [acronym] and [/acronym]
    $text = bbencode_first_pass_pda($text, $uid, '/\\[acronym=(\\\\".*?\\\\")\\]/is', '[/acronym]', '', false, '', "[acronym:{$uid}=\\1]");
    /* END CMX ACRONYM MOD */
    // [list] and [list=x] for (un)ordered lists.
    $open_tag = array();
    $open_tag[0] = '[list]';
    // unordered..
    $text = bbencode_first_pass_pda($text, $uid, $open_tag, '[/list]', '[/list:u]', false, 'replace_listitems');
    $open_tag[0] = '[list=1]';
    $open_tag[1] = '[list=a]';
    // ordered.
    $text = bbencode_first_pass_pda($text, $uid, $open_tag, '[/list]', '[/list:o]', false, 'replace_listitems');
    // Table-cell start
    $open_tags = array();
    $open_tags[0] = '[table]';
    $text = bbencode_first_pass_pda($text, $uid, $open_tags, '[/table]', '[/table]', false, 'replace_tableitems');
    // Table-cell end
    // [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);
    // [size] and [/size] for setting text size
    $text = preg_replace("#\\[size=([1-2]?[0-9])\\](.*?)\\[/size\\]#si", "[size=\\1:{$uid}]\\2[/size:{$uid}]", $text);
    // [font] and [/font] for setting font style (note: The font=(.*?) is needed for Non-Western font names)
    $text = preg_replace("#\\[font=(.*?)\\](.*?)\\[/font\\]#si", "[font=\\1:{$uid}]\\2[/font:{$uid}]", $text);
    // BEGIN Align BBcode MOD
    // [align] and [/align] for setting text align
    $text = preg_replace("#\\[align=(left|right|center|justify)\\](.*?)\\[/align\\]#si", "[align=\\1:{$uid}]\\2[/align:{$uid}]", $text);
    // END Align BBcode MOD
    // [b] and [/b] for bolding text.
    $text = preg_replace("#\\[b\\](.*?)\\[/b\\]#si", "[b:{$uid}]\\1[/b:{$uid}]", $text);
    // [tab] for inserting tabs.
    $text = preg_replace("#\\[tab\\]#si", "[tab:{$uid}]", $text);
    // [break] for breaking news headlines from the full details
    //$text = preg_replace("#\[break\]#si", "[break:$uid]", $text);
    // [strike] and [/strike] for barring text.
    $text = preg_replace("#\\[strike\\](.*?)\\[/strike\\]#si", "[strike:{$uid}]\\1[/strike:{$uid}]", $text);
    // [u] and [/u] for underlining text.
    $text = preg_replace("#\\[u\\](.*?)\\[/u\\]#si", "[u:{$uid}]\\1[/u:{$uid}]", $text);
    // [i] and [/i] for italicizing text.
    $text = preg_replace("#\\[i\\](.*?)\\[/i\\]#si", "[i:{$uid}]\\1[/i:{$uid}]", $text);
    // [spoiler] and [/spoiler] for setting spoiler-text
    $text = preg_replace("#\\[spoiler\\](.*?)\\[/spoiler\\]#si", "[spoiler:{$uid}]\\1[/spoiler:{$uid}]", $text);
    // [img]image_url_here[/img] code..
    $text = preg_replace("#\\[img\\]((http|ftp|https|ftps)://)([^ \\?&=\\#\"\n\r\t<]*?(\\.(jpg|jpeg|gif|png)))\\[/img\\]#sie", "'[img:{$uid}]\\1' . str_replace(' ', '%20', '\\3') . '[/img:{$uid}]'", $text);
    // Custom BBCodes Mod
    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'] == '=') {
                    $search = '\\[' . $bbcode['bbcode_code'] . '=(.*?)\\](.*?)\\[\\/' . $bbcode['bbcode_code'] . '\\]';
                    $replace = '[' . $bbcode['bbcode_code'] . '=\\1:' . $uid . ']\\2[/' . $bbcode['bbcode_code'] . ':' . $uid . ']';
                } else {
                    $params = explode(',', $bbcode['bbcode_params']);
                    $search = '\\[' . $bbcode['bbcode_code'];
                    $replace = '[' . $bbcode['bbcode_code'];
                    for ($x = 0, $max = count($params); $x < $max; $x++) {
                        if (empty($params[$x])) {
                            break;
                        }
                        $search .= ' ' . $params[$x] . '=(.*?)';
                        $replace .= ' ' . $params[$x] . '=\\' . ($x + 1);
                    }
                    $search .= '\\](.*?)\\[\\/' . $bbcode['bbcode_code'] . '\\]';
                    $replace .= ':' . $uid . ']\\' . ($x + 1) . '[/' . $bbcode['bbcode_code'] . ':' . $uid . ']';
                }
                $text = preg_replace('/' . $search . '/si', $replace, $text);
            }
        }
    }
    //End of Custom BBCode
    // Remove our padding from the string..
    return substr($text, 1);
}