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