| 1 |
<?php |
| 2 |
/** |
| 3 |
* Spam check abstract class |
| 4 |
* |
| 5 |
* @since 6.21 |
| 6 |
* |
| 7 |
* @package Formidable |
| 8 |
*/ |
| 9 |
|
| 10 |
if ( ! defined( 'ABSPATH' ) ) { |
| 11 |
die( 'You are not allowed to call this page directly.' ); |
| 12 |
} |
| 13 |
|
| 14 |
abstract class FrmSpamCheck { |
| 15 |
|
| 16 |
/** |
| 17 |
* Entry values. |
| 18 |
* |
| 19 |
* @var array |
| 20 |
*/ |
| 21 |
protected $values; |
| 22 |
|
| 23 |
/** |
| 24 |
* @param array $values |
| 25 |
*/ |
| 26 |
public function __construct( $values ) { |
| 27 |
$this->values = $values; |
| 28 |
} |
| 29 |
|
| 30 |
/** |
| 31 |
* Checks if is spam. |
| 32 |
* |
| 33 |
* @return bool|string Return the spam message or `false` if is not spam. |
| 34 |
*/ |
| 35 |
public function is_spam() { |
| 36 |
if ( ! $this->is_enabled() ) { |
| 37 |
return false; |
| 38 |
} |
| 39 |
|
| 40 |
$is_spam = $this->check(); |
| 41 |
|
| 42 |
return $is_spam ? $this->get_spam_message() : false; |
| 43 |
} |
| 44 |
|
| 45 |
/** |
| 46 |
* Checks for spam. |
| 47 |
* |
| 48 |
* @return bool Return `true` if this is spam. |
| 49 |
*/ |
| 50 |
abstract protected function check(); |
| 51 |
|
| 52 |
/** |
| 53 |
* Checks if the check is enabled. |
| 54 |
* |
| 55 |
* @return bool |
| 56 |
*/ |
| 57 |
protected function is_enabled() { |
| 58 |
return true; |
| 59 |
} |
| 60 |
|
| 61 |
/** |
| 62 |
* Gets spam message. |
| 63 |
* |
| 64 |
* @return string If this is empty string, a default message will be used. |
| 65 |
*/ |
| 66 |
protected function get_spam_message() { |
| 67 |
return FrmAntiSpamController::get_default_spam_message(); |
| 68 |
} |
| 69 |
} |
| 70 |
|