Example #1
0
function preparse_bbcode($text, &$errors, $is_signature = false)
{
    global $luna_config, $re_list;
    // Remove empty tags
    while (($new_text = strip_empty_bbcode($text)) !== false) {
        if ($new_text != $text) {
            $text = $new_text;
            if ($new_text == '') {
                $errors[] = __('It seems your post consisted of empty BBCodes only. It is possible that this happened because e.g. the innermost quote was discarded because of the maximum quote depth level.', 'luna');
                return '';
            }
        } else {
            break;
        }
    }
    if ($is_signature) {
        if (preg_match('%\\[/?(?:quote|code|video|list|h)\\b[^\\]]*\\]%i', $text)) {
            $errors[] = __('The quote, code, list, video, and heading BBCodes are not allowed in signatures.', 'luna');
        }
    }
    // If the message contains a code tag we have to split it up (text within [code][/code] shouldn't be touched)
    if (strpos($text, '[code]') !== false && strpos($text, '[/code]') !== false) {
        list($inside, $text) = extract_blocks($text, '[code]', '[/code]');
    }
    // Tidy up lists
    $temp = preg_replace_callback($re_list, create_function('$matches', 'return preparse_list_tag($matches[2], $matches[1]);'), $text);
    // If the regex failed
    if (is_null($temp)) {
        $errors[] = __('Your list was too long to parse, please make it smaller!', 'luna');
    } else {
        $text = str_replace('*' . "" . ']', '*]', $temp);
    }
    if ($luna_config['o_make_links'] == '1') {
        $text = do_clickable($text);
    }
    $temp_text = false;
    if (empty($errors)) {
        $temp_text = preparse_tags($text, $errors, $is_signature);
    }
    if ($temp_text !== false) {
        $text = $temp_text;
    }
    // If we split up the message before we have to concatenate it together again (code tags)
    if (isset($inside)) {
        $outside = explode("", $text);
        $text = '';
        $num_tokens = count($outside);
        for ($i = 0; $i < $num_tokens; ++$i) {
            $text .= $outside[$i];
            if (isset($inside[$i])) {
                $text .= '[code]' . $inside[$i] . '[/code]';
            }
        }
        unset($inside);
    }
    // Remove empty tags
    while (($new_text = strip_empty_bbcode($text)) !== false) {
        if ($new_text != $text) {
            $text = $new_text;
            if ($new_text == '') {
                $errors[] = __('It seems your post consisted of empty BBCodes only. It is possible that this happened because e.g. the innermost quote was discarded because of the maximum quote depth level.', 'luna');
                break;
            }
        } else {
            break;
        }
    }
    return luna_trim($text);
}
Example #2
0
function preparse_bbcode($text, &$errors, $is_signature = false)
{
    global $pun_config, $lang_common, $lang_post, $re_list;
    // Remove empty tags
    while (($new_text = strip_empty_bbcode($text)) !== false) {
        if ($new_text != $text) {
            $text = $new_text;
            if ($new_text == '') {
                $errors[] = $lang_post['Empty after strip'];
                return '';
            }
        } else {
            break;
        }
    }
    if ($is_signature) {
        global $lang_profile;
        if (preg_match('%\\[/?(?:quote|code|list|h)\\b[^\\]]*\\]%i', $text)) {
            $errors[] = $lang_profile['Signature quote/code/list/h'];
        }
    }
    // If the message contains a code tag we have to split it up (text within [code][/code] shouldn't be touched)
    if (strpos($text, '[code]') !== false && strpos($text, '[/code]') !== false) {
        list($inside, $text) = extract_blocks($text, '[code]', '[/code]');
    }
    // Tidy up lists
    $temp = preg_replace_callback($re_list, create_function('$matches', 'return preparse_list_tag($matches[2], $matches[1]);'), $text);
    // If the regex failed
    if (is_null($temp)) {
        $errors[] = $lang_common['BBCode list size error'];
    } else {
        $text = str_replace('*' . "" . ']', '*]', $temp);
    }
    if ($pun_config['o_make_links'] == '1') {
        $text = do_clickable($text);
    }
    $temp_text = false;
    if (empty($errors)) {
        $temp_text = preparse_tags($text, $errors, $is_signature);
    }
    if ($temp_text !== false) {
        $text = $temp_text;
    }
    // If we split up the message before we have to concatenate it together again (code tags)
    if (isset($inside)) {
        $outside = explode("", $text);
        $text = '';
        $num_tokens = count($outside);
        for ($i = 0; $i < $num_tokens; ++$i) {
            $text .= $outside[$i];
            if (isset($inside[$i])) {
                $text .= '[code]' . $inside[$i] . '[/code]';
            }
        }
        unset($inside);
    }
    // Remove empty tags
    while (($new_text = strip_empty_bbcode($text)) !== false) {
        if ($new_text != $text) {
            $text = $new_text;
            if ($new_text == '') {
                $errors[] = $lang_post['Empty after strip'];
                break;
            }
        } else {
            break;
        }
    }
    return pun_trim($text);
}