From: <al...@us...> - 2008-10-06 17:14:10
|
Revision: 723 http://sciret.svn.sourceforge.net/sciret/?rev=723&view=rev Author: alpeb Date: 2008-10-06 17:13:07 +0000 (Mon, 06 Oct 2008) Log Message: ----------- added ability for the admin to choose whether to use Askimet, TypePad Antispam, or Bad-Behavior Modified Paths: -------------- trunk/actions/AddCommentAndRating.php trunk/actions/SavePreferences.php trunk/javascript/general.js trunk/models/AntiSpam.php trunk/templates/EditPreferences.tpl trunk/views/EditPreferences.php Modified: trunk/actions/AddCommentAndRating.php =================================================================== --- trunk/actions/AddCommentAndRating.php 2008-10-06 17:11:43 UTC (rev 722) +++ trunk/actions/AddCommentAndRating.php 2008-10-06 17:13:07 UTC (rev 723) @@ -11,9 +11,15 @@ require 'actions/Action.php'; -class AddCommentAndRating extends Action { +class AddCommentAndRating extends Action +{ - function dispatch() { + function dispatch() + { + if ($this->configuration->getConfigValue('badBehaviorEnabled')) { + require 'libs/bad-behavior/bad-behavior-generic.php'; + } + $artId = isset($_GET['artId'])? (int)$_GET['artId'] : 0; if ($_POST['comment_box'] != '' && $_POST['commentUserName'] == '') { exit; @@ -22,30 +28,17 @@ $message = ''; if ($_POST['comment_box'] != '') { - $antiSpam = new AntiSpam($this->configuration); - try { - $data = array( - 'user_ip' => $_SERVER['REMOTE_ADDR'], - 'user_agent' => $_SERVER['HTTP_USER_AGENT'], - 'referer' => isset($_SERVER['HTTP_REFERER'])? $_SERVER['HTTP_REFERER'] : '', - 'permalink' => Library::getBaseURL() . "/view=ViewArticle&id=$artId", - 'comment_type' => 'comment', - 'comment_author' => $_POST['commentUserName'], - 'comment_content' => $_POST['comment_box'], - ); - if ($antiSpam->isSpam($data)) { - $message = $this->user->lang('Comment detected as spam. ** DISCARDED **'); - Library::redirect(Library::getLink(array( - 'view' => 'ViewComments', - 'artId' => $artId, - 'commentsMessage' => urlencode($message) - ))); - } - } catch (Exception $e) { - // TypePad AntiSpam API Key is wrong, so nothing to do in this case :( + if ($this->configuration->getConfigValue('akismetEnabled')) { + $antiSpam = new AntiSpam($this->configuration, AntiSpam::TYPE_AKISMET); + $this->_checkForSpam($antiSpam, $artId); } + if ($this->configuration->getConfigValue('typePadAntiSpamEnabled')) { + $antiSpam = new AntiSpam($this->configuration, AntiSpam::TYPE_TYPEPAD); + $this->_checkForSpam($antiSpam, $artId); + } + $comment = new Comment; $comment->setUserName($_POST['commentUserName']); $comment->setEntered(date('Y-m-d h:i:s')); @@ -73,6 +66,30 @@ Library::redirect(Library::getLink(array('view' => 'ViewComments', 'artId' => $artId, 'commentsMessage' => urlencode($message)))); } + + private function _checkForSpam($antiSpam, $artId) + { + $data = array( + 'user_ip' => $_SERVER['REMOTE_ADDR'], + 'user_agent' => $_SERVER['HTTP_USER_AGENT'], + 'referer' => isset($_SERVER['HTTP_REFERER'])? $_SERVER['HTTP_REFERER'] : '', + 'permalink' => Library::getBaseURL() . "/view=ViewArticle&id=$artId", + 'comment_type' => 'comment', + 'comment_author' => $_POST['commentUserName'], + 'comment_content' => $_POST['comment_box'], + ); + + try { + if ($antiSpam->isSpam($data)) { + $message = $this->user->lang('Comment detected as spam. ** DISCARDED **'); + Library::redirect(Library::getLink(array( + 'view' => 'ViewComments', + 'artId' => $artId, + 'commentsMessage' => urlencode($message) + ))); + } + } catch (Exception $e) { + // TypePad AntiSpam API Key is wrong, so nothing to do in this case :( + } + } } - -?> Modified: trunk/actions/SavePreferences.php =================================================================== --- trunk/actions/SavePreferences.php 2008-10-06 17:11:43 UTC (rev 722) +++ trunk/actions/SavePreferences.php 2008-10-06 17:13:07 UTC (rev 723) @@ -55,6 +55,10 @@ $this->configuration->setConfigValue('smtpPassword', $_POST['smtpPassword']); $this->configuration->setConfigValue('smtpPort', $_POST['smtpPort']); $this->configuration->setConfigValue('useClamAV', $_POST['useClamAV']); + $this->configuration->setConfigValue('akismetEnabled', isset($_POST['akismetEnabled'])); + $this->configuration->setConfigValue('typePadAntiSpamEnabled', isset($_POST['typePadAntiSpamEnabled'])); + $this->configuration->setConfigValue('badBehaviorEnabled', isset($_POST['badBehaviorEnabled'])); + $this->configuration->setConfigValue('akismetKey', $_POST['akismetKey']); $this->configuration->setConfigValue('typePadAntiSpamKey', $_POST['typePadAntiSpamKey']); if ($_POST['useClamAV'] == '1') { @@ -66,14 +70,24 @@ } } - if ($_POST['typePadAntiSpamKey'] != '') { - $antiSpam = new AntiSpam($this->configuration); + if (isset($_POST['typePadAntiSpamEnabled'])) { + $antiSpam = new AntiSpam($this->configuration, AntiSpam::TYPE_TYPEPAD); if (!$antiSpam->verifyKey()) { $errors[] = $this->user->lang('Your TypePad AntiSpam key is wrong. Please verify.'); + $this->configuration->setConfigValue('typePadAntiSpamEnabled', false); $this->configuration->setConfigValue('typePadAntiSpamKey', ''); } } + if (isset($_POST['akismetEnabled'])) { + $antiSpam = new AntiSpam($this->configuration, AntiSpam::TYPE_AKISMET); + if (!$antiSpam->verifyKey()) { + $errors[] = $this->user->lang('Your Akismet key is wrong. Please verify.'); + $this->configuration->setConfigValue('akismetEnabled', false); + $this->configuration->setConfigValue('akismetKey', ''); + } + } + $this->configuration->save(); } Modified: trunk/javascript/general.js =================================================================== --- trunk/javascript/general.js 2008-10-06 17:11:43 UTC (rev 722) +++ trunk/javascript/general.js 2008-10-06 17:13:07 UTC (rev 723) @@ -58,6 +58,22 @@ replaceContent: function(responseObj, elId) { $(elId).innerHTML = responseObj.responseText; SCIRET.utils.evalScripts(elId); + }, + + show: function(elId, useEffects) { + if (useEffects) { + new YAHOO.widget.Effects.Appear(elId, {seconds: 0.5}); + } else { + $(elId).style.display = ""; + } + }, + + hide: function(elId, useEffects) { + if (useEffects) { + new YAHOO.widget.Effects.Fade(elId, {seconds: 0.5}); + } else { + $(elId).style.display = "none"; + } } }; }(); @@ -290,14 +306,31 @@ } } -function toggleSMTPSettings(smtp) -{ - if (smtp == 'smtp') { - new YAHOO.widget.Effects.Appear('smtp_options', {seconds: 0.5}); - } else { - new YAHOO.widget.Effects.Fade('smtp_options', {seconds: 0.5}); +SCIRET.preferences = function() { + return { + toggleKeyFields: function(useEffects) { + if (document.preferencesForm.akismetEnabled.checked) { + SCIRET.utils.show("trAkismetKey", useEffects); + } else { + SCIRET.utils.hide("trAkismetKey", useEffects); + } + + if (document.preferencesForm.typePadAntiSpamEnabled.checked) { + SCIRET.utils.show("trTypePadAntiSpamKey", useEffects); + } else { + SCIRET.utils.hide("trTypePadAntiSpamKey", useEffects); + } + }, + + toggleSMTPSettings: function(smtp) { + if (smtp == 'smtp') { + SCIRET.utils.show('smtp_options', true); + } else { + SCIRET.utils.hide('smtp_options', true); + } + } } -} +}(); // ********************************************************* // ** CALENDAR FUNCTIONS ** Modified: trunk/models/AntiSpam.php =================================================================== --- trunk/models/AntiSpam.php 2008-10-06 17:11:43 UTC (rev 722) +++ trunk/models/AntiSpam.php 2008-10-06 17:13:07 UTC (rev 723) @@ -11,25 +11,42 @@ class AntiSpam extends Zend_Service_Akismet { - const API_URL = 'api.antispam.typepad.com'; + const TYPE_AKISMET = 1; + const TYPE_TYPEPAD = 2; + const TYPEPAD_API_URL = 'api.antispam.typepad.com'; + private $_config; + private $_type; - public function __construct($config) + public function __construct($config, $type) { $this->_config = $config; + $this->_type = $type; - parent::__construct($config->getConfigValue('typePadAntiSpamKey'), - Library::getBaseURL()); + switch ($type) { + case self::TYPE_AKISMET: + parent::__construct($config->getConfigValue('akismetKey'), + Library::getBaseURL()); + break; + case self::TYPE_TYPEPAD: + parent::__construct($config->getConfigValue('typePadAntiSpamKey'), + Library::getBaseURL()); + break; + default: + throw new Exception('Wrong spam service type'); + } } protected function _post($host, $path, array $params) { - $caller = $this->_getCallerMethod(); - if (strtolower($caller) == 'verifykey') { - $host = self::API_URL; - } else { - $host = $this->getApiKey() . '.' . self::API_URL; + if ($this->_type == self::TYPE_TYPEPAD) { + $caller = $this->_getCallerMethod(); + if (strtolower($caller) == 'verifykey') { + $host = self::TYPEPAD_API_URL; + } else { + $host = $this->getApiKey() . '.' . self::TYPEPAD_API_URL; + } } return parent::_post($host, $path, $params); Modified: trunk/templates/EditPreferences.tpl =================================================================== --- trunk/templates/EditPreferences.tpl 2008-10-06 17:11:43 UTC (rev 722) +++ trunk/templates/EditPreferences.tpl 2008-10-06 17:13:07 UTC (rev 723) @@ -9,7 +9,7 @@ */ --> -<form method="post" action="{formAction}"> +<form name="preferencesForm" method="post" action="{formAction}"> <table cellpadding="3" cellspacing="2" border="0" style="margin:5px auto; border:1px solid black"> <tr class="row_on"> <td style="text-align:right; font-weight:bold">[l]Always start browsing[/l]:</td> @@ -139,7 +139,26 @@ </tr> <tr class="row_off"> <td style="text-align:right; font-weight:bold"> - [l]Enter your TypePad AntiSpam API key to be able to discard spam comments[/l]:<br /> + [l]Enable the following spam filtering services[/l]: + </td> + <td> + <input type="checkbox" name="akismetEnabled" {akismetEnabled} onclick="SCIRET.preferences.toggleKeyFields(true)" />Akismet<br /> + <input type="checkbox" name="typePadAntiSpamEnabled" {typePadAntiSpamEnabled} onclick="SCIRET.preferences.toggleKeyFields(true)" />TypePad AntiSpam<br /> + <input type="checkbox" name="badBehaviorEnabled" {badBehaviorEnabled} onclick="SCIRET.preferences.toggleKeyFields(true)" />Bad-Behavior + </td> + </tr> + <tr id="trAkismetKey" class="row_off" style="display:none"> + <td style="text-align:right; font-weight:bold"> + [l]Enter your Akismet API key[/l]:<br /> + [l](You can get a free key <a href="http://akismet.com/personal/">here</a>)[/l] + </td> + <td> + <input type="text" name="akismetKey" value="{akismetKey}"/> + </td> + </tr> + <tr id="trTypePadAntiSpamKey" class="row_off" style="display:none"> + <td style="text-align:right; font-weight:bold"> + [l]Enter your TypePad AntiSpam API key[/l]:<br /> [l](You can get a free key <a href="http://antispam.typepad.com/info/get-api-key.html">here</a>)[/l] </td> <td> @@ -188,7 +207,7 @@ <tr class="row_on"> <td style="text-align:right; font-weight:bold">[l]Send mail using[/l]:</td> <td> - <select name="mailTransport" onchange="javascript:toggleSMTPSettings(value);"> + <select name="mailTransport" onchange="SCIRET.preferences.toggleSMTPSettings(value);"> <option value="sendmail" {sendMailUsing_sendmail_selected}>Sendmail</option> <option value="smtp" {sendMailUsing_smtp_selected}>SMTP</option> </select> @@ -223,3 +242,6 @@ </tr> </table> </form> +<script> + SCIRET.preferences.toggleKeyFields(false); +</script> Modified: trunk/views/EditPreferences.php =================================================================== --- trunk/views/EditPreferences.php 2008-10-06 17:11:43 UTC (rev 722) +++ trunk/views/EditPreferences.php 2008-10-06 17:13:07 UTC (rev 723) @@ -68,6 +68,10 @@ 'smtpPort' => $this->configuration->getConfigValue('smtpPort'), 'useClamAV_yes_selected' => $this->configuration->getConfigValue('useClamAV') == '1'? 'selected="true"' : '', 'useClamAV_no_selected' => $this->configuration->getConfigValue('useClamAV') == '0'? 'selected="true"' : '', + 'akismetEnabled' => $this->configuration->getConfigValue('akismetEnabled') == '1'? 'checked="true"' : '', + 'typePadAntiSpamEnabled' => $this->configuration->getConfigValue('typePadAntiSpamEnabled') == '1'? 'checked="true"' : '', + 'badBehaviorEnabled' => $this->configuration->getConfigValue('badBehaviorEnabled') == '1'? 'checked="true"' : '', + 'akismetKey' => $this->configuration->getConfigValue('akismetKey'), 'typePadAntiSpamKey' => $this->configuration->getConfigValue('typePadAntiSpamKey'), )); This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |