diff --git a/code/sitefeatures/MathSpamProtection.php b/code/sitefeatures/MathSpamProtection.php new file mode 100644 index 00000000..50a9e9a4 --- /dev/null +++ b/code/sitefeatures/MathSpamProtection.php @@ -0,0 +1,59 @@ + diff --git a/code/sitefeatures/PageCommentInterface.php b/code/sitefeatures/PageCommentInterface.php index d386f23b..5ebbb20c 100755 --- a/code/sitefeatures/PageCommentInterface.php +++ b/code/sitefeatures/PageCommentInterface.php @@ -30,12 +30,22 @@ class PageCommentInterface extends ViewableData { Requirements::javascript('jsparty/scriptaculous/effects.js'); Requirements::javascript('cms/javascript/PageCommentInterface.js'); - $form = new PageCommentInterface_Form($this->controller, $this->methodName . ".PostCommentForm", new FieldSet( - new HiddenField("ParentID", "ParentID", $this->page->ID), - new TextField("Name", "Your name"), - new TextareaField("Comment", "Comments") - ), new FieldSet( + $fields = new FieldSet( + 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())); + } + + 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( new FormAction("postcomment", "Post") )); @@ -102,6 +112,20 @@ class PageCommentInterface_Form extends Form { } } + //check if spam question was right. + if(MathSpamProtection::isEnabled()){ + if(!MathSpamProtection::correctAnswer($data['Math'])){ + echo "

You got the spam protection question wrong.

"; + return; + } + } + + if(CaptchaSpamProtection::isEnabled()){ + if(!CaptchaSpamProtection::correctAnswer($data['Captcha'])){ + echo "

You got the captcha protection question wrong.

"; + return; + } + } Cookie::set("PageCommentInterface_Name", $data['Name']);