This file is part of phpCF. phpCF is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. phpCF is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with phpCF; if not, write to the Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA *****************************************************************************/ require_once 'phpCF.config.php'; // Define a couple of constants. define("PHPCF_VERSION", "0.3.5"); define("DEBUG", true); @ini_set('user_agent', "phpCF/".PHPCF_VERSION." (http://freshmeat.net/projects/phpcf/)"); class CFBase { var $error = array(); var $log = array(); var $score; // For debugging purposes only! var $debug = ""; // Main methods. function CFBase($text, $email = false, $ip = false) { $this->score = $this->scan($text, $email, $ip); } function isSpam() { global $SPAM_THRESHOLD; if ($this->score > $SPAM_THRESHOLD) { return true; } else { return false; } } function scan($text, $email = false, $ip = false) { $points = 0.0; $checks = $this->availableChecks(); foreach ($checks as $c) { if (method_exists($this, "c_" . $c)) { $funct = "c_$c"; $points += $this->$funct($text); } else { $this->error[] = "\"$c\": No such checking method."; } } if ($email != false && !empty($email) && is_string($email)) { $email_checks = $this->availableEmailChecks(); foreach ($email_checks as $ec) { if (method_exists($this, "ec_" . $ec)) { $funct = "ec_$ec"; $points += $this->$funct($email); } else { $this->error[] = "\"$ec\": No such email checking method."; } } } if ($ip != false && !empty($ip) && is_string($ip)) { $ip_checks = $this->availableIpChecks(); foreach ($ip_checks as $ic) { if (method_exists($this, "ic_" . $ic)) { $funct = "ic_$ic"; $points += $this->$funct($ip); } else { $this->error[] = "\"$ic\": No such IP checking method."; } } } return $points; } // Error functions. function hasError() { if (!empty($this->error)) { return true; } else { return false; } } function printErrorList() { if (!empty($this->error)) { echo "\n"; } } function getLastError() { if (!empty($this->error) && is_array($this->error)) { return $this->error[count($this->error) - 1]; } } // Logging functions. function printLog() { if (!empty($this->log)) { echo "\n"; } } function availableChecks() { $ret = array(); foreach (get_class_methods($this) as $m) { if (preg_match("/^c_/", $m)) { $ret[] = preg_replace("/^(c_)(.+)$/", "\\2", $m); } } return $ret; } function availableEmailChecks() { $ret = array(); foreach (get_class_methods($this) as $m) { if (preg_match("/^ec_/", $m)) { $ret[] = preg_replace("/^(ec_)(.+)$/", "\\2", $m); } } return $ret; } function availableIpChecks() { $ret = array(); foreach (get_class_methods($this) as $m) { if (preg_match("/^ic_/", $m)) { $ret[] = preg_replace("/^(ic_)(.+)$/", "\\2", $m); } } return $ret; } function getThreshold() { global $SPAM_THRESHOLD; return $SPAM_THRESHOLD; } // Debugging methods function debug($txt) { if (DEBUG) { $this->debug .= $txt . "\n"; } } function getDebugInfo() { return $this->debug; } } ?>