', $str);
$str = preg_replace("/\[quote=[\"\']?([^\"\'\]]+)[\"\']?\](\r?\n)*/i", '
\\1: ', $str);
$str = preg_replace("/(\r?\n)*\[(\/|\*)quote\](\r?\n)?/i", '
', $str);
$str = preg_replace('/\[img\]([^"\[]+)\[(\/|\*)img\]/i', '

', $str);
$str = preg_replace('/\[(sup|sub)\]/i', '<\\1>', $str);
$str = preg_replace('/\[(\/|\*)(sup|sub)\]/i', '\\2>', $str);
$str = preg_replace('/(\r?\n)*\[\*\]/', '
', $str);
$str = preg_replace('/\[list( | )+type=[\"\']?(1|a|i)[\"\']?\](\r?\n)*/i', '', $str);
$str = preg_replace('/\[list\](\r?\n)*/i', '', $str);
$str = preg_replace('/(\r?\n)*\[(\/|\*)list\](\r?\n)?/i', '
', $str);
}
else $str = preg_replace('/\[(\/|\*)?(code|quote|img|sup|sub|list( type=(1|a|i))?|\*)\]/i', '', $str);
$str = preg_replace('/\[(b|i|u)\]/i', '<\\1>', $str);
$str = preg_replace('/\[(\/|\*)(b|i|u)\]/i', '\\2>', $str);
$str = preg_replace('/\[email\]([^"\[]+)\[(\/|\*)email\]/i', '\\1', $str);
if($allowURLs) {
$str = preg_replace('/\[url\]((https?|ftp):\/\/[^"\[]+)\[(\/|\*)url\]/i', '\\1', $str);
$str = preg_replace('/\[url\]([^"\[]+)\[(\/|\*)url\]/i', '\\1', $str);
$str = preg_replace('/\[url=[\"\']?((https?|ftp):\/\/[^"\[]+)[\"\']?\]([^\[]+)\[(\/|\*)url\]/i', '\\3', $str);
$str = preg_replace('/\[url=[\"\']?([^\"\'\]]+)[\"\']?\]([^\[]+)\[(\/|\*)url\]/i', '\\2', $str);
}
return $str;
}
//------------------------------------------------------------------------------------------------------
// Get entity for multibyte character
// Arguments: multibyte character (2 bytes)
//
function mb2entity($char) {
$code = ord($char[1]) % 128;
$c = (ord($char[0]) % 252 % 248 % 240 % 224 % 192) + 128;
$code += ($c % 128) * 64;
return '' . $code . ';';
}
//------------------------------------------------------------------------------------------------------
// Replace multibyte characters with entities
// Arguments: text
//
function replaceMbChars($str) {
return preg_replace('/[\xC0-\xF7][\x80-\xBF]/e', 'mb2entity("\\0")', $str);
}
//------------------------------------------------------------------------------------------------------
// Format text
// Arguments: text, max. word length, max. image width, [text is one line (true or false)]
//
function format($str, $wordLength, $imgWidth, $textline = false) {
global $textLength, $allowHTML, $allowUBBs, $allowURLs;
$str = preg_replace('/(\s){2}/', '\\1', $str);
$str = replaceMbChars($str);
if($textLength) $str = cutString($str, $textLength);
if(!$allowHTML) $str = replaceHTML($str);
if(!$allowURLs) $str = replaceURLs($str);
if($allowUBBs) $str = replaceUBBs($str, $textline);
if($allowHTML || $allowUBBs) $str = checkImages($str, $imgWidth);
$str = checkRepeats($str);
$str = checkLongWords($str, $wordLength);
$str = replaceSmilies($str);
$str = replaceNonos($str);
$str = nl2br($str);
return $str;
}
//------------------------------------------------------------------------------------------------------
// Check for spam
// Arguments: message ID, timestamp, name, e-mail, subject, text, [message signature]
//
function checkSpam($id, $tstamp, $name, $email, $subject, $text, $signature = '') {
global $PHP_SELF, $HTTP_REFERER, $HTTP_USER_AGENT, $agents, $allowURLs, $allowHTML,
$enableIDs, $enableSignature, $enableLinkCheck, $enableRefererCheck, $enableAgentCheck;
$sec = time() - $tstamp;
if($name && preg_match("/\r|\n/", $name)) return true;
if($email && preg_match("/\r|\n/", $email)) return true;
if($subject && preg_match("/\r|\n/", $subject)) return true;
if($tstamp != -1 && ($sec < 5 || $sec > 20 * 60)) return true;
if($enableIDs && (!$id || $id != $_SESSION['msgID'])) return true;
if($enableSignature && (!$signature || $signature != $_SESSION['secCode'])) return true;
if($enableRefererCheck && !ereg($PHP_SELF, $HTTP_REFERER)) return true;
if($enableLinkCheck && !$allowURLs && checkLinks($text)) return true;
if($enableAgentCheck) {
for($i = $found = 0; $i < count($agents) && !$found; $i++) {
if(eregi($agents[$i], $HTTP_USER_AGENT)) $found++;
}
if(!$found) return true;
}
return false;
}
?>