1: <?php
2:
3: /**
4: * This is a shell plugin for SPAM filtering. It does almost nothing, but serves as the template
5: * for more robust SPAM filters.
6: * @author Stephen Billard (sbillard)
7: * @package plugins
8: * @subpackage spam
9: */
10: $plugin_is_filter = 5 | CLASS_PLUGIN;
11: $plugin_description = gettext("Trivial SPAM filter.");
12: $plugin_author = "Stephen Billard (sbillard)";
13: $plugin_disable = (isset($_zp_spamFilter) && !extensionEnabled('trivialSpam')) ? 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) : '';
14:
15: $option_interface = 'zpTrivialSpam';
16:
17: if ($plugin_disable) {
18: enableExtension('trivialSpam', 0);
19: } else {
20: $_zp_spamFilter = new zpTrivialSpam();
21: }
22:
23: /**
24: * This implements the standard SpamFilter class for the none spam filter.
25: *
26: * Note that this filter will always pass comments from users with "manage" rights
27: * on the commented object.
28: *
29: */
30: class zpTrivialSpam {
31:
32: var $name = 'trivialSpam';
33:
34: /**
35: * The SpamFilter class instantiation function.
36: *
37: * @return SpamFilter
38: */
39: function __construct() {
40: if (OFFSET_PATH == 2)
41: setOptionDefault('spamFilter_none_action', 'pass');
42: }
43:
44: function displayName() {
45: return $this->name;
46: }
47:
48: /**
49: * The admin options interface
50: * called from admin Options tab
51: * returns an array of the option names the theme supports
52: * the array is indexed by the option name. The value for each option is an array:
53: * 'type' => 0 says for admin to use a standard textbox for the option
54: * 'type' => 1 says for admin to use a standard checkbox for the option
55: * 'type' => OPTION_TYPE_CUSTOM will cause admin to call handleOption to generate the HTML for the option
56: * 'desc' => text to be displayed for the option description.
57: *
58: * @return array
59: */
60: function getOptionsSupported() {
61: return array(gettext('Action') => array('key' => 'spamFilter_none_action', 'type' => OPTION_TYPE_SELECTOR,
62: 'selections' => array(gettext('pass') => 'pass', gettext('moderate') => 'moderate', gettext('reject') => 'reject'),
63: 'desc' => gettext('This action will be taken for all messages.')));
64: }
65:
66: /**
67: * Handles custom formatting of options for Admin
68: *
69: * @param string $option the option name of the option to be processed
70: * @param mixed $currentValue the current value of the option (the "before" value)
71: */
72: function handleOption($option, $currentValue) {
73:
74: }
75:
76: /**
77: * The function for processing a message to see if it might be SPAM
78: * returns:
79: * 0 if the message is SPAM
80: * 1 if the message might be SPAM (it will be marked for moderation)
81: * 2 if the message is not SPAM
82: *
83: * @param string $author Author field from the posting
84: * @param string $email Email field from the posting
85: * @param string $website Website field from the posting
86: * @param string $body The text of the comment
87: * @param string $receiver The object on which the post was made
88: * @param string $ip the IP address of the comment poster
89: *
90: * @return int
91: */
92: function filterMessage($author, $email, $website, $body, $receiver, $ip) {
93: if (zp_loggedin($receiver->manage_rights) || $receiver->isMyItem($receiver->manage_some_rights)) { // trust "managers"
94: return 2;
95: }
96: $strategy = getOption('spamFilter_none_action');
97: switch ($strategy) {
98: case 'reject': return 0;
99: case 'moderate': return 1;
100: }
101: return 2;
102: }
103:
104: }
105:
106: ?>
107: