From c0f872b8fed99f31359fadffda9d3dbe6b80277f Mon Sep 17 00:00:00 2001 From: Jeremy Shipman Date: Tue, 14 Aug 2007 04:39:29 +0000 Subject: [PATCH] Improved spam protection question updating. Now refreshes immediately after posting the form, no matter if you get it right or wrong. More consistent notification if you get the question wrong (same box used as other notifications). git-svn-id: svn://svn.silverstripe.com/silverstripe/open/modules/cms/trunk@39981 467b73ca-7a2a-4603-9d3b-597d59a354a9 --- code/sitefeatures/MathSpamProtection.php | 10 +++++- code/sitefeatures/PageCommentInterface.php | 41 ++++++++++++---------- 2 files changed, 31 insertions(+), 20 deletions(-) diff --git a/code/sitefeatures/MathSpamProtection.php b/code/sitefeatures/MathSpamProtection.php index 841894b9..091fd321 100644 --- a/code/sitefeatures/MathSpamProtection.php +++ b/code/sitefeatures/MathSpamProtection.php @@ -38,7 +38,15 @@ class MathSpamProtection { static function correctAnswer($answer){ $v1 = Session::get("mathQuestionV1"); $v2 = Session::get("mathQuestionV2"); - return (MathSpamProtection::digitToWord($v1 + $v2) == $answer || ($v1 + $v2) == $answer) ? true : false; + + Session::clear('mathQuestionV1'); + Session::clear('mathQuestionV2'); + + if(MathSpamProtection::digitToWord($v1 + $v2) == $answer || ($v1 + $v2) == $answer){ + return true; + } + return false; + } /** diff --git a/code/sitefeatures/PageCommentInterface.php b/code/sitefeatures/PageCommentInterface.php index 71bad90e..83070a9b 100755 --- a/code/sitefeatures/PageCommentInterface.php +++ b/code/sitefeatures/PageCommentInterface.php @@ -35,15 +35,11 @@ class PageCommentInterface extends ViewableData { new HiddenField("ParentID", "ParentID", $this->page->ID), new TextField("Name", "Your name") ); + if(MathSpamProtection::isEnabled()){ $fields->push(new TextField("Math","Spam protection question: ".MathSpamProtection::getMathQuestion())); } - /*//TODO - if(CaptchaSpamProtection::isEnabled()){ - $fields->push(new TextField("Captcha",CaptchaSpamProtection::getImage()."

Please copy down the text from the image above")); - } */ - $fields->push(new TextareaField("Comment", "Comments")); $form = new PageCommentInterface_Form($this->controller, $this->methodName . ".PostCommentForm",$fields, new FieldSet( @@ -116,25 +112,15 @@ class PageCommentInterface_Form extends Form { } //check if spam question was right. - if(MathSpamProtection::isEnabled()){ + if(MathSpamProtection::isEnabled()){ if(!MathSpamProtection::correctAnswer($data['Math'])){ - if(Director::is_ajax()) { - echo "

You got the spam protection question wrong.

"; - } else { + if(!Director::is_ajax()) { Director::redirectBack(); } - return; + return "spamprotectionfalied"; //used by javascript for checking if the spam question was wrong } } - /* - if(CaptchaSpamProtection::isEnabled()){ - if(!CaptchaSpamProtection::correctAnswer($data['Captcha'])){ - echo "

You got the captcha protection question wrong.

"; - return; - } - }*/ - Cookie::set("PageCommentInterface_Name", $data['Name']); $comment = Object::create('PageComment'); @@ -145,11 +131,28 @@ class PageCommentInterface_Form extends Form { $comment->write(); if(Director::is_ajax()) { - echo $comment->renderWith('PageCommentInterface_singlecomment'); + if($comment->NeedsModeration){ + echo "Your comment has been submitted and is now awating moderation."; + } else{ + echo $comment->renderWith('PageCommentInterface_singlecomment'); + } } else { Director::redirectBack(); } } } +class PageCommentInterface_Controller extends ContentController { + function __construct() { + parent::__construct(null); + } + + function newspamquestion() { + if(Director::is_ajax()) { + echo Convert::raw2xml("Spam protection question: ".MathSpamProtection::getMathQuestion()); + exit; + } + } +} + ?> \ No newline at end of file