@@ -1,16 +1,16 @@ discard block |
||
1 | 1 | <?php if ( ! defined('EVENT_ESPRESSO_VERSION')) { exit('No direct script access allowed'); } |
2 | 2 | /** |
3 | - * |
|
4 | - * Class EE_SPCO_JSON_Response |
|
5 | - * |
|
6 | - * Description |
|
7 | - * |
|
8 | - * @package Event Espresso |
|
9 | - * @subpackage core |
|
10 | - * @author Brent Christensen |
|
11 | - * |
|
12 | - * |
|
13 | - */ |
|
3 | + * |
|
4 | + * Class EE_SPCO_JSON_Response |
|
5 | + * |
|
6 | + * Description |
|
7 | + * |
|
8 | + * @package Event Espresso |
|
9 | + * @subpackage core |
|
10 | + * @author Brent Christensen |
|
11 | + * |
|
12 | + * |
|
13 | + */ |
|
14 | 14 | class EE_SPCO_JSON_Response { |
15 | 15 | |
16 | 16 | /** |
@@ -84,7 +84,7 @@ discard block |
||
84 | 84 | |
85 | 85 | /** |
86 | 86 | * class constructor |
87 | - */ |
|
87 | + */ |
|
88 | 88 | public function __construct( ) { |
89 | 89 | } |
90 | 90 | |
@@ -271,10 +271,10 @@ discard block |
||
271 | 271 | } |
272 | 272 | |
273 | 273 | |
274 | - /** |
|
275 | - * @param float $payment_amount |
|
276 | - * @throws EE_Error |
|
277 | - */ |
|
274 | + /** |
|
275 | + * @param float $payment_amount |
|
276 | + * @throws EE_Error |
|
277 | + */ |
|
278 | 278 | public function set_payment_amount( $payment_amount ) { |
279 | 279 | $this->_payment_amount = (float)$payment_amount; |
280 | 280 | } |
@@ -408,11 +408,11 @@ discard block |
||
408 | 408 | } |
409 | 409 | |
410 | 410 | |
411 | - public function echoAndExit() |
|
412 | - { |
|
413 | - echo $this; |
|
414 | - exit(); |
|
415 | - } |
|
411 | + public function echoAndExit() |
|
412 | + { |
|
413 | + echo $this; |
|
414 | + exit(); |
|
415 | + } |
|
416 | 416 | |
417 | 417 | } |
418 | 418 | // End of file EE_SPCO_JSON_Response.php |
@@ -104,71 +104,71 @@ discard block |
||
104 | 104 | public function __toString() { |
105 | 105 | $JSON_response = array(); |
106 | 106 | // grab notices |
107 | - $notices = EE_Error::get_notices( FALSE ); |
|
108 | - $this->set_attention( isset( $notices['attention'] ) ? $notices['attention'] : '' ); |
|
109 | - $this->set_errors( isset( $notices['errors'] ) ? $notices['errors'] : '' ); |
|
110 | - $this->set_success( isset( $notices['success'] ) ? $notices['success'] : '' ); |
|
107 | + $notices = EE_Error::get_notices(FALSE); |
|
108 | + $this->set_attention(isset($notices['attention']) ? $notices['attention'] : ''); |
|
109 | + $this->set_errors(isset($notices['errors']) ? $notices['errors'] : ''); |
|
110 | + $this->set_success(isset($notices['success']) ? $notices['success'] : ''); |
|
111 | 111 | // add notices to JSON response, but only if they exist |
112 | - if ( $this->attention() ) { |
|
112 | + if ($this->attention()) { |
|
113 | 113 | $JSON_response['attention'] = $this->attention(); |
114 | 114 | } |
115 | - if ( $this->errors() ) { |
|
115 | + if ($this->errors()) { |
|
116 | 116 | $JSON_response['errors'] = $this->errors(); |
117 | 117 | } |
118 | - if ( $this->unexpected_errors() ) { |
|
118 | + if ($this->unexpected_errors()) { |
|
119 | 119 | $JSON_response['unexpected_errors'] = $this->unexpected_errors(); |
120 | 120 | } |
121 | - if ( $this->success() ) { |
|
121 | + if ($this->success()) { |
|
122 | 122 | $JSON_response['success'] = $this->success(); |
123 | 123 | } |
124 | 124 | // but if NO notices are set... at least set the "success" as a key so that the JS knows everything worked |
125 | - if ( ! isset( $JSON_response[ 'attention' ] ) && ! isset( $JSON_response[ 'errors' ] ) && ! isset( $JSON_response[ 'success' ] ) ) { |
|
125 | + if ( ! isset($JSON_response['attention']) && ! isset($JSON_response['errors']) && ! isset($JSON_response['success'])) { |
|
126 | 126 | $JSON_response['success'] = null; |
127 | 127 | } |
128 | 128 | // set redirect_url, IF it exists |
129 | - if ( $this->redirect_url() ) { |
|
129 | + if ($this->redirect_url()) { |
|
130 | 130 | $JSON_response['redirect_url'] = $this->redirect_url(); |
131 | 131 | } |
132 | 132 | // set registration_time_limit, IF it exists |
133 | - if ( $this->registration_time_limit() ) { |
|
133 | + if ($this->registration_time_limit()) { |
|
134 | 134 | $JSON_response['registration_time_limit'] = $this->registration_time_limit(); |
135 | 135 | } |
136 | 136 | // set payment_amount, IF it exists |
137 | - if ( $this->payment_amount() !== null ) { |
|
138 | - $JSON_response[ 'payment_amount' ] = $this->payment_amount(); |
|
137 | + if ($this->payment_amount() !== null) { |
|
138 | + $JSON_response['payment_amount'] = $this->payment_amount(); |
|
139 | 139 | } |
140 | 140 | // grab generic return data |
141 | 141 | $return_data = $this->return_data(); |
142 | 142 | // add billing form validation rules |
143 | - if ( $this->validation_rules() ) { |
|
143 | + if ($this->validation_rules()) { |
|
144 | 144 | $return_data['validation_rules'] = $this->validation_rules(); |
145 | 145 | } |
146 | 146 | // set reg_step_html, IF it exists |
147 | - if ( $this->reg_step_html() ) { |
|
147 | + if ($this->reg_step_html()) { |
|
148 | 148 | $return_data['reg_step_html'] = $this->reg_step_html(); |
149 | 149 | } |
150 | 150 | // set method of payment, IF it exists |
151 | - if ( $this->method_of_payment() ) { |
|
151 | + if ($this->method_of_payment()) { |
|
152 | 152 | $return_data['method_of_payment'] = $this->method_of_payment(); |
153 | 153 | } |
154 | 154 | // set "plz_select_method_of_payment" message, IF it exists |
155 | - if ( $this->plz_select_method_of_payment() ) { |
|
155 | + if ($this->plz_select_method_of_payment()) { |
|
156 | 156 | $return_data['plz_select_method_of_payment'] = $this->plz_select_method_of_payment(); |
157 | 157 | } |
158 | 158 | // set redirect_form, IF it exists |
159 | - if ( $this->redirect_form() ) { |
|
159 | + if ($this->redirect_form()) { |
|
160 | 160 | $return_data['redirect_form'] = $this->redirect_form(); |
161 | 161 | } |
162 | 162 | // and finally, add return_data array to main JSON response array, IF it contains anything |
163 | 163 | // why did we add some of the above properties to the return data array? |
164 | 164 | // because it is easier and cleaner in the Javascript to deal with this way |
165 | - if ( ! empty( $return_data )) { |
|
165 | + if ( ! empty($return_data)) { |
|
166 | 166 | $JSON_response['return_data'] = $return_data; |
167 | 167 | } |
168 | 168 | // filter final array |
169 | - $JSON_response = apply_filters( 'FHEE__EE_SPCO_JSON_Response___toString__JSON_response', $JSON_response ); |
|
169 | + $JSON_response = apply_filters('FHEE__EE_SPCO_JSON_Response___toString__JSON_response', $JSON_response); |
|
170 | 170 | // return encoded array |
171 | - return (string) wp_json_encode( $JSON_response ); |
|
171 | + return (string) wp_json_encode($JSON_response); |
|
172 | 172 | } |
173 | 173 | |
174 | 174 | |
@@ -176,7 +176,7 @@ discard block |
||
176 | 176 | /** |
177 | 177 | * @param string $attention |
178 | 178 | */ |
179 | - public function set_attention( $attention ) { |
|
179 | + public function set_attention($attention) { |
|
180 | 180 | $this->_attention = $attention; |
181 | 181 | } |
182 | 182 | |
@@ -194,7 +194,7 @@ discard block |
||
194 | 194 | /** |
195 | 195 | * @param string $errors |
196 | 196 | */ |
197 | - public function set_errors( $errors ) { |
|
197 | + public function set_errors($errors) { |
|
198 | 198 | $this->_errors = $errors; |
199 | 199 | } |
200 | 200 | |
@@ -221,7 +221,7 @@ discard block |
||
221 | 221 | /** |
222 | 222 | * @param string $unexpected_errors |
223 | 223 | */ |
224 | - public function set_unexpected_errors( $unexpected_errors ) { |
|
224 | + public function set_unexpected_errors($unexpected_errors) { |
|
225 | 225 | $this->_unexpected_errors = $unexpected_errors; |
226 | 226 | } |
227 | 227 | |
@@ -230,7 +230,7 @@ discard block |
||
230 | 230 | /** |
231 | 231 | * @param string $success |
232 | 232 | */ |
233 | - public function set_success( $success ) { |
|
233 | + public function set_success($success) { |
|
234 | 234 | $this->_success = $success; |
235 | 235 | } |
236 | 236 | |
@@ -248,7 +248,7 @@ discard block |
||
248 | 248 | /** |
249 | 249 | * @param string $method_of_payment |
250 | 250 | */ |
251 | - public function set_method_of_payment( $method_of_payment ) { |
|
251 | + public function set_method_of_payment($method_of_payment) { |
|
252 | 252 | $this->_method_of_payment = $method_of_payment; |
253 | 253 | } |
254 | 254 | |
@@ -275,8 +275,8 @@ discard block |
||
275 | 275 | * @param float $payment_amount |
276 | 276 | * @throws EE_Error |
277 | 277 | */ |
278 | - public function set_payment_amount( $payment_amount ) { |
|
279 | - $this->_payment_amount = (float)$payment_amount; |
|
278 | + public function set_payment_amount($payment_amount) { |
|
279 | + $this->_payment_amount = (float) $payment_amount; |
|
280 | 280 | } |
281 | 281 | |
282 | 282 | |
@@ -284,7 +284,7 @@ discard block |
||
284 | 284 | /** |
285 | 285 | * @param string $next_step_html |
286 | 286 | */ |
287 | - public function set_reg_step_html( $next_step_html ) { |
|
287 | + public function set_reg_step_html($next_step_html) { |
|
288 | 288 | $this->_reg_step_html = $next_step_html; |
289 | 289 | } |
290 | 290 | |
@@ -302,7 +302,7 @@ discard block |
||
302 | 302 | /** |
303 | 303 | * @param string $redirect_form |
304 | 304 | */ |
305 | - public function set_redirect_form( $redirect_form ) { |
|
305 | + public function set_redirect_form($redirect_form) { |
|
306 | 306 | $this->_redirect_form = $redirect_form; |
307 | 307 | } |
308 | 308 | |
@@ -312,7 +312,7 @@ discard block |
||
312 | 312 | * @return string |
313 | 313 | */ |
314 | 314 | public function redirect_form() { |
315 | - return ! empty( $this->_redirect_form ) ? $this->_redirect_form : FALSE; |
|
315 | + return ! empty($this->_redirect_form) ? $this->_redirect_form : FALSE; |
|
316 | 316 | } |
317 | 317 | |
318 | 318 | |
@@ -320,7 +320,7 @@ discard block |
||
320 | 320 | /** |
321 | 321 | * @param string $plz_select_method_of_payment |
322 | 322 | */ |
323 | - public function set_plz_select_method_of_payment( $plz_select_method_of_payment ) { |
|
323 | + public function set_plz_select_method_of_payment($plz_select_method_of_payment) { |
|
324 | 324 | $this->_plz_select_method_of_payment = $plz_select_method_of_payment; |
325 | 325 | } |
326 | 326 | |
@@ -338,7 +338,7 @@ discard block |
||
338 | 338 | /** |
339 | 339 | * @param string $redirect_url |
340 | 340 | */ |
341 | - public function set_redirect_url( $redirect_url ) { |
|
341 | + public function set_redirect_url($redirect_url) { |
|
342 | 342 | $this->_redirect_url = $redirect_url; |
343 | 343 | } |
344 | 344 | |
@@ -365,7 +365,7 @@ discard block |
||
365 | 365 | /** |
366 | 366 | * @param string $registration_time_limit |
367 | 367 | */ |
368 | - public function set_registration_time_limit( $registration_time_limit ) { |
|
368 | + public function set_registration_time_limit($registration_time_limit) { |
|
369 | 369 | $this->_registration_time_limit = $registration_time_limit; |
370 | 370 | } |
371 | 371 | |
@@ -374,8 +374,8 @@ discard block |
||
374 | 374 | /** |
375 | 375 | * @param array $return_data |
376 | 376 | */ |
377 | - public function set_return_data( $return_data ) { |
|
378 | - $this->_return_data = array_merge( $this->_return_data, $return_data ); |
|
377 | + public function set_return_data($return_data) { |
|
378 | + $this->_return_data = array_merge($this->_return_data, $return_data); |
|
379 | 379 | } |
380 | 380 | |
381 | 381 | |
@@ -393,8 +393,8 @@ discard block |
||
393 | 393 | * @param array $validation_rules |
394 | 394 | */ |
395 | 395 | public function add_validation_rules(array $validation_rules = array()) { |
396 | - if ( is_array( $validation_rules ) && ! empty( $validation_rules )) { |
|
397 | - $this->_validation_rules = array_merge( $this->_validation_rules, $validation_rules ); |
|
396 | + if (is_array($validation_rules) && ! empty($validation_rules)) { |
|
397 | + $this->_validation_rules = array_merge($this->_validation_rules, $validation_rules); |
|
398 | 398 | } |
399 | 399 | } |
400 | 400 | |
@@ -404,7 +404,7 @@ discard block |
||
404 | 404 | * @return array | bool |
405 | 405 | */ |
406 | 406 | public function validation_rules() { |
407 | - return ! empty( $this->_validation_rules ) ? $this->_validation_rules : FALSE; |
|
407 | + return ! empty($this->_validation_rules) ? $this->_validation_rules : FALSE; |
|
408 | 408 | } |
409 | 409 | |
410 | 410 |
@@ -111,8 +111,8 @@ discard block |
||
111 | 111 | //AND we are going to make sure they're in that specified order |
112 | 112 | $reordered_subsections = array(); |
113 | 113 | foreach ($options_array['include'] as $input_name) { |
114 | - if (isset($this->_subsections[ $input_name ])) { |
|
115 | - $reordered_subsections[ $input_name ] = $this->_subsections[ $input_name ]; |
|
114 | + if (isset($this->_subsections[$input_name])) { |
|
115 | + $reordered_subsections[$input_name] = $this->_subsections[$input_name]; |
|
116 | 116 | } |
117 | 117 | } |
118 | 118 | $this->_subsections = $reordered_subsections; |
@@ -124,7 +124,7 @@ discard block |
||
124 | 124 | if (isset($options_array['layout_strategy'])) { |
125 | 125 | $this->_layout_strategy = $options_array['layout_strategy']; |
126 | 126 | } |
127 | - if (! $this->_layout_strategy) { |
|
127 | + if ( ! $this->_layout_strategy) { |
|
128 | 128 | $this->_layout_strategy = is_admin() ? new EE_Admin_Two_Column_Layout() : new EE_Two_Column_Layout(); |
129 | 129 | } |
130 | 130 | $this->_layout_strategy->_construct_finalize($this); |
@@ -277,7 +277,7 @@ discard block |
||
277 | 277 | $req_data, |
278 | 278 | $this |
279 | 279 | ); |
280 | - $this->cached_request_data = (array)$req_data; |
|
280 | + $this->cached_request_data = (array) $req_data; |
|
281 | 281 | } |
282 | 282 | return $this->cached_request_data; |
283 | 283 | } |
@@ -313,7 +313,7 @@ discard block |
||
313 | 313 | if ($validate) { |
314 | 314 | $this->_validate(); |
315 | 315 | //if it's invalid, we're going to want to re-display so remember what they submitted |
316 | - if (! $this->is_valid()) { |
|
316 | + if ( ! $this->is_valid()) { |
|
317 | 317 | $this->store_submitted_form_data_in_session(); |
318 | 318 | } |
319 | 319 | } |
@@ -426,11 +426,11 @@ discard block |
||
426 | 426 | public function populate_defaults($default_data) |
427 | 427 | { |
428 | 428 | foreach ($this->subsections(false) as $subsection_name => $subsection) { |
429 | - if (isset($default_data[ $subsection_name ])) { |
|
429 | + if (isset($default_data[$subsection_name])) { |
|
430 | 430 | if ($subsection instanceof EE_Form_Input_Base) { |
431 | - $subsection->set_default($default_data[ $subsection_name ]); |
|
431 | + $subsection->set_default($default_data[$subsection_name]); |
|
432 | 432 | } elseif ($subsection instanceof EE_Form_Section_Proper) { |
433 | - $subsection->populate_defaults($default_data[ $subsection_name ]); |
|
433 | + $subsection->populate_defaults($default_data[$subsection_name]); |
|
434 | 434 | } |
435 | 435 | } |
436 | 436 | } |
@@ -445,7 +445,7 @@ discard block |
||
445 | 445 | */ |
446 | 446 | public function subsection_exists($name) |
447 | 447 | { |
448 | - return isset($this->_subsections[ $name ]) ? true : false; |
|
448 | + return isset($this->_subsections[$name]) ? true : false; |
|
449 | 449 | } |
450 | 450 | |
451 | 451 | |
@@ -467,7 +467,7 @@ discard block |
||
467 | 467 | if ($require_construction_to_be_finalized) { |
468 | 468 | $this->ensure_construct_finalized_called(); |
469 | 469 | } |
470 | - return $this->subsection_exists($name) ? $this->_subsections[ $name ] : null; |
|
470 | + return $this->subsection_exists($name) ? $this->_subsections[$name] : null; |
|
471 | 471 | } |
472 | 472 | |
473 | 473 | |
@@ -482,7 +482,7 @@ discard block |
||
482 | 482 | $validatable_subsections = array(); |
483 | 483 | foreach ($this->subsections() as $name => $obj) { |
484 | 484 | if ($obj instanceof EE_Form_Section_Validatable) { |
485 | - $validatable_subsections[ $name ] = $obj; |
|
485 | + $validatable_subsections[$name] = $obj; |
|
486 | 486 | } |
487 | 487 | } |
488 | 488 | return $validatable_subsections; |
@@ -509,7 +509,7 @@ discard block |
||
509 | 509 | $name, |
510 | 510 | $require_construction_to_be_finalized |
511 | 511 | ); |
512 | - if (! $subsection instanceof EE_Form_Input_Base) { |
|
512 | + if ( ! $subsection instanceof EE_Form_Input_Base) { |
|
513 | 513 | throw new EE_Error( |
514 | 514 | sprintf( |
515 | 515 | esc_html__( |
@@ -546,7 +546,7 @@ discard block |
||
546 | 546 | $name, |
547 | 547 | $require_construction_to_be_finalized |
548 | 548 | ); |
549 | - if (! $subsection instanceof EE_Form_Section_Proper) { |
|
549 | + if ( ! $subsection instanceof EE_Form_Section_Proper) { |
|
550 | 550 | throw new EE_Error( |
551 | 551 | sprintf( |
552 | 552 | esc_html__( |
@@ -585,8 +585,8 @@ discard block |
||
585 | 585 | */ |
586 | 586 | public function is_valid() |
587 | 587 | { |
588 | - if($this->is_valid === null) { |
|
589 | - if (! $this->has_received_submission()) { |
|
588 | + if ($this->is_valid === null) { |
|
589 | + if ( ! $this->has_received_submission()) { |
|
590 | 590 | throw new EE_Error( |
591 | 591 | sprintf( |
592 | 592 | esc_html__( |
@@ -596,14 +596,14 @@ discard block |
||
596 | 596 | ) |
597 | 597 | ); |
598 | 598 | } |
599 | - if (! parent::is_valid()) { |
|
599 | + if ( ! parent::is_valid()) { |
|
600 | 600 | $this->is_valid = false; |
601 | 601 | } else { |
602 | 602 | // ok so no general errors to this entire form section. |
603 | 603 | // so let's check the subsections, but only set errors if that hasn't been done yet |
604 | 604 | $this->is_valid = true; |
605 | 605 | foreach ($this->get_validatable_subsections() as $subsection) { |
606 | - if (! $subsection->is_valid()) { |
|
606 | + if ( ! $subsection->is_valid()) { |
|
607 | 607 | $this->is_valid = false; |
608 | 608 | } |
609 | 609 | } |
@@ -620,7 +620,7 @@ discard block |
||
620 | 620 | */ |
621 | 621 | protected function _set_default_name_if_empty() |
622 | 622 | { |
623 | - if (! $this->_name) { |
|
623 | + if ( ! $this->_name) { |
|
624 | 624 | $classname = get_class($this); |
625 | 625 | $default_name = str_replace('EE_', '', $classname); |
626 | 626 | $this->_name = $default_name; |
@@ -710,7 +710,7 @@ discard block |
||
710 | 710 | { |
711 | 711 | wp_register_script( |
712 | 712 | 'ee_form_section_validation', |
713 | - EE_GLOBAL_ASSETS_URL . 'scripts' . DS . 'form_section_validation.js', |
|
713 | + EE_GLOBAL_ASSETS_URL.'scripts'.DS.'form_section_validation.js', |
|
714 | 714 | array('jquery-validate', 'jquery-ui-datepicker', 'jquery-validate-extra-methods'), |
715 | 715 | EVENT_ESPRESSO_VERSION, |
716 | 716 | true |
@@ -754,13 +754,13 @@ discard block |
||
754 | 754 | // we only want to localize vars ONCE for the entire form, |
755 | 755 | // so if the form section doesn't have a parent, then it must be the top dog |
756 | 756 | if ($return_for_subsection || ! $this->parent_section()) { |
757 | - EE_Form_Section_Proper::$_js_localization['form_data'][ $this->html_id() ] = array( |
|
757 | + EE_Form_Section_Proper::$_js_localization['form_data'][$this->html_id()] = array( |
|
758 | 758 | 'form_section_id' => $this->html_id(true), |
759 | 759 | 'validation_rules' => $this->get_jquery_validation_rules(), |
760 | 760 | 'other_data' => $this->get_other_js_data(), |
761 | 761 | 'errors' => $this->subsection_validation_errors_by_html_name(), |
762 | 762 | ); |
763 | - EE_Form_Section_Proper::$_scripts_localized = true; |
|
763 | + EE_Form_Section_Proper::$_scripts_localized = true; |
|
764 | 764 | } |
765 | 765 | } |
766 | 766 | |
@@ -795,7 +795,7 @@ discard block |
||
795 | 795 | $inputs = array(); |
796 | 796 | foreach ($this->subsections() as $subsection) { |
797 | 797 | if ($subsection instanceof EE_Form_Input_Base) { |
798 | - $inputs[ $subsection->html_name() ] = $subsection; |
|
798 | + $inputs[$subsection->html_name()] = $subsection; |
|
799 | 799 | } elseif ($subsection instanceof EE_Form_Section_Proper) { |
800 | 800 | $inputs += $subsection->inputs_in_subsections(); |
801 | 801 | } |
@@ -818,7 +818,7 @@ discard block |
||
818 | 818 | $errors = array(); |
819 | 819 | foreach ($inputs as $form_input) { |
820 | 820 | if ($form_input instanceof EE_Form_Input_Base && $form_input->get_validation_errors()) { |
821 | - $errors[ $form_input->html_name() ] = $form_input->get_validation_error_string(); |
|
821 | + $errors[$form_input->html_name()] = $form_input->get_validation_error_string(); |
|
822 | 822 | } |
823 | 823 | } |
824 | 824 | return $errors; |
@@ -841,7 +841,7 @@ discard block |
||
841 | 841 | $email_validation_level = isset(EE_Registry::instance()->CFG->registration->email_validation_level) |
842 | 842 | ? EE_Registry::instance()->CFG->registration->email_validation_level |
843 | 843 | : 'wp_default'; |
844 | - EE_Form_Section_Proper::$_js_localization['email_validation_level'] = $email_validation_level; |
|
844 | + EE_Form_Section_Proper::$_js_localization['email_validation_level'] = $email_validation_level; |
|
845 | 845 | wp_enqueue_script('ee_form_section_validation'); |
846 | 846 | wp_localize_script( |
847 | 847 | 'ee_form_section_validation', |
@@ -858,7 +858,7 @@ discard block |
||
858 | 858 | */ |
859 | 859 | public function ensure_scripts_localized() |
860 | 860 | { |
861 | - if (! EE_Form_Section_Proper::$_scripts_localized) { |
|
861 | + if ( ! EE_Form_Section_Proper::$_scripts_localized) { |
|
862 | 862 | $this->_enqueue_and_localize_form_js(); |
863 | 863 | } |
864 | 864 | } |
@@ -954,8 +954,8 @@ discard block |
||
954 | 954 | //reset the cache of whether this form is valid or not- we're re-validating it now |
955 | 955 | $this->is_valid = null; |
956 | 956 | foreach ($this->get_validatable_subsections() as $subsection_name => $subsection) { |
957 | - if (method_exists($this, '_validate_' . $subsection_name)) { |
|
958 | - call_user_func_array(array($this, '_validate_' . $subsection_name), array($subsection)); |
|
957 | + if (method_exists($this, '_validate_'.$subsection_name)) { |
|
958 | + call_user_func_array(array($this, '_validate_'.$subsection_name), array($subsection)); |
|
959 | 959 | } |
960 | 960 | $subsection->_validate(); |
961 | 961 | } |
@@ -973,9 +973,9 @@ discard block |
||
973 | 973 | $inputs = array(); |
974 | 974 | foreach ($this->subsections() as $subsection_name => $subsection) { |
975 | 975 | if ($subsection instanceof EE_Form_Section_Proper) { |
976 | - $inputs[ $subsection_name ] = $subsection->valid_data(); |
|
976 | + $inputs[$subsection_name] = $subsection->valid_data(); |
|
977 | 977 | } elseif ($subsection instanceof EE_Form_Input_Base) { |
978 | - $inputs[ $subsection_name ] = $subsection->normalized_value(); |
|
978 | + $inputs[$subsection_name] = $subsection->normalized_value(); |
|
979 | 979 | } |
980 | 980 | } |
981 | 981 | return $inputs; |
@@ -993,7 +993,7 @@ discard block |
||
993 | 993 | $inputs = array(); |
994 | 994 | foreach ($this->subsections() as $subsection_name => $subsection) { |
995 | 995 | if ($subsection instanceof EE_Form_Input_Base) { |
996 | - $inputs[ $subsection_name ] = $subsection; |
|
996 | + $inputs[$subsection_name] = $subsection; |
|
997 | 997 | } |
998 | 998 | } |
999 | 999 | return $inputs; |
@@ -1011,7 +1011,7 @@ discard block |
||
1011 | 1011 | $form_sections = array(); |
1012 | 1012 | foreach ($this->subsections() as $name => $obj) { |
1013 | 1013 | if ($obj instanceof EE_Form_Section_Proper) { |
1014 | - $form_sections[ $name ] = $obj; |
|
1014 | + $form_sections[$name] = $obj; |
|
1015 | 1015 | } |
1016 | 1016 | } |
1017 | 1017 | return $form_sections; |
@@ -1118,7 +1118,7 @@ discard block |
||
1118 | 1118 | $input_values = array(); |
1119 | 1119 | foreach ($this->subsections() as $subsection_name => $subsection) { |
1120 | 1120 | if ($subsection instanceof EE_Form_Input_Base) { |
1121 | - $input_values[ $subsection_name ] = $pretty |
|
1121 | + $input_values[$subsection_name] = $pretty |
|
1122 | 1122 | ? $subsection->pretty_value() |
1123 | 1123 | : $subsection->normalized_value(); |
1124 | 1124 | } elseif ($subsection instanceof EE_Form_Section_Proper && $include_subform_inputs) { |
@@ -1130,7 +1130,7 @@ discard block |
||
1130 | 1130 | if ($flatten) { |
1131 | 1131 | $input_values = array_merge($input_values, $subform_input_values); |
1132 | 1132 | } else { |
1133 | - $input_values[ $subsection_name ] = $subform_input_values; |
|
1133 | + $input_values[$subsection_name] = $subform_input_values; |
|
1134 | 1134 | } |
1135 | 1135 | } |
1136 | 1136 | } |
@@ -1158,7 +1158,7 @@ discard block |
||
1158 | 1158 | if ($subsection instanceof EE_Form_Input_Base) { |
1159 | 1159 | // is this input part of an array of inputs? |
1160 | 1160 | if (strpos($subsection->html_name(), '[') !== false) { |
1161 | - $full_input_name = EEH_Array::convert_array_values_to_keys( |
|
1161 | + $full_input_name = EEH_Array::convert_array_values_to_keys( |
|
1162 | 1162 | explode( |
1163 | 1163 | '[', |
1164 | 1164 | str_replace(']', '', $subsection->html_name()) |
@@ -1167,7 +1167,7 @@ discard block |
||
1167 | 1167 | ); |
1168 | 1168 | $submitted_values = array_replace_recursive($submitted_values, $full_input_name); |
1169 | 1169 | } else { |
1170 | - $submitted_values[ $subsection->html_name() ] = $subsection->raw_value(); |
|
1170 | + $submitted_values[$subsection->html_name()] = $subsection->raw_value(); |
|
1171 | 1171 | } |
1172 | 1172 | } elseif ($subsection instanceof EE_Form_Section_Proper && $include_subforms) { |
1173 | 1173 | $subform_input_values = $subsection->submitted_values($include_subforms); |
@@ -1202,7 +1202,7 @@ discard block |
||
1202 | 1202 | public function exclude(array $inputs_to_exclude = array()) |
1203 | 1203 | { |
1204 | 1204 | foreach ($inputs_to_exclude as $input_to_exclude_name) { |
1205 | - unset($this->_subsections[ $input_to_exclude_name ]); |
|
1205 | + unset($this->_subsections[$input_to_exclude_name]); |
|
1206 | 1206 | } |
1207 | 1207 | } |
1208 | 1208 | |
@@ -1244,7 +1244,7 @@ discard block |
||
1244 | 1244 | public function add_subsections($new_subsections, $subsection_name_to_target = null, $add_before = true) |
1245 | 1245 | { |
1246 | 1246 | foreach ($new_subsections as $subsection_name => $subsection) { |
1247 | - if (! $subsection instanceof EE_Form_Section_Base) { |
|
1247 | + if ( ! $subsection instanceof EE_Form_Section_Base) { |
|
1248 | 1248 | EE_Error::add_error( |
1249 | 1249 | sprintf( |
1250 | 1250 | esc_html__( |
@@ -1256,7 +1256,7 @@ discard block |
||
1256 | 1256 | $this->name() |
1257 | 1257 | ) |
1258 | 1258 | ); |
1259 | - unset($new_subsections[ $subsection_name ]); |
|
1259 | + unset($new_subsections[$subsection_name]); |
|
1260 | 1260 | } |
1261 | 1261 | } |
1262 | 1262 | $this->_subsections = EEH_Array::insert_into_array( |
@@ -1280,7 +1280,7 @@ discard block |
||
1280 | 1280 | */ |
1281 | 1281 | public function has_subsection($subsection_name, $recursive = false) |
1282 | 1282 | { |
1283 | - foreach ($this->_subsections as $name => $subsection) {if( |
|
1283 | + foreach ($this->_subsections as $name => $subsection) {if ( |
|
1284 | 1284 | $name === $subsection_name |
1285 | 1285 | || ( |
1286 | 1286 | $recursive |
@@ -1371,7 +1371,7 @@ discard block |
||
1371 | 1371 | public function html_name_prefix() |
1372 | 1372 | { |
1373 | 1373 | if ($this->parent_section() instanceof EE_Form_Section_Proper) { |
1374 | - return $this->parent_section()->html_name_prefix() . '[' . $this->name() . ']'; |
|
1374 | + return $this->parent_section()->html_name_prefix().'['.$this->name().']'; |
|
1375 | 1375 | } |
1376 | 1376 | return $this->name(); |
1377 | 1377 | } |
@@ -1411,7 +1411,7 @@ discard block |
||
1411 | 1411 | */ |
1412 | 1412 | public function ensure_construct_finalized_called() |
1413 | 1413 | { |
1414 | - if (! $this->_construction_finalized) { |
|
1414 | + if ( ! $this->_construction_finalized) { |
|
1415 | 1415 | $this->_construct_finalize($this->_parent_section, $this->_name); |
1416 | 1416 | } |
1417 | 1417 | } |
@@ -1484,7 +1484,7 @@ discard block |
||
1484 | 1484 | $form_section = $validation_error->get_form_section(); |
1485 | 1485 | if ($form_section instanceof EE_Form_Input_Base) { |
1486 | 1486 | $label = $validation_error->get_form_section()->html_label_text(); |
1487 | - } elseif($form_section instanceof EE_Form_Section_Validatable) { |
|
1487 | + } elseif ($form_section instanceof EE_Form_Section_Validatable) { |
|
1488 | 1488 | $label = $validation_error->get_form_section()->name(); |
1489 | 1489 | } else { |
1490 | 1490 | $label = esc_html__('Unknown', 'event_espresso'); |
@@ -14,1529 +14,1529 @@ |
||
14 | 14 | class EE_Form_Section_Proper extends EE_Form_Section_Validatable |
15 | 15 | { |
16 | 16 | |
17 | - const SUBMITTED_FORM_DATA_SSN_KEY = 'submitted_form_data'; |
|
18 | - |
|
19 | - /** |
|
20 | - * Subsections |
|
21 | - * |
|
22 | - * @var EE_Form_Section_Validatable[] |
|
23 | - */ |
|
24 | - protected $_subsections = array(); |
|
25 | - |
|
26 | - /** |
|
27 | - * Strategy for laying out the form |
|
28 | - * |
|
29 | - * @var EE_Form_Section_Layout_Base |
|
30 | - */ |
|
31 | - protected $_layout_strategy; |
|
32 | - |
|
33 | - /** |
|
34 | - * Whether or not this form has received and validated a form submission yet |
|
35 | - * |
|
36 | - * @var boolean |
|
37 | - */ |
|
38 | - protected $_received_submission = false; |
|
39 | - |
|
40 | - /** |
|
41 | - * message displayed to users upon successful form submission |
|
42 | - * |
|
43 | - * @var string |
|
44 | - */ |
|
45 | - protected $_form_submission_success_message = ''; |
|
46 | - |
|
47 | - /** |
|
48 | - * message displayed to users upon unsuccessful form submission |
|
49 | - * |
|
50 | - * @var string |
|
51 | - */ |
|
52 | - protected $_form_submission_error_message = ''; |
|
53 | - |
|
54 | - /** |
|
55 | - * @var array like $_REQUEST |
|
56 | - */ |
|
57 | - protected $cached_request_data; |
|
58 | - |
|
59 | - /** |
|
60 | - * Stores whether this form (and its sub-sections) were found to be valid or not. |
|
61 | - * Starts off as null, but once the form is validated, it set to either true or false |
|
62 | - * @var boolean|null |
|
63 | - */ |
|
64 | - protected $is_valid; |
|
65 | - |
|
66 | - /** |
|
67 | - * Stores all the data that will localized for form validation |
|
68 | - * |
|
69 | - * @var array |
|
70 | - */ |
|
71 | - static protected $_js_localization = array(); |
|
72 | - |
|
73 | - /** |
|
74 | - * whether or not the form's localized validation JS vars have been set |
|
75 | - * |
|
76 | - * @type boolean |
|
77 | - */ |
|
78 | - static protected $_scripts_localized = false; |
|
79 | - |
|
80 | - |
|
81 | - /** |
|
82 | - * when constructing a proper form section, calls _construct_finalize on children |
|
83 | - * so that they know who their parent is, and what name they've been given. |
|
84 | - * |
|
85 | - * @param array[] $options_array { |
|
86 | - * @type $subsections EE_Form_Section_Validatable[] where keys are the section's name |
|
87 | - * @type $include string[] numerically-indexed where values are section names to be included, |
|
88 | - * and in that order. This is handy if you want |
|
89 | - * the subsections to be ordered differently than the default, and if you override |
|
90 | - * which fields are shown |
|
91 | - * @type $exclude string[] values are subsections to be excluded. This is handy if you want |
|
92 | - * to remove certain default subsections (note: if you specify BOTH 'include' AND |
|
93 | - * 'exclude', the inclusions will be applied first, and the exclusions will exclude |
|
94 | - * items from that list of inclusions) |
|
95 | - * @type $layout_strategy EE_Form_Section_Layout_Base strategy for laying out the form |
|
96 | - * } @see EE_Form_Section_Validatable::__construct() |
|
97 | - * @throws EE_Error |
|
98 | - */ |
|
99 | - public function __construct($options_array = array()) |
|
100 | - { |
|
101 | - $options_array = (array) apply_filters( |
|
102 | - 'FHEE__EE_Form_Section_Proper___construct__options_array', |
|
103 | - $options_array, |
|
104 | - $this |
|
105 | - ); |
|
106 | - //call parent first, as it may be setting the name |
|
107 | - parent::__construct($options_array); |
|
108 | - //if they've included subsections in the constructor, add them now |
|
109 | - if (isset($options_array['include'])) { |
|
110 | - //we are going to make sure we ONLY have those subsections to include |
|
111 | - //AND we are going to make sure they're in that specified order |
|
112 | - $reordered_subsections = array(); |
|
113 | - foreach ($options_array['include'] as $input_name) { |
|
114 | - if (isset($this->_subsections[ $input_name ])) { |
|
115 | - $reordered_subsections[ $input_name ] = $this->_subsections[ $input_name ]; |
|
116 | - } |
|
117 | - } |
|
118 | - $this->_subsections = $reordered_subsections; |
|
119 | - } |
|
120 | - if (isset($options_array['exclude'])) { |
|
121 | - $exclude = $options_array['exclude']; |
|
122 | - $this->_subsections = array_diff_key($this->_subsections, array_flip($exclude)); |
|
123 | - } |
|
124 | - if (isset($options_array['layout_strategy'])) { |
|
125 | - $this->_layout_strategy = $options_array['layout_strategy']; |
|
126 | - } |
|
127 | - if (! $this->_layout_strategy) { |
|
128 | - $this->_layout_strategy = is_admin() ? new EE_Admin_Two_Column_Layout() : new EE_Two_Column_Layout(); |
|
129 | - } |
|
130 | - $this->_layout_strategy->_construct_finalize($this); |
|
131 | - //ok so we are definitely going to want the forms JS, |
|
132 | - //so enqueue it or remember to enqueue it during wp_enqueue_scripts |
|
133 | - if (did_action('wp_enqueue_scripts') || did_action('admin_enqueue_scripts')) { |
|
134 | - //ok so they've constructed this object after when they should have. |
|
135 | - //just enqueue the generic form scripts and initialize the form immediately in the JS |
|
136 | - EE_Form_Section_Proper::wp_enqueue_scripts(true); |
|
137 | - } else { |
|
138 | - add_action('wp_enqueue_scripts', array('EE_Form_Section_Proper', 'wp_enqueue_scripts')); |
|
139 | - add_action('admin_enqueue_scripts', array('EE_Form_Section_Proper', 'wp_enqueue_scripts')); |
|
140 | - } |
|
141 | - add_action('wp_footer', array($this, 'ensure_scripts_localized'), 1); |
|
142 | - /** |
|
143 | - * Gives other plugins a chance to hook in before construct finalize is called. |
|
144 | - * The form probably doesn't yet have a parent form section. |
|
145 | - * Since 4.9.32, when this action was introduced, this is the best place to add a subsection onto a form, |
|
146 | - * assuming you don't care what the form section's name, HTML ID, or HTML name etc are. |
|
147 | - * Also see AHEE__EE_Form_Section_Proper___construct_finalize__end |
|
148 | - * |
|
149 | - * @since 4.9.32 |
|
150 | - * @param EE_Form_Section_Proper $this before __construct is done, but all of its logic, |
|
151 | - * except maybe calling _construct_finalize has been done |
|
152 | - * @param array $options_array options passed into the constructor |
|
153 | - */ |
|
154 | - do_action( |
|
155 | - 'AHEE__EE_Form_Input_Base___construct__before_construct_finalize_called', |
|
156 | - $this, |
|
157 | - $options_array |
|
158 | - ); |
|
159 | - if (isset($options_array['name'])) { |
|
160 | - $this->_construct_finalize(null, $options_array['name']); |
|
161 | - } |
|
162 | - } |
|
163 | - |
|
164 | - |
|
165 | - /** |
|
166 | - * Finishes construction given the parent form section and this form section's name |
|
167 | - * |
|
168 | - * @param EE_Form_Section_Proper $parent_form_section |
|
169 | - * @param string $name |
|
170 | - * @throws EE_Error |
|
171 | - */ |
|
172 | - public function _construct_finalize($parent_form_section, $name) |
|
173 | - { |
|
174 | - parent::_construct_finalize($parent_form_section, $name); |
|
175 | - $this->_set_default_name_if_empty(); |
|
176 | - $this->_set_default_html_id_if_empty(); |
|
177 | - foreach ($this->_subsections as $subsection_name => $subsection) { |
|
178 | - if ($subsection instanceof EE_Form_Section_Base) { |
|
179 | - $subsection->_construct_finalize($this, $subsection_name); |
|
180 | - } else { |
|
181 | - throw new EE_Error( |
|
182 | - sprintf( |
|
183 | - esc_html__( |
|
184 | - 'Subsection "%s" is not an instanceof EE_Form_Section_Base on form "%s". It is a "%s"', |
|
185 | - 'event_espresso' |
|
186 | - ), |
|
187 | - $subsection_name, |
|
188 | - get_class($this), |
|
189 | - $subsection ? get_class($subsection) : esc_html__('NULL', 'event_espresso') |
|
190 | - ) |
|
191 | - ); |
|
192 | - } |
|
193 | - } |
|
194 | - /** |
|
195 | - * Action performed just after form has been given a name (and HTML ID etc) and is fully constructed. |
|
196 | - * If you have code that should modify the form and needs it and its subsections to have a name, HTML ID |
|
197 | - * (or other attributes derived from the name like the HTML label id, etc), this is where it should be done. |
|
198 | - * This might only happen just before displaying the form, or just before it receives form submission data. |
|
199 | - * If you need to modify the form or its subsections before _construct_finalize is called on it (and we've |
|
200 | - * ensured it has a name, HTML IDs, etc |
|
201 | - * |
|
202 | - * @param EE_Form_Section_Proper $this |
|
203 | - * @param EE_Form_Section_Proper|null $parent_form_section |
|
204 | - * @param string $name |
|
205 | - */ |
|
206 | - do_action( |
|
207 | - 'AHEE__EE_Form_Section_Proper___construct_finalize__end', |
|
208 | - $this, |
|
209 | - $parent_form_section, |
|
210 | - $name |
|
211 | - ); |
|
212 | - } |
|
213 | - |
|
214 | - |
|
215 | - /** |
|
216 | - * Gets the layout strategy for this form section |
|
217 | - * |
|
218 | - * @return EE_Form_Section_Layout_Base |
|
219 | - */ |
|
220 | - public function get_layout_strategy() |
|
221 | - { |
|
222 | - return $this->_layout_strategy; |
|
223 | - } |
|
224 | - |
|
225 | - |
|
226 | - /** |
|
227 | - * Gets the HTML for a single input for this form section according |
|
228 | - * to the layout strategy |
|
229 | - * |
|
230 | - * @param EE_Form_Input_Base $input |
|
231 | - * @return string |
|
232 | - */ |
|
233 | - public function get_html_for_input($input) |
|
234 | - { |
|
235 | - return $this->_layout_strategy->layout_input($input); |
|
236 | - } |
|
237 | - |
|
238 | - |
|
239 | - /** |
|
240 | - * was_submitted - checks if form inputs are present in request data |
|
241 | - * Basically an alias for form_data_present_in() (which is used by both |
|
242 | - * proper form sections and form inputs) |
|
243 | - * |
|
244 | - * @param null $form_data |
|
245 | - * @return boolean |
|
246 | - * @throws EE_Error |
|
247 | - */ |
|
248 | - public function was_submitted($form_data = null) |
|
249 | - { |
|
250 | - return $this->form_data_present_in($form_data); |
|
251 | - } |
|
252 | - |
|
253 | - /** |
|
254 | - * Gets the cached request data; but if there is none, or $req_data was set with |
|
255 | - * something different, refresh the cache, and then return it |
|
256 | - * @param null $req_data |
|
257 | - * @return array |
|
258 | - */ |
|
259 | - protected function getCachedRequest($req_data = null) |
|
260 | - { |
|
261 | - if ($this->cached_request_data === null |
|
262 | - || ( |
|
263 | - $req_data !== null && |
|
264 | - $req_data !== $this->cached_request_data |
|
265 | - ) |
|
266 | - ) { |
|
267 | - $req_data = apply_filters( |
|
268 | - 'FHEE__EE_Form_Section_Proper__receive_form_submission__req_data', |
|
269 | - $req_data, |
|
270 | - $this |
|
271 | - ); |
|
272 | - if ($req_data === null) { |
|
273 | - $req_data = array_merge($_GET, $_POST); |
|
274 | - } |
|
275 | - $req_data = apply_filters( |
|
276 | - 'FHEE__EE_Form_Section_Proper__receive_form_submission__request_data', |
|
277 | - $req_data, |
|
278 | - $this |
|
279 | - ); |
|
280 | - $this->cached_request_data = (array)$req_data; |
|
281 | - } |
|
282 | - return $this->cached_request_data; |
|
283 | - } |
|
284 | - |
|
285 | - |
|
286 | - /** |
|
287 | - * After the form section is initially created, call this to sanitize the data in the submission |
|
288 | - * which relates to this form section, validate it, and set it as properties on the form. |
|
289 | - * |
|
290 | - * @param array|null $req_data should usually be $_POST (the default). |
|
291 | - * However, you CAN supply a different array. |
|
292 | - * Consider using set_defaults() instead however. |
|
293 | - * (If you rendered the form in the page using echo $form_x->get_html() |
|
294 | - * the inputs will have the correct name in the request data for this function |
|
295 | - * to find them and populate the form with them. |
|
296 | - * If you have a flat form (with only input subsections), |
|
297 | - * you can supply a flat array where keys |
|
298 | - * are the form input names and values are their values) |
|
299 | - * @param boolean $validate whether or not to perform validation on this data. Default is, |
|
300 | - * of course, to validate that data, and set errors on the invalid values. |
|
301 | - * But if the data has already been validated |
|
302 | - * (eg you validated the data then stored it in the DB) |
|
303 | - * you may want to skip this step. |
|
304 | - * @throws InvalidArgumentException |
|
305 | - * @throws InvalidInterfaceException |
|
306 | - * @throws InvalidDataTypeException |
|
307 | - * @throws EE_Error |
|
308 | - */ |
|
309 | - public function receive_form_submission($req_data = null, $validate = true) |
|
310 | - { |
|
311 | - $req_data = $this->getCachedRequest($req_data); |
|
312 | - $this->_normalize($req_data); |
|
313 | - if ($validate) { |
|
314 | - $this->_validate(); |
|
315 | - //if it's invalid, we're going to want to re-display so remember what they submitted |
|
316 | - if (! $this->is_valid()) { |
|
317 | - $this->store_submitted_form_data_in_session(); |
|
318 | - } |
|
319 | - } |
|
320 | - if ($this->submission_error_message() === '' && ! $this->is_valid()) { |
|
321 | - $this->set_submission_error_message(); |
|
322 | - } |
|
323 | - do_action( |
|
324 | - 'AHEE__EE_Form_Section_Proper__receive_form_submission__end', |
|
325 | - $req_data, |
|
326 | - $this, |
|
327 | - $validate |
|
328 | - ); |
|
329 | - } |
|
330 | - |
|
331 | - |
|
332 | - /** |
|
333 | - * caches the originally submitted input values in the session |
|
334 | - * so that they can be used to repopulate the form if it failed validation |
|
335 | - * |
|
336 | - * @return boolean whether or not the data was successfully stored in the session |
|
337 | - * @throws InvalidArgumentException |
|
338 | - * @throws InvalidInterfaceException |
|
339 | - * @throws InvalidDataTypeException |
|
340 | - * @throws EE_Error |
|
341 | - */ |
|
342 | - protected function store_submitted_form_data_in_session() |
|
343 | - { |
|
344 | - return EE_Registry::instance()->SSN->set_session_data( |
|
345 | - array( |
|
346 | - EE_Form_Section_Proper::SUBMITTED_FORM_DATA_SSN_KEY => $this->submitted_values(true), |
|
347 | - ) |
|
348 | - ); |
|
349 | - } |
|
350 | - |
|
351 | - |
|
352 | - /** |
|
353 | - * retrieves the originally submitted input values in the session |
|
354 | - * so that they can be used to repopulate the form if it failed validation |
|
355 | - * |
|
356 | - * @return array |
|
357 | - * @throws InvalidArgumentException |
|
358 | - * @throws InvalidInterfaceException |
|
359 | - * @throws InvalidDataTypeException |
|
360 | - */ |
|
361 | - protected function get_submitted_form_data_from_session() |
|
362 | - { |
|
363 | - $session = EE_Registry::instance()->SSN; |
|
364 | - if ($session instanceof EE_Session) { |
|
365 | - return $session->get_session_data( |
|
366 | - EE_Form_Section_Proper::SUBMITTED_FORM_DATA_SSN_KEY |
|
367 | - ); |
|
368 | - } |
|
369 | - return array(); |
|
370 | - } |
|
371 | - |
|
372 | - |
|
373 | - /** |
|
374 | - * flushed the originally submitted input values from the session |
|
375 | - * |
|
376 | - * @return boolean whether or not the data was successfully removed from the session |
|
377 | - * @throws InvalidArgumentException |
|
378 | - * @throws InvalidInterfaceException |
|
379 | - * @throws InvalidDataTypeException |
|
380 | - */ |
|
381 | - protected function flush_submitted_form_data_from_session() |
|
382 | - { |
|
383 | - return EE_Registry::instance()->SSN->reset_data( |
|
384 | - array(EE_Form_Section_Proper::SUBMITTED_FORM_DATA_SSN_KEY) |
|
385 | - ); |
|
386 | - } |
|
387 | - |
|
388 | - |
|
389 | - /** |
|
390 | - * Populates this form and its subsections with data from the session. |
|
391 | - * (Wrapper for EE_Form_Section_Proper::receive_form_submission, so it shows |
|
392 | - * validation errors when displaying too) |
|
393 | - * Returns true if the form was populated from the session, false otherwise |
|
394 | - * |
|
395 | - * @return boolean |
|
396 | - * @throws InvalidArgumentException |
|
397 | - * @throws InvalidInterfaceException |
|
398 | - * @throws InvalidDataTypeException |
|
399 | - * @throws EE_Error |
|
400 | - */ |
|
401 | - public function populate_from_session() |
|
402 | - { |
|
403 | - $form_data_in_session = $this->get_submitted_form_data_from_session(); |
|
404 | - if (empty($form_data_in_session)) { |
|
405 | - return false; |
|
406 | - } |
|
407 | - $this->receive_form_submission($form_data_in_session); |
|
408 | - $this->flush_submitted_form_data_from_session(); |
|
409 | - if ($this->form_data_present_in($form_data_in_session)) { |
|
410 | - return true; |
|
411 | - } |
|
412 | - return false; |
|
413 | - } |
|
414 | - |
|
415 | - |
|
416 | - /** |
|
417 | - * Populates the default data for the form, given an array where keys are |
|
418 | - * the input names, and values are their values (preferably normalized to be their |
|
419 | - * proper PHP types, not all strings... although that should be ok too). |
|
420 | - * Proper subsections are sub-arrays, the key being the subsection's name, and |
|
421 | - * the value being an array formatted in teh same way |
|
422 | - * |
|
423 | - * @param array $default_data |
|
424 | - * @throws EE_Error |
|
425 | - */ |
|
426 | - public function populate_defaults($default_data) |
|
427 | - { |
|
428 | - foreach ($this->subsections(false) as $subsection_name => $subsection) { |
|
429 | - if (isset($default_data[ $subsection_name ])) { |
|
430 | - if ($subsection instanceof EE_Form_Input_Base) { |
|
431 | - $subsection->set_default($default_data[ $subsection_name ]); |
|
432 | - } elseif ($subsection instanceof EE_Form_Section_Proper) { |
|
433 | - $subsection->populate_defaults($default_data[ $subsection_name ]); |
|
434 | - } |
|
435 | - } |
|
436 | - } |
|
437 | - } |
|
438 | - |
|
439 | - |
|
440 | - /** |
|
441 | - * returns true if subsection exists |
|
442 | - * |
|
443 | - * @param string $name |
|
444 | - * @return boolean |
|
445 | - */ |
|
446 | - public function subsection_exists($name) |
|
447 | - { |
|
448 | - return isset($this->_subsections[ $name ]) ? true : false; |
|
449 | - } |
|
450 | - |
|
451 | - |
|
452 | - /** |
|
453 | - * Gets the subsection specified by its name |
|
454 | - * |
|
455 | - * @param string $name |
|
456 | - * @param boolean $require_construction_to_be_finalized most client code should leave this as TRUE |
|
457 | - * so that the inputs will be properly configured. |
|
458 | - * However, some client code may be ok |
|
459 | - * with construction finalize being called later |
|
460 | - * (realizing that the subsections' html names |
|
461 | - * might not be set yet, etc.) |
|
462 | - * @return EE_Form_Section_Base |
|
463 | - * @throws EE_Error |
|
464 | - */ |
|
465 | - public function get_subsection($name, $require_construction_to_be_finalized = true) |
|
466 | - { |
|
467 | - if ($require_construction_to_be_finalized) { |
|
468 | - $this->ensure_construct_finalized_called(); |
|
469 | - } |
|
470 | - return $this->subsection_exists($name) ? $this->_subsections[ $name ] : null; |
|
471 | - } |
|
472 | - |
|
473 | - |
|
474 | - /** |
|
475 | - * Gets all the validatable subsections of this form section |
|
476 | - * |
|
477 | - * @return EE_Form_Section_Validatable[] |
|
478 | - * @throws EE_Error |
|
479 | - */ |
|
480 | - public function get_validatable_subsections() |
|
481 | - { |
|
482 | - $validatable_subsections = array(); |
|
483 | - foreach ($this->subsections() as $name => $obj) { |
|
484 | - if ($obj instanceof EE_Form_Section_Validatable) { |
|
485 | - $validatable_subsections[ $name ] = $obj; |
|
486 | - } |
|
487 | - } |
|
488 | - return $validatable_subsections; |
|
489 | - } |
|
490 | - |
|
491 | - |
|
492 | - /** |
|
493 | - * Gets an input by the given name. If not found, or if its not an EE_FOrm_Input_Base child, |
|
494 | - * throw an EE_Error. |
|
495 | - * |
|
496 | - * @param string $name |
|
497 | - * @param boolean $require_construction_to_be_finalized most client code should |
|
498 | - * leave this as TRUE so that the inputs will be properly |
|
499 | - * configured. However, some client code may be ok with |
|
500 | - * construction finalize being called later |
|
501 | - * (realizing that the subsections' html names might not be |
|
502 | - * set yet, etc.) |
|
503 | - * @return EE_Form_Input_Base |
|
504 | - * @throws EE_Error |
|
505 | - */ |
|
506 | - public function get_input($name, $require_construction_to_be_finalized = true) |
|
507 | - { |
|
508 | - $subsection = $this->get_subsection( |
|
509 | - $name, |
|
510 | - $require_construction_to_be_finalized |
|
511 | - ); |
|
512 | - if (! $subsection instanceof EE_Form_Input_Base) { |
|
513 | - throw new EE_Error( |
|
514 | - sprintf( |
|
515 | - esc_html__( |
|
516 | - "Subsection '%s' is not an instanceof EE_Form_Input_Base on form '%s'. It is a '%s'", |
|
517 | - 'event_espresso' |
|
518 | - ), |
|
519 | - $name, |
|
520 | - get_class($this), |
|
521 | - $subsection ? get_class($subsection) : esc_html__('NULL', 'event_espresso') |
|
522 | - ) |
|
523 | - ); |
|
524 | - } |
|
525 | - return $subsection; |
|
526 | - } |
|
527 | - |
|
528 | - |
|
529 | - /** |
|
530 | - * Like get_input(), gets the proper subsection of the form given the name, |
|
531 | - * otherwise throws an EE_Error |
|
532 | - * |
|
533 | - * @param string $name |
|
534 | - * @param boolean $require_construction_to_be_finalized most client code should |
|
535 | - * leave this as TRUE so that the inputs will be properly |
|
536 | - * configured. However, some client code may be ok with |
|
537 | - * construction finalize being called later |
|
538 | - * (realizing that the subsections' html names might not be |
|
539 | - * set yet, etc.) |
|
540 | - * @return EE_Form_Section_Proper |
|
541 | - * @throws EE_Error |
|
542 | - */ |
|
543 | - public function get_proper_subsection($name, $require_construction_to_be_finalized = true) |
|
544 | - { |
|
545 | - $subsection = $this->get_subsection( |
|
546 | - $name, |
|
547 | - $require_construction_to_be_finalized |
|
548 | - ); |
|
549 | - if (! $subsection instanceof EE_Form_Section_Proper) { |
|
550 | - throw new EE_Error( |
|
551 | - sprintf( |
|
552 | - esc_html__( |
|
553 | - "Subsection '%'s is not an instanceof EE_Form_Section_Proper on form '%s'", |
|
554 | - 'event_espresso' |
|
555 | - ), |
|
556 | - $name, |
|
557 | - get_class($this) |
|
558 | - ) |
|
559 | - ); |
|
560 | - } |
|
561 | - return $subsection; |
|
562 | - } |
|
563 | - |
|
564 | - |
|
565 | - /** |
|
566 | - * Gets the value of the specified input. Should be called after receive_form_submission() |
|
567 | - * or populate_defaults() on the form, where the normalized value on the input is set. |
|
568 | - * |
|
569 | - * @param string $name |
|
570 | - * @return mixed depending on the input's type and its normalization strategy |
|
571 | - * @throws EE_Error |
|
572 | - */ |
|
573 | - public function get_input_value($name) |
|
574 | - { |
|
575 | - $input = $this->get_input($name); |
|
576 | - return $input->normalized_value(); |
|
577 | - } |
|
578 | - |
|
579 | - |
|
580 | - /** |
|
581 | - * Checks if this form section itself is valid, and then checks its subsections |
|
582 | - * |
|
583 | - * @throws EE_Error |
|
584 | - * @return boolean |
|
585 | - */ |
|
586 | - public function is_valid() |
|
587 | - { |
|
588 | - if($this->is_valid === null) { |
|
589 | - if (! $this->has_received_submission()) { |
|
590 | - throw new EE_Error( |
|
591 | - sprintf( |
|
592 | - esc_html__( |
|
593 | - 'You cannot check if a form is valid before receiving the form submission using receive_form_submission', |
|
594 | - 'event_espresso' |
|
595 | - ) |
|
596 | - ) |
|
597 | - ); |
|
598 | - } |
|
599 | - if (! parent::is_valid()) { |
|
600 | - $this->is_valid = false; |
|
601 | - } else { |
|
602 | - // ok so no general errors to this entire form section. |
|
603 | - // so let's check the subsections, but only set errors if that hasn't been done yet |
|
604 | - $this->is_valid = true; |
|
605 | - foreach ($this->get_validatable_subsections() as $subsection) { |
|
606 | - if (! $subsection->is_valid()) { |
|
607 | - $this->is_valid = false; |
|
608 | - } |
|
609 | - } |
|
610 | - } |
|
611 | - } |
|
612 | - return $this->is_valid; |
|
613 | - } |
|
614 | - |
|
615 | - |
|
616 | - /** |
|
617 | - * gets the default name of this form section if none is specified |
|
618 | - * |
|
619 | - * @return void |
|
620 | - */ |
|
621 | - protected function _set_default_name_if_empty() |
|
622 | - { |
|
623 | - if (! $this->_name) { |
|
624 | - $classname = get_class($this); |
|
625 | - $default_name = str_replace('EE_', '', $classname); |
|
626 | - $this->_name = $default_name; |
|
627 | - } |
|
628 | - } |
|
629 | - |
|
630 | - |
|
631 | - /** |
|
632 | - * Returns the HTML for the form, except for the form opening and closing tags |
|
633 | - * (as the form section doesn't know where you necessarily want to send the information to), |
|
634 | - * and except for a submit button. Enqueues JS and CSS; if called early enough we will |
|
635 | - * try to enqueue them in the header, otherwise they'll be enqueued in the footer. |
|
636 | - * Not doing_it_wrong because theoretically this CAN be used properly, |
|
637 | - * provided its used during "wp_enqueue_scripts", or it doesn't need to enqueue |
|
638 | - * any CSS. |
|
639 | - * |
|
640 | - * @throws InvalidArgumentException |
|
641 | - * @throws InvalidInterfaceException |
|
642 | - * @throws InvalidDataTypeException |
|
643 | - * @throws EE_Error |
|
644 | - */ |
|
645 | - public function get_html_and_js() |
|
646 | - { |
|
647 | - $this->enqueue_js(); |
|
648 | - return $this->get_html(); |
|
649 | - } |
|
650 | - |
|
651 | - |
|
652 | - /** |
|
653 | - * returns HTML for displaying this form section. recursively calls display_section() on all subsections |
|
654 | - * |
|
655 | - * @param bool $display_previously_submitted_data |
|
656 | - * @return string |
|
657 | - * @throws InvalidArgumentException |
|
658 | - * @throws InvalidInterfaceException |
|
659 | - * @throws InvalidDataTypeException |
|
660 | - * @throws EE_Error |
|
661 | - * @throws EE_Error |
|
662 | - * @throws EE_Error |
|
663 | - */ |
|
664 | - public function get_html($display_previously_submitted_data = true) |
|
665 | - { |
|
666 | - $this->ensure_construct_finalized_called(); |
|
667 | - if ($display_previously_submitted_data) { |
|
668 | - $this->populate_from_session(); |
|
669 | - } |
|
670 | - return $this->_form_html_filter |
|
671 | - ? $this->_form_html_filter->filterHtml($this->_layout_strategy->layout_form(), $this) |
|
672 | - : $this->_layout_strategy->layout_form(); |
|
673 | - } |
|
674 | - |
|
675 | - |
|
676 | - /** |
|
677 | - * enqueues JS and CSS for the form. |
|
678 | - * It is preferred to call this before wp_enqueue_scripts so the |
|
679 | - * scripts and styles can be put in the header, but if called later |
|
680 | - * they will be put in the footer (which is OK for JS, but in HTML4 CSS should |
|
681 | - * only be in the header; but in HTML5 its ok in the body. |
|
682 | - * See http://stackoverflow.com/questions/4957446/load-external-css-file-in-body-tag. |
|
683 | - * So if your form enqueues CSS, it's preferred to call this before wp_enqueue_scripts.) |
|
684 | - * |
|
685 | - * @return void |
|
686 | - * @throws EE_Error |
|
687 | - */ |
|
688 | - public function enqueue_js() |
|
689 | - { |
|
690 | - $this->_enqueue_and_localize_form_js(); |
|
691 | - foreach ($this->subsections() as $subsection) { |
|
692 | - $subsection->enqueue_js(); |
|
693 | - } |
|
694 | - } |
|
695 | - |
|
696 | - |
|
697 | - /** |
|
698 | - * adds a filter so that jquery validate gets enqueued in EE_System::wp_enqueue_scripts(). |
|
699 | - * This must be done BEFORE wp_enqueue_scripts() gets called, which is on |
|
700 | - * the wp_enqueue_scripts hook. |
|
701 | - * However, registering the form js and localizing it can happen when we |
|
702 | - * actually output the form (which is preferred, seeing how teh form's fields |
|
703 | - * could change until it's actually outputted) |
|
704 | - * |
|
705 | - * @param boolean $init_form_validation_automatically whether or not we want the form validation |
|
706 | - * to be triggered automatically or not |
|
707 | - * @return void |
|
708 | - */ |
|
709 | - public static function wp_enqueue_scripts($init_form_validation_automatically = true) |
|
710 | - { |
|
711 | - wp_register_script( |
|
712 | - 'ee_form_section_validation', |
|
713 | - EE_GLOBAL_ASSETS_URL . 'scripts' . DS . 'form_section_validation.js', |
|
714 | - array('jquery-validate', 'jquery-ui-datepicker', 'jquery-validate-extra-methods'), |
|
715 | - EVENT_ESPRESSO_VERSION, |
|
716 | - true |
|
717 | - ); |
|
718 | - wp_localize_script( |
|
719 | - 'ee_form_section_validation', |
|
720 | - 'ee_form_section_validation_init', |
|
721 | - array('init' => $init_form_validation_automatically ? '1' : '0') |
|
722 | - ); |
|
723 | - } |
|
724 | - |
|
725 | - |
|
726 | - /** |
|
727 | - * gets the variables used by form_section_validation.js. |
|
728 | - * This needs to be called AFTER we've called $this->_enqueue_jquery_validate_script, |
|
729 | - * but before the wordpress hook wp_loaded |
|
730 | - * |
|
731 | - * @throws EE_Error |
|
732 | - */ |
|
733 | - public function _enqueue_and_localize_form_js() |
|
734 | - { |
|
735 | - $this->ensure_construct_finalized_called(); |
|
736 | - //actually, we don't want to localize just yet. There may be other forms on the page. |
|
737 | - //so we need to add our form section data to a static variable accessible by all form sections |
|
738 | - //and localize it just before the footer |
|
739 | - $this->localize_validation_rules(); |
|
740 | - add_action('wp_footer', array('EE_Form_Section_Proper', 'localize_script_for_all_forms'), 2); |
|
741 | - add_action('admin_footer', array('EE_Form_Section_Proper', 'localize_script_for_all_forms')); |
|
742 | - } |
|
743 | - |
|
744 | - |
|
745 | - /** |
|
746 | - * add our form section data to a static variable accessible by all form sections |
|
747 | - * |
|
748 | - * @param bool $return_for_subsection |
|
749 | - * @return void |
|
750 | - * @throws EE_Error |
|
751 | - */ |
|
752 | - public function localize_validation_rules($return_for_subsection = false) |
|
753 | - { |
|
754 | - // we only want to localize vars ONCE for the entire form, |
|
755 | - // so if the form section doesn't have a parent, then it must be the top dog |
|
756 | - if ($return_for_subsection || ! $this->parent_section()) { |
|
757 | - EE_Form_Section_Proper::$_js_localization['form_data'][ $this->html_id() ] = array( |
|
758 | - 'form_section_id' => $this->html_id(true), |
|
759 | - 'validation_rules' => $this->get_jquery_validation_rules(), |
|
760 | - 'other_data' => $this->get_other_js_data(), |
|
761 | - 'errors' => $this->subsection_validation_errors_by_html_name(), |
|
762 | - ); |
|
763 | - EE_Form_Section_Proper::$_scripts_localized = true; |
|
764 | - } |
|
765 | - } |
|
766 | - |
|
767 | - |
|
768 | - /** |
|
769 | - * Gets an array of extra data that will be useful for client-side javascript. |
|
770 | - * This is primarily data added by inputs and forms in addition to any |
|
771 | - * scripts they might enqueue |
|
772 | - * |
|
773 | - * @param array $form_other_js_data |
|
774 | - * @return array |
|
775 | - * @throws EE_Error |
|
776 | - */ |
|
777 | - public function get_other_js_data($form_other_js_data = array()) |
|
778 | - { |
|
779 | - foreach ($this->subsections() as $subsection) { |
|
780 | - $form_other_js_data = $subsection->get_other_js_data($form_other_js_data); |
|
781 | - } |
|
782 | - return $form_other_js_data; |
|
783 | - } |
|
784 | - |
|
785 | - |
|
786 | - /** |
|
787 | - * Gets a flat array of inputs for this form section and its subsections. |
|
788 | - * Keys are their form names, and values are the inputs themselves |
|
789 | - * |
|
790 | - * @return EE_Form_Input_Base |
|
791 | - * @throws EE_Error |
|
792 | - */ |
|
793 | - public function inputs_in_subsections() |
|
794 | - { |
|
795 | - $inputs = array(); |
|
796 | - foreach ($this->subsections() as $subsection) { |
|
797 | - if ($subsection instanceof EE_Form_Input_Base) { |
|
798 | - $inputs[ $subsection->html_name() ] = $subsection; |
|
799 | - } elseif ($subsection instanceof EE_Form_Section_Proper) { |
|
800 | - $inputs += $subsection->inputs_in_subsections(); |
|
801 | - } |
|
802 | - } |
|
803 | - return $inputs; |
|
804 | - } |
|
805 | - |
|
806 | - |
|
807 | - /** |
|
808 | - * Gets a flat array of all the validation errors. |
|
809 | - * Keys are html names (because those should be unique) |
|
810 | - * and values are a string of all their validation errors |
|
811 | - * |
|
812 | - * @return string[] |
|
813 | - * @throws EE_Error |
|
814 | - */ |
|
815 | - public function subsection_validation_errors_by_html_name() |
|
816 | - { |
|
817 | - $inputs = $this->inputs(); |
|
818 | - $errors = array(); |
|
819 | - foreach ($inputs as $form_input) { |
|
820 | - if ($form_input instanceof EE_Form_Input_Base && $form_input->get_validation_errors()) { |
|
821 | - $errors[ $form_input->html_name() ] = $form_input->get_validation_error_string(); |
|
822 | - } |
|
823 | - } |
|
824 | - return $errors; |
|
825 | - } |
|
826 | - |
|
827 | - |
|
828 | - /** |
|
829 | - * passes all the form data required by the JS to the JS, and enqueues the few required JS files. |
|
830 | - * Should be setup by each form during the _enqueues_and_localize_form_js |
|
831 | - * |
|
832 | - * @throws InvalidArgumentException |
|
833 | - * @throws InvalidInterfaceException |
|
834 | - * @throws InvalidDataTypeException |
|
835 | - */ |
|
836 | - public static function localize_script_for_all_forms() |
|
837 | - { |
|
838 | - //allow inputs and stuff to hook in their JS and stuff here |
|
839 | - do_action('AHEE__EE_Form_Section_Proper__localize_script_for_all_forms__begin'); |
|
840 | - EE_Form_Section_Proper::$_js_localization['localized_error_messages'] = EE_Form_Section_Proper::_get_localized_error_messages(); |
|
841 | - $email_validation_level = isset(EE_Registry::instance()->CFG->registration->email_validation_level) |
|
842 | - ? EE_Registry::instance()->CFG->registration->email_validation_level |
|
843 | - : 'wp_default'; |
|
844 | - EE_Form_Section_Proper::$_js_localization['email_validation_level'] = $email_validation_level; |
|
845 | - wp_enqueue_script('ee_form_section_validation'); |
|
846 | - wp_localize_script( |
|
847 | - 'ee_form_section_validation', |
|
848 | - 'ee_form_section_vars', |
|
849 | - EE_Form_Section_Proper::$_js_localization |
|
850 | - ); |
|
851 | - } |
|
852 | - |
|
853 | - |
|
854 | - /** |
|
855 | - * ensure_scripts_localized |
|
856 | - * |
|
857 | - * @throws EE_Error |
|
858 | - */ |
|
859 | - public function ensure_scripts_localized() |
|
860 | - { |
|
861 | - if (! EE_Form_Section_Proper::$_scripts_localized) { |
|
862 | - $this->_enqueue_and_localize_form_js(); |
|
863 | - } |
|
864 | - } |
|
865 | - |
|
866 | - |
|
867 | - /** |
|
868 | - * Gets the hard-coded validation error messages to be used in the JS. The convention |
|
869 | - * is that the key here should be the same as the custom validation rule put in the JS file |
|
870 | - * |
|
871 | - * @return array keys are custom validation rules, and values are internationalized strings |
|
872 | - */ |
|
873 | - private static function _get_localized_error_messages() |
|
874 | - { |
|
875 | - return array( |
|
876 | - 'validUrl' => esc_html__('This is not a valid absolute URL. Eg, http://domain.com/monkey.jpg', 'event_espresso'), |
|
877 | - 'regex' => esc_html__('Please check your input', 'event_espresso'), |
|
878 | - ); |
|
879 | - } |
|
880 | - |
|
881 | - |
|
882 | - /** |
|
883 | - * @return array |
|
884 | - */ |
|
885 | - public static function js_localization() |
|
886 | - { |
|
887 | - return self::$_js_localization; |
|
888 | - } |
|
889 | - |
|
890 | - |
|
891 | - /** |
|
892 | - * @return void |
|
893 | - */ |
|
894 | - public static function reset_js_localization() |
|
895 | - { |
|
896 | - self::$_js_localization = array(); |
|
897 | - } |
|
898 | - |
|
899 | - |
|
900 | - /** |
|
901 | - * Gets the JS to put inside the jquery validation rules for subsection of this form section. |
|
902 | - * See parent function for more... |
|
903 | - * |
|
904 | - * @return array |
|
905 | - * @throws EE_Error |
|
906 | - */ |
|
907 | - public function get_jquery_validation_rules() |
|
908 | - { |
|
909 | - $jquery_validation_rules = array(); |
|
910 | - foreach ($this->get_validatable_subsections() as $subsection) { |
|
911 | - $jquery_validation_rules = array_merge( |
|
912 | - $jquery_validation_rules, |
|
913 | - $subsection->get_jquery_validation_rules() |
|
914 | - ); |
|
915 | - } |
|
916 | - return $jquery_validation_rules; |
|
917 | - } |
|
918 | - |
|
919 | - |
|
920 | - /** |
|
921 | - * Sanitizes all the data and sets the sanitized value of each field |
|
922 | - * |
|
923 | - * @param array $req_data like $_POST |
|
924 | - * @return void |
|
925 | - * @throws EE_Error |
|
926 | - */ |
|
927 | - protected function _normalize($req_data) |
|
928 | - { |
|
929 | - $this->_received_submission = true; |
|
930 | - $this->_validation_errors = array(); |
|
931 | - foreach ($this->get_validatable_subsections() as $subsection) { |
|
932 | - try { |
|
933 | - $subsection->_normalize($req_data); |
|
934 | - } catch (EE_Validation_Error $e) { |
|
935 | - $subsection->add_validation_error($e); |
|
936 | - } |
|
937 | - } |
|
938 | - } |
|
939 | - |
|
940 | - |
|
941 | - /** |
|
942 | - * Performs validation on this form section and its subsections. |
|
943 | - * For each subsection, |
|
944 | - * calls _validate_{subsection_name} on THIS form (if the function exists) |
|
945 | - * and passes it the subsection, then calls _validate on that subsection. |
|
946 | - * If you need to perform validation on the form as a whole (considering multiple) |
|
947 | - * you would be best to override this _validate method, |
|
948 | - * calling parent::_validate() first. |
|
949 | - * |
|
950 | - * @throws EE_Error |
|
951 | - */ |
|
952 | - protected function _validate() |
|
953 | - { |
|
954 | - //reset the cache of whether this form is valid or not- we're re-validating it now |
|
955 | - $this->is_valid = null; |
|
956 | - foreach ($this->get_validatable_subsections() as $subsection_name => $subsection) { |
|
957 | - if (method_exists($this, '_validate_' . $subsection_name)) { |
|
958 | - call_user_func_array(array($this, '_validate_' . $subsection_name), array($subsection)); |
|
959 | - } |
|
960 | - $subsection->_validate(); |
|
961 | - } |
|
962 | - } |
|
963 | - |
|
964 | - |
|
965 | - /** |
|
966 | - * Gets all the validated inputs for the form section |
|
967 | - * |
|
968 | - * @return array |
|
969 | - * @throws EE_Error |
|
970 | - */ |
|
971 | - public function valid_data() |
|
972 | - { |
|
973 | - $inputs = array(); |
|
974 | - foreach ($this->subsections() as $subsection_name => $subsection) { |
|
975 | - if ($subsection instanceof EE_Form_Section_Proper) { |
|
976 | - $inputs[ $subsection_name ] = $subsection->valid_data(); |
|
977 | - } elseif ($subsection instanceof EE_Form_Input_Base) { |
|
978 | - $inputs[ $subsection_name ] = $subsection->normalized_value(); |
|
979 | - } |
|
980 | - } |
|
981 | - return $inputs; |
|
982 | - } |
|
983 | - |
|
984 | - |
|
985 | - /** |
|
986 | - * Gets all the inputs on this form section |
|
987 | - * |
|
988 | - * @return EE_Form_Input_Base[] |
|
989 | - * @throws EE_Error |
|
990 | - */ |
|
991 | - public function inputs() |
|
992 | - { |
|
993 | - $inputs = array(); |
|
994 | - foreach ($this->subsections() as $subsection_name => $subsection) { |
|
995 | - if ($subsection instanceof EE_Form_Input_Base) { |
|
996 | - $inputs[ $subsection_name ] = $subsection; |
|
997 | - } |
|
998 | - } |
|
999 | - return $inputs; |
|
1000 | - } |
|
1001 | - |
|
1002 | - |
|
1003 | - /** |
|
1004 | - * Gets all the subsections which are a proper form |
|
1005 | - * |
|
1006 | - * @return EE_Form_Section_Proper[] |
|
1007 | - * @throws EE_Error |
|
1008 | - */ |
|
1009 | - public function subforms() |
|
1010 | - { |
|
1011 | - $form_sections = array(); |
|
1012 | - foreach ($this->subsections() as $name => $obj) { |
|
1013 | - if ($obj instanceof EE_Form_Section_Proper) { |
|
1014 | - $form_sections[ $name ] = $obj; |
|
1015 | - } |
|
1016 | - } |
|
1017 | - return $form_sections; |
|
1018 | - } |
|
1019 | - |
|
1020 | - |
|
1021 | - /** |
|
1022 | - * Gets all the subsections (inputs, proper subsections, or html-only sections). |
|
1023 | - * Consider using inputs() or subforms() |
|
1024 | - * if you only want form inputs or proper form sections. |
|
1025 | - * |
|
1026 | - * @param boolean $require_construction_to_be_finalized most client code should |
|
1027 | - * leave this as TRUE so that the inputs will be properly |
|
1028 | - * configured. However, some client code may be ok with |
|
1029 | - * construction finalize being called later |
|
1030 | - * (realizing that the subsections' html names might not be |
|
1031 | - * set yet, etc.) |
|
1032 | - * @return EE_Form_Section_Proper[] |
|
1033 | - * @throws EE_Error |
|
1034 | - */ |
|
1035 | - public function subsections($require_construction_to_be_finalized = true) |
|
1036 | - { |
|
1037 | - if ($require_construction_to_be_finalized) { |
|
1038 | - $this->ensure_construct_finalized_called(); |
|
1039 | - } |
|
1040 | - return $this->_subsections; |
|
1041 | - } |
|
1042 | - |
|
1043 | - |
|
1044 | - /** |
|
1045 | - * Returns whether this form has any subforms or inputs |
|
1046 | - * @return bool |
|
1047 | - */ |
|
1048 | - public function hasSubsections() |
|
1049 | - { |
|
1050 | - return ! empty($this->_subsections); |
|
1051 | - } |
|
1052 | - |
|
1053 | - |
|
1054 | - /** |
|
1055 | - * Returns a simple array where keys are input names, and values are their normalized |
|
1056 | - * values. (Similar to calling get_input_value on inputs) |
|
1057 | - * |
|
1058 | - * @param boolean $include_subform_inputs Whether to include inputs from subforms, |
|
1059 | - * or just this forms' direct children inputs |
|
1060 | - * @param boolean $flatten Whether to force the results into 1-dimensional array, |
|
1061 | - * or allow multidimensional array |
|
1062 | - * @return array if $flatten is TRUE it will always be a 1-dimensional array |
|
1063 | - * with array keys being input names |
|
1064 | - * (regardless of whether they are from a subsection or not), |
|
1065 | - * and if $flatten is FALSE it can be a multidimensional array |
|
1066 | - * where keys are always subsection names and values are either |
|
1067 | - * the input's normalized value, or an array like the top-level array |
|
1068 | - * @throws EE_Error |
|
1069 | - */ |
|
1070 | - public function input_values($include_subform_inputs = false, $flatten = false) |
|
1071 | - { |
|
1072 | - return $this->_input_values(false, $include_subform_inputs, $flatten); |
|
1073 | - } |
|
1074 | - |
|
1075 | - |
|
1076 | - /** |
|
1077 | - * Similar to EE_Form_Section_Proper::input_values(), except this returns the 'display_value' |
|
1078 | - * of each input. On some inputs (especially radio boxes or checkboxes), the value stored |
|
1079 | - * is not necessarily the value we want to display to users. This creates an array |
|
1080 | - * where keys are the input names, and values are their display values |
|
1081 | - * |
|
1082 | - * @param boolean $include_subform_inputs Whether to include inputs from subforms, |
|
1083 | - * or just this forms' direct children inputs |
|
1084 | - * @param boolean $flatten Whether to force the results into 1-dimensional array, |
|
1085 | - * or allow multidimensional array |
|
1086 | - * @return array if $flatten is TRUE it will always be a 1-dimensional array |
|
1087 | - * with array keys being input names |
|
1088 | - * (regardless of whether they are from a subsection or not), |
|
1089 | - * and if $flatten is FALSE it can be a multidimensional array |
|
1090 | - * where keys are always subsection names and values are either |
|
1091 | - * the input's normalized value, or an array like the top-level array |
|
1092 | - * @throws EE_Error |
|
1093 | - */ |
|
1094 | - public function input_pretty_values($include_subform_inputs = false, $flatten = false) |
|
1095 | - { |
|
1096 | - return $this->_input_values(true, $include_subform_inputs, $flatten); |
|
1097 | - } |
|
1098 | - |
|
1099 | - |
|
1100 | - /** |
|
1101 | - * Gets the input values from the form |
|
1102 | - * |
|
1103 | - * @param boolean $pretty Whether to retrieve the pretty value, |
|
1104 | - * or just the normalized value |
|
1105 | - * @param boolean $include_subform_inputs Whether to include inputs from subforms, |
|
1106 | - * or just this forms' direct children inputs |
|
1107 | - * @param boolean $flatten Whether to force the results into 1-dimensional array, |
|
1108 | - * or allow multidimensional array |
|
1109 | - * @return array if $flatten is TRUE it will always be a 1-dimensional array with array keys being |
|
1110 | - * input names (regardless of whether they are from a subsection or not), |
|
1111 | - * and if $flatten is FALSE it can be a multidimensional array |
|
1112 | - * where keys are always subsection names and values are either |
|
1113 | - * the input's normalized value, or an array like the top-level array |
|
1114 | - * @throws EE_Error |
|
1115 | - */ |
|
1116 | - public function _input_values($pretty = false, $include_subform_inputs = false, $flatten = false) |
|
1117 | - { |
|
1118 | - $input_values = array(); |
|
1119 | - foreach ($this->subsections() as $subsection_name => $subsection) { |
|
1120 | - if ($subsection instanceof EE_Form_Input_Base) { |
|
1121 | - $input_values[ $subsection_name ] = $pretty |
|
1122 | - ? $subsection->pretty_value() |
|
1123 | - : $subsection->normalized_value(); |
|
1124 | - } elseif ($subsection instanceof EE_Form_Section_Proper && $include_subform_inputs) { |
|
1125 | - $subform_input_values = $subsection->_input_values( |
|
1126 | - $pretty, |
|
1127 | - $include_subform_inputs, |
|
1128 | - $flatten |
|
1129 | - ); |
|
1130 | - if ($flatten) { |
|
1131 | - $input_values = array_merge($input_values, $subform_input_values); |
|
1132 | - } else { |
|
1133 | - $input_values[ $subsection_name ] = $subform_input_values; |
|
1134 | - } |
|
1135 | - } |
|
1136 | - } |
|
1137 | - return $input_values; |
|
1138 | - } |
|
1139 | - |
|
1140 | - |
|
1141 | - /** |
|
1142 | - * Gets the originally submitted input values from the form |
|
1143 | - * |
|
1144 | - * @param boolean $include_subforms Whether to include inputs from subforms, |
|
1145 | - * or just this forms' direct children inputs |
|
1146 | - * @return array if $flatten is TRUE it will always be a 1-dimensional array |
|
1147 | - * with array keys being input names |
|
1148 | - * (regardless of whether they are from a subsection or not), |
|
1149 | - * and if $flatten is FALSE it can be a multidimensional array |
|
1150 | - * where keys are always subsection names and values are either |
|
1151 | - * the input's normalized value, or an array like the top-level array |
|
1152 | - * @throws EE_Error |
|
1153 | - */ |
|
1154 | - public function submitted_values($include_subforms = false) |
|
1155 | - { |
|
1156 | - $submitted_values = array(); |
|
1157 | - foreach ($this->subsections() as $subsection) { |
|
1158 | - if ($subsection instanceof EE_Form_Input_Base) { |
|
1159 | - // is this input part of an array of inputs? |
|
1160 | - if (strpos($subsection->html_name(), '[') !== false) { |
|
1161 | - $full_input_name = EEH_Array::convert_array_values_to_keys( |
|
1162 | - explode( |
|
1163 | - '[', |
|
1164 | - str_replace(']', '', $subsection->html_name()) |
|
1165 | - ), |
|
1166 | - $subsection->raw_value() |
|
1167 | - ); |
|
1168 | - $submitted_values = array_replace_recursive($submitted_values, $full_input_name); |
|
1169 | - } else { |
|
1170 | - $submitted_values[ $subsection->html_name() ] = $subsection->raw_value(); |
|
1171 | - } |
|
1172 | - } elseif ($subsection instanceof EE_Form_Section_Proper && $include_subforms) { |
|
1173 | - $subform_input_values = $subsection->submitted_values($include_subforms); |
|
1174 | - $submitted_values = array_replace_recursive($submitted_values, $subform_input_values); |
|
1175 | - } |
|
1176 | - } |
|
1177 | - return $submitted_values; |
|
1178 | - } |
|
1179 | - |
|
1180 | - |
|
1181 | - /** |
|
1182 | - * Indicates whether or not this form has received a submission yet |
|
1183 | - * (ie, had receive_form_submission called on it yet) |
|
1184 | - * |
|
1185 | - * @return boolean |
|
1186 | - * @throws EE_Error |
|
1187 | - */ |
|
1188 | - public function has_received_submission() |
|
1189 | - { |
|
1190 | - $this->ensure_construct_finalized_called(); |
|
1191 | - return $this->_received_submission; |
|
1192 | - } |
|
1193 | - |
|
1194 | - |
|
1195 | - /** |
|
1196 | - * Equivalent to passing 'exclude' in the constructor's options array. |
|
1197 | - * Removes the listed inputs from the form |
|
1198 | - * |
|
1199 | - * @param array $inputs_to_exclude values are the input names |
|
1200 | - * @return void |
|
1201 | - */ |
|
1202 | - public function exclude(array $inputs_to_exclude = array()) |
|
1203 | - { |
|
1204 | - foreach ($inputs_to_exclude as $input_to_exclude_name) { |
|
1205 | - unset($this->_subsections[ $input_to_exclude_name ]); |
|
1206 | - } |
|
1207 | - } |
|
1208 | - |
|
1209 | - |
|
1210 | - /** |
|
1211 | - * Changes these inputs' display strategy to be EE_Hidden_Display_Strategy. |
|
1212 | - * @param array $inputs_to_hide |
|
1213 | - * @throws EE_Error |
|
1214 | - */ |
|
1215 | - public function hide(array $inputs_to_hide = array()) |
|
1216 | - { |
|
1217 | - foreach ($inputs_to_hide as $input_to_hide) { |
|
1218 | - $input = $this->get_input($input_to_hide); |
|
1219 | - $input->set_display_strategy(new EE_Hidden_Display_Strategy()); |
|
1220 | - } |
|
1221 | - } |
|
1222 | - |
|
1223 | - |
|
1224 | - /** |
|
1225 | - * add_subsections |
|
1226 | - * Adds the listed subsections to the form section. |
|
1227 | - * If $subsection_name_to_target is provided, |
|
1228 | - * then new subsections are added before or after that subsection, |
|
1229 | - * otherwise to the start or end of the entire subsections array. |
|
1230 | - * |
|
1231 | - * @param EE_Form_Section_Base[] $new_subsections array of new form subsections |
|
1232 | - * where keys are their names |
|
1233 | - * @param string $subsection_name_to_target an existing for section that $new_subsections |
|
1234 | - * should be added before or after |
|
1235 | - * IF $subsection_name_to_target is null, |
|
1236 | - * then $new_subsections will be added to |
|
1237 | - * the beginning or end of the entire subsections array |
|
1238 | - * @param boolean $add_before whether to add $new_subsections, before or after |
|
1239 | - * $subsection_name_to_target, |
|
1240 | - * or if $subsection_name_to_target is null, |
|
1241 | - * before or after entire subsections array |
|
1242 | - * @return void |
|
1243 | - * @throws EE_Error |
|
1244 | - */ |
|
1245 | - public function add_subsections($new_subsections, $subsection_name_to_target = null, $add_before = true) |
|
1246 | - { |
|
1247 | - foreach ($new_subsections as $subsection_name => $subsection) { |
|
1248 | - if (! $subsection instanceof EE_Form_Section_Base) { |
|
1249 | - EE_Error::add_error( |
|
1250 | - sprintf( |
|
1251 | - esc_html__( |
|
1252 | - "Trying to add a %s as a subsection (it was named '%s') to the form section '%s'. It was removed.", |
|
1253 | - 'event_espresso' |
|
1254 | - ), |
|
1255 | - get_class($subsection), |
|
1256 | - $subsection_name, |
|
1257 | - $this->name() |
|
1258 | - ) |
|
1259 | - ); |
|
1260 | - unset($new_subsections[ $subsection_name ]); |
|
1261 | - } |
|
1262 | - } |
|
1263 | - $this->_subsections = EEH_Array::insert_into_array( |
|
1264 | - $this->_subsections, |
|
1265 | - $new_subsections, |
|
1266 | - $subsection_name_to_target, |
|
1267 | - $add_before |
|
1268 | - ); |
|
1269 | - if ($this->_construction_finalized) { |
|
1270 | - foreach ($this->_subsections as $name => $subsection) { |
|
1271 | - $subsection->_construct_finalize($this, $name); |
|
1272 | - } |
|
1273 | - } |
|
1274 | - } |
|
1275 | - |
|
1276 | - |
|
1277 | - /** |
|
1278 | - * @param string $subsection_name |
|
1279 | - * @param bool $recursive |
|
1280 | - * @return bool |
|
1281 | - */ |
|
1282 | - public function has_subsection($subsection_name, $recursive = false) |
|
1283 | - { |
|
1284 | - foreach ($this->_subsections as $name => $subsection) {if( |
|
1285 | - $name === $subsection_name |
|
1286 | - || ( |
|
1287 | - $recursive |
|
1288 | - && $subsection instanceof EE_Form_Section_Proper |
|
1289 | - && $subsection->has_subsection($subsection_name, $recursive) |
|
1290 | - ) |
|
1291 | - ) { |
|
1292 | - return true; |
|
1293 | - } |
|
1294 | - } |
|
1295 | - return false; |
|
1296 | - } |
|
1297 | - |
|
1298 | - |
|
1299 | - |
|
1300 | - /** |
|
1301 | - * Just gets all validatable subsections to clean their sensitive data |
|
1302 | - * |
|
1303 | - * @throws EE_Error |
|
1304 | - */ |
|
1305 | - public function clean_sensitive_data() |
|
1306 | - { |
|
1307 | - foreach ($this->get_validatable_subsections() as $subsection) { |
|
1308 | - $subsection->clean_sensitive_data(); |
|
1309 | - } |
|
1310 | - } |
|
1311 | - |
|
1312 | - |
|
1313 | - /** |
|
1314 | - * Sets the submission error message (aka validation error message for this form section and all sub-sections) |
|
1315 | - * @param string $form_submission_error_message |
|
1316 | - * @param EE_Form_Section_Validatable $form_section unused |
|
1317 | - * @throws EE_Error |
|
1318 | - */ |
|
1319 | - public function set_submission_error_message( |
|
1320 | - $form_submission_error_message = '' |
|
1321 | - ) { |
|
1322 | - $this->_form_submission_error_message = ! empty($form_submission_error_message) |
|
1323 | - ? $form_submission_error_message |
|
1324 | - : $this->getAllValidationErrorsString(); |
|
1325 | - } |
|
1326 | - |
|
1327 | - |
|
1328 | - /** |
|
1329 | - * Returns the cached error message. A default value is set for this during _validate(), |
|
1330 | - * (called during receive_form_submission) but it can be explicitly set using |
|
1331 | - * set_submission_error_message |
|
1332 | - * |
|
1333 | - * @return string |
|
1334 | - */ |
|
1335 | - public function submission_error_message() |
|
1336 | - { |
|
1337 | - return $this->_form_submission_error_message; |
|
1338 | - } |
|
1339 | - |
|
1340 | - |
|
1341 | - /** |
|
1342 | - * Sets a message to display if the data submitted to the form was valid. |
|
1343 | - * @param string $form_submission_success_message |
|
1344 | - */ |
|
1345 | - public function set_submission_success_message($form_submission_success_message = '') |
|
1346 | - { |
|
1347 | - $this->_form_submission_success_message = ! empty($form_submission_success_message) |
|
1348 | - ? $form_submission_success_message |
|
1349 | - : esc_html__('Form submitted successfully', 'event_espresso'); |
|
1350 | - } |
|
1351 | - |
|
1352 | - |
|
1353 | - /** |
|
1354 | - * Gets a message appropriate for display when the form is correctly submitted |
|
1355 | - * @return string |
|
1356 | - */ |
|
1357 | - public function submission_success_message() |
|
1358 | - { |
|
1359 | - return $this->_form_submission_success_message; |
|
1360 | - } |
|
1361 | - |
|
1362 | - |
|
1363 | - /** |
|
1364 | - * Returns the prefix that should be used on child of this form section for |
|
1365 | - * their html names. If this form section itself has a parent, prepends ITS |
|
1366 | - * prefix onto this form section's prefix. Used primarily by |
|
1367 | - * EE_Form_Input_Base::_set_default_html_name_if_empty |
|
1368 | - * |
|
1369 | - * @return string |
|
1370 | - * @throws EE_Error |
|
1371 | - */ |
|
1372 | - public function html_name_prefix() |
|
1373 | - { |
|
1374 | - if ($this->parent_section() instanceof EE_Form_Section_Proper) { |
|
1375 | - return $this->parent_section()->html_name_prefix() . '[' . $this->name() . ']'; |
|
1376 | - } |
|
1377 | - return $this->name(); |
|
1378 | - } |
|
1379 | - |
|
1380 | - |
|
1381 | - /** |
|
1382 | - * Gets the name, but first checks _construct_finalize has been called. If not, |
|
1383 | - * calls it (assumes there is no parent and that we want the name to be whatever |
|
1384 | - * was set, which is probably nothing, or the classname) |
|
1385 | - * |
|
1386 | - * @return string |
|
1387 | - * @throws EE_Error |
|
1388 | - */ |
|
1389 | - public function name() |
|
1390 | - { |
|
1391 | - $this->ensure_construct_finalized_called(); |
|
1392 | - return parent::name(); |
|
1393 | - } |
|
1394 | - |
|
1395 | - |
|
1396 | - /** |
|
1397 | - * @return EE_Form_Section_Proper |
|
1398 | - * @throws EE_Error |
|
1399 | - */ |
|
1400 | - public function parent_section() |
|
1401 | - { |
|
1402 | - $this->ensure_construct_finalized_called(); |
|
1403 | - return parent::parent_section(); |
|
1404 | - } |
|
1405 | - |
|
1406 | - |
|
1407 | - /** |
|
1408 | - * make sure construction finalized was called, otherwise children might not be ready |
|
1409 | - * |
|
1410 | - * @return void |
|
1411 | - * @throws EE_Error |
|
1412 | - */ |
|
1413 | - public function ensure_construct_finalized_called() |
|
1414 | - { |
|
1415 | - if (! $this->_construction_finalized) { |
|
1416 | - $this->_construct_finalize($this->_parent_section, $this->_name); |
|
1417 | - } |
|
1418 | - } |
|
1419 | - |
|
1420 | - |
|
1421 | - /** |
|
1422 | - * Checks if any of this form section's inputs, or any of its children's inputs, |
|
1423 | - * are in teh form data. If any are found, returns true. Else false |
|
1424 | - * |
|
1425 | - * @param array $req_data |
|
1426 | - * @return boolean |
|
1427 | - * @throws EE_Error |
|
1428 | - */ |
|
1429 | - public function form_data_present_in($req_data = null) |
|
1430 | - { |
|
1431 | - $req_data = $this->getCachedRequest($req_data); |
|
1432 | - foreach ($this->subsections() as $subsection) { |
|
1433 | - if ($subsection instanceof EE_Form_Input_Base) { |
|
1434 | - if ($subsection->form_data_present_in($req_data)) { |
|
1435 | - return true; |
|
1436 | - } |
|
1437 | - } elseif ($subsection instanceof EE_Form_Section_Proper) { |
|
1438 | - if ($subsection->form_data_present_in($req_data)) { |
|
1439 | - return true; |
|
1440 | - } |
|
1441 | - } |
|
1442 | - } |
|
1443 | - return false; |
|
1444 | - } |
|
1445 | - |
|
1446 | - |
|
1447 | - /** |
|
1448 | - * Gets validation errors for this form section and subsections |
|
1449 | - * Similar to EE_Form_Section_Validatable::get_validation_errors() except this |
|
1450 | - * gets the validation errors for ALL subsection |
|
1451 | - * |
|
1452 | - * @return EE_Validation_Error[] |
|
1453 | - * @throws EE_Error |
|
1454 | - */ |
|
1455 | - public function get_validation_errors_accumulated() |
|
1456 | - { |
|
1457 | - $validation_errors = $this->get_validation_errors(); |
|
1458 | - foreach ($this->get_validatable_subsections() as $subsection) { |
|
1459 | - if ($subsection instanceof EE_Form_Section_Proper) { |
|
1460 | - $validation_errors_on_this_subsection = $subsection->get_validation_errors_accumulated(); |
|
1461 | - } else { |
|
1462 | - $validation_errors_on_this_subsection = $subsection->get_validation_errors(); |
|
1463 | - } |
|
1464 | - if ($validation_errors_on_this_subsection) { |
|
1465 | - $validation_errors = array_merge($validation_errors, $validation_errors_on_this_subsection); |
|
1466 | - } |
|
1467 | - } |
|
1468 | - return $validation_errors; |
|
1469 | - } |
|
1470 | - |
|
1471 | - /** |
|
1472 | - * Fetch validation errors from children and grandchildren and puts them in a single string. |
|
1473 | - * This traverses the form section tree to generate this, but you probably want to instead use |
|
1474 | - * get_form_submission_error_message() which is usually this message cached (or a custom validation error message) |
|
1475 | - * |
|
1476 | - * @return string |
|
1477 | - * @since $VID:$ |
|
1478 | - */ |
|
1479 | - protected function getAllValidationErrorsString() |
|
1480 | - { |
|
1481 | - $submission_error_messages = array(); |
|
1482 | - // bad, bad, bad registrant |
|
1483 | - foreach ($this->get_validation_errors_accumulated() as $validation_error) { |
|
1484 | - if ($validation_error instanceof EE_Validation_Error) { |
|
1485 | - $form_section = $validation_error->get_form_section(); |
|
1486 | - if ($form_section instanceof EE_Form_Input_Base) { |
|
1487 | - $label = $validation_error->get_form_section()->html_label_text(); |
|
1488 | - } elseif($form_section instanceof EE_Form_Section_Validatable) { |
|
1489 | - $label = $validation_error->get_form_section()->name(); |
|
1490 | - } else { |
|
1491 | - $label = esc_html__('Unknown', 'event_espresso'); |
|
1492 | - } |
|
1493 | - $submission_error_messages[] = sprintf( |
|
1494 | - __('%s : %s', 'event_espresso'), |
|
1495 | - $label, |
|
1496 | - $validation_error->getMessage() |
|
1497 | - ); |
|
1498 | - } |
|
1499 | - } |
|
1500 | - return implode('<br', $submission_error_messages); |
|
1501 | - } |
|
1502 | - |
|
1503 | - |
|
1504 | - /** |
|
1505 | - * This isn't just the name of an input, it's a path pointing to an input. The |
|
1506 | - * path is similar to a folder path: slash (/) means to descend into a subsection, |
|
1507 | - * dot-dot-slash (../) means to ascend into the parent section. |
|
1508 | - * After a series of slashes and dot-dot-slashes, there should be the name of an input, |
|
1509 | - * which will be returned. |
|
1510 | - * Eg, if you want the related input to be conditional on a sibling input name 'foobar' |
|
1511 | - * just use 'foobar'. If you want it to be conditional on an aunt/uncle input name |
|
1512 | - * 'baz', use '../baz'. If you want it to be conditional on a cousin input, |
|
1513 | - * the child of 'baz_section' named 'baz_child', use '../baz_section/baz_child'. |
|
1514 | - * Etc |
|
1515 | - * |
|
1516 | - * @param string|false $form_section_path we accept false also because substr( '../', '../' ) = false |
|
1517 | - * @return EE_Form_Section_Base |
|
1518 | - * @throws EE_Error |
|
1519 | - */ |
|
1520 | - public function find_section_from_path($form_section_path) |
|
1521 | - { |
|
1522 | - //check if we can find the input from purely going straight up the tree |
|
1523 | - $input = parent::find_section_from_path($form_section_path); |
|
1524 | - if ($input instanceof EE_Form_Section_Base) { |
|
1525 | - return $input; |
|
1526 | - } |
|
1527 | - $next_slash_pos = strpos($form_section_path, '/'); |
|
1528 | - if ($next_slash_pos !== false) { |
|
1529 | - $child_section_name = substr($form_section_path, 0, $next_slash_pos); |
|
1530 | - $subpath = substr($form_section_path, $next_slash_pos + 1); |
|
1531 | - } else { |
|
1532 | - $child_section_name = $form_section_path; |
|
1533 | - $subpath = ''; |
|
1534 | - } |
|
1535 | - $child_section = $this->get_subsection($child_section_name); |
|
1536 | - if ($child_section instanceof EE_Form_Section_Base) { |
|
1537 | - return $child_section->find_section_from_path($subpath); |
|
1538 | - } |
|
1539 | - return null; |
|
1540 | - } |
|
17 | + const SUBMITTED_FORM_DATA_SSN_KEY = 'submitted_form_data'; |
|
18 | + |
|
19 | + /** |
|
20 | + * Subsections |
|
21 | + * |
|
22 | + * @var EE_Form_Section_Validatable[] |
|
23 | + */ |
|
24 | + protected $_subsections = array(); |
|
25 | + |
|
26 | + /** |
|
27 | + * Strategy for laying out the form |
|
28 | + * |
|
29 | + * @var EE_Form_Section_Layout_Base |
|
30 | + */ |
|
31 | + protected $_layout_strategy; |
|
32 | + |
|
33 | + /** |
|
34 | + * Whether or not this form has received and validated a form submission yet |
|
35 | + * |
|
36 | + * @var boolean |
|
37 | + */ |
|
38 | + protected $_received_submission = false; |
|
39 | + |
|
40 | + /** |
|
41 | + * message displayed to users upon successful form submission |
|
42 | + * |
|
43 | + * @var string |
|
44 | + */ |
|
45 | + protected $_form_submission_success_message = ''; |
|
46 | + |
|
47 | + /** |
|
48 | + * message displayed to users upon unsuccessful form submission |
|
49 | + * |
|
50 | + * @var string |
|
51 | + */ |
|
52 | + protected $_form_submission_error_message = ''; |
|
53 | + |
|
54 | + /** |
|
55 | + * @var array like $_REQUEST |
|
56 | + */ |
|
57 | + protected $cached_request_data; |
|
58 | + |
|
59 | + /** |
|
60 | + * Stores whether this form (and its sub-sections) were found to be valid or not. |
|
61 | + * Starts off as null, but once the form is validated, it set to either true or false |
|
62 | + * @var boolean|null |
|
63 | + */ |
|
64 | + protected $is_valid; |
|
65 | + |
|
66 | + /** |
|
67 | + * Stores all the data that will localized for form validation |
|
68 | + * |
|
69 | + * @var array |
|
70 | + */ |
|
71 | + static protected $_js_localization = array(); |
|
72 | + |
|
73 | + /** |
|
74 | + * whether or not the form's localized validation JS vars have been set |
|
75 | + * |
|
76 | + * @type boolean |
|
77 | + */ |
|
78 | + static protected $_scripts_localized = false; |
|
79 | + |
|
80 | + |
|
81 | + /** |
|
82 | + * when constructing a proper form section, calls _construct_finalize on children |
|
83 | + * so that they know who their parent is, and what name they've been given. |
|
84 | + * |
|
85 | + * @param array[] $options_array { |
|
86 | + * @type $subsections EE_Form_Section_Validatable[] where keys are the section's name |
|
87 | + * @type $include string[] numerically-indexed where values are section names to be included, |
|
88 | + * and in that order. This is handy if you want |
|
89 | + * the subsections to be ordered differently than the default, and if you override |
|
90 | + * which fields are shown |
|
91 | + * @type $exclude string[] values are subsections to be excluded. This is handy if you want |
|
92 | + * to remove certain default subsections (note: if you specify BOTH 'include' AND |
|
93 | + * 'exclude', the inclusions will be applied first, and the exclusions will exclude |
|
94 | + * items from that list of inclusions) |
|
95 | + * @type $layout_strategy EE_Form_Section_Layout_Base strategy for laying out the form |
|
96 | + * } @see EE_Form_Section_Validatable::__construct() |
|
97 | + * @throws EE_Error |
|
98 | + */ |
|
99 | + public function __construct($options_array = array()) |
|
100 | + { |
|
101 | + $options_array = (array) apply_filters( |
|
102 | + 'FHEE__EE_Form_Section_Proper___construct__options_array', |
|
103 | + $options_array, |
|
104 | + $this |
|
105 | + ); |
|
106 | + //call parent first, as it may be setting the name |
|
107 | + parent::__construct($options_array); |
|
108 | + //if they've included subsections in the constructor, add them now |
|
109 | + if (isset($options_array['include'])) { |
|
110 | + //we are going to make sure we ONLY have those subsections to include |
|
111 | + //AND we are going to make sure they're in that specified order |
|
112 | + $reordered_subsections = array(); |
|
113 | + foreach ($options_array['include'] as $input_name) { |
|
114 | + if (isset($this->_subsections[ $input_name ])) { |
|
115 | + $reordered_subsections[ $input_name ] = $this->_subsections[ $input_name ]; |
|
116 | + } |
|
117 | + } |
|
118 | + $this->_subsections = $reordered_subsections; |
|
119 | + } |
|
120 | + if (isset($options_array['exclude'])) { |
|
121 | + $exclude = $options_array['exclude']; |
|
122 | + $this->_subsections = array_diff_key($this->_subsections, array_flip($exclude)); |
|
123 | + } |
|
124 | + if (isset($options_array['layout_strategy'])) { |
|
125 | + $this->_layout_strategy = $options_array['layout_strategy']; |
|
126 | + } |
|
127 | + if (! $this->_layout_strategy) { |
|
128 | + $this->_layout_strategy = is_admin() ? new EE_Admin_Two_Column_Layout() : new EE_Two_Column_Layout(); |
|
129 | + } |
|
130 | + $this->_layout_strategy->_construct_finalize($this); |
|
131 | + //ok so we are definitely going to want the forms JS, |
|
132 | + //so enqueue it or remember to enqueue it during wp_enqueue_scripts |
|
133 | + if (did_action('wp_enqueue_scripts') || did_action('admin_enqueue_scripts')) { |
|
134 | + //ok so they've constructed this object after when they should have. |
|
135 | + //just enqueue the generic form scripts and initialize the form immediately in the JS |
|
136 | + EE_Form_Section_Proper::wp_enqueue_scripts(true); |
|
137 | + } else { |
|
138 | + add_action('wp_enqueue_scripts', array('EE_Form_Section_Proper', 'wp_enqueue_scripts')); |
|
139 | + add_action('admin_enqueue_scripts', array('EE_Form_Section_Proper', 'wp_enqueue_scripts')); |
|
140 | + } |
|
141 | + add_action('wp_footer', array($this, 'ensure_scripts_localized'), 1); |
|
142 | + /** |
|
143 | + * Gives other plugins a chance to hook in before construct finalize is called. |
|
144 | + * The form probably doesn't yet have a parent form section. |
|
145 | + * Since 4.9.32, when this action was introduced, this is the best place to add a subsection onto a form, |
|
146 | + * assuming you don't care what the form section's name, HTML ID, or HTML name etc are. |
|
147 | + * Also see AHEE__EE_Form_Section_Proper___construct_finalize__end |
|
148 | + * |
|
149 | + * @since 4.9.32 |
|
150 | + * @param EE_Form_Section_Proper $this before __construct is done, but all of its logic, |
|
151 | + * except maybe calling _construct_finalize has been done |
|
152 | + * @param array $options_array options passed into the constructor |
|
153 | + */ |
|
154 | + do_action( |
|
155 | + 'AHEE__EE_Form_Input_Base___construct__before_construct_finalize_called', |
|
156 | + $this, |
|
157 | + $options_array |
|
158 | + ); |
|
159 | + if (isset($options_array['name'])) { |
|
160 | + $this->_construct_finalize(null, $options_array['name']); |
|
161 | + } |
|
162 | + } |
|
163 | + |
|
164 | + |
|
165 | + /** |
|
166 | + * Finishes construction given the parent form section and this form section's name |
|
167 | + * |
|
168 | + * @param EE_Form_Section_Proper $parent_form_section |
|
169 | + * @param string $name |
|
170 | + * @throws EE_Error |
|
171 | + */ |
|
172 | + public function _construct_finalize($parent_form_section, $name) |
|
173 | + { |
|
174 | + parent::_construct_finalize($parent_form_section, $name); |
|
175 | + $this->_set_default_name_if_empty(); |
|
176 | + $this->_set_default_html_id_if_empty(); |
|
177 | + foreach ($this->_subsections as $subsection_name => $subsection) { |
|
178 | + if ($subsection instanceof EE_Form_Section_Base) { |
|
179 | + $subsection->_construct_finalize($this, $subsection_name); |
|
180 | + } else { |
|
181 | + throw new EE_Error( |
|
182 | + sprintf( |
|
183 | + esc_html__( |
|
184 | + 'Subsection "%s" is not an instanceof EE_Form_Section_Base on form "%s". It is a "%s"', |
|
185 | + 'event_espresso' |
|
186 | + ), |
|
187 | + $subsection_name, |
|
188 | + get_class($this), |
|
189 | + $subsection ? get_class($subsection) : esc_html__('NULL', 'event_espresso') |
|
190 | + ) |
|
191 | + ); |
|
192 | + } |
|
193 | + } |
|
194 | + /** |
|
195 | + * Action performed just after form has been given a name (and HTML ID etc) and is fully constructed. |
|
196 | + * If you have code that should modify the form and needs it and its subsections to have a name, HTML ID |
|
197 | + * (or other attributes derived from the name like the HTML label id, etc), this is where it should be done. |
|
198 | + * This might only happen just before displaying the form, or just before it receives form submission data. |
|
199 | + * If you need to modify the form or its subsections before _construct_finalize is called on it (and we've |
|
200 | + * ensured it has a name, HTML IDs, etc |
|
201 | + * |
|
202 | + * @param EE_Form_Section_Proper $this |
|
203 | + * @param EE_Form_Section_Proper|null $parent_form_section |
|
204 | + * @param string $name |
|
205 | + */ |
|
206 | + do_action( |
|
207 | + 'AHEE__EE_Form_Section_Proper___construct_finalize__end', |
|
208 | + $this, |
|
209 | + $parent_form_section, |
|
210 | + $name |
|
211 | + ); |
|
212 | + } |
|
213 | + |
|
214 | + |
|
215 | + /** |
|
216 | + * Gets the layout strategy for this form section |
|
217 | + * |
|
218 | + * @return EE_Form_Section_Layout_Base |
|
219 | + */ |
|
220 | + public function get_layout_strategy() |
|
221 | + { |
|
222 | + return $this->_layout_strategy; |
|
223 | + } |
|
224 | + |
|
225 | + |
|
226 | + /** |
|
227 | + * Gets the HTML for a single input for this form section according |
|
228 | + * to the layout strategy |
|
229 | + * |
|
230 | + * @param EE_Form_Input_Base $input |
|
231 | + * @return string |
|
232 | + */ |
|
233 | + public function get_html_for_input($input) |
|
234 | + { |
|
235 | + return $this->_layout_strategy->layout_input($input); |
|
236 | + } |
|
237 | + |
|
238 | + |
|
239 | + /** |
|
240 | + * was_submitted - checks if form inputs are present in request data |
|
241 | + * Basically an alias for form_data_present_in() (which is used by both |
|
242 | + * proper form sections and form inputs) |
|
243 | + * |
|
244 | + * @param null $form_data |
|
245 | + * @return boolean |
|
246 | + * @throws EE_Error |
|
247 | + */ |
|
248 | + public function was_submitted($form_data = null) |
|
249 | + { |
|
250 | + return $this->form_data_present_in($form_data); |
|
251 | + } |
|
252 | + |
|
253 | + /** |
|
254 | + * Gets the cached request data; but if there is none, or $req_data was set with |
|
255 | + * something different, refresh the cache, and then return it |
|
256 | + * @param null $req_data |
|
257 | + * @return array |
|
258 | + */ |
|
259 | + protected function getCachedRequest($req_data = null) |
|
260 | + { |
|
261 | + if ($this->cached_request_data === null |
|
262 | + || ( |
|
263 | + $req_data !== null && |
|
264 | + $req_data !== $this->cached_request_data |
|
265 | + ) |
|
266 | + ) { |
|
267 | + $req_data = apply_filters( |
|
268 | + 'FHEE__EE_Form_Section_Proper__receive_form_submission__req_data', |
|
269 | + $req_data, |
|
270 | + $this |
|
271 | + ); |
|
272 | + if ($req_data === null) { |
|
273 | + $req_data = array_merge($_GET, $_POST); |
|
274 | + } |
|
275 | + $req_data = apply_filters( |
|
276 | + 'FHEE__EE_Form_Section_Proper__receive_form_submission__request_data', |
|
277 | + $req_data, |
|
278 | + $this |
|
279 | + ); |
|
280 | + $this->cached_request_data = (array)$req_data; |
|
281 | + } |
|
282 | + return $this->cached_request_data; |
|
283 | + } |
|
284 | + |
|
285 | + |
|
286 | + /** |
|
287 | + * After the form section is initially created, call this to sanitize the data in the submission |
|
288 | + * which relates to this form section, validate it, and set it as properties on the form. |
|
289 | + * |
|
290 | + * @param array|null $req_data should usually be $_POST (the default). |
|
291 | + * However, you CAN supply a different array. |
|
292 | + * Consider using set_defaults() instead however. |
|
293 | + * (If you rendered the form in the page using echo $form_x->get_html() |
|
294 | + * the inputs will have the correct name in the request data for this function |
|
295 | + * to find them and populate the form with them. |
|
296 | + * If you have a flat form (with only input subsections), |
|
297 | + * you can supply a flat array where keys |
|
298 | + * are the form input names and values are their values) |
|
299 | + * @param boolean $validate whether or not to perform validation on this data. Default is, |
|
300 | + * of course, to validate that data, and set errors on the invalid values. |
|
301 | + * But if the data has already been validated |
|
302 | + * (eg you validated the data then stored it in the DB) |
|
303 | + * you may want to skip this step. |
|
304 | + * @throws InvalidArgumentException |
|
305 | + * @throws InvalidInterfaceException |
|
306 | + * @throws InvalidDataTypeException |
|
307 | + * @throws EE_Error |
|
308 | + */ |
|
309 | + public function receive_form_submission($req_data = null, $validate = true) |
|
310 | + { |
|
311 | + $req_data = $this->getCachedRequest($req_data); |
|
312 | + $this->_normalize($req_data); |
|
313 | + if ($validate) { |
|
314 | + $this->_validate(); |
|
315 | + //if it's invalid, we're going to want to re-display so remember what they submitted |
|
316 | + if (! $this->is_valid()) { |
|
317 | + $this->store_submitted_form_data_in_session(); |
|
318 | + } |
|
319 | + } |
|
320 | + if ($this->submission_error_message() === '' && ! $this->is_valid()) { |
|
321 | + $this->set_submission_error_message(); |
|
322 | + } |
|
323 | + do_action( |
|
324 | + 'AHEE__EE_Form_Section_Proper__receive_form_submission__end', |
|
325 | + $req_data, |
|
326 | + $this, |
|
327 | + $validate |
|
328 | + ); |
|
329 | + } |
|
330 | + |
|
331 | + |
|
332 | + /** |
|
333 | + * caches the originally submitted input values in the session |
|
334 | + * so that they can be used to repopulate the form if it failed validation |
|
335 | + * |
|
336 | + * @return boolean whether or not the data was successfully stored in the session |
|
337 | + * @throws InvalidArgumentException |
|
338 | + * @throws InvalidInterfaceException |
|
339 | + * @throws InvalidDataTypeException |
|
340 | + * @throws EE_Error |
|
341 | + */ |
|
342 | + protected function store_submitted_form_data_in_session() |
|
343 | + { |
|
344 | + return EE_Registry::instance()->SSN->set_session_data( |
|
345 | + array( |
|
346 | + EE_Form_Section_Proper::SUBMITTED_FORM_DATA_SSN_KEY => $this->submitted_values(true), |
|
347 | + ) |
|
348 | + ); |
|
349 | + } |
|
350 | + |
|
351 | + |
|
352 | + /** |
|
353 | + * retrieves the originally submitted input values in the session |
|
354 | + * so that they can be used to repopulate the form if it failed validation |
|
355 | + * |
|
356 | + * @return array |
|
357 | + * @throws InvalidArgumentException |
|
358 | + * @throws InvalidInterfaceException |
|
359 | + * @throws InvalidDataTypeException |
|
360 | + */ |
|
361 | + protected function get_submitted_form_data_from_session() |
|
362 | + { |
|
363 | + $session = EE_Registry::instance()->SSN; |
|
364 | + if ($session instanceof EE_Session) { |
|
365 | + return $session->get_session_data( |
|
366 | + EE_Form_Section_Proper::SUBMITTED_FORM_DATA_SSN_KEY |
|
367 | + ); |
|
368 | + } |
|
369 | + return array(); |
|
370 | + } |
|
371 | + |
|
372 | + |
|
373 | + /** |
|
374 | + * flushed the originally submitted input values from the session |
|
375 | + * |
|
376 | + * @return boolean whether or not the data was successfully removed from the session |
|
377 | + * @throws InvalidArgumentException |
|
378 | + * @throws InvalidInterfaceException |
|
379 | + * @throws InvalidDataTypeException |
|
380 | + */ |
|
381 | + protected function flush_submitted_form_data_from_session() |
|
382 | + { |
|
383 | + return EE_Registry::instance()->SSN->reset_data( |
|
384 | + array(EE_Form_Section_Proper::SUBMITTED_FORM_DATA_SSN_KEY) |
|
385 | + ); |
|
386 | + } |
|
387 | + |
|
388 | + |
|
389 | + /** |
|
390 | + * Populates this form and its subsections with data from the session. |
|
391 | + * (Wrapper for EE_Form_Section_Proper::receive_form_submission, so it shows |
|
392 | + * validation errors when displaying too) |
|
393 | + * Returns true if the form was populated from the session, false otherwise |
|
394 | + * |
|
395 | + * @return boolean |
|
396 | + * @throws InvalidArgumentException |
|
397 | + * @throws InvalidInterfaceException |
|
398 | + * @throws InvalidDataTypeException |
|
399 | + * @throws EE_Error |
|
400 | + */ |
|
401 | + public function populate_from_session() |
|
402 | + { |
|
403 | + $form_data_in_session = $this->get_submitted_form_data_from_session(); |
|
404 | + if (empty($form_data_in_session)) { |
|
405 | + return false; |
|
406 | + } |
|
407 | + $this->receive_form_submission($form_data_in_session); |
|
408 | + $this->flush_submitted_form_data_from_session(); |
|
409 | + if ($this->form_data_present_in($form_data_in_session)) { |
|
410 | + return true; |
|
411 | + } |
|
412 | + return false; |
|
413 | + } |
|
414 | + |
|
415 | + |
|
416 | + /** |
|
417 | + * Populates the default data for the form, given an array where keys are |
|
418 | + * the input names, and values are their values (preferably normalized to be their |
|
419 | + * proper PHP types, not all strings... although that should be ok too). |
|
420 | + * Proper subsections are sub-arrays, the key being the subsection's name, and |
|
421 | + * the value being an array formatted in teh same way |
|
422 | + * |
|
423 | + * @param array $default_data |
|
424 | + * @throws EE_Error |
|
425 | + */ |
|
426 | + public function populate_defaults($default_data) |
|
427 | + { |
|
428 | + foreach ($this->subsections(false) as $subsection_name => $subsection) { |
|
429 | + if (isset($default_data[ $subsection_name ])) { |
|
430 | + if ($subsection instanceof EE_Form_Input_Base) { |
|
431 | + $subsection->set_default($default_data[ $subsection_name ]); |
|
432 | + } elseif ($subsection instanceof EE_Form_Section_Proper) { |
|
433 | + $subsection->populate_defaults($default_data[ $subsection_name ]); |
|
434 | + } |
|
435 | + } |
|
436 | + } |
|
437 | + } |
|
438 | + |
|
439 | + |
|
440 | + /** |
|
441 | + * returns true if subsection exists |
|
442 | + * |
|
443 | + * @param string $name |
|
444 | + * @return boolean |
|
445 | + */ |
|
446 | + public function subsection_exists($name) |
|
447 | + { |
|
448 | + return isset($this->_subsections[ $name ]) ? true : false; |
|
449 | + } |
|
450 | + |
|
451 | + |
|
452 | + /** |
|
453 | + * Gets the subsection specified by its name |
|
454 | + * |
|
455 | + * @param string $name |
|
456 | + * @param boolean $require_construction_to_be_finalized most client code should leave this as TRUE |
|
457 | + * so that the inputs will be properly configured. |
|
458 | + * However, some client code may be ok |
|
459 | + * with construction finalize being called later |
|
460 | + * (realizing that the subsections' html names |
|
461 | + * might not be set yet, etc.) |
|
462 | + * @return EE_Form_Section_Base |
|
463 | + * @throws EE_Error |
|
464 | + */ |
|
465 | + public function get_subsection($name, $require_construction_to_be_finalized = true) |
|
466 | + { |
|
467 | + if ($require_construction_to_be_finalized) { |
|
468 | + $this->ensure_construct_finalized_called(); |
|
469 | + } |
|
470 | + return $this->subsection_exists($name) ? $this->_subsections[ $name ] : null; |
|
471 | + } |
|
472 | + |
|
473 | + |
|
474 | + /** |
|
475 | + * Gets all the validatable subsections of this form section |
|
476 | + * |
|
477 | + * @return EE_Form_Section_Validatable[] |
|
478 | + * @throws EE_Error |
|
479 | + */ |
|
480 | + public function get_validatable_subsections() |
|
481 | + { |
|
482 | + $validatable_subsections = array(); |
|
483 | + foreach ($this->subsections() as $name => $obj) { |
|
484 | + if ($obj instanceof EE_Form_Section_Validatable) { |
|
485 | + $validatable_subsections[ $name ] = $obj; |
|
486 | + } |
|
487 | + } |
|
488 | + return $validatable_subsections; |
|
489 | + } |
|
490 | + |
|
491 | + |
|
492 | + /** |
|
493 | + * Gets an input by the given name. If not found, or if its not an EE_FOrm_Input_Base child, |
|
494 | + * throw an EE_Error. |
|
495 | + * |
|
496 | + * @param string $name |
|
497 | + * @param boolean $require_construction_to_be_finalized most client code should |
|
498 | + * leave this as TRUE so that the inputs will be properly |
|
499 | + * configured. However, some client code may be ok with |
|
500 | + * construction finalize being called later |
|
501 | + * (realizing that the subsections' html names might not be |
|
502 | + * set yet, etc.) |
|
503 | + * @return EE_Form_Input_Base |
|
504 | + * @throws EE_Error |
|
505 | + */ |
|
506 | + public function get_input($name, $require_construction_to_be_finalized = true) |
|
507 | + { |
|
508 | + $subsection = $this->get_subsection( |
|
509 | + $name, |
|
510 | + $require_construction_to_be_finalized |
|
511 | + ); |
|
512 | + if (! $subsection instanceof EE_Form_Input_Base) { |
|
513 | + throw new EE_Error( |
|
514 | + sprintf( |
|
515 | + esc_html__( |
|
516 | + "Subsection '%s' is not an instanceof EE_Form_Input_Base on form '%s'. It is a '%s'", |
|
517 | + 'event_espresso' |
|
518 | + ), |
|
519 | + $name, |
|
520 | + get_class($this), |
|
521 | + $subsection ? get_class($subsection) : esc_html__('NULL', 'event_espresso') |
|
522 | + ) |
|
523 | + ); |
|
524 | + } |
|
525 | + return $subsection; |
|
526 | + } |
|
527 | + |
|
528 | + |
|
529 | + /** |
|
530 | + * Like get_input(), gets the proper subsection of the form given the name, |
|
531 | + * otherwise throws an EE_Error |
|
532 | + * |
|
533 | + * @param string $name |
|
534 | + * @param boolean $require_construction_to_be_finalized most client code should |
|
535 | + * leave this as TRUE so that the inputs will be properly |
|
536 | + * configured. However, some client code may be ok with |
|
537 | + * construction finalize being called later |
|
538 | + * (realizing that the subsections' html names might not be |
|
539 | + * set yet, etc.) |
|
540 | + * @return EE_Form_Section_Proper |
|
541 | + * @throws EE_Error |
|
542 | + */ |
|
543 | + public function get_proper_subsection($name, $require_construction_to_be_finalized = true) |
|
544 | + { |
|
545 | + $subsection = $this->get_subsection( |
|
546 | + $name, |
|
547 | + $require_construction_to_be_finalized |
|
548 | + ); |
|
549 | + if (! $subsection instanceof EE_Form_Section_Proper) { |
|
550 | + throw new EE_Error( |
|
551 | + sprintf( |
|
552 | + esc_html__( |
|
553 | + "Subsection '%'s is not an instanceof EE_Form_Section_Proper on form '%s'", |
|
554 | + 'event_espresso' |
|
555 | + ), |
|
556 | + $name, |
|
557 | + get_class($this) |
|
558 | + ) |
|
559 | + ); |
|
560 | + } |
|
561 | + return $subsection; |
|
562 | + } |
|
563 | + |
|
564 | + |
|
565 | + /** |
|
566 | + * Gets the value of the specified input. Should be called after receive_form_submission() |
|
567 | + * or populate_defaults() on the form, where the normalized value on the input is set. |
|
568 | + * |
|
569 | + * @param string $name |
|
570 | + * @return mixed depending on the input's type and its normalization strategy |
|
571 | + * @throws EE_Error |
|
572 | + */ |
|
573 | + public function get_input_value($name) |
|
574 | + { |
|
575 | + $input = $this->get_input($name); |
|
576 | + return $input->normalized_value(); |
|
577 | + } |
|
578 | + |
|
579 | + |
|
580 | + /** |
|
581 | + * Checks if this form section itself is valid, and then checks its subsections |
|
582 | + * |
|
583 | + * @throws EE_Error |
|
584 | + * @return boolean |
|
585 | + */ |
|
586 | + public function is_valid() |
|
587 | + { |
|
588 | + if($this->is_valid === null) { |
|
589 | + if (! $this->has_received_submission()) { |
|
590 | + throw new EE_Error( |
|
591 | + sprintf( |
|
592 | + esc_html__( |
|
593 | + 'You cannot check if a form is valid before receiving the form submission using receive_form_submission', |
|
594 | + 'event_espresso' |
|
595 | + ) |
|
596 | + ) |
|
597 | + ); |
|
598 | + } |
|
599 | + if (! parent::is_valid()) { |
|
600 | + $this->is_valid = false; |
|
601 | + } else { |
|
602 | + // ok so no general errors to this entire form section. |
|
603 | + // so let's check the subsections, but only set errors if that hasn't been done yet |
|
604 | + $this->is_valid = true; |
|
605 | + foreach ($this->get_validatable_subsections() as $subsection) { |
|
606 | + if (! $subsection->is_valid()) { |
|
607 | + $this->is_valid = false; |
|
608 | + } |
|
609 | + } |
|
610 | + } |
|
611 | + } |
|
612 | + return $this->is_valid; |
|
613 | + } |
|
614 | + |
|
615 | + |
|
616 | + /** |
|
617 | + * gets the default name of this form section if none is specified |
|
618 | + * |
|
619 | + * @return void |
|
620 | + */ |
|
621 | + protected function _set_default_name_if_empty() |
|
622 | + { |
|
623 | + if (! $this->_name) { |
|
624 | + $classname = get_class($this); |
|
625 | + $default_name = str_replace('EE_', '', $classname); |
|
626 | + $this->_name = $default_name; |
|
627 | + } |
|
628 | + } |
|
629 | + |
|
630 | + |
|
631 | + /** |
|
632 | + * Returns the HTML for the form, except for the form opening and closing tags |
|
633 | + * (as the form section doesn't know where you necessarily want to send the information to), |
|
634 | + * and except for a submit button. Enqueues JS and CSS; if called early enough we will |
|
635 | + * try to enqueue them in the header, otherwise they'll be enqueued in the footer. |
|
636 | + * Not doing_it_wrong because theoretically this CAN be used properly, |
|
637 | + * provided its used during "wp_enqueue_scripts", or it doesn't need to enqueue |
|
638 | + * any CSS. |
|
639 | + * |
|
640 | + * @throws InvalidArgumentException |
|
641 | + * @throws InvalidInterfaceException |
|
642 | + * @throws InvalidDataTypeException |
|
643 | + * @throws EE_Error |
|
644 | + */ |
|
645 | + public function get_html_and_js() |
|
646 | + { |
|
647 | + $this->enqueue_js(); |
|
648 | + return $this->get_html(); |
|
649 | + } |
|
650 | + |
|
651 | + |
|
652 | + /** |
|
653 | + * returns HTML for displaying this form section. recursively calls display_section() on all subsections |
|
654 | + * |
|
655 | + * @param bool $display_previously_submitted_data |
|
656 | + * @return string |
|
657 | + * @throws InvalidArgumentException |
|
658 | + * @throws InvalidInterfaceException |
|
659 | + * @throws InvalidDataTypeException |
|
660 | + * @throws EE_Error |
|
661 | + * @throws EE_Error |
|
662 | + * @throws EE_Error |
|
663 | + */ |
|
664 | + public function get_html($display_previously_submitted_data = true) |
|
665 | + { |
|
666 | + $this->ensure_construct_finalized_called(); |
|
667 | + if ($display_previously_submitted_data) { |
|
668 | + $this->populate_from_session(); |
|
669 | + } |
|
670 | + return $this->_form_html_filter |
|
671 | + ? $this->_form_html_filter->filterHtml($this->_layout_strategy->layout_form(), $this) |
|
672 | + : $this->_layout_strategy->layout_form(); |
|
673 | + } |
|
674 | + |
|
675 | + |
|
676 | + /** |
|
677 | + * enqueues JS and CSS for the form. |
|
678 | + * It is preferred to call this before wp_enqueue_scripts so the |
|
679 | + * scripts and styles can be put in the header, but if called later |
|
680 | + * they will be put in the footer (which is OK for JS, but in HTML4 CSS should |
|
681 | + * only be in the header; but in HTML5 its ok in the body. |
|
682 | + * See http://stackoverflow.com/questions/4957446/load-external-css-file-in-body-tag. |
|
683 | + * So if your form enqueues CSS, it's preferred to call this before wp_enqueue_scripts.) |
|
684 | + * |
|
685 | + * @return void |
|
686 | + * @throws EE_Error |
|
687 | + */ |
|
688 | + public function enqueue_js() |
|
689 | + { |
|
690 | + $this->_enqueue_and_localize_form_js(); |
|
691 | + foreach ($this->subsections() as $subsection) { |
|
692 | + $subsection->enqueue_js(); |
|
693 | + } |
|
694 | + } |
|
695 | + |
|
696 | + |
|
697 | + /** |
|
698 | + * adds a filter so that jquery validate gets enqueued in EE_System::wp_enqueue_scripts(). |
|
699 | + * This must be done BEFORE wp_enqueue_scripts() gets called, which is on |
|
700 | + * the wp_enqueue_scripts hook. |
|
701 | + * However, registering the form js and localizing it can happen when we |
|
702 | + * actually output the form (which is preferred, seeing how teh form's fields |
|
703 | + * could change until it's actually outputted) |
|
704 | + * |
|
705 | + * @param boolean $init_form_validation_automatically whether or not we want the form validation |
|
706 | + * to be triggered automatically or not |
|
707 | + * @return void |
|
708 | + */ |
|
709 | + public static function wp_enqueue_scripts($init_form_validation_automatically = true) |
|
710 | + { |
|
711 | + wp_register_script( |
|
712 | + 'ee_form_section_validation', |
|
713 | + EE_GLOBAL_ASSETS_URL . 'scripts' . DS . 'form_section_validation.js', |
|
714 | + array('jquery-validate', 'jquery-ui-datepicker', 'jquery-validate-extra-methods'), |
|
715 | + EVENT_ESPRESSO_VERSION, |
|
716 | + true |
|
717 | + ); |
|
718 | + wp_localize_script( |
|
719 | + 'ee_form_section_validation', |
|
720 | + 'ee_form_section_validation_init', |
|
721 | + array('init' => $init_form_validation_automatically ? '1' : '0') |
|
722 | + ); |
|
723 | + } |
|
724 | + |
|
725 | + |
|
726 | + /** |
|
727 | + * gets the variables used by form_section_validation.js. |
|
728 | + * This needs to be called AFTER we've called $this->_enqueue_jquery_validate_script, |
|
729 | + * but before the wordpress hook wp_loaded |
|
730 | + * |
|
731 | + * @throws EE_Error |
|
732 | + */ |
|
733 | + public function _enqueue_and_localize_form_js() |
|
734 | + { |
|
735 | + $this->ensure_construct_finalized_called(); |
|
736 | + //actually, we don't want to localize just yet. There may be other forms on the page. |
|
737 | + //so we need to add our form section data to a static variable accessible by all form sections |
|
738 | + //and localize it just before the footer |
|
739 | + $this->localize_validation_rules(); |
|
740 | + add_action('wp_footer', array('EE_Form_Section_Proper', 'localize_script_for_all_forms'), 2); |
|
741 | + add_action('admin_footer', array('EE_Form_Section_Proper', 'localize_script_for_all_forms')); |
|
742 | + } |
|
743 | + |
|
744 | + |
|
745 | + /** |
|
746 | + * add our form section data to a static variable accessible by all form sections |
|
747 | + * |
|
748 | + * @param bool $return_for_subsection |
|
749 | + * @return void |
|
750 | + * @throws EE_Error |
|
751 | + */ |
|
752 | + public function localize_validation_rules($return_for_subsection = false) |
|
753 | + { |
|
754 | + // we only want to localize vars ONCE for the entire form, |
|
755 | + // so if the form section doesn't have a parent, then it must be the top dog |
|
756 | + if ($return_for_subsection || ! $this->parent_section()) { |
|
757 | + EE_Form_Section_Proper::$_js_localization['form_data'][ $this->html_id() ] = array( |
|
758 | + 'form_section_id' => $this->html_id(true), |
|
759 | + 'validation_rules' => $this->get_jquery_validation_rules(), |
|
760 | + 'other_data' => $this->get_other_js_data(), |
|
761 | + 'errors' => $this->subsection_validation_errors_by_html_name(), |
|
762 | + ); |
|
763 | + EE_Form_Section_Proper::$_scripts_localized = true; |
|
764 | + } |
|
765 | + } |
|
766 | + |
|
767 | + |
|
768 | + /** |
|
769 | + * Gets an array of extra data that will be useful for client-side javascript. |
|
770 | + * This is primarily data added by inputs and forms in addition to any |
|
771 | + * scripts they might enqueue |
|
772 | + * |
|
773 | + * @param array $form_other_js_data |
|
774 | + * @return array |
|
775 | + * @throws EE_Error |
|
776 | + */ |
|
777 | + public function get_other_js_data($form_other_js_data = array()) |
|
778 | + { |
|
779 | + foreach ($this->subsections() as $subsection) { |
|
780 | + $form_other_js_data = $subsection->get_other_js_data($form_other_js_data); |
|
781 | + } |
|
782 | + return $form_other_js_data; |
|
783 | + } |
|
784 | + |
|
785 | + |
|
786 | + /** |
|
787 | + * Gets a flat array of inputs for this form section and its subsections. |
|
788 | + * Keys are their form names, and values are the inputs themselves |
|
789 | + * |
|
790 | + * @return EE_Form_Input_Base |
|
791 | + * @throws EE_Error |
|
792 | + */ |
|
793 | + public function inputs_in_subsections() |
|
794 | + { |
|
795 | + $inputs = array(); |
|
796 | + foreach ($this->subsections() as $subsection) { |
|
797 | + if ($subsection instanceof EE_Form_Input_Base) { |
|
798 | + $inputs[ $subsection->html_name() ] = $subsection; |
|
799 | + } elseif ($subsection instanceof EE_Form_Section_Proper) { |
|
800 | + $inputs += $subsection->inputs_in_subsections(); |
|
801 | + } |
|
802 | + } |
|
803 | + return $inputs; |
|
804 | + } |
|
805 | + |
|
806 | + |
|
807 | + /** |
|
808 | + * Gets a flat array of all the validation errors. |
|
809 | + * Keys are html names (because those should be unique) |
|
810 | + * and values are a string of all their validation errors |
|
811 | + * |
|
812 | + * @return string[] |
|
813 | + * @throws EE_Error |
|
814 | + */ |
|
815 | + public function subsection_validation_errors_by_html_name() |
|
816 | + { |
|
817 | + $inputs = $this->inputs(); |
|
818 | + $errors = array(); |
|
819 | + foreach ($inputs as $form_input) { |
|
820 | + if ($form_input instanceof EE_Form_Input_Base && $form_input->get_validation_errors()) { |
|
821 | + $errors[ $form_input->html_name() ] = $form_input->get_validation_error_string(); |
|
822 | + } |
|
823 | + } |
|
824 | + return $errors; |
|
825 | + } |
|
826 | + |
|
827 | + |
|
828 | + /** |
|
829 | + * passes all the form data required by the JS to the JS, and enqueues the few required JS files. |
|
830 | + * Should be setup by each form during the _enqueues_and_localize_form_js |
|
831 | + * |
|
832 | + * @throws InvalidArgumentException |
|
833 | + * @throws InvalidInterfaceException |
|
834 | + * @throws InvalidDataTypeException |
|
835 | + */ |
|
836 | + public static function localize_script_for_all_forms() |
|
837 | + { |
|
838 | + //allow inputs and stuff to hook in their JS and stuff here |
|
839 | + do_action('AHEE__EE_Form_Section_Proper__localize_script_for_all_forms__begin'); |
|
840 | + EE_Form_Section_Proper::$_js_localization['localized_error_messages'] = EE_Form_Section_Proper::_get_localized_error_messages(); |
|
841 | + $email_validation_level = isset(EE_Registry::instance()->CFG->registration->email_validation_level) |
|
842 | + ? EE_Registry::instance()->CFG->registration->email_validation_level |
|
843 | + : 'wp_default'; |
|
844 | + EE_Form_Section_Proper::$_js_localization['email_validation_level'] = $email_validation_level; |
|
845 | + wp_enqueue_script('ee_form_section_validation'); |
|
846 | + wp_localize_script( |
|
847 | + 'ee_form_section_validation', |
|
848 | + 'ee_form_section_vars', |
|
849 | + EE_Form_Section_Proper::$_js_localization |
|
850 | + ); |
|
851 | + } |
|
852 | + |
|
853 | + |
|
854 | + /** |
|
855 | + * ensure_scripts_localized |
|
856 | + * |
|
857 | + * @throws EE_Error |
|
858 | + */ |
|
859 | + public function ensure_scripts_localized() |
|
860 | + { |
|
861 | + if (! EE_Form_Section_Proper::$_scripts_localized) { |
|
862 | + $this->_enqueue_and_localize_form_js(); |
|
863 | + } |
|
864 | + } |
|
865 | + |
|
866 | + |
|
867 | + /** |
|
868 | + * Gets the hard-coded validation error messages to be used in the JS. The convention |
|
869 | + * is that the key here should be the same as the custom validation rule put in the JS file |
|
870 | + * |
|
871 | + * @return array keys are custom validation rules, and values are internationalized strings |
|
872 | + */ |
|
873 | + private static function _get_localized_error_messages() |
|
874 | + { |
|
875 | + return array( |
|
876 | + 'validUrl' => esc_html__('This is not a valid absolute URL. Eg, http://domain.com/monkey.jpg', 'event_espresso'), |
|
877 | + 'regex' => esc_html__('Please check your input', 'event_espresso'), |
|
878 | + ); |
|
879 | + } |
|
880 | + |
|
881 | + |
|
882 | + /** |
|
883 | + * @return array |
|
884 | + */ |
|
885 | + public static function js_localization() |
|
886 | + { |
|
887 | + return self::$_js_localization; |
|
888 | + } |
|
889 | + |
|
890 | + |
|
891 | + /** |
|
892 | + * @return void |
|
893 | + */ |
|
894 | + public static function reset_js_localization() |
|
895 | + { |
|
896 | + self::$_js_localization = array(); |
|
897 | + } |
|
898 | + |
|
899 | + |
|
900 | + /** |
|
901 | + * Gets the JS to put inside the jquery validation rules for subsection of this form section. |
|
902 | + * See parent function for more... |
|
903 | + * |
|
904 | + * @return array |
|
905 | + * @throws EE_Error |
|
906 | + */ |
|
907 | + public function get_jquery_validation_rules() |
|
908 | + { |
|
909 | + $jquery_validation_rules = array(); |
|
910 | + foreach ($this->get_validatable_subsections() as $subsection) { |
|
911 | + $jquery_validation_rules = array_merge( |
|
912 | + $jquery_validation_rules, |
|
913 | + $subsection->get_jquery_validation_rules() |
|
914 | + ); |
|
915 | + } |
|
916 | + return $jquery_validation_rules; |
|
917 | + } |
|
918 | + |
|
919 | + |
|
920 | + /** |
|
921 | + * Sanitizes all the data and sets the sanitized value of each field |
|
922 | + * |
|
923 | + * @param array $req_data like $_POST |
|
924 | + * @return void |
|
925 | + * @throws EE_Error |
|
926 | + */ |
|
927 | + protected function _normalize($req_data) |
|
928 | + { |
|
929 | + $this->_received_submission = true; |
|
930 | + $this->_validation_errors = array(); |
|
931 | + foreach ($this->get_validatable_subsections() as $subsection) { |
|
932 | + try { |
|
933 | + $subsection->_normalize($req_data); |
|
934 | + } catch (EE_Validation_Error $e) { |
|
935 | + $subsection->add_validation_error($e); |
|
936 | + } |
|
937 | + } |
|
938 | + } |
|
939 | + |
|
940 | + |
|
941 | + /** |
|
942 | + * Performs validation on this form section and its subsections. |
|
943 | + * For each subsection, |
|
944 | + * calls _validate_{subsection_name} on THIS form (if the function exists) |
|
945 | + * and passes it the subsection, then calls _validate on that subsection. |
|
946 | + * If you need to perform validation on the form as a whole (considering multiple) |
|
947 | + * you would be best to override this _validate method, |
|
948 | + * calling parent::_validate() first. |
|
949 | + * |
|
950 | + * @throws EE_Error |
|
951 | + */ |
|
952 | + protected function _validate() |
|
953 | + { |
|
954 | + //reset the cache of whether this form is valid or not- we're re-validating it now |
|
955 | + $this->is_valid = null; |
|
956 | + foreach ($this->get_validatable_subsections() as $subsection_name => $subsection) { |
|
957 | + if (method_exists($this, '_validate_' . $subsection_name)) { |
|
958 | + call_user_func_array(array($this, '_validate_' . $subsection_name), array($subsection)); |
|
959 | + } |
|
960 | + $subsection->_validate(); |
|
961 | + } |
|
962 | + } |
|
963 | + |
|
964 | + |
|
965 | + /** |
|
966 | + * Gets all the validated inputs for the form section |
|
967 | + * |
|
968 | + * @return array |
|
969 | + * @throws EE_Error |
|
970 | + */ |
|
971 | + public function valid_data() |
|
972 | + { |
|
973 | + $inputs = array(); |
|
974 | + foreach ($this->subsections() as $subsection_name => $subsection) { |
|
975 | + if ($subsection instanceof EE_Form_Section_Proper) { |
|
976 | + $inputs[ $subsection_name ] = $subsection->valid_data(); |
|
977 | + } elseif ($subsection instanceof EE_Form_Input_Base) { |
|
978 | + $inputs[ $subsection_name ] = $subsection->normalized_value(); |
|
979 | + } |
|
980 | + } |
|
981 | + return $inputs; |
|
982 | + } |
|
983 | + |
|
984 | + |
|
985 | + /** |
|
986 | + * Gets all the inputs on this form section |
|
987 | + * |
|
988 | + * @return EE_Form_Input_Base[] |
|
989 | + * @throws EE_Error |
|
990 | + */ |
|
991 | + public function inputs() |
|
992 | + { |
|
993 | + $inputs = array(); |
|
994 | + foreach ($this->subsections() as $subsection_name => $subsection) { |
|
995 | + if ($subsection instanceof EE_Form_Input_Base) { |
|
996 | + $inputs[ $subsection_name ] = $subsection; |
|
997 | + } |
|
998 | + } |
|
999 | + return $inputs; |
|
1000 | + } |
|
1001 | + |
|
1002 | + |
|
1003 | + /** |
|
1004 | + * Gets all the subsections which are a proper form |
|
1005 | + * |
|
1006 | + * @return EE_Form_Section_Proper[] |
|
1007 | + * @throws EE_Error |
|
1008 | + */ |
|
1009 | + public function subforms() |
|
1010 | + { |
|
1011 | + $form_sections = array(); |
|
1012 | + foreach ($this->subsections() as $name => $obj) { |
|
1013 | + if ($obj instanceof EE_Form_Section_Proper) { |
|
1014 | + $form_sections[ $name ] = $obj; |
|
1015 | + } |
|
1016 | + } |
|
1017 | + return $form_sections; |
|
1018 | + } |
|
1019 | + |
|
1020 | + |
|
1021 | + /** |
|
1022 | + * Gets all the subsections (inputs, proper subsections, or html-only sections). |
|
1023 | + * Consider using inputs() or subforms() |
|
1024 | + * if you only want form inputs or proper form sections. |
|
1025 | + * |
|
1026 | + * @param boolean $require_construction_to_be_finalized most client code should |
|
1027 | + * leave this as TRUE so that the inputs will be properly |
|
1028 | + * configured. However, some client code may be ok with |
|
1029 | + * construction finalize being called later |
|
1030 | + * (realizing that the subsections' html names might not be |
|
1031 | + * set yet, etc.) |
|
1032 | + * @return EE_Form_Section_Proper[] |
|
1033 | + * @throws EE_Error |
|
1034 | + */ |
|
1035 | + public function subsections($require_construction_to_be_finalized = true) |
|
1036 | + { |
|
1037 | + if ($require_construction_to_be_finalized) { |
|
1038 | + $this->ensure_construct_finalized_called(); |
|
1039 | + } |
|
1040 | + return $this->_subsections; |
|
1041 | + } |
|
1042 | + |
|
1043 | + |
|
1044 | + /** |
|
1045 | + * Returns whether this form has any subforms or inputs |
|
1046 | + * @return bool |
|
1047 | + */ |
|
1048 | + public function hasSubsections() |
|
1049 | + { |
|
1050 | + return ! empty($this->_subsections); |
|
1051 | + } |
|
1052 | + |
|
1053 | + |
|
1054 | + /** |
|
1055 | + * Returns a simple array where keys are input names, and values are their normalized |
|
1056 | + * values. (Similar to calling get_input_value on inputs) |
|
1057 | + * |
|
1058 | + * @param boolean $include_subform_inputs Whether to include inputs from subforms, |
|
1059 | + * or just this forms' direct children inputs |
|
1060 | + * @param boolean $flatten Whether to force the results into 1-dimensional array, |
|
1061 | + * or allow multidimensional array |
|
1062 | + * @return array if $flatten is TRUE it will always be a 1-dimensional array |
|
1063 | + * with array keys being input names |
|
1064 | + * (regardless of whether they are from a subsection or not), |
|
1065 | + * and if $flatten is FALSE it can be a multidimensional array |
|
1066 | + * where keys are always subsection names and values are either |
|
1067 | + * the input's normalized value, or an array like the top-level array |
|
1068 | + * @throws EE_Error |
|
1069 | + */ |
|
1070 | + public function input_values($include_subform_inputs = false, $flatten = false) |
|
1071 | + { |
|
1072 | + return $this->_input_values(false, $include_subform_inputs, $flatten); |
|
1073 | + } |
|
1074 | + |
|
1075 | + |
|
1076 | + /** |
|
1077 | + * Similar to EE_Form_Section_Proper::input_values(), except this returns the 'display_value' |
|
1078 | + * of each input. On some inputs (especially radio boxes or checkboxes), the value stored |
|
1079 | + * is not necessarily the value we want to display to users. This creates an array |
|
1080 | + * where keys are the input names, and values are their display values |
|
1081 | + * |
|
1082 | + * @param boolean $include_subform_inputs Whether to include inputs from subforms, |
|
1083 | + * or just this forms' direct children inputs |
|
1084 | + * @param boolean $flatten Whether to force the results into 1-dimensional array, |
|
1085 | + * or allow multidimensional array |
|
1086 | + * @return array if $flatten is TRUE it will always be a 1-dimensional array |
|
1087 | + * with array keys being input names |
|
1088 | + * (regardless of whether they are from a subsection or not), |
|
1089 | + * and if $flatten is FALSE it can be a multidimensional array |
|
1090 | + * where keys are always subsection names and values are either |
|
1091 | + * the input's normalized value, or an array like the top-level array |
|
1092 | + * @throws EE_Error |
|
1093 | + */ |
|
1094 | + public function input_pretty_values($include_subform_inputs = false, $flatten = false) |
|
1095 | + { |
|
1096 | + return $this->_input_values(true, $include_subform_inputs, $flatten); |
|
1097 | + } |
|
1098 | + |
|
1099 | + |
|
1100 | + /** |
|
1101 | + * Gets the input values from the form |
|
1102 | + * |
|
1103 | + * @param boolean $pretty Whether to retrieve the pretty value, |
|
1104 | + * or just the normalized value |
|
1105 | + * @param boolean $include_subform_inputs Whether to include inputs from subforms, |
|
1106 | + * or just this forms' direct children inputs |
|
1107 | + * @param boolean $flatten Whether to force the results into 1-dimensional array, |
|
1108 | + * or allow multidimensional array |
|
1109 | + * @return array if $flatten is TRUE it will always be a 1-dimensional array with array keys being |
|
1110 | + * input names (regardless of whether they are from a subsection or not), |
|
1111 | + * and if $flatten is FALSE it can be a multidimensional array |
|
1112 | + * where keys are always subsection names and values are either |
|
1113 | + * the input's normalized value, or an array like the top-level array |
|
1114 | + * @throws EE_Error |
|
1115 | + */ |
|
1116 | + public function _input_values($pretty = false, $include_subform_inputs = false, $flatten = false) |
|
1117 | + { |
|
1118 | + $input_values = array(); |
|
1119 | + foreach ($this->subsections() as $subsection_name => $subsection) { |
|
1120 | + if ($subsection instanceof EE_Form_Input_Base) { |
|
1121 | + $input_values[ $subsection_name ] = $pretty |
|
1122 | + ? $subsection->pretty_value() |
|
1123 | + : $subsection->normalized_value(); |
|
1124 | + } elseif ($subsection instanceof EE_Form_Section_Proper && $include_subform_inputs) { |
|
1125 | + $subform_input_values = $subsection->_input_values( |
|
1126 | + $pretty, |
|
1127 | + $include_subform_inputs, |
|
1128 | + $flatten |
|
1129 | + ); |
|
1130 | + if ($flatten) { |
|
1131 | + $input_values = array_merge($input_values, $subform_input_values); |
|
1132 | + } else { |
|
1133 | + $input_values[ $subsection_name ] = $subform_input_values; |
|
1134 | + } |
|
1135 | + } |
|
1136 | + } |
|
1137 | + return $input_values; |
|
1138 | + } |
|
1139 | + |
|
1140 | + |
|
1141 | + /** |
|
1142 | + * Gets the originally submitted input values from the form |
|
1143 | + * |
|
1144 | + * @param boolean $include_subforms Whether to include inputs from subforms, |
|
1145 | + * or just this forms' direct children inputs |
|
1146 | + * @return array if $flatten is TRUE it will always be a 1-dimensional array |
|
1147 | + * with array keys being input names |
|
1148 | + * (regardless of whether they are from a subsection or not), |
|
1149 | + * and if $flatten is FALSE it can be a multidimensional array |
|
1150 | + * where keys are always subsection names and values are either |
|
1151 | + * the input's normalized value, or an array like the top-level array |
|
1152 | + * @throws EE_Error |
|
1153 | + */ |
|
1154 | + public function submitted_values($include_subforms = false) |
|
1155 | + { |
|
1156 | + $submitted_values = array(); |
|
1157 | + foreach ($this->subsections() as $subsection) { |
|
1158 | + if ($subsection instanceof EE_Form_Input_Base) { |
|
1159 | + // is this input part of an array of inputs? |
|
1160 | + if (strpos($subsection->html_name(), '[') !== false) { |
|
1161 | + $full_input_name = EEH_Array::convert_array_values_to_keys( |
|
1162 | + explode( |
|
1163 | + '[', |
|
1164 | + str_replace(']', '', $subsection->html_name()) |
|
1165 | + ), |
|
1166 | + $subsection->raw_value() |
|
1167 | + ); |
|
1168 | + $submitted_values = array_replace_recursive($submitted_values, $full_input_name); |
|
1169 | + } else { |
|
1170 | + $submitted_values[ $subsection->html_name() ] = $subsection->raw_value(); |
|
1171 | + } |
|
1172 | + } elseif ($subsection instanceof EE_Form_Section_Proper && $include_subforms) { |
|
1173 | + $subform_input_values = $subsection->submitted_values($include_subforms); |
|
1174 | + $submitted_values = array_replace_recursive($submitted_values, $subform_input_values); |
|
1175 | + } |
|
1176 | + } |
|
1177 | + return $submitted_values; |
|
1178 | + } |
|
1179 | + |
|
1180 | + |
|
1181 | + /** |
|
1182 | + * Indicates whether or not this form has received a submission yet |
|
1183 | + * (ie, had receive_form_submission called on it yet) |
|
1184 | + * |
|
1185 | + * @return boolean |
|
1186 | + * @throws EE_Error |
|
1187 | + */ |
|
1188 | + public function has_received_submission() |
|
1189 | + { |
|
1190 | + $this->ensure_construct_finalized_called(); |
|
1191 | + return $this->_received_submission; |
|
1192 | + } |
|
1193 | + |
|
1194 | + |
|
1195 | + /** |
|
1196 | + * Equivalent to passing 'exclude' in the constructor's options array. |
|
1197 | + * Removes the listed inputs from the form |
|
1198 | + * |
|
1199 | + * @param array $inputs_to_exclude values are the input names |
|
1200 | + * @return void |
|
1201 | + */ |
|
1202 | + public function exclude(array $inputs_to_exclude = array()) |
|
1203 | + { |
|
1204 | + foreach ($inputs_to_exclude as $input_to_exclude_name) { |
|
1205 | + unset($this->_subsections[ $input_to_exclude_name ]); |
|
1206 | + } |
|
1207 | + } |
|
1208 | + |
|
1209 | + |
|
1210 | + /** |
|
1211 | + * Changes these inputs' display strategy to be EE_Hidden_Display_Strategy. |
|
1212 | + * @param array $inputs_to_hide |
|
1213 | + * @throws EE_Error |
|
1214 | + */ |
|
1215 | + public function hide(array $inputs_to_hide = array()) |
|
1216 | + { |
|
1217 | + foreach ($inputs_to_hide as $input_to_hide) { |
|
1218 | + $input = $this->get_input($input_to_hide); |
|
1219 | + $input->set_display_strategy(new EE_Hidden_Display_Strategy()); |
|
1220 | + } |
|
1221 | + } |
|
1222 | + |
|
1223 | + |
|
1224 | + /** |
|
1225 | + * add_subsections |
|
1226 | + * Adds the listed subsections to the form section. |
|
1227 | + * If $subsection_name_to_target is provided, |
|
1228 | + * then new subsections are added before or after that subsection, |
|
1229 | + * otherwise to the start or end of the entire subsections array. |
|
1230 | + * |
|
1231 | + * @param EE_Form_Section_Base[] $new_subsections array of new form subsections |
|
1232 | + * where keys are their names |
|
1233 | + * @param string $subsection_name_to_target an existing for section that $new_subsections |
|
1234 | + * should be added before or after |
|
1235 | + * IF $subsection_name_to_target is null, |
|
1236 | + * then $new_subsections will be added to |
|
1237 | + * the beginning or end of the entire subsections array |
|
1238 | + * @param boolean $add_before whether to add $new_subsections, before or after |
|
1239 | + * $subsection_name_to_target, |
|
1240 | + * or if $subsection_name_to_target is null, |
|
1241 | + * before or after entire subsections array |
|
1242 | + * @return void |
|
1243 | + * @throws EE_Error |
|
1244 | + */ |
|
1245 | + public function add_subsections($new_subsections, $subsection_name_to_target = null, $add_before = true) |
|
1246 | + { |
|
1247 | + foreach ($new_subsections as $subsection_name => $subsection) { |
|
1248 | + if (! $subsection instanceof EE_Form_Section_Base) { |
|
1249 | + EE_Error::add_error( |
|
1250 | + sprintf( |
|
1251 | + esc_html__( |
|
1252 | + "Trying to add a %s as a subsection (it was named '%s') to the form section '%s'. It was removed.", |
|
1253 | + 'event_espresso' |
|
1254 | + ), |
|
1255 | + get_class($subsection), |
|
1256 | + $subsection_name, |
|
1257 | + $this->name() |
|
1258 | + ) |
|
1259 | + ); |
|
1260 | + unset($new_subsections[ $subsection_name ]); |
|
1261 | + } |
|
1262 | + } |
|
1263 | + $this->_subsections = EEH_Array::insert_into_array( |
|
1264 | + $this->_subsections, |
|
1265 | + $new_subsections, |
|
1266 | + $subsection_name_to_target, |
|
1267 | + $add_before |
|
1268 | + ); |
|
1269 | + if ($this->_construction_finalized) { |
|
1270 | + foreach ($this->_subsections as $name => $subsection) { |
|
1271 | + $subsection->_construct_finalize($this, $name); |
|
1272 | + } |
|
1273 | + } |
|
1274 | + } |
|
1275 | + |
|
1276 | + |
|
1277 | + /** |
|
1278 | + * @param string $subsection_name |
|
1279 | + * @param bool $recursive |
|
1280 | + * @return bool |
|
1281 | + */ |
|
1282 | + public function has_subsection($subsection_name, $recursive = false) |
|
1283 | + { |
|
1284 | + foreach ($this->_subsections as $name => $subsection) {if( |
|
1285 | + $name === $subsection_name |
|
1286 | + || ( |
|
1287 | + $recursive |
|
1288 | + && $subsection instanceof EE_Form_Section_Proper |
|
1289 | + && $subsection->has_subsection($subsection_name, $recursive) |
|
1290 | + ) |
|
1291 | + ) { |
|
1292 | + return true; |
|
1293 | + } |
|
1294 | + } |
|
1295 | + return false; |
|
1296 | + } |
|
1297 | + |
|
1298 | + |
|
1299 | + |
|
1300 | + /** |
|
1301 | + * Just gets all validatable subsections to clean their sensitive data |
|
1302 | + * |
|
1303 | + * @throws EE_Error |
|
1304 | + */ |
|
1305 | + public function clean_sensitive_data() |
|
1306 | + { |
|
1307 | + foreach ($this->get_validatable_subsections() as $subsection) { |
|
1308 | + $subsection->clean_sensitive_data(); |
|
1309 | + } |
|
1310 | + } |
|
1311 | + |
|
1312 | + |
|
1313 | + /** |
|
1314 | + * Sets the submission error message (aka validation error message for this form section and all sub-sections) |
|
1315 | + * @param string $form_submission_error_message |
|
1316 | + * @param EE_Form_Section_Validatable $form_section unused |
|
1317 | + * @throws EE_Error |
|
1318 | + */ |
|
1319 | + public function set_submission_error_message( |
|
1320 | + $form_submission_error_message = '' |
|
1321 | + ) { |
|
1322 | + $this->_form_submission_error_message = ! empty($form_submission_error_message) |
|
1323 | + ? $form_submission_error_message |
|
1324 | + : $this->getAllValidationErrorsString(); |
|
1325 | + } |
|
1326 | + |
|
1327 | + |
|
1328 | + /** |
|
1329 | + * Returns the cached error message. A default value is set for this during _validate(), |
|
1330 | + * (called during receive_form_submission) but it can be explicitly set using |
|
1331 | + * set_submission_error_message |
|
1332 | + * |
|
1333 | + * @return string |
|
1334 | + */ |
|
1335 | + public function submission_error_message() |
|
1336 | + { |
|
1337 | + return $this->_form_submission_error_message; |
|
1338 | + } |
|
1339 | + |
|
1340 | + |
|
1341 | + /** |
|
1342 | + * Sets a message to display if the data submitted to the form was valid. |
|
1343 | + * @param string $form_submission_success_message |
|
1344 | + */ |
|
1345 | + public function set_submission_success_message($form_submission_success_message = '') |
|
1346 | + { |
|
1347 | + $this->_form_submission_success_message = ! empty($form_submission_success_message) |
|
1348 | + ? $form_submission_success_message |
|
1349 | + : esc_html__('Form submitted successfully', 'event_espresso'); |
|
1350 | + } |
|
1351 | + |
|
1352 | + |
|
1353 | + /** |
|
1354 | + * Gets a message appropriate for display when the form is correctly submitted |
|
1355 | + * @return string |
|
1356 | + */ |
|
1357 | + public function submission_success_message() |
|
1358 | + { |
|
1359 | + return $this->_form_submission_success_message; |
|
1360 | + } |
|
1361 | + |
|
1362 | + |
|
1363 | + /** |
|
1364 | + * Returns the prefix that should be used on child of this form section for |
|
1365 | + * their html names. If this form section itself has a parent, prepends ITS |
|
1366 | + * prefix onto this form section's prefix. Used primarily by |
|
1367 | + * EE_Form_Input_Base::_set_default_html_name_if_empty |
|
1368 | + * |
|
1369 | + * @return string |
|
1370 | + * @throws EE_Error |
|
1371 | + */ |
|
1372 | + public function html_name_prefix() |
|
1373 | + { |
|
1374 | + if ($this->parent_section() instanceof EE_Form_Section_Proper) { |
|
1375 | + return $this->parent_section()->html_name_prefix() . '[' . $this->name() . ']'; |
|
1376 | + } |
|
1377 | + return $this->name(); |
|
1378 | + } |
|
1379 | + |
|
1380 | + |
|
1381 | + /** |
|
1382 | + * Gets the name, but first checks _construct_finalize has been called. If not, |
|
1383 | + * calls it (assumes there is no parent and that we want the name to be whatever |
|
1384 | + * was set, which is probably nothing, or the classname) |
|
1385 | + * |
|
1386 | + * @return string |
|
1387 | + * @throws EE_Error |
|
1388 | + */ |
|
1389 | + public function name() |
|
1390 | + { |
|
1391 | + $this->ensure_construct_finalized_called(); |
|
1392 | + return parent::name(); |
|
1393 | + } |
|
1394 | + |
|
1395 | + |
|
1396 | + /** |
|
1397 | + * @return EE_Form_Section_Proper |
|
1398 | + * @throws EE_Error |
|
1399 | + */ |
|
1400 | + public function parent_section() |
|
1401 | + { |
|
1402 | + $this->ensure_construct_finalized_called(); |
|
1403 | + return parent::parent_section(); |
|
1404 | + } |
|
1405 | + |
|
1406 | + |
|
1407 | + /** |
|
1408 | + * make sure construction finalized was called, otherwise children might not be ready |
|
1409 | + * |
|
1410 | + * @return void |
|
1411 | + * @throws EE_Error |
|
1412 | + */ |
|
1413 | + public function ensure_construct_finalized_called() |
|
1414 | + { |
|
1415 | + if (! $this->_construction_finalized) { |
|
1416 | + $this->_construct_finalize($this->_parent_section, $this->_name); |
|
1417 | + } |
|
1418 | + } |
|
1419 | + |
|
1420 | + |
|
1421 | + /** |
|
1422 | + * Checks if any of this form section's inputs, or any of its children's inputs, |
|
1423 | + * are in teh form data. If any are found, returns true. Else false |
|
1424 | + * |
|
1425 | + * @param array $req_data |
|
1426 | + * @return boolean |
|
1427 | + * @throws EE_Error |
|
1428 | + */ |
|
1429 | + public function form_data_present_in($req_data = null) |
|
1430 | + { |
|
1431 | + $req_data = $this->getCachedRequest($req_data); |
|
1432 | + foreach ($this->subsections() as $subsection) { |
|
1433 | + if ($subsection instanceof EE_Form_Input_Base) { |
|
1434 | + if ($subsection->form_data_present_in($req_data)) { |
|
1435 | + return true; |
|
1436 | + } |
|
1437 | + } elseif ($subsection instanceof EE_Form_Section_Proper) { |
|
1438 | + if ($subsection->form_data_present_in($req_data)) { |
|
1439 | + return true; |
|
1440 | + } |
|
1441 | + } |
|
1442 | + } |
|
1443 | + return false; |
|
1444 | + } |
|
1445 | + |
|
1446 | + |
|
1447 | + /** |
|
1448 | + * Gets validation errors for this form section and subsections |
|
1449 | + * Similar to EE_Form_Section_Validatable::get_validation_errors() except this |
|
1450 | + * gets the validation errors for ALL subsection |
|
1451 | + * |
|
1452 | + * @return EE_Validation_Error[] |
|
1453 | + * @throws EE_Error |
|
1454 | + */ |
|
1455 | + public function get_validation_errors_accumulated() |
|
1456 | + { |
|
1457 | + $validation_errors = $this->get_validation_errors(); |
|
1458 | + foreach ($this->get_validatable_subsections() as $subsection) { |
|
1459 | + if ($subsection instanceof EE_Form_Section_Proper) { |
|
1460 | + $validation_errors_on_this_subsection = $subsection->get_validation_errors_accumulated(); |
|
1461 | + } else { |
|
1462 | + $validation_errors_on_this_subsection = $subsection->get_validation_errors(); |
|
1463 | + } |
|
1464 | + if ($validation_errors_on_this_subsection) { |
|
1465 | + $validation_errors = array_merge($validation_errors, $validation_errors_on_this_subsection); |
|
1466 | + } |
|
1467 | + } |
|
1468 | + return $validation_errors; |
|
1469 | + } |
|
1470 | + |
|
1471 | + /** |
|
1472 | + * Fetch validation errors from children and grandchildren and puts them in a single string. |
|
1473 | + * This traverses the form section tree to generate this, but you probably want to instead use |
|
1474 | + * get_form_submission_error_message() which is usually this message cached (or a custom validation error message) |
|
1475 | + * |
|
1476 | + * @return string |
|
1477 | + * @since $VID:$ |
|
1478 | + */ |
|
1479 | + protected function getAllValidationErrorsString() |
|
1480 | + { |
|
1481 | + $submission_error_messages = array(); |
|
1482 | + // bad, bad, bad registrant |
|
1483 | + foreach ($this->get_validation_errors_accumulated() as $validation_error) { |
|
1484 | + if ($validation_error instanceof EE_Validation_Error) { |
|
1485 | + $form_section = $validation_error->get_form_section(); |
|
1486 | + if ($form_section instanceof EE_Form_Input_Base) { |
|
1487 | + $label = $validation_error->get_form_section()->html_label_text(); |
|
1488 | + } elseif($form_section instanceof EE_Form_Section_Validatable) { |
|
1489 | + $label = $validation_error->get_form_section()->name(); |
|
1490 | + } else { |
|
1491 | + $label = esc_html__('Unknown', 'event_espresso'); |
|
1492 | + } |
|
1493 | + $submission_error_messages[] = sprintf( |
|
1494 | + __('%s : %s', 'event_espresso'), |
|
1495 | + $label, |
|
1496 | + $validation_error->getMessage() |
|
1497 | + ); |
|
1498 | + } |
|
1499 | + } |
|
1500 | + return implode('<br', $submission_error_messages); |
|
1501 | + } |
|
1502 | + |
|
1503 | + |
|
1504 | + /** |
|
1505 | + * This isn't just the name of an input, it's a path pointing to an input. The |
|
1506 | + * path is similar to a folder path: slash (/) means to descend into a subsection, |
|
1507 | + * dot-dot-slash (../) means to ascend into the parent section. |
|
1508 | + * After a series of slashes and dot-dot-slashes, there should be the name of an input, |
|
1509 | + * which will be returned. |
|
1510 | + * Eg, if you want the related input to be conditional on a sibling input name 'foobar' |
|
1511 | + * just use 'foobar'. If you want it to be conditional on an aunt/uncle input name |
|
1512 | + * 'baz', use '../baz'. If you want it to be conditional on a cousin input, |
|
1513 | + * the child of 'baz_section' named 'baz_child', use '../baz_section/baz_child'. |
|
1514 | + * Etc |
|
1515 | + * |
|
1516 | + * @param string|false $form_section_path we accept false also because substr( '../', '../' ) = false |
|
1517 | + * @return EE_Form_Section_Base |
|
1518 | + * @throws EE_Error |
|
1519 | + */ |
|
1520 | + public function find_section_from_path($form_section_path) |
|
1521 | + { |
|
1522 | + //check if we can find the input from purely going straight up the tree |
|
1523 | + $input = parent::find_section_from_path($form_section_path); |
|
1524 | + if ($input instanceof EE_Form_Section_Base) { |
|
1525 | + return $input; |
|
1526 | + } |
|
1527 | + $next_slash_pos = strpos($form_section_path, '/'); |
|
1528 | + if ($next_slash_pos !== false) { |
|
1529 | + $child_section_name = substr($form_section_path, 0, $next_slash_pos); |
|
1530 | + $subpath = substr($form_section_path, $next_slash_pos + 1); |
|
1531 | + } else { |
|
1532 | + $child_section_name = $form_section_path; |
|
1533 | + $subpath = ''; |
|
1534 | + } |
|
1535 | + $child_section = $this->get_subsection($child_section_name); |
|
1536 | + if ($child_section instanceof EE_Form_Section_Base) { |
|
1537 | + return $child_section->find_section_from_path($subpath); |
|
1538 | + } |
|
1539 | + return null; |
|
1540 | + } |
|
1541 | 1541 | } |
1542 | 1542 |
@@ -20,590 +20,590 @@ |
||
20 | 20 | class Request implements InterminableInterface, RequestInterface |
21 | 21 | { |
22 | 22 | |
23 | - /** |
|
24 | - * $_GET parameters |
|
25 | - * |
|
26 | - * @var array $get |
|
27 | - */ |
|
28 | - private $get; |
|
29 | - |
|
30 | - /** |
|
31 | - * $_POST parameters |
|
32 | - * |
|
33 | - * @var array $post |
|
34 | - */ |
|
35 | - private $post; |
|
36 | - |
|
37 | - /** |
|
38 | - * $_COOKIE parameters |
|
39 | - * |
|
40 | - * @var array $cookie |
|
41 | - */ |
|
42 | - private $cookie; |
|
43 | - |
|
44 | - /** |
|
45 | - * $_SERVER parameters |
|
46 | - * |
|
47 | - * @var array $server |
|
48 | - */ |
|
49 | - private $server; |
|
50 | - |
|
51 | - /** |
|
52 | - * $_REQUEST parameters |
|
53 | - * |
|
54 | - * @var array $request |
|
55 | - */ |
|
56 | - private $request; |
|
57 | - |
|
58 | - /** |
|
59 | - * @var RequestTypeContextCheckerInterface |
|
60 | - */ |
|
61 | - private $request_type; |
|
62 | - |
|
63 | - /** |
|
64 | - * IP address for request |
|
65 | - * |
|
66 | - * @var string $ip_address |
|
67 | - */ |
|
68 | - private $ip_address; |
|
69 | - |
|
70 | - /** |
|
71 | - * @var string $user_agent |
|
72 | - */ |
|
73 | - private $user_agent; |
|
74 | - |
|
75 | - /** |
|
76 | - * true if current user appears to be some kind of bot |
|
77 | - * |
|
78 | - * @var bool $is_bot |
|
79 | - */ |
|
80 | - private $is_bot; |
|
81 | - |
|
82 | - |
|
83 | - |
|
84 | - /** |
|
85 | - * @param array $get |
|
86 | - * @param array $post |
|
87 | - * @param array $cookie |
|
88 | - * @param array $server |
|
89 | - */ |
|
90 | - public function __construct(array $get, array $post, array $cookie, array $server) |
|
91 | - { |
|
92 | - // grab request vars |
|
93 | - $this->get = $get; |
|
94 | - $this->post = $post; |
|
95 | - $this->cookie = $cookie; |
|
96 | - $this->server = $server; |
|
97 | - $this->request = array_merge($this->get, $this->post); |
|
98 | - $this->ip_address = $this->visitorIp(); |
|
99 | - } |
|
100 | - |
|
101 | - |
|
102 | - /** |
|
103 | - * @param RequestTypeContextCheckerInterface $type |
|
104 | - */ |
|
105 | - public function setRequestTypeContextChecker(RequestTypeContextCheckerInterface $type) |
|
106 | - { |
|
107 | - $this->request_type = $type; |
|
108 | - } |
|
109 | - |
|
110 | - |
|
111 | - |
|
112 | - /** |
|
113 | - * @return array |
|
114 | - */ |
|
115 | - public function getParams() |
|
116 | - { |
|
117 | - return $this->get; |
|
118 | - } |
|
119 | - |
|
120 | - |
|
121 | - |
|
122 | - /** |
|
123 | - * @return array |
|
124 | - */ |
|
125 | - public function postParams() |
|
126 | - { |
|
127 | - return $this->post; |
|
128 | - } |
|
129 | - |
|
130 | - |
|
131 | - |
|
132 | - /** |
|
133 | - * @return array |
|
134 | - */ |
|
135 | - public function cookieParams() |
|
136 | - { |
|
137 | - return $this->cookie; |
|
138 | - } |
|
139 | - |
|
140 | - |
|
141 | - /** |
|
142 | - * @return array |
|
143 | - */ |
|
144 | - public function serverParams() |
|
145 | - { |
|
146 | - return $this->server; |
|
147 | - } |
|
148 | - |
|
149 | - |
|
150 | - |
|
151 | - /** |
|
152 | - * returns contents of $_REQUEST |
|
153 | - * |
|
154 | - * @return array |
|
155 | - */ |
|
156 | - public function requestParams() |
|
157 | - { |
|
158 | - return $this->request; |
|
159 | - } |
|
160 | - |
|
161 | - |
|
162 | - |
|
163 | - /** |
|
164 | - * @param $key |
|
165 | - * @param $value |
|
166 | - * @param bool $override_ee |
|
167 | - * @return void |
|
168 | - */ |
|
169 | - public function setRequestParam($key, $value, $override_ee = false) |
|
170 | - { |
|
171 | - // don't allow "ee" to be overwritten unless explicitly instructed to do so |
|
172 | - if ( |
|
173 | - $key !== 'ee' |
|
174 | - || ($key === 'ee' && empty($this->request['ee'])) |
|
175 | - || ($key === 'ee' && ! empty($this->request['ee']) && $override_ee) |
|
176 | - ) { |
|
177 | - $this->request[ $key ] = $value; |
|
178 | - } |
|
179 | - } |
|
180 | - |
|
181 | - |
|
182 | - |
|
183 | - /** |
|
184 | - * returns the value for a request param if the given key exists |
|
185 | - * |
|
186 | - * @param $key |
|
187 | - * @param null $default |
|
188 | - * @return mixed |
|
189 | - */ |
|
190 | - public function getRequestParam($key, $default = null) |
|
191 | - { |
|
192 | - return $this->requestParameterDrillDown($key, $default, 'get'); |
|
193 | - } |
|
194 | - |
|
195 | - |
|
196 | - |
|
197 | - /** |
|
198 | - * check if param exists |
|
199 | - * |
|
200 | - * @param $key |
|
201 | - * @return bool |
|
202 | - */ |
|
203 | - public function requestParamIsSet($key) |
|
204 | - { |
|
205 | - return $this->requestParameterDrillDown($key); |
|
206 | - } |
|
207 | - |
|
208 | - |
|
209 | - /** |
|
210 | - * check if a request parameter exists whose key that matches the supplied wildcard pattern |
|
211 | - * and return the value for the first match found |
|
212 | - * wildcards can be either of the following: |
|
213 | - * ? to represent a single character of any type |
|
214 | - * * to represent one or more characters of any type |
|
215 | - * |
|
216 | - * @param string $pattern |
|
217 | - * @param null|mixed $default |
|
218 | - * @return false|int |
|
219 | - */ |
|
220 | - public function getMatch($pattern, $default = null) |
|
221 | - { |
|
222 | - return $this->requestParameterDrillDown($pattern, $default, 'match'); |
|
223 | - } |
|
224 | - |
|
225 | - |
|
226 | - /** |
|
227 | - * check if a request parameter exists whose key matches the supplied wildcard pattern |
|
228 | - * wildcards can be either of the following: |
|
229 | - * ? to represent a single character of any type |
|
230 | - * * to represent one or more characters of any type |
|
231 | - * returns true if a match is found or false if not |
|
232 | - * |
|
233 | - * @param string $pattern |
|
234 | - * @return false|int |
|
235 | - */ |
|
236 | - public function matches($pattern) |
|
237 | - { |
|
238 | - return $this->requestParameterDrillDown($pattern, null, 'match') !== null; |
|
239 | - } |
|
240 | - |
|
241 | - |
|
242 | - /** |
|
243 | - * @see https://stackoverflow.com/questions/6163055/php-string-matching-with-wildcard |
|
244 | - * @param string $pattern A string including wildcards to be converted to a regex pattern |
|
245 | - * and used to search through the current request's parameter keys |
|
246 | - * @param array $request_params The array of request parameters to search through |
|
247 | - * @param mixed $default [optional] The value to be returned if no match is found. |
|
248 | - * Default is null |
|
249 | - * @param string $return [optional] Controls what kind of value is returned. |
|
250 | - * Options are: |
|
251 | - * 'bool' will return true or false if match is found or not |
|
252 | - * 'key' will return the first key found that matches the supplied pattern |
|
253 | - * 'value' will return the value for the first request parameter |
|
254 | - * whose key matches the supplied pattern |
|
255 | - * Default is 'value' |
|
256 | - * @return boolean|string |
|
257 | - */ |
|
258 | - private function match($pattern, array $request_params, $default = null, $return = 'value') |
|
259 | - { |
|
260 | - $return = in_array($return, array('bool', 'key', 'value'), true) |
|
261 | - ? $return |
|
262 | - : 'is_set'; |
|
263 | - // replace wildcard chars with regex chars |
|
264 | - $pattern = str_replace( |
|
265 | - array("\*", "\?"), |
|
266 | - array('.*', '.'), |
|
267 | - preg_quote($pattern, '/') |
|
268 | - ); |
|
269 | - foreach ($request_params as $key => $request_param) { |
|
270 | - if (preg_match('/^' . $pattern . '$/is', $key)) { |
|
271 | - // return value for request param |
|
272 | - if ($return === 'value') { |
|
273 | - return $request_params[ $key ]; |
|
274 | - } |
|
275 | - // or actual key or true just to indicate it was found |
|
276 | - return $return === 'key' ? $key : true; |
|
277 | - } |
|
278 | - } |
|
279 | - // match not found so return default value or false |
|
280 | - return $return === 'value' ? $default : false; |
|
281 | - } |
|
282 | - |
|
283 | - |
|
284 | - /** |
|
285 | - * the supplied key can be a simple string to represent a "top-level" request parameter |
|
286 | - * or represent a key for a request parameter that is nested deeper within the request parameter array, |
|
287 | - * by using square brackets to surround keys for deeper array elements. |
|
288 | - * For example : |
|
289 | - * if the supplied $key was: "first[second][third]" |
|
290 | - * then this will attempt to drill down into the request parameter array to find a value. |
|
291 | - * Given the following request parameters: |
|
292 | - * array( |
|
293 | - * 'first' => array( |
|
294 | - * 'second' => array( |
|
295 | - * 'third' => 'has a value' |
|
296 | - * ) |
|
297 | - * ) |
|
298 | - * ) |
|
299 | - * would return true if default parameters were set |
|
300 | - * |
|
301 | - * @param string $callback |
|
302 | - * @param $key |
|
303 | - * @param null $default |
|
304 | - * @param array $request_params |
|
305 | - * @return bool|mixed|null |
|
306 | - */ |
|
307 | - private function requestParameterDrillDown( |
|
308 | - $key, |
|
309 | - $default = null, |
|
310 | - $callback = 'is_set', |
|
311 | - array $request_params = array() |
|
312 | - ) { |
|
313 | - $callback = in_array($callback, array('is_set', 'get', 'match'), true) |
|
314 | - ? $callback |
|
315 | - : 'is_set'; |
|
316 | - $request_params = ! empty($request_params) |
|
317 | - ? $request_params |
|
318 | - : $this->request; |
|
319 | - // does incoming key represent an array like 'first[second][third]' ? |
|
320 | - if (strpos($key, '[') !== false) { |
|
321 | - // turn it into an actual array |
|
322 | - $key = str_replace(']', '', $key); |
|
323 | - $keys = explode('[', $key); |
|
324 | - $key = array_shift($keys); |
|
325 | - if ($callback === 'match') { |
|
326 | - $real_key = $this->match($key, $request_params, $default, 'key'); |
|
327 | - $key = $real_key ? $real_key : $key; |
|
328 | - } |
|
329 | - // check if top level key exists |
|
330 | - if (isset($request_params[ $key ])) { |
|
331 | - // build a new key to pass along like: 'second[third]' |
|
332 | - // or just 'second' depending on depth of keys |
|
333 | - $key_string = array_shift($keys); |
|
334 | - if (! empty($keys)) { |
|
335 | - $key_string .= '[' . implode('][', $keys) . ']'; |
|
336 | - } |
|
337 | - return $this->requestParameterDrillDown( |
|
338 | - $key_string, |
|
339 | - $default, |
|
340 | - $callback, |
|
341 | - $request_params[ $key ] |
|
342 | - ); |
|
343 | - } |
|
344 | - } |
|
345 | - if ($callback === 'is_set') { |
|
346 | - return isset($request_params[ $key ]); |
|
347 | - } |
|
348 | - if ($callback === 'match') { |
|
349 | - return $this->match($key, $request_params, $default); |
|
350 | - } |
|
351 | - return isset($request_params[ $key ]) |
|
352 | - ? $request_params[ $key ] |
|
353 | - : $default; |
|
354 | - } |
|
355 | - |
|
356 | - |
|
357 | - /** |
|
358 | - * remove param |
|
359 | - * |
|
360 | - * @param $key |
|
361 | - * @param bool $unset_from_global_too |
|
362 | - */ |
|
363 | - public function unSetRequestParam($key, $unset_from_global_too = false) |
|
364 | - { |
|
365 | - unset($this->request[ $key ]); |
|
366 | - if ($unset_from_global_too) { |
|
367 | - unset($_REQUEST[ $key ]); |
|
368 | - } |
|
369 | - } |
|
370 | - |
|
371 | - |
|
372 | - |
|
373 | - /** |
|
374 | - * @return string |
|
375 | - */ |
|
376 | - public function ipAddress() |
|
377 | - { |
|
378 | - return $this->ip_address; |
|
379 | - } |
|
380 | - |
|
381 | - |
|
382 | - /** |
|
383 | - * attempt to get IP address of current visitor from server |
|
384 | - * plz see: http://stackoverflow.com/a/2031935/1475279 |
|
385 | - * |
|
386 | - * @access public |
|
387 | - * @return string |
|
388 | - */ |
|
389 | - private function visitorIp() |
|
390 | - { |
|
391 | - $visitor_ip = '0.0.0.0'; |
|
392 | - $server_keys = array( |
|
393 | - 'HTTP_CLIENT_IP', |
|
394 | - 'HTTP_X_FORWARDED_FOR', |
|
395 | - 'HTTP_X_FORWARDED', |
|
396 | - 'HTTP_X_CLUSTER_CLIENT_IP', |
|
397 | - 'HTTP_FORWARDED_FOR', |
|
398 | - 'HTTP_FORWARDED', |
|
399 | - 'REMOTE_ADDR', |
|
400 | - ); |
|
401 | - foreach ($server_keys as $key) { |
|
402 | - if (isset($this->server[ $key ])) { |
|
403 | - foreach (array_map('trim', explode(',', $this->server[ $key ])) as $ip) { |
|
404 | - if ($ip === '127.0.0.1' || filter_var($ip, FILTER_VALIDATE_IP) !== false) { |
|
405 | - $visitor_ip = $ip; |
|
406 | - } |
|
407 | - } |
|
408 | - } |
|
409 | - } |
|
410 | - return $visitor_ip; |
|
411 | - } |
|
412 | - |
|
413 | - |
|
414 | - /** |
|
415 | - * @return string |
|
416 | - */ |
|
417 | - public function requestUri() |
|
418 | - { |
|
419 | - $request_uri = filter_input( |
|
420 | - INPUT_SERVER, |
|
421 | - 'REQUEST_URI', |
|
422 | - FILTER_SANITIZE_URL, |
|
423 | - FILTER_NULL_ON_FAILURE |
|
424 | - ); |
|
425 | - if (empty($request_uri)) { |
|
426 | - // fallback sanitization if the above fails |
|
427 | - $request_uri = wp_sanitize_redirect($this->server['REQUEST_URI']); |
|
428 | - } |
|
429 | - return $request_uri; |
|
430 | - } |
|
431 | - |
|
432 | - |
|
433 | - /** |
|
434 | - * @return string |
|
435 | - */ |
|
436 | - public function userAgent() |
|
437 | - { |
|
438 | - return $this->user_agent; |
|
439 | - } |
|
440 | - |
|
441 | - |
|
442 | - /** |
|
443 | - * @param string $user_agent |
|
444 | - */ |
|
445 | - public function setUserAgent($user_agent = '') |
|
446 | - { |
|
447 | - if ($user_agent === '' || ! is_string($user_agent)) { |
|
448 | - $user_agent = isset($_SERVER['HTTP_USER_AGENT']) ? (string) esc_attr($_SERVER['HTTP_USER_AGENT']) : ''; |
|
449 | - } |
|
450 | - $this->user_agent = $user_agent; |
|
451 | - } |
|
452 | - |
|
453 | - |
|
454 | - /** |
|
455 | - * @return bool |
|
456 | - */ |
|
457 | - public function isBot() |
|
458 | - { |
|
459 | - return $this->is_bot; |
|
460 | - } |
|
461 | - |
|
462 | - |
|
463 | - /** |
|
464 | - * @param bool $is_bot |
|
465 | - */ |
|
466 | - public function setIsBot($is_bot) |
|
467 | - { |
|
468 | - $this->is_bot = filter_var($is_bot, FILTER_VALIDATE_BOOLEAN); |
|
469 | - } |
|
470 | - |
|
471 | - |
|
472 | - /** |
|
473 | - * @return bool |
|
474 | - */ |
|
475 | - public function isActivation() |
|
476 | - { |
|
477 | - return $this->request_type->isActivation(); |
|
478 | - } |
|
479 | - |
|
480 | - |
|
481 | - /** |
|
482 | - * @param $is_activation |
|
483 | - * @return bool |
|
484 | - */ |
|
485 | - public function setIsActivation($is_activation) |
|
486 | - { |
|
487 | - return $this->request_type->setIsActivation($is_activation); |
|
488 | - } |
|
489 | - |
|
490 | - |
|
491 | - /** |
|
492 | - * @return bool |
|
493 | - */ |
|
494 | - public function isAdmin() |
|
495 | - { |
|
496 | - return $this->request_type->isAdmin(); |
|
497 | - } |
|
498 | - |
|
499 | - |
|
500 | - /** |
|
501 | - * @return bool |
|
502 | - */ |
|
503 | - public function isAdminAjax() |
|
504 | - { |
|
505 | - return $this->request_type->isAdminAjax(); |
|
506 | - } |
|
507 | - |
|
508 | - |
|
509 | - /** |
|
510 | - * @return bool |
|
511 | - */ |
|
512 | - public function isAjax() |
|
513 | - { |
|
514 | - return $this->request_type->isAjax(); |
|
515 | - } |
|
516 | - |
|
517 | - |
|
518 | - /** |
|
519 | - * @return bool |
|
520 | - */ |
|
521 | - public function isEeAjax() |
|
522 | - { |
|
523 | - return $this->request_type->isEeAjax(); |
|
524 | - } |
|
525 | - |
|
526 | - |
|
527 | - /** |
|
528 | - * @return bool |
|
529 | - */ |
|
530 | - public function isOtherAjax() |
|
531 | - { |
|
532 | - return $this->request_type->isOtherAjax(); |
|
533 | - } |
|
534 | - |
|
535 | - |
|
536 | - /** |
|
537 | - * @return bool |
|
538 | - */ |
|
539 | - public function isApi() |
|
540 | - { |
|
541 | - return $this->request_type->isApi(); |
|
542 | - } |
|
543 | - |
|
544 | - |
|
545 | - /** |
|
546 | - * @return bool |
|
547 | - */ |
|
548 | - public function isCli() |
|
549 | - { |
|
550 | - return $this->request_type->isCli(); |
|
551 | - } |
|
552 | - |
|
553 | - |
|
554 | - /** |
|
555 | - * @return bool |
|
556 | - */ |
|
557 | - public function isCron() |
|
558 | - { |
|
559 | - return $this->request_type->isCron(); |
|
560 | - } |
|
561 | - |
|
562 | - |
|
563 | - /** |
|
564 | - * @return bool |
|
565 | - */ |
|
566 | - public function isFeed() |
|
567 | - { |
|
568 | - return $this->request_type->isFeed(); |
|
569 | - } |
|
570 | - |
|
571 | - |
|
572 | - /** |
|
573 | - * @return bool |
|
574 | - */ |
|
575 | - public function isFrontend() |
|
576 | - { |
|
577 | - return $this->request_type->isFrontend(); |
|
578 | - } |
|
579 | - |
|
580 | - |
|
581 | - /** |
|
582 | - * @return bool |
|
583 | - */ |
|
584 | - public function isFrontAjax() |
|
585 | - { |
|
586 | - return $this->request_type->isFrontAjax(); |
|
587 | - } |
|
588 | - |
|
589 | - |
|
590 | - |
|
591 | - /** |
|
592 | - * @return bool |
|
593 | - */ |
|
594 | - public function isIframe() |
|
595 | - { |
|
596 | - return $this->request_type->isIframe(); |
|
597 | - } |
|
598 | - |
|
599 | - |
|
600 | - /** |
|
601 | - * @return string |
|
602 | - */ |
|
603 | - public function slug() |
|
604 | - { |
|
605 | - return $this->request_type->slug(); |
|
606 | - } |
|
23 | + /** |
|
24 | + * $_GET parameters |
|
25 | + * |
|
26 | + * @var array $get |
|
27 | + */ |
|
28 | + private $get; |
|
29 | + |
|
30 | + /** |
|
31 | + * $_POST parameters |
|
32 | + * |
|
33 | + * @var array $post |
|
34 | + */ |
|
35 | + private $post; |
|
36 | + |
|
37 | + /** |
|
38 | + * $_COOKIE parameters |
|
39 | + * |
|
40 | + * @var array $cookie |
|
41 | + */ |
|
42 | + private $cookie; |
|
43 | + |
|
44 | + /** |
|
45 | + * $_SERVER parameters |
|
46 | + * |
|
47 | + * @var array $server |
|
48 | + */ |
|
49 | + private $server; |
|
50 | + |
|
51 | + /** |
|
52 | + * $_REQUEST parameters |
|
53 | + * |
|
54 | + * @var array $request |
|
55 | + */ |
|
56 | + private $request; |
|
57 | + |
|
58 | + /** |
|
59 | + * @var RequestTypeContextCheckerInterface |
|
60 | + */ |
|
61 | + private $request_type; |
|
62 | + |
|
63 | + /** |
|
64 | + * IP address for request |
|
65 | + * |
|
66 | + * @var string $ip_address |
|
67 | + */ |
|
68 | + private $ip_address; |
|
69 | + |
|
70 | + /** |
|
71 | + * @var string $user_agent |
|
72 | + */ |
|
73 | + private $user_agent; |
|
74 | + |
|
75 | + /** |
|
76 | + * true if current user appears to be some kind of bot |
|
77 | + * |
|
78 | + * @var bool $is_bot |
|
79 | + */ |
|
80 | + private $is_bot; |
|
81 | + |
|
82 | + |
|
83 | + |
|
84 | + /** |
|
85 | + * @param array $get |
|
86 | + * @param array $post |
|
87 | + * @param array $cookie |
|
88 | + * @param array $server |
|
89 | + */ |
|
90 | + public function __construct(array $get, array $post, array $cookie, array $server) |
|
91 | + { |
|
92 | + // grab request vars |
|
93 | + $this->get = $get; |
|
94 | + $this->post = $post; |
|
95 | + $this->cookie = $cookie; |
|
96 | + $this->server = $server; |
|
97 | + $this->request = array_merge($this->get, $this->post); |
|
98 | + $this->ip_address = $this->visitorIp(); |
|
99 | + } |
|
100 | + |
|
101 | + |
|
102 | + /** |
|
103 | + * @param RequestTypeContextCheckerInterface $type |
|
104 | + */ |
|
105 | + public function setRequestTypeContextChecker(RequestTypeContextCheckerInterface $type) |
|
106 | + { |
|
107 | + $this->request_type = $type; |
|
108 | + } |
|
109 | + |
|
110 | + |
|
111 | + |
|
112 | + /** |
|
113 | + * @return array |
|
114 | + */ |
|
115 | + public function getParams() |
|
116 | + { |
|
117 | + return $this->get; |
|
118 | + } |
|
119 | + |
|
120 | + |
|
121 | + |
|
122 | + /** |
|
123 | + * @return array |
|
124 | + */ |
|
125 | + public function postParams() |
|
126 | + { |
|
127 | + return $this->post; |
|
128 | + } |
|
129 | + |
|
130 | + |
|
131 | + |
|
132 | + /** |
|
133 | + * @return array |
|
134 | + */ |
|
135 | + public function cookieParams() |
|
136 | + { |
|
137 | + return $this->cookie; |
|
138 | + } |
|
139 | + |
|
140 | + |
|
141 | + /** |
|
142 | + * @return array |
|
143 | + */ |
|
144 | + public function serverParams() |
|
145 | + { |
|
146 | + return $this->server; |
|
147 | + } |
|
148 | + |
|
149 | + |
|
150 | + |
|
151 | + /** |
|
152 | + * returns contents of $_REQUEST |
|
153 | + * |
|
154 | + * @return array |
|
155 | + */ |
|
156 | + public function requestParams() |
|
157 | + { |
|
158 | + return $this->request; |
|
159 | + } |
|
160 | + |
|
161 | + |
|
162 | + |
|
163 | + /** |
|
164 | + * @param $key |
|
165 | + * @param $value |
|
166 | + * @param bool $override_ee |
|
167 | + * @return void |
|
168 | + */ |
|
169 | + public function setRequestParam($key, $value, $override_ee = false) |
|
170 | + { |
|
171 | + // don't allow "ee" to be overwritten unless explicitly instructed to do so |
|
172 | + if ( |
|
173 | + $key !== 'ee' |
|
174 | + || ($key === 'ee' && empty($this->request['ee'])) |
|
175 | + || ($key === 'ee' && ! empty($this->request['ee']) && $override_ee) |
|
176 | + ) { |
|
177 | + $this->request[ $key ] = $value; |
|
178 | + } |
|
179 | + } |
|
180 | + |
|
181 | + |
|
182 | + |
|
183 | + /** |
|
184 | + * returns the value for a request param if the given key exists |
|
185 | + * |
|
186 | + * @param $key |
|
187 | + * @param null $default |
|
188 | + * @return mixed |
|
189 | + */ |
|
190 | + public function getRequestParam($key, $default = null) |
|
191 | + { |
|
192 | + return $this->requestParameterDrillDown($key, $default, 'get'); |
|
193 | + } |
|
194 | + |
|
195 | + |
|
196 | + |
|
197 | + /** |
|
198 | + * check if param exists |
|
199 | + * |
|
200 | + * @param $key |
|
201 | + * @return bool |
|
202 | + */ |
|
203 | + public function requestParamIsSet($key) |
|
204 | + { |
|
205 | + return $this->requestParameterDrillDown($key); |
|
206 | + } |
|
207 | + |
|
208 | + |
|
209 | + /** |
|
210 | + * check if a request parameter exists whose key that matches the supplied wildcard pattern |
|
211 | + * and return the value for the first match found |
|
212 | + * wildcards can be either of the following: |
|
213 | + * ? to represent a single character of any type |
|
214 | + * * to represent one or more characters of any type |
|
215 | + * |
|
216 | + * @param string $pattern |
|
217 | + * @param null|mixed $default |
|
218 | + * @return false|int |
|
219 | + */ |
|
220 | + public function getMatch($pattern, $default = null) |
|
221 | + { |
|
222 | + return $this->requestParameterDrillDown($pattern, $default, 'match'); |
|
223 | + } |
|
224 | + |
|
225 | + |
|
226 | + /** |
|
227 | + * check if a request parameter exists whose key matches the supplied wildcard pattern |
|
228 | + * wildcards can be either of the following: |
|
229 | + * ? to represent a single character of any type |
|
230 | + * * to represent one or more characters of any type |
|
231 | + * returns true if a match is found or false if not |
|
232 | + * |
|
233 | + * @param string $pattern |
|
234 | + * @return false|int |
|
235 | + */ |
|
236 | + public function matches($pattern) |
|
237 | + { |
|
238 | + return $this->requestParameterDrillDown($pattern, null, 'match') !== null; |
|
239 | + } |
|
240 | + |
|
241 | + |
|
242 | + /** |
|
243 | + * @see https://stackoverflow.com/questions/6163055/php-string-matching-with-wildcard |
|
244 | + * @param string $pattern A string including wildcards to be converted to a regex pattern |
|
245 | + * and used to search through the current request's parameter keys |
|
246 | + * @param array $request_params The array of request parameters to search through |
|
247 | + * @param mixed $default [optional] The value to be returned if no match is found. |
|
248 | + * Default is null |
|
249 | + * @param string $return [optional] Controls what kind of value is returned. |
|
250 | + * Options are: |
|
251 | + * 'bool' will return true or false if match is found or not |
|
252 | + * 'key' will return the first key found that matches the supplied pattern |
|
253 | + * 'value' will return the value for the first request parameter |
|
254 | + * whose key matches the supplied pattern |
|
255 | + * Default is 'value' |
|
256 | + * @return boolean|string |
|
257 | + */ |
|
258 | + private function match($pattern, array $request_params, $default = null, $return = 'value') |
|
259 | + { |
|
260 | + $return = in_array($return, array('bool', 'key', 'value'), true) |
|
261 | + ? $return |
|
262 | + : 'is_set'; |
|
263 | + // replace wildcard chars with regex chars |
|
264 | + $pattern = str_replace( |
|
265 | + array("\*", "\?"), |
|
266 | + array('.*', '.'), |
|
267 | + preg_quote($pattern, '/') |
|
268 | + ); |
|
269 | + foreach ($request_params as $key => $request_param) { |
|
270 | + if (preg_match('/^' . $pattern . '$/is', $key)) { |
|
271 | + // return value for request param |
|
272 | + if ($return === 'value') { |
|
273 | + return $request_params[ $key ]; |
|
274 | + } |
|
275 | + // or actual key or true just to indicate it was found |
|
276 | + return $return === 'key' ? $key : true; |
|
277 | + } |
|
278 | + } |
|
279 | + // match not found so return default value or false |
|
280 | + return $return === 'value' ? $default : false; |
|
281 | + } |
|
282 | + |
|
283 | + |
|
284 | + /** |
|
285 | + * the supplied key can be a simple string to represent a "top-level" request parameter |
|
286 | + * or represent a key for a request parameter that is nested deeper within the request parameter array, |
|
287 | + * by using square brackets to surround keys for deeper array elements. |
|
288 | + * For example : |
|
289 | + * if the supplied $key was: "first[second][third]" |
|
290 | + * then this will attempt to drill down into the request parameter array to find a value. |
|
291 | + * Given the following request parameters: |
|
292 | + * array( |
|
293 | + * 'first' => array( |
|
294 | + * 'second' => array( |
|
295 | + * 'third' => 'has a value' |
|
296 | + * ) |
|
297 | + * ) |
|
298 | + * ) |
|
299 | + * would return true if default parameters were set |
|
300 | + * |
|
301 | + * @param string $callback |
|
302 | + * @param $key |
|
303 | + * @param null $default |
|
304 | + * @param array $request_params |
|
305 | + * @return bool|mixed|null |
|
306 | + */ |
|
307 | + private function requestParameterDrillDown( |
|
308 | + $key, |
|
309 | + $default = null, |
|
310 | + $callback = 'is_set', |
|
311 | + array $request_params = array() |
|
312 | + ) { |
|
313 | + $callback = in_array($callback, array('is_set', 'get', 'match'), true) |
|
314 | + ? $callback |
|
315 | + : 'is_set'; |
|
316 | + $request_params = ! empty($request_params) |
|
317 | + ? $request_params |
|
318 | + : $this->request; |
|
319 | + // does incoming key represent an array like 'first[second][third]' ? |
|
320 | + if (strpos($key, '[') !== false) { |
|
321 | + // turn it into an actual array |
|
322 | + $key = str_replace(']', '', $key); |
|
323 | + $keys = explode('[', $key); |
|
324 | + $key = array_shift($keys); |
|
325 | + if ($callback === 'match') { |
|
326 | + $real_key = $this->match($key, $request_params, $default, 'key'); |
|
327 | + $key = $real_key ? $real_key : $key; |
|
328 | + } |
|
329 | + // check if top level key exists |
|
330 | + if (isset($request_params[ $key ])) { |
|
331 | + // build a new key to pass along like: 'second[third]' |
|
332 | + // or just 'second' depending on depth of keys |
|
333 | + $key_string = array_shift($keys); |
|
334 | + if (! empty($keys)) { |
|
335 | + $key_string .= '[' . implode('][', $keys) . ']'; |
|
336 | + } |
|
337 | + return $this->requestParameterDrillDown( |
|
338 | + $key_string, |
|
339 | + $default, |
|
340 | + $callback, |
|
341 | + $request_params[ $key ] |
|
342 | + ); |
|
343 | + } |
|
344 | + } |
|
345 | + if ($callback === 'is_set') { |
|
346 | + return isset($request_params[ $key ]); |
|
347 | + } |
|
348 | + if ($callback === 'match') { |
|
349 | + return $this->match($key, $request_params, $default); |
|
350 | + } |
|
351 | + return isset($request_params[ $key ]) |
|
352 | + ? $request_params[ $key ] |
|
353 | + : $default; |
|
354 | + } |
|
355 | + |
|
356 | + |
|
357 | + /** |
|
358 | + * remove param |
|
359 | + * |
|
360 | + * @param $key |
|
361 | + * @param bool $unset_from_global_too |
|
362 | + */ |
|
363 | + public function unSetRequestParam($key, $unset_from_global_too = false) |
|
364 | + { |
|
365 | + unset($this->request[ $key ]); |
|
366 | + if ($unset_from_global_too) { |
|
367 | + unset($_REQUEST[ $key ]); |
|
368 | + } |
|
369 | + } |
|
370 | + |
|
371 | + |
|
372 | + |
|
373 | + /** |
|
374 | + * @return string |
|
375 | + */ |
|
376 | + public function ipAddress() |
|
377 | + { |
|
378 | + return $this->ip_address; |
|
379 | + } |
|
380 | + |
|
381 | + |
|
382 | + /** |
|
383 | + * attempt to get IP address of current visitor from server |
|
384 | + * plz see: http://stackoverflow.com/a/2031935/1475279 |
|
385 | + * |
|
386 | + * @access public |
|
387 | + * @return string |
|
388 | + */ |
|
389 | + private function visitorIp() |
|
390 | + { |
|
391 | + $visitor_ip = '0.0.0.0'; |
|
392 | + $server_keys = array( |
|
393 | + 'HTTP_CLIENT_IP', |
|
394 | + 'HTTP_X_FORWARDED_FOR', |
|
395 | + 'HTTP_X_FORWARDED', |
|
396 | + 'HTTP_X_CLUSTER_CLIENT_IP', |
|
397 | + 'HTTP_FORWARDED_FOR', |
|
398 | + 'HTTP_FORWARDED', |
|
399 | + 'REMOTE_ADDR', |
|
400 | + ); |
|
401 | + foreach ($server_keys as $key) { |
|
402 | + if (isset($this->server[ $key ])) { |
|
403 | + foreach (array_map('trim', explode(',', $this->server[ $key ])) as $ip) { |
|
404 | + if ($ip === '127.0.0.1' || filter_var($ip, FILTER_VALIDATE_IP) !== false) { |
|
405 | + $visitor_ip = $ip; |
|
406 | + } |
|
407 | + } |
|
408 | + } |
|
409 | + } |
|
410 | + return $visitor_ip; |
|
411 | + } |
|
412 | + |
|
413 | + |
|
414 | + /** |
|
415 | + * @return string |
|
416 | + */ |
|
417 | + public function requestUri() |
|
418 | + { |
|
419 | + $request_uri = filter_input( |
|
420 | + INPUT_SERVER, |
|
421 | + 'REQUEST_URI', |
|
422 | + FILTER_SANITIZE_URL, |
|
423 | + FILTER_NULL_ON_FAILURE |
|
424 | + ); |
|
425 | + if (empty($request_uri)) { |
|
426 | + // fallback sanitization if the above fails |
|
427 | + $request_uri = wp_sanitize_redirect($this->server['REQUEST_URI']); |
|
428 | + } |
|
429 | + return $request_uri; |
|
430 | + } |
|
431 | + |
|
432 | + |
|
433 | + /** |
|
434 | + * @return string |
|
435 | + */ |
|
436 | + public function userAgent() |
|
437 | + { |
|
438 | + return $this->user_agent; |
|
439 | + } |
|
440 | + |
|
441 | + |
|
442 | + /** |
|
443 | + * @param string $user_agent |
|
444 | + */ |
|
445 | + public function setUserAgent($user_agent = '') |
|
446 | + { |
|
447 | + if ($user_agent === '' || ! is_string($user_agent)) { |
|
448 | + $user_agent = isset($_SERVER['HTTP_USER_AGENT']) ? (string) esc_attr($_SERVER['HTTP_USER_AGENT']) : ''; |
|
449 | + } |
|
450 | + $this->user_agent = $user_agent; |
|
451 | + } |
|
452 | + |
|
453 | + |
|
454 | + /** |
|
455 | + * @return bool |
|
456 | + */ |
|
457 | + public function isBot() |
|
458 | + { |
|
459 | + return $this->is_bot; |
|
460 | + } |
|
461 | + |
|
462 | + |
|
463 | + /** |
|
464 | + * @param bool $is_bot |
|
465 | + */ |
|
466 | + public function setIsBot($is_bot) |
|
467 | + { |
|
468 | + $this->is_bot = filter_var($is_bot, FILTER_VALIDATE_BOOLEAN); |
|
469 | + } |
|
470 | + |
|
471 | + |
|
472 | + /** |
|
473 | + * @return bool |
|
474 | + */ |
|
475 | + public function isActivation() |
|
476 | + { |
|
477 | + return $this->request_type->isActivation(); |
|
478 | + } |
|
479 | + |
|
480 | + |
|
481 | + /** |
|
482 | + * @param $is_activation |
|
483 | + * @return bool |
|
484 | + */ |
|
485 | + public function setIsActivation($is_activation) |
|
486 | + { |
|
487 | + return $this->request_type->setIsActivation($is_activation); |
|
488 | + } |
|
489 | + |
|
490 | + |
|
491 | + /** |
|
492 | + * @return bool |
|
493 | + */ |
|
494 | + public function isAdmin() |
|
495 | + { |
|
496 | + return $this->request_type->isAdmin(); |
|
497 | + } |
|
498 | + |
|
499 | + |
|
500 | + /** |
|
501 | + * @return bool |
|
502 | + */ |
|
503 | + public function isAdminAjax() |
|
504 | + { |
|
505 | + return $this->request_type->isAdminAjax(); |
|
506 | + } |
|
507 | + |
|
508 | + |
|
509 | + /** |
|
510 | + * @return bool |
|
511 | + */ |
|
512 | + public function isAjax() |
|
513 | + { |
|
514 | + return $this->request_type->isAjax(); |
|
515 | + } |
|
516 | + |
|
517 | + |
|
518 | + /** |
|
519 | + * @return bool |
|
520 | + */ |
|
521 | + public function isEeAjax() |
|
522 | + { |
|
523 | + return $this->request_type->isEeAjax(); |
|
524 | + } |
|
525 | + |
|
526 | + |
|
527 | + /** |
|
528 | + * @return bool |
|
529 | + */ |
|
530 | + public function isOtherAjax() |
|
531 | + { |
|
532 | + return $this->request_type->isOtherAjax(); |
|
533 | + } |
|
534 | + |
|
535 | + |
|
536 | + /** |
|
537 | + * @return bool |
|
538 | + */ |
|
539 | + public function isApi() |
|
540 | + { |
|
541 | + return $this->request_type->isApi(); |
|
542 | + } |
|
543 | + |
|
544 | + |
|
545 | + /** |
|
546 | + * @return bool |
|
547 | + */ |
|
548 | + public function isCli() |
|
549 | + { |
|
550 | + return $this->request_type->isCli(); |
|
551 | + } |
|
552 | + |
|
553 | + |
|
554 | + /** |
|
555 | + * @return bool |
|
556 | + */ |
|
557 | + public function isCron() |
|
558 | + { |
|
559 | + return $this->request_type->isCron(); |
|
560 | + } |
|
561 | + |
|
562 | + |
|
563 | + /** |
|
564 | + * @return bool |
|
565 | + */ |
|
566 | + public function isFeed() |
|
567 | + { |
|
568 | + return $this->request_type->isFeed(); |
|
569 | + } |
|
570 | + |
|
571 | + |
|
572 | + /** |
|
573 | + * @return bool |
|
574 | + */ |
|
575 | + public function isFrontend() |
|
576 | + { |
|
577 | + return $this->request_type->isFrontend(); |
|
578 | + } |
|
579 | + |
|
580 | + |
|
581 | + /** |
|
582 | + * @return bool |
|
583 | + */ |
|
584 | + public function isFrontAjax() |
|
585 | + { |
|
586 | + return $this->request_type->isFrontAjax(); |
|
587 | + } |
|
588 | + |
|
589 | + |
|
590 | + |
|
591 | + /** |
|
592 | + * @return bool |
|
593 | + */ |
|
594 | + public function isIframe() |
|
595 | + { |
|
596 | + return $this->request_type->isIframe(); |
|
597 | + } |
|
598 | + |
|
599 | + |
|
600 | + /** |
|
601 | + * @return string |
|
602 | + */ |
|
603 | + public function slug() |
|
604 | + { |
|
605 | + return $this->request_type->slug(); |
|
606 | + } |
|
607 | 607 | |
608 | 608 | |
609 | 609 | } |
@@ -174,7 +174,7 @@ discard block |
||
174 | 174 | || ($key === 'ee' && empty($this->request['ee'])) |
175 | 175 | || ($key === 'ee' && ! empty($this->request['ee']) && $override_ee) |
176 | 176 | ) { |
177 | - $this->request[ $key ] = $value; |
|
177 | + $this->request[$key] = $value; |
|
178 | 178 | } |
179 | 179 | } |
180 | 180 | |
@@ -267,10 +267,10 @@ discard block |
||
267 | 267 | preg_quote($pattern, '/') |
268 | 268 | ); |
269 | 269 | foreach ($request_params as $key => $request_param) { |
270 | - if (preg_match('/^' . $pattern . '$/is', $key)) { |
|
270 | + if (preg_match('/^'.$pattern.'$/is', $key)) { |
|
271 | 271 | // return value for request param |
272 | 272 | if ($return === 'value') { |
273 | - return $request_params[ $key ]; |
|
273 | + return $request_params[$key]; |
|
274 | 274 | } |
275 | 275 | // or actual key or true just to indicate it was found |
276 | 276 | return $return === 'key' ? $key : true; |
@@ -327,29 +327,29 @@ discard block |
||
327 | 327 | $key = $real_key ? $real_key : $key; |
328 | 328 | } |
329 | 329 | // check if top level key exists |
330 | - if (isset($request_params[ $key ])) { |
|
330 | + if (isset($request_params[$key])) { |
|
331 | 331 | // build a new key to pass along like: 'second[third]' |
332 | 332 | // or just 'second' depending on depth of keys |
333 | 333 | $key_string = array_shift($keys); |
334 | - if (! empty($keys)) { |
|
335 | - $key_string .= '[' . implode('][', $keys) . ']'; |
|
334 | + if ( ! empty($keys)) { |
|
335 | + $key_string .= '['.implode('][', $keys).']'; |
|
336 | 336 | } |
337 | 337 | return $this->requestParameterDrillDown( |
338 | 338 | $key_string, |
339 | 339 | $default, |
340 | 340 | $callback, |
341 | - $request_params[ $key ] |
|
341 | + $request_params[$key] |
|
342 | 342 | ); |
343 | 343 | } |
344 | 344 | } |
345 | 345 | if ($callback === 'is_set') { |
346 | - return isset($request_params[ $key ]); |
|
346 | + return isset($request_params[$key]); |
|
347 | 347 | } |
348 | 348 | if ($callback === 'match') { |
349 | 349 | return $this->match($key, $request_params, $default); |
350 | 350 | } |
351 | - return isset($request_params[ $key ]) |
|
352 | - ? $request_params[ $key ] |
|
351 | + return isset($request_params[$key]) |
|
352 | + ? $request_params[$key] |
|
353 | 353 | : $default; |
354 | 354 | } |
355 | 355 | |
@@ -362,9 +362,9 @@ discard block |
||
362 | 362 | */ |
363 | 363 | public function unSetRequestParam($key, $unset_from_global_too = false) |
364 | 364 | { |
365 | - unset($this->request[ $key ]); |
|
365 | + unset($this->request[$key]); |
|
366 | 366 | if ($unset_from_global_too) { |
367 | - unset($_REQUEST[ $key ]); |
|
367 | + unset($_REQUEST[$key]); |
|
368 | 368 | } |
369 | 369 | } |
370 | 370 | |
@@ -399,8 +399,8 @@ discard block |
||
399 | 399 | 'REMOTE_ADDR', |
400 | 400 | ); |
401 | 401 | foreach ($server_keys as $key) { |
402 | - if (isset($this->server[ $key ])) { |
|
403 | - foreach (array_map('trim', explode(',', $this->server[ $key ])) as $ip) { |
|
402 | + if (isset($this->server[$key])) { |
|
403 | + foreach (array_map('trim', explode(',', $this->server[$key])) as $ip) { |
|
404 | 404 | if ($ip === '127.0.0.1' || filter_var($ip, FILTER_VALIDATE_IP) !== false) { |
405 | 405 | $visitor_ip = $ip; |
406 | 406 | } |
@@ -185,7 +185,7 @@ discard block |
||
185 | 185 | * |
186 | 186 | * @param $key |
187 | 187 | * @param null $default |
188 | - * @return mixed |
|
188 | + * @return integer |
|
189 | 189 | */ |
190 | 190 | public function getRequestParam($key, $default = null) |
191 | 191 | { |
@@ -231,7 +231,7 @@ discard block |
||
231 | 231 | * returns true if a match is found or false if not |
232 | 232 | * |
233 | 233 | * @param string $pattern |
234 | - * @return false|int |
|
234 | + * @return boolean |
|
235 | 235 | */ |
236 | 236 | public function matches($pattern) |
237 | 237 | { |
@@ -299,7 +299,7 @@ discard block |
||
299 | 299 | * would return true if default parameters were set |
300 | 300 | * |
301 | 301 | * @param string $callback |
302 | - * @param $key |
|
302 | + * @param string $key |
|
303 | 303 | * @param null $default |
304 | 304 | * @param array $request_params |
305 | 305 | * @return bool|mixed|null |
@@ -20,139 +20,139 @@ |
||
20 | 20 | interface RequestInterface extends RequestTypeContextCheckerInterface |
21 | 21 | { |
22 | 22 | |
23 | - /** |
|
24 | - * @param RequestTypeContextCheckerInterface $type |
|
25 | - */ |
|
26 | - public function setRequestTypeContextChecker(RequestTypeContextCheckerInterface $type); |
|
27 | - |
|
28 | - /** |
|
29 | - * @return array |
|
30 | - */ |
|
31 | - public function getParams(); |
|
32 | - |
|
33 | - |
|
34 | - /** |
|
35 | - * @return array |
|
36 | - */ |
|
37 | - public function postParams(); |
|
38 | - |
|
39 | - |
|
40 | - /** |
|
41 | - * @return array |
|
42 | - */ |
|
43 | - public function cookieParams(); |
|
44 | - |
|
45 | - |
|
46 | - /** |
|
47 | - * @return array |
|
48 | - */ |
|
49 | - public function serverParams(); |
|
50 | - |
|
51 | - |
|
52 | - /** |
|
53 | - * returns contents of $_REQUEST |
|
54 | - * |
|
55 | - * @return array |
|
56 | - */ |
|
57 | - public function requestParams(); |
|
23 | + /** |
|
24 | + * @param RequestTypeContextCheckerInterface $type |
|
25 | + */ |
|
26 | + public function setRequestTypeContextChecker(RequestTypeContextCheckerInterface $type); |
|
27 | + |
|
28 | + /** |
|
29 | + * @return array |
|
30 | + */ |
|
31 | + public function getParams(); |
|
32 | + |
|
33 | + |
|
34 | + /** |
|
35 | + * @return array |
|
36 | + */ |
|
37 | + public function postParams(); |
|
38 | + |
|
39 | + |
|
40 | + /** |
|
41 | + * @return array |
|
42 | + */ |
|
43 | + public function cookieParams(); |
|
44 | + |
|
45 | + |
|
46 | + /** |
|
47 | + * @return array |
|
48 | + */ |
|
49 | + public function serverParams(); |
|
50 | + |
|
51 | + |
|
52 | + /** |
|
53 | + * returns contents of $_REQUEST |
|
54 | + * |
|
55 | + * @return array |
|
56 | + */ |
|
57 | + public function requestParams(); |
|
58 | 58 | |
59 | 59 | |
60 | - /** |
|
61 | - * @param string $key |
|
62 | - * @param string $value |
|
63 | - * @param bool $override_ee |
|
64 | - * @return void |
|
65 | - */ |
|
66 | - public function setRequestParam($key, $value, $override_ee = false); |
|
60 | + /** |
|
61 | + * @param string $key |
|
62 | + * @param string $value |
|
63 | + * @param bool $override_ee |
|
64 | + * @return void |
|
65 | + */ |
|
66 | + public function setRequestParam($key, $value, $override_ee = false); |
|
67 | 67 | |
68 | 68 | |
69 | - /** |
|
70 | - * returns the value for a request param if the given key exists |
|
71 | - * |
|
72 | - * @param string $key |
|
73 | - * @param null $default |
|
74 | - * @return mixed |
|
75 | - */ |
|
76 | - public function getRequestParam($key, $default = null); |
|
69 | + /** |
|
70 | + * returns the value for a request param if the given key exists |
|
71 | + * |
|
72 | + * @param string $key |
|
73 | + * @param null $default |
|
74 | + * @return mixed |
|
75 | + */ |
|
76 | + public function getRequestParam($key, $default = null); |
|
77 | 77 | |
78 | 78 | |
79 | - /** |
|
80 | - * check if param exists |
|
81 | - * |
|
82 | - * @param string $key |
|
83 | - * @return bool |
|
84 | - */ |
|
85 | - public function requestParamIsSet($key); |
|
79 | + /** |
|
80 | + * check if param exists |
|
81 | + * |
|
82 | + * @param string $key |
|
83 | + * @return bool |
|
84 | + */ |
|
85 | + public function requestParamIsSet($key); |
|
86 | 86 | |
87 | 87 | |
88 | - /** |
|
89 | - * check if a request parameter exists whose key that matches the supplied wildcard pattern |
|
90 | - * and return the value for the first match found |
|
91 | - * wildcards can be either of the following: |
|
92 | - * ? to represent a single character of any type |
|
93 | - * * to represent one or more characters of any type |
|
94 | - * |
|
95 | - * @param string $pattern |
|
96 | - * @param null|mixed $default |
|
97 | - * @return false|int |
|
98 | - */ |
|
99 | - public function getMatch($pattern, $default = null); |
|
88 | + /** |
|
89 | + * check if a request parameter exists whose key that matches the supplied wildcard pattern |
|
90 | + * and return the value for the first match found |
|
91 | + * wildcards can be either of the following: |
|
92 | + * ? to represent a single character of any type |
|
93 | + * * to represent one or more characters of any type |
|
94 | + * |
|
95 | + * @param string $pattern |
|
96 | + * @param null|mixed $default |
|
97 | + * @return false|int |
|
98 | + */ |
|
99 | + public function getMatch($pattern, $default = null); |
|
100 | 100 | |
101 | 101 | |
102 | - /** |
|
103 | - * check if a request parameter exists whose key matches the supplied wildcard pattern |
|
104 | - * wildcards can be either of the following: |
|
105 | - * ? to represent a single character of any type |
|
106 | - * * to represent one or more characters of any type |
|
107 | - * returns true if a match is found or false if not |
|
108 | - * |
|
109 | - * @param string $pattern |
|
110 | - * @return false|int |
|
111 | - */ |
|
112 | - public function matches($pattern); |
|
102 | + /** |
|
103 | + * check if a request parameter exists whose key matches the supplied wildcard pattern |
|
104 | + * wildcards can be either of the following: |
|
105 | + * ? to represent a single character of any type |
|
106 | + * * to represent one or more characters of any type |
|
107 | + * returns true if a match is found or false if not |
|
108 | + * |
|
109 | + * @param string $pattern |
|
110 | + * @return false|int |
|
111 | + */ |
|
112 | + public function matches($pattern); |
|
113 | 113 | |
114 | 114 | |
115 | - /** |
|
116 | - * remove param |
|
117 | - * |
|
118 | - * @param string $key |
|
119 | - * @param bool $unset_from_global_too |
|
120 | - */ |
|
121 | - public function unSetRequestParam($key, $unset_from_global_too = false); |
|
115 | + /** |
|
116 | + * remove param |
|
117 | + * |
|
118 | + * @param string $key |
|
119 | + * @param bool $unset_from_global_too |
|
120 | + */ |
|
121 | + public function unSetRequestParam($key, $unset_from_global_too = false); |
|
122 | 122 | |
123 | 123 | |
124 | - /** |
|
125 | - * @return string |
|
126 | - */ |
|
127 | - public function ipAddress(); |
|
124 | + /** |
|
125 | + * @return string |
|
126 | + */ |
|
127 | + public function ipAddress(); |
|
128 | 128 | |
129 | 129 | |
130 | - /** |
|
131 | - * @return string |
|
132 | - */ |
|
133 | - public function requestUri(); |
|
134 | - |
|
130 | + /** |
|
131 | + * @return string |
|
132 | + */ |
|
133 | + public function requestUri(); |
|
134 | + |
|
135 | 135 | |
136 | - /** |
|
137 | - * @return string |
|
138 | - */ |
|
139 | - public function userAgent(); |
|
140 | - |
|
141 | - |
|
142 | - /** |
|
143 | - * @param string $user_agent |
|
144 | - */ |
|
145 | - public function setUserAgent($user_agent = ''); |
|
146 | - |
|
147 | - |
|
148 | - /** |
|
149 | - * @return bool |
|
150 | - */ |
|
151 | - public function isBot(); |
|
152 | - |
|
153 | - |
|
154 | - /** |
|
155 | - * @param bool $is_bot |
|
156 | - */ |
|
157 | - public function setIsBot($is_bot); |
|
136 | + /** |
|
137 | + * @return string |
|
138 | + */ |
|
139 | + public function userAgent(); |
|
140 | + |
|
141 | + |
|
142 | + /** |
|
143 | + * @param string $user_agent |
|
144 | + */ |
|
145 | + public function setUserAgent($user_agent = ''); |
|
146 | + |
|
147 | + |
|
148 | + /** |
|
149 | + * @return bool |
|
150 | + */ |
|
151 | + public function isBot(); |
|
152 | + |
|
153 | + |
|
154 | + /** |
|
155 | + * @param bool $is_bot |
|
156 | + */ |
|
157 | + public function setIsBot($is_bot); |
|
158 | 158 | } |
@@ -83,12 +83,12 @@ |
||
83 | 83 | <div class="notice inline notice-alt"> |
84 | 84 | <div class="ee-upsell-container"> |
85 | 85 | <div class="ee-upsell-inner-container"> |
86 | - <a href="' . $button_url . '"> |
|
87 | - ' . $button_text . ' |
|
86 | + <a href="' . $button_url.'"> |
|
87 | + ' . $button_text.' |
|
88 | 88 | </a> |
89 | 89 | </div> |
90 | 90 | <div class="ee-upsell-inner-container"> |
91 | - <p>' . $upsell_text . '</p> |
|
91 | + <p>' . $upsell_text.'</p> |
|
92 | 92 | </div> |
93 | 93 | <div style="clear:both"></div> |
94 | 94 | </div> |
@@ -16,46 +16,46 @@ discard block |
||
16 | 16 | class PluginUpsells |
17 | 17 | { |
18 | 18 | |
19 | - /** |
|
20 | - * @var DomainInterface |
|
21 | - */ |
|
22 | - private $domain; |
|
19 | + /** |
|
20 | + * @var DomainInterface |
|
21 | + */ |
|
22 | + private $domain; |
|
23 | 23 | |
24 | 24 | |
25 | - /** |
|
26 | - * PluginUpsells constructor. |
|
27 | - * |
|
28 | - * @param DomainInterface $domain |
|
29 | - */ |
|
30 | - public function __construct(DomainInterface $domain) |
|
31 | - { |
|
32 | - $this->domain = $domain; |
|
33 | - } |
|
25 | + /** |
|
26 | + * PluginUpsells constructor. |
|
27 | + * |
|
28 | + * @param DomainInterface $domain |
|
29 | + */ |
|
30 | + public function __construct(DomainInterface $domain) |
|
31 | + { |
|
32 | + $this->domain = $domain; |
|
33 | + } |
|
34 | 34 | |
35 | 35 | |
36 | - /** |
|
37 | - * Hook in various upsells for the decaf version of EE. |
|
38 | - */ |
|
39 | - public function decafUpsells() |
|
40 | - { |
|
41 | - if ($this->domain instanceof CaffeinatedInterface && ! $this->domain->isCaffeinated()) { |
|
42 | - add_action('after_plugin_row', array($this, 'doPremiumUpsell'), 10, 3); |
|
43 | - } |
|
44 | - } |
|
36 | + /** |
|
37 | + * Hook in various upsells for the decaf version of EE. |
|
38 | + */ |
|
39 | + public function decafUpsells() |
|
40 | + { |
|
41 | + if ($this->domain instanceof CaffeinatedInterface && ! $this->domain->isCaffeinated()) { |
|
42 | + add_action('after_plugin_row', array($this, 'doPremiumUpsell'), 10, 3); |
|
43 | + } |
|
44 | + } |
|
45 | 45 | |
46 | 46 | |
47 | - /** |
|
48 | - * Callback for `after_plugin_row` to add upsell info |
|
49 | - * @param string $plugin_file |
|
50 | - * @param array $plugin_data |
|
51 | - * @param string $status |
|
52 | - * @throws DomainException |
|
53 | - */ |
|
54 | - public function doPremiumUpsell($plugin_file, $plugin_data, $status) |
|
55 | - { |
|
56 | - if ($plugin_file === $this->domain->pluginBasename()) { |
|
57 | - list($button_text, $button_url, $upsell_text) = $this->getAfterPluginRowDetails(); |
|
58 | - echo '<tr class="plugin-update-tr ee-upsell-plugin-list-table active"> |
|
47 | + /** |
|
48 | + * Callback for `after_plugin_row` to add upsell info |
|
49 | + * @param string $plugin_file |
|
50 | + * @param array $plugin_data |
|
51 | + * @param string $status |
|
52 | + * @throws DomainException |
|
53 | + */ |
|
54 | + public function doPremiumUpsell($plugin_file, $plugin_data, $status) |
|
55 | + { |
|
56 | + if ($plugin_file === $this->domain->pluginBasename()) { |
|
57 | + list($button_text, $button_url, $upsell_text) = $this->getAfterPluginRowDetails(); |
|
58 | + echo '<tr class="plugin-update-tr ee-upsell-plugin-list-table active"> |
|
59 | 59 | <td colspan="3" class="plugin-update colspanchange"> |
60 | 60 | <div class="notice inline notice-alt"> |
61 | 61 | <div class="ee-upsell-container"> |
@@ -72,26 +72,26 @@ discard block |
||
72 | 72 | </div> |
73 | 73 | </td> |
74 | 74 | </tr>'; |
75 | - } |
|
76 | - } |
|
75 | + } |
|
76 | + } |
|
77 | 77 | |
78 | - /** |
|
79 | - * Provide the details used for the upsell container. |
|
80 | - * @return array |
|
81 | - */ |
|
82 | - protected function getAfterPluginRowDetails() |
|
83 | - { |
|
84 | - return array( |
|
85 | - esc_html__('Upgrade for Support', 'event_espresso'), |
|
86 | - 'https://eventespresso.com/purchase/?slug=ee4-license-personal&utm_source=wp_admin_plugins_screen&utm_medium=link&utm_campaign=plugins_screen_upgrade_link" class="button button-primary', |
|
87 | - sprintf( |
|
88 | - esc_html__( |
|
89 | - 'You\'re missing out on %1$sexpert support%2$s and %1$sone-click updates%2$s! Don\'t have an Event Espresso support license key? Support the project and buy one today!', |
|
90 | - 'event_espresso' |
|
91 | - ), |
|
92 | - '<strong>', |
|
93 | - '</strong>' |
|
94 | - ) |
|
95 | - ); |
|
96 | - } |
|
78 | + /** |
|
79 | + * Provide the details used for the upsell container. |
|
80 | + * @return array |
|
81 | + */ |
|
82 | + protected function getAfterPluginRowDetails() |
|
83 | + { |
|
84 | + return array( |
|
85 | + esc_html__('Upgrade for Support', 'event_espresso'), |
|
86 | + 'https://eventespresso.com/purchase/?slug=ee4-license-personal&utm_source=wp_admin_plugins_screen&utm_medium=link&utm_campaign=plugins_screen_upgrade_link" class="button button-primary', |
|
87 | + sprintf( |
|
88 | + esc_html__( |
|
89 | + 'You\'re missing out on %1$sexpert support%2$s and %1$sone-click updates%2$s! Don\'t have an Event Espresso support license key? Support the project and buy one today!', |
|
90 | + 'event_espresso' |
|
91 | + ), |
|
92 | + '<strong>', |
|
93 | + '</strong>' |
|
94 | + ) |
|
95 | + ); |
|
96 | + } |
|
97 | 97 | } |
@@ -21,326 +21,326 @@ |
||
21 | 21 | class EED_Recaptcha_Invisible extends EED_Module |
22 | 22 | { |
23 | 23 | |
24 | - /** |
|
25 | - * @var EE_Registration_Config $config |
|
26 | - */ |
|
27 | - private static $config; |
|
28 | - |
|
29 | - |
|
30 | - /** |
|
31 | - * @return EED_Module|EED_Recaptcha |
|
32 | - */ |
|
33 | - public static function instance() |
|
34 | - { |
|
35 | - return parent::get_instance(__CLASS__); |
|
36 | - } |
|
37 | - |
|
38 | - |
|
39 | - /** |
|
40 | - * @return void |
|
41 | - * @throws InvalidInterfaceException |
|
42 | - * @throws InvalidDataTypeException |
|
43 | - * @throws InvalidArgumentException |
|
44 | - */ |
|
45 | - public static function set_hooks() |
|
46 | - { |
|
47 | - EED_Recaptcha_Invisible::setProperties(); |
|
48 | - if (EED_Recaptcha_Invisible::useInvisibleRecaptcha()) { |
|
49 | - if(EED_Recaptcha_Invisible::protectForm('ticket_selector')){ |
|
50 | - // ticket selection |
|
51 | - add_filter( |
|
52 | - 'FHEE__EE_Ticket_Selector__after_ticket_selector_submit', |
|
53 | - array('EED_Recaptcha_Invisible', 'ticketSelectorForm'), |
|
54 | - 10, 3 |
|
55 | - ); |
|
56 | - add_action( |
|
57 | - 'EED_Ticket_Selector__process_ticket_selections__before', |
|
58 | - array('EED_Recaptcha_Invisible', 'processTicketSelectorForm') |
|
59 | - ); |
|
60 | - } |
|
61 | - if (EED_Recaptcha_Invisible::protectForm('registration_form')) { |
|
62 | - // checkout |
|
63 | - add_action( |
|
64 | - 'AHEE__EE_SPCO_Reg_Step__display_reg_form__reg_form', |
|
65 | - array('EED_Recaptcha_Invisible', 'spcoRegStepForm') |
|
66 | - ); |
|
67 | - add_filter( |
|
68 | - 'FHEE__EE_Form_Section_Proper__receive_form_submission__req_data', |
|
69 | - array('EED_Recaptcha_Invisible', 'receiveSpcoRegStepForm'), |
|
70 | - 10, 2 |
|
71 | - ); |
|
72 | - } |
|
73 | - add_action('loop_end', array('EED_Recaptcha_Invisible', 'localizeScriptVars')); |
|
74 | - } |
|
75 | - } |
|
76 | - |
|
77 | - |
|
78 | - /** |
|
79 | - * @return void |
|
80 | - * @throws InvalidInterfaceException |
|
81 | - * @throws InvalidDataTypeException |
|
82 | - * @throws InvalidArgumentException |
|
83 | - */ |
|
84 | - public static function set_hooks_admin() |
|
85 | - { |
|
86 | - EED_Recaptcha_Invisible::setProperties(); |
|
87 | - if (EED_Recaptcha_Invisible::protectForm('ticket_selector')) { |
|
88 | - add_action( |
|
89 | - 'EED_Ticket_Selector__process_ticket_selections__before', |
|
90 | - array('EED_Recaptcha_Invisible', 'processTicketSelectorForm') |
|
91 | - ); |
|
92 | - } |
|
93 | - if (EED_Recaptcha_Invisible::protectForm('registration_form')) { |
|
94 | - add_filter( |
|
95 | - 'FHEE__EE_Form_Section_Proper__receive_form_submission__req_data', |
|
96 | - array('EED_Recaptcha_Invisible', 'receiveSpcoRegStepForm'), |
|
97 | - 10, 2 |
|
98 | - ); |
|
99 | - } |
|
100 | - // admin settings |
|
101 | - add_action( |
|
102 | - 'AHEE__Extend_Registration_Form_Admin_Page___reg_form_settings_template', |
|
103 | - array('EED_Recaptcha_Invisible', 'adminSettings') |
|
104 | - ); |
|
105 | - add_filter( |
|
106 | - 'FHEE__Extend_Registration_Form_Admin_Page___update_reg_form_settings__CFG_registration', |
|
107 | - array('EED_Recaptcha_Invisible', 'updateAdminSettings') |
|
108 | - ); |
|
109 | - } |
|
110 | - |
|
111 | - |
|
112 | - /** |
|
113 | - * @return void |
|
114 | - * @throws InvalidInterfaceException |
|
115 | - * @throws InvalidDataTypeException |
|
116 | - * @throws InvalidArgumentException |
|
117 | - */ |
|
118 | - public static function setProperties() |
|
119 | - { |
|
120 | - |
|
121 | - EED_Recaptcha_Invisible::$config = EE_Registry::instance()->CFG->registration; |
|
122 | - } |
|
123 | - |
|
124 | - |
|
125 | - |
|
126 | - /** |
|
127 | - * @return boolean |
|
128 | - */ |
|
129 | - public static function useInvisibleRecaptcha() |
|
130 | - { |
|
131 | - return EED_Recaptcha_Invisible::$config->use_captcha |
|
132 | - && EED_Recaptcha_Invisible::$config->recaptcha_theme === 'invisible'; |
|
133 | - } |
|
134 | - |
|
135 | - |
|
136 | - /** |
|
137 | - * @param string $form |
|
138 | - * @return boolean |
|
139 | - */ |
|
140 | - public static function protectForm($form) |
|
141 | - { |
|
142 | - return is_array(EED_Recaptcha_Invisible::$config->recaptcha_protected_forms) |
|
143 | - && in_array($form, EED_Recaptcha_Invisible::$config->recaptcha_protected_forms, true); |
|
144 | - } |
|
145 | - |
|
146 | - |
|
147 | - |
|
148 | - |
|
149 | - /** |
|
150 | - * @return void |
|
151 | - * @throws InvalidInterfaceException |
|
152 | - * @throws InvalidDataTypeException |
|
153 | - * @throws InvalidArgumentException |
|
154 | - */ |
|
155 | - public static function localizeScriptVars() |
|
156 | - { |
|
157 | - wp_localize_script( |
|
158 | - EE_Invisible_Recaptcha_Input::SCRIPT_HANDLE_ESPRESSO_INVISIBLE_RECAPTCHA, |
|
159 | - 'eeRecaptcha', |
|
160 | - RecaptchaFactory::create()->getLocalizedVars() |
|
161 | - ); |
|
162 | - } |
|
163 | - |
|
164 | - |
|
165 | - /** |
|
166 | - * @return string |
|
167 | - */ |
|
168 | - public static function assetsUrl() |
|
169 | - { |
|
170 | - return plugin_dir_url(__FILE__) . 'assets' . DS; |
|
171 | - } |
|
172 | - |
|
173 | - |
|
174 | - /** |
|
175 | - * @param \WP $WP |
|
176 | - */ |
|
177 | - public function run($WP) |
|
178 | - { |
|
179 | - } |
|
180 | - |
|
181 | - |
|
182 | - |
|
183 | - /** |
|
184 | - * @param EE_Request $request |
|
185 | - * @return bool |
|
186 | - * @throws InvalidArgumentException |
|
187 | - * @throws InvalidDataTypeException |
|
188 | - * @throws InvalidInterfaceException |
|
189 | - * @throws RuntimeException |
|
190 | - */ |
|
191 | - public static function verifyToken(EE_Request $request) |
|
192 | - { |
|
193 | - return RecaptchaFactory::create()->verifyToken($request); |
|
194 | - } |
|
195 | - |
|
196 | - |
|
197 | - /** |
|
198 | - * @param EE_Form_Section_Proper $reg_form |
|
199 | - * @return void |
|
200 | - * @throws EE_Error |
|
201 | - * @throws InvalidArgumentException |
|
202 | - * @throws InvalidDataTypeException |
|
203 | - * @throws InvalidInterfaceException |
|
204 | - * @throws DomainException |
|
205 | - */ |
|
206 | - public static function spcoRegStepForm(EE_Form_Section_Proper $reg_form) |
|
207 | - { |
|
208 | - // do nothing if form isn't for a reg step or test has already been passed |
|
209 | - if (! EED_Recaptcha_Invisible::processSpcoRegStepForm($reg_form)) { |
|
210 | - return; |
|
211 | - } |
|
212 | - $default_hidden_inputs = $reg_form->get_subsection('default_hidden_inputs'); |
|
213 | - if ($default_hidden_inputs instanceof EE_Form_Section_Proper) { |
|
214 | - $invisible_recaptcha = RecaptchaFactory::create(); |
|
215 | - $invisible_recaptcha->addToFormSection($default_hidden_inputs); |
|
216 | - } |
|
217 | - } |
|
218 | - |
|
219 | - |
|
220 | - /** |
|
221 | - * @param EE_Form_Section_Proper $reg_form |
|
222 | - * @return bool |
|
223 | - * @throws InvalidDataTypeException |
|
224 | - * @throws InvalidInterfaceException |
|
225 | - * @throws EE_Error |
|
226 | - * @throws InvalidArgumentException |
|
227 | - */ |
|
228 | - public static function processSpcoRegStepForm(EE_Form_Section_Proper $reg_form) |
|
229 | - { |
|
230 | - return strpos($reg_form->name(), 'reg-step-form') !== false |
|
231 | - && ! RecaptchaFactory::create()->recaptchaPassed(); |
|
232 | - } |
|
233 | - |
|
234 | - |
|
235 | - /** |
|
236 | - * @param array|null $req_data |
|
237 | - * @param EE_Form_Section_Proper $reg_form |
|
238 | - * @return array |
|
239 | - * @throws EE_Error |
|
240 | - * @throws InvalidArgumentException |
|
241 | - * @throws InvalidDataTypeException |
|
242 | - * @throws InvalidInterfaceException |
|
243 | - * @throws RuntimeException |
|
244 | - */ |
|
245 | - public static function receiveSpcoRegStepForm($req_data = array(), EE_Form_Section_Proper $reg_form) |
|
246 | - { |
|
247 | - // do nothing if form isn't for a reg step or test has already been passed |
|
248 | - if (! EED_Recaptcha_Invisible::processSpcoRegStepForm($reg_form)) { |
|
249 | - return $req_data; |
|
250 | - } |
|
251 | - /** @var EE_Request $request */ |
|
252 | - $request = LoaderFactory::getLoader()->getShared('EE_Request'); |
|
253 | - if (! EED_Recaptcha_Invisible::verifyToken($request)) { |
|
254 | - if ($request->isAjax()) { |
|
255 | - $json_response = new EE_SPCO_JSON_Response(); |
|
256 | - $json_response->echoAndExit(); |
|
257 | - } |
|
258 | - EEH_URL::safeRedirectAndExit( |
|
259 | - EE_Registry::instance()->CFG->core->reg_page_url() |
|
260 | - ); |
|
261 | - } |
|
262 | - return $req_data; |
|
263 | - } |
|
264 | - |
|
265 | - |
|
266 | - /** |
|
267 | - * @param string $html |
|
268 | - * @param EE_Event $event |
|
269 | - * @param bool $iframe |
|
270 | - * @return string |
|
271 | - * @throws EE_Error |
|
272 | - * @throws InvalidArgumentException |
|
273 | - * @throws InvalidDataTypeException |
|
274 | - * @throws InvalidInterfaceException |
|
275 | - * @throws ReflectionException |
|
276 | - * @throws DomainException |
|
277 | - */ |
|
278 | - public static function ticketSelectorForm($html = '', EE_Event $event, $iframe = false) |
|
279 | - { |
|
280 | - $recaptcha = RecaptchaFactory::create(); |
|
281 | - // do nothing if test has already been passed |
|
282 | - if ($recaptcha->recaptchaPassed()) { |
|
283 | - return $html; |
|
284 | - } |
|
285 | - $html .= $recaptcha->getInputHtml( |
|
286 | - array( |
|
287 | - 'recaptcha_id' => $event->ID(), |
|
288 | - 'iframe' => $iframe, |
|
289 | - 'localized_vars' => $recaptcha->getLocalizedVars(), |
|
290 | - ) |
|
291 | - ); |
|
292 | - return $html; |
|
293 | - } |
|
294 | - |
|
295 | - |
|
296 | - /** |
|
297 | - * @return void |
|
298 | - * @throws InvalidArgumentException |
|
299 | - * @throws InvalidInterfaceException |
|
300 | - * @throws InvalidDataTypeException |
|
301 | - * @throws RuntimeException |
|
302 | - */ |
|
303 | - public static function processTicketSelectorForm() |
|
304 | - { |
|
305 | - // do nothing if test has already been passed |
|
306 | - if (RecaptchaFactory::create()->recaptchaPassed()) { |
|
307 | - return; |
|
308 | - } |
|
309 | - /** @var EE_Request $request */ |
|
310 | - $request = LoaderFactory::getLoader()->getShared('EE_Request'); |
|
311 | - if (! EED_Recaptcha_Invisible::verifyToken($request)) { |
|
312 | - $event_id = $request->get('tkt-slctr-event-id'); |
|
313 | - $return_url = $request->is_set("tkt-slctr-return-url-{$event_id}") |
|
314 | - ? $request->get("tkt-slctr-return-url-{$event_id}") |
|
315 | - : get_permalink($event_id); |
|
316 | - EEH_URL::safeRedirectAndExit($return_url); |
|
317 | - } |
|
318 | - } |
|
319 | - |
|
320 | - |
|
321 | - /** |
|
322 | - * @throws EE_Error |
|
323 | - * @throws InvalidArgumentException |
|
324 | - * @throws InvalidDataTypeException |
|
325 | - * @throws InvalidInterfaceException |
|
326 | - */ |
|
327 | - public static function adminSettings() |
|
328 | - { |
|
329 | - RecaptchaFactory::getAdminModule()->adminSettings(); |
|
330 | - } |
|
331 | - |
|
332 | - |
|
333 | - /** |
|
334 | - * @param EE_Registration_Config $EE_Registration_Config |
|
335 | - * @return EE_Registration_Config |
|
336 | - * @throws EE_Error |
|
337 | - * @throws InvalidArgumentException |
|
338 | - * @throws InvalidDataTypeException |
|
339 | - * @throws InvalidInterfaceException |
|
340 | - * @throws ReflectionException |
|
341 | - */ |
|
342 | - public static function updateAdminSettings(EE_Registration_Config $EE_Registration_Config) |
|
343 | - { |
|
344 | - return RecaptchaFactory::getAdminModule()->updateAdminSettings($EE_Registration_Config); |
|
345 | - } |
|
24 | + /** |
|
25 | + * @var EE_Registration_Config $config |
|
26 | + */ |
|
27 | + private static $config; |
|
28 | + |
|
29 | + |
|
30 | + /** |
|
31 | + * @return EED_Module|EED_Recaptcha |
|
32 | + */ |
|
33 | + public static function instance() |
|
34 | + { |
|
35 | + return parent::get_instance(__CLASS__); |
|
36 | + } |
|
37 | + |
|
38 | + |
|
39 | + /** |
|
40 | + * @return void |
|
41 | + * @throws InvalidInterfaceException |
|
42 | + * @throws InvalidDataTypeException |
|
43 | + * @throws InvalidArgumentException |
|
44 | + */ |
|
45 | + public static function set_hooks() |
|
46 | + { |
|
47 | + EED_Recaptcha_Invisible::setProperties(); |
|
48 | + if (EED_Recaptcha_Invisible::useInvisibleRecaptcha()) { |
|
49 | + if(EED_Recaptcha_Invisible::protectForm('ticket_selector')){ |
|
50 | + // ticket selection |
|
51 | + add_filter( |
|
52 | + 'FHEE__EE_Ticket_Selector__after_ticket_selector_submit', |
|
53 | + array('EED_Recaptcha_Invisible', 'ticketSelectorForm'), |
|
54 | + 10, 3 |
|
55 | + ); |
|
56 | + add_action( |
|
57 | + 'EED_Ticket_Selector__process_ticket_selections__before', |
|
58 | + array('EED_Recaptcha_Invisible', 'processTicketSelectorForm') |
|
59 | + ); |
|
60 | + } |
|
61 | + if (EED_Recaptcha_Invisible::protectForm('registration_form')) { |
|
62 | + // checkout |
|
63 | + add_action( |
|
64 | + 'AHEE__EE_SPCO_Reg_Step__display_reg_form__reg_form', |
|
65 | + array('EED_Recaptcha_Invisible', 'spcoRegStepForm') |
|
66 | + ); |
|
67 | + add_filter( |
|
68 | + 'FHEE__EE_Form_Section_Proper__receive_form_submission__req_data', |
|
69 | + array('EED_Recaptcha_Invisible', 'receiveSpcoRegStepForm'), |
|
70 | + 10, 2 |
|
71 | + ); |
|
72 | + } |
|
73 | + add_action('loop_end', array('EED_Recaptcha_Invisible', 'localizeScriptVars')); |
|
74 | + } |
|
75 | + } |
|
76 | + |
|
77 | + |
|
78 | + /** |
|
79 | + * @return void |
|
80 | + * @throws InvalidInterfaceException |
|
81 | + * @throws InvalidDataTypeException |
|
82 | + * @throws InvalidArgumentException |
|
83 | + */ |
|
84 | + public static function set_hooks_admin() |
|
85 | + { |
|
86 | + EED_Recaptcha_Invisible::setProperties(); |
|
87 | + if (EED_Recaptcha_Invisible::protectForm('ticket_selector')) { |
|
88 | + add_action( |
|
89 | + 'EED_Ticket_Selector__process_ticket_selections__before', |
|
90 | + array('EED_Recaptcha_Invisible', 'processTicketSelectorForm') |
|
91 | + ); |
|
92 | + } |
|
93 | + if (EED_Recaptcha_Invisible::protectForm('registration_form')) { |
|
94 | + add_filter( |
|
95 | + 'FHEE__EE_Form_Section_Proper__receive_form_submission__req_data', |
|
96 | + array('EED_Recaptcha_Invisible', 'receiveSpcoRegStepForm'), |
|
97 | + 10, 2 |
|
98 | + ); |
|
99 | + } |
|
100 | + // admin settings |
|
101 | + add_action( |
|
102 | + 'AHEE__Extend_Registration_Form_Admin_Page___reg_form_settings_template', |
|
103 | + array('EED_Recaptcha_Invisible', 'adminSettings') |
|
104 | + ); |
|
105 | + add_filter( |
|
106 | + 'FHEE__Extend_Registration_Form_Admin_Page___update_reg_form_settings__CFG_registration', |
|
107 | + array('EED_Recaptcha_Invisible', 'updateAdminSettings') |
|
108 | + ); |
|
109 | + } |
|
110 | + |
|
111 | + |
|
112 | + /** |
|
113 | + * @return void |
|
114 | + * @throws InvalidInterfaceException |
|
115 | + * @throws InvalidDataTypeException |
|
116 | + * @throws InvalidArgumentException |
|
117 | + */ |
|
118 | + public static function setProperties() |
|
119 | + { |
|
120 | + |
|
121 | + EED_Recaptcha_Invisible::$config = EE_Registry::instance()->CFG->registration; |
|
122 | + } |
|
123 | + |
|
124 | + |
|
125 | + |
|
126 | + /** |
|
127 | + * @return boolean |
|
128 | + */ |
|
129 | + public static function useInvisibleRecaptcha() |
|
130 | + { |
|
131 | + return EED_Recaptcha_Invisible::$config->use_captcha |
|
132 | + && EED_Recaptcha_Invisible::$config->recaptcha_theme === 'invisible'; |
|
133 | + } |
|
134 | + |
|
135 | + |
|
136 | + /** |
|
137 | + * @param string $form |
|
138 | + * @return boolean |
|
139 | + */ |
|
140 | + public static function protectForm($form) |
|
141 | + { |
|
142 | + return is_array(EED_Recaptcha_Invisible::$config->recaptcha_protected_forms) |
|
143 | + && in_array($form, EED_Recaptcha_Invisible::$config->recaptcha_protected_forms, true); |
|
144 | + } |
|
145 | + |
|
146 | + |
|
147 | + |
|
148 | + |
|
149 | + /** |
|
150 | + * @return void |
|
151 | + * @throws InvalidInterfaceException |
|
152 | + * @throws InvalidDataTypeException |
|
153 | + * @throws InvalidArgumentException |
|
154 | + */ |
|
155 | + public static function localizeScriptVars() |
|
156 | + { |
|
157 | + wp_localize_script( |
|
158 | + EE_Invisible_Recaptcha_Input::SCRIPT_HANDLE_ESPRESSO_INVISIBLE_RECAPTCHA, |
|
159 | + 'eeRecaptcha', |
|
160 | + RecaptchaFactory::create()->getLocalizedVars() |
|
161 | + ); |
|
162 | + } |
|
163 | + |
|
164 | + |
|
165 | + /** |
|
166 | + * @return string |
|
167 | + */ |
|
168 | + public static function assetsUrl() |
|
169 | + { |
|
170 | + return plugin_dir_url(__FILE__) . 'assets' . DS; |
|
171 | + } |
|
172 | + |
|
173 | + |
|
174 | + /** |
|
175 | + * @param \WP $WP |
|
176 | + */ |
|
177 | + public function run($WP) |
|
178 | + { |
|
179 | + } |
|
180 | + |
|
181 | + |
|
182 | + |
|
183 | + /** |
|
184 | + * @param EE_Request $request |
|
185 | + * @return bool |
|
186 | + * @throws InvalidArgumentException |
|
187 | + * @throws InvalidDataTypeException |
|
188 | + * @throws InvalidInterfaceException |
|
189 | + * @throws RuntimeException |
|
190 | + */ |
|
191 | + public static function verifyToken(EE_Request $request) |
|
192 | + { |
|
193 | + return RecaptchaFactory::create()->verifyToken($request); |
|
194 | + } |
|
195 | + |
|
196 | + |
|
197 | + /** |
|
198 | + * @param EE_Form_Section_Proper $reg_form |
|
199 | + * @return void |
|
200 | + * @throws EE_Error |
|
201 | + * @throws InvalidArgumentException |
|
202 | + * @throws InvalidDataTypeException |
|
203 | + * @throws InvalidInterfaceException |
|
204 | + * @throws DomainException |
|
205 | + */ |
|
206 | + public static function spcoRegStepForm(EE_Form_Section_Proper $reg_form) |
|
207 | + { |
|
208 | + // do nothing if form isn't for a reg step or test has already been passed |
|
209 | + if (! EED_Recaptcha_Invisible::processSpcoRegStepForm($reg_form)) { |
|
210 | + return; |
|
211 | + } |
|
212 | + $default_hidden_inputs = $reg_form->get_subsection('default_hidden_inputs'); |
|
213 | + if ($default_hidden_inputs instanceof EE_Form_Section_Proper) { |
|
214 | + $invisible_recaptcha = RecaptchaFactory::create(); |
|
215 | + $invisible_recaptcha->addToFormSection($default_hidden_inputs); |
|
216 | + } |
|
217 | + } |
|
218 | + |
|
219 | + |
|
220 | + /** |
|
221 | + * @param EE_Form_Section_Proper $reg_form |
|
222 | + * @return bool |
|
223 | + * @throws InvalidDataTypeException |
|
224 | + * @throws InvalidInterfaceException |
|
225 | + * @throws EE_Error |
|
226 | + * @throws InvalidArgumentException |
|
227 | + */ |
|
228 | + public static function processSpcoRegStepForm(EE_Form_Section_Proper $reg_form) |
|
229 | + { |
|
230 | + return strpos($reg_form->name(), 'reg-step-form') !== false |
|
231 | + && ! RecaptchaFactory::create()->recaptchaPassed(); |
|
232 | + } |
|
233 | + |
|
234 | + |
|
235 | + /** |
|
236 | + * @param array|null $req_data |
|
237 | + * @param EE_Form_Section_Proper $reg_form |
|
238 | + * @return array |
|
239 | + * @throws EE_Error |
|
240 | + * @throws InvalidArgumentException |
|
241 | + * @throws InvalidDataTypeException |
|
242 | + * @throws InvalidInterfaceException |
|
243 | + * @throws RuntimeException |
|
244 | + */ |
|
245 | + public static function receiveSpcoRegStepForm($req_data = array(), EE_Form_Section_Proper $reg_form) |
|
246 | + { |
|
247 | + // do nothing if form isn't for a reg step or test has already been passed |
|
248 | + if (! EED_Recaptcha_Invisible::processSpcoRegStepForm($reg_form)) { |
|
249 | + return $req_data; |
|
250 | + } |
|
251 | + /** @var EE_Request $request */ |
|
252 | + $request = LoaderFactory::getLoader()->getShared('EE_Request'); |
|
253 | + if (! EED_Recaptcha_Invisible::verifyToken($request)) { |
|
254 | + if ($request->isAjax()) { |
|
255 | + $json_response = new EE_SPCO_JSON_Response(); |
|
256 | + $json_response->echoAndExit(); |
|
257 | + } |
|
258 | + EEH_URL::safeRedirectAndExit( |
|
259 | + EE_Registry::instance()->CFG->core->reg_page_url() |
|
260 | + ); |
|
261 | + } |
|
262 | + return $req_data; |
|
263 | + } |
|
264 | + |
|
265 | + |
|
266 | + /** |
|
267 | + * @param string $html |
|
268 | + * @param EE_Event $event |
|
269 | + * @param bool $iframe |
|
270 | + * @return string |
|
271 | + * @throws EE_Error |
|
272 | + * @throws InvalidArgumentException |
|
273 | + * @throws InvalidDataTypeException |
|
274 | + * @throws InvalidInterfaceException |
|
275 | + * @throws ReflectionException |
|
276 | + * @throws DomainException |
|
277 | + */ |
|
278 | + public static function ticketSelectorForm($html = '', EE_Event $event, $iframe = false) |
|
279 | + { |
|
280 | + $recaptcha = RecaptchaFactory::create(); |
|
281 | + // do nothing if test has already been passed |
|
282 | + if ($recaptcha->recaptchaPassed()) { |
|
283 | + return $html; |
|
284 | + } |
|
285 | + $html .= $recaptcha->getInputHtml( |
|
286 | + array( |
|
287 | + 'recaptcha_id' => $event->ID(), |
|
288 | + 'iframe' => $iframe, |
|
289 | + 'localized_vars' => $recaptcha->getLocalizedVars(), |
|
290 | + ) |
|
291 | + ); |
|
292 | + return $html; |
|
293 | + } |
|
294 | + |
|
295 | + |
|
296 | + /** |
|
297 | + * @return void |
|
298 | + * @throws InvalidArgumentException |
|
299 | + * @throws InvalidInterfaceException |
|
300 | + * @throws InvalidDataTypeException |
|
301 | + * @throws RuntimeException |
|
302 | + */ |
|
303 | + public static function processTicketSelectorForm() |
|
304 | + { |
|
305 | + // do nothing if test has already been passed |
|
306 | + if (RecaptchaFactory::create()->recaptchaPassed()) { |
|
307 | + return; |
|
308 | + } |
|
309 | + /** @var EE_Request $request */ |
|
310 | + $request = LoaderFactory::getLoader()->getShared('EE_Request'); |
|
311 | + if (! EED_Recaptcha_Invisible::verifyToken($request)) { |
|
312 | + $event_id = $request->get('tkt-slctr-event-id'); |
|
313 | + $return_url = $request->is_set("tkt-slctr-return-url-{$event_id}") |
|
314 | + ? $request->get("tkt-slctr-return-url-{$event_id}") |
|
315 | + : get_permalink($event_id); |
|
316 | + EEH_URL::safeRedirectAndExit($return_url); |
|
317 | + } |
|
318 | + } |
|
319 | + |
|
320 | + |
|
321 | + /** |
|
322 | + * @throws EE_Error |
|
323 | + * @throws InvalidArgumentException |
|
324 | + * @throws InvalidDataTypeException |
|
325 | + * @throws InvalidInterfaceException |
|
326 | + */ |
|
327 | + public static function adminSettings() |
|
328 | + { |
|
329 | + RecaptchaFactory::getAdminModule()->adminSettings(); |
|
330 | + } |
|
331 | + |
|
332 | + |
|
333 | + /** |
|
334 | + * @param EE_Registration_Config $EE_Registration_Config |
|
335 | + * @return EE_Registration_Config |
|
336 | + * @throws EE_Error |
|
337 | + * @throws InvalidArgumentException |
|
338 | + * @throws InvalidDataTypeException |
|
339 | + * @throws InvalidInterfaceException |
|
340 | + * @throws ReflectionException |
|
341 | + */ |
|
342 | + public static function updateAdminSettings(EE_Registration_Config $EE_Registration_Config) |
|
343 | + { |
|
344 | + return RecaptchaFactory::getAdminModule()->updateAdminSettings($EE_Registration_Config); |
|
345 | + } |
|
346 | 346 | } |
@@ -46,7 +46,7 @@ discard block |
||
46 | 46 | { |
47 | 47 | EED_Recaptcha_Invisible::setProperties(); |
48 | 48 | if (EED_Recaptcha_Invisible::useInvisibleRecaptcha()) { |
49 | - if(EED_Recaptcha_Invisible::protectForm('ticket_selector')){ |
|
49 | + if (EED_Recaptcha_Invisible::protectForm('ticket_selector')) { |
|
50 | 50 | // ticket selection |
51 | 51 | add_filter( |
52 | 52 | 'FHEE__EE_Ticket_Selector__after_ticket_selector_submit', |
@@ -167,7 +167,7 @@ discard block |
||
167 | 167 | */ |
168 | 168 | public static function assetsUrl() |
169 | 169 | { |
170 | - return plugin_dir_url(__FILE__) . 'assets' . DS; |
|
170 | + return plugin_dir_url(__FILE__).'assets'.DS; |
|
171 | 171 | } |
172 | 172 | |
173 | 173 | |
@@ -206,7 +206,7 @@ discard block |
||
206 | 206 | public static function spcoRegStepForm(EE_Form_Section_Proper $reg_form) |
207 | 207 | { |
208 | 208 | // do nothing if form isn't for a reg step or test has already been passed |
209 | - if (! EED_Recaptcha_Invisible::processSpcoRegStepForm($reg_form)) { |
|
209 | + if ( ! EED_Recaptcha_Invisible::processSpcoRegStepForm($reg_form)) { |
|
210 | 210 | return; |
211 | 211 | } |
212 | 212 | $default_hidden_inputs = $reg_form->get_subsection('default_hidden_inputs'); |
@@ -245,12 +245,12 @@ discard block |
||
245 | 245 | public static function receiveSpcoRegStepForm($req_data = array(), EE_Form_Section_Proper $reg_form) |
246 | 246 | { |
247 | 247 | // do nothing if form isn't for a reg step or test has already been passed |
248 | - if (! EED_Recaptcha_Invisible::processSpcoRegStepForm($reg_form)) { |
|
248 | + if ( ! EED_Recaptcha_Invisible::processSpcoRegStepForm($reg_form)) { |
|
249 | 249 | return $req_data; |
250 | 250 | } |
251 | 251 | /** @var EE_Request $request */ |
252 | 252 | $request = LoaderFactory::getLoader()->getShared('EE_Request'); |
253 | - if (! EED_Recaptcha_Invisible::verifyToken($request)) { |
|
253 | + if ( ! EED_Recaptcha_Invisible::verifyToken($request)) { |
|
254 | 254 | if ($request->isAjax()) { |
255 | 255 | $json_response = new EE_SPCO_JSON_Response(); |
256 | 256 | $json_response->echoAndExit(); |
@@ -308,7 +308,7 @@ discard block |
||
308 | 308 | } |
309 | 309 | /** @var EE_Request $request */ |
310 | 310 | $request = LoaderFactory::getLoader()->getShared('EE_Request'); |
311 | - if (! EED_Recaptcha_Invisible::verifyToken($request)) { |
|
311 | + if ( ! EED_Recaptcha_Invisible::verifyToken($request)) { |
|
312 | 312 | $event_id = $request->get('tkt-slctr-event-id'); |
313 | 313 | $return_url = $request->is_set("tkt-slctr-return-url-{$event_id}") |
314 | 314 | ? $request->get("tkt-slctr-return-url-{$event_id}") |
@@ -35,337 +35,337 @@ |
||
35 | 35 | class RecaptchaAdminSettings |
36 | 36 | { |
37 | 37 | |
38 | - /** |
|
39 | - * @var EE_Registration_Config $config |
|
40 | - */ |
|
41 | - private $config; |
|
38 | + /** |
|
39 | + * @var EE_Registration_Config $config |
|
40 | + */ |
|
41 | + private $config; |
|
42 | 42 | |
43 | 43 | |
44 | - /** |
|
45 | - * RecaptchaAdminSettings constructor. |
|
46 | - * |
|
47 | - * @param EE_Registration_Config $registration_config |
|
48 | - */ |
|
49 | - public function __construct(EE_Registration_Config $registration_config) |
|
50 | - { |
|
51 | - $this->config = $registration_config; |
|
52 | - } |
|
44 | + /** |
|
45 | + * RecaptchaAdminSettings constructor. |
|
46 | + * |
|
47 | + * @param EE_Registration_Config $registration_config |
|
48 | + */ |
|
49 | + public function __construct(EE_Registration_Config $registration_config) |
|
50 | + { |
|
51 | + $this->config = $registration_config; |
|
52 | + } |
|
53 | 53 | |
54 | 54 | |
55 | - /** |
|
56 | - * @throws InvalidArgumentException |
|
57 | - * @throws InvalidInterfaceException |
|
58 | - * @throws InvalidDataTypeException |
|
59 | - * @throws EE_Error |
|
60 | - */ |
|
61 | - public function adminSettings() |
|
62 | - { |
|
63 | - echo $this->settingsForm()->get_html_and_js(); |
|
64 | - } |
|
55 | + /** |
|
56 | + * @throws InvalidArgumentException |
|
57 | + * @throws InvalidInterfaceException |
|
58 | + * @throws InvalidDataTypeException |
|
59 | + * @throws EE_Error |
|
60 | + */ |
|
61 | + public function adminSettings() |
|
62 | + { |
|
63 | + echo $this->settingsForm()->get_html_and_js(); |
|
64 | + } |
|
65 | 65 | |
66 | 66 | |
67 | - /** |
|
68 | - * @return EE_Form_Section_Proper |
|
69 | - * @throws EE_Error |
|
70 | - */ |
|
71 | - protected function settingsForm() |
|
72 | - { |
|
73 | - return new EE_Form_Section_Proper( |
|
74 | - array( |
|
75 | - 'name' => 'recaptcha_settings_form', |
|
76 | - 'html_id' => 'recaptcha_settings_form', |
|
77 | - 'layout_strategy' => new EE_Div_Per_Section_Layout(), |
|
78 | - 'subsections' => apply_filters( |
|
79 | - 'FHEE__EED_Recaptcha___recaptcha_settings_form__form_subsections', |
|
80 | - array( |
|
81 | - 'main_settings_hdr' => new EE_Form_Section_HTML( |
|
82 | - EEH_HTML::h2( |
|
83 | - esc_html__('reCAPTCHA Anti-spam Settings', 'event_espresso') |
|
84 | - . EEH_Template::get_help_tab_link('recaptcha_info') |
|
85 | - ) |
|
86 | - ), |
|
87 | - 'main_settings' => $this->mainSettings(), |
|
88 | - 'appearance_settings_hdr' => new EE_Form_Section_HTML( |
|
89 | - EEH_HTML::h2(esc_html__('reCAPTCHA Appearance', 'event_espresso')) |
|
90 | - ), |
|
91 | - 'appearance_settings' => $this->appearanceSettings(), |
|
92 | - 'required_fields_note' => new EE_Form_Section_HTML( |
|
93 | - EEH_HTML::p( |
|
94 | - esc_html__('All fields marked with a * are required fields', 'event_espresso'), |
|
95 | - '', 'grey-text' |
|
96 | - ) |
|
97 | - ), |
|
98 | - ) |
|
99 | - ), |
|
100 | - ) |
|
101 | - ); |
|
102 | - } |
|
67 | + /** |
|
68 | + * @return EE_Form_Section_Proper |
|
69 | + * @throws EE_Error |
|
70 | + */ |
|
71 | + protected function settingsForm() |
|
72 | + { |
|
73 | + return new EE_Form_Section_Proper( |
|
74 | + array( |
|
75 | + 'name' => 'recaptcha_settings_form', |
|
76 | + 'html_id' => 'recaptcha_settings_form', |
|
77 | + 'layout_strategy' => new EE_Div_Per_Section_Layout(), |
|
78 | + 'subsections' => apply_filters( |
|
79 | + 'FHEE__EED_Recaptcha___recaptcha_settings_form__form_subsections', |
|
80 | + array( |
|
81 | + 'main_settings_hdr' => new EE_Form_Section_HTML( |
|
82 | + EEH_HTML::h2( |
|
83 | + esc_html__('reCAPTCHA Anti-spam Settings', 'event_espresso') |
|
84 | + . EEH_Template::get_help_tab_link('recaptcha_info') |
|
85 | + ) |
|
86 | + ), |
|
87 | + 'main_settings' => $this->mainSettings(), |
|
88 | + 'appearance_settings_hdr' => new EE_Form_Section_HTML( |
|
89 | + EEH_HTML::h2(esc_html__('reCAPTCHA Appearance', 'event_espresso')) |
|
90 | + ), |
|
91 | + 'appearance_settings' => $this->appearanceSettings(), |
|
92 | + 'required_fields_note' => new EE_Form_Section_HTML( |
|
93 | + EEH_HTML::p( |
|
94 | + esc_html__('All fields marked with a * are required fields', 'event_espresso'), |
|
95 | + '', 'grey-text' |
|
96 | + ) |
|
97 | + ), |
|
98 | + ) |
|
99 | + ), |
|
100 | + ) |
|
101 | + ); |
|
102 | + } |
|
103 | 103 | |
104 | 104 | |
105 | - /** |
|
106 | - * @return EE_Form_Section_Proper |
|
107 | - * @throws EE_Error |
|
108 | - */ |
|
109 | - protected function mainSettings() |
|
110 | - { |
|
111 | - return new EE_Form_Section_Proper( |
|
112 | - array( |
|
113 | - 'name' => 'recaptcha_settings_tbl', |
|
114 | - 'html_id' => 'recaptcha_settings_tbl', |
|
115 | - 'html_class' => 'form-table', |
|
116 | - 'layout_strategy' => new EE_Admin_Two_Column_Layout(), |
|
117 | - 'subsections' => apply_filters( |
|
118 | - 'FHEE__EED_Recaptcha___recaptcha_main_settings__form_subsections', |
|
119 | - array( |
|
120 | - 'use_captcha' => new EE_Yes_No_Input( |
|
121 | - array( |
|
122 | - 'html_label_text' => esc_html__('Use reCAPTCHA', 'event_espresso'), |
|
123 | - 'html_help_text' => sprintf( |
|
124 | - esc_html__('reCAPTCHA is a free service that protects your website from spam and abuse. It employs advanced risk analysis technology to separate humans from abusive actors. Sign up %1$shere%2$s to receive your Public and Private keys.', |
|
125 | - 'event_espresso'), |
|
126 | - '<a href="https://www.google.com/recaptcha/intro/index.html">', |
|
127 | - '</a>' |
|
128 | - ), |
|
129 | - 'default' => $this->config->use_captcha !== null |
|
130 | - ? $this->config->use_captcha : false, |
|
131 | - 'display_html_label_text' => false, |
|
132 | - ) |
|
133 | - ), |
|
134 | - 'recaptcha_publickey' => new EE_Text_Input( |
|
135 | - array( |
|
136 | - 'html_label_text' => esc_html__('Site Key', 'event_espresso'), |
|
137 | - 'html_help_text' => esc_html__('The site key is used to display the widget on your site.', |
|
138 | - 'event_espresso'), |
|
139 | - 'default' => $this->config->recaptcha_publickey !== null |
|
140 | - ? stripslashes($this->config->recaptcha_publickey) : '', |
|
141 | - ) |
|
142 | - ), |
|
143 | - 'recaptcha_privatekey' => new EE_Text_Input( |
|
144 | - array( |
|
145 | - 'html_label_text' => esc_html__('Secret Key', 'event_espresso'), |
|
146 | - 'html_help_text' => esc_html__('The secret key authorizes communication between your application backend and the reCAPTCHA server to verify the user\'s response. The secret key needs to be kept safe for security purposes.', |
|
147 | - 'event_espresso'), |
|
148 | - 'default' => $this->config->recaptcha_privatekey !== null |
|
149 | - ? stripslashes($this->config->recaptcha_privatekey) |
|
150 | - : '', |
|
151 | - ) |
|
152 | - ), |
|
153 | - 'recaptcha_protected_forms' => new EE_Checkbox_Multi_Input( |
|
154 | - array( |
|
155 | - 'ticket_selector' => esc_html__('Ticket Selector', 'event_espresso'), |
|
156 | - 'registration_form' => esc_html__('Registration Form', 'event_espresso'), |
|
157 | - ), |
|
158 | - array( |
|
159 | - 'html_label_text' => esc_html__('Invisible reCAPTCHA Protection', 'event_espresso'), |
|
160 | - 'html_help_text' => esc_html__('Select which Event Espresso forms you would like to enable Invisible reCAPTCHA on.', |
|
161 | - 'event_espresso'), |
|
162 | - 'default' => is_array($this->config->recaptcha_protected_forms) |
|
163 | - ? $this->config->recaptcha_protected_forms |
|
164 | - : array(), |
|
165 | - 'display_html_label_text' => false, |
|
166 | - ) |
|
167 | - ), |
|
168 | - ) |
|
169 | - ), |
|
170 | - ) |
|
171 | - ); |
|
172 | - } |
|
105 | + /** |
|
106 | + * @return EE_Form_Section_Proper |
|
107 | + * @throws EE_Error |
|
108 | + */ |
|
109 | + protected function mainSettings() |
|
110 | + { |
|
111 | + return new EE_Form_Section_Proper( |
|
112 | + array( |
|
113 | + 'name' => 'recaptcha_settings_tbl', |
|
114 | + 'html_id' => 'recaptcha_settings_tbl', |
|
115 | + 'html_class' => 'form-table', |
|
116 | + 'layout_strategy' => new EE_Admin_Two_Column_Layout(), |
|
117 | + 'subsections' => apply_filters( |
|
118 | + 'FHEE__EED_Recaptcha___recaptcha_main_settings__form_subsections', |
|
119 | + array( |
|
120 | + 'use_captcha' => new EE_Yes_No_Input( |
|
121 | + array( |
|
122 | + 'html_label_text' => esc_html__('Use reCAPTCHA', 'event_espresso'), |
|
123 | + 'html_help_text' => sprintf( |
|
124 | + esc_html__('reCAPTCHA is a free service that protects your website from spam and abuse. It employs advanced risk analysis technology to separate humans from abusive actors. Sign up %1$shere%2$s to receive your Public and Private keys.', |
|
125 | + 'event_espresso'), |
|
126 | + '<a href="https://www.google.com/recaptcha/intro/index.html">', |
|
127 | + '</a>' |
|
128 | + ), |
|
129 | + 'default' => $this->config->use_captcha !== null |
|
130 | + ? $this->config->use_captcha : false, |
|
131 | + 'display_html_label_text' => false, |
|
132 | + ) |
|
133 | + ), |
|
134 | + 'recaptcha_publickey' => new EE_Text_Input( |
|
135 | + array( |
|
136 | + 'html_label_text' => esc_html__('Site Key', 'event_espresso'), |
|
137 | + 'html_help_text' => esc_html__('The site key is used to display the widget on your site.', |
|
138 | + 'event_espresso'), |
|
139 | + 'default' => $this->config->recaptcha_publickey !== null |
|
140 | + ? stripslashes($this->config->recaptcha_publickey) : '', |
|
141 | + ) |
|
142 | + ), |
|
143 | + 'recaptcha_privatekey' => new EE_Text_Input( |
|
144 | + array( |
|
145 | + 'html_label_text' => esc_html__('Secret Key', 'event_espresso'), |
|
146 | + 'html_help_text' => esc_html__('The secret key authorizes communication between your application backend and the reCAPTCHA server to verify the user\'s response. The secret key needs to be kept safe for security purposes.', |
|
147 | + 'event_espresso'), |
|
148 | + 'default' => $this->config->recaptcha_privatekey !== null |
|
149 | + ? stripslashes($this->config->recaptcha_privatekey) |
|
150 | + : '', |
|
151 | + ) |
|
152 | + ), |
|
153 | + 'recaptcha_protected_forms' => new EE_Checkbox_Multi_Input( |
|
154 | + array( |
|
155 | + 'ticket_selector' => esc_html__('Ticket Selector', 'event_espresso'), |
|
156 | + 'registration_form' => esc_html__('Registration Form', 'event_espresso'), |
|
157 | + ), |
|
158 | + array( |
|
159 | + 'html_label_text' => esc_html__('Invisible reCAPTCHA Protection', 'event_espresso'), |
|
160 | + 'html_help_text' => esc_html__('Select which Event Espresso forms you would like to enable Invisible reCAPTCHA on.', |
|
161 | + 'event_espresso'), |
|
162 | + 'default' => is_array($this->config->recaptcha_protected_forms) |
|
163 | + ? $this->config->recaptcha_protected_forms |
|
164 | + : array(), |
|
165 | + 'display_html_label_text' => false, |
|
166 | + ) |
|
167 | + ), |
|
168 | + ) |
|
169 | + ), |
|
170 | + ) |
|
171 | + ); |
|
172 | + } |
|
173 | 173 | |
174 | 174 | |
175 | - /** |
|
176 | - * @return EE_Form_Section_Proper |
|
177 | - * @throws EE_Error |
|
178 | - */ |
|
179 | - protected function appearanceSettings() |
|
180 | - { |
|
181 | - return new EE_Form_Section_Proper( |
|
182 | - array( |
|
183 | - 'name' => 'recaptcha_appearance_settings_tbl', |
|
184 | - 'html_id' => 'recaptcha_appearance_settings_tbl', |
|
185 | - 'html_class' => 'form-table', |
|
186 | - 'layout_strategy' => new EE_Admin_Two_Column_Layout(), |
|
187 | - 'subsections' => apply_filters( |
|
188 | - 'FHEE__EED_Recaptcha___recaptcha_appearance_settings__form_subsections', |
|
189 | - array( |
|
190 | - 'recaptcha_theme' => new EE_Radio_Button_Input( |
|
191 | - array( |
|
192 | - 'invisible' => esc_html__('Invisible', 'event_espresso'), |
|
193 | - 'light' => esc_html__('Light', 'event_espresso'), |
|
194 | - 'dark' => esc_html__('Dark', 'event_espresso'), |
|
195 | - ), |
|
196 | - array( |
|
197 | - 'html_label_text' => esc_html__('Theme', 'event_espresso'), |
|
198 | - 'html_help_text' => esc_html__('The color theme of the widget.', |
|
199 | - 'event_espresso'), |
|
200 | - 'default' => $this->config->recaptcha_theme !== null |
|
201 | - ? $this->config->recaptcha_theme |
|
202 | - : 'invisible', |
|
203 | - 'display_html_label_text' => false, |
|
204 | - ) |
|
205 | - ), |
|
206 | - 'recaptcha_badge' => new EE_Radio_Button_Input( |
|
207 | - array( |
|
208 | - 'bottomleft' => esc_html__('Bottom Left', 'event_espresso'), |
|
209 | - 'bottomright' => esc_html__('Bottom Right', 'event_espresso'), |
|
210 | - 'inline' => esc_html__('Inline', 'event_espresso'), |
|
211 | - ), |
|
212 | - array( |
|
213 | - 'html_label_text' => esc_html__('Invisible reCAPTCHA Badge Position', 'event_espresso'), |
|
214 | - 'html_help_text' => esc_html__( |
|
215 | - 'If using Invisible reCAPTCHA, then this determines the position of the reCAPTCHA badge. "Bottom Left" and "Bottom Right" both will float at the bottom of the screen. "Inline" appears beside the submit button but allows you to control the CSS.', |
|
216 | - 'event_espresso' |
|
217 | - ), |
|
218 | - 'default' => $this->config->recaptcha_badge !== null |
|
219 | - ? $this->config->recaptcha_badge |
|
220 | - : 'bottomleft', |
|
221 | - 'display_html_label_text' => false, |
|
222 | - ) |
|
223 | - ), |
|
224 | - 'recaptcha_type' => new EE_Radio_Button_Input( |
|
225 | - array( |
|
226 | - 'image' => esc_html__('Image', 'event_espresso'), |
|
227 | - 'audio' => esc_html__('Audio', 'event_espresso'), |
|
228 | - ), |
|
229 | - array( |
|
230 | - 'html_label_text' => esc_html__('Type', 'event_espresso'), |
|
231 | - 'html_help_text' => esc_html__('The type of CAPTCHA to serve.', |
|
232 | - 'event_espresso'), |
|
233 | - 'default' => $this->config->recaptcha_type !== null |
|
234 | - ? $this->config->recaptcha_type |
|
235 | - : 'image', |
|
236 | - 'display_html_label_text' => false, |
|
237 | - ) |
|
238 | - ), |
|
239 | - 'recaptcha_language' => new EE_Select_Input( |
|
240 | - array( |
|
241 | - 'ar' => esc_html__('Arabic', 'event_espresso'), |
|
242 | - 'bg' => esc_html__('Bulgarian', 'event_espresso'), |
|
243 | - 'ca' => esc_html__('Catalan', 'event_espresso'), |
|
244 | - 'zh-CN' => esc_html__('Chinese (Simplified)', 'event_espresso'), |
|
245 | - 'zh-TW' => esc_html__('Chinese (Traditional) ', 'event_espresso'), |
|
246 | - 'hr' => esc_html__('Croatian', 'event_espresso'), |
|
247 | - 'cs' => esc_html__('Czech', 'event_espresso'), |
|
248 | - 'da' => esc_html__('Danish', 'event_espresso'), |
|
249 | - 'nl' => esc_html__('Dutch', 'event_espresso'), |
|
250 | - 'en-GB' => esc_html__('English (UK)', 'event_espresso'), |
|
251 | - 'en' => esc_html__('English (US)', 'event_espresso'), |
|
252 | - 'fil' => esc_html__('Filipino', 'event_espresso'), |
|
253 | - 'fi' => esc_html__('Finnish', 'event_espresso'), |
|
254 | - 'fr' => esc_html__('French', 'event_espresso'), |
|
255 | - 'fr-CA' => esc_html__('French (Canadian)', 'event_espresso'), |
|
256 | - 'de' => esc_html__('German', 'event_espresso'), |
|
257 | - 'de-AT' => esc_html__('German (Austria)', 'event_espresso'), |
|
258 | - 'de-CH' => esc_html__('German (Switzerland)', 'event_espresso'), |
|
259 | - 'el' => esc_html__('Greek', 'event_espresso'), |
|
260 | - 'iw' => esc_html__('Hebrew', 'event_espresso'), |
|
261 | - 'hi' => esc_html__('Hindi', 'event_espresso'), |
|
262 | - 'hu' => esc_html__('Hungarian', 'event_espresso'), |
|
263 | - 'id' => esc_html__('Indonesian', 'event_espresso'), |
|
264 | - 'it' => esc_html__('Italian', 'event_espresso'), |
|
265 | - 'ja' => esc_html__('Japanese', 'event_espresso'), |
|
266 | - 'ko' => esc_html__('Korean', 'event_espresso'), |
|
267 | - 'lv' => esc_html__('Latvian', 'event_espresso'), |
|
268 | - 'lt' => esc_html__('Lithuanian', 'event_espresso'), |
|
269 | - 'no' => esc_html__('Norwegian', 'event_espresso'), |
|
270 | - 'fa' => esc_html__('Persian', 'event_espresso'), |
|
271 | - 'pl' => esc_html__('Polish', 'event_espresso'), |
|
272 | - 'pt' => esc_html__('Portuguese', 'event_espresso'), |
|
273 | - 'pt-BR' => esc_html__('Portuguese (Brazil)', 'event_espresso'), |
|
274 | - 'pt-PT' => esc_html__('Portuguese (Portugal)', 'event_espresso'), |
|
275 | - 'ro' => esc_html__('Romanian', 'event_espresso'), |
|
276 | - 'ru' => esc_html__('Russian', 'event_espresso'), |
|
277 | - 'sr' => esc_html__('Serbian', 'event_espresso'), |
|
278 | - 'sk' => esc_html__('Slovak', 'event_espresso'), |
|
279 | - 'sl' => esc_html__('Slovenian', 'event_espresso'), |
|
280 | - 'es' => esc_html__('Spanish', 'event_espresso'), |
|
281 | - 'es-419' => esc_html__('Spanish (Latin America)', 'event_espresso'), |
|
282 | - 'sv' => esc_html__('Swedish', 'event_espresso'), |
|
283 | - 'th' => esc_html__('Thai', 'event_espresso'), |
|
284 | - 'tr' => esc_html__('Turkish', 'event_espresso'), |
|
285 | - 'uk' => esc_html__('Ukrainian', 'event_espresso'), |
|
286 | - 'vi' => esc_html__('Vietnamese', 'event_espresso'), |
|
287 | - ), |
|
288 | - array( |
|
289 | - 'html_label_text' => esc_html__('Language', 'event_espresso'), |
|
290 | - 'html_help_text' => esc_html__('Forces the widget to render in a specific language.', |
|
291 | - 'event_espresso'), |
|
292 | - 'default' => $this->config->recaptcha_language !== null |
|
293 | - ? $this->config->recaptcha_language : 'en', |
|
294 | - ) |
|
295 | - ), |
|
296 | - ) |
|
297 | - ), |
|
298 | - ) |
|
299 | - ); |
|
300 | - } |
|
175 | + /** |
|
176 | + * @return EE_Form_Section_Proper |
|
177 | + * @throws EE_Error |
|
178 | + */ |
|
179 | + protected function appearanceSettings() |
|
180 | + { |
|
181 | + return new EE_Form_Section_Proper( |
|
182 | + array( |
|
183 | + 'name' => 'recaptcha_appearance_settings_tbl', |
|
184 | + 'html_id' => 'recaptcha_appearance_settings_tbl', |
|
185 | + 'html_class' => 'form-table', |
|
186 | + 'layout_strategy' => new EE_Admin_Two_Column_Layout(), |
|
187 | + 'subsections' => apply_filters( |
|
188 | + 'FHEE__EED_Recaptcha___recaptcha_appearance_settings__form_subsections', |
|
189 | + array( |
|
190 | + 'recaptcha_theme' => new EE_Radio_Button_Input( |
|
191 | + array( |
|
192 | + 'invisible' => esc_html__('Invisible', 'event_espresso'), |
|
193 | + 'light' => esc_html__('Light', 'event_espresso'), |
|
194 | + 'dark' => esc_html__('Dark', 'event_espresso'), |
|
195 | + ), |
|
196 | + array( |
|
197 | + 'html_label_text' => esc_html__('Theme', 'event_espresso'), |
|
198 | + 'html_help_text' => esc_html__('The color theme of the widget.', |
|
199 | + 'event_espresso'), |
|
200 | + 'default' => $this->config->recaptcha_theme !== null |
|
201 | + ? $this->config->recaptcha_theme |
|
202 | + : 'invisible', |
|
203 | + 'display_html_label_text' => false, |
|
204 | + ) |
|
205 | + ), |
|
206 | + 'recaptcha_badge' => new EE_Radio_Button_Input( |
|
207 | + array( |
|
208 | + 'bottomleft' => esc_html__('Bottom Left', 'event_espresso'), |
|
209 | + 'bottomright' => esc_html__('Bottom Right', 'event_espresso'), |
|
210 | + 'inline' => esc_html__('Inline', 'event_espresso'), |
|
211 | + ), |
|
212 | + array( |
|
213 | + 'html_label_text' => esc_html__('Invisible reCAPTCHA Badge Position', 'event_espresso'), |
|
214 | + 'html_help_text' => esc_html__( |
|
215 | + 'If using Invisible reCAPTCHA, then this determines the position of the reCAPTCHA badge. "Bottom Left" and "Bottom Right" both will float at the bottom of the screen. "Inline" appears beside the submit button but allows you to control the CSS.', |
|
216 | + 'event_espresso' |
|
217 | + ), |
|
218 | + 'default' => $this->config->recaptcha_badge !== null |
|
219 | + ? $this->config->recaptcha_badge |
|
220 | + : 'bottomleft', |
|
221 | + 'display_html_label_text' => false, |
|
222 | + ) |
|
223 | + ), |
|
224 | + 'recaptcha_type' => new EE_Radio_Button_Input( |
|
225 | + array( |
|
226 | + 'image' => esc_html__('Image', 'event_espresso'), |
|
227 | + 'audio' => esc_html__('Audio', 'event_espresso'), |
|
228 | + ), |
|
229 | + array( |
|
230 | + 'html_label_text' => esc_html__('Type', 'event_espresso'), |
|
231 | + 'html_help_text' => esc_html__('The type of CAPTCHA to serve.', |
|
232 | + 'event_espresso'), |
|
233 | + 'default' => $this->config->recaptcha_type !== null |
|
234 | + ? $this->config->recaptcha_type |
|
235 | + : 'image', |
|
236 | + 'display_html_label_text' => false, |
|
237 | + ) |
|
238 | + ), |
|
239 | + 'recaptcha_language' => new EE_Select_Input( |
|
240 | + array( |
|
241 | + 'ar' => esc_html__('Arabic', 'event_espresso'), |
|
242 | + 'bg' => esc_html__('Bulgarian', 'event_espresso'), |
|
243 | + 'ca' => esc_html__('Catalan', 'event_espresso'), |
|
244 | + 'zh-CN' => esc_html__('Chinese (Simplified)', 'event_espresso'), |
|
245 | + 'zh-TW' => esc_html__('Chinese (Traditional) ', 'event_espresso'), |
|
246 | + 'hr' => esc_html__('Croatian', 'event_espresso'), |
|
247 | + 'cs' => esc_html__('Czech', 'event_espresso'), |
|
248 | + 'da' => esc_html__('Danish', 'event_espresso'), |
|
249 | + 'nl' => esc_html__('Dutch', 'event_espresso'), |
|
250 | + 'en-GB' => esc_html__('English (UK)', 'event_espresso'), |
|
251 | + 'en' => esc_html__('English (US)', 'event_espresso'), |
|
252 | + 'fil' => esc_html__('Filipino', 'event_espresso'), |
|
253 | + 'fi' => esc_html__('Finnish', 'event_espresso'), |
|
254 | + 'fr' => esc_html__('French', 'event_espresso'), |
|
255 | + 'fr-CA' => esc_html__('French (Canadian)', 'event_espresso'), |
|
256 | + 'de' => esc_html__('German', 'event_espresso'), |
|
257 | + 'de-AT' => esc_html__('German (Austria)', 'event_espresso'), |
|
258 | + 'de-CH' => esc_html__('German (Switzerland)', 'event_espresso'), |
|
259 | + 'el' => esc_html__('Greek', 'event_espresso'), |
|
260 | + 'iw' => esc_html__('Hebrew', 'event_espresso'), |
|
261 | + 'hi' => esc_html__('Hindi', 'event_espresso'), |
|
262 | + 'hu' => esc_html__('Hungarian', 'event_espresso'), |
|
263 | + 'id' => esc_html__('Indonesian', 'event_espresso'), |
|
264 | + 'it' => esc_html__('Italian', 'event_espresso'), |
|
265 | + 'ja' => esc_html__('Japanese', 'event_espresso'), |
|
266 | + 'ko' => esc_html__('Korean', 'event_espresso'), |
|
267 | + 'lv' => esc_html__('Latvian', 'event_espresso'), |
|
268 | + 'lt' => esc_html__('Lithuanian', 'event_espresso'), |
|
269 | + 'no' => esc_html__('Norwegian', 'event_espresso'), |
|
270 | + 'fa' => esc_html__('Persian', 'event_espresso'), |
|
271 | + 'pl' => esc_html__('Polish', 'event_espresso'), |
|
272 | + 'pt' => esc_html__('Portuguese', 'event_espresso'), |
|
273 | + 'pt-BR' => esc_html__('Portuguese (Brazil)', 'event_espresso'), |
|
274 | + 'pt-PT' => esc_html__('Portuguese (Portugal)', 'event_espresso'), |
|
275 | + 'ro' => esc_html__('Romanian', 'event_espresso'), |
|
276 | + 'ru' => esc_html__('Russian', 'event_espresso'), |
|
277 | + 'sr' => esc_html__('Serbian', 'event_espresso'), |
|
278 | + 'sk' => esc_html__('Slovak', 'event_espresso'), |
|
279 | + 'sl' => esc_html__('Slovenian', 'event_espresso'), |
|
280 | + 'es' => esc_html__('Spanish', 'event_espresso'), |
|
281 | + 'es-419' => esc_html__('Spanish (Latin America)', 'event_espresso'), |
|
282 | + 'sv' => esc_html__('Swedish', 'event_espresso'), |
|
283 | + 'th' => esc_html__('Thai', 'event_espresso'), |
|
284 | + 'tr' => esc_html__('Turkish', 'event_espresso'), |
|
285 | + 'uk' => esc_html__('Ukrainian', 'event_espresso'), |
|
286 | + 'vi' => esc_html__('Vietnamese', 'event_espresso'), |
|
287 | + ), |
|
288 | + array( |
|
289 | + 'html_label_text' => esc_html__('Language', 'event_espresso'), |
|
290 | + 'html_help_text' => esc_html__('Forces the widget to render in a specific language.', |
|
291 | + 'event_espresso'), |
|
292 | + 'default' => $this->config->recaptcha_language !== null |
|
293 | + ? $this->config->recaptcha_language : 'en', |
|
294 | + ) |
|
295 | + ), |
|
296 | + ) |
|
297 | + ), |
|
298 | + ) |
|
299 | + ); |
|
300 | + } |
|
301 | 301 | |
302 | 302 | |
303 | - /** |
|
304 | - * @param EE_Registration_Config $EE_Registration_Config |
|
305 | - * @return EE_Registration_Config |
|
306 | - * @throws InvalidArgumentException |
|
307 | - * @throws InvalidInterfaceException |
|
308 | - * @throws InvalidDataTypeException |
|
309 | - * @throws EE_Error |
|
310 | - * @throws ReflectionException |
|
311 | - */ |
|
312 | - public function updateAdminSettings(EE_Registration_Config $EE_Registration_Config) |
|
313 | - { |
|
314 | - try { |
|
315 | - $recaptcha_settings_form = $this->settingsForm(); |
|
316 | - // if not displaying a form, then check for form submission |
|
317 | - if ($recaptcha_settings_form->was_submitted()) { |
|
318 | - // capture form data |
|
319 | - $recaptcha_settings_form->receive_form_submission(); |
|
320 | - // validate form data |
|
321 | - if ($recaptcha_settings_form->is_valid()) { |
|
322 | - // grab validated data from form |
|
323 | - $valid_data = $recaptcha_settings_form->valid_data(); |
|
324 | - // user proofing recaptcha: If Use reCAPTCHA is set to yes but we dont' have site or secret keys then set Use reCAPTCHA to FALSE and give error message. |
|
325 | - if ( |
|
326 | - $valid_data['main_settings']['use_captcha'] |
|
327 | - && ( |
|
328 | - ! $EE_Registration_Config->use_captcha |
|
329 | - && ( |
|
330 | - empty($valid_data['main_settings']['recaptcha_publickey']) |
|
331 | - || empty($valid_data['main_settings']['recaptcha_privatekey']) |
|
332 | - ) |
|
333 | - ) |
|
334 | - && apply_filters( |
|
335 | - 'FHEE__Extend_Registration_Form_Admin_Page__check_for_recaptcha_keys', |
|
336 | - true, |
|
337 | - $EE_Registration_Config |
|
338 | - ) |
|
339 | - ) { |
|
340 | - $valid_data['main_settings']['use_captcha'] = false; |
|
341 | - EE_Error::add_error( |
|
342 | - esc_html__( |
|
343 | - 'The use reCAPTCHA setting has been reset to "no". In order to enable the reCAPTCHA service, you must enter a Site Key and Secret Key.', |
|
344 | - 'event_espresso' |
|
345 | - ), |
|
346 | - __FILE__, __FUNCTION__, __LINE__ |
|
347 | - ); |
|
348 | - } |
|
349 | - $EE_Registration_Config->use_captcha = $valid_data['main_settings']['use_captcha']; |
|
350 | - $EE_Registration_Config->recaptcha_publickey = $valid_data['main_settings']['recaptcha_publickey']; |
|
351 | - $EE_Registration_Config->recaptcha_protected_forms = $valid_data['main_settings']['recaptcha_protected_forms']; |
|
352 | - $EE_Registration_Config->recaptcha_privatekey = $valid_data['main_settings']['recaptcha_privatekey']; |
|
353 | - $EE_Registration_Config->recaptcha_type = $valid_data['appearance_settings']['recaptcha_type']; |
|
354 | - $EE_Registration_Config->recaptcha_theme = $valid_data['appearance_settings']['recaptcha_theme']; |
|
355 | - $EE_Registration_Config->recaptcha_badge = $valid_data['appearance_settings']['recaptcha_badge']; |
|
356 | - $EE_Registration_Config->recaptcha_language = $valid_data['appearance_settings']['recaptcha_language']; |
|
357 | - } else { |
|
358 | - if ($recaptcha_settings_form->submission_error_message() !== '') { |
|
359 | - EE_Error::add_error( |
|
360 | - $recaptcha_settings_form->submission_error_message(), |
|
361 | - __FILE__, __FUNCTION__, __LINE__ |
|
362 | - ); |
|
363 | - } |
|
364 | - } |
|
365 | - } |
|
366 | - } catch (EE_Error $e) { |
|
367 | - $e->get_error(); |
|
368 | - } |
|
369 | - return $EE_Registration_Config; |
|
370 | - } |
|
303 | + /** |
|
304 | + * @param EE_Registration_Config $EE_Registration_Config |
|
305 | + * @return EE_Registration_Config |
|
306 | + * @throws InvalidArgumentException |
|
307 | + * @throws InvalidInterfaceException |
|
308 | + * @throws InvalidDataTypeException |
|
309 | + * @throws EE_Error |
|
310 | + * @throws ReflectionException |
|
311 | + */ |
|
312 | + public function updateAdminSettings(EE_Registration_Config $EE_Registration_Config) |
|
313 | + { |
|
314 | + try { |
|
315 | + $recaptcha_settings_form = $this->settingsForm(); |
|
316 | + // if not displaying a form, then check for form submission |
|
317 | + if ($recaptcha_settings_form->was_submitted()) { |
|
318 | + // capture form data |
|
319 | + $recaptcha_settings_form->receive_form_submission(); |
|
320 | + // validate form data |
|
321 | + if ($recaptcha_settings_form->is_valid()) { |
|
322 | + // grab validated data from form |
|
323 | + $valid_data = $recaptcha_settings_form->valid_data(); |
|
324 | + // user proofing recaptcha: If Use reCAPTCHA is set to yes but we dont' have site or secret keys then set Use reCAPTCHA to FALSE and give error message. |
|
325 | + if ( |
|
326 | + $valid_data['main_settings']['use_captcha'] |
|
327 | + && ( |
|
328 | + ! $EE_Registration_Config->use_captcha |
|
329 | + && ( |
|
330 | + empty($valid_data['main_settings']['recaptcha_publickey']) |
|
331 | + || empty($valid_data['main_settings']['recaptcha_privatekey']) |
|
332 | + ) |
|
333 | + ) |
|
334 | + && apply_filters( |
|
335 | + 'FHEE__Extend_Registration_Form_Admin_Page__check_for_recaptcha_keys', |
|
336 | + true, |
|
337 | + $EE_Registration_Config |
|
338 | + ) |
|
339 | + ) { |
|
340 | + $valid_data['main_settings']['use_captcha'] = false; |
|
341 | + EE_Error::add_error( |
|
342 | + esc_html__( |
|
343 | + 'The use reCAPTCHA setting has been reset to "no". In order to enable the reCAPTCHA service, you must enter a Site Key and Secret Key.', |
|
344 | + 'event_espresso' |
|
345 | + ), |
|
346 | + __FILE__, __FUNCTION__, __LINE__ |
|
347 | + ); |
|
348 | + } |
|
349 | + $EE_Registration_Config->use_captcha = $valid_data['main_settings']['use_captcha']; |
|
350 | + $EE_Registration_Config->recaptcha_publickey = $valid_data['main_settings']['recaptcha_publickey']; |
|
351 | + $EE_Registration_Config->recaptcha_protected_forms = $valid_data['main_settings']['recaptcha_protected_forms']; |
|
352 | + $EE_Registration_Config->recaptcha_privatekey = $valid_data['main_settings']['recaptcha_privatekey']; |
|
353 | + $EE_Registration_Config->recaptcha_type = $valid_data['appearance_settings']['recaptcha_type']; |
|
354 | + $EE_Registration_Config->recaptcha_theme = $valid_data['appearance_settings']['recaptcha_theme']; |
|
355 | + $EE_Registration_Config->recaptcha_badge = $valid_data['appearance_settings']['recaptcha_badge']; |
|
356 | + $EE_Registration_Config->recaptcha_language = $valid_data['appearance_settings']['recaptcha_language']; |
|
357 | + } else { |
|
358 | + if ($recaptcha_settings_form->submission_error_message() !== '') { |
|
359 | + EE_Error::add_error( |
|
360 | + $recaptcha_settings_form->submission_error_message(), |
|
361 | + __FILE__, __FUNCTION__, __LINE__ |
|
362 | + ); |
|
363 | + } |
|
364 | + } |
|
365 | + } |
|
366 | + } catch (EE_Error $e) { |
|
367 | + $e->get_error(); |
|
368 | + } |
|
369 | + return $EE_Registration_Config; |
|
370 | + } |
|
371 | 371 | } |
@@ -12,9 +12,9 @@ |
||
12 | 12 | */ |
13 | 13 | interface CaffeinatedInterface |
14 | 14 | { |
15 | - /** |
|
16 | - * Used to indicate when functionality is caffeinated or not. |
|
17 | - * @return bool |
|
18 | - */ |
|
19 | - public function isCaffeinated(); |
|
15 | + /** |
|
16 | + * Used to indicate when functionality is caffeinated or not. |
|
17 | + * @return bool |
|
18 | + */ |
|
19 | + public function isCaffeinated(); |
|
20 | 20 | } |
21 | 21 | \ No newline at end of file |
@@ -19,54 +19,54 @@ |
||
19 | 19 | class Domain extends DomainBase implements CaffeinatedInterface |
20 | 20 | { |
21 | 21 | |
22 | - /** |
|
23 | - * URL path component used to denote an API request |
|
24 | - */ |
|
25 | - const API_NAMESPACE = 'ee/v'; |
|
22 | + /** |
|
23 | + * URL path component used to denote an API request |
|
24 | + */ |
|
25 | + const API_NAMESPACE = 'ee/v'; |
|
26 | 26 | |
27 | - /** |
|
28 | - * Slug used for the context where a registration status is changed from a manual trigger in the Registration Admin |
|
29 | - * Page ui. |
|
30 | - */ |
|
31 | - const CONTEXT_REGISTRATION_STATUS_CHANGE_REGISTRATION_ADMIN |
|
32 | - = 'manual_registration_status_change_from_registration_admin'; |
|
27 | + /** |
|
28 | + * Slug used for the context where a registration status is changed from a manual trigger in the Registration Admin |
|
29 | + * Page ui. |
|
30 | + */ |
|
31 | + const CONTEXT_REGISTRATION_STATUS_CHANGE_REGISTRATION_ADMIN |
|
32 | + = 'manual_registration_status_change_from_registration_admin'; |
|
33 | 33 | |
34 | - const CONTEXT_REGISTRATION_STATUS_CHANGE_REGISTRATION_ADMIN_NOTIFY |
|
35 | - = 'manual_registration_status_change_from_registration_admin_and_notify'; |
|
34 | + const CONTEXT_REGISTRATION_STATUS_CHANGE_REGISTRATION_ADMIN_NOTIFY |
|
35 | + = 'manual_registration_status_change_from_registration_admin_and_notify'; |
|
36 | 36 | |
37 | 37 | |
38 | - /** |
|
39 | - * Whether or not EE core is the full premium version. |
|
40 | - * @since $VID:$ |
|
41 | - * @var bool |
|
42 | - */ |
|
43 | - private $caffeinated; |
|
38 | + /** |
|
39 | + * Whether or not EE core is the full premium version. |
|
40 | + * @since $VID:$ |
|
41 | + * @var bool |
|
42 | + */ |
|
43 | + private $caffeinated; |
|
44 | 44 | |
45 | 45 | |
46 | - public function __construct(FilePath $plugin_file, Version $version) |
|
47 | - { |
|
48 | - parent::__construct($plugin_file, $version); |
|
49 | - $this->setCaffeinated(); |
|
50 | - } |
|
46 | + public function __construct(FilePath $plugin_file, Version $version) |
|
47 | + { |
|
48 | + parent::__construct($plugin_file, $version); |
|
49 | + $this->setCaffeinated(); |
|
50 | + } |
|
51 | 51 | |
52 | - /** |
|
53 | - * Whether or not EE core is the full premium version. |
|
54 | - * @since $VID:$ |
|
55 | - * @return bool |
|
56 | - */ |
|
57 | - public function isCaffeinated() |
|
58 | - { |
|
59 | - return $this->caffeinated; |
|
60 | - } |
|
52 | + /** |
|
53 | + * Whether or not EE core is the full premium version. |
|
54 | + * @since $VID:$ |
|
55 | + * @return bool |
|
56 | + */ |
|
57 | + public function isCaffeinated() |
|
58 | + { |
|
59 | + return $this->caffeinated; |
|
60 | + } |
|
61 | 61 | |
62 | 62 | |
63 | - /** |
|
64 | - * Setter for $is_caffeinated property. |
|
65 | - * @since $VID:$ |
|
66 | - */ |
|
67 | - private function setCaffeinated() |
|
68 | - { |
|
69 | - $this->caffeinated = (! defined('EE_DECAF') || EE_DECAF !== true) |
|
70 | - && is_readable($this->pluginPath() . 'caffeinated/brewing_regular.php'); |
|
71 | - } |
|
63 | + /** |
|
64 | + * Setter for $is_caffeinated property. |
|
65 | + * @since $VID:$ |
|
66 | + */ |
|
67 | + private function setCaffeinated() |
|
68 | + { |
|
69 | + $this->caffeinated = (! defined('EE_DECAF') || EE_DECAF !== true) |
|
70 | + && is_readable($this->pluginPath() . 'caffeinated/brewing_regular.php'); |
|
71 | + } |
|
72 | 72 | } |
@@ -66,7 +66,7 @@ |
||
66 | 66 | */ |
67 | 67 | private function setCaffeinated() |
68 | 68 | { |
69 | - $this->caffeinated = (! defined('EE_DECAF') || EE_DECAF !== true) |
|
70 | - && is_readable($this->pluginPath() . 'caffeinated/brewing_regular.php'); |
|
69 | + $this->caffeinated = ( ! defined('EE_DECAF') || EE_DECAF !== true) |
|
70 | + && is_readable($this->pluginPath().'caffeinated/brewing_regular.php'); |
|
71 | 71 | } |
72 | 72 | } |