function preparse_bbcode($text, &$errors, $is_signature = false) { global $pun_config, $lang_common, $lang_post, $re_list; 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, $outside) = split_text($text, '[code]', '[/code]', $errors); $text = implode("", $outside); } // Tidy up lists $temp = preg_replace($re_list, 'preparse_list_tag(\'$2\', \'$1\', $errors)', $text); // If the regex failed if ($temp === null) { $errors[] = $lang_common['BBCode list size error']; } else { $text = str_replace('*' . "" . ']', '*]', $temp); } if ($pun_config['o_make_links'] == '1') { $text = do_clickable($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); } $temp_text = false; if (empty($errors)) { $temp_text = preparse_tags($text, $errors, $is_signature); } if ($temp_text !== false) { $text = $temp_text; } // Remove empty tags while (($new_text = strip_empty_bbcode($text, $errors)) !== false) { if ($new_text != $text) { $text = $new_text; if ($new_text == '') { $errors[] = $lang_post['Empty after strip']; break; } } else { break; } } return pun_trim($text); }
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); }
function preparse_bbcode($text, &$errors, $is_signature = false) { global $forum_config; $return = ($hook = get_hook('ps_preparse_bbcode_start')) ? eval($hook) : null; if ($return != null) { return $return; } if ($is_signature) { global $lang_profile; if (preg_match('#\\[quote(=("|"|\'|)(.*)\\1)?\\]|\\[/quote\\]|\\[code\\]|\\[/code\\]|\\[list(=([1a\\*]))?\\]|\\[/list\\]#i', $text)) { $errors[] = $lang_profile['Signature quote/code/list']; } } if ($forum_config['p_sig_bbcode'] == '1' && $is_signature || $forum_config['p_message_bbcode'] == '1' && !$is_signature) { // 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, $outside) = split_text($text, '[code]', '[/code]', $errors); $text = implode("", $outside); } // Tidy up lists $pattern_callback = '%\\[list(?:=([1a*]))?+\\]((?:(?>.*?(?=\\[list(?:=[1a*])?+\\]|\\[/list\\]))|(?R))*)\\[/list\\]%is'; $replace_callback = 'preparse_list_tag($matches[2], $matches[1], $errors)'; $text = preg_replace_callback($pattern_callback, create_function('$matches', 'return ' . $replace_callback . ';'), $text); $text = str_replace('*' . "" . ']', '*]', $text); if ($forum_config['o_make_links'] == '1') { $text = do_clickable($text, defined('FORUM_SUPPORT_PCRE_UNICODE')); } // 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]'; } } } $temp_text = false; if (empty($errors)) { $temp_text = preparse_tags($text, $errors, $is_signature); } if ($temp_text !== false) { $text = $temp_text; } // Remove empty tags while ($new_text = preg_replace('/\\[(b|u|i|h|colou?r|quote|code|img|url|email|list)(?:\\=[^\\]]*)?\\]\\[\\/\\1\\]/', '', $text)) { if ($new_text != $text) { $text = $new_text; } else { break; } } } $return = ($hook = get_hook('ps_preparse_bbcode_end')) ? eval($hook) : null; if ($return != null) { return $return; } return forum_trim($text); }