<?php


if (!function_exists("formatArray")) include "functions.php";
function isSpam($msg) {
    global $debug, $prefix;
    $msg=strtolower($msg);
    $max_total = 2;
    //variables
    $spamwords=Array("acquiring"=>1, "advertising"=>1, "brand"=>1,"buy"=>1, "business"=>2, "cheap"=>1, "click"=>4,
        "consider"=>1, "consulting"=>1, "customers"=>2, "discount"=>1, "grat\w*i\w*s"=>2, "handbags"=>3,
        "horny"=>1, "investments"=>2, "marketing"=>1, "offers"=>2, "paying"=>1, "promoted"=>1, "promoting"=>1,
        "sale"=>1, "seo"=>1, "sex"=>1, "store"=>1, "survey"=>1, "unsubscribe"=>2, "vagin"=>1, "visitors"=>1,
        "bitcoin" => 2, "bitcoins" => 2, "btc" => 2, "fuck" => 1);
    $total=0;
    if($debug === true) echo "<hr>Word Analysis<br>\n";
    foreach ($spamwords as $word=>$max) {
        if ($cnt=preg_match_all("/$word/is", $msg, $tmp)) $count[] = $cnt;
        else $count[]=0;
        if ($count[0] >= $max) {
            if ($cnt=preg_match_all("/\b$word\b/is", $msg, $tmp)) $count[] = $cnt;
            else $count[]=0;
            if ($debug === true){
                if ($count[0]>0) {
                    if ($count[0] != $count[1]) echo "[".$count[1]."|".($count[0]-$count[1])."] ";
                    echo "$word ($max): ";
                    echo (($count[0]==$count[1])?$count[0]:(($count[0]-$count[1])/2+$count[1]));
                    echo " (".(($count[0]==$count[1])?$count[0]:(($count[0]-$count[1])/2+$count[1]))/$max.")<br>\n";
                }
            }
            $total+=(($count[0]==$count[1])?$count[0]:(($count[0]+$count[1])/2))/$max;
        }


        unset($count);
    }
    if($debug === true) echo "<hr>Regex Analysis<br>\n";
    if($debug === true) $msg=stripslashes($msg);
    //
    //
    $spamregex=Array("/[^\[=\:\/\]]+\ \[url=https?\:\/\/(?:[\w\-]+\.)[\w\-]+\.com\]\[b\][^\[\]=\/]+\[\/b\]\[\/url\]\.\ /is"=>25);
    foreach ($spamregex as $regex=>$max) {
        if ($cnt=preg_match_all($regex, $msg, $tmp)){
            $n=0; foreach ($tmp as $value) $n+=strlen($value[0]); $avg=$n/$cnt;
            if($debug === true) {
                echo "[Detected] $regex (c=$cnt; len(avg=$avg, max=$max); p=".$avg/$max."; t=".$cnt*$avg/$max.")<br>\n";
            }
            $total+=$cnt*$avg/$max;
        }
    }

    if($debug === true) {
        echo "<hr>Total (Word+Regex): $total (max: $max_total)\n";
        echo "<hr>Link Analysis<br>\n";
    }
    $dbg= "[".date("Y-m-d H:i:s")."]".
    "\n\$_GET=".formatArray($_GET).
    ";\n\$_POST=".formatArray($_POST).
    ";\n\$_SERVER=".formatArray($_SERVER).
    ";\n\$_SESSION=".formatArray($_SESSION).
    (isset($words)?(";\n\$words=".formatArray($words)):"").
    ";\n\$total=".$total.";\n";

    /*
        Values to Check:
        $_SERVER['REQUEST_METHOD'];
        $_SERVER['HTTP_USER_AGENT'];
    */


    if (preg_match_all("/(?:ftp|https?):\/\/(?:[\w\-]+\.)?([\w\-]{14,})\.[\w]{2,5}(\/[\w\d-]{14,})?(\.[\w]{3,5})?[\s\r\n]*/is", $msg, $tmp)){
        $count=count($tmp[0]);
        foreach($tmp[1] as $name=>$value){
            $len[]=strlen($value);
        }
        if($debug === true) {
            echo "Length<br>\n";
            echo "Min: ".min($len)."<br>\n";
            echo "Max: ".max($len)."<br>\n";
            echo "Max-Min: ".(max($len)-min($len))."<br>\n";
            echo "Avg: ".(array_sum($len)/count($len))."<br>\n";
            echo "Total: ".array_sum($len)."<br>\n";
        }

        if($debug === true) echo "<hr>Bad Link Count: $count<hr>\n";
        $dbg.="\$badlink_count=".$count.";\n";
    }
    $file=fopen("$prefix/logs/antispamdbg.txt", "a");
    if ($file !== false) {
        fwrite($file, $dbg);
        fclose($file);
    }

    if(isset($count) && $count > 0) return true;
    //6.56

    if ($total >= $max_total) return true; //4
    return false;
}

?>

You can also check other includes below:
functions.php