Update of /cvsroot/php-blog/serendipity/plugins/serendipity_event_spamblock
In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv23962/plugins/serendipity_event_spamblock
Modified Files:
serendipity_event_spamblock.php
Log Message:
let's make kris a happy guy
Index: serendipity_event_spamblock.php
===================================================================
RCS file: /cvsroot/php-blog/serendipity/plugins/serendipity_event_spamblock/serendipity_event_spamblock.php,v
retrieving revision 1.38
retrieving revision 1.39
diff -u -d -r1.38 -r1.39
--- serendipity_event_spamblock.php 5 Dec 2004 10:53:51 -0000 1.38
+++ serendipity_event_spamblock.php 8 Dec 2004 00:34:42 -0000 1.39
@@ -56,6 +56,12 @@
@define('PLUGIN_EVENT_SPAMBLOCK_HIDE_EMAIL', 'E-Mail-Adressen bei Kommentatoren verstecken');
@define('PLUGIN_EVENT_SPAMBLOCK_HIDE_EMAIL_DESC', 'Zeigt in den Kommentaren keine E-Mail Adressen der jeweiligen Kommentatoren an');
@define('PLUGIN_EVENT_SPAMBLOCK_HIDE_EMAIL_NOTICE', 'Die angegebene E-Mail Adressse wird nicht dargestellt, sondern nur für evtl. Benachrichtigungen verwendet');
+
+ @define('PLUGIN_EVENT_SPAMBLOCK_LOGTYPE', 'Protokollierung von fehlgeschlagenen Kommentaren');
+ @define('PLUGIN_EVENT_SPAMBLOCK_LOGTYPE_DESC', 'Die Protokollierung von fehlgeschlagenen Kommentaren und deren Gründen kann auf mehrere Arten durchgeführt werden.');
+ @define('PLUGIN_EVENT_SPAMBLOCK_LOGTYPE_FILE', 'Einfache Datei (siehe Option "Logfile")');
+ @define('PLUGIN_EVENT_SPAMBLOCK_LOGTYPE_DB', 'Datenbank');
+ @define('PLUGIN_EVENT_SPAMBLOCK_LOGTYPE_NONE', 'Keine Protokollierung');
break;
default:
@@ -112,10 +118,15 @@
@define('PLUGIN_EVENT_SPAMBLOCK_REASON_FORCEMODERATION', 'Auto-moderation after X days');
@define('PLUGIN_EVENT_SPAMBLOCK_REASON_LINKS_REJECT', 'Too many hyperlinks');
@define('PLUGIN_EVENT_SPAMBLOCK_REASON_LINKS_MODERATE', 'Too many hyperlinks');
- @define('PLUGIN_EVENT_SPAMBLOCK_HIDE_EMAIL', 'Hide E-Mail addresses for commenting users');
- @define('PLUGIN_EVENT_SPAMBLOCK_HIDE_EMAIL_DESC', 'Will show no E-Mail addresses in comments of commenting users');
+ @define('PLUGIN_EVENT_SPAMBLOCK_HIDE_EMAIL', 'Hide E-Mail addresses of commenting users');
+ @define('PLUGIN_EVENT_SPAMBLOCK_HIDE_EMAIL_DESC', 'Will show no E-Mail addresses of commenting users');
@define('PLUGIN_EVENT_SPAMBLOCK_HIDE_EMAIL_NOTICE', 'E-Mail addresses will not be displayed and only used for E-Mail notifications');
+ @define('PLUGIN_EVENT_SPAMBLOCK_LOGTYPE', 'Choose logging method');
+ @define('PLUGIN_EVENT_SPAMBLOCK_LOGTYPE_DESC', 'Logging of rejected comments can be done in Database or to a plaintext file');
+ @define('PLUGIN_EVENT_SPAMBLOCK_LOGTYPE_FILE', 'File (see "logfile" option below)');
+ @define('PLUGIN_EVENT_SPAMBLOCK_LOGTYPE_DB', 'Database');
+ @define('PLUGIN_EVENT_SPAMBLOCK_LOGTYPE_NONE', 'No Logging');
break;
}
@@ -133,14 +144,14 @@
$propbag->add('description', PLUGIN_EVENT_SPAMBLOCK_DESC);
$propbag->add('stackable', false);
$propbag->add('author', 'Garvin Hicking, Sebastian Nohn');
- $propbag->add('version', '1.15');
+ $propbag->add('version', '1.2');
$propbag->add('event_hooks', array(
'frontend_saveComment' => true,
'external_plugin' => true,
'frontend_comment' => true,
'fetchcomments' => true
));
- $propbag->add('configuration', array('killswitch', 'bodyclone', 'ipflood', 'surbl_enabled', 'rbl_enabled', 'rbllist', 'captchas', 'captchas_ttl', 'captcha_color', 'forcemoderation', 'links_moderate', 'links_reject', 'logfile', 'hide_email'));
+ $propbag->add('configuration', array('killswitch', 'bodyclone', 'ipflood', 'surbl_enabled', 'rbl_enabled', 'rbllist', 'captchas', 'captchas_ttl', 'captcha_color', 'forcemoderation', 'links_moderate', 'links_reject', 'hide_email', 'logtype', 'logfile'));
}
function introspect_config_item($name, &$propbag)
@@ -183,6 +194,19 @@
$propbag->add('default', $serendipity['serendipityPath'] . 'spamblock.log');
break;
+ case 'logtype':
+ $propbag->add('type', 'radio');
+ $propbag->add('name', PLUGIN_EVENT_SPAMBLOCK_LOGTYPE);
+ $propbag->add('description', PLUGIN_EVENT_SPAMBLOCK_LOGTYPE_DESC);
+ $propbag->add('default', 'db');
+ $propbag->add('radio', array(
+ 'value' => array('file', 'db', 'none'),
+ 'desc' => array(PLUGIN_EVENT_SPAMBLOCK_LOGTYPE_FILE, PLUGIN_EVENT_SPAMBLOCK_LOGTYPE_DB, PLUGIN_EVENT_SPAMBLOCK_LOGTYPE_NONE)
+ ));
+ $propbag->add('radio_per_row', '1');
+
+ break;
+
case 'ipflood':
$propbag->add('type', 'string');
$propbag->add('name', PLUGIN_EVENT_SPAMBLOCK_IPFLOOD);
@@ -253,6 +277,40 @@
return true;
}
+ function checkScheme($maxVersion) {
+ global $serendipity;
+
+ $version = $this->get_config('version', '1.0');
+
+ if ($version != $maxVersion) {
+ $q = "CREATE TABLE {$serendipity['dbPrefix']}spamblocklog (
+ timestamp int(10) {UNSIGNED} default null,
+ type varchar(255),
+ reason text,
+ entry_id int(10) {UNSIGNED} not null default '0',
+ author varchar(80),
+ email varchar(200),
+ url varchar(200),
+ useragent varchar(255),
+ ip varchar(15),
+ referer varchar(255),
+ body text)";
+ $sql = serendipity_db_schema_import($q);
+
+ $q = "CREATE INDEX kspamidx ON {$serendipity['dbPrefix']}karma (timestamp);";
+ $sql = serendipity_db_schema_import($q);
+
+ $q = "CREATE INDEX kspamtypeidx ON {$serendipity['dbPrefix']}karma (type);";
+ $sql = serendipity_db_schema_import($q);
+
+ $q = "CREATE INDEX kspamentryidx ON {$serendipity['dbPrefix']}karma (entry_id);";
+ $sql = serendipity_db_schema_import($q);
+
+ $this->set_config('version', $maxVersion);
+ }
+
+ return true;
+ }
function generate_content(&$title) {
$title = $this->title;
@@ -296,6 +354,10 @@
case 'frontend_saveComment':
if (!is_array($eventData) || serendipity_db_bool($eventData['allow_comments'])) {
+ if ($this->get_config('logtype', 'db') == 'db' && $this->get_config('version') != $bag->get('version')) {
+ $this->checkScheme($bag->get('version'));
+ }
+
$serendipity['csuccess'] = 'true';
$logfile = $this->get_config('logfile', $serendipity['serendipityPath'] . 'spamblock.log');
@@ -570,30 +632,62 @@
function log($logfile, $id, $switch, $reason, $comment) {
global $serendipity;
- if (empty($logfile)) {
- return;
- }
+ $method = $this->get_config('logtype');
- $fp = @fopen($logfile, 'a+');
- if (!is_resource($fp)) {
- return;
- }
+ switch($method) {
+ case 'file':
+ if (empty($logfile)) {
+ return;
+ }
- fwrite($fp, sprintf(
- '[%s] - [%s: %s] - [#%s, Name "%s", E-Mail "%s", URL "%s", User-Agent "%s", IP %s] - [%s]' . "\n",
- date('Y-m-d H:i:s', serendipity_serverOffsetHour()),
- $switch,
- $reason,
- $id,
- str_replace("\n", ' ', $comment['name']),
- str_replace("\n", ' ', $comment['email']),
- str_replace("\n", ' ', $comment['url']),
- str_replace("\n", ' ', $_SERVER['HTTP_USER_AGENT']),
- $_SERVER['REMOTE_ADDR'],
- str_replace("\n", ' ', $comment['comment'])
- ));
+ $fp = @fopen($logfile, 'a+');
+ if (!is_resource($fp)) {
+ return;
+ }
- fclose($fp);
+ fwrite($fp, sprintf(
+ '[%s] - [%s: %s] - [#%s, Name "%s", E-Mail "%s", URL "%s", User-Agent "%s", IP %s] - [%s]' . "\n",
+ date('Y-m-d H:i:s', serendipity_serverOffsetHour()),
+ $switch,
+ $reason,
+ $id,
+ str_replace("\n", ' ', $comment['name']),
+ str_replace("\n", ' ', $comment['email']),
+ str_replace("\n", ' ', $comment['url']),
+ str_replace("\n", ' ', $_SERVER['HTTP_USER_AGENT']),
+ $_SERVER['REMOTE_ADDR'],
+ str_replace("\n", ' ', $comment['comment'])
+ ));
+
+ fclose($fp);
+ break;
+
+ case 'none':
+ return;
+ break;
+
+ case 'db':
+ default:
+ $q = sprintf("INSERT INTO {$serendipity['dbPrefix']}spamblocklog
+ (timestamp, type, reason, entry_id, author, email, url, useragent, ip, referer, body)
+ VALUES (%d, '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s')",
+
+ serendipity_serverOffsetHour(),
+ serendipity_db_escape_string($switch),
+ serendipity_db_escape_string($reason),
+ serendipity_db_escape_string($id),
+ serendipity_db_escape_string($comment['name']),
+ serendipity_db_escape_string($comment['email']),
+ serendipity_db_escape_string($comment['url']),
+ serendipity_db_escape_string($_SERVER['HTTP_USER_AGENT']),
+ serendipity_db_escape_string($_SERVER['REMOTE_ADDR']),
+ serendipity_db_escape_string(isset($_SESSION['HTTP_REFERER']) ? $_SESSION['HTTP_REFERER'] : $_SERVER['HTTP_REFERER']),
+ serendipity_db_escape_string($comment['comment'])
+ );
+
+ serendipity_db_query($q);
+ break;
+ }
}
}
|