PluginProbe
JetFormBuilder — Dynamic Blocks Form Builder / 3.6.6
JetFormBuilder — Dynamic Blocks Form Builder v3.6.6
3.6.6.1 3.6.6 3.6.5.4 3.6.5.3 3.6.5.2 3.6.5.1 3.6.5 3.6.4.2 3.6.4.1 3.6.4 3.6.3.1 3.6.3 3.6.2.2 3.6.2.1 3.6.2 3.6.1.1 3.6.1 3.6.0.1 trunk 1.0.0 1.0.1 1.0.2 1.0.3 1.1.0 1.1.1 All 134 releases
jetformbuilder / modules / captcha / abstract-captcha / base-captcha.php

base-captcha.php in JetFormBuilder — Dynamic Blocks Form Builder 3.6.6, at modules/captcha/abstract-captcha/base-captcha.php

109 lines 2.5 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3
4 namespace JFB_Modules\Captcha\Abstract_Captcha;
5
6 use Jet_Form_Builder\Admin\Tabs_Handlers\Tab_Handler_Manager;
7 use Jet_Form_Builder\Blocks\Exceptions\Render_Empty_Field;
8 use Jet_Form_Builder\Classes\Arrayable\Arrayable;
9 use JFB_Components\Repository\Repository_Item_Instance_Trait;
10 use Jet_Form_Builder\Exceptions\Repository_Exception;
11 use Jet_Form_Builder\Exceptions\Request_Exception;
12 use JFB_Components\Module\Base_Module_After_Install_It;
13 use JFB_Components\Module\Base_Module_Dir_It;
14 use JFB_Components\Module\Base_Module_Handle_It;
15 use JFB_Components\Module\Base_Module_It;
16 use JFB_Components\Module\Base_Module_Url_It;
17 use JFB_Modules\Captcha\Module;
18 use JFB_Modules\Security\Exceptions\Spam_Exception;
19
20 // If this file is called directly, abort.
21 if ( ! defined( 'WPINC' ) ) {
22 die;
23 }
24
25 abstract class Base_Captcha implements
26 Repository_Item_Instance_Trait,
27 Arrayable {
28
29 protected $options;
30 protected $locked_render = false;
31 /**
32 * @var bool
33 */
34 protected $exist_container;
35
36 const FIELD_CLASS = 'captcha-token';
37 const FIELD = '_captcha_token';
38 const HANDLE_API = 'jet-form-builder-recaptcha';
39 const HANDLE_USER = self::HANDLE_API . '-handler';
40
41 abstract public function get_id(): string;
42
43 abstract public function get_title(): string;
44
45 /**
46 * @param array $request
47 *
48 * @throws Spam_Exception
49 */
50 abstract public function verify( array $request );
51
52 abstract protected function render(): string;
53
54 public function get_output(): string {
55 return $this->render();
56 }
57
58 public function sanitize_options( array $options ): Base_Captcha {
59 $this->options = $options[ $this->get_id() ] ?? array();
60
61 return $this;
62 }
63
64 public function rep_item_id() {
65 return $this->get_id();
66 }
67
68 public function to_array(): array {
69 return array(
70 'label' => $this->get_title(),
71 'value' => $this->get_id(),
72 );
73 }
74
75 public function lock_render() {
76 $this->locked_render = true;
77 }
78
79 public function is_locked_render(): bool {
80 return $this->locked_render;
81 }
82
83 public function get_handle( string $unique = '' ): string {
84 return $this->module()->get_handle( $this->get_id() . $unique );
85 }
86
87 /**
88 * @return Module|mixed
89 */
90 public function module() {
91 try {
92 return jet_form_builder()->module( 'captcha' );
93 } catch ( Repository_Exception $exception ) {
94 return false;
95 }
96 }
97
98 public function set_exist_container( bool $exist_container ) {
99 $this->exist_container = $exist_container;
100 }
101
102 /**
103 * @return bool|null
104 */
105 public function is_exist_container() {
106 return $this->exist_container;
107 }
108 }
109