From a1b85b0d970d8595a43a79cc36af2e38b05d084e Mon Sep 17 00:00:00 2001 From: Jarkko Linnanvirta Date: Wed, 26 Aug 2015 21:58:40 +0300 Subject: [PATCH 1/2] Create allow_numeric_answer option This option allows you to stop accepting numeric answers as they do not always prevent spam. By default, numeric answers are accepted, so this commit does not make any unintended changes to the behaviour of this field. --- code/MathSpamProtectorField.php | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/code/MathSpamProtectorField.php b/code/MathSpamProtectorField.php index 54ca3ea..00988f5 100644 --- a/code/MathSpamProtectorField.php +++ b/code/MathSpamProtectorField.php @@ -22,6 +22,13 @@ class MathSpamProtectorField extends TextField { */ private static $question_prefix; + /** + * @config + * + * @var bool $allow_numeric_answer + */ + private static $allow_numeric_answer = true; + public function Field($properties = array()) { if(Config::inst()->get('MathSpamProtectorField', 'enabled')) { return parent::Field($properties); @@ -126,7 +133,8 @@ class MathSpamProtectorField extends TextField { $word = MathSpamProtectorField::digit_to_word($v1 + $v2); - return ($word == strtolower($answer) || ($v1 + $v2) == $answer); + $allow_numeric_answer = Config::inst()->get('MathSpamProtectorField', 'allow_numeric_answer'); + return ($word == strtolower($answer) || ((($v1 + $v2) == $answer) and $allow_numeric_answer)); } /** From 644360c9c00e4b29cc630e4109fc3b334278ba03 Mon Sep 17 00:00:00 2001 From: Jarkko Linnanvirta Date: Mon, 31 Aug 2015 17:09:40 +0300 Subject: [PATCH 2/2] Update MathSpamProtectorField.php --- code/MathSpamProtectorField.php | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/code/MathSpamProtectorField.php b/code/MathSpamProtectorField.php index 00988f5..6570c7a 100644 --- a/code/MathSpamProtectorField.php +++ b/code/MathSpamProtectorField.php @@ -133,8 +133,7 @@ class MathSpamProtectorField extends TextField { $word = MathSpamProtectorField::digit_to_word($v1 + $v2); - $allow_numeric_answer = Config::inst()->get('MathSpamProtectorField', 'allow_numeric_answer'); - return ($word == strtolower($answer) || ((($v1 + $v2) == $answer) and $allow_numeric_answer)); + return ($word == strtolower($answer) || (Config::inst()->get('MathSpamProtectorField', 'allow_numeric_answer') && (($v1 + $v2) == $answer))); } /**