@@ -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); |
@@ -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__( |
@@ -586,7 +586,7 @@ discard block |
||
586 | 586 | public function is_valid() |
587 | 587 | { |
588 | 588 | if ($this->is_valid === null) { |
589 | - if (! $this->has_received_submission()) { |
|
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' . '/form_section_validation.js', |
|
713 | + EE_GLOBAL_ASSETS_URL.'scripts'.'/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 | |
@@ -1245,7 +1245,7 @@ discard block |
||
1245 | 1245 | public function add_subsections($new_subsections, $subsection_name_to_target = null, $add_before = true) |
1246 | 1246 | { |
1247 | 1247 | foreach ($new_subsections as $subsection_name => $subsection) { |
1248 | - if (! $subsection instanceof EE_Form_Section_Base) { |
|
1248 | + if ( ! $subsection instanceof EE_Form_Section_Base) { |
|
1249 | 1249 | EE_Error::add_error( |
1250 | 1250 | sprintf( |
1251 | 1251 | esc_html__( |
@@ -1257,7 +1257,7 @@ discard block |
||
1257 | 1257 | $this->name() |
1258 | 1258 | ) |
1259 | 1259 | ); |
1260 | - unset($new_subsections[ $subsection_name ]); |
|
1260 | + unset($new_subsections[$subsection_name]); |
|
1261 | 1261 | } |
1262 | 1262 | } |
1263 | 1263 | $this->_subsections = EEH_Array::insert_into_array( |
@@ -1372,7 +1372,7 @@ discard block |
||
1372 | 1372 | public function html_name_prefix() |
1373 | 1373 | { |
1374 | 1374 | if ($this->parent_section() instanceof EE_Form_Section_Proper) { |
1375 | - return $this->parent_section()->html_name_prefix() . '[' . $this->name() . ']'; |
|
1375 | + return $this->parent_section()->html_name_prefix().'['.$this->name().']'; |
|
1376 | 1376 | } |
1377 | 1377 | return $this->name(); |
1378 | 1378 | } |
@@ -1412,7 +1412,7 @@ discard block |
||
1412 | 1412 | */ |
1413 | 1413 | public function ensure_construct_finalized_called() |
1414 | 1414 | { |
1415 | - if (! $this->_construction_finalized) { |
|
1415 | + if ( ! $this->_construction_finalized) { |
|
1416 | 1416 | $this->_construct_finalize($this->_parent_section, $this->_name); |
1417 | 1417 | } |
1418 | 1418 | } |
@@ -14,1530 +14,1530 @@ |
||
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 | - protected static $_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 | - protected static $_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 ( |
|
262 | - $this->cached_request_data === null |
|
263 | - || ( |
|
264 | - $req_data !== null |
|
265 | - && $req_data !== $this->cached_request_data |
|
266 | - ) |
|
267 | - ) { |
|
268 | - $req_data = apply_filters( |
|
269 | - 'FHEE__EE_Form_Section_Proper__receive_form_submission__req_data', |
|
270 | - $req_data, |
|
271 | - $this |
|
272 | - ); |
|
273 | - if ($req_data === null) { |
|
274 | - $req_data = array_merge($_GET, $_POST); |
|
275 | - } |
|
276 | - $req_data = apply_filters( |
|
277 | - 'FHEE__EE_Form_Section_Proper__receive_form_submission__request_data', |
|
278 | - $req_data, |
|
279 | - $this |
|
280 | - ); |
|
281 | - $this->cached_request_data = (array) $req_data; |
|
282 | - } |
|
283 | - return $this->cached_request_data; |
|
284 | - } |
|
285 | - |
|
286 | - |
|
287 | - /** |
|
288 | - * After the form section is initially created, call this to sanitize the data in the submission |
|
289 | - * which relates to this form section, validate it, and set it as properties on the form. |
|
290 | - * |
|
291 | - * @param array|null $req_data should usually be $_POST (the default). |
|
292 | - * However, you CAN supply a different array. |
|
293 | - * Consider using set_defaults() instead however. |
|
294 | - * (If you rendered the form in the page using echo $form_x->get_html() |
|
295 | - * the inputs will have the correct name in the request data for this function |
|
296 | - * to find them and populate the form with them. |
|
297 | - * If you have a flat form (with only input subsections), |
|
298 | - * you can supply a flat array where keys |
|
299 | - * are the form input names and values are their values) |
|
300 | - * @param boolean $validate whether or not to perform validation on this data. Default is, |
|
301 | - * of course, to validate that data, and set errors on the invalid values. |
|
302 | - * But if the data has already been validated |
|
303 | - * (eg you validated the data then stored it in the DB) |
|
304 | - * you may want to skip this step. |
|
305 | - * @throws InvalidArgumentException |
|
306 | - * @throws InvalidInterfaceException |
|
307 | - * @throws InvalidDataTypeException |
|
308 | - * @throws EE_Error |
|
309 | - */ |
|
310 | - public function receive_form_submission($req_data = null, $validate = true) |
|
311 | - { |
|
312 | - $req_data = $this->getCachedRequest($req_data); |
|
313 | - $this->_normalize($req_data); |
|
314 | - if ($validate) { |
|
315 | - $this->_validate(); |
|
316 | - // if it's invalid, we're going to want to re-display so remember what they submitted |
|
317 | - if (! $this->is_valid()) { |
|
318 | - $this->store_submitted_form_data_in_session(); |
|
319 | - } |
|
320 | - } |
|
321 | - if ($this->submission_error_message() === '' && ! $this->is_valid()) { |
|
322 | - $this->set_submission_error_message(); |
|
323 | - } |
|
324 | - do_action( |
|
325 | - 'AHEE__EE_Form_Section_Proper__receive_form_submission__end', |
|
326 | - $req_data, |
|
327 | - $this, |
|
328 | - $validate |
|
329 | - ); |
|
330 | - } |
|
331 | - |
|
332 | - |
|
333 | - /** |
|
334 | - * caches the originally submitted input values in the session |
|
335 | - * so that they can be used to repopulate the form if it failed validation |
|
336 | - * |
|
337 | - * @return boolean whether or not the data was successfully stored in the session |
|
338 | - * @throws InvalidArgumentException |
|
339 | - * @throws InvalidInterfaceException |
|
340 | - * @throws InvalidDataTypeException |
|
341 | - * @throws EE_Error |
|
342 | - */ |
|
343 | - protected function store_submitted_form_data_in_session() |
|
344 | - { |
|
345 | - return EE_Registry::instance()->SSN->set_session_data( |
|
346 | - array( |
|
347 | - EE_Form_Section_Proper::SUBMITTED_FORM_DATA_SSN_KEY => $this->submitted_values(true), |
|
348 | - ) |
|
349 | - ); |
|
350 | - } |
|
351 | - |
|
352 | - |
|
353 | - /** |
|
354 | - * retrieves the originally submitted input values in the session |
|
355 | - * so that they can be used to repopulate the form if it failed validation |
|
356 | - * |
|
357 | - * @return array |
|
358 | - * @throws InvalidArgumentException |
|
359 | - * @throws InvalidInterfaceException |
|
360 | - * @throws InvalidDataTypeException |
|
361 | - */ |
|
362 | - protected function get_submitted_form_data_from_session() |
|
363 | - { |
|
364 | - $session = EE_Registry::instance()->SSN; |
|
365 | - if ($session instanceof EE_Session) { |
|
366 | - return $session->get_session_data( |
|
367 | - EE_Form_Section_Proper::SUBMITTED_FORM_DATA_SSN_KEY |
|
368 | - ); |
|
369 | - } |
|
370 | - return array(); |
|
371 | - } |
|
372 | - |
|
373 | - |
|
374 | - /** |
|
375 | - * flushed the originally submitted input values from the session |
|
376 | - * |
|
377 | - * @return boolean whether or not the data was successfully removed from the session |
|
378 | - * @throws InvalidArgumentException |
|
379 | - * @throws InvalidInterfaceException |
|
380 | - * @throws InvalidDataTypeException |
|
381 | - */ |
|
382 | - public static function flush_submitted_form_data_from_session() |
|
383 | - { |
|
384 | - return EE_Registry::instance()->SSN->reset_data( |
|
385 | - array(EE_Form_Section_Proper::SUBMITTED_FORM_DATA_SSN_KEY) |
|
386 | - ); |
|
387 | - } |
|
388 | - |
|
389 | - |
|
390 | - /** |
|
391 | - * Populates this form and its subsections with data from the session. |
|
392 | - * (Wrapper for EE_Form_Section_Proper::receive_form_submission, so it shows |
|
393 | - * validation errors when displaying too) |
|
394 | - * Returns true if the form was populated from the session, false otherwise |
|
395 | - * |
|
396 | - * @return boolean |
|
397 | - * @throws InvalidArgumentException |
|
398 | - * @throws InvalidInterfaceException |
|
399 | - * @throws InvalidDataTypeException |
|
400 | - * @throws EE_Error |
|
401 | - */ |
|
402 | - public function populate_from_session() |
|
403 | - { |
|
404 | - $form_data_in_session = $this->get_submitted_form_data_from_session(); |
|
405 | - if (empty($form_data_in_session)) { |
|
406 | - return false; |
|
407 | - } |
|
408 | - $this->receive_form_submission($form_data_in_session); |
|
409 | - add_action('shutdown', array('EE_Form_Section_Proper', 'flush_submitted_form_data_from_session')); |
|
410 | - if ($this->form_data_present_in($form_data_in_session)) { |
|
411 | - return true; |
|
412 | - } |
|
413 | - return false; |
|
414 | - } |
|
415 | - |
|
416 | - |
|
417 | - /** |
|
418 | - * Populates the default data for the form, given an array where keys are |
|
419 | - * the input names, and values are their values (preferably normalized to be their |
|
420 | - * proper PHP types, not all strings... although that should be ok too). |
|
421 | - * Proper subsections are sub-arrays, the key being the subsection's name, and |
|
422 | - * the value being an array formatted in teh same way |
|
423 | - * |
|
424 | - * @param array $default_data |
|
425 | - * @throws EE_Error |
|
426 | - */ |
|
427 | - public function populate_defaults($default_data) |
|
428 | - { |
|
429 | - foreach ($this->subsections(false) as $subsection_name => $subsection) { |
|
430 | - if (isset($default_data[ $subsection_name ])) { |
|
431 | - if ($subsection instanceof EE_Form_Input_Base) { |
|
432 | - $subsection->set_default($default_data[ $subsection_name ]); |
|
433 | - } elseif ($subsection instanceof EE_Form_Section_Proper) { |
|
434 | - $subsection->populate_defaults($default_data[ $subsection_name ]); |
|
435 | - } |
|
436 | - } |
|
437 | - } |
|
438 | - } |
|
439 | - |
|
440 | - |
|
441 | - /** |
|
442 | - * returns true if subsection exists |
|
443 | - * |
|
444 | - * @param string $name |
|
445 | - * @return boolean |
|
446 | - */ |
|
447 | - public function subsection_exists($name) |
|
448 | - { |
|
449 | - return isset($this->_subsections[ $name ]) ? true : false; |
|
450 | - } |
|
451 | - |
|
452 | - |
|
453 | - /** |
|
454 | - * Gets the subsection specified by its name |
|
455 | - * |
|
456 | - * @param string $name |
|
457 | - * @param boolean $require_construction_to_be_finalized most client code should leave this as TRUE |
|
458 | - * so that the inputs will be properly configured. |
|
459 | - * However, some client code may be ok |
|
460 | - * with construction finalize being called later |
|
461 | - * (realizing that the subsections' html names |
|
462 | - * might not be set yet, etc.) |
|
463 | - * @return EE_Form_Section_Base |
|
464 | - * @throws EE_Error |
|
465 | - */ |
|
466 | - public function get_subsection($name, $require_construction_to_be_finalized = true) |
|
467 | - { |
|
468 | - if ($require_construction_to_be_finalized) { |
|
469 | - $this->ensure_construct_finalized_called(); |
|
470 | - } |
|
471 | - return $this->subsection_exists($name) ? $this->_subsections[ $name ] : null; |
|
472 | - } |
|
473 | - |
|
474 | - |
|
475 | - /** |
|
476 | - * Gets all the validatable subsections of this form section |
|
477 | - * |
|
478 | - * @return EE_Form_Section_Validatable[] |
|
479 | - * @throws EE_Error |
|
480 | - */ |
|
481 | - public function get_validatable_subsections() |
|
482 | - { |
|
483 | - $validatable_subsections = array(); |
|
484 | - foreach ($this->subsections() as $name => $obj) { |
|
485 | - if ($obj instanceof EE_Form_Section_Validatable) { |
|
486 | - $validatable_subsections[ $name ] = $obj; |
|
487 | - } |
|
488 | - } |
|
489 | - return $validatable_subsections; |
|
490 | - } |
|
491 | - |
|
492 | - |
|
493 | - /** |
|
494 | - * Gets an input by the given name. If not found, or if its not an EE_FOrm_Input_Base child, |
|
495 | - * throw an EE_Error. |
|
496 | - * |
|
497 | - * @param string $name |
|
498 | - * @param boolean $require_construction_to_be_finalized most client code should |
|
499 | - * leave this as TRUE so that the inputs will be properly |
|
500 | - * configured. However, some client code may be ok with |
|
501 | - * construction finalize being called later |
|
502 | - * (realizing that the subsections' html names might not be |
|
503 | - * set yet, etc.) |
|
504 | - * @return EE_Form_Input_Base |
|
505 | - * @throws EE_Error |
|
506 | - */ |
|
507 | - public function get_input($name, $require_construction_to_be_finalized = true) |
|
508 | - { |
|
509 | - $subsection = $this->get_subsection( |
|
510 | - $name, |
|
511 | - $require_construction_to_be_finalized |
|
512 | - ); |
|
513 | - if (! $subsection instanceof EE_Form_Input_Base) { |
|
514 | - throw new EE_Error( |
|
515 | - sprintf( |
|
516 | - esc_html__( |
|
517 | - "Subsection '%s' is not an instanceof EE_Form_Input_Base on form '%s'. It is a '%s'", |
|
518 | - 'event_espresso' |
|
519 | - ), |
|
520 | - $name, |
|
521 | - get_class($this), |
|
522 | - $subsection ? get_class($subsection) : esc_html__('NULL', 'event_espresso') |
|
523 | - ) |
|
524 | - ); |
|
525 | - } |
|
526 | - return $subsection; |
|
527 | - } |
|
528 | - |
|
529 | - |
|
530 | - /** |
|
531 | - * Like get_input(), gets the proper subsection of the form given the name, |
|
532 | - * otherwise throws an EE_Error |
|
533 | - * |
|
534 | - * @param string $name |
|
535 | - * @param boolean $require_construction_to_be_finalized most client code should |
|
536 | - * leave this as TRUE so that the inputs will be properly |
|
537 | - * configured. However, some client code may be ok with |
|
538 | - * construction finalize being called later |
|
539 | - * (realizing that the subsections' html names might not be |
|
540 | - * set yet, etc.) |
|
541 | - * @return EE_Form_Section_Proper |
|
542 | - * @throws EE_Error |
|
543 | - */ |
|
544 | - public function get_proper_subsection($name, $require_construction_to_be_finalized = true) |
|
545 | - { |
|
546 | - $subsection = $this->get_subsection( |
|
547 | - $name, |
|
548 | - $require_construction_to_be_finalized |
|
549 | - ); |
|
550 | - if (! $subsection instanceof EE_Form_Section_Proper) { |
|
551 | - throw new EE_Error( |
|
552 | - sprintf( |
|
553 | - esc_html__( |
|
554 | - "Subsection '%'s is not an instanceof EE_Form_Section_Proper on form '%s'", |
|
555 | - 'event_espresso' |
|
556 | - ), |
|
557 | - $name, |
|
558 | - get_class($this) |
|
559 | - ) |
|
560 | - ); |
|
561 | - } |
|
562 | - return $subsection; |
|
563 | - } |
|
564 | - |
|
565 | - |
|
566 | - /** |
|
567 | - * Gets the value of the specified input. Should be called after receive_form_submission() |
|
568 | - * or populate_defaults() on the form, where the normalized value on the input is set. |
|
569 | - * |
|
570 | - * @param string $name |
|
571 | - * @return mixed depending on the input's type and its normalization strategy |
|
572 | - * @throws EE_Error |
|
573 | - */ |
|
574 | - public function get_input_value($name) |
|
575 | - { |
|
576 | - $input = $this->get_input($name); |
|
577 | - return $input->normalized_value(); |
|
578 | - } |
|
579 | - |
|
580 | - |
|
581 | - /** |
|
582 | - * Checks if this form section itself is valid, and then checks its subsections |
|
583 | - * |
|
584 | - * @throws EE_Error |
|
585 | - * @return boolean |
|
586 | - */ |
|
587 | - public function is_valid() |
|
588 | - { |
|
589 | - if ($this->is_valid === null) { |
|
590 | - if (! $this->has_received_submission()) { |
|
591 | - throw new EE_Error( |
|
592 | - sprintf( |
|
593 | - esc_html__( |
|
594 | - 'You cannot check if a form is valid before receiving the form submission using receive_form_submission', |
|
595 | - 'event_espresso' |
|
596 | - ) |
|
597 | - ) |
|
598 | - ); |
|
599 | - } |
|
600 | - if (! parent::is_valid()) { |
|
601 | - $this->is_valid = false; |
|
602 | - } else { |
|
603 | - // ok so no general errors to this entire form section. |
|
604 | - // so let's check the subsections, but only set errors if that hasn't been done yet |
|
605 | - $this->is_valid = true; |
|
606 | - foreach ($this->get_validatable_subsections() as $subsection) { |
|
607 | - if (! $subsection->is_valid()) { |
|
608 | - $this->is_valid = false; |
|
609 | - } |
|
610 | - } |
|
611 | - } |
|
612 | - } |
|
613 | - return $this->is_valid; |
|
614 | - } |
|
615 | - |
|
616 | - |
|
617 | - /** |
|
618 | - * gets the default name of this form section if none is specified |
|
619 | - * |
|
620 | - * @return void |
|
621 | - */ |
|
622 | - protected function _set_default_name_if_empty() |
|
623 | - { |
|
624 | - if (! $this->_name) { |
|
625 | - $classname = get_class($this); |
|
626 | - $default_name = str_replace('EE_', '', $classname); |
|
627 | - $this->_name = $default_name; |
|
628 | - } |
|
629 | - } |
|
630 | - |
|
631 | - |
|
632 | - /** |
|
633 | - * Returns the HTML for the form, except for the form opening and closing tags |
|
634 | - * (as the form section doesn't know where you necessarily want to send the information to), |
|
635 | - * and except for a submit button. Enqueues JS and CSS; if called early enough we will |
|
636 | - * try to enqueue them in the header, otherwise they'll be enqueued in the footer. |
|
637 | - * Not doing_it_wrong because theoretically this CAN be used properly, |
|
638 | - * provided its used during "wp_enqueue_scripts", or it doesn't need to enqueue |
|
639 | - * any CSS. |
|
640 | - * |
|
641 | - * @throws InvalidArgumentException |
|
642 | - * @throws InvalidInterfaceException |
|
643 | - * @throws InvalidDataTypeException |
|
644 | - * @throws EE_Error |
|
645 | - */ |
|
646 | - public function get_html_and_js() |
|
647 | - { |
|
648 | - $this->enqueue_js(); |
|
649 | - return $this->get_html(); |
|
650 | - } |
|
651 | - |
|
652 | - |
|
653 | - /** |
|
654 | - * returns HTML for displaying this form section. recursively calls display_section() on all subsections |
|
655 | - * |
|
656 | - * @param bool $display_previously_submitted_data |
|
657 | - * @return string |
|
658 | - * @throws InvalidArgumentException |
|
659 | - * @throws InvalidInterfaceException |
|
660 | - * @throws InvalidDataTypeException |
|
661 | - * @throws EE_Error |
|
662 | - * @throws EE_Error |
|
663 | - * @throws EE_Error |
|
664 | - */ |
|
665 | - public function get_html($display_previously_submitted_data = true) |
|
666 | - { |
|
667 | - $this->ensure_construct_finalized_called(); |
|
668 | - if ($display_previously_submitted_data) { |
|
669 | - $this->populate_from_session(); |
|
670 | - } |
|
671 | - return $this->_form_html_filter |
|
672 | - ? $this->_form_html_filter->filterHtml($this->_layout_strategy->layout_form(), $this) |
|
673 | - : $this->_layout_strategy->layout_form(); |
|
674 | - } |
|
675 | - |
|
676 | - |
|
677 | - /** |
|
678 | - * enqueues JS and CSS for the form. |
|
679 | - * It is preferred to call this before wp_enqueue_scripts so the |
|
680 | - * scripts and styles can be put in the header, but if called later |
|
681 | - * they will be put in the footer (which is OK for JS, but in HTML4 CSS should |
|
682 | - * only be in the header; but in HTML5 its ok in the body. |
|
683 | - * See http://stackoverflow.com/questions/4957446/load-external-css-file-in-body-tag. |
|
684 | - * So if your form enqueues CSS, it's preferred to call this before wp_enqueue_scripts.) |
|
685 | - * |
|
686 | - * @return void |
|
687 | - * @throws EE_Error |
|
688 | - */ |
|
689 | - public function enqueue_js() |
|
690 | - { |
|
691 | - $this->_enqueue_and_localize_form_js(); |
|
692 | - foreach ($this->subsections() as $subsection) { |
|
693 | - $subsection->enqueue_js(); |
|
694 | - } |
|
695 | - } |
|
696 | - |
|
697 | - |
|
698 | - /** |
|
699 | - * adds a filter so that jquery validate gets enqueued in EE_System::wp_enqueue_scripts(). |
|
700 | - * This must be done BEFORE wp_enqueue_scripts() gets called, which is on |
|
701 | - * the wp_enqueue_scripts hook. |
|
702 | - * However, registering the form js and localizing it can happen when we |
|
703 | - * actually output the form (which is preferred, seeing how teh form's fields |
|
704 | - * could change until it's actually outputted) |
|
705 | - * |
|
706 | - * @param boolean $init_form_validation_automatically whether or not we want the form validation |
|
707 | - * to be triggered automatically or not |
|
708 | - * @return void |
|
709 | - */ |
|
710 | - public static function wp_enqueue_scripts($init_form_validation_automatically = true) |
|
711 | - { |
|
712 | - wp_register_script( |
|
713 | - 'ee_form_section_validation', |
|
714 | - EE_GLOBAL_ASSETS_URL . 'scripts' . '/form_section_validation.js', |
|
715 | - array('jquery-validate', 'jquery-ui-datepicker', 'jquery-validate-extra-methods'), |
|
716 | - EVENT_ESPRESSO_VERSION, |
|
717 | - true |
|
718 | - ); |
|
719 | - wp_localize_script( |
|
720 | - 'ee_form_section_validation', |
|
721 | - 'ee_form_section_validation_init', |
|
722 | - array('init' => $init_form_validation_automatically ? '1' : '0') |
|
723 | - ); |
|
724 | - } |
|
725 | - |
|
726 | - |
|
727 | - /** |
|
728 | - * gets the variables used by form_section_validation.js. |
|
729 | - * This needs to be called AFTER we've called $this->_enqueue_jquery_validate_script, |
|
730 | - * but before the wordpress hook wp_loaded |
|
731 | - * |
|
732 | - * @throws EE_Error |
|
733 | - */ |
|
734 | - public function _enqueue_and_localize_form_js() |
|
735 | - { |
|
736 | - $this->ensure_construct_finalized_called(); |
|
737 | - // actually, we don't want to localize just yet. There may be other forms on the page. |
|
738 | - // so we need to add our form section data to a static variable accessible by all form sections |
|
739 | - // and localize it just before the footer |
|
740 | - $this->localize_validation_rules(); |
|
741 | - add_action('wp_footer', array('EE_Form_Section_Proper', 'localize_script_for_all_forms'), 2); |
|
742 | - add_action('admin_footer', array('EE_Form_Section_Proper', 'localize_script_for_all_forms')); |
|
743 | - } |
|
744 | - |
|
745 | - |
|
746 | - /** |
|
747 | - * add our form section data to a static variable accessible by all form sections |
|
748 | - * |
|
749 | - * @param bool $return_for_subsection |
|
750 | - * @return void |
|
751 | - * @throws EE_Error |
|
752 | - */ |
|
753 | - public function localize_validation_rules($return_for_subsection = false) |
|
754 | - { |
|
755 | - // we only want to localize vars ONCE for the entire form, |
|
756 | - // so if the form section doesn't have a parent, then it must be the top dog |
|
757 | - if ($return_for_subsection || ! $this->parent_section()) { |
|
758 | - EE_Form_Section_Proper::$_js_localization['form_data'][ $this->html_id() ] = array( |
|
759 | - 'form_section_id' => $this->html_id(true), |
|
760 | - 'validation_rules' => $this->get_jquery_validation_rules(), |
|
761 | - 'other_data' => $this->get_other_js_data(), |
|
762 | - 'errors' => $this->subsection_validation_errors_by_html_name(), |
|
763 | - ); |
|
764 | - EE_Form_Section_Proper::$_scripts_localized = true; |
|
765 | - } |
|
766 | - } |
|
767 | - |
|
768 | - |
|
769 | - /** |
|
770 | - * Gets an array of extra data that will be useful for client-side javascript. |
|
771 | - * This is primarily data added by inputs and forms in addition to any |
|
772 | - * scripts they might enqueue |
|
773 | - * |
|
774 | - * @param array $form_other_js_data |
|
775 | - * @return array |
|
776 | - * @throws EE_Error |
|
777 | - */ |
|
778 | - public function get_other_js_data($form_other_js_data = array()) |
|
779 | - { |
|
780 | - foreach ($this->subsections() as $subsection) { |
|
781 | - $form_other_js_data = $subsection->get_other_js_data($form_other_js_data); |
|
782 | - } |
|
783 | - return $form_other_js_data; |
|
784 | - } |
|
785 | - |
|
786 | - |
|
787 | - /** |
|
788 | - * Gets a flat array of inputs for this form section and its subsections. |
|
789 | - * Keys are their form names, and values are the inputs themselves |
|
790 | - * |
|
791 | - * @return EE_Form_Input_Base |
|
792 | - * @throws EE_Error |
|
793 | - */ |
|
794 | - public function inputs_in_subsections() |
|
795 | - { |
|
796 | - $inputs = array(); |
|
797 | - foreach ($this->subsections() as $subsection) { |
|
798 | - if ($subsection instanceof EE_Form_Input_Base) { |
|
799 | - $inputs[ $subsection->html_name() ] = $subsection; |
|
800 | - } elseif ($subsection instanceof EE_Form_Section_Proper) { |
|
801 | - $inputs += $subsection->inputs_in_subsections(); |
|
802 | - } |
|
803 | - } |
|
804 | - return $inputs; |
|
805 | - } |
|
806 | - |
|
807 | - |
|
808 | - /** |
|
809 | - * Gets a flat array of all the validation errors. |
|
810 | - * Keys are html names (because those should be unique) |
|
811 | - * and values are a string of all their validation errors |
|
812 | - * |
|
813 | - * @return string[] |
|
814 | - * @throws EE_Error |
|
815 | - */ |
|
816 | - public function subsection_validation_errors_by_html_name() |
|
817 | - { |
|
818 | - $inputs = $this->inputs(); |
|
819 | - $errors = array(); |
|
820 | - foreach ($inputs as $form_input) { |
|
821 | - if ($form_input instanceof EE_Form_Input_Base && $form_input->get_validation_errors()) { |
|
822 | - $errors[ $form_input->html_name() ] = $form_input->get_validation_error_string(); |
|
823 | - } |
|
824 | - } |
|
825 | - return $errors; |
|
826 | - } |
|
827 | - |
|
828 | - |
|
829 | - /** |
|
830 | - * passes all the form data required by the JS to the JS, and enqueues the few required JS files. |
|
831 | - * Should be setup by each form during the _enqueues_and_localize_form_js |
|
832 | - * |
|
833 | - * @throws InvalidArgumentException |
|
834 | - * @throws InvalidInterfaceException |
|
835 | - * @throws InvalidDataTypeException |
|
836 | - */ |
|
837 | - public static function localize_script_for_all_forms() |
|
838 | - { |
|
839 | - // allow inputs and stuff to hook in their JS and stuff here |
|
840 | - do_action('AHEE__EE_Form_Section_Proper__localize_script_for_all_forms__begin'); |
|
841 | - EE_Form_Section_Proper::$_js_localization['localized_error_messages'] = EE_Form_Section_Proper::_get_localized_error_messages(); |
|
842 | - $email_validation_level = isset(EE_Registry::instance()->CFG->registration->email_validation_level) |
|
843 | - ? EE_Registry::instance()->CFG->registration->email_validation_level |
|
844 | - : 'wp_default'; |
|
845 | - EE_Form_Section_Proper::$_js_localization['email_validation_level'] = $email_validation_level; |
|
846 | - wp_enqueue_script('ee_form_section_validation'); |
|
847 | - wp_localize_script( |
|
848 | - 'ee_form_section_validation', |
|
849 | - 'ee_form_section_vars', |
|
850 | - EE_Form_Section_Proper::$_js_localization |
|
851 | - ); |
|
852 | - } |
|
853 | - |
|
854 | - |
|
855 | - /** |
|
856 | - * ensure_scripts_localized |
|
857 | - * |
|
858 | - * @throws EE_Error |
|
859 | - */ |
|
860 | - public function ensure_scripts_localized() |
|
861 | - { |
|
862 | - if (! EE_Form_Section_Proper::$_scripts_localized) { |
|
863 | - $this->_enqueue_and_localize_form_js(); |
|
864 | - } |
|
865 | - } |
|
866 | - |
|
867 | - |
|
868 | - /** |
|
869 | - * Gets the hard-coded validation error messages to be used in the JS. The convention |
|
870 | - * is that the key here should be the same as the custom validation rule put in the JS file |
|
871 | - * |
|
872 | - * @return array keys are custom validation rules, and values are internationalized strings |
|
873 | - */ |
|
874 | - private static function _get_localized_error_messages() |
|
875 | - { |
|
876 | - return array( |
|
877 | - 'validUrl' => esc_html__('This is not a valid absolute URL. Eg, http://domain.com/monkey.jpg', 'event_espresso'), |
|
878 | - 'regex' => esc_html__('Please check your input', 'event_espresso'), |
|
879 | - ); |
|
880 | - } |
|
881 | - |
|
882 | - |
|
883 | - /** |
|
884 | - * @return array |
|
885 | - */ |
|
886 | - public static function js_localization() |
|
887 | - { |
|
888 | - return self::$_js_localization; |
|
889 | - } |
|
890 | - |
|
891 | - |
|
892 | - /** |
|
893 | - * @return void |
|
894 | - */ |
|
895 | - public static function reset_js_localization() |
|
896 | - { |
|
897 | - self::$_js_localization = array(); |
|
898 | - } |
|
899 | - |
|
900 | - |
|
901 | - /** |
|
902 | - * Gets the JS to put inside the jquery validation rules for subsection of this form section. |
|
903 | - * See parent function for more... |
|
904 | - * |
|
905 | - * @return array |
|
906 | - * @throws EE_Error |
|
907 | - */ |
|
908 | - public function get_jquery_validation_rules() |
|
909 | - { |
|
910 | - $jquery_validation_rules = array(); |
|
911 | - foreach ($this->get_validatable_subsections() as $subsection) { |
|
912 | - $jquery_validation_rules = array_merge( |
|
913 | - $jquery_validation_rules, |
|
914 | - $subsection->get_jquery_validation_rules() |
|
915 | - ); |
|
916 | - } |
|
917 | - return $jquery_validation_rules; |
|
918 | - } |
|
919 | - |
|
920 | - |
|
921 | - /** |
|
922 | - * Sanitizes all the data and sets the sanitized value of each field |
|
923 | - * |
|
924 | - * @param array $req_data like $_POST |
|
925 | - * @return void |
|
926 | - * @throws EE_Error |
|
927 | - */ |
|
928 | - protected function _normalize($req_data) |
|
929 | - { |
|
930 | - $this->_received_submission = true; |
|
931 | - $this->_validation_errors = array(); |
|
932 | - foreach ($this->get_validatable_subsections() as $subsection) { |
|
933 | - try { |
|
934 | - $subsection->_normalize($req_data); |
|
935 | - } catch (EE_Validation_Error $e) { |
|
936 | - $subsection->add_validation_error($e); |
|
937 | - } |
|
938 | - } |
|
939 | - } |
|
940 | - |
|
941 | - |
|
942 | - /** |
|
943 | - * Performs validation on this form section and its subsections. |
|
944 | - * For each subsection, |
|
945 | - * calls _validate_{subsection_name} on THIS form (if the function exists) |
|
946 | - * and passes it the subsection, then calls _validate on that subsection. |
|
947 | - * If you need to perform validation on the form as a whole (considering multiple) |
|
948 | - * you would be best to override this _validate method, |
|
949 | - * calling parent::_validate() first. |
|
950 | - * |
|
951 | - * @throws EE_Error |
|
952 | - */ |
|
953 | - protected function _validate() |
|
954 | - { |
|
955 | - // reset the cache of whether this form is valid or not- we're re-validating it now |
|
956 | - $this->is_valid = null; |
|
957 | - foreach ($this->get_validatable_subsections() as $subsection_name => $subsection) { |
|
958 | - if (method_exists($this, '_validate_' . $subsection_name)) { |
|
959 | - call_user_func_array(array($this, '_validate_' . $subsection_name), array($subsection)); |
|
960 | - } |
|
961 | - $subsection->_validate(); |
|
962 | - } |
|
963 | - } |
|
964 | - |
|
965 | - |
|
966 | - /** |
|
967 | - * Gets all the validated inputs for the form section |
|
968 | - * |
|
969 | - * @return array |
|
970 | - * @throws EE_Error |
|
971 | - */ |
|
972 | - public function valid_data() |
|
973 | - { |
|
974 | - $inputs = array(); |
|
975 | - foreach ($this->subsections() as $subsection_name => $subsection) { |
|
976 | - if ($subsection instanceof EE_Form_Section_Proper) { |
|
977 | - $inputs[ $subsection_name ] = $subsection->valid_data(); |
|
978 | - } elseif ($subsection instanceof EE_Form_Input_Base) { |
|
979 | - $inputs[ $subsection_name ] = $subsection->normalized_value(); |
|
980 | - } |
|
981 | - } |
|
982 | - return $inputs; |
|
983 | - } |
|
984 | - |
|
985 | - |
|
986 | - /** |
|
987 | - * Gets all the inputs on this form section |
|
988 | - * |
|
989 | - * @return EE_Form_Input_Base[] |
|
990 | - * @throws EE_Error |
|
991 | - */ |
|
992 | - public function inputs() |
|
993 | - { |
|
994 | - $inputs = array(); |
|
995 | - foreach ($this->subsections() as $subsection_name => $subsection) { |
|
996 | - if ($subsection instanceof EE_Form_Input_Base) { |
|
997 | - $inputs[ $subsection_name ] = $subsection; |
|
998 | - } |
|
999 | - } |
|
1000 | - return $inputs; |
|
1001 | - } |
|
1002 | - |
|
1003 | - |
|
1004 | - /** |
|
1005 | - * Gets all the subsections which are a proper form |
|
1006 | - * |
|
1007 | - * @return EE_Form_Section_Proper[] |
|
1008 | - * @throws EE_Error |
|
1009 | - */ |
|
1010 | - public function subforms() |
|
1011 | - { |
|
1012 | - $form_sections = array(); |
|
1013 | - foreach ($this->subsections() as $name => $obj) { |
|
1014 | - if ($obj instanceof EE_Form_Section_Proper) { |
|
1015 | - $form_sections[ $name ] = $obj; |
|
1016 | - } |
|
1017 | - } |
|
1018 | - return $form_sections; |
|
1019 | - } |
|
1020 | - |
|
1021 | - |
|
1022 | - /** |
|
1023 | - * Gets all the subsections (inputs, proper subsections, or html-only sections). |
|
1024 | - * Consider using inputs() or subforms() |
|
1025 | - * if you only want form inputs or proper form sections. |
|
1026 | - * |
|
1027 | - * @param boolean $require_construction_to_be_finalized most client code should |
|
1028 | - * leave this as TRUE so that the inputs will be properly |
|
1029 | - * configured. However, some client code may be ok with |
|
1030 | - * construction finalize being called later |
|
1031 | - * (realizing that the subsections' html names might not be |
|
1032 | - * set yet, etc.) |
|
1033 | - * @return EE_Form_Section_Proper[] |
|
1034 | - * @throws EE_Error |
|
1035 | - */ |
|
1036 | - public function subsections($require_construction_to_be_finalized = true) |
|
1037 | - { |
|
1038 | - if ($require_construction_to_be_finalized) { |
|
1039 | - $this->ensure_construct_finalized_called(); |
|
1040 | - } |
|
1041 | - return $this->_subsections; |
|
1042 | - } |
|
1043 | - |
|
1044 | - |
|
1045 | - /** |
|
1046 | - * Returns whether this form has any subforms or inputs |
|
1047 | - * @return bool |
|
1048 | - */ |
|
1049 | - public function hasSubsections() |
|
1050 | - { |
|
1051 | - return ! empty($this->_subsections); |
|
1052 | - } |
|
1053 | - |
|
1054 | - |
|
1055 | - /** |
|
1056 | - * Returns a simple array where keys are input names, and values are their normalized |
|
1057 | - * values. (Similar to calling get_input_value on inputs) |
|
1058 | - * |
|
1059 | - * @param boolean $include_subform_inputs Whether to include inputs from subforms, |
|
1060 | - * or just this forms' direct children inputs |
|
1061 | - * @param boolean $flatten Whether to force the results into 1-dimensional array, |
|
1062 | - * or allow multidimensional array |
|
1063 | - * @return array if $flatten is TRUE it will always be a 1-dimensional array |
|
1064 | - * with array keys being input names |
|
1065 | - * (regardless of whether they are from a subsection or not), |
|
1066 | - * and if $flatten is FALSE it can be a multidimensional array |
|
1067 | - * where keys are always subsection names and values are either |
|
1068 | - * the input's normalized value, or an array like the top-level array |
|
1069 | - * @throws EE_Error |
|
1070 | - */ |
|
1071 | - public function input_values($include_subform_inputs = false, $flatten = false) |
|
1072 | - { |
|
1073 | - return $this->_input_values(false, $include_subform_inputs, $flatten); |
|
1074 | - } |
|
1075 | - |
|
1076 | - |
|
1077 | - /** |
|
1078 | - * Similar to EE_Form_Section_Proper::input_values(), except this returns the 'display_value' |
|
1079 | - * of each input. On some inputs (especially radio boxes or checkboxes), the value stored |
|
1080 | - * is not necessarily the value we want to display to users. This creates an array |
|
1081 | - * where keys are the input names, and values are their display values |
|
1082 | - * |
|
1083 | - * @param boolean $include_subform_inputs Whether to include inputs from subforms, |
|
1084 | - * or just this forms' direct children inputs |
|
1085 | - * @param boolean $flatten Whether to force the results into 1-dimensional array, |
|
1086 | - * or allow multidimensional array |
|
1087 | - * @return array if $flatten is TRUE it will always be a 1-dimensional array |
|
1088 | - * with array keys being input names |
|
1089 | - * (regardless of whether they are from a subsection or not), |
|
1090 | - * and if $flatten is FALSE it can be a multidimensional array |
|
1091 | - * where keys are always subsection names and values are either |
|
1092 | - * the input's normalized value, or an array like the top-level array |
|
1093 | - * @throws EE_Error |
|
1094 | - */ |
|
1095 | - public function input_pretty_values($include_subform_inputs = false, $flatten = false) |
|
1096 | - { |
|
1097 | - return $this->_input_values(true, $include_subform_inputs, $flatten); |
|
1098 | - } |
|
1099 | - |
|
1100 | - |
|
1101 | - /** |
|
1102 | - * Gets the input values from the form |
|
1103 | - * |
|
1104 | - * @param boolean $pretty Whether to retrieve the pretty value, |
|
1105 | - * or just the normalized value |
|
1106 | - * @param boolean $include_subform_inputs Whether to include inputs from subforms, |
|
1107 | - * or just this forms' direct children inputs |
|
1108 | - * @param boolean $flatten Whether to force the results into 1-dimensional array, |
|
1109 | - * or allow multidimensional array |
|
1110 | - * @return array if $flatten is TRUE it will always be a 1-dimensional array with array keys being |
|
1111 | - * input names (regardless of whether they are from a subsection or not), |
|
1112 | - * and if $flatten is FALSE it can be a multidimensional array |
|
1113 | - * where keys are always subsection names and values are either |
|
1114 | - * the input's normalized value, or an array like the top-level array |
|
1115 | - * @throws EE_Error |
|
1116 | - */ |
|
1117 | - public function _input_values($pretty = false, $include_subform_inputs = false, $flatten = false) |
|
1118 | - { |
|
1119 | - $input_values = array(); |
|
1120 | - foreach ($this->subsections() as $subsection_name => $subsection) { |
|
1121 | - if ($subsection instanceof EE_Form_Input_Base) { |
|
1122 | - $input_values[ $subsection_name ] = $pretty |
|
1123 | - ? $subsection->pretty_value() |
|
1124 | - : $subsection->normalized_value(); |
|
1125 | - } elseif ($subsection instanceof EE_Form_Section_Proper && $include_subform_inputs) { |
|
1126 | - $subform_input_values = $subsection->_input_values( |
|
1127 | - $pretty, |
|
1128 | - $include_subform_inputs, |
|
1129 | - $flatten |
|
1130 | - ); |
|
1131 | - if ($flatten) { |
|
1132 | - $input_values = array_merge($input_values, $subform_input_values); |
|
1133 | - } else { |
|
1134 | - $input_values[ $subsection_name ] = $subform_input_values; |
|
1135 | - } |
|
1136 | - } |
|
1137 | - } |
|
1138 | - return $input_values; |
|
1139 | - } |
|
1140 | - |
|
1141 | - |
|
1142 | - /** |
|
1143 | - * Gets the originally submitted input values from the form |
|
1144 | - * |
|
1145 | - * @param boolean $include_subforms Whether to include inputs from subforms, |
|
1146 | - * or just this forms' direct children inputs |
|
1147 | - * @return array if $flatten is TRUE it will always be a 1-dimensional array |
|
1148 | - * with array keys being input names |
|
1149 | - * (regardless of whether they are from a subsection or not), |
|
1150 | - * and if $flatten is FALSE it can be a multidimensional array |
|
1151 | - * where keys are always subsection names and values are either |
|
1152 | - * the input's normalized value, or an array like the top-level array |
|
1153 | - * @throws EE_Error |
|
1154 | - */ |
|
1155 | - public function submitted_values($include_subforms = false) |
|
1156 | - { |
|
1157 | - $submitted_values = array(); |
|
1158 | - foreach ($this->subsections() as $subsection) { |
|
1159 | - if ($subsection instanceof EE_Form_Input_Base) { |
|
1160 | - // is this input part of an array of inputs? |
|
1161 | - if (strpos($subsection->html_name(), '[') !== false) { |
|
1162 | - $full_input_name = EEH_Array::convert_array_values_to_keys( |
|
1163 | - explode( |
|
1164 | - '[', |
|
1165 | - str_replace(']', '', $subsection->html_name()) |
|
1166 | - ), |
|
1167 | - $subsection->raw_value() |
|
1168 | - ); |
|
1169 | - $submitted_values = array_replace_recursive($submitted_values, $full_input_name); |
|
1170 | - } else { |
|
1171 | - $submitted_values[ $subsection->html_name() ] = $subsection->raw_value(); |
|
1172 | - } |
|
1173 | - } elseif ($subsection instanceof EE_Form_Section_Proper && $include_subforms) { |
|
1174 | - $subform_input_values = $subsection->submitted_values($include_subforms); |
|
1175 | - $submitted_values = array_replace_recursive($submitted_values, $subform_input_values); |
|
1176 | - } |
|
1177 | - } |
|
1178 | - return $submitted_values; |
|
1179 | - } |
|
1180 | - |
|
1181 | - |
|
1182 | - /** |
|
1183 | - * Indicates whether or not this form has received a submission yet |
|
1184 | - * (ie, had receive_form_submission called on it yet) |
|
1185 | - * |
|
1186 | - * @return boolean |
|
1187 | - * @throws EE_Error |
|
1188 | - */ |
|
1189 | - public function has_received_submission() |
|
1190 | - { |
|
1191 | - $this->ensure_construct_finalized_called(); |
|
1192 | - return $this->_received_submission; |
|
1193 | - } |
|
1194 | - |
|
1195 | - |
|
1196 | - /** |
|
1197 | - * Equivalent to passing 'exclude' in the constructor's options array. |
|
1198 | - * Removes the listed inputs from the form |
|
1199 | - * |
|
1200 | - * @param array $inputs_to_exclude values are the input names |
|
1201 | - * @return void |
|
1202 | - */ |
|
1203 | - public function exclude(array $inputs_to_exclude = array()) |
|
1204 | - { |
|
1205 | - foreach ($inputs_to_exclude as $input_to_exclude_name) { |
|
1206 | - unset($this->_subsections[ $input_to_exclude_name ]); |
|
1207 | - } |
|
1208 | - } |
|
1209 | - |
|
1210 | - |
|
1211 | - /** |
|
1212 | - * Changes these inputs' display strategy to be EE_Hidden_Display_Strategy. |
|
1213 | - * @param array $inputs_to_hide |
|
1214 | - * @throws EE_Error |
|
1215 | - */ |
|
1216 | - public function hide(array $inputs_to_hide = array()) |
|
1217 | - { |
|
1218 | - foreach ($inputs_to_hide as $input_to_hide) { |
|
1219 | - $input = $this->get_input($input_to_hide); |
|
1220 | - $input->set_display_strategy(new EE_Hidden_Display_Strategy()); |
|
1221 | - } |
|
1222 | - } |
|
1223 | - |
|
1224 | - |
|
1225 | - /** |
|
1226 | - * add_subsections |
|
1227 | - * Adds the listed subsections to the form section. |
|
1228 | - * If $subsection_name_to_target is provided, |
|
1229 | - * then new subsections are added before or after that subsection, |
|
1230 | - * otherwise to the start or end of the entire subsections array. |
|
1231 | - * |
|
1232 | - * @param EE_Form_Section_Base[] $new_subsections array of new form subsections |
|
1233 | - * where keys are their names |
|
1234 | - * @param string $subsection_name_to_target an existing for section that $new_subsections |
|
1235 | - * should be added before or after |
|
1236 | - * IF $subsection_name_to_target is null, |
|
1237 | - * then $new_subsections will be added to |
|
1238 | - * the beginning or end of the entire subsections array |
|
1239 | - * @param boolean $add_before whether to add $new_subsections, before or after |
|
1240 | - * $subsection_name_to_target, |
|
1241 | - * or if $subsection_name_to_target is null, |
|
1242 | - * before or after entire subsections array |
|
1243 | - * @return void |
|
1244 | - * @throws EE_Error |
|
1245 | - */ |
|
1246 | - public function add_subsections($new_subsections, $subsection_name_to_target = null, $add_before = true) |
|
1247 | - { |
|
1248 | - foreach ($new_subsections as $subsection_name => $subsection) { |
|
1249 | - if (! $subsection instanceof EE_Form_Section_Base) { |
|
1250 | - EE_Error::add_error( |
|
1251 | - sprintf( |
|
1252 | - esc_html__( |
|
1253 | - "Trying to add a %s as a subsection (it was named '%s') to the form section '%s'. It was removed.", |
|
1254 | - 'event_espresso' |
|
1255 | - ), |
|
1256 | - get_class($subsection), |
|
1257 | - $subsection_name, |
|
1258 | - $this->name() |
|
1259 | - ) |
|
1260 | - ); |
|
1261 | - unset($new_subsections[ $subsection_name ]); |
|
1262 | - } |
|
1263 | - } |
|
1264 | - $this->_subsections = EEH_Array::insert_into_array( |
|
1265 | - $this->_subsections, |
|
1266 | - $new_subsections, |
|
1267 | - $subsection_name_to_target, |
|
1268 | - $add_before |
|
1269 | - ); |
|
1270 | - if ($this->_construction_finalized) { |
|
1271 | - foreach ($this->_subsections as $name => $subsection) { |
|
1272 | - $subsection->_construct_finalize($this, $name); |
|
1273 | - } |
|
1274 | - } |
|
1275 | - } |
|
1276 | - |
|
1277 | - |
|
1278 | - /** |
|
1279 | - * @param string $subsection_name |
|
1280 | - * @param bool $recursive |
|
1281 | - * @return bool |
|
1282 | - */ |
|
1283 | - public function has_subsection($subsection_name, $recursive = false) |
|
1284 | - { |
|
1285 | - foreach ($this->_subsections as $name => $subsection) { |
|
1286 | - if ( |
|
1287 | - $name === $subsection_name |
|
1288 | - || ( |
|
1289 | - $recursive |
|
1290 | - && $subsection instanceof EE_Form_Section_Proper |
|
1291 | - && $subsection->has_subsection($subsection_name, $recursive) |
|
1292 | - ) |
|
1293 | - ) { |
|
1294 | - return true; |
|
1295 | - } |
|
1296 | - } |
|
1297 | - return false; |
|
1298 | - } |
|
1299 | - |
|
1300 | - |
|
1301 | - |
|
1302 | - /** |
|
1303 | - * Just gets all validatable subsections to clean their sensitive data |
|
1304 | - * |
|
1305 | - * @throws EE_Error |
|
1306 | - */ |
|
1307 | - public function clean_sensitive_data() |
|
1308 | - { |
|
1309 | - foreach ($this->get_validatable_subsections() as $subsection) { |
|
1310 | - $subsection->clean_sensitive_data(); |
|
1311 | - } |
|
1312 | - } |
|
1313 | - |
|
1314 | - |
|
1315 | - /** |
|
1316 | - * Sets the submission error message (aka validation error message for this form section and all sub-sections) |
|
1317 | - * @param string $form_submission_error_message |
|
1318 | - * @param EE_Form_Section_Validatable $form_section unused |
|
1319 | - * @throws EE_Error |
|
1320 | - */ |
|
1321 | - public function set_submission_error_message( |
|
1322 | - $form_submission_error_message = '' |
|
1323 | - ) { |
|
1324 | - $this->_form_submission_error_message = ! empty($form_submission_error_message) |
|
1325 | - ? $form_submission_error_message |
|
1326 | - : $this->getAllValidationErrorsString(); |
|
1327 | - } |
|
1328 | - |
|
1329 | - |
|
1330 | - /** |
|
1331 | - * Returns the cached error message. A default value is set for this during _validate(), |
|
1332 | - * (called during receive_form_submission) but it can be explicitly set using |
|
1333 | - * set_submission_error_message |
|
1334 | - * |
|
1335 | - * @return string |
|
1336 | - */ |
|
1337 | - public function submission_error_message() |
|
1338 | - { |
|
1339 | - return $this->_form_submission_error_message; |
|
1340 | - } |
|
1341 | - |
|
1342 | - |
|
1343 | - /** |
|
1344 | - * Sets a message to display if the data submitted to the form was valid. |
|
1345 | - * @param string $form_submission_success_message |
|
1346 | - */ |
|
1347 | - public function set_submission_success_message($form_submission_success_message = '') |
|
1348 | - { |
|
1349 | - $this->_form_submission_success_message = ! empty($form_submission_success_message) |
|
1350 | - ? $form_submission_success_message |
|
1351 | - : esc_html__('Form submitted successfully', 'event_espresso'); |
|
1352 | - } |
|
1353 | - |
|
1354 | - |
|
1355 | - /** |
|
1356 | - * Gets a message appropriate for display when the form is correctly submitted |
|
1357 | - * @return string |
|
1358 | - */ |
|
1359 | - public function submission_success_message() |
|
1360 | - { |
|
1361 | - return $this->_form_submission_success_message; |
|
1362 | - } |
|
1363 | - |
|
1364 | - |
|
1365 | - /** |
|
1366 | - * Returns the prefix that should be used on child of this form section for |
|
1367 | - * their html names. If this form section itself has a parent, prepends ITS |
|
1368 | - * prefix onto this form section's prefix. Used primarily by |
|
1369 | - * EE_Form_Input_Base::_set_default_html_name_if_empty |
|
1370 | - * |
|
1371 | - * @return string |
|
1372 | - * @throws EE_Error |
|
1373 | - */ |
|
1374 | - public function html_name_prefix() |
|
1375 | - { |
|
1376 | - if ($this->parent_section() instanceof EE_Form_Section_Proper) { |
|
1377 | - return $this->parent_section()->html_name_prefix() . '[' . $this->name() . ']'; |
|
1378 | - } |
|
1379 | - return $this->name(); |
|
1380 | - } |
|
1381 | - |
|
1382 | - |
|
1383 | - /** |
|
1384 | - * Gets the name, but first checks _construct_finalize has been called. If not, |
|
1385 | - * calls it (assumes there is no parent and that we want the name to be whatever |
|
1386 | - * was set, which is probably nothing, or the classname) |
|
1387 | - * |
|
1388 | - * @return string |
|
1389 | - * @throws EE_Error |
|
1390 | - */ |
|
1391 | - public function name() |
|
1392 | - { |
|
1393 | - $this->ensure_construct_finalized_called(); |
|
1394 | - return parent::name(); |
|
1395 | - } |
|
1396 | - |
|
1397 | - |
|
1398 | - /** |
|
1399 | - * @return EE_Form_Section_Proper |
|
1400 | - * @throws EE_Error |
|
1401 | - */ |
|
1402 | - public function parent_section() |
|
1403 | - { |
|
1404 | - $this->ensure_construct_finalized_called(); |
|
1405 | - return parent::parent_section(); |
|
1406 | - } |
|
1407 | - |
|
1408 | - |
|
1409 | - /** |
|
1410 | - * make sure construction finalized was called, otherwise children might not be ready |
|
1411 | - * |
|
1412 | - * @return void |
|
1413 | - * @throws EE_Error |
|
1414 | - */ |
|
1415 | - public function ensure_construct_finalized_called() |
|
1416 | - { |
|
1417 | - if (! $this->_construction_finalized) { |
|
1418 | - $this->_construct_finalize($this->_parent_section, $this->_name); |
|
1419 | - } |
|
1420 | - } |
|
1421 | - |
|
1422 | - |
|
1423 | - /** |
|
1424 | - * Checks if any of this form section's inputs, or any of its children's inputs, |
|
1425 | - * are in teh form data. If any are found, returns true. Else false |
|
1426 | - * |
|
1427 | - * @param array $req_data |
|
1428 | - * @return boolean |
|
1429 | - * @throws EE_Error |
|
1430 | - */ |
|
1431 | - public function form_data_present_in($req_data = null) |
|
1432 | - { |
|
1433 | - $req_data = $this->getCachedRequest($req_data); |
|
1434 | - foreach ($this->subsections() as $subsection) { |
|
1435 | - if ($subsection instanceof EE_Form_Input_Base) { |
|
1436 | - if ($subsection->form_data_present_in($req_data)) { |
|
1437 | - return true; |
|
1438 | - } |
|
1439 | - } elseif ($subsection instanceof EE_Form_Section_Proper) { |
|
1440 | - if ($subsection->form_data_present_in($req_data)) { |
|
1441 | - return true; |
|
1442 | - } |
|
1443 | - } |
|
1444 | - } |
|
1445 | - return false; |
|
1446 | - } |
|
1447 | - |
|
1448 | - |
|
1449 | - /** |
|
1450 | - * Gets validation errors for this form section and subsections |
|
1451 | - * Similar to EE_Form_Section_Validatable::get_validation_errors() except this |
|
1452 | - * gets the validation errors for ALL subsection |
|
1453 | - * |
|
1454 | - * @return EE_Validation_Error[] |
|
1455 | - * @throws EE_Error |
|
1456 | - */ |
|
1457 | - public function get_validation_errors_accumulated() |
|
1458 | - { |
|
1459 | - $validation_errors = $this->get_validation_errors(); |
|
1460 | - foreach ($this->get_validatable_subsections() as $subsection) { |
|
1461 | - if ($subsection instanceof EE_Form_Section_Proper) { |
|
1462 | - $validation_errors_on_this_subsection = $subsection->get_validation_errors_accumulated(); |
|
1463 | - } else { |
|
1464 | - $validation_errors_on_this_subsection = $subsection->get_validation_errors(); |
|
1465 | - } |
|
1466 | - if ($validation_errors_on_this_subsection) { |
|
1467 | - $validation_errors = array_merge($validation_errors, $validation_errors_on_this_subsection); |
|
1468 | - } |
|
1469 | - } |
|
1470 | - return $validation_errors; |
|
1471 | - } |
|
1472 | - |
|
1473 | - /** |
|
1474 | - * Fetch validation errors from children and grandchildren and puts them in a single string. |
|
1475 | - * This traverses the form section tree to generate this, but you probably want to instead use |
|
1476 | - * get_form_submission_error_message() which is usually this message cached (or a custom validation error message) |
|
1477 | - * |
|
1478 | - * @return string |
|
1479 | - * @since 4.9.59.p |
|
1480 | - */ |
|
1481 | - protected function getAllValidationErrorsString() |
|
1482 | - { |
|
1483 | - $submission_error_messages = array(); |
|
1484 | - // bad, bad, bad registrant |
|
1485 | - foreach ($this->get_validation_errors_accumulated() as $validation_error) { |
|
1486 | - if ($validation_error instanceof EE_Validation_Error) { |
|
1487 | - $form_section = $validation_error->get_form_section(); |
|
1488 | - if ($form_section instanceof EE_Form_Input_Base) { |
|
1489 | - $label = $validation_error->get_form_section()->html_label_text(); |
|
1490 | - } elseif ($form_section instanceof EE_Form_Section_Validatable) { |
|
1491 | - $label = $validation_error->get_form_section()->name(); |
|
1492 | - } else { |
|
1493 | - $label = esc_html__('Unknown', 'event_espresso'); |
|
1494 | - } |
|
1495 | - $submission_error_messages[] = sprintf( |
|
1496 | - __('%s : %s', 'event_espresso'), |
|
1497 | - $label, |
|
1498 | - $validation_error->getMessage() |
|
1499 | - ); |
|
1500 | - } |
|
1501 | - } |
|
1502 | - return implode('<br>', $submission_error_messages); |
|
1503 | - } |
|
1504 | - |
|
1505 | - |
|
1506 | - /** |
|
1507 | - * This isn't just the name of an input, it's a path pointing to an input. The |
|
1508 | - * path is similar to a folder path: slash (/) means to descend into a subsection, |
|
1509 | - * dot-dot-slash (../) means to ascend into the parent section. |
|
1510 | - * After a series of slashes and dot-dot-slashes, there should be the name of an input, |
|
1511 | - * which will be returned. |
|
1512 | - * Eg, if you want the related input to be conditional on a sibling input name 'foobar' |
|
1513 | - * just use 'foobar'. If you want it to be conditional on an aunt/uncle input name |
|
1514 | - * 'baz', use '../baz'. If you want it to be conditional on a cousin input, |
|
1515 | - * the child of 'baz_section' named 'baz_child', use '../baz_section/baz_child'. |
|
1516 | - * Etc |
|
1517 | - * |
|
1518 | - * @param string|false $form_section_path we accept false also because substr( '../', '../' ) = false |
|
1519 | - * @return EE_Form_Section_Base |
|
1520 | - * @throws EE_Error |
|
1521 | - */ |
|
1522 | - public function find_section_from_path($form_section_path) |
|
1523 | - { |
|
1524 | - // check if we can find the input from purely going straight up the tree |
|
1525 | - $input = parent::find_section_from_path($form_section_path); |
|
1526 | - if ($input instanceof EE_Form_Section_Base) { |
|
1527 | - return $input; |
|
1528 | - } |
|
1529 | - $next_slash_pos = strpos($form_section_path, '/'); |
|
1530 | - if ($next_slash_pos !== false) { |
|
1531 | - $child_section_name = substr($form_section_path, 0, $next_slash_pos); |
|
1532 | - $subpath = substr($form_section_path, $next_slash_pos + 1); |
|
1533 | - } else { |
|
1534 | - $child_section_name = $form_section_path; |
|
1535 | - $subpath = ''; |
|
1536 | - } |
|
1537 | - $child_section = $this->get_subsection($child_section_name); |
|
1538 | - if ($child_section instanceof EE_Form_Section_Base) { |
|
1539 | - return $child_section->find_section_from_path($subpath); |
|
1540 | - } |
|
1541 | - return null; |
|
1542 | - } |
|
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 | + protected static $_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 | + protected static $_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 ( |
|
262 | + $this->cached_request_data === null |
|
263 | + || ( |
|
264 | + $req_data !== null |
|
265 | + && $req_data !== $this->cached_request_data |
|
266 | + ) |
|
267 | + ) { |
|
268 | + $req_data = apply_filters( |
|
269 | + 'FHEE__EE_Form_Section_Proper__receive_form_submission__req_data', |
|
270 | + $req_data, |
|
271 | + $this |
|
272 | + ); |
|
273 | + if ($req_data === null) { |
|
274 | + $req_data = array_merge($_GET, $_POST); |
|
275 | + } |
|
276 | + $req_data = apply_filters( |
|
277 | + 'FHEE__EE_Form_Section_Proper__receive_form_submission__request_data', |
|
278 | + $req_data, |
|
279 | + $this |
|
280 | + ); |
|
281 | + $this->cached_request_data = (array) $req_data; |
|
282 | + } |
|
283 | + return $this->cached_request_data; |
|
284 | + } |
|
285 | + |
|
286 | + |
|
287 | + /** |
|
288 | + * After the form section is initially created, call this to sanitize the data in the submission |
|
289 | + * which relates to this form section, validate it, and set it as properties on the form. |
|
290 | + * |
|
291 | + * @param array|null $req_data should usually be $_POST (the default). |
|
292 | + * However, you CAN supply a different array. |
|
293 | + * Consider using set_defaults() instead however. |
|
294 | + * (If you rendered the form in the page using echo $form_x->get_html() |
|
295 | + * the inputs will have the correct name in the request data for this function |
|
296 | + * to find them and populate the form with them. |
|
297 | + * If you have a flat form (with only input subsections), |
|
298 | + * you can supply a flat array where keys |
|
299 | + * are the form input names and values are their values) |
|
300 | + * @param boolean $validate whether or not to perform validation on this data. Default is, |
|
301 | + * of course, to validate that data, and set errors on the invalid values. |
|
302 | + * But if the data has already been validated |
|
303 | + * (eg you validated the data then stored it in the DB) |
|
304 | + * you may want to skip this step. |
|
305 | + * @throws InvalidArgumentException |
|
306 | + * @throws InvalidInterfaceException |
|
307 | + * @throws InvalidDataTypeException |
|
308 | + * @throws EE_Error |
|
309 | + */ |
|
310 | + public function receive_form_submission($req_data = null, $validate = true) |
|
311 | + { |
|
312 | + $req_data = $this->getCachedRequest($req_data); |
|
313 | + $this->_normalize($req_data); |
|
314 | + if ($validate) { |
|
315 | + $this->_validate(); |
|
316 | + // if it's invalid, we're going to want to re-display so remember what they submitted |
|
317 | + if (! $this->is_valid()) { |
|
318 | + $this->store_submitted_form_data_in_session(); |
|
319 | + } |
|
320 | + } |
|
321 | + if ($this->submission_error_message() === '' && ! $this->is_valid()) { |
|
322 | + $this->set_submission_error_message(); |
|
323 | + } |
|
324 | + do_action( |
|
325 | + 'AHEE__EE_Form_Section_Proper__receive_form_submission__end', |
|
326 | + $req_data, |
|
327 | + $this, |
|
328 | + $validate |
|
329 | + ); |
|
330 | + } |
|
331 | + |
|
332 | + |
|
333 | + /** |
|
334 | + * caches the originally submitted input values in the session |
|
335 | + * so that they can be used to repopulate the form if it failed validation |
|
336 | + * |
|
337 | + * @return boolean whether or not the data was successfully stored in the session |
|
338 | + * @throws InvalidArgumentException |
|
339 | + * @throws InvalidInterfaceException |
|
340 | + * @throws InvalidDataTypeException |
|
341 | + * @throws EE_Error |
|
342 | + */ |
|
343 | + protected function store_submitted_form_data_in_session() |
|
344 | + { |
|
345 | + return EE_Registry::instance()->SSN->set_session_data( |
|
346 | + array( |
|
347 | + EE_Form_Section_Proper::SUBMITTED_FORM_DATA_SSN_KEY => $this->submitted_values(true), |
|
348 | + ) |
|
349 | + ); |
|
350 | + } |
|
351 | + |
|
352 | + |
|
353 | + /** |
|
354 | + * retrieves the originally submitted input values in the session |
|
355 | + * so that they can be used to repopulate the form if it failed validation |
|
356 | + * |
|
357 | + * @return array |
|
358 | + * @throws InvalidArgumentException |
|
359 | + * @throws InvalidInterfaceException |
|
360 | + * @throws InvalidDataTypeException |
|
361 | + */ |
|
362 | + protected function get_submitted_form_data_from_session() |
|
363 | + { |
|
364 | + $session = EE_Registry::instance()->SSN; |
|
365 | + if ($session instanceof EE_Session) { |
|
366 | + return $session->get_session_data( |
|
367 | + EE_Form_Section_Proper::SUBMITTED_FORM_DATA_SSN_KEY |
|
368 | + ); |
|
369 | + } |
|
370 | + return array(); |
|
371 | + } |
|
372 | + |
|
373 | + |
|
374 | + /** |
|
375 | + * flushed the originally submitted input values from the session |
|
376 | + * |
|
377 | + * @return boolean whether or not the data was successfully removed from the session |
|
378 | + * @throws InvalidArgumentException |
|
379 | + * @throws InvalidInterfaceException |
|
380 | + * @throws InvalidDataTypeException |
|
381 | + */ |
|
382 | + public static function flush_submitted_form_data_from_session() |
|
383 | + { |
|
384 | + return EE_Registry::instance()->SSN->reset_data( |
|
385 | + array(EE_Form_Section_Proper::SUBMITTED_FORM_DATA_SSN_KEY) |
|
386 | + ); |
|
387 | + } |
|
388 | + |
|
389 | + |
|
390 | + /** |
|
391 | + * Populates this form and its subsections with data from the session. |
|
392 | + * (Wrapper for EE_Form_Section_Proper::receive_form_submission, so it shows |
|
393 | + * validation errors when displaying too) |
|
394 | + * Returns true if the form was populated from the session, false otherwise |
|
395 | + * |
|
396 | + * @return boolean |
|
397 | + * @throws InvalidArgumentException |
|
398 | + * @throws InvalidInterfaceException |
|
399 | + * @throws InvalidDataTypeException |
|
400 | + * @throws EE_Error |
|
401 | + */ |
|
402 | + public function populate_from_session() |
|
403 | + { |
|
404 | + $form_data_in_session = $this->get_submitted_form_data_from_session(); |
|
405 | + if (empty($form_data_in_session)) { |
|
406 | + return false; |
|
407 | + } |
|
408 | + $this->receive_form_submission($form_data_in_session); |
|
409 | + add_action('shutdown', array('EE_Form_Section_Proper', 'flush_submitted_form_data_from_session')); |
|
410 | + if ($this->form_data_present_in($form_data_in_session)) { |
|
411 | + return true; |
|
412 | + } |
|
413 | + return false; |
|
414 | + } |
|
415 | + |
|
416 | + |
|
417 | + /** |
|
418 | + * Populates the default data for the form, given an array where keys are |
|
419 | + * the input names, and values are their values (preferably normalized to be their |
|
420 | + * proper PHP types, not all strings... although that should be ok too). |
|
421 | + * Proper subsections are sub-arrays, the key being the subsection's name, and |
|
422 | + * the value being an array formatted in teh same way |
|
423 | + * |
|
424 | + * @param array $default_data |
|
425 | + * @throws EE_Error |
|
426 | + */ |
|
427 | + public function populate_defaults($default_data) |
|
428 | + { |
|
429 | + foreach ($this->subsections(false) as $subsection_name => $subsection) { |
|
430 | + if (isset($default_data[ $subsection_name ])) { |
|
431 | + if ($subsection instanceof EE_Form_Input_Base) { |
|
432 | + $subsection->set_default($default_data[ $subsection_name ]); |
|
433 | + } elseif ($subsection instanceof EE_Form_Section_Proper) { |
|
434 | + $subsection->populate_defaults($default_data[ $subsection_name ]); |
|
435 | + } |
|
436 | + } |
|
437 | + } |
|
438 | + } |
|
439 | + |
|
440 | + |
|
441 | + /** |
|
442 | + * returns true if subsection exists |
|
443 | + * |
|
444 | + * @param string $name |
|
445 | + * @return boolean |
|
446 | + */ |
|
447 | + public function subsection_exists($name) |
|
448 | + { |
|
449 | + return isset($this->_subsections[ $name ]) ? true : false; |
|
450 | + } |
|
451 | + |
|
452 | + |
|
453 | + /** |
|
454 | + * Gets the subsection specified by its name |
|
455 | + * |
|
456 | + * @param string $name |
|
457 | + * @param boolean $require_construction_to_be_finalized most client code should leave this as TRUE |
|
458 | + * so that the inputs will be properly configured. |
|
459 | + * However, some client code may be ok |
|
460 | + * with construction finalize being called later |
|
461 | + * (realizing that the subsections' html names |
|
462 | + * might not be set yet, etc.) |
|
463 | + * @return EE_Form_Section_Base |
|
464 | + * @throws EE_Error |
|
465 | + */ |
|
466 | + public function get_subsection($name, $require_construction_to_be_finalized = true) |
|
467 | + { |
|
468 | + if ($require_construction_to_be_finalized) { |
|
469 | + $this->ensure_construct_finalized_called(); |
|
470 | + } |
|
471 | + return $this->subsection_exists($name) ? $this->_subsections[ $name ] : null; |
|
472 | + } |
|
473 | + |
|
474 | + |
|
475 | + /** |
|
476 | + * Gets all the validatable subsections of this form section |
|
477 | + * |
|
478 | + * @return EE_Form_Section_Validatable[] |
|
479 | + * @throws EE_Error |
|
480 | + */ |
|
481 | + public function get_validatable_subsections() |
|
482 | + { |
|
483 | + $validatable_subsections = array(); |
|
484 | + foreach ($this->subsections() as $name => $obj) { |
|
485 | + if ($obj instanceof EE_Form_Section_Validatable) { |
|
486 | + $validatable_subsections[ $name ] = $obj; |
|
487 | + } |
|
488 | + } |
|
489 | + return $validatable_subsections; |
|
490 | + } |
|
491 | + |
|
492 | + |
|
493 | + /** |
|
494 | + * Gets an input by the given name. If not found, or if its not an EE_FOrm_Input_Base child, |
|
495 | + * throw an EE_Error. |
|
496 | + * |
|
497 | + * @param string $name |
|
498 | + * @param boolean $require_construction_to_be_finalized most client code should |
|
499 | + * leave this as TRUE so that the inputs will be properly |
|
500 | + * configured. However, some client code may be ok with |
|
501 | + * construction finalize being called later |
|
502 | + * (realizing that the subsections' html names might not be |
|
503 | + * set yet, etc.) |
|
504 | + * @return EE_Form_Input_Base |
|
505 | + * @throws EE_Error |
|
506 | + */ |
|
507 | + public function get_input($name, $require_construction_to_be_finalized = true) |
|
508 | + { |
|
509 | + $subsection = $this->get_subsection( |
|
510 | + $name, |
|
511 | + $require_construction_to_be_finalized |
|
512 | + ); |
|
513 | + if (! $subsection instanceof EE_Form_Input_Base) { |
|
514 | + throw new EE_Error( |
|
515 | + sprintf( |
|
516 | + esc_html__( |
|
517 | + "Subsection '%s' is not an instanceof EE_Form_Input_Base on form '%s'. It is a '%s'", |
|
518 | + 'event_espresso' |
|
519 | + ), |
|
520 | + $name, |
|
521 | + get_class($this), |
|
522 | + $subsection ? get_class($subsection) : esc_html__('NULL', 'event_espresso') |
|
523 | + ) |
|
524 | + ); |
|
525 | + } |
|
526 | + return $subsection; |
|
527 | + } |
|
528 | + |
|
529 | + |
|
530 | + /** |
|
531 | + * Like get_input(), gets the proper subsection of the form given the name, |
|
532 | + * otherwise throws an EE_Error |
|
533 | + * |
|
534 | + * @param string $name |
|
535 | + * @param boolean $require_construction_to_be_finalized most client code should |
|
536 | + * leave this as TRUE so that the inputs will be properly |
|
537 | + * configured. However, some client code may be ok with |
|
538 | + * construction finalize being called later |
|
539 | + * (realizing that the subsections' html names might not be |
|
540 | + * set yet, etc.) |
|
541 | + * @return EE_Form_Section_Proper |
|
542 | + * @throws EE_Error |
|
543 | + */ |
|
544 | + public function get_proper_subsection($name, $require_construction_to_be_finalized = true) |
|
545 | + { |
|
546 | + $subsection = $this->get_subsection( |
|
547 | + $name, |
|
548 | + $require_construction_to_be_finalized |
|
549 | + ); |
|
550 | + if (! $subsection instanceof EE_Form_Section_Proper) { |
|
551 | + throw new EE_Error( |
|
552 | + sprintf( |
|
553 | + esc_html__( |
|
554 | + "Subsection '%'s is not an instanceof EE_Form_Section_Proper on form '%s'", |
|
555 | + 'event_espresso' |
|
556 | + ), |
|
557 | + $name, |
|
558 | + get_class($this) |
|
559 | + ) |
|
560 | + ); |
|
561 | + } |
|
562 | + return $subsection; |
|
563 | + } |
|
564 | + |
|
565 | + |
|
566 | + /** |
|
567 | + * Gets the value of the specified input. Should be called after receive_form_submission() |
|
568 | + * or populate_defaults() on the form, where the normalized value on the input is set. |
|
569 | + * |
|
570 | + * @param string $name |
|
571 | + * @return mixed depending on the input's type and its normalization strategy |
|
572 | + * @throws EE_Error |
|
573 | + */ |
|
574 | + public function get_input_value($name) |
|
575 | + { |
|
576 | + $input = $this->get_input($name); |
|
577 | + return $input->normalized_value(); |
|
578 | + } |
|
579 | + |
|
580 | + |
|
581 | + /** |
|
582 | + * Checks if this form section itself is valid, and then checks its subsections |
|
583 | + * |
|
584 | + * @throws EE_Error |
|
585 | + * @return boolean |
|
586 | + */ |
|
587 | + public function is_valid() |
|
588 | + { |
|
589 | + if ($this->is_valid === null) { |
|
590 | + if (! $this->has_received_submission()) { |
|
591 | + throw new EE_Error( |
|
592 | + sprintf( |
|
593 | + esc_html__( |
|
594 | + 'You cannot check if a form is valid before receiving the form submission using receive_form_submission', |
|
595 | + 'event_espresso' |
|
596 | + ) |
|
597 | + ) |
|
598 | + ); |
|
599 | + } |
|
600 | + if (! parent::is_valid()) { |
|
601 | + $this->is_valid = false; |
|
602 | + } else { |
|
603 | + // ok so no general errors to this entire form section. |
|
604 | + // so let's check the subsections, but only set errors if that hasn't been done yet |
|
605 | + $this->is_valid = true; |
|
606 | + foreach ($this->get_validatable_subsections() as $subsection) { |
|
607 | + if (! $subsection->is_valid()) { |
|
608 | + $this->is_valid = false; |
|
609 | + } |
|
610 | + } |
|
611 | + } |
|
612 | + } |
|
613 | + return $this->is_valid; |
|
614 | + } |
|
615 | + |
|
616 | + |
|
617 | + /** |
|
618 | + * gets the default name of this form section if none is specified |
|
619 | + * |
|
620 | + * @return void |
|
621 | + */ |
|
622 | + protected function _set_default_name_if_empty() |
|
623 | + { |
|
624 | + if (! $this->_name) { |
|
625 | + $classname = get_class($this); |
|
626 | + $default_name = str_replace('EE_', '', $classname); |
|
627 | + $this->_name = $default_name; |
|
628 | + } |
|
629 | + } |
|
630 | + |
|
631 | + |
|
632 | + /** |
|
633 | + * Returns the HTML for the form, except for the form opening and closing tags |
|
634 | + * (as the form section doesn't know where you necessarily want to send the information to), |
|
635 | + * and except for a submit button. Enqueues JS and CSS; if called early enough we will |
|
636 | + * try to enqueue them in the header, otherwise they'll be enqueued in the footer. |
|
637 | + * Not doing_it_wrong because theoretically this CAN be used properly, |
|
638 | + * provided its used during "wp_enqueue_scripts", or it doesn't need to enqueue |
|
639 | + * any CSS. |
|
640 | + * |
|
641 | + * @throws InvalidArgumentException |
|
642 | + * @throws InvalidInterfaceException |
|
643 | + * @throws InvalidDataTypeException |
|
644 | + * @throws EE_Error |
|
645 | + */ |
|
646 | + public function get_html_and_js() |
|
647 | + { |
|
648 | + $this->enqueue_js(); |
|
649 | + return $this->get_html(); |
|
650 | + } |
|
651 | + |
|
652 | + |
|
653 | + /** |
|
654 | + * returns HTML for displaying this form section. recursively calls display_section() on all subsections |
|
655 | + * |
|
656 | + * @param bool $display_previously_submitted_data |
|
657 | + * @return string |
|
658 | + * @throws InvalidArgumentException |
|
659 | + * @throws InvalidInterfaceException |
|
660 | + * @throws InvalidDataTypeException |
|
661 | + * @throws EE_Error |
|
662 | + * @throws EE_Error |
|
663 | + * @throws EE_Error |
|
664 | + */ |
|
665 | + public function get_html($display_previously_submitted_data = true) |
|
666 | + { |
|
667 | + $this->ensure_construct_finalized_called(); |
|
668 | + if ($display_previously_submitted_data) { |
|
669 | + $this->populate_from_session(); |
|
670 | + } |
|
671 | + return $this->_form_html_filter |
|
672 | + ? $this->_form_html_filter->filterHtml($this->_layout_strategy->layout_form(), $this) |
|
673 | + : $this->_layout_strategy->layout_form(); |
|
674 | + } |
|
675 | + |
|
676 | + |
|
677 | + /** |
|
678 | + * enqueues JS and CSS for the form. |
|
679 | + * It is preferred to call this before wp_enqueue_scripts so the |
|
680 | + * scripts and styles can be put in the header, but if called later |
|
681 | + * they will be put in the footer (which is OK for JS, but in HTML4 CSS should |
|
682 | + * only be in the header; but in HTML5 its ok in the body. |
|
683 | + * See http://stackoverflow.com/questions/4957446/load-external-css-file-in-body-tag. |
|
684 | + * So if your form enqueues CSS, it's preferred to call this before wp_enqueue_scripts.) |
|
685 | + * |
|
686 | + * @return void |
|
687 | + * @throws EE_Error |
|
688 | + */ |
|
689 | + public function enqueue_js() |
|
690 | + { |
|
691 | + $this->_enqueue_and_localize_form_js(); |
|
692 | + foreach ($this->subsections() as $subsection) { |
|
693 | + $subsection->enqueue_js(); |
|
694 | + } |
|
695 | + } |
|
696 | + |
|
697 | + |
|
698 | + /** |
|
699 | + * adds a filter so that jquery validate gets enqueued in EE_System::wp_enqueue_scripts(). |
|
700 | + * This must be done BEFORE wp_enqueue_scripts() gets called, which is on |
|
701 | + * the wp_enqueue_scripts hook. |
|
702 | + * However, registering the form js and localizing it can happen when we |
|
703 | + * actually output the form (which is preferred, seeing how teh form's fields |
|
704 | + * could change until it's actually outputted) |
|
705 | + * |
|
706 | + * @param boolean $init_form_validation_automatically whether or not we want the form validation |
|
707 | + * to be triggered automatically or not |
|
708 | + * @return void |
|
709 | + */ |
|
710 | + public static function wp_enqueue_scripts($init_form_validation_automatically = true) |
|
711 | + { |
|
712 | + wp_register_script( |
|
713 | + 'ee_form_section_validation', |
|
714 | + EE_GLOBAL_ASSETS_URL . 'scripts' . '/form_section_validation.js', |
|
715 | + array('jquery-validate', 'jquery-ui-datepicker', 'jquery-validate-extra-methods'), |
|
716 | + EVENT_ESPRESSO_VERSION, |
|
717 | + true |
|
718 | + ); |
|
719 | + wp_localize_script( |
|
720 | + 'ee_form_section_validation', |
|
721 | + 'ee_form_section_validation_init', |
|
722 | + array('init' => $init_form_validation_automatically ? '1' : '0') |
|
723 | + ); |
|
724 | + } |
|
725 | + |
|
726 | + |
|
727 | + /** |
|
728 | + * gets the variables used by form_section_validation.js. |
|
729 | + * This needs to be called AFTER we've called $this->_enqueue_jquery_validate_script, |
|
730 | + * but before the wordpress hook wp_loaded |
|
731 | + * |
|
732 | + * @throws EE_Error |
|
733 | + */ |
|
734 | + public function _enqueue_and_localize_form_js() |
|
735 | + { |
|
736 | + $this->ensure_construct_finalized_called(); |
|
737 | + // actually, we don't want to localize just yet. There may be other forms on the page. |
|
738 | + // so we need to add our form section data to a static variable accessible by all form sections |
|
739 | + // and localize it just before the footer |
|
740 | + $this->localize_validation_rules(); |
|
741 | + add_action('wp_footer', array('EE_Form_Section_Proper', 'localize_script_for_all_forms'), 2); |
|
742 | + add_action('admin_footer', array('EE_Form_Section_Proper', 'localize_script_for_all_forms')); |
|
743 | + } |
|
744 | + |
|
745 | + |
|
746 | + /** |
|
747 | + * add our form section data to a static variable accessible by all form sections |
|
748 | + * |
|
749 | + * @param bool $return_for_subsection |
|
750 | + * @return void |
|
751 | + * @throws EE_Error |
|
752 | + */ |
|
753 | + public function localize_validation_rules($return_for_subsection = false) |
|
754 | + { |
|
755 | + // we only want to localize vars ONCE for the entire form, |
|
756 | + // so if the form section doesn't have a parent, then it must be the top dog |
|
757 | + if ($return_for_subsection || ! $this->parent_section()) { |
|
758 | + EE_Form_Section_Proper::$_js_localization['form_data'][ $this->html_id() ] = array( |
|
759 | + 'form_section_id' => $this->html_id(true), |
|
760 | + 'validation_rules' => $this->get_jquery_validation_rules(), |
|
761 | + 'other_data' => $this->get_other_js_data(), |
|
762 | + 'errors' => $this->subsection_validation_errors_by_html_name(), |
|
763 | + ); |
|
764 | + EE_Form_Section_Proper::$_scripts_localized = true; |
|
765 | + } |
|
766 | + } |
|
767 | + |
|
768 | + |
|
769 | + /** |
|
770 | + * Gets an array of extra data that will be useful for client-side javascript. |
|
771 | + * This is primarily data added by inputs and forms in addition to any |
|
772 | + * scripts they might enqueue |
|
773 | + * |
|
774 | + * @param array $form_other_js_data |
|
775 | + * @return array |
|
776 | + * @throws EE_Error |
|
777 | + */ |
|
778 | + public function get_other_js_data($form_other_js_data = array()) |
|
779 | + { |
|
780 | + foreach ($this->subsections() as $subsection) { |
|
781 | + $form_other_js_data = $subsection->get_other_js_data($form_other_js_data); |
|
782 | + } |
|
783 | + return $form_other_js_data; |
|
784 | + } |
|
785 | + |
|
786 | + |
|
787 | + /** |
|
788 | + * Gets a flat array of inputs for this form section and its subsections. |
|
789 | + * Keys are their form names, and values are the inputs themselves |
|
790 | + * |
|
791 | + * @return EE_Form_Input_Base |
|
792 | + * @throws EE_Error |
|
793 | + */ |
|
794 | + public function inputs_in_subsections() |
|
795 | + { |
|
796 | + $inputs = array(); |
|
797 | + foreach ($this->subsections() as $subsection) { |
|
798 | + if ($subsection instanceof EE_Form_Input_Base) { |
|
799 | + $inputs[ $subsection->html_name() ] = $subsection; |
|
800 | + } elseif ($subsection instanceof EE_Form_Section_Proper) { |
|
801 | + $inputs += $subsection->inputs_in_subsections(); |
|
802 | + } |
|
803 | + } |
|
804 | + return $inputs; |
|
805 | + } |
|
806 | + |
|
807 | + |
|
808 | + /** |
|
809 | + * Gets a flat array of all the validation errors. |
|
810 | + * Keys are html names (because those should be unique) |
|
811 | + * and values are a string of all their validation errors |
|
812 | + * |
|
813 | + * @return string[] |
|
814 | + * @throws EE_Error |
|
815 | + */ |
|
816 | + public function subsection_validation_errors_by_html_name() |
|
817 | + { |
|
818 | + $inputs = $this->inputs(); |
|
819 | + $errors = array(); |
|
820 | + foreach ($inputs as $form_input) { |
|
821 | + if ($form_input instanceof EE_Form_Input_Base && $form_input->get_validation_errors()) { |
|
822 | + $errors[ $form_input->html_name() ] = $form_input->get_validation_error_string(); |
|
823 | + } |
|
824 | + } |
|
825 | + return $errors; |
|
826 | + } |
|
827 | + |
|
828 | + |
|
829 | + /** |
|
830 | + * passes all the form data required by the JS to the JS, and enqueues the few required JS files. |
|
831 | + * Should be setup by each form during the _enqueues_and_localize_form_js |
|
832 | + * |
|
833 | + * @throws InvalidArgumentException |
|
834 | + * @throws InvalidInterfaceException |
|
835 | + * @throws InvalidDataTypeException |
|
836 | + */ |
|
837 | + public static function localize_script_for_all_forms() |
|
838 | + { |
|
839 | + // allow inputs and stuff to hook in their JS and stuff here |
|
840 | + do_action('AHEE__EE_Form_Section_Proper__localize_script_for_all_forms__begin'); |
|
841 | + EE_Form_Section_Proper::$_js_localization['localized_error_messages'] = EE_Form_Section_Proper::_get_localized_error_messages(); |
|
842 | + $email_validation_level = isset(EE_Registry::instance()->CFG->registration->email_validation_level) |
|
843 | + ? EE_Registry::instance()->CFG->registration->email_validation_level |
|
844 | + : 'wp_default'; |
|
845 | + EE_Form_Section_Proper::$_js_localization['email_validation_level'] = $email_validation_level; |
|
846 | + wp_enqueue_script('ee_form_section_validation'); |
|
847 | + wp_localize_script( |
|
848 | + 'ee_form_section_validation', |
|
849 | + 'ee_form_section_vars', |
|
850 | + EE_Form_Section_Proper::$_js_localization |
|
851 | + ); |
|
852 | + } |
|
853 | + |
|
854 | + |
|
855 | + /** |
|
856 | + * ensure_scripts_localized |
|
857 | + * |
|
858 | + * @throws EE_Error |
|
859 | + */ |
|
860 | + public function ensure_scripts_localized() |
|
861 | + { |
|
862 | + if (! EE_Form_Section_Proper::$_scripts_localized) { |
|
863 | + $this->_enqueue_and_localize_form_js(); |
|
864 | + } |
|
865 | + } |
|
866 | + |
|
867 | + |
|
868 | + /** |
|
869 | + * Gets the hard-coded validation error messages to be used in the JS. The convention |
|
870 | + * is that the key here should be the same as the custom validation rule put in the JS file |
|
871 | + * |
|
872 | + * @return array keys are custom validation rules, and values are internationalized strings |
|
873 | + */ |
|
874 | + private static function _get_localized_error_messages() |
|
875 | + { |
|
876 | + return array( |
|
877 | + 'validUrl' => esc_html__('This is not a valid absolute URL. Eg, http://domain.com/monkey.jpg', 'event_espresso'), |
|
878 | + 'regex' => esc_html__('Please check your input', 'event_espresso'), |
|
879 | + ); |
|
880 | + } |
|
881 | + |
|
882 | + |
|
883 | + /** |
|
884 | + * @return array |
|
885 | + */ |
|
886 | + public static function js_localization() |
|
887 | + { |
|
888 | + return self::$_js_localization; |
|
889 | + } |
|
890 | + |
|
891 | + |
|
892 | + /** |
|
893 | + * @return void |
|
894 | + */ |
|
895 | + public static function reset_js_localization() |
|
896 | + { |
|
897 | + self::$_js_localization = array(); |
|
898 | + } |
|
899 | + |
|
900 | + |
|
901 | + /** |
|
902 | + * Gets the JS to put inside the jquery validation rules for subsection of this form section. |
|
903 | + * See parent function for more... |
|
904 | + * |
|
905 | + * @return array |
|
906 | + * @throws EE_Error |
|
907 | + */ |
|
908 | + public function get_jquery_validation_rules() |
|
909 | + { |
|
910 | + $jquery_validation_rules = array(); |
|
911 | + foreach ($this->get_validatable_subsections() as $subsection) { |
|
912 | + $jquery_validation_rules = array_merge( |
|
913 | + $jquery_validation_rules, |
|
914 | + $subsection->get_jquery_validation_rules() |
|
915 | + ); |
|
916 | + } |
|
917 | + return $jquery_validation_rules; |
|
918 | + } |
|
919 | + |
|
920 | + |
|
921 | + /** |
|
922 | + * Sanitizes all the data and sets the sanitized value of each field |
|
923 | + * |
|
924 | + * @param array $req_data like $_POST |
|
925 | + * @return void |
|
926 | + * @throws EE_Error |
|
927 | + */ |
|
928 | + protected function _normalize($req_data) |
|
929 | + { |
|
930 | + $this->_received_submission = true; |
|
931 | + $this->_validation_errors = array(); |
|
932 | + foreach ($this->get_validatable_subsections() as $subsection) { |
|
933 | + try { |
|
934 | + $subsection->_normalize($req_data); |
|
935 | + } catch (EE_Validation_Error $e) { |
|
936 | + $subsection->add_validation_error($e); |
|
937 | + } |
|
938 | + } |
|
939 | + } |
|
940 | + |
|
941 | + |
|
942 | + /** |
|
943 | + * Performs validation on this form section and its subsections. |
|
944 | + * For each subsection, |
|
945 | + * calls _validate_{subsection_name} on THIS form (if the function exists) |
|
946 | + * and passes it the subsection, then calls _validate on that subsection. |
|
947 | + * If you need to perform validation on the form as a whole (considering multiple) |
|
948 | + * you would be best to override this _validate method, |
|
949 | + * calling parent::_validate() first. |
|
950 | + * |
|
951 | + * @throws EE_Error |
|
952 | + */ |
|
953 | + protected function _validate() |
|
954 | + { |
|
955 | + // reset the cache of whether this form is valid or not- we're re-validating it now |
|
956 | + $this->is_valid = null; |
|
957 | + foreach ($this->get_validatable_subsections() as $subsection_name => $subsection) { |
|
958 | + if (method_exists($this, '_validate_' . $subsection_name)) { |
|
959 | + call_user_func_array(array($this, '_validate_' . $subsection_name), array($subsection)); |
|
960 | + } |
|
961 | + $subsection->_validate(); |
|
962 | + } |
|
963 | + } |
|
964 | + |
|
965 | + |
|
966 | + /** |
|
967 | + * Gets all the validated inputs for the form section |
|
968 | + * |
|
969 | + * @return array |
|
970 | + * @throws EE_Error |
|
971 | + */ |
|
972 | + public function valid_data() |
|
973 | + { |
|
974 | + $inputs = array(); |
|
975 | + foreach ($this->subsections() as $subsection_name => $subsection) { |
|
976 | + if ($subsection instanceof EE_Form_Section_Proper) { |
|
977 | + $inputs[ $subsection_name ] = $subsection->valid_data(); |
|
978 | + } elseif ($subsection instanceof EE_Form_Input_Base) { |
|
979 | + $inputs[ $subsection_name ] = $subsection->normalized_value(); |
|
980 | + } |
|
981 | + } |
|
982 | + return $inputs; |
|
983 | + } |
|
984 | + |
|
985 | + |
|
986 | + /** |
|
987 | + * Gets all the inputs on this form section |
|
988 | + * |
|
989 | + * @return EE_Form_Input_Base[] |
|
990 | + * @throws EE_Error |
|
991 | + */ |
|
992 | + public function inputs() |
|
993 | + { |
|
994 | + $inputs = array(); |
|
995 | + foreach ($this->subsections() as $subsection_name => $subsection) { |
|
996 | + if ($subsection instanceof EE_Form_Input_Base) { |
|
997 | + $inputs[ $subsection_name ] = $subsection; |
|
998 | + } |
|
999 | + } |
|
1000 | + return $inputs; |
|
1001 | + } |
|
1002 | + |
|
1003 | + |
|
1004 | + /** |
|
1005 | + * Gets all the subsections which are a proper form |
|
1006 | + * |
|
1007 | + * @return EE_Form_Section_Proper[] |
|
1008 | + * @throws EE_Error |
|
1009 | + */ |
|
1010 | + public function subforms() |
|
1011 | + { |
|
1012 | + $form_sections = array(); |
|
1013 | + foreach ($this->subsections() as $name => $obj) { |
|
1014 | + if ($obj instanceof EE_Form_Section_Proper) { |
|
1015 | + $form_sections[ $name ] = $obj; |
|
1016 | + } |
|
1017 | + } |
|
1018 | + return $form_sections; |
|
1019 | + } |
|
1020 | + |
|
1021 | + |
|
1022 | + /** |
|
1023 | + * Gets all the subsections (inputs, proper subsections, or html-only sections). |
|
1024 | + * Consider using inputs() or subforms() |
|
1025 | + * if you only want form inputs or proper form sections. |
|
1026 | + * |
|
1027 | + * @param boolean $require_construction_to_be_finalized most client code should |
|
1028 | + * leave this as TRUE so that the inputs will be properly |
|
1029 | + * configured. However, some client code may be ok with |
|
1030 | + * construction finalize being called later |
|
1031 | + * (realizing that the subsections' html names might not be |
|
1032 | + * set yet, etc.) |
|
1033 | + * @return EE_Form_Section_Proper[] |
|
1034 | + * @throws EE_Error |
|
1035 | + */ |
|
1036 | + public function subsections($require_construction_to_be_finalized = true) |
|
1037 | + { |
|
1038 | + if ($require_construction_to_be_finalized) { |
|
1039 | + $this->ensure_construct_finalized_called(); |
|
1040 | + } |
|
1041 | + return $this->_subsections; |
|
1042 | + } |
|
1043 | + |
|
1044 | + |
|
1045 | + /** |
|
1046 | + * Returns whether this form has any subforms or inputs |
|
1047 | + * @return bool |
|
1048 | + */ |
|
1049 | + public function hasSubsections() |
|
1050 | + { |
|
1051 | + return ! empty($this->_subsections); |
|
1052 | + } |
|
1053 | + |
|
1054 | + |
|
1055 | + /** |
|
1056 | + * Returns a simple array where keys are input names, and values are their normalized |
|
1057 | + * values. (Similar to calling get_input_value on inputs) |
|
1058 | + * |
|
1059 | + * @param boolean $include_subform_inputs Whether to include inputs from subforms, |
|
1060 | + * or just this forms' direct children inputs |
|
1061 | + * @param boolean $flatten Whether to force the results into 1-dimensional array, |
|
1062 | + * or allow multidimensional array |
|
1063 | + * @return array if $flatten is TRUE it will always be a 1-dimensional array |
|
1064 | + * with array keys being input names |
|
1065 | + * (regardless of whether they are from a subsection or not), |
|
1066 | + * and if $flatten is FALSE it can be a multidimensional array |
|
1067 | + * where keys are always subsection names and values are either |
|
1068 | + * the input's normalized value, or an array like the top-level array |
|
1069 | + * @throws EE_Error |
|
1070 | + */ |
|
1071 | + public function input_values($include_subform_inputs = false, $flatten = false) |
|
1072 | + { |
|
1073 | + return $this->_input_values(false, $include_subform_inputs, $flatten); |
|
1074 | + } |
|
1075 | + |
|
1076 | + |
|
1077 | + /** |
|
1078 | + * Similar to EE_Form_Section_Proper::input_values(), except this returns the 'display_value' |
|
1079 | + * of each input. On some inputs (especially radio boxes or checkboxes), the value stored |
|
1080 | + * is not necessarily the value we want to display to users. This creates an array |
|
1081 | + * where keys are the input names, and values are their display values |
|
1082 | + * |
|
1083 | + * @param boolean $include_subform_inputs Whether to include inputs from subforms, |
|
1084 | + * or just this forms' direct children inputs |
|
1085 | + * @param boolean $flatten Whether to force the results into 1-dimensional array, |
|
1086 | + * or allow multidimensional array |
|
1087 | + * @return array if $flatten is TRUE it will always be a 1-dimensional array |
|
1088 | + * with array keys being input names |
|
1089 | + * (regardless of whether they are from a subsection or not), |
|
1090 | + * and if $flatten is FALSE it can be a multidimensional array |
|
1091 | + * where keys are always subsection names and values are either |
|
1092 | + * the input's normalized value, or an array like the top-level array |
|
1093 | + * @throws EE_Error |
|
1094 | + */ |
|
1095 | + public function input_pretty_values($include_subform_inputs = false, $flatten = false) |
|
1096 | + { |
|
1097 | + return $this->_input_values(true, $include_subform_inputs, $flatten); |
|
1098 | + } |
|
1099 | + |
|
1100 | + |
|
1101 | + /** |
|
1102 | + * Gets the input values from the form |
|
1103 | + * |
|
1104 | + * @param boolean $pretty Whether to retrieve the pretty value, |
|
1105 | + * or just the normalized value |
|
1106 | + * @param boolean $include_subform_inputs Whether to include inputs from subforms, |
|
1107 | + * or just this forms' direct children inputs |
|
1108 | + * @param boolean $flatten Whether to force the results into 1-dimensional array, |
|
1109 | + * or allow multidimensional array |
|
1110 | + * @return array if $flatten is TRUE it will always be a 1-dimensional array with array keys being |
|
1111 | + * input names (regardless of whether they are from a subsection or not), |
|
1112 | + * and if $flatten is FALSE it can be a multidimensional array |
|
1113 | + * where keys are always subsection names and values are either |
|
1114 | + * the input's normalized value, or an array like the top-level array |
|
1115 | + * @throws EE_Error |
|
1116 | + */ |
|
1117 | + public function _input_values($pretty = false, $include_subform_inputs = false, $flatten = false) |
|
1118 | + { |
|
1119 | + $input_values = array(); |
|
1120 | + foreach ($this->subsections() as $subsection_name => $subsection) { |
|
1121 | + if ($subsection instanceof EE_Form_Input_Base) { |
|
1122 | + $input_values[ $subsection_name ] = $pretty |
|
1123 | + ? $subsection->pretty_value() |
|
1124 | + : $subsection->normalized_value(); |
|
1125 | + } elseif ($subsection instanceof EE_Form_Section_Proper && $include_subform_inputs) { |
|
1126 | + $subform_input_values = $subsection->_input_values( |
|
1127 | + $pretty, |
|
1128 | + $include_subform_inputs, |
|
1129 | + $flatten |
|
1130 | + ); |
|
1131 | + if ($flatten) { |
|
1132 | + $input_values = array_merge($input_values, $subform_input_values); |
|
1133 | + } else { |
|
1134 | + $input_values[ $subsection_name ] = $subform_input_values; |
|
1135 | + } |
|
1136 | + } |
|
1137 | + } |
|
1138 | + return $input_values; |
|
1139 | + } |
|
1140 | + |
|
1141 | + |
|
1142 | + /** |
|
1143 | + * Gets the originally submitted input values from the form |
|
1144 | + * |
|
1145 | + * @param boolean $include_subforms Whether to include inputs from subforms, |
|
1146 | + * or just this forms' direct children inputs |
|
1147 | + * @return array if $flatten is TRUE it will always be a 1-dimensional array |
|
1148 | + * with array keys being input names |
|
1149 | + * (regardless of whether they are from a subsection or not), |
|
1150 | + * and if $flatten is FALSE it can be a multidimensional array |
|
1151 | + * where keys are always subsection names and values are either |
|
1152 | + * the input's normalized value, or an array like the top-level array |
|
1153 | + * @throws EE_Error |
|
1154 | + */ |
|
1155 | + public function submitted_values($include_subforms = false) |
|
1156 | + { |
|
1157 | + $submitted_values = array(); |
|
1158 | + foreach ($this->subsections() as $subsection) { |
|
1159 | + if ($subsection instanceof EE_Form_Input_Base) { |
|
1160 | + // is this input part of an array of inputs? |
|
1161 | + if (strpos($subsection->html_name(), '[') !== false) { |
|
1162 | + $full_input_name = EEH_Array::convert_array_values_to_keys( |
|
1163 | + explode( |
|
1164 | + '[', |
|
1165 | + str_replace(']', '', $subsection->html_name()) |
|
1166 | + ), |
|
1167 | + $subsection->raw_value() |
|
1168 | + ); |
|
1169 | + $submitted_values = array_replace_recursive($submitted_values, $full_input_name); |
|
1170 | + } else { |
|
1171 | + $submitted_values[ $subsection->html_name() ] = $subsection->raw_value(); |
|
1172 | + } |
|
1173 | + } elseif ($subsection instanceof EE_Form_Section_Proper && $include_subforms) { |
|
1174 | + $subform_input_values = $subsection->submitted_values($include_subforms); |
|
1175 | + $submitted_values = array_replace_recursive($submitted_values, $subform_input_values); |
|
1176 | + } |
|
1177 | + } |
|
1178 | + return $submitted_values; |
|
1179 | + } |
|
1180 | + |
|
1181 | + |
|
1182 | + /** |
|
1183 | + * Indicates whether or not this form has received a submission yet |
|
1184 | + * (ie, had receive_form_submission called on it yet) |
|
1185 | + * |
|
1186 | + * @return boolean |
|
1187 | + * @throws EE_Error |
|
1188 | + */ |
|
1189 | + public function has_received_submission() |
|
1190 | + { |
|
1191 | + $this->ensure_construct_finalized_called(); |
|
1192 | + return $this->_received_submission; |
|
1193 | + } |
|
1194 | + |
|
1195 | + |
|
1196 | + /** |
|
1197 | + * Equivalent to passing 'exclude' in the constructor's options array. |
|
1198 | + * Removes the listed inputs from the form |
|
1199 | + * |
|
1200 | + * @param array $inputs_to_exclude values are the input names |
|
1201 | + * @return void |
|
1202 | + */ |
|
1203 | + public function exclude(array $inputs_to_exclude = array()) |
|
1204 | + { |
|
1205 | + foreach ($inputs_to_exclude as $input_to_exclude_name) { |
|
1206 | + unset($this->_subsections[ $input_to_exclude_name ]); |
|
1207 | + } |
|
1208 | + } |
|
1209 | + |
|
1210 | + |
|
1211 | + /** |
|
1212 | + * Changes these inputs' display strategy to be EE_Hidden_Display_Strategy. |
|
1213 | + * @param array $inputs_to_hide |
|
1214 | + * @throws EE_Error |
|
1215 | + */ |
|
1216 | + public function hide(array $inputs_to_hide = array()) |
|
1217 | + { |
|
1218 | + foreach ($inputs_to_hide as $input_to_hide) { |
|
1219 | + $input = $this->get_input($input_to_hide); |
|
1220 | + $input->set_display_strategy(new EE_Hidden_Display_Strategy()); |
|
1221 | + } |
|
1222 | + } |
|
1223 | + |
|
1224 | + |
|
1225 | + /** |
|
1226 | + * add_subsections |
|
1227 | + * Adds the listed subsections to the form section. |
|
1228 | + * If $subsection_name_to_target is provided, |
|
1229 | + * then new subsections are added before or after that subsection, |
|
1230 | + * otherwise to the start or end of the entire subsections array. |
|
1231 | + * |
|
1232 | + * @param EE_Form_Section_Base[] $new_subsections array of new form subsections |
|
1233 | + * where keys are their names |
|
1234 | + * @param string $subsection_name_to_target an existing for section that $new_subsections |
|
1235 | + * should be added before or after |
|
1236 | + * IF $subsection_name_to_target is null, |
|
1237 | + * then $new_subsections will be added to |
|
1238 | + * the beginning or end of the entire subsections array |
|
1239 | + * @param boolean $add_before whether to add $new_subsections, before or after |
|
1240 | + * $subsection_name_to_target, |
|
1241 | + * or if $subsection_name_to_target is null, |
|
1242 | + * before or after entire subsections array |
|
1243 | + * @return void |
|
1244 | + * @throws EE_Error |
|
1245 | + */ |
|
1246 | + public function add_subsections($new_subsections, $subsection_name_to_target = null, $add_before = true) |
|
1247 | + { |
|
1248 | + foreach ($new_subsections as $subsection_name => $subsection) { |
|
1249 | + if (! $subsection instanceof EE_Form_Section_Base) { |
|
1250 | + EE_Error::add_error( |
|
1251 | + sprintf( |
|
1252 | + esc_html__( |
|
1253 | + "Trying to add a %s as a subsection (it was named '%s') to the form section '%s'. It was removed.", |
|
1254 | + 'event_espresso' |
|
1255 | + ), |
|
1256 | + get_class($subsection), |
|
1257 | + $subsection_name, |
|
1258 | + $this->name() |
|
1259 | + ) |
|
1260 | + ); |
|
1261 | + unset($new_subsections[ $subsection_name ]); |
|
1262 | + } |
|
1263 | + } |
|
1264 | + $this->_subsections = EEH_Array::insert_into_array( |
|
1265 | + $this->_subsections, |
|
1266 | + $new_subsections, |
|
1267 | + $subsection_name_to_target, |
|
1268 | + $add_before |
|
1269 | + ); |
|
1270 | + if ($this->_construction_finalized) { |
|
1271 | + foreach ($this->_subsections as $name => $subsection) { |
|
1272 | + $subsection->_construct_finalize($this, $name); |
|
1273 | + } |
|
1274 | + } |
|
1275 | + } |
|
1276 | + |
|
1277 | + |
|
1278 | + /** |
|
1279 | + * @param string $subsection_name |
|
1280 | + * @param bool $recursive |
|
1281 | + * @return bool |
|
1282 | + */ |
|
1283 | + public function has_subsection($subsection_name, $recursive = false) |
|
1284 | + { |
|
1285 | + foreach ($this->_subsections as $name => $subsection) { |
|
1286 | + if ( |
|
1287 | + $name === $subsection_name |
|
1288 | + || ( |
|
1289 | + $recursive |
|
1290 | + && $subsection instanceof EE_Form_Section_Proper |
|
1291 | + && $subsection->has_subsection($subsection_name, $recursive) |
|
1292 | + ) |
|
1293 | + ) { |
|
1294 | + return true; |
|
1295 | + } |
|
1296 | + } |
|
1297 | + return false; |
|
1298 | + } |
|
1299 | + |
|
1300 | + |
|
1301 | + |
|
1302 | + /** |
|
1303 | + * Just gets all validatable subsections to clean their sensitive data |
|
1304 | + * |
|
1305 | + * @throws EE_Error |
|
1306 | + */ |
|
1307 | + public function clean_sensitive_data() |
|
1308 | + { |
|
1309 | + foreach ($this->get_validatable_subsections() as $subsection) { |
|
1310 | + $subsection->clean_sensitive_data(); |
|
1311 | + } |
|
1312 | + } |
|
1313 | + |
|
1314 | + |
|
1315 | + /** |
|
1316 | + * Sets the submission error message (aka validation error message for this form section and all sub-sections) |
|
1317 | + * @param string $form_submission_error_message |
|
1318 | + * @param EE_Form_Section_Validatable $form_section unused |
|
1319 | + * @throws EE_Error |
|
1320 | + */ |
|
1321 | + public function set_submission_error_message( |
|
1322 | + $form_submission_error_message = '' |
|
1323 | + ) { |
|
1324 | + $this->_form_submission_error_message = ! empty($form_submission_error_message) |
|
1325 | + ? $form_submission_error_message |
|
1326 | + : $this->getAllValidationErrorsString(); |
|
1327 | + } |
|
1328 | + |
|
1329 | + |
|
1330 | + /** |
|
1331 | + * Returns the cached error message. A default value is set for this during _validate(), |
|
1332 | + * (called during receive_form_submission) but it can be explicitly set using |
|
1333 | + * set_submission_error_message |
|
1334 | + * |
|
1335 | + * @return string |
|
1336 | + */ |
|
1337 | + public function submission_error_message() |
|
1338 | + { |
|
1339 | + return $this->_form_submission_error_message; |
|
1340 | + } |
|
1341 | + |
|
1342 | + |
|
1343 | + /** |
|
1344 | + * Sets a message to display if the data submitted to the form was valid. |
|
1345 | + * @param string $form_submission_success_message |
|
1346 | + */ |
|
1347 | + public function set_submission_success_message($form_submission_success_message = '') |
|
1348 | + { |
|
1349 | + $this->_form_submission_success_message = ! empty($form_submission_success_message) |
|
1350 | + ? $form_submission_success_message |
|
1351 | + : esc_html__('Form submitted successfully', 'event_espresso'); |
|
1352 | + } |
|
1353 | + |
|
1354 | + |
|
1355 | + /** |
|
1356 | + * Gets a message appropriate for display when the form is correctly submitted |
|
1357 | + * @return string |
|
1358 | + */ |
|
1359 | + public function submission_success_message() |
|
1360 | + { |
|
1361 | + return $this->_form_submission_success_message; |
|
1362 | + } |
|
1363 | + |
|
1364 | + |
|
1365 | + /** |
|
1366 | + * Returns the prefix that should be used on child of this form section for |
|
1367 | + * their html names. If this form section itself has a parent, prepends ITS |
|
1368 | + * prefix onto this form section's prefix. Used primarily by |
|
1369 | + * EE_Form_Input_Base::_set_default_html_name_if_empty |
|
1370 | + * |
|
1371 | + * @return string |
|
1372 | + * @throws EE_Error |
|
1373 | + */ |
|
1374 | + public function html_name_prefix() |
|
1375 | + { |
|
1376 | + if ($this->parent_section() instanceof EE_Form_Section_Proper) { |
|
1377 | + return $this->parent_section()->html_name_prefix() . '[' . $this->name() . ']'; |
|
1378 | + } |
|
1379 | + return $this->name(); |
|
1380 | + } |
|
1381 | + |
|
1382 | + |
|
1383 | + /** |
|
1384 | + * Gets the name, but first checks _construct_finalize has been called. If not, |
|
1385 | + * calls it (assumes there is no parent and that we want the name to be whatever |
|
1386 | + * was set, which is probably nothing, or the classname) |
|
1387 | + * |
|
1388 | + * @return string |
|
1389 | + * @throws EE_Error |
|
1390 | + */ |
|
1391 | + public function name() |
|
1392 | + { |
|
1393 | + $this->ensure_construct_finalized_called(); |
|
1394 | + return parent::name(); |
|
1395 | + } |
|
1396 | + |
|
1397 | + |
|
1398 | + /** |
|
1399 | + * @return EE_Form_Section_Proper |
|
1400 | + * @throws EE_Error |
|
1401 | + */ |
|
1402 | + public function parent_section() |
|
1403 | + { |
|
1404 | + $this->ensure_construct_finalized_called(); |
|
1405 | + return parent::parent_section(); |
|
1406 | + } |
|
1407 | + |
|
1408 | + |
|
1409 | + /** |
|
1410 | + * make sure construction finalized was called, otherwise children might not be ready |
|
1411 | + * |
|
1412 | + * @return void |
|
1413 | + * @throws EE_Error |
|
1414 | + */ |
|
1415 | + public function ensure_construct_finalized_called() |
|
1416 | + { |
|
1417 | + if (! $this->_construction_finalized) { |
|
1418 | + $this->_construct_finalize($this->_parent_section, $this->_name); |
|
1419 | + } |
|
1420 | + } |
|
1421 | + |
|
1422 | + |
|
1423 | + /** |
|
1424 | + * Checks if any of this form section's inputs, or any of its children's inputs, |
|
1425 | + * are in teh form data. If any are found, returns true. Else false |
|
1426 | + * |
|
1427 | + * @param array $req_data |
|
1428 | + * @return boolean |
|
1429 | + * @throws EE_Error |
|
1430 | + */ |
|
1431 | + public function form_data_present_in($req_data = null) |
|
1432 | + { |
|
1433 | + $req_data = $this->getCachedRequest($req_data); |
|
1434 | + foreach ($this->subsections() as $subsection) { |
|
1435 | + if ($subsection instanceof EE_Form_Input_Base) { |
|
1436 | + if ($subsection->form_data_present_in($req_data)) { |
|
1437 | + return true; |
|
1438 | + } |
|
1439 | + } elseif ($subsection instanceof EE_Form_Section_Proper) { |
|
1440 | + if ($subsection->form_data_present_in($req_data)) { |
|
1441 | + return true; |
|
1442 | + } |
|
1443 | + } |
|
1444 | + } |
|
1445 | + return false; |
|
1446 | + } |
|
1447 | + |
|
1448 | + |
|
1449 | + /** |
|
1450 | + * Gets validation errors for this form section and subsections |
|
1451 | + * Similar to EE_Form_Section_Validatable::get_validation_errors() except this |
|
1452 | + * gets the validation errors for ALL subsection |
|
1453 | + * |
|
1454 | + * @return EE_Validation_Error[] |
|
1455 | + * @throws EE_Error |
|
1456 | + */ |
|
1457 | + public function get_validation_errors_accumulated() |
|
1458 | + { |
|
1459 | + $validation_errors = $this->get_validation_errors(); |
|
1460 | + foreach ($this->get_validatable_subsections() as $subsection) { |
|
1461 | + if ($subsection instanceof EE_Form_Section_Proper) { |
|
1462 | + $validation_errors_on_this_subsection = $subsection->get_validation_errors_accumulated(); |
|
1463 | + } else { |
|
1464 | + $validation_errors_on_this_subsection = $subsection->get_validation_errors(); |
|
1465 | + } |
|
1466 | + if ($validation_errors_on_this_subsection) { |
|
1467 | + $validation_errors = array_merge($validation_errors, $validation_errors_on_this_subsection); |
|
1468 | + } |
|
1469 | + } |
|
1470 | + return $validation_errors; |
|
1471 | + } |
|
1472 | + |
|
1473 | + /** |
|
1474 | + * Fetch validation errors from children and grandchildren and puts them in a single string. |
|
1475 | + * This traverses the form section tree to generate this, but you probably want to instead use |
|
1476 | + * get_form_submission_error_message() which is usually this message cached (or a custom validation error message) |
|
1477 | + * |
|
1478 | + * @return string |
|
1479 | + * @since 4.9.59.p |
|
1480 | + */ |
|
1481 | + protected function getAllValidationErrorsString() |
|
1482 | + { |
|
1483 | + $submission_error_messages = array(); |
|
1484 | + // bad, bad, bad registrant |
|
1485 | + foreach ($this->get_validation_errors_accumulated() as $validation_error) { |
|
1486 | + if ($validation_error instanceof EE_Validation_Error) { |
|
1487 | + $form_section = $validation_error->get_form_section(); |
|
1488 | + if ($form_section instanceof EE_Form_Input_Base) { |
|
1489 | + $label = $validation_error->get_form_section()->html_label_text(); |
|
1490 | + } elseif ($form_section instanceof EE_Form_Section_Validatable) { |
|
1491 | + $label = $validation_error->get_form_section()->name(); |
|
1492 | + } else { |
|
1493 | + $label = esc_html__('Unknown', 'event_espresso'); |
|
1494 | + } |
|
1495 | + $submission_error_messages[] = sprintf( |
|
1496 | + __('%s : %s', 'event_espresso'), |
|
1497 | + $label, |
|
1498 | + $validation_error->getMessage() |
|
1499 | + ); |
|
1500 | + } |
|
1501 | + } |
|
1502 | + return implode('<br>', $submission_error_messages); |
|
1503 | + } |
|
1504 | + |
|
1505 | + |
|
1506 | + /** |
|
1507 | + * This isn't just the name of an input, it's a path pointing to an input. The |
|
1508 | + * path is similar to a folder path: slash (/) means to descend into a subsection, |
|
1509 | + * dot-dot-slash (../) means to ascend into the parent section. |
|
1510 | + * After a series of slashes and dot-dot-slashes, there should be the name of an input, |
|
1511 | + * which will be returned. |
|
1512 | + * Eg, if you want the related input to be conditional on a sibling input name 'foobar' |
|
1513 | + * just use 'foobar'. If you want it to be conditional on an aunt/uncle input name |
|
1514 | + * 'baz', use '../baz'. If you want it to be conditional on a cousin input, |
|
1515 | + * the child of 'baz_section' named 'baz_child', use '../baz_section/baz_child'. |
|
1516 | + * Etc |
|
1517 | + * |
|
1518 | + * @param string|false $form_section_path we accept false also because substr( '../', '../' ) = false |
|
1519 | + * @return EE_Form_Section_Base |
|
1520 | + * @throws EE_Error |
|
1521 | + */ |
|
1522 | + public function find_section_from_path($form_section_path) |
|
1523 | + { |
|
1524 | + // check if we can find the input from purely going straight up the tree |
|
1525 | + $input = parent::find_section_from_path($form_section_path); |
|
1526 | + if ($input instanceof EE_Form_Section_Base) { |
|
1527 | + return $input; |
|
1528 | + } |
|
1529 | + $next_slash_pos = strpos($form_section_path, '/'); |
|
1530 | + if ($next_slash_pos !== false) { |
|
1531 | + $child_section_name = substr($form_section_path, 0, $next_slash_pos); |
|
1532 | + $subpath = substr($form_section_path, $next_slash_pos + 1); |
|
1533 | + } else { |
|
1534 | + $child_section_name = $form_section_path; |
|
1535 | + $subpath = ''; |
|
1536 | + } |
|
1537 | + $child_section = $this->get_subsection($child_section_name); |
|
1538 | + if ($child_section instanceof EE_Form_Section_Base) { |
|
1539 | + return $child_section->find_section_from_path($subpath); |
|
1540 | + } |
|
1541 | + return null; |
|
1542 | + } |
|
1543 | 1543 | } |
@@ -16,127 +16,127 @@ |
||
16 | 16 | |
17 | 17 | |
18 | 18 | |
19 | - /** |
|
20 | - * @type EE_Messenger_Collection $_messenger_collection |
|
21 | - */ |
|
22 | - protected $_messenger_collection = null; |
|
23 | - |
|
24 | - |
|
25 | - |
|
26 | - /** |
|
27 | - * EE_Messenger_Collection_Loader constructor. |
|
28 | - * |
|
29 | - * @param EE_Messenger_Collection $messengers |
|
30 | - */ |
|
31 | - public function __construct(EE_Messenger_Collection $messengers) |
|
32 | - { |
|
33 | - $this->set_messenger_collection($messengers); |
|
34 | - } |
|
35 | - |
|
36 | - |
|
37 | - |
|
38 | - /** |
|
39 | - * @return EE_Messenger_Collection |
|
40 | - */ |
|
41 | - public function messenger_collection() |
|
42 | - { |
|
43 | - return $this->_messenger_collection; |
|
44 | - } |
|
45 | - |
|
46 | - |
|
47 | - |
|
48 | - /** |
|
49 | - * @param mixed $messengers |
|
50 | - */ |
|
51 | - public function set_messenger_collection(EE_Messenger_Collection $messengers) |
|
52 | - { |
|
53 | - $this->_messenger_collection = $messengers; |
|
54 | - } |
|
55 | - |
|
56 | - |
|
57 | - |
|
58 | - /** |
|
59 | - * load_messengers |
|
60 | - * globs the supplied filepath and adds any found |
|
61 | - * |
|
62 | - * @param string $folder |
|
63 | - * @throws \EE_Error |
|
64 | - */ |
|
65 | - public function load_messengers_from_folder($folder = '') |
|
66 | - { |
|
67 | - // make sure autoloaders are set (fail-safe) |
|
68 | - EED_Messages::set_autoloaders(); |
|
69 | - $folder = ! empty($folder) ? $folder : EE_LIBRARIES . 'messages/messenger'; |
|
70 | - $folder .= $folder[ strlen($folder) - 1 ] != '/' ? '/' : ''; |
|
71 | - // get all the files in that folder that end in ".class.php |
|
72 | - $filepaths = apply_filters( |
|
73 | - 'FHEE__EE_messages__get_installed__messenger_files', |
|
74 | - glob($folder . '*.class.php') |
|
75 | - ); |
|
76 | - if (empty($filepaths)) { |
|
77 | - return; |
|
78 | - } |
|
79 | - foreach ((array) $filepaths as $file_path) { |
|
80 | - // extract filename from path |
|
81 | - $file_path = basename($file_path); |
|
82 | - // now remove any file extensions |
|
83 | - $messenger_class_name = substr($file_path, 0, strpos($file_path, '.')); |
|
84 | - |
|
85 | - // first check to see if the class name represents an actual messenger class. |
|
86 | - if (strpos(strtolower($messenger_class_name), 'messenger') === false) { |
|
87 | - continue; |
|
88 | - } |
|
89 | - |
|
90 | - if (! class_exists($messenger_class_name)) { |
|
91 | - throw new EE_Error( |
|
92 | - sprintf( |
|
93 | - __('The "%1$s" messenger class can\'t be loaded from %2$s. Likely there is a typo in the class name or the file name.', 'event_espresso'), |
|
94 | - $messenger_class_name, |
|
95 | - $file_path |
|
96 | - ) |
|
97 | - ); |
|
98 | - } |
|
99 | - |
|
100 | - $this->_load_messenger(new $messenger_class_name()); |
|
101 | - } |
|
102 | - } |
|
103 | - |
|
104 | - |
|
105 | - /** |
|
106 | - * load_messengers |
|
107 | - * globs the supplied filepath and adds any found |
|
108 | - * |
|
109 | - * @return array |
|
110 | - */ |
|
111 | - public function load_active_messengers_from_db() |
|
112 | - { |
|
113 | - // make sure autoloaders are set (fail-safe) |
|
114 | - EED_Messages::set_autoloaders(); |
|
115 | - $active_messengers = apply_filters( |
|
116 | - 'FHEE__EEH_MSG_Template__get_active_messengers_in_db', |
|
117 | - get_option('ee_active_messengers', array()) |
|
118 | - ); |
|
119 | - foreach ((array) $active_messengers as $active_messenger_classname => $active_messenger) { |
|
120 | - $this->_load_messenger($active_messenger); |
|
121 | - } |
|
122 | - } |
|
123 | - |
|
124 | - |
|
125 | - |
|
126 | - /** |
|
127 | - * load_messenger |
|
128 | - * |
|
129 | - * @param \EE_messenger $messenger |
|
130 | - * @return bool |
|
131 | - */ |
|
132 | - protected function _load_messenger(EE_messenger $messenger) |
|
133 | - { |
|
134 | - if ($this->messenger_collection()->has_by_name($messenger->name)) { |
|
135 | - return true; |
|
136 | - } |
|
137 | - return $this->messenger_collection()->add( |
|
138 | - $messenger, |
|
139 | - $messenger->name |
|
140 | - ); |
|
141 | - } |
|
19 | + /** |
|
20 | + * @type EE_Messenger_Collection $_messenger_collection |
|
21 | + */ |
|
22 | + protected $_messenger_collection = null; |
|
23 | + |
|
24 | + |
|
25 | + |
|
26 | + /** |
|
27 | + * EE_Messenger_Collection_Loader constructor. |
|
28 | + * |
|
29 | + * @param EE_Messenger_Collection $messengers |
|
30 | + */ |
|
31 | + public function __construct(EE_Messenger_Collection $messengers) |
|
32 | + { |
|
33 | + $this->set_messenger_collection($messengers); |
|
34 | + } |
|
35 | + |
|
36 | + |
|
37 | + |
|
38 | + /** |
|
39 | + * @return EE_Messenger_Collection |
|
40 | + */ |
|
41 | + public function messenger_collection() |
|
42 | + { |
|
43 | + return $this->_messenger_collection; |
|
44 | + } |
|
45 | + |
|
46 | + |
|
47 | + |
|
48 | + /** |
|
49 | + * @param mixed $messengers |
|
50 | + */ |
|
51 | + public function set_messenger_collection(EE_Messenger_Collection $messengers) |
|
52 | + { |
|
53 | + $this->_messenger_collection = $messengers; |
|
54 | + } |
|
55 | + |
|
56 | + |
|
57 | + |
|
58 | + /** |
|
59 | + * load_messengers |
|
60 | + * globs the supplied filepath and adds any found |
|
61 | + * |
|
62 | + * @param string $folder |
|
63 | + * @throws \EE_Error |
|
64 | + */ |
|
65 | + public function load_messengers_from_folder($folder = '') |
|
66 | + { |
|
67 | + // make sure autoloaders are set (fail-safe) |
|
68 | + EED_Messages::set_autoloaders(); |
|
69 | + $folder = ! empty($folder) ? $folder : EE_LIBRARIES . 'messages/messenger'; |
|
70 | + $folder .= $folder[ strlen($folder) - 1 ] != '/' ? '/' : ''; |
|
71 | + // get all the files in that folder that end in ".class.php |
|
72 | + $filepaths = apply_filters( |
|
73 | + 'FHEE__EE_messages__get_installed__messenger_files', |
|
74 | + glob($folder . '*.class.php') |
|
75 | + ); |
|
76 | + if (empty($filepaths)) { |
|
77 | + return; |
|
78 | + } |
|
79 | + foreach ((array) $filepaths as $file_path) { |
|
80 | + // extract filename from path |
|
81 | + $file_path = basename($file_path); |
|
82 | + // now remove any file extensions |
|
83 | + $messenger_class_name = substr($file_path, 0, strpos($file_path, '.')); |
|
84 | + |
|
85 | + // first check to see if the class name represents an actual messenger class. |
|
86 | + if (strpos(strtolower($messenger_class_name), 'messenger') === false) { |
|
87 | + continue; |
|
88 | + } |
|
89 | + |
|
90 | + if (! class_exists($messenger_class_name)) { |
|
91 | + throw new EE_Error( |
|
92 | + sprintf( |
|
93 | + __('The "%1$s" messenger class can\'t be loaded from %2$s. Likely there is a typo in the class name or the file name.', 'event_espresso'), |
|
94 | + $messenger_class_name, |
|
95 | + $file_path |
|
96 | + ) |
|
97 | + ); |
|
98 | + } |
|
99 | + |
|
100 | + $this->_load_messenger(new $messenger_class_name()); |
|
101 | + } |
|
102 | + } |
|
103 | + |
|
104 | + |
|
105 | + /** |
|
106 | + * load_messengers |
|
107 | + * globs the supplied filepath and adds any found |
|
108 | + * |
|
109 | + * @return array |
|
110 | + */ |
|
111 | + public function load_active_messengers_from_db() |
|
112 | + { |
|
113 | + // make sure autoloaders are set (fail-safe) |
|
114 | + EED_Messages::set_autoloaders(); |
|
115 | + $active_messengers = apply_filters( |
|
116 | + 'FHEE__EEH_MSG_Template__get_active_messengers_in_db', |
|
117 | + get_option('ee_active_messengers', array()) |
|
118 | + ); |
|
119 | + foreach ((array) $active_messengers as $active_messenger_classname => $active_messenger) { |
|
120 | + $this->_load_messenger($active_messenger); |
|
121 | + } |
|
122 | + } |
|
123 | + |
|
124 | + |
|
125 | + |
|
126 | + /** |
|
127 | + * load_messenger |
|
128 | + * |
|
129 | + * @param \EE_messenger $messenger |
|
130 | + * @return bool |
|
131 | + */ |
|
132 | + protected function _load_messenger(EE_messenger $messenger) |
|
133 | + { |
|
134 | + if ($this->messenger_collection()->has_by_name($messenger->name)) { |
|
135 | + return true; |
|
136 | + } |
|
137 | + return $this->messenger_collection()->add( |
|
138 | + $messenger, |
|
139 | + $messenger->name |
|
140 | + ); |
|
141 | + } |
|
142 | 142 | } |
@@ -66,12 +66,12 @@ discard block |
||
66 | 66 | { |
67 | 67 | // make sure autoloaders are set (fail-safe) |
68 | 68 | EED_Messages::set_autoloaders(); |
69 | - $folder = ! empty($folder) ? $folder : EE_LIBRARIES . 'messages/messenger'; |
|
70 | - $folder .= $folder[ strlen($folder) - 1 ] != '/' ? '/' : ''; |
|
69 | + $folder = ! empty($folder) ? $folder : EE_LIBRARIES.'messages/messenger'; |
|
70 | + $folder .= $folder[strlen($folder) - 1] != '/' ? '/' : ''; |
|
71 | 71 | // get all the files in that folder that end in ".class.php |
72 | 72 | $filepaths = apply_filters( |
73 | 73 | 'FHEE__EE_messages__get_installed__messenger_files', |
74 | - glob($folder . '*.class.php') |
|
74 | + glob($folder.'*.class.php') |
|
75 | 75 | ); |
76 | 76 | if (empty($filepaths)) { |
77 | 77 | return; |
@@ -87,7 +87,7 @@ discard block |
||
87 | 87 | continue; |
88 | 88 | } |
89 | 89 | |
90 | - if (! class_exists($messenger_class_name)) { |
|
90 | + if ( ! class_exists($messenger_class_name)) { |
|
91 | 91 | throw new EE_Error( |
92 | 92 | sprintf( |
93 | 93 | __('The "%1$s" messenger class can\'t be loaded from %2$s. Likely there is a typo in the class name or the file name.', 'event_espresso'), |
@@ -65,12 +65,12 @@ discard block |
||
65 | 65 | { |
66 | 66 | // make sure autoloaders are set (fail-safe) |
67 | 67 | EED_Messages::set_autoloaders(); |
68 | - $folder = ! empty($folder) ? $folder : EE_LIBRARIES . 'messages/message_type'; |
|
69 | - $folder .= $folder[ strlen($folder) - 1 ] != '/' ? '/' : ''; |
|
68 | + $folder = ! empty($folder) ? $folder : EE_LIBRARIES.'messages/message_type'; |
|
69 | + $folder .= $folder[strlen($folder) - 1] != '/' ? '/' : ''; |
|
70 | 70 | // get all the files in that folder that end in ".class.php |
71 | 71 | $filepaths = apply_filters( |
72 | 72 | 'FHEE__EE_messages__get_installed__messagetype_files', |
73 | - glob($folder . '*.class.php') |
|
73 | + glob($folder.'*.class.php') |
|
74 | 74 | ); |
75 | 75 | if (empty($filepaths)) { |
76 | 76 | return; |
@@ -86,7 +86,7 @@ discard block |
||
86 | 86 | continue; |
87 | 87 | } |
88 | 88 | |
89 | - if (! class_exists($message_type_class_name)) { |
|
89 | + if ( ! class_exists($message_type_class_name)) { |
|
90 | 90 | throw new EE_Error( |
91 | 91 | sprintf( |
92 | 92 | __('The "%1$s" message type class can\'t be loaded from %2$s. Likely there is a typo in the class name or the file name.', 'event_espresso'), |
@@ -15,105 +15,105 @@ |
||
15 | 15 | { |
16 | 16 | |
17 | 17 | |
18 | - /** |
|
19 | - * @type EE_Message_Type_Collection $_message_type_collection |
|
20 | - */ |
|
21 | - protected $_message_type_collection = null; |
|
22 | - |
|
23 | - |
|
24 | - |
|
25 | - /** |
|
26 | - * EE_Message_Type_Collection_Loader constructor. |
|
27 | - * |
|
28 | - * @param EE_Message_Type_Collection $message_types |
|
29 | - */ |
|
30 | - public function __construct(EE_Message_Type_Collection $message_types) |
|
31 | - { |
|
32 | - $this->set_message_type_collection($message_types); |
|
33 | - } |
|
34 | - |
|
35 | - |
|
36 | - |
|
37 | - /** |
|
38 | - * @return EE_Message_Type_Collection |
|
39 | - */ |
|
40 | - public function message_type_collection() |
|
41 | - { |
|
42 | - return $this->_message_type_collection; |
|
43 | - } |
|
44 | - |
|
45 | - |
|
46 | - |
|
47 | - /** |
|
48 | - * @param mixed $message_types |
|
49 | - */ |
|
50 | - public function set_message_type_collection(EE_Message_Type_Collection $message_types) |
|
51 | - { |
|
52 | - $this->_message_type_collection = $message_types; |
|
53 | - } |
|
54 | - |
|
55 | - |
|
56 | - |
|
57 | - /** |
|
58 | - * load_message_types |
|
59 | - * globs the supplied filepath and adds any found |
|
60 | - * |
|
61 | - * @param string $folder |
|
62 | - * @throws \EE_Error |
|
63 | - */ |
|
64 | - public function load_message_types_from_folder($folder = '') |
|
65 | - { |
|
66 | - // make sure autoloaders are set (fail-safe) |
|
67 | - EED_Messages::set_autoloaders(); |
|
68 | - $folder = ! empty($folder) ? $folder : EE_LIBRARIES . 'messages/message_type'; |
|
69 | - $folder .= $folder[ strlen($folder) - 1 ] != '/' ? '/' : ''; |
|
70 | - // get all the files in that folder that end in ".class.php |
|
71 | - $filepaths = apply_filters( |
|
72 | - 'FHEE__EE_messages__get_installed__messagetype_files', |
|
73 | - glob($folder . '*.class.php') |
|
74 | - ); |
|
75 | - if (empty($filepaths)) { |
|
76 | - return; |
|
77 | - } |
|
78 | - foreach ((array) $filepaths as $file_path) { |
|
79 | - // extract filename from path |
|
80 | - $file_path = basename($file_path); |
|
81 | - // now remove any file extensions |
|
82 | - $message_type_class_name = substr($file_path, 0, strpos($file_path, '.')); |
|
83 | - |
|
84 | - // if this class name doesn't represent a message type class, then we just skip. |
|
85 | - if (strpos(strtolower($message_type_class_name), 'message_type') === false) { |
|
86 | - continue; |
|
87 | - } |
|
88 | - |
|
89 | - if (! class_exists($message_type_class_name)) { |
|
90 | - throw new EE_Error( |
|
91 | - sprintf( |
|
92 | - __('The "%1$s" message type class can\'t be loaded from %2$s. Likely there is a typo in the class name or the file name.', 'event_espresso'), |
|
93 | - $message_type_class_name, |
|
94 | - $file_path |
|
95 | - ) |
|
96 | - ); |
|
97 | - } |
|
98 | - |
|
99 | - $this->_load_message_type(new $message_type_class_name()); |
|
100 | - } |
|
101 | - } |
|
102 | - |
|
103 | - |
|
104 | - /** |
|
105 | - * Loads the given message type into the message type collection if it doesn't already exist. |
|
106 | - * @param EE_message_type $message_type |
|
107 | - * @return bool |
|
108 | - */ |
|
109 | - protected function _load_message_type(EE_message_type $message_type) |
|
110 | - { |
|
111 | - if ($this->message_type_collection()->has_by_name($message_type->name)) { |
|
112 | - return true; |
|
113 | - } |
|
114 | - return $this->message_type_collection()->add( |
|
115 | - $message_type, |
|
116 | - $message_type->name |
|
117 | - ); |
|
118 | - } |
|
18 | + /** |
|
19 | + * @type EE_Message_Type_Collection $_message_type_collection |
|
20 | + */ |
|
21 | + protected $_message_type_collection = null; |
|
22 | + |
|
23 | + |
|
24 | + |
|
25 | + /** |
|
26 | + * EE_Message_Type_Collection_Loader constructor. |
|
27 | + * |
|
28 | + * @param EE_Message_Type_Collection $message_types |
|
29 | + */ |
|
30 | + public function __construct(EE_Message_Type_Collection $message_types) |
|
31 | + { |
|
32 | + $this->set_message_type_collection($message_types); |
|
33 | + } |
|
34 | + |
|
35 | + |
|
36 | + |
|
37 | + /** |
|
38 | + * @return EE_Message_Type_Collection |
|
39 | + */ |
|
40 | + public function message_type_collection() |
|
41 | + { |
|
42 | + return $this->_message_type_collection; |
|
43 | + } |
|
44 | + |
|
45 | + |
|
46 | + |
|
47 | + /** |
|
48 | + * @param mixed $message_types |
|
49 | + */ |
|
50 | + public function set_message_type_collection(EE_Message_Type_Collection $message_types) |
|
51 | + { |
|
52 | + $this->_message_type_collection = $message_types; |
|
53 | + } |
|
54 | + |
|
55 | + |
|
56 | + |
|
57 | + /** |
|
58 | + * load_message_types |
|
59 | + * globs the supplied filepath and adds any found |
|
60 | + * |
|
61 | + * @param string $folder |
|
62 | + * @throws \EE_Error |
|
63 | + */ |
|
64 | + public function load_message_types_from_folder($folder = '') |
|
65 | + { |
|
66 | + // make sure autoloaders are set (fail-safe) |
|
67 | + EED_Messages::set_autoloaders(); |
|
68 | + $folder = ! empty($folder) ? $folder : EE_LIBRARIES . 'messages/message_type'; |
|
69 | + $folder .= $folder[ strlen($folder) - 1 ] != '/' ? '/' : ''; |
|
70 | + // get all the files in that folder that end in ".class.php |
|
71 | + $filepaths = apply_filters( |
|
72 | + 'FHEE__EE_messages__get_installed__messagetype_files', |
|
73 | + glob($folder . '*.class.php') |
|
74 | + ); |
|
75 | + if (empty($filepaths)) { |
|
76 | + return; |
|
77 | + } |
|
78 | + foreach ((array) $filepaths as $file_path) { |
|
79 | + // extract filename from path |
|
80 | + $file_path = basename($file_path); |
|
81 | + // now remove any file extensions |
|
82 | + $message_type_class_name = substr($file_path, 0, strpos($file_path, '.')); |
|
83 | + |
|
84 | + // if this class name doesn't represent a message type class, then we just skip. |
|
85 | + if (strpos(strtolower($message_type_class_name), 'message_type') === false) { |
|
86 | + continue; |
|
87 | + } |
|
88 | + |
|
89 | + if (! class_exists($message_type_class_name)) { |
|
90 | + throw new EE_Error( |
|
91 | + sprintf( |
|
92 | + __('The "%1$s" message type class can\'t be loaded from %2$s. Likely there is a typo in the class name or the file name.', 'event_espresso'), |
|
93 | + $message_type_class_name, |
|
94 | + $file_path |
|
95 | + ) |
|
96 | + ); |
|
97 | + } |
|
98 | + |
|
99 | + $this->_load_message_type(new $message_type_class_name()); |
|
100 | + } |
|
101 | + } |
|
102 | + |
|
103 | + |
|
104 | + /** |
|
105 | + * Loads the given message type into the message type collection if it doesn't already exist. |
|
106 | + * @param EE_message_type $message_type |
|
107 | + * @return bool |
|
108 | + */ |
|
109 | + protected function _load_message_type(EE_message_type $message_type) |
|
110 | + { |
|
111 | + if ($this->message_type_collection()->has_by_name($message_type->name)) { |
|
112 | + return true; |
|
113 | + } |
|
114 | + return $this->message_type_collection()->add( |
|
115 | + $message_type, |
|
116 | + $message_type->name |
|
117 | + ); |
|
118 | + } |
|
119 | 119 | } |
@@ -83,7 +83,7 @@ discard block |
||
83 | 83 | public function __construct($title, $content) |
84 | 84 | { |
85 | 85 | global $wp_version; |
86 | - if (! defined('EE_IFRAME_DIR_URL')) { |
|
86 | + if ( ! defined('EE_IFRAME_DIR_URL')) { |
|
87 | 87 | define('EE_IFRAME_DIR_URL', plugin_dir_url(__FILE__)); |
88 | 88 | } |
89 | 89 | $this->setContent($content); |
@@ -93,10 +93,10 @@ discard block |
||
93 | 93 | 'FHEE___EventEspresso_core_libraries_iframe_display_Iframe__construct__default_css', |
94 | 94 | array( |
95 | 95 | 'site_theme' => get_stylesheet_directory_uri() |
96 | - . '/style.css?ver=' . EVENT_ESPRESSO_VERSION, |
|
97 | - 'dashicons' => includes_url('css/dashicons.min.css?ver=' . $wp_version), |
|
96 | + . '/style.css?ver='.EVENT_ESPRESSO_VERSION, |
|
97 | + 'dashicons' => includes_url('css/dashicons.min.css?ver='.$wp_version), |
|
98 | 98 | 'espresso_default' => EE_GLOBAL_ASSETS_URL |
99 | - . 'css/espresso_default.css?ver=' . EVENT_ESPRESSO_VERSION, |
|
99 | + . 'css/espresso_default.css?ver='.EVENT_ESPRESSO_VERSION, |
|
100 | 100 | ), |
101 | 101 | $this |
102 | 102 | ) |
@@ -105,9 +105,9 @@ discard block |
||
105 | 105 | apply_filters( |
106 | 106 | 'FHEE___EventEspresso_core_libraries_iframe_display_Iframe__construct__default_js', |
107 | 107 | array( |
108 | - 'jquery' => includes_url('js/jquery/jquery.js?ver=' . $wp_version), |
|
108 | + 'jquery' => includes_url('js/jquery/jquery.js?ver='.$wp_version), |
|
109 | 109 | 'espresso_core' => EE_GLOBAL_ASSETS_URL |
110 | - . 'scripts/espresso_core.js?ver=' . EVENT_ESPRESSO_VERSION, |
|
110 | + . 'scripts/espresso_core.js?ver='.EVENT_ESPRESSO_VERSION, |
|
111 | 111 | ), |
112 | 112 | $this |
113 | 113 | ) |
@@ -181,7 +181,7 @@ discard block |
||
181 | 181 | ); |
182 | 182 | } |
183 | 183 | foreach ($stylesheets as $handle => $stylesheet) { |
184 | - $this->css[ $handle ] = $stylesheet; |
|
184 | + $this->css[$handle] = $stylesheet; |
|
185 | 185 | } |
186 | 186 | } |
187 | 187 | |
@@ -203,9 +203,9 @@ discard block |
||
203 | 203 | } |
204 | 204 | foreach ($scripts as $handle => $script) { |
205 | 205 | if ($add_to_header) { |
206 | - $this->header_js[ $handle ] = $script; |
|
206 | + $this->header_js[$handle] = $script; |
|
207 | 207 | } else { |
208 | - $this->footer_js[ $handle ] = $script; |
|
208 | + $this->footer_js[$handle] = $script; |
|
209 | 209 | } |
210 | 210 | } |
211 | 211 | } |
@@ -228,9 +228,9 @@ discard block |
||
228 | 228 | } |
229 | 229 | foreach ($script_attributes as $handle => $script_attribute) { |
230 | 230 | if ($add_to_header) { |
231 | - $this->header_js_attributes[ $handle ] = $script_attribute; |
|
231 | + $this->header_js_attributes[$handle] = $script_attribute; |
|
232 | 232 | } else { |
233 | - $this->footer_js_attributes[ $handle ] = $script_attribute; |
|
233 | + $this->footer_js_attributes[$handle] = $script_attribute; |
|
234 | 234 | } |
235 | 235 | } |
236 | 236 | } |
@@ -253,14 +253,14 @@ discard block |
||
253 | 253 | } |
254 | 254 | foreach ($vars as $handle => $var) { |
255 | 255 | if ($var_name === 'eei18n') { |
256 | - EE_Registry::$i18n_js_strings[ $handle ] = $var; |
|
256 | + EE_Registry::$i18n_js_strings[$handle] = $var; |
|
257 | 257 | } elseif ($var_name === 'eeCAL' && $handle === 'espresso_calendar') { |
258 | - $this->localized_vars[ $var_name ] = $var; |
|
258 | + $this->localized_vars[$var_name] = $var; |
|
259 | 259 | } else { |
260 | - if (! isset($this->localized_vars[ $var_name ])) { |
|
261 | - $this->localized_vars[ $var_name ] = array(); |
|
260 | + if ( ! isset($this->localized_vars[$var_name])) { |
|
261 | + $this->localized_vars[$var_name] = array(); |
|
262 | 262 | } |
263 | - $this->localized_vars[ $var_name ][ $handle ] = $var; |
|
263 | + $this->localized_vars[$var_name][$handle] = $var; |
|
264 | 264 | } |
265 | 265 | } |
266 | 266 | } |
@@ -290,7 +290,7 @@ discard block |
||
290 | 290 | public function getTemplate() |
291 | 291 | { |
292 | 292 | return EEH_Template::display_template( |
293 | - __DIR__ . DIRECTORY_SEPARATOR . 'iframe_wrapper.template.php', |
|
293 | + __DIR__.DIRECTORY_SEPARATOR.'iframe_wrapper.template.php', |
|
294 | 294 | array( |
295 | 295 | 'title' => apply_filters( |
296 | 296 | 'FHEE___EventEspresso_core_libraries_iframe_display_Iframe__getTemplate__title', |
@@ -334,11 +334,11 @@ discard block |
||
334 | 334 | ), |
335 | 335 | 'eei18n' => apply_filters( |
336 | 336 | 'FHEE___EventEspresso_core_libraries_iframe_display_Iframe__getTemplate__eei18n_js_strings', |
337 | - EE_Registry::localize_i18n_js_strings() . $this->localizeJsonVars(), |
|
337 | + EE_Registry::localize_i18n_js_strings().$this->localizeJsonVars(), |
|
338 | 338 | $this |
339 | 339 | ), |
340 | 340 | 'notices' => EEH_Template::display_template( |
341 | - EE_TEMPLATES . 'espresso-ajax-notices.template.php', |
|
341 | + EE_TEMPLATES.'espresso-ajax-notices.template.php', |
|
342 | 342 | array(), |
343 | 343 | true |
344 | 344 | ), |
@@ -358,9 +358,9 @@ discard block |
||
358 | 358 | { |
359 | 359 | $JSON = ''; |
360 | 360 | foreach ((array) $this->localized_vars as $var_name => $vars) { |
361 | - $this->localized_vars[ $var_name ] = $this->encodeJsonVars($vars); |
|
361 | + $this->localized_vars[$var_name] = $this->encodeJsonVars($vars); |
|
362 | 362 | $JSON .= "/* <![CDATA[ */ var {$var_name} = "; |
363 | - $JSON .= wp_json_encode($this->localized_vars[ $var_name ]); |
|
363 | + $JSON .= wp_json_encode($this->localized_vars[$var_name]); |
|
364 | 364 | $JSON .= '; /* ]]> */'; |
365 | 365 | } |
366 | 366 | return $JSON; |
@@ -376,7 +376,7 @@ discard block |
||
376 | 376 | if (is_array($var)) { |
377 | 377 | $localized_vars = array(); |
378 | 378 | foreach ((array) $var as $key => $value) { |
379 | - $localized_vars[ $key ] = $this->encodeJsonVars($value); |
|
379 | + $localized_vars[$key] = $this->encodeJsonVars($value); |
|
380 | 380 | } |
381 | 381 | return $localized_vars; |
382 | 382 | } |
@@ -18,373 +18,373 @@ |
||
18 | 18 | class Iframe |
19 | 19 | { |
20 | 20 | |
21 | - /* |
|
21 | + /* |
|
22 | 22 | * HTML for notices and ajax gif |
23 | 23 | * @var string $title |
24 | 24 | */ |
25 | - protected $title = ''; |
|
25 | + protected $title = ''; |
|
26 | 26 | |
27 | - /* |
|
27 | + /* |
|
28 | 28 | * HTML for the content being displayed |
29 | 29 | * @var string $content |
30 | 30 | */ |
31 | - protected $content = ''; |
|
31 | + protected $content = ''; |
|
32 | 32 | |
33 | - /* |
|
33 | + /* |
|
34 | 34 | * whether or not to call wp_head() and wp_footer() |
35 | 35 | * @var boolean $enqueue_wp_assets |
36 | 36 | */ |
37 | - protected $enqueue_wp_assets = false; |
|
37 | + protected $enqueue_wp_assets = false; |
|
38 | 38 | |
39 | - /* |
|
39 | + /* |
|
40 | 40 | * an array of CSS URLs |
41 | 41 | * @var array $css |
42 | 42 | */ |
43 | - protected $css = array(); |
|
43 | + protected $css = array(); |
|
44 | 44 | |
45 | - /* |
|
45 | + /* |
|
46 | 46 | * an array of JS URLs to be set in the HTML header. |
47 | 47 | * @var array $header_js |
48 | 48 | */ |
49 | - protected $header_js = array(); |
|
49 | + protected $header_js = array(); |
|
50 | 50 | |
51 | - /* |
|
51 | + /* |
|
52 | 52 | * an array of additional attributes to be added to <script> tags for header JS |
53 | 53 | * @var array $footer_js |
54 | 54 | */ |
55 | - protected $header_js_attributes = array(); |
|
55 | + protected $header_js_attributes = array(); |
|
56 | 56 | |
57 | - /* |
|
57 | + /* |
|
58 | 58 | * an array of JS URLs to be displayed before the HTML </body> tag |
59 | 59 | * @var array $footer_js |
60 | 60 | */ |
61 | - protected $footer_js = array(); |
|
61 | + protected $footer_js = array(); |
|
62 | 62 | |
63 | - /* |
|
63 | + /* |
|
64 | 64 | * an array of additional attributes to be added to <script> tags for footer JS |
65 | 65 | * @var array $footer_js_attributes |
66 | 66 | */ |
67 | - protected $footer_js_attributes = array(); |
|
67 | + protected $footer_js_attributes = array(); |
|
68 | 68 | |
69 | - /* |
|
69 | + /* |
|
70 | 70 | * an array of JSON vars to be set in the HTML header. |
71 | 71 | * @var array $localized_vars |
72 | 72 | */ |
73 | - protected $localized_vars = array(); |
|
74 | - |
|
75 | - |
|
76 | - /** |
|
77 | - * Iframe constructor |
|
78 | - * |
|
79 | - * @param string $title |
|
80 | - * @param string $content |
|
81 | - * @throws DomainException |
|
82 | - */ |
|
83 | - public function __construct($title, $content) |
|
84 | - { |
|
85 | - global $wp_version; |
|
86 | - if (! defined('EE_IFRAME_DIR_URL')) { |
|
87 | - define('EE_IFRAME_DIR_URL', plugin_dir_url(__FILE__)); |
|
88 | - } |
|
89 | - $this->setContent($content); |
|
90 | - $this->setTitle($title); |
|
91 | - $this->addStylesheets( |
|
92 | - apply_filters( |
|
93 | - 'FHEE___EventEspresso_core_libraries_iframe_display_Iframe__construct__default_css', |
|
94 | - array( |
|
95 | - 'site_theme' => get_stylesheet_directory_uri() |
|
96 | - . '/style.css?ver=' . EVENT_ESPRESSO_VERSION, |
|
97 | - 'dashicons' => includes_url('css/dashicons.min.css?ver=' . $wp_version), |
|
98 | - 'espresso_default' => EE_GLOBAL_ASSETS_URL |
|
99 | - . 'css/espresso_default.css?ver=' . EVENT_ESPRESSO_VERSION, |
|
100 | - ), |
|
101 | - $this |
|
102 | - ) |
|
103 | - ); |
|
104 | - $this->addScripts( |
|
105 | - apply_filters( |
|
106 | - 'FHEE___EventEspresso_core_libraries_iframe_display_Iframe__construct__default_js', |
|
107 | - array( |
|
108 | - 'jquery' => includes_url('js/jquery/jquery.js?ver=' . $wp_version), |
|
109 | - 'espresso_core' => EE_GLOBAL_ASSETS_URL |
|
110 | - . 'scripts/espresso_core.js?ver=' . EVENT_ESPRESSO_VERSION, |
|
111 | - ), |
|
112 | - $this |
|
113 | - ) |
|
114 | - ); |
|
115 | - if ( |
|
116 | - apply_filters( |
|
117 | - 'FHEE___EventEspresso_core_libraries_iframe_display_Iframe__construct__load_default_theme_stylesheet', |
|
118 | - false |
|
119 | - ) |
|
120 | - ) { |
|
121 | - $this->addStylesheets( |
|
122 | - apply_filters( |
|
123 | - 'FHEE___EventEspresso_core_libraries_iframe_display_Iframe__construct__default_theme_stylesheet', |
|
124 | - array('default_theme_stylesheet' => get_stylesheet_uri()), |
|
125 | - $this |
|
126 | - ) |
|
127 | - ); |
|
128 | - } |
|
129 | - } |
|
130 | - |
|
131 | - |
|
132 | - /** |
|
133 | - * @param string $title |
|
134 | - * @throws DomainException |
|
135 | - */ |
|
136 | - public function setTitle($title) |
|
137 | - { |
|
138 | - if (empty($title)) { |
|
139 | - throw new DomainException( |
|
140 | - esc_html__('You must provide a page title in order to create an iframe.', 'event_espresso') |
|
141 | - ); |
|
142 | - } |
|
143 | - $this->title = $title; |
|
144 | - } |
|
145 | - |
|
146 | - |
|
147 | - /** |
|
148 | - * @param string $content |
|
149 | - * @throws DomainException |
|
150 | - */ |
|
151 | - public function setContent($content) |
|
152 | - { |
|
153 | - if (empty($content)) { |
|
154 | - throw new DomainException( |
|
155 | - esc_html__('You must provide content in order to create an iframe.', 'event_espresso') |
|
156 | - ); |
|
157 | - } |
|
158 | - $this->content = $content; |
|
159 | - } |
|
160 | - |
|
161 | - |
|
162 | - /** |
|
163 | - * @param boolean $enqueue_wp_assets |
|
164 | - */ |
|
165 | - public function setEnqueueWpAssets($enqueue_wp_assets) |
|
166 | - { |
|
167 | - $this->enqueue_wp_assets = filter_var($enqueue_wp_assets, FILTER_VALIDATE_BOOLEAN); |
|
168 | - } |
|
169 | - |
|
170 | - |
|
171 | - /** |
|
172 | - * @param array $stylesheets |
|
173 | - * @throws DomainException |
|
174 | - */ |
|
175 | - public function addStylesheets(array $stylesheets) |
|
176 | - { |
|
177 | - if (empty($stylesheets)) { |
|
178 | - throw new DomainException( |
|
179 | - esc_html__( |
|
180 | - 'A non-empty array of URLs, is required to add a CSS stylesheet to an iframe.', |
|
181 | - 'event_espresso' |
|
182 | - ) |
|
183 | - ); |
|
184 | - } |
|
185 | - foreach ($stylesheets as $handle => $stylesheet) { |
|
186 | - $this->css[ $handle ] = $stylesheet; |
|
187 | - } |
|
188 | - } |
|
189 | - |
|
190 | - |
|
191 | - /** |
|
192 | - * @param array $scripts |
|
193 | - * @param bool $add_to_header |
|
194 | - * @throws DomainException |
|
195 | - */ |
|
196 | - public function addScripts(array $scripts, $add_to_header = false) |
|
197 | - { |
|
198 | - if (empty($scripts)) { |
|
199 | - throw new DomainException( |
|
200 | - esc_html__( |
|
201 | - 'A non-empty array of URLs, is required to add Javascript to an iframe.', |
|
202 | - 'event_espresso' |
|
203 | - ) |
|
204 | - ); |
|
205 | - } |
|
206 | - foreach ($scripts as $handle => $script) { |
|
207 | - if ($add_to_header) { |
|
208 | - $this->header_js[ $handle ] = $script; |
|
209 | - } else { |
|
210 | - $this->footer_js[ $handle ] = $script; |
|
211 | - } |
|
212 | - } |
|
213 | - } |
|
214 | - |
|
215 | - |
|
216 | - /** |
|
217 | - * @param array $script_attributes |
|
218 | - * @param bool $add_to_header |
|
219 | - * @throws DomainException |
|
220 | - */ |
|
221 | - public function addScriptAttributes(array $script_attributes, $add_to_header = false) |
|
222 | - { |
|
223 | - if (empty($script_attributes)) { |
|
224 | - throw new DomainException( |
|
225 | - esc_html__( |
|
226 | - 'A non-empty array of strings, is required to add attributes to iframe Javascript.', |
|
227 | - 'event_espresso' |
|
228 | - ) |
|
229 | - ); |
|
230 | - } |
|
231 | - foreach ($script_attributes as $handle => $script_attribute) { |
|
232 | - if ($add_to_header) { |
|
233 | - $this->header_js_attributes[ $handle ] = $script_attribute; |
|
234 | - } else { |
|
235 | - $this->footer_js_attributes[ $handle ] = $script_attribute; |
|
236 | - } |
|
237 | - } |
|
238 | - } |
|
239 | - |
|
240 | - |
|
241 | - /** |
|
242 | - * @param array $vars |
|
243 | - * @param string $var_name |
|
244 | - * @throws DomainException |
|
245 | - */ |
|
246 | - public function addLocalizedVars(array $vars, $var_name = 'eei18n') |
|
247 | - { |
|
248 | - if (empty($vars)) { |
|
249 | - throw new DomainException( |
|
250 | - esc_html__( |
|
251 | - 'A non-empty array of vars, is required to add localized Javascript vars to an iframe.', |
|
252 | - 'event_espresso' |
|
253 | - ) |
|
254 | - ); |
|
255 | - } |
|
256 | - foreach ($vars as $handle => $var) { |
|
257 | - if ($var_name === 'eei18n') { |
|
258 | - EE_Registry::$i18n_js_strings[ $handle ] = $var; |
|
259 | - } elseif ($var_name === 'eeCAL' && $handle === 'espresso_calendar') { |
|
260 | - $this->localized_vars[ $var_name ] = $var; |
|
261 | - } else { |
|
262 | - if (! isset($this->localized_vars[ $var_name ])) { |
|
263 | - $this->localized_vars[ $var_name ] = array(); |
|
264 | - } |
|
265 | - $this->localized_vars[ $var_name ][ $handle ] = $var; |
|
266 | - } |
|
267 | - } |
|
268 | - } |
|
269 | - |
|
270 | - |
|
271 | - /** |
|
272 | - * @param string $utm_content |
|
273 | - * @throws DomainException |
|
274 | - */ |
|
275 | - public function display($utm_content = '') |
|
276 | - { |
|
277 | - $this->content .= EEH_Template::powered_by_event_espresso( |
|
278 | - '', |
|
279 | - '', |
|
280 | - ! empty($utm_content) ? array('utm_content' => $utm_content) : array() |
|
281 | - ); |
|
282 | - EE_System::do_not_cache(); |
|
283 | - echo $this->getTemplate(); |
|
284 | - exit; |
|
285 | - } |
|
286 | - |
|
287 | - |
|
288 | - /** |
|
289 | - * @return string |
|
290 | - * @throws DomainException |
|
291 | - */ |
|
292 | - public function getTemplate() |
|
293 | - { |
|
294 | - return EEH_Template::display_template( |
|
295 | - __DIR__ . DIRECTORY_SEPARATOR . 'iframe_wrapper.template.php', |
|
296 | - array( |
|
297 | - 'title' => apply_filters( |
|
298 | - 'FHEE___EventEspresso_core_libraries_iframe_display_Iframe__getTemplate__title', |
|
299 | - $this->title, |
|
300 | - $this |
|
301 | - ), |
|
302 | - 'content' => apply_filters( |
|
303 | - 'FHEE___EventEspresso_core_libraries_iframe_display_Iframe__getTemplate__content', |
|
304 | - $this->content, |
|
305 | - $this |
|
306 | - ), |
|
307 | - 'enqueue_wp_assets' => apply_filters( |
|
308 | - 'FHEE___EventEspresso_core_libraries_iframe_display_Iframe__getTemplate__enqueue_wp_assets', |
|
309 | - $this->enqueue_wp_assets, |
|
310 | - $this |
|
311 | - ), |
|
312 | - 'css' => (array) apply_filters( |
|
313 | - 'FHEE___EventEspresso_core_libraries_iframe_display_Iframe__getTemplate__css_urls', |
|
314 | - $this->css, |
|
315 | - $this |
|
316 | - ), |
|
317 | - 'header_js' => (array) apply_filters( |
|
318 | - 'FHEE___EventEspresso_core_libraries_iframe_display_Iframe__getTemplate__header_js_urls', |
|
319 | - $this->header_js, |
|
320 | - $this |
|
321 | - ), |
|
322 | - 'header_js_attributes' => (array) apply_filters( |
|
323 | - 'FHEE___EventEspresso_core_libraries_iframe_display_Iframe__getTemplate__header_js_attributes', |
|
324 | - $this->header_js_attributes, |
|
325 | - $this |
|
326 | - ), |
|
327 | - 'footer_js' => (array) apply_filters( |
|
328 | - 'FHEE___EventEspresso_core_libraries_iframe_display_Iframe__getTemplate__footer_js_urls', |
|
329 | - $this->footer_js, |
|
330 | - $this |
|
331 | - ), |
|
332 | - 'footer_js_attributes' => (array) apply_filters( |
|
333 | - 'FHEE___EventEspresso_core_libraries_iframe_display_Iframe__getTemplate__footer_js_attributes', |
|
334 | - $this->footer_js_attributes, |
|
335 | - $this |
|
336 | - ), |
|
337 | - 'eei18n' => apply_filters( |
|
338 | - 'FHEE___EventEspresso_core_libraries_iframe_display_Iframe__getTemplate__eei18n_js_strings', |
|
339 | - EE_Registry::localize_i18n_js_strings() . $this->localizeJsonVars(), |
|
340 | - $this |
|
341 | - ), |
|
342 | - 'notices' => EEH_Template::display_template( |
|
343 | - EE_TEMPLATES . 'espresso-ajax-notices.template.php', |
|
344 | - array(), |
|
345 | - true |
|
346 | - ), |
|
347 | - ), |
|
348 | - true, |
|
349 | - true |
|
350 | - ); |
|
351 | - } |
|
352 | - |
|
353 | - |
|
354 | - /** |
|
355 | - * localizeJsonVars |
|
356 | - * |
|
357 | - * @return string |
|
358 | - */ |
|
359 | - public function localizeJsonVars() |
|
360 | - { |
|
361 | - $JSON = ''; |
|
362 | - foreach ((array) $this->localized_vars as $var_name => $vars) { |
|
363 | - $this->localized_vars[ $var_name ] = $this->encodeJsonVars($vars); |
|
364 | - $JSON .= "/* <![CDATA[ */ var {$var_name} = "; |
|
365 | - $JSON .= wp_json_encode($this->localized_vars[ $var_name ]); |
|
366 | - $JSON .= '; /* ]]> */'; |
|
367 | - } |
|
368 | - return $JSON; |
|
369 | - } |
|
370 | - |
|
371 | - |
|
372 | - /** |
|
373 | - * @param bool|int|float|string|array $var |
|
374 | - * @return array |
|
375 | - */ |
|
376 | - public function encodeJsonVars($var) |
|
377 | - { |
|
378 | - if (is_array($var)) { |
|
379 | - $localized_vars = array(); |
|
380 | - foreach ((array) $var as $key => $value) { |
|
381 | - $localized_vars[ $key ] = $this->encodeJsonVars($value); |
|
382 | - } |
|
383 | - return $localized_vars; |
|
384 | - } |
|
385 | - if (is_scalar($var)) { |
|
386 | - return html_entity_decode((string) $var, ENT_QUOTES, 'UTF-8'); |
|
387 | - } |
|
388 | - return null; |
|
389 | - } |
|
73 | + protected $localized_vars = array(); |
|
74 | + |
|
75 | + |
|
76 | + /** |
|
77 | + * Iframe constructor |
|
78 | + * |
|
79 | + * @param string $title |
|
80 | + * @param string $content |
|
81 | + * @throws DomainException |
|
82 | + */ |
|
83 | + public function __construct($title, $content) |
|
84 | + { |
|
85 | + global $wp_version; |
|
86 | + if (! defined('EE_IFRAME_DIR_URL')) { |
|
87 | + define('EE_IFRAME_DIR_URL', plugin_dir_url(__FILE__)); |
|
88 | + } |
|
89 | + $this->setContent($content); |
|
90 | + $this->setTitle($title); |
|
91 | + $this->addStylesheets( |
|
92 | + apply_filters( |
|
93 | + 'FHEE___EventEspresso_core_libraries_iframe_display_Iframe__construct__default_css', |
|
94 | + array( |
|
95 | + 'site_theme' => get_stylesheet_directory_uri() |
|
96 | + . '/style.css?ver=' . EVENT_ESPRESSO_VERSION, |
|
97 | + 'dashicons' => includes_url('css/dashicons.min.css?ver=' . $wp_version), |
|
98 | + 'espresso_default' => EE_GLOBAL_ASSETS_URL |
|
99 | + . 'css/espresso_default.css?ver=' . EVENT_ESPRESSO_VERSION, |
|
100 | + ), |
|
101 | + $this |
|
102 | + ) |
|
103 | + ); |
|
104 | + $this->addScripts( |
|
105 | + apply_filters( |
|
106 | + 'FHEE___EventEspresso_core_libraries_iframe_display_Iframe__construct__default_js', |
|
107 | + array( |
|
108 | + 'jquery' => includes_url('js/jquery/jquery.js?ver=' . $wp_version), |
|
109 | + 'espresso_core' => EE_GLOBAL_ASSETS_URL |
|
110 | + . 'scripts/espresso_core.js?ver=' . EVENT_ESPRESSO_VERSION, |
|
111 | + ), |
|
112 | + $this |
|
113 | + ) |
|
114 | + ); |
|
115 | + if ( |
|
116 | + apply_filters( |
|
117 | + 'FHEE___EventEspresso_core_libraries_iframe_display_Iframe__construct__load_default_theme_stylesheet', |
|
118 | + false |
|
119 | + ) |
|
120 | + ) { |
|
121 | + $this->addStylesheets( |
|
122 | + apply_filters( |
|
123 | + 'FHEE___EventEspresso_core_libraries_iframe_display_Iframe__construct__default_theme_stylesheet', |
|
124 | + array('default_theme_stylesheet' => get_stylesheet_uri()), |
|
125 | + $this |
|
126 | + ) |
|
127 | + ); |
|
128 | + } |
|
129 | + } |
|
130 | + |
|
131 | + |
|
132 | + /** |
|
133 | + * @param string $title |
|
134 | + * @throws DomainException |
|
135 | + */ |
|
136 | + public function setTitle($title) |
|
137 | + { |
|
138 | + if (empty($title)) { |
|
139 | + throw new DomainException( |
|
140 | + esc_html__('You must provide a page title in order to create an iframe.', 'event_espresso') |
|
141 | + ); |
|
142 | + } |
|
143 | + $this->title = $title; |
|
144 | + } |
|
145 | + |
|
146 | + |
|
147 | + /** |
|
148 | + * @param string $content |
|
149 | + * @throws DomainException |
|
150 | + */ |
|
151 | + public function setContent($content) |
|
152 | + { |
|
153 | + if (empty($content)) { |
|
154 | + throw new DomainException( |
|
155 | + esc_html__('You must provide content in order to create an iframe.', 'event_espresso') |
|
156 | + ); |
|
157 | + } |
|
158 | + $this->content = $content; |
|
159 | + } |
|
160 | + |
|
161 | + |
|
162 | + /** |
|
163 | + * @param boolean $enqueue_wp_assets |
|
164 | + */ |
|
165 | + public function setEnqueueWpAssets($enqueue_wp_assets) |
|
166 | + { |
|
167 | + $this->enqueue_wp_assets = filter_var($enqueue_wp_assets, FILTER_VALIDATE_BOOLEAN); |
|
168 | + } |
|
169 | + |
|
170 | + |
|
171 | + /** |
|
172 | + * @param array $stylesheets |
|
173 | + * @throws DomainException |
|
174 | + */ |
|
175 | + public function addStylesheets(array $stylesheets) |
|
176 | + { |
|
177 | + if (empty($stylesheets)) { |
|
178 | + throw new DomainException( |
|
179 | + esc_html__( |
|
180 | + 'A non-empty array of URLs, is required to add a CSS stylesheet to an iframe.', |
|
181 | + 'event_espresso' |
|
182 | + ) |
|
183 | + ); |
|
184 | + } |
|
185 | + foreach ($stylesheets as $handle => $stylesheet) { |
|
186 | + $this->css[ $handle ] = $stylesheet; |
|
187 | + } |
|
188 | + } |
|
189 | + |
|
190 | + |
|
191 | + /** |
|
192 | + * @param array $scripts |
|
193 | + * @param bool $add_to_header |
|
194 | + * @throws DomainException |
|
195 | + */ |
|
196 | + public function addScripts(array $scripts, $add_to_header = false) |
|
197 | + { |
|
198 | + if (empty($scripts)) { |
|
199 | + throw new DomainException( |
|
200 | + esc_html__( |
|
201 | + 'A non-empty array of URLs, is required to add Javascript to an iframe.', |
|
202 | + 'event_espresso' |
|
203 | + ) |
|
204 | + ); |
|
205 | + } |
|
206 | + foreach ($scripts as $handle => $script) { |
|
207 | + if ($add_to_header) { |
|
208 | + $this->header_js[ $handle ] = $script; |
|
209 | + } else { |
|
210 | + $this->footer_js[ $handle ] = $script; |
|
211 | + } |
|
212 | + } |
|
213 | + } |
|
214 | + |
|
215 | + |
|
216 | + /** |
|
217 | + * @param array $script_attributes |
|
218 | + * @param bool $add_to_header |
|
219 | + * @throws DomainException |
|
220 | + */ |
|
221 | + public function addScriptAttributes(array $script_attributes, $add_to_header = false) |
|
222 | + { |
|
223 | + if (empty($script_attributes)) { |
|
224 | + throw new DomainException( |
|
225 | + esc_html__( |
|
226 | + 'A non-empty array of strings, is required to add attributes to iframe Javascript.', |
|
227 | + 'event_espresso' |
|
228 | + ) |
|
229 | + ); |
|
230 | + } |
|
231 | + foreach ($script_attributes as $handle => $script_attribute) { |
|
232 | + if ($add_to_header) { |
|
233 | + $this->header_js_attributes[ $handle ] = $script_attribute; |
|
234 | + } else { |
|
235 | + $this->footer_js_attributes[ $handle ] = $script_attribute; |
|
236 | + } |
|
237 | + } |
|
238 | + } |
|
239 | + |
|
240 | + |
|
241 | + /** |
|
242 | + * @param array $vars |
|
243 | + * @param string $var_name |
|
244 | + * @throws DomainException |
|
245 | + */ |
|
246 | + public function addLocalizedVars(array $vars, $var_name = 'eei18n') |
|
247 | + { |
|
248 | + if (empty($vars)) { |
|
249 | + throw new DomainException( |
|
250 | + esc_html__( |
|
251 | + 'A non-empty array of vars, is required to add localized Javascript vars to an iframe.', |
|
252 | + 'event_espresso' |
|
253 | + ) |
|
254 | + ); |
|
255 | + } |
|
256 | + foreach ($vars as $handle => $var) { |
|
257 | + if ($var_name === 'eei18n') { |
|
258 | + EE_Registry::$i18n_js_strings[ $handle ] = $var; |
|
259 | + } elseif ($var_name === 'eeCAL' && $handle === 'espresso_calendar') { |
|
260 | + $this->localized_vars[ $var_name ] = $var; |
|
261 | + } else { |
|
262 | + if (! isset($this->localized_vars[ $var_name ])) { |
|
263 | + $this->localized_vars[ $var_name ] = array(); |
|
264 | + } |
|
265 | + $this->localized_vars[ $var_name ][ $handle ] = $var; |
|
266 | + } |
|
267 | + } |
|
268 | + } |
|
269 | + |
|
270 | + |
|
271 | + /** |
|
272 | + * @param string $utm_content |
|
273 | + * @throws DomainException |
|
274 | + */ |
|
275 | + public function display($utm_content = '') |
|
276 | + { |
|
277 | + $this->content .= EEH_Template::powered_by_event_espresso( |
|
278 | + '', |
|
279 | + '', |
|
280 | + ! empty($utm_content) ? array('utm_content' => $utm_content) : array() |
|
281 | + ); |
|
282 | + EE_System::do_not_cache(); |
|
283 | + echo $this->getTemplate(); |
|
284 | + exit; |
|
285 | + } |
|
286 | + |
|
287 | + |
|
288 | + /** |
|
289 | + * @return string |
|
290 | + * @throws DomainException |
|
291 | + */ |
|
292 | + public function getTemplate() |
|
293 | + { |
|
294 | + return EEH_Template::display_template( |
|
295 | + __DIR__ . DIRECTORY_SEPARATOR . 'iframe_wrapper.template.php', |
|
296 | + array( |
|
297 | + 'title' => apply_filters( |
|
298 | + 'FHEE___EventEspresso_core_libraries_iframe_display_Iframe__getTemplate__title', |
|
299 | + $this->title, |
|
300 | + $this |
|
301 | + ), |
|
302 | + 'content' => apply_filters( |
|
303 | + 'FHEE___EventEspresso_core_libraries_iframe_display_Iframe__getTemplate__content', |
|
304 | + $this->content, |
|
305 | + $this |
|
306 | + ), |
|
307 | + 'enqueue_wp_assets' => apply_filters( |
|
308 | + 'FHEE___EventEspresso_core_libraries_iframe_display_Iframe__getTemplate__enqueue_wp_assets', |
|
309 | + $this->enqueue_wp_assets, |
|
310 | + $this |
|
311 | + ), |
|
312 | + 'css' => (array) apply_filters( |
|
313 | + 'FHEE___EventEspresso_core_libraries_iframe_display_Iframe__getTemplate__css_urls', |
|
314 | + $this->css, |
|
315 | + $this |
|
316 | + ), |
|
317 | + 'header_js' => (array) apply_filters( |
|
318 | + 'FHEE___EventEspresso_core_libraries_iframe_display_Iframe__getTemplate__header_js_urls', |
|
319 | + $this->header_js, |
|
320 | + $this |
|
321 | + ), |
|
322 | + 'header_js_attributes' => (array) apply_filters( |
|
323 | + 'FHEE___EventEspresso_core_libraries_iframe_display_Iframe__getTemplate__header_js_attributes', |
|
324 | + $this->header_js_attributes, |
|
325 | + $this |
|
326 | + ), |
|
327 | + 'footer_js' => (array) apply_filters( |
|
328 | + 'FHEE___EventEspresso_core_libraries_iframe_display_Iframe__getTemplate__footer_js_urls', |
|
329 | + $this->footer_js, |
|
330 | + $this |
|
331 | + ), |
|
332 | + 'footer_js_attributes' => (array) apply_filters( |
|
333 | + 'FHEE___EventEspresso_core_libraries_iframe_display_Iframe__getTemplate__footer_js_attributes', |
|
334 | + $this->footer_js_attributes, |
|
335 | + $this |
|
336 | + ), |
|
337 | + 'eei18n' => apply_filters( |
|
338 | + 'FHEE___EventEspresso_core_libraries_iframe_display_Iframe__getTemplate__eei18n_js_strings', |
|
339 | + EE_Registry::localize_i18n_js_strings() . $this->localizeJsonVars(), |
|
340 | + $this |
|
341 | + ), |
|
342 | + 'notices' => EEH_Template::display_template( |
|
343 | + EE_TEMPLATES . 'espresso-ajax-notices.template.php', |
|
344 | + array(), |
|
345 | + true |
|
346 | + ), |
|
347 | + ), |
|
348 | + true, |
|
349 | + true |
|
350 | + ); |
|
351 | + } |
|
352 | + |
|
353 | + |
|
354 | + /** |
|
355 | + * localizeJsonVars |
|
356 | + * |
|
357 | + * @return string |
|
358 | + */ |
|
359 | + public function localizeJsonVars() |
|
360 | + { |
|
361 | + $JSON = ''; |
|
362 | + foreach ((array) $this->localized_vars as $var_name => $vars) { |
|
363 | + $this->localized_vars[ $var_name ] = $this->encodeJsonVars($vars); |
|
364 | + $JSON .= "/* <![CDATA[ */ var {$var_name} = "; |
|
365 | + $JSON .= wp_json_encode($this->localized_vars[ $var_name ]); |
|
366 | + $JSON .= '; /* ]]> */'; |
|
367 | + } |
|
368 | + return $JSON; |
|
369 | + } |
|
370 | + |
|
371 | + |
|
372 | + /** |
|
373 | + * @param bool|int|float|string|array $var |
|
374 | + * @return array |
|
375 | + */ |
|
376 | + public function encodeJsonVars($var) |
|
377 | + { |
|
378 | + if (is_array($var)) { |
|
379 | + $localized_vars = array(); |
|
380 | + foreach ((array) $var as $key => $value) { |
|
381 | + $localized_vars[ $key ] = $this->encodeJsonVars($value); |
|
382 | + } |
|
383 | + return $localized_vars; |
|
384 | + } |
|
385 | + if (is_scalar($var)) { |
|
386 | + return html_entity_decode((string) $var, ENT_QUOTES, 'UTF-8'); |
|
387 | + } |
|
388 | + return null; |
|
389 | + } |
|
390 | 390 | } |
@@ -17,135 +17,135 @@ |
||
17 | 17 | */ |
18 | 18 | abstract class JobHandlerFile extends JobHandler |
19 | 19 | { |
20 | - // phpcs:disable Generic.NamingConventions.UpperCaseConstantName.ClassConstantNotUpperCase |
|
21 | - const temp_folder_name = 'batch_temp_folder'; |
|
20 | + // phpcs:disable Generic.NamingConventions.UpperCaseConstantName.ClassConstantNotUpperCase |
|
21 | + const temp_folder_name = 'batch_temp_folder'; |
|
22 | 22 | |
23 | - // phpcs:disable PSR2.Classes.PropertyDeclaration.Underscore |
|
24 | - /** |
|
25 | - * @var \EEHI_File |
|
26 | - */ |
|
27 | - protected $_file_helper = null; |
|
23 | + // phpcs:disable PSR2.Classes.PropertyDeclaration.Underscore |
|
24 | + /** |
|
25 | + * @var \EEHI_File |
|
26 | + */ |
|
27 | + protected $_file_helper = null; |
|
28 | 28 | |
29 | 29 | |
30 | - /** |
|
31 | - * JobHandlerFile constructor. |
|
32 | - * |
|
33 | - * @param \EEHI_File|null $file_helper |
|
34 | - */ |
|
35 | - public function __construct(\EEHI_File $file_helper = null) |
|
36 | - { |
|
37 | - if (! $file_helper) { |
|
38 | - $this->_file_helper = new EEH_File(); |
|
39 | - } |
|
40 | - } |
|
30 | + /** |
|
31 | + * JobHandlerFile constructor. |
|
32 | + * |
|
33 | + * @param \EEHI_File|null $file_helper |
|
34 | + */ |
|
35 | + public function __construct(\EEHI_File $file_helper = null) |
|
36 | + { |
|
37 | + if (! $file_helper) { |
|
38 | + $this->_file_helper = new EEH_File(); |
|
39 | + } |
|
40 | + } |
|
41 | 41 | |
42 | - // phpcs:disable PSR1.Methods.CamelCapsMethodName.NotCamelCaps |
|
43 | - /** |
|
44 | - * Creates a file |
|
45 | - * |
|
46 | - * @param string $job_id |
|
47 | - * @param string $filename |
|
48 | - * @param string $filetype |
|
49 | - * @param string $bom initial content to place in the file. |
|
50 | - * @return string |
|
51 | - * @throws \EventEspressoBatchRequest\Helpers\BatchRequestException |
|
52 | - */ |
|
53 | - public function create_file_from_job_with_name( |
|
54 | - $job_id, |
|
55 | - $filename, |
|
56 | - $filetype = 'application/ms-excel', |
|
57 | - $bom = "\xEF\xBB\xBF" |
|
58 | - ) { |
|
59 | - $filepath = ''; |
|
60 | - try { |
|
61 | - $base_folder = $this->get_base_folder(); |
|
62 | - $success = $this->_file_helper->ensure_folder_exists_and_is_writable( |
|
63 | - $base_folder . JobHandlerFile::temp_folder_name |
|
64 | - ); |
|
65 | - if ($success) { |
|
66 | - $success = $this->_file_helper->ensure_folder_exists_and_is_writable( |
|
67 | - $base_folder . JobHandlerFile::temp_folder_name . '/' . $job_id |
|
68 | - ); |
|
69 | - } |
|
70 | - if ($success) { |
|
71 | - $filepath = $base_folder . JobHandlerFile::temp_folder_name . '/' . $job_id . '/' . $filename; |
|
72 | - $success = $this->_file_helper->ensure_file_exists_and_is_writable($filepath); |
|
73 | - } |
|
74 | - // let's add the .htaccess file so safari will open the file properly |
|
75 | - if ($success) { |
|
76 | - $extension = EEH_File::get_file_extension($filepath); |
|
77 | - EEH_File::write_to_file( |
|
78 | - $base_folder . JobHandlerFile::temp_folder_name . '/' . $job_id . '/.htaccess', |
|
79 | - 'AddType ' . $filetype . ' ' . $extension, |
|
80 | - '.htaccess' |
|
81 | - ); |
|
82 | - } |
|
83 | - /** |
|
84 | - * Filters what initial content will be added to the file. |
|
85 | - * @param string $return_value. By default it's whatever was pased into |
|
86 | - * JobHandlerFile::create_file_from_job_with_name() |
|
87 | - * @param string $filename |
|
88 | - * @param string $filetype default 'application/ms-excel' |
|
89 | - * @param string $filepath |
|
90 | - */ |
|
91 | - EEH_File::write_to_file( |
|
92 | - $filepath, |
|
93 | - apply_filters( |
|
94 | - 'FHEE__EE_CSV__begin_sending_csv__start_writing', |
|
95 | - $bom, |
|
96 | - $filename, |
|
97 | - $filetype, |
|
98 | - $filepath |
|
99 | - ) |
|
100 | - ); |
|
101 | - // those methods normally fail with an exception, but if not, let's do it |
|
102 | - if (! $success) { |
|
103 | - throw new \EE_Error(__('Could not create temporary file, an unknown error occurred', 'event_espresso')); |
|
104 | - } |
|
105 | - } catch (\EE_Error $e) { |
|
106 | - throw new BatchRequestException( |
|
107 | - sprintf( |
|
108 | - // phpcs:disable WordPress.WP.I18n.MissingTranslatorsComment |
|
109 | - __('Could not create temporary file for job %1$s, because: %2$s ', 'event_espresso'), |
|
110 | - $job_id, |
|
111 | - $e->getMessage() |
|
112 | - ), |
|
113 | - 500, |
|
114 | - $e |
|
115 | - ); |
|
116 | - } |
|
117 | - return $filepath; |
|
118 | - } |
|
42 | + // phpcs:disable PSR1.Methods.CamelCapsMethodName.NotCamelCaps |
|
43 | + /** |
|
44 | + * Creates a file |
|
45 | + * |
|
46 | + * @param string $job_id |
|
47 | + * @param string $filename |
|
48 | + * @param string $filetype |
|
49 | + * @param string $bom initial content to place in the file. |
|
50 | + * @return string |
|
51 | + * @throws \EventEspressoBatchRequest\Helpers\BatchRequestException |
|
52 | + */ |
|
53 | + public function create_file_from_job_with_name( |
|
54 | + $job_id, |
|
55 | + $filename, |
|
56 | + $filetype = 'application/ms-excel', |
|
57 | + $bom = "\xEF\xBB\xBF" |
|
58 | + ) { |
|
59 | + $filepath = ''; |
|
60 | + try { |
|
61 | + $base_folder = $this->get_base_folder(); |
|
62 | + $success = $this->_file_helper->ensure_folder_exists_and_is_writable( |
|
63 | + $base_folder . JobHandlerFile::temp_folder_name |
|
64 | + ); |
|
65 | + if ($success) { |
|
66 | + $success = $this->_file_helper->ensure_folder_exists_and_is_writable( |
|
67 | + $base_folder . JobHandlerFile::temp_folder_name . '/' . $job_id |
|
68 | + ); |
|
69 | + } |
|
70 | + if ($success) { |
|
71 | + $filepath = $base_folder . JobHandlerFile::temp_folder_name . '/' . $job_id . '/' . $filename; |
|
72 | + $success = $this->_file_helper->ensure_file_exists_and_is_writable($filepath); |
|
73 | + } |
|
74 | + // let's add the .htaccess file so safari will open the file properly |
|
75 | + if ($success) { |
|
76 | + $extension = EEH_File::get_file_extension($filepath); |
|
77 | + EEH_File::write_to_file( |
|
78 | + $base_folder . JobHandlerFile::temp_folder_name . '/' . $job_id . '/.htaccess', |
|
79 | + 'AddType ' . $filetype . ' ' . $extension, |
|
80 | + '.htaccess' |
|
81 | + ); |
|
82 | + } |
|
83 | + /** |
|
84 | + * Filters what initial content will be added to the file. |
|
85 | + * @param string $return_value. By default it's whatever was pased into |
|
86 | + * JobHandlerFile::create_file_from_job_with_name() |
|
87 | + * @param string $filename |
|
88 | + * @param string $filetype default 'application/ms-excel' |
|
89 | + * @param string $filepath |
|
90 | + */ |
|
91 | + EEH_File::write_to_file( |
|
92 | + $filepath, |
|
93 | + apply_filters( |
|
94 | + 'FHEE__EE_CSV__begin_sending_csv__start_writing', |
|
95 | + $bom, |
|
96 | + $filename, |
|
97 | + $filetype, |
|
98 | + $filepath |
|
99 | + ) |
|
100 | + ); |
|
101 | + // those methods normally fail with an exception, but if not, let's do it |
|
102 | + if (! $success) { |
|
103 | + throw new \EE_Error(__('Could not create temporary file, an unknown error occurred', 'event_espresso')); |
|
104 | + } |
|
105 | + } catch (\EE_Error $e) { |
|
106 | + throw new BatchRequestException( |
|
107 | + sprintf( |
|
108 | + // phpcs:disable WordPress.WP.I18n.MissingTranslatorsComment |
|
109 | + __('Could not create temporary file for job %1$s, because: %2$s ', 'event_espresso'), |
|
110 | + $job_id, |
|
111 | + $e->getMessage() |
|
112 | + ), |
|
113 | + 500, |
|
114 | + $e |
|
115 | + ); |
|
116 | + } |
|
117 | + return $filepath; |
|
118 | + } |
|
119 | 119 | |
120 | - /** |
|
121 | - * Gets the URL to download the file |
|
122 | - * |
|
123 | - * @param string $filepath |
|
124 | - * @return string url to file |
|
125 | - */ |
|
126 | - public function get_url_to_file($filepath) |
|
127 | - { |
|
128 | - return str_replace($this->get_base_folder(), $this->get_base_url(), $filepath); |
|
129 | - } |
|
120 | + /** |
|
121 | + * Gets the URL to download the file |
|
122 | + * |
|
123 | + * @param string $filepath |
|
124 | + * @return string url to file |
|
125 | + */ |
|
126 | + public function get_url_to_file($filepath) |
|
127 | + { |
|
128 | + return str_replace($this->get_base_folder(), $this->get_base_url(), $filepath); |
|
129 | + } |
|
130 | 130 | |
131 | - /** |
|
132 | - * Gets the folder which will contain the "batch_temp_folder" |
|
133 | - * |
|
134 | - * @return string |
|
135 | - */ |
|
136 | - public function get_base_folder() |
|
137 | - { |
|
138 | - return apply_filters( |
|
139 | - 'FHEE__EventEspressoBatchRequest\JobHandlerBaseClasses\JobHandlerFile__get_base_folder', |
|
140 | - EVENT_ESPRESSO_UPLOAD_DIR |
|
141 | - ); |
|
142 | - } |
|
131 | + /** |
|
132 | + * Gets the folder which will contain the "batch_temp_folder" |
|
133 | + * |
|
134 | + * @return string |
|
135 | + */ |
|
136 | + public function get_base_folder() |
|
137 | + { |
|
138 | + return apply_filters( |
|
139 | + 'FHEE__EventEspressoBatchRequest\JobHandlerBaseClasses\JobHandlerFile__get_base_folder', |
|
140 | + EVENT_ESPRESSO_UPLOAD_DIR |
|
141 | + ); |
|
142 | + } |
|
143 | 143 | |
144 | - public function get_base_url() |
|
145 | - { |
|
146 | - return apply_filters( |
|
147 | - 'FHEE__EventEspressoBatchRequest\JobHandlerBaseClasses\JobHandlerFile__get_base_url', |
|
148 | - EVENT_ESPRESSO_UPLOAD_URL |
|
149 | - ); |
|
150 | - } |
|
144 | + public function get_base_url() |
|
145 | + { |
|
146 | + return apply_filters( |
|
147 | + 'FHEE__EventEspressoBatchRequest\JobHandlerBaseClasses\JobHandlerFile__get_base_url', |
|
148 | + EVENT_ESPRESSO_UPLOAD_URL |
|
149 | + ); |
|
150 | + } |
|
151 | 151 | } |
@@ -34,7 +34,7 @@ discard block |
||
34 | 34 | */ |
35 | 35 | public function __construct(\EEHI_File $file_helper = null) |
36 | 36 | { |
37 | - if (! $file_helper) { |
|
37 | + if ( ! $file_helper) { |
|
38 | 38 | $this->_file_helper = new EEH_File(); |
39 | 39 | } |
40 | 40 | } |
@@ -60,23 +60,23 @@ discard block |
||
60 | 60 | try { |
61 | 61 | $base_folder = $this->get_base_folder(); |
62 | 62 | $success = $this->_file_helper->ensure_folder_exists_and_is_writable( |
63 | - $base_folder . JobHandlerFile::temp_folder_name |
|
63 | + $base_folder.JobHandlerFile::temp_folder_name |
|
64 | 64 | ); |
65 | 65 | if ($success) { |
66 | 66 | $success = $this->_file_helper->ensure_folder_exists_and_is_writable( |
67 | - $base_folder . JobHandlerFile::temp_folder_name . '/' . $job_id |
|
67 | + $base_folder.JobHandlerFile::temp_folder_name.'/'.$job_id |
|
68 | 68 | ); |
69 | 69 | } |
70 | 70 | if ($success) { |
71 | - $filepath = $base_folder . JobHandlerFile::temp_folder_name . '/' . $job_id . '/' . $filename; |
|
71 | + $filepath = $base_folder.JobHandlerFile::temp_folder_name.'/'.$job_id.'/'.$filename; |
|
72 | 72 | $success = $this->_file_helper->ensure_file_exists_and_is_writable($filepath); |
73 | 73 | } |
74 | 74 | // let's add the .htaccess file so safari will open the file properly |
75 | 75 | if ($success) { |
76 | 76 | $extension = EEH_File::get_file_extension($filepath); |
77 | 77 | EEH_File::write_to_file( |
78 | - $base_folder . JobHandlerFile::temp_folder_name . '/' . $job_id . '/.htaccess', |
|
79 | - 'AddType ' . $filetype . ' ' . $extension, |
|
78 | + $base_folder.JobHandlerFile::temp_folder_name.'/'.$job_id.'/.htaccess', |
|
79 | + 'AddType '.$filetype.' '.$extension, |
|
80 | 80 | '.htaccess' |
81 | 81 | ); |
82 | 82 | } |
@@ -99,7 +99,7 @@ discard block |
||
99 | 99 | ) |
100 | 100 | ); |
101 | 101 | // those methods normally fail with an exception, but if not, let's do it |
102 | - if (! $success) { |
|
102 | + if ( ! $success) { |
|
103 | 103 | throw new \EE_Error(__('Could not create temporary file, an unknown error occurred', 'event_espresso')); |
104 | 104 | } |
105 | 105 | } catch (\EE_Error $e) { |
@@ -126,8 +126,8 @@ discard block |
||
126 | 126 | */ |
127 | 127 | public static function set_definitions() |
128 | 128 | { |
129 | - define('THANK_YOU_ASSETS_URL', plugin_dir_url(__FILE__) . 'assets/'); |
|
130 | - define('THANK_YOU_TEMPLATES_PATH', str_replace('\\', '/', plugin_dir_path(__FILE__)) . 'templates/'); |
|
129 | + define('THANK_YOU_ASSETS_URL', plugin_dir_url(__FILE__).'assets/'); |
|
130 | + define('THANK_YOU_TEMPLATES_PATH', str_replace('\\', '/', plugin_dir_path(__FILE__)).'templates/'); |
|
131 | 131 | } |
132 | 132 | |
133 | 133 | |
@@ -142,7 +142,7 @@ discard block |
||
142 | 142 | return $this->_current_txn; |
143 | 143 | } |
144 | 144 | $TXN_model = EE_Registry::instance()->load_model('Transaction'); |
145 | - if (! $TXN_model instanceof EEM_Transaction) { |
|
145 | + if ( ! $TXN_model instanceof EEM_Transaction) { |
|
146 | 146 | EE_Error::add_error( |
147 | 147 | __('The transaction model could not be established.', 'event_espresso'), |
148 | 148 | __FILE__, |
@@ -179,7 +179,7 @@ discard block |
||
179 | 179 | */ |
180 | 180 | public function get_txn_payments($since = 0) |
181 | 181 | { |
182 | - if (! $this->get_txn()) { |
|
182 | + if ( ! $this->get_txn()) { |
|
183 | 183 | return false; |
184 | 184 | } |
185 | 185 | $args = array('order_by' => array('PAY_timestamp' => 'ASC')); |
@@ -209,7 +209,7 @@ discard block |
||
209 | 209 | */ |
210 | 210 | private function _get_reg_url_link() |
211 | 211 | { |
212 | - if (! empty($this->_reg_url_link)) { |
|
212 | + if ( ! empty($this->_reg_url_link)) { |
|
213 | 213 | return; |
214 | 214 | } |
215 | 215 | // only do thank you page stuff if we have a REG_url_link in the url |
@@ -321,7 +321,7 @@ discard block |
||
321 | 321 | { |
322 | 322 | wp_register_script( |
323 | 323 | 'thank_you_page', |
324 | - THANK_YOU_ASSETS_URL . 'thank_you_page.js', |
|
324 | + THANK_YOU_ASSETS_URL.'thank_you_page.js', |
|
325 | 325 | array('espresso_core', 'heartbeat'), |
326 | 326 | EVENT_ESPRESSO_VERSION, |
327 | 327 | true |
@@ -340,9 +340,9 @@ discard block |
||
340 | 340 | public function init() |
341 | 341 | { |
342 | 342 | $this->_get_reg_url_link(); |
343 | - if (! $this->get_txn()) { |
|
343 | + if ( ! $this->get_txn()) { |
|
344 | 344 | echo EEH_HTML::div( |
345 | - EEH_HTML::h4(__('We\'re sorry...', 'event_espresso'), '', '') . |
|
345 | + EEH_HTML::h4(__('We\'re sorry...', 'event_espresso'), '', ''). |
|
346 | 346 | sprintf( |
347 | 347 | __( |
348 | 348 | 'This is a system page for displaying transaction information after a purchase.%1$sYou are most likely seeing this notice because you have navigated to this page%1$sthrough some means other than completing a transaction.%1$sSorry for the disappointment, but you will most likely find nothing of interest here.%1$s%1$s', |
@@ -432,12 +432,12 @@ discard block |
||
432 | 432 | public function thank_you_page_results() |
433 | 433 | { |
434 | 434 | $this->init(); |
435 | - if (! $this->_current_txn instanceof EE_Transaction) { |
|
435 | + if ( ! $this->_current_txn instanceof EE_Transaction) { |
|
436 | 436 | return EE_Error::get_notices(); |
437 | 437 | } |
438 | 438 | // link to receipt |
439 | 439 | $template_args['TXN_receipt_url'] = $this->_current_txn->receipt_url('html'); |
440 | - if (! empty($template_args['TXN_receipt_url'])) { |
|
440 | + if ( ! empty($template_args['TXN_receipt_url'])) { |
|
441 | 441 | $template_args['order_conf_desc'] = __( |
442 | 442 | '%1$sCongratulations%2$sYour registration has been successfully processed.%3$sCheck your email for your registration confirmation or click the button below to view / download / print a full description of your purchases and registration information.', |
443 | 443 | 'event_espresso' |
@@ -455,7 +455,7 @@ discard block |
||
455 | 455 | add_action('AHEE__thank_you_page_overview_template__content', array($this, 'get_ajax_content')); |
456 | 456 | } |
457 | 457 | return EEH_Template::locate_template( |
458 | - THANK_YOU_TEMPLATES_PATH . 'thank-you-page-overview.template.php', |
|
458 | + THANK_YOU_TEMPLATES_PATH.'thank-you-page-overview.template.php', |
|
459 | 459 | $template_args, |
460 | 460 | true, |
461 | 461 | true |
@@ -507,7 +507,7 @@ discard block |
||
507 | 507 | '$SPCO_attendee_information_url' |
508 | 508 | ); |
509 | 509 | echo EEH_Template::locate_template( |
510 | - THANK_YOU_TEMPLATES_PATH . 'thank-you-page-registration-details.template.php', |
|
510 | + THANK_YOU_TEMPLATES_PATH.'thank-you-page-registration-details.template.php', |
|
511 | 511 | $template_args, |
512 | 512 | true, |
513 | 513 | true |
@@ -580,7 +580,7 @@ discard block |
||
580 | 580 | */ |
581 | 581 | public function get_ajax_content() |
582 | 582 | { |
583 | - if (! $this->get_txn()) { |
|
583 | + if ( ! $this->get_txn()) { |
|
584 | 584 | return; |
585 | 585 | } |
586 | 586 | // first determine which event(s) require pre-approval or not |
@@ -591,9 +591,9 @@ discard block |
||
591 | 591 | $event = $registration->event(); |
592 | 592 | if ($event instanceof EE_Event) { |
593 | 593 | if ($registration->is_not_approved() && $registration->event() instanceof EE_Event) { |
594 | - $events_requiring_pre_approval[ $event->ID() ] = $event; |
|
594 | + $events_requiring_pre_approval[$event->ID()] = $event; |
|
595 | 595 | } else { |
596 | - $events[ $event->ID() ] = $event; |
|
596 | + $events[$event->ID()] = $event; |
|
597 | 597 | } |
598 | 598 | } |
599 | 599 | } |
@@ -611,7 +611,7 @@ discard block |
||
611 | 611 | */ |
612 | 612 | public function display_details_for_events($events = array()) |
613 | 613 | { |
614 | - if (! empty($events)) { |
|
614 | + if ( ! empty($events)) { |
|
615 | 615 | ?> |
616 | 616 | <div id="espresso-thank-you-page-ajax-content-dv"> |
617 | 617 | <div id="espresso-thank-you-page-ajax-transaction-dv"></div> |
@@ -624,7 +624,7 @@ discard block |
||
624 | 624 | 'event_espresso' |
625 | 625 | ); ?></span> |
626 | 626 | </div> |
627 | - <?php if (! $this->_is_offline_payment_method && ! $this->_payments_closed) : ?> |
|
627 | + <?php if ( ! $this->_is_offline_payment_method && ! $this->_payments_closed) : ?> |
|
628 | 628 | <p id="ee-ajax-loading-pg" class="highlight-bg small-text clear"> |
629 | 629 | <?php echo apply_filters( |
630 | 630 | 'EED_Thank_You_Page__get_ajax_content__waiting_for_IPN_msg', |
@@ -655,7 +655,7 @@ discard block |
||
655 | 655 | */ |
656 | 656 | public function display_details_for_events_requiring_pre_approval($events = array()) |
657 | 657 | { |
658 | - if (! empty($events)) { |
|
658 | + if ( ! empty($events)) { |
|
659 | 659 | ?> |
660 | 660 | <div id="espresso-thank-you-page-not-approved-message-dv"> |
661 | 661 | <h4 class="orange-text"><?php _e('Important Notice:', 'event_espresso'); ?></h4> |
@@ -712,7 +712,7 @@ discard block |
||
712 | 712 | '$SPCO_payment_options_url' |
713 | 713 | ); |
714 | 714 | return EEH_Template::locate_template( |
715 | - THANK_YOU_TEMPLATES_PATH . 'thank-you-page-transaction-details.template.php', |
|
715 | + THANK_YOU_TEMPLATES_PATH.'thank-you-page-transaction-details.template.php', |
|
716 | 716 | $template_args, |
717 | 717 | true, |
718 | 718 | true |
@@ -741,25 +741,25 @@ discard block |
||
741 | 741 | $payment->set_status(EEM_Payment::status_id_pending); |
742 | 742 | } |
743 | 743 | $payment_declined_msg = $payment->STS_ID() === EEM_Payment::status_id_declined |
744 | - ? '<br /><span class="small-text">' . $payment->gateway_response() . '</span>' |
|
744 | + ? '<br /><span class="small-text">'.$payment->gateway_response().'</span>' |
|
745 | 745 | : ''; |
746 | 746 | $html .= ' |
747 | 747 | <tr> |
748 | 748 | <td> |
749 | - ' . $payment->timestamp() . ' |
|
749 | + ' . $payment->timestamp().' |
|
750 | 750 | </td> |
751 | 751 | <td> |
752 | 752 | ' . ( |
753 | 753 | $payment->payment_method() instanceof EE_Payment_Method |
754 | 754 | ? $payment->payment_method()->name() |
755 | 755 | : __('Unknown', 'event_espresso') |
756 | - ) . ' |
|
756 | + ).' |
|
757 | 757 | </td> |
758 | 758 | <td class="jst-rght"> |
759 | - ' . EEH_Template::format_currency($payment->amount()) . ' |
|
759 | + ' . EEH_Template::format_currency($payment->amount()).' |
|
760 | 760 | </td> |
761 | 761 | <td class="jst-rght" style="line-height:1;"> |
762 | - ' . $payment->pretty_status(true) . $payment_declined_msg . ' |
|
762 | + ' . $payment->pretty_status(true).$payment_declined_msg.' |
|
763 | 763 | </td> |
764 | 764 | </tr>'; |
765 | 765 | do_action('AHEE__thank_you_page_payment_details_template__after_each_payment', $payment); |
@@ -817,7 +817,7 @@ discard block |
||
817 | 817 | '$SPCO_payment_options_url' |
818 | 818 | ); |
819 | 819 | return EEH_Template::locate_template( |
820 | - THANK_YOU_TEMPLATES_PATH . 'thank-you-page-payment-details.template.php', |
|
820 | + THANK_YOU_TEMPLATES_PATH.'thank-you-page-payment-details.template.php', |
|
821 | 821 | $template_args, |
822 | 822 | true, |
823 | 823 | true |
@@ -10,611 +10,611 @@ discard block |
||
10 | 10 | class EED_Thank_You_Page extends EED_Module |
11 | 11 | { |
12 | 12 | |
13 | - /** |
|
14 | - * time in seconds to wait for the IPN to arrive before telling the registrant to bugger off ( 1200s = 20 minutes ) |
|
15 | - */ |
|
16 | - const IPN_wait_time = 1200; |
|
17 | - |
|
18 | - /** |
|
19 | - * The transaction specified by the reg_url_link passed from the Request, or from the Session |
|
20 | - * |
|
21 | - * @var EE_Transaction $_current_txn |
|
22 | - */ |
|
23 | - private $_current_txn; |
|
24 | - |
|
25 | - /** |
|
26 | - * @var EE_Registration $_primary_registrant |
|
27 | - */ |
|
28 | - private $_primary_registrant; |
|
29 | - |
|
30 | - /** |
|
31 | - * The reg_url_link passed from the Request, or from the Session |
|
32 | - * |
|
33 | - * @var string $_reg_url_link |
|
34 | - */ |
|
35 | - private $_reg_url_link; |
|
36 | - |
|
37 | - /** |
|
38 | - * whether the incoming reg_url_link is for the primary registrant or not |
|
39 | - * |
|
40 | - * @var boolean $_is_primary |
|
41 | - */ |
|
42 | - private $_is_primary; |
|
43 | - |
|
44 | - /** |
|
45 | - * The URL for revisiting the SPCO attendee information step |
|
46 | - * |
|
47 | - * @var string $_SPCO_attendee_information_url |
|
48 | - */ |
|
49 | - private $_SPCO_attendee_information_url; |
|
50 | - |
|
51 | - /** |
|
52 | - * The URL for revisiting the SPCO payment options step |
|
53 | - * |
|
54 | - * @var string $_SPCO_payment_options_url |
|
55 | - */ |
|
56 | - private $_SPCO_payment_options_url; |
|
57 | - |
|
58 | - /** |
|
59 | - * whether to display the Payment Options link |
|
60 | - * |
|
61 | - * @var boolean $_show_try_pay_again_link |
|
62 | - */ |
|
63 | - private $_show_try_pay_again_link = false; |
|
64 | - |
|
65 | - /** |
|
66 | - * whether payments are allowed at this time |
|
67 | - * |
|
68 | - * @var boolean $_payments_closed |
|
69 | - */ |
|
70 | - private $_payments_closed = false; |
|
71 | - |
|
72 | - /** |
|
73 | - * whether the selected payment method is Bank, Check , Invoice, etc |
|
74 | - * |
|
75 | - * @var boolean $_is_offline_payment_method |
|
76 | - */ |
|
77 | - private $_is_offline_payment_method = true; |
|
78 | - |
|
79 | - |
|
80 | - /** |
|
81 | - * @return EED_Module|EED_Thank_You_Page |
|
82 | - */ |
|
83 | - public static function instance() |
|
84 | - { |
|
85 | - return parent::get_instance(__CLASS__); |
|
86 | - } |
|
87 | - |
|
88 | - |
|
89 | - /** |
|
90 | - * set_hooks - for hooking into EE Core, modules, etc |
|
91 | - * |
|
92 | - * @return void |
|
93 | - */ |
|
94 | - public static function set_hooks() |
|
95 | - { |
|
96 | - add_action('wp_loaded', array('EED_Thank_You_Page', 'set_definitions'), 2); |
|
97 | - } |
|
98 | - |
|
99 | - |
|
100 | - /** |
|
101 | - * set_hooks_admin - for hooking into EE Admin Core, modules, etc |
|
102 | - * |
|
103 | - * @return void |
|
104 | - */ |
|
105 | - public static function set_hooks_admin() |
|
106 | - { |
|
107 | - add_action( |
|
108 | - 'wp_ajax_espresso_resend_reg_confirmation_email', |
|
109 | - array('EED_Thank_You_Page', 'resend_reg_confirmation_email'), |
|
110 | - 10, |
|
111 | - 2 |
|
112 | - ); |
|
113 | - add_action( |
|
114 | - 'wp_ajax_nopriv_espresso_resend_reg_confirmation_email', |
|
115 | - array('EED_Thank_You_Page', 'resend_reg_confirmation_email'), |
|
116 | - 10, |
|
117 | - 2 |
|
118 | - ); |
|
119 | - } |
|
120 | - |
|
121 | - |
|
122 | - /** |
|
123 | - * set_definitions |
|
124 | - * |
|
125 | - * @return void |
|
126 | - */ |
|
127 | - public static function set_definitions() |
|
128 | - { |
|
129 | - define('THANK_YOU_ASSETS_URL', plugin_dir_url(__FILE__) . 'assets/'); |
|
130 | - define('THANK_YOU_TEMPLATES_PATH', str_replace('\\', '/', plugin_dir_path(__FILE__)) . 'templates/'); |
|
131 | - } |
|
132 | - |
|
133 | - |
|
134 | - /** |
|
135 | - * get_txn |
|
136 | - * |
|
137 | - * @return EE_Transaction |
|
138 | - */ |
|
139 | - public function get_txn() |
|
140 | - { |
|
141 | - if ($this->_current_txn instanceof EE_Transaction) { |
|
142 | - return $this->_current_txn; |
|
143 | - } |
|
144 | - $TXN_model = EE_Registry::instance()->load_model('Transaction'); |
|
145 | - if (! $TXN_model instanceof EEM_Transaction) { |
|
146 | - EE_Error::add_error( |
|
147 | - __('The transaction model could not be established.', 'event_espresso'), |
|
148 | - __FILE__, |
|
149 | - __FUNCTION__, |
|
150 | - __LINE__ |
|
151 | - ); |
|
152 | - return null; |
|
153 | - } |
|
154 | - // get the transaction. yes, we may have just loaded it, but it may have been updated, or this may be via an ajax request |
|
155 | - $this->_current_txn = $TXN_model->get_transaction_from_reg_url_link($this->_reg_url_link); |
|
156 | - // verify TXN |
|
157 | - if (WP_DEBUG && ! $this->_current_txn instanceof EE_Transaction) { |
|
158 | - EE_Error::add_error( |
|
159 | - __( |
|
160 | - 'No transaction information could be retrieved or the transaction data is not of the correct type.', |
|
161 | - 'event_espresso' |
|
162 | - ), |
|
163 | - __FILE__, |
|
164 | - __FUNCTION__, |
|
165 | - __LINE__ |
|
166 | - ); |
|
167 | - return null; |
|
168 | - } |
|
169 | - return $this->_current_txn; |
|
170 | - } |
|
171 | - |
|
172 | - |
|
173 | - /** |
|
174 | - * get_txn_payments |
|
175 | - * |
|
176 | - * @param int $since |
|
177 | - * @return mixed array of EE_Payment || FALSE |
|
178 | - * @throws \EE_Error |
|
179 | - */ |
|
180 | - public function get_txn_payments($since = 0) |
|
181 | - { |
|
182 | - if (! $this->get_txn()) { |
|
183 | - return false; |
|
184 | - } |
|
185 | - $args = array('order_by' => array('PAY_timestamp' => 'ASC')); |
|
186 | - if ($since > 0) { |
|
187 | - $args[0] = array('PAY_timestamp' => array('>', $since)); |
|
188 | - } |
|
189 | - // get array of payments with most recent first |
|
190 | - return $this->_current_txn->payments($args); |
|
191 | - } |
|
192 | - |
|
193 | - |
|
194 | - /** |
|
195 | - * @return bool |
|
196 | - */ |
|
197 | - public function isOfflinePaymentMethod() |
|
198 | - { |
|
199 | - return $this->_is_offline_payment_method; |
|
200 | - } |
|
201 | - |
|
202 | - |
|
203 | - |
|
204 | - |
|
205 | - /** |
|
206 | - * get_reg_url_link |
|
207 | - * |
|
208 | - * @return void |
|
209 | - */ |
|
210 | - private function _get_reg_url_link() |
|
211 | - { |
|
212 | - if (! empty($this->_reg_url_link)) { |
|
213 | - return; |
|
214 | - } |
|
215 | - // only do thank you page stuff if we have a REG_url_link in the url |
|
216 | - if (WP_DEBUG && ! EE_Registry::instance()->REQ->is_set('e_reg_url_link')) { |
|
217 | - EE_Error::add_error( |
|
218 | - __( |
|
219 | - 'No transaction information could be retrieved because the registration URL link is missing or invalid.', |
|
220 | - 'event_espresso' |
|
221 | - ), |
|
222 | - __FILE__, |
|
223 | - __FUNCTION__, |
|
224 | - __LINE__ |
|
225 | - ); |
|
226 | - return; |
|
227 | - } |
|
228 | - // check for reg_url_link |
|
229 | - $this->_reg_url_link = EE_Registry::instance()->REQ->get('e_reg_url_link'); |
|
230 | - } |
|
231 | - |
|
232 | - |
|
233 | - /** |
|
234 | - * set_reg_url_link |
|
235 | - * |
|
236 | - * @param string $reg_url_link |
|
237 | - */ |
|
238 | - public function set_reg_url_link($reg_url_link = null) |
|
239 | - { |
|
240 | - $this->_reg_url_link = ! empty($reg_url_link) ? $reg_url_link : $this->_reg_url_link; |
|
241 | - } |
|
242 | - |
|
243 | - |
|
244 | - /** |
|
245 | - * run - initial module setup |
|
246 | - * this method is primarily used for activating resources in the EE_Front_Controller thru the use of filters |
|
247 | - * |
|
248 | - * @param WP $WP |
|
249 | - * @return void |
|
250 | - * @throws \EE_Error |
|
251 | - */ |
|
252 | - public function run($WP) |
|
253 | - { |
|
254 | - } |
|
255 | - |
|
256 | - |
|
257 | - /** |
|
258 | - * load_resources |
|
259 | - * |
|
260 | - * @return void |
|
261 | - * @throws \EE_Error |
|
262 | - */ |
|
263 | - public function load_resources() |
|
264 | - { |
|
265 | - $this->_get_reg_url_link(); |
|
266 | - // resend_reg_confirmation_email ? |
|
267 | - if (EE_Registry::instance()->REQ->is_set('resend')) { |
|
268 | - EED_Thank_You_Page::resend_reg_confirmation_email(); |
|
269 | - } |
|
270 | - EE_Registry::instance()->SSN->clear_session(__CLASS__, __FUNCTION__); |
|
271 | - $this->_translate_strings(); |
|
272 | - // load assets |
|
273 | - add_action('wp_enqueue_scripts', array($this, 'load_js'), 10); |
|
274 | - } |
|
275 | - |
|
276 | - |
|
277 | - /** |
|
278 | - * load_js |
|
279 | - * |
|
280 | - * @return void |
|
281 | - */ |
|
282 | - protected function _translate_strings() |
|
283 | - { |
|
284 | - EE_Registry::$i18n_js_strings['e_reg_url_link'] = $this->_reg_url_link; |
|
285 | - EE_Registry::$i18n_js_strings['initial_access'] = time(); |
|
286 | - EE_Registry::$i18n_js_strings['IPN_wait_time'] = EED_Thank_You_Page::IPN_wait_time; |
|
287 | - EE_Registry::$i18n_js_strings['TXN_complete'] = EEM_Transaction::complete_status_code; |
|
288 | - EE_Registry::$i18n_js_strings['TXN_incomplete'] = EEM_Transaction::incomplete_status_code; |
|
289 | - EE_Registry::$i18n_js_strings['checking_for_new_payments'] = __( |
|
290 | - 'checking for new payments...', |
|
291 | - 'event_espresso' |
|
292 | - ); |
|
293 | - EE_Registry::$i18n_js_strings['loading_payment_info'] = __( |
|
294 | - 'loading payment information...', |
|
295 | - 'event_espresso' |
|
296 | - ); |
|
297 | - EE_Registry::$i18n_js_strings['server_error'] = __( |
|
298 | - 'An unknown error occurred on the server while attempting to process your request. Please refresh the page and try again.', |
|
299 | - 'event_espresso' |
|
300 | - ); |
|
301 | - EE_Registry::$i18n_js_strings['slow_IPN'] = apply_filters( |
|
302 | - 'EED_Thank_You_Page__load_js__slow_IPN', |
|
303 | - sprintf( |
|
304 | - __( |
|
305 | - '%sThe Payment Notification appears to be taking longer than usual to arrive. Maybe check back later or just wait for your payment and registration confirmation results to be sent to you via email. We apologize for any inconvenience this may have caused.%s', |
|
306 | - 'event_espresso' |
|
307 | - ), |
|
308 | - '<div id="espresso-thank-you-page-slow-IPN-dv" class="ee-attention jst-left">', |
|
309 | - '</div>' |
|
310 | - ) |
|
311 | - ); |
|
312 | - } |
|
313 | - |
|
314 | - |
|
315 | - /** |
|
316 | - * load_js |
|
317 | - * |
|
318 | - * @return void |
|
319 | - */ |
|
320 | - public function load_js() |
|
321 | - { |
|
322 | - wp_register_script( |
|
323 | - 'thank_you_page', |
|
324 | - THANK_YOU_ASSETS_URL . 'thank_you_page.js', |
|
325 | - array('espresso_core', 'heartbeat'), |
|
326 | - EVENT_ESPRESSO_VERSION, |
|
327 | - true |
|
328 | - ); |
|
329 | - wp_enqueue_script('thank_you_page'); |
|
330 | - wp_enqueue_style('espresso_default'); |
|
331 | - } |
|
332 | - |
|
333 | - |
|
334 | - /** |
|
335 | - * init |
|
336 | - * |
|
337 | - * @return void |
|
338 | - * @throws \EE_Error |
|
339 | - */ |
|
340 | - public function init() |
|
341 | - { |
|
342 | - $this->_get_reg_url_link(); |
|
343 | - if (! $this->get_txn()) { |
|
344 | - echo EEH_HTML::div( |
|
345 | - EEH_HTML::h4(__('We\'re sorry...', 'event_espresso'), '', '') . |
|
346 | - sprintf( |
|
347 | - __( |
|
348 | - 'This is a system page for displaying transaction information after a purchase.%1$sYou are most likely seeing this notice because you have navigated to this page%1$sthrough some means other than completing a transaction.%1$sSorry for the disappointment, but you will most likely find nothing of interest here.%1$s%1$s', |
|
349 | - 'event_espresso' |
|
350 | - ), |
|
351 | - '<br/>' |
|
352 | - ), |
|
353 | - '', |
|
354 | - 'ee-attention' |
|
355 | - ); |
|
356 | - return null; |
|
357 | - } |
|
358 | - // if we've made it to the Thank You page, then let's toggle any "Failed" transactions to "Incomplete" |
|
359 | - if ($this->_current_txn->status_ID() === EEM_Transaction::failed_status_code) { |
|
360 | - $this->_current_txn->set_status(EEM_Transaction::incomplete_status_code); |
|
361 | - $this->_current_txn->save(); |
|
362 | - } |
|
363 | - $this->_primary_registrant = $this->_current_txn->primary_registration() instanceof EE_Registration |
|
364 | - ? $this->_current_txn->primary_registration() |
|
365 | - : null; |
|
366 | - $this->_is_primary = $this->_primary_registrant->reg_url_link() === $this->_reg_url_link ? true : false; |
|
367 | - $show_try_pay_again_link_default = apply_filters( |
|
368 | - 'AFEE__EED_Thank_You_Page__init__show_try_pay_again_link_default', |
|
369 | - true |
|
370 | - ); |
|
371 | - $this->_show_try_pay_again_link = $show_try_pay_again_link_default; |
|
372 | - // txn status ? |
|
373 | - if ($this->_current_txn->is_completed()) { |
|
374 | - $this->_show_try_pay_again_link = $show_try_pay_again_link_default; |
|
375 | - } elseif ( |
|
376 | - $this->_current_txn->is_incomplete() |
|
377 | - && ($this->_primary_registrant->is_approved() |
|
378 | - || $this->_primary_registrant->is_pending_payment()) |
|
379 | - ) { |
|
380 | - $this->_show_try_pay_again_link = true; |
|
381 | - } elseif ($this->_primary_registrant->is_approved() || $this->_primary_registrant->is_pending_payment()) { |
|
382 | - // its pending |
|
383 | - $this->_show_try_pay_again_link = isset( |
|
384 | - EE_Registry::instance()->CFG->registration->show_pending_payment_options |
|
385 | - ) |
|
386 | - && EE_Registry::instance()->CFG |
|
387 | - ->registration->show_pending_payment_options |
|
388 | - ? true |
|
389 | - : $show_try_pay_again_link_default; |
|
390 | - } |
|
391 | - $this->_payments_closed = ! $this->_current_txn->payment_method() instanceof EE_Payment_Method |
|
392 | - ? true |
|
393 | - : false; |
|
394 | - $this->_is_offline_payment_method = false; |
|
395 | - if ( |
|
13 | + /** |
|
14 | + * time in seconds to wait for the IPN to arrive before telling the registrant to bugger off ( 1200s = 20 minutes ) |
|
15 | + */ |
|
16 | + const IPN_wait_time = 1200; |
|
17 | + |
|
18 | + /** |
|
19 | + * The transaction specified by the reg_url_link passed from the Request, or from the Session |
|
20 | + * |
|
21 | + * @var EE_Transaction $_current_txn |
|
22 | + */ |
|
23 | + private $_current_txn; |
|
24 | + |
|
25 | + /** |
|
26 | + * @var EE_Registration $_primary_registrant |
|
27 | + */ |
|
28 | + private $_primary_registrant; |
|
29 | + |
|
30 | + /** |
|
31 | + * The reg_url_link passed from the Request, or from the Session |
|
32 | + * |
|
33 | + * @var string $_reg_url_link |
|
34 | + */ |
|
35 | + private $_reg_url_link; |
|
36 | + |
|
37 | + /** |
|
38 | + * whether the incoming reg_url_link is for the primary registrant or not |
|
39 | + * |
|
40 | + * @var boolean $_is_primary |
|
41 | + */ |
|
42 | + private $_is_primary; |
|
43 | + |
|
44 | + /** |
|
45 | + * The URL for revisiting the SPCO attendee information step |
|
46 | + * |
|
47 | + * @var string $_SPCO_attendee_information_url |
|
48 | + */ |
|
49 | + private $_SPCO_attendee_information_url; |
|
50 | + |
|
51 | + /** |
|
52 | + * The URL for revisiting the SPCO payment options step |
|
53 | + * |
|
54 | + * @var string $_SPCO_payment_options_url |
|
55 | + */ |
|
56 | + private $_SPCO_payment_options_url; |
|
57 | + |
|
58 | + /** |
|
59 | + * whether to display the Payment Options link |
|
60 | + * |
|
61 | + * @var boolean $_show_try_pay_again_link |
|
62 | + */ |
|
63 | + private $_show_try_pay_again_link = false; |
|
64 | + |
|
65 | + /** |
|
66 | + * whether payments are allowed at this time |
|
67 | + * |
|
68 | + * @var boolean $_payments_closed |
|
69 | + */ |
|
70 | + private $_payments_closed = false; |
|
71 | + |
|
72 | + /** |
|
73 | + * whether the selected payment method is Bank, Check , Invoice, etc |
|
74 | + * |
|
75 | + * @var boolean $_is_offline_payment_method |
|
76 | + */ |
|
77 | + private $_is_offline_payment_method = true; |
|
78 | + |
|
79 | + |
|
80 | + /** |
|
81 | + * @return EED_Module|EED_Thank_You_Page |
|
82 | + */ |
|
83 | + public static function instance() |
|
84 | + { |
|
85 | + return parent::get_instance(__CLASS__); |
|
86 | + } |
|
87 | + |
|
88 | + |
|
89 | + /** |
|
90 | + * set_hooks - for hooking into EE Core, modules, etc |
|
91 | + * |
|
92 | + * @return void |
|
93 | + */ |
|
94 | + public static function set_hooks() |
|
95 | + { |
|
96 | + add_action('wp_loaded', array('EED_Thank_You_Page', 'set_definitions'), 2); |
|
97 | + } |
|
98 | + |
|
99 | + |
|
100 | + /** |
|
101 | + * set_hooks_admin - for hooking into EE Admin Core, modules, etc |
|
102 | + * |
|
103 | + * @return void |
|
104 | + */ |
|
105 | + public static function set_hooks_admin() |
|
106 | + { |
|
107 | + add_action( |
|
108 | + 'wp_ajax_espresso_resend_reg_confirmation_email', |
|
109 | + array('EED_Thank_You_Page', 'resend_reg_confirmation_email'), |
|
110 | + 10, |
|
111 | + 2 |
|
112 | + ); |
|
113 | + add_action( |
|
114 | + 'wp_ajax_nopriv_espresso_resend_reg_confirmation_email', |
|
115 | + array('EED_Thank_You_Page', 'resend_reg_confirmation_email'), |
|
116 | + 10, |
|
117 | + 2 |
|
118 | + ); |
|
119 | + } |
|
120 | + |
|
121 | + |
|
122 | + /** |
|
123 | + * set_definitions |
|
124 | + * |
|
125 | + * @return void |
|
126 | + */ |
|
127 | + public static function set_definitions() |
|
128 | + { |
|
129 | + define('THANK_YOU_ASSETS_URL', plugin_dir_url(__FILE__) . 'assets/'); |
|
130 | + define('THANK_YOU_TEMPLATES_PATH', str_replace('\\', '/', plugin_dir_path(__FILE__)) . 'templates/'); |
|
131 | + } |
|
132 | + |
|
133 | + |
|
134 | + /** |
|
135 | + * get_txn |
|
136 | + * |
|
137 | + * @return EE_Transaction |
|
138 | + */ |
|
139 | + public function get_txn() |
|
140 | + { |
|
141 | + if ($this->_current_txn instanceof EE_Transaction) { |
|
142 | + return $this->_current_txn; |
|
143 | + } |
|
144 | + $TXN_model = EE_Registry::instance()->load_model('Transaction'); |
|
145 | + if (! $TXN_model instanceof EEM_Transaction) { |
|
146 | + EE_Error::add_error( |
|
147 | + __('The transaction model could not be established.', 'event_espresso'), |
|
148 | + __FILE__, |
|
149 | + __FUNCTION__, |
|
150 | + __LINE__ |
|
151 | + ); |
|
152 | + return null; |
|
153 | + } |
|
154 | + // get the transaction. yes, we may have just loaded it, but it may have been updated, or this may be via an ajax request |
|
155 | + $this->_current_txn = $TXN_model->get_transaction_from_reg_url_link($this->_reg_url_link); |
|
156 | + // verify TXN |
|
157 | + if (WP_DEBUG && ! $this->_current_txn instanceof EE_Transaction) { |
|
158 | + EE_Error::add_error( |
|
159 | + __( |
|
160 | + 'No transaction information could be retrieved or the transaction data is not of the correct type.', |
|
161 | + 'event_espresso' |
|
162 | + ), |
|
163 | + __FILE__, |
|
164 | + __FUNCTION__, |
|
165 | + __LINE__ |
|
166 | + ); |
|
167 | + return null; |
|
168 | + } |
|
169 | + return $this->_current_txn; |
|
170 | + } |
|
171 | + |
|
172 | + |
|
173 | + /** |
|
174 | + * get_txn_payments |
|
175 | + * |
|
176 | + * @param int $since |
|
177 | + * @return mixed array of EE_Payment || FALSE |
|
178 | + * @throws \EE_Error |
|
179 | + */ |
|
180 | + public function get_txn_payments($since = 0) |
|
181 | + { |
|
182 | + if (! $this->get_txn()) { |
|
183 | + return false; |
|
184 | + } |
|
185 | + $args = array('order_by' => array('PAY_timestamp' => 'ASC')); |
|
186 | + if ($since > 0) { |
|
187 | + $args[0] = array('PAY_timestamp' => array('>', $since)); |
|
188 | + } |
|
189 | + // get array of payments with most recent first |
|
190 | + return $this->_current_txn->payments($args); |
|
191 | + } |
|
192 | + |
|
193 | + |
|
194 | + /** |
|
195 | + * @return bool |
|
196 | + */ |
|
197 | + public function isOfflinePaymentMethod() |
|
198 | + { |
|
199 | + return $this->_is_offline_payment_method; |
|
200 | + } |
|
201 | + |
|
202 | + |
|
203 | + |
|
204 | + |
|
205 | + /** |
|
206 | + * get_reg_url_link |
|
207 | + * |
|
208 | + * @return void |
|
209 | + */ |
|
210 | + private function _get_reg_url_link() |
|
211 | + { |
|
212 | + if (! empty($this->_reg_url_link)) { |
|
213 | + return; |
|
214 | + } |
|
215 | + // only do thank you page stuff if we have a REG_url_link in the url |
|
216 | + if (WP_DEBUG && ! EE_Registry::instance()->REQ->is_set('e_reg_url_link')) { |
|
217 | + EE_Error::add_error( |
|
218 | + __( |
|
219 | + 'No transaction information could be retrieved because the registration URL link is missing or invalid.', |
|
220 | + 'event_espresso' |
|
221 | + ), |
|
222 | + __FILE__, |
|
223 | + __FUNCTION__, |
|
224 | + __LINE__ |
|
225 | + ); |
|
226 | + return; |
|
227 | + } |
|
228 | + // check for reg_url_link |
|
229 | + $this->_reg_url_link = EE_Registry::instance()->REQ->get('e_reg_url_link'); |
|
230 | + } |
|
231 | + |
|
232 | + |
|
233 | + /** |
|
234 | + * set_reg_url_link |
|
235 | + * |
|
236 | + * @param string $reg_url_link |
|
237 | + */ |
|
238 | + public function set_reg_url_link($reg_url_link = null) |
|
239 | + { |
|
240 | + $this->_reg_url_link = ! empty($reg_url_link) ? $reg_url_link : $this->_reg_url_link; |
|
241 | + } |
|
242 | + |
|
243 | + |
|
244 | + /** |
|
245 | + * run - initial module setup |
|
246 | + * this method is primarily used for activating resources in the EE_Front_Controller thru the use of filters |
|
247 | + * |
|
248 | + * @param WP $WP |
|
249 | + * @return void |
|
250 | + * @throws \EE_Error |
|
251 | + */ |
|
252 | + public function run($WP) |
|
253 | + { |
|
254 | + } |
|
255 | + |
|
256 | + |
|
257 | + /** |
|
258 | + * load_resources |
|
259 | + * |
|
260 | + * @return void |
|
261 | + * @throws \EE_Error |
|
262 | + */ |
|
263 | + public function load_resources() |
|
264 | + { |
|
265 | + $this->_get_reg_url_link(); |
|
266 | + // resend_reg_confirmation_email ? |
|
267 | + if (EE_Registry::instance()->REQ->is_set('resend')) { |
|
268 | + EED_Thank_You_Page::resend_reg_confirmation_email(); |
|
269 | + } |
|
270 | + EE_Registry::instance()->SSN->clear_session(__CLASS__, __FUNCTION__); |
|
271 | + $this->_translate_strings(); |
|
272 | + // load assets |
|
273 | + add_action('wp_enqueue_scripts', array($this, 'load_js'), 10); |
|
274 | + } |
|
275 | + |
|
276 | + |
|
277 | + /** |
|
278 | + * load_js |
|
279 | + * |
|
280 | + * @return void |
|
281 | + */ |
|
282 | + protected function _translate_strings() |
|
283 | + { |
|
284 | + EE_Registry::$i18n_js_strings['e_reg_url_link'] = $this->_reg_url_link; |
|
285 | + EE_Registry::$i18n_js_strings['initial_access'] = time(); |
|
286 | + EE_Registry::$i18n_js_strings['IPN_wait_time'] = EED_Thank_You_Page::IPN_wait_time; |
|
287 | + EE_Registry::$i18n_js_strings['TXN_complete'] = EEM_Transaction::complete_status_code; |
|
288 | + EE_Registry::$i18n_js_strings['TXN_incomplete'] = EEM_Transaction::incomplete_status_code; |
|
289 | + EE_Registry::$i18n_js_strings['checking_for_new_payments'] = __( |
|
290 | + 'checking for new payments...', |
|
291 | + 'event_espresso' |
|
292 | + ); |
|
293 | + EE_Registry::$i18n_js_strings['loading_payment_info'] = __( |
|
294 | + 'loading payment information...', |
|
295 | + 'event_espresso' |
|
296 | + ); |
|
297 | + EE_Registry::$i18n_js_strings['server_error'] = __( |
|
298 | + 'An unknown error occurred on the server while attempting to process your request. Please refresh the page and try again.', |
|
299 | + 'event_espresso' |
|
300 | + ); |
|
301 | + EE_Registry::$i18n_js_strings['slow_IPN'] = apply_filters( |
|
302 | + 'EED_Thank_You_Page__load_js__slow_IPN', |
|
303 | + sprintf( |
|
304 | + __( |
|
305 | + '%sThe Payment Notification appears to be taking longer than usual to arrive. Maybe check back later or just wait for your payment and registration confirmation results to be sent to you via email. We apologize for any inconvenience this may have caused.%s', |
|
306 | + 'event_espresso' |
|
307 | + ), |
|
308 | + '<div id="espresso-thank-you-page-slow-IPN-dv" class="ee-attention jst-left">', |
|
309 | + '</div>' |
|
310 | + ) |
|
311 | + ); |
|
312 | + } |
|
313 | + |
|
314 | + |
|
315 | + /** |
|
316 | + * load_js |
|
317 | + * |
|
318 | + * @return void |
|
319 | + */ |
|
320 | + public function load_js() |
|
321 | + { |
|
322 | + wp_register_script( |
|
323 | + 'thank_you_page', |
|
324 | + THANK_YOU_ASSETS_URL . 'thank_you_page.js', |
|
325 | + array('espresso_core', 'heartbeat'), |
|
326 | + EVENT_ESPRESSO_VERSION, |
|
327 | + true |
|
328 | + ); |
|
329 | + wp_enqueue_script('thank_you_page'); |
|
330 | + wp_enqueue_style('espresso_default'); |
|
331 | + } |
|
332 | + |
|
333 | + |
|
334 | + /** |
|
335 | + * init |
|
336 | + * |
|
337 | + * @return void |
|
338 | + * @throws \EE_Error |
|
339 | + */ |
|
340 | + public function init() |
|
341 | + { |
|
342 | + $this->_get_reg_url_link(); |
|
343 | + if (! $this->get_txn()) { |
|
344 | + echo EEH_HTML::div( |
|
345 | + EEH_HTML::h4(__('We\'re sorry...', 'event_espresso'), '', '') . |
|
346 | + sprintf( |
|
347 | + __( |
|
348 | + 'This is a system page for displaying transaction information after a purchase.%1$sYou are most likely seeing this notice because you have navigated to this page%1$sthrough some means other than completing a transaction.%1$sSorry for the disappointment, but you will most likely find nothing of interest here.%1$s%1$s', |
|
349 | + 'event_espresso' |
|
350 | + ), |
|
351 | + '<br/>' |
|
352 | + ), |
|
353 | + '', |
|
354 | + 'ee-attention' |
|
355 | + ); |
|
356 | + return null; |
|
357 | + } |
|
358 | + // if we've made it to the Thank You page, then let's toggle any "Failed" transactions to "Incomplete" |
|
359 | + if ($this->_current_txn->status_ID() === EEM_Transaction::failed_status_code) { |
|
360 | + $this->_current_txn->set_status(EEM_Transaction::incomplete_status_code); |
|
361 | + $this->_current_txn->save(); |
|
362 | + } |
|
363 | + $this->_primary_registrant = $this->_current_txn->primary_registration() instanceof EE_Registration |
|
364 | + ? $this->_current_txn->primary_registration() |
|
365 | + : null; |
|
366 | + $this->_is_primary = $this->_primary_registrant->reg_url_link() === $this->_reg_url_link ? true : false; |
|
367 | + $show_try_pay_again_link_default = apply_filters( |
|
368 | + 'AFEE__EED_Thank_You_Page__init__show_try_pay_again_link_default', |
|
369 | + true |
|
370 | + ); |
|
371 | + $this->_show_try_pay_again_link = $show_try_pay_again_link_default; |
|
372 | + // txn status ? |
|
373 | + if ($this->_current_txn->is_completed()) { |
|
374 | + $this->_show_try_pay_again_link = $show_try_pay_again_link_default; |
|
375 | + } elseif ( |
|
376 | + $this->_current_txn->is_incomplete() |
|
377 | + && ($this->_primary_registrant->is_approved() |
|
378 | + || $this->_primary_registrant->is_pending_payment()) |
|
379 | + ) { |
|
380 | + $this->_show_try_pay_again_link = true; |
|
381 | + } elseif ($this->_primary_registrant->is_approved() || $this->_primary_registrant->is_pending_payment()) { |
|
382 | + // its pending |
|
383 | + $this->_show_try_pay_again_link = isset( |
|
384 | + EE_Registry::instance()->CFG->registration->show_pending_payment_options |
|
385 | + ) |
|
386 | + && EE_Registry::instance()->CFG |
|
387 | + ->registration->show_pending_payment_options |
|
388 | + ? true |
|
389 | + : $show_try_pay_again_link_default; |
|
390 | + } |
|
391 | + $this->_payments_closed = ! $this->_current_txn->payment_method() instanceof EE_Payment_Method |
|
392 | + ? true |
|
393 | + : false; |
|
394 | + $this->_is_offline_payment_method = false; |
|
395 | + if ( |
|
396 | 396 | // if payment method is unknown |
397 | - ! $this->_current_txn->payment_method() instanceof EE_Payment_Method |
|
398 | - || ( |
|
399 | - // or is an offline payment method |
|
400 | - $this->_current_txn->payment_method() instanceof EE_Payment_Method |
|
401 | - && $this->_current_txn->payment_method()->is_off_line() |
|
402 | - ) |
|
403 | - ) { |
|
404 | - $this->_is_offline_payment_method = true; |
|
405 | - } |
|
406 | - // link to SPCO |
|
407 | - $revisit_spco_url = add_query_arg( |
|
408 | - array('ee' => '_register', 'revisit' => true, 'e_reg_url_link' => $this->_reg_url_link), |
|
409 | - EE_Registry::instance()->CFG->core->reg_page_url() |
|
410 | - ); |
|
411 | - // link to SPCO payment_options |
|
412 | - $this->_SPCO_payment_options_url = $this->_primary_registrant instanceof EE_Registration |
|
413 | - ? $this->_primary_registrant->payment_overview_url() |
|
414 | - : add_query_arg( |
|
415 | - array('step' => 'payment_options'), |
|
416 | - $revisit_spco_url |
|
417 | - ); |
|
418 | - // link to SPCO attendee_information |
|
419 | - $this->_SPCO_attendee_information_url = $this->_primary_registrant instanceof EE_Registration |
|
420 | - ? $this->_primary_registrant->edit_attendee_information_url() |
|
421 | - : false; |
|
422 | - do_action('AHEE__EED_Thank_You_Page__init_end', $this->_current_txn); |
|
423 | - // set no cache headers and constants |
|
424 | - EE_System::do_not_cache(); |
|
425 | - } |
|
426 | - |
|
427 | - |
|
428 | - /** |
|
429 | - * display_thank_you_page_results |
|
430 | - * |
|
431 | - * @return string |
|
432 | - * @throws \EE_Error |
|
433 | - */ |
|
434 | - public function thank_you_page_results() |
|
435 | - { |
|
436 | - $this->init(); |
|
437 | - if (! $this->_current_txn instanceof EE_Transaction) { |
|
438 | - return EE_Error::get_notices(); |
|
439 | - } |
|
440 | - // link to receipt |
|
441 | - $template_args['TXN_receipt_url'] = $this->_current_txn->receipt_url('html'); |
|
442 | - if (! empty($template_args['TXN_receipt_url'])) { |
|
443 | - $template_args['order_conf_desc'] = __( |
|
444 | - '%1$sCongratulations%2$sYour registration has been successfully processed.%3$sCheck your email for your registration confirmation or click the button below to view / download / print a full description of your purchases and registration information.', |
|
445 | - 'event_espresso' |
|
446 | - ); |
|
447 | - } else { |
|
448 | - $template_args['order_conf_desc'] = __( |
|
449 | - '%1$sCongratulations%2$sYour registration has been successfully processed.%3$sCheck your email for your registration confirmation.', |
|
450 | - 'event_espresso' |
|
451 | - ); |
|
452 | - } |
|
453 | - $template_args['transaction'] = $this->_current_txn; |
|
454 | - $template_args['revisit'] = EE_Registry::instance()->REQ->get('revisit', false); |
|
455 | - add_action('AHEE__thank_you_page_overview_template__content', array($this, 'get_registration_details')); |
|
456 | - if ($this->_is_primary && ! $this->_current_txn->is_free()) { |
|
457 | - add_action('AHEE__thank_you_page_overview_template__content', array($this, 'get_ajax_content')); |
|
458 | - } |
|
459 | - return EEH_Template::locate_template( |
|
460 | - THANK_YOU_TEMPLATES_PATH . 'thank-you-page-overview.template.php', |
|
461 | - $template_args, |
|
462 | - true, |
|
463 | - true |
|
464 | - ); |
|
465 | - } |
|
466 | - |
|
467 | - |
|
468 | - |
|
469 | - /** |
|
470 | - * _update_server_wait_time |
|
471 | - * |
|
472 | - * @param array $thank_you_page_data thank you page portion of the incoming JSON array from the WP heartbeat data |
|
473 | - * @return array |
|
474 | - * @throws \EE_Error |
|
475 | - */ |
|
476 | - private function _update_server_wait_time($thank_you_page_data = array()) |
|
477 | - { |
|
478 | - $response['espresso_thank_you_page'] = array( |
|
479 | - 'still_waiting' => isset($thank_you_page_data['initial_access']) |
|
480 | - ? time() - $thank_you_page_data['initial_access'] |
|
481 | - : 0, |
|
482 | - 'txn_status' => $this->_current_txn->status_ID(), |
|
483 | - ); |
|
484 | - return $response; |
|
485 | - } |
|
486 | - |
|
487 | - |
|
488 | - /** |
|
489 | - * get_registration_details |
|
490 | - * |
|
491 | - * @throws \EE_Error |
|
492 | - */ |
|
493 | - public function get_registration_details() |
|
494 | - { |
|
495 | - // prepare variables for displaying |
|
496 | - $template_args = array(); |
|
497 | - $template_args['transaction'] = $this->_current_txn; |
|
498 | - $template_args['reg_url_link'] = $this->_reg_url_link; |
|
499 | - $template_args['is_primary'] = $this->_is_primary; |
|
500 | - $template_args['SPCO_attendee_information_url'] = $this->_SPCO_attendee_information_url; |
|
501 | - $template_args['resend_reg_confirmation_url'] = add_query_arg( |
|
502 | - array('token' => $this->_reg_url_link, 'resend_reg_confirmation' => 'true'), |
|
503 | - EE_Registry::instance()->CFG->core->thank_you_page_url() |
|
504 | - ); |
|
505 | - // verify template arguments |
|
506 | - EEH_Template_Validator::verify_instanceof($template_args['transaction'], '$transaction', 'EE_Transaction'); |
|
507 | - EEH_Template_Validator::verify_isnt_null( |
|
508 | - $template_args['SPCO_attendee_information_url'], |
|
509 | - '$SPCO_attendee_information_url' |
|
510 | - ); |
|
511 | - echo EEH_Template::locate_template( |
|
512 | - THANK_YOU_TEMPLATES_PATH . 'thank-you-page-registration-details.template.php', |
|
513 | - $template_args, |
|
514 | - true, |
|
515 | - true |
|
516 | - ); |
|
517 | - } |
|
518 | - |
|
519 | - |
|
520 | - /** |
|
521 | - * resend_reg_confirmation_email |
|
522 | - * |
|
523 | - * @throws \EE_Error |
|
524 | - */ |
|
525 | - public static function resend_reg_confirmation_email() |
|
526 | - { |
|
527 | - EE_Registry::instance()->load_core('Request_Handler'); |
|
528 | - $reg_url_link = EE_Registry::instance()->REQ->get('token'); |
|
529 | - // was a REG_ID passed ? |
|
530 | - if ($reg_url_link) { |
|
531 | - $registration = EE_Registry::instance()->load_model('Registration')->get_one( |
|
532 | - array(array('REG_url_link' => $reg_url_link)) |
|
533 | - ); |
|
534 | - if ($registration instanceof EE_Registration) { |
|
535 | - // resend email |
|
536 | - EED_Messages::process_resend(array('_REG_ID' => $registration->ID())); |
|
537 | - } else { |
|
538 | - EE_Error::add_error( |
|
539 | - __( |
|
540 | - 'The Registration Confirmation email could not be sent because a valid Registration could not be retrieved from the database.', |
|
541 | - 'event_espresso' |
|
542 | - ), |
|
543 | - __FILE__, |
|
544 | - __FUNCTION__, |
|
545 | - __LINE__ |
|
546 | - ); |
|
547 | - } |
|
548 | - } else { |
|
549 | - EE_Error::add_error( |
|
550 | - __( |
|
551 | - 'The Registration Confirmation email could not be sent because a registration token is missing or invalid.', |
|
552 | - 'event_espresso' |
|
553 | - ), |
|
554 | - __FILE__, |
|
555 | - __FUNCTION__, |
|
556 | - __LINE__ |
|
557 | - ); |
|
558 | - } |
|
559 | - // request sent via AJAX ? |
|
560 | - if (EE_FRONT_AJAX) { |
|
561 | - echo wp_json_encode(EE_Error::get_notices(false)); |
|
562 | - die(); |
|
563 | - // or was JS disabled ? |
|
564 | - } else { |
|
565 | - // save errors so that they get picked up on the next request |
|
566 | - EE_Error::get_notices(true, true); |
|
567 | - wp_safe_redirect( |
|
568 | - add_query_arg( |
|
569 | - array('e_reg_url_link' => $reg_url_link), |
|
570 | - EE_Registry::instance()->CFG->core->thank_you_page_url() |
|
571 | - ) |
|
572 | - ); |
|
573 | - } |
|
574 | - } |
|
575 | - |
|
576 | - |
|
577 | - /** |
|
578 | - * get_ajax_content |
|
579 | - * |
|
580 | - * @return void |
|
581 | - * @throws \EE_Error |
|
582 | - */ |
|
583 | - public function get_ajax_content() |
|
584 | - { |
|
585 | - if (! $this->get_txn()) { |
|
586 | - return; |
|
587 | - } |
|
588 | - // first determine which event(s) require pre-approval or not |
|
589 | - $events = array(); |
|
590 | - $events_requiring_pre_approval = array(); |
|
591 | - foreach ($this->_current_txn->registrations() as $registration) { |
|
592 | - if ($registration instanceof EE_Registration) { |
|
593 | - $event = $registration->event(); |
|
594 | - if ($event instanceof EE_Event) { |
|
595 | - if ($registration->is_not_approved() && $registration->event() instanceof EE_Event) { |
|
596 | - $events_requiring_pre_approval[ $event->ID() ] = $event; |
|
597 | - } else { |
|
598 | - $events[ $event->ID() ] = $event; |
|
599 | - } |
|
600 | - } |
|
601 | - } |
|
602 | - } |
|
603 | - $this->display_details_for_events_requiring_pre_approval($events_requiring_pre_approval); |
|
604 | - $this->display_details_for_events($events); |
|
605 | - } |
|
606 | - |
|
607 | - |
|
608 | - /** |
|
609 | - * display_details_for_events |
|
610 | - * |
|
611 | - * @param EE_Event[] $events |
|
612 | - * @return void |
|
613 | - */ |
|
614 | - public function display_details_for_events($events = array()) |
|
615 | - { |
|
616 | - if (! empty($events)) { |
|
617 | - ?> |
|
397 | + ! $this->_current_txn->payment_method() instanceof EE_Payment_Method |
|
398 | + || ( |
|
399 | + // or is an offline payment method |
|
400 | + $this->_current_txn->payment_method() instanceof EE_Payment_Method |
|
401 | + && $this->_current_txn->payment_method()->is_off_line() |
|
402 | + ) |
|
403 | + ) { |
|
404 | + $this->_is_offline_payment_method = true; |
|
405 | + } |
|
406 | + // link to SPCO |
|
407 | + $revisit_spco_url = add_query_arg( |
|
408 | + array('ee' => '_register', 'revisit' => true, 'e_reg_url_link' => $this->_reg_url_link), |
|
409 | + EE_Registry::instance()->CFG->core->reg_page_url() |
|
410 | + ); |
|
411 | + // link to SPCO payment_options |
|
412 | + $this->_SPCO_payment_options_url = $this->_primary_registrant instanceof EE_Registration |
|
413 | + ? $this->_primary_registrant->payment_overview_url() |
|
414 | + : add_query_arg( |
|
415 | + array('step' => 'payment_options'), |
|
416 | + $revisit_spco_url |
|
417 | + ); |
|
418 | + // link to SPCO attendee_information |
|
419 | + $this->_SPCO_attendee_information_url = $this->_primary_registrant instanceof EE_Registration |
|
420 | + ? $this->_primary_registrant->edit_attendee_information_url() |
|
421 | + : false; |
|
422 | + do_action('AHEE__EED_Thank_You_Page__init_end', $this->_current_txn); |
|
423 | + // set no cache headers and constants |
|
424 | + EE_System::do_not_cache(); |
|
425 | + } |
|
426 | + |
|
427 | + |
|
428 | + /** |
|
429 | + * display_thank_you_page_results |
|
430 | + * |
|
431 | + * @return string |
|
432 | + * @throws \EE_Error |
|
433 | + */ |
|
434 | + public function thank_you_page_results() |
|
435 | + { |
|
436 | + $this->init(); |
|
437 | + if (! $this->_current_txn instanceof EE_Transaction) { |
|
438 | + return EE_Error::get_notices(); |
|
439 | + } |
|
440 | + // link to receipt |
|
441 | + $template_args['TXN_receipt_url'] = $this->_current_txn->receipt_url('html'); |
|
442 | + if (! empty($template_args['TXN_receipt_url'])) { |
|
443 | + $template_args['order_conf_desc'] = __( |
|
444 | + '%1$sCongratulations%2$sYour registration has been successfully processed.%3$sCheck your email for your registration confirmation or click the button below to view / download / print a full description of your purchases and registration information.', |
|
445 | + 'event_espresso' |
|
446 | + ); |
|
447 | + } else { |
|
448 | + $template_args['order_conf_desc'] = __( |
|
449 | + '%1$sCongratulations%2$sYour registration has been successfully processed.%3$sCheck your email for your registration confirmation.', |
|
450 | + 'event_espresso' |
|
451 | + ); |
|
452 | + } |
|
453 | + $template_args['transaction'] = $this->_current_txn; |
|
454 | + $template_args['revisit'] = EE_Registry::instance()->REQ->get('revisit', false); |
|
455 | + add_action('AHEE__thank_you_page_overview_template__content', array($this, 'get_registration_details')); |
|
456 | + if ($this->_is_primary && ! $this->_current_txn->is_free()) { |
|
457 | + add_action('AHEE__thank_you_page_overview_template__content', array($this, 'get_ajax_content')); |
|
458 | + } |
|
459 | + return EEH_Template::locate_template( |
|
460 | + THANK_YOU_TEMPLATES_PATH . 'thank-you-page-overview.template.php', |
|
461 | + $template_args, |
|
462 | + true, |
|
463 | + true |
|
464 | + ); |
|
465 | + } |
|
466 | + |
|
467 | + |
|
468 | + |
|
469 | + /** |
|
470 | + * _update_server_wait_time |
|
471 | + * |
|
472 | + * @param array $thank_you_page_data thank you page portion of the incoming JSON array from the WP heartbeat data |
|
473 | + * @return array |
|
474 | + * @throws \EE_Error |
|
475 | + */ |
|
476 | + private function _update_server_wait_time($thank_you_page_data = array()) |
|
477 | + { |
|
478 | + $response['espresso_thank_you_page'] = array( |
|
479 | + 'still_waiting' => isset($thank_you_page_data['initial_access']) |
|
480 | + ? time() - $thank_you_page_data['initial_access'] |
|
481 | + : 0, |
|
482 | + 'txn_status' => $this->_current_txn->status_ID(), |
|
483 | + ); |
|
484 | + return $response; |
|
485 | + } |
|
486 | + |
|
487 | + |
|
488 | + /** |
|
489 | + * get_registration_details |
|
490 | + * |
|
491 | + * @throws \EE_Error |
|
492 | + */ |
|
493 | + public function get_registration_details() |
|
494 | + { |
|
495 | + // prepare variables for displaying |
|
496 | + $template_args = array(); |
|
497 | + $template_args['transaction'] = $this->_current_txn; |
|
498 | + $template_args['reg_url_link'] = $this->_reg_url_link; |
|
499 | + $template_args['is_primary'] = $this->_is_primary; |
|
500 | + $template_args['SPCO_attendee_information_url'] = $this->_SPCO_attendee_information_url; |
|
501 | + $template_args['resend_reg_confirmation_url'] = add_query_arg( |
|
502 | + array('token' => $this->_reg_url_link, 'resend_reg_confirmation' => 'true'), |
|
503 | + EE_Registry::instance()->CFG->core->thank_you_page_url() |
|
504 | + ); |
|
505 | + // verify template arguments |
|
506 | + EEH_Template_Validator::verify_instanceof($template_args['transaction'], '$transaction', 'EE_Transaction'); |
|
507 | + EEH_Template_Validator::verify_isnt_null( |
|
508 | + $template_args['SPCO_attendee_information_url'], |
|
509 | + '$SPCO_attendee_information_url' |
|
510 | + ); |
|
511 | + echo EEH_Template::locate_template( |
|
512 | + THANK_YOU_TEMPLATES_PATH . 'thank-you-page-registration-details.template.php', |
|
513 | + $template_args, |
|
514 | + true, |
|
515 | + true |
|
516 | + ); |
|
517 | + } |
|
518 | + |
|
519 | + |
|
520 | + /** |
|
521 | + * resend_reg_confirmation_email |
|
522 | + * |
|
523 | + * @throws \EE_Error |
|
524 | + */ |
|
525 | + public static function resend_reg_confirmation_email() |
|
526 | + { |
|
527 | + EE_Registry::instance()->load_core('Request_Handler'); |
|
528 | + $reg_url_link = EE_Registry::instance()->REQ->get('token'); |
|
529 | + // was a REG_ID passed ? |
|
530 | + if ($reg_url_link) { |
|
531 | + $registration = EE_Registry::instance()->load_model('Registration')->get_one( |
|
532 | + array(array('REG_url_link' => $reg_url_link)) |
|
533 | + ); |
|
534 | + if ($registration instanceof EE_Registration) { |
|
535 | + // resend email |
|
536 | + EED_Messages::process_resend(array('_REG_ID' => $registration->ID())); |
|
537 | + } else { |
|
538 | + EE_Error::add_error( |
|
539 | + __( |
|
540 | + 'The Registration Confirmation email could not be sent because a valid Registration could not be retrieved from the database.', |
|
541 | + 'event_espresso' |
|
542 | + ), |
|
543 | + __FILE__, |
|
544 | + __FUNCTION__, |
|
545 | + __LINE__ |
|
546 | + ); |
|
547 | + } |
|
548 | + } else { |
|
549 | + EE_Error::add_error( |
|
550 | + __( |
|
551 | + 'The Registration Confirmation email could not be sent because a registration token is missing or invalid.', |
|
552 | + 'event_espresso' |
|
553 | + ), |
|
554 | + __FILE__, |
|
555 | + __FUNCTION__, |
|
556 | + __LINE__ |
|
557 | + ); |
|
558 | + } |
|
559 | + // request sent via AJAX ? |
|
560 | + if (EE_FRONT_AJAX) { |
|
561 | + echo wp_json_encode(EE_Error::get_notices(false)); |
|
562 | + die(); |
|
563 | + // or was JS disabled ? |
|
564 | + } else { |
|
565 | + // save errors so that they get picked up on the next request |
|
566 | + EE_Error::get_notices(true, true); |
|
567 | + wp_safe_redirect( |
|
568 | + add_query_arg( |
|
569 | + array('e_reg_url_link' => $reg_url_link), |
|
570 | + EE_Registry::instance()->CFG->core->thank_you_page_url() |
|
571 | + ) |
|
572 | + ); |
|
573 | + } |
|
574 | + } |
|
575 | + |
|
576 | + |
|
577 | + /** |
|
578 | + * get_ajax_content |
|
579 | + * |
|
580 | + * @return void |
|
581 | + * @throws \EE_Error |
|
582 | + */ |
|
583 | + public function get_ajax_content() |
|
584 | + { |
|
585 | + if (! $this->get_txn()) { |
|
586 | + return; |
|
587 | + } |
|
588 | + // first determine which event(s) require pre-approval or not |
|
589 | + $events = array(); |
|
590 | + $events_requiring_pre_approval = array(); |
|
591 | + foreach ($this->_current_txn->registrations() as $registration) { |
|
592 | + if ($registration instanceof EE_Registration) { |
|
593 | + $event = $registration->event(); |
|
594 | + if ($event instanceof EE_Event) { |
|
595 | + if ($registration->is_not_approved() && $registration->event() instanceof EE_Event) { |
|
596 | + $events_requiring_pre_approval[ $event->ID() ] = $event; |
|
597 | + } else { |
|
598 | + $events[ $event->ID() ] = $event; |
|
599 | + } |
|
600 | + } |
|
601 | + } |
|
602 | + } |
|
603 | + $this->display_details_for_events_requiring_pre_approval($events_requiring_pre_approval); |
|
604 | + $this->display_details_for_events($events); |
|
605 | + } |
|
606 | + |
|
607 | + |
|
608 | + /** |
|
609 | + * display_details_for_events |
|
610 | + * |
|
611 | + * @param EE_Event[] $events |
|
612 | + * @return void |
|
613 | + */ |
|
614 | + public function display_details_for_events($events = array()) |
|
615 | + { |
|
616 | + if (! empty($events)) { |
|
617 | + ?> |
|
618 | 618 | <div id="espresso-thank-you-page-ajax-content-dv"> |
619 | 619 | <div id="espresso-thank-you-page-ajax-transaction-dv"></div> |
620 | 620 | <div id="espresso-thank-you-page-ajax-payment-dv"></div> |
@@ -622,19 +622,19 @@ discard block |
||
622 | 622 | <div id="ee-ajax-loading-dv" class="float-left lt-blue-text"> |
623 | 623 | <span class="dashicons dashicons-upload"></span><span id="ee-ajax-loading-msg-spn"> |
624 | 624 | <?php _e( |
625 | - 'loading transaction and payment information...', |
|
626 | - 'event_espresso' |
|
627 | - ); ?></span> |
|
625 | + 'loading transaction and payment information...', |
|
626 | + 'event_espresso' |
|
627 | + ); ?></span> |
|
628 | 628 | </div> |
629 | 629 | <?php if (! $this->_is_offline_payment_method && ! $this->_payments_closed) : ?> |
630 | 630 | <p id="ee-ajax-loading-pg" class="highlight-bg small-text clear"> |
631 | 631 | <?php echo apply_filters( |
632 | - 'EED_Thank_You_Page__get_ajax_content__waiting_for_IPN_msg', |
|
633 | - __( |
|
634 | - 'Some payment gateways can take 15 minutes or more to return their payment notification, so please be patient if you require payment confirmation as soon as possible. Please note that as soon as everything is finalized, we will send your full payment and registration confirmation results to you via email.', |
|
635 | - 'event_espresso' |
|
636 | - ) |
|
637 | - ); ?> |
|
632 | + 'EED_Thank_You_Page__get_ajax_content__waiting_for_IPN_msg', |
|
633 | + __( |
|
634 | + 'Some payment gateways can take 15 minutes or more to return their payment notification, so please be patient if you require payment confirmation as soon as possible. Please note that as soon as everything is finalized, we will send your full payment and registration confirmation results to you via email.', |
|
635 | + 'event_espresso' |
|
636 | + ) |
|
637 | + ); ?> |
|
638 | 638 | <br/> |
639 | 639 | <span class="jst-rght ee-block small-text lt-grey-text"> |
640 | 640 | <?php _e('current wait time ', 'event_espresso'); ?> |
@@ -645,118 +645,118 @@ discard block |
||
645 | 645 | <div class="clear"></div> |
646 | 646 | </div> |
647 | 647 | <?php |
648 | - } |
|
649 | - } |
|
650 | - |
|
651 | - |
|
652 | - /** |
|
653 | - * display_details_for_events_requiring_pre_approval |
|
654 | - * |
|
655 | - * @param EE_Event[] $events |
|
656 | - * @return void |
|
657 | - */ |
|
658 | - public function display_details_for_events_requiring_pre_approval($events = array()) |
|
659 | - { |
|
660 | - if (! empty($events)) { |
|
661 | - ?> |
|
648 | + } |
|
649 | + } |
|
650 | + |
|
651 | + |
|
652 | + /** |
|
653 | + * display_details_for_events_requiring_pre_approval |
|
654 | + * |
|
655 | + * @param EE_Event[] $events |
|
656 | + * @return void |
|
657 | + */ |
|
658 | + public function display_details_for_events_requiring_pre_approval($events = array()) |
|
659 | + { |
|
660 | + if (! empty($events)) { |
|
661 | + ?> |
|
662 | 662 | <div id="espresso-thank-you-page-not-approved-message-dv"> |
663 | 663 | <h4 class="orange-text"><?php _e('Important Notice:', 'event_espresso'); ?></h4> |
664 | 664 | <p id="events-requiring-pre-approval-pg" class="small-text"> |
665 | 665 | <?php echo apply_filters( |
666 | - 'AHEE__EED_Thank_You_Page__get_ajax_content__not_approved_message', |
|
667 | - __( |
|
668 | - 'The following Event(s) you have registered for do not require payment at this time and will not be billed for during this transaction. Billing will only occur after all attendees have been approved by the event organizer. You will be notified when your registration has been processed. If this is a free event, then no billing will occur.', |
|
669 | - 'event_espresso' |
|
670 | - ) |
|
671 | - ); ?> |
|
666 | + 'AHEE__EED_Thank_You_Page__get_ajax_content__not_approved_message', |
|
667 | + __( |
|
668 | + 'The following Event(s) you have registered for do not require payment at this time and will not be billed for during this transaction. Billing will only occur after all attendees have been approved by the event organizer. You will be notified when your registration has been processed. If this is a free event, then no billing will occur.', |
|
669 | + 'event_espresso' |
|
670 | + ) |
|
671 | + ); ?> |
|
672 | 672 | </p> |
673 | 673 | <ul class="events-requiring-pre-approval-ul"> |
674 | 674 | <?php |
675 | - foreach ($events as $event) { |
|
676 | - if ($event instanceof EE_Event) { |
|
677 | - echo '<li><span class="dashicons dashicons-marker ee-icon-size-16 orange-text"></span>', |
|
678 | - $event->name(), |
|
679 | - '</li>'; |
|
680 | - } |
|
681 | - } ?> |
|
675 | + foreach ($events as $event) { |
|
676 | + if ($event instanceof EE_Event) { |
|
677 | + echo '<li><span class="dashicons dashicons-marker ee-icon-size-16 orange-text"></span>', |
|
678 | + $event->name(), |
|
679 | + '</li>'; |
|
680 | + } |
|
681 | + } ?> |
|
682 | 682 | </ul> |
683 | 683 | <div class="clear"></div> |
684 | 684 | </div> |
685 | 685 | <?php |
686 | - } |
|
687 | - } |
|
688 | - |
|
689 | - |
|
690 | - /** |
|
691 | - * get_transaction_details |
|
692 | - * |
|
693 | - * @return string |
|
694 | - * @throws \EE_Error |
|
695 | - */ |
|
696 | - public function get_transaction_details() |
|
697 | - { |
|
698 | - // prepare variables for displaying |
|
699 | - $template_args = array(); |
|
700 | - $template_args['transaction'] = $this->_current_txn; |
|
701 | - $template_args['reg_url_link'] = $this->_reg_url_link; |
|
702 | - $template_args['primary_registrant_name'] = $this->_primary_registrant->attendee()->full_name(true); |
|
703 | - // link to SPCO payment_options |
|
704 | - $template_args['show_try_pay_again_link'] = $this->_show_try_pay_again_link; |
|
705 | - $template_args['SPCO_payment_options_url'] = $this->_SPCO_payment_options_url; |
|
706 | - // verify template arguments |
|
707 | - EEH_Template_Validator::verify_instanceof($template_args['transaction'], '$transaction', 'EE_Transaction'); |
|
708 | - EEH_Template_Validator::verify_isnt_null( |
|
709 | - $template_args['show_try_pay_again_link'], |
|
710 | - '$show_try_pay_again_link' |
|
711 | - ); |
|
712 | - EEH_Template_Validator::verify_isnt_null( |
|
713 | - $template_args['SPCO_payment_options_url'], |
|
714 | - '$SPCO_payment_options_url' |
|
715 | - ); |
|
716 | - return EEH_Template::locate_template( |
|
717 | - THANK_YOU_TEMPLATES_PATH . 'thank-you-page-transaction-details.template.php', |
|
718 | - $template_args, |
|
719 | - true, |
|
720 | - true |
|
721 | - ); |
|
722 | - } |
|
723 | - |
|
724 | - |
|
725 | - /** |
|
726 | - * get_payment_row_html |
|
727 | - * |
|
728 | - * @param EE_Payment $payment |
|
729 | - * @return string |
|
730 | - * @throws \EE_Error |
|
731 | - */ |
|
732 | - public function get_payment_row_html($payment = null) |
|
733 | - { |
|
734 | - $html = ''; |
|
735 | - if ($payment instanceof EE_Payment) { |
|
736 | - if ( |
|
737 | - $payment->payment_method() instanceof EE_Payment_Method |
|
738 | - && $payment->status() === EEM_Payment::status_id_failed |
|
739 | - && $payment->payment_method()->is_off_site() |
|
740 | - ) { |
|
741 | - // considering the registrant has made it to the Thank You page, |
|
742 | - // any failed payments may actually be pending and the IPN is just slow |
|
743 | - // so let's |
|
744 | - $payment->set_status(EEM_Payment::status_id_pending); |
|
745 | - } |
|
746 | - $payment_declined_msg = $payment->STS_ID() === EEM_Payment::status_id_declined |
|
747 | - ? '<br /><span class="small-text">' . $payment->gateway_response() . '</span>' |
|
748 | - : ''; |
|
749 | - $html .= ' |
|
686 | + } |
|
687 | + } |
|
688 | + |
|
689 | + |
|
690 | + /** |
|
691 | + * get_transaction_details |
|
692 | + * |
|
693 | + * @return string |
|
694 | + * @throws \EE_Error |
|
695 | + */ |
|
696 | + public function get_transaction_details() |
|
697 | + { |
|
698 | + // prepare variables for displaying |
|
699 | + $template_args = array(); |
|
700 | + $template_args['transaction'] = $this->_current_txn; |
|
701 | + $template_args['reg_url_link'] = $this->_reg_url_link; |
|
702 | + $template_args['primary_registrant_name'] = $this->_primary_registrant->attendee()->full_name(true); |
|
703 | + // link to SPCO payment_options |
|
704 | + $template_args['show_try_pay_again_link'] = $this->_show_try_pay_again_link; |
|
705 | + $template_args['SPCO_payment_options_url'] = $this->_SPCO_payment_options_url; |
|
706 | + // verify template arguments |
|
707 | + EEH_Template_Validator::verify_instanceof($template_args['transaction'], '$transaction', 'EE_Transaction'); |
|
708 | + EEH_Template_Validator::verify_isnt_null( |
|
709 | + $template_args['show_try_pay_again_link'], |
|
710 | + '$show_try_pay_again_link' |
|
711 | + ); |
|
712 | + EEH_Template_Validator::verify_isnt_null( |
|
713 | + $template_args['SPCO_payment_options_url'], |
|
714 | + '$SPCO_payment_options_url' |
|
715 | + ); |
|
716 | + return EEH_Template::locate_template( |
|
717 | + THANK_YOU_TEMPLATES_PATH . 'thank-you-page-transaction-details.template.php', |
|
718 | + $template_args, |
|
719 | + true, |
|
720 | + true |
|
721 | + ); |
|
722 | + } |
|
723 | + |
|
724 | + |
|
725 | + /** |
|
726 | + * get_payment_row_html |
|
727 | + * |
|
728 | + * @param EE_Payment $payment |
|
729 | + * @return string |
|
730 | + * @throws \EE_Error |
|
731 | + */ |
|
732 | + public function get_payment_row_html($payment = null) |
|
733 | + { |
|
734 | + $html = ''; |
|
735 | + if ($payment instanceof EE_Payment) { |
|
736 | + if ( |
|
737 | + $payment->payment_method() instanceof EE_Payment_Method |
|
738 | + && $payment->status() === EEM_Payment::status_id_failed |
|
739 | + && $payment->payment_method()->is_off_site() |
|
740 | + ) { |
|
741 | + // considering the registrant has made it to the Thank You page, |
|
742 | + // any failed payments may actually be pending and the IPN is just slow |
|
743 | + // so let's |
|
744 | + $payment->set_status(EEM_Payment::status_id_pending); |
|
745 | + } |
|
746 | + $payment_declined_msg = $payment->STS_ID() === EEM_Payment::status_id_declined |
|
747 | + ? '<br /><span class="small-text">' . $payment->gateway_response() . '</span>' |
|
748 | + : ''; |
|
749 | + $html .= ' |
|
750 | 750 | <tr> |
751 | 751 | <td> |
752 | 752 | ' . $payment->timestamp() . ' |
753 | 753 | </td> |
754 | 754 | <td> |
755 | 755 | ' . ( |
756 | - $payment->payment_method() instanceof EE_Payment_Method |
|
757 | - ? $payment->payment_method()->name() |
|
758 | - : __('Unknown', 'event_espresso') |
|
759 | - ) . ' |
|
756 | + $payment->payment_method() instanceof EE_Payment_Method |
|
757 | + ? $payment->payment_method()->name() |
|
758 | + : __('Unknown', 'event_espresso') |
|
759 | + ) . ' |
|
760 | 760 | </td> |
761 | 761 | <td class="jst-rght"> |
762 | 762 | ' . EEH_Template::format_currency($payment->amount()) . ' |
@@ -765,83 +765,83 @@ discard block |
||
765 | 765 | ' . $payment->pretty_status(true) . $payment_declined_msg . ' |
766 | 766 | </td> |
767 | 767 | </tr>'; |
768 | - do_action('AHEE__thank_you_page_payment_details_template__after_each_payment', $payment); |
|
769 | - } |
|
770 | - return $html; |
|
771 | - } |
|
772 | - |
|
773 | - |
|
774 | - /** |
|
775 | - * get_payment_details |
|
776 | - * |
|
777 | - * @param array $payments |
|
778 | - * @return string |
|
779 | - * @throws \EE_Error |
|
780 | - */ |
|
781 | - public function get_payment_details($payments = array()) |
|
782 | - { |
|
783 | - // prepare variables for displaying |
|
784 | - $template_args = array(); |
|
785 | - $template_args['transaction'] = $this->_current_txn; |
|
786 | - $template_args['reg_url_link'] = $this->_reg_url_link; |
|
787 | - $template_args['payments'] = array(); |
|
788 | - foreach ($payments as $payment) { |
|
789 | - $template_args['payments'][] = $this->get_payment_row_html($payment); |
|
790 | - } |
|
791 | - // create a hacky payment object, but dont save it |
|
792 | - $payment = EE_Payment::new_instance( |
|
793 | - array( |
|
794 | - 'TXN_ID' => $this->_current_txn->ID(), |
|
795 | - 'STS_ID' => EEM_Payment::status_id_pending, |
|
796 | - 'PAY_timestamp' => time(), |
|
797 | - 'PAY_amount' => $this->_current_txn->total(), |
|
798 | - 'PMD_ID' => $this->_current_txn->payment_method_ID(), |
|
799 | - ) |
|
800 | - ); |
|
801 | - $payment_method = $this->_current_txn->payment_method(); |
|
802 | - if ($payment_method instanceof EE_Payment_Method && $payment_method->type_obj() instanceof EE_PMT_Base) { |
|
803 | - $template_args['gateway_content'] = $payment_method->type_obj()->payment_overview_content($payment); |
|
804 | - } else { |
|
805 | - $template_args['gateway_content'] = ''; |
|
806 | - } |
|
807 | - // link to SPCO payment_options |
|
808 | - $template_args['show_try_pay_again_link'] = $this->_show_try_pay_again_link; |
|
809 | - $template_args['SPCO_payment_options_url'] = $this->_SPCO_payment_options_url; |
|
810 | - // verify template arguments |
|
811 | - EEH_Template_Validator::verify_instanceof($template_args['transaction'], '$transaction', 'EE_Transaction'); |
|
812 | - EEH_Template_Validator::verify_isnt_null($template_args['payments'], '$payments'); |
|
813 | - EEH_Template_Validator::verify_isnt_null( |
|
814 | - $template_args['show_try_pay_again_link'], |
|
815 | - '$show_try_pay_again_link' |
|
816 | - ); |
|
817 | - EEH_Template_Validator::verify_isnt_null($template_args['gateway_content'], '$gateway_content'); |
|
818 | - EEH_Template_Validator::verify_isnt_null( |
|
819 | - $template_args['SPCO_payment_options_url'], |
|
820 | - '$SPCO_payment_options_url' |
|
821 | - ); |
|
822 | - return EEH_Template::locate_template( |
|
823 | - THANK_YOU_TEMPLATES_PATH . 'thank-you-page-payment-details.template.php', |
|
824 | - $template_args, |
|
825 | - true, |
|
826 | - true |
|
827 | - ); |
|
828 | - } |
|
829 | - |
|
830 | - |
|
831 | - /** |
|
832 | - * get_payment_details |
|
833 | - * |
|
834 | - * @param array $payments |
|
835 | - * @return string |
|
836 | - * @throws \EE_Error |
|
837 | - */ |
|
838 | - public function get_new_payments($payments = array()) |
|
839 | - { |
|
840 | - $payments_html = ''; |
|
841 | - // prepare variables for displaying |
|
842 | - foreach ($payments as $payment) { |
|
843 | - $payments_html .= $this->get_payment_row_html($payment); |
|
844 | - } |
|
845 | - return $payments_html; |
|
846 | - } |
|
768 | + do_action('AHEE__thank_you_page_payment_details_template__after_each_payment', $payment); |
|
769 | + } |
|
770 | + return $html; |
|
771 | + } |
|
772 | + |
|
773 | + |
|
774 | + /** |
|
775 | + * get_payment_details |
|
776 | + * |
|
777 | + * @param array $payments |
|
778 | + * @return string |
|
779 | + * @throws \EE_Error |
|
780 | + */ |
|
781 | + public function get_payment_details($payments = array()) |
|
782 | + { |
|
783 | + // prepare variables for displaying |
|
784 | + $template_args = array(); |
|
785 | + $template_args['transaction'] = $this->_current_txn; |
|
786 | + $template_args['reg_url_link'] = $this->_reg_url_link; |
|
787 | + $template_args['payments'] = array(); |
|
788 | + foreach ($payments as $payment) { |
|
789 | + $template_args['payments'][] = $this->get_payment_row_html($payment); |
|
790 | + } |
|
791 | + // create a hacky payment object, but dont save it |
|
792 | + $payment = EE_Payment::new_instance( |
|
793 | + array( |
|
794 | + 'TXN_ID' => $this->_current_txn->ID(), |
|
795 | + 'STS_ID' => EEM_Payment::status_id_pending, |
|
796 | + 'PAY_timestamp' => time(), |
|
797 | + 'PAY_amount' => $this->_current_txn->total(), |
|
798 | + 'PMD_ID' => $this->_current_txn->payment_method_ID(), |
|
799 | + ) |
|
800 | + ); |
|
801 | + $payment_method = $this->_current_txn->payment_method(); |
|
802 | + if ($payment_method instanceof EE_Payment_Method && $payment_method->type_obj() instanceof EE_PMT_Base) { |
|
803 | + $template_args['gateway_content'] = $payment_method->type_obj()->payment_overview_content($payment); |
|
804 | + } else { |
|
805 | + $template_args['gateway_content'] = ''; |
|
806 | + } |
|
807 | + // link to SPCO payment_options |
|
808 | + $template_args['show_try_pay_again_link'] = $this->_show_try_pay_again_link; |
|
809 | + $template_args['SPCO_payment_options_url'] = $this->_SPCO_payment_options_url; |
|
810 | + // verify template arguments |
|
811 | + EEH_Template_Validator::verify_instanceof($template_args['transaction'], '$transaction', 'EE_Transaction'); |
|
812 | + EEH_Template_Validator::verify_isnt_null($template_args['payments'], '$payments'); |
|
813 | + EEH_Template_Validator::verify_isnt_null( |
|
814 | + $template_args['show_try_pay_again_link'], |
|
815 | + '$show_try_pay_again_link' |
|
816 | + ); |
|
817 | + EEH_Template_Validator::verify_isnt_null($template_args['gateway_content'], '$gateway_content'); |
|
818 | + EEH_Template_Validator::verify_isnt_null( |
|
819 | + $template_args['SPCO_payment_options_url'], |
|
820 | + '$SPCO_payment_options_url' |
|
821 | + ); |
|
822 | + return EEH_Template::locate_template( |
|
823 | + THANK_YOU_TEMPLATES_PATH . 'thank-you-page-payment-details.template.php', |
|
824 | + $template_args, |
|
825 | + true, |
|
826 | + true |
|
827 | + ); |
|
828 | + } |
|
829 | + |
|
830 | + |
|
831 | + /** |
|
832 | + * get_payment_details |
|
833 | + * |
|
834 | + * @param array $payments |
|
835 | + * @return string |
|
836 | + * @throws \EE_Error |
|
837 | + */ |
|
838 | + public function get_new_payments($payments = array()) |
|
839 | + { |
|
840 | + $payments_html = ''; |
|
841 | + // prepare variables for displaying |
|
842 | + foreach ($payments as $payment) { |
|
843 | + $payments_html .= $this->get_payment_row_html($payment); |
|
844 | + } |
|
845 | + return $payments_html; |
|
846 | + } |
|
847 | 847 | } |
@@ -162,7 +162,7 @@ discard block |
||
162 | 162 | */ |
163 | 163 | public function venue_location($content) |
164 | 164 | { |
165 | - return $content . EEH_Template::locate_template('content-espresso_venues-location.php'); |
|
165 | + return $content.EEH_Template::locate_template('content-espresso_venues-location.php'); |
|
166 | 166 | } |
167 | 167 | |
168 | 168 | |
@@ -177,16 +177,16 @@ discard block |
||
177 | 177 | // get some style |
178 | 178 | if (apply_filters('FHEE_enable_default_espresso_css', true) && is_single()) { |
179 | 179 | // first check theme folder |
180 | - if (is_readable(get_stylesheet_directory() . $this->theme . '/style.css')) { |
|
180 | + if (is_readable(get_stylesheet_directory().$this->theme.'/style.css')) { |
|
181 | 181 | wp_register_style( |
182 | 182 | $this->theme, |
183 | - get_stylesheet_directory_uri() . $this->theme . '/style.css', |
|
183 | + get_stylesheet_directory_uri().$this->theme.'/style.css', |
|
184 | 184 | array('dashicons', 'espresso_default') |
185 | 185 | ); |
186 | - } elseif (is_readable(EE_TEMPLATES . $this->theme . '/style.css')) { |
|
186 | + } elseif (is_readable(EE_TEMPLATES.$this->theme.'/style.css')) { |
|
187 | 187 | wp_register_style( |
188 | 188 | $this->theme, |
189 | - EE_TEMPLATES_URL . $this->theme . '/style.css', |
|
189 | + EE_TEMPLATES_URL.$this->theme.'/style.css', |
|
190 | 190 | array('dashicons', 'espresso_default') |
191 | 191 | ); |
192 | 192 | } |
@@ -29,173 +29,173 @@ |
||
29 | 29 | class EED_Venue_Single extends EED_Module |
30 | 30 | { |
31 | 31 | |
32 | - /** |
|
33 | - * @return EED_Venue_Single |
|
34 | - */ |
|
35 | - public static function instance() |
|
36 | - { |
|
37 | - return parent::get_instance(__CLASS__); |
|
38 | - } |
|
39 | - |
|
40 | - |
|
41 | - /** |
|
42 | - * set_hooks - for hooking into EE Core, other modules, etc |
|
43 | - * |
|
44 | - * @return void |
|
45 | - * @throws InvalidArgumentException |
|
46 | - * @throws InvalidDataTypeException |
|
47 | - * @throws InvalidInterfaceException |
|
48 | - */ |
|
49 | - public static function set_hooks() |
|
50 | - { |
|
51 | - /** @var EventEspresso\core\domain\entities\custom_post_types\CustomPostTypeDefinitions $custom_post_type_definitions */ |
|
52 | - $custom_post_type_definitions = LoaderFactory::getLoader()->getShared( |
|
53 | - 'EventEspresso\core\domain\entities\custom_post_types\CustomPostTypeDefinitions' |
|
54 | - ); |
|
55 | - $custom_post_types = $custom_post_type_definitions->getDefinitions(); |
|
56 | - EE_Config::register_route( |
|
57 | - $custom_post_types['espresso_venues']['singular_slug'], |
|
58 | - 'Venue_Single', |
|
59 | - 'run' |
|
60 | - ); |
|
61 | - } |
|
62 | - |
|
63 | - /** |
|
64 | - * set_hooks_admin - for hooking into EE Admin Core, other modules, etc |
|
65 | - * |
|
66 | - * @access public |
|
67 | - * @return void |
|
68 | - */ |
|
69 | - public static function set_hooks_admin() |
|
70 | - { |
|
71 | - } |
|
72 | - |
|
73 | - |
|
74 | - /** |
|
75 | - * run - initial module setup |
|
76 | - * |
|
77 | - * @access public |
|
78 | - * @param \WP $WP |
|
79 | - */ |
|
80 | - public function run($WP) |
|
81 | - { |
|
82 | - // check what template is loaded |
|
83 | - add_filter('template_include', array($this, 'template_include'), 999, 1); |
|
84 | - add_action('wp_enqueue_scripts', array($this, 'wp_enqueue_scripts'), 10); |
|
85 | - } |
|
86 | - |
|
87 | - |
|
88 | - /** |
|
89 | - * template_include |
|
90 | - * |
|
91 | - * @access public |
|
92 | - * @param string $template |
|
93 | - * @return string |
|
94 | - */ |
|
95 | - public function template_include($template) |
|
96 | - { |
|
97 | - // not a custom template? |
|
98 | - if ( |
|
99 | - EE_Registry::instance() |
|
100 | - ->load_core('Front_Controller', array(), false, true) |
|
101 | - ->get_selected_template() != 'single-espresso_venues.php' |
|
102 | - ) { |
|
103 | - EEH_Template::load_espresso_theme_functions(); |
|
104 | - // then add extra event data via hooks |
|
105 | - add_filter('the_title', array($this, 'the_title'), 100, 1); |
|
106 | - add_filter('the_content', array($this, 'venue_details'), 100); |
|
107 | - // don't display entry meta because the existing theme will take car of that |
|
108 | - add_filter('FHEE__content_espresso_venues_details_template__display_entry_meta', '__return_false'); |
|
109 | - } |
|
110 | - return $template; |
|
111 | - } |
|
112 | - |
|
113 | - |
|
114 | - /** |
|
115 | - * the_title |
|
116 | - * |
|
117 | - * @access public |
|
118 | - * @param string $title |
|
119 | - * @return string |
|
120 | - */ |
|
121 | - public function the_title($title = '') |
|
122 | - { |
|
123 | - return $title; |
|
124 | - } |
|
125 | - |
|
126 | - |
|
127 | - /** |
|
128 | - * venue_details |
|
129 | - * |
|
130 | - * @access public |
|
131 | - * @param string $content |
|
132 | - * @return string |
|
133 | - */ |
|
134 | - public function venue_details($content) |
|
135 | - { |
|
136 | - global $post; |
|
137 | - if ( |
|
138 | - $post->post_type == 'espresso_venues' |
|
139 | - && ! post_password_required() |
|
140 | - ) { |
|
141 | - // since the 'content-espresso_venues-details.php' template might be used directly from within a theme, |
|
142 | - // it uses the_content() for displaying the $post->post_content |
|
143 | - // so in order to load a template that uses the_content() from within a callback being used to filter the_content(), |
|
144 | - // we need to first remove this callback from being applied to the_content() (otherwise it will recurse and blow up the interweb) |
|
145 | - remove_filter('the_content', array($this, 'venue_details'), 100); |
|
146 | - // add filters we want |
|
147 | - add_filter('the_content', array($this, 'venue_location'), 110); |
|
148 | - // now load our template |
|
149 | - $template = EEH_Template::locate_template('content-espresso_venues-details.php'); |
|
150 | - // remove other filters we added so they won't get applied to the next post |
|
151 | - remove_filter('the_content', array($this, 'venue_location'), 110); |
|
152 | - } |
|
153 | - // we're not returning the $content directly because the template we are loading uses the_content (or the_excerpt) |
|
154 | - return ! empty($template) ? $template : $content; |
|
155 | - } |
|
156 | - |
|
157 | - |
|
158 | - /** |
|
159 | - * venue_location |
|
160 | - * |
|
161 | - * @access public |
|
162 | - * @param string $content |
|
163 | - * @return string |
|
164 | - */ |
|
165 | - public function venue_location($content) |
|
166 | - { |
|
167 | - return $content . EEH_Template::locate_template('content-espresso_venues-location.php'); |
|
168 | - } |
|
169 | - |
|
170 | - |
|
171 | - /** |
|
172 | - * wp_enqueue_scripts |
|
173 | - * |
|
174 | - * @access public |
|
175 | - * @return void |
|
176 | - */ |
|
177 | - public function wp_enqueue_scripts() |
|
178 | - { |
|
179 | - // get some style |
|
180 | - if (apply_filters('FHEE_enable_default_espresso_css', true) && is_single()) { |
|
181 | - // first check theme folder |
|
182 | - if (is_readable(get_stylesheet_directory() . $this->theme . '/style.css')) { |
|
183 | - wp_register_style( |
|
184 | - $this->theme, |
|
185 | - get_stylesheet_directory_uri() . $this->theme . '/style.css', |
|
186 | - array('dashicons', 'espresso_default') |
|
187 | - ); |
|
188 | - } elseif (is_readable(EE_TEMPLATES . $this->theme . '/style.css')) { |
|
189 | - wp_register_style( |
|
190 | - $this->theme, |
|
191 | - EE_TEMPLATES_URL . $this->theme . '/style.css', |
|
192 | - array('dashicons', 'espresso_default') |
|
193 | - ); |
|
194 | - } |
|
195 | - wp_enqueue_style($this->theme); |
|
196 | - if (EE_Registry::instance()->CFG->map_settings->use_google_maps) { |
|
197 | - add_action('wp_enqueue_scripts', array('EEH_Maps', 'espresso_google_map_js'), 11); |
|
198 | - } |
|
199 | - } |
|
200 | - } |
|
32 | + /** |
|
33 | + * @return EED_Venue_Single |
|
34 | + */ |
|
35 | + public static function instance() |
|
36 | + { |
|
37 | + return parent::get_instance(__CLASS__); |
|
38 | + } |
|
39 | + |
|
40 | + |
|
41 | + /** |
|
42 | + * set_hooks - for hooking into EE Core, other modules, etc |
|
43 | + * |
|
44 | + * @return void |
|
45 | + * @throws InvalidArgumentException |
|
46 | + * @throws InvalidDataTypeException |
|
47 | + * @throws InvalidInterfaceException |
|
48 | + */ |
|
49 | + public static function set_hooks() |
|
50 | + { |
|
51 | + /** @var EventEspresso\core\domain\entities\custom_post_types\CustomPostTypeDefinitions $custom_post_type_definitions */ |
|
52 | + $custom_post_type_definitions = LoaderFactory::getLoader()->getShared( |
|
53 | + 'EventEspresso\core\domain\entities\custom_post_types\CustomPostTypeDefinitions' |
|
54 | + ); |
|
55 | + $custom_post_types = $custom_post_type_definitions->getDefinitions(); |
|
56 | + EE_Config::register_route( |
|
57 | + $custom_post_types['espresso_venues']['singular_slug'], |
|
58 | + 'Venue_Single', |
|
59 | + 'run' |
|
60 | + ); |
|
61 | + } |
|
62 | + |
|
63 | + /** |
|
64 | + * set_hooks_admin - for hooking into EE Admin Core, other modules, etc |
|
65 | + * |
|
66 | + * @access public |
|
67 | + * @return void |
|
68 | + */ |
|
69 | + public static function set_hooks_admin() |
|
70 | + { |
|
71 | + } |
|
72 | + |
|
73 | + |
|
74 | + /** |
|
75 | + * run - initial module setup |
|
76 | + * |
|
77 | + * @access public |
|
78 | + * @param \WP $WP |
|
79 | + */ |
|
80 | + public function run($WP) |
|
81 | + { |
|
82 | + // check what template is loaded |
|
83 | + add_filter('template_include', array($this, 'template_include'), 999, 1); |
|
84 | + add_action('wp_enqueue_scripts', array($this, 'wp_enqueue_scripts'), 10); |
|
85 | + } |
|
86 | + |
|
87 | + |
|
88 | + /** |
|
89 | + * template_include |
|
90 | + * |
|
91 | + * @access public |
|
92 | + * @param string $template |
|
93 | + * @return string |
|
94 | + */ |
|
95 | + public function template_include($template) |
|
96 | + { |
|
97 | + // not a custom template? |
|
98 | + if ( |
|
99 | + EE_Registry::instance() |
|
100 | + ->load_core('Front_Controller', array(), false, true) |
|
101 | + ->get_selected_template() != 'single-espresso_venues.php' |
|
102 | + ) { |
|
103 | + EEH_Template::load_espresso_theme_functions(); |
|
104 | + // then add extra event data via hooks |
|
105 | + add_filter('the_title', array($this, 'the_title'), 100, 1); |
|
106 | + add_filter('the_content', array($this, 'venue_details'), 100); |
|
107 | + // don't display entry meta because the existing theme will take car of that |
|
108 | + add_filter('FHEE__content_espresso_venues_details_template__display_entry_meta', '__return_false'); |
|
109 | + } |
|
110 | + return $template; |
|
111 | + } |
|
112 | + |
|
113 | + |
|
114 | + /** |
|
115 | + * the_title |
|
116 | + * |
|
117 | + * @access public |
|
118 | + * @param string $title |
|
119 | + * @return string |
|
120 | + */ |
|
121 | + public function the_title($title = '') |
|
122 | + { |
|
123 | + return $title; |
|
124 | + } |
|
125 | + |
|
126 | + |
|
127 | + /** |
|
128 | + * venue_details |
|
129 | + * |
|
130 | + * @access public |
|
131 | + * @param string $content |
|
132 | + * @return string |
|
133 | + */ |
|
134 | + public function venue_details($content) |
|
135 | + { |
|
136 | + global $post; |
|
137 | + if ( |
|
138 | + $post->post_type == 'espresso_venues' |
|
139 | + && ! post_password_required() |
|
140 | + ) { |
|
141 | + // since the 'content-espresso_venues-details.php' template might be used directly from within a theme, |
|
142 | + // it uses the_content() for displaying the $post->post_content |
|
143 | + // so in order to load a template that uses the_content() from within a callback being used to filter the_content(), |
|
144 | + // we need to first remove this callback from being applied to the_content() (otherwise it will recurse and blow up the interweb) |
|
145 | + remove_filter('the_content', array($this, 'venue_details'), 100); |
|
146 | + // add filters we want |
|
147 | + add_filter('the_content', array($this, 'venue_location'), 110); |
|
148 | + // now load our template |
|
149 | + $template = EEH_Template::locate_template('content-espresso_venues-details.php'); |
|
150 | + // remove other filters we added so they won't get applied to the next post |
|
151 | + remove_filter('the_content', array($this, 'venue_location'), 110); |
|
152 | + } |
|
153 | + // we're not returning the $content directly because the template we are loading uses the_content (or the_excerpt) |
|
154 | + return ! empty($template) ? $template : $content; |
|
155 | + } |
|
156 | + |
|
157 | + |
|
158 | + /** |
|
159 | + * venue_location |
|
160 | + * |
|
161 | + * @access public |
|
162 | + * @param string $content |
|
163 | + * @return string |
|
164 | + */ |
|
165 | + public function venue_location($content) |
|
166 | + { |
|
167 | + return $content . EEH_Template::locate_template('content-espresso_venues-location.php'); |
|
168 | + } |
|
169 | + |
|
170 | + |
|
171 | + /** |
|
172 | + * wp_enqueue_scripts |
|
173 | + * |
|
174 | + * @access public |
|
175 | + * @return void |
|
176 | + */ |
|
177 | + public function wp_enqueue_scripts() |
|
178 | + { |
|
179 | + // get some style |
|
180 | + if (apply_filters('FHEE_enable_default_espresso_css', true) && is_single()) { |
|
181 | + // first check theme folder |
|
182 | + if (is_readable(get_stylesheet_directory() . $this->theme . '/style.css')) { |
|
183 | + wp_register_style( |
|
184 | + $this->theme, |
|
185 | + get_stylesheet_directory_uri() . $this->theme . '/style.css', |
|
186 | + array('dashicons', 'espresso_default') |
|
187 | + ); |
|
188 | + } elseif (is_readable(EE_TEMPLATES . $this->theme . '/style.css')) { |
|
189 | + wp_register_style( |
|
190 | + $this->theme, |
|
191 | + EE_TEMPLATES_URL . $this->theme . '/style.css', |
|
192 | + array('dashicons', 'espresso_default') |
|
193 | + ); |
|
194 | + } |
|
195 | + wp_enqueue_style($this->theme); |
|
196 | + if (EE_Registry::instance()->CFG->map_settings->use_google_maps) { |
|
197 | + add_action('wp_enqueue_scripts', array('EEH_Maps', 'espresso_google_map_js'), 11); |
|
198 | + } |
|
199 | + } |
|
200 | + } |
|
201 | 201 | } |
@@ -53,7 +53,7 @@ discard block |
||
53 | 53 | */ |
54 | 54 | public static function set_trap() |
55 | 55 | { |
56 | - define('EE_BOT_TRAP_BASE_URL', plugin_dir_url(__FILE__) . '/'); |
|
56 | + define('EE_BOT_TRAP_BASE_URL', plugin_dir_url(__FILE__).'/'); |
|
57 | 57 | add_action( |
58 | 58 | 'AHEE__ticket_selector_chart__template__after_ticket_selector', |
59 | 59 | array('EED_Bot_Trap', 'generate_bot_trap'), |
@@ -119,9 +119,9 @@ discard block |
||
119 | 119 | $do_not_enter = esc_html__('please do not enter anything in this input', 'event_espresso'); |
120 | 120 | $time = microtime(true); |
121 | 121 | $html = '<div class="tkt-slctr-request-processor-dv" style="float:left; margin:0 0 0 -999em; height: 0;">'; |
122 | - $html .= '<label for="tkt-slctr-request-processor-email-' . $time . '">' . $do_not_enter . '</label>'; |
|
122 | + $html .= '<label for="tkt-slctr-request-processor-email-'.$time.'">'.$do_not_enter.'</label>'; |
|
123 | 123 | $html .= '<input type="email" id="tkt-slctr-request-processor-email-'; |
124 | - $html .= $time . '" name="tkt-slctr-request-processor-email" value=""/>'; |
|
124 | + $html .= $time.'" name="tkt-slctr-request-processor-email" value=""/>'; |
|
125 | 125 | $html .= '</div><!-- .tkt-slctr-request-processor-dv -->'; |
126 | 126 | echo $html; |
127 | 127 | } |
@@ -147,7 +147,7 @@ discard block |
||
147 | 147 | return; |
148 | 148 | } |
149 | 149 | // check the given callback is valid first before executing |
150 | - if (! is_callable($triggered_trap_callback)) { |
|
150 | + if ( ! is_callable($triggered_trap_callback)) { |
|
151 | 151 | // invalid callback so lets just sub in our default. |
152 | 152 | $triggered_trap_callback = array('EED_Bot_Trap', 'triggered_trap_response'); |
153 | 153 | } |
@@ -16,306 +16,306 @@ |
||
16 | 16 | class EED_Bot_Trap extends EED_Module |
17 | 17 | { |
18 | 18 | |
19 | - /** |
|
20 | - * @return EED_Bot_Trap|EED_Module |
|
21 | - */ |
|
22 | - public static function instance() |
|
23 | - { |
|
24 | - return parent::get_instance(__CLASS__); |
|
25 | - } |
|
19 | + /** |
|
20 | + * @return EED_Bot_Trap|EED_Module |
|
21 | + */ |
|
22 | + public static function instance() |
|
23 | + { |
|
24 | + return parent::get_instance(__CLASS__); |
|
25 | + } |
|
26 | 26 | |
27 | 27 | |
28 | - /** |
|
29 | - * set_hooks - for hooking into EE Core, other modules, etc |
|
30 | - * |
|
31 | - * @return void |
|
32 | - */ |
|
33 | - public static function set_hooks() |
|
34 | - { |
|
35 | - if ( |
|
36 | - apply_filters('FHEE__EED_Bot_Trap__set_hooks__use_bot_trap', true) && |
|
37 | - EE_Registry::instance()->CFG->registration->use_bot_trap |
|
38 | - ) { |
|
39 | - EED_Bot_Trap::set_trap(); |
|
40 | - // redirect bots to bogus success page |
|
41 | - EE_Config::register_route( |
|
42 | - 'ticket_selection_received', |
|
43 | - 'EED_Bot_Trap', |
|
44 | - 'display_bot_trap_success' |
|
45 | - ); |
|
46 | - } |
|
47 | - } |
|
28 | + /** |
|
29 | + * set_hooks - for hooking into EE Core, other modules, etc |
|
30 | + * |
|
31 | + * @return void |
|
32 | + */ |
|
33 | + public static function set_hooks() |
|
34 | + { |
|
35 | + if ( |
|
36 | + apply_filters('FHEE__EED_Bot_Trap__set_hooks__use_bot_trap', true) && |
|
37 | + EE_Registry::instance()->CFG->registration->use_bot_trap |
|
38 | + ) { |
|
39 | + EED_Bot_Trap::set_trap(); |
|
40 | + // redirect bots to bogus success page |
|
41 | + EE_Config::register_route( |
|
42 | + 'ticket_selection_received', |
|
43 | + 'EED_Bot_Trap', |
|
44 | + 'display_bot_trap_success' |
|
45 | + ); |
|
46 | + } |
|
47 | + } |
|
48 | 48 | |
49 | 49 | |
50 | - /** |
|
51 | - * set_hooks_admin - for hooking into EE Admin Core, other modules, etc |
|
52 | - * |
|
53 | - * @return void |
|
54 | - */ |
|
55 | - public static function set_trap() |
|
56 | - { |
|
57 | - define('EE_BOT_TRAP_BASE_URL', plugin_dir_url(__FILE__) . '/'); |
|
58 | - add_action( |
|
59 | - 'AHEE__ticket_selector_chart__template__after_ticket_selector', |
|
60 | - array('EED_Bot_Trap', 'generate_bot_trap'), |
|
61 | - 10, |
|
62 | - 2 |
|
63 | - ); |
|
64 | - add_action( |
|
65 | - 'EED_Ticket_Selector__process_ticket_selections__before', |
|
66 | - array('EED_Bot_Trap', 'process_bot_trap'), |
|
67 | - 1, |
|
68 | - 2 |
|
69 | - ); |
|
70 | - } |
|
50 | + /** |
|
51 | + * set_hooks_admin - for hooking into EE Admin Core, other modules, etc |
|
52 | + * |
|
53 | + * @return void |
|
54 | + */ |
|
55 | + public static function set_trap() |
|
56 | + { |
|
57 | + define('EE_BOT_TRAP_BASE_URL', plugin_dir_url(__FILE__) . '/'); |
|
58 | + add_action( |
|
59 | + 'AHEE__ticket_selector_chart__template__after_ticket_selector', |
|
60 | + array('EED_Bot_Trap', 'generate_bot_trap'), |
|
61 | + 10, |
|
62 | + 2 |
|
63 | + ); |
|
64 | + add_action( |
|
65 | + 'EED_Ticket_Selector__process_ticket_selections__before', |
|
66 | + array('EED_Bot_Trap', 'process_bot_trap'), |
|
67 | + 1, |
|
68 | + 2 |
|
69 | + ); |
|
70 | + } |
|
71 | 71 | |
72 | 72 | |
73 | - /** |
|
74 | - * set_hooks_admin - for hooking into EE Admin Core, other modules, etc |
|
75 | - * |
|
76 | - * @return void |
|
77 | - */ |
|
78 | - public static function set_hooks_admin() |
|
79 | - { |
|
80 | - if ( |
|
81 | - defined('DOING_AJAX') |
|
82 | - && DOING_AJAX |
|
83 | - && apply_filters('FHEE__EED_Bot_Trap__set_hooks__use_bot_trap', true) |
|
84 | - && EE_Registry::instance()->CFG->registration->use_bot_trap |
|
85 | - ) { |
|
86 | - EED_Bot_Trap::set_trap(); |
|
87 | - } |
|
88 | - add_action( |
|
89 | - 'AHEE__Extend_Registration_Form_Admin_Page___reg_form_settings_template', |
|
90 | - array('EED_Bot_Trap', 'bot_trap_settings_form'), |
|
91 | - 5 |
|
92 | - ); |
|
93 | - add_filter( |
|
94 | - 'FHEE__Extend_Registration_Form_Admin_Page___update_reg_form_settings__CFG_registration', |
|
95 | - array('EED_Bot_Trap', 'update_bot_trap_settings_form'), |
|
96 | - 10, |
|
97 | - 1 |
|
98 | - ); |
|
99 | - } |
|
73 | + /** |
|
74 | + * set_hooks_admin - for hooking into EE Admin Core, other modules, etc |
|
75 | + * |
|
76 | + * @return void |
|
77 | + */ |
|
78 | + public static function set_hooks_admin() |
|
79 | + { |
|
80 | + if ( |
|
81 | + defined('DOING_AJAX') |
|
82 | + && DOING_AJAX |
|
83 | + && apply_filters('FHEE__EED_Bot_Trap__set_hooks__use_bot_trap', true) |
|
84 | + && EE_Registry::instance()->CFG->registration->use_bot_trap |
|
85 | + ) { |
|
86 | + EED_Bot_Trap::set_trap(); |
|
87 | + } |
|
88 | + add_action( |
|
89 | + 'AHEE__Extend_Registration_Form_Admin_Page___reg_form_settings_template', |
|
90 | + array('EED_Bot_Trap', 'bot_trap_settings_form'), |
|
91 | + 5 |
|
92 | + ); |
|
93 | + add_filter( |
|
94 | + 'FHEE__Extend_Registration_Form_Admin_Page___update_reg_form_settings__CFG_registration', |
|
95 | + array('EED_Bot_Trap', 'update_bot_trap_settings_form'), |
|
96 | + 10, |
|
97 | + 1 |
|
98 | + ); |
|
99 | + } |
|
100 | 100 | |
101 | 101 | |
102 | - /** |
|
103 | - * run - initial module setup |
|
104 | - * |
|
105 | - * @param WP $WP |
|
106 | - * @return void |
|
107 | - */ |
|
108 | - public function run($WP) |
|
109 | - { |
|
110 | - } |
|
102 | + /** |
|
103 | + * run - initial module setup |
|
104 | + * |
|
105 | + * @param WP $WP |
|
106 | + * @return void |
|
107 | + */ |
|
108 | + public function run($WP) |
|
109 | + { |
|
110 | + } |
|
111 | 111 | |
112 | 112 | |
113 | - /** |
|
114 | - * generate_bot_trap |
|
115 | - * |
|
116 | - * @return void |
|
117 | - * @throws RuntimeException |
|
118 | - */ |
|
119 | - public static function generate_bot_trap() |
|
120 | - { |
|
121 | - $do_not_enter = esc_html__('please do not enter anything in this input', 'event_espresso'); |
|
122 | - $time = microtime(true); |
|
123 | - $html = '<div class="tkt-slctr-request-processor-dv" style="float:left; margin:0 0 0 -999em; height: 0;">'; |
|
124 | - $html .= '<label for="tkt-slctr-request-processor-email-' . $time . '">' . $do_not_enter . '</label>'; |
|
125 | - $html .= '<input type="email" id="tkt-slctr-request-processor-email-'; |
|
126 | - $html .= $time . '" name="tkt-slctr-request-processor-email" value=""/>'; |
|
127 | - $html .= '</div><!-- .tkt-slctr-request-processor-dv -->'; |
|
128 | - echo $html; |
|
129 | - } |
|
113 | + /** |
|
114 | + * generate_bot_trap |
|
115 | + * |
|
116 | + * @return void |
|
117 | + * @throws RuntimeException |
|
118 | + */ |
|
119 | + public static function generate_bot_trap() |
|
120 | + { |
|
121 | + $do_not_enter = esc_html__('please do not enter anything in this input', 'event_espresso'); |
|
122 | + $time = microtime(true); |
|
123 | + $html = '<div class="tkt-slctr-request-processor-dv" style="float:left; margin:0 0 0 -999em; height: 0;">'; |
|
124 | + $html .= '<label for="tkt-slctr-request-processor-email-' . $time . '">' . $do_not_enter . '</label>'; |
|
125 | + $html .= '<input type="email" id="tkt-slctr-request-processor-email-'; |
|
126 | + $html .= $time . '" name="tkt-slctr-request-processor-email" value=""/>'; |
|
127 | + $html .= '</div><!-- .tkt-slctr-request-processor-dv -->'; |
|
128 | + echo $html; |
|
129 | + } |
|
130 | 130 | |
131 | 131 | |
132 | - /** |
|
133 | - * process_bot_trap |
|
134 | - * |
|
135 | - * @param array|string $triggered_trap_callback Callback that will be executed for handling the |
|
136 | - * response if the bot trap is triggered. |
|
137 | - * It should receive one argument: a boolean indicating |
|
138 | - * whether the trap was triggered by suspicious timing or not. |
|
139 | - * @throws RuntimeException |
|
140 | - */ |
|
141 | - public static function process_bot_trap($triggered_trap_callback = array()) |
|
142 | - { |
|
143 | - // what's your email address Mr. Bot ? |
|
144 | - $empty_trap = isset($_REQUEST['tkt-slctr-request-processor-email']) |
|
145 | - && $_REQUEST['tkt-slctr-request-processor-email'] === ''; |
|
146 | - // are we human ? |
|
147 | - if ($empty_trap) { |
|
148 | - do_action('AHEE__EED_Bot_Trap__process_bot_trap__trap_not_triggered'); |
|
149 | - return; |
|
150 | - } |
|
151 | - // check the given callback is valid first before executing |
|
152 | - if (! is_callable($triggered_trap_callback)) { |
|
153 | - // invalid callback so lets just sub in our default. |
|
154 | - $triggered_trap_callback = array('EED_Bot_Trap', 'triggered_trap_response'); |
|
155 | - } |
|
156 | - call_user_func($triggered_trap_callback); |
|
157 | - } |
|
132 | + /** |
|
133 | + * process_bot_trap |
|
134 | + * |
|
135 | + * @param array|string $triggered_trap_callback Callback that will be executed for handling the |
|
136 | + * response if the bot trap is triggered. |
|
137 | + * It should receive one argument: a boolean indicating |
|
138 | + * whether the trap was triggered by suspicious timing or not. |
|
139 | + * @throws RuntimeException |
|
140 | + */ |
|
141 | + public static function process_bot_trap($triggered_trap_callback = array()) |
|
142 | + { |
|
143 | + // what's your email address Mr. Bot ? |
|
144 | + $empty_trap = isset($_REQUEST['tkt-slctr-request-processor-email']) |
|
145 | + && $_REQUEST['tkt-slctr-request-processor-email'] === ''; |
|
146 | + // are we human ? |
|
147 | + if ($empty_trap) { |
|
148 | + do_action('AHEE__EED_Bot_Trap__process_bot_trap__trap_not_triggered'); |
|
149 | + return; |
|
150 | + } |
|
151 | + // check the given callback is valid first before executing |
|
152 | + if (! is_callable($triggered_trap_callback)) { |
|
153 | + // invalid callback so lets just sub in our default. |
|
154 | + $triggered_trap_callback = array('EED_Bot_Trap', 'triggered_trap_response'); |
|
155 | + } |
|
156 | + call_user_func($triggered_trap_callback); |
|
157 | + } |
|
158 | 158 | |
159 | 159 | |
160 | - /** |
|
161 | - * This is the default callback executed by EED_Bot_Trap::process_bot_trap that handles the response. |
|
162 | - * |
|
163 | - * @throws InvalidArgumentException |
|
164 | - * @throws InvalidDataTypeException |
|
165 | - * @throws InvalidInterfaceException |
|
166 | - */ |
|
167 | - public static function triggered_trap_response() |
|
168 | - { |
|
169 | - // UH OH... |
|
170 | - $redirect_url = apply_filters( |
|
171 | - 'FHEE__EED_Bot_Trap__process_bot_trap__redirect_url', |
|
172 | - add_query_arg( |
|
173 | - array('ee' => 'ticket_selection_received'), |
|
174 | - EE_Registry::instance()->CFG->core->reg_page_url() |
|
175 | - ) |
|
176 | - ); |
|
177 | - // if AJAX, return the redirect URL |
|
178 | - if (defined('DOING_AJAX') && DOING_AJAX) { |
|
179 | - echo wp_json_encode( |
|
180 | - array_merge( |
|
181 | - EE_Error::get_notices(false), |
|
182 | - array( |
|
183 | - 'redirect_url' => $redirect_url, |
|
184 | - ) |
|
185 | - ) |
|
186 | - ); |
|
187 | - exit(); |
|
188 | - } |
|
189 | - wp_safe_redirect($redirect_url); |
|
190 | - exit(); |
|
191 | - } |
|
160 | + /** |
|
161 | + * This is the default callback executed by EED_Bot_Trap::process_bot_trap that handles the response. |
|
162 | + * |
|
163 | + * @throws InvalidArgumentException |
|
164 | + * @throws InvalidDataTypeException |
|
165 | + * @throws InvalidInterfaceException |
|
166 | + */ |
|
167 | + public static function triggered_trap_response() |
|
168 | + { |
|
169 | + // UH OH... |
|
170 | + $redirect_url = apply_filters( |
|
171 | + 'FHEE__EED_Bot_Trap__process_bot_trap__redirect_url', |
|
172 | + add_query_arg( |
|
173 | + array('ee' => 'ticket_selection_received'), |
|
174 | + EE_Registry::instance()->CFG->core->reg_page_url() |
|
175 | + ) |
|
176 | + ); |
|
177 | + // if AJAX, return the redirect URL |
|
178 | + if (defined('DOING_AJAX') && DOING_AJAX) { |
|
179 | + echo wp_json_encode( |
|
180 | + array_merge( |
|
181 | + EE_Error::get_notices(false), |
|
182 | + array( |
|
183 | + 'redirect_url' => $redirect_url, |
|
184 | + ) |
|
185 | + ) |
|
186 | + ); |
|
187 | + exit(); |
|
188 | + } |
|
189 | + wp_safe_redirect($redirect_url); |
|
190 | + exit(); |
|
191 | + } |
|
192 | 192 | |
193 | 193 | |
194 | - /** |
|
195 | - * display_bot_trap_success |
|
196 | - * shows a "success" screen to bots so that they (ie: the ppl managing them) |
|
197 | - * think the form was submitted successfully |
|
198 | - * |
|
199 | - * @return void |
|
200 | - */ |
|
201 | - public static function display_bot_trap_success() |
|
202 | - { |
|
203 | - add_filter('FHEE__EED_Single_Page_Checkout__run', '__return_false'); |
|
204 | - $bot_notice = esc_html__( |
|
205 | - 'Thank you so much. Your ticket selections have been received for consideration.', |
|
206 | - 'event_espresso' |
|
207 | - ); |
|
208 | - $bot_notice = isset($_REQUEST['ee-notice']) && $_REQUEST['ee-notice'] !== '' |
|
209 | - ? sanitize_text_field(stripslashes($_REQUEST['ee-notice'])) |
|
210 | - : $bot_notice; |
|
211 | - EE_Registry::instance()->REQ->add_output(EEH_HTML::div($bot_notice, '', 'ee-attention')); |
|
212 | - } |
|
194 | + /** |
|
195 | + * display_bot_trap_success |
|
196 | + * shows a "success" screen to bots so that they (ie: the ppl managing them) |
|
197 | + * think the form was submitted successfully |
|
198 | + * |
|
199 | + * @return void |
|
200 | + */ |
|
201 | + public static function display_bot_trap_success() |
|
202 | + { |
|
203 | + add_filter('FHEE__EED_Single_Page_Checkout__run', '__return_false'); |
|
204 | + $bot_notice = esc_html__( |
|
205 | + 'Thank you so much. Your ticket selections have been received for consideration.', |
|
206 | + 'event_espresso' |
|
207 | + ); |
|
208 | + $bot_notice = isset($_REQUEST['ee-notice']) && $_REQUEST['ee-notice'] !== '' |
|
209 | + ? sanitize_text_field(stripslashes($_REQUEST['ee-notice'])) |
|
210 | + : $bot_notice; |
|
211 | + EE_Registry::instance()->REQ->add_output(EEH_HTML::div($bot_notice, '', 'ee-attention')); |
|
212 | + } |
|
213 | 213 | |
214 | 214 | |
215 | 215 | |
216 | - /*********************************** ADMIN **********************************/ |
|
216 | + /*********************************** ADMIN **********************************/ |
|
217 | 217 | |
218 | 218 | |
219 | - /** |
|
220 | - * bot_trap_settings_form |
|
221 | - * |
|
222 | - * @return void |
|
223 | - * @throws EE_Error |
|
224 | - * @throws InvalidArgumentException |
|
225 | - * @throws InvalidDataTypeException |
|
226 | - * @throws InvalidInterfaceException |
|
227 | - */ |
|
228 | - public static function bot_trap_settings_form() |
|
229 | - { |
|
230 | - EED_Bot_Trap::_bot_trap_settings_form()->enqueue_js(); |
|
231 | - echo EED_Bot_Trap::_bot_trap_settings_form()->get_html(); |
|
232 | - } |
|
219 | + /** |
|
220 | + * bot_trap_settings_form |
|
221 | + * |
|
222 | + * @return void |
|
223 | + * @throws EE_Error |
|
224 | + * @throws InvalidArgumentException |
|
225 | + * @throws InvalidDataTypeException |
|
226 | + * @throws InvalidInterfaceException |
|
227 | + */ |
|
228 | + public static function bot_trap_settings_form() |
|
229 | + { |
|
230 | + EED_Bot_Trap::_bot_trap_settings_form()->enqueue_js(); |
|
231 | + echo EED_Bot_Trap::_bot_trap_settings_form()->get_html(); |
|
232 | + } |
|
233 | 233 | |
234 | 234 | |
235 | - /** |
|
236 | - * _bot_trap_settings_form |
|
237 | - * |
|
238 | - * @return EE_Form_Section_Proper |
|
239 | - * @throws EE_Error |
|
240 | - */ |
|
241 | - protected static function _bot_trap_settings_form() |
|
242 | - { |
|
243 | - return new EE_Form_Section_Proper( |
|
244 | - array( |
|
245 | - 'name' => 'bot_trap_settings', |
|
246 | - 'html_id' => 'bot_trap_settings', |
|
247 | - 'layout_strategy' => new EE_Admin_Two_Column_Layout(), |
|
248 | - 'subsections' => array( |
|
249 | - 'bot_trap_hdr' => new EE_Form_Section_HTML( |
|
250 | - EEH_HTML::h2(esc_html__('Bot Trap Settings', 'event_espresso')) |
|
251 | - ), |
|
252 | - 'use_bot_trap' => new EE_Yes_No_Input( |
|
253 | - array( |
|
254 | - 'html_label_text' => esc_html__('Enable Bot Trap', 'event_espresso'), |
|
255 | - 'html_help_text' => esc_html__( |
|
256 | - 'The Event Espresso Bot Trap will insert a fake input into your Ticket Selector forms that is hidden from regular site visitors, but visible to spam bots. Because the input asks for an email address, it is irresistible to spam bots who will of course enter text into it. Since regular site visitors can not see this input, any value detected during form submission means a bot has been detected, which will then be blocked from submitting the form.', |
|
257 | - 'event_espresso' |
|
258 | - ), |
|
259 | - 'default' => EE_Registry::instance()->CFG->registration->use_bot_trap !== null |
|
260 | - ? EE_Registry::instance()->CFG->registration->use_bot_trap |
|
261 | - : true, |
|
262 | - 'required' => false, |
|
263 | - ) |
|
264 | - ), |
|
265 | - ), |
|
266 | - ) |
|
267 | - ); |
|
268 | - } |
|
235 | + /** |
|
236 | + * _bot_trap_settings_form |
|
237 | + * |
|
238 | + * @return EE_Form_Section_Proper |
|
239 | + * @throws EE_Error |
|
240 | + */ |
|
241 | + protected static function _bot_trap_settings_form() |
|
242 | + { |
|
243 | + return new EE_Form_Section_Proper( |
|
244 | + array( |
|
245 | + 'name' => 'bot_trap_settings', |
|
246 | + 'html_id' => 'bot_trap_settings', |
|
247 | + 'layout_strategy' => new EE_Admin_Two_Column_Layout(), |
|
248 | + 'subsections' => array( |
|
249 | + 'bot_trap_hdr' => new EE_Form_Section_HTML( |
|
250 | + EEH_HTML::h2(esc_html__('Bot Trap Settings', 'event_espresso')) |
|
251 | + ), |
|
252 | + 'use_bot_trap' => new EE_Yes_No_Input( |
|
253 | + array( |
|
254 | + 'html_label_text' => esc_html__('Enable Bot Trap', 'event_espresso'), |
|
255 | + 'html_help_text' => esc_html__( |
|
256 | + 'The Event Espresso Bot Trap will insert a fake input into your Ticket Selector forms that is hidden from regular site visitors, but visible to spam bots. Because the input asks for an email address, it is irresistible to spam bots who will of course enter text into it. Since regular site visitors can not see this input, any value detected during form submission means a bot has been detected, which will then be blocked from submitting the form.', |
|
257 | + 'event_espresso' |
|
258 | + ), |
|
259 | + 'default' => EE_Registry::instance()->CFG->registration->use_bot_trap !== null |
|
260 | + ? EE_Registry::instance()->CFG->registration->use_bot_trap |
|
261 | + : true, |
|
262 | + 'required' => false, |
|
263 | + ) |
|
264 | + ), |
|
265 | + ), |
|
266 | + ) |
|
267 | + ); |
|
268 | + } |
|
269 | 269 | |
270 | 270 | |
271 | - /** |
|
272 | - * update_bot_trap_settings_form |
|
273 | - * |
|
274 | - * @param EE_Registration_Config $EE_Registration_Config |
|
275 | - * @return EE_Registration_Config |
|
276 | - * @throws EE_Error |
|
277 | - * @throws InvalidArgumentException |
|
278 | - * @throws ReflectionException |
|
279 | - * @throws InvalidDataTypeException |
|
280 | - * @throws InvalidInterfaceException |
|
281 | - */ |
|
282 | - public static function update_bot_trap_settings_form(EE_Registration_Config $EE_Registration_Config) |
|
283 | - { |
|
284 | - try { |
|
285 | - $bot_trap_settings_form = EED_Bot_Trap::_bot_trap_settings_form(); |
|
286 | - // if not displaying a form, then check for form submission |
|
287 | - if ($bot_trap_settings_form->was_submitted()) { |
|
288 | - // capture form data |
|
289 | - $bot_trap_settings_form->receive_form_submission(); |
|
290 | - // validate form data |
|
291 | - if ($bot_trap_settings_form->is_valid()) { |
|
292 | - // grab validated data from form |
|
293 | - $valid_data = $bot_trap_settings_form->valid_data(); |
|
294 | - if (isset($valid_data['use_bot_trap'])) { |
|
295 | - $EE_Registration_Config->use_bot_trap = $valid_data['use_bot_trap']; |
|
296 | - } else { |
|
297 | - EE_Error::add_error( |
|
298 | - esc_html__( |
|
299 | - 'Invalid or missing Bot Trap settings. Please refresh the form and try again.', |
|
300 | - 'event_espresso' |
|
301 | - ), |
|
302 | - __FILE__, |
|
303 | - __FUNCTION__, |
|
304 | - __LINE__ |
|
305 | - ); |
|
306 | - } |
|
307 | - } elseif ($bot_trap_settings_form->submission_error_message() !== '') { |
|
308 | - EE_Error::add_error( |
|
309 | - $bot_trap_settings_form->submission_error_message(), |
|
310 | - __FILE__, |
|
311 | - __FUNCTION__, |
|
312 | - __LINE__ |
|
313 | - ); |
|
314 | - } |
|
315 | - } |
|
316 | - } catch (EE_Error $e) { |
|
317 | - $e->get_error(); |
|
318 | - } |
|
319 | - return $EE_Registration_Config; |
|
320 | - } |
|
271 | + /** |
|
272 | + * update_bot_trap_settings_form |
|
273 | + * |
|
274 | + * @param EE_Registration_Config $EE_Registration_Config |
|
275 | + * @return EE_Registration_Config |
|
276 | + * @throws EE_Error |
|
277 | + * @throws InvalidArgumentException |
|
278 | + * @throws ReflectionException |
|
279 | + * @throws InvalidDataTypeException |
|
280 | + * @throws InvalidInterfaceException |
|
281 | + */ |
|
282 | + public static function update_bot_trap_settings_form(EE_Registration_Config $EE_Registration_Config) |
|
283 | + { |
|
284 | + try { |
|
285 | + $bot_trap_settings_form = EED_Bot_Trap::_bot_trap_settings_form(); |
|
286 | + // if not displaying a form, then check for form submission |
|
287 | + if ($bot_trap_settings_form->was_submitted()) { |
|
288 | + // capture form data |
|
289 | + $bot_trap_settings_form->receive_form_submission(); |
|
290 | + // validate form data |
|
291 | + if ($bot_trap_settings_form->is_valid()) { |
|
292 | + // grab validated data from form |
|
293 | + $valid_data = $bot_trap_settings_form->valid_data(); |
|
294 | + if (isset($valid_data['use_bot_trap'])) { |
|
295 | + $EE_Registration_Config->use_bot_trap = $valid_data['use_bot_trap']; |
|
296 | + } else { |
|
297 | + EE_Error::add_error( |
|
298 | + esc_html__( |
|
299 | + 'Invalid or missing Bot Trap settings. Please refresh the form and try again.', |
|
300 | + 'event_espresso' |
|
301 | + ), |
|
302 | + __FILE__, |
|
303 | + __FUNCTION__, |
|
304 | + __LINE__ |
|
305 | + ); |
|
306 | + } |
|
307 | + } elseif ($bot_trap_settings_form->submission_error_message() !== '') { |
|
308 | + EE_Error::add_error( |
|
309 | + $bot_trap_settings_form->submission_error_message(), |
|
310 | + __FILE__, |
|
311 | + __FUNCTION__, |
|
312 | + __LINE__ |
|
313 | + ); |
|
314 | + } |
|
315 | + } |
|
316 | + } catch (EE_Error $e) { |
|
317 | + $e->get_error(); |
|
318 | + } |
|
319 | + return $EE_Registration_Config; |
|
320 | + } |
|
321 | 321 | } |
@@ -113,7 +113,7 @@ discard block |
||
113 | 113 | */ |
114 | 114 | protected function getLoader() |
115 | 115 | { |
116 | - if (!$this->loader instanceof LoaderInterface) { |
|
116 | + if ( ! $this->loader instanceof LoaderInterface) { |
|
117 | 117 | $this->loader = LoaderFactory::getLoader(); |
118 | 118 | } |
119 | 119 | return $this->loader; |
@@ -131,7 +131,7 @@ discard block |
||
131 | 131 | && $_REQUEST['page'] == 'espresso_batch' |
132 | 132 | ) |
133 | 133 | ) { |
134 | - if (! isset($_REQUEST['default_nonce']) || ! wp_verify_nonce($_REQUEST['default_nonce'], 'default_nonce')) { |
|
134 | + if ( ! isset($_REQUEST['default_nonce']) || ! wp_verify_nonce($_REQUEST['default_nonce'], 'default_nonce')) { |
|
135 | 135 | wp_die(esc_html__('The link you clicked to start the batch job has expired. Please go back and refresh the previous page.', 'event_espresso')); |
136 | 136 | } |
137 | 137 | switch ($this->batch_request_type()) { |
@@ -153,7 +153,7 @@ discard block |
||
153 | 153 | $job_response = $this->_enqueue_batch_job_scripts_and_styles_and_start_job(); |
154 | 154 | wp_enqueue_script( |
155 | 155 | 'batch_runner_init', |
156 | - BATCH_URL . 'assets/batch_runner_init.js', |
|
156 | + BATCH_URL.'assets/batch_runner_init.js', |
|
157 | 157 | array('batch_runner'), |
158 | 158 | EVENT_ESPRESSO_VERSION, |
159 | 159 | true |
@@ -177,7 +177,7 @@ discard block |
||
177 | 177 | $job_response = $this->_enqueue_batch_job_scripts_and_styles_and_start_job(); |
178 | 178 | wp_enqueue_script( |
179 | 179 | 'batch_file_runner_init', |
180 | - BATCH_URL . 'assets/batch_file_runner_init.js', |
|
180 | + BATCH_URL.'assets/batch_file_runner_init.js', |
|
181 | 181 | array('batch_runner'), |
182 | 182 | EVENT_ESPRESSO_VERSION, |
183 | 183 | true |
@@ -189,7 +189,7 @@ discard block |
||
189 | 189 | array( |
190 | 190 | 'download_and_redirecting' => sprintf( |
191 | 191 | __('File Generation complete. Downloading, and %1$sredirecting%2$s...', 'event_espresso'), |
192 | - '<a href="' . $_REQUEST['return_url'] . '">', |
|
192 | + '<a href="'.$_REQUEST['return_url'].'">', |
|
193 | 193 | '</a>' |
194 | 194 | ), |
195 | 195 | 'return_url' => $_REQUEST['return_url'], |
@@ -207,26 +207,26 @@ discard block |
||
207 | 207 | protected function _enqueue_batch_job_scripts_and_styles_and_start_job() |
208 | 208 | { |
209 | 209 | // just copy the bits of EE admin's eei18n that we need in the JS |
210 | - EE_Registry::$i18n_js_strings['batchJobError'] = esc_html__( |
|
210 | + EE_Registry::$i18n_js_strings['batchJobError'] = esc_html__( |
|
211 | 211 | 'An error occurred and the job has been stopped. Please refresh the page to try again.', |
212 | 212 | 'event_espresso' |
213 | 213 | ); |
214 | 214 | wp_register_script( |
215 | 215 | 'progress_bar', |
216 | - EE_PLUGIN_DIR_URL . 'core/libraries/batch/Assets/progress_bar.js', |
|
216 | + EE_PLUGIN_DIR_URL.'core/libraries/batch/Assets/progress_bar.js', |
|
217 | 217 | array('jquery'), |
218 | 218 | EVENT_ESPRESSO_VERSION, |
219 | 219 | true |
220 | 220 | ); |
221 | 221 | wp_enqueue_style( |
222 | 222 | 'progress_bar', |
223 | - EE_PLUGIN_DIR_URL . 'core/libraries/batch/Assets/progress_bar.css', |
|
223 | + EE_PLUGIN_DIR_URL.'core/libraries/batch/Assets/progress_bar.css', |
|
224 | 224 | array(), |
225 | 225 | EVENT_ESPRESSO_VERSION |
226 | 226 | ); |
227 | 227 | wp_enqueue_script( |
228 | 228 | 'batch_runner', |
229 | - EE_PLUGIN_DIR_URL . 'core/libraries/batch/Assets/batch_runner.js', |
|
229 | + EE_PLUGIN_DIR_URL.'core/libraries/batch/Assets/batch_runner.js', |
|
230 | 230 | array('progress_bar', CoreAssetManager::JS_HANDLE_CORE), |
231 | 231 | EVENT_ESPRESSO_VERSION, |
232 | 232 | true |
@@ -253,7 +253,7 @@ discard block |
||
253 | 253 | public function override_template($template) |
254 | 254 | { |
255 | 255 | if (isset($_REQUEST['espresso_batch']) && isset($_REQUEST['batch'])) { |
256 | - return EE_MODULES . 'batch/templates/batch_frontend_wrapper.template.html'; |
|
256 | + return EE_MODULES.'batch/templates/batch_frontend_wrapper.template.html'; |
|
257 | 257 | } |
258 | 258 | return $template; |
259 | 259 | } |
@@ -280,7 +280,7 @@ discard block |
||
280 | 280 | public function show_admin_page() |
281 | 281 | { |
282 | 282 | echo EEH_Template::locate_template( |
283 | - EE_MODULES . 'batch/templates/batch_wrapper.template.html', |
|
283 | + EE_MODULES.'batch/templates/batch_wrapper.template.html', |
|
284 | 284 | array('batch_request_type' => $this->batch_request_type()) |
285 | 285 | ); |
286 | 286 | } |
@@ -29,359 +29,359 @@ |
||
29 | 29 | class EED_Batch extends EED_Module |
30 | 30 | { |
31 | 31 | |
32 | - /** |
|
33 | - * Possibly value for $_REQUEST[ 'batch' ]. Indicates to run a job that |
|
34 | - * processes data only |
|
35 | - */ |
|
36 | - const batch_job = 'job'; |
|
37 | - /** |
|
38 | - * Possibly value for $_REQUEST[ 'batch' ]. Indicates to run a job that |
|
39 | - * produces a file for download |
|
40 | - */ |
|
41 | - const batch_file_job = 'file'; |
|
42 | - /** |
|
43 | - * Possibly value for $_REQUEST[ 'batch' ]. Indicates this request is NOT |
|
44 | - * for a batch job. It's the same as not providing the $_REQUEST[ 'batch' ] |
|
45 | - * at all |
|
46 | - */ |
|
47 | - const batch_not_job = 'none'; |
|
32 | + /** |
|
33 | + * Possibly value for $_REQUEST[ 'batch' ]. Indicates to run a job that |
|
34 | + * processes data only |
|
35 | + */ |
|
36 | + const batch_job = 'job'; |
|
37 | + /** |
|
38 | + * Possibly value for $_REQUEST[ 'batch' ]. Indicates to run a job that |
|
39 | + * produces a file for download |
|
40 | + */ |
|
41 | + const batch_file_job = 'file'; |
|
42 | + /** |
|
43 | + * Possibly value for $_REQUEST[ 'batch' ]. Indicates this request is NOT |
|
44 | + * for a batch job. It's the same as not providing the $_REQUEST[ 'batch' ] |
|
45 | + * at all |
|
46 | + */ |
|
47 | + const batch_not_job = 'none'; |
|
48 | 48 | |
49 | - /** |
|
50 | - * |
|
51 | - * @var string 'file', or 'job', or false to indicate its not a batch request at all |
|
52 | - */ |
|
53 | - protected $_batch_request_type = null; |
|
49 | + /** |
|
50 | + * |
|
51 | + * @var string 'file', or 'job', or false to indicate its not a batch request at all |
|
52 | + */ |
|
53 | + protected $_batch_request_type = null; |
|
54 | 54 | |
55 | - /** |
|
56 | - * Because we want to use the response in both the localized JS and in the body |
|
57 | - * we need to make this response available between method calls |
|
58 | - * |
|
59 | - * @var \EventEspressoBatchRequest\Helpers\JobStepResponse |
|
60 | - */ |
|
61 | - protected $_job_step_response = null; |
|
55 | + /** |
|
56 | + * Because we want to use the response in both the localized JS and in the body |
|
57 | + * we need to make this response available between method calls |
|
58 | + * |
|
59 | + * @var \EventEspressoBatchRequest\Helpers\JobStepResponse |
|
60 | + */ |
|
61 | + protected $_job_step_response = null; |
|
62 | 62 | |
63 | - /** |
|
64 | - * @var LoaderInterface |
|
65 | - */ |
|
66 | - protected $loader; |
|
63 | + /** |
|
64 | + * @var LoaderInterface |
|
65 | + */ |
|
66 | + protected $loader; |
|
67 | 67 | |
68 | - /** |
|
69 | - * Gets the batch instance |
|
70 | - * |
|
71 | - * @return EED_Batch |
|
72 | - */ |
|
73 | - public static function instance() |
|
74 | - { |
|
75 | - return self::get_instance(); |
|
76 | - } |
|
68 | + /** |
|
69 | + * Gets the batch instance |
|
70 | + * |
|
71 | + * @return EED_Batch |
|
72 | + */ |
|
73 | + public static function instance() |
|
74 | + { |
|
75 | + return self::get_instance(); |
|
76 | + } |
|
77 | 77 | |
78 | - /** |
|
79 | - * Sets hooks to enable batch jobs on the frontend. Disabled by default |
|
80 | - * because it's an attack vector and there are currently no implementations |
|
81 | - */ |
|
82 | - public static function set_hooks() |
|
83 | - { |
|
84 | - // because this is a possibel attack vector, let's have this disabled until |
|
85 | - // we at least have a real use for it on the frontend |
|
86 | - if (apply_filters('FHEE__EED_Batch__set_hooks__enable_frontend_batch', false)) { |
|
87 | - add_action('wp_enqueue_scripts', array(self::instance(), 'enqueue_scripts')); |
|
88 | - add_filter('template_include', array(self::instance(), 'override_template'), 99); |
|
89 | - } |
|
90 | - } |
|
78 | + /** |
|
79 | + * Sets hooks to enable batch jobs on the frontend. Disabled by default |
|
80 | + * because it's an attack vector and there are currently no implementations |
|
81 | + */ |
|
82 | + public static function set_hooks() |
|
83 | + { |
|
84 | + // because this is a possibel attack vector, let's have this disabled until |
|
85 | + // we at least have a real use for it on the frontend |
|
86 | + if (apply_filters('FHEE__EED_Batch__set_hooks__enable_frontend_batch', false)) { |
|
87 | + add_action('wp_enqueue_scripts', array(self::instance(), 'enqueue_scripts')); |
|
88 | + add_filter('template_include', array(self::instance(), 'override_template'), 99); |
|
89 | + } |
|
90 | + } |
|
91 | 91 | |
92 | - /** |
|
93 | - * Initializes some hooks for the admin in order to run batch jobs |
|
94 | - */ |
|
95 | - public static function set_hooks_admin() |
|
96 | - { |
|
97 | - add_action('admin_menu', array(self::instance(), 'register_admin_pages')); |
|
98 | - add_action('admin_enqueue_scripts', array(self::instance(), 'enqueue_scripts')); |
|
92 | + /** |
|
93 | + * Initializes some hooks for the admin in order to run batch jobs |
|
94 | + */ |
|
95 | + public static function set_hooks_admin() |
|
96 | + { |
|
97 | + add_action('admin_menu', array(self::instance(), 'register_admin_pages')); |
|
98 | + add_action('admin_enqueue_scripts', array(self::instance(), 'enqueue_scripts')); |
|
99 | 99 | |
100 | - // ajax |
|
101 | - add_action('wp_ajax_espresso_batch_continue', array(self::instance(), 'batch_continue')); |
|
102 | - add_action('wp_ajax_espresso_batch_cleanup', array(self::instance(), 'batch_cleanup')); |
|
103 | - add_action('wp_ajax_nopriv_espresso_batch_continue', array(self::instance(), 'batch_continue')); |
|
104 | - add_action('wp_ajax_nopriv_espresso_batch_cleanup', array(self::instance(), 'batch_cleanup')); |
|
105 | - } |
|
100 | + // ajax |
|
101 | + add_action('wp_ajax_espresso_batch_continue', array(self::instance(), 'batch_continue')); |
|
102 | + add_action('wp_ajax_espresso_batch_cleanup', array(self::instance(), 'batch_cleanup')); |
|
103 | + add_action('wp_ajax_nopriv_espresso_batch_continue', array(self::instance(), 'batch_continue')); |
|
104 | + add_action('wp_ajax_nopriv_espresso_batch_cleanup', array(self::instance(), 'batch_cleanup')); |
|
105 | + } |
|
106 | 106 | |
107 | - /** |
|
108 | - * @since 4.9.80.p |
|
109 | - * @return LoaderInterface |
|
110 | - * @throws InvalidArgumentException |
|
111 | - * @throws InvalidDataTypeException |
|
112 | - * @throws InvalidInterfaceException |
|
113 | - */ |
|
114 | - protected function getLoader() |
|
115 | - { |
|
116 | - if (!$this->loader instanceof LoaderInterface) { |
|
117 | - $this->loader = LoaderFactory::getLoader(); |
|
118 | - } |
|
119 | - return $this->loader; |
|
120 | - } |
|
107 | + /** |
|
108 | + * @since 4.9.80.p |
|
109 | + * @return LoaderInterface |
|
110 | + * @throws InvalidArgumentException |
|
111 | + * @throws InvalidDataTypeException |
|
112 | + * @throws InvalidInterfaceException |
|
113 | + */ |
|
114 | + protected function getLoader() |
|
115 | + { |
|
116 | + if (!$this->loader instanceof LoaderInterface) { |
|
117 | + $this->loader = LoaderFactory::getLoader(); |
|
118 | + } |
|
119 | + return $this->loader; |
|
120 | + } |
|
121 | 121 | |
122 | - /** |
|
123 | - * Enqueues batch scripts on the frontend or admin, and creates a job |
|
124 | - */ |
|
125 | - public function enqueue_scripts() |
|
126 | - { |
|
127 | - if ( |
|
128 | - isset($_REQUEST['espresso_batch']) |
|
129 | - || |
|
130 | - ( |
|
131 | - isset($_REQUEST['page']) |
|
132 | - && $_REQUEST['page'] == 'espresso_batch' |
|
133 | - ) |
|
134 | - ) { |
|
135 | - if (! isset($_REQUEST['default_nonce']) || ! wp_verify_nonce($_REQUEST['default_nonce'], 'default_nonce')) { |
|
136 | - wp_die(esc_html__('The link you clicked to start the batch job has expired. Please go back and refresh the previous page.', 'event_espresso')); |
|
137 | - } |
|
138 | - switch ($this->batch_request_type()) { |
|
139 | - case self::batch_job: |
|
140 | - $this->enqueue_scripts_styles_batch_create(); |
|
141 | - break; |
|
142 | - case self::batch_file_job: |
|
143 | - $this->enqueue_scripts_styles_batch_file_create(); |
|
144 | - break; |
|
145 | - } |
|
146 | - } |
|
147 | - } |
|
122 | + /** |
|
123 | + * Enqueues batch scripts on the frontend or admin, and creates a job |
|
124 | + */ |
|
125 | + public function enqueue_scripts() |
|
126 | + { |
|
127 | + if ( |
|
128 | + isset($_REQUEST['espresso_batch']) |
|
129 | + || |
|
130 | + ( |
|
131 | + isset($_REQUEST['page']) |
|
132 | + && $_REQUEST['page'] == 'espresso_batch' |
|
133 | + ) |
|
134 | + ) { |
|
135 | + if (! isset($_REQUEST['default_nonce']) || ! wp_verify_nonce($_REQUEST['default_nonce'], 'default_nonce')) { |
|
136 | + wp_die(esc_html__('The link you clicked to start the batch job has expired. Please go back and refresh the previous page.', 'event_espresso')); |
|
137 | + } |
|
138 | + switch ($this->batch_request_type()) { |
|
139 | + case self::batch_job: |
|
140 | + $this->enqueue_scripts_styles_batch_create(); |
|
141 | + break; |
|
142 | + case self::batch_file_job: |
|
143 | + $this->enqueue_scripts_styles_batch_file_create(); |
|
144 | + break; |
|
145 | + } |
|
146 | + } |
|
147 | + } |
|
148 | 148 | |
149 | - /** |
|
150 | - * Create a batch job, enqueues a script to run it, and localizes some data for it |
|
151 | - */ |
|
152 | - public function enqueue_scripts_styles_batch_create() |
|
153 | - { |
|
154 | - $job_response = $this->_enqueue_batch_job_scripts_and_styles_and_start_job(); |
|
155 | - wp_enqueue_script( |
|
156 | - 'batch_runner_init', |
|
157 | - BATCH_URL . 'assets/batch_runner_init.js', |
|
158 | - array('batch_runner'), |
|
159 | - EVENT_ESPRESSO_VERSION, |
|
160 | - true |
|
161 | - ); |
|
162 | - wp_localize_script('batch_runner_init', 'ee_job_response', $job_response->to_array()); |
|
163 | - wp_localize_script( |
|
164 | - 'batch_runner_init', |
|
165 | - 'ee_job_i18n', |
|
166 | - array( |
|
167 | - 'return_url' => $_REQUEST['return_url'], |
|
168 | - ) |
|
169 | - ); |
|
170 | - } |
|
149 | + /** |
|
150 | + * Create a batch job, enqueues a script to run it, and localizes some data for it |
|
151 | + */ |
|
152 | + public function enqueue_scripts_styles_batch_create() |
|
153 | + { |
|
154 | + $job_response = $this->_enqueue_batch_job_scripts_and_styles_and_start_job(); |
|
155 | + wp_enqueue_script( |
|
156 | + 'batch_runner_init', |
|
157 | + BATCH_URL . 'assets/batch_runner_init.js', |
|
158 | + array('batch_runner'), |
|
159 | + EVENT_ESPRESSO_VERSION, |
|
160 | + true |
|
161 | + ); |
|
162 | + wp_localize_script('batch_runner_init', 'ee_job_response', $job_response->to_array()); |
|
163 | + wp_localize_script( |
|
164 | + 'batch_runner_init', |
|
165 | + 'ee_job_i18n', |
|
166 | + array( |
|
167 | + 'return_url' => $_REQUEST['return_url'], |
|
168 | + ) |
|
169 | + ); |
|
170 | + } |
|
171 | 171 | |
172 | - /** |
|
173 | - * Creates a batch job which will download a file, enqueues a script to run the job, and localizes some data for it |
|
174 | - */ |
|
175 | - public function enqueue_scripts_styles_batch_file_create() |
|
176 | - { |
|
177 | - // creates a job based on the request variable |
|
178 | - $job_response = $this->_enqueue_batch_job_scripts_and_styles_and_start_job(); |
|
179 | - wp_enqueue_script( |
|
180 | - 'batch_file_runner_init', |
|
181 | - BATCH_URL . 'assets/batch_file_runner_init.js', |
|
182 | - array('batch_runner'), |
|
183 | - EVENT_ESPRESSO_VERSION, |
|
184 | - true |
|
185 | - ); |
|
186 | - wp_localize_script('batch_file_runner_init', 'ee_job_response', $job_response->to_array()); |
|
187 | - wp_localize_script( |
|
188 | - 'batch_file_runner_init', |
|
189 | - 'ee_job_i18n', |
|
190 | - array( |
|
191 | - 'download_and_redirecting' => sprintf( |
|
192 | - __('File Generation complete. Downloading, and %1$sredirecting%2$s...', 'event_espresso'), |
|
193 | - '<a href="' . $_REQUEST['return_url'] . '">', |
|
194 | - '</a>' |
|
195 | - ), |
|
196 | - 'return_url' => $_REQUEST['return_url'], |
|
197 | - ) |
|
198 | - ); |
|
199 | - } |
|
172 | + /** |
|
173 | + * Creates a batch job which will download a file, enqueues a script to run the job, and localizes some data for it |
|
174 | + */ |
|
175 | + public function enqueue_scripts_styles_batch_file_create() |
|
176 | + { |
|
177 | + // creates a job based on the request variable |
|
178 | + $job_response = $this->_enqueue_batch_job_scripts_and_styles_and_start_job(); |
|
179 | + wp_enqueue_script( |
|
180 | + 'batch_file_runner_init', |
|
181 | + BATCH_URL . 'assets/batch_file_runner_init.js', |
|
182 | + array('batch_runner'), |
|
183 | + EVENT_ESPRESSO_VERSION, |
|
184 | + true |
|
185 | + ); |
|
186 | + wp_localize_script('batch_file_runner_init', 'ee_job_response', $job_response->to_array()); |
|
187 | + wp_localize_script( |
|
188 | + 'batch_file_runner_init', |
|
189 | + 'ee_job_i18n', |
|
190 | + array( |
|
191 | + 'download_and_redirecting' => sprintf( |
|
192 | + __('File Generation complete. Downloading, and %1$sredirecting%2$s...', 'event_espresso'), |
|
193 | + '<a href="' . $_REQUEST['return_url'] . '">', |
|
194 | + '</a>' |
|
195 | + ), |
|
196 | + 'return_url' => $_REQUEST['return_url'], |
|
197 | + ) |
|
198 | + ); |
|
199 | + } |
|
200 | 200 | |
201 | - /** |
|
202 | - * Enqueues scripts and styles common to any batch job, and creates |
|
203 | - * a job from the request data, and stores the response in the |
|
204 | - * $this->_job_step_response property |
|
205 | - * |
|
206 | - * @return \EventEspressoBatchRequest\Helpers\JobStepResponse |
|
207 | - */ |
|
208 | - protected function _enqueue_batch_job_scripts_and_styles_and_start_job() |
|
209 | - { |
|
210 | - // just copy the bits of EE admin's eei18n that we need in the JS |
|
211 | - EE_Registry::$i18n_js_strings['batchJobError'] = esc_html__( |
|
212 | - 'An error occurred and the job has been stopped. Please refresh the page to try again.', |
|
213 | - 'event_espresso' |
|
214 | - ); |
|
215 | - wp_register_script( |
|
216 | - 'progress_bar', |
|
217 | - EE_PLUGIN_DIR_URL . 'core/libraries/batch/Assets/progress_bar.js', |
|
218 | - array('jquery'), |
|
219 | - EVENT_ESPRESSO_VERSION, |
|
220 | - true |
|
221 | - ); |
|
222 | - wp_enqueue_style( |
|
223 | - 'progress_bar', |
|
224 | - EE_PLUGIN_DIR_URL . 'core/libraries/batch/Assets/progress_bar.css', |
|
225 | - array(), |
|
226 | - EVENT_ESPRESSO_VERSION |
|
227 | - ); |
|
228 | - wp_enqueue_script( |
|
229 | - 'batch_runner', |
|
230 | - EE_PLUGIN_DIR_URL . 'core/libraries/batch/Assets/batch_runner.js', |
|
231 | - array('progress_bar', CoreAssetManager::JS_HANDLE_CORE), |
|
232 | - EVENT_ESPRESSO_VERSION, |
|
233 | - true |
|
234 | - ); |
|
235 | - $job_handler_classname = stripslashes($_GET['job_handler']); |
|
236 | - $request_data = array_diff_key( |
|
237 | - $_REQUEST, |
|
238 | - array_flip(array('action', 'page', 'ee', 'batch')) |
|
239 | - ); |
|
240 | - $batch_runner = $this->getLoader()->getShared('EventEspressoBatchRequest\BatchRequestProcessor'); |
|
241 | - // eg 'EventEspressoBatchRequest\JobHandlers\RegistrationsReport' |
|
242 | - $job_response = $batch_runner->create_job($job_handler_classname, $request_data); |
|
243 | - // remember the response for later. We need it to display the page body |
|
244 | - $this->_job_step_response = $job_response; |
|
245 | - return $job_response; |
|
246 | - } |
|
201 | + /** |
|
202 | + * Enqueues scripts and styles common to any batch job, and creates |
|
203 | + * a job from the request data, and stores the response in the |
|
204 | + * $this->_job_step_response property |
|
205 | + * |
|
206 | + * @return \EventEspressoBatchRequest\Helpers\JobStepResponse |
|
207 | + */ |
|
208 | + protected function _enqueue_batch_job_scripts_and_styles_and_start_job() |
|
209 | + { |
|
210 | + // just copy the bits of EE admin's eei18n that we need in the JS |
|
211 | + EE_Registry::$i18n_js_strings['batchJobError'] = esc_html__( |
|
212 | + 'An error occurred and the job has been stopped. Please refresh the page to try again.', |
|
213 | + 'event_espresso' |
|
214 | + ); |
|
215 | + wp_register_script( |
|
216 | + 'progress_bar', |
|
217 | + EE_PLUGIN_DIR_URL . 'core/libraries/batch/Assets/progress_bar.js', |
|
218 | + array('jquery'), |
|
219 | + EVENT_ESPRESSO_VERSION, |
|
220 | + true |
|
221 | + ); |
|
222 | + wp_enqueue_style( |
|
223 | + 'progress_bar', |
|
224 | + EE_PLUGIN_DIR_URL . 'core/libraries/batch/Assets/progress_bar.css', |
|
225 | + array(), |
|
226 | + EVENT_ESPRESSO_VERSION |
|
227 | + ); |
|
228 | + wp_enqueue_script( |
|
229 | + 'batch_runner', |
|
230 | + EE_PLUGIN_DIR_URL . 'core/libraries/batch/Assets/batch_runner.js', |
|
231 | + array('progress_bar', CoreAssetManager::JS_HANDLE_CORE), |
|
232 | + EVENT_ESPRESSO_VERSION, |
|
233 | + true |
|
234 | + ); |
|
235 | + $job_handler_classname = stripslashes($_GET['job_handler']); |
|
236 | + $request_data = array_diff_key( |
|
237 | + $_REQUEST, |
|
238 | + array_flip(array('action', 'page', 'ee', 'batch')) |
|
239 | + ); |
|
240 | + $batch_runner = $this->getLoader()->getShared('EventEspressoBatchRequest\BatchRequestProcessor'); |
|
241 | + // eg 'EventEspressoBatchRequest\JobHandlers\RegistrationsReport' |
|
242 | + $job_response = $batch_runner->create_job($job_handler_classname, $request_data); |
|
243 | + // remember the response for later. We need it to display the page body |
|
244 | + $this->_job_step_response = $job_response; |
|
245 | + return $job_response; |
|
246 | + } |
|
247 | 247 | |
248 | - /** |
|
249 | - * If we are doing a frontend batch job, this makes it so WP shows our template's HTML |
|
250 | - * |
|
251 | - * @param string $template |
|
252 | - * @return string |
|
253 | - */ |
|
254 | - public function override_template($template) |
|
255 | - { |
|
256 | - if (isset($_REQUEST['espresso_batch']) && isset($_REQUEST['batch'])) { |
|
257 | - return EE_MODULES . 'batch/templates/batch_frontend_wrapper.template.html'; |
|
258 | - } |
|
259 | - return $template; |
|
260 | - } |
|
248 | + /** |
|
249 | + * If we are doing a frontend batch job, this makes it so WP shows our template's HTML |
|
250 | + * |
|
251 | + * @param string $template |
|
252 | + * @return string |
|
253 | + */ |
|
254 | + public function override_template($template) |
|
255 | + { |
|
256 | + if (isset($_REQUEST['espresso_batch']) && isset($_REQUEST['batch'])) { |
|
257 | + return EE_MODULES . 'batch/templates/batch_frontend_wrapper.template.html'; |
|
258 | + } |
|
259 | + return $template; |
|
260 | + } |
|
261 | 261 | |
262 | - /** |
|
263 | - * Adds an admin page which doesn't appear in the admin menu |
|
264 | - */ |
|
265 | - public function register_admin_pages() |
|
266 | - { |
|
267 | - add_submenu_page( |
|
268 | - '', // parent slug. we don't want this to actually appear in the menu |
|
269 | - __('Batch Job', 'event_espresso'), // page title |
|
270 | - 'n/a', // menu title |
|
271 | - 'read', // we want this page to actually be accessible to anyone, |
|
272 | - 'espresso_batch', // menu slug |
|
273 | - array(self::instance(), 'show_admin_page') |
|
274 | - ); |
|
275 | - } |
|
262 | + /** |
|
263 | + * Adds an admin page which doesn't appear in the admin menu |
|
264 | + */ |
|
265 | + public function register_admin_pages() |
|
266 | + { |
|
267 | + add_submenu_page( |
|
268 | + '', // parent slug. we don't want this to actually appear in the menu |
|
269 | + __('Batch Job', 'event_espresso'), // page title |
|
270 | + 'n/a', // menu title |
|
271 | + 'read', // we want this page to actually be accessible to anyone, |
|
272 | + 'espresso_batch', // menu slug |
|
273 | + array(self::instance(), 'show_admin_page') |
|
274 | + ); |
|
275 | + } |
|
276 | 276 | |
277 | - /** |
|
278 | - * Renders the admin page, after most of the work was already done during enqueuing scripts |
|
279 | - * of creating the job and localizing some data |
|
280 | - */ |
|
281 | - public function show_admin_page() |
|
282 | - { |
|
283 | - echo EEH_Template::locate_template( |
|
284 | - EE_MODULES . 'batch/templates/batch_wrapper.template.html', |
|
285 | - array('batch_request_type' => $this->batch_request_type()) |
|
286 | - ); |
|
287 | - } |
|
277 | + /** |
|
278 | + * Renders the admin page, after most of the work was already done during enqueuing scripts |
|
279 | + * of creating the job and localizing some data |
|
280 | + */ |
|
281 | + public function show_admin_page() |
|
282 | + { |
|
283 | + echo EEH_Template::locate_template( |
|
284 | + EE_MODULES . 'batch/templates/batch_wrapper.template.html', |
|
285 | + array('batch_request_type' => $this->batch_request_type()) |
|
286 | + ); |
|
287 | + } |
|
288 | 288 | |
289 | - /** |
|
290 | - * Receives ajax calls for continuing a job |
|
291 | - */ |
|
292 | - public function batch_continue() |
|
293 | - { |
|
294 | - $job_id = sanitize_text_field($_REQUEST['job_id']); |
|
295 | - $batch_runner = $this->getLoader()->getShared('EventEspressoBatchRequest\BatchRequestProcessor'); |
|
296 | - $response_obj = $batch_runner->continue_job($job_id); |
|
297 | - $this->_return_json($response_obj->to_array()); |
|
298 | - } |
|
289 | + /** |
|
290 | + * Receives ajax calls for continuing a job |
|
291 | + */ |
|
292 | + public function batch_continue() |
|
293 | + { |
|
294 | + $job_id = sanitize_text_field($_REQUEST['job_id']); |
|
295 | + $batch_runner = $this->getLoader()->getShared('EventEspressoBatchRequest\BatchRequestProcessor'); |
|
296 | + $response_obj = $batch_runner->continue_job($job_id); |
|
297 | + $this->_return_json($response_obj->to_array()); |
|
298 | + } |
|
299 | 299 | |
300 | - /** |
|
301 | - * Receives the ajax call to cleanup a job |
|
302 | - * |
|
303 | - * @return type |
|
304 | - */ |
|
305 | - public function batch_cleanup() |
|
306 | - { |
|
307 | - $job_id = sanitize_text_field($_REQUEST['job_id']); |
|
308 | - $batch_runner = $this->getLoader()->getShared('EventEspressoBatchRequest\BatchRequestProcessor'); |
|
309 | - $response_obj = $batch_runner->cleanup_job($job_id); |
|
310 | - $this->_return_json($response_obj->to_array()); |
|
311 | - } |
|
300 | + /** |
|
301 | + * Receives the ajax call to cleanup a job |
|
302 | + * |
|
303 | + * @return type |
|
304 | + */ |
|
305 | + public function batch_cleanup() |
|
306 | + { |
|
307 | + $job_id = sanitize_text_field($_REQUEST['job_id']); |
|
308 | + $batch_runner = $this->getLoader()->getShared('EventEspressoBatchRequest\BatchRequestProcessor'); |
|
309 | + $response_obj = $batch_runner->cleanup_job($job_id); |
|
310 | + $this->_return_json($response_obj->to_array()); |
|
311 | + } |
|
312 | 312 | |
313 | 313 | |
314 | - /** |
|
315 | - * Returns a json response |
|
316 | - * |
|
317 | - * @param array $data The data we want to send echo via in the JSON response's "data" element |
|
318 | - * |
|
319 | - * The returned json object is created from an array in the following format: |
|
320 | - * array( |
|
321 | - * 'notices' => '', // - contains any EE_Error formatted notices |
|
322 | - * 'data' => array() //this can be any key/value pairs that a method returns for later json parsing by the js. |
|
323 | - * We're also going to include the template args with every package (so js can pick out any specific template |
|
324 | - * args that might be included in here) |
|
325 | - * 'isEEajax' => true,//indicates this is a response from EE |
|
326 | - * ) |
|
327 | - */ |
|
328 | - protected function _return_json($data) |
|
329 | - { |
|
330 | - $json = array( |
|
331 | - 'notices' => EE_Error::get_notices(), |
|
332 | - 'data' => $data, |
|
333 | - 'isEEajax' => true |
|
334 | - // special flag so any ajax.Success methods in js can identify this return package as a EEajax package. |
|
335 | - ); |
|
314 | + /** |
|
315 | + * Returns a json response |
|
316 | + * |
|
317 | + * @param array $data The data we want to send echo via in the JSON response's "data" element |
|
318 | + * |
|
319 | + * The returned json object is created from an array in the following format: |
|
320 | + * array( |
|
321 | + * 'notices' => '', // - contains any EE_Error formatted notices |
|
322 | + * 'data' => array() //this can be any key/value pairs that a method returns for later json parsing by the js. |
|
323 | + * We're also going to include the template args with every package (so js can pick out any specific template |
|
324 | + * args that might be included in here) |
|
325 | + * 'isEEajax' => true,//indicates this is a response from EE |
|
326 | + * ) |
|
327 | + */ |
|
328 | + protected function _return_json($data) |
|
329 | + { |
|
330 | + $json = array( |
|
331 | + 'notices' => EE_Error::get_notices(), |
|
332 | + 'data' => $data, |
|
333 | + 'isEEajax' => true |
|
334 | + // special flag so any ajax.Success methods in js can identify this return package as a EEajax package. |
|
335 | + ); |
|
336 | 336 | |
337 | 337 | |
338 | - // make sure there are no php errors or headers_sent. Then we can set correct json header. |
|
339 | - if (null === error_get_last() || ! headers_sent()) { |
|
340 | - header('Content-Type: application/json; charset=UTF-8'); |
|
341 | - } |
|
342 | - echo wp_json_encode($json); |
|
343 | - exit(); |
|
344 | - } |
|
338 | + // make sure there are no php errors or headers_sent. Then we can set correct json header. |
|
339 | + if (null === error_get_last() || ! headers_sent()) { |
|
340 | + header('Content-Type: application/json; charset=UTF-8'); |
|
341 | + } |
|
342 | + echo wp_json_encode($json); |
|
343 | + exit(); |
|
344 | + } |
|
345 | 345 | |
346 | - /** |
|
347 | - * Gets the job step response which was done during the enqueuing of scripts |
|
348 | - * |
|
349 | - * @return \EventEspressoBatchRequest\Helpers\JobStepResponse |
|
350 | - */ |
|
351 | - public function job_step_response() |
|
352 | - { |
|
353 | - return $this->_job_step_response; |
|
354 | - } |
|
346 | + /** |
|
347 | + * Gets the job step response which was done during the enqueuing of scripts |
|
348 | + * |
|
349 | + * @return \EventEspressoBatchRequest\Helpers\JobStepResponse |
|
350 | + */ |
|
351 | + public function job_step_response() |
|
352 | + { |
|
353 | + return $this->_job_step_response; |
|
354 | + } |
|
355 | 355 | |
356 | - /** |
|
357 | - * Gets the batch request type indicated in the $_REQUEST |
|
358 | - * |
|
359 | - * @return string: EED_Batch::batch_job, EED_Batch::batch_file_job, EED_Batch::batch_not_job |
|
360 | - */ |
|
361 | - public function batch_request_type() |
|
362 | - { |
|
363 | - if ($this->_batch_request_type === null) { |
|
364 | - if (isset($_GET['batch'])) { |
|
365 | - if ($_GET['batch'] == self::batch_job) { |
|
366 | - $this->_batch_request_type = self::batch_job; |
|
367 | - } elseif ($_GET['batch'] == self::batch_file_job) { |
|
368 | - $this->_batch_request_type = self::batch_file_job; |
|
369 | - } |
|
370 | - } |
|
371 | - // if we didn't find that it was a batch request, indicate it wasn't |
|
372 | - if ($this->_batch_request_type === null) { |
|
373 | - $this->_batch_request_type = self::batch_not_job; |
|
374 | - } |
|
375 | - } |
|
376 | - return $this->_batch_request_type; |
|
377 | - } |
|
356 | + /** |
|
357 | + * Gets the batch request type indicated in the $_REQUEST |
|
358 | + * |
|
359 | + * @return string: EED_Batch::batch_job, EED_Batch::batch_file_job, EED_Batch::batch_not_job |
|
360 | + */ |
|
361 | + public function batch_request_type() |
|
362 | + { |
|
363 | + if ($this->_batch_request_type === null) { |
|
364 | + if (isset($_GET['batch'])) { |
|
365 | + if ($_GET['batch'] == self::batch_job) { |
|
366 | + $this->_batch_request_type = self::batch_job; |
|
367 | + } elseif ($_GET['batch'] == self::batch_file_job) { |
|
368 | + $this->_batch_request_type = self::batch_file_job; |
|
369 | + } |
|
370 | + } |
|
371 | + // if we didn't find that it was a batch request, indicate it wasn't |
|
372 | + if ($this->_batch_request_type === null) { |
|
373 | + $this->_batch_request_type = self::batch_not_job; |
|
374 | + } |
|
375 | + } |
|
376 | + return $this->_batch_request_type; |
|
377 | + } |
|
378 | 378 | |
379 | - /** |
|
380 | - * Unnecessary |
|
381 | - * |
|
382 | - * @param type $WP |
|
383 | - */ |
|
384 | - public function run($WP) |
|
385 | - { |
|
386 | - } |
|
379 | + /** |
|
380 | + * Unnecessary |
|
381 | + * |
|
382 | + * @param type $WP |
|
383 | + */ |
|
384 | + public function run($WP) |
|
385 | + { |
|
386 | + } |
|
387 | 387 | } |