From: garvinhicking Date: Fri, 30 Dec 2005 15:38:56 +0000 (+0000) Subject: People seem to want this: Block comments based on their content. X-Git-Tag: 1.0~200 X-Git-Url: http://git.mjollnir.org/gw?a=commitdiff_plain;h=c73da4501e6175acff4abd253846f2c3913063f3;p=s9y.git People seem to want this: Block comments based on their content. --- diff --git a/docs/NEWS b/docs/NEWS index 397f17d..8eba31e 100644 --- a/docs/NEWS +++ b/docs/NEWS @@ -3,6 +3,9 @@ Version 1.0 () ------------------------------------------------------------------------ + * Make spartacus plugin be able to filter comment bodies + (garvinhicking) + * Fixed bug which broke thumbnail generation with Imagemagick when safe-mode was ON (tomsommer) diff --git a/plugins/serendipity_event_spamblock/lang_en.inc.php b/plugins/serendipity_event_spamblock/lang_en.inc.php index 9ad2878..45c4241 100644 --- a/plugins/serendipity_event_spamblock/lang_en.inc.php +++ b/plugins/serendipity_event_spamblock/lang_en.inc.php @@ -72,6 +72,7 @@ @define('PLUGIN_EVENT_SPAMBLOCK_FILTER_URLS_DESC', 'Regular Expressions allowed, separate strings by semicolons (;).'); @define('PLUGIN_EVENT_SPAMBLOCK_FILTER_AUTHORS', 'Wordfilter for author names'); @define('PLUGIN_EVENT_SPAMBLOCK_FILTER_AUTHORS_DESC', 'Regular Expressions allowed, separate strings by semicolons (;).'); +@define('PLUGIN_EVENT_SPAMBLOCK_FILTER_WORDS', 'Wordfilter for comment body'); @define('PLUGIN_EVENT_SPAMBLOCK_REASON_CHECKMAIL', 'Invalid e-mail address'); @define('PLUGIN_EVENT_SPAMBLOCK_CHECKMAIL', 'Check e-mail addresses?'); diff --git a/plugins/serendipity_event_spamblock/serendipity_event_spamblock.php b/plugins/serendipity_event_spamblock/serendipity_event_spamblock.php index d1aed6e..9881020 100644 --- a/plugins/serendipity_event_spamblock/serendipity_event_spamblock.php +++ b/plugins/serendipity_event_spamblock/serendipity_event_spamblock.php @@ -34,7 +34,7 @@ var $filter_defaults; 'smarty' => '2.6.7', 'php' => '4.1.0' )); - $propbag->add('version', '1.27'); + $propbag->add('version', '1.30'); $propbag->add('event_hooks', array( 'frontend_saveComment' => true, 'external_plugin' => true, @@ -48,7 +48,8 @@ var $filter_defaults; $this->filter_defaults = array( 'authors' => 'casino;phentermine;credit;loans;poker', - 'urls' => '8gold\.com;911easymoney\.com;canadianlabels\.net;condodream\.com;crepesuzette\.com;debt-help-bill-consolidation-elimination\.com;fidelityfunding\.net;flafeber\.com;gb\.com;houseofsevengables\.com;instant-quick-money-cash-advance-personal-loans-until-pay-day\.com;mediavisor\.com;newtruths\.com;oiline\.com;onlinegamingassociation\.com;online\-+poker\.com;popwow\.com;royalmailhotel\.com;spoodles\.com;sportsparent\.com;stmaryonline\.org;thatwhichis\.com;tmsathai\.org;uaeecommerce\.com;learnhowtoplay\.com' + 'urls' => '8gold\.com;911easymoney\.com;canadianlabels\.net;condodream\.com;crepesuzette\.com;debt-help-bill-consolidation-elimination\.com;fidelityfunding\.net;flafeber\.com;gb\.com;houseofsevengables\.com;instant-quick-money-cash-advance-personal-loans-until-pay-day\.com;mediavisor\.com;newtruths\.com;oiline\.com;onlinegamingassociation\.com;online\-+poker\.com;popwow\.com;royalmailhotel\.com;spoodles\.com;sportsparent\.com;stmaryonline\.org;thatwhichis\.com;tmsathai\.org;uaeecommerce\.com;learnhowtoplay\.com', + 'words' => 'very good site!;Real good stuff!' ); } @@ -159,6 +160,13 @@ var $filter_defaults; $propbag->add('default', $this->filter_defaults['authors']); break; + case 'contentfilter_words': + $propbag->add('type', 'text'); + $propbag->add('name', PLUGIN_EVENT_SPAMBLOCK_FILTER_WORDS); + $propbag->add('description', PLUGIN_EVENT_SPAMBLOCK_FILTER_AUTHORS_DESC); + $propbag->add('default', $this->filter_defaults['words']); + break; + case 'logfile': $propbag->add('type', 'string'); $propbag->add('name', PLUGIN_EVENT_SPAMBLOCK_LOGFILE); @@ -231,19 +239,19 @@ var $filter_defaults; function getBlacklist($where) { global $serendipity; - + switch($where) { case 'blogg.de': $target = $serendipity['serendipityPath'] . PATH_SMARTY_COMPILE . '/blogg.de.blacklist.txt'; $timeout = 3600; // One hour - + if (file_exists($target) && filemtime($target) > time()-$timeout) { $data = file_get_contents($target); } else { $data = ''; require_once S9Y_PEAR_PATH . 'HTTP/Request.php'; $req = &new HTTP_Request('http://spam.blogg.de/blacklist.txt'); - + if (PEAR::isError($req->sendRequest()) || $req->getResponseCode() != '200') { if (file_exists($target) && filesize($target) > 0) { $data = file_get_contents($target); @@ -252,17 +260,17 @@ var $filter_defaults; // Fetch file $data = $req->getResponseBody(); $fp = @fopen($target, 'w'); - + if ($fp) { fwrite($fp, $data); fclose($fp); } } } - + $blacklist = explode("\n", $data); return $blacklist; - + default: return false; } @@ -352,7 +360,7 @@ var $filter_defaults; $serendipity['csuccess'] = 'true'; $logfile = $this->get_config('logfile', $serendipity['serendipityPath'] . 'spamblock.log'); $required_fields = $this->get_config('required_fields', ''); - + // Check required fields if ($addData['type'] == 'NORMAL' && !empty($required_fields)) { $required_field_list = explode(',', $required_fields); @@ -366,7 +374,7 @@ var $filter_defaults; } } } - + // Check if entry title is the same as comment body if (serendipity_db_bool($this->get_config('entrytitle')) && trim($eventData['title']) == trim($addData['comment'])) { $this->log($logfile, $eventData['id'], 'REJECTED', PLUGIN_EVENT_SPAMBLOCK_REASON_TITLE, $addData); @@ -448,8 +456,32 @@ var $filter_defaults; } } } + + // Filter Content + $filter_bodys = explode(';', $this->get_config('contentfilter_words', $this->filter_defaults['words'])); + if (is_array($filter_bodys)) { + foreach($filter_bodys AS $filter_body) { + if (empty($filter_body)) { + continue; + } + if (preg_match('@' . $filter_body . '@', $addData['comment'])) { + if ($filter_type == 'moderate') { + $this->log($logfile, $eventData['id'], 'MODERATE', PLUGIN_EVENT_SPAMBLOCK_FILTER_WORDS, $addData); + $eventData['moderate_comments'] = true; + $serendipity['csuccess'] = 'moderate'; + $serendipity['moderate_reason'] = PLUGIN_EVENT_SPAMBLOCK_ERROR_BODY; + return false; + } else { + $this->log($logfile, $eventData['id'], 'REJECTED', PLUGIN_EVENT_SPAMBLOCK_FILTER_WORDS, $addData); + $eventData = array('allow_comments' => false); + $serendipity['messagestack']['comments'][] = PLUGIN_EVENT_SPAMBLOCK_ERROR_BODY; + return false; + } + } + } + } } - + // Filter Blogg.de Blacklist? $bloggdeblacklist = $this->get_config('bloggdeblacklist'); if ($bloggdeblacklist == 'moderate' || $bloggdeblacklist == 'reject') { @@ -460,7 +492,7 @@ var $filter_defaults; if (empty($domain)) { continue; } - + if (preg_match('@' . preg_quote($domain) . '@i', $addData['url'])) { if ($bloggdeblacklist == 'moderate') { $this->log($logfile, $eventData['id'], 'MODERATE', PLUGIN_EVENT_SPAMBLOCK_REASON_BLOGG_SPAMLIST . ': ' . $domain, $addData); @@ -546,7 +578,7 @@ var $filter_defaults; return false; } } - + // Check invalid email if ($addData['type'] == 'NORMAL' && serendipity_db_bool($this->get_config('checkmail', false))) { if (!empty($addData['email']) && strstr($addData['email'], '@') === false) { @@ -556,7 +588,7 @@ var $filter_defaults; } } } - + return true; break; @@ -742,7 +774,7 @@ var $filter_defaults; } } } - + if ($getItems) { if (!$filtered && !empty($match)) { $items[] = preg_quote($match, '@'); @@ -750,18 +782,18 @@ var $filter_defaults; return $items; } - + return $filtered; } function getComment($key, $id) { global $serendipity; $c = serendipity_db_query("SELECT $key FROM {$serendipity['dbPrefix']}comments WHERE id = '" . (int)$id . "'", true, 'assoc'); - + if (!is_array($c) || !isset($c[$key])) { return false; } - + return $c[$key]; }