3 * StatusNet, the distributed open-source microblogging tool
5 * Plugin to check submitted notices with blogspam.net
9 * LICENCE: This program is free software: you can redistribute it and/or modify
10 * it under the terms of the GNU Affero General Public License as published by
11 * the Free Software Foundation, either version 3 of the License, or
12 * (at your option) any later version.
14 * This program is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU Affero General Public License for more details.
19 * You should have received a copy of the GNU Affero General Public License
20 * along with this program. If not, see <http://www.gnu.org/licenses/>.
24 * @author Evan Prodromou <evan@status.net>
25 * @author Brion Vibber <brion@status.net>
26 * @copyright 2009 StatusNet, Inc.
27 * @license http://www.fsf.org/licensing/licenses/agpl-3.0.html GNU Affero General Public License version 3.0
28 * @link http://status.net/
31 if (!defined('STATUSNET')) {
35 define('BLOGSPAMNETPLUGIN_VERSION', '0.1');
38 * Plugin to check submitted notices with blogspam.net
40 * When new notices are saved, we check their text with blogspam.net (or
41 * a compatible service).
43 * Blogspam.net is supposed to catch blog comment spam, and I found that
44 * some of its tests (min/max size, bayesian match) gave a lot of false positives.
45 * So, I've turned those tests off by default. This may not get as many
46 * hits, but it's better than nothing.
50 * @author Evan Prodromou <evan@status.net>
51 * @license http://www.fsf.org/licensing/licenses/agpl-3.0.html GNU Affero General Public License version 3.0
52 * @link http://status.net/
57 class BlogspamNetPlugin extends Plugin
59 var $baseUrl = 'http://test.blogspam.net:8888/';
61 function __construct($url=null)
63 parent::__construct();
65 $this->baseUrl = $url;
69 function onStartNoticeSave($notice)
71 $args = $this->testArgs($notice);
72 common_debug("Blogspamnet args = " . print_r($args, TRUE));
73 $requestBody = xmlrpc_encode_request('testComment', array($args));
75 $request = new HTTPClient($this->baseUrl, HTTPClient::METHOD_POST);
76 $request->setHeader('Content-Type', 'text/xml');
77 $request->setBody($requestBody);
78 $httpResponse = $request->send();
80 $response = xmlrpc_decode($httpResponse->getBody());
81 if (xmlrpc_is_fault($response)) {
82 throw new ServerException("$response[faultString] ($response[faultCode])", 500);
84 common_debug("Blogspamnet results = " . $response);
85 if (preg_match('/^ERROR(:(.*))?$/', $response, $match)) {
86 throw new ServerException(sprintf(_("Error from %s: %s"), $this->baseUrl, $match[2]), 500);
87 } else if (preg_match('/^SPAM(:(.*))?$/', $response, $match)) {
88 throw new ClientException(sprintf(_("Spam checker results: %s"), $match[2]), 400);
89 } else if (preg_match('/^OK$/', $response)) {
92 throw new ServerException(sprintf(_("Unexpected response from %s: %s"), $this->baseUrl, $response), 500);
98 function testArgs($notice)
101 $args['comment'] = $notice->content;
102 $args['ip'] = $this->getClientIP();
104 if (isset($_SERVER) && array_key_exists('HTTP_USER_AGENT', $_SERVER)) {
105 $args['agent'] = $_SERVER['HTTP_USER_AGENT'];
108 $profile = $notice->getProfile();
110 if ($profile && $profile->homepage) {
111 $args['link'] = $profile->homepage;
114 if ($profile && $profile->fullname) {
115 $args['name'] = $profile->fullname;
117 $args['name'] = $profile->nickname;
120 $args['site'] = common_root_url();
121 $args['version'] = $this->userAgent();
123 $args['options'] = "max-size=" . common_config('site','textlimit') . ",min-size=0,min-words=0,exclude=bayasian";
128 function getClientIP()
130 if (isset($_SERVER) && array_key_exists('REQUEST_METHOD', $_SERVER)) {
131 // Note: order matters here; use proxy-forwarded stuff first
132 foreach (array('HTTP_X_FORWARDED_FOR', 'CLIENT-IP', 'REMOTE_ADDR') as $k) {
133 if (isset($_SERVER[$k])) {
143 return 'BlogspamNetPlugin/'.BLOGSPAMNETPLUGIN_VERSION . ' StatusNet/' . STATUSNET_VERSION;