| 1 |
<?php |
| 2 |
if ( ! defined( 'ABSPATH' ) ) { |
| 3 |
die( 'You are not allowed to call this page directly.' ); |
| 4 |
} |
| 5 |
|
| 6 |
abstract class FrmValidate { |
| 7 |
|
| 8 |
/** |
| 9 |
* @var int |
| 10 |
*/ |
| 11 |
protected $form_id; |
| 12 |
|
| 13 |
/** |
| 14 |
* @var object|null |
| 15 |
*/ |
| 16 |
protected $form; |
| 17 |
|
| 18 |
/** |
| 19 |
* @since 6.21 |
| 20 |
* |
| 21 |
* @var string |
| 22 |
*/ |
| 23 |
protected $option_type = 'form'; |
| 24 |
|
| 25 |
/** |
| 26 |
* @param int $form_id |
| 27 |
*/ |
| 28 |
public function __construct( $form_id ) { |
| 29 |
$this->form_id = $form_id; |
| 30 |
} |
| 31 |
|
| 32 |
/** |
| 33 |
* @return object|null Form. |
| 34 |
*/ |
| 35 |
protected function get_form() { |
| 36 |
if ( ! $this->form ) { |
| 37 |
$this->form = FrmForm::getOne( $this->form_id ); |
| 38 |
} |
| 39 |
return $this->form; |
| 40 |
} |
| 41 |
|
| 42 |
/** |
| 43 |
* @return bool |
| 44 |
*/ |
| 45 |
protected function is_option_on() { |
| 46 |
$key = $this->get_option_key(); |
| 47 |
|
| 48 |
if ( 'global' === $this->option_type ) { |
| 49 |
$frm_settings = FrmAppHelper::get_settings(); |
| 50 |
return ! empty( $frm_settings->$key ); |
| 51 |
} |
| 52 |
|
| 53 |
$form = $this->get_form(); |
| 54 |
return ! empty( $form->options[ $key ] ) && 'off' !== $form->options[ $key ]; |
| 55 |
} |
| 56 |
|
| 57 |
/** |
| 58 |
* @return bool|string |
| 59 |
*/ |
| 60 |
abstract public function validate(); |
| 61 |
|
| 62 |
/** |
| 63 |
* Track the form option key used for is_option_on function. |
| 64 |
* |
| 65 |
* @return string |
| 66 |
*/ |
| 67 |
abstract protected function get_option_key(); |
| 68 |
} |
| 69 |
|