1: 2: 3: 4: 5: 6: 7: 8: 9: 10: 11: 12: 13: 14: 15: 16: 17: 18: 19: 20: 21: 22: 23: 24: 25: 26: 27: 28: 29: 30: 31: 32: 33: 34: 35: 36: 37: 38: 39: 40: 41: 42: 43: 44: 45: 46: 47: 48: 49: 50: 51: 52: 53: 54: 55: 56: 57: 58: 59: 60: 61: 62: 63: 64: 65: 66: 67: 68: 69: 70: 71: 72: 73: 74: 75: 76: 77: 78: 79: 80: 81: 82: 83: 84: 85: 86: 87: 88: 89: 90: 91: 92: 93: 94: 95: 96: 97: 98: 99: 100: 101: 102: 103: 104: 105: 106: 107: 108: 109: 110: 111: 112: 113: 114: 115: 116: 117: 118: 119: 120: 121: 122: 123: 124: 125: 126: 127: 128: 129: 130: 131: 132: 133: 134: 135: 136: 137: 138: 139: 140: 141: 142: 143: 144: 145: 146: 147: 148: 149: 150: 151: 152: 153: 154: 155: 156: 157: 158: 159: 160: 161: 162: 163: 164: 165: 166: 167:
<?php
$plugin_is_filter = 5 | CLASS_PLUGIN;
$plugin_description = gettext("Simple SPAM filter.");
$plugin_author = "Stephen Billard (sbillard)";
$plugin_disable = (isset($_zp_spamFilter) && !extensionEnabled('simpleSpam')) ? sprintf(gettext('Only one SPAM handler plugin may be enabled. <a href="#%1$s"><code>%1$s</code></a> is already enabled.'), $_zp_spamFilter->name) : '';
$plugin_category = gettext('Spam');
$option_interface = 'zpSimpleSpam';
if ($plugin_disable) {
enableExtension('simpleSpam', 0);
} else {
$_zp_spamFilter = new zpSimpleSpam();
}
class zpSimpleSpam {
var $name = 'simpleSpam';
var $wordsToDieOn = array('cialis', 'ebony', 'nude', 'porn', 'porno', 'pussy', 'upskirt', 'ringtones', 'phentermine', 'viagra', 'levitra');
var $patternsToDieOn = array('\[url=.*\]');
var $excessiveURLCount = 5;
function __construct() {
setOptionDefault('Words_to_die_on', implode(',', $this->wordsToDieOn));
setOptionDefault('Patterns_to_die_on', implode(' ', $this->patternsToDieOn));
setOptionDefault('Excessive_URL_count', $this->excessiveURLCount);
setOptionDefault('Forgiving', 0);
setOptionDefault('Banned_IP_list', serialize(array()));
}
function displayName() {
return $this->name;
}
function getOptionsSupported() {
return array(gettext('Words to die on') => array('key' => 'Words_to_die_on', 'type' => OPTION_TYPE_TEXTAREA,
'multilingual' => false,
'desc' => gettext('SPAM blacklist words (separate with commas)')),
gettext('Patterns to die on') => array('key' => 'Patterns_to_die_on', 'type' => OPTION_TYPE_TEXTAREA,
'multilingual' => false,
'desc' => gettext('SPAM blacklist <a href="http://en.wikipedia.org/wiki/Regular_expression">regular expressions</a> (separate with spaces)')),
gettext('Excessive URL count') => array('key' => 'Excessive_URL_count', 'type' => OPTION_TYPE_TEXTBOX, 'desc' => gettext('Message is considered SPAM if there are more than this many URLs in it')),
gettext('Banned IPs') => array('key' => 'Banned_IP_list', 'type' => OPTION_TYPE_TEXTAREA,
'multilingual' => false,
'desc' => gettext('Prevent posts from this list of IP addresses')),
gettext('Forgiving') => array('key' => 'Forgiving', 'type' => OPTION_TYPE_CHECKBOX, 'desc' => gettext('Mark suspected SPAM for moderation rather than as SPAM')));
}
function handleOption($option, $currentValue) {
}
function filterMessage($author, $email, $website, $body, $receiver, $ip) {
if (strpos(getOption('Banned_IP_list'), $ip) !== false) {
return 0;
}
$forgive = getOption('Forgiving');
$list = getOption('Words_to_die_on');
$list = strtolower($list);
$this->wordsToDieOn = explode(',', $list);
$list = getOption('Patterns_to_die_on');
$list = strtolower($list);
$this->patternsToDieOn = explode(' ', $list);
$this->excessiveURLCount = getOption('Excessive_URL_count');
$die = 2;
foreach (array($author, $email, $website, $body) as $check) {
if ($check) {
if (($num = substr_count($check, 'http://')) >= $this->excessiveURLCount) {
$die = $forgive;
} else {
if ($pattern = $this->hasSpamPattern($check)) {
$die = $forgive;
} else {
if ($spamWords = $this->hasSpamWords($check)) {
$die = $forgive;
}
}
}
}
}
return $die;
}
function hasSpamPattern($text) {
$patterns = $this->patternsToDieOn;
foreach ($patterns as $pattern) {
if (preg_match('|' . preg_quote(trim($pattern), '/') . '|i', $text)) {
return true;
}
}
return false;
}
function hasSpamWords($text) {
$words = $this->getWords($text);
$blacklist = $this->wordsToDieOn;
$intersect = array_intersect($blacklist, $words);
return $intersect;
}
function getWords($text, $notUnique = false) {
if ($notUnique) {
return preg_split("/[\W]+/", strtolower(strip_tags($text)));
} else {
return array_unique(preg_split("/[\W]+/", strtolower(strip_tags($text))));
}
}
}
?>