From 0d88c9da19720f7449c64cd3fcc759b3e0ffc31c Mon Sep 17 00:00:00 2001 From: Marijn Kampf Date: Thu, 9 Jun 2011 02:35:23 -0700 Subject: [PATCH 1/2] Inserted missing validator notify callback object --- code/MathSpamProtectorField.php | 58 +++++++++++++++++++-------------- 1 file changed, 34 insertions(+), 24 deletions(-) diff --git a/code/MathSpamProtectorField.php b/code/MathSpamProtectorField.php index 6b0f804..754645d 100644 --- a/code/MathSpamProtectorField.php +++ b/code/MathSpamProtectorField.php @@ -2,7 +2,7 @@ /** * {@link FormField} for adding an optional maths protection question to a form. - * + * * @package mathspamprotection */ @@ -12,7 +12,7 @@ class MathSpamProtectorField extends SpamProtectorField { * @var bool If MathSpamProtection is enabled */ private static $enabled = true; - + /** * Outputs the field HTML to the the web browser * @@ -31,37 +31,47 @@ class MathSpamProtectorField extends SpamProtectorField { 'maxlength' => ($this->maxLength) ? $this->maxLength : null, 'size' => ($this->maxLength) ? min( $this->maxLength, 30 ) : null ); - + return $this->createTag('input', $attributes); } } - + /** * Returns the spam question - * + * * @return string */ function Title() { return sprintf(_t('MathSpamProtectionField.SPAMQUESTION', "Spam protection question: %s"), self::get_math_question()); } - + /** * Validates the value submitted by the user with the one saved - * into the {@link Session} + * into the {@link Session} and then notify callback object + * with the spam checking result. * - * @return bool + * @return bool */ function validate($validator) { if(!self::is_enabled()) return true; if(!self::correct_answer($this->Value())){ + $validator->validationError( + $this->name, + _t( + 'MathSpamProtectionField.INCORRECTSOLUTION', + "Incorrect solution to the spam protection question, please try again.", + PR_MEDIUM + ), + "error" + ); return false; } - + return true; } - - + + /** * Creates the question from random variables, which are also saved to the session. * @@ -78,16 +88,16 @@ class MathSpamProtectorField extends SpamProtectorField { $v1 = Session::get("mathQuestionV1"); $v2 = Session::get("mathQuestionV2"); } - + return sprintf( - _t('MathSpamProtection.WHATIS',"What is %s plus %s?"), - MathSpamProtectorField::digit_to_word($v1), + _t('MathSpamProtection.WHATIS',"What is %s plus %s?"), + MathSpamProtectorField::digit_to_word($v1), MathSpamProtectorField::digit_to_word($v2) ); } - + /** - * Checks the given answer if it matches the addition of the saved session variables. + * Checks the given answer if it matches the addition of the saved session variables. * Users can answer using words or digits. * * @return bool @@ -95,13 +105,13 @@ class MathSpamProtectorField extends SpamProtectorField { public static function correct_answer($answer){ $v1 = Session::get("mathQuestionV1"); $v2 = Session::get("mathQuestionV2"); - + Session::clear('mathQuestionV1'); Session::clear('mathQuestionV2'); - + return (MathSpamProtectorField::digit_to_word($v1 + $v2) == $answer || ($v1 + $v2) == $answer); } - + /** * Helper method for converting digits to their equivalent english words * @@ -126,13 +136,13 @@ class MathSpamProtectorField extends SpamProtectorField { _t('MathSpamProtection.FIFTEEN', 'fifteen'), _t('MathSpamProtection.SIXTEEN', 'sixteen'), _t('MathSpamProtection.SEVENTEEN', 'seventeen'), - _t('MathSpamProtection.EIGHTEEN', 'eighteen')); - + _t('MathSpamProtection.EIGHTEEN', 'eighteen')); + if($num < 0) return "minus ".($numbers[-1*$num]); - + return $numbers[$num]; } - + /** * Returns true when math spam protection is enabled * @@ -141,7 +151,7 @@ class MathSpamProtectorField extends SpamProtectorField { public static function is_enabled() { return (bool) self::$enabled; } - + /** * Set whether math spam protection is enabled * From 8bb002688e718b263263b182d6436ee5289b1ba0 Mon Sep 17 00:00:00 2001 From: Marijn Kampf Date: Thu, 9 Jun 2011 11:41:44 +0100 Subject: [PATCH 2/2] Ordered numbering in language files for easier translation Added Dutch translation --- lang/en_US.php | 37 +++++++++++++++++++------------------ lang/nl_NL.php | 28 ++++++++++++++++++++++++++++ 2 files changed, 47 insertions(+), 18 deletions(-) create mode 100644 lang/nl_NL.php diff --git a/lang/en_US.php b/lang/en_US.php index 82f362e..2deb5cb 100644 --- a/lang/en_US.php +++ b/lang/en_US.php @@ -2,26 +2,27 @@ global $lang; -$lang['en_US']['MathSpamProtection']['EIGHT'] = 'eight'; -$lang['en_US']['MathSpamProtection']['EIGHTEEN'] = 'eighteen'; -$lang['en_US']['MathSpamProtection']['ELEVEN'] = 'eleven'; -$lang['en_US']['MathSpamProtection']['FIFTEEN'] = 'fifteen'; -$lang['en_US']['MathSpamProtection']['FIVE'] = 'five'; -$lang['en_US']['MathSpamProtection']['FOUR'] = 'four'; -$lang['en_US']['MathSpamProtection']['FOURTEEN'] = 'fourteen'; -$lang['en_US']['MathSpamProtection']['NINE'] = 'nine'; -$lang['en_US']['MathSpamProtection']['ONE'] = 'one'; -$lang['en_US']['MathSpamProtection']['SEVEN'] = 'seven'; +$lang['en_US']['MathSpamProtection']['ZERO'] = 'zero'; +$lang['en_US']['MathSpamProtection']['ONE'] = 'one'; +$lang['en_US']['MathSpamProtection']['TWO'] = 'two'; +$lang['en_US']['MathSpamProtection']['THREE'] = 'three'; +$lang['en_US']['MathSpamProtection']['FOUR'] = 'four'; +$lang['en_US']['MathSpamProtection']['FIVE'] = 'five'; +$lang['en_US']['MathSpamProtection']['SIX'] = 'six'; +$lang['en_US']['MathSpamProtection']['SEVEN'] = 'seven'; +$lang['en_US']['MathSpamProtection']['EIGHT'] = 'eight'; +$lang['en_US']['MathSpamProtection']['NINE'] = 'nine'; +$lang['en_US']['MathSpamProtection']['TEN'] = 'ten'; +$lang['en_US']['MathSpamProtection']['ELEVEN'] = 'eleven'; +$lang['en_US']['MathSpamProtection']['TWELVE'] = 'twelve'; +$lang['en_US']['MathSpamProtection']['THIRTEEN'] = 'thirteen'; +$lang['en_US']['MathSpamProtection']['FOURTEEN'] = 'fourteen'; +$lang['en_US']['MathSpamProtection']['FIFTEEN'] = 'fifteen'; +$lang['en_US']['MathSpamProtection']['SIXTEEN'] = 'sixteen'; $lang['en_US']['MathSpamProtection']['SEVENTEEN'] = 'seventeen'; -$lang['en_US']['MathSpamProtection']['SIX'] = 'six'; -$lang['en_US']['MathSpamProtection']['SIXTEEN'] = 'sixteen'; -$lang['en_US']['MathSpamProtection']['TEN'] = 'ten'; -$lang['en_US']['MathSpamProtection']['THIRTEEN'] = 'thirteen'; -$lang['en_US']['MathSpamProtection']['THREE'] = 'three'; -$lang['en_US']['MathSpamProtection']['TWELVE'] = 'twelve'; -$lang['en_US']['MathSpamProtection']['TWO'] = 'two'; +$lang['en_US']['MathSpamProtection']['EIGHTEEN'] = 'eighteen'; $lang['en_US']['MathSpamProtection']['WHATIS'] = 'What is %s plus %s?'; -$lang['en_US']['MathSpamProtection']['ZERO'] = 'zero'; $lang['en_US']['MathSpamProtectionField']['SPAMQUESTION'] = 'Spam protection question: %s'; +$lang['en_US']['MathSpamProtectionField']['INCORRECTSOLUTION'] = 'Incorrect solution to the spam protection question, please try again.'; ?> \ No newline at end of file diff --git a/lang/nl_NL.php b/lang/nl_NL.php new file mode 100644 index 0000000..68d218f --- /dev/null +++ b/lang/nl_NL.php @@ -0,0 +1,28 @@ + \ No newline at end of file