1: <?php
2: /**
3: * Check post attempts for "spaminess" on stopforumspam.com
4: * Please see http://www.stopforumspam.com/usage before enabling for restrictions and conditions
5: *
6: * We can check at registration, but this will repeat the check for subsequent posts. The more time that passes
7: * between registration and posting, the more likely it is that the spammer is caught before doing damage.
8: *
9: * If the poster is determined to be a spammer, the account is deactivated. The determination is made by
10: * inspecting the confidence level returned by the stopforumspam API. If that confidence, for either
11: * email or IP address, exceeds the configured $minimumConfidence, the post is denied and the account
12: * is deactivated.
13: */
14: class Protector_postcommon_post_stopforumspam extends ProtectorFilterAbstract
15: {
16: /** @var int after this number of posts by the user, skip this filter */
17: protected $minPosts = 5;
18:
19: /** @var float $minimumConfidence
20: * This is a percentage confidence as reported by stopforumspam api.
21: * When the reported confidence for any entry is above this, the post will be denied.
22: */
23: protected $minimumConfidence = 65.0; // set at your desired threshold
24:
25: /**
26: * @return bool
27: */
28: public function execute()
29: {
30: /* @var $xoopsUser XoopsUser */
31: global $xoopsUser;
32:
33: // we only check POST transactions
34: if ($_SERVER['REQUEST_METHOD'] !== 'POST' || !is_object($xoopsUser)) {
35: return true;
36: }
37:
38: // don't process for admin and experienced users
39: if (is_object($xoopsUser) && ($xoopsUser->isAdmin() || $this->minPosts < $xoopsUser->posts())) {
40: return true;
41: }
42:
43: $report = array();
44: $report['email'] = $xoopsUser->email();
45: $report['ip'] = $_SERVER['REMOTE_ADDR'];
46: $result = $this->protector->stopForumSpamLookup($report['email'], $report['ip'], null);
47: if (false === $result) {
48: return true;
49: }
50: if (!is_array($result)) {
51: // not sure what this would be, but log it just in case.
52: $this->protector->message = json_encode($result);
53: $this->protector->output_log('SFS-UNKNOWN');
54: return true;
55: }
56: foreach ($result as $entry) {
57: if (isset($entry['confidence']) && ((float) $entry['confidence'] > $this->minimumConfidence)) {
58: $report['result'] = $result;
59: $this->protector->message = json_encode($report);
60: $this->protector->output_log('SFS SPAMMER Check', $xoopsUser->uid());
61: $this->protector->deactivateCurrentUser();
62: // write any message as you like
63: echo 'Your post has been denied. '
64: . 'If you feel this is in error, please contact the site administrator.';
65: exit;
66: }
67: }
68: }
69: }
70: