| @@ -2,13 +2,10 @@ | ||
| 2 | 2 | |
| 3 | 3 | namespace Jet_Form_Builder; |
| 4 | 4 | |
| 5 | 5 | use Jet_Form_Builder\Actions\Action_Handler; |
| 6 | -use Jet_Form_Builder\Actions\Events\Default_Process\Default_Process_Event; | |
| 7 | 6 | use Jet_Form_Builder\Actions\Events\Default_Required\Default_Required_Event; |
| 8 | -use Jet_Form_Builder\Admin\Tabs_Handlers\Tab_Handler_Manager; | |
| 9 | -use Jet_Form_Builder\Admin\Tabs_Handlers\Options_Handler; | |
| 10 | -use Jet_Form_Builder\Blocks\Block_Helper; | |
| 7 | +use Jet_Form_Builder\Classes\Macros_Parser; | |
| 11 | 8 | use Jet_Form_Builder\Classes\Tools; |
| 12 | 9 | use Jet_Form_Builder\Exceptions\Action_Exception; |
| 13 | 10 | use Jet_Form_Builder\Exceptions\Handler_Exception; |
| 14 | 11 | use Jet_Form_Builder\Exceptions\Not_Router_Request; |
| @@ -13,13 +10,13 @@ | ||
| 13 | 10 | use Jet_Form_Builder\Exceptions\Handler_Exception; |
| 14 | 11 | use Jet_Form_Builder\Exceptions\Not_Router_Request; |
| 15 | 12 | use Jet_Form_Builder\Exceptions\Repository_Exception; |
| 16 | 13 | use Jet_Form_Builder\Exceptions\Request_Exception; |
| 14 | +use Jet_Form_Builder\Form_Response; | |
| 15 | +use JFB_Modules\Security\Exceptions\Spam_Exception; | |
| 17 | 16 | use Jet_Form_Builder\Request\Form_Request_Router; |
| 18 | 17 | use Jet_Form_Builder\Request\Request_Handler; |
| 19 | -use JFB_Modules\Rich_Content\Macros_Parser; | |
| 20 | -use JFB_Modules\Rich_Content\Module; | |
| 21 | -use JFB_Modules\Security\Exceptions\Spam_Exception; | |
| 18 | +use Jet_Form_Builder\Actions\Events\Default_Process\Default_Process_Event; | |
| 22 | 19 | |
| 23 | 20 | // If this file is called directly, abort. |
| 24 | 21 | if ( ! defined( 'WPINC' ) ) { |
| 25 | 22 | die; |
| @@ -25,22 +22,19 @@ | ||
| 25 | 22 | die; |
| 26 | 23 | } |
| 27 | 24 | |
| 28 | 25 | /** |
| 29 | - * @property Macros_Parser parser | |
| 30 | - * | |
| 31 | 26 | * Define Jet_Engine_Booking_Forms_Handler class |
| 32 | 27 | */ |
| 33 | 28 | class Form_Handler { |
| 34 | 29 | |
| 35 | - public $hook_key = 'jet_form_builder_submit'; | |
| 36 | - public $hook_val = 'submit'; | |
| 37 | - public $form_data = array(); | |
| 38 | - public $response_data = array(); | |
| 39 | - public $is_ajax = false; | |
| 40 | - public $is_success = false; | |
| 41 | - public $response_args = array(); | |
| 42 | - public $user_journey_data = array(); | |
| 30 | + public $hook_key = 'jet_form_builder_submit'; | |
| 31 | + public $hook_val = 'submit'; | |
| 32 | + public $form_data = array(); | |
| 33 | + public $response_data = array(); | |
| 34 | + public $is_ajax = false; | |
| 35 | + public $is_success = false; | |
| 36 | + public $response_args = array(); | |
| 43 | 37 | |
| 44 | 38 | public $form_id; |
| 45 | 39 | public $refer; |
| 46 | 40 | public $manager; |
| @@ -47,25 +41,27 @@ | ||
| 47 | 41 | |
| 48 | 42 | /** @var Action_Handler */ |
| 49 | 43 | public $action_handler; |
| 50 | 44 | |
| 51 | - public $form_key = '_jet_engine_booking_form_id'; | |
| 52 | - public $refer_key = '_jet_engine_refer'; | |
| 53 | - public $post_id_key = '__queried_post_id'; | |
| 54 | - public $user_journey_key = '_user_journey'; | |
| 45 | + public $form_key = '_jet_engine_booking_form_id'; | |
| 46 | + public $refer_key = '_jet_engine_refer'; | |
| 47 | + public $post_id_key = '__queried_post_id'; | |
| 55 | 48 | /** |
| 56 | 49 | * @var Request_Handler |
| 57 | 50 | */ |
| 58 | 51 | public $request_handler; |
| 59 | 52 | |
| 53 | + /** @var Macros_Parser */ | |
| 54 | + public $parser; | |
| 60 | 55 | |
| 56 | + | |
| 61 | 57 | /** |
| 62 | 58 | * Constructor for the class |
| 63 | 59 | */ |
| 64 | 60 | public function __construct() { |
| 65 | - $this->set_jfb_request_args(); | |
| 66 | 61 | $this->action_handler = new Action_Handler(); |
| 67 | 62 | $this->request_handler = new Request_Handler(); |
| 63 | + $this->parser = new Macros_Parser(); | |
| 68 | 64 | } |
| 69 | 65 | |
| 70 | 66 | public function call_form() { |
| 71 | 67 | try { |
| @@ -102,11 +98,8 @@ | ||
| 102 | 98 | ), |
| 103 | 99 | $this->post_id_key => array( |
| 104 | 100 | 'callback' => array( Tools::class, 'set_current_post' ), |
| 105 | 101 | ), |
| 106 | - $this->user_journey_key => array( | |
| 107 | - 'callback' => array( $this, 'set_user_journey_data' ), | |
| 108 | - ), | |
| 109 | 102 | ) |
| 110 | 103 | ); |
| 111 | 104 | } |
| 112 | 105 | |
| @@ -123,17 +116,9 @@ | ||
| 123 | 116 | jet_fb_context()->make_secure( $name ); |
| 124 | 117 | } |
| 125 | 118 | } |
| 126 | 119 | |
| 127 | - public function set_user_journey_data( $data ) { | |
| 128 | - $this->user_journey_data = $data; | |
| 129 | - } | |
| 130 | 120 | |
| 131 | - public function get_user_journey_data() { | |
| 132 | - return $this->user_journey_data; | |
| 133 | - } | |
| 134 | - | |
| 135 | - | |
| 136 | 121 | public function set_referrer( $url ): Form_Handler { |
| 137 | 122 | $refer = remove_query_arg( |
| 138 | 123 | array( 'values', 'status', 'fields' ), |
| 139 | 124 | esc_url_raw( $url ) |
| @@ -148,12 +133,10 @@ | ||
| 148 | 133 | return $this->refer; |
| 149 | 134 | } |
| 150 | 135 | |
| 151 | 136 | public function set_form_id( $form_id ) { |
| 152 | - $form_id = absint( $form_id ); | |
| 137 | + $this->form_id = absint( $form_id ); | |
| 153 | 138 | |
| 154 | - $this->form_id = Block_Helper::is_valid_form_post( $form_id, true ) ? $form_id : 0; | |
| 155 | - | |
| 156 | 139 | return $this; |
| 157 | 140 | } |
| 158 | 141 | |
| 159 | 142 | public function get_form_id() { |
| @@ -254,10 +237,8 @@ | ||
| 254 | 237 | 'status' => 'failed', |
| 255 | 238 | ) |
| 256 | 239 | ); |
| 257 | 240 | $this->send_raw_response(); |
| 258 | - | |
| 259 | - return; | |
| 260 | 241 | } |
| 261 | 242 | |
| 262 | 243 | $this->try_send(); |
| 263 | 244 | |
| @@ -306,15 +287,11 @@ | ||
| 306 | 287 | } |
| 307 | 288 | } |
| 308 | 289 | |
| 309 | 290 | /** |
| 310 | - * @throws Request_Exception | |
| 291 | + * @throws Request_Exception|Action_Exception|Spam_Exception | |
| 311 | 292 | */ |
| 312 | 293 | public function send_form() { |
| 313 | - if ( ! $this->form_id ) { | |
| 314 | - throw new Request_Exception( 'failed' ); | |
| 315 | - } | |
| 316 | - | |
| 317 | 294 | $this->action_handler->set_form_id( $this->form_id ); |
| 318 | 295 | $this->request_handler->set_form_data(); |
| 319 | 296 | |
| 320 | 297 | do_action( 'jet-form-builder/form-handler/before-send', $this ); |
| @@ -384,39 +361,7 @@ | ||
| 384 | 361 | ( new Form_Response\Response( |
| 385 | 362 | $this->get_response_manager(), |
| 386 | 363 | $this->response_data |
| 387 | 364 | ) )->init( $this->response_args )->send(); |
| 388 | - } | |
| 389 | - | |
| 390 | - /** | |
| 391 | - * Backward compatibility to deprecated properties | |
| 392 | - * | |
| 393 | - * @param $name | |
| 394 | - * | |
| 395 | - * @return mixed | |
| 396 | - * @throws Repository_Exception | |
| 397 | - */ | |
| 398 | - public function __get( $name ) { | |
| 399 | - switch ( $name ) { | |
| 400 | - case 'parser': | |
| 401 | - /** @var Module $rich */ | |
| 402 | - $rich = jet_form_builder()->module( 'rich-content' ); | |
| 403 | - | |
| 404 | - return $rich->get_parser(); | |
| 405 | - default: | |
| 406 | - return null; | |
| 407 | - } | |
| 408 | - } | |
| 409 | - | |
| 410 | - public function set_jfb_request_args() { | |
| 411 | - $options_handler = new Options_Handler(); | |
| 412 | - $options_handler->set_jfb_request_args(); | |
| 413 | - $options = Tab_Handler_Manager::get_options( 'options-tab' ); | |
| 414 | - if ( isset( $options['gfb_request_args_key'] ) ) { | |
| 415 | - $this->hook_key = $options['gfb_request_args_key']; | |
| 416 | - } | |
| 417 | - if ( isset( $options['gfb_request_args_value'] ) ) { | |
| 418 | - $this->hook_val = $options['gfb_request_args_value']; | |
| 419 | - } | |
| 420 | 365 | } |
| 421 | 366 | |
| 422 | 367 | } |