@@ -86,7 +86,7 @@ discard block |
||
86 | 86 | */ |
87 | 87 | public function __construct($options_array = array()) |
88 | 88 | { |
89 | - $options_array = (array)apply_filters('FHEE__EE_Form_Section_Proper___construct__options_array', $options_array, |
|
89 | + $options_array = (array) apply_filters('FHEE__EE_Form_Section_Proper___construct__options_array', $options_array, |
|
90 | 90 | $this); |
91 | 91 | //call parent first, as it may be setting the name |
92 | 92 | parent::__construct($options_array); |
@@ -109,7 +109,7 @@ discard block |
||
109 | 109 | if (isset($options_array['layout_strategy'])) { |
110 | 110 | $this->_layout_strategy = $options_array['layout_strategy']; |
111 | 111 | } |
112 | - if (! $this->_layout_strategy) { |
|
112 | + if ( ! $this->_layout_strategy) { |
|
113 | 113 | $this->_layout_strategy = is_admin() ? new EE_Admin_Two_Column_Layout() : new EE_Two_Column_Layout(); |
114 | 114 | } |
115 | 115 | $this->_layout_strategy->_construct_finalize($this); |
@@ -238,7 +238,7 @@ discard block |
||
238 | 238 | if ($validate) { |
239 | 239 | $this->_validate(); |
240 | 240 | //if it's invalid, we're going to want to re-display so remember what they submitted |
241 | - if (! $this->is_valid()) { |
|
241 | + if ( ! $this->is_valid()) { |
|
242 | 242 | $this->store_submitted_form_data_in_session(); |
243 | 243 | } |
244 | 244 | } |
@@ -418,7 +418,7 @@ discard block |
||
418 | 418 | public function get_input($name, $require_construction_to_be_finalized = true) |
419 | 419 | { |
420 | 420 | $subsection = $this->get_subsection($name, $require_construction_to_be_finalized); |
421 | - if (! $subsection instanceof EE_Form_Input_Base) { |
|
421 | + if ( ! $subsection instanceof EE_Form_Input_Base) { |
|
422 | 422 | throw new EE_Error( |
423 | 423 | sprintf( |
424 | 424 | __( |
@@ -453,7 +453,7 @@ discard block |
||
453 | 453 | public function get_proper_subsection($name, $require_construction_to_be_finalized = true) |
454 | 454 | { |
455 | 455 | $subsection = $this->get_subsection($name, $require_construction_to_be_finalized); |
456 | - if (! $subsection instanceof EE_Form_Section_Proper) { |
|
456 | + if ( ! $subsection instanceof EE_Form_Section_Proper) { |
|
457 | 457 | throw new EE_Error( |
458 | 458 | sprintf( |
459 | 459 | __("Subsection '%'s is not an instanceof EE_Form_Section_Proper on form '%s'", 'event_espresso'), |
@@ -491,7 +491,7 @@ discard block |
||
491 | 491 | */ |
492 | 492 | public function is_valid() |
493 | 493 | { |
494 | - if (! $this->has_received_submission()) { |
|
494 | + if ( ! $this->has_received_submission()) { |
|
495 | 495 | throw new EE_Error( |
496 | 496 | sprintf( |
497 | 497 | __( |
@@ -501,14 +501,14 @@ discard block |
||
501 | 501 | ) |
502 | 502 | ); |
503 | 503 | } |
504 | - if (! parent::is_valid()) { |
|
504 | + if ( ! parent::is_valid()) { |
|
505 | 505 | return false; |
506 | 506 | } |
507 | 507 | // ok so no general errors to this entire form section. |
508 | 508 | // so let's check the subsections, but only set errors if that hasn't been done yet |
509 | 509 | $set_submission_errors = $this->submission_error_message() === '' ? true : false; |
510 | 510 | foreach ($this->get_validatable_subsections() as $subsection) { |
511 | - if (! $subsection->is_valid() || $subsection->get_validation_error_string() !== '') { |
|
511 | + if ( ! $subsection->is_valid() || $subsection->get_validation_error_string() !== '') { |
|
512 | 512 | if ($set_submission_errors) { |
513 | 513 | $this->set_submission_error_message($subsection->get_validation_error_string()); |
514 | 514 | } |
@@ -527,7 +527,7 @@ discard block |
||
527 | 527 | */ |
528 | 528 | protected function _set_default_name_if_empty() |
529 | 529 | { |
530 | - if (! $this->_name) { |
|
530 | + if ( ! $this->_name) { |
|
531 | 531 | $classname = get_class($this); |
532 | 532 | $default_name = str_replace("EE_", "", $classname); |
533 | 533 | $this->_name = $default_name; |
@@ -611,7 +611,7 @@ discard block |
||
611 | 611 | add_filter('FHEE_load_jquery_validate', '__return_true'); |
612 | 612 | wp_register_script( |
613 | 613 | 'ee_form_section_validation', |
614 | - EE_GLOBAL_ASSETS_URL . 'scripts' . DS . 'form_section_validation.js', |
|
614 | + EE_GLOBAL_ASSETS_URL.'scripts'.DS.'form_section_validation.js', |
|
615 | 615 | array('jquery-validate', 'jquery-ui-datepicker', 'jquery-validate-extra-methods'), |
616 | 616 | EVENT_ESPRESSO_VERSION, |
617 | 617 | true |
@@ -757,7 +757,7 @@ discard block |
||
757 | 757 | */ |
758 | 758 | public function ensure_scripts_localized() |
759 | 759 | { |
760 | - if (! EE_Form_Section_Proper::$_scripts_localized) { |
|
760 | + if ( ! EE_Form_Section_Proper::$_scripts_localized) { |
|
761 | 761 | $this->_enqueue_and_localize_form_js(); |
762 | 762 | } |
763 | 763 | } |
@@ -853,8 +853,8 @@ discard block |
||
853 | 853 | protected function _validate() |
854 | 854 | { |
855 | 855 | foreach ($this->get_validatable_subsections() as $subsection_name => $subsection) { |
856 | - if (method_exists($this, '_validate_' . $subsection_name)) { |
|
857 | - call_user_func_array(array($this, '_validate_' . $subsection_name), array($subsection)); |
|
856 | + if (method_exists($this, '_validate_'.$subsection_name)) { |
|
857 | + call_user_func_array(array($this, '_validate_'.$subsection_name), array($subsection)); |
|
858 | 858 | } |
859 | 859 | $subsection->_validate(); |
860 | 860 | } |
@@ -1130,7 +1130,7 @@ discard block |
||
1130 | 1130 | public function add_subsections($new_subsections, $subsection_name_to_target = null, $add_before = true) |
1131 | 1131 | { |
1132 | 1132 | foreach ($new_subsections as $subsection_name => $subsection) { |
1133 | - if (! $subsection instanceof EE_Form_Section_Base) { |
|
1133 | + if ( ! $subsection instanceof EE_Form_Section_Base) { |
|
1134 | 1134 | EE_Error::add_error( |
1135 | 1135 | sprintf( |
1136 | 1136 | __( |
@@ -1228,7 +1228,7 @@ discard block |
||
1228 | 1228 | public function html_name_prefix() |
1229 | 1229 | { |
1230 | 1230 | if ($this->parent_section() instanceof EE_Form_Section_Proper) { |
1231 | - return $this->parent_section()->html_name_prefix() . '[' . $this->name() . ']'; |
|
1231 | + return $this->parent_section()->html_name_prefix().'['.$this->name().']'; |
|
1232 | 1232 | } else { |
1233 | 1233 | return $this->name(); |
1234 | 1234 | } |
@@ -1272,7 +1272,7 @@ discard block |
||
1272 | 1272 | */ |
1273 | 1273 | public function ensure_construct_finalized_called() |
1274 | 1274 | { |
1275 | - if (! $this->_construction_finalized) { |
|
1275 | + if ( ! $this->_construction_finalized) { |
|
1276 | 1276 | $this->_construct_finalize($this->_parent_section, $this->_name); |
1277 | 1277 | } |
1278 | 1278 | } |
@@ -11,1386 +11,1386 @@ |
||
11 | 11 | class EE_Form_Section_Proper extends EE_Form_Section_Validatable |
12 | 12 | { |
13 | 13 | |
14 | - const SUBMITTED_FORM_DATA_SSN_KEY = 'submitted_form_data'; |
|
15 | - |
|
16 | - /** |
|
17 | - * Subsections |
|
18 | - * |
|
19 | - * @var EE_Form_Section_Validatable[] |
|
20 | - */ |
|
21 | - protected $_subsections = array(); |
|
22 | - |
|
23 | - /** |
|
24 | - * Strategy for laying out the form |
|
25 | - * |
|
26 | - * @var EE_Form_Section_Layout_Base |
|
27 | - */ |
|
28 | - protected $_layout_strategy; |
|
29 | - |
|
30 | - /** |
|
31 | - * Whether or not this form has received and validated a form submission yet |
|
32 | - * |
|
33 | - * @var boolean |
|
34 | - */ |
|
35 | - protected $_received_submission = false; |
|
36 | - |
|
37 | - /** |
|
38 | - * message displayed to users upon successful form submission |
|
39 | - * |
|
40 | - * @var string |
|
41 | - */ |
|
42 | - protected $_form_submission_success_message = ''; |
|
43 | - |
|
44 | - /** |
|
45 | - * message displayed to users upon unsuccessful form submission |
|
46 | - * |
|
47 | - * @var string |
|
48 | - */ |
|
49 | - protected $_form_submission_error_message = ''; |
|
50 | - |
|
51 | - /** |
|
52 | - * Stores all the data that will localized for form validation |
|
53 | - * |
|
54 | - * @var array |
|
55 | - */ |
|
56 | - static protected $_js_localization = array(); |
|
57 | - |
|
58 | - /** |
|
59 | - * whether or not the form's localized validation JS vars have been set |
|
60 | - * |
|
61 | - * @type boolean |
|
62 | - */ |
|
63 | - static protected $_scripts_localized = false; |
|
64 | - |
|
65 | - |
|
66 | - |
|
67 | - /** |
|
68 | - * when constructing a proper form section, calls _construct_finalize on children |
|
69 | - * so that they know who their parent is, and what name they've been given. |
|
70 | - * |
|
71 | - * @param array $options_array { |
|
72 | - * @type $subsections EE_Form_Section_Validatable[] where keys are the section's name |
|
73 | - * @type $include string[] numerically-indexed where values are section names to be included, |
|
74 | - * and in that order. This is handy if you want |
|
75 | - * the subsections to be ordered differently than the default, and if you override |
|
76 | - * which fields are shown |
|
77 | - * @type $exclude string[] values are subsections to be excluded. This is handy if you want |
|
78 | - * to remove certain default subsections (note: if you specify BOTH 'include' AND |
|
79 | - * 'exclude', the inclusions will be applied first, and the exclusions will exclude |
|
80 | - * items from that list of inclusions) |
|
81 | - * @type $layout_strategy EE_Form_Section_Layout_Base strategy for laying out the form |
|
82 | - * } @see EE_Form_Section_Validatable::__construct() |
|
83 | - * @throws \EE_Error |
|
84 | - */ |
|
85 | - public function __construct($options_array = array()) |
|
86 | - { |
|
87 | - $options_array = (array)apply_filters('FHEE__EE_Form_Section_Proper___construct__options_array', $options_array, |
|
88 | - $this); |
|
89 | - //call parent first, as it may be setting the name |
|
90 | - parent::__construct($options_array); |
|
91 | - //if they've included subsections in the constructor, add them now |
|
92 | - if (isset($options_array['include'])) { |
|
93 | - //we are going to make sure we ONLY have those subsections to include |
|
94 | - //AND we are going to make sure they're in that specified order |
|
95 | - $reordered_subsections = array(); |
|
96 | - foreach ($options_array['include'] as $input_name) { |
|
97 | - if (isset($this->_subsections[$input_name])) { |
|
98 | - $reordered_subsections[$input_name] = $this->_subsections[$input_name]; |
|
99 | - } |
|
100 | - } |
|
101 | - $this->_subsections = $reordered_subsections; |
|
102 | - } |
|
103 | - if (isset($options_array['exclude'])) { |
|
104 | - $exclude = $options_array['exclude']; |
|
105 | - $this->_subsections = array_diff_key($this->_subsections, array_flip($exclude)); |
|
106 | - } |
|
107 | - if (isset($options_array['layout_strategy'])) { |
|
108 | - $this->_layout_strategy = $options_array['layout_strategy']; |
|
109 | - } |
|
110 | - if (! $this->_layout_strategy) { |
|
111 | - $this->_layout_strategy = is_admin() ? new EE_Admin_Two_Column_Layout() : new EE_Two_Column_Layout(); |
|
112 | - } |
|
113 | - $this->_layout_strategy->_construct_finalize($this); |
|
114 | - //ok so we are definitely going to want the forms JS, |
|
115 | - //so enqueue it or remember to enqueue it during wp_enqueue_scripts |
|
116 | - if (did_action('wp_enqueue_scripts') || did_action('admin_enqueue_scripts')) { |
|
117 | - //ok so they've constructed this object after when they should have. |
|
118 | - //just enqueue the generic form scripts and initialize the form immediately in the JS |
|
119 | - \EE_Form_Section_Proper::wp_enqueue_scripts(true); |
|
120 | - } else { |
|
121 | - add_action('wp_enqueue_scripts', array('EE_Form_Section_Proper', 'wp_enqueue_scripts')); |
|
122 | - add_action('admin_enqueue_scripts', array('EE_Form_Section_Proper', 'wp_enqueue_scripts')); |
|
123 | - } |
|
124 | - add_action('wp_footer', array($this, 'ensure_scripts_localized'), 1); |
|
125 | - |
|
126 | - /** |
|
127 | - * Gives other plugins a chance to hook in before construct finalize is called. The form probably doesn't |
|
128 | - * yet have a parent form section. Since 4.9.32, when this action was introduced, this is the best place to |
|
129 | - * add a subsection onto a form, assuming you don't care what the form section's name, HTML ID, or HTML name etc are. |
|
130 | - * Also see AHEE__EE_Form_Section_Proper___construct_finalize__end |
|
131 | - * @since 4.9.32 |
|
132 | - * @param EE_Form_Section_Proper $this before __construct is done, but all of its logic, except maybe calling |
|
133 | - * _construct_finalize has been done |
|
134 | - * @param array $options_array options passed into the constructor |
|
135 | - */ |
|
136 | - do_action('AHEE__EE_Form_Input_Base___construct__before_construct_finalize_called', $this, $options_array); |
|
137 | - |
|
138 | - if (isset($options_array['name'])) { |
|
139 | - $this->_construct_finalize(null, $options_array['name']); |
|
140 | - } |
|
141 | - } |
|
142 | - |
|
143 | - |
|
144 | - |
|
145 | - /** |
|
146 | - * Finishes construction given the parent form section and this form section's name |
|
147 | - * |
|
148 | - * @param EE_Form_Section_Proper $parent_form_section |
|
149 | - * @param string $name |
|
150 | - * @throws \EE_Error |
|
151 | - */ |
|
152 | - public function _construct_finalize($parent_form_section, $name) |
|
153 | - { |
|
154 | - parent::_construct_finalize($parent_form_section, $name); |
|
155 | - $this->_set_default_name_if_empty(); |
|
156 | - $this->_set_default_html_id_if_empty(); |
|
157 | - foreach ($this->_subsections as $subsection_name => $subsection) { |
|
158 | - if ($subsection instanceof EE_Form_Section_Base) { |
|
159 | - $subsection->_construct_finalize($this, $subsection_name); |
|
160 | - } else { |
|
161 | - throw new EE_Error( |
|
162 | - sprintf( |
|
163 | - __('Subsection "%s" is not an instanceof EE_Form_Section_Base on form "%s". It is a "%s"', |
|
164 | - 'event_espresso'), |
|
165 | - $subsection_name, |
|
166 | - get_class($this), |
|
167 | - $subsection ? get_class($subsection) : __('NULL', 'event_espresso') |
|
168 | - ) |
|
169 | - ); |
|
170 | - } |
|
171 | - } |
|
172 | - /** |
|
173 | - * Action performed just after form has been given a name (and HTML ID etc) and is fully constructed. |
|
174 | - * If you have code that should modify the form and needs it and its subsections to have a name, HTML ID (or other attributes derived |
|
175 | - * from the name like the HTML label id, etc), this is where it should be done. |
|
176 | - * This might only happen just before displaying the form, or just before it receives form submission data. |
|
177 | - * If you need to modify the form or its subsections before _construct_finalize is called on it (and we've |
|
178 | - * ensured it has a name, HTML IDs, etc |
|
179 | - * @param EE_Form_Section_Proper $this |
|
180 | - * @param EE_Form_Section_Proper|null $parent_form_section |
|
181 | - * @param string $name |
|
182 | - */ |
|
183 | - do_action('AHEE__EE_Form_Section_Proper___construct_finalize__end', $this, $parent_form_section, $name); |
|
184 | - } |
|
185 | - |
|
186 | - |
|
187 | - |
|
188 | - /** |
|
189 | - * Gets the layout strategy for this form section |
|
190 | - * |
|
191 | - * @return EE_Form_Section_Layout_Base |
|
192 | - */ |
|
193 | - public function get_layout_strategy() |
|
194 | - { |
|
195 | - return $this->_layout_strategy; |
|
196 | - } |
|
197 | - |
|
198 | - |
|
199 | - |
|
200 | - /** |
|
201 | - * Gets the HTML for a single input for this form section according |
|
202 | - * to the layout strategy |
|
203 | - * |
|
204 | - * @param EE_Form_Input_Base $input |
|
205 | - * @return string |
|
206 | - */ |
|
207 | - public function get_html_for_input($input) |
|
208 | - { |
|
209 | - return $this->_layout_strategy->layout_input($input); |
|
210 | - } |
|
211 | - |
|
212 | - |
|
213 | - |
|
214 | - /** |
|
215 | - * was_submitted - checks if form inputs are present in request data |
|
216 | - * Basically an alias for form_data_present_in() (which is used by both |
|
217 | - * proper form sections and form inputs) |
|
218 | - * |
|
219 | - * @param null $form_data |
|
220 | - * @return boolean |
|
221 | - */ |
|
222 | - public function was_submitted($form_data = null) |
|
223 | - { |
|
224 | - return $this->form_data_present_in($form_data); |
|
225 | - } |
|
226 | - |
|
227 | - |
|
228 | - |
|
229 | - /** |
|
230 | - * After the form section is initially created, call this to sanitize the data in the submission |
|
231 | - * which relates to this form section, validate it, and set it as properties on the form. |
|
232 | - * |
|
233 | - * @param array|null $req_data should usually be $_POST (the default). |
|
234 | - * However, you CAN supply a different array. |
|
235 | - * Consider using set_defaults() instead however. |
|
236 | - * (If you rendered the form in the page using echo $form_x->get_html() |
|
237 | - * the inputs will have the correct name in the request data for this function |
|
238 | - * to find them and populate the form with them. |
|
239 | - * If you have a flat form (with only input subsections), |
|
240 | - * you can supply a flat array where keys |
|
241 | - * are the form input names and values are their values) |
|
242 | - * @param boolean $validate whether or not to perform validation on this data. Default is, |
|
243 | - * of course, to validate that data, and set errors on the invalid values. |
|
244 | - * But if the data has already been validated |
|
245 | - * (eg you validated the data then stored it in the DB) |
|
246 | - * you may want to skip this step. |
|
247 | - */ |
|
248 | - public function receive_form_submission($req_data = null, $validate = true) |
|
249 | - { |
|
250 | - $req_data = apply_filters('FHEE__EE_Form_Section_Proper__receive_form_submission__req_data', $req_data, $this, |
|
251 | - $validate); |
|
252 | - if ($req_data === null) { |
|
253 | - $req_data = array_merge($_GET, $_POST); |
|
254 | - } |
|
255 | - $req_data = apply_filters('FHEE__EE_Form_Section_Proper__receive_form_submission__request_data', $req_data, |
|
256 | - $this); |
|
257 | - $this->_normalize($req_data); |
|
258 | - if ($validate) { |
|
259 | - $this->_validate(); |
|
260 | - //if it's invalid, we're going to want to re-display so remember what they submitted |
|
261 | - if (! $this->is_valid()) { |
|
262 | - $this->store_submitted_form_data_in_session(); |
|
263 | - } |
|
264 | - } |
|
265 | - do_action('AHEE__EE_Form_Section_Proper__receive_form_submission__end', $req_data, $this, $validate); |
|
266 | - } |
|
267 | - |
|
268 | - |
|
269 | - |
|
270 | - /** |
|
271 | - * caches the originally submitted input values in the session |
|
272 | - * so that they can be used to repopulate the form if it failed validation |
|
273 | - * |
|
274 | - * @return boolean whether or not the data was successfully stored in the session |
|
275 | - */ |
|
276 | - protected function store_submitted_form_data_in_session() |
|
277 | - { |
|
278 | - return EE_Registry::instance()->SSN->set_session_data( |
|
279 | - array( |
|
280 | - \EE_Form_Section_Proper::SUBMITTED_FORM_DATA_SSN_KEY => $this->submitted_values(true), |
|
281 | - ) |
|
282 | - ); |
|
283 | - } |
|
284 | - |
|
285 | - |
|
286 | - |
|
287 | - /** |
|
288 | - * retrieves the originally submitted input values in the session |
|
289 | - * so that they can be used to repopulate the form if it failed validation |
|
290 | - * |
|
291 | - * @return array |
|
292 | - */ |
|
293 | - protected function get_submitted_form_data_from_session() |
|
294 | - { |
|
295 | - $session = EE_Registry::instance()->SSN; |
|
296 | - if ($session instanceof EE_Session) { |
|
297 | - return $session->get_session_data( |
|
298 | - \EE_Form_Section_Proper::SUBMITTED_FORM_DATA_SSN_KEY |
|
299 | - ); |
|
300 | - } else { |
|
301 | - return array(); |
|
302 | - } |
|
303 | - } |
|
304 | - |
|
305 | - |
|
306 | - |
|
307 | - /** |
|
308 | - * flushed the originally submitted input values from the session |
|
309 | - * |
|
310 | - * @return boolean whether or not the data was successfully removed from the session |
|
311 | - */ |
|
312 | - protected function flush_submitted_form_data_from_session() |
|
313 | - { |
|
314 | - return EE_Registry::instance()->SSN->reset_data( |
|
315 | - array(\EE_Form_Section_Proper::SUBMITTED_FORM_DATA_SSN_KEY) |
|
316 | - ); |
|
317 | - } |
|
318 | - |
|
319 | - |
|
320 | - |
|
321 | - /** |
|
322 | - * Populates this form and its subsections with data from the session. |
|
323 | - * (Wrapper for EE_Form_Section_Proper::receive_form_submission, so it shows |
|
324 | - * validation errors when displaying too) |
|
325 | - * Returns true if the form was populated from the session, false otherwise |
|
326 | - * |
|
327 | - * @return boolean |
|
328 | - */ |
|
329 | - public function populate_from_session() |
|
330 | - { |
|
331 | - $form_data_in_session = $this->get_submitted_form_data_from_session(); |
|
332 | - if (empty($form_data_in_session)) { |
|
333 | - return false; |
|
334 | - } |
|
335 | - $this->receive_form_submission($form_data_in_session); |
|
336 | - $this->flush_submitted_form_data_from_session(); |
|
337 | - if ($this->form_data_present_in($form_data_in_session)) { |
|
338 | - return true; |
|
339 | - } else { |
|
340 | - return false; |
|
341 | - } |
|
342 | - } |
|
343 | - |
|
344 | - |
|
345 | - |
|
346 | - /** |
|
347 | - * Populates the default data for the form, given an array where keys are |
|
348 | - * the input names, and values are their values (preferably normalized to be their |
|
349 | - * proper PHP types, not all strings... although that should be ok too). |
|
350 | - * Proper subsections are sub-arrays, the key being the subsection's name, and |
|
351 | - * the value being an array formatted in teh same way |
|
352 | - * |
|
353 | - * @param array $default_data |
|
354 | - */ |
|
355 | - public function populate_defaults($default_data) |
|
356 | - { |
|
357 | - foreach ($this->subsections(false) as $subsection_name => $subsection) { |
|
358 | - if (isset($default_data[$subsection_name])) { |
|
359 | - if ($subsection instanceof EE_Form_Input_Base) { |
|
360 | - $subsection->set_default($default_data[$subsection_name]); |
|
361 | - } elseif ($subsection instanceof EE_Form_Section_Proper) { |
|
362 | - $subsection->populate_defaults($default_data[$subsection_name]); |
|
363 | - } |
|
364 | - } |
|
365 | - } |
|
366 | - } |
|
367 | - |
|
368 | - |
|
369 | - |
|
370 | - /** |
|
371 | - * returns true if subsection exists |
|
372 | - * |
|
373 | - * @param string $name |
|
374 | - * @return boolean |
|
375 | - */ |
|
376 | - public function subsection_exists($name) |
|
377 | - { |
|
378 | - return isset($this->_subsections[$name]) ? true : false; |
|
379 | - } |
|
380 | - |
|
381 | - |
|
382 | - |
|
383 | - /** |
|
384 | - * Gets the subsection specified by its name |
|
385 | - * |
|
386 | - * @param string $name |
|
387 | - * @param boolean $require_construction_to_be_finalized most client code should leave this as TRUE |
|
388 | - * so that the inputs will be properly configured. |
|
389 | - * However, some client code may be ok |
|
390 | - * with construction finalize being called later |
|
391 | - * (realizing that the subsections' html names |
|
392 | - * might not be set yet, etc.) |
|
393 | - * @return EE_Form_Section_Base |
|
394 | - * @throws \EE_Error |
|
395 | - */ |
|
396 | - public function get_subsection($name, $require_construction_to_be_finalized = true) |
|
397 | - { |
|
398 | - if ($require_construction_to_be_finalized) { |
|
399 | - $this->ensure_construct_finalized_called(); |
|
400 | - } |
|
401 | - return $this->subsection_exists($name) ? $this->_subsections[$name] : null; |
|
402 | - } |
|
403 | - |
|
404 | - |
|
405 | - |
|
406 | - /** |
|
407 | - * Gets all the validatable subsections of this form section |
|
408 | - * |
|
409 | - * @return EE_Form_Section_Validatable[] |
|
410 | - */ |
|
411 | - public function get_validatable_subsections() |
|
412 | - { |
|
413 | - $validatable_subsections = array(); |
|
414 | - foreach ($this->subsections() as $name => $obj) { |
|
415 | - if ($obj instanceof EE_Form_Section_Validatable) { |
|
416 | - $validatable_subsections[$name] = $obj; |
|
417 | - } |
|
418 | - } |
|
419 | - return $validatable_subsections; |
|
420 | - } |
|
421 | - |
|
422 | - |
|
423 | - |
|
424 | - /** |
|
425 | - * Gets an input by the given name. If not found, or if its not an EE_FOrm_Input_Base child, |
|
426 | - * throw an EE_Error. |
|
427 | - * |
|
428 | - * @param string $name |
|
429 | - * @param boolean $require_construction_to_be_finalized most client code should |
|
430 | - * leave this as TRUE so that the inputs will be properly |
|
431 | - * configured. However, some client code may be ok with |
|
432 | - * construction finalize being called later |
|
433 | - * (realizing that the subsections' html names might not be |
|
434 | - * set yet, etc.) |
|
435 | - * @return EE_Form_Input_Base |
|
436 | - * @throws EE_Error |
|
437 | - */ |
|
438 | - public function get_input($name, $require_construction_to_be_finalized = true) |
|
439 | - { |
|
440 | - $subsection = $this->get_subsection($name, $require_construction_to_be_finalized); |
|
441 | - if (! $subsection instanceof EE_Form_Input_Base) { |
|
442 | - throw new EE_Error( |
|
443 | - sprintf( |
|
444 | - __( |
|
445 | - "Subsection '%s' is not an instanceof EE_Form_Input_Base on form '%s'. It is a '%s'", |
|
446 | - 'event_espresso' |
|
447 | - ), |
|
448 | - $name, |
|
449 | - get_class($this), |
|
450 | - $subsection ? get_class($subsection) : __("NULL", 'event_espresso') |
|
451 | - ) |
|
452 | - ); |
|
453 | - } |
|
454 | - return $subsection; |
|
455 | - } |
|
456 | - |
|
457 | - |
|
458 | - |
|
459 | - /** |
|
460 | - * Like get_input(), gets the proper subsection of the form given the name, |
|
461 | - * otherwise throws an EE_Error |
|
462 | - * |
|
463 | - * @param string $name |
|
464 | - * @param boolean $require_construction_to_be_finalized most client code should |
|
465 | - * leave this as TRUE so that the inputs will be properly |
|
466 | - * configured. However, some client code may be ok with |
|
467 | - * construction finalize being called later |
|
468 | - * (realizing that the subsections' html names might not be |
|
469 | - * set yet, etc.) |
|
470 | - * @return EE_Form_Section_Proper |
|
471 | - * @throws EE_Error |
|
472 | - */ |
|
473 | - public function get_proper_subsection($name, $require_construction_to_be_finalized = true) |
|
474 | - { |
|
475 | - $subsection = $this->get_subsection($name, $require_construction_to_be_finalized); |
|
476 | - if (! $subsection instanceof EE_Form_Section_Proper) { |
|
477 | - throw new EE_Error( |
|
478 | - sprintf( |
|
479 | - __("Subsection '%'s is not an instanceof EE_Form_Section_Proper on form '%s'", 'event_espresso'), |
|
480 | - $name, |
|
481 | - get_class($this) |
|
482 | - ) |
|
483 | - ); |
|
484 | - } |
|
485 | - return $subsection; |
|
486 | - } |
|
487 | - |
|
488 | - |
|
489 | - |
|
490 | - /** |
|
491 | - * Gets the value of the specified input. Should be called after receive_form_submission() |
|
492 | - * or populate_defaults() on the form, where the normalized value on the input is set. |
|
493 | - * |
|
494 | - * @param string $name |
|
495 | - * @return mixed depending on the input's type and its normalization strategy |
|
496 | - * @throws \EE_Error |
|
497 | - */ |
|
498 | - public function get_input_value($name) |
|
499 | - { |
|
500 | - $input = $this->get_input($name); |
|
501 | - return $input->normalized_value(); |
|
502 | - } |
|
503 | - |
|
504 | - |
|
505 | - |
|
506 | - /** |
|
507 | - * Checks if this form section itself is valid, and then checks its subsections |
|
508 | - * |
|
509 | - * @throws EE_Error |
|
510 | - * @return boolean |
|
511 | - */ |
|
512 | - public function is_valid() |
|
513 | - { |
|
514 | - if (! $this->has_received_submission()) { |
|
515 | - throw new EE_Error( |
|
516 | - sprintf( |
|
517 | - __( |
|
518 | - "You cannot check if a form is valid before receiving the form submission using receive_form_submission", |
|
519 | - "event_espresso" |
|
520 | - ) |
|
521 | - ) |
|
522 | - ); |
|
523 | - } |
|
524 | - if (! parent::is_valid()) { |
|
525 | - return false; |
|
526 | - } |
|
527 | - // ok so no general errors to this entire form section. |
|
528 | - // so let's check the subsections, but only set errors if that hasn't been done yet |
|
529 | - $set_submission_errors = $this->submission_error_message() === '' ? true : false; |
|
530 | - foreach ($this->get_validatable_subsections() as $subsection) { |
|
531 | - if (! $subsection->is_valid() || $subsection->get_validation_error_string() !== '') { |
|
532 | - if ($set_submission_errors) { |
|
533 | - $this->set_submission_error_message($subsection->get_validation_error_string()); |
|
534 | - } |
|
535 | - return false; |
|
536 | - } |
|
537 | - } |
|
538 | - return true; |
|
539 | - } |
|
540 | - |
|
541 | - |
|
542 | - |
|
543 | - /** |
|
544 | - * gets teh default name of this form section if none is specified |
|
545 | - * |
|
546 | - * @return string |
|
547 | - */ |
|
548 | - protected function _set_default_name_if_empty() |
|
549 | - { |
|
550 | - if (! $this->_name) { |
|
551 | - $classname = get_class($this); |
|
552 | - $default_name = str_replace("EE_", "", $classname); |
|
553 | - $this->_name = $default_name; |
|
554 | - } |
|
555 | - } |
|
556 | - |
|
557 | - |
|
558 | - |
|
559 | - /** |
|
560 | - * Returns the HTML for the form, except for the form opening and closing tags |
|
561 | - * (as the form section doesn't know where you necessarily want to send the information to), |
|
562 | - * and except for a submit button. Enqueus JS and CSS; if called early enough we will |
|
563 | - * try to enqueue them in the header, otherwise they'll be enqueued in the footer. |
|
564 | - * Not doing_it_wrong because theoretically this CAN be used properly, |
|
565 | - * provided its used during "wp_enqueue_scripts", or it doesn't need to enqueue |
|
566 | - * any CSS. |
|
567 | - * |
|
568 | - * @throws \EE_Error |
|
569 | - */ |
|
570 | - public function get_html_and_js() |
|
571 | - { |
|
572 | - $this->enqueue_js(); |
|
573 | - return $this->get_html(); |
|
574 | - } |
|
575 | - |
|
576 | - |
|
577 | - |
|
578 | - /** |
|
579 | - * returns HTML for displaying this form section. recursively calls display_section() on all subsections |
|
580 | - * |
|
581 | - * @param bool $display_previously_submitted_data |
|
582 | - * @return string |
|
583 | - */ |
|
584 | - public function get_html($display_previously_submitted_data = true) |
|
585 | - { |
|
586 | - $this->ensure_construct_finalized_called(); |
|
587 | - if ($display_previously_submitted_data) { |
|
588 | - $this->populate_from_session(); |
|
589 | - } |
|
590 | - return $this->_form_html_filter |
|
591 | - ? $this->_form_html_filter->filterHtml($this->_layout_strategy->layout_form(), $this) |
|
592 | - : $this->_layout_strategy->layout_form(); |
|
593 | - } |
|
594 | - |
|
595 | - |
|
596 | - |
|
597 | - /** |
|
598 | - * enqueues JS and CSS for the form. |
|
599 | - * It is preferred to call this before wp_enqueue_scripts so the |
|
600 | - * scripts and styles can be put in the header, but if called later |
|
601 | - * they will be put in the footer (which is OK for JS, but in HTML4 CSS should |
|
602 | - * only be in the header; but in HTML5 its ok in the body. |
|
603 | - * See http://stackoverflow.com/questions/4957446/load-external-css-file-in-body-tag. |
|
604 | - * So if your form enqueues CSS, it's preferred to call this before wp_enqueue_scripts.) |
|
605 | - * |
|
606 | - * @return string |
|
607 | - * @throws \EE_Error |
|
608 | - */ |
|
609 | - public function enqueue_js() |
|
610 | - { |
|
611 | - $this->_enqueue_and_localize_form_js(); |
|
612 | - foreach ($this->subsections() as $subsection) { |
|
613 | - $subsection->enqueue_js(); |
|
614 | - } |
|
615 | - } |
|
616 | - |
|
617 | - |
|
618 | - |
|
619 | - /** |
|
620 | - * adds a filter so that jquery validate gets enqueued in EE_System::wp_enqueue_scripts(). |
|
621 | - * This must be done BEFORE wp_enqueue_scripts() gets called, which is on |
|
622 | - * the wp_enqueue_scripts hook. |
|
623 | - * However, registering the form js and localizing it can happen when we |
|
624 | - * actually output the form (which is preferred, seeing how teh form's fields |
|
625 | - * could change until it's actually outputted) |
|
626 | - * |
|
627 | - * @param boolean $init_form_validation_automatically whether or not we want the form validation |
|
628 | - * to be triggered automatically or not |
|
629 | - * @return void |
|
630 | - */ |
|
631 | - public static function wp_enqueue_scripts($init_form_validation_automatically = true) |
|
632 | - { |
|
633 | - add_filter('FHEE_load_jquery_validate', '__return_true'); |
|
634 | - wp_register_script( |
|
635 | - 'ee_form_section_validation', |
|
636 | - EE_GLOBAL_ASSETS_URL . 'scripts' . DS . 'form_section_validation.js', |
|
637 | - array('jquery-validate', 'jquery-ui-datepicker', 'jquery-validate-extra-methods'), |
|
638 | - EVENT_ESPRESSO_VERSION, |
|
639 | - true |
|
640 | - ); |
|
641 | - wp_localize_script( |
|
642 | - 'ee_form_section_validation', |
|
643 | - 'ee_form_section_validation_init', |
|
644 | - array('init' => $init_form_validation_automatically ? '1' : '0') |
|
645 | - ); |
|
646 | - } |
|
647 | - |
|
648 | - |
|
649 | - |
|
650 | - /** |
|
651 | - * gets the variables used by form_section_validation.js. |
|
652 | - * This needs to be called AFTER we've called $this->_enqueue_jquery_validate_script, |
|
653 | - * but before the wordpress hook wp_loaded |
|
654 | - * |
|
655 | - * @throws \EE_Error |
|
656 | - */ |
|
657 | - public function _enqueue_and_localize_form_js() |
|
658 | - { |
|
659 | - $this->ensure_construct_finalized_called(); |
|
660 | - //actually, we don't want to localize just yet. There may be other forms on the page. |
|
661 | - //so we need to add our form section data to a static variable accessible by all form sections |
|
662 | - //and localize it just before the footer |
|
663 | - $this->localize_validation_rules(); |
|
664 | - add_action('wp_footer', array('EE_Form_Section_Proper', 'localize_script_for_all_forms'), 2); |
|
665 | - add_action('admin_footer', array('EE_Form_Section_Proper', 'localize_script_for_all_forms')); |
|
666 | - } |
|
667 | - |
|
668 | - |
|
669 | - |
|
670 | - /** |
|
671 | - * add our form section data to a static variable accessible by all form sections |
|
672 | - * |
|
673 | - * @param bool $return_for_subsection |
|
674 | - * @return void |
|
675 | - * @throws \EE_Error |
|
676 | - */ |
|
677 | - public function localize_validation_rules($return_for_subsection = false) |
|
678 | - { |
|
679 | - // we only want to localize vars ONCE for the entire form, |
|
680 | - // so if the form section doesn't have a parent, then it must be the top dog |
|
681 | - if ($return_for_subsection || ! $this->parent_section()) { |
|
682 | - EE_Form_Section_Proper::$_js_localization['form_data'][$this->html_id()] = array( |
|
683 | - 'form_section_id' => $this->html_id(true), |
|
684 | - 'validation_rules' => $this->get_jquery_validation_rules(), |
|
685 | - 'other_data' => $this->get_other_js_data(), |
|
686 | - 'errors' => $this->subsection_validation_errors_by_html_name(), |
|
687 | - ); |
|
688 | - EE_Form_Section_Proper::$_scripts_localized = true; |
|
689 | - } |
|
690 | - } |
|
691 | - |
|
692 | - |
|
693 | - |
|
694 | - /** |
|
695 | - * Gets an array of extra data that will be useful for client-side javascript. |
|
696 | - * This is primarily data added by inputs and forms in addition to any |
|
697 | - * scripts they might enqueue |
|
698 | - * |
|
699 | - * @param array $form_other_js_data |
|
700 | - * @return array |
|
701 | - */ |
|
702 | - public function get_other_js_data($form_other_js_data = array()) |
|
703 | - { |
|
704 | - foreach ($this->subsections() as $subsection) { |
|
705 | - $form_other_js_data = $subsection->get_other_js_data($form_other_js_data); |
|
706 | - } |
|
707 | - return $form_other_js_data; |
|
708 | - } |
|
709 | - |
|
710 | - |
|
711 | - |
|
712 | - /** |
|
713 | - * Gets a flat array of inputs for this form section and its subsections. |
|
714 | - * Keys are their form names, and values are the inputs themselves |
|
715 | - * |
|
716 | - * @return EE_Form_Input_Base |
|
717 | - */ |
|
718 | - public function inputs_in_subsections() |
|
719 | - { |
|
720 | - $inputs = array(); |
|
721 | - foreach ($this->subsections() as $subsection) { |
|
722 | - if ($subsection instanceof EE_Form_Input_Base) { |
|
723 | - $inputs[$subsection->html_name()] = $subsection; |
|
724 | - } elseif ($subsection instanceof EE_Form_Section_Proper) { |
|
725 | - $inputs += $subsection->inputs_in_subsections(); |
|
726 | - } |
|
727 | - } |
|
728 | - return $inputs; |
|
729 | - } |
|
730 | - |
|
731 | - |
|
732 | - |
|
733 | - /** |
|
734 | - * Gets a flat array of all the validation errors. |
|
735 | - * Keys are html names (because those should be unique) |
|
736 | - * and values are a string of all their validation errors |
|
737 | - * |
|
738 | - * @return string[] |
|
739 | - */ |
|
740 | - public function subsection_validation_errors_by_html_name() |
|
741 | - { |
|
742 | - $inputs = $this->inputs(); |
|
743 | - $errors = array(); |
|
744 | - foreach ($inputs as $form_input) { |
|
745 | - if ($form_input instanceof EE_Form_Input_Base && $form_input->get_validation_errors()) { |
|
746 | - $errors[$form_input->html_name()] = $form_input->get_validation_error_string(); |
|
747 | - } |
|
748 | - } |
|
749 | - return $errors; |
|
750 | - } |
|
751 | - |
|
752 | - |
|
753 | - |
|
754 | - /** |
|
755 | - * passes all the form data required by the JS to the JS, and enqueues the few required JS files. |
|
756 | - * Should be setup by each form during the _enqueues_and_localize_form_js |
|
757 | - */ |
|
758 | - public static function localize_script_for_all_forms() |
|
759 | - { |
|
760 | - //allow inputs and stuff to hook in their JS and stuff here |
|
761 | - do_action('AHEE__EE_Form_Section_Proper__localize_script_for_all_forms__begin'); |
|
762 | - EE_Form_Section_Proper::$_js_localization['localized_error_messages'] = EE_Form_Section_Proper::_get_localized_error_messages(); |
|
763 | - $email_validation_level = isset(EE_Registry::instance()->CFG->registration->email_validation_level) |
|
764 | - ? EE_Registry::instance()->CFG->registration->email_validation_level |
|
765 | - : 'wp_default'; |
|
766 | - EE_Form_Section_Proper::$_js_localization['email_validation_level'] = $email_validation_level; |
|
767 | - wp_enqueue_script('ee_form_section_validation'); |
|
768 | - wp_localize_script( |
|
769 | - 'ee_form_section_validation', |
|
770 | - 'ee_form_section_vars', |
|
771 | - EE_Form_Section_Proper::$_js_localization |
|
772 | - ); |
|
773 | - } |
|
774 | - |
|
775 | - |
|
776 | - |
|
777 | - /** |
|
778 | - * ensure_scripts_localized |
|
779 | - */ |
|
780 | - public function ensure_scripts_localized() |
|
781 | - { |
|
782 | - if (! EE_Form_Section_Proper::$_scripts_localized) { |
|
783 | - $this->_enqueue_and_localize_form_js(); |
|
784 | - } |
|
785 | - } |
|
786 | - |
|
787 | - |
|
788 | - |
|
789 | - /** |
|
790 | - * Gets the hard-coded validation error messages to be used in the JS. The convention |
|
791 | - * is that the key here should be the same as the custom validation rule put in the JS file |
|
792 | - * |
|
793 | - * @return array keys are custom validation rules, and values are internationalized strings |
|
794 | - */ |
|
795 | - private static function _get_localized_error_messages() |
|
796 | - { |
|
797 | - return array( |
|
798 | - 'validUrl' => __("This is not a valid absolute URL. Eg, http://domain.com/monkey.jpg", "event_espresso"), |
|
799 | - 'regex' => __('Please check your input', 'event_espresso'), |
|
800 | - ); |
|
801 | - } |
|
802 | - |
|
803 | - |
|
804 | - |
|
805 | - /** |
|
806 | - * @return array |
|
807 | - */ |
|
808 | - public static function js_localization() |
|
809 | - { |
|
810 | - return self::$_js_localization; |
|
811 | - } |
|
812 | - |
|
813 | - |
|
814 | - |
|
815 | - /** |
|
816 | - * @return array |
|
817 | - */ |
|
818 | - public static function reset_js_localization() |
|
819 | - { |
|
820 | - self::$_js_localization = array(); |
|
821 | - } |
|
822 | - |
|
823 | - |
|
824 | - |
|
825 | - /** |
|
826 | - * Gets the JS to put inside the jquery validation rules for subsection of this form section. |
|
827 | - * See parent function for more... |
|
828 | - * |
|
829 | - * @return array |
|
830 | - */ |
|
831 | - public function get_jquery_validation_rules() |
|
832 | - { |
|
833 | - $jquery_validation_rules = array(); |
|
834 | - foreach ($this->get_validatable_subsections() as $subsection) { |
|
835 | - $jquery_validation_rules = array_merge( |
|
836 | - $jquery_validation_rules, |
|
837 | - $subsection->get_jquery_validation_rules() |
|
838 | - ); |
|
839 | - } |
|
840 | - return $jquery_validation_rules; |
|
841 | - } |
|
842 | - |
|
843 | - |
|
844 | - |
|
845 | - /** |
|
846 | - * Sanitizes all the data and sets the sanitized value of each field |
|
847 | - * |
|
848 | - * @param array $req_data like $_POST |
|
849 | - * @return void |
|
850 | - */ |
|
851 | - protected function _normalize($req_data) |
|
852 | - { |
|
853 | - $this->_received_submission = true; |
|
854 | - $this->_validation_errors = array(); |
|
855 | - foreach ($this->get_validatable_subsections() as $subsection) { |
|
856 | - try { |
|
857 | - $subsection->_normalize($req_data); |
|
858 | - } catch (EE_Validation_Error $e) { |
|
859 | - $subsection->add_validation_error($e); |
|
860 | - } |
|
861 | - } |
|
862 | - } |
|
863 | - |
|
864 | - |
|
865 | - |
|
866 | - /** |
|
867 | - * Performs validation on this form section and its subsections. |
|
868 | - * For each subsection, |
|
869 | - * calls _validate_{subsection_name} on THIS form (if the function exists) |
|
870 | - * and passes it the subsection, then calls _validate on that subsection. |
|
871 | - * If you need to perform validation on the form as a whole (considering multiple) |
|
872 | - * you would be best to override this _validate method, |
|
873 | - * calling parent::_validate() first. |
|
874 | - */ |
|
875 | - protected function _validate() |
|
876 | - { |
|
877 | - foreach ($this->get_validatable_subsections() as $subsection_name => $subsection) { |
|
878 | - if (method_exists($this, '_validate_' . $subsection_name)) { |
|
879 | - call_user_func_array(array($this, '_validate_' . $subsection_name), array($subsection)); |
|
880 | - } |
|
881 | - $subsection->_validate(); |
|
882 | - } |
|
883 | - } |
|
884 | - |
|
885 | - |
|
886 | - |
|
887 | - /** |
|
888 | - * Gets all the validated inputs for the form section |
|
889 | - * |
|
890 | - * @return array |
|
891 | - */ |
|
892 | - public function valid_data() |
|
893 | - { |
|
894 | - $inputs = array(); |
|
895 | - foreach ($this->subsections() as $subsection_name => $subsection) { |
|
896 | - if ($subsection instanceof EE_Form_Section_Proper) { |
|
897 | - $inputs[$subsection_name] = $subsection->valid_data(); |
|
898 | - } else if ($subsection instanceof EE_Form_Input_Base) { |
|
899 | - $inputs[$subsection_name] = $subsection->normalized_value(); |
|
900 | - } |
|
901 | - } |
|
902 | - return $inputs; |
|
903 | - } |
|
904 | - |
|
905 | - |
|
906 | - |
|
907 | - /** |
|
908 | - * Gets all the inputs on this form section |
|
909 | - * |
|
910 | - * @return EE_Form_Input_Base[] |
|
911 | - */ |
|
912 | - public function inputs() |
|
913 | - { |
|
914 | - $inputs = array(); |
|
915 | - foreach ($this->subsections() as $subsection_name => $subsection) { |
|
916 | - if ($subsection instanceof EE_Form_Input_Base) { |
|
917 | - $inputs[$subsection_name] = $subsection; |
|
918 | - } |
|
919 | - } |
|
920 | - return $inputs; |
|
921 | - } |
|
922 | - |
|
923 | - |
|
924 | - |
|
925 | - /** |
|
926 | - * Gets all the subsections which are a proper form |
|
927 | - * |
|
928 | - * @return EE_Form_Section_Proper[] |
|
929 | - */ |
|
930 | - public function subforms() |
|
931 | - { |
|
932 | - $form_sections = array(); |
|
933 | - foreach ($this->subsections() as $name => $obj) { |
|
934 | - if ($obj instanceof EE_Form_Section_Proper) { |
|
935 | - $form_sections[$name] = $obj; |
|
936 | - } |
|
937 | - } |
|
938 | - return $form_sections; |
|
939 | - } |
|
940 | - |
|
941 | - |
|
942 | - |
|
943 | - /** |
|
944 | - * Gets all the subsections (inputs, proper subsections, or html-only sections). |
|
945 | - * Consider using inputs() or subforms() |
|
946 | - * if you only want form inputs or proper form sections. |
|
947 | - * |
|
948 | - * @param boolean $require_construction_to_be_finalized most client code should |
|
949 | - * leave this as TRUE so that the inputs will be properly |
|
950 | - * configured. However, some client code may be ok with |
|
951 | - * construction finalize being called later |
|
952 | - * (realizing that the subsections' html names might not be |
|
953 | - * set yet, etc.) |
|
954 | - * @return EE_Form_Section_Proper[] |
|
955 | - */ |
|
956 | - public function subsections($require_construction_to_be_finalized = true) |
|
957 | - { |
|
958 | - if ($require_construction_to_be_finalized) { |
|
959 | - $this->ensure_construct_finalized_called(); |
|
960 | - } |
|
961 | - return $this->_subsections; |
|
962 | - } |
|
963 | - |
|
964 | - |
|
965 | - |
|
966 | - /** |
|
967 | - * Returns a simple array where keys are input names, and values are their normalized |
|
968 | - * values. (Similar to calling get_input_value on inputs) |
|
969 | - * |
|
970 | - * @param boolean $include_subform_inputs Whether to include inputs from subforms, |
|
971 | - * or just this forms' direct children inputs |
|
972 | - * @param boolean $flatten Whether to force the results into 1-dimensional array, |
|
973 | - * or allow multidimensional array |
|
974 | - * @return array if $flatten is TRUE it will always be a 1-dimensional array |
|
975 | - * with array keys being input names |
|
976 | - * (regardless of whether they are from a subsection or not), |
|
977 | - * and if $flatten is FALSE it can be a multidimensional array |
|
978 | - * where keys are always subsection names and values are either |
|
979 | - * the input's normalized value, or an array like the top-level array |
|
980 | - */ |
|
981 | - public function input_values($include_subform_inputs = false, $flatten = false) |
|
982 | - { |
|
983 | - return $this->_input_values(false, $include_subform_inputs, $flatten); |
|
984 | - } |
|
985 | - |
|
986 | - |
|
987 | - |
|
988 | - /** |
|
989 | - * Similar to EE_Form_Section_Proper::input_values(), except this returns the 'display_value' |
|
990 | - * of each input. On some inputs (especially radio boxes or checkboxes), the value stored |
|
991 | - * is not necessarily the value we want to display to users. This creates an array |
|
992 | - * where keys are the input names, and values are their display values |
|
993 | - * |
|
994 | - * @param boolean $include_subform_inputs Whether to include inputs from subforms, |
|
995 | - * or just this forms' direct children inputs |
|
996 | - * @param boolean $flatten Whether to force the results into 1-dimensional array, |
|
997 | - * or allow multidimensional array |
|
998 | - * @return array if $flatten is TRUE it will always be a 1-dimensional array |
|
999 | - * with array keys being input names |
|
1000 | - * (regardless of whether they are from a subsection or not), |
|
1001 | - * and if $flatten is FALSE it can be a multidimensional array |
|
1002 | - * where keys are always subsection names and values are either |
|
1003 | - * the input's normalized value, or an array like the top-level array |
|
1004 | - */ |
|
1005 | - public function input_pretty_values($include_subform_inputs = false, $flatten = false) |
|
1006 | - { |
|
1007 | - return $this->_input_values(true, $include_subform_inputs, $flatten); |
|
1008 | - } |
|
1009 | - |
|
1010 | - |
|
1011 | - |
|
1012 | - /** |
|
1013 | - * Gets the input values from the form |
|
1014 | - * |
|
1015 | - * @param boolean $pretty Whether to retrieve the pretty value, |
|
1016 | - * or just the normalized value |
|
1017 | - * @param boolean $include_subform_inputs Whether to include inputs from subforms, |
|
1018 | - * or just this forms' direct children inputs |
|
1019 | - * @param boolean $flatten Whether to force the results into 1-dimensional array, |
|
1020 | - * or allow multidimensional array |
|
1021 | - * @return array if $flatten is TRUE it will always be a 1-dimensional array with array keys being |
|
1022 | - * input names (regardless of whether they are from a subsection or not), |
|
1023 | - * and if $flatten is FALSE it can be a multidimensional array |
|
1024 | - * where keys are always subsection names and values are either |
|
1025 | - * the input's normalized value, or an array like the top-level array |
|
1026 | - */ |
|
1027 | - public function _input_values($pretty = false, $include_subform_inputs = false, $flatten = false) |
|
1028 | - { |
|
1029 | - $input_values = array(); |
|
1030 | - foreach ($this->subsections() as $subsection_name => $subsection) { |
|
1031 | - if ($subsection instanceof EE_Form_Input_Base) { |
|
1032 | - $input_values[$subsection_name] = $pretty |
|
1033 | - ? $subsection->pretty_value() |
|
1034 | - : $subsection->normalized_value(); |
|
1035 | - } else if ($subsection instanceof EE_Form_Section_Proper && $include_subform_inputs) { |
|
1036 | - $subform_input_values = $subsection->_input_values($pretty, $include_subform_inputs, $flatten); |
|
1037 | - if ($flatten) { |
|
1038 | - $input_values = array_merge($input_values, $subform_input_values); |
|
1039 | - } else { |
|
1040 | - $input_values[$subsection_name] = $subform_input_values; |
|
1041 | - } |
|
1042 | - } |
|
1043 | - } |
|
1044 | - return $input_values; |
|
1045 | - } |
|
1046 | - |
|
1047 | - |
|
1048 | - |
|
1049 | - /** |
|
1050 | - * Gets the originally submitted input values from the form |
|
1051 | - * |
|
1052 | - * @param boolean $include_subforms Whether to include inputs from subforms, |
|
1053 | - * or just this forms' direct children inputs |
|
1054 | - * @return array if $flatten is TRUE it will always be a 1-dimensional array |
|
1055 | - * with array keys being input names |
|
1056 | - * (regardless of whether they are from a subsection or not), |
|
1057 | - * and if $flatten is FALSE it can be a multidimensional array |
|
1058 | - * where keys are always subsection names and values are either |
|
1059 | - * the input's normalized value, or an array like the top-level array |
|
1060 | - */ |
|
1061 | - public function submitted_values($include_subforms = false) |
|
1062 | - { |
|
1063 | - $submitted_values = array(); |
|
1064 | - foreach ($this->subsections() as $subsection) { |
|
1065 | - if ($subsection instanceof EE_Form_Input_Base) { |
|
1066 | - // is this input part of an array of inputs? |
|
1067 | - if (strpos($subsection->html_name(), '[') !== false) { |
|
1068 | - $full_input_name = \EEH_Array::convert_array_values_to_keys( |
|
1069 | - explode('[', str_replace(']', '', $subsection->html_name())), |
|
1070 | - $subsection->raw_value() |
|
1071 | - ); |
|
1072 | - $submitted_values = array_replace_recursive($submitted_values, $full_input_name); |
|
1073 | - } else { |
|
1074 | - $submitted_values[$subsection->html_name()] = $subsection->raw_value(); |
|
1075 | - } |
|
1076 | - } else if ($subsection instanceof EE_Form_Section_Proper && $include_subforms) { |
|
1077 | - $subform_input_values = $subsection->submitted_values($include_subforms); |
|
1078 | - $submitted_values = array_replace_recursive($submitted_values, $subform_input_values); |
|
1079 | - } |
|
1080 | - } |
|
1081 | - return $submitted_values; |
|
1082 | - } |
|
1083 | - |
|
1084 | - |
|
1085 | - |
|
1086 | - /** |
|
1087 | - * Indicates whether or not this form has received a submission yet |
|
1088 | - * (ie, had receive_form_submission called on it yet) |
|
1089 | - * |
|
1090 | - * @return boolean |
|
1091 | - * @throws \EE_Error |
|
1092 | - */ |
|
1093 | - public function has_received_submission() |
|
1094 | - { |
|
1095 | - $this->ensure_construct_finalized_called(); |
|
1096 | - return $this->_received_submission; |
|
1097 | - } |
|
1098 | - |
|
1099 | - |
|
1100 | - |
|
1101 | - /** |
|
1102 | - * Equivalent to passing 'exclude' in the constructor's options array. |
|
1103 | - * Removes the listed inputs from the form |
|
1104 | - * |
|
1105 | - * @param array $inputs_to_exclude values are the input names |
|
1106 | - * @return void |
|
1107 | - */ |
|
1108 | - public function exclude(array $inputs_to_exclude = array()) |
|
1109 | - { |
|
1110 | - foreach ($inputs_to_exclude as $input_to_exclude_name) { |
|
1111 | - unset($this->_subsections[$input_to_exclude_name]); |
|
1112 | - } |
|
1113 | - } |
|
1114 | - |
|
1115 | - |
|
1116 | - |
|
1117 | - /** |
|
1118 | - * @param array $inputs_to_hide |
|
1119 | - * @throws \EE_Error |
|
1120 | - */ |
|
1121 | - public function hide(array $inputs_to_hide = array()) |
|
1122 | - { |
|
1123 | - foreach ($inputs_to_hide as $input_to_hide) { |
|
1124 | - $input = $this->get_input($input_to_hide); |
|
1125 | - $input->set_display_strategy(new EE_Hidden_Display_Strategy()); |
|
1126 | - } |
|
1127 | - } |
|
1128 | - |
|
1129 | - |
|
1130 | - |
|
1131 | - /** |
|
1132 | - * add_subsections |
|
1133 | - * Adds the listed subsections to the form section. |
|
1134 | - * If $subsection_name_to_target is provided, |
|
1135 | - * then new subsections are added before or after that subsection, |
|
1136 | - * otherwise to the start or end of the entire subsections array. |
|
1137 | - * |
|
1138 | - * @param EE_Form_Section_Base[] $new_subsections array of new form subsections |
|
1139 | - * where keys are their names |
|
1140 | - * @param string $subsection_name_to_target an existing for section that $new_subsections |
|
1141 | - * should be added before or after |
|
1142 | - * IF $subsection_name_to_target is null, |
|
1143 | - * then $new_subsections will be added to |
|
1144 | - * the beginning or end of the entire subsections array |
|
1145 | - * @param boolean $add_before whether to add $new_subsections, before or after |
|
1146 | - * $subsection_name_to_target, |
|
1147 | - * or if $subsection_name_to_target is null, |
|
1148 | - * before or after entire subsections array |
|
1149 | - * @return void |
|
1150 | - * @throws \EE_Error |
|
1151 | - */ |
|
1152 | - public function add_subsections($new_subsections, $subsection_name_to_target = null, $add_before = true) |
|
1153 | - { |
|
1154 | - foreach ($new_subsections as $subsection_name => $subsection) { |
|
1155 | - if (! $subsection instanceof EE_Form_Section_Base) { |
|
1156 | - EE_Error::add_error( |
|
1157 | - sprintf( |
|
1158 | - __( |
|
1159 | - "Trying to add a %s as a subsection (it was named '%s') to the form section '%s'. It was removed.", |
|
1160 | - "event_espresso" |
|
1161 | - ), |
|
1162 | - get_class($subsection), |
|
1163 | - $subsection_name, |
|
1164 | - $this->name() |
|
1165 | - ) |
|
1166 | - ); |
|
1167 | - unset($new_subsections[$subsection_name]); |
|
1168 | - } |
|
1169 | - } |
|
1170 | - $this->_subsections = EEH_Array::insert_into_array( |
|
1171 | - $this->_subsections, |
|
1172 | - $new_subsections, |
|
1173 | - $subsection_name_to_target, |
|
1174 | - $add_before |
|
1175 | - ); |
|
1176 | - if ($this->_construction_finalized) { |
|
1177 | - foreach ($this->_subsections as $name => $subsection) { |
|
1178 | - $subsection->_construct_finalize($this, $name); |
|
1179 | - } |
|
1180 | - } |
|
1181 | - } |
|
1182 | - |
|
1183 | - |
|
1184 | - |
|
1185 | - /** |
|
1186 | - * Just gets all validatable subsections to clean their sensitive data |
|
1187 | - */ |
|
1188 | - public function clean_sensitive_data() |
|
1189 | - { |
|
1190 | - foreach ($this->get_validatable_subsections() as $subsection) { |
|
1191 | - $subsection->clean_sensitive_data(); |
|
1192 | - } |
|
1193 | - } |
|
1194 | - |
|
1195 | - |
|
1196 | - |
|
1197 | - /** |
|
1198 | - * @param string $form_submission_error_message |
|
1199 | - */ |
|
1200 | - public function set_submission_error_message($form_submission_error_message = '') |
|
1201 | - { |
|
1202 | - $this->_form_submission_error_message .= ! empty($form_submission_error_message) |
|
1203 | - ? $form_submission_error_message |
|
1204 | - : __('Form submission failed due to errors', 'event_espresso'); |
|
1205 | - } |
|
1206 | - |
|
1207 | - |
|
1208 | - |
|
1209 | - /** |
|
1210 | - * @return string |
|
1211 | - */ |
|
1212 | - public function submission_error_message() |
|
1213 | - { |
|
1214 | - return $this->_form_submission_error_message; |
|
1215 | - } |
|
1216 | - |
|
1217 | - |
|
1218 | - |
|
1219 | - /** |
|
1220 | - * @param string $form_submission_success_message |
|
1221 | - */ |
|
1222 | - public function set_submission_success_message($form_submission_success_message) |
|
1223 | - { |
|
1224 | - $this->_form_submission_success_message .= ! empty($form_submission_success_message) |
|
1225 | - ? $form_submission_success_message |
|
1226 | - : __('Form submitted successfully', 'event_espresso'); |
|
1227 | - } |
|
1228 | - |
|
1229 | - |
|
1230 | - |
|
1231 | - /** |
|
1232 | - * @return string |
|
1233 | - */ |
|
1234 | - public function submission_success_message() |
|
1235 | - { |
|
1236 | - return $this->_form_submission_success_message; |
|
1237 | - } |
|
1238 | - |
|
1239 | - |
|
1240 | - |
|
1241 | - /** |
|
1242 | - * Returns the prefix that should be used on child of this form section for |
|
1243 | - * their html names. If this form section itself has a parent, prepends ITS |
|
1244 | - * prefix onto this form section's prefix. Used primarily by |
|
1245 | - * EE_Form_Input_Base::_set_default_html_name_if_empty |
|
1246 | - * |
|
1247 | - * @return string |
|
1248 | - * @throws \EE_Error |
|
1249 | - */ |
|
1250 | - public function html_name_prefix() |
|
1251 | - { |
|
1252 | - if ($this->parent_section() instanceof EE_Form_Section_Proper) { |
|
1253 | - return $this->parent_section()->html_name_prefix() . '[' . $this->name() . ']'; |
|
1254 | - } else { |
|
1255 | - return $this->name(); |
|
1256 | - } |
|
1257 | - } |
|
1258 | - |
|
1259 | - |
|
1260 | - |
|
1261 | - /** |
|
1262 | - * Gets the name, but first checks _construct_finalize has been called. If not, |
|
1263 | - * calls it (assumes there is no parent and that we want the name to be whatever |
|
1264 | - * was set, which is probably nothing, or the classname) |
|
1265 | - * |
|
1266 | - * @return string |
|
1267 | - * @throws \EE_Error |
|
1268 | - */ |
|
1269 | - public function name() |
|
1270 | - { |
|
1271 | - $this->ensure_construct_finalized_called(); |
|
1272 | - return parent::name(); |
|
1273 | - } |
|
1274 | - |
|
1275 | - |
|
1276 | - |
|
1277 | - /** |
|
1278 | - * @return EE_Form_Section_Proper |
|
1279 | - * @throws \EE_Error |
|
1280 | - */ |
|
1281 | - public function parent_section() |
|
1282 | - { |
|
1283 | - $this->ensure_construct_finalized_called(); |
|
1284 | - return parent::parent_section(); |
|
1285 | - } |
|
1286 | - |
|
1287 | - |
|
1288 | - |
|
1289 | - /** |
|
1290 | - * make sure construction finalized was called, otherwise children might not be ready |
|
1291 | - * |
|
1292 | - * @return void |
|
1293 | - * @throws \EE_Error |
|
1294 | - */ |
|
1295 | - public function ensure_construct_finalized_called() |
|
1296 | - { |
|
1297 | - if (! $this->_construction_finalized) { |
|
1298 | - $this->_construct_finalize($this->_parent_section, $this->_name); |
|
1299 | - } |
|
1300 | - } |
|
1301 | - |
|
1302 | - |
|
1303 | - |
|
1304 | - /** |
|
1305 | - * Checks if any of this form section's inputs, or any of its children's inputs, |
|
1306 | - * are in teh form data. If any are found, returns true. Else false |
|
1307 | - * |
|
1308 | - * @param array $req_data |
|
1309 | - * @return boolean |
|
1310 | - */ |
|
1311 | - public function form_data_present_in($req_data = null) |
|
1312 | - { |
|
1313 | - if ($req_data === null) { |
|
1314 | - $req_data = $_POST; |
|
1315 | - } |
|
1316 | - foreach ($this->subsections() as $subsection) { |
|
1317 | - if ($subsection instanceof EE_Form_Input_Base) { |
|
1318 | - if ($subsection->form_data_present_in($req_data)) { |
|
1319 | - return true; |
|
1320 | - } |
|
1321 | - } elseif ($subsection instanceof EE_Form_Section_Proper) { |
|
1322 | - if ($subsection->form_data_present_in($req_data)) { |
|
1323 | - return true; |
|
1324 | - } |
|
1325 | - } |
|
1326 | - } |
|
1327 | - return false; |
|
1328 | - } |
|
1329 | - |
|
1330 | - |
|
1331 | - |
|
1332 | - /** |
|
1333 | - * Gets validation errors for this form section and subsections |
|
1334 | - * Similar to EE_Form_Section_Validatable::get_validation_errors() except this |
|
1335 | - * gets the validation errors for ALL subsection |
|
1336 | - * |
|
1337 | - * @return EE_Validation_Error[] |
|
1338 | - */ |
|
1339 | - public function get_validation_errors_accumulated() |
|
1340 | - { |
|
1341 | - $validation_errors = $this->get_validation_errors(); |
|
1342 | - foreach ($this->get_validatable_subsections() as $subsection) { |
|
1343 | - if ($subsection instanceof EE_Form_Section_Proper) { |
|
1344 | - $validation_errors_on_this_subsection = $subsection->get_validation_errors_accumulated(); |
|
1345 | - } else { |
|
1346 | - $validation_errors_on_this_subsection = $subsection->get_validation_errors(); |
|
1347 | - } |
|
1348 | - if ($validation_errors_on_this_subsection) { |
|
1349 | - $validation_errors = array_merge($validation_errors, $validation_errors_on_this_subsection); |
|
1350 | - } |
|
1351 | - } |
|
1352 | - return $validation_errors; |
|
1353 | - } |
|
1354 | - |
|
1355 | - |
|
1356 | - |
|
1357 | - /** |
|
1358 | - * This isn't just the name of an input, it's a path pointing to an input. The |
|
1359 | - * path is similar to a folder path: slash (/) means to descend into a subsection, |
|
1360 | - * dot-dot-slash (../) means to ascend into the parent section. |
|
1361 | - * After a series of slashes and dot-dot-slashes, there should be the name of an input, |
|
1362 | - * which will be returned. |
|
1363 | - * Eg, if you want the related input to be conditional on a sibling input name 'foobar' |
|
1364 | - * just use 'foobar'. If you want it to be conditional on an aunt/uncle input name |
|
1365 | - * 'baz', use '../baz'. If you want it to be conditional on a cousin input, |
|
1366 | - * the child of 'baz_section' named 'baz_child', use '../baz_section/baz_child'. |
|
1367 | - * Etc |
|
1368 | - * |
|
1369 | - * @param string|false $form_section_path we accept false also because substr( '../', '../' ) = false |
|
1370 | - * @return EE_Form_Section_Base |
|
1371 | - */ |
|
1372 | - public function find_section_from_path($form_section_path) |
|
1373 | - { |
|
1374 | - //check if we can find the input from purely going straight up the tree |
|
1375 | - $input = parent::find_section_from_path($form_section_path); |
|
1376 | - if ($input instanceof EE_Form_Section_Base) { |
|
1377 | - return $input; |
|
1378 | - } |
|
1379 | - $next_slash_pos = strpos($form_section_path, '/'); |
|
1380 | - if ($next_slash_pos !== false) { |
|
1381 | - $child_section_name = substr($form_section_path, 0, $next_slash_pos); |
|
1382 | - $subpath = substr($form_section_path, $next_slash_pos + 1); |
|
1383 | - } else { |
|
1384 | - $child_section_name = $form_section_path; |
|
1385 | - $subpath = ''; |
|
1386 | - } |
|
1387 | - $child_section = $this->get_subsection($child_section_name); |
|
1388 | - if ($child_section instanceof EE_Form_Section_Base) { |
|
1389 | - return $child_section->find_section_from_path($subpath); |
|
1390 | - } else { |
|
1391 | - return null; |
|
1392 | - } |
|
1393 | - } |
|
14 | + const SUBMITTED_FORM_DATA_SSN_KEY = 'submitted_form_data'; |
|
15 | + |
|
16 | + /** |
|
17 | + * Subsections |
|
18 | + * |
|
19 | + * @var EE_Form_Section_Validatable[] |
|
20 | + */ |
|
21 | + protected $_subsections = array(); |
|
22 | + |
|
23 | + /** |
|
24 | + * Strategy for laying out the form |
|
25 | + * |
|
26 | + * @var EE_Form_Section_Layout_Base |
|
27 | + */ |
|
28 | + protected $_layout_strategy; |
|
29 | + |
|
30 | + /** |
|
31 | + * Whether or not this form has received and validated a form submission yet |
|
32 | + * |
|
33 | + * @var boolean |
|
34 | + */ |
|
35 | + protected $_received_submission = false; |
|
36 | + |
|
37 | + /** |
|
38 | + * message displayed to users upon successful form submission |
|
39 | + * |
|
40 | + * @var string |
|
41 | + */ |
|
42 | + protected $_form_submission_success_message = ''; |
|
43 | + |
|
44 | + /** |
|
45 | + * message displayed to users upon unsuccessful form submission |
|
46 | + * |
|
47 | + * @var string |
|
48 | + */ |
|
49 | + protected $_form_submission_error_message = ''; |
|
50 | + |
|
51 | + /** |
|
52 | + * Stores all the data that will localized for form validation |
|
53 | + * |
|
54 | + * @var array |
|
55 | + */ |
|
56 | + static protected $_js_localization = array(); |
|
57 | + |
|
58 | + /** |
|
59 | + * whether or not the form's localized validation JS vars have been set |
|
60 | + * |
|
61 | + * @type boolean |
|
62 | + */ |
|
63 | + static protected $_scripts_localized = false; |
|
64 | + |
|
65 | + |
|
66 | + |
|
67 | + /** |
|
68 | + * when constructing a proper form section, calls _construct_finalize on children |
|
69 | + * so that they know who their parent is, and what name they've been given. |
|
70 | + * |
|
71 | + * @param array $options_array { |
|
72 | + * @type $subsections EE_Form_Section_Validatable[] where keys are the section's name |
|
73 | + * @type $include string[] numerically-indexed where values are section names to be included, |
|
74 | + * and in that order. This is handy if you want |
|
75 | + * the subsections to be ordered differently than the default, and if you override |
|
76 | + * which fields are shown |
|
77 | + * @type $exclude string[] values are subsections to be excluded. This is handy if you want |
|
78 | + * to remove certain default subsections (note: if you specify BOTH 'include' AND |
|
79 | + * 'exclude', the inclusions will be applied first, and the exclusions will exclude |
|
80 | + * items from that list of inclusions) |
|
81 | + * @type $layout_strategy EE_Form_Section_Layout_Base strategy for laying out the form |
|
82 | + * } @see EE_Form_Section_Validatable::__construct() |
|
83 | + * @throws \EE_Error |
|
84 | + */ |
|
85 | + public function __construct($options_array = array()) |
|
86 | + { |
|
87 | + $options_array = (array)apply_filters('FHEE__EE_Form_Section_Proper___construct__options_array', $options_array, |
|
88 | + $this); |
|
89 | + //call parent first, as it may be setting the name |
|
90 | + parent::__construct($options_array); |
|
91 | + //if they've included subsections in the constructor, add them now |
|
92 | + if (isset($options_array['include'])) { |
|
93 | + //we are going to make sure we ONLY have those subsections to include |
|
94 | + //AND we are going to make sure they're in that specified order |
|
95 | + $reordered_subsections = array(); |
|
96 | + foreach ($options_array['include'] as $input_name) { |
|
97 | + if (isset($this->_subsections[$input_name])) { |
|
98 | + $reordered_subsections[$input_name] = $this->_subsections[$input_name]; |
|
99 | + } |
|
100 | + } |
|
101 | + $this->_subsections = $reordered_subsections; |
|
102 | + } |
|
103 | + if (isset($options_array['exclude'])) { |
|
104 | + $exclude = $options_array['exclude']; |
|
105 | + $this->_subsections = array_diff_key($this->_subsections, array_flip($exclude)); |
|
106 | + } |
|
107 | + if (isset($options_array['layout_strategy'])) { |
|
108 | + $this->_layout_strategy = $options_array['layout_strategy']; |
|
109 | + } |
|
110 | + if (! $this->_layout_strategy) { |
|
111 | + $this->_layout_strategy = is_admin() ? new EE_Admin_Two_Column_Layout() : new EE_Two_Column_Layout(); |
|
112 | + } |
|
113 | + $this->_layout_strategy->_construct_finalize($this); |
|
114 | + //ok so we are definitely going to want the forms JS, |
|
115 | + //so enqueue it or remember to enqueue it during wp_enqueue_scripts |
|
116 | + if (did_action('wp_enqueue_scripts') || did_action('admin_enqueue_scripts')) { |
|
117 | + //ok so they've constructed this object after when they should have. |
|
118 | + //just enqueue the generic form scripts and initialize the form immediately in the JS |
|
119 | + \EE_Form_Section_Proper::wp_enqueue_scripts(true); |
|
120 | + } else { |
|
121 | + add_action('wp_enqueue_scripts', array('EE_Form_Section_Proper', 'wp_enqueue_scripts')); |
|
122 | + add_action('admin_enqueue_scripts', array('EE_Form_Section_Proper', 'wp_enqueue_scripts')); |
|
123 | + } |
|
124 | + add_action('wp_footer', array($this, 'ensure_scripts_localized'), 1); |
|
125 | + |
|
126 | + /** |
|
127 | + * Gives other plugins a chance to hook in before construct finalize is called. The form probably doesn't |
|
128 | + * yet have a parent form section. Since 4.9.32, when this action was introduced, this is the best place to |
|
129 | + * add a subsection onto a form, assuming you don't care what the form section's name, HTML ID, or HTML name etc are. |
|
130 | + * Also see AHEE__EE_Form_Section_Proper___construct_finalize__end |
|
131 | + * @since 4.9.32 |
|
132 | + * @param EE_Form_Section_Proper $this before __construct is done, but all of its logic, except maybe calling |
|
133 | + * _construct_finalize has been done |
|
134 | + * @param array $options_array options passed into the constructor |
|
135 | + */ |
|
136 | + do_action('AHEE__EE_Form_Input_Base___construct__before_construct_finalize_called', $this, $options_array); |
|
137 | + |
|
138 | + if (isset($options_array['name'])) { |
|
139 | + $this->_construct_finalize(null, $options_array['name']); |
|
140 | + } |
|
141 | + } |
|
142 | + |
|
143 | + |
|
144 | + |
|
145 | + /** |
|
146 | + * Finishes construction given the parent form section and this form section's name |
|
147 | + * |
|
148 | + * @param EE_Form_Section_Proper $parent_form_section |
|
149 | + * @param string $name |
|
150 | + * @throws \EE_Error |
|
151 | + */ |
|
152 | + public function _construct_finalize($parent_form_section, $name) |
|
153 | + { |
|
154 | + parent::_construct_finalize($parent_form_section, $name); |
|
155 | + $this->_set_default_name_if_empty(); |
|
156 | + $this->_set_default_html_id_if_empty(); |
|
157 | + foreach ($this->_subsections as $subsection_name => $subsection) { |
|
158 | + if ($subsection instanceof EE_Form_Section_Base) { |
|
159 | + $subsection->_construct_finalize($this, $subsection_name); |
|
160 | + } else { |
|
161 | + throw new EE_Error( |
|
162 | + sprintf( |
|
163 | + __('Subsection "%s" is not an instanceof EE_Form_Section_Base on form "%s". It is a "%s"', |
|
164 | + 'event_espresso'), |
|
165 | + $subsection_name, |
|
166 | + get_class($this), |
|
167 | + $subsection ? get_class($subsection) : __('NULL', 'event_espresso') |
|
168 | + ) |
|
169 | + ); |
|
170 | + } |
|
171 | + } |
|
172 | + /** |
|
173 | + * Action performed just after form has been given a name (and HTML ID etc) and is fully constructed. |
|
174 | + * If you have code that should modify the form and needs it and its subsections to have a name, HTML ID (or other attributes derived |
|
175 | + * from the name like the HTML label id, etc), this is where it should be done. |
|
176 | + * This might only happen just before displaying the form, or just before it receives form submission data. |
|
177 | + * If you need to modify the form or its subsections before _construct_finalize is called on it (and we've |
|
178 | + * ensured it has a name, HTML IDs, etc |
|
179 | + * @param EE_Form_Section_Proper $this |
|
180 | + * @param EE_Form_Section_Proper|null $parent_form_section |
|
181 | + * @param string $name |
|
182 | + */ |
|
183 | + do_action('AHEE__EE_Form_Section_Proper___construct_finalize__end', $this, $parent_form_section, $name); |
|
184 | + } |
|
185 | + |
|
186 | + |
|
187 | + |
|
188 | + /** |
|
189 | + * Gets the layout strategy for this form section |
|
190 | + * |
|
191 | + * @return EE_Form_Section_Layout_Base |
|
192 | + */ |
|
193 | + public function get_layout_strategy() |
|
194 | + { |
|
195 | + return $this->_layout_strategy; |
|
196 | + } |
|
197 | + |
|
198 | + |
|
199 | + |
|
200 | + /** |
|
201 | + * Gets the HTML for a single input for this form section according |
|
202 | + * to the layout strategy |
|
203 | + * |
|
204 | + * @param EE_Form_Input_Base $input |
|
205 | + * @return string |
|
206 | + */ |
|
207 | + public function get_html_for_input($input) |
|
208 | + { |
|
209 | + return $this->_layout_strategy->layout_input($input); |
|
210 | + } |
|
211 | + |
|
212 | + |
|
213 | + |
|
214 | + /** |
|
215 | + * was_submitted - checks if form inputs are present in request data |
|
216 | + * Basically an alias for form_data_present_in() (which is used by both |
|
217 | + * proper form sections and form inputs) |
|
218 | + * |
|
219 | + * @param null $form_data |
|
220 | + * @return boolean |
|
221 | + */ |
|
222 | + public function was_submitted($form_data = null) |
|
223 | + { |
|
224 | + return $this->form_data_present_in($form_data); |
|
225 | + } |
|
226 | + |
|
227 | + |
|
228 | + |
|
229 | + /** |
|
230 | + * After the form section is initially created, call this to sanitize the data in the submission |
|
231 | + * which relates to this form section, validate it, and set it as properties on the form. |
|
232 | + * |
|
233 | + * @param array|null $req_data should usually be $_POST (the default). |
|
234 | + * However, you CAN supply a different array. |
|
235 | + * Consider using set_defaults() instead however. |
|
236 | + * (If you rendered the form in the page using echo $form_x->get_html() |
|
237 | + * the inputs will have the correct name in the request data for this function |
|
238 | + * to find them and populate the form with them. |
|
239 | + * If you have a flat form (with only input subsections), |
|
240 | + * you can supply a flat array where keys |
|
241 | + * are the form input names and values are their values) |
|
242 | + * @param boolean $validate whether or not to perform validation on this data. Default is, |
|
243 | + * of course, to validate that data, and set errors on the invalid values. |
|
244 | + * But if the data has already been validated |
|
245 | + * (eg you validated the data then stored it in the DB) |
|
246 | + * you may want to skip this step. |
|
247 | + */ |
|
248 | + public function receive_form_submission($req_data = null, $validate = true) |
|
249 | + { |
|
250 | + $req_data = apply_filters('FHEE__EE_Form_Section_Proper__receive_form_submission__req_data', $req_data, $this, |
|
251 | + $validate); |
|
252 | + if ($req_data === null) { |
|
253 | + $req_data = array_merge($_GET, $_POST); |
|
254 | + } |
|
255 | + $req_data = apply_filters('FHEE__EE_Form_Section_Proper__receive_form_submission__request_data', $req_data, |
|
256 | + $this); |
|
257 | + $this->_normalize($req_data); |
|
258 | + if ($validate) { |
|
259 | + $this->_validate(); |
|
260 | + //if it's invalid, we're going to want to re-display so remember what they submitted |
|
261 | + if (! $this->is_valid()) { |
|
262 | + $this->store_submitted_form_data_in_session(); |
|
263 | + } |
|
264 | + } |
|
265 | + do_action('AHEE__EE_Form_Section_Proper__receive_form_submission__end', $req_data, $this, $validate); |
|
266 | + } |
|
267 | + |
|
268 | + |
|
269 | + |
|
270 | + /** |
|
271 | + * caches the originally submitted input values in the session |
|
272 | + * so that they can be used to repopulate the form if it failed validation |
|
273 | + * |
|
274 | + * @return boolean whether or not the data was successfully stored in the session |
|
275 | + */ |
|
276 | + protected function store_submitted_form_data_in_session() |
|
277 | + { |
|
278 | + return EE_Registry::instance()->SSN->set_session_data( |
|
279 | + array( |
|
280 | + \EE_Form_Section_Proper::SUBMITTED_FORM_DATA_SSN_KEY => $this->submitted_values(true), |
|
281 | + ) |
|
282 | + ); |
|
283 | + } |
|
284 | + |
|
285 | + |
|
286 | + |
|
287 | + /** |
|
288 | + * retrieves the originally submitted input values in the session |
|
289 | + * so that they can be used to repopulate the form if it failed validation |
|
290 | + * |
|
291 | + * @return array |
|
292 | + */ |
|
293 | + protected function get_submitted_form_data_from_session() |
|
294 | + { |
|
295 | + $session = EE_Registry::instance()->SSN; |
|
296 | + if ($session instanceof EE_Session) { |
|
297 | + return $session->get_session_data( |
|
298 | + \EE_Form_Section_Proper::SUBMITTED_FORM_DATA_SSN_KEY |
|
299 | + ); |
|
300 | + } else { |
|
301 | + return array(); |
|
302 | + } |
|
303 | + } |
|
304 | + |
|
305 | + |
|
306 | + |
|
307 | + /** |
|
308 | + * flushed the originally submitted input values from the session |
|
309 | + * |
|
310 | + * @return boolean whether or not the data was successfully removed from the session |
|
311 | + */ |
|
312 | + protected function flush_submitted_form_data_from_session() |
|
313 | + { |
|
314 | + return EE_Registry::instance()->SSN->reset_data( |
|
315 | + array(\EE_Form_Section_Proper::SUBMITTED_FORM_DATA_SSN_KEY) |
|
316 | + ); |
|
317 | + } |
|
318 | + |
|
319 | + |
|
320 | + |
|
321 | + /** |
|
322 | + * Populates this form and its subsections with data from the session. |
|
323 | + * (Wrapper for EE_Form_Section_Proper::receive_form_submission, so it shows |
|
324 | + * validation errors when displaying too) |
|
325 | + * Returns true if the form was populated from the session, false otherwise |
|
326 | + * |
|
327 | + * @return boolean |
|
328 | + */ |
|
329 | + public function populate_from_session() |
|
330 | + { |
|
331 | + $form_data_in_session = $this->get_submitted_form_data_from_session(); |
|
332 | + if (empty($form_data_in_session)) { |
|
333 | + return false; |
|
334 | + } |
|
335 | + $this->receive_form_submission($form_data_in_session); |
|
336 | + $this->flush_submitted_form_data_from_session(); |
|
337 | + if ($this->form_data_present_in($form_data_in_session)) { |
|
338 | + return true; |
|
339 | + } else { |
|
340 | + return false; |
|
341 | + } |
|
342 | + } |
|
343 | + |
|
344 | + |
|
345 | + |
|
346 | + /** |
|
347 | + * Populates the default data for the form, given an array where keys are |
|
348 | + * the input names, and values are their values (preferably normalized to be their |
|
349 | + * proper PHP types, not all strings... although that should be ok too). |
|
350 | + * Proper subsections are sub-arrays, the key being the subsection's name, and |
|
351 | + * the value being an array formatted in teh same way |
|
352 | + * |
|
353 | + * @param array $default_data |
|
354 | + */ |
|
355 | + public function populate_defaults($default_data) |
|
356 | + { |
|
357 | + foreach ($this->subsections(false) as $subsection_name => $subsection) { |
|
358 | + if (isset($default_data[$subsection_name])) { |
|
359 | + if ($subsection instanceof EE_Form_Input_Base) { |
|
360 | + $subsection->set_default($default_data[$subsection_name]); |
|
361 | + } elseif ($subsection instanceof EE_Form_Section_Proper) { |
|
362 | + $subsection->populate_defaults($default_data[$subsection_name]); |
|
363 | + } |
|
364 | + } |
|
365 | + } |
|
366 | + } |
|
367 | + |
|
368 | + |
|
369 | + |
|
370 | + /** |
|
371 | + * returns true if subsection exists |
|
372 | + * |
|
373 | + * @param string $name |
|
374 | + * @return boolean |
|
375 | + */ |
|
376 | + public function subsection_exists($name) |
|
377 | + { |
|
378 | + return isset($this->_subsections[$name]) ? true : false; |
|
379 | + } |
|
380 | + |
|
381 | + |
|
382 | + |
|
383 | + /** |
|
384 | + * Gets the subsection specified by its name |
|
385 | + * |
|
386 | + * @param string $name |
|
387 | + * @param boolean $require_construction_to_be_finalized most client code should leave this as TRUE |
|
388 | + * so that the inputs will be properly configured. |
|
389 | + * However, some client code may be ok |
|
390 | + * with construction finalize being called later |
|
391 | + * (realizing that the subsections' html names |
|
392 | + * might not be set yet, etc.) |
|
393 | + * @return EE_Form_Section_Base |
|
394 | + * @throws \EE_Error |
|
395 | + */ |
|
396 | + public function get_subsection($name, $require_construction_to_be_finalized = true) |
|
397 | + { |
|
398 | + if ($require_construction_to_be_finalized) { |
|
399 | + $this->ensure_construct_finalized_called(); |
|
400 | + } |
|
401 | + return $this->subsection_exists($name) ? $this->_subsections[$name] : null; |
|
402 | + } |
|
403 | + |
|
404 | + |
|
405 | + |
|
406 | + /** |
|
407 | + * Gets all the validatable subsections of this form section |
|
408 | + * |
|
409 | + * @return EE_Form_Section_Validatable[] |
|
410 | + */ |
|
411 | + public function get_validatable_subsections() |
|
412 | + { |
|
413 | + $validatable_subsections = array(); |
|
414 | + foreach ($this->subsections() as $name => $obj) { |
|
415 | + if ($obj instanceof EE_Form_Section_Validatable) { |
|
416 | + $validatable_subsections[$name] = $obj; |
|
417 | + } |
|
418 | + } |
|
419 | + return $validatable_subsections; |
|
420 | + } |
|
421 | + |
|
422 | + |
|
423 | + |
|
424 | + /** |
|
425 | + * Gets an input by the given name. If not found, or if its not an EE_FOrm_Input_Base child, |
|
426 | + * throw an EE_Error. |
|
427 | + * |
|
428 | + * @param string $name |
|
429 | + * @param boolean $require_construction_to_be_finalized most client code should |
|
430 | + * leave this as TRUE so that the inputs will be properly |
|
431 | + * configured. However, some client code may be ok with |
|
432 | + * construction finalize being called later |
|
433 | + * (realizing that the subsections' html names might not be |
|
434 | + * set yet, etc.) |
|
435 | + * @return EE_Form_Input_Base |
|
436 | + * @throws EE_Error |
|
437 | + */ |
|
438 | + public function get_input($name, $require_construction_to_be_finalized = true) |
|
439 | + { |
|
440 | + $subsection = $this->get_subsection($name, $require_construction_to_be_finalized); |
|
441 | + if (! $subsection instanceof EE_Form_Input_Base) { |
|
442 | + throw new EE_Error( |
|
443 | + sprintf( |
|
444 | + __( |
|
445 | + "Subsection '%s' is not an instanceof EE_Form_Input_Base on form '%s'. It is a '%s'", |
|
446 | + 'event_espresso' |
|
447 | + ), |
|
448 | + $name, |
|
449 | + get_class($this), |
|
450 | + $subsection ? get_class($subsection) : __("NULL", 'event_espresso') |
|
451 | + ) |
|
452 | + ); |
|
453 | + } |
|
454 | + return $subsection; |
|
455 | + } |
|
456 | + |
|
457 | + |
|
458 | + |
|
459 | + /** |
|
460 | + * Like get_input(), gets the proper subsection of the form given the name, |
|
461 | + * otherwise throws an EE_Error |
|
462 | + * |
|
463 | + * @param string $name |
|
464 | + * @param boolean $require_construction_to_be_finalized most client code should |
|
465 | + * leave this as TRUE so that the inputs will be properly |
|
466 | + * configured. However, some client code may be ok with |
|
467 | + * construction finalize being called later |
|
468 | + * (realizing that the subsections' html names might not be |
|
469 | + * set yet, etc.) |
|
470 | + * @return EE_Form_Section_Proper |
|
471 | + * @throws EE_Error |
|
472 | + */ |
|
473 | + public function get_proper_subsection($name, $require_construction_to_be_finalized = true) |
|
474 | + { |
|
475 | + $subsection = $this->get_subsection($name, $require_construction_to_be_finalized); |
|
476 | + if (! $subsection instanceof EE_Form_Section_Proper) { |
|
477 | + throw new EE_Error( |
|
478 | + sprintf( |
|
479 | + __("Subsection '%'s is not an instanceof EE_Form_Section_Proper on form '%s'", 'event_espresso'), |
|
480 | + $name, |
|
481 | + get_class($this) |
|
482 | + ) |
|
483 | + ); |
|
484 | + } |
|
485 | + return $subsection; |
|
486 | + } |
|
487 | + |
|
488 | + |
|
489 | + |
|
490 | + /** |
|
491 | + * Gets the value of the specified input. Should be called after receive_form_submission() |
|
492 | + * or populate_defaults() on the form, where the normalized value on the input is set. |
|
493 | + * |
|
494 | + * @param string $name |
|
495 | + * @return mixed depending on the input's type and its normalization strategy |
|
496 | + * @throws \EE_Error |
|
497 | + */ |
|
498 | + public function get_input_value($name) |
|
499 | + { |
|
500 | + $input = $this->get_input($name); |
|
501 | + return $input->normalized_value(); |
|
502 | + } |
|
503 | + |
|
504 | + |
|
505 | + |
|
506 | + /** |
|
507 | + * Checks if this form section itself is valid, and then checks its subsections |
|
508 | + * |
|
509 | + * @throws EE_Error |
|
510 | + * @return boolean |
|
511 | + */ |
|
512 | + public function is_valid() |
|
513 | + { |
|
514 | + if (! $this->has_received_submission()) { |
|
515 | + throw new EE_Error( |
|
516 | + sprintf( |
|
517 | + __( |
|
518 | + "You cannot check if a form is valid before receiving the form submission using receive_form_submission", |
|
519 | + "event_espresso" |
|
520 | + ) |
|
521 | + ) |
|
522 | + ); |
|
523 | + } |
|
524 | + if (! parent::is_valid()) { |
|
525 | + return false; |
|
526 | + } |
|
527 | + // ok so no general errors to this entire form section. |
|
528 | + // so let's check the subsections, but only set errors if that hasn't been done yet |
|
529 | + $set_submission_errors = $this->submission_error_message() === '' ? true : false; |
|
530 | + foreach ($this->get_validatable_subsections() as $subsection) { |
|
531 | + if (! $subsection->is_valid() || $subsection->get_validation_error_string() !== '') { |
|
532 | + if ($set_submission_errors) { |
|
533 | + $this->set_submission_error_message($subsection->get_validation_error_string()); |
|
534 | + } |
|
535 | + return false; |
|
536 | + } |
|
537 | + } |
|
538 | + return true; |
|
539 | + } |
|
540 | + |
|
541 | + |
|
542 | + |
|
543 | + /** |
|
544 | + * gets teh default name of this form section if none is specified |
|
545 | + * |
|
546 | + * @return string |
|
547 | + */ |
|
548 | + protected function _set_default_name_if_empty() |
|
549 | + { |
|
550 | + if (! $this->_name) { |
|
551 | + $classname = get_class($this); |
|
552 | + $default_name = str_replace("EE_", "", $classname); |
|
553 | + $this->_name = $default_name; |
|
554 | + } |
|
555 | + } |
|
556 | + |
|
557 | + |
|
558 | + |
|
559 | + /** |
|
560 | + * Returns the HTML for the form, except for the form opening and closing tags |
|
561 | + * (as the form section doesn't know where you necessarily want to send the information to), |
|
562 | + * and except for a submit button. Enqueus JS and CSS; if called early enough we will |
|
563 | + * try to enqueue them in the header, otherwise they'll be enqueued in the footer. |
|
564 | + * Not doing_it_wrong because theoretically this CAN be used properly, |
|
565 | + * provided its used during "wp_enqueue_scripts", or it doesn't need to enqueue |
|
566 | + * any CSS. |
|
567 | + * |
|
568 | + * @throws \EE_Error |
|
569 | + */ |
|
570 | + public function get_html_and_js() |
|
571 | + { |
|
572 | + $this->enqueue_js(); |
|
573 | + return $this->get_html(); |
|
574 | + } |
|
575 | + |
|
576 | + |
|
577 | + |
|
578 | + /** |
|
579 | + * returns HTML for displaying this form section. recursively calls display_section() on all subsections |
|
580 | + * |
|
581 | + * @param bool $display_previously_submitted_data |
|
582 | + * @return string |
|
583 | + */ |
|
584 | + public function get_html($display_previously_submitted_data = true) |
|
585 | + { |
|
586 | + $this->ensure_construct_finalized_called(); |
|
587 | + if ($display_previously_submitted_data) { |
|
588 | + $this->populate_from_session(); |
|
589 | + } |
|
590 | + return $this->_form_html_filter |
|
591 | + ? $this->_form_html_filter->filterHtml($this->_layout_strategy->layout_form(), $this) |
|
592 | + : $this->_layout_strategy->layout_form(); |
|
593 | + } |
|
594 | + |
|
595 | + |
|
596 | + |
|
597 | + /** |
|
598 | + * enqueues JS and CSS for the form. |
|
599 | + * It is preferred to call this before wp_enqueue_scripts so the |
|
600 | + * scripts and styles can be put in the header, but if called later |
|
601 | + * they will be put in the footer (which is OK for JS, but in HTML4 CSS should |
|
602 | + * only be in the header; but in HTML5 its ok in the body. |
|
603 | + * See http://stackoverflow.com/questions/4957446/load-external-css-file-in-body-tag. |
|
604 | + * So if your form enqueues CSS, it's preferred to call this before wp_enqueue_scripts.) |
|
605 | + * |
|
606 | + * @return string |
|
607 | + * @throws \EE_Error |
|
608 | + */ |
|
609 | + public function enqueue_js() |
|
610 | + { |
|
611 | + $this->_enqueue_and_localize_form_js(); |
|
612 | + foreach ($this->subsections() as $subsection) { |
|
613 | + $subsection->enqueue_js(); |
|
614 | + } |
|
615 | + } |
|
616 | + |
|
617 | + |
|
618 | + |
|
619 | + /** |
|
620 | + * adds a filter so that jquery validate gets enqueued in EE_System::wp_enqueue_scripts(). |
|
621 | + * This must be done BEFORE wp_enqueue_scripts() gets called, which is on |
|
622 | + * the wp_enqueue_scripts hook. |
|
623 | + * However, registering the form js and localizing it can happen when we |
|
624 | + * actually output the form (which is preferred, seeing how teh form's fields |
|
625 | + * could change until it's actually outputted) |
|
626 | + * |
|
627 | + * @param boolean $init_form_validation_automatically whether or not we want the form validation |
|
628 | + * to be triggered automatically or not |
|
629 | + * @return void |
|
630 | + */ |
|
631 | + public static function wp_enqueue_scripts($init_form_validation_automatically = true) |
|
632 | + { |
|
633 | + add_filter('FHEE_load_jquery_validate', '__return_true'); |
|
634 | + wp_register_script( |
|
635 | + 'ee_form_section_validation', |
|
636 | + EE_GLOBAL_ASSETS_URL . 'scripts' . DS . 'form_section_validation.js', |
|
637 | + array('jquery-validate', 'jquery-ui-datepicker', 'jquery-validate-extra-methods'), |
|
638 | + EVENT_ESPRESSO_VERSION, |
|
639 | + true |
|
640 | + ); |
|
641 | + wp_localize_script( |
|
642 | + 'ee_form_section_validation', |
|
643 | + 'ee_form_section_validation_init', |
|
644 | + array('init' => $init_form_validation_automatically ? '1' : '0') |
|
645 | + ); |
|
646 | + } |
|
647 | + |
|
648 | + |
|
649 | + |
|
650 | + /** |
|
651 | + * gets the variables used by form_section_validation.js. |
|
652 | + * This needs to be called AFTER we've called $this->_enqueue_jquery_validate_script, |
|
653 | + * but before the wordpress hook wp_loaded |
|
654 | + * |
|
655 | + * @throws \EE_Error |
|
656 | + */ |
|
657 | + public function _enqueue_and_localize_form_js() |
|
658 | + { |
|
659 | + $this->ensure_construct_finalized_called(); |
|
660 | + //actually, we don't want to localize just yet. There may be other forms on the page. |
|
661 | + //so we need to add our form section data to a static variable accessible by all form sections |
|
662 | + //and localize it just before the footer |
|
663 | + $this->localize_validation_rules(); |
|
664 | + add_action('wp_footer', array('EE_Form_Section_Proper', 'localize_script_for_all_forms'), 2); |
|
665 | + add_action('admin_footer', array('EE_Form_Section_Proper', 'localize_script_for_all_forms')); |
|
666 | + } |
|
667 | + |
|
668 | + |
|
669 | + |
|
670 | + /** |
|
671 | + * add our form section data to a static variable accessible by all form sections |
|
672 | + * |
|
673 | + * @param bool $return_for_subsection |
|
674 | + * @return void |
|
675 | + * @throws \EE_Error |
|
676 | + */ |
|
677 | + public function localize_validation_rules($return_for_subsection = false) |
|
678 | + { |
|
679 | + // we only want to localize vars ONCE for the entire form, |
|
680 | + // so if the form section doesn't have a parent, then it must be the top dog |
|
681 | + if ($return_for_subsection || ! $this->parent_section()) { |
|
682 | + EE_Form_Section_Proper::$_js_localization['form_data'][$this->html_id()] = array( |
|
683 | + 'form_section_id' => $this->html_id(true), |
|
684 | + 'validation_rules' => $this->get_jquery_validation_rules(), |
|
685 | + 'other_data' => $this->get_other_js_data(), |
|
686 | + 'errors' => $this->subsection_validation_errors_by_html_name(), |
|
687 | + ); |
|
688 | + EE_Form_Section_Proper::$_scripts_localized = true; |
|
689 | + } |
|
690 | + } |
|
691 | + |
|
692 | + |
|
693 | + |
|
694 | + /** |
|
695 | + * Gets an array of extra data that will be useful for client-side javascript. |
|
696 | + * This is primarily data added by inputs and forms in addition to any |
|
697 | + * scripts they might enqueue |
|
698 | + * |
|
699 | + * @param array $form_other_js_data |
|
700 | + * @return array |
|
701 | + */ |
|
702 | + public function get_other_js_data($form_other_js_data = array()) |
|
703 | + { |
|
704 | + foreach ($this->subsections() as $subsection) { |
|
705 | + $form_other_js_data = $subsection->get_other_js_data($form_other_js_data); |
|
706 | + } |
|
707 | + return $form_other_js_data; |
|
708 | + } |
|
709 | + |
|
710 | + |
|
711 | + |
|
712 | + /** |
|
713 | + * Gets a flat array of inputs for this form section and its subsections. |
|
714 | + * Keys are their form names, and values are the inputs themselves |
|
715 | + * |
|
716 | + * @return EE_Form_Input_Base |
|
717 | + */ |
|
718 | + public function inputs_in_subsections() |
|
719 | + { |
|
720 | + $inputs = array(); |
|
721 | + foreach ($this->subsections() as $subsection) { |
|
722 | + if ($subsection instanceof EE_Form_Input_Base) { |
|
723 | + $inputs[$subsection->html_name()] = $subsection; |
|
724 | + } elseif ($subsection instanceof EE_Form_Section_Proper) { |
|
725 | + $inputs += $subsection->inputs_in_subsections(); |
|
726 | + } |
|
727 | + } |
|
728 | + return $inputs; |
|
729 | + } |
|
730 | + |
|
731 | + |
|
732 | + |
|
733 | + /** |
|
734 | + * Gets a flat array of all the validation errors. |
|
735 | + * Keys are html names (because those should be unique) |
|
736 | + * and values are a string of all their validation errors |
|
737 | + * |
|
738 | + * @return string[] |
|
739 | + */ |
|
740 | + public function subsection_validation_errors_by_html_name() |
|
741 | + { |
|
742 | + $inputs = $this->inputs(); |
|
743 | + $errors = array(); |
|
744 | + foreach ($inputs as $form_input) { |
|
745 | + if ($form_input instanceof EE_Form_Input_Base && $form_input->get_validation_errors()) { |
|
746 | + $errors[$form_input->html_name()] = $form_input->get_validation_error_string(); |
|
747 | + } |
|
748 | + } |
|
749 | + return $errors; |
|
750 | + } |
|
751 | + |
|
752 | + |
|
753 | + |
|
754 | + /** |
|
755 | + * passes all the form data required by the JS to the JS, and enqueues the few required JS files. |
|
756 | + * Should be setup by each form during the _enqueues_and_localize_form_js |
|
757 | + */ |
|
758 | + public static function localize_script_for_all_forms() |
|
759 | + { |
|
760 | + //allow inputs and stuff to hook in their JS and stuff here |
|
761 | + do_action('AHEE__EE_Form_Section_Proper__localize_script_for_all_forms__begin'); |
|
762 | + EE_Form_Section_Proper::$_js_localization['localized_error_messages'] = EE_Form_Section_Proper::_get_localized_error_messages(); |
|
763 | + $email_validation_level = isset(EE_Registry::instance()->CFG->registration->email_validation_level) |
|
764 | + ? EE_Registry::instance()->CFG->registration->email_validation_level |
|
765 | + : 'wp_default'; |
|
766 | + EE_Form_Section_Proper::$_js_localization['email_validation_level'] = $email_validation_level; |
|
767 | + wp_enqueue_script('ee_form_section_validation'); |
|
768 | + wp_localize_script( |
|
769 | + 'ee_form_section_validation', |
|
770 | + 'ee_form_section_vars', |
|
771 | + EE_Form_Section_Proper::$_js_localization |
|
772 | + ); |
|
773 | + } |
|
774 | + |
|
775 | + |
|
776 | + |
|
777 | + /** |
|
778 | + * ensure_scripts_localized |
|
779 | + */ |
|
780 | + public function ensure_scripts_localized() |
|
781 | + { |
|
782 | + if (! EE_Form_Section_Proper::$_scripts_localized) { |
|
783 | + $this->_enqueue_and_localize_form_js(); |
|
784 | + } |
|
785 | + } |
|
786 | + |
|
787 | + |
|
788 | + |
|
789 | + /** |
|
790 | + * Gets the hard-coded validation error messages to be used in the JS. The convention |
|
791 | + * is that the key here should be the same as the custom validation rule put in the JS file |
|
792 | + * |
|
793 | + * @return array keys are custom validation rules, and values are internationalized strings |
|
794 | + */ |
|
795 | + private static function _get_localized_error_messages() |
|
796 | + { |
|
797 | + return array( |
|
798 | + 'validUrl' => __("This is not a valid absolute URL. Eg, http://domain.com/monkey.jpg", "event_espresso"), |
|
799 | + 'regex' => __('Please check your input', 'event_espresso'), |
|
800 | + ); |
|
801 | + } |
|
802 | + |
|
803 | + |
|
804 | + |
|
805 | + /** |
|
806 | + * @return array |
|
807 | + */ |
|
808 | + public static function js_localization() |
|
809 | + { |
|
810 | + return self::$_js_localization; |
|
811 | + } |
|
812 | + |
|
813 | + |
|
814 | + |
|
815 | + /** |
|
816 | + * @return array |
|
817 | + */ |
|
818 | + public static function reset_js_localization() |
|
819 | + { |
|
820 | + self::$_js_localization = array(); |
|
821 | + } |
|
822 | + |
|
823 | + |
|
824 | + |
|
825 | + /** |
|
826 | + * Gets the JS to put inside the jquery validation rules for subsection of this form section. |
|
827 | + * See parent function for more... |
|
828 | + * |
|
829 | + * @return array |
|
830 | + */ |
|
831 | + public function get_jquery_validation_rules() |
|
832 | + { |
|
833 | + $jquery_validation_rules = array(); |
|
834 | + foreach ($this->get_validatable_subsections() as $subsection) { |
|
835 | + $jquery_validation_rules = array_merge( |
|
836 | + $jquery_validation_rules, |
|
837 | + $subsection->get_jquery_validation_rules() |
|
838 | + ); |
|
839 | + } |
|
840 | + return $jquery_validation_rules; |
|
841 | + } |
|
842 | + |
|
843 | + |
|
844 | + |
|
845 | + /** |
|
846 | + * Sanitizes all the data and sets the sanitized value of each field |
|
847 | + * |
|
848 | + * @param array $req_data like $_POST |
|
849 | + * @return void |
|
850 | + */ |
|
851 | + protected function _normalize($req_data) |
|
852 | + { |
|
853 | + $this->_received_submission = true; |
|
854 | + $this->_validation_errors = array(); |
|
855 | + foreach ($this->get_validatable_subsections() as $subsection) { |
|
856 | + try { |
|
857 | + $subsection->_normalize($req_data); |
|
858 | + } catch (EE_Validation_Error $e) { |
|
859 | + $subsection->add_validation_error($e); |
|
860 | + } |
|
861 | + } |
|
862 | + } |
|
863 | + |
|
864 | + |
|
865 | + |
|
866 | + /** |
|
867 | + * Performs validation on this form section and its subsections. |
|
868 | + * For each subsection, |
|
869 | + * calls _validate_{subsection_name} on THIS form (if the function exists) |
|
870 | + * and passes it the subsection, then calls _validate on that subsection. |
|
871 | + * If you need to perform validation on the form as a whole (considering multiple) |
|
872 | + * you would be best to override this _validate method, |
|
873 | + * calling parent::_validate() first. |
|
874 | + */ |
|
875 | + protected function _validate() |
|
876 | + { |
|
877 | + foreach ($this->get_validatable_subsections() as $subsection_name => $subsection) { |
|
878 | + if (method_exists($this, '_validate_' . $subsection_name)) { |
|
879 | + call_user_func_array(array($this, '_validate_' . $subsection_name), array($subsection)); |
|
880 | + } |
|
881 | + $subsection->_validate(); |
|
882 | + } |
|
883 | + } |
|
884 | + |
|
885 | + |
|
886 | + |
|
887 | + /** |
|
888 | + * Gets all the validated inputs for the form section |
|
889 | + * |
|
890 | + * @return array |
|
891 | + */ |
|
892 | + public function valid_data() |
|
893 | + { |
|
894 | + $inputs = array(); |
|
895 | + foreach ($this->subsections() as $subsection_name => $subsection) { |
|
896 | + if ($subsection instanceof EE_Form_Section_Proper) { |
|
897 | + $inputs[$subsection_name] = $subsection->valid_data(); |
|
898 | + } else if ($subsection instanceof EE_Form_Input_Base) { |
|
899 | + $inputs[$subsection_name] = $subsection->normalized_value(); |
|
900 | + } |
|
901 | + } |
|
902 | + return $inputs; |
|
903 | + } |
|
904 | + |
|
905 | + |
|
906 | + |
|
907 | + /** |
|
908 | + * Gets all the inputs on this form section |
|
909 | + * |
|
910 | + * @return EE_Form_Input_Base[] |
|
911 | + */ |
|
912 | + public function inputs() |
|
913 | + { |
|
914 | + $inputs = array(); |
|
915 | + foreach ($this->subsections() as $subsection_name => $subsection) { |
|
916 | + if ($subsection instanceof EE_Form_Input_Base) { |
|
917 | + $inputs[$subsection_name] = $subsection; |
|
918 | + } |
|
919 | + } |
|
920 | + return $inputs; |
|
921 | + } |
|
922 | + |
|
923 | + |
|
924 | + |
|
925 | + /** |
|
926 | + * Gets all the subsections which are a proper form |
|
927 | + * |
|
928 | + * @return EE_Form_Section_Proper[] |
|
929 | + */ |
|
930 | + public function subforms() |
|
931 | + { |
|
932 | + $form_sections = array(); |
|
933 | + foreach ($this->subsections() as $name => $obj) { |
|
934 | + if ($obj instanceof EE_Form_Section_Proper) { |
|
935 | + $form_sections[$name] = $obj; |
|
936 | + } |
|
937 | + } |
|
938 | + return $form_sections; |
|
939 | + } |
|
940 | + |
|
941 | + |
|
942 | + |
|
943 | + /** |
|
944 | + * Gets all the subsections (inputs, proper subsections, or html-only sections). |
|
945 | + * Consider using inputs() or subforms() |
|
946 | + * if you only want form inputs or proper form sections. |
|
947 | + * |
|
948 | + * @param boolean $require_construction_to_be_finalized most client code should |
|
949 | + * leave this as TRUE so that the inputs will be properly |
|
950 | + * configured. However, some client code may be ok with |
|
951 | + * construction finalize being called later |
|
952 | + * (realizing that the subsections' html names might not be |
|
953 | + * set yet, etc.) |
|
954 | + * @return EE_Form_Section_Proper[] |
|
955 | + */ |
|
956 | + public function subsections($require_construction_to_be_finalized = true) |
|
957 | + { |
|
958 | + if ($require_construction_to_be_finalized) { |
|
959 | + $this->ensure_construct_finalized_called(); |
|
960 | + } |
|
961 | + return $this->_subsections; |
|
962 | + } |
|
963 | + |
|
964 | + |
|
965 | + |
|
966 | + /** |
|
967 | + * Returns a simple array where keys are input names, and values are their normalized |
|
968 | + * values. (Similar to calling get_input_value on inputs) |
|
969 | + * |
|
970 | + * @param boolean $include_subform_inputs Whether to include inputs from subforms, |
|
971 | + * or just this forms' direct children inputs |
|
972 | + * @param boolean $flatten Whether to force the results into 1-dimensional array, |
|
973 | + * or allow multidimensional array |
|
974 | + * @return array if $flatten is TRUE it will always be a 1-dimensional array |
|
975 | + * with array keys being input names |
|
976 | + * (regardless of whether they are from a subsection or not), |
|
977 | + * and if $flatten is FALSE it can be a multidimensional array |
|
978 | + * where keys are always subsection names and values are either |
|
979 | + * the input's normalized value, or an array like the top-level array |
|
980 | + */ |
|
981 | + public function input_values($include_subform_inputs = false, $flatten = false) |
|
982 | + { |
|
983 | + return $this->_input_values(false, $include_subform_inputs, $flatten); |
|
984 | + } |
|
985 | + |
|
986 | + |
|
987 | + |
|
988 | + /** |
|
989 | + * Similar to EE_Form_Section_Proper::input_values(), except this returns the 'display_value' |
|
990 | + * of each input. On some inputs (especially radio boxes or checkboxes), the value stored |
|
991 | + * is not necessarily the value we want to display to users. This creates an array |
|
992 | + * where keys are the input names, and values are their display values |
|
993 | + * |
|
994 | + * @param boolean $include_subform_inputs Whether to include inputs from subforms, |
|
995 | + * or just this forms' direct children inputs |
|
996 | + * @param boolean $flatten Whether to force the results into 1-dimensional array, |
|
997 | + * or allow multidimensional array |
|
998 | + * @return array if $flatten is TRUE it will always be a 1-dimensional array |
|
999 | + * with array keys being input names |
|
1000 | + * (regardless of whether they are from a subsection or not), |
|
1001 | + * and if $flatten is FALSE it can be a multidimensional array |
|
1002 | + * where keys are always subsection names and values are either |
|
1003 | + * the input's normalized value, or an array like the top-level array |
|
1004 | + */ |
|
1005 | + public function input_pretty_values($include_subform_inputs = false, $flatten = false) |
|
1006 | + { |
|
1007 | + return $this->_input_values(true, $include_subform_inputs, $flatten); |
|
1008 | + } |
|
1009 | + |
|
1010 | + |
|
1011 | + |
|
1012 | + /** |
|
1013 | + * Gets the input values from the form |
|
1014 | + * |
|
1015 | + * @param boolean $pretty Whether to retrieve the pretty value, |
|
1016 | + * or just the normalized value |
|
1017 | + * @param boolean $include_subform_inputs Whether to include inputs from subforms, |
|
1018 | + * or just this forms' direct children inputs |
|
1019 | + * @param boolean $flatten Whether to force the results into 1-dimensional array, |
|
1020 | + * or allow multidimensional array |
|
1021 | + * @return array if $flatten is TRUE it will always be a 1-dimensional array with array keys being |
|
1022 | + * input names (regardless of whether they are from a subsection or not), |
|
1023 | + * and if $flatten is FALSE it can be a multidimensional array |
|
1024 | + * where keys are always subsection names and values are either |
|
1025 | + * the input's normalized value, or an array like the top-level array |
|
1026 | + */ |
|
1027 | + public function _input_values($pretty = false, $include_subform_inputs = false, $flatten = false) |
|
1028 | + { |
|
1029 | + $input_values = array(); |
|
1030 | + foreach ($this->subsections() as $subsection_name => $subsection) { |
|
1031 | + if ($subsection instanceof EE_Form_Input_Base) { |
|
1032 | + $input_values[$subsection_name] = $pretty |
|
1033 | + ? $subsection->pretty_value() |
|
1034 | + : $subsection->normalized_value(); |
|
1035 | + } else if ($subsection instanceof EE_Form_Section_Proper && $include_subform_inputs) { |
|
1036 | + $subform_input_values = $subsection->_input_values($pretty, $include_subform_inputs, $flatten); |
|
1037 | + if ($flatten) { |
|
1038 | + $input_values = array_merge($input_values, $subform_input_values); |
|
1039 | + } else { |
|
1040 | + $input_values[$subsection_name] = $subform_input_values; |
|
1041 | + } |
|
1042 | + } |
|
1043 | + } |
|
1044 | + return $input_values; |
|
1045 | + } |
|
1046 | + |
|
1047 | + |
|
1048 | + |
|
1049 | + /** |
|
1050 | + * Gets the originally submitted input values from the form |
|
1051 | + * |
|
1052 | + * @param boolean $include_subforms Whether to include inputs from subforms, |
|
1053 | + * or just this forms' direct children inputs |
|
1054 | + * @return array if $flatten is TRUE it will always be a 1-dimensional array |
|
1055 | + * with array keys being input names |
|
1056 | + * (regardless of whether they are from a subsection or not), |
|
1057 | + * and if $flatten is FALSE it can be a multidimensional array |
|
1058 | + * where keys are always subsection names and values are either |
|
1059 | + * the input's normalized value, or an array like the top-level array |
|
1060 | + */ |
|
1061 | + public function submitted_values($include_subforms = false) |
|
1062 | + { |
|
1063 | + $submitted_values = array(); |
|
1064 | + foreach ($this->subsections() as $subsection) { |
|
1065 | + if ($subsection instanceof EE_Form_Input_Base) { |
|
1066 | + // is this input part of an array of inputs? |
|
1067 | + if (strpos($subsection->html_name(), '[') !== false) { |
|
1068 | + $full_input_name = \EEH_Array::convert_array_values_to_keys( |
|
1069 | + explode('[', str_replace(']', '', $subsection->html_name())), |
|
1070 | + $subsection->raw_value() |
|
1071 | + ); |
|
1072 | + $submitted_values = array_replace_recursive($submitted_values, $full_input_name); |
|
1073 | + } else { |
|
1074 | + $submitted_values[$subsection->html_name()] = $subsection->raw_value(); |
|
1075 | + } |
|
1076 | + } else if ($subsection instanceof EE_Form_Section_Proper && $include_subforms) { |
|
1077 | + $subform_input_values = $subsection->submitted_values($include_subforms); |
|
1078 | + $submitted_values = array_replace_recursive($submitted_values, $subform_input_values); |
|
1079 | + } |
|
1080 | + } |
|
1081 | + return $submitted_values; |
|
1082 | + } |
|
1083 | + |
|
1084 | + |
|
1085 | + |
|
1086 | + /** |
|
1087 | + * Indicates whether or not this form has received a submission yet |
|
1088 | + * (ie, had receive_form_submission called on it yet) |
|
1089 | + * |
|
1090 | + * @return boolean |
|
1091 | + * @throws \EE_Error |
|
1092 | + */ |
|
1093 | + public function has_received_submission() |
|
1094 | + { |
|
1095 | + $this->ensure_construct_finalized_called(); |
|
1096 | + return $this->_received_submission; |
|
1097 | + } |
|
1098 | + |
|
1099 | + |
|
1100 | + |
|
1101 | + /** |
|
1102 | + * Equivalent to passing 'exclude' in the constructor's options array. |
|
1103 | + * Removes the listed inputs from the form |
|
1104 | + * |
|
1105 | + * @param array $inputs_to_exclude values are the input names |
|
1106 | + * @return void |
|
1107 | + */ |
|
1108 | + public function exclude(array $inputs_to_exclude = array()) |
|
1109 | + { |
|
1110 | + foreach ($inputs_to_exclude as $input_to_exclude_name) { |
|
1111 | + unset($this->_subsections[$input_to_exclude_name]); |
|
1112 | + } |
|
1113 | + } |
|
1114 | + |
|
1115 | + |
|
1116 | + |
|
1117 | + /** |
|
1118 | + * @param array $inputs_to_hide |
|
1119 | + * @throws \EE_Error |
|
1120 | + */ |
|
1121 | + public function hide(array $inputs_to_hide = array()) |
|
1122 | + { |
|
1123 | + foreach ($inputs_to_hide as $input_to_hide) { |
|
1124 | + $input = $this->get_input($input_to_hide); |
|
1125 | + $input->set_display_strategy(new EE_Hidden_Display_Strategy()); |
|
1126 | + } |
|
1127 | + } |
|
1128 | + |
|
1129 | + |
|
1130 | + |
|
1131 | + /** |
|
1132 | + * add_subsections |
|
1133 | + * Adds the listed subsections to the form section. |
|
1134 | + * If $subsection_name_to_target is provided, |
|
1135 | + * then new subsections are added before or after that subsection, |
|
1136 | + * otherwise to the start or end of the entire subsections array. |
|
1137 | + * |
|
1138 | + * @param EE_Form_Section_Base[] $new_subsections array of new form subsections |
|
1139 | + * where keys are their names |
|
1140 | + * @param string $subsection_name_to_target an existing for section that $new_subsections |
|
1141 | + * should be added before or after |
|
1142 | + * IF $subsection_name_to_target is null, |
|
1143 | + * then $new_subsections will be added to |
|
1144 | + * the beginning or end of the entire subsections array |
|
1145 | + * @param boolean $add_before whether to add $new_subsections, before or after |
|
1146 | + * $subsection_name_to_target, |
|
1147 | + * or if $subsection_name_to_target is null, |
|
1148 | + * before or after entire subsections array |
|
1149 | + * @return void |
|
1150 | + * @throws \EE_Error |
|
1151 | + */ |
|
1152 | + public function add_subsections($new_subsections, $subsection_name_to_target = null, $add_before = true) |
|
1153 | + { |
|
1154 | + foreach ($new_subsections as $subsection_name => $subsection) { |
|
1155 | + if (! $subsection instanceof EE_Form_Section_Base) { |
|
1156 | + EE_Error::add_error( |
|
1157 | + sprintf( |
|
1158 | + __( |
|
1159 | + "Trying to add a %s as a subsection (it was named '%s') to the form section '%s'. It was removed.", |
|
1160 | + "event_espresso" |
|
1161 | + ), |
|
1162 | + get_class($subsection), |
|
1163 | + $subsection_name, |
|
1164 | + $this->name() |
|
1165 | + ) |
|
1166 | + ); |
|
1167 | + unset($new_subsections[$subsection_name]); |
|
1168 | + } |
|
1169 | + } |
|
1170 | + $this->_subsections = EEH_Array::insert_into_array( |
|
1171 | + $this->_subsections, |
|
1172 | + $new_subsections, |
|
1173 | + $subsection_name_to_target, |
|
1174 | + $add_before |
|
1175 | + ); |
|
1176 | + if ($this->_construction_finalized) { |
|
1177 | + foreach ($this->_subsections as $name => $subsection) { |
|
1178 | + $subsection->_construct_finalize($this, $name); |
|
1179 | + } |
|
1180 | + } |
|
1181 | + } |
|
1182 | + |
|
1183 | + |
|
1184 | + |
|
1185 | + /** |
|
1186 | + * Just gets all validatable subsections to clean their sensitive data |
|
1187 | + */ |
|
1188 | + public function clean_sensitive_data() |
|
1189 | + { |
|
1190 | + foreach ($this->get_validatable_subsections() as $subsection) { |
|
1191 | + $subsection->clean_sensitive_data(); |
|
1192 | + } |
|
1193 | + } |
|
1194 | + |
|
1195 | + |
|
1196 | + |
|
1197 | + /** |
|
1198 | + * @param string $form_submission_error_message |
|
1199 | + */ |
|
1200 | + public function set_submission_error_message($form_submission_error_message = '') |
|
1201 | + { |
|
1202 | + $this->_form_submission_error_message .= ! empty($form_submission_error_message) |
|
1203 | + ? $form_submission_error_message |
|
1204 | + : __('Form submission failed due to errors', 'event_espresso'); |
|
1205 | + } |
|
1206 | + |
|
1207 | + |
|
1208 | + |
|
1209 | + /** |
|
1210 | + * @return string |
|
1211 | + */ |
|
1212 | + public function submission_error_message() |
|
1213 | + { |
|
1214 | + return $this->_form_submission_error_message; |
|
1215 | + } |
|
1216 | + |
|
1217 | + |
|
1218 | + |
|
1219 | + /** |
|
1220 | + * @param string $form_submission_success_message |
|
1221 | + */ |
|
1222 | + public function set_submission_success_message($form_submission_success_message) |
|
1223 | + { |
|
1224 | + $this->_form_submission_success_message .= ! empty($form_submission_success_message) |
|
1225 | + ? $form_submission_success_message |
|
1226 | + : __('Form submitted successfully', 'event_espresso'); |
|
1227 | + } |
|
1228 | + |
|
1229 | + |
|
1230 | + |
|
1231 | + /** |
|
1232 | + * @return string |
|
1233 | + */ |
|
1234 | + public function submission_success_message() |
|
1235 | + { |
|
1236 | + return $this->_form_submission_success_message; |
|
1237 | + } |
|
1238 | + |
|
1239 | + |
|
1240 | + |
|
1241 | + /** |
|
1242 | + * Returns the prefix that should be used on child of this form section for |
|
1243 | + * their html names. If this form section itself has a parent, prepends ITS |
|
1244 | + * prefix onto this form section's prefix. Used primarily by |
|
1245 | + * EE_Form_Input_Base::_set_default_html_name_if_empty |
|
1246 | + * |
|
1247 | + * @return string |
|
1248 | + * @throws \EE_Error |
|
1249 | + */ |
|
1250 | + public function html_name_prefix() |
|
1251 | + { |
|
1252 | + if ($this->parent_section() instanceof EE_Form_Section_Proper) { |
|
1253 | + return $this->parent_section()->html_name_prefix() . '[' . $this->name() . ']'; |
|
1254 | + } else { |
|
1255 | + return $this->name(); |
|
1256 | + } |
|
1257 | + } |
|
1258 | + |
|
1259 | + |
|
1260 | + |
|
1261 | + /** |
|
1262 | + * Gets the name, but first checks _construct_finalize has been called. If not, |
|
1263 | + * calls it (assumes there is no parent and that we want the name to be whatever |
|
1264 | + * was set, which is probably nothing, or the classname) |
|
1265 | + * |
|
1266 | + * @return string |
|
1267 | + * @throws \EE_Error |
|
1268 | + */ |
|
1269 | + public function name() |
|
1270 | + { |
|
1271 | + $this->ensure_construct_finalized_called(); |
|
1272 | + return parent::name(); |
|
1273 | + } |
|
1274 | + |
|
1275 | + |
|
1276 | + |
|
1277 | + /** |
|
1278 | + * @return EE_Form_Section_Proper |
|
1279 | + * @throws \EE_Error |
|
1280 | + */ |
|
1281 | + public function parent_section() |
|
1282 | + { |
|
1283 | + $this->ensure_construct_finalized_called(); |
|
1284 | + return parent::parent_section(); |
|
1285 | + } |
|
1286 | + |
|
1287 | + |
|
1288 | + |
|
1289 | + /** |
|
1290 | + * make sure construction finalized was called, otherwise children might not be ready |
|
1291 | + * |
|
1292 | + * @return void |
|
1293 | + * @throws \EE_Error |
|
1294 | + */ |
|
1295 | + public function ensure_construct_finalized_called() |
|
1296 | + { |
|
1297 | + if (! $this->_construction_finalized) { |
|
1298 | + $this->_construct_finalize($this->_parent_section, $this->_name); |
|
1299 | + } |
|
1300 | + } |
|
1301 | + |
|
1302 | + |
|
1303 | + |
|
1304 | + /** |
|
1305 | + * Checks if any of this form section's inputs, or any of its children's inputs, |
|
1306 | + * are in teh form data. If any are found, returns true. Else false |
|
1307 | + * |
|
1308 | + * @param array $req_data |
|
1309 | + * @return boolean |
|
1310 | + */ |
|
1311 | + public function form_data_present_in($req_data = null) |
|
1312 | + { |
|
1313 | + if ($req_data === null) { |
|
1314 | + $req_data = $_POST; |
|
1315 | + } |
|
1316 | + foreach ($this->subsections() as $subsection) { |
|
1317 | + if ($subsection instanceof EE_Form_Input_Base) { |
|
1318 | + if ($subsection->form_data_present_in($req_data)) { |
|
1319 | + return true; |
|
1320 | + } |
|
1321 | + } elseif ($subsection instanceof EE_Form_Section_Proper) { |
|
1322 | + if ($subsection->form_data_present_in($req_data)) { |
|
1323 | + return true; |
|
1324 | + } |
|
1325 | + } |
|
1326 | + } |
|
1327 | + return false; |
|
1328 | + } |
|
1329 | + |
|
1330 | + |
|
1331 | + |
|
1332 | + /** |
|
1333 | + * Gets validation errors for this form section and subsections |
|
1334 | + * Similar to EE_Form_Section_Validatable::get_validation_errors() except this |
|
1335 | + * gets the validation errors for ALL subsection |
|
1336 | + * |
|
1337 | + * @return EE_Validation_Error[] |
|
1338 | + */ |
|
1339 | + public function get_validation_errors_accumulated() |
|
1340 | + { |
|
1341 | + $validation_errors = $this->get_validation_errors(); |
|
1342 | + foreach ($this->get_validatable_subsections() as $subsection) { |
|
1343 | + if ($subsection instanceof EE_Form_Section_Proper) { |
|
1344 | + $validation_errors_on_this_subsection = $subsection->get_validation_errors_accumulated(); |
|
1345 | + } else { |
|
1346 | + $validation_errors_on_this_subsection = $subsection->get_validation_errors(); |
|
1347 | + } |
|
1348 | + if ($validation_errors_on_this_subsection) { |
|
1349 | + $validation_errors = array_merge($validation_errors, $validation_errors_on_this_subsection); |
|
1350 | + } |
|
1351 | + } |
|
1352 | + return $validation_errors; |
|
1353 | + } |
|
1354 | + |
|
1355 | + |
|
1356 | + |
|
1357 | + /** |
|
1358 | + * This isn't just the name of an input, it's a path pointing to an input. The |
|
1359 | + * path is similar to a folder path: slash (/) means to descend into a subsection, |
|
1360 | + * dot-dot-slash (../) means to ascend into the parent section. |
|
1361 | + * After a series of slashes and dot-dot-slashes, there should be the name of an input, |
|
1362 | + * which will be returned. |
|
1363 | + * Eg, if you want the related input to be conditional on a sibling input name 'foobar' |
|
1364 | + * just use 'foobar'. If you want it to be conditional on an aunt/uncle input name |
|
1365 | + * 'baz', use '../baz'. If you want it to be conditional on a cousin input, |
|
1366 | + * the child of 'baz_section' named 'baz_child', use '../baz_section/baz_child'. |
|
1367 | + * Etc |
|
1368 | + * |
|
1369 | + * @param string|false $form_section_path we accept false also because substr( '../', '../' ) = false |
|
1370 | + * @return EE_Form_Section_Base |
|
1371 | + */ |
|
1372 | + public function find_section_from_path($form_section_path) |
|
1373 | + { |
|
1374 | + //check if we can find the input from purely going straight up the tree |
|
1375 | + $input = parent::find_section_from_path($form_section_path); |
|
1376 | + if ($input instanceof EE_Form_Section_Base) { |
|
1377 | + return $input; |
|
1378 | + } |
|
1379 | + $next_slash_pos = strpos($form_section_path, '/'); |
|
1380 | + if ($next_slash_pos !== false) { |
|
1381 | + $child_section_name = substr($form_section_path, 0, $next_slash_pos); |
|
1382 | + $subpath = substr($form_section_path, $next_slash_pos + 1); |
|
1383 | + } else { |
|
1384 | + $child_section_name = $form_section_path; |
|
1385 | + $subpath = ''; |
|
1386 | + } |
|
1387 | + $child_section = $this->get_subsection($child_section_name); |
|
1388 | + if ($child_section instanceof EE_Form_Section_Base) { |
|
1389 | + return $child_section->find_section_from_path($subpath); |
|
1390 | + } else { |
|
1391 | + return null; |
|
1392 | + } |
|
1393 | + } |
|
1394 | 1394 | |
1395 | 1395 | } |
1396 | 1396 |
@@ -1,6 +1,6 @@ discard block |
||
1 | 1 | <?php |
2 | 2 | if (! defined('EVENT_ESPRESSO_VERSION')) { |
3 | - exit('No direct script access allowed'); |
|
3 | + exit('No direct script access allowed'); |
|
4 | 4 | } |
5 | 5 | |
6 | 6 | |
@@ -35,150 +35,150 @@ discard block |
||
35 | 35 | abstract class EE_Form_Section_Validatable extends EE_Form_Section_Base |
36 | 36 | { |
37 | 37 | |
38 | - /** |
|
39 | - * Array of validation errors in this section. Does not contain validation errors in subsections, however. |
|
40 | - * Those are stored individually on each subsection. |
|
41 | - * |
|
42 | - * @var EE_Validation_Error[] |
|
43 | - */ |
|
44 | - protected $_validation_errors = array(); |
|
45 | - |
|
46 | - |
|
47 | - |
|
48 | - /** |
|
49 | - * Errors on this form section. Note: EE_Form_Section_Proper |
|
50 | - * has another function for getting all errors in this form section and subsections |
|
51 | - * called get_validation_errors_accumulated |
|
52 | - * |
|
53 | - * @return EE_Validation_Error[] |
|
54 | - */ |
|
55 | - public function get_validation_errors() |
|
56 | - { |
|
57 | - return $this->_validation_errors; |
|
58 | - } |
|
59 | - |
|
60 | - |
|
61 | - |
|
62 | - /** |
|
63 | - * returns a ul html element with all the validation errors in it. |
|
64 | - * If we want this to be customizable, we may decide to create a strategy for displaying it. |
|
65 | - * |
|
66 | - * @return string |
|
67 | - */ |
|
68 | - public function get_validation_error_string() |
|
69 | - { |
|
70 | - $validation_error_messages = array(); |
|
71 | - if ($this->get_validation_errors()) { |
|
72 | - foreach ($this->get_validation_errors() as $validation_error) { |
|
73 | - if ($validation_error instanceof EE_Validation_Error) { |
|
74 | - $validation_error_messages[] = $validation_error->getMessage(); |
|
75 | - } |
|
76 | - } |
|
77 | - } |
|
78 | - return implode(", ", $validation_error_messages); |
|
79 | - } |
|
80 | - |
|
81 | - |
|
82 | - |
|
83 | - /** |
|
84 | - * Performs validation on this form section (and subsections). Should be called after _normalize() |
|
85 | - * |
|
86 | - * @return boolean of whether or not the form section is valid |
|
87 | - */ |
|
88 | - abstract protected function _validate(); |
|
89 | - |
|
90 | - |
|
91 | - |
|
92 | - /** |
|
93 | - * Checks if this field has any validation errors |
|
94 | - * |
|
95 | - * @return boolean |
|
96 | - */ |
|
97 | - public function is_valid() |
|
98 | - { |
|
99 | - if (count($this->_validation_errors)) { |
|
100 | - return false; |
|
101 | - } else { |
|
102 | - return true; |
|
103 | - } |
|
104 | - } |
|
105 | - |
|
106 | - |
|
107 | - |
|
108 | - /** |
|
109 | - * Sanitizes input for this form section |
|
110 | - * |
|
111 | - * @param array $req_data is the full request data like $_POST |
|
112 | - * @return boolean of whether a normalization error occurred |
|
113 | - */ |
|
114 | - abstract protected function _normalize($req_data); |
|
115 | - |
|
116 | - |
|
117 | - |
|
118 | - /** |
|
119 | - * Creates a validation error from the arguments provided, and adds it to the form section's list. |
|
120 | - * If such an EE_Validation_Error object is passed in as the first arg, simply sets this as its form section, and |
|
121 | - * adds it to the list of validation errors of errors |
|
122 | - * |
|
123 | - * @param mixed $message_or_object internationalized string describing the validation error; or it could be a |
|
124 | - * proper EE_Validation_Error object |
|
125 | - * @param string $error_code a short key which can be used to uniquely identify the error |
|
126 | - * @param Exception $previous_exception if there was an exception that caused the error, that exception |
|
127 | - * @return void |
|
128 | - */ |
|
129 | - public function add_validation_error($message_or_object, $error_code = null, $previous_exception = null) |
|
130 | - { |
|
131 | - if ($message_or_object instanceof EE_Validation_Error) { |
|
132 | - $validation_error = $message_or_object; |
|
133 | - $validation_error->set_form_section($this); |
|
134 | - } else { |
|
135 | - $validation_error = new EE_Validation_Error($message_or_object, $error_code, $this, $previous_exception); |
|
136 | - } |
|
137 | - $this->_validation_errors[] = $validation_error; |
|
138 | - } |
|
139 | - |
|
140 | - |
|
141 | - |
|
142 | - /** |
|
143 | - * When generating the JS for the jquery validation rules like<br> |
|
144 | - * <code>$( "#myform" ).validate({ |
|
145 | - * rules: { |
|
146 | - * password: "required", |
|
147 | - * password_again: { |
|
148 | - * equalTo: "#password" |
|
149 | - * } |
|
150 | - * } |
|
151 | - * });</code> |
|
152 | - * gets the sections like |
|
153 | - * <br><code>password: "required", |
|
154 | - * password_again: { |
|
155 | - * equalTo: "#password" |
|
156 | - * }</code> |
|
157 | - * except we leave it as a PHP object, and leave wp_localize_script to |
|
158 | - * turn it into a JSON object which can be used by the js |
|
159 | - * |
|
160 | - * @return array |
|
161 | - */ |
|
162 | - abstract public function get_jquery_validation_rules(); |
|
163 | - |
|
164 | - |
|
165 | - |
|
166 | - /** |
|
167 | - * Checks if this form section's data is present in the req data specified |
|
168 | - * |
|
169 | - * @param array $req_data usually $_POST, if null that's what's used |
|
170 | - * @return boolean |
|
171 | - */ |
|
172 | - abstract public function form_data_present_in($req_data = null); |
|
173 | - |
|
174 | - |
|
175 | - |
|
176 | - /** |
|
177 | - * Removes teh sensitive data from this form section (usually done after |
|
178 | - * utilizing the data business function, but before saving it somewhere. Eg, |
|
179 | - * may remove a password from the form after verifying it was correct) |
|
180 | - * |
|
181 | - * @return void |
|
182 | - */ |
|
183 | - abstract public function clean_sensitive_data(); |
|
38 | + /** |
|
39 | + * Array of validation errors in this section. Does not contain validation errors in subsections, however. |
|
40 | + * Those are stored individually on each subsection. |
|
41 | + * |
|
42 | + * @var EE_Validation_Error[] |
|
43 | + */ |
|
44 | + protected $_validation_errors = array(); |
|
45 | + |
|
46 | + |
|
47 | + |
|
48 | + /** |
|
49 | + * Errors on this form section. Note: EE_Form_Section_Proper |
|
50 | + * has another function for getting all errors in this form section and subsections |
|
51 | + * called get_validation_errors_accumulated |
|
52 | + * |
|
53 | + * @return EE_Validation_Error[] |
|
54 | + */ |
|
55 | + public function get_validation_errors() |
|
56 | + { |
|
57 | + return $this->_validation_errors; |
|
58 | + } |
|
59 | + |
|
60 | + |
|
61 | + |
|
62 | + /** |
|
63 | + * returns a ul html element with all the validation errors in it. |
|
64 | + * If we want this to be customizable, we may decide to create a strategy for displaying it. |
|
65 | + * |
|
66 | + * @return string |
|
67 | + */ |
|
68 | + public function get_validation_error_string() |
|
69 | + { |
|
70 | + $validation_error_messages = array(); |
|
71 | + if ($this->get_validation_errors()) { |
|
72 | + foreach ($this->get_validation_errors() as $validation_error) { |
|
73 | + if ($validation_error instanceof EE_Validation_Error) { |
|
74 | + $validation_error_messages[] = $validation_error->getMessage(); |
|
75 | + } |
|
76 | + } |
|
77 | + } |
|
78 | + return implode(", ", $validation_error_messages); |
|
79 | + } |
|
80 | + |
|
81 | + |
|
82 | + |
|
83 | + /** |
|
84 | + * Performs validation on this form section (and subsections). Should be called after _normalize() |
|
85 | + * |
|
86 | + * @return boolean of whether or not the form section is valid |
|
87 | + */ |
|
88 | + abstract protected function _validate(); |
|
89 | + |
|
90 | + |
|
91 | + |
|
92 | + /** |
|
93 | + * Checks if this field has any validation errors |
|
94 | + * |
|
95 | + * @return boolean |
|
96 | + */ |
|
97 | + public function is_valid() |
|
98 | + { |
|
99 | + if (count($this->_validation_errors)) { |
|
100 | + return false; |
|
101 | + } else { |
|
102 | + return true; |
|
103 | + } |
|
104 | + } |
|
105 | + |
|
106 | + |
|
107 | + |
|
108 | + /** |
|
109 | + * Sanitizes input for this form section |
|
110 | + * |
|
111 | + * @param array $req_data is the full request data like $_POST |
|
112 | + * @return boolean of whether a normalization error occurred |
|
113 | + */ |
|
114 | + abstract protected function _normalize($req_data); |
|
115 | + |
|
116 | + |
|
117 | + |
|
118 | + /** |
|
119 | + * Creates a validation error from the arguments provided, and adds it to the form section's list. |
|
120 | + * If such an EE_Validation_Error object is passed in as the first arg, simply sets this as its form section, and |
|
121 | + * adds it to the list of validation errors of errors |
|
122 | + * |
|
123 | + * @param mixed $message_or_object internationalized string describing the validation error; or it could be a |
|
124 | + * proper EE_Validation_Error object |
|
125 | + * @param string $error_code a short key which can be used to uniquely identify the error |
|
126 | + * @param Exception $previous_exception if there was an exception that caused the error, that exception |
|
127 | + * @return void |
|
128 | + */ |
|
129 | + public function add_validation_error($message_or_object, $error_code = null, $previous_exception = null) |
|
130 | + { |
|
131 | + if ($message_or_object instanceof EE_Validation_Error) { |
|
132 | + $validation_error = $message_or_object; |
|
133 | + $validation_error->set_form_section($this); |
|
134 | + } else { |
|
135 | + $validation_error = new EE_Validation_Error($message_or_object, $error_code, $this, $previous_exception); |
|
136 | + } |
|
137 | + $this->_validation_errors[] = $validation_error; |
|
138 | + } |
|
139 | + |
|
140 | + |
|
141 | + |
|
142 | + /** |
|
143 | + * When generating the JS for the jquery validation rules like<br> |
|
144 | + * <code>$( "#myform" ).validate({ |
|
145 | + * rules: { |
|
146 | + * password: "required", |
|
147 | + * password_again: { |
|
148 | + * equalTo: "#password" |
|
149 | + * } |
|
150 | + * } |
|
151 | + * });</code> |
|
152 | + * gets the sections like |
|
153 | + * <br><code>password: "required", |
|
154 | + * password_again: { |
|
155 | + * equalTo: "#password" |
|
156 | + * }</code> |
|
157 | + * except we leave it as a PHP object, and leave wp_localize_script to |
|
158 | + * turn it into a JSON object which can be used by the js |
|
159 | + * |
|
160 | + * @return array |
|
161 | + */ |
|
162 | + abstract public function get_jquery_validation_rules(); |
|
163 | + |
|
164 | + |
|
165 | + |
|
166 | + /** |
|
167 | + * Checks if this form section's data is present in the req data specified |
|
168 | + * |
|
169 | + * @param array $req_data usually $_POST, if null that's what's used |
|
170 | + * @return boolean |
|
171 | + */ |
|
172 | + abstract public function form_data_present_in($req_data = null); |
|
173 | + |
|
174 | + |
|
175 | + |
|
176 | + /** |
|
177 | + * Removes teh sensitive data from this form section (usually done after |
|
178 | + * utilizing the data business function, but before saving it somewhere. Eg, |
|
179 | + * may remove a password from the form after verifying it was correct) |
|
180 | + * |
|
181 | + * @return void |
|
182 | + */ |
|
183 | + abstract public function clean_sensitive_data(); |
|
184 | 184 | } |
185 | 185 | \ No newline at end of file |
@@ -1,5 +1,5 @@ |
||
1 | 1 | <?php |
2 | -if (! defined('EVENT_ESPRESSO_VERSION')) { |
|
2 | +if ( ! defined('EVENT_ESPRESSO_VERSION')) { |
|
3 | 3 | exit('No direct script access allowed'); |
4 | 4 | } |
5 | 5 |
@@ -249,7 +249,7 @@ discard block |
||
249 | 249 | |
250 | 250 | /** |
251 | 251 | * @access public |
252 | - * @return string |
|
252 | + * @return boolean |
|
253 | 253 | */ |
254 | 254 | public static function is_iframe() { |
255 | 255 | return \EED_Events_Archive::$iframe; |
@@ -722,7 +722,7 @@ discard block |
||
722 | 722 | * display_description |
723 | 723 | * |
724 | 724 | * @access public |
725 | - * @param $value |
|
725 | + * @param integer $value |
|
726 | 726 | * @return bool |
727 | 727 | */ |
728 | 728 | public static function display_description( $value ) { |
@@ -14,13 +14,13 @@ discard block |
||
14 | 14 | */ |
15 | 15 | class EED_Events_Archive extends EED_Module { |
16 | 16 | |
17 | - const EVENT_DETAILS_PRIORITY = 100; |
|
18 | - const EVENT_DATETIMES_PRIORITY = 110; |
|
19 | - const EVENT_TICKETS_PRIORITY = 120; |
|
20 | - const EVENT_VENUES_PRIORITY = 130; |
|
17 | + const EVENT_DETAILS_PRIORITY = 100; |
|
18 | + const EVENT_DATETIMES_PRIORITY = 110; |
|
19 | + const EVENT_TICKETS_PRIORITY = 120; |
|
20 | + const EVENT_VENUES_PRIORITY = 130; |
|
21 | 21 | |
22 | 22 | |
23 | - public static $espresso_event_list_ID = 0; |
|
23 | + public static $espresso_event_list_ID = 0; |
|
24 | 24 | public static $espresso_grid_event_lists = array(); |
25 | 25 | |
26 | 26 | /** |
@@ -28,19 +28,19 @@ discard block |
||
28 | 28 | */ |
29 | 29 | protected static $using_get_the_excerpt = false; |
30 | 30 | |
31 | - /** |
|
32 | - * Used to flag when the event list is being called from an external iframe. |
|
33 | - * |
|
34 | - * @var bool $iframe |
|
35 | - */ |
|
36 | - protected static $iframe = false; |
|
31 | + /** |
|
32 | + * Used to flag when the event list is being called from an external iframe. |
|
33 | + * |
|
34 | + * @var bool $iframe |
|
35 | + */ |
|
36 | + protected static $iframe = false; |
|
37 | 37 | |
38 | - /** |
|
38 | + /** |
|
39 | 39 | * @var \EventEspresso\core\libraries\iframe_display\EventListIframeEmbedButton $_iframe_embed_button |
40 | 40 | */ |
41 | 41 | private static $_iframe_embed_button; |
42 | 42 | |
43 | - /** |
|
43 | + /** |
|
44 | 44 | * @type EE_Template_Part_Manager $template_parts |
45 | 45 | */ |
46 | 46 | protected $template_parts; |
@@ -210,9 +210,9 @@ discard block |
||
210 | 210 | |
211 | 211 | |
212 | 212 | /** |
213 | - * most likely called by the ESPRESSO_EVENTS shortcode which uses this module to do some of it's lifting |
|
214 | - * |
|
215 | - * @return void |
|
213 | + * most likely called by the ESPRESSO_EVENTS shortcode which uses this module to do some of it's lifting |
|
214 | + * |
|
215 | + * @return void |
|
216 | 216 | */ |
217 | 217 | public function event_list() { |
218 | 218 | // ensure valid EE_Events_Archive_Config() object exists |
@@ -223,36 +223,36 @@ discard block |
||
223 | 223 | |
224 | 224 | |
225 | 225 | |
226 | - /** |
|
227 | - * @access public |
|
228 | - * @return void |
|
229 | - * @throws \EE_Error |
|
230 | - * @throws \DomainException |
|
231 | - */ |
|
226 | + /** |
|
227 | + * @access public |
|
228 | + * @return void |
|
229 | + * @throws \EE_Error |
|
230 | + * @throws \DomainException |
|
231 | + */ |
|
232 | 232 | public function event_list_iframe() { |
233 | - \EED_Events_Archive::$iframe = true; |
|
233 | + \EED_Events_Archive::$iframe = true; |
|
234 | 234 | $event_list_iframe = new EventsArchiveIframe( $this ); |
235 | 235 | $event_list_iframe->display(); |
236 | 236 | } |
237 | 237 | |
238 | 238 | |
239 | 239 | |
240 | - /** |
|
241 | - * @access public |
|
242 | - * @return string |
|
243 | - */ |
|
240 | + /** |
|
241 | + * @access public |
|
242 | + * @return string |
|
243 | + */ |
|
244 | 244 | public static function is_iframe() { |
245 | - return \EED_Events_Archive::$iframe; |
|
245 | + return \EED_Events_Archive::$iframe; |
|
246 | 246 | } |
247 | 247 | |
248 | 248 | |
249 | 249 | |
250 | - /** |
|
251 | - * @access public |
|
252 | - * @return string |
|
253 | - */ |
|
250 | + /** |
|
251 | + * @access public |
|
252 | + * @return string |
|
253 | + */ |
|
254 | 254 | public static function link_target() { |
255 | - return \EED_Events_Archive::$iframe ? ' target="_blank"' : ''; |
|
255 | + return \EED_Events_Archive::$iframe ? ' target="_blank"' : ''; |
|
256 | 256 | } |
257 | 257 | |
258 | 258 | |
@@ -280,10 +280,10 @@ discard block |
||
280 | 280 | } |
281 | 281 | // if NOT a custom template |
282 | 282 | if ( |
283 | - apply_filters('FHEE__EED_Event_Archive__template_include__allow_custom_selected_template', false) |
|
283 | + apply_filters('FHEE__EED_Event_Archive__template_include__allow_custom_selected_template', false) |
|
284 | 284 | || EE_Registry::instance() |
285 | - ->load_core( 'Front_Controller' ) |
|
286 | - ->get_selected_template() !== 'archive-espresso_events.php' |
|
285 | + ->load_core( 'Front_Controller' ) |
|
286 | + ->get_selected_template() !== 'archive-espresso_events.php' |
|
287 | 287 | ) { |
288 | 288 | // don't display entry meta because the existing theme will take care of that |
289 | 289 | add_filter( 'FHEE__EED_Events_Archive__template_include__events_list_active', '__return_true' ); |
@@ -291,16 +291,16 @@ discard block |
||
291 | 291 | EEH_Template::load_espresso_theme_functions(); |
292 | 292 | // because we don't know if the theme is using the_excerpt() |
293 | 293 | add_filter( |
294 | - 'the_excerpt', |
|
295 | - array( 'EED_Events_Archive', 'event_details' ), |
|
296 | - EED_Events_Archive::EVENT_DETAILS_PRIORITY |
|
297 | - ); |
|
294 | + 'the_excerpt', |
|
295 | + array( 'EED_Events_Archive', 'event_details' ), |
|
296 | + EED_Events_Archive::EVENT_DETAILS_PRIORITY |
|
297 | + ); |
|
298 | 298 | // or the_content |
299 | 299 | add_filter( |
300 | - 'the_content', |
|
301 | - array( 'EED_Events_Archive', 'event_details' ), |
|
302 | - EED_Events_Archive::EVENT_DETAILS_PRIORITY |
|
303 | - ); |
|
300 | + 'the_content', |
|
301 | + array( 'EED_Events_Archive', 'event_details' ), |
|
302 | + EED_Events_Archive::EVENT_DETAILS_PRIORITY |
|
303 | + ); |
|
304 | 304 | // and just in case they are running get_the_excerpt() which DESTROYS things |
305 | 305 | add_filter( 'get_the_excerpt', array( 'EED_Events_Archive', 'get_the_excerpt' ), 1, 1 ); |
306 | 306 | // don't display entry meta because the existing theme will take care of that |
@@ -325,15 +325,15 @@ discard block |
||
325 | 325 | } |
326 | 326 | if ( apply_filters( 'FHEE__EED_Events_Archive__get_the_excerpt__theme_uses_get_the_excerpt', false ) ) { |
327 | 327 | remove_filter( |
328 | - 'the_excerpt', |
|
329 | - array( 'EED_Events_Archive', 'event_details' ), |
|
330 | - EED_Events_Archive::EVENT_DETAILS_PRIORITY |
|
331 | - ); |
|
328 | + 'the_excerpt', |
|
329 | + array( 'EED_Events_Archive', 'event_details' ), |
|
330 | + EED_Events_Archive::EVENT_DETAILS_PRIORITY |
|
331 | + ); |
|
332 | 332 | remove_filter( |
333 | - 'the_content', |
|
334 | - array( 'EED_Events_Archive', 'event_details' ), |
|
335 | - EED_Events_Archive::EVENT_DETAILS_PRIORITY |
|
336 | - ); |
|
333 | + 'the_content', |
|
334 | + array( 'EED_Events_Archive', 'event_details' ), |
|
335 | + EED_Events_Archive::EVENT_DETAILS_PRIORITY |
|
336 | + ); |
|
337 | 337 | $excerpt = EED_Events_Archive::event_details( $excerpt ); |
338 | 338 | } else { |
339 | 339 | EED_Events_Archive::$using_get_the_excerpt = true; |
@@ -424,17 +424,17 @@ discard block |
||
424 | 424 | // no further password checks required atm |
425 | 425 | add_filter( 'FHEE__EED_Events_Archive__event_details__no_post_password_required', '__return_true' ); |
426 | 426 | // we need to first remove this callback from being applied to the_content() or the_excerpt() |
427 | - // (otherwise it will recurse and blow up the interweb) |
|
427 | + // (otherwise it will recurse and blow up the interweb) |
|
428 | 428 | remove_filter( |
429 | - 'the_excerpt', |
|
430 | - array( 'EED_Events_Archive', 'event_details' ), |
|
431 | - EED_Events_Archive::EVENT_DETAILS_PRIORITY |
|
432 | - ); |
|
429 | + 'the_excerpt', |
|
430 | + array( 'EED_Events_Archive', 'event_details' ), |
|
431 | + EED_Events_Archive::EVENT_DETAILS_PRIORITY |
|
432 | + ); |
|
433 | 433 | remove_filter( |
434 | - 'the_content', |
|
435 | - array( 'EED_Events_Archive', 'event_details' ), |
|
436 | - EED_Events_Archive::EVENT_DETAILS_PRIORITY |
|
437 | - ); |
|
434 | + 'the_content', |
|
435 | + array( 'EED_Events_Archive', 'event_details' ), |
|
436 | + EED_Events_Archive::EVENT_DETAILS_PRIORITY |
|
437 | + ); |
|
438 | 438 | remove_filter( 'get_the_excerpt', array( 'EED_Events_Archive', 'get_the_excerpt' ), 1 ); |
439 | 439 | // now add additional content depending on whether event is using the_excerpt() or the_content() |
440 | 440 | EED_Events_Archive::instance()->template_parts = EED_Events_Archive::instance()->initialize_template_parts(); |
@@ -442,20 +442,20 @@ discard block |
||
442 | 442 | $content = EED_Events_Archive::instance()->template_parts->apply_template_part_filters( $content ); |
443 | 443 | // re-add our main filters (or else the next event won't have them) |
444 | 444 | add_filter( |
445 | - 'the_excerpt', |
|
446 | - array( 'EED_Events_Archive', 'event_details' ), |
|
447 | - EED_Events_Archive::EVENT_DETAILS_PRIORITY |
|
448 | - ); |
|
445 | + 'the_excerpt', |
|
446 | + array( 'EED_Events_Archive', 'event_details' ), |
|
447 | + EED_Events_Archive::EVENT_DETAILS_PRIORITY |
|
448 | + ); |
|
449 | 449 | add_filter( |
450 | - 'the_content', |
|
451 | - array( 'EED_Events_Archive', 'event_details' ), |
|
452 | - EED_Events_Archive::EVENT_DETAILS_PRIORITY |
|
453 | - ); |
|
450 | + 'the_content', |
|
451 | + array( 'EED_Events_Archive', 'event_details' ), |
|
452 | + EED_Events_Archive::EVENT_DETAILS_PRIORITY |
|
453 | + ); |
|
454 | 454 | add_filter( 'get_the_excerpt', array( 'EED_Events_Archive', 'get_the_excerpt' ), 1, 1 ); |
455 | 455 | remove_filter( |
456 | - 'FHEE__EED_Events_Archive__event_details__no_post_password_required', |
|
457 | - '__return_true' |
|
458 | - ); |
|
456 | + 'FHEE__EED_Events_Archive__event_details__no_post_password_required', |
|
457 | + '__return_true' |
|
458 | + ); |
|
459 | 459 | return $content; |
460 | 460 | } |
461 | 461 | |
@@ -471,15 +471,15 @@ discard block |
||
471 | 471 | // we need to first remove this callback from being applied to the_content() |
472 | 472 | // (otherwise it will recurse and blow up the interweb) |
473 | 473 | remove_filter( |
474 | - 'the_excerpt', |
|
475 | - array( 'EED_Events_Archive', 'event_details' ), |
|
476 | - EED_Events_Archive::EVENT_DETAILS_PRIORITY |
|
477 | - ); |
|
474 | + 'the_excerpt', |
|
475 | + array( 'EED_Events_Archive', 'event_details' ), |
|
476 | + EED_Events_Archive::EVENT_DETAILS_PRIORITY |
|
477 | + ); |
|
478 | 478 | remove_filter( |
479 | - 'the_content', |
|
480 | - array( 'EED_Events_Archive', 'event_details' ), |
|
481 | - EED_Events_Archive::EVENT_DETAILS_PRIORITY |
|
482 | - ); |
|
479 | + 'the_content', |
|
480 | + array( 'EED_Events_Archive', 'event_details' ), |
|
481 | + EED_Events_Archive::EVENT_DETAILS_PRIORITY |
|
482 | + ); |
|
483 | 483 | remove_filter( 'get_the_excerpt', array( 'EED_Events_Archive', 'get_the_excerpt' ), 1 ); |
484 | 484 | //now add additional content depending on whether event is using the_excerpt() or the_content() |
485 | 485 | EED_Events_Archive::_add_additional_excerpt_filters(); |
@@ -489,15 +489,15 @@ discard block |
||
489 | 489 | $content = EEH_Template::locate_template( 'content-espresso_events-details.php' ); |
490 | 490 | // re-add our main filters (or else the next event won't have them) |
491 | 491 | add_filter( |
492 | - 'the_excerpt', |
|
493 | - array( 'EED_Events_Archive', 'event_details' ), |
|
494 | - EED_Events_Archive::EVENT_DETAILS_PRIORITY |
|
495 | - ); |
|
492 | + 'the_excerpt', |
|
493 | + array( 'EED_Events_Archive', 'event_details' ), |
|
494 | + EED_Events_Archive::EVENT_DETAILS_PRIORITY |
|
495 | + ); |
|
496 | 496 | add_filter( |
497 | - 'the_content', |
|
498 | - array( 'EED_Events_Archive', 'event_details' ), |
|
499 | - EED_Events_Archive::EVENT_DETAILS_PRIORITY |
|
500 | - ); |
|
497 | + 'the_content', |
|
498 | + array( 'EED_Events_Archive', 'event_details' ), |
|
499 | + EED_Events_Archive::EVENT_DETAILS_PRIORITY |
|
500 | + ); |
|
501 | 501 | add_filter( 'get_the_excerpt', array( 'EED_Events_Archive', 'get_the_excerpt' ), 1, 1 ); |
502 | 502 | // but remove the other filters so that they don't get applied to the next post |
503 | 503 | EED_Events_Archive::_remove_additional_events_archive_filters(); |
@@ -574,20 +574,20 @@ discard block |
||
574 | 574 | */ |
575 | 575 | private static function _add_additional_excerpt_filters() { |
576 | 576 | add_filter( |
577 | - 'the_excerpt', |
|
578 | - array( 'EED_Events_Archive', 'event_datetimes' ), |
|
579 | - EED_Events_Archive::EVENT_DATETIMES_PRIORITY |
|
580 | - ); |
|
577 | + 'the_excerpt', |
|
578 | + array( 'EED_Events_Archive', 'event_datetimes' ), |
|
579 | + EED_Events_Archive::EVENT_DATETIMES_PRIORITY |
|
580 | + ); |
|
581 | 581 | add_filter( |
582 | - 'the_excerpt', |
|
583 | - array( 'EED_Events_Archive', 'event_tickets' ), |
|
584 | - EED_Events_Archive::EVENT_TICKETS_PRIORITY |
|
585 | - ); |
|
582 | + 'the_excerpt', |
|
583 | + array( 'EED_Events_Archive', 'event_tickets' ), |
|
584 | + EED_Events_Archive::EVENT_TICKETS_PRIORITY |
|
585 | + ); |
|
586 | 586 | add_filter( |
587 | - 'the_excerpt', |
|
588 | - array( 'EED_Events_Archive', 'event_venues' ), |
|
589 | - EED_Events_Archive::EVENT_VENUES_PRIORITY |
|
590 | - ); |
|
587 | + 'the_excerpt', |
|
588 | + array( 'EED_Events_Archive', 'event_venues' ), |
|
589 | + EED_Events_Archive::EVENT_VENUES_PRIORITY |
|
590 | + ); |
|
591 | 591 | } |
592 | 592 | |
593 | 593 | |
@@ -600,20 +600,20 @@ discard block |
||
600 | 600 | */ |
601 | 601 | private static function _add_additional_content_filters() { |
602 | 602 | add_filter( |
603 | - 'the_content', |
|
604 | - array( 'EED_Events_Archive', 'event_datetimes' ), |
|
605 | - EED_Events_Archive::EVENT_DATETIMES_PRIORITY |
|
606 | - ); |
|
603 | + 'the_content', |
|
604 | + array( 'EED_Events_Archive', 'event_datetimes' ), |
|
605 | + EED_Events_Archive::EVENT_DATETIMES_PRIORITY |
|
606 | + ); |
|
607 | 607 | add_filter( |
608 | - 'the_content', |
|
609 | - array( 'EED_Events_Archive', 'event_tickets' ), |
|
610 | - EED_Events_Archive::EVENT_TICKETS_PRIORITY |
|
611 | - ); |
|
608 | + 'the_content', |
|
609 | + array( 'EED_Events_Archive', 'event_tickets' ), |
|
610 | + EED_Events_Archive::EVENT_TICKETS_PRIORITY |
|
611 | + ); |
|
612 | 612 | add_filter( |
613 | - 'the_content', |
|
614 | - array( 'EED_Events_Archive', 'event_venues' ), |
|
615 | - EED_Events_Archive::EVENT_VENUES_PRIORITY |
|
616 | - ); |
|
613 | + 'the_content', |
|
614 | + array( 'EED_Events_Archive', 'event_venues' ), |
|
615 | + EED_Events_Archive::EVENT_VENUES_PRIORITY |
|
616 | + ); |
|
617 | 617 | } |
618 | 618 | |
619 | 619 | |
@@ -626,35 +626,35 @@ discard block |
||
626 | 626 | */ |
627 | 627 | private static function _remove_additional_events_archive_filters() { |
628 | 628 | remove_filter( |
629 | - 'the_excerpt', |
|
630 | - array( 'EED_Events_Archive', 'event_datetimes' ), |
|
631 | - EED_Events_Archive::EVENT_DATETIMES_PRIORITY |
|
632 | - ); |
|
629 | + 'the_excerpt', |
|
630 | + array( 'EED_Events_Archive', 'event_datetimes' ), |
|
631 | + EED_Events_Archive::EVENT_DATETIMES_PRIORITY |
|
632 | + ); |
|
633 | 633 | remove_filter( |
634 | - 'the_excerpt', |
|
635 | - array( 'EED_Events_Archive', 'event_tickets' ), |
|
636 | - EED_Events_Archive::EVENT_TICKETS_PRIORITY |
|
637 | - ); |
|
634 | + 'the_excerpt', |
|
635 | + array( 'EED_Events_Archive', 'event_tickets' ), |
|
636 | + EED_Events_Archive::EVENT_TICKETS_PRIORITY |
|
637 | + ); |
|
638 | 638 | remove_filter( |
639 | - 'the_excerpt', |
|
640 | - array( 'EED_Events_Archive', 'event_venues' ), |
|
641 | - EED_Events_Archive::EVENT_VENUES_PRIORITY |
|
642 | - ); |
|
639 | + 'the_excerpt', |
|
640 | + array( 'EED_Events_Archive', 'event_venues' ), |
|
641 | + EED_Events_Archive::EVENT_VENUES_PRIORITY |
|
642 | + ); |
|
643 | 643 | remove_filter( |
644 | - 'the_content', |
|
645 | - array( 'EED_Events_Archive', 'event_datetimes' ), |
|
646 | - EED_Events_Archive::EVENT_DATETIMES_PRIORITY |
|
647 | - ); |
|
644 | + 'the_content', |
|
645 | + array( 'EED_Events_Archive', 'event_datetimes' ), |
|
646 | + EED_Events_Archive::EVENT_DATETIMES_PRIORITY |
|
647 | + ); |
|
648 | 648 | remove_filter( |
649 | - 'the_content', |
|
650 | - array( 'EED_Events_Archive', 'event_tickets' ), |
|
651 | - EED_Events_Archive::EVENT_TICKETS_PRIORITY |
|
652 | - ); |
|
649 | + 'the_content', |
|
650 | + array( 'EED_Events_Archive', 'event_tickets' ), |
|
651 | + EED_Events_Archive::EVENT_TICKETS_PRIORITY |
|
652 | + ); |
|
653 | 653 | remove_filter( |
654 | - 'the_content', |
|
655 | - array( 'EED_Events_Archive', 'event_venues' ), |
|
656 | - EED_Events_Archive::EVENT_VENUES_PRIORITY |
|
657 | - ); |
|
654 | + 'the_content', |
|
655 | + array( 'EED_Events_Archive', 'event_venues' ), |
|
656 | + EED_Events_Archive::EVENT_VENUES_PRIORITY |
|
657 | + ); |
|
658 | 658 | } |
659 | 659 | |
660 | 660 | |
@@ -669,50 +669,50 @@ discard block |
||
669 | 669 | //remove_filter( 'get_the_excerpt', array( 'EED_Events_Archive', 'get_the_excerpt' ), 1 ); |
670 | 670 | remove_filter( 'the_title', array( 'EED_Events_Archive', 'the_title' ), 1 ); |
671 | 671 | remove_filter( |
672 | - 'the_excerpt', |
|
673 | - array( 'EED_Events_Archive', 'event_details' ), |
|
674 | - EED_Events_Archive::EVENT_DETAILS_PRIORITY |
|
675 | - ); |
|
672 | + 'the_excerpt', |
|
673 | + array( 'EED_Events_Archive', 'event_details' ), |
|
674 | + EED_Events_Archive::EVENT_DETAILS_PRIORITY |
|
675 | + ); |
|
676 | 676 | remove_filter( |
677 | - 'the_excerpt', |
|
678 | - array( 'EED_Events_Archive', 'event_datetimes' ), |
|
679 | - EED_Events_Archive::EVENT_DATETIMES_PRIORITY |
|
680 | - ); |
|
677 | + 'the_excerpt', |
|
678 | + array( 'EED_Events_Archive', 'event_datetimes' ), |
|
679 | + EED_Events_Archive::EVENT_DATETIMES_PRIORITY |
|
680 | + ); |
|
681 | 681 | remove_filter( |
682 | - 'the_excerpt', |
|
683 | - array( 'EED_Events_Archive', 'event_tickets' ), |
|
684 | - EED_Events_Archive::EVENT_TICKETS_PRIORITY |
|
685 | - ); |
|
682 | + 'the_excerpt', |
|
683 | + array( 'EED_Events_Archive', 'event_tickets' ), |
|
684 | + EED_Events_Archive::EVENT_TICKETS_PRIORITY |
|
685 | + ); |
|
686 | 686 | remove_filter( |
687 | - 'the_excerpt', |
|
688 | - array( 'EED_Events_Archive', 'event_venues' ), |
|
689 | - EED_Events_Archive::EVENT_VENUES_PRIORITY |
|
690 | - ); |
|
687 | + 'the_excerpt', |
|
688 | + array( 'EED_Events_Archive', 'event_venues' ), |
|
689 | + EED_Events_Archive::EVENT_VENUES_PRIORITY |
|
690 | + ); |
|
691 | 691 | remove_filter( |
692 | - 'the_content', |
|
693 | - array( 'EED_Events_Archive', 'event_details' ), |
|
694 | - EED_Events_Archive::EVENT_DETAILS_PRIORITY |
|
695 | - ); |
|
692 | + 'the_content', |
|
693 | + array( 'EED_Events_Archive', 'event_details' ), |
|
694 | + EED_Events_Archive::EVENT_DETAILS_PRIORITY |
|
695 | + ); |
|
696 | 696 | remove_filter( |
697 | - 'the_content', |
|
698 | - array( 'EED_Events_Archive', 'event_datetimes' ), |
|
699 | - EED_Events_Archive::EVENT_DATETIMES_PRIORITY |
|
700 | - ); |
|
697 | + 'the_content', |
|
698 | + array( 'EED_Events_Archive', 'event_datetimes' ), |
|
699 | + EED_Events_Archive::EVENT_DATETIMES_PRIORITY |
|
700 | + ); |
|
701 | 701 | remove_filter( |
702 | - 'the_content', |
|
703 | - array( 'EED_Events_Archive', 'event_tickets' ), |
|
704 | - EED_Events_Archive::EVENT_TICKETS_PRIORITY |
|
705 | - ); |
|
702 | + 'the_content', |
|
703 | + array( 'EED_Events_Archive', 'event_tickets' ), |
|
704 | + EED_Events_Archive::EVENT_TICKETS_PRIORITY |
|
705 | + ); |
|
706 | 706 | remove_filter( |
707 | - 'the_content', |
|
708 | - array( 'EED_Events_Archive', 'event_venues' ), |
|
709 | - EED_Events_Archive::EVENT_VENUES_PRIORITY |
|
710 | - ); |
|
707 | + 'the_content', |
|
708 | + array( 'EED_Events_Archive', 'event_venues' ), |
|
709 | + EED_Events_Archive::EVENT_VENUES_PRIORITY |
|
710 | + ); |
|
711 | 711 | // don't display entry meta because the existing theme will take care of that |
712 | 712 | remove_filter( |
713 | - 'FHEE__content_espresso_events_details_template__display_entry_meta', |
|
714 | - '__return_false' |
|
715 | - ); |
|
713 | + 'FHEE__content_espresso_events_details_template__display_entry_meta', |
|
714 | + '__return_false' |
|
715 | + ); |
|
716 | 716 | } |
717 | 717 | |
718 | 718 | |
@@ -727,7 +727,7 @@ discard block |
||
727 | 727 | * @return void |
728 | 728 | */ |
729 | 729 | public function load_event_list_assets() { |
730 | - do_action( 'AHEE__EED_Events_Archive__before_load_assets' ); |
|
730 | + do_action( 'AHEE__EED_Events_Archive__before_load_assets' ); |
|
731 | 731 | add_filter( 'FHEE_load_EE_Session', '__return_true' ); |
732 | 732 | add_filter( 'FHEE__EED_Ticket_Selector__load_tckt_slctr_assets', '__return_true' ); |
733 | 733 | add_action('wp_enqueue_scripts', array( $this, 'wp_enqueue_scripts' ), 10 ); |
@@ -3,7 +3,7 @@ discard block |
||
3 | 3 | use EventEspresso\core\libraries\iframe_display\EventListIframeEmbedButton; |
4 | 4 | use EventEspresso\modules\events_archive\EventsArchiveIframe; |
5 | 5 | |
6 | -defined( 'EVENT_ESPRESSO_VERSION') || exit('No direct script access allowed'); |
|
6 | +defined('EVENT_ESPRESSO_VERSION') || exit('No direct script access allowed'); |
|
7 | 7 | |
8 | 8 | /** |
9 | 9 | * Event List |
@@ -51,7 +51,7 @@ discard block |
||
51 | 51 | * @return EED_Events_Archive |
52 | 52 | */ |
53 | 53 | public static function instance() { |
54 | - return parent::get_instance( __CLASS__ ); |
|
54 | + return parent::get_instance(__CLASS__); |
|
55 | 55 | } |
56 | 56 | |
57 | 57 | |
@@ -63,10 +63,10 @@ discard block |
||
63 | 63 | * @return void |
64 | 64 | */ |
65 | 65 | public static function set_hooks() { |
66 | - EE_Config::register_route( EE_Registry::instance()->CFG->core->event_cpt_slug, 'Events_Archive', 'run' ); |
|
67 | - EE_Config::register_route( 'event_list', 'Events_Archive', 'event_list' ); |
|
68 | - EE_Config::register_route( 'iframe', 'Events_Archive', 'event_list_iframe', 'event_list' ); |
|
69 | - add_action( 'wp_loaded', array( 'EED_Events_Archive', 'set_definitions' ), 2 ); |
|
66 | + EE_Config::register_route(EE_Registry::instance()->CFG->core->event_cpt_slug, 'Events_Archive', 'run'); |
|
67 | + EE_Config::register_route('event_list', 'Events_Archive', 'event_list'); |
|
68 | + EE_Config::register_route('iframe', 'Events_Archive', 'event_list_iframe', 'event_list'); |
|
69 | + add_action('wp_loaded', array('EED_Events_Archive', 'set_definitions'), 2); |
|
70 | 70 | } |
71 | 71 | |
72 | 72 | /** |
@@ -76,12 +76,12 @@ discard block |
||
76 | 76 | * @return void |
77 | 77 | */ |
78 | 78 | public static function set_hooks_admin() { |
79 | - add_action( 'wp_loaded', array( 'EED_Events_Archive', 'set_definitions' ), 2 ); |
|
79 | + add_action('wp_loaded', array('EED_Events_Archive', 'set_definitions'), 2); |
|
80 | 80 | // hook into the end of the \EE_Admin_Page::_load_page_dependencies() |
81 | 81 | // to load assets for "espresso_events" page on the "default" route (action) |
82 | 82 | add_action( |
83 | 83 | 'FHEE__EE_Admin_Page___load_page_dependencies__after_load__espresso_events__default', |
84 | - array( 'EED_Events_Archive', 'event_list_iframe_embed_button' ), |
|
84 | + array('EED_Events_Archive', 'event_list_iframe_embed_button'), |
|
85 | 85 | 10 |
86 | 86 | ); |
87 | 87 | } |
@@ -96,8 +96,8 @@ discard block |
||
96 | 96 | * @return void |
97 | 97 | */ |
98 | 98 | public static function set_definitions() { |
99 | - define( 'EVENTS_ARCHIVE_ASSETS_URL', plugin_dir_url( __FILE__ ) . 'assets' . DS ); |
|
100 | - define( 'EVENTS_ARCHIVE_TEMPLATES_PATH', str_replace( '\\', DS, plugin_dir_path( __FILE__ )) . 'templates' . DS ); |
|
99 | + define('EVENTS_ARCHIVE_ASSETS_URL', plugin_dir_url(__FILE__).'assets'.DS); |
|
100 | + define('EVENTS_ARCHIVE_TEMPLATES_PATH', str_replace('\\', DS, plugin_dir_path(__FILE__)).'templates'.DS); |
|
101 | 101 | } |
102 | 102 | |
103 | 103 | |
@@ -105,10 +105,10 @@ discard block |
||
105 | 105 | /** |
106 | 106 | * set up EE_Events_Archive_Config |
107 | 107 | */ |
108 | - protected function set_config(){ |
|
109 | - $this->set_config_section( 'template_settings' ); |
|
110 | - $this->set_config_class( 'EE_Events_Archive_Config' ); |
|
111 | - $this->set_config_name( 'EED_Events_Archive' ); |
|
108 | + protected function set_config() { |
|
109 | + $this->set_config_section('template_settings'); |
|
110 | + $this->set_config_class('EE_Events_Archive_Config'); |
|
111 | + $this->set_config_name('EED_Events_Archive'); |
|
112 | 112 | } |
113 | 113 | |
114 | 114 | |
@@ -117,7 +117,7 @@ discard block |
||
117 | 117 | * @return EventListIframeEmbedButton |
118 | 118 | */ |
119 | 119 | public static function get_iframe_embed_button() { |
120 | - if ( ! self::$_iframe_embed_button instanceof EventListIframeEmbedButton ) { |
|
120 | + if ( ! self::$_iframe_embed_button instanceof EventListIframeEmbedButton) { |
|
121 | 121 | self::$_iframe_embed_button = new EventListIframeEmbedButton(); |
122 | 122 | } |
123 | 123 | return self::$_iframe_embed_button; |
@@ -143,35 +143,35 @@ discard block |
||
143 | 143 | * @param \EE_Events_Archive_Config $config |
144 | 144 | * @return \EE_Template_Part_Manager |
145 | 145 | */ |
146 | - public function initialize_template_parts( EE_Events_Archive_Config $config = null ) { |
|
146 | + public function initialize_template_parts(EE_Events_Archive_Config $config = null) { |
|
147 | 147 | $config = $config instanceof EE_Events_Archive_Config ? $config : $this->config(); |
148 | 148 | EEH_Autoloader::instance()->register_template_part_autoloaders(); |
149 | 149 | $template_parts = new EE_Template_Part_Manager(); |
150 | 150 | $template_parts->add_template_part( |
151 | 151 | 'tickets', |
152 | - __( 'Ticket Selector', 'event_espresso' ), |
|
152 | + __('Ticket Selector', 'event_espresso'), |
|
153 | 153 | 'content-espresso_events-tickets.php', |
154 | 154 | $config->display_order_tickets |
155 | 155 | ); |
156 | 156 | $template_parts->add_template_part( |
157 | 157 | 'datetimes', |
158 | - __( 'Dates and Times', 'event_espresso' ), |
|
158 | + __('Dates and Times', 'event_espresso'), |
|
159 | 159 | 'content-espresso_events-datetimes.php', |
160 | 160 | $config->display_order_datetimes |
161 | 161 | ); |
162 | 162 | $template_parts->add_template_part( |
163 | 163 | 'event', |
164 | - __( 'Event Description', 'event_espresso' ), |
|
164 | + __('Event Description', 'event_espresso'), |
|
165 | 165 | 'content-espresso_events-details.php', |
166 | 166 | $config->display_order_event |
167 | 167 | ); |
168 | 168 | $template_parts->add_template_part( |
169 | 169 | 'venue', |
170 | - __( 'Venue Information', 'event_espresso' ), |
|
170 | + __('Venue Information', 'event_espresso'), |
|
171 | 171 | 'content-espresso_events-venues.php', |
172 | 172 | $config->display_order_venue |
173 | 173 | ); |
174 | - do_action( 'AHEE__EED_Event_Archive__initialize_template_parts', $template_parts ); |
|
174 | + do_action('AHEE__EED_Event_Archive__initialize_template_parts', $template_parts); |
|
175 | 175 | return $template_parts; |
176 | 176 | } |
177 | 177 | |
@@ -184,8 +184,8 @@ discard block |
||
184 | 184 | * @param WP $WP |
185 | 185 | * @return void |
186 | 186 | */ |
187 | - public function run( $WP ) { |
|
188 | - do_action( 'AHEE__EED_Events_Archive__before_run' ); |
|
187 | + public function run($WP) { |
|
188 | + do_action('AHEE__EED_Events_Archive__before_run'); |
|
189 | 189 | // ensure valid EE_Events_Archive_Config() object exists |
190 | 190 | $this->set_config(); |
191 | 191 | /** @type EE_Events_Archive_Config $config */ |
@@ -197,14 +197,14 @@ discard block |
||
197 | 197 | EEH_Event_Query::add_query_filters(); |
198 | 198 | // set params that will get used by the filters |
199 | 199 | EEH_Event_Query::set_query_params( |
200 | - '', // month |
|
201 | - '', // category |
|
202 | - $config->display_expired_events, // show_expired |
|
203 | - 'start_date', // orderby |
|
200 | + '', // month |
|
201 | + '', // category |
|
202 | + $config->display_expired_events, // show_expired |
|
203 | + 'start_date', // orderby |
|
204 | 204 | 'ASC' // sort |
205 | 205 | ); |
206 | 206 | // check what template is loaded |
207 | - add_filter( 'template_include', array( $this, 'template_include' ), 999, 1 ); |
|
207 | + add_filter('template_include', array($this, 'template_include'), 999, 1); |
|
208 | 208 | } |
209 | 209 | |
210 | 210 | |
@@ -231,7 +231,7 @@ discard block |
||
231 | 231 | */ |
232 | 232 | public function event_list_iframe() { |
233 | 233 | \EED_Events_Archive::$iframe = true; |
234 | - $event_list_iframe = new EventsArchiveIframe( $this ); |
|
234 | + $event_list_iframe = new EventsArchiveIframe($this); |
|
235 | 235 | $event_list_iframe->display(); |
236 | 236 | } |
237 | 237 | |
@@ -269,42 +269,42 @@ discard block |
||
269 | 269 | * @param string $template |
270 | 270 | * @return string |
271 | 271 | */ |
272 | - public function template_include( $template = '' ) { |
|
272 | + public function template_include($template = '') { |
|
273 | 273 | // don't add content filter for dedicated EE child themes or private posts |
274 | - if ( ! EEH_Template::is_espresso_theme() ) { |
|
274 | + if ( ! EEH_Template::is_espresso_theme()) { |
|
275 | 275 | /** @type EE_Events_Archive_Config $config */ |
276 | 276 | $config = $this->config(); |
277 | 277 | // add status banner ? |
278 | - if ( $config->display_status_banner ) { |
|
279 | - add_filter( 'the_title', array( 'EED_Events_Archive', 'the_title' ), 100, 2 ); |
|
278 | + if ($config->display_status_banner) { |
|
279 | + add_filter('the_title', array('EED_Events_Archive', 'the_title'), 100, 2); |
|
280 | 280 | } |
281 | 281 | // if NOT a custom template |
282 | 282 | if ( |
283 | 283 | apply_filters('FHEE__EED_Event_Archive__template_include__allow_custom_selected_template', false) |
284 | 284 | || EE_Registry::instance() |
285 | - ->load_core( 'Front_Controller' ) |
|
285 | + ->load_core('Front_Controller') |
|
286 | 286 | ->get_selected_template() !== 'archive-espresso_events.php' |
287 | 287 | ) { |
288 | 288 | // don't display entry meta because the existing theme will take care of that |
289 | - add_filter( 'FHEE__EED_Events_Archive__template_include__events_list_active', '__return_true' ); |
|
289 | + add_filter('FHEE__EED_Events_Archive__template_include__events_list_active', '__return_true'); |
|
290 | 290 | // load functions.php file for the theme (loaded by WP if using child theme) |
291 | 291 | EEH_Template::load_espresso_theme_functions(); |
292 | 292 | // because we don't know if the theme is using the_excerpt() |
293 | 293 | add_filter( |
294 | 294 | 'the_excerpt', |
295 | - array( 'EED_Events_Archive', 'event_details' ), |
|
295 | + array('EED_Events_Archive', 'event_details'), |
|
296 | 296 | EED_Events_Archive::EVENT_DETAILS_PRIORITY |
297 | 297 | ); |
298 | 298 | // or the_content |
299 | 299 | add_filter( |
300 | 300 | 'the_content', |
301 | - array( 'EED_Events_Archive', 'event_details' ), |
|
301 | + array('EED_Events_Archive', 'event_details'), |
|
302 | 302 | EED_Events_Archive::EVENT_DETAILS_PRIORITY |
303 | 303 | ); |
304 | 304 | // and just in case they are running get_the_excerpt() which DESTROYS things |
305 | - add_filter( 'get_the_excerpt', array( 'EED_Events_Archive', 'get_the_excerpt' ), 1, 1 ); |
|
305 | + add_filter('get_the_excerpt', array('EED_Events_Archive', 'get_the_excerpt'), 1, 1); |
|
306 | 306 | // don't display entry meta because the existing theme will take care of that |
307 | - add_filter( 'FHEE__content_espresso_events_details_template__display_entry_meta', '__return_false' ); |
|
307 | + add_filter('FHEE__content_espresso_events_details_template__display_entry_meta', '__return_false'); |
|
308 | 308 | } |
309 | 309 | } |
310 | 310 | return $template; |
@@ -319,25 +319,25 @@ discard block |
||
319 | 319 | * @param string $excerpt |
320 | 320 | * @return string |
321 | 321 | */ |
322 | - public static function get_the_excerpt( $excerpt = '' ) { |
|
323 | - if ( post_password_required() ) { |
|
322 | + public static function get_the_excerpt($excerpt = '') { |
|
323 | + if (post_password_required()) { |
|
324 | 324 | return $excerpt; |
325 | 325 | } |
326 | - if ( apply_filters( 'FHEE__EED_Events_Archive__get_the_excerpt__theme_uses_get_the_excerpt', false ) ) { |
|
326 | + if (apply_filters('FHEE__EED_Events_Archive__get_the_excerpt__theme_uses_get_the_excerpt', false)) { |
|
327 | 327 | remove_filter( |
328 | 328 | 'the_excerpt', |
329 | - array( 'EED_Events_Archive', 'event_details' ), |
|
329 | + array('EED_Events_Archive', 'event_details'), |
|
330 | 330 | EED_Events_Archive::EVENT_DETAILS_PRIORITY |
331 | 331 | ); |
332 | 332 | remove_filter( |
333 | 333 | 'the_content', |
334 | - array( 'EED_Events_Archive', 'event_details' ), |
|
334 | + array('EED_Events_Archive', 'event_details'), |
|
335 | 335 | EED_Events_Archive::EVENT_DETAILS_PRIORITY |
336 | 336 | ); |
337 | - $excerpt = EED_Events_Archive::event_details( $excerpt ); |
|
337 | + $excerpt = EED_Events_Archive::event_details($excerpt); |
|
338 | 338 | } else { |
339 | 339 | EED_Events_Archive::$using_get_the_excerpt = true; |
340 | - add_filter( 'wp_trim_excerpt', array( 'EED_Events_Archive', 'end_get_the_excerpt' ), 999, 1 ); |
|
340 | + add_filter('wp_trim_excerpt', array('EED_Events_Archive', 'end_get_the_excerpt'), 999, 1); |
|
341 | 341 | } |
342 | 342 | return $excerpt; |
343 | 343 | } |
@@ -351,7 +351,7 @@ discard block |
||
351 | 351 | * @param string $text |
352 | 352 | * @return string |
353 | 353 | */ |
354 | - public static function end_get_the_excerpt( $text = '' ) { |
|
354 | + public static function end_get_the_excerpt($text = '') { |
|
355 | 355 | EED_Events_Archive::$using_get_the_excerpt = false; |
356 | 356 | return $text; |
357 | 357 | } |
@@ -366,10 +366,10 @@ discard block |
||
366 | 366 | * @param string $id |
367 | 367 | * @return string |
368 | 368 | */ |
369 | - public static function the_title( $title = '', $id = '' ) { |
|
369 | + public static function the_title($title = '', $id = '') { |
|
370 | 370 | global $post; |
371 | - if ( $post instanceof WP_Post ) { |
|
372 | - return in_the_loop() && $post->ID == $id ? espresso_event_status_banner( $post->ID ) . $title : $title; |
|
371 | + if ($post instanceof WP_Post) { |
|
372 | + return in_the_loop() && $post->ID == $id ? espresso_event_status_banner($post->ID).$title : $title; |
|
373 | 373 | } |
374 | 374 | return $title; |
375 | 375 | } |
@@ -383,7 +383,7 @@ discard block |
||
383 | 383 | * @param string $content |
384 | 384 | * @return string |
385 | 385 | */ |
386 | - public static function event_details( $content ) { |
|
386 | + public static function event_details($content) { |
|
387 | 387 | global $post; |
388 | 388 | static $current_post_ID = 0; |
389 | 389 | if ( |
@@ -392,8 +392,8 @@ discard block |
||
392 | 392 | && ! EED_Events_Archive::$using_get_the_excerpt |
393 | 393 | && ! post_password_required() |
394 | 394 | && ( |
395 | - apply_filters( 'FHEE__EES_Espresso_Events__process_shortcode__true', false ) |
|
396 | - || ! apply_filters( 'FHEE__content_espresso_events__template_loaded', false ) |
|
395 | + apply_filters('FHEE__EES_Espresso_Events__process_shortcode__true', false) |
|
396 | + || ! apply_filters('FHEE__content_espresso_events__template_loaded', false) |
|
397 | 397 | ) |
398 | 398 | ) { |
399 | 399 | // Set current post ID to prevent showing content twice, but only if headers have definitely been sent. |
@@ -402,8 +402,8 @@ discard block |
||
402 | 402 | // We want to allow those plugins to still do their thing and have access to our content, but depending on |
403 | 403 | // how your event content is being displayed (shortcode, CPT route, etc), this filter can get applied twice, |
404 | 404 | // so the following allows this filter to be applied multiple times, but only once for real |
405 | - $current_post_ID = did_action( 'loop_start' ) ? $post->ID : 0; |
|
406 | - if ( EE_Registry::instance()->CFG->template_settings->EED_Events_Archive->use_sortable_display_order ) { |
|
405 | + $current_post_ID = did_action('loop_start') ? $post->ID : 0; |
|
406 | + if (EE_Registry::instance()->CFG->template_settings->EED_Events_Archive->use_sortable_display_order) { |
|
407 | 407 | $content = \EED_Events_Archive::use_sortable_display_order(); |
408 | 408 | } else { |
409 | 409 | $content = \EED_Events_Archive::use_filterable_display_order(); |
@@ -422,36 +422,36 @@ discard block |
||
422 | 422 | */ |
423 | 423 | protected static function use_sortable_display_order() { |
424 | 424 | // no further password checks required atm |
425 | - add_filter( 'FHEE__EED_Events_Archive__event_details__no_post_password_required', '__return_true' ); |
|
425 | + add_filter('FHEE__EED_Events_Archive__event_details__no_post_password_required', '__return_true'); |
|
426 | 426 | // we need to first remove this callback from being applied to the_content() or the_excerpt() |
427 | 427 | // (otherwise it will recurse and blow up the interweb) |
428 | 428 | remove_filter( |
429 | 429 | 'the_excerpt', |
430 | - array( 'EED_Events_Archive', 'event_details' ), |
|
430 | + array('EED_Events_Archive', 'event_details'), |
|
431 | 431 | EED_Events_Archive::EVENT_DETAILS_PRIORITY |
432 | 432 | ); |
433 | 433 | remove_filter( |
434 | 434 | 'the_content', |
435 | - array( 'EED_Events_Archive', 'event_details' ), |
|
435 | + array('EED_Events_Archive', 'event_details'), |
|
436 | 436 | EED_Events_Archive::EVENT_DETAILS_PRIORITY |
437 | 437 | ); |
438 | - remove_filter( 'get_the_excerpt', array( 'EED_Events_Archive', 'get_the_excerpt' ), 1 ); |
|
438 | + remove_filter('get_the_excerpt', array('EED_Events_Archive', 'get_the_excerpt'), 1); |
|
439 | 439 | // now add additional content depending on whether event is using the_excerpt() or the_content() |
440 | 440 | EED_Events_Archive::instance()->template_parts = EED_Events_Archive::instance()->initialize_template_parts(); |
441 | - $content = EEH_Template::locate_template( 'content-espresso_events-details.php' ); |
|
442 | - $content = EED_Events_Archive::instance()->template_parts->apply_template_part_filters( $content ); |
|
441 | + $content = EEH_Template::locate_template('content-espresso_events-details.php'); |
|
442 | + $content = EED_Events_Archive::instance()->template_parts->apply_template_part_filters($content); |
|
443 | 443 | // re-add our main filters (or else the next event won't have them) |
444 | 444 | add_filter( |
445 | 445 | 'the_excerpt', |
446 | - array( 'EED_Events_Archive', 'event_details' ), |
|
446 | + array('EED_Events_Archive', 'event_details'), |
|
447 | 447 | EED_Events_Archive::EVENT_DETAILS_PRIORITY |
448 | 448 | ); |
449 | 449 | add_filter( |
450 | 450 | 'the_content', |
451 | - array( 'EED_Events_Archive', 'event_details' ), |
|
451 | + array('EED_Events_Archive', 'event_details'), |
|
452 | 452 | EED_Events_Archive::EVENT_DETAILS_PRIORITY |
453 | 453 | ); |
454 | - add_filter( 'get_the_excerpt', array( 'EED_Events_Archive', 'get_the_excerpt' ), 1, 1 ); |
|
454 | + add_filter('get_the_excerpt', array('EED_Events_Archive', 'get_the_excerpt'), 1, 1); |
|
455 | 455 | remove_filter( |
456 | 456 | 'FHEE__EED_Events_Archive__event_details__no_post_password_required', |
457 | 457 | '__return_true' |
@@ -472,36 +472,36 @@ discard block |
||
472 | 472 | // (otherwise it will recurse and blow up the interweb) |
473 | 473 | remove_filter( |
474 | 474 | 'the_excerpt', |
475 | - array( 'EED_Events_Archive', 'event_details' ), |
|
475 | + array('EED_Events_Archive', 'event_details'), |
|
476 | 476 | EED_Events_Archive::EVENT_DETAILS_PRIORITY |
477 | 477 | ); |
478 | 478 | remove_filter( |
479 | 479 | 'the_content', |
480 | - array( 'EED_Events_Archive', 'event_details' ), |
|
480 | + array('EED_Events_Archive', 'event_details'), |
|
481 | 481 | EED_Events_Archive::EVENT_DETAILS_PRIORITY |
482 | 482 | ); |
483 | - remove_filter( 'get_the_excerpt', array( 'EED_Events_Archive', 'get_the_excerpt' ), 1 ); |
|
483 | + remove_filter('get_the_excerpt', array('EED_Events_Archive', 'get_the_excerpt'), 1); |
|
484 | 484 | //now add additional content depending on whether event is using the_excerpt() or the_content() |
485 | 485 | EED_Events_Archive::_add_additional_excerpt_filters(); |
486 | 486 | EED_Events_Archive::_add_additional_content_filters(); |
487 | - do_action( 'AHEE__EED_Events_Archive__use_filterable_display_order__after_add_filters' ); |
|
487 | + do_action('AHEE__EED_Events_Archive__use_filterable_display_order__after_add_filters'); |
|
488 | 488 | // now load our template |
489 | - $content = EEH_Template::locate_template( 'content-espresso_events-details.php' ); |
|
489 | + $content = EEH_Template::locate_template('content-espresso_events-details.php'); |
|
490 | 490 | // re-add our main filters (or else the next event won't have them) |
491 | 491 | add_filter( |
492 | 492 | 'the_excerpt', |
493 | - array( 'EED_Events_Archive', 'event_details' ), |
|
493 | + array('EED_Events_Archive', 'event_details'), |
|
494 | 494 | EED_Events_Archive::EVENT_DETAILS_PRIORITY |
495 | 495 | ); |
496 | 496 | add_filter( |
497 | 497 | 'the_content', |
498 | - array( 'EED_Events_Archive', 'event_details' ), |
|
498 | + array('EED_Events_Archive', 'event_details'), |
|
499 | 499 | EED_Events_Archive::EVENT_DETAILS_PRIORITY |
500 | 500 | ); |
501 | - add_filter( 'get_the_excerpt', array( 'EED_Events_Archive', 'get_the_excerpt' ), 1, 1 ); |
|
501 | + add_filter('get_the_excerpt', array('EED_Events_Archive', 'get_the_excerpt'), 1, 1); |
|
502 | 502 | // but remove the other filters so that they don't get applied to the next post |
503 | 503 | EED_Events_Archive::_remove_additional_events_archive_filters(); |
504 | - do_action( 'AHEE__EED_Events_Archive__use_filterable_display_order__after_remove_filters' ); |
|
504 | + do_action('AHEE__EED_Events_Archive__use_filterable_display_order__after_remove_filters'); |
|
505 | 505 | // we're not returning the $content directly because the template we are loading uses the_content (or the_excerpt) |
506 | 506 | //return ! empty( $template ) ? $template : $content; |
507 | 507 | return $content; |
@@ -516,11 +516,11 @@ discard block |
||
516 | 516 | * @param string $content |
517 | 517 | * @return string |
518 | 518 | */ |
519 | - public static function event_datetimes( $content ) { |
|
520 | - if ( post_password_required() ) { |
|
519 | + public static function event_datetimes($content) { |
|
520 | + if (post_password_required()) { |
|
521 | 521 | return $content; |
522 | 522 | } |
523 | - return EEH_Template::locate_template( 'content-espresso_events-datetimes.php' ) . $content; |
|
523 | + return EEH_Template::locate_template('content-espresso_events-datetimes.php').$content; |
|
524 | 524 | } |
525 | 525 | |
526 | 526 | /** |
@@ -530,11 +530,11 @@ discard block |
||
530 | 530 | * @param string $content |
531 | 531 | * @return string |
532 | 532 | */ |
533 | - public static function event_tickets( $content ) { |
|
534 | - if ( post_password_required() ) { |
|
533 | + public static function event_tickets($content) { |
|
534 | + if (post_password_required()) { |
|
535 | 535 | return $content; |
536 | 536 | } |
537 | - return EEH_Template::locate_template( 'content-espresso_events-tickets.php' ) . $content; |
|
537 | + return EEH_Template::locate_template('content-espresso_events-tickets.php').$content; |
|
538 | 538 | } |
539 | 539 | |
540 | 540 | |
@@ -546,8 +546,8 @@ discard block |
||
546 | 546 | * @param string $content |
547 | 547 | * @return string |
548 | 548 | */ |
549 | - public static function event_venue( $content ) { |
|
550 | - return EED_Events_Archive::event_venues( $content ); |
|
549 | + public static function event_venue($content) { |
|
550 | + return EED_Events_Archive::event_venues($content); |
|
551 | 551 | } |
552 | 552 | |
553 | 553 | /** |
@@ -557,11 +557,11 @@ discard block |
||
557 | 557 | * @param string $content |
558 | 558 | * @return string |
559 | 559 | */ |
560 | - public static function event_venues( $content ) { |
|
561 | - if ( post_password_required() ) { |
|
560 | + public static function event_venues($content) { |
|
561 | + if (post_password_required()) { |
|
562 | 562 | return $content; |
563 | 563 | } |
564 | - return $content . EEH_Template::locate_template( 'content-espresso_events-venues.php' ); |
|
564 | + return $content.EEH_Template::locate_template('content-espresso_events-venues.php'); |
|
565 | 565 | } |
566 | 566 | |
567 | 567 | |
@@ -575,17 +575,17 @@ discard block |
||
575 | 575 | private static function _add_additional_excerpt_filters() { |
576 | 576 | add_filter( |
577 | 577 | 'the_excerpt', |
578 | - array( 'EED_Events_Archive', 'event_datetimes' ), |
|
578 | + array('EED_Events_Archive', 'event_datetimes'), |
|
579 | 579 | EED_Events_Archive::EVENT_DATETIMES_PRIORITY |
580 | 580 | ); |
581 | 581 | add_filter( |
582 | 582 | 'the_excerpt', |
583 | - array( 'EED_Events_Archive', 'event_tickets' ), |
|
583 | + array('EED_Events_Archive', 'event_tickets'), |
|
584 | 584 | EED_Events_Archive::EVENT_TICKETS_PRIORITY |
585 | 585 | ); |
586 | 586 | add_filter( |
587 | 587 | 'the_excerpt', |
588 | - array( 'EED_Events_Archive', 'event_venues' ), |
|
588 | + array('EED_Events_Archive', 'event_venues'), |
|
589 | 589 | EED_Events_Archive::EVENT_VENUES_PRIORITY |
590 | 590 | ); |
591 | 591 | } |
@@ -601,17 +601,17 @@ discard block |
||
601 | 601 | private static function _add_additional_content_filters() { |
602 | 602 | add_filter( |
603 | 603 | 'the_content', |
604 | - array( 'EED_Events_Archive', 'event_datetimes' ), |
|
604 | + array('EED_Events_Archive', 'event_datetimes'), |
|
605 | 605 | EED_Events_Archive::EVENT_DATETIMES_PRIORITY |
606 | 606 | ); |
607 | 607 | add_filter( |
608 | 608 | 'the_content', |
609 | - array( 'EED_Events_Archive', 'event_tickets' ), |
|
609 | + array('EED_Events_Archive', 'event_tickets'), |
|
610 | 610 | EED_Events_Archive::EVENT_TICKETS_PRIORITY |
611 | 611 | ); |
612 | 612 | add_filter( |
613 | 613 | 'the_content', |
614 | - array( 'EED_Events_Archive', 'event_venues' ), |
|
614 | + array('EED_Events_Archive', 'event_venues'), |
|
615 | 615 | EED_Events_Archive::EVENT_VENUES_PRIORITY |
616 | 616 | ); |
617 | 617 | } |
@@ -627,32 +627,32 @@ discard block |
||
627 | 627 | private static function _remove_additional_events_archive_filters() { |
628 | 628 | remove_filter( |
629 | 629 | 'the_excerpt', |
630 | - array( 'EED_Events_Archive', 'event_datetimes' ), |
|
630 | + array('EED_Events_Archive', 'event_datetimes'), |
|
631 | 631 | EED_Events_Archive::EVENT_DATETIMES_PRIORITY |
632 | 632 | ); |
633 | 633 | remove_filter( |
634 | 634 | 'the_excerpt', |
635 | - array( 'EED_Events_Archive', 'event_tickets' ), |
|
635 | + array('EED_Events_Archive', 'event_tickets'), |
|
636 | 636 | EED_Events_Archive::EVENT_TICKETS_PRIORITY |
637 | 637 | ); |
638 | 638 | remove_filter( |
639 | 639 | 'the_excerpt', |
640 | - array( 'EED_Events_Archive', 'event_venues' ), |
|
640 | + array('EED_Events_Archive', 'event_venues'), |
|
641 | 641 | EED_Events_Archive::EVENT_VENUES_PRIORITY |
642 | 642 | ); |
643 | 643 | remove_filter( |
644 | 644 | 'the_content', |
645 | - array( 'EED_Events_Archive', 'event_datetimes' ), |
|
645 | + array('EED_Events_Archive', 'event_datetimes'), |
|
646 | 646 | EED_Events_Archive::EVENT_DATETIMES_PRIORITY |
647 | 647 | ); |
648 | 648 | remove_filter( |
649 | 649 | 'the_content', |
650 | - array( 'EED_Events_Archive', 'event_tickets' ), |
|
650 | + array('EED_Events_Archive', 'event_tickets'), |
|
651 | 651 | EED_Events_Archive::EVENT_TICKETS_PRIORITY |
652 | 652 | ); |
653 | 653 | remove_filter( |
654 | 654 | 'the_content', |
655 | - array( 'EED_Events_Archive', 'event_venues' ), |
|
655 | + array('EED_Events_Archive', 'event_venues'), |
|
656 | 656 | EED_Events_Archive::EVENT_VENUES_PRIORITY |
657 | 657 | ); |
658 | 658 | } |
@@ -667,45 +667,45 @@ discard block |
||
667 | 667 | */ |
668 | 668 | public static function remove_all_events_archive_filters() { |
669 | 669 | //remove_filter( 'get_the_excerpt', array( 'EED_Events_Archive', 'get_the_excerpt' ), 1 ); |
670 | - remove_filter( 'the_title', array( 'EED_Events_Archive', 'the_title' ), 1 ); |
|
670 | + remove_filter('the_title', array('EED_Events_Archive', 'the_title'), 1); |
|
671 | 671 | remove_filter( |
672 | 672 | 'the_excerpt', |
673 | - array( 'EED_Events_Archive', 'event_details' ), |
|
673 | + array('EED_Events_Archive', 'event_details'), |
|
674 | 674 | EED_Events_Archive::EVENT_DETAILS_PRIORITY |
675 | 675 | ); |
676 | 676 | remove_filter( |
677 | 677 | 'the_excerpt', |
678 | - array( 'EED_Events_Archive', 'event_datetimes' ), |
|
678 | + array('EED_Events_Archive', 'event_datetimes'), |
|
679 | 679 | EED_Events_Archive::EVENT_DATETIMES_PRIORITY |
680 | 680 | ); |
681 | 681 | remove_filter( |
682 | 682 | 'the_excerpt', |
683 | - array( 'EED_Events_Archive', 'event_tickets' ), |
|
683 | + array('EED_Events_Archive', 'event_tickets'), |
|
684 | 684 | EED_Events_Archive::EVENT_TICKETS_PRIORITY |
685 | 685 | ); |
686 | 686 | remove_filter( |
687 | 687 | 'the_excerpt', |
688 | - array( 'EED_Events_Archive', 'event_venues' ), |
|
688 | + array('EED_Events_Archive', 'event_venues'), |
|
689 | 689 | EED_Events_Archive::EVENT_VENUES_PRIORITY |
690 | 690 | ); |
691 | 691 | remove_filter( |
692 | 692 | 'the_content', |
693 | - array( 'EED_Events_Archive', 'event_details' ), |
|
693 | + array('EED_Events_Archive', 'event_details'), |
|
694 | 694 | EED_Events_Archive::EVENT_DETAILS_PRIORITY |
695 | 695 | ); |
696 | 696 | remove_filter( |
697 | 697 | 'the_content', |
698 | - array( 'EED_Events_Archive', 'event_datetimes' ), |
|
698 | + array('EED_Events_Archive', 'event_datetimes'), |
|
699 | 699 | EED_Events_Archive::EVENT_DATETIMES_PRIORITY |
700 | 700 | ); |
701 | 701 | remove_filter( |
702 | 702 | 'the_content', |
703 | - array( 'EED_Events_Archive', 'event_tickets' ), |
|
703 | + array('EED_Events_Archive', 'event_tickets'), |
|
704 | 704 | EED_Events_Archive::EVENT_TICKETS_PRIORITY |
705 | 705 | ); |
706 | 706 | remove_filter( |
707 | 707 | 'the_content', |
708 | - array( 'EED_Events_Archive', 'event_venues' ), |
|
708 | + array('EED_Events_Archive', 'event_venues'), |
|
709 | 709 | EED_Events_Archive::EVENT_VENUES_PRIORITY |
710 | 710 | ); |
711 | 711 | // don't display entry meta because the existing theme will take care of that |
@@ -727,12 +727,12 @@ discard block |
||
727 | 727 | * @return void |
728 | 728 | */ |
729 | 729 | public function load_event_list_assets() { |
730 | - do_action( 'AHEE__EED_Events_Archive__before_load_assets' ); |
|
731 | - add_filter( 'FHEE_load_EE_Session', '__return_true' ); |
|
732 | - add_filter( 'FHEE__EED_Ticket_Selector__load_tckt_slctr_assets', '__return_true' ); |
|
733 | - add_action('wp_enqueue_scripts', array( $this, 'wp_enqueue_scripts' ), 10 ); |
|
734 | - if ( EE_Registry::instance()->CFG->map_settings->use_google_maps ) { |
|
735 | - add_action('wp_enqueue_scripts', array( 'EEH_Maps', 'espresso_google_map_js' ), 11 ); |
|
730 | + do_action('AHEE__EED_Events_Archive__before_load_assets'); |
|
731 | + add_filter('FHEE_load_EE_Session', '__return_true'); |
|
732 | + add_filter('FHEE__EED_Ticket_Selector__load_tckt_slctr_assets', '__return_true'); |
|
733 | + add_action('wp_enqueue_scripts', array($this, 'wp_enqueue_scripts'), 10); |
|
734 | + if (EE_Registry::instance()->CFG->map_settings->use_google_maps) { |
|
735 | + add_action('wp_enqueue_scripts', array('EEH_Maps', 'espresso_google_map_js'), 11); |
|
736 | 736 | } |
737 | 737 | } |
738 | 738 | |
@@ -749,13 +749,13 @@ discard block |
||
749 | 749 | */ |
750 | 750 | public function wp_enqueue_scripts() { |
751 | 751 | // get some style |
752 | - if ( apply_filters( 'FHEE_enable_default_espresso_css', FALSE ) ) { |
|
752 | + if (apply_filters('FHEE_enable_default_espresso_css', FALSE)) { |
|
753 | 753 | // first check uploads folder |
754 | - if ( EEH_File::is_readable( get_stylesheet_directory() . $this->theme . DS . 'style.css' )) { |
|
755 | - wp_register_style( $this->theme, get_stylesheet_directory_uri() . $this->theme . DS . 'style.css', array( 'dashicons', 'espresso_default' )); |
|
754 | + if (EEH_File::is_readable(get_stylesheet_directory().$this->theme.DS.'style.css')) { |
|
755 | + wp_register_style($this->theme, get_stylesheet_directory_uri().$this->theme.DS.'style.css', array('dashicons', 'espresso_default')); |
|
756 | 756 | } else { |
757 | 757 | } |
758 | - wp_enqueue_style( $this->theme ); |
|
758 | + wp_enqueue_style($this->theme); |
|
759 | 759 | |
760 | 760 | } |
761 | 761 | } |
@@ -773,8 +773,8 @@ discard block |
||
773 | 773 | */ |
774 | 774 | public static function template_settings_form() { |
775 | 775 | $template_settings = EE_Registry::instance()->CFG->template_settings; |
776 | - $template_settings->EED_Events_Archive = isset( $template_settings->EED_Events_Archive ) ? $template_settings->EED_Events_Archive : new EE_Events_Archive_Config(); |
|
777 | - $template_settings->EED_Events_Archive = apply_filters( 'FHEE__EED_Events_Archive__template_settings_form__event_list_config', $template_settings->EED_Events_Archive ); |
|
776 | + $template_settings->EED_Events_Archive = isset($template_settings->EED_Events_Archive) ? $template_settings->EED_Events_Archive : new EE_Events_Archive_Config(); |
|
777 | + $template_settings->EED_Events_Archive = apply_filters('FHEE__EED_Events_Archive__template_settings_form__event_list_config', $template_settings->EED_Events_Archive); |
|
778 | 778 | $events_archive_settings = array( |
779 | 779 | 'display_status_banner' => 0, |
780 | 780 | 'display_description' => 1, |
@@ -783,8 +783,8 @@ discard block |
||
783 | 783 | 'display_venue' => 0, |
784 | 784 | 'display_expired_events' => 0 |
785 | 785 | ); |
786 | - $events_archive_settings = array_merge( $events_archive_settings, (array)$template_settings->EED_Events_Archive ); |
|
787 | - EEH_Template::display_template( EVENTS_ARCHIVE_TEMPLATES_PATH . 'admin-event-list-settings.template.php', $events_archive_settings ); |
|
786 | + $events_archive_settings = array_merge($events_archive_settings, (array) $template_settings->EED_Events_Archive); |
|
787 | + EEH_Template::display_template(EVENTS_ARCHIVE_TEMPLATES_PATH.'admin-event-list-settings.template.php', $events_archive_settings); |
|
788 | 788 | } |
789 | 789 | |
790 | 790 | |
@@ -800,16 +800,16 @@ discard block |
||
800 | 800 | * @param EE_Request_Handler $REQ |
801 | 801 | * @return EE_Template_Config |
802 | 802 | */ |
803 | - public static function update_template_settings( $CFG, $REQ ) { |
|
803 | + public static function update_template_settings($CFG, $REQ) { |
|
804 | 804 | $CFG->EED_Events_Archive = new EE_Events_Archive_Config(); |
805 | 805 | // unless we are resetting the config... |
806 | - if ( ! isset( $REQ['EED_Events_Archive_reset_event_list_settings'] ) || absint( $REQ['EED_Events_Archive_reset_event_list_settings'] ) !== 1 ) { |
|
807 | - $CFG->EED_Events_Archive->display_status_banner = isset( $REQ['EED_Events_Archive_display_status_banner'] ) ? absint( $REQ['EED_Events_Archive_display_status_banner'] ) : 0; |
|
808 | - $CFG->EED_Events_Archive->display_description = isset( $REQ['EED_Events_Archive_display_description'] ) ? absint( $REQ['EED_Events_Archive_display_description'] ) : 1; |
|
809 | - $CFG->EED_Events_Archive->display_ticket_selector = isset( $REQ['EED_Events_Archive_display_ticket_selector'] ) ? absint( $REQ['EED_Events_Archive_display_ticket_selector'] ) : 0; |
|
810 | - $CFG->EED_Events_Archive->display_datetimes = isset( $REQ['EED_Events_Archive_display_datetimes'] ) ? absint( $REQ['EED_Events_Archive_display_datetimes'] ) : 1; |
|
811 | - $CFG->EED_Events_Archive->display_venue = isset( $REQ['EED_Events_Archive_display_venue'] ) ? absint( $REQ['EED_Events_Archive_display_venue'] ) : 0; |
|
812 | - $CFG->EED_Events_Archive->display_expired_events = isset( $REQ['EED_Events_Archive_display_expired_events'] ) ? absint( $REQ['EED_Events_Archive_display_expired_events'] ) : 0; } |
|
806 | + if ( ! isset($REQ['EED_Events_Archive_reset_event_list_settings']) || absint($REQ['EED_Events_Archive_reset_event_list_settings']) !== 1) { |
|
807 | + $CFG->EED_Events_Archive->display_status_banner = isset($REQ['EED_Events_Archive_display_status_banner']) ? absint($REQ['EED_Events_Archive_display_status_banner']) : 0; |
|
808 | + $CFG->EED_Events_Archive->display_description = isset($REQ['EED_Events_Archive_display_description']) ? absint($REQ['EED_Events_Archive_display_description']) : 1; |
|
809 | + $CFG->EED_Events_Archive->display_ticket_selector = isset($REQ['EED_Events_Archive_display_ticket_selector']) ? absint($REQ['EED_Events_Archive_display_ticket_selector']) : 0; |
|
810 | + $CFG->EED_Events_Archive->display_datetimes = isset($REQ['EED_Events_Archive_display_datetimes']) ? absint($REQ['EED_Events_Archive_display_datetimes']) : 1; |
|
811 | + $CFG->EED_Events_Archive->display_venue = isset($REQ['EED_Events_Archive_display_venue']) ? absint($REQ['EED_Events_Archive_display_venue']) : 0; |
|
812 | + $CFG->EED_Events_Archive->display_expired_events = isset($REQ['EED_Events_Archive_display_expired_events']) ? absint($REQ['EED_Events_Archive_display_expired_events']) : 0; } |
|
813 | 813 | return $CFG; |
814 | 814 | } |
815 | 815 | |
@@ -822,10 +822,10 @@ discard block |
||
822 | 822 | * @param string $extra_class |
823 | 823 | * @return string |
824 | 824 | */ |
825 | - public static function event_list_css( $extra_class = '' ) { |
|
826 | - $event_list_css = ! empty( $extra_class ) ? array( $extra_class ) : array(); |
|
825 | + public static function event_list_css($extra_class = '') { |
|
826 | + $event_list_css = ! empty($extra_class) ? array($extra_class) : array(); |
|
827 | 827 | $event_list_css[] = 'espresso-event-list-event'; |
828 | - return implode( ' ', $event_list_css ); |
|
828 | + return implode(' ', $event_list_css); |
|
829 | 829 | } |
830 | 830 | |
831 | 831 | |
@@ -852,9 +852,9 @@ discard block |
||
852 | 852 | * @param $value |
853 | 853 | * @return bool |
854 | 854 | */ |
855 | - public static function display_description( $value ) { |
|
855 | + public static function display_description($value) { |
|
856 | 856 | $config = EE_Registry::instance()->CFG->template_settings->EED_Events_Archive; |
857 | - $display_description= isset( $config->display_description ) ? $config->display_description : 1; |
|
857 | + $display_description = isset($config->display_description) ? $config->display_description : 1; |
|
858 | 858 | return $display_description === $value ? TRUE : FALSE; |
859 | 859 | } |
860 | 860 | |
@@ -867,7 +867,7 @@ discard block |
||
867 | 867 | */ |
868 | 868 | public static function display_ticket_selector() { |
869 | 869 | $config = EE_Registry::instance()->CFG->template_settings->EED_Events_Archive; |
870 | - return isset( $config->display_ticket_selector ) && $config->display_ticket_selector ? TRUE : FALSE; |
|
870 | + return isset($config->display_ticket_selector) && $config->display_ticket_selector ? TRUE : FALSE; |
|
871 | 871 | } |
872 | 872 | |
873 | 873 | |
@@ -880,7 +880,7 @@ discard block |
||
880 | 880 | */ |
881 | 881 | public static function display_venue() { |
882 | 882 | $config = EE_Registry::instance()->CFG->template_settings->EED_Events_Archive; |
883 | - return isset( $config->display_venue ) && $config->display_venue && EEH_Venue_View::venue_name() ? TRUE : FALSE; |
|
883 | + return isset($config->display_venue) && $config->display_venue && EEH_Venue_View::venue_name() ? TRUE : FALSE; |
|
884 | 884 | } |
885 | 885 | |
886 | 886 | |
@@ -892,7 +892,7 @@ discard block |
||
892 | 892 | */ |
893 | 893 | public static function display_datetimes() { |
894 | 894 | $config = EE_Registry::instance()->CFG->template_settings->EED_Events_Archive; |
895 | - return isset( $config->display_datetimes ) && $config->display_datetimes ? TRUE : FALSE; |
|
895 | + return isset($config->display_datetimes) && $config->display_datetimes ? TRUE : FALSE; |
|
896 | 896 | } |
897 | 897 | |
898 | 898 | |
@@ -907,7 +907,7 @@ discard block |
||
907 | 907 | * @return string |
908 | 908 | */ |
909 | 909 | public static function event_list_title() { |
910 | - return apply_filters( 'FHEE__archive_espresso_events_template__upcoming_events_h1', __( 'Upcoming Events', 'event_espresso' )); |
|
910 | + return apply_filters('FHEE__archive_espresso_events_template__upcoming_events_h1', __('Upcoming Events', 'event_espresso')); |
|
911 | 911 | } |
912 | 912 | |
913 | 913 | |
@@ -916,11 +916,11 @@ discard block |
||
916 | 916 | /** |
917 | 917 | * @since 4.4.0 |
918 | 918 | */ |
919 | - public static function _doing_it_wrong_notice( $function = '' ) { |
|
919 | + public static function _doing_it_wrong_notice($function = '') { |
|
920 | 920 | EE_Error::doing_it_wrong( |
921 | 921 | __FUNCTION__, |
922 | 922 | sprintf( |
923 | - __( 'EED_Events_Archive::%1$s was moved to EEH_Event_Query::%1$s:%2$sPlease update your existing code because the method it calls will be removed in version %3$s', 'event_espresso' ), |
|
923 | + __('EED_Events_Archive::%1$s was moved to EEH_Event_Query::%1$s:%2$sPlease update your existing code because the method it calls will be removed in version %3$s', 'event_espresso'), |
|
924 | 924 | $function, |
925 | 925 | '<br />', |
926 | 926 | '4.6.0' |
@@ -942,89 +942,89 @@ discard block |
||
942 | 942 | * @deprecated |
943 | 943 | * @since 4.4.0 |
944 | 944 | */ |
945 | - public function posts_fields( $SQL, WP_Query $wp_query ) { |
|
946 | - EED_Events_Archive::_doing_it_wrong_notice( __FUNCTION__ ); |
|
947 | - return EEH_Event_Query::posts_fields( $SQL, $wp_query ); |
|
945 | + public function posts_fields($SQL, WP_Query $wp_query) { |
|
946 | + EED_Events_Archive::_doing_it_wrong_notice(__FUNCTION__); |
|
947 | + return EEH_Event_Query::posts_fields($SQL, $wp_query); |
|
948 | 948 | } |
949 | 949 | /** |
950 | 950 | * @deprecated |
951 | 951 | * @since 4.4.0 |
952 | 952 | */ |
953 | - public static function posts_fields_sql_for_orderby( $orderby_params = array() ) { |
|
954 | - EED_Events_Archive::_doing_it_wrong_notice( __FUNCTION__ ); |
|
955 | - return EEH_Event_Query::posts_fields_sql_for_orderby( $orderby_params ); |
|
953 | + public static function posts_fields_sql_for_orderby($orderby_params = array()) { |
|
954 | + EED_Events_Archive::_doing_it_wrong_notice(__FUNCTION__); |
|
955 | + return EEH_Event_Query::posts_fields_sql_for_orderby($orderby_params); |
|
956 | 956 | } |
957 | 957 | /** |
958 | 958 | * @deprecated |
959 | 959 | * @since 4.4.0 |
960 | 960 | */ |
961 | - public function posts_join( $SQL, WP_Query $wp_query ) { |
|
962 | - EED_Events_Archive::_doing_it_wrong_notice( __FUNCTION__ ); |
|
963 | - return EEH_Event_Query::posts_join( $SQL, $wp_query ); |
|
961 | + public function posts_join($SQL, WP_Query $wp_query) { |
|
962 | + EED_Events_Archive::_doing_it_wrong_notice(__FUNCTION__); |
|
963 | + return EEH_Event_Query::posts_join($SQL, $wp_query); |
|
964 | 964 | } |
965 | 965 | /** |
966 | 966 | * @deprecated |
967 | 967 | * @since 4.4.0 |
968 | 968 | */ |
969 | - public static function posts_join_sql_for_terms( $join_terms = NULL ) { |
|
970 | - EED_Events_Archive::_doing_it_wrong_notice( __FUNCTION__ ); |
|
971 | - return EEH_Event_Query::posts_join_sql_for_terms( $join_terms ); |
|
969 | + public static function posts_join_sql_for_terms($join_terms = NULL) { |
|
970 | + EED_Events_Archive::_doing_it_wrong_notice(__FUNCTION__); |
|
971 | + return EEH_Event_Query::posts_join_sql_for_terms($join_terms); |
|
972 | 972 | } |
973 | 973 | /** |
974 | 974 | * @deprecated |
975 | 975 | * @since 4.4.0 |
976 | 976 | */ |
977 | - public static function posts_join_for_orderby( $orderby_params = array() ) { |
|
978 | - EED_Events_Archive::_doing_it_wrong_notice( __FUNCTION__ ); |
|
979 | - return EEH_Event_Query::posts_join_for_orderby( $orderby_params ); |
|
977 | + public static function posts_join_for_orderby($orderby_params = array()) { |
|
978 | + EED_Events_Archive::_doing_it_wrong_notice(__FUNCTION__); |
|
979 | + return EEH_Event_Query::posts_join_for_orderby($orderby_params); |
|
980 | 980 | } |
981 | 981 | /** |
982 | 982 | * @deprecated |
983 | 983 | * @since 4.4.0 |
984 | 984 | */ |
985 | - public function posts_where( $SQL, WP_Query $wp_query ) { |
|
986 | - EED_Events_Archive::_doing_it_wrong_notice( __FUNCTION__ ); |
|
987 | - return EEH_Event_Query::posts_where( $SQL, $wp_query ); |
|
985 | + public function posts_where($SQL, WP_Query $wp_query) { |
|
986 | + EED_Events_Archive::_doing_it_wrong_notice(__FUNCTION__); |
|
987 | + return EEH_Event_Query::posts_where($SQL, $wp_query); |
|
988 | 988 | } |
989 | 989 | /** |
990 | 990 | * @deprecated |
991 | 991 | * @since 4.4.0 |
992 | 992 | */ |
993 | - public static function posts_where_sql_for_show_expired( $show_expired = FALSE ) { |
|
994 | - EED_Events_Archive::_doing_it_wrong_notice( __FUNCTION__ ); |
|
995 | - return EEH_Event_Query::posts_where_sql_for_show_expired( $show_expired ); |
|
993 | + public static function posts_where_sql_for_show_expired($show_expired = FALSE) { |
|
994 | + EED_Events_Archive::_doing_it_wrong_notice(__FUNCTION__); |
|
995 | + return EEH_Event_Query::posts_where_sql_for_show_expired($show_expired); |
|
996 | 996 | } |
997 | 997 | /** |
998 | 998 | * @deprecated |
999 | 999 | * @since 4.4.0 |
1000 | 1000 | */ |
1001 | - public static function posts_where_sql_for_event_category_slug( $event_category_slug = NULL ) { |
|
1002 | - EED_Events_Archive::_doing_it_wrong_notice( __FUNCTION__ ); |
|
1003 | - return EEH_Event_Query::posts_where_sql_for_event_category_slug( $event_category_slug ); |
|
1001 | + public static function posts_where_sql_for_event_category_slug($event_category_slug = NULL) { |
|
1002 | + EED_Events_Archive::_doing_it_wrong_notice(__FUNCTION__); |
|
1003 | + return EEH_Event_Query::posts_where_sql_for_event_category_slug($event_category_slug); |
|
1004 | 1004 | } |
1005 | 1005 | /** |
1006 | 1006 | * @deprecated |
1007 | 1007 | * @since 4.4.0 |
1008 | 1008 | */ |
1009 | - public static function posts_where_sql_for_event_list_month( $month = NULL ) { |
|
1010 | - EED_Events_Archive::_doing_it_wrong_notice( __FUNCTION__ ); |
|
1011 | - return EEH_Event_Query::posts_where_sql_for_event_list_month( $month ); |
|
1009 | + public static function posts_where_sql_for_event_list_month($month = NULL) { |
|
1010 | + EED_Events_Archive::_doing_it_wrong_notice(__FUNCTION__); |
|
1011 | + return EEH_Event_Query::posts_where_sql_for_event_list_month($month); |
|
1012 | 1012 | } |
1013 | 1013 | /** |
1014 | 1014 | * @deprecated |
1015 | 1015 | * @since 4.4.0 |
1016 | 1016 | */ |
1017 | - public function posts_orderby( $SQL, WP_Query $wp_query ) { |
|
1018 | - EED_Events_Archive::_doing_it_wrong_notice( __FUNCTION__ ); |
|
1019 | - return EEH_Event_Query::posts_orderby( $SQL, $wp_query ); |
|
1017 | + public function posts_orderby($SQL, WP_Query $wp_query) { |
|
1018 | + EED_Events_Archive::_doing_it_wrong_notice(__FUNCTION__); |
|
1019 | + return EEH_Event_Query::posts_orderby($SQL, $wp_query); |
|
1020 | 1020 | } |
1021 | 1021 | /** |
1022 | 1022 | * @deprecated |
1023 | 1023 | * @since 4.4.0 |
1024 | 1024 | */ |
1025 | - public static function posts_orderby_sql( $orderby_params = array(), $sort = 'ASC' ) { |
|
1026 | - EED_Events_Archive::_doing_it_wrong_notice( __FUNCTION__ ); |
|
1027 | - return EEH_Event_Query::posts_orderby_sql( $orderby_params, $sort ); |
|
1025 | + public static function posts_orderby_sql($orderby_params = array(), $sort = 'ASC') { |
|
1026 | + EED_Events_Archive::_doing_it_wrong_notice(__FUNCTION__); |
|
1027 | + return EEH_Event_Query::posts_orderby_sql($orderby_params, $sort); |
|
1028 | 1028 | } |
1029 | 1029 | |
1030 | 1030 | |
@@ -1055,8 +1055,8 @@ discard block |
||
1055 | 1055 | * @param string $extra_class |
1056 | 1056 | * @return string |
1057 | 1057 | */ |
1058 | -function espresso_event_list_css( $extra_class = '' ) { |
|
1059 | - return EED_Events_Archive::event_list_css( $extra_class ); |
|
1058 | +function espresso_event_list_css($extra_class = '') { |
|
1059 | + return EED_Events_Archive::event_list_css($extra_class); |
|
1060 | 1060 | } |
1061 | 1061 | |
1062 | 1062 | /** |
@@ -1070,14 +1070,14 @@ discard block |
||
1070 | 1070 | * @return bool |
1071 | 1071 | */ |
1072 | 1072 | function espresso_display_full_description_in_event_list() { |
1073 | - return EED_Events_Archive::display_description( 2 ); |
|
1073 | + return EED_Events_Archive::display_description(2); |
|
1074 | 1074 | } |
1075 | 1075 | |
1076 | 1076 | /** |
1077 | 1077 | * @return bool |
1078 | 1078 | */ |
1079 | 1079 | function espresso_display_excerpt_in_event_list() { |
1080 | - return EED_Events_Archive::display_description( 1 ); |
|
1080 | + return EED_Events_Archive::display_description(1); |
|
1081 | 1081 | } |
1082 | 1082 | |
1083 | 1083 | /** |
@@ -4,7 +4,7 @@ discard block |
||
4 | 4 | use EventEspresso\core\libraries\iframe_display\Iframe; |
5 | 5 | |
6 | 6 | if ( ! defined( 'EVENT_ESPRESSO_VERSION' ) ) { |
7 | - exit( 'No direct script access allowed' ); |
|
7 | + exit( 'No direct script access allowed' ); |
|
8 | 8 | } |
9 | 9 | |
10 | 10 | |
@@ -21,57 +21,57 @@ discard block |
||
21 | 21 | |
22 | 22 | |
23 | 23 | |
24 | - /** |
|
25 | - * EventsArchiveIframe constructor. |
|
26 | - * |
|
27 | - * @param \EED_Events_Archive $EED_Events_Archive |
|
28 | - * @throws \DomainException |
|
29 | - */ |
|
30 | - public function __construct( $EED_Events_Archive ) |
|
31 | - { |
|
32 | - \EE_Registry::instance()->REQ->set_espresso_page( true ); |
|
33 | - add_filter('FHEE__EED_Events_Archive__event_list_iframe', '__return_true'); |
|
34 | - $EED_Events_Archive->event_list(); |
|
35 | - /** @var \EventEspresso\core\domain\entities\shortcodes\EspressoEvents $event_list */ |
|
36 | - $event_list = \EE_Registry::instance()->create('EventEspresso\core\domain\entities\shortcodes\EspressoEvents'); |
|
37 | - parent::__construct( |
|
38 | - esc_html__( 'Event List', 'event_espresso' ), |
|
39 | - $event_list->processShortcode() |
|
40 | - ); |
|
41 | - $this->addStylesheets( |
|
42 | - apply_filters( |
|
43 | - 'FHEE__EventEspresso_modules_events_archive_EventsArchiveIframe__display__css', |
|
44 | - array( |
|
45 | - 'espresso_default' => is_readable( EVENT_ESPRESSO_UPLOAD_DIR . 'css/style.css' ) |
|
46 | - ? EVENT_ESPRESSO_UPLOAD_DIR . 'css/espresso_default.css?ver=' . EVENT_ESPRESSO_VERSION |
|
47 | - : EE_GLOBAL_ASSETS_URL . 'css/espresso_default.css?ver=' . EVENT_ESPRESSO_VERSION, |
|
48 | - ), |
|
49 | - $this |
|
50 | - ) |
|
51 | - ); |
|
52 | - $this->addScripts( |
|
53 | - apply_filters( |
|
54 | - 'FHEE__EventEspresso_modules_events_archive_EventsArchiveIframe__display__js', |
|
55 | - array( |
|
56 | - 'gmap_api' => sprintf( |
|
57 | - 'https://maps.googleapis.com/maps/api/js?key=%s', |
|
58 | - apply_filters( |
|
59 | - 'FHEE__EEH_Maps__espresso_google_maps_js__api_key', |
|
60 | - \EE_Registry::instance()->CFG->map_settings->google_map_api_key |
|
61 | - ) |
|
62 | - ), |
|
63 | - 'ee_gmap' => EE_HELPERS_ASSETS . 'ee_gmap.js?ver=1.0', |
|
64 | - ), |
|
65 | - $this |
|
66 | - ) |
|
67 | - ); |
|
68 | - $this->addLocalizedVars( |
|
69 | - array( |
|
70 | - 'ee_gmap' => \EEH_Maps::$gmap_vars, |
|
71 | - ), |
|
72 | - 'ee_gmap_vars' |
|
73 | - ); |
|
74 | - } |
|
24 | + /** |
|
25 | + * EventsArchiveIframe constructor. |
|
26 | + * |
|
27 | + * @param \EED_Events_Archive $EED_Events_Archive |
|
28 | + * @throws \DomainException |
|
29 | + */ |
|
30 | + public function __construct( $EED_Events_Archive ) |
|
31 | + { |
|
32 | + \EE_Registry::instance()->REQ->set_espresso_page( true ); |
|
33 | + add_filter('FHEE__EED_Events_Archive__event_list_iframe', '__return_true'); |
|
34 | + $EED_Events_Archive->event_list(); |
|
35 | + /** @var \EventEspresso\core\domain\entities\shortcodes\EspressoEvents $event_list */ |
|
36 | + $event_list = \EE_Registry::instance()->create('EventEspresso\core\domain\entities\shortcodes\EspressoEvents'); |
|
37 | + parent::__construct( |
|
38 | + esc_html__( 'Event List', 'event_espresso' ), |
|
39 | + $event_list->processShortcode() |
|
40 | + ); |
|
41 | + $this->addStylesheets( |
|
42 | + apply_filters( |
|
43 | + 'FHEE__EventEspresso_modules_events_archive_EventsArchiveIframe__display__css', |
|
44 | + array( |
|
45 | + 'espresso_default' => is_readable( EVENT_ESPRESSO_UPLOAD_DIR . 'css/style.css' ) |
|
46 | + ? EVENT_ESPRESSO_UPLOAD_DIR . 'css/espresso_default.css?ver=' . EVENT_ESPRESSO_VERSION |
|
47 | + : EE_GLOBAL_ASSETS_URL . 'css/espresso_default.css?ver=' . EVENT_ESPRESSO_VERSION, |
|
48 | + ), |
|
49 | + $this |
|
50 | + ) |
|
51 | + ); |
|
52 | + $this->addScripts( |
|
53 | + apply_filters( |
|
54 | + 'FHEE__EventEspresso_modules_events_archive_EventsArchiveIframe__display__js', |
|
55 | + array( |
|
56 | + 'gmap_api' => sprintf( |
|
57 | + 'https://maps.googleapis.com/maps/api/js?key=%s', |
|
58 | + apply_filters( |
|
59 | + 'FHEE__EEH_Maps__espresso_google_maps_js__api_key', |
|
60 | + \EE_Registry::instance()->CFG->map_settings->google_map_api_key |
|
61 | + ) |
|
62 | + ), |
|
63 | + 'ee_gmap' => EE_HELPERS_ASSETS . 'ee_gmap.js?ver=1.0', |
|
64 | + ), |
|
65 | + $this |
|
66 | + ) |
|
67 | + ); |
|
68 | + $this->addLocalizedVars( |
|
69 | + array( |
|
70 | + 'ee_gmap' => \EEH_Maps::$gmap_vars, |
|
71 | + ), |
|
72 | + 'ee_gmap_vars' |
|
73 | + ); |
|
74 | + } |
|
75 | 75 | |
76 | 76 | |
77 | 77 |
@@ -3,8 +3,8 @@ discard block |
||
3 | 3 | |
4 | 4 | use EventEspresso\core\libraries\iframe_display\Iframe; |
5 | 5 | |
6 | -if ( ! defined( 'EVENT_ESPRESSO_VERSION' ) ) { |
|
7 | - exit( 'No direct script access allowed' ); |
|
6 | +if ( ! defined('EVENT_ESPRESSO_VERSION')) { |
|
7 | + exit('No direct script access allowed'); |
|
8 | 8 | } |
9 | 9 | |
10 | 10 | |
@@ -27,24 +27,24 @@ discard block |
||
27 | 27 | * @param \EED_Events_Archive $EED_Events_Archive |
28 | 28 | * @throws \DomainException |
29 | 29 | */ |
30 | - public function __construct( $EED_Events_Archive ) |
|
30 | + public function __construct($EED_Events_Archive) |
|
31 | 31 | { |
32 | - \EE_Registry::instance()->REQ->set_espresso_page( true ); |
|
32 | + \EE_Registry::instance()->REQ->set_espresso_page(true); |
|
33 | 33 | add_filter('FHEE__EED_Events_Archive__event_list_iframe', '__return_true'); |
34 | 34 | $EED_Events_Archive->event_list(); |
35 | 35 | /** @var \EventEspresso\core\domain\entities\shortcodes\EspressoEvents $event_list */ |
36 | 36 | $event_list = \EE_Registry::instance()->create('EventEspresso\core\domain\entities\shortcodes\EspressoEvents'); |
37 | 37 | parent::__construct( |
38 | - esc_html__( 'Event List', 'event_espresso' ), |
|
38 | + esc_html__('Event List', 'event_espresso'), |
|
39 | 39 | $event_list->processShortcode() |
40 | 40 | ); |
41 | 41 | $this->addStylesheets( |
42 | 42 | apply_filters( |
43 | 43 | 'FHEE__EventEspresso_modules_events_archive_EventsArchiveIframe__display__css', |
44 | 44 | array( |
45 | - 'espresso_default' => is_readable( EVENT_ESPRESSO_UPLOAD_DIR . 'css/style.css' ) |
|
46 | - ? EVENT_ESPRESSO_UPLOAD_DIR . 'css/espresso_default.css?ver=' . EVENT_ESPRESSO_VERSION |
|
47 | - : EE_GLOBAL_ASSETS_URL . 'css/espresso_default.css?ver=' . EVENT_ESPRESSO_VERSION, |
|
45 | + 'espresso_default' => is_readable(EVENT_ESPRESSO_UPLOAD_DIR.'css/style.css') |
|
46 | + ? EVENT_ESPRESSO_UPLOAD_DIR.'css/espresso_default.css?ver='.EVENT_ESPRESSO_VERSION |
|
47 | + : EE_GLOBAL_ASSETS_URL.'css/espresso_default.css?ver='.EVENT_ESPRESSO_VERSION, |
|
48 | 48 | ), |
49 | 49 | $this |
50 | 50 | ) |
@@ -60,7 +60,7 @@ discard block |
||
60 | 60 | \EE_Registry::instance()->CFG->map_settings->google_map_api_key |
61 | 61 | ) |
62 | 62 | ), |
63 | - 'ee_gmap' => EE_HELPERS_ASSETS . 'ee_gmap.js?ver=1.0', |
|
63 | + 'ee_gmap' => EE_HELPERS_ASSETS.'ee_gmap.js?ver=1.0', |
|
64 | 64 | ), |
65 | 65 | $this |
66 | 66 | ) |
@@ -16,1374 +16,1374 @@ |
||
16 | 16 | class EE_Registry |
17 | 17 | { |
18 | 18 | |
19 | - /** |
|
20 | - * EE_Registry Object |
|
21 | - * |
|
22 | - * @var EE_Registry $_instance |
|
23 | - * @access private |
|
24 | - */ |
|
25 | - private static $_instance = null; |
|
26 | - |
|
27 | - /** |
|
28 | - * @var EE_Dependency_Map $_dependency_map |
|
29 | - * @access protected |
|
30 | - */ |
|
31 | - protected $_dependency_map = null; |
|
32 | - |
|
33 | - /** |
|
34 | - * @var array $_class_abbreviations |
|
35 | - * @access protected |
|
36 | - */ |
|
37 | - protected $_class_abbreviations = array(); |
|
38 | - |
|
39 | - /** |
|
40 | - * @access public |
|
41 | - * @var \EventEspresso\core\services\commands\CommandBusInterface $BUS |
|
42 | - */ |
|
43 | - public $BUS; |
|
44 | - |
|
45 | - /** |
|
46 | - * EE_Cart Object |
|
47 | - * |
|
48 | - * @access public |
|
49 | - * @var EE_Cart $CART |
|
50 | - */ |
|
51 | - public $CART = null; |
|
52 | - |
|
53 | - /** |
|
54 | - * EE_Config Object |
|
55 | - * |
|
56 | - * @access public |
|
57 | - * @var EE_Config $CFG |
|
58 | - */ |
|
59 | - public $CFG = null; |
|
60 | - |
|
61 | - /** |
|
62 | - * EE_Network_Config Object |
|
63 | - * |
|
64 | - * @access public |
|
65 | - * @var EE_Network_Config $NET_CFG |
|
66 | - */ |
|
67 | - public $NET_CFG = null; |
|
68 | - |
|
69 | - /** |
|
70 | - * StdClass object for storing library classes in |
|
71 | - * |
|
72 | - * @public LIB |
|
73 | - * @var StdClass $LIB |
|
74 | - */ |
|
75 | - public $LIB = null; |
|
76 | - |
|
77 | - /** |
|
78 | - * EE_Request_Handler Object |
|
79 | - * |
|
80 | - * @access public |
|
81 | - * @var EE_Request_Handler $REQ |
|
82 | - */ |
|
83 | - public $REQ = null; |
|
84 | - |
|
85 | - /** |
|
86 | - * EE_Session Object |
|
87 | - * |
|
88 | - * @access public |
|
89 | - * @var EE_Session $SSN |
|
90 | - */ |
|
91 | - public $SSN = null; |
|
92 | - |
|
93 | - /** |
|
94 | - * holds the ee capabilities object. |
|
95 | - * |
|
96 | - * @since 4.5.0 |
|
97 | - * @var EE_Capabilities |
|
98 | - */ |
|
99 | - public $CAP = null; |
|
100 | - |
|
101 | - /** |
|
102 | - * holds the EE_Message_Resource_Manager object. |
|
103 | - * |
|
104 | - * @since 4.9.0 |
|
105 | - * @var EE_Message_Resource_Manager |
|
106 | - */ |
|
107 | - public $MRM = null; |
|
108 | - |
|
109 | - |
|
110 | - /** |
|
111 | - * Holds the Assets Registry instance |
|
112 | - * @var Registry |
|
113 | - */ |
|
114 | - public $AssetsRegistry = null; |
|
115 | - |
|
116 | - /** |
|
117 | - * $addons - StdClass object for holding addons which have registered themselves to work with EE core |
|
118 | - * |
|
119 | - * @access public |
|
120 | - * @var EE_Addon[] |
|
121 | - */ |
|
122 | - public $addons = null; |
|
123 | - |
|
124 | - /** |
|
125 | - * $models |
|
126 | - * @access public |
|
127 | - * @var EEM_Base[] $models keys are 'short names' (eg Event), values are class names (eg 'EEM_Event') |
|
128 | - */ |
|
129 | - public $models = array(); |
|
130 | - |
|
131 | - /** |
|
132 | - * $modules |
|
133 | - * @access public |
|
134 | - * @var EED_Module[] $modules |
|
135 | - */ |
|
136 | - public $modules = null; |
|
137 | - |
|
138 | - /** |
|
139 | - * $shortcodes |
|
140 | - * @access public |
|
141 | - * @var EES_Shortcode[] $shortcodes |
|
142 | - */ |
|
143 | - public $shortcodes = null; |
|
144 | - |
|
145 | - /** |
|
146 | - * $widgets |
|
147 | - * @access public |
|
148 | - * @var WP_Widget[] $widgets |
|
149 | - */ |
|
150 | - public $widgets = null; |
|
151 | - |
|
152 | - /** |
|
153 | - * $non_abstract_db_models |
|
154 | - * @access public |
|
155 | - * @var array this is an array of all implemented model names (i.e. not the parent abstract models, or models |
|
156 | - * which don't actually fetch items from the DB in the normal way (ie, are not children of EEM_Base)). |
|
157 | - * Keys are model "short names" (eg "Event") as used in model relations, and values are |
|
158 | - * classnames (eg "EEM_Event") |
|
159 | - */ |
|
160 | - public $non_abstract_db_models = array(); |
|
161 | - |
|
162 | - |
|
163 | - /** |
|
164 | - * $i18n_js_strings - internationalization for JS strings |
|
165 | - * usage: EE_Registry::i18n_js_strings['string_key'] = __( 'string to translate.', 'event_espresso' ); |
|
166 | - * in js file: var translatedString = eei18n.string_key; |
|
167 | - * |
|
168 | - * @access public |
|
169 | - * @var array |
|
170 | - */ |
|
171 | - public static $i18n_js_strings = array(); |
|
172 | - |
|
173 | - |
|
174 | - /** |
|
175 | - * $main_file - path to espresso.php |
|
176 | - * |
|
177 | - * @access public |
|
178 | - * @var array |
|
179 | - */ |
|
180 | - public $main_file; |
|
181 | - |
|
182 | - /** |
|
183 | - * array of ReflectionClass objects where the key is the class name |
|
184 | - * |
|
185 | - * @access public |
|
186 | - * @var ReflectionClass[] |
|
187 | - */ |
|
188 | - public $_reflectors; |
|
189 | - |
|
190 | - /** |
|
191 | - * boolean flag to indicate whether or not to load/save dependencies from/to the cache |
|
192 | - * |
|
193 | - * @access protected |
|
194 | - * @var boolean $_cache_on |
|
195 | - */ |
|
196 | - protected $_cache_on = true; |
|
197 | - |
|
198 | - |
|
199 | - |
|
200 | - /** |
|
201 | - * @singleton method used to instantiate class object |
|
202 | - * @access public |
|
203 | - * @param \EE_Dependency_Map $dependency_map |
|
204 | - * @return \EE_Registry instance |
|
205 | - */ |
|
206 | - public static function instance(\EE_Dependency_Map $dependency_map = null) |
|
207 | - { |
|
208 | - // check if class object is instantiated |
|
209 | - if ( ! self::$_instance instanceof EE_Registry) { |
|
210 | - self::$_instance = new EE_Registry($dependency_map); |
|
211 | - } |
|
212 | - return self::$_instance; |
|
213 | - } |
|
214 | - |
|
215 | - |
|
216 | - |
|
217 | - /** |
|
218 | - *protected constructor to prevent direct creation |
|
219 | - * |
|
220 | - * @Constructor |
|
221 | - * @access protected |
|
222 | - * @param \EE_Dependency_Map $dependency_map |
|
223 | - * @return \EE_Registry |
|
224 | - */ |
|
225 | - protected function __construct(\EE_Dependency_Map $dependency_map) |
|
226 | - { |
|
227 | - $this->_dependency_map = $dependency_map; |
|
228 | - add_action('EE_Load_Espresso_Core__handle_request__initialize_core_loading', array($this, 'initialize')); |
|
229 | - } |
|
230 | - |
|
231 | - |
|
232 | - |
|
233 | - /** |
|
234 | - * initialize |
|
235 | - */ |
|
236 | - public function initialize() |
|
237 | - { |
|
238 | - $this->_class_abbreviations = apply_filters( |
|
239 | - 'FHEE__EE_Registry____construct___class_abbreviations', |
|
240 | - array( |
|
241 | - 'EE_Config' => 'CFG', |
|
242 | - 'EE_Session' => 'SSN', |
|
243 | - 'EE_Capabilities' => 'CAP', |
|
244 | - 'EE_Cart' => 'CART', |
|
245 | - 'EE_Network_Config' => 'NET_CFG', |
|
246 | - 'EE_Request_Handler' => 'REQ', |
|
247 | - 'EE_Message_Resource_Manager' => 'MRM', |
|
248 | - 'EventEspresso\core\services\commands\CommandBus' => 'BUS', |
|
249 | - ) |
|
250 | - ); |
|
251 | - // class library |
|
252 | - $this->LIB = new stdClass(); |
|
253 | - $this->addons = new stdClass(); |
|
254 | - $this->modules = new stdClass(); |
|
255 | - $this->shortcodes = new stdClass(); |
|
256 | - $this->widgets = new stdClass(); |
|
257 | - $this->load_core('Base', array(), true); |
|
258 | - // add our request and response objects to the cache |
|
259 | - $request_loader = $this->_dependency_map->class_loader('EE_Request'); |
|
260 | - $this->_set_cached_class( |
|
261 | - $request_loader(), |
|
262 | - 'EE_Request' |
|
263 | - ); |
|
264 | - $response_loader = $this->_dependency_map->class_loader('EE_Response'); |
|
265 | - $this->_set_cached_class( |
|
266 | - $response_loader(), |
|
267 | - 'EE_Response' |
|
268 | - ); |
|
269 | - add_action('AHEE__EE_System__set_hooks_for_core', array($this, 'init')); |
|
270 | - } |
|
271 | - |
|
272 | - |
|
273 | - |
|
274 | - /** |
|
275 | - * init |
|
276 | - * |
|
277 | - * @access public |
|
278 | - * @return void |
|
279 | - */ |
|
280 | - public function init() |
|
281 | - { |
|
282 | - $this->AssetsRegistry = new Registry(); |
|
283 | - // Get current page protocol |
|
284 | - $protocol = isset($_SERVER['HTTPS']) ? 'https://' : 'http://'; |
|
285 | - // Output admin-ajax.php URL with same protocol as current page |
|
286 | - self::$i18n_js_strings['ajax_url'] = admin_url('admin-ajax.php', $protocol); |
|
287 | - self::$i18n_js_strings['wp_debug'] = defined('WP_DEBUG') ? WP_DEBUG : false; |
|
288 | - } |
|
289 | - |
|
290 | - |
|
291 | - |
|
292 | - /** |
|
293 | - * localize_i18n_js_strings |
|
294 | - * |
|
295 | - * @return string |
|
296 | - */ |
|
297 | - public static function localize_i18n_js_strings() |
|
298 | - { |
|
299 | - $i18n_js_strings = (array)EE_Registry::$i18n_js_strings; |
|
300 | - foreach ($i18n_js_strings as $key => $value) { |
|
301 | - if (is_scalar($value)) { |
|
302 | - $i18n_js_strings[$key] = html_entity_decode((string)$value, ENT_QUOTES, 'UTF-8'); |
|
303 | - } |
|
304 | - } |
|
305 | - return "/* <![CDATA[ */ var eei18n = " . wp_json_encode($i18n_js_strings) . '; /* ]]> */'; |
|
306 | - } |
|
307 | - |
|
308 | - |
|
309 | - |
|
310 | - /** |
|
311 | - * @param mixed string | EED_Module $module |
|
312 | - */ |
|
313 | - public function add_module($module) |
|
314 | - { |
|
315 | - if ($module instanceof EED_Module) { |
|
316 | - $module_class = get_class($module); |
|
317 | - $this->modules->{$module_class} = $module; |
|
318 | - } else { |
|
319 | - if ( ! class_exists('EE_Module_Request_Router')) { |
|
320 | - $this->load_core('Module_Request_Router'); |
|
321 | - } |
|
322 | - $this->modules->{$module} = EE_Module_Request_Router::module_factory($module); |
|
323 | - } |
|
324 | - } |
|
325 | - |
|
326 | - |
|
327 | - |
|
328 | - /** |
|
329 | - * @param string $module_name |
|
330 | - * @return mixed EED_Module | NULL |
|
331 | - */ |
|
332 | - public function get_module($module_name = '') |
|
333 | - { |
|
334 | - return isset($this->modules->{$module_name}) ? $this->modules->{$module_name} : null; |
|
335 | - } |
|
336 | - |
|
337 | - |
|
338 | - |
|
339 | - /** |
|
340 | - * loads core classes - must be singletons |
|
341 | - * |
|
342 | - * @access public |
|
343 | - * @param string $class_name - simple class name ie: session |
|
344 | - * @param mixed $arguments |
|
345 | - * @param bool $load_only |
|
346 | - * @return mixed |
|
347 | - */ |
|
348 | - public function load_core($class_name, $arguments = array(), $load_only = false) |
|
349 | - { |
|
350 | - $core_paths = apply_filters( |
|
351 | - 'FHEE__EE_Registry__load_core__core_paths', |
|
352 | - array( |
|
353 | - EE_CORE, |
|
354 | - EE_ADMIN, |
|
355 | - EE_CPTS, |
|
356 | - EE_CORE . 'data_migration_scripts' . DS, |
|
357 | - EE_CORE . 'request_stack' . DS, |
|
358 | - EE_CORE . 'middleware' . DS, |
|
359 | - ) |
|
360 | - ); |
|
361 | - // retrieve instantiated class |
|
362 | - return $this->_load($core_paths, 'EE_', $class_name, 'core', $arguments, false, true, $load_only); |
|
363 | - } |
|
364 | - |
|
365 | - |
|
366 | - |
|
367 | - /** |
|
368 | - * loads service classes |
|
369 | - * |
|
370 | - * @access public |
|
371 | - * @param string $class_name - simple class name ie: session |
|
372 | - * @param mixed $arguments |
|
373 | - * @param bool $load_only |
|
374 | - * @return mixed |
|
375 | - */ |
|
376 | - public function load_service($class_name, $arguments = array(), $load_only = false) |
|
377 | - { |
|
378 | - $service_paths = apply_filters( |
|
379 | - 'FHEE__EE_Registry__load_service__service_paths', |
|
380 | - array( |
|
381 | - EE_CORE . 'services' . DS, |
|
382 | - ) |
|
383 | - ); |
|
384 | - // retrieve instantiated class |
|
385 | - return $this->_load($service_paths, 'EE_', $class_name, 'class', $arguments, false, true, $load_only); |
|
386 | - } |
|
387 | - |
|
388 | - |
|
389 | - |
|
390 | - /** |
|
391 | - * loads data_migration_scripts |
|
392 | - * |
|
393 | - * @access public |
|
394 | - * @param string $class_name - class name for the DMS ie: EE_DMS_Core_4_2_0 |
|
395 | - * @param mixed $arguments |
|
396 | - * @return EE_Data_Migration_Script_Base|mixed |
|
397 | - */ |
|
398 | - public function load_dms($class_name, $arguments = array()) |
|
399 | - { |
|
400 | - // retrieve instantiated class |
|
401 | - return $this->_load(EE_Data_Migration_Manager::instance()->get_data_migration_script_folders(), 'EE_DMS_', $class_name, 'dms', $arguments, false, false, false); |
|
402 | - } |
|
403 | - |
|
404 | - |
|
405 | - |
|
406 | - /** |
|
407 | - * loads object creating classes - must be singletons |
|
408 | - * |
|
409 | - * @param string $class_name - simple class name ie: attendee |
|
410 | - * @param mixed $arguments - an array of arguments to pass to the class |
|
411 | - * @param bool $from_db - some classes are instantiated from the db and thus call a different method to instantiate |
|
412 | - * @param bool $cache if you don't want the class to be stored in the internal cache (non-persistent) then set this to FALSE (ie. when instantiating model objects from client in a loop) |
|
413 | - * @param bool $load_only whether or not to just load the file and NOT instantiate, or load AND instantiate (default) |
|
414 | - * @return EE_Base_Class | bool |
|
415 | - */ |
|
416 | - public function load_class($class_name, $arguments = array(), $from_db = false, $cache = true, $load_only = false) |
|
417 | - { |
|
418 | - $paths = apply_filters('FHEE__EE_Registry__load_class__paths', array( |
|
419 | - EE_CORE, |
|
420 | - EE_CLASSES, |
|
421 | - EE_BUSINESS, |
|
422 | - )); |
|
423 | - // retrieve instantiated class |
|
424 | - return $this->_load($paths, 'EE_', $class_name, 'class', $arguments, $from_db, $cache, $load_only); |
|
425 | - } |
|
426 | - |
|
427 | - |
|
428 | - |
|
429 | - /** |
|
430 | - * loads helper classes - must be singletons |
|
431 | - * |
|
432 | - * @param string $class_name - simple class name ie: price |
|
433 | - * @param mixed $arguments |
|
434 | - * @param bool $load_only |
|
435 | - * @return EEH_Base | bool |
|
436 | - */ |
|
437 | - public function load_helper($class_name, $arguments = array(), $load_only = true) |
|
438 | - { |
|
439 | - // todo: add doing_it_wrong() in a few versions after all addons have had calls to this method removed |
|
440 | - $helper_paths = apply_filters('FHEE__EE_Registry__load_helper__helper_paths', array(EE_HELPERS)); |
|
441 | - // retrieve instantiated class |
|
442 | - return $this->_load($helper_paths, 'EEH_', $class_name, 'helper', $arguments, false, true, $load_only); |
|
443 | - } |
|
444 | - |
|
445 | - |
|
446 | - |
|
447 | - /** |
|
448 | - * loads core classes - must be singletons |
|
449 | - * |
|
450 | - * @access public |
|
451 | - * @param string $class_name - simple class name ie: session |
|
452 | - * @param mixed $arguments |
|
453 | - * @param bool $load_only |
|
454 | - * @param bool $cache whether to cache the object or not. |
|
455 | - * @return mixed |
|
456 | - */ |
|
457 | - public function load_lib($class_name, $arguments = array(), $load_only = false, $cache = true) |
|
458 | - { |
|
459 | - $paths = array( |
|
460 | - EE_LIBRARIES, |
|
461 | - EE_LIBRARIES . 'messages' . DS, |
|
462 | - EE_LIBRARIES . 'shortcodes' . DS, |
|
463 | - EE_LIBRARIES . 'qtips' . DS, |
|
464 | - EE_LIBRARIES . 'payment_methods' . DS, |
|
465 | - ); |
|
466 | - // retrieve instantiated class |
|
467 | - return $this->_load($paths, 'EE_', $class_name, 'lib', $arguments, false, $cache, $load_only); |
|
468 | - } |
|
469 | - |
|
470 | - |
|
471 | - |
|
472 | - /** |
|
473 | - * loads model classes - must be singletons |
|
474 | - * |
|
475 | - * @param string $class_name - simple class name ie: price |
|
476 | - * @param mixed $arguments |
|
477 | - * @param bool $load_only |
|
478 | - * @return EEM_Base | bool |
|
479 | - */ |
|
480 | - public function load_model($class_name, $arguments = array(), $load_only = false) |
|
481 | - { |
|
482 | - $paths = apply_filters('FHEE__EE_Registry__load_model__paths', array( |
|
483 | - EE_MODELS, |
|
484 | - EE_CORE, |
|
485 | - )); |
|
486 | - // retrieve instantiated class |
|
487 | - return $this->_load($paths, 'EEM_', $class_name, 'model', $arguments, false, true, $load_only); |
|
488 | - } |
|
489 | - |
|
490 | - |
|
491 | - |
|
492 | - /** |
|
493 | - * loads model classes - must be singletons |
|
494 | - * |
|
495 | - * @param string $class_name - simple class name ie: price |
|
496 | - * @param mixed $arguments |
|
497 | - * @param bool $load_only |
|
498 | - * @return mixed | bool |
|
499 | - */ |
|
500 | - public function load_model_class($class_name, $arguments = array(), $load_only = true) |
|
501 | - { |
|
502 | - $paths = array( |
|
503 | - EE_MODELS . 'fields' . DS, |
|
504 | - EE_MODELS . 'helpers' . DS, |
|
505 | - EE_MODELS . 'relations' . DS, |
|
506 | - EE_MODELS . 'strategies' . DS, |
|
507 | - ); |
|
508 | - // retrieve instantiated class |
|
509 | - return $this->_load($paths, 'EE_', $class_name, '', $arguments, false, true, $load_only); |
|
510 | - } |
|
511 | - |
|
512 | - |
|
513 | - |
|
514 | - /** |
|
515 | - * Determines if $model_name is the name of an actual EE model. |
|
516 | - * |
|
517 | - * @param string $model_name like Event, Attendee, Question_Group_Question, etc. |
|
518 | - * @return boolean |
|
519 | - */ |
|
520 | - public function is_model_name($model_name) |
|
521 | - { |
|
522 | - return isset($this->models[$model_name]) ? true : false; |
|
523 | - } |
|
524 | - |
|
525 | - |
|
526 | - |
|
527 | - /** |
|
528 | - * generic class loader |
|
529 | - * |
|
530 | - * @param string $path_to_file - directory path to file location, not including filename |
|
531 | - * @param string $file_name - file name ie: my_file.php, including extension |
|
532 | - * @param string $type - file type - core? class? helper? model? |
|
533 | - * @param mixed $arguments |
|
534 | - * @param bool $load_only |
|
535 | - * @return mixed |
|
536 | - */ |
|
537 | - public function load_file($path_to_file, $file_name, $type = '', $arguments = array(), $load_only = true) |
|
538 | - { |
|
539 | - // retrieve instantiated class |
|
540 | - return $this->_load($path_to_file, '', $file_name, $type, $arguments, false, true, $load_only); |
|
541 | - } |
|
542 | - |
|
543 | - |
|
544 | - |
|
545 | - /** |
|
546 | - * load_addon |
|
547 | - * |
|
548 | - * @param string $path_to_file - directory path to file location, not including filename |
|
549 | - * @param string $class_name - full class name ie: My_Class |
|
550 | - * @param string $type - file type - core? class? helper? model? |
|
551 | - * @param mixed $arguments |
|
552 | - * @param bool $load_only |
|
553 | - * @return EE_Addon |
|
554 | - */ |
|
555 | - public function load_addon($path_to_file, $class_name, $type = 'class', $arguments = array(), $load_only = false) |
|
556 | - { |
|
557 | - // retrieve instantiated class |
|
558 | - return $this->_load($path_to_file, 'addon', $class_name, $type, $arguments, false, true, $load_only); |
|
559 | - } |
|
560 | - |
|
561 | - |
|
562 | - |
|
563 | - /** |
|
564 | - * instantiates, caches, and automatically resolves dependencies |
|
565 | - * for classes that use a Fully Qualified Class Name. |
|
566 | - * if the class is not capable of being loaded using PSR-4 autoloading, |
|
567 | - * then you need to use one of the existing load_*() methods |
|
568 | - * which can resolve the classname and filepath from the passed arguments |
|
569 | - * |
|
570 | - * @param bool|string $class_name Fully Qualified Class Name |
|
571 | - * @param array $arguments an argument, or array of arguments to pass to the class upon instantiation |
|
572 | - * @param bool $cache whether to cache the instantiated object for reuse |
|
573 | - * @param bool $from_db some classes are instantiated from the db |
|
574 | - * and thus call a different method to instantiate |
|
575 | - * @param bool $load_only if true, will only load the file, but will NOT instantiate an object |
|
576 | - * @param bool|string $addon if true, will cache the object in the EE_Registry->$addons array |
|
577 | - * @return mixed null = failure to load or instantiate class object. |
|
578 | - * object = class loaded and instantiated successfully. |
|
579 | - * bool = fail or success when $load_only is true |
|
580 | - */ |
|
581 | - public function create( |
|
582 | - $class_name = false, |
|
583 | - $arguments = array(), |
|
584 | - $cache = false, |
|
585 | - $from_db = false, |
|
586 | - $load_only = false, |
|
587 | - $addon = false |
|
588 | - ) { |
|
589 | - $class_name = ltrim($class_name, '\\'); |
|
590 | - $class_name = $this->_dependency_map->get_alias($class_name); |
|
591 | - if ( ! class_exists($class_name)) { |
|
592 | - // maybe the class is registered with a preceding \ |
|
593 | - $class_name = strpos($class_name, '\\') !== 0 ? '\\' . $class_name : $class_name; |
|
594 | - // still doesn't exist ? |
|
595 | - if ( ! class_exists($class_name)) { |
|
596 | - return null; |
|
597 | - } |
|
598 | - } |
|
599 | - // if we're only loading the class and it already exists, then let's just return true immediately |
|
600 | - if ($load_only) { |
|
601 | - return true; |
|
602 | - } |
|
603 | - $addon = $addon ? 'addon' : ''; |
|
604 | - // $this->_cache_on is toggled during the recursive loading that can occur with dependency injection |
|
605 | - // $cache is controlled by individual calls to separate Registry loader methods like load_class() |
|
606 | - // $load_only is also controlled by individual calls to separate Registry loader methods like load_file() |
|
607 | - if ($this->_cache_on && $cache && ! $load_only) { |
|
608 | - // return object if it's already cached |
|
609 | - $cached_class = $this->_get_cached_class($class_name, $addon); |
|
610 | - if ($cached_class !== null) { |
|
611 | - return $cached_class; |
|
612 | - } |
|
613 | - } |
|
614 | - // instantiate the requested object |
|
615 | - $class_obj = $this->_create_object($class_name, $arguments, $addon, $from_db); |
|
616 | - if ($this->_cache_on && $cache) { |
|
617 | - // save it for later... kinda like gum { : $ |
|
618 | - $this->_set_cached_class($class_obj, $class_name, $addon, $from_db); |
|
619 | - } |
|
620 | - $this->_cache_on = true; |
|
621 | - return $class_obj; |
|
622 | - } |
|
623 | - |
|
624 | - |
|
625 | - |
|
626 | - /** |
|
627 | - * instantiates, caches, and injects dependencies for classes |
|
628 | - * |
|
629 | - * @param array $file_paths an array of paths to folders to look in |
|
630 | - * @param string $class_prefix EE or EEM or... ??? |
|
631 | - * @param bool|string $class_name $class name |
|
632 | - * @param string $type file type - core? class? helper? model? |
|
633 | - * @param mixed $arguments an argument or array of arguments to pass to the class upon instantiation |
|
634 | - * @param bool $from_db some classes are instantiated from the db |
|
635 | - * and thus call a different method to instantiate |
|
636 | - * @param bool $cache whether to cache the instantiated object for reuse |
|
637 | - * @param bool $load_only if true, will only load the file, but will NOT instantiate an object |
|
638 | - * @return null|object|bool null = failure to load or instantiate class object. |
|
639 | - * object = class loaded and instantiated successfully. |
|
640 | - * bool = fail or success when $load_only is true |
|
641 | - */ |
|
642 | - protected function _load( |
|
643 | - $file_paths = array(), |
|
644 | - $class_prefix = 'EE_', |
|
645 | - $class_name = false, |
|
646 | - $type = 'class', |
|
647 | - $arguments = array(), |
|
648 | - $from_db = false, |
|
649 | - $cache = true, |
|
650 | - $load_only = false |
|
651 | - ) { |
|
652 | - $class_name = ltrim($class_name, '\\'); |
|
653 | - // strip php file extension |
|
654 | - $class_name = str_replace('.php', '', trim($class_name)); |
|
655 | - // does the class have a prefix ? |
|
656 | - if ( ! empty($class_prefix) && $class_prefix != 'addon') { |
|
657 | - // make sure $class_prefix is uppercase |
|
658 | - $class_prefix = strtoupper(trim($class_prefix)); |
|
659 | - // add class prefix ONCE!!! |
|
660 | - $class_name = $class_prefix . str_replace($class_prefix, '', $class_name); |
|
661 | - } |
|
662 | - $class_name = $this->_dependency_map->get_alias($class_name); |
|
663 | - $class_exists = class_exists($class_name); |
|
664 | - // if we're only loading the class and it already exists, then let's just return true immediately |
|
665 | - if ($load_only && $class_exists) { |
|
666 | - return true; |
|
667 | - } |
|
668 | - // $this->_cache_on is toggled during the recursive loading that can occur with dependency injection |
|
669 | - // $cache is controlled by individual calls to separate Registry loader methods like load_class() |
|
670 | - // $load_only is also controlled by individual calls to separate Registry loader methods like load_file() |
|
671 | - if ($this->_cache_on && $cache && ! $load_only) { |
|
672 | - // return object if it's already cached |
|
673 | - $cached_class = $this->_get_cached_class($class_name, $class_prefix); |
|
674 | - if ($cached_class !== null) { |
|
675 | - return $cached_class; |
|
676 | - } |
|
677 | - } |
|
678 | - // if the class doesn't already exist.. then we need to try and find the file and load it |
|
679 | - if ( ! $class_exists) { |
|
680 | - // get full path to file |
|
681 | - $path = $this->_resolve_path($class_name, $type, $file_paths); |
|
682 | - // load the file |
|
683 | - $loaded = $this->_require_file($path, $class_name, $type, $file_paths); |
|
684 | - // if loading failed, or we are only loading a file but NOT instantiating an object |
|
685 | - if ( ! $loaded || $load_only) { |
|
686 | - // return boolean if only loading, or null if an object was expected |
|
687 | - return $load_only ? $loaded : null; |
|
688 | - } |
|
689 | - } |
|
690 | - // instantiate the requested object |
|
691 | - $class_obj = $this->_create_object($class_name, $arguments, $type, $from_db); |
|
692 | - if ($this->_cache_on && $cache) { |
|
693 | - // save it for later... kinda like gum { : $ |
|
694 | - $this->_set_cached_class($class_obj, $class_name, $class_prefix, $from_db); |
|
695 | - } |
|
696 | - $this->_cache_on = true; |
|
697 | - return $class_obj; |
|
698 | - } |
|
699 | - |
|
700 | - |
|
701 | - |
|
702 | - /** |
|
703 | - * _get_cached_class |
|
704 | - * attempts to find a cached version of the requested class |
|
705 | - * by looking in the following places: |
|
706 | - * $this->{$class_abbreviation} ie: $this->CART |
|
707 | - * $this->{$class_name} ie: $this->Some_Class |
|
708 | - * $this->LIB->{$class_name} ie: $this->LIB->Some_Class |
|
709 | - * $this->addon->{$class_name} ie: $this->addon->Some_Addon_Class |
|
710 | - * |
|
711 | - * @access protected |
|
712 | - * @param string $class_name |
|
713 | - * @param string $class_prefix |
|
714 | - * @return mixed |
|
715 | - */ |
|
716 | - protected function _get_cached_class($class_name, $class_prefix = '') |
|
717 | - { |
|
718 | - if (isset($this->_class_abbreviations[$class_name])) { |
|
719 | - $class_abbreviation = $this->_class_abbreviations[$class_name]; |
|
720 | - } else { |
|
721 | - // have to specify something, but not anything that will conflict |
|
722 | - $class_abbreviation = 'FANCY_BATMAN_PANTS'; |
|
723 | - } |
|
724 | - // check if class has already been loaded, and return it if it has been |
|
725 | - if (isset($this->{$class_abbreviation}) && ! is_null($this->{$class_abbreviation})) { |
|
726 | - return $this->{$class_abbreviation}; |
|
727 | - } else if (isset ($this->{$class_name})) { |
|
728 | - return $this->{$class_name}; |
|
729 | - } else if (isset ($this->LIB->{$class_name})) { |
|
730 | - return $this->LIB->{$class_name}; |
|
731 | - } else if ($class_prefix == 'addon' && isset ($this->addons->{$class_name})) { |
|
732 | - return $this->addons->{$class_name}; |
|
733 | - } |
|
734 | - return null; |
|
735 | - } |
|
736 | - |
|
737 | - |
|
738 | - |
|
739 | - /** |
|
740 | - * _resolve_path |
|
741 | - * attempts to find a full valid filepath for the requested class. |
|
742 | - * loops thru each of the base paths in the $file_paths array and appends : "{classname} . {file type} . php" |
|
743 | - * then returns that path if the target file has been found and is readable |
|
744 | - * |
|
745 | - * @access protected |
|
746 | - * @param string $class_name |
|
747 | - * @param string $type |
|
748 | - * @param array $file_paths |
|
749 | - * @return string | bool |
|
750 | - */ |
|
751 | - protected function _resolve_path($class_name, $type = '', $file_paths = array()) |
|
752 | - { |
|
753 | - // make sure $file_paths is an array |
|
754 | - $file_paths = is_array($file_paths) ? $file_paths : array($file_paths); |
|
755 | - // cycle thru paths |
|
756 | - foreach ($file_paths as $key => $file_path) { |
|
757 | - // convert all separators to proper DS, if no filepath, then use EE_CLASSES |
|
758 | - $file_path = $file_path ? str_replace(array('/', '\\'), DS, $file_path) : EE_CLASSES; |
|
759 | - // prep file type |
|
760 | - $type = ! empty($type) ? trim($type, '.') . '.' : ''; |
|
761 | - // build full file path |
|
762 | - $file_paths[$key] = rtrim($file_path, DS) . DS . $class_name . '.' . $type . 'php'; |
|
763 | - //does the file exist and can be read ? |
|
764 | - if (is_readable($file_paths[$key])) { |
|
765 | - return $file_paths[$key]; |
|
766 | - } |
|
767 | - } |
|
768 | - return false; |
|
769 | - } |
|
770 | - |
|
771 | - |
|
772 | - |
|
773 | - /** |
|
774 | - * _require_file |
|
775 | - * basically just performs a require_once() |
|
776 | - * but with some error handling |
|
777 | - * |
|
778 | - * @access protected |
|
779 | - * @param string $path |
|
780 | - * @param string $class_name |
|
781 | - * @param string $type |
|
782 | - * @param array $file_paths |
|
783 | - * @return boolean |
|
784 | - * @throws \EE_Error |
|
785 | - */ |
|
786 | - protected function _require_file($path, $class_name, $type = '', $file_paths = array()) |
|
787 | - { |
|
788 | - // don't give up! you gotta... |
|
789 | - try { |
|
790 | - //does the file exist and can it be read ? |
|
791 | - if ( ! $path) { |
|
792 | - // so sorry, can't find the file |
|
793 | - throw new EE_Error ( |
|
794 | - sprintf( |
|
795 | - __('The %1$s file %2$s could not be located or is not readable due to file permissions. Please ensure that the following filepath(s) are correct: %3$s', 'event_espresso'), |
|
796 | - trim($type, '.'), |
|
797 | - $class_name, |
|
798 | - '<br />' . implode(',<br />', $file_paths) |
|
799 | - ) |
|
800 | - ); |
|
801 | - } |
|
802 | - // get the file |
|
803 | - require_once($path); |
|
804 | - // if the class isn't already declared somewhere |
|
805 | - if (class_exists($class_name, false) === false) { |
|
806 | - // so sorry, not a class |
|
807 | - throw new EE_Error( |
|
808 | - sprintf( |
|
809 | - __('The %s file %s does not appear to contain the %s Class.', 'event_espresso'), |
|
810 | - $type, |
|
811 | - $path, |
|
812 | - $class_name |
|
813 | - ) |
|
814 | - ); |
|
815 | - } |
|
816 | - } catch (EE_Error $e) { |
|
817 | - $e->get_error(); |
|
818 | - return false; |
|
819 | - } |
|
820 | - return true; |
|
821 | - } |
|
822 | - |
|
823 | - |
|
824 | - |
|
825 | - /** |
|
826 | - * _create_object |
|
827 | - * Attempts to instantiate the requested class via any of the |
|
828 | - * commonly used instantiation methods employed throughout EE. |
|
829 | - * The priority for instantiation is as follows: |
|
830 | - * - abstract classes or any class flagged as "load only" (no instantiation occurs) |
|
831 | - * - model objects via their 'new_instance_from_db' method |
|
832 | - * - model objects via their 'new_instance' method |
|
833 | - * - "singleton" classes" via their 'instance' method |
|
834 | - * - standard instantiable classes via their __constructor |
|
835 | - * Prior to instantiation, if the classname exists in the dependency_map, |
|
836 | - * then the constructor for the requested class will be examined to determine |
|
837 | - * if any dependencies exist, and if they can be injected. |
|
838 | - * If so, then those classes will be added to the array of arguments passed to the constructor |
|
839 | - * |
|
840 | - * @access protected |
|
841 | - * @param string $class_name |
|
842 | - * @param array $arguments |
|
843 | - * @param string $type |
|
844 | - * @param bool $from_db |
|
845 | - * @return null | object |
|
846 | - * @throws \EE_Error |
|
847 | - */ |
|
848 | - protected function _create_object($class_name, $arguments = array(), $type = '', $from_db = false) |
|
849 | - { |
|
850 | - $class_obj = null; |
|
851 | - $instantiation_mode = '0) none'; |
|
852 | - // don't give up! you gotta... |
|
853 | - try { |
|
854 | - // create reflection |
|
855 | - $reflector = $this->get_ReflectionClass($class_name); |
|
856 | - // make sure arguments are an array |
|
857 | - $arguments = is_array($arguments) ? $arguments : array($arguments); |
|
858 | - // and if arguments array is numerically and sequentially indexed, then we want it to remain as is, |
|
859 | - // else wrap it in an additional array so that it doesn't get split into multiple parameters |
|
860 | - $arguments = $this->_array_is_numerically_and_sequentially_indexed($arguments) |
|
861 | - ? $arguments |
|
862 | - : array($arguments); |
|
863 | - // attempt to inject dependencies ? |
|
864 | - if ($this->_dependency_map->has($class_name)) { |
|
865 | - $arguments = $this->_resolve_dependencies($reflector, $class_name, $arguments); |
|
866 | - } |
|
867 | - // instantiate the class if possible |
|
868 | - if ($reflector->isAbstract()) { |
|
869 | - // nothing to instantiate, loading file was enough |
|
870 | - // does not throw an exception so $instantiation_mode is unused |
|
871 | - // $instantiation_mode = "1) no constructor abstract class"; |
|
872 | - $class_obj = true; |
|
873 | - } else if ($reflector->getConstructor() === null && $reflector->isInstantiable() && empty($arguments)) { |
|
874 | - // no constructor = static methods only... nothing to instantiate, loading file was enough |
|
875 | - $instantiation_mode = "2) no constructor but instantiable"; |
|
876 | - $class_obj = $reflector->newInstance(); |
|
877 | - } else if ($from_db && method_exists($class_name, 'new_instance_from_db')) { |
|
878 | - $instantiation_mode = "3) new_instance_from_db()"; |
|
879 | - $class_obj = call_user_func_array(array($class_name, 'new_instance_from_db'), $arguments); |
|
880 | - } else if (method_exists($class_name, 'new_instance')) { |
|
881 | - $instantiation_mode = "4) new_instance()"; |
|
882 | - $class_obj = call_user_func_array(array($class_name, 'new_instance'), $arguments); |
|
883 | - } else if (method_exists($class_name, 'instance')) { |
|
884 | - $instantiation_mode = "5) instance()"; |
|
885 | - $class_obj = call_user_func_array(array($class_name, 'instance'), $arguments); |
|
886 | - } else if ($reflector->isInstantiable()) { |
|
887 | - $instantiation_mode = "6) constructor"; |
|
888 | - $class_obj = $reflector->newInstanceArgs($arguments); |
|
889 | - } else { |
|
890 | - // heh ? something's not right ! |
|
891 | - throw new EE_Error( |
|
892 | - sprintf( |
|
893 | - __('The %s file %s could not be instantiated.', 'event_espresso'), |
|
894 | - $type, |
|
895 | - $class_name |
|
896 | - ) |
|
897 | - ); |
|
898 | - } |
|
899 | - } catch (Exception $e) { |
|
900 | - if ( ! $e instanceof EE_Error) { |
|
901 | - $e = new EE_Error( |
|
902 | - sprintf( |
|
903 | - __('The following error occurred while attempting to instantiate "%1$s": %2$s %3$s %2$s instantiation mode : %4$s', 'event_espresso'), |
|
904 | - $class_name, |
|
905 | - '<br />', |
|
906 | - $e->getMessage(), |
|
907 | - $instantiation_mode |
|
908 | - ) |
|
909 | - ); |
|
910 | - } |
|
911 | - $e->get_error(); |
|
912 | - } |
|
913 | - return $class_obj; |
|
914 | - } |
|
915 | - |
|
916 | - |
|
917 | - |
|
918 | - /** |
|
919 | - * @see http://stackoverflow.com/questions/173400/how-to-check-if-php-array-is-associative-or-sequential |
|
920 | - * @param array $array |
|
921 | - * @return bool |
|
922 | - */ |
|
923 | - protected function _array_is_numerically_and_sequentially_indexed(array $array) |
|
924 | - { |
|
925 | - return ! empty($array) ? array_keys($array) === range(0, count($array) - 1) : true; |
|
926 | - } |
|
927 | - |
|
928 | - |
|
929 | - |
|
930 | - /** |
|
931 | - * getReflectionClass |
|
932 | - * checks if a ReflectionClass object has already been generated for a class |
|
933 | - * and returns that instead of creating a new one |
|
934 | - * |
|
935 | - * @access public |
|
936 | - * @param string $class_name |
|
937 | - * @return ReflectionClass |
|
938 | - */ |
|
939 | - public function get_ReflectionClass($class_name) |
|
940 | - { |
|
941 | - if ( |
|
942 | - ! isset($this->_reflectors[$class_name]) |
|
943 | - || ! $this->_reflectors[$class_name] instanceof ReflectionClass |
|
944 | - ) { |
|
945 | - $this->_reflectors[$class_name] = new ReflectionClass($class_name); |
|
946 | - } |
|
947 | - return $this->_reflectors[$class_name]; |
|
948 | - } |
|
949 | - |
|
950 | - |
|
951 | - |
|
952 | - /** |
|
953 | - * _resolve_dependencies |
|
954 | - * examines the constructor for the requested class to determine |
|
955 | - * if any dependencies exist, and if they can be injected. |
|
956 | - * If so, then those classes will be added to the array of arguments passed to the constructor |
|
957 | - * PLZ NOTE: this is achieved by type hinting the constructor params |
|
958 | - * For example: |
|
959 | - * if attempting to load a class "Foo" with the following constructor: |
|
960 | - * __construct( Bar $bar_class, Fighter $grohl_class ) |
|
961 | - * then $bar_class and $grohl_class will be added to the $arguments array, |
|
962 | - * but only IF they are NOT already present in the incoming arguments array, |
|
963 | - * and the correct classes can be loaded |
|
964 | - * |
|
965 | - * @access protected |
|
966 | - * @param ReflectionClass $reflector |
|
967 | - * @param string $class_name |
|
968 | - * @param array $arguments |
|
969 | - * @return array |
|
970 | - * @throws \ReflectionException |
|
971 | - */ |
|
972 | - protected function _resolve_dependencies(ReflectionClass $reflector, $class_name, $arguments = array()) |
|
973 | - { |
|
974 | - // let's examine the constructor |
|
975 | - $constructor = $reflector->getConstructor(); |
|
976 | - // whu? huh? nothing? |
|
977 | - if ( ! $constructor) { |
|
978 | - return $arguments; |
|
979 | - } |
|
980 | - // get constructor parameters |
|
981 | - $params = $constructor->getParameters(); |
|
982 | - // and the keys for the incoming arguments array so that we can compare existing arguments with what is expected |
|
983 | - $argument_keys = array_keys($arguments); |
|
984 | - // now loop thru all of the constructors expected parameters |
|
985 | - foreach ($params as $index => $param) { |
|
986 | - // is this a dependency for a specific class ? |
|
987 | - $param_class = $param->getClass() ? $param->getClass()->name : null; |
|
988 | - if ( |
|
989 | - // param is not even a class |
|
990 | - empty($param_class) |
|
991 | - // and something already exists in the incoming arguments for this param |
|
992 | - && isset($argument_keys[$index], $arguments[$argument_keys[$index]]) |
|
993 | - ) { |
|
994 | - // so let's skip this argument and move on to the next |
|
995 | - continue; |
|
996 | - } else if ( |
|
997 | - // parameter is type hinted as a class, exists as an incoming argument, AND it's the correct class |
|
998 | - ! empty($param_class) |
|
999 | - && isset($argument_keys[$index], $arguments[$argument_keys[$index]]) |
|
1000 | - && $arguments[$argument_keys[$index]] instanceof $param_class |
|
1001 | - ) { |
|
1002 | - // skip this argument and move on to the next |
|
1003 | - continue; |
|
1004 | - } else if ( |
|
1005 | - // parameter is type hinted as a class, and should be injected |
|
1006 | - ! empty($param_class) |
|
1007 | - && $this->_dependency_map->has_dependency_for_class($class_name, $param_class) |
|
1008 | - ) { |
|
1009 | - $arguments = $this->_resolve_dependency($class_name, $param_class, $arguments, $index); |
|
1010 | - } else { |
|
1011 | - try { |
|
1012 | - $arguments[$index] = $param->getDefaultValue(); |
|
1013 | - } catch (ReflectionException $e) { |
|
1014 | - throw new ReflectionException( |
|
1015 | - sprintf( |
|
1016 | - __('%1$s for parameter "$%2$s"', 'event_espresso'), |
|
1017 | - $e->getMessage(), |
|
1018 | - $param->getName() |
|
1019 | - ) |
|
1020 | - ); |
|
1021 | - } |
|
1022 | - } |
|
1023 | - } |
|
1024 | - return $arguments; |
|
1025 | - } |
|
1026 | - |
|
1027 | - |
|
1028 | - |
|
1029 | - /** |
|
1030 | - * @access protected |
|
1031 | - * @param string $class_name |
|
1032 | - * @param string $param_class |
|
1033 | - * @param array $arguments |
|
1034 | - * @param mixed $index |
|
1035 | - * @return array |
|
1036 | - */ |
|
1037 | - protected function _resolve_dependency($class_name, $param_class, $arguments, $index) |
|
1038 | - { |
|
1039 | - $dependency = null; |
|
1040 | - // should dependency be loaded from cache ? |
|
1041 | - $cache_on = $this->_dependency_map->loading_strategy_for_class_dependency($class_name, $param_class) |
|
1042 | - !== EE_Dependency_Map::load_new_object |
|
1043 | - ? true |
|
1044 | - : false; |
|
1045 | - // we might have a dependency... |
|
1046 | - // let's MAYBE try and find it in our cache if that's what's been requested |
|
1047 | - $cached_class = $cache_on ? $this->_get_cached_class($param_class) : null; |
|
1048 | - // and grab it if it exists |
|
1049 | - if ($cached_class instanceof $param_class) { |
|
1050 | - $dependency = $cached_class; |
|
1051 | - } else if ($param_class != $class_name) { |
|
1052 | - // obtain the loader method from the dependency map |
|
1053 | - $loader = $this->_dependency_map->class_loader($param_class); |
|
1054 | - // is loader a custom closure ? |
|
1055 | - if ($loader instanceof Closure) { |
|
1056 | - $dependency = $loader(); |
|
1057 | - } else { |
|
1058 | - // set the cache on property for the recursive loading call |
|
1059 | - $this->_cache_on = $cache_on; |
|
1060 | - // if not, then let's try and load it via the registry |
|
1061 | - if (method_exists($this, $loader)) { |
|
1062 | - $dependency = $this->{$loader}($param_class); |
|
1063 | - } else { |
|
1064 | - $dependency = $this->create($param_class, array(), $cache_on); |
|
1065 | - } |
|
1066 | - } |
|
1067 | - } |
|
1068 | - // did we successfully find the correct dependency ? |
|
1069 | - if ($dependency instanceof $param_class) { |
|
1070 | - // then let's inject it into the incoming array of arguments at the correct location |
|
1071 | - if (isset($argument_keys[$index])) { |
|
1072 | - $arguments[$argument_keys[$index]] = $dependency; |
|
1073 | - } else { |
|
1074 | - $arguments[$index] = $dependency; |
|
1075 | - } |
|
1076 | - } |
|
1077 | - return $arguments; |
|
1078 | - } |
|
1079 | - |
|
1080 | - |
|
1081 | - |
|
1082 | - /** |
|
1083 | - * _set_cached_class |
|
1084 | - * attempts to cache the instantiated class locally |
|
1085 | - * in one of the following places, in the following order: |
|
1086 | - * $this->{class_abbreviation} ie: $this->CART |
|
1087 | - * $this->{$class_name} ie: $this->Some_Class |
|
1088 | - * $this->addon->{$$class_name} ie: $this->addon->Some_Addon_Class |
|
1089 | - * $this->LIB->{$class_name} ie: $this->LIB->Some_Class |
|
1090 | - * |
|
1091 | - * @access protected |
|
1092 | - * @param object $class_obj |
|
1093 | - * @param string $class_name |
|
1094 | - * @param string $class_prefix |
|
1095 | - * @param bool $from_db |
|
1096 | - * @return void |
|
1097 | - */ |
|
1098 | - protected function _set_cached_class($class_obj, $class_name, $class_prefix = '', $from_db = false) |
|
1099 | - { |
|
1100 | - if (empty($class_obj)) { |
|
1101 | - return; |
|
1102 | - } |
|
1103 | - // return newly instantiated class |
|
1104 | - if (isset($this->_class_abbreviations[$class_name])) { |
|
1105 | - $class_abbreviation = $this->_class_abbreviations[$class_name]; |
|
1106 | - $this->{$class_abbreviation} = $class_obj; |
|
1107 | - } else if (property_exists($this, $class_name)) { |
|
1108 | - $this->{$class_name} = $class_obj; |
|
1109 | - } else if ($class_prefix == 'addon') { |
|
1110 | - $this->addons->{$class_name} = $class_obj; |
|
1111 | - } else if ( ! $from_db) { |
|
1112 | - $this->LIB->{$class_name} = $class_obj; |
|
1113 | - } |
|
1114 | - } |
|
1115 | - |
|
1116 | - |
|
1117 | - |
|
1118 | - /** |
|
1119 | - * call any loader that's been registered in the EE_Dependency_Map::$_class_loaders array |
|
1120 | - * |
|
1121 | - * @param string $classname PLEASE NOTE: the class name needs to match what's registered |
|
1122 | - * in the EE_Dependency_Map::$_class_loaders array, |
|
1123 | - * including the class prefix, ie: "EE_", "EEM_", "EEH_", etc |
|
1124 | - * @param array $arguments |
|
1125 | - * @return object |
|
1126 | - */ |
|
1127 | - public static function factory($classname, $arguments = array()) |
|
1128 | - { |
|
1129 | - $loader = self::instance()->_dependency_map->class_loader($classname); |
|
1130 | - if ($loader instanceof Closure) { |
|
1131 | - return $loader($arguments); |
|
1132 | - } else if (method_exists(EE_Registry::instance(), $loader)) { |
|
1133 | - return EE_Registry::instance()->{$loader}($classname, $arguments); |
|
1134 | - } |
|
1135 | - return null; |
|
1136 | - } |
|
1137 | - |
|
1138 | - |
|
1139 | - |
|
1140 | - /** |
|
1141 | - * Gets the addon by its name/slug (not classname. For that, just |
|
1142 | - * use the classname as the property name on EE_Config::instance()->addons) |
|
1143 | - * |
|
1144 | - * @param string $name |
|
1145 | - * @return EE_Addon |
|
1146 | - */ |
|
1147 | - public function get_addon_by_name($name) |
|
1148 | - { |
|
1149 | - foreach ($this->addons as $addon) { |
|
1150 | - if ($addon->name() == $name) { |
|
1151 | - return $addon; |
|
1152 | - } |
|
1153 | - } |
|
1154 | - return null; |
|
1155 | - } |
|
1156 | - |
|
1157 | - |
|
1158 | - |
|
1159 | - /** |
|
1160 | - * Gets an array of all the registered addons, where the keys are their names. (ie, what each returns for their name() function) They're already available on EE_Config::instance()->addons as properties, where each property's name is |
|
1161 | - * the addon's classname. So if you just want to get the addon by classname, use EE_Config::instance()->addons->{classname} |
|
1162 | - * |
|
1163 | - * @return EE_Addon[] where the KEYS are the addon's name() |
|
1164 | - */ |
|
1165 | - public function get_addons_by_name() |
|
1166 | - { |
|
1167 | - $addons = array(); |
|
1168 | - foreach ($this->addons as $addon) { |
|
1169 | - $addons[$addon->name()] = $addon; |
|
1170 | - } |
|
1171 | - return $addons; |
|
1172 | - } |
|
1173 | - |
|
1174 | - |
|
1175 | - |
|
1176 | - /** |
|
1177 | - * Resets the specified model's instance AND makes sure EE_Registry doesn't keep |
|
1178 | - * a stale copy of it around |
|
1179 | - * |
|
1180 | - * @param string $model_name |
|
1181 | - * @return \EEM_Base |
|
1182 | - * @throws \EE_Error |
|
1183 | - */ |
|
1184 | - public function reset_model($model_name) |
|
1185 | - { |
|
1186 | - $model_class_name = strpos($model_name, 'EEM_') !== 0 ? "EEM_{$model_name}" : $model_name; |
|
1187 | - if ( ! isset($this->LIB->{$model_class_name}) || ! $this->LIB->{$model_class_name} instanceof EEM_Base) { |
|
1188 | - return null; |
|
1189 | - } |
|
1190 | - //get that model reset it and make sure we nuke the old reference to it |
|
1191 | - if ($this->LIB->{$model_class_name} instanceof $model_class_name && is_callable(array($model_class_name, 'reset'))) { |
|
1192 | - $this->LIB->{$model_class_name} = $this->LIB->{$model_class_name}->reset(); |
|
1193 | - } else { |
|
1194 | - throw new EE_Error(sprintf(__('Model %s does not have a method "reset"', 'event_espresso'), $model_name)); |
|
1195 | - } |
|
1196 | - return $this->LIB->{$model_class_name}; |
|
1197 | - } |
|
1198 | - |
|
1199 | - |
|
1200 | - |
|
1201 | - /** |
|
1202 | - * Resets the registry. |
|
1203 | - * The criteria for what gets reset is based on what can be shared between sites on the same request when switch_to_blog |
|
1204 | - * is used in a multisite install. Here is a list of things that are NOT reset. |
|
1205 | - * - $_dependency_map |
|
1206 | - * - $_class_abbreviations |
|
1207 | - * - $NET_CFG (EE_Network_Config): The config is shared network wide so no need to reset. |
|
1208 | - * - $REQ: Still on the same request so no need to change. |
|
1209 | - * - $CAP: There is no site specific state in the EE_Capability class. |
|
1210 | - * - $SSN: Although ideally, the session should not be shared between site switches, we can't reset it because only one Session |
|
1211 | - * can be active in a single request. Resetting could resolve in "headers already sent" errors. |
|
1212 | - * - $addons: In multisite, the state of the addons is something controlled via hooks etc in a normal request. So |
|
1213 | - * for now, we won't reset the addons because it could break calls to an add-ons class/methods in the |
|
1214 | - * switch or on the restore. |
|
1215 | - * - $modules |
|
1216 | - * - $shortcodes |
|
1217 | - * - $widgets |
|
1218 | - * |
|
1219 | - * @param boolean $hard whether to reset data in the database too, or just refresh |
|
1220 | - * the Registry to its state at the beginning of the request |
|
1221 | - * @param boolean $reinstantiate whether to create new instances of EE_Registry's singletons too, |
|
1222 | - * or just reset without re-instantiating (handy to set to FALSE if you're not sure if you CAN |
|
1223 | - * currently reinstantiate the singletons at the moment) |
|
1224 | - * @param bool $reset_models Defaults to true. When false, then the models are not reset. This is so client |
|
1225 | - * code instead can just change the model context to a different blog id if necessary |
|
1226 | - * @return EE_Registry |
|
1227 | - */ |
|
1228 | - public static function reset($hard = false, $reinstantiate = true, $reset_models = true) |
|
1229 | - { |
|
1230 | - $instance = self::instance(); |
|
1231 | - EEH_Activation::reset(); |
|
1232 | - //properties that get reset |
|
1233 | - $instance->_cache_on = true; |
|
1234 | - $instance->CFG = EE_Config::reset($hard, $reinstantiate); |
|
1235 | - $instance->CART = null; |
|
1236 | - $instance->MRM = null; |
|
1237 | - $instance->AssetsRegistry = new Registry(); |
|
1238 | - //messages reset |
|
1239 | - EED_Messages::reset(); |
|
1240 | - if ($reset_models) { |
|
1241 | - foreach (array_keys($instance->non_abstract_db_models) as $model_name) { |
|
1242 | - $instance->reset_model($model_name); |
|
1243 | - } |
|
1244 | - } |
|
1245 | - $instance->LIB = new stdClass(); |
|
1246 | - return $instance; |
|
1247 | - } |
|
1248 | - |
|
1249 | - |
|
1250 | - |
|
1251 | - /** |
|
1252 | - * @override magic methods |
|
1253 | - * @return void |
|
1254 | - */ |
|
1255 | - final function __destruct() |
|
1256 | - { |
|
1257 | - } |
|
1258 | - |
|
1259 | - |
|
1260 | - |
|
1261 | - /** |
|
1262 | - * @param $a |
|
1263 | - * @param $b |
|
1264 | - */ |
|
1265 | - final function __call($a, $b) |
|
1266 | - { |
|
1267 | - } |
|
1268 | - |
|
1269 | - |
|
1270 | - |
|
1271 | - /** |
|
1272 | - * @param $a |
|
1273 | - */ |
|
1274 | - final function __get($a) |
|
1275 | - { |
|
1276 | - } |
|
1277 | - |
|
1278 | - |
|
1279 | - |
|
1280 | - /** |
|
1281 | - * @param $a |
|
1282 | - * @param $b |
|
1283 | - */ |
|
1284 | - final function __set($a, $b) |
|
1285 | - { |
|
1286 | - } |
|
1287 | - |
|
1288 | - |
|
1289 | - |
|
1290 | - /** |
|
1291 | - * @param $a |
|
1292 | - */ |
|
1293 | - final function __isset($a) |
|
1294 | - { |
|
1295 | - } |
|
19 | + /** |
|
20 | + * EE_Registry Object |
|
21 | + * |
|
22 | + * @var EE_Registry $_instance |
|
23 | + * @access private |
|
24 | + */ |
|
25 | + private static $_instance = null; |
|
26 | + |
|
27 | + /** |
|
28 | + * @var EE_Dependency_Map $_dependency_map |
|
29 | + * @access protected |
|
30 | + */ |
|
31 | + protected $_dependency_map = null; |
|
32 | + |
|
33 | + /** |
|
34 | + * @var array $_class_abbreviations |
|
35 | + * @access protected |
|
36 | + */ |
|
37 | + protected $_class_abbreviations = array(); |
|
38 | + |
|
39 | + /** |
|
40 | + * @access public |
|
41 | + * @var \EventEspresso\core\services\commands\CommandBusInterface $BUS |
|
42 | + */ |
|
43 | + public $BUS; |
|
44 | + |
|
45 | + /** |
|
46 | + * EE_Cart Object |
|
47 | + * |
|
48 | + * @access public |
|
49 | + * @var EE_Cart $CART |
|
50 | + */ |
|
51 | + public $CART = null; |
|
52 | + |
|
53 | + /** |
|
54 | + * EE_Config Object |
|
55 | + * |
|
56 | + * @access public |
|
57 | + * @var EE_Config $CFG |
|
58 | + */ |
|
59 | + public $CFG = null; |
|
60 | + |
|
61 | + /** |
|
62 | + * EE_Network_Config Object |
|
63 | + * |
|
64 | + * @access public |
|
65 | + * @var EE_Network_Config $NET_CFG |
|
66 | + */ |
|
67 | + public $NET_CFG = null; |
|
68 | + |
|
69 | + /** |
|
70 | + * StdClass object for storing library classes in |
|
71 | + * |
|
72 | + * @public LIB |
|
73 | + * @var StdClass $LIB |
|
74 | + */ |
|
75 | + public $LIB = null; |
|
76 | + |
|
77 | + /** |
|
78 | + * EE_Request_Handler Object |
|
79 | + * |
|
80 | + * @access public |
|
81 | + * @var EE_Request_Handler $REQ |
|
82 | + */ |
|
83 | + public $REQ = null; |
|
84 | + |
|
85 | + /** |
|
86 | + * EE_Session Object |
|
87 | + * |
|
88 | + * @access public |
|
89 | + * @var EE_Session $SSN |
|
90 | + */ |
|
91 | + public $SSN = null; |
|
92 | + |
|
93 | + /** |
|
94 | + * holds the ee capabilities object. |
|
95 | + * |
|
96 | + * @since 4.5.0 |
|
97 | + * @var EE_Capabilities |
|
98 | + */ |
|
99 | + public $CAP = null; |
|
100 | + |
|
101 | + /** |
|
102 | + * holds the EE_Message_Resource_Manager object. |
|
103 | + * |
|
104 | + * @since 4.9.0 |
|
105 | + * @var EE_Message_Resource_Manager |
|
106 | + */ |
|
107 | + public $MRM = null; |
|
108 | + |
|
109 | + |
|
110 | + /** |
|
111 | + * Holds the Assets Registry instance |
|
112 | + * @var Registry |
|
113 | + */ |
|
114 | + public $AssetsRegistry = null; |
|
115 | + |
|
116 | + /** |
|
117 | + * $addons - StdClass object for holding addons which have registered themselves to work with EE core |
|
118 | + * |
|
119 | + * @access public |
|
120 | + * @var EE_Addon[] |
|
121 | + */ |
|
122 | + public $addons = null; |
|
123 | + |
|
124 | + /** |
|
125 | + * $models |
|
126 | + * @access public |
|
127 | + * @var EEM_Base[] $models keys are 'short names' (eg Event), values are class names (eg 'EEM_Event') |
|
128 | + */ |
|
129 | + public $models = array(); |
|
130 | + |
|
131 | + /** |
|
132 | + * $modules |
|
133 | + * @access public |
|
134 | + * @var EED_Module[] $modules |
|
135 | + */ |
|
136 | + public $modules = null; |
|
137 | + |
|
138 | + /** |
|
139 | + * $shortcodes |
|
140 | + * @access public |
|
141 | + * @var EES_Shortcode[] $shortcodes |
|
142 | + */ |
|
143 | + public $shortcodes = null; |
|
144 | + |
|
145 | + /** |
|
146 | + * $widgets |
|
147 | + * @access public |
|
148 | + * @var WP_Widget[] $widgets |
|
149 | + */ |
|
150 | + public $widgets = null; |
|
151 | + |
|
152 | + /** |
|
153 | + * $non_abstract_db_models |
|
154 | + * @access public |
|
155 | + * @var array this is an array of all implemented model names (i.e. not the parent abstract models, or models |
|
156 | + * which don't actually fetch items from the DB in the normal way (ie, are not children of EEM_Base)). |
|
157 | + * Keys are model "short names" (eg "Event") as used in model relations, and values are |
|
158 | + * classnames (eg "EEM_Event") |
|
159 | + */ |
|
160 | + public $non_abstract_db_models = array(); |
|
161 | + |
|
162 | + |
|
163 | + /** |
|
164 | + * $i18n_js_strings - internationalization for JS strings |
|
165 | + * usage: EE_Registry::i18n_js_strings['string_key'] = __( 'string to translate.', 'event_espresso' ); |
|
166 | + * in js file: var translatedString = eei18n.string_key; |
|
167 | + * |
|
168 | + * @access public |
|
169 | + * @var array |
|
170 | + */ |
|
171 | + public static $i18n_js_strings = array(); |
|
172 | + |
|
173 | + |
|
174 | + /** |
|
175 | + * $main_file - path to espresso.php |
|
176 | + * |
|
177 | + * @access public |
|
178 | + * @var array |
|
179 | + */ |
|
180 | + public $main_file; |
|
181 | + |
|
182 | + /** |
|
183 | + * array of ReflectionClass objects where the key is the class name |
|
184 | + * |
|
185 | + * @access public |
|
186 | + * @var ReflectionClass[] |
|
187 | + */ |
|
188 | + public $_reflectors; |
|
189 | + |
|
190 | + /** |
|
191 | + * boolean flag to indicate whether or not to load/save dependencies from/to the cache |
|
192 | + * |
|
193 | + * @access protected |
|
194 | + * @var boolean $_cache_on |
|
195 | + */ |
|
196 | + protected $_cache_on = true; |
|
197 | + |
|
198 | + |
|
199 | + |
|
200 | + /** |
|
201 | + * @singleton method used to instantiate class object |
|
202 | + * @access public |
|
203 | + * @param \EE_Dependency_Map $dependency_map |
|
204 | + * @return \EE_Registry instance |
|
205 | + */ |
|
206 | + public static function instance(\EE_Dependency_Map $dependency_map = null) |
|
207 | + { |
|
208 | + // check if class object is instantiated |
|
209 | + if ( ! self::$_instance instanceof EE_Registry) { |
|
210 | + self::$_instance = new EE_Registry($dependency_map); |
|
211 | + } |
|
212 | + return self::$_instance; |
|
213 | + } |
|
214 | + |
|
215 | + |
|
216 | + |
|
217 | + /** |
|
218 | + *protected constructor to prevent direct creation |
|
219 | + * |
|
220 | + * @Constructor |
|
221 | + * @access protected |
|
222 | + * @param \EE_Dependency_Map $dependency_map |
|
223 | + * @return \EE_Registry |
|
224 | + */ |
|
225 | + protected function __construct(\EE_Dependency_Map $dependency_map) |
|
226 | + { |
|
227 | + $this->_dependency_map = $dependency_map; |
|
228 | + add_action('EE_Load_Espresso_Core__handle_request__initialize_core_loading', array($this, 'initialize')); |
|
229 | + } |
|
230 | + |
|
231 | + |
|
232 | + |
|
233 | + /** |
|
234 | + * initialize |
|
235 | + */ |
|
236 | + public function initialize() |
|
237 | + { |
|
238 | + $this->_class_abbreviations = apply_filters( |
|
239 | + 'FHEE__EE_Registry____construct___class_abbreviations', |
|
240 | + array( |
|
241 | + 'EE_Config' => 'CFG', |
|
242 | + 'EE_Session' => 'SSN', |
|
243 | + 'EE_Capabilities' => 'CAP', |
|
244 | + 'EE_Cart' => 'CART', |
|
245 | + 'EE_Network_Config' => 'NET_CFG', |
|
246 | + 'EE_Request_Handler' => 'REQ', |
|
247 | + 'EE_Message_Resource_Manager' => 'MRM', |
|
248 | + 'EventEspresso\core\services\commands\CommandBus' => 'BUS', |
|
249 | + ) |
|
250 | + ); |
|
251 | + // class library |
|
252 | + $this->LIB = new stdClass(); |
|
253 | + $this->addons = new stdClass(); |
|
254 | + $this->modules = new stdClass(); |
|
255 | + $this->shortcodes = new stdClass(); |
|
256 | + $this->widgets = new stdClass(); |
|
257 | + $this->load_core('Base', array(), true); |
|
258 | + // add our request and response objects to the cache |
|
259 | + $request_loader = $this->_dependency_map->class_loader('EE_Request'); |
|
260 | + $this->_set_cached_class( |
|
261 | + $request_loader(), |
|
262 | + 'EE_Request' |
|
263 | + ); |
|
264 | + $response_loader = $this->_dependency_map->class_loader('EE_Response'); |
|
265 | + $this->_set_cached_class( |
|
266 | + $response_loader(), |
|
267 | + 'EE_Response' |
|
268 | + ); |
|
269 | + add_action('AHEE__EE_System__set_hooks_for_core', array($this, 'init')); |
|
270 | + } |
|
271 | + |
|
272 | + |
|
273 | + |
|
274 | + /** |
|
275 | + * init |
|
276 | + * |
|
277 | + * @access public |
|
278 | + * @return void |
|
279 | + */ |
|
280 | + public function init() |
|
281 | + { |
|
282 | + $this->AssetsRegistry = new Registry(); |
|
283 | + // Get current page protocol |
|
284 | + $protocol = isset($_SERVER['HTTPS']) ? 'https://' : 'http://'; |
|
285 | + // Output admin-ajax.php URL with same protocol as current page |
|
286 | + self::$i18n_js_strings['ajax_url'] = admin_url('admin-ajax.php', $protocol); |
|
287 | + self::$i18n_js_strings['wp_debug'] = defined('WP_DEBUG') ? WP_DEBUG : false; |
|
288 | + } |
|
289 | + |
|
290 | + |
|
291 | + |
|
292 | + /** |
|
293 | + * localize_i18n_js_strings |
|
294 | + * |
|
295 | + * @return string |
|
296 | + */ |
|
297 | + public static function localize_i18n_js_strings() |
|
298 | + { |
|
299 | + $i18n_js_strings = (array)EE_Registry::$i18n_js_strings; |
|
300 | + foreach ($i18n_js_strings as $key => $value) { |
|
301 | + if (is_scalar($value)) { |
|
302 | + $i18n_js_strings[$key] = html_entity_decode((string)$value, ENT_QUOTES, 'UTF-8'); |
|
303 | + } |
|
304 | + } |
|
305 | + return "/* <![CDATA[ */ var eei18n = " . wp_json_encode($i18n_js_strings) . '; /* ]]> */'; |
|
306 | + } |
|
307 | + |
|
308 | + |
|
309 | + |
|
310 | + /** |
|
311 | + * @param mixed string | EED_Module $module |
|
312 | + */ |
|
313 | + public function add_module($module) |
|
314 | + { |
|
315 | + if ($module instanceof EED_Module) { |
|
316 | + $module_class = get_class($module); |
|
317 | + $this->modules->{$module_class} = $module; |
|
318 | + } else { |
|
319 | + if ( ! class_exists('EE_Module_Request_Router')) { |
|
320 | + $this->load_core('Module_Request_Router'); |
|
321 | + } |
|
322 | + $this->modules->{$module} = EE_Module_Request_Router::module_factory($module); |
|
323 | + } |
|
324 | + } |
|
325 | + |
|
326 | + |
|
327 | + |
|
328 | + /** |
|
329 | + * @param string $module_name |
|
330 | + * @return mixed EED_Module | NULL |
|
331 | + */ |
|
332 | + public function get_module($module_name = '') |
|
333 | + { |
|
334 | + return isset($this->modules->{$module_name}) ? $this->modules->{$module_name} : null; |
|
335 | + } |
|
336 | + |
|
337 | + |
|
338 | + |
|
339 | + /** |
|
340 | + * loads core classes - must be singletons |
|
341 | + * |
|
342 | + * @access public |
|
343 | + * @param string $class_name - simple class name ie: session |
|
344 | + * @param mixed $arguments |
|
345 | + * @param bool $load_only |
|
346 | + * @return mixed |
|
347 | + */ |
|
348 | + public function load_core($class_name, $arguments = array(), $load_only = false) |
|
349 | + { |
|
350 | + $core_paths = apply_filters( |
|
351 | + 'FHEE__EE_Registry__load_core__core_paths', |
|
352 | + array( |
|
353 | + EE_CORE, |
|
354 | + EE_ADMIN, |
|
355 | + EE_CPTS, |
|
356 | + EE_CORE . 'data_migration_scripts' . DS, |
|
357 | + EE_CORE . 'request_stack' . DS, |
|
358 | + EE_CORE . 'middleware' . DS, |
|
359 | + ) |
|
360 | + ); |
|
361 | + // retrieve instantiated class |
|
362 | + return $this->_load($core_paths, 'EE_', $class_name, 'core', $arguments, false, true, $load_only); |
|
363 | + } |
|
364 | + |
|
365 | + |
|
366 | + |
|
367 | + /** |
|
368 | + * loads service classes |
|
369 | + * |
|
370 | + * @access public |
|
371 | + * @param string $class_name - simple class name ie: session |
|
372 | + * @param mixed $arguments |
|
373 | + * @param bool $load_only |
|
374 | + * @return mixed |
|
375 | + */ |
|
376 | + public function load_service($class_name, $arguments = array(), $load_only = false) |
|
377 | + { |
|
378 | + $service_paths = apply_filters( |
|
379 | + 'FHEE__EE_Registry__load_service__service_paths', |
|
380 | + array( |
|
381 | + EE_CORE . 'services' . DS, |
|
382 | + ) |
|
383 | + ); |
|
384 | + // retrieve instantiated class |
|
385 | + return $this->_load($service_paths, 'EE_', $class_name, 'class', $arguments, false, true, $load_only); |
|
386 | + } |
|
387 | + |
|
388 | + |
|
389 | + |
|
390 | + /** |
|
391 | + * loads data_migration_scripts |
|
392 | + * |
|
393 | + * @access public |
|
394 | + * @param string $class_name - class name for the DMS ie: EE_DMS_Core_4_2_0 |
|
395 | + * @param mixed $arguments |
|
396 | + * @return EE_Data_Migration_Script_Base|mixed |
|
397 | + */ |
|
398 | + public function load_dms($class_name, $arguments = array()) |
|
399 | + { |
|
400 | + // retrieve instantiated class |
|
401 | + return $this->_load(EE_Data_Migration_Manager::instance()->get_data_migration_script_folders(), 'EE_DMS_', $class_name, 'dms', $arguments, false, false, false); |
|
402 | + } |
|
403 | + |
|
404 | + |
|
405 | + |
|
406 | + /** |
|
407 | + * loads object creating classes - must be singletons |
|
408 | + * |
|
409 | + * @param string $class_name - simple class name ie: attendee |
|
410 | + * @param mixed $arguments - an array of arguments to pass to the class |
|
411 | + * @param bool $from_db - some classes are instantiated from the db and thus call a different method to instantiate |
|
412 | + * @param bool $cache if you don't want the class to be stored in the internal cache (non-persistent) then set this to FALSE (ie. when instantiating model objects from client in a loop) |
|
413 | + * @param bool $load_only whether or not to just load the file and NOT instantiate, or load AND instantiate (default) |
|
414 | + * @return EE_Base_Class | bool |
|
415 | + */ |
|
416 | + public function load_class($class_name, $arguments = array(), $from_db = false, $cache = true, $load_only = false) |
|
417 | + { |
|
418 | + $paths = apply_filters('FHEE__EE_Registry__load_class__paths', array( |
|
419 | + EE_CORE, |
|
420 | + EE_CLASSES, |
|
421 | + EE_BUSINESS, |
|
422 | + )); |
|
423 | + // retrieve instantiated class |
|
424 | + return $this->_load($paths, 'EE_', $class_name, 'class', $arguments, $from_db, $cache, $load_only); |
|
425 | + } |
|
426 | + |
|
427 | + |
|
428 | + |
|
429 | + /** |
|
430 | + * loads helper classes - must be singletons |
|
431 | + * |
|
432 | + * @param string $class_name - simple class name ie: price |
|
433 | + * @param mixed $arguments |
|
434 | + * @param bool $load_only |
|
435 | + * @return EEH_Base | bool |
|
436 | + */ |
|
437 | + public function load_helper($class_name, $arguments = array(), $load_only = true) |
|
438 | + { |
|
439 | + // todo: add doing_it_wrong() in a few versions after all addons have had calls to this method removed |
|
440 | + $helper_paths = apply_filters('FHEE__EE_Registry__load_helper__helper_paths', array(EE_HELPERS)); |
|
441 | + // retrieve instantiated class |
|
442 | + return $this->_load($helper_paths, 'EEH_', $class_name, 'helper', $arguments, false, true, $load_only); |
|
443 | + } |
|
444 | + |
|
445 | + |
|
446 | + |
|
447 | + /** |
|
448 | + * loads core classes - must be singletons |
|
449 | + * |
|
450 | + * @access public |
|
451 | + * @param string $class_name - simple class name ie: session |
|
452 | + * @param mixed $arguments |
|
453 | + * @param bool $load_only |
|
454 | + * @param bool $cache whether to cache the object or not. |
|
455 | + * @return mixed |
|
456 | + */ |
|
457 | + public function load_lib($class_name, $arguments = array(), $load_only = false, $cache = true) |
|
458 | + { |
|
459 | + $paths = array( |
|
460 | + EE_LIBRARIES, |
|
461 | + EE_LIBRARIES . 'messages' . DS, |
|
462 | + EE_LIBRARIES . 'shortcodes' . DS, |
|
463 | + EE_LIBRARIES . 'qtips' . DS, |
|
464 | + EE_LIBRARIES . 'payment_methods' . DS, |
|
465 | + ); |
|
466 | + // retrieve instantiated class |
|
467 | + return $this->_load($paths, 'EE_', $class_name, 'lib', $arguments, false, $cache, $load_only); |
|
468 | + } |
|
469 | + |
|
470 | + |
|
471 | + |
|
472 | + /** |
|
473 | + * loads model classes - must be singletons |
|
474 | + * |
|
475 | + * @param string $class_name - simple class name ie: price |
|
476 | + * @param mixed $arguments |
|
477 | + * @param bool $load_only |
|
478 | + * @return EEM_Base | bool |
|
479 | + */ |
|
480 | + public function load_model($class_name, $arguments = array(), $load_only = false) |
|
481 | + { |
|
482 | + $paths = apply_filters('FHEE__EE_Registry__load_model__paths', array( |
|
483 | + EE_MODELS, |
|
484 | + EE_CORE, |
|
485 | + )); |
|
486 | + // retrieve instantiated class |
|
487 | + return $this->_load($paths, 'EEM_', $class_name, 'model', $arguments, false, true, $load_only); |
|
488 | + } |
|
489 | + |
|
490 | + |
|
491 | + |
|
492 | + /** |
|
493 | + * loads model classes - must be singletons |
|
494 | + * |
|
495 | + * @param string $class_name - simple class name ie: price |
|
496 | + * @param mixed $arguments |
|
497 | + * @param bool $load_only |
|
498 | + * @return mixed | bool |
|
499 | + */ |
|
500 | + public function load_model_class($class_name, $arguments = array(), $load_only = true) |
|
501 | + { |
|
502 | + $paths = array( |
|
503 | + EE_MODELS . 'fields' . DS, |
|
504 | + EE_MODELS . 'helpers' . DS, |
|
505 | + EE_MODELS . 'relations' . DS, |
|
506 | + EE_MODELS . 'strategies' . DS, |
|
507 | + ); |
|
508 | + // retrieve instantiated class |
|
509 | + return $this->_load($paths, 'EE_', $class_name, '', $arguments, false, true, $load_only); |
|
510 | + } |
|
511 | + |
|
512 | + |
|
513 | + |
|
514 | + /** |
|
515 | + * Determines if $model_name is the name of an actual EE model. |
|
516 | + * |
|
517 | + * @param string $model_name like Event, Attendee, Question_Group_Question, etc. |
|
518 | + * @return boolean |
|
519 | + */ |
|
520 | + public function is_model_name($model_name) |
|
521 | + { |
|
522 | + return isset($this->models[$model_name]) ? true : false; |
|
523 | + } |
|
524 | + |
|
525 | + |
|
526 | + |
|
527 | + /** |
|
528 | + * generic class loader |
|
529 | + * |
|
530 | + * @param string $path_to_file - directory path to file location, not including filename |
|
531 | + * @param string $file_name - file name ie: my_file.php, including extension |
|
532 | + * @param string $type - file type - core? class? helper? model? |
|
533 | + * @param mixed $arguments |
|
534 | + * @param bool $load_only |
|
535 | + * @return mixed |
|
536 | + */ |
|
537 | + public function load_file($path_to_file, $file_name, $type = '', $arguments = array(), $load_only = true) |
|
538 | + { |
|
539 | + // retrieve instantiated class |
|
540 | + return $this->_load($path_to_file, '', $file_name, $type, $arguments, false, true, $load_only); |
|
541 | + } |
|
542 | + |
|
543 | + |
|
544 | + |
|
545 | + /** |
|
546 | + * load_addon |
|
547 | + * |
|
548 | + * @param string $path_to_file - directory path to file location, not including filename |
|
549 | + * @param string $class_name - full class name ie: My_Class |
|
550 | + * @param string $type - file type - core? class? helper? model? |
|
551 | + * @param mixed $arguments |
|
552 | + * @param bool $load_only |
|
553 | + * @return EE_Addon |
|
554 | + */ |
|
555 | + public function load_addon($path_to_file, $class_name, $type = 'class', $arguments = array(), $load_only = false) |
|
556 | + { |
|
557 | + // retrieve instantiated class |
|
558 | + return $this->_load($path_to_file, 'addon', $class_name, $type, $arguments, false, true, $load_only); |
|
559 | + } |
|
560 | + |
|
561 | + |
|
562 | + |
|
563 | + /** |
|
564 | + * instantiates, caches, and automatically resolves dependencies |
|
565 | + * for classes that use a Fully Qualified Class Name. |
|
566 | + * if the class is not capable of being loaded using PSR-4 autoloading, |
|
567 | + * then you need to use one of the existing load_*() methods |
|
568 | + * which can resolve the classname and filepath from the passed arguments |
|
569 | + * |
|
570 | + * @param bool|string $class_name Fully Qualified Class Name |
|
571 | + * @param array $arguments an argument, or array of arguments to pass to the class upon instantiation |
|
572 | + * @param bool $cache whether to cache the instantiated object for reuse |
|
573 | + * @param bool $from_db some classes are instantiated from the db |
|
574 | + * and thus call a different method to instantiate |
|
575 | + * @param bool $load_only if true, will only load the file, but will NOT instantiate an object |
|
576 | + * @param bool|string $addon if true, will cache the object in the EE_Registry->$addons array |
|
577 | + * @return mixed null = failure to load or instantiate class object. |
|
578 | + * object = class loaded and instantiated successfully. |
|
579 | + * bool = fail or success when $load_only is true |
|
580 | + */ |
|
581 | + public function create( |
|
582 | + $class_name = false, |
|
583 | + $arguments = array(), |
|
584 | + $cache = false, |
|
585 | + $from_db = false, |
|
586 | + $load_only = false, |
|
587 | + $addon = false |
|
588 | + ) { |
|
589 | + $class_name = ltrim($class_name, '\\'); |
|
590 | + $class_name = $this->_dependency_map->get_alias($class_name); |
|
591 | + if ( ! class_exists($class_name)) { |
|
592 | + // maybe the class is registered with a preceding \ |
|
593 | + $class_name = strpos($class_name, '\\') !== 0 ? '\\' . $class_name : $class_name; |
|
594 | + // still doesn't exist ? |
|
595 | + if ( ! class_exists($class_name)) { |
|
596 | + return null; |
|
597 | + } |
|
598 | + } |
|
599 | + // if we're only loading the class and it already exists, then let's just return true immediately |
|
600 | + if ($load_only) { |
|
601 | + return true; |
|
602 | + } |
|
603 | + $addon = $addon ? 'addon' : ''; |
|
604 | + // $this->_cache_on is toggled during the recursive loading that can occur with dependency injection |
|
605 | + // $cache is controlled by individual calls to separate Registry loader methods like load_class() |
|
606 | + // $load_only is also controlled by individual calls to separate Registry loader methods like load_file() |
|
607 | + if ($this->_cache_on && $cache && ! $load_only) { |
|
608 | + // return object if it's already cached |
|
609 | + $cached_class = $this->_get_cached_class($class_name, $addon); |
|
610 | + if ($cached_class !== null) { |
|
611 | + return $cached_class; |
|
612 | + } |
|
613 | + } |
|
614 | + // instantiate the requested object |
|
615 | + $class_obj = $this->_create_object($class_name, $arguments, $addon, $from_db); |
|
616 | + if ($this->_cache_on && $cache) { |
|
617 | + // save it for later... kinda like gum { : $ |
|
618 | + $this->_set_cached_class($class_obj, $class_name, $addon, $from_db); |
|
619 | + } |
|
620 | + $this->_cache_on = true; |
|
621 | + return $class_obj; |
|
622 | + } |
|
623 | + |
|
624 | + |
|
625 | + |
|
626 | + /** |
|
627 | + * instantiates, caches, and injects dependencies for classes |
|
628 | + * |
|
629 | + * @param array $file_paths an array of paths to folders to look in |
|
630 | + * @param string $class_prefix EE or EEM or... ??? |
|
631 | + * @param bool|string $class_name $class name |
|
632 | + * @param string $type file type - core? class? helper? model? |
|
633 | + * @param mixed $arguments an argument or array of arguments to pass to the class upon instantiation |
|
634 | + * @param bool $from_db some classes are instantiated from the db |
|
635 | + * and thus call a different method to instantiate |
|
636 | + * @param bool $cache whether to cache the instantiated object for reuse |
|
637 | + * @param bool $load_only if true, will only load the file, but will NOT instantiate an object |
|
638 | + * @return null|object|bool null = failure to load or instantiate class object. |
|
639 | + * object = class loaded and instantiated successfully. |
|
640 | + * bool = fail or success when $load_only is true |
|
641 | + */ |
|
642 | + protected function _load( |
|
643 | + $file_paths = array(), |
|
644 | + $class_prefix = 'EE_', |
|
645 | + $class_name = false, |
|
646 | + $type = 'class', |
|
647 | + $arguments = array(), |
|
648 | + $from_db = false, |
|
649 | + $cache = true, |
|
650 | + $load_only = false |
|
651 | + ) { |
|
652 | + $class_name = ltrim($class_name, '\\'); |
|
653 | + // strip php file extension |
|
654 | + $class_name = str_replace('.php', '', trim($class_name)); |
|
655 | + // does the class have a prefix ? |
|
656 | + if ( ! empty($class_prefix) && $class_prefix != 'addon') { |
|
657 | + // make sure $class_prefix is uppercase |
|
658 | + $class_prefix = strtoupper(trim($class_prefix)); |
|
659 | + // add class prefix ONCE!!! |
|
660 | + $class_name = $class_prefix . str_replace($class_prefix, '', $class_name); |
|
661 | + } |
|
662 | + $class_name = $this->_dependency_map->get_alias($class_name); |
|
663 | + $class_exists = class_exists($class_name); |
|
664 | + // if we're only loading the class and it already exists, then let's just return true immediately |
|
665 | + if ($load_only && $class_exists) { |
|
666 | + return true; |
|
667 | + } |
|
668 | + // $this->_cache_on is toggled during the recursive loading that can occur with dependency injection |
|
669 | + // $cache is controlled by individual calls to separate Registry loader methods like load_class() |
|
670 | + // $load_only is also controlled by individual calls to separate Registry loader methods like load_file() |
|
671 | + if ($this->_cache_on && $cache && ! $load_only) { |
|
672 | + // return object if it's already cached |
|
673 | + $cached_class = $this->_get_cached_class($class_name, $class_prefix); |
|
674 | + if ($cached_class !== null) { |
|
675 | + return $cached_class; |
|
676 | + } |
|
677 | + } |
|
678 | + // if the class doesn't already exist.. then we need to try and find the file and load it |
|
679 | + if ( ! $class_exists) { |
|
680 | + // get full path to file |
|
681 | + $path = $this->_resolve_path($class_name, $type, $file_paths); |
|
682 | + // load the file |
|
683 | + $loaded = $this->_require_file($path, $class_name, $type, $file_paths); |
|
684 | + // if loading failed, or we are only loading a file but NOT instantiating an object |
|
685 | + if ( ! $loaded || $load_only) { |
|
686 | + // return boolean if only loading, or null if an object was expected |
|
687 | + return $load_only ? $loaded : null; |
|
688 | + } |
|
689 | + } |
|
690 | + // instantiate the requested object |
|
691 | + $class_obj = $this->_create_object($class_name, $arguments, $type, $from_db); |
|
692 | + if ($this->_cache_on && $cache) { |
|
693 | + // save it for later... kinda like gum { : $ |
|
694 | + $this->_set_cached_class($class_obj, $class_name, $class_prefix, $from_db); |
|
695 | + } |
|
696 | + $this->_cache_on = true; |
|
697 | + return $class_obj; |
|
698 | + } |
|
699 | + |
|
700 | + |
|
701 | + |
|
702 | + /** |
|
703 | + * _get_cached_class |
|
704 | + * attempts to find a cached version of the requested class |
|
705 | + * by looking in the following places: |
|
706 | + * $this->{$class_abbreviation} ie: $this->CART |
|
707 | + * $this->{$class_name} ie: $this->Some_Class |
|
708 | + * $this->LIB->{$class_name} ie: $this->LIB->Some_Class |
|
709 | + * $this->addon->{$class_name} ie: $this->addon->Some_Addon_Class |
|
710 | + * |
|
711 | + * @access protected |
|
712 | + * @param string $class_name |
|
713 | + * @param string $class_prefix |
|
714 | + * @return mixed |
|
715 | + */ |
|
716 | + protected function _get_cached_class($class_name, $class_prefix = '') |
|
717 | + { |
|
718 | + if (isset($this->_class_abbreviations[$class_name])) { |
|
719 | + $class_abbreviation = $this->_class_abbreviations[$class_name]; |
|
720 | + } else { |
|
721 | + // have to specify something, but not anything that will conflict |
|
722 | + $class_abbreviation = 'FANCY_BATMAN_PANTS'; |
|
723 | + } |
|
724 | + // check if class has already been loaded, and return it if it has been |
|
725 | + if (isset($this->{$class_abbreviation}) && ! is_null($this->{$class_abbreviation})) { |
|
726 | + return $this->{$class_abbreviation}; |
|
727 | + } else if (isset ($this->{$class_name})) { |
|
728 | + return $this->{$class_name}; |
|
729 | + } else if (isset ($this->LIB->{$class_name})) { |
|
730 | + return $this->LIB->{$class_name}; |
|
731 | + } else if ($class_prefix == 'addon' && isset ($this->addons->{$class_name})) { |
|
732 | + return $this->addons->{$class_name}; |
|
733 | + } |
|
734 | + return null; |
|
735 | + } |
|
736 | + |
|
737 | + |
|
738 | + |
|
739 | + /** |
|
740 | + * _resolve_path |
|
741 | + * attempts to find a full valid filepath for the requested class. |
|
742 | + * loops thru each of the base paths in the $file_paths array and appends : "{classname} . {file type} . php" |
|
743 | + * then returns that path if the target file has been found and is readable |
|
744 | + * |
|
745 | + * @access protected |
|
746 | + * @param string $class_name |
|
747 | + * @param string $type |
|
748 | + * @param array $file_paths |
|
749 | + * @return string | bool |
|
750 | + */ |
|
751 | + protected function _resolve_path($class_name, $type = '', $file_paths = array()) |
|
752 | + { |
|
753 | + // make sure $file_paths is an array |
|
754 | + $file_paths = is_array($file_paths) ? $file_paths : array($file_paths); |
|
755 | + // cycle thru paths |
|
756 | + foreach ($file_paths as $key => $file_path) { |
|
757 | + // convert all separators to proper DS, if no filepath, then use EE_CLASSES |
|
758 | + $file_path = $file_path ? str_replace(array('/', '\\'), DS, $file_path) : EE_CLASSES; |
|
759 | + // prep file type |
|
760 | + $type = ! empty($type) ? trim($type, '.') . '.' : ''; |
|
761 | + // build full file path |
|
762 | + $file_paths[$key] = rtrim($file_path, DS) . DS . $class_name . '.' . $type . 'php'; |
|
763 | + //does the file exist and can be read ? |
|
764 | + if (is_readable($file_paths[$key])) { |
|
765 | + return $file_paths[$key]; |
|
766 | + } |
|
767 | + } |
|
768 | + return false; |
|
769 | + } |
|
770 | + |
|
771 | + |
|
772 | + |
|
773 | + /** |
|
774 | + * _require_file |
|
775 | + * basically just performs a require_once() |
|
776 | + * but with some error handling |
|
777 | + * |
|
778 | + * @access protected |
|
779 | + * @param string $path |
|
780 | + * @param string $class_name |
|
781 | + * @param string $type |
|
782 | + * @param array $file_paths |
|
783 | + * @return boolean |
|
784 | + * @throws \EE_Error |
|
785 | + */ |
|
786 | + protected function _require_file($path, $class_name, $type = '', $file_paths = array()) |
|
787 | + { |
|
788 | + // don't give up! you gotta... |
|
789 | + try { |
|
790 | + //does the file exist and can it be read ? |
|
791 | + if ( ! $path) { |
|
792 | + // so sorry, can't find the file |
|
793 | + throw new EE_Error ( |
|
794 | + sprintf( |
|
795 | + __('The %1$s file %2$s could not be located or is not readable due to file permissions. Please ensure that the following filepath(s) are correct: %3$s', 'event_espresso'), |
|
796 | + trim($type, '.'), |
|
797 | + $class_name, |
|
798 | + '<br />' . implode(',<br />', $file_paths) |
|
799 | + ) |
|
800 | + ); |
|
801 | + } |
|
802 | + // get the file |
|
803 | + require_once($path); |
|
804 | + // if the class isn't already declared somewhere |
|
805 | + if (class_exists($class_name, false) === false) { |
|
806 | + // so sorry, not a class |
|
807 | + throw new EE_Error( |
|
808 | + sprintf( |
|
809 | + __('The %s file %s does not appear to contain the %s Class.', 'event_espresso'), |
|
810 | + $type, |
|
811 | + $path, |
|
812 | + $class_name |
|
813 | + ) |
|
814 | + ); |
|
815 | + } |
|
816 | + } catch (EE_Error $e) { |
|
817 | + $e->get_error(); |
|
818 | + return false; |
|
819 | + } |
|
820 | + return true; |
|
821 | + } |
|
822 | + |
|
823 | + |
|
824 | + |
|
825 | + /** |
|
826 | + * _create_object |
|
827 | + * Attempts to instantiate the requested class via any of the |
|
828 | + * commonly used instantiation methods employed throughout EE. |
|
829 | + * The priority for instantiation is as follows: |
|
830 | + * - abstract classes or any class flagged as "load only" (no instantiation occurs) |
|
831 | + * - model objects via their 'new_instance_from_db' method |
|
832 | + * - model objects via their 'new_instance' method |
|
833 | + * - "singleton" classes" via their 'instance' method |
|
834 | + * - standard instantiable classes via their __constructor |
|
835 | + * Prior to instantiation, if the classname exists in the dependency_map, |
|
836 | + * then the constructor for the requested class will be examined to determine |
|
837 | + * if any dependencies exist, and if they can be injected. |
|
838 | + * If so, then those classes will be added to the array of arguments passed to the constructor |
|
839 | + * |
|
840 | + * @access protected |
|
841 | + * @param string $class_name |
|
842 | + * @param array $arguments |
|
843 | + * @param string $type |
|
844 | + * @param bool $from_db |
|
845 | + * @return null | object |
|
846 | + * @throws \EE_Error |
|
847 | + */ |
|
848 | + protected function _create_object($class_name, $arguments = array(), $type = '', $from_db = false) |
|
849 | + { |
|
850 | + $class_obj = null; |
|
851 | + $instantiation_mode = '0) none'; |
|
852 | + // don't give up! you gotta... |
|
853 | + try { |
|
854 | + // create reflection |
|
855 | + $reflector = $this->get_ReflectionClass($class_name); |
|
856 | + // make sure arguments are an array |
|
857 | + $arguments = is_array($arguments) ? $arguments : array($arguments); |
|
858 | + // and if arguments array is numerically and sequentially indexed, then we want it to remain as is, |
|
859 | + // else wrap it in an additional array so that it doesn't get split into multiple parameters |
|
860 | + $arguments = $this->_array_is_numerically_and_sequentially_indexed($arguments) |
|
861 | + ? $arguments |
|
862 | + : array($arguments); |
|
863 | + // attempt to inject dependencies ? |
|
864 | + if ($this->_dependency_map->has($class_name)) { |
|
865 | + $arguments = $this->_resolve_dependencies($reflector, $class_name, $arguments); |
|
866 | + } |
|
867 | + // instantiate the class if possible |
|
868 | + if ($reflector->isAbstract()) { |
|
869 | + // nothing to instantiate, loading file was enough |
|
870 | + // does not throw an exception so $instantiation_mode is unused |
|
871 | + // $instantiation_mode = "1) no constructor abstract class"; |
|
872 | + $class_obj = true; |
|
873 | + } else if ($reflector->getConstructor() === null && $reflector->isInstantiable() && empty($arguments)) { |
|
874 | + // no constructor = static methods only... nothing to instantiate, loading file was enough |
|
875 | + $instantiation_mode = "2) no constructor but instantiable"; |
|
876 | + $class_obj = $reflector->newInstance(); |
|
877 | + } else if ($from_db && method_exists($class_name, 'new_instance_from_db')) { |
|
878 | + $instantiation_mode = "3) new_instance_from_db()"; |
|
879 | + $class_obj = call_user_func_array(array($class_name, 'new_instance_from_db'), $arguments); |
|
880 | + } else if (method_exists($class_name, 'new_instance')) { |
|
881 | + $instantiation_mode = "4) new_instance()"; |
|
882 | + $class_obj = call_user_func_array(array($class_name, 'new_instance'), $arguments); |
|
883 | + } else if (method_exists($class_name, 'instance')) { |
|
884 | + $instantiation_mode = "5) instance()"; |
|
885 | + $class_obj = call_user_func_array(array($class_name, 'instance'), $arguments); |
|
886 | + } else if ($reflector->isInstantiable()) { |
|
887 | + $instantiation_mode = "6) constructor"; |
|
888 | + $class_obj = $reflector->newInstanceArgs($arguments); |
|
889 | + } else { |
|
890 | + // heh ? something's not right ! |
|
891 | + throw new EE_Error( |
|
892 | + sprintf( |
|
893 | + __('The %s file %s could not be instantiated.', 'event_espresso'), |
|
894 | + $type, |
|
895 | + $class_name |
|
896 | + ) |
|
897 | + ); |
|
898 | + } |
|
899 | + } catch (Exception $e) { |
|
900 | + if ( ! $e instanceof EE_Error) { |
|
901 | + $e = new EE_Error( |
|
902 | + sprintf( |
|
903 | + __('The following error occurred while attempting to instantiate "%1$s": %2$s %3$s %2$s instantiation mode : %4$s', 'event_espresso'), |
|
904 | + $class_name, |
|
905 | + '<br />', |
|
906 | + $e->getMessage(), |
|
907 | + $instantiation_mode |
|
908 | + ) |
|
909 | + ); |
|
910 | + } |
|
911 | + $e->get_error(); |
|
912 | + } |
|
913 | + return $class_obj; |
|
914 | + } |
|
915 | + |
|
916 | + |
|
917 | + |
|
918 | + /** |
|
919 | + * @see http://stackoverflow.com/questions/173400/how-to-check-if-php-array-is-associative-or-sequential |
|
920 | + * @param array $array |
|
921 | + * @return bool |
|
922 | + */ |
|
923 | + protected function _array_is_numerically_and_sequentially_indexed(array $array) |
|
924 | + { |
|
925 | + return ! empty($array) ? array_keys($array) === range(0, count($array) - 1) : true; |
|
926 | + } |
|
927 | + |
|
928 | + |
|
929 | + |
|
930 | + /** |
|
931 | + * getReflectionClass |
|
932 | + * checks if a ReflectionClass object has already been generated for a class |
|
933 | + * and returns that instead of creating a new one |
|
934 | + * |
|
935 | + * @access public |
|
936 | + * @param string $class_name |
|
937 | + * @return ReflectionClass |
|
938 | + */ |
|
939 | + public function get_ReflectionClass($class_name) |
|
940 | + { |
|
941 | + if ( |
|
942 | + ! isset($this->_reflectors[$class_name]) |
|
943 | + || ! $this->_reflectors[$class_name] instanceof ReflectionClass |
|
944 | + ) { |
|
945 | + $this->_reflectors[$class_name] = new ReflectionClass($class_name); |
|
946 | + } |
|
947 | + return $this->_reflectors[$class_name]; |
|
948 | + } |
|
949 | + |
|
950 | + |
|
951 | + |
|
952 | + /** |
|
953 | + * _resolve_dependencies |
|
954 | + * examines the constructor for the requested class to determine |
|
955 | + * if any dependencies exist, and if they can be injected. |
|
956 | + * If so, then those classes will be added to the array of arguments passed to the constructor |
|
957 | + * PLZ NOTE: this is achieved by type hinting the constructor params |
|
958 | + * For example: |
|
959 | + * if attempting to load a class "Foo" with the following constructor: |
|
960 | + * __construct( Bar $bar_class, Fighter $grohl_class ) |
|
961 | + * then $bar_class and $grohl_class will be added to the $arguments array, |
|
962 | + * but only IF they are NOT already present in the incoming arguments array, |
|
963 | + * and the correct classes can be loaded |
|
964 | + * |
|
965 | + * @access protected |
|
966 | + * @param ReflectionClass $reflector |
|
967 | + * @param string $class_name |
|
968 | + * @param array $arguments |
|
969 | + * @return array |
|
970 | + * @throws \ReflectionException |
|
971 | + */ |
|
972 | + protected function _resolve_dependencies(ReflectionClass $reflector, $class_name, $arguments = array()) |
|
973 | + { |
|
974 | + // let's examine the constructor |
|
975 | + $constructor = $reflector->getConstructor(); |
|
976 | + // whu? huh? nothing? |
|
977 | + if ( ! $constructor) { |
|
978 | + return $arguments; |
|
979 | + } |
|
980 | + // get constructor parameters |
|
981 | + $params = $constructor->getParameters(); |
|
982 | + // and the keys for the incoming arguments array so that we can compare existing arguments with what is expected |
|
983 | + $argument_keys = array_keys($arguments); |
|
984 | + // now loop thru all of the constructors expected parameters |
|
985 | + foreach ($params as $index => $param) { |
|
986 | + // is this a dependency for a specific class ? |
|
987 | + $param_class = $param->getClass() ? $param->getClass()->name : null; |
|
988 | + if ( |
|
989 | + // param is not even a class |
|
990 | + empty($param_class) |
|
991 | + // and something already exists in the incoming arguments for this param |
|
992 | + && isset($argument_keys[$index], $arguments[$argument_keys[$index]]) |
|
993 | + ) { |
|
994 | + // so let's skip this argument and move on to the next |
|
995 | + continue; |
|
996 | + } else if ( |
|
997 | + // parameter is type hinted as a class, exists as an incoming argument, AND it's the correct class |
|
998 | + ! empty($param_class) |
|
999 | + && isset($argument_keys[$index], $arguments[$argument_keys[$index]]) |
|
1000 | + && $arguments[$argument_keys[$index]] instanceof $param_class |
|
1001 | + ) { |
|
1002 | + // skip this argument and move on to the next |
|
1003 | + continue; |
|
1004 | + } else if ( |
|
1005 | + // parameter is type hinted as a class, and should be injected |
|
1006 | + ! empty($param_class) |
|
1007 | + && $this->_dependency_map->has_dependency_for_class($class_name, $param_class) |
|
1008 | + ) { |
|
1009 | + $arguments = $this->_resolve_dependency($class_name, $param_class, $arguments, $index); |
|
1010 | + } else { |
|
1011 | + try { |
|
1012 | + $arguments[$index] = $param->getDefaultValue(); |
|
1013 | + } catch (ReflectionException $e) { |
|
1014 | + throw new ReflectionException( |
|
1015 | + sprintf( |
|
1016 | + __('%1$s for parameter "$%2$s"', 'event_espresso'), |
|
1017 | + $e->getMessage(), |
|
1018 | + $param->getName() |
|
1019 | + ) |
|
1020 | + ); |
|
1021 | + } |
|
1022 | + } |
|
1023 | + } |
|
1024 | + return $arguments; |
|
1025 | + } |
|
1026 | + |
|
1027 | + |
|
1028 | + |
|
1029 | + /** |
|
1030 | + * @access protected |
|
1031 | + * @param string $class_name |
|
1032 | + * @param string $param_class |
|
1033 | + * @param array $arguments |
|
1034 | + * @param mixed $index |
|
1035 | + * @return array |
|
1036 | + */ |
|
1037 | + protected function _resolve_dependency($class_name, $param_class, $arguments, $index) |
|
1038 | + { |
|
1039 | + $dependency = null; |
|
1040 | + // should dependency be loaded from cache ? |
|
1041 | + $cache_on = $this->_dependency_map->loading_strategy_for_class_dependency($class_name, $param_class) |
|
1042 | + !== EE_Dependency_Map::load_new_object |
|
1043 | + ? true |
|
1044 | + : false; |
|
1045 | + // we might have a dependency... |
|
1046 | + // let's MAYBE try and find it in our cache if that's what's been requested |
|
1047 | + $cached_class = $cache_on ? $this->_get_cached_class($param_class) : null; |
|
1048 | + // and grab it if it exists |
|
1049 | + if ($cached_class instanceof $param_class) { |
|
1050 | + $dependency = $cached_class; |
|
1051 | + } else if ($param_class != $class_name) { |
|
1052 | + // obtain the loader method from the dependency map |
|
1053 | + $loader = $this->_dependency_map->class_loader($param_class); |
|
1054 | + // is loader a custom closure ? |
|
1055 | + if ($loader instanceof Closure) { |
|
1056 | + $dependency = $loader(); |
|
1057 | + } else { |
|
1058 | + // set the cache on property for the recursive loading call |
|
1059 | + $this->_cache_on = $cache_on; |
|
1060 | + // if not, then let's try and load it via the registry |
|
1061 | + if (method_exists($this, $loader)) { |
|
1062 | + $dependency = $this->{$loader}($param_class); |
|
1063 | + } else { |
|
1064 | + $dependency = $this->create($param_class, array(), $cache_on); |
|
1065 | + } |
|
1066 | + } |
|
1067 | + } |
|
1068 | + // did we successfully find the correct dependency ? |
|
1069 | + if ($dependency instanceof $param_class) { |
|
1070 | + // then let's inject it into the incoming array of arguments at the correct location |
|
1071 | + if (isset($argument_keys[$index])) { |
|
1072 | + $arguments[$argument_keys[$index]] = $dependency; |
|
1073 | + } else { |
|
1074 | + $arguments[$index] = $dependency; |
|
1075 | + } |
|
1076 | + } |
|
1077 | + return $arguments; |
|
1078 | + } |
|
1079 | + |
|
1080 | + |
|
1081 | + |
|
1082 | + /** |
|
1083 | + * _set_cached_class |
|
1084 | + * attempts to cache the instantiated class locally |
|
1085 | + * in one of the following places, in the following order: |
|
1086 | + * $this->{class_abbreviation} ie: $this->CART |
|
1087 | + * $this->{$class_name} ie: $this->Some_Class |
|
1088 | + * $this->addon->{$$class_name} ie: $this->addon->Some_Addon_Class |
|
1089 | + * $this->LIB->{$class_name} ie: $this->LIB->Some_Class |
|
1090 | + * |
|
1091 | + * @access protected |
|
1092 | + * @param object $class_obj |
|
1093 | + * @param string $class_name |
|
1094 | + * @param string $class_prefix |
|
1095 | + * @param bool $from_db |
|
1096 | + * @return void |
|
1097 | + */ |
|
1098 | + protected function _set_cached_class($class_obj, $class_name, $class_prefix = '', $from_db = false) |
|
1099 | + { |
|
1100 | + if (empty($class_obj)) { |
|
1101 | + return; |
|
1102 | + } |
|
1103 | + // return newly instantiated class |
|
1104 | + if (isset($this->_class_abbreviations[$class_name])) { |
|
1105 | + $class_abbreviation = $this->_class_abbreviations[$class_name]; |
|
1106 | + $this->{$class_abbreviation} = $class_obj; |
|
1107 | + } else if (property_exists($this, $class_name)) { |
|
1108 | + $this->{$class_name} = $class_obj; |
|
1109 | + } else if ($class_prefix == 'addon') { |
|
1110 | + $this->addons->{$class_name} = $class_obj; |
|
1111 | + } else if ( ! $from_db) { |
|
1112 | + $this->LIB->{$class_name} = $class_obj; |
|
1113 | + } |
|
1114 | + } |
|
1115 | + |
|
1116 | + |
|
1117 | + |
|
1118 | + /** |
|
1119 | + * call any loader that's been registered in the EE_Dependency_Map::$_class_loaders array |
|
1120 | + * |
|
1121 | + * @param string $classname PLEASE NOTE: the class name needs to match what's registered |
|
1122 | + * in the EE_Dependency_Map::$_class_loaders array, |
|
1123 | + * including the class prefix, ie: "EE_", "EEM_", "EEH_", etc |
|
1124 | + * @param array $arguments |
|
1125 | + * @return object |
|
1126 | + */ |
|
1127 | + public static function factory($classname, $arguments = array()) |
|
1128 | + { |
|
1129 | + $loader = self::instance()->_dependency_map->class_loader($classname); |
|
1130 | + if ($loader instanceof Closure) { |
|
1131 | + return $loader($arguments); |
|
1132 | + } else if (method_exists(EE_Registry::instance(), $loader)) { |
|
1133 | + return EE_Registry::instance()->{$loader}($classname, $arguments); |
|
1134 | + } |
|
1135 | + return null; |
|
1136 | + } |
|
1137 | + |
|
1138 | + |
|
1139 | + |
|
1140 | + /** |
|
1141 | + * Gets the addon by its name/slug (not classname. For that, just |
|
1142 | + * use the classname as the property name on EE_Config::instance()->addons) |
|
1143 | + * |
|
1144 | + * @param string $name |
|
1145 | + * @return EE_Addon |
|
1146 | + */ |
|
1147 | + public function get_addon_by_name($name) |
|
1148 | + { |
|
1149 | + foreach ($this->addons as $addon) { |
|
1150 | + if ($addon->name() == $name) { |
|
1151 | + return $addon; |
|
1152 | + } |
|
1153 | + } |
|
1154 | + return null; |
|
1155 | + } |
|
1156 | + |
|
1157 | + |
|
1158 | + |
|
1159 | + /** |
|
1160 | + * Gets an array of all the registered addons, where the keys are their names. (ie, what each returns for their name() function) They're already available on EE_Config::instance()->addons as properties, where each property's name is |
|
1161 | + * the addon's classname. So if you just want to get the addon by classname, use EE_Config::instance()->addons->{classname} |
|
1162 | + * |
|
1163 | + * @return EE_Addon[] where the KEYS are the addon's name() |
|
1164 | + */ |
|
1165 | + public function get_addons_by_name() |
|
1166 | + { |
|
1167 | + $addons = array(); |
|
1168 | + foreach ($this->addons as $addon) { |
|
1169 | + $addons[$addon->name()] = $addon; |
|
1170 | + } |
|
1171 | + return $addons; |
|
1172 | + } |
|
1173 | + |
|
1174 | + |
|
1175 | + |
|
1176 | + /** |
|
1177 | + * Resets the specified model's instance AND makes sure EE_Registry doesn't keep |
|
1178 | + * a stale copy of it around |
|
1179 | + * |
|
1180 | + * @param string $model_name |
|
1181 | + * @return \EEM_Base |
|
1182 | + * @throws \EE_Error |
|
1183 | + */ |
|
1184 | + public function reset_model($model_name) |
|
1185 | + { |
|
1186 | + $model_class_name = strpos($model_name, 'EEM_') !== 0 ? "EEM_{$model_name}" : $model_name; |
|
1187 | + if ( ! isset($this->LIB->{$model_class_name}) || ! $this->LIB->{$model_class_name} instanceof EEM_Base) { |
|
1188 | + return null; |
|
1189 | + } |
|
1190 | + //get that model reset it and make sure we nuke the old reference to it |
|
1191 | + if ($this->LIB->{$model_class_name} instanceof $model_class_name && is_callable(array($model_class_name, 'reset'))) { |
|
1192 | + $this->LIB->{$model_class_name} = $this->LIB->{$model_class_name}->reset(); |
|
1193 | + } else { |
|
1194 | + throw new EE_Error(sprintf(__('Model %s does not have a method "reset"', 'event_espresso'), $model_name)); |
|
1195 | + } |
|
1196 | + return $this->LIB->{$model_class_name}; |
|
1197 | + } |
|
1198 | + |
|
1199 | + |
|
1200 | + |
|
1201 | + /** |
|
1202 | + * Resets the registry. |
|
1203 | + * The criteria for what gets reset is based on what can be shared between sites on the same request when switch_to_blog |
|
1204 | + * is used in a multisite install. Here is a list of things that are NOT reset. |
|
1205 | + * - $_dependency_map |
|
1206 | + * - $_class_abbreviations |
|
1207 | + * - $NET_CFG (EE_Network_Config): The config is shared network wide so no need to reset. |
|
1208 | + * - $REQ: Still on the same request so no need to change. |
|
1209 | + * - $CAP: There is no site specific state in the EE_Capability class. |
|
1210 | + * - $SSN: Although ideally, the session should not be shared between site switches, we can't reset it because only one Session |
|
1211 | + * can be active in a single request. Resetting could resolve in "headers already sent" errors. |
|
1212 | + * - $addons: In multisite, the state of the addons is something controlled via hooks etc in a normal request. So |
|
1213 | + * for now, we won't reset the addons because it could break calls to an add-ons class/methods in the |
|
1214 | + * switch or on the restore. |
|
1215 | + * - $modules |
|
1216 | + * - $shortcodes |
|
1217 | + * - $widgets |
|
1218 | + * |
|
1219 | + * @param boolean $hard whether to reset data in the database too, or just refresh |
|
1220 | + * the Registry to its state at the beginning of the request |
|
1221 | + * @param boolean $reinstantiate whether to create new instances of EE_Registry's singletons too, |
|
1222 | + * or just reset without re-instantiating (handy to set to FALSE if you're not sure if you CAN |
|
1223 | + * currently reinstantiate the singletons at the moment) |
|
1224 | + * @param bool $reset_models Defaults to true. When false, then the models are not reset. This is so client |
|
1225 | + * code instead can just change the model context to a different blog id if necessary |
|
1226 | + * @return EE_Registry |
|
1227 | + */ |
|
1228 | + public static function reset($hard = false, $reinstantiate = true, $reset_models = true) |
|
1229 | + { |
|
1230 | + $instance = self::instance(); |
|
1231 | + EEH_Activation::reset(); |
|
1232 | + //properties that get reset |
|
1233 | + $instance->_cache_on = true; |
|
1234 | + $instance->CFG = EE_Config::reset($hard, $reinstantiate); |
|
1235 | + $instance->CART = null; |
|
1236 | + $instance->MRM = null; |
|
1237 | + $instance->AssetsRegistry = new Registry(); |
|
1238 | + //messages reset |
|
1239 | + EED_Messages::reset(); |
|
1240 | + if ($reset_models) { |
|
1241 | + foreach (array_keys($instance->non_abstract_db_models) as $model_name) { |
|
1242 | + $instance->reset_model($model_name); |
|
1243 | + } |
|
1244 | + } |
|
1245 | + $instance->LIB = new stdClass(); |
|
1246 | + return $instance; |
|
1247 | + } |
|
1248 | + |
|
1249 | + |
|
1250 | + |
|
1251 | + /** |
|
1252 | + * @override magic methods |
|
1253 | + * @return void |
|
1254 | + */ |
|
1255 | + final function __destruct() |
|
1256 | + { |
|
1257 | + } |
|
1258 | + |
|
1259 | + |
|
1260 | + |
|
1261 | + /** |
|
1262 | + * @param $a |
|
1263 | + * @param $b |
|
1264 | + */ |
|
1265 | + final function __call($a, $b) |
|
1266 | + { |
|
1267 | + } |
|
1268 | + |
|
1269 | + |
|
1270 | + |
|
1271 | + /** |
|
1272 | + * @param $a |
|
1273 | + */ |
|
1274 | + final function __get($a) |
|
1275 | + { |
|
1276 | + } |
|
1277 | + |
|
1278 | + |
|
1279 | + |
|
1280 | + /** |
|
1281 | + * @param $a |
|
1282 | + * @param $b |
|
1283 | + */ |
|
1284 | + final function __set($a, $b) |
|
1285 | + { |
|
1286 | + } |
|
1287 | + |
|
1288 | + |
|
1289 | + |
|
1290 | + /** |
|
1291 | + * @param $a |
|
1292 | + */ |
|
1293 | + final function __isset($a) |
|
1294 | + { |
|
1295 | + } |
|
1296 | 1296 | |
1297 | 1297 | |
1298 | 1298 | |
1299 | - /** |
|
1300 | - * @param $a |
|
1301 | - */ |
|
1302 | - final function __unset($a) |
|
1303 | - { |
|
1304 | - } |
|
1299 | + /** |
|
1300 | + * @param $a |
|
1301 | + */ |
|
1302 | + final function __unset($a) |
|
1303 | + { |
|
1304 | + } |
|
1305 | 1305 | |
1306 | 1306 | |
1307 | 1307 | |
1308 | - /** |
|
1309 | - * @return array |
|
1310 | - */ |
|
1311 | - final function __sleep() |
|
1312 | - { |
|
1313 | - return array(); |
|
1314 | - } |
|
1308 | + /** |
|
1309 | + * @return array |
|
1310 | + */ |
|
1311 | + final function __sleep() |
|
1312 | + { |
|
1313 | + return array(); |
|
1314 | + } |
|
1315 | 1315 | |
1316 | 1316 | |
1317 | 1317 | |
1318 | - final function __wakeup() |
|
1319 | - { |
|
1320 | - } |
|
1318 | + final function __wakeup() |
|
1319 | + { |
|
1320 | + } |
|
1321 | 1321 | |
1322 | 1322 | |
1323 | 1323 | |
1324 | - /** |
|
1325 | - * @return string |
|
1326 | - */ |
|
1327 | - final function __toString() |
|
1328 | - { |
|
1329 | - return ''; |
|
1330 | - } |
|
1324 | + /** |
|
1325 | + * @return string |
|
1326 | + */ |
|
1327 | + final function __toString() |
|
1328 | + { |
|
1329 | + return ''; |
|
1330 | + } |
|
1331 | 1331 | |
1332 | 1332 | |
1333 | 1333 | |
1334 | - final function __invoke() |
|
1335 | - { |
|
1336 | - } |
|
1334 | + final function __invoke() |
|
1335 | + { |
|
1336 | + } |
|
1337 | 1337 | |
1338 | 1338 | |
1339 | 1339 | |
1340 | - final static function __set_state() |
|
1341 | - { |
|
1342 | - } |
|
1340 | + final static function __set_state() |
|
1341 | + { |
|
1342 | + } |
|
1343 | 1343 | |
1344 | 1344 | |
1345 | 1345 | |
1346 | - final function __clone() |
|
1347 | - { |
|
1348 | - } |
|
1346 | + final function __clone() |
|
1347 | + { |
|
1348 | + } |
|
1349 | 1349 | |
1350 | 1350 | |
1351 | 1351 | |
1352 | - /** |
|
1353 | - * @param $a |
|
1354 | - * @param $b |
|
1355 | - */ |
|
1356 | - final static function __callStatic($a, $b) |
|
1357 | - { |
|
1358 | - } |
|
1352 | + /** |
|
1353 | + * @param $a |
|
1354 | + * @param $b |
|
1355 | + */ |
|
1356 | + final static function __callStatic($a, $b) |
|
1357 | + { |
|
1358 | + } |
|
1359 | 1359 | |
1360 | 1360 | |
1361 | 1361 | |
1362 | - /** |
|
1363 | - * Gets all the custom post type models defined |
|
1364 | - * |
|
1365 | - * @return array keys are model "short names" (Eg "Event") and keys are classnames (eg "EEM_Event") |
|
1366 | - */ |
|
1367 | - public function cpt_models() |
|
1368 | - { |
|
1369 | - $cpt_models = array(); |
|
1370 | - foreach ($this->non_abstract_db_models as $short_name => $classname) { |
|
1371 | - if (is_subclass_of($classname, 'EEM_CPT_Base')) { |
|
1372 | - $cpt_models[$short_name] = $classname; |
|
1373 | - } |
|
1374 | - } |
|
1375 | - return $cpt_models; |
|
1376 | - } |
|
1362 | + /** |
|
1363 | + * Gets all the custom post type models defined |
|
1364 | + * |
|
1365 | + * @return array keys are model "short names" (Eg "Event") and keys are classnames (eg "EEM_Event") |
|
1366 | + */ |
|
1367 | + public function cpt_models() |
|
1368 | + { |
|
1369 | + $cpt_models = array(); |
|
1370 | + foreach ($this->non_abstract_db_models as $short_name => $classname) { |
|
1371 | + if (is_subclass_of($classname, 'EEM_CPT_Base')) { |
|
1372 | + $cpt_models[$short_name] = $classname; |
|
1373 | + } |
|
1374 | + } |
|
1375 | + return $cpt_models; |
|
1376 | + } |
|
1377 | 1377 | |
1378 | 1378 | |
1379 | 1379 | |
1380 | - /** |
|
1381 | - * @return \EE_Config |
|
1382 | - */ |
|
1383 | - public static function CFG() |
|
1384 | - { |
|
1385 | - return self::instance()->CFG; |
|
1386 | - } |
|
1380 | + /** |
|
1381 | + * @return \EE_Config |
|
1382 | + */ |
|
1383 | + public static function CFG() |
|
1384 | + { |
|
1385 | + return self::instance()->CFG; |
|
1386 | + } |
|
1387 | 1387 | |
1388 | 1388 | |
1389 | 1389 | } |
@@ -63,7 +63,7 @@ discard block |
||
63 | 63 | } |
64 | 64 | } |
65 | 65 | return $this->shortcodeContent( |
66 | - $this->sanitizeAttributes((array)$attributes) |
|
66 | + $this->sanitizeAttributes((array) $attributes) |
|
67 | 67 | ); |
68 | 68 | } |
69 | 69 | |
@@ -91,7 +91,7 @@ discard block |
||
91 | 91 | // serialized attributes |
92 | 92 | wp_json_encode($attributes), |
93 | 93 | // Closure for generating content if cache is expired |
94 | - function () use ($shortcode, $attributes) { |
|
94 | + function() use ($shortcode, $attributes) { |
|
95 | 95 | return $shortcode->processShortcode($attributes); |
96 | 96 | }, |
97 | 97 | // filterable cache expiration set by each shortcode |
@@ -20,198 +20,198 @@ |
||
20 | 20 | abstract class EspressoShortcode implements ShortcodeInterface |
21 | 21 | { |
22 | 22 | |
23 | - /** |
|
24 | - * transient prefix |
|
25 | - * |
|
26 | - * @type string |
|
27 | - */ |
|
28 | - const CACHE_TRANSIENT_PREFIX = 'ee_sc_'; |
|
29 | - |
|
30 | - /** |
|
31 | - * @var PostRelatedCacheManager $cache_manager |
|
32 | - */ |
|
33 | - private $cache_manager; |
|
34 | - |
|
35 | - |
|
36 | - |
|
37 | - /** |
|
38 | - * EspressoShortcode constructor |
|
39 | - * |
|
40 | - * @param PostRelatedCacheManager $cache_manager |
|
41 | - */ |
|
42 | - public function __construct(PostRelatedCacheManager $cache_manager) |
|
43 | - { |
|
44 | - $this->cache_manager = $cache_manager; |
|
45 | - } |
|
46 | - |
|
47 | - |
|
48 | - |
|
49 | - /** |
|
50 | - * enqueues scripts then processes the shortcode |
|
51 | - * |
|
52 | - * @param array $attributes |
|
53 | - * @return string |
|
54 | - * @throws \EE_Error |
|
55 | - */ |
|
56 | - final public function processShortcodeCallback($attributes = array()) |
|
57 | - { |
|
58 | - if ($this instanceof EnqueueAssetsInterface) { |
|
59 | - if (is_admin()) { |
|
60 | - $this->enqueueAdminScripts(); |
|
61 | - } else { |
|
62 | - $this->enqueueScripts(); |
|
63 | - } |
|
64 | - } |
|
65 | - return $this->shortcodeContent( |
|
66 | - $this->sanitizeAttributes((array)$attributes) |
|
67 | - ); |
|
68 | - } |
|
69 | - |
|
70 | - |
|
71 | - |
|
72 | - /** |
|
73 | - * If shortcode caching is enabled for the shortcode, |
|
74 | - * and cached results exist, then that will be returned |
|
75 | - * else new content will be generated. |
|
76 | - * If caching is enabled, then the new content will be cached for later. |
|
77 | - * |
|
78 | - * @param array $attributes |
|
79 | - * @return mixed|string |
|
80 | - * @throws \EE_Error |
|
81 | - */ |
|
82 | - private function shortcodeContent(array $attributes) |
|
83 | - { |
|
84 | - $shortcode = $this; |
|
85 | - $post_ID = $this->currentPostID(); |
|
86 | - // something like "SC_EVENTS-123" |
|
87 | - $cache_ID = $this->shortcodeCacheID($post_ID); |
|
88 | - $this->cache_manager->clearPostRelatedCacheOnUpdate($post_ID, $cache_ID); |
|
89 | - return $this->cache_manager->get( |
|
90 | - $cache_ID, |
|
91 | - // serialized attributes |
|
92 | - wp_json_encode($attributes), |
|
93 | - // Closure for generating content if cache is expired |
|
94 | - function () use ($shortcode, $attributes) { |
|
95 | - return $shortcode->processShortcode($attributes); |
|
96 | - }, |
|
97 | - // filterable cache expiration set by each shortcode |
|
98 | - apply_filters( |
|
99 | - 'FHEE__EventEspresso_core_services_shortcodes_EspressoShortcode__shortcodeContent__cache_expiration', |
|
100 | - $this->cacheExpiration(), |
|
101 | - $this->getTag(), |
|
102 | - $this |
|
103 | - ) |
|
104 | - ); |
|
105 | - } |
|
106 | - |
|
107 | - |
|
108 | - |
|
109 | - /** |
|
110 | - * @return int |
|
111 | - * @throws \EE_Error |
|
112 | - */ |
|
113 | - private function currentPostID() |
|
114 | - { |
|
115 | - // try to get EE_Event any way we can |
|
116 | - $event = EEH_Event_View::get_event(); |
|
117 | - // then get some kind of ID |
|
118 | - if ($event instanceof \EE_Event) { |
|
119 | - $post_ID = $event->ID(); |
|
120 | - } else { |
|
121 | - global $post; |
|
122 | - $post_ID = $post->ID; |
|
123 | - } |
|
124 | - return $post_ID; |
|
125 | - } |
|
126 | - |
|
127 | - |
|
128 | - |
|
129 | - /** |
|
130 | - * @param int $post_ID |
|
131 | - * @return string |
|
132 | - * @throws \EE_Error |
|
133 | - */ |
|
134 | - private function shortcodeCacheID($post_ID) |
|
135 | - { |
|
136 | - $tag = str_replace('ESPRESSO_', '', $this->getTag()); |
|
137 | - return "SC_{$tag}-{$post_ID}"; |
|
138 | - } |
|
139 | - |
|
140 | - |
|
141 | - |
|
142 | - /** |
|
143 | - * array for defining custom attribute sanitization callbacks, |
|
144 | - * where keys match keys in your attributes array, |
|
145 | - * and values represent the sanitization function you wish to be applied to that attribute. |
|
146 | - * So for example, if you had an integer attribute named "event_id" |
|
147 | - * that you wanted to be sanitized using absint(), |
|
148 | - * then you would return the following: |
|
149 | - * array('event_id' => 'absint') |
|
150 | - * Entering 'skip_sanitization' for the callback value |
|
151 | - * means that no sanitization will be applied |
|
152 | - * on the assumption that the attribute |
|
153 | - * will be sanitized at some point... right? |
|
154 | - * You wouldn't pass around unsanitized attributes would you? |
|
155 | - * That would be very Tom Foolery of you!!! |
|
156 | - * |
|
157 | - * @return array |
|
158 | - */ |
|
159 | - protected function customAttributeSanitizationMap() |
|
160 | - { |
|
161 | - return array(); |
|
162 | - } |
|
163 | - |
|
164 | - |
|
165 | - |
|
166 | - /** |
|
167 | - * Performs basic sanitization on shortcode attributes |
|
168 | - * Since incoming attributes from the shortcode usage in the WP editor will all be strings, |
|
169 | - * most attributes will by default be sanitized using the sanitize_text_field() function. |
|
170 | - * This can be overridden using the customAttributeSanitizationMap() method (see above), |
|
171 | - * all other attributes would be sanitized using the defaults in the switch statement below |
|
172 | - * |
|
173 | - * @param array $attributes |
|
174 | - * @return array |
|
175 | - */ |
|
176 | - private function sanitizeAttributes(array $attributes) |
|
177 | - { |
|
178 | - $custom_sanitization = $this->customAttributeSanitizationMap(); |
|
179 | - foreach ($attributes as $key => $value) { |
|
180 | - // is a custom sanitization callback specified ? |
|
181 | - if (isset($custom_sanitization[$key])) { |
|
182 | - $callback = $custom_sanitization[$key]; |
|
183 | - if ($callback === 'skip_sanitization') { |
|
184 | - $attributes[$key] = $value; |
|
185 | - continue; |
|
186 | - } |
|
187 | - if (function_exists($callback)) { |
|
188 | - $attributes[$key] = $callback($value); |
|
189 | - continue; |
|
190 | - } |
|
191 | - } |
|
192 | - switch (true) { |
|
193 | - case $value === null : |
|
194 | - case is_int($value) : |
|
195 | - case is_float($value) : |
|
196 | - // typical booleans |
|
197 | - case in_array($value, array(true, 'true', '1', 'on', 'yes', false, 'false', '0', 'off', 'no'), true) : |
|
198 | - $attributes[$key] = $value; |
|
199 | - break; |
|
200 | - case is_string($value) : |
|
201 | - $attributes[$key] = sanitize_text_field($value); |
|
202 | - break; |
|
203 | - case is_array($value) : |
|
204 | - $attributes[$key] = $this->sanitizeAttributes($value); |
|
205 | - break; |
|
206 | - default : |
|
207 | - // only remaining data types are Object and Resource |
|
208 | - // which are not allowed as shortcode attributes |
|
209 | - $attributes[$key] = null; |
|
210 | - break; |
|
211 | - } |
|
212 | - } |
|
213 | - return $attributes; |
|
214 | - } |
|
23 | + /** |
|
24 | + * transient prefix |
|
25 | + * |
|
26 | + * @type string |
|
27 | + */ |
|
28 | + const CACHE_TRANSIENT_PREFIX = 'ee_sc_'; |
|
29 | + |
|
30 | + /** |
|
31 | + * @var PostRelatedCacheManager $cache_manager |
|
32 | + */ |
|
33 | + private $cache_manager; |
|
34 | + |
|
35 | + |
|
36 | + |
|
37 | + /** |
|
38 | + * EspressoShortcode constructor |
|
39 | + * |
|
40 | + * @param PostRelatedCacheManager $cache_manager |
|
41 | + */ |
|
42 | + public function __construct(PostRelatedCacheManager $cache_manager) |
|
43 | + { |
|
44 | + $this->cache_manager = $cache_manager; |
|
45 | + } |
|
46 | + |
|
47 | + |
|
48 | + |
|
49 | + /** |
|
50 | + * enqueues scripts then processes the shortcode |
|
51 | + * |
|
52 | + * @param array $attributes |
|
53 | + * @return string |
|
54 | + * @throws \EE_Error |
|
55 | + */ |
|
56 | + final public function processShortcodeCallback($attributes = array()) |
|
57 | + { |
|
58 | + if ($this instanceof EnqueueAssetsInterface) { |
|
59 | + if (is_admin()) { |
|
60 | + $this->enqueueAdminScripts(); |
|
61 | + } else { |
|
62 | + $this->enqueueScripts(); |
|
63 | + } |
|
64 | + } |
|
65 | + return $this->shortcodeContent( |
|
66 | + $this->sanitizeAttributes((array)$attributes) |
|
67 | + ); |
|
68 | + } |
|
69 | + |
|
70 | + |
|
71 | + |
|
72 | + /** |
|
73 | + * If shortcode caching is enabled for the shortcode, |
|
74 | + * and cached results exist, then that will be returned |
|
75 | + * else new content will be generated. |
|
76 | + * If caching is enabled, then the new content will be cached for later. |
|
77 | + * |
|
78 | + * @param array $attributes |
|
79 | + * @return mixed|string |
|
80 | + * @throws \EE_Error |
|
81 | + */ |
|
82 | + private function shortcodeContent(array $attributes) |
|
83 | + { |
|
84 | + $shortcode = $this; |
|
85 | + $post_ID = $this->currentPostID(); |
|
86 | + // something like "SC_EVENTS-123" |
|
87 | + $cache_ID = $this->shortcodeCacheID($post_ID); |
|
88 | + $this->cache_manager->clearPostRelatedCacheOnUpdate($post_ID, $cache_ID); |
|
89 | + return $this->cache_manager->get( |
|
90 | + $cache_ID, |
|
91 | + // serialized attributes |
|
92 | + wp_json_encode($attributes), |
|
93 | + // Closure for generating content if cache is expired |
|
94 | + function () use ($shortcode, $attributes) { |
|
95 | + return $shortcode->processShortcode($attributes); |
|
96 | + }, |
|
97 | + // filterable cache expiration set by each shortcode |
|
98 | + apply_filters( |
|
99 | + 'FHEE__EventEspresso_core_services_shortcodes_EspressoShortcode__shortcodeContent__cache_expiration', |
|
100 | + $this->cacheExpiration(), |
|
101 | + $this->getTag(), |
|
102 | + $this |
|
103 | + ) |
|
104 | + ); |
|
105 | + } |
|
106 | + |
|
107 | + |
|
108 | + |
|
109 | + /** |
|
110 | + * @return int |
|
111 | + * @throws \EE_Error |
|
112 | + */ |
|
113 | + private function currentPostID() |
|
114 | + { |
|
115 | + // try to get EE_Event any way we can |
|
116 | + $event = EEH_Event_View::get_event(); |
|
117 | + // then get some kind of ID |
|
118 | + if ($event instanceof \EE_Event) { |
|
119 | + $post_ID = $event->ID(); |
|
120 | + } else { |
|
121 | + global $post; |
|
122 | + $post_ID = $post->ID; |
|
123 | + } |
|
124 | + return $post_ID; |
|
125 | + } |
|
126 | + |
|
127 | + |
|
128 | + |
|
129 | + /** |
|
130 | + * @param int $post_ID |
|
131 | + * @return string |
|
132 | + * @throws \EE_Error |
|
133 | + */ |
|
134 | + private function shortcodeCacheID($post_ID) |
|
135 | + { |
|
136 | + $tag = str_replace('ESPRESSO_', '', $this->getTag()); |
|
137 | + return "SC_{$tag}-{$post_ID}"; |
|
138 | + } |
|
139 | + |
|
140 | + |
|
141 | + |
|
142 | + /** |
|
143 | + * array for defining custom attribute sanitization callbacks, |
|
144 | + * where keys match keys in your attributes array, |
|
145 | + * and values represent the sanitization function you wish to be applied to that attribute. |
|
146 | + * So for example, if you had an integer attribute named "event_id" |
|
147 | + * that you wanted to be sanitized using absint(), |
|
148 | + * then you would return the following: |
|
149 | + * array('event_id' => 'absint') |
|
150 | + * Entering 'skip_sanitization' for the callback value |
|
151 | + * means that no sanitization will be applied |
|
152 | + * on the assumption that the attribute |
|
153 | + * will be sanitized at some point... right? |
|
154 | + * You wouldn't pass around unsanitized attributes would you? |
|
155 | + * That would be very Tom Foolery of you!!! |
|
156 | + * |
|
157 | + * @return array |
|
158 | + */ |
|
159 | + protected function customAttributeSanitizationMap() |
|
160 | + { |
|
161 | + return array(); |
|
162 | + } |
|
163 | + |
|
164 | + |
|
165 | + |
|
166 | + /** |
|
167 | + * Performs basic sanitization on shortcode attributes |
|
168 | + * Since incoming attributes from the shortcode usage in the WP editor will all be strings, |
|
169 | + * most attributes will by default be sanitized using the sanitize_text_field() function. |
|
170 | + * This can be overridden using the customAttributeSanitizationMap() method (see above), |
|
171 | + * all other attributes would be sanitized using the defaults in the switch statement below |
|
172 | + * |
|
173 | + * @param array $attributes |
|
174 | + * @return array |
|
175 | + */ |
|
176 | + private function sanitizeAttributes(array $attributes) |
|
177 | + { |
|
178 | + $custom_sanitization = $this->customAttributeSanitizationMap(); |
|
179 | + foreach ($attributes as $key => $value) { |
|
180 | + // is a custom sanitization callback specified ? |
|
181 | + if (isset($custom_sanitization[$key])) { |
|
182 | + $callback = $custom_sanitization[$key]; |
|
183 | + if ($callback === 'skip_sanitization') { |
|
184 | + $attributes[$key] = $value; |
|
185 | + continue; |
|
186 | + } |
|
187 | + if (function_exists($callback)) { |
|
188 | + $attributes[$key] = $callback($value); |
|
189 | + continue; |
|
190 | + } |
|
191 | + } |
|
192 | + switch (true) { |
|
193 | + case $value === null : |
|
194 | + case is_int($value) : |
|
195 | + case is_float($value) : |
|
196 | + // typical booleans |
|
197 | + case in_array($value, array(true, 'true', '1', 'on', 'yes', false, 'false', '0', 'off', 'no'), true) : |
|
198 | + $attributes[$key] = $value; |
|
199 | + break; |
|
200 | + case is_string($value) : |
|
201 | + $attributes[$key] = sanitize_text_field($value); |
|
202 | + break; |
|
203 | + case is_array($value) : |
|
204 | + $attributes[$key] = $this->sanitizeAttributes($value); |
|
205 | + break; |
|
206 | + default : |
|
207 | + // only remaining data types are Object and Resource |
|
208 | + // which are not allowed as shortcode attributes |
|
209 | + $attributes[$key] = null; |
|
210 | + break; |
|
211 | + } |
|
212 | + } |
|
213 | + return $attributes; |
|
214 | + } |
|
215 | 215 | |
216 | 216 | |
217 | 217 |
@@ -91,7 +91,7 @@ |
||
91 | 91 | $cache_id |
92 | 92 | ) |
93 | 93 | ); |
94 | - $cache_id = substr($this->cachePrefix() . $id_prefix . '-' . md5($cache_id), 0, 182); |
|
94 | + $cache_id = substr($this->cachePrefix().$id_prefix.'-'.md5($cache_id), 0, 182); |
|
95 | 95 | // is caching enabled for this content ? |
96 | 96 | if ($expiration) { |
97 | 97 | $content = $this->cache_storage->get($cache_id); |
@@ -19,118 +19,118 @@ |
||
19 | 19 | class BasicCacheManager implements CacheManagerInterface |
20 | 20 | { |
21 | 21 | |
22 | - /** |
|
23 | - * @type string |
|
24 | - */ |
|
25 | - const CACHE_PREFIX = 'ee_cache_'; |
|
26 | - |
|
27 | - /** |
|
28 | - * set to true to monitor when content is being served from cache or not |
|
29 | - * |
|
30 | - * @type boolean |
|
31 | - */ |
|
32 | - const DEBUG = false; |
|
33 | - |
|
34 | - /** |
|
35 | - * @var CacheStorageInterface $cache_storage |
|
36 | - */ |
|
37 | - private $cache_storage; |
|
38 | - |
|
39 | - |
|
40 | - |
|
41 | - /** |
|
42 | - * BasicCacheManager constructor. |
|
43 | - * |
|
44 | - * @param CacheStorageInterface $cache_storage [required] |
|
45 | - */ |
|
46 | - public function __construct(CacheStorageInterface $cache_storage) |
|
47 | - { |
|
48 | - $this->cache_storage = $cache_storage; |
|
49 | - } |
|
50 | - |
|
51 | - |
|
52 | - |
|
53 | - /** |
|
54 | - * returns a string that will be prepended to all cache identifiers |
|
55 | - * |
|
56 | - * @return string |
|
57 | - */ |
|
58 | - public function cachePrefix() |
|
59 | - { |
|
60 | - return BasicCacheManager::CACHE_PREFIX; |
|
61 | - } |
|
62 | - |
|
63 | - |
|
64 | - |
|
65 | - /** |
|
66 | - * @param string $id_prefix [required] Prepended to all cache IDs. Can be helpful in finding specific cache types. |
|
67 | - * May also be helpful to include an additional specific identifier, |
|
68 | - * such as a post ID as part of the $id_prefix so that individual caches |
|
69 | - * can be found and/or cleared. ex: "venue-28", or "shortcode-156". |
|
70 | - * BasicCacheManager::CACHE_PREFIX will also be prepended to the cache id. |
|
71 | - * @param string $cache_id [required] Additional identifying details that make this cache unique. |
|
72 | - * It is advisable to use some of the actual data |
|
73 | - * that is used to generate the content being cached, |
|
74 | - * in order to guarantee that the cache id is unique for that content. |
|
75 | - * The cache id will be md5'd before usage to make it more db friendly, |
|
76 | - * and the entire cache id string will be truncated to 190 characters. |
|
77 | - * @param Closure $callback [required] since the point of caching is to avoid generating content when not |
|
78 | - * necessary, |
|
79 | - * we wrap our content creation in a Closure so that it is not executed until needed. |
|
80 | - * @param int $expiration |
|
81 | - * @return Closure|mixed |
|
82 | - */ |
|
83 | - public function get($id_prefix, $cache_id, Closure $callback, $expiration = HOUR_IN_SECONDS) |
|
84 | - { |
|
85 | - $content = ''; |
|
86 | - // how long should we cache this content for? 0 means no caching. |
|
87 | - $expiration = ! WP_DEBUG ? $expiration : 0; |
|
88 | - $expiration = absint( |
|
89 | - apply_filters( |
|
90 | - 'FHEE__CacheManager__get__cache_expiration', |
|
91 | - $expiration, |
|
92 | - $id_prefix, |
|
93 | - $cache_id |
|
94 | - ) |
|
95 | - ); |
|
96 | - $cache_id = substr($this->cachePrefix() . $id_prefix . '-' . md5($cache_id), 0, 182); |
|
97 | - // is caching enabled for this content ? |
|
98 | - if ($expiration) { |
|
99 | - $content = $this->cache_storage->get($cache_id); |
|
100 | - } |
|
101 | - // any existing content ? |
|
102 | - if (empty($content)) { |
|
103 | - // nope! let's generate some new stuff |
|
104 | - $content = $callback(); |
|
105 | - // save the new content if caching is enabled |
|
106 | - if ($expiration) { |
|
107 | - if (BasicCacheManager::DEBUG) { |
|
108 | - EEH_Debug_Tools::printr($cache_id, 'REFRESH CACHE', __FILE__, __LINE__); |
|
109 | - } |
|
110 | - $this->cache_storage->add($cache_id, $content, $expiration); |
|
111 | - } |
|
112 | - } else { |
|
113 | - if (BasicCacheManager::DEBUG) { |
|
114 | - EEH_Debug_Tools::printr($cache_id, 'CACHED CONTENT', __FILE__, __LINE__); |
|
115 | - } |
|
116 | - } |
|
117 | - return $content; |
|
118 | - } |
|
119 | - |
|
120 | - |
|
121 | - |
|
122 | - /** |
|
123 | - * @param array|string $cache_id [required] Could be an ID prefix affecting many caches |
|
124 | - * or a specific ID targeting a single cache item |
|
125 | - * @return void |
|
126 | - */ |
|
127 | - public function clear($cache_id) |
|
128 | - { |
|
129 | - // ensure incoming arg is in an array |
|
130 | - $cache_id = is_array($cache_id) ? $cache_id : array($cache_id); |
|
131 | - // delete corresponding transients for the supplied id prefix |
|
132 | - $this->cache_storage->deleteMany($cache_id); |
|
133 | - } |
|
22 | + /** |
|
23 | + * @type string |
|
24 | + */ |
|
25 | + const CACHE_PREFIX = 'ee_cache_'; |
|
26 | + |
|
27 | + /** |
|
28 | + * set to true to monitor when content is being served from cache or not |
|
29 | + * |
|
30 | + * @type boolean |
|
31 | + */ |
|
32 | + const DEBUG = false; |
|
33 | + |
|
34 | + /** |
|
35 | + * @var CacheStorageInterface $cache_storage |
|
36 | + */ |
|
37 | + private $cache_storage; |
|
38 | + |
|
39 | + |
|
40 | + |
|
41 | + /** |
|
42 | + * BasicCacheManager constructor. |
|
43 | + * |
|
44 | + * @param CacheStorageInterface $cache_storage [required] |
|
45 | + */ |
|
46 | + public function __construct(CacheStorageInterface $cache_storage) |
|
47 | + { |
|
48 | + $this->cache_storage = $cache_storage; |
|
49 | + } |
|
50 | + |
|
51 | + |
|
52 | + |
|
53 | + /** |
|
54 | + * returns a string that will be prepended to all cache identifiers |
|
55 | + * |
|
56 | + * @return string |
|
57 | + */ |
|
58 | + public function cachePrefix() |
|
59 | + { |
|
60 | + return BasicCacheManager::CACHE_PREFIX; |
|
61 | + } |
|
62 | + |
|
63 | + |
|
64 | + |
|
65 | + /** |
|
66 | + * @param string $id_prefix [required] Prepended to all cache IDs. Can be helpful in finding specific cache types. |
|
67 | + * May also be helpful to include an additional specific identifier, |
|
68 | + * such as a post ID as part of the $id_prefix so that individual caches |
|
69 | + * can be found and/or cleared. ex: "venue-28", or "shortcode-156". |
|
70 | + * BasicCacheManager::CACHE_PREFIX will also be prepended to the cache id. |
|
71 | + * @param string $cache_id [required] Additional identifying details that make this cache unique. |
|
72 | + * It is advisable to use some of the actual data |
|
73 | + * that is used to generate the content being cached, |
|
74 | + * in order to guarantee that the cache id is unique for that content. |
|
75 | + * The cache id will be md5'd before usage to make it more db friendly, |
|
76 | + * and the entire cache id string will be truncated to 190 characters. |
|
77 | + * @param Closure $callback [required] since the point of caching is to avoid generating content when not |
|
78 | + * necessary, |
|
79 | + * we wrap our content creation in a Closure so that it is not executed until needed. |
|
80 | + * @param int $expiration |
|
81 | + * @return Closure|mixed |
|
82 | + */ |
|
83 | + public function get($id_prefix, $cache_id, Closure $callback, $expiration = HOUR_IN_SECONDS) |
|
84 | + { |
|
85 | + $content = ''; |
|
86 | + // how long should we cache this content for? 0 means no caching. |
|
87 | + $expiration = ! WP_DEBUG ? $expiration : 0; |
|
88 | + $expiration = absint( |
|
89 | + apply_filters( |
|
90 | + 'FHEE__CacheManager__get__cache_expiration', |
|
91 | + $expiration, |
|
92 | + $id_prefix, |
|
93 | + $cache_id |
|
94 | + ) |
|
95 | + ); |
|
96 | + $cache_id = substr($this->cachePrefix() . $id_prefix . '-' . md5($cache_id), 0, 182); |
|
97 | + // is caching enabled for this content ? |
|
98 | + if ($expiration) { |
|
99 | + $content = $this->cache_storage->get($cache_id); |
|
100 | + } |
|
101 | + // any existing content ? |
|
102 | + if (empty($content)) { |
|
103 | + // nope! let's generate some new stuff |
|
104 | + $content = $callback(); |
|
105 | + // save the new content if caching is enabled |
|
106 | + if ($expiration) { |
|
107 | + if (BasicCacheManager::DEBUG) { |
|
108 | + EEH_Debug_Tools::printr($cache_id, 'REFRESH CACHE', __FILE__, __LINE__); |
|
109 | + } |
|
110 | + $this->cache_storage->add($cache_id, $content, $expiration); |
|
111 | + } |
|
112 | + } else { |
|
113 | + if (BasicCacheManager::DEBUG) { |
|
114 | + EEH_Debug_Tools::printr($cache_id, 'CACHED CONTENT', __FILE__, __LINE__); |
|
115 | + } |
|
116 | + } |
|
117 | + return $content; |
|
118 | + } |
|
119 | + |
|
120 | + |
|
121 | + |
|
122 | + /** |
|
123 | + * @param array|string $cache_id [required] Could be an ID prefix affecting many caches |
|
124 | + * or a specific ID targeting a single cache item |
|
125 | + * @return void |
|
126 | + */ |
|
127 | + public function clear($cache_id) |
|
128 | + { |
|
129 | + // ensure incoming arg is in an array |
|
130 | + $cache_id = is_array($cache_id) ? $cache_id : array($cache_id); |
|
131 | + // delete corresponding transients for the supplied id prefix |
|
132 | + $this->cache_storage->deleteMany($cache_id); |
|
133 | + } |
|
134 | 134 | |
135 | 135 | |
136 | 136 |
@@ -16,92 +16,92 @@ |
||
16 | 16 | class PostRelatedCacheManager extends BasicCacheManager |
17 | 17 | { |
18 | 18 | |
19 | - /** |
|
20 | - * @type string |
|
21 | - */ |
|
22 | - const POST_CACHE_PREFIX = 'ee_cache_post_'; |
|
23 | - |
|
24 | - /** |
|
25 | - * wp-option option_name for tracking post related cache |
|
26 | - * |
|
27 | - * @type string |
|
28 | - */ |
|
29 | - const POST_CACHE_OPTIONS_KEY = 'ee_post_cache'; |
|
30 | - |
|
31 | - |
|
32 | - |
|
33 | - /** |
|
34 | - * PostRelatedCacheManager constructor. |
|
35 | - * |
|
36 | - * @param CacheStorageInterface $cache_storage |
|
37 | - */ |
|
38 | - public function __construct(CacheStorageInterface $cache_storage) |
|
39 | - { |
|
40 | - parent::__construct($cache_storage); |
|
41 | - add_action('save_post', array($this, 'clearPostRelatedCache')); |
|
42 | - } |
|
43 | - |
|
44 | - |
|
45 | - |
|
46 | - /** |
|
47 | - * returns a string that will be prepended to all cache identifiers |
|
48 | - * |
|
49 | - * @return string |
|
50 | - */ |
|
51 | - public function cachePrefix() |
|
52 | - { |
|
53 | - return PostRelatedCacheManager::POST_CACHE_PREFIX; |
|
54 | - } |
|
55 | - |
|
56 | - |
|
57 | - |
|
58 | - /** |
|
59 | - * If you are caching content that pertains to a Post of any type, |
|
60 | - * then it is recommended to pass the post id and cache id prefix to this method |
|
61 | - * so that it can be added to the post related cache tracking. |
|
62 | - * Then, whenever that post is updated, the cache will automatically be deleted, |
|
63 | - * which helps to ensure that outdated cache content will not be served |
|
64 | - * |
|
65 | - * @param int $post_ID [required] |
|
66 | - * @param string $id_prefix [required] Appended to all cache IDs. Can be helpful in finding specific cache types. |
|
67 | - * May also be helpful to include an additional specific identifier, |
|
68 | - * such as a post ID as part of the $id_prefix so that individual caches |
|
69 | - * can be found and/or cleared. ex: "venue-28", or "shortcode-156". |
|
70 | - * BasicCacheManager::CACHE_PREFIX will also be prepended to the cache id. |
|
71 | - */ |
|
72 | - public function clearPostRelatedCacheOnUpdate($post_ID, $id_prefix) |
|
73 | - { |
|
74 | - $post_related_cache = (array)get_option(PostRelatedCacheManager::POST_CACHE_OPTIONS_KEY, array()); |
|
75 | - // if post is not already being tracked |
|
76 | - if ( ! isset($post_related_cache[$post_ID])) { |
|
77 | - // add array to add cache ids to |
|
78 | - $post_related_cache[$post_ID] = array(); |
|
79 | - } |
|
80 | - // add cache id to be tracked |
|
81 | - $post_related_cache[$post_ID][] = $id_prefix; |
|
82 | - update_option(PostRelatedCacheManager::POST_CACHE_OPTIONS_KEY, $post_related_cache); |
|
83 | - } |
|
84 | - |
|
85 | - |
|
86 | - |
|
87 | - /** |
|
88 | - * callback hooked into the WordPress "save_post" action |
|
89 | - * deletes any cache content associated with the post |
|
90 | - * |
|
91 | - * @param int $post_ID [required] |
|
92 | - */ |
|
93 | - public function clearPostRelatedCache($post_ID) |
|
94 | - { |
|
95 | - $post_related_cache = (array)get_option(PostRelatedCacheManager::POST_CACHE_OPTIONS_KEY, array()); |
|
96 | - // if post is not being tracked |
|
97 | - if ( ! isset($post_related_cache[$post_ID])) { |
|
98 | - return; |
|
99 | - } |
|
100 | - // get cache id prefixes for post, and delete their corresponding transients |
|
101 | - $this->clear($post_related_cache[$post_ID]); |
|
102 | - unset($post_related_cache[$post_ID]); |
|
103 | - update_option(PostRelatedCacheManager::POST_CACHE_OPTIONS_KEY, $post_related_cache); |
|
104 | - } |
|
19 | + /** |
|
20 | + * @type string |
|
21 | + */ |
|
22 | + const POST_CACHE_PREFIX = 'ee_cache_post_'; |
|
23 | + |
|
24 | + /** |
|
25 | + * wp-option option_name for tracking post related cache |
|
26 | + * |
|
27 | + * @type string |
|
28 | + */ |
|
29 | + const POST_CACHE_OPTIONS_KEY = 'ee_post_cache'; |
|
30 | + |
|
31 | + |
|
32 | + |
|
33 | + /** |
|
34 | + * PostRelatedCacheManager constructor. |
|
35 | + * |
|
36 | + * @param CacheStorageInterface $cache_storage |
|
37 | + */ |
|
38 | + public function __construct(CacheStorageInterface $cache_storage) |
|
39 | + { |
|
40 | + parent::__construct($cache_storage); |
|
41 | + add_action('save_post', array($this, 'clearPostRelatedCache')); |
|
42 | + } |
|
43 | + |
|
44 | + |
|
45 | + |
|
46 | + /** |
|
47 | + * returns a string that will be prepended to all cache identifiers |
|
48 | + * |
|
49 | + * @return string |
|
50 | + */ |
|
51 | + public function cachePrefix() |
|
52 | + { |
|
53 | + return PostRelatedCacheManager::POST_CACHE_PREFIX; |
|
54 | + } |
|
55 | + |
|
56 | + |
|
57 | + |
|
58 | + /** |
|
59 | + * If you are caching content that pertains to a Post of any type, |
|
60 | + * then it is recommended to pass the post id and cache id prefix to this method |
|
61 | + * so that it can be added to the post related cache tracking. |
|
62 | + * Then, whenever that post is updated, the cache will automatically be deleted, |
|
63 | + * which helps to ensure that outdated cache content will not be served |
|
64 | + * |
|
65 | + * @param int $post_ID [required] |
|
66 | + * @param string $id_prefix [required] Appended to all cache IDs. Can be helpful in finding specific cache types. |
|
67 | + * May also be helpful to include an additional specific identifier, |
|
68 | + * such as a post ID as part of the $id_prefix so that individual caches |
|
69 | + * can be found and/or cleared. ex: "venue-28", or "shortcode-156". |
|
70 | + * BasicCacheManager::CACHE_PREFIX will also be prepended to the cache id. |
|
71 | + */ |
|
72 | + public function clearPostRelatedCacheOnUpdate($post_ID, $id_prefix) |
|
73 | + { |
|
74 | + $post_related_cache = (array)get_option(PostRelatedCacheManager::POST_CACHE_OPTIONS_KEY, array()); |
|
75 | + // if post is not already being tracked |
|
76 | + if ( ! isset($post_related_cache[$post_ID])) { |
|
77 | + // add array to add cache ids to |
|
78 | + $post_related_cache[$post_ID] = array(); |
|
79 | + } |
|
80 | + // add cache id to be tracked |
|
81 | + $post_related_cache[$post_ID][] = $id_prefix; |
|
82 | + update_option(PostRelatedCacheManager::POST_CACHE_OPTIONS_KEY, $post_related_cache); |
|
83 | + } |
|
84 | + |
|
85 | + |
|
86 | + |
|
87 | + /** |
|
88 | + * callback hooked into the WordPress "save_post" action |
|
89 | + * deletes any cache content associated with the post |
|
90 | + * |
|
91 | + * @param int $post_ID [required] |
|
92 | + */ |
|
93 | + public function clearPostRelatedCache($post_ID) |
|
94 | + { |
|
95 | + $post_related_cache = (array)get_option(PostRelatedCacheManager::POST_CACHE_OPTIONS_KEY, array()); |
|
96 | + // if post is not being tracked |
|
97 | + if ( ! isset($post_related_cache[$post_ID])) { |
|
98 | + return; |
|
99 | + } |
|
100 | + // get cache id prefixes for post, and delete their corresponding transients |
|
101 | + $this->clear($post_related_cache[$post_ID]); |
|
102 | + unset($post_related_cache[$post_ID]); |
|
103 | + update_option(PostRelatedCacheManager::POST_CACHE_OPTIONS_KEY, $post_related_cache); |
|
104 | + } |
|
105 | 105 | |
106 | 106 | |
107 | 107 | } |
@@ -71,7 +71,7 @@ discard block |
||
71 | 71 | */ |
72 | 72 | public function clearPostRelatedCacheOnUpdate($post_ID, $id_prefix) |
73 | 73 | { |
74 | - $post_related_cache = (array)get_option(PostRelatedCacheManager::POST_CACHE_OPTIONS_KEY, array()); |
|
74 | + $post_related_cache = (array) get_option(PostRelatedCacheManager::POST_CACHE_OPTIONS_KEY, array()); |
|
75 | 75 | // if post is not already being tracked |
76 | 76 | if ( ! isset($post_related_cache[$post_ID])) { |
77 | 77 | // add array to add cache ids to |
@@ -92,7 +92,7 @@ discard block |
||
92 | 92 | */ |
93 | 93 | public function clearPostRelatedCache($post_ID) |
94 | 94 | { |
95 | - $post_related_cache = (array)get_option(PostRelatedCacheManager::POST_CACHE_OPTIONS_KEY, array()); |
|
95 | + $post_related_cache = (array) get_option(PostRelatedCacheManager::POST_CACHE_OPTIONS_KEY, array()); |
|
96 | 96 | // if post is not being tracked |
97 | 97 | if ( ! isset($post_related_cache[$post_ID])) { |
98 | 98 | return; |
@@ -18,43 +18,43 @@ |
||
18 | 18 | interface CacheManagerInterface |
19 | 19 | { |
20 | 20 | |
21 | - /** |
|
22 | - * returns a string that will be prepended to all cache identifiers |
|
23 | - * |
|
24 | - * @return string |
|
25 | - */ |
|
26 | - public function cachePrefix(); |
|
27 | - |
|
28 | - |
|
29 | - |
|
30 | - /** |
|
31 | - * @param string $id_prefix [required] Prepended to all cache IDs. Can be helpful in finding specific cache types. |
|
32 | - * May also be helpful to include an additional specific identifier, |
|
33 | - * such as a post ID as part of the $id_prefix so that individual caches |
|
34 | - * can be found and/or cleared. ex: "venue-28", or "shortcode-156". |
|
35 | - * BasicCacheManager::CACHE_PREFIX will also be prepended to the cache id. |
|
36 | - * @param string $cache_id [required] Additional identifying details that make this cache unique. |
|
37 | - * It is advisable to use some of the actual data |
|
38 | - * that is used to generate the content being cached, |
|
39 | - * in order to guarantee that the cache id is unique for that content. |
|
40 | - * The cache id will be md5'd before usage to make it more db friendly, |
|
41 | - * and the entire cache id string will be truncated to 190 characters. |
|
42 | - * @param Closure $callback [required] since the point of caching is to avoid generating content when not |
|
43 | - * necessary, |
|
44 | - * we wrap our content creation in a Closure so that it is not executed until needed. |
|
45 | - * @param int $expiration |
|
46 | - * @return Closure|mixed |
|
47 | - */ |
|
48 | - public function get($id_prefix, $cache_id, Closure $callback, $expiration = HOUR_IN_SECONDS); |
|
49 | - |
|
50 | - |
|
51 | - |
|
52 | - /** |
|
53 | - * @param array|string $cache_id [required] Could be an ID prefix affecting many caches |
|
54 | - * or a specific ID targeting a single cache item |
|
55 | - * @return void |
|
56 | - */ |
|
57 | - public function clear($cache_id); |
|
21 | + /** |
|
22 | + * returns a string that will be prepended to all cache identifiers |
|
23 | + * |
|
24 | + * @return string |
|
25 | + */ |
|
26 | + public function cachePrefix(); |
|
27 | + |
|
28 | + |
|
29 | + |
|
30 | + /** |
|
31 | + * @param string $id_prefix [required] Prepended to all cache IDs. Can be helpful in finding specific cache types. |
|
32 | + * May also be helpful to include an additional specific identifier, |
|
33 | + * such as a post ID as part of the $id_prefix so that individual caches |
|
34 | + * can be found and/or cleared. ex: "venue-28", or "shortcode-156". |
|
35 | + * BasicCacheManager::CACHE_PREFIX will also be prepended to the cache id. |
|
36 | + * @param string $cache_id [required] Additional identifying details that make this cache unique. |
|
37 | + * It is advisable to use some of the actual data |
|
38 | + * that is used to generate the content being cached, |
|
39 | + * in order to guarantee that the cache id is unique for that content. |
|
40 | + * The cache id will be md5'd before usage to make it more db friendly, |
|
41 | + * and the entire cache id string will be truncated to 190 characters. |
|
42 | + * @param Closure $callback [required] since the point of caching is to avoid generating content when not |
|
43 | + * necessary, |
|
44 | + * we wrap our content creation in a Closure so that it is not executed until needed. |
|
45 | + * @param int $expiration |
|
46 | + * @return Closure|mixed |
|
47 | + */ |
|
48 | + public function get($id_prefix, $cache_id, Closure $callback, $expiration = HOUR_IN_SECONDS); |
|
49 | + |
|
50 | + |
|
51 | + |
|
52 | + /** |
|
53 | + * @param array|string $cache_id [required] Could be an ID prefix affecting many caches |
|
54 | + * or a specific ID targeting a single cache item |
|
55 | + * @return void |
|
56 | + */ |
|
57 | + public function clear($cache_id); |
|
58 | 58 | |
59 | 59 | } |
60 | 60 | // End of file CacheManagerInterface.php |