| @@ -1,241 +1,422 @@ | ||
| 1 | -<?php | |
| 2 | - | |
| 3 | -namespace Jet_Form_Builder; | |
| 4 | - | |
| 5 | - | |
| 6 | -use Jet_Form_Builder\Actions\Action_Handler; | |
| 7 | -use Jet_Form_Builder\Classes\Tools; | |
| 8 | -use Jet_Form_Builder\Exceptions\Handler_Exception; | |
| 9 | -use Jet_Form_Builder\Exceptions\Request_Exception; | |
| 10 | -use Jet_Form_Builder\Form_Messages; | |
| 11 | -use Jet_Form_Builder\Form_Response; | |
| 12 | -use Jet_Form_Builder\Request\Request_Handler; | |
| 13 | - | |
| 14 | -/** | |
| 15 | - * Form builder class | |
| 16 | - */ | |
| 17 | - | |
| 18 | -// If this file is called directly, abort. | |
| 19 | -if ( ! defined( 'WPINC' ) ) { | |
| 20 | - die; | |
| 21 | -} | |
| 22 | - | |
| 23 | -/** | |
| 24 | - * Define Jet_Engine_Booking_Forms_Handler class | |
| 25 | - */ | |
| 26 | -class Form_Handler { | |
| 27 | - | |
| 28 | - public $hook_key = 'jet_form_builder_submit'; | |
| 29 | - public $hook_val = 'submit'; | |
| 30 | - public $form_data = array(); | |
| 31 | - public $response_data = array(); | |
| 32 | - public $is_ajax = false; | |
| 33 | - public $is_success = false; | |
| 34 | - public $response_status = 'failed'; | |
| 35 | - | |
| 36 | - public $form_id; | |
| 37 | - public $refer; | |
| 38 | - public $manager; | |
| 39 | - public $action_handler; | |
| 40 | - public $request_data; | |
| 41 | - | |
| 42 | - public $form_key = '_jet_engine_booking_form_id'; | |
| 43 | - public $refer_key = '_jet_engine_refer'; | |
| 44 | - public $post_id_key = '__queried_post_id'; | |
| 45 | - | |
| 46 | - | |
| 47 | - /** | |
| 48 | - * Constructor for the class | |
| 49 | - */ | |
| 50 | - function __construct() { | |
| 51 | - | |
| 52 | - if ( wp_doing_ajax() ) { | |
| 53 | - | |
| 54 | - add_action( | |
| 55 | - 'wp_ajax_' . $this->hook_key, | |
| 56 | - array( $this, 'process_ajax_form' ) | |
| 57 | - ); | |
| 58 | - add_action( | |
| 59 | - 'wp_ajax_nopriv_' . $this->hook_key, | |
| 60 | - array( $this, 'process_ajax_form' ) | |
| 61 | - ); | |
| 62 | - | |
| 63 | - } else { | |
| 64 | - | |
| 65 | - if ( ! isset( $_REQUEST[ $this->hook_key ] ) || $this->hook_val !== $_REQUEST[ $this->hook_key ] ) { | |
| 66 | - return; | |
| 67 | - } | |
| 68 | - | |
| 69 | - add_action( 'wp_loaded', array( $this, 'process_form' ), 0 ); | |
| 70 | - } | |
| 71 | - } | |
| 72 | - | |
| 73 | - /** | |
| 74 | - * Is ajax form processing or not | |
| 75 | - * | |
| 76 | - * @return boolean [description] | |
| 77 | - */ | |
| 78 | - public function is_ajax() { | |
| 79 | - return $this->is_ajax; | |
| 80 | - } | |
| 81 | - | |
| 82 | - /** | |
| 83 | - * Setup form data | |
| 84 | - * | |
| 85 | - * @return [type] [description] | |
| 86 | - */ | |
| 87 | - public function setup_form() { | |
| 88 | - global $post; | |
| 89 | - | |
| 90 | - if ( ! $this->is_ajax ) { | |
| 91 | - $post = ! empty( $_REQUEST[ $this->post_id_key ] ) ? get_post( $_REQUEST[ $this->post_id_key ] ) : null; | |
| 92 | - $this->form_id = ! empty( $_REQUEST[ $this->form_key ] ) ? absint( $_REQUEST[ $this->form_key ] ) : false; | |
| 93 | - $this->refer = ! empty( $_REQUEST[ $this->refer_key ] ) ? esc_url( $_REQUEST[ $this->refer_key ] ) : false; | |
| 94 | - } else { | |
| 95 | - $values = ! empty( $_REQUEST['values'] ) ? Tools::maybe_recursive_sanitize( $_REQUEST['values'] ) : array(); | |
| 96 | - | |
| 97 | - foreach ( $values as $data ) { | |
| 98 | - switch ( $data['name'] ) { | |
| 99 | - case $this->form_key: | |
| 100 | - $this->form_id = $data['value']; | |
| 101 | - break; | |
| 102 | - case $this->post_id_key: | |
| 103 | - $post = get_post( $data['value'] ); | |
| 104 | - break; | |
| 105 | - case $this->refer_key: | |
| 106 | - $this->refer = esc_attr( $data['value'] ); | |
| 107 | - // Clear form-related arguments | |
| 108 | - $this->refer = remove_query_arg( array( 'values', 'status', 'fields' ), $this->refer ); | |
| 109 | - break; | |
| 110 | - } | |
| 111 | - } | |
| 112 | - | |
| 113 | - } | |
| 114 | - } | |
| 115 | - | |
| 116 | - private function get_response_manager() { | |
| 117 | - if ( $this->is_ajax ) { | |
| 118 | - return new Form_Response\Types\Ajax_Response( array( | |
| 119 | - 'form_id' => $this->form_id, | |
| 120 | - 'actions' => $this->action_handler->get_all(), | |
| 121 | - ) ); | |
| 122 | - } else { | |
| 123 | - return new Form_Response\Types\Reload_Response( array( | |
| 124 | - 'refer' => $this->refer, | |
| 125 | - ) ); | |
| 126 | - } | |
| 127 | - } | |
| 128 | - | |
| 129 | - /** | |
| 130 | - * Process form with Ajax | |
| 131 | - * | |
| 132 | - * @return [type] [description] | |
| 133 | - */ | |
| 134 | - public function process_ajax_form() { | |
| 135 | - $this->is_ajax = true; | |
| 136 | - $this->process_form(); | |
| 137 | - } | |
| 138 | - | |
| 139 | - /** | |
| 140 | - * Process current form | |
| 141 | - * | |
| 142 | - * @return [type] [description] | |
| 143 | - */ | |
| 144 | - public function process_form() { | |
| 145 | - | |
| 146 | - $this->setup_form(); | |
| 147 | - | |
| 148 | - $this->try_set_data(); | |
| 149 | - | |
| 150 | - do_action( 'jet-form-builder/form-handler/before-send', $this ); | |
| 151 | - | |
| 152 | - $this->try_to_do_actions(); | |
| 153 | - | |
| 154 | - do_action( 'jet-form-builder/form-handler/after-send', $this, $this->is_success ); | |
| 155 | - | |
| 156 | - if ( true === $this->is_success ) { | |
| 157 | - $this->send_response( array( | |
| 158 | - 'status' => 'success', | |
| 159 | - ) ); | |
| 160 | - } else { | |
| 161 | - $this->send_response( array( | |
| 162 | - 'status' => 'failed', | |
| 163 | - ) ); | |
| 164 | - } | |
| 165 | - } | |
| 166 | - | |
| 167 | - public function try_set_data() { | |
| 168 | - try { | |
| 169 | - $request = array( | |
| 170 | - 'form_id' => $this->form_id, | |
| 171 | - 'is_ajax' => $this->is_ajax, | |
| 172 | - 'refer' => $this->refer | |
| 173 | - ); | |
| 174 | - $this->action_handler = new Action_Handler( $this->form_id ); | |
| 175 | - $this->request_data = ( new Request_Handler( $request ) )->get_form_data(); | |
| 176 | - | |
| 177 | - } catch ( Request_Exception $exception ) { | |
| 178 | - $this->send_response( array( | |
| 179 | - 'status' => $exception->get_form_status(), | |
| 180 | - 'errors' => $exception->get_fields_errors() | |
| 181 | - ) ); | |
| 182 | - } | |
| 183 | - } | |
| 184 | - | |
| 185 | - | |
| 186 | - public function try_to_do_actions() { | |
| 187 | - try { | |
| 188 | - $this->action_handler->add_request( $this->request_data ); | |
| 189 | - | |
| 190 | - $this->add_response_data( $this->action_handler->do_actions() ); | |
| 191 | - $this->is_success = true; | |
| 192 | - | |
| 193 | - } catch ( Handler_Exception $exception ) { | |
| 194 | - $this->send_response( array( | |
| 195 | - 'status' => $exception->get_form_status(), | |
| 196 | - ) ); | |
| 197 | - } | |
| 198 | - } | |
| 199 | - | |
| 200 | - public function get_message_builder_data( $form_id ) { | |
| 201 | - $form_id = $this->form_id ? $this->form_id : $form_id; | |
| 202 | - | |
| 203 | - if ( $this->action_handler && ! empty( $this->action_handler->form_actions ) ) { | |
| 204 | - $actions = $this->action_handler->form_actions; | |
| 205 | - } else { | |
| 206 | - $actions = ( new Action_Handler( $form_id ) )->get_all(); | |
| 207 | - } | |
| 208 | - | |
| 209 | - return ( object ) array( | |
| 210 | - 'form_id' => $form_id, | |
| 211 | - 'actions' => $actions | |
| 212 | - ); | |
| 213 | - } | |
| 214 | - | |
| 215 | - public function get_message_builder( $form_id ) { | |
| 216 | - return new Form_Messages\Builder( $this->get_message_builder_data( $form_id ) ); | |
| 217 | - } | |
| 218 | - | |
| 219 | - /** | |
| 220 | - * Add new properties into response data | |
| 221 | - * | |
| 222 | - * @param array $data [description] | |
| 223 | - */ | |
| 224 | - public function add_response_data( $data = array() ) { | |
| 225 | - $this->response_data = array_merge( $this->response_data, $data ); | |
| 226 | - } | |
| 227 | - | |
| 228 | - /** | |
| 229 | - * Redirect back to refer | |
| 230 | - * | |
| 231 | - * @param array $args [description] | |
| 232 | - * | |
| 233 | - * @return void [description] | |
| 234 | - */ | |
| 235 | - public function send_response( $args = array() ) { | |
| 236 | - ( new Form_Response\Response( $this->get_response_manager(), $this->response_data ) )->init( $args )->send(); | |
| 237 | - } | |
| 238 | - | |
| 239 | -} | |
| 240 | - | |
| 241 | - | |
| 1 | +<?php | |
| 2 | + | |
| 3 | +namespace Jet_Form_Builder; | |
| 4 | + | |
| 5 | +use Jet_Form_Builder\Actions\Action_Handler; | |
| 6 | +use Jet_Form_Builder\Actions\Events\Default_Process\Default_Process_Event; | |
| 7 | +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; | |
| 11 | +use Jet_Form_Builder\Classes\Tools; | |
| 12 | +use Jet_Form_Builder\Exceptions\Action_Exception; | |
| 13 | +use Jet_Form_Builder\Exceptions\Handler_Exception; | |
| 14 | +use Jet_Form_Builder\Exceptions\Not_Router_Request; | |
| 15 | +use Jet_Form_Builder\Exceptions\Repository_Exception; | |
| 16 | +use Jet_Form_Builder\Exceptions\Request_Exception; | |
| 17 | +use Jet_Form_Builder\Request\Form_Request_Router; | |
| 18 | +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; | |
| 22 | + | |
| 23 | +// If this file is called directly, abort. | |
| 24 | +if ( ! defined( 'WPINC' ) ) { | |
| 25 | + die; | |
| 26 | +} | |
| 27 | + | |
| 28 | +/** | |
| 29 | + * @property Macros_Parser parser | |
| 30 | + * | |
| 31 | + * Define Jet_Engine_Booking_Forms_Handler class | |
| 32 | + */ | |
| 33 | +class Form_Handler { | |
| 34 | + | |
| 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(); | |
| 43 | + | |
| 44 | + public $form_id; | |
| 45 | + public $refer; | |
| 46 | + public $manager; | |
| 47 | + | |
| 48 | + /** @var Action_Handler */ | |
| 49 | + public $action_handler; | |
| 50 | + | |
| 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'; | |
| 55 | + /** | |
| 56 | + * @var Request_Handler | |
| 57 | + */ | |
| 58 | + public $request_handler; | |
| 59 | + | |
| 60 | + | |
| 61 | + /** | |
| 62 | + * Constructor for the class | |
| 63 | + */ | |
| 64 | + public function __construct() { | |
| 65 | + $this->set_jfb_request_args(); | |
| 66 | + $this->action_handler = new Action_Handler(); | |
| 67 | + $this->request_handler = new Request_Handler(); | |
| 68 | + } | |
| 69 | + | |
| 70 | + public function call_form() { | |
| 71 | + try { | |
| 72 | + Form_Request_Router::listen(); | |
| 73 | + } catch ( Not_Router_Request $exception ) { | |
| 74 | + return; | |
| 75 | + } | |
| 76 | + | |
| 77 | + add_action( 'jet-form-builder/request', array( $this, 'merge_request' ), 1 ); | |
| 78 | + | |
| 79 | + if ( wp_doing_ajax() ) { | |
| 80 | + add_action( | |
| 81 | + 'wp_ajax_' . $this->hook_key, | |
| 82 | + array( $this, 'process_ajax_form' ) | |
| 83 | + ); | |
| 84 | + add_action( | |
| 85 | + 'wp_ajax_nopriv_' . $this->hook_key, | |
| 86 | + array( $this, 'process_ajax_form' ) | |
| 87 | + ); | |
| 88 | + } else { | |
| 89 | + add_action( 'wp_loaded', array( $this, 'process_form' ), 0 ); | |
| 90 | + } | |
| 91 | + } | |
| 92 | + | |
| 93 | + public function core_fields() { | |
| 94 | + return apply_filters( | |
| 95 | + 'jet-form-builder/form-handler/core-fields', | |
| 96 | + array( | |
| 97 | + $this->form_key => array( | |
| 98 | + 'callback' => array( $this, 'set_form_id' ), | |
| 99 | + ), | |
| 100 | + $this->refer_key => array( | |
| 101 | + 'callback' => array( $this, 'set_referrer' ), | |
| 102 | + ), | |
| 103 | + $this->post_id_key => array( | |
| 104 | + 'callback' => array( Tools::class, 'set_current_post' ), | |
| 105 | + ), | |
| 106 | + $this->user_journey_key => array( | |
| 107 | + 'callback' => array( $this, 'set_user_journey_data' ), | |
| 108 | + ), | |
| 109 | + ) | |
| 110 | + ); | |
| 111 | + } | |
| 112 | + | |
| 113 | + public function merge_request() { | |
| 114 | + $fields = array( | |
| 115 | + '__form_id' => $this->get_form_id(), | |
| 116 | + '__refer' => $this->get_referrer(), | |
| 117 | + '__is_ajax' => $this->is_ajax(), | |
| 118 | + ); | |
| 119 | + | |
| 120 | + foreach ( $fields as $name => $value ) { | |
| 121 | + jet_fb_context()->set_field_type( 'text-field', $name ); | |
| 122 | + jet_fb_context()->update_request( $value, $name ); | |
| 123 | + jet_fb_context()->make_secure( $name ); | |
| 124 | + } | |
| 125 | + } | |
| 126 | + | |
| 127 | + public function set_user_journey_data( $data ) { | |
| 128 | + $this->user_journey_data = $data; | |
| 129 | + } | |
| 130 | + | |
| 131 | + public function get_user_journey_data() { | |
| 132 | + return $this->user_journey_data; | |
| 133 | + } | |
| 134 | + | |
| 135 | + | |
| 136 | + public function set_referrer( $url ): Form_Handler { | |
| 137 | + $refer = remove_query_arg( | |
| 138 | + array( 'values', 'status', 'fields' ), | |
| 139 | + esc_url_raw( $url ) | |
| 140 | + ); | |
| 141 | + | |
| 142 | + $this->refer = wp_validate_redirect( $refer ); | |
| 143 | + | |
| 144 | + return $this; | |
| 145 | + } | |
| 146 | + | |
| 147 | + public function get_referrer() { | |
| 148 | + return $this->refer; | |
| 149 | + } | |
| 150 | + | |
| 151 | + public function set_form_id( $form_id ) { | |
| 152 | + $form_id = absint( $form_id ); | |
| 153 | + | |
| 154 | + $this->form_id = Block_Helper::is_valid_form_post( $form_id, true ) ? $form_id : 0; | |
| 155 | + | |
| 156 | + return $this; | |
| 157 | + } | |
| 158 | + | |
| 159 | + public function get_form_id() { | |
| 160 | + return $this->form_id; | |
| 161 | + } | |
| 162 | + | |
| 163 | + /** | |
| 164 | + * Is ajax form processing or not | |
| 165 | + * | |
| 166 | + * @return boolean [description] | |
| 167 | + */ | |
| 168 | + public function is_ajax(): bool { | |
| 169 | + return $this->is_ajax; | |
| 170 | + } | |
| 171 | + | |
| 172 | + /** | |
| 173 | + * Is form processing or not | |
| 174 | + * | |
| 175 | + * @return bool | |
| 176 | + */ | |
| 177 | + public function is_process(): bool { | |
| 178 | + return ! empty( $this->refer ); | |
| 179 | + } | |
| 180 | + | |
| 181 | + /** | |
| 182 | + * Setup form data | |
| 183 | + * | |
| 184 | + * @return void [description] | |
| 185 | + */ | |
| 186 | + public function setup_form() { | |
| 187 | + | |
| 188 | + if ( $this->form_id ) { | |
| 189 | + return; | |
| 190 | + } | |
| 191 | + | |
| 192 | + $fields = $this->core_fields(); | |
| 193 | + | |
| 194 | + foreach ( $fields as $field_name => $options ) { | |
| 195 | + // phpcs:disable WordPress.Security | |
| 196 | + if ( ! isset( $_POST[ $field_name ] ) ) { | |
| 197 | + continue; | |
| 198 | + } | |
| 199 | + | |
| 200 | + Tools::call( $options['callback'] ?? false, $_POST[ $field_name ] ); | |
| 201 | + // phpcs:enable WordPress.Security | |
| 202 | + } | |
| 203 | + } | |
| 204 | + | |
| 205 | + private function get_response_manager() { | |
| 206 | + if ( ! $this->form_id ) { | |
| 207 | + $this->setup_form(); | |
| 208 | + } | |
| 209 | + | |
| 210 | + if ( $this->is_ajax ) { | |
| 211 | + jet_fb_action_handler()->set_form_id( $this->form_id ); | |
| 212 | + | |
| 213 | + return new Form_Response\Types\Ajax_Response( | |
| 214 | + array( | |
| 215 | + 'form_id' => $this->form_id, | |
| 216 | + 'actions' => jet_fb_action_handler()->get_all(), | |
| 217 | + ) | |
| 218 | + ); | |
| 219 | + } else { | |
| 220 | + return new Form_Response\Types\Reload_Response( | |
| 221 | + array( | |
| 222 | + 'refer' => $this->refer, | |
| 223 | + ) | |
| 224 | + ); | |
| 225 | + } | |
| 226 | + } | |
| 227 | + | |
| 228 | + /** | |
| 229 | + * Process form with Ajax | |
| 230 | + * | |
| 231 | + * @return void | |
| 232 | + */ | |
| 233 | + public function process_ajax_form() { | |
| 234 | + $this->is_ajax = true; | |
| 235 | + $this->process_form(); | |
| 236 | + } | |
| 237 | + | |
| 238 | + /** | |
| 239 | + * Process current form | |
| 240 | + * | |
| 241 | + * @return void [description] | |
| 242 | + */ | |
| 243 | + public function process_form() { | |
| 244 | + $this->setup_form(); | |
| 245 | + | |
| 246 | + if ( ! $this->form_id || ! $this->refer ) { | |
| 247 | + $this->add_response_data( | |
| 248 | + array( | |
| 249 | + 'reload' => true, | |
| 250 | + ) | |
| 251 | + ); | |
| 252 | + $this->set_response_args( | |
| 253 | + array( | |
| 254 | + 'status' => 'failed', | |
| 255 | + ) | |
| 256 | + ); | |
| 257 | + $this->send_raw_response(); | |
| 258 | + | |
| 259 | + return; | |
| 260 | + } | |
| 261 | + | |
| 262 | + $this->try_send(); | |
| 263 | + | |
| 264 | + if ( true === $this->is_success ) { | |
| 265 | + $this->send_response( | |
| 266 | + array( | |
| 267 | + 'status' => 'success', | |
| 268 | + ) | |
| 269 | + ); | |
| 270 | + } else { | |
| 271 | + $this->send_response( | |
| 272 | + array( | |
| 273 | + 'status' => 'failed', | |
| 274 | + ) | |
| 275 | + ); | |
| 276 | + } | |
| 277 | + } | |
| 278 | + | |
| 279 | + public function try_send() { | |
| 280 | + try { | |
| 281 | + $this->send_form(); | |
| 282 | + } catch ( Request_Exception $exception ) { | |
| 283 | + $this->send_response( | |
| 284 | + array( | |
| 285 | + 'status' => $exception->get_form_status(), | |
| 286 | + 'errors' => $exception->get_fields_errors(), | |
| 287 | + ) | |
| 288 | + ); | |
| 289 | + } catch ( Action_Exception $exception ) { | |
| 290 | + /** | |
| 291 | + * @see https://github.com/Crocoblock/jetformbuilder/issues/334 | |
| 292 | + */ | |
| 293 | + $this->is_success = $exception->is_success(); | |
| 294 | + | |
| 295 | + $this->send_response( | |
| 296 | + array( | |
| 297 | + 'status' => $exception->get_form_status(), | |
| 298 | + ) | |
| 299 | + ); | |
| 300 | + } catch ( Spam_Exception $exception ) { | |
| 301 | + $this->send_response( | |
| 302 | + array( | |
| 303 | + 'status' => $exception->get_form_status(), | |
| 304 | + ) | |
| 305 | + ); | |
| 306 | + } | |
| 307 | + } | |
| 308 | + | |
| 309 | + /** | |
| 310 | + * @throws Request_Exception | |
| 311 | + */ | |
| 312 | + public function send_form() { | |
| 313 | + if ( ! $this->form_id ) { | |
| 314 | + throw new Request_Exception( 'failed' ); | |
| 315 | + } | |
| 316 | + | |
| 317 | + $this->action_handler->set_form_id( $this->form_id ); | |
| 318 | + $this->request_handler->set_form_data(); | |
| 319 | + | |
| 320 | + do_action( 'jet-form-builder/form-handler/before-send', $this ); | |
| 321 | + | |
| 322 | + // execute all actions | |
| 323 | + jet_fb_events()->execute( Default_Process_Event::class ); | |
| 324 | + | |
| 325 | + $this->add_response_data( $this->action_handler->response_data ); | |
| 326 | + | |
| 327 | + $this->is_success = true; | |
| 328 | + } | |
| 329 | + | |
| 330 | + | |
| 331 | + /** | |
| 332 | + * Add new properties into response data | |
| 333 | + * | |
| 334 | + * @param array $data [description] | |
| 335 | + */ | |
| 336 | + public function add_response_data( $data = array() ) { | |
| 337 | + $this->response_data = array_merge( $this->response_data, $data ); | |
| 338 | + } | |
| 339 | + | |
| 340 | + public function set_response_args( $args ) { | |
| 341 | + $this->response_args = array_merge( $this->response_args, $args ); | |
| 342 | + | |
| 343 | + return $this; | |
| 344 | + } | |
| 345 | + | |
| 346 | + public function get_response_args() { | |
| 347 | + return $this->response_args; | |
| 348 | + } | |
| 349 | + | |
| 350 | + /** | |
| 351 | + * Redirect back to refer | |
| 352 | + * | |
| 353 | + * @param array $args [description] | |
| 354 | + * | |
| 355 | + * @return void [description] | |
| 356 | + */ | |
| 357 | + public function send_response( $args = array() ) { | |
| 358 | + try { | |
| 359 | + $this->set_response_args( $args ); | |
| 360 | + | |
| 361 | + jet_fb_events()->execute( Default_Required_Event::class ); | |
| 362 | + | |
| 363 | + do_action( 'jet-form-builder/form-handler/after-send', $this, $this->is_success ); | |
| 364 | + } catch ( Repository_Exception $exception ) { | |
| 365 | + $this->send_raw_response(); | |
| 366 | + | |
| 367 | + return; | |
| 368 | + } catch ( Handler_Exception $exception ) { | |
| 369 | + $this->is_success = false; | |
| 370 | + $this->response_args = array( | |
| 371 | + 'status' => $exception->get_form_status(), | |
| 372 | + ); | |
| 373 | + $this->response_data = array(); | |
| 374 | + | |
| 375 | + $this->send_raw_response(); | |
| 376 | + | |
| 377 | + return; | |
| 378 | + } | |
| 379 | + | |
| 380 | + $this->send_raw_response(); | |
| 381 | + } | |
| 382 | + | |
| 383 | + public function send_raw_response() { | |
| 384 | + ( new Form_Response\Response( | |
| 385 | + $this->get_response_manager(), | |
| 386 | + $this->response_data | |
| 387 | + ) )->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 | + } | |
| 421 | + | |
| 422 | +} | |