Update of /cvsroot/php-blog/serendipity/plugins/serendipity_event_spamblock
In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv24774
Modified Files:
serendipity_event_spamblock.php
Log Message:
- Add configuration GUI to spamkiller
- Add 'Emergency comment shutdown' option, which disables comment submission for all entries
Index: serendipity_event_spamblock.php
===================================================================
RCS file: /cvsroot/php-blog/serendipity/plugins/serendipity_event_spamblock/serendipity_event_spamblock.php,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -d -r1.2 -r1.3
--- serendipity_event_spamblock.php 3 Sep 2004 15:00:17 -0000 1.2
+++ serendipity_event_spamblock.php 3 Sep 2004 23:24:20 -0000 1.3
@@ -2,11 +2,16 @@
switch ($serendipity['lang']) {
default:
- @define('PLUGIN_EVENT_SPAMBLOCK_TITLE', 'Spam-Protection');
- @define('PLUGIN_EVENT_SPAMBLOCK_DESC', 'Protection of comment spam, ... (ALPHA)');
+ @define('PLUGIN_EVENT_SPAMBLOCK_TITLE', 'Spam Protector');
+ @define('PLUGIN_EVENT_SPAMBLOCK_DESC', 'A varity of methods to prevent comment spam');
@define('PLUGIN_EVENT_SPAMBLOCK_ERROR_BODY', 'SPAM Prevention detected invalid message. Comment not added.');
@define('PLUGIN_EVENT_SPAMBLOCK_ERROR_IP', 'SPAM Prevention asks you to not mass-post comments to this blog. Comment not added.');
-
+ @define('PLUGIN_EVENT_SPAMBLOCK_BODYCLONE', 'Do not allow doublicate comments');
+ @define('PLUGIN_EVENT_SPAMBLOCK_BODYCLONE_DESC', 'Do not allow users to submit a comment which contains the same body as an already submitted comment');
+ @define('PLUGIN_EVENT_SPAMBLOCK_KILLSWITCH', 'Emergency comment shutdown');
+ @define('PLUGIN_EVENT_SPAMBLOCK_KILLSWITCH_DESC', 'Temporarily disable comments for all entries. Useful if your blog is under spam attack.');
+ @define('PLUGIN_EVENT_SPAMBLOCK_IPFLOOD', 'IP block interval');
+ @define('PLUGIN_EVENT_SPAMBLOCK_IPFLOOD_DESC', 'Only allow an IP to submit a comment every n minutes. Useful to prevent comment floods.');
break;
}
@@ -23,8 +28,41 @@
$propbag->add('event_hooks', array(
'frontend_saveComment' => true
));
+ $propbag->add('configuration', array('bodyclone', 'killswitch', 'ipflood'));
+ }
+
+ function introspect_config_item($name, &$propbag)
+ {
+ switch($name) {
+ case 'bodyclone':
+ $propbag->add('type', 'boolean');
+ $propbag->add('name', PLUGIN_EVENT_SPAMBLOCK_BODYCLONE);
+ $propbag->add('description', PLUGIN_EVENT_SPAMBLOCK_BODYCLONE_DESC);
+ $propbag->add('default', true);
+
+ break;
+
+ case 'killswitch':
+ $propbag->add('type', 'boolean');
+ $propbag->add('name', PLUGIN_EVENT_SPAMBLOCK_KILLSWITCH);
+ $propbag->add('description', PLUGIN_EVENT_SPAMBLOCK_KILLSWITCH_DESC);
+ $propbag->add('default', false);
+ break;
+
+ case 'ipflood':
+ $propbag->add('type', 'string');
+ $propbag->add('name', PLUGIN_EVENT_SPAMBLOCK_IPFLOOD);
+ $propbag->add('description', PLUGIN_EVENT_SPAMBLOCK_IPFLOOD_DESC);
+ $propbag->add('default', 2);
+ break;
+
+ default:
+ return false;
+ }
+ return true;
}
+
function generate_content(&$title) {
$title = PLUGIN_EVENT_SPAMBLOCK_TITLE;
}
@@ -38,22 +76,32 @@
case 'frontend_saveComment':
if (!is_array($eventData) || serendipity_db_bool($eventData['allow_comments'])) {
- // Check for identical comments.
- $query = "SELECT count(id) AS counter FROM {$serendipity['dbPrefix']}comments WHERE body = '" . serendipity_db_escape_string($addData['comment']) . "'";
- $row = serendipity_db_query($query, true);
- if (is_array($row) && $row['counter'] > 0) {
+ if ( $this->get_config('killswitch', false) === true ) {
$eventData = array('allow_comments' => false);
- $serendipity['messagestack']['comments'][] = PLUGIN_EVENT_SPAMBLOCK_ERROR_BODY;
+ $serendipity['messagestack']['comments'][] = 'This blog is in "Emergency Comment Blockage Mode", please come back another time';
return false;
}
+ // Check for identical comments.
+ if ( $this->get_config('bodyclone', true) === true ) {
+ $query = "SELECT count(id) AS counter FROM {$serendipity['dbPrefix']}comments WHERE body = '" . serendipity_db_escape_string($addData['comment']) . "'";
+ $row = serendipity_db_query($query, true);
+ if (is_array($row) && $row['counter'] > 0) {
+ $eventData = array('allow_comments' => false);
+ $serendipity['messagestack']['comments'][] = PLUGIN_EVENT_SPAMBLOCK_ERROR_BODY;
+ return false;
+ }
+ }
+
// Check last IP
- $query = "SELECT max(timestamp) AS last_post FROM {$serendipity['dbPrefix']}comments WHERE ip = '" . serendipity_db_escape_string($_SERVER['REMOTE_ADDR']) . "'";
- $row = serendipity_db_query($query, true);
- if (is_array($row) && $row['last_post'] > (time() - 120)) {
- $eventData = array('allow_comments' => false);
- $serendipity['messagestack']['comments'][] = PLUGIN_EVENT_SPAMBLOCK_ERROR_IP;
- return false;
+ if ( $this->get_config('ipflood', 2) != 0 ) {
+ $query = "SELECT max(timestamp) AS last_post FROM {$serendipity['dbPrefix']}comments WHERE ip = '" . serendipity_db_escape_string($_SERVER['REMOTE_ADDR']) . "'";
+ $row = serendipity_db_query($query, true);
+ if (is_array($row) && $row['last_post'] > (time() - $this->get_config('ipflood', 2)*60)) {
+ $eventData = array('allow_comments' => false);
+ $serendipity['messagestack']['comments'][] = PLUGIN_EVENT_SPAMBLOCK_ERROR_IP;
+ return false;
+ }
}
}
|