예제 #1
0
파일: parser.php 프로젝트: Razze/hamsterpaj
function preparse_bbcode($text, &$errors)
{
    // Change all simple BBCodes to lower case
    $a = array('[B]', '[I]', '[U]', '[/B]', '[/I]', '[/U]');
    $b = array('[b]', '[i]', '[u]', '[/b]', '[/i]', '[/u]');
    $text = str_replace($a, $b, $text);
    // Do the more complex BBCodes (also strip excessive whitespace and useless quotes)
    $a = array('#\\[url=("|\'|)(.*?)\\1\\]\\s*#i', '#\\[url\\]\\s*#i', '#\\s*\\[/url\\]#i', '#\\[email=("|\'|)(.*?)\\1\\]\\s*#i', '#\\[email\\]\\s*#i', '#\\s*\\[/email\\]#i', '#\\[img\\]\\s*(.*?)\\s*\\[/img\\]#is', '#\\[colou?r=("|\'|)(.*?)\\1\\](.*?)\\[/colou?r\\]#is');
    $b = array('[url=$2]', '[url]', '[/url]', '[email=$2]', '[email]', '[/email]', '[img]$1[/img]', '[color=$2]$3[/color]');
    $a[] = '#\\[quote=("|"|\'|)(.*?)\\1\\]\\s*#i';
    $a[] = '#\\[quote\\]\\s*#i';
    $a[] = '#\\s*\\[/quote\\]\\s*#i';
    $a[] = '#\\[code\\][\\r\\n]*(.*?)\\s*\\[/code\\]\\s*#is';
    $b[] = '[quote=$1$2$1]';
    $b[] = '[quote]';
    $b[] = '[/quote]' . "\n";
    $b[] = '[code]$1[/code]' . "\n";
    // Run this baby!
    $text = preg_replace($a, $b, $text);
    $overflow = check_tag_order($text, $error);
    if ($error) {
        // A BBCode error was spotted in check_tag_order()
        $errors[] = $error;
    } else {
        if ($overflow) {
            $text = substr($text, 0, $overflow[0]) . substr($text, $overflow[1], strlen($text) - $overflow[0]);
        }
    }
    return trim($text);
}
예제 #2
0
function preparse_bbcode($text, &$errors, $is_signature = false)
{
    // Change all simple BBCodes to lower case
    $a = array('[B]', '[I]', '[U]', '[S]', '[Q]', '[C]', '[P]', '[/B]', '[/I]', '[/U]', '[/S]', '[/Q]', '[/C]');
    $b = array('[b]', '[i]', '[u]', '[s]', '[q]', '[c]', '[p]', '[/b]', '[/i]', '[/u]', '[/s]', '[/q]', '[/c]');
    $text = str_replace($a, $b, $text);
    // Do the more complex BBCodes (also strip excessive whitespace and useless quotes)
    $base_url = 'http://' . $_SERVER['SERVER_NAME'];
    $a = array('#\\[url=("|\'|)(.*?)\\1\\s*\\]\\s*#i', '#\\[url(=\\]|\\])\\s*#i', '#\\s*\\[/url\\]#i', '#\\[url=(.*?)\\]\\1\\[/url\\]#i', '#\\[url(=|\\])(ht+ps?)?:*/*w*m*\\.*camptocamp\\.org(/([^\\[\\]]+))#i', '#\\[email=("|\'|)(.*?)\\1\\s*\\]\\s*#i', '#\\[email(=\\]|\\])\\s*#i', '#\\s*\\[/email\\]#i', '#\\[email=(.*?)\\]\\1\\[/email\\]#i', '#\\[img=\\s*("|\'|)(.*?)\\1\\s*\\]\\s*#i', '#\\[img(=\\]|\\])\\s*#i', '#\\[img(=|\\])' . $base_url . '#i', '#\\s*\\[/img\\]#i', '#\\[colou?r=("|\'|)(.*?)\\1\\s*\\]\\s*#i', '#\\[/colou?r\\]#i', '#\\[(cent(er|re|ré)|<>)\\]\\s*#i', '#\\[/(cent(er|re|ré)|<>)\\]\\s?#i', '#\\[(right|rigth|ritgh|rithg|droite?|>)\\]\\s*#i', '#\\[/(right|rigth|ritgh|rithg|droite?|>)\\]\\s?#i', '#\\[(justif(y|ie|ié|)|=)\\]\\s*#i', '#\\[/(justif(y|ie|ié|)|=)\\]\\s?#i');
    $b = array('[url=$2]', '[url]', '[/url]', '[url]$1[/url]', '[url$1$3', '[email=$2]', '[email]', '[/email]', '[email]$1[/email]', '[img=$2]', '[img]', '[img$1', '[/img]', '[color=$2]', '[/color]', '[center]', '[/center]' . "\n", '[right]', '[/right]' . "\n", '[justify]', '[/justify]' . "\n");
    if (!$is_signature) {
        // For non-signatures, we have to do the quote and code tags as well
        $a[] = '#\\[quote=(&quot;|"|\'|)(.*?)\\1\\s*\\]\\s*#i';
        $a[] = '#\\[quote(=\\]|\\])\\s*#i';
        $a[] = '#\\s*\\[/quote\\]\\s?#i';
        $a[] = '#\\[code\\][\\r\\n]*(.*?)\\s*\\[/code\\]\\s?#is';
        $a[] = '#\\[spoiler=("|\'|)(.*?)\\1\\]\\s*#i';
        $a[] = '#\\[spoiler(=\\]|\\])\\s*#i';
        $a[] = '#\\s*\\[/spoiler\\]\\s?#i';
        $a[] = '#\\[video([^0-9\\]]*)([0-9]+)([^0-9\\]]+)([0-9]+)([^0-9\\]]*)\\]\\s*#i';
        $a[] = '#\\[video\\]\\s*#i';
        $a[] = '#\\s*\\[/video\\]\\s?#i';
        $a[] = '#\\[p\\]\\s?#i';
        $b[] = '[quote=$1$2$1]';
        $b[] = '[quote]';
        $b[] = '[/quote]' . "\n";
        $b[] = '[code]$1[/code]' . "\n";
        $b[] = '[spoiler=$2]';
        $b[] = '[spoiler]';
        $b[] = '[/spoiler]' . "\n";
        $b[] = '[video $2,$4]';
        $b[] = '[video]';
        $b[] = '[/video]' . "\n";
        $b[] = '[p]' . "\n";
    }
    $a[] = '#(?<!^|\\n)([ \\t]*)(\\[(center|right|justify|quote|code|spoiler|video))#i';
    $b[] = '$1' . "\n" . '$2';
    // Run this baby!
    $text = preg_replace($a, $b, $text);
    if (!$is_signature) {
        $overflow = check_tag_order($text, $error);
        if ($error) {
            // A BBCode error was spotted in check_tag_order()
            $errors[] = $error;
        } elseif ($overflow) {
            // The quote depth level was too high, so we strip out the inner most quote(s)
            $text = substr($text, 0, $overflow[0]) . substr($text, $overflow[1], strlen($text) - $overflow[0]);
        }
    } else {
        global $lang_prof_reg;
        if (preg_match('#\\[quote=(&quot;|"|\'|)(.*)\\1\\]|\\[quote\\]|\\[/quote\\]|\\[code\\]|\\[/code\\]#i', $text)) {
            message($lang_prof_reg['Signature quote/code']);
        }
    }
    return trim($text);
}
예제 #3
0
function preparse_bbcode($text, &$errors, $is_signature = false)
{
    global $lang_prof_reg;
    // Change all simple BBCodes to lower case
    // MODERN BBCODE BEGIN
    $text = str_replace(array('[B]', '[I]', '[U]', '[/B]', '[/I]', '[/U]', '[S]', '[/S]'), array('[b]', '[i]', '[u]', '[/b]', '[/i]', '[/u]', '[s]', '[/s]'), $text);
    // MODERN BBCODE END
    // Do the more complex BBCodes (also strip excessive whitespace and useless quotes)
    $a = array('#\\[url=("|\'|)(.*?)$1\\]\\s*#i', '#\\[url\\]\\s*#i', '#\\s*\\[/url\\]#i', '#\\[search=("|\'|)(.*?)$1\\]\\s*#i', '#\\[search\\]\\s*#i', '#\\s*\\[/search\\]#i', '#\\[email=("|\'|)(.*?)$1\\]\\s*#i', '#\\[email\\]\\s*#i', '#\\s*\\[/email\\]#i', '#\\[img\\]\\s*(.*?)\\s*\\[/img\\]#is', '#\\[color=("|\'|)(.*?)$1\\](.*?)\\[/color\\]#is', '#\\[font=("|\'|)(.*?)$1\\](.*?)\\[/font\\]#is');
    $b = array('[url=$2]', '[url]', '[/url]', '[search=$2]', '[search]', '[/search]', '[email=$2]', '[email]', '[/email]', '[img]$1[/img]', '[color=$2]$3[/color]', '[font=$2]$3[/font]');
    if (!$is_signature) {
        // For non-signatures, we have to do the quote and code tags as well
        $a[] = '#\\[quote=(&quot;|"|\'|)(.*?)$1\\]\\s*#i';
        $a[] = '#\\[quote\\]\\s*#i';
        $a[] = '#\\s*\\[/quote\\]\\s*#i';
        $a[] = '#\\[code\\][\\r\\n]*(.*?)\\s*\\[/code\\]\\s*#is';
        $a[] = '#\\[hide=(&quot;|"|\'|)(.*?)$1\\]\\s*#i';
        $a[] = '#\\[hide\\]\\s*#i';
        $a[] = '#\\s*\\[/hide\\]\\s*#i';
        $b[] = '[quote=$1$2$1]';
        $b[] = '[quote]';
        $b[] = '[/quote]' . "\n";
        $b[] = '[code]$1[/code]' . "\n";
        $b[] = '[hide=$1$2$1]';
        $b[] = '[hide]';
        $b[] = '[/hide]' . "\n";
    }
    // Run this baby!
    $text = preg_replace($a, $b, $text);
    if (!$is_signature) {
        $error = '';
        $overflow = check_tag_order($text, $error);
        if ($error) {
            // A BBCode error was spotted in check_tag_order()
            $errors[] = $error;
        } else {
            if ($overflow) {
                // The quote depth level was too high, so we strip out the inner most quote(s)
                $text = substr($text, 0, $overflow[0]) . substr($text, $overflow[1], strlen($text) - $overflow[0]);
            }
        }
    } else {
        if (preg_match('#\\[quote=(&quot;|"|\'|)(.*)\\1\\]|\\[quote\\]|\\[/quote\\]|\\[code\\]|\\[/code\\]|\\[hide=(&quot;|"|\'|)(.*)\\1\\]|\\[hide\\]|\\[/hide\\]#i', $text)) {
            if (basename(dirname($_SERVER['PHP_SELF'])) == 'wap') {
                wap_message($lang_prof_reg['Signature quote/code']);
            } else {
                message($lang_prof_reg['Signature quote/code']);
            }
        }
    }
    return trim($text);
}