mirror of
https://github.com/silverstripe/silverstripe-mathspamprotection
synced 2024-10-22 08:05:52 +02:00
Converted to PSR-2
This commit is contained in:
parent
a1a3227cb8
commit
82a51add39
@ -4,20 +4,22 @@
|
|||||||
* @package mathspamprotection
|
* @package mathspamprotection
|
||||||
*/
|
*/
|
||||||
|
|
||||||
class MathSpamProtector implements SpamProtector {
|
class MathSpamProtector implements SpamProtector
|
||||||
|
{
|
||||||
/**
|
/**
|
||||||
* Returns the {@link MathSpamProtectorField} associated with this protector
|
* Returns the {@link MathSpamProtectorField} associated with this protector
|
||||||
*
|
*
|
||||||
* @return MathSpamProtectorField
|
* @return MathSpamProtectorField
|
||||||
*/
|
*/
|
||||||
public function getFormField($name = null, $title = null, $value = null) {
|
public function getFormField($name = null, $title = null, $value = null)
|
||||||
|
{
|
||||||
return new MathSpamProtectorField($name, $title, $value);
|
return new MathSpamProtectorField($name, $title, $value);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Not used by MathSpamProtector
|
* Not used by MathSpamProtector
|
||||||
*/
|
*/
|
||||||
public function setFieldMapping($fieldMapping) {}
|
public function setFieldMapping($fieldMapping)
|
||||||
|
{
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -6,8 +6,8 @@
|
|||||||
* @package mathspamprotection
|
* @package mathspamprotection
|
||||||
*/
|
*/
|
||||||
|
|
||||||
class MathSpamProtectorField extends TextField {
|
class MathSpamProtectorField extends TextField
|
||||||
|
{
|
||||||
/**
|
/**
|
||||||
* @config
|
* @config
|
||||||
*
|
*
|
||||||
@ -29,7 +29,8 @@ class MathSpamProtectorField extends TextField {
|
|||||||
*/
|
*/
|
||||||
private static $allow_numeric_answer = true;
|
private static $allow_numeric_answer = true;
|
||||||
|
|
||||||
public function Field($properties = array()) {
|
public function Field($properties = array())
|
||||||
|
{
|
||||||
if (Config::inst()->get('MathSpamProtectorField', 'enabled')) {
|
if (Config::inst()->get('MathSpamProtectorField', 'enabled')) {
|
||||||
return parent::Field($properties);
|
return parent::Field($properties);
|
||||||
}
|
}
|
||||||
@ -37,7 +38,8 @@ class MathSpamProtectorField extends TextField {
|
|||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function FieldHolder($properties = array()) {
|
public function FieldHolder($properties = array())
|
||||||
|
{
|
||||||
if (Config::inst()->get('MathSpamProtectorField', 'enabled')) {
|
if (Config::inst()->get('MathSpamProtectorField', 'enabled')) {
|
||||||
return parent::FieldHolder($properties);
|
return parent::FieldHolder($properties);
|
||||||
}
|
}
|
||||||
@ -50,7 +52,8 @@ class MathSpamProtectorField extends TextField {
|
|||||||
*
|
*
|
||||||
* @return string
|
* @return string
|
||||||
*/
|
*/
|
||||||
public function Title() {
|
public function Title()
|
||||||
|
{
|
||||||
$prefix = Config::inst()->get('MathSpamProtection', 'question_prefix');
|
$prefix = Config::inst()->get('MathSpamProtection', 'question_prefix');
|
||||||
|
|
||||||
if (!$prefix) {
|
if (!$prefix) {
|
||||||
@ -70,7 +73,8 @@ class MathSpamProtectorField extends TextField {
|
|||||||
*
|
*
|
||||||
* @return bool
|
* @return bool
|
||||||
*/
|
*/
|
||||||
public function validate($validator) {
|
public function validate($validator)
|
||||||
|
{
|
||||||
if (!Config::inst()->get('MathSpamProtectorField', 'enabled')) {
|
if (!Config::inst()->get('MathSpamProtectorField', 'enabled')) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
@ -97,7 +101,8 @@ class MathSpamProtectorField extends TextField {
|
|||||||
*
|
*
|
||||||
* @return string
|
* @return string
|
||||||
*/
|
*/
|
||||||
public static function get_math_question() {
|
public static function get_math_question()
|
||||||
|
{
|
||||||
if (!Session::get("mathQuestionV1") && !Session::get("mathQuestionV2")) {
|
if (!Session::get("mathQuestionV1") && !Session::get("mathQuestionV2")) {
|
||||||
$v1 = rand(1, 9);
|
$v1 = rand(1, 9);
|
||||||
$v2 = rand(1, 9);
|
$v2 = rand(1, 9);
|
||||||
@ -124,7 +129,8 @@ class MathSpamProtectorField extends TextField {
|
|||||||
*
|
*
|
||||||
* @return bool
|
* @return bool
|
||||||
*/
|
*/
|
||||||
public static function correct_answer($answer){
|
public static function correct_answer($answer)
|
||||||
|
{
|
||||||
$v1 = Session::get("mathQuestionV1");
|
$v1 = Session::get("mathQuestionV1");
|
||||||
$v2 = Session::get("mathQuestionV2");
|
$v2 = Session::get("mathQuestionV2");
|
||||||
|
|
||||||
@ -141,7 +147,8 @@ class MathSpamProtectorField extends TextField {
|
|||||||
*
|
*
|
||||||
* @return string
|
* @return string
|
||||||
*/
|
*/
|
||||||
public static function digit_to_word($num){
|
public static function digit_to_word($num)
|
||||||
|
{
|
||||||
$numbers = array(_t('MathSpamProtection.ZERO', 'zero'),
|
$numbers = array(_t('MathSpamProtection.ZERO', 'zero'),
|
||||||
_t('MathSpamProtection.ONE', 'one'),
|
_t('MathSpamProtection.ONE', 'one'),
|
||||||
_t('MathSpamProtection.TWO', 'two'),
|
_t('MathSpamProtection.TWO', 'two'),
|
||||||
@ -162,12 +169,15 @@ class MathSpamProtectorField extends TextField {
|
|||||||
_t('MathSpamProtection.SEVENTEEN', 'seventeen'),
|
_t('MathSpamProtection.SEVENTEEN', 'seventeen'),
|
||||||
_t('MathSpamProtection.EIGHTEEN', 'eighteen'));
|
_t('MathSpamProtection.EIGHTEEN', 'eighteen'));
|
||||||
|
|
||||||
if($num < 0) return "minus ".($numbers[-1*$num]);
|
if ($num < 0) {
|
||||||
|
return "minus ".($numbers[-1*$num]);
|
||||||
|
}
|
||||||
|
|
||||||
return $numbers[$num];
|
return $numbers[$num];
|
||||||
}
|
}
|
||||||
|
|
||||||
public function Type() {
|
public function Type()
|
||||||
|
{
|
||||||
return 'mathspamprotector text';
|
return 'mathspamprotector text';
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user