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