@@ -12,109 +12,109 @@ discard block |
||
12 | 12 | class EEW_Upcoming_Events extends EspressoWidget |
13 | 13 | { |
14 | 14 | |
15 | - /** |
|
16 | - * @var string |
|
17 | - */ |
|
18 | - private $title; |
|
19 | - /** |
|
20 | - * @var string |
|
21 | - */ |
|
22 | - private $events_category; |
|
23 | - |
|
24 | - /** |
|
25 | - * @var bool |
|
26 | - */ |
|
27 | - private $show_expired; |
|
28 | - |
|
29 | - /** |
|
30 | - * @var string |
|
31 | - */ |
|
32 | - private $image_size; |
|
33 | - |
|
34 | - /** |
|
35 | - * @var bool |
|
36 | - */ |
|
37 | - private $show_desc; |
|
38 | - |
|
39 | - /** |
|
40 | - * @var bool |
|
41 | - */ |
|
42 | - private $show_dates; |
|
43 | - |
|
44 | - /** |
|
45 | - * @var string |
|
46 | - */ |
|
47 | - private $date_limit; |
|
48 | - |
|
49 | - /** |
|
50 | - * @var string |
|
51 | - */ |
|
52 | - private $date_range; |
|
53 | - |
|
54 | - /** |
|
55 | - * @var string |
|
56 | - */ |
|
57 | - private $limit; |
|
58 | - |
|
59 | - /** |
|
60 | - * @var string |
|
61 | - */ |
|
62 | - private $order; |
|
63 | - |
|
64 | - |
|
65 | - /** |
|
66 | - * Register widget with WordPress. |
|
67 | - */ |
|
68 | - public function __construct() |
|
69 | - { |
|
70 | - parent::__construct( |
|
71 | - esc_html__('Event Espresso Upcoming Events', 'event_espresso'), |
|
72 | - ['description' => esc_html__('A widget to display your upcoming events.', 'event_espresso')] |
|
73 | - ); |
|
74 | - } |
|
75 | - |
|
76 | - |
|
77 | - /** |
|
78 | - * Back-end widget form. |
|
79 | - * |
|
80 | - * @param array $instance Previously saved values from database. |
|
81 | - * @return void |
|
82 | - * @throws EE_Error |
|
83 | - * @throws ReflectionException |
|
84 | - * @see WP_Widget::form() |
|
85 | - */ |
|
86 | - public function form($instance) |
|
87 | - { |
|
88 | - |
|
89 | - EE_Registry::instance()->load_class('Question_Option', [], false, false, true); |
|
90 | - // Set up some default widget settings. |
|
91 | - $defaults = [ |
|
92 | - 'title' => esc_html__('Upcoming Events', 'event_espresso'), |
|
93 | - 'category_name' => '', |
|
94 | - 'show_expired' => 0, |
|
95 | - 'show_desc' => true, |
|
96 | - 'show_dates' => true, |
|
97 | - 'show_everywhere' => false, |
|
98 | - 'date_limit' => 2, |
|
99 | - 'limit' => 10, |
|
100 | - 'sort' => 'ASC', |
|
101 | - 'date_range' => false, |
|
102 | - 'image_size' => 'medium', |
|
103 | - ]; |
|
104 | - |
|
105 | - $instance = wp_parse_args((array) $instance, $defaults); |
|
106 | - // don't add HTML labels for EE_Form_Fields generated inputs |
|
107 | - add_filter('FHEE__EEH_Form_Fields__label_html', '__return_empty_string'); |
|
108 | - $yes_no_values = [ |
|
109 | - EE_Question_Option::new_instance(['QSO_value' => false, 'QSO_desc' => esc_html__('No', 'event_espresso')]), |
|
110 | - EE_Question_Option::new_instance(['QSO_value' => true, 'QSO_desc' => esc_html__('Yes', 'event_espresso')]), |
|
111 | - ]; |
|
112 | - $sort_values = [ |
|
113 | - EE_Question_Option::new_instance(['QSO_value' => 'ASC', 'QSO_desc' => esc_html__('ASC', 'event_espresso')]), |
|
114 | - EE_Question_Option::new_instance(['QSO_value' => 'DESC', 'QSO_desc' => esc_html__('DESC', 'event_espresso')]), |
|
115 | - ]; |
|
116 | - |
|
117 | - ?> |
|
15 | + /** |
|
16 | + * @var string |
|
17 | + */ |
|
18 | + private $title; |
|
19 | + /** |
|
20 | + * @var string |
|
21 | + */ |
|
22 | + private $events_category; |
|
23 | + |
|
24 | + /** |
|
25 | + * @var bool |
|
26 | + */ |
|
27 | + private $show_expired; |
|
28 | + |
|
29 | + /** |
|
30 | + * @var string |
|
31 | + */ |
|
32 | + private $image_size; |
|
33 | + |
|
34 | + /** |
|
35 | + * @var bool |
|
36 | + */ |
|
37 | + private $show_desc; |
|
38 | + |
|
39 | + /** |
|
40 | + * @var bool |
|
41 | + */ |
|
42 | + private $show_dates; |
|
43 | + |
|
44 | + /** |
|
45 | + * @var string |
|
46 | + */ |
|
47 | + private $date_limit; |
|
48 | + |
|
49 | + /** |
|
50 | + * @var string |
|
51 | + */ |
|
52 | + private $date_range; |
|
53 | + |
|
54 | + /** |
|
55 | + * @var string |
|
56 | + */ |
|
57 | + private $limit; |
|
58 | + |
|
59 | + /** |
|
60 | + * @var string |
|
61 | + */ |
|
62 | + private $order; |
|
63 | + |
|
64 | + |
|
65 | + /** |
|
66 | + * Register widget with WordPress. |
|
67 | + */ |
|
68 | + public function __construct() |
|
69 | + { |
|
70 | + parent::__construct( |
|
71 | + esc_html__('Event Espresso Upcoming Events', 'event_espresso'), |
|
72 | + ['description' => esc_html__('A widget to display your upcoming events.', 'event_espresso')] |
|
73 | + ); |
|
74 | + } |
|
75 | + |
|
76 | + |
|
77 | + /** |
|
78 | + * Back-end widget form. |
|
79 | + * |
|
80 | + * @param array $instance Previously saved values from database. |
|
81 | + * @return void |
|
82 | + * @throws EE_Error |
|
83 | + * @throws ReflectionException |
|
84 | + * @see WP_Widget::form() |
|
85 | + */ |
|
86 | + public function form($instance) |
|
87 | + { |
|
88 | + |
|
89 | + EE_Registry::instance()->load_class('Question_Option', [], false, false, true); |
|
90 | + // Set up some default widget settings. |
|
91 | + $defaults = [ |
|
92 | + 'title' => esc_html__('Upcoming Events', 'event_espresso'), |
|
93 | + 'category_name' => '', |
|
94 | + 'show_expired' => 0, |
|
95 | + 'show_desc' => true, |
|
96 | + 'show_dates' => true, |
|
97 | + 'show_everywhere' => false, |
|
98 | + 'date_limit' => 2, |
|
99 | + 'limit' => 10, |
|
100 | + 'sort' => 'ASC', |
|
101 | + 'date_range' => false, |
|
102 | + 'image_size' => 'medium', |
|
103 | + ]; |
|
104 | + |
|
105 | + $instance = wp_parse_args((array) $instance, $defaults); |
|
106 | + // don't add HTML labels for EE_Form_Fields generated inputs |
|
107 | + add_filter('FHEE__EEH_Form_Fields__label_html', '__return_empty_string'); |
|
108 | + $yes_no_values = [ |
|
109 | + EE_Question_Option::new_instance(['QSO_value' => false, 'QSO_desc' => esc_html__('No', 'event_espresso')]), |
|
110 | + EE_Question_Option::new_instance(['QSO_value' => true, 'QSO_desc' => esc_html__('Yes', 'event_espresso')]), |
|
111 | + ]; |
|
112 | + $sort_values = [ |
|
113 | + EE_Question_Option::new_instance(['QSO_value' => 'ASC', 'QSO_desc' => esc_html__('ASC', 'event_espresso')]), |
|
114 | + EE_Question_Option::new_instance(['QSO_value' => 'DESC', 'QSO_desc' => esc_html__('DESC', 'event_espresso')]), |
|
115 | + ]; |
|
116 | + |
|
117 | + ?> |
|
118 | 118 | |
119 | 119 | <!-- Widget Title: Text Input --> |
120 | 120 | |
@@ -151,32 +151,32 @@ discard block |
||
151 | 151 | <?php esc_html_e('Show Expired Events:', 'event_espresso'); ?> |
152 | 152 | </label> |
153 | 153 | <?php |
154 | - $show_expired_options = $yes_no_values; |
|
155 | - $show_expired_options[] = EE_Question_Option::new_instance( |
|
156 | - ['QSO_value' => 2, 'QSO_desc' => esc_html__('Show Only Expired', 'event_espresso')] |
|
157 | - ); |
|
158 | - echo EEH_Form_Fields::select( |
|
159 | - esc_html__('Show Expired Events:', 'event_espresso'), |
|
160 | - $instance['show_expired'], |
|
161 | - $show_expired_options, |
|
162 | - $this->fieldName('show_expired'), |
|
163 | - $this->fieldID('show_expired') |
|
164 | - ); |
|
165 | - ?> |
|
154 | + $show_expired_options = $yes_no_values; |
|
155 | + $show_expired_options[] = EE_Question_Option::new_instance( |
|
156 | + ['QSO_value' => 2, 'QSO_desc' => esc_html__('Show Only Expired', 'event_espresso')] |
|
157 | + ); |
|
158 | + echo EEH_Form_Fields::select( |
|
159 | + esc_html__('Show Expired Events:', 'event_espresso'), |
|
160 | + $instance['show_expired'], |
|
161 | + $show_expired_options, |
|
162 | + $this->fieldName('show_expired'), |
|
163 | + $this->fieldID('show_expired') |
|
164 | + ); |
|
165 | + ?> |
|
166 | 166 | </p> |
167 | 167 | <p> |
168 | 168 | <label for="<?php echo $this->fieldID('sort'); ?>"> |
169 | 169 | <?php esc_html_e('Sort Events:', 'event_espresso'); ?> |
170 | 170 | </label> |
171 | 171 | <?php |
172 | - echo EEH_Form_Fields::select( |
|
173 | - esc_html__('Sort Events:', 'event_espresso'), |
|
174 | - $instance['sort'], |
|
175 | - $sort_values, |
|
176 | - $this->fieldName('sort'), |
|
177 | - $this->fieldID('sort') |
|
178 | - ); |
|
179 | - ?> |
|
172 | + echo EEH_Form_Fields::select( |
|
173 | + esc_html__('Sort Events:', 'event_espresso'), |
|
174 | + $instance['sort'], |
|
175 | + $sort_values, |
|
176 | + $this->fieldName('sort'), |
|
177 | + $this->fieldID('sort') |
|
178 | + ); |
|
179 | + ?> |
|
180 | 180 | </p> |
181 | 181 | <p> |
182 | 182 | <label for="<?php echo $this->fieldID('image_size'); ?>"> |
@@ -190,42 +190,42 @@ discard block |
||
190 | 190 | <?php esc_html_e('Show Description:', 'event_espresso'); ?> |
191 | 191 | </label> |
192 | 192 | <?php |
193 | - echo EEH_Form_Fields::select( |
|
194 | - esc_html__('Show Description:', 'event_espresso'), |
|
195 | - $instance['show_desc'], |
|
196 | - $yes_no_values, |
|
197 | - $this->fieldName('show_desc'), |
|
198 | - $this->fieldID('show_desc') |
|
199 | - ); |
|
200 | - ?> |
|
193 | + echo EEH_Form_Fields::select( |
|
194 | + esc_html__('Show Description:', 'event_espresso'), |
|
195 | + $instance['show_desc'], |
|
196 | + $yes_no_values, |
|
197 | + $this->fieldName('show_desc'), |
|
198 | + $this->fieldID('show_desc') |
|
199 | + ); |
|
200 | + ?> |
|
201 | 201 | </p> |
202 | 202 | <p> |
203 | 203 | <label for="<?php echo $this->fieldID('show_dates'); ?>"> |
204 | 204 | <?php esc_html_e('Show Dates:', 'event_espresso'); ?> |
205 | 205 | </label> |
206 | 206 | <?php |
207 | - echo EEH_Form_Fields::select( |
|
208 | - esc_html__('Show Dates:', 'event_espresso'), |
|
209 | - $instance['show_dates'], |
|
210 | - $yes_no_values, |
|
211 | - $this->fieldName('show_dates'), |
|
212 | - $this->fieldID('show_dates') |
|
213 | - ); |
|
214 | - ?> |
|
207 | + echo EEH_Form_Fields::select( |
|
208 | + esc_html__('Show Dates:', 'event_espresso'), |
|
209 | + $instance['show_dates'], |
|
210 | + $yes_no_values, |
|
211 | + $this->fieldName('show_dates'), |
|
212 | + $this->fieldID('show_dates') |
|
213 | + ); |
|
214 | + ?> |
|
215 | 215 | </p> |
216 | 216 | <p> |
217 | 217 | <label for="<?php echo $this->fieldID('show_everywhere'); ?>"> |
218 | 218 | <?php esc_html_e('Show on all Pages:', 'event_espresso'); ?> |
219 | 219 | </label> |
220 | 220 | <?php |
221 | - echo EEH_Form_Fields::select( |
|
222 | - esc_html__('Show on all Pages:', 'event_espresso'), |
|
223 | - $instance['show_everywhere'], |
|
224 | - $yes_no_values, |
|
225 | - $this->fieldName('show_everywhere'), |
|
226 | - $this->fieldID('show_everywhere') |
|
227 | - ); |
|
228 | - ?> |
|
221 | + echo EEH_Form_Fields::select( |
|
222 | + esc_html__('Show on all Pages:', 'event_espresso'), |
|
223 | + $instance['show_everywhere'], |
|
224 | + $yes_no_values, |
|
225 | + $this->fieldName('show_everywhere'), |
|
226 | + $this->fieldID('show_everywhere') |
|
227 | + ); |
|
228 | + ?> |
|
229 | 229 | </p> |
230 | 230 | <p> |
231 | 231 | <label for="<?php echo $this->fieldID('date_limit'); ?>"> |
@@ -243,278 +243,278 @@ discard block |
||
243 | 243 | <?php esc_html_e('Show Date Range:', 'event_espresso'); ?> |
244 | 244 | </label> |
245 | 245 | <?php |
246 | - echo EEH_Form_Fields::select( |
|
247 | - esc_html__('Show Date Range:', 'event_espresso'), |
|
248 | - $instance['date_range'], |
|
249 | - $yes_no_values, |
|
250 | - $this->fieldName('date_range'), |
|
251 | - $this->fieldID('date_range') |
|
252 | - ); |
|
253 | - ?> |
|
246 | + echo EEH_Form_Fields::select( |
|
247 | + esc_html__('Show Date Range:', 'event_espresso'), |
|
248 | + $instance['date_range'], |
|
249 | + $yes_no_values, |
|
250 | + $this->fieldName('date_range'), |
|
251 | + $this->fieldID('date_range') |
|
252 | + ); |
|
253 | + ?> |
|
254 | 254 | <span class="description"> |
255 | 255 | <br /> |
256 | 256 | <?php esc_html_e( |
257 | - 'This setting will replace the list of dates in the widget.', |
|
258 | - 'event_espresso' |
|
259 | - ); ?> |
|
257 | + 'This setting will replace the list of dates in the widget.', |
|
258 | + 'event_espresso' |
|
259 | + ); ?> |
|
260 | 260 | </span> |
261 | 261 | </p> |
262 | 262 | |
263 | 263 | <?php |
264 | - } |
|
265 | - |
|
266 | - |
|
267 | - /** |
|
268 | - * Sanitize widget form values as they are saved. |
|
269 | - * |
|
270 | - * @param array $new_instance Values just sent to be saved. |
|
271 | - * @param array $old_instance Previously saved values from database. |
|
272 | - * |
|
273 | - * @return array Updated safe values to be saved. |
|
274 | - * @see WP_Widget::update() |
|
275 | - * |
|
276 | - */ |
|
277 | - public function update($new_instance, $old_instance) |
|
278 | - { |
|
279 | - $instance = $old_instance; |
|
280 | - $instance['title'] = ! empty($new_instance['title']) ? strip_tags($new_instance['title']) : ''; |
|
281 | - $instance['category_name'] = $new_instance['category_name']; |
|
282 | - $instance['show_expired'] = $new_instance['show_expired']; |
|
283 | - $instance['limit'] = $new_instance['limit']; |
|
284 | - $instance['sort'] = $new_instance['sort']; |
|
285 | - $instance['image_size'] = $new_instance['image_size']; |
|
286 | - $instance['show_desc'] = $new_instance['show_desc']; |
|
287 | - $instance['show_dates'] = $new_instance['show_dates']; |
|
288 | - $instance['show_everywhere'] = $new_instance['show_everywhere']; |
|
289 | - $instance['date_limit'] = $new_instance['date_limit']; |
|
290 | - $instance['date_range'] = $new_instance['date_range']; |
|
291 | - return $instance; |
|
292 | - } |
|
293 | - |
|
294 | - |
|
295 | - /** |
|
296 | - * Front-end display of widget. |
|
297 | - * |
|
298 | - * @param array $args Widget arguments. |
|
299 | - * @param array $instance Saved values from database. |
|
300 | - * @throws EE_Error |
|
301 | - * @throws ReflectionException |
|
302 | - * @see WP_Widget::widget() |
|
303 | - * |
|
304 | - */ |
|
305 | - public function widget($args, $instance) |
|
306 | - { |
|
307 | - |
|
308 | - global $post; |
|
309 | - // make sure there is some kinda post object |
|
310 | - if ($post instanceof WP_Post) { |
|
311 | - $before_widget = ''; |
|
312 | - $before_title = ''; |
|
313 | - $after_title = ''; |
|
314 | - $after_widget = ''; |
|
315 | - // but NOT an events archives page, cuz that would be like two event lists on the same page |
|
316 | - $show_everywhere = ! isset($instance['show_everywhere']) || absint($instance['show_everywhere']); |
|
317 | - if ($show_everywhere || ! ($post->post_type == 'espresso_events' && is_archive())) { |
|
318 | - // let's use some of the event helper functions' |
|
319 | - // make separate vars out of attributes |
|
320 | - extract($args); |
|
321 | - |
|
322 | - // grab widget settings |
|
323 | - $this->parseWidgetSettings($instance); |
|
324 | - $title = $this->widgetTitle(); |
|
325 | - |
|
326 | - // Before widget (defined by themes). |
|
327 | - echo $before_widget; |
|
328 | - // Display the widget title if one was input (before and after defined by themes). |
|
329 | - if (! empty($title)) { |
|
330 | - echo $before_title . $title . $after_title; |
|
331 | - } |
|
332 | - echo $this->widgetContent($post); |
|
333 | - // After widget (defined by themes). |
|
334 | - echo $after_widget; |
|
335 | - } |
|
336 | - } |
|
337 | - } |
|
338 | - |
|
339 | - |
|
340 | - /** |
|
341 | - * make_the_title_a_link |
|
342 | - * callback for widget_title filter |
|
343 | - * |
|
344 | - * @param $title |
|
345 | - * @return string |
|
346 | - */ |
|
347 | - public function make_the_title_a_link($title) |
|
348 | - { |
|
349 | - return '<a href="' . EEH_Event_View::event_archive_url() . '">' . $title . '</a>'; |
|
350 | - } |
|
351 | - |
|
352 | - |
|
353 | - /** |
|
354 | - * @param string $field_name |
|
355 | - * @return string |
|
356 | - * @since 4.10.14.p |
|
357 | - */ |
|
358 | - public function fieldID($field_name) |
|
359 | - { |
|
360 | - return esc_attr(parent::get_field_id($field_name)); |
|
361 | - } |
|
362 | - |
|
363 | - |
|
364 | - /** |
|
365 | - * @param string $field_name |
|
366 | - * @return string |
|
367 | - * @since 4.10.14.p |
|
368 | - */ |
|
369 | - public function fieldName($field_name) |
|
370 | - { |
|
371 | - return esc_attr(parent::get_field_name($field_name)); |
|
372 | - } |
|
373 | - |
|
374 | - |
|
375 | - /** |
|
376 | - * @param array $instance |
|
377 | - * @throws EE_Error |
|
378 | - * @throws ReflectionException |
|
379 | - * @since 4.10.14.p |
|
380 | - */ |
|
381 | - private function eventCategoriesSelector(array $instance) |
|
382 | - { |
|
383 | - $event_categories = []; |
|
384 | - $categories = EEM_Term::instance()->get_all_ee_categories(true); |
|
385 | - if ($categories) { |
|
386 | - foreach ($categories as $category) { |
|
387 | - if ($category instanceof EE_Term) { |
|
388 | - $event_categories[] = |
|
389 | - EE_Question_Option::new_instance( |
|
390 | - [ |
|
391 | - 'QSO_value' => $category->get('slug'), |
|
392 | - 'QSO_desc' => $category->get('name'), |
|
393 | - ] |
|
394 | - ); |
|
395 | - } |
|
396 | - } |
|
397 | - } |
|
398 | - array_unshift( |
|
399 | - $event_categories, |
|
400 | - EE_Question_Option::new_instance( |
|
401 | - [ |
|
402 | - 'QSO_value' => '', |
|
403 | - 'QSO_desc' => esc_html__(' - display all - ', 'event_espresso'), |
|
404 | - ] |
|
405 | - ) |
|
406 | - ); |
|
407 | - echo EEH_Form_Fields::select( |
|
408 | - esc_html__('Event Category:', 'event_espresso'), |
|
409 | - $instance['category_name'], |
|
410 | - $event_categories, |
|
411 | - $this->fieldName('category_name'), |
|
412 | - $this->fieldID('category_name') |
|
413 | - ); |
|
414 | - } |
|
415 | - |
|
416 | - |
|
417 | - /** |
|
418 | - * @param array $instance |
|
419 | - * @since 4.10.14.p |
|
420 | - */ |
|
421 | - private function imageSizeSelector(array $instance) |
|
422 | - { |
|
423 | - $image_sizes = []; |
|
424 | - $sizes = get_intermediate_image_sizes(); |
|
425 | - if ($sizes) { |
|
426 | - // loop thru images and create option objects out of them |
|
427 | - foreach ($sizes as $image_size) { |
|
428 | - $image_size = trim($image_size); |
|
429 | - // no big images plz |
|
430 | - if (! in_array($image_size, ['large', 'post-thumbnail'])) { |
|
431 | - $image_sizes[] = |
|
432 | - EE_Question_Option::new_instance(['QSO_value' => $image_size, 'QSO_desc' => $image_size]); |
|
433 | - } |
|
434 | - } |
|
435 | - $image_sizes[] = |
|
436 | - EE_Question_Option::new_instance( |
|
437 | - ['QSO_value' => 'none', 'QSO_desc' => esc_html__('don\'t show images', 'event_espresso')] |
|
438 | - ); |
|
439 | - } |
|
440 | - echo EEH_Form_Fields::select( |
|
441 | - esc_html__('Image Size:', 'event_espresso'), |
|
442 | - $instance['image_size'], |
|
443 | - $image_sizes, |
|
444 | - $this->fieldName('image_size'), |
|
445 | - $this->fieldID('image_size') |
|
446 | - ); |
|
447 | - } |
|
448 | - |
|
449 | - |
|
450 | - /** |
|
451 | - * @param array $instance |
|
452 | - * @since 4.10.14.p |
|
453 | - */ |
|
454 | - private function parseWidgetSettings(array $instance) |
|
455 | - { |
|
456 | - $this->title = isset($instance['title']) && ! empty($instance['title']) ? $instance['title'] : ''; |
|
457 | - $this->events_category = isset($instance['category_name']) && ! empty($instance['category_name']) |
|
458 | - ? $instance['category_name'] |
|
459 | - : false; |
|
460 | - $this->show_expired = isset($instance['show_expired']) |
|
461 | - ? filter_var($instance['show_expired'], FILTER_VALIDATE_BOOLEAN) |
|
462 | - : 0; |
|
463 | - $this->image_size = isset($instance['image_size']) && ! empty($instance['image_size']) |
|
464 | - ? $instance['image_size'] |
|
465 | - : 'medium'; |
|
466 | - $this->show_desc = ! isset($instance['show_desc']) |
|
467 | - || filter_var($instance['show_desc'], FILTER_VALIDATE_BOOLEAN); |
|
468 | - $this->show_dates = ! isset($instance['show_dates']) |
|
469 | - || filter_var($instance['show_dates'], FILTER_VALIDATE_BOOLEAN); |
|
470 | - $this->date_limit = isset($instance['date_limit']) && ! empty($instance['date_limit']) |
|
471 | - ? $instance['date_limit'] |
|
472 | - : null; |
|
473 | - $this->date_range = isset($instance['date_range']) && ! empty($instance['date_range']) |
|
474 | - ? $instance['date_range'] |
|
475 | - : false; |
|
476 | - $this->limit = isset($instance['limit']) ? absint($instance['limit']) : 10; |
|
477 | - $this->order = isset($instance['sort']) && $instance['sort'] === 'DESC' |
|
478 | - ? 'DESC' |
|
479 | - : 'ASC'; |
|
480 | - } |
|
481 | - |
|
482 | - |
|
483 | - /** |
|
484 | - * @return mixed|void |
|
485 | - * @since 4.10.14.p |
|
486 | - */ |
|
487 | - private function widgetTitle() |
|
488 | - { |
|
489 | - // add function to make the title a link |
|
490 | - add_filter('widget_title', [$this, 'make_the_title_a_link'], 15); |
|
491 | - // filter the title |
|
492 | - $title = apply_filters('widget_title', $this->title); |
|
493 | - // remove the function from the filter, so it does not affect other widgets |
|
494 | - remove_filter('widget_title', [$this, 'make_the_title_a_link'], 15); |
|
495 | - return $title; |
|
496 | - } |
|
497 | - |
|
498 | - |
|
499 | - /** |
|
500 | - * @param WP_Post $post |
|
501 | - * @return string |
|
502 | - * @throws EE_Error |
|
503 | - * @throws ReflectionException |
|
504 | - * @since 4.10.14.p |
|
505 | - */ |
|
506 | - private function widgetContent(WP_Post $post) |
|
507 | - { |
|
508 | - // run the query |
|
509 | - $events = $this->getUpcomingEvents(); |
|
510 | - if (empty($events)) { |
|
511 | - return ''; |
|
512 | - } |
|
513 | - $list_items = ''; |
|
514 | - foreach ($events as $event) { |
|
515 | - if ($event instanceof EE_Event && (! is_single() || $post->ID != $event->ID())) { |
|
516 | - $event_url = $this->eventUrl($event); |
|
517 | - $list_items .= ' |
|
264 | + } |
|
265 | + |
|
266 | + |
|
267 | + /** |
|
268 | + * Sanitize widget form values as they are saved. |
|
269 | + * |
|
270 | + * @param array $new_instance Values just sent to be saved. |
|
271 | + * @param array $old_instance Previously saved values from database. |
|
272 | + * |
|
273 | + * @return array Updated safe values to be saved. |
|
274 | + * @see WP_Widget::update() |
|
275 | + * |
|
276 | + */ |
|
277 | + public function update($new_instance, $old_instance) |
|
278 | + { |
|
279 | + $instance = $old_instance; |
|
280 | + $instance['title'] = ! empty($new_instance['title']) ? strip_tags($new_instance['title']) : ''; |
|
281 | + $instance['category_name'] = $new_instance['category_name']; |
|
282 | + $instance['show_expired'] = $new_instance['show_expired']; |
|
283 | + $instance['limit'] = $new_instance['limit']; |
|
284 | + $instance['sort'] = $new_instance['sort']; |
|
285 | + $instance['image_size'] = $new_instance['image_size']; |
|
286 | + $instance['show_desc'] = $new_instance['show_desc']; |
|
287 | + $instance['show_dates'] = $new_instance['show_dates']; |
|
288 | + $instance['show_everywhere'] = $new_instance['show_everywhere']; |
|
289 | + $instance['date_limit'] = $new_instance['date_limit']; |
|
290 | + $instance['date_range'] = $new_instance['date_range']; |
|
291 | + return $instance; |
|
292 | + } |
|
293 | + |
|
294 | + |
|
295 | + /** |
|
296 | + * Front-end display of widget. |
|
297 | + * |
|
298 | + * @param array $args Widget arguments. |
|
299 | + * @param array $instance Saved values from database. |
|
300 | + * @throws EE_Error |
|
301 | + * @throws ReflectionException |
|
302 | + * @see WP_Widget::widget() |
|
303 | + * |
|
304 | + */ |
|
305 | + public function widget($args, $instance) |
|
306 | + { |
|
307 | + |
|
308 | + global $post; |
|
309 | + // make sure there is some kinda post object |
|
310 | + if ($post instanceof WP_Post) { |
|
311 | + $before_widget = ''; |
|
312 | + $before_title = ''; |
|
313 | + $after_title = ''; |
|
314 | + $after_widget = ''; |
|
315 | + // but NOT an events archives page, cuz that would be like two event lists on the same page |
|
316 | + $show_everywhere = ! isset($instance['show_everywhere']) || absint($instance['show_everywhere']); |
|
317 | + if ($show_everywhere || ! ($post->post_type == 'espresso_events' && is_archive())) { |
|
318 | + // let's use some of the event helper functions' |
|
319 | + // make separate vars out of attributes |
|
320 | + extract($args); |
|
321 | + |
|
322 | + // grab widget settings |
|
323 | + $this->parseWidgetSettings($instance); |
|
324 | + $title = $this->widgetTitle(); |
|
325 | + |
|
326 | + // Before widget (defined by themes). |
|
327 | + echo $before_widget; |
|
328 | + // Display the widget title if one was input (before and after defined by themes). |
|
329 | + if (! empty($title)) { |
|
330 | + echo $before_title . $title . $after_title; |
|
331 | + } |
|
332 | + echo $this->widgetContent($post); |
|
333 | + // After widget (defined by themes). |
|
334 | + echo $after_widget; |
|
335 | + } |
|
336 | + } |
|
337 | + } |
|
338 | + |
|
339 | + |
|
340 | + /** |
|
341 | + * make_the_title_a_link |
|
342 | + * callback for widget_title filter |
|
343 | + * |
|
344 | + * @param $title |
|
345 | + * @return string |
|
346 | + */ |
|
347 | + public function make_the_title_a_link($title) |
|
348 | + { |
|
349 | + return '<a href="' . EEH_Event_View::event_archive_url() . '">' . $title . '</a>'; |
|
350 | + } |
|
351 | + |
|
352 | + |
|
353 | + /** |
|
354 | + * @param string $field_name |
|
355 | + * @return string |
|
356 | + * @since 4.10.14.p |
|
357 | + */ |
|
358 | + public function fieldID($field_name) |
|
359 | + { |
|
360 | + return esc_attr(parent::get_field_id($field_name)); |
|
361 | + } |
|
362 | + |
|
363 | + |
|
364 | + /** |
|
365 | + * @param string $field_name |
|
366 | + * @return string |
|
367 | + * @since 4.10.14.p |
|
368 | + */ |
|
369 | + public function fieldName($field_name) |
|
370 | + { |
|
371 | + return esc_attr(parent::get_field_name($field_name)); |
|
372 | + } |
|
373 | + |
|
374 | + |
|
375 | + /** |
|
376 | + * @param array $instance |
|
377 | + * @throws EE_Error |
|
378 | + * @throws ReflectionException |
|
379 | + * @since 4.10.14.p |
|
380 | + */ |
|
381 | + private function eventCategoriesSelector(array $instance) |
|
382 | + { |
|
383 | + $event_categories = []; |
|
384 | + $categories = EEM_Term::instance()->get_all_ee_categories(true); |
|
385 | + if ($categories) { |
|
386 | + foreach ($categories as $category) { |
|
387 | + if ($category instanceof EE_Term) { |
|
388 | + $event_categories[] = |
|
389 | + EE_Question_Option::new_instance( |
|
390 | + [ |
|
391 | + 'QSO_value' => $category->get('slug'), |
|
392 | + 'QSO_desc' => $category->get('name'), |
|
393 | + ] |
|
394 | + ); |
|
395 | + } |
|
396 | + } |
|
397 | + } |
|
398 | + array_unshift( |
|
399 | + $event_categories, |
|
400 | + EE_Question_Option::new_instance( |
|
401 | + [ |
|
402 | + 'QSO_value' => '', |
|
403 | + 'QSO_desc' => esc_html__(' - display all - ', 'event_espresso'), |
|
404 | + ] |
|
405 | + ) |
|
406 | + ); |
|
407 | + echo EEH_Form_Fields::select( |
|
408 | + esc_html__('Event Category:', 'event_espresso'), |
|
409 | + $instance['category_name'], |
|
410 | + $event_categories, |
|
411 | + $this->fieldName('category_name'), |
|
412 | + $this->fieldID('category_name') |
|
413 | + ); |
|
414 | + } |
|
415 | + |
|
416 | + |
|
417 | + /** |
|
418 | + * @param array $instance |
|
419 | + * @since 4.10.14.p |
|
420 | + */ |
|
421 | + private function imageSizeSelector(array $instance) |
|
422 | + { |
|
423 | + $image_sizes = []; |
|
424 | + $sizes = get_intermediate_image_sizes(); |
|
425 | + if ($sizes) { |
|
426 | + // loop thru images and create option objects out of them |
|
427 | + foreach ($sizes as $image_size) { |
|
428 | + $image_size = trim($image_size); |
|
429 | + // no big images plz |
|
430 | + if (! in_array($image_size, ['large', 'post-thumbnail'])) { |
|
431 | + $image_sizes[] = |
|
432 | + EE_Question_Option::new_instance(['QSO_value' => $image_size, 'QSO_desc' => $image_size]); |
|
433 | + } |
|
434 | + } |
|
435 | + $image_sizes[] = |
|
436 | + EE_Question_Option::new_instance( |
|
437 | + ['QSO_value' => 'none', 'QSO_desc' => esc_html__('don\'t show images', 'event_espresso')] |
|
438 | + ); |
|
439 | + } |
|
440 | + echo EEH_Form_Fields::select( |
|
441 | + esc_html__('Image Size:', 'event_espresso'), |
|
442 | + $instance['image_size'], |
|
443 | + $image_sizes, |
|
444 | + $this->fieldName('image_size'), |
|
445 | + $this->fieldID('image_size') |
|
446 | + ); |
|
447 | + } |
|
448 | + |
|
449 | + |
|
450 | + /** |
|
451 | + * @param array $instance |
|
452 | + * @since 4.10.14.p |
|
453 | + */ |
|
454 | + private function parseWidgetSettings(array $instance) |
|
455 | + { |
|
456 | + $this->title = isset($instance['title']) && ! empty($instance['title']) ? $instance['title'] : ''; |
|
457 | + $this->events_category = isset($instance['category_name']) && ! empty($instance['category_name']) |
|
458 | + ? $instance['category_name'] |
|
459 | + : false; |
|
460 | + $this->show_expired = isset($instance['show_expired']) |
|
461 | + ? filter_var($instance['show_expired'], FILTER_VALIDATE_BOOLEAN) |
|
462 | + : 0; |
|
463 | + $this->image_size = isset($instance['image_size']) && ! empty($instance['image_size']) |
|
464 | + ? $instance['image_size'] |
|
465 | + : 'medium'; |
|
466 | + $this->show_desc = ! isset($instance['show_desc']) |
|
467 | + || filter_var($instance['show_desc'], FILTER_VALIDATE_BOOLEAN); |
|
468 | + $this->show_dates = ! isset($instance['show_dates']) |
|
469 | + || filter_var($instance['show_dates'], FILTER_VALIDATE_BOOLEAN); |
|
470 | + $this->date_limit = isset($instance['date_limit']) && ! empty($instance['date_limit']) |
|
471 | + ? $instance['date_limit'] |
|
472 | + : null; |
|
473 | + $this->date_range = isset($instance['date_range']) && ! empty($instance['date_range']) |
|
474 | + ? $instance['date_range'] |
|
475 | + : false; |
|
476 | + $this->limit = isset($instance['limit']) ? absint($instance['limit']) : 10; |
|
477 | + $this->order = isset($instance['sort']) && $instance['sort'] === 'DESC' |
|
478 | + ? 'DESC' |
|
479 | + : 'ASC'; |
|
480 | + } |
|
481 | + |
|
482 | + |
|
483 | + /** |
|
484 | + * @return mixed|void |
|
485 | + * @since 4.10.14.p |
|
486 | + */ |
|
487 | + private function widgetTitle() |
|
488 | + { |
|
489 | + // add function to make the title a link |
|
490 | + add_filter('widget_title', [$this, 'make_the_title_a_link'], 15); |
|
491 | + // filter the title |
|
492 | + $title = apply_filters('widget_title', $this->title); |
|
493 | + // remove the function from the filter, so it does not affect other widgets |
|
494 | + remove_filter('widget_title', [$this, 'make_the_title_a_link'], 15); |
|
495 | + return $title; |
|
496 | + } |
|
497 | + |
|
498 | + |
|
499 | + /** |
|
500 | + * @param WP_Post $post |
|
501 | + * @return string |
|
502 | + * @throws EE_Error |
|
503 | + * @throws ReflectionException |
|
504 | + * @since 4.10.14.p |
|
505 | + */ |
|
506 | + private function widgetContent(WP_Post $post) |
|
507 | + { |
|
508 | + // run the query |
|
509 | + $events = $this->getUpcomingEvents(); |
|
510 | + if (empty($events)) { |
|
511 | + return ''; |
|
512 | + } |
|
513 | + $list_items = ''; |
|
514 | + foreach ($events as $event) { |
|
515 | + if ($event instanceof EE_Event && (! is_single() || $post->ID != $event->ID())) { |
|
516 | + $event_url = $this->eventUrl($event); |
|
517 | + $list_items .= ' |
|
518 | 518 | <li id="ee-upcoming-events-widget-li-' . esc_attr($event->ID()) . '" |
519 | 519 | class="ee-upcoming-events-widget-li" |
520 | 520 | > |
@@ -525,194 +525,194 @@ discard block |
||
525 | 525 | </h5> |
526 | 526 | ' . $this->eventWidgetContent($event, $event_url) . ' |
527 | 527 | </li>'; |
528 | - } |
|
529 | - } |
|
530 | - return ' |
|
528 | + } |
|
529 | + } |
|
530 | + return ' |
|
531 | 531 | <ul class="ee-upcoming-events-widget-ul"> |
532 | 532 | ' . $list_items . ' |
533 | 533 | </ul>'; |
534 | - } |
|
535 | - |
|
536 | - |
|
537 | - /** |
|
538 | - * @param EE_Event $event |
|
539 | - * @return string|null |
|
540 | - * @throws EE_Error |
|
541 | - * @since 4.10.14.p |
|
542 | - */ |
|
543 | - private function eventUrl(EE_Event $event) |
|
544 | - { |
|
545 | - return esc_url_raw( |
|
546 | - apply_filters( |
|
547 | - 'FHEE_EEW_Upcoming_Events__widget__event_url', |
|
548 | - $event->get_permalink(), |
|
549 | - $event |
|
550 | - ) |
|
551 | - ); |
|
552 | - } |
|
553 | - |
|
554 | - |
|
555 | - /** |
|
556 | - * @return EE_Base_Class[] |
|
557 | - * @throws EE_Error |
|
558 | - */ |
|
559 | - private function getUpcomingEvents() |
|
560 | - { |
|
561 | - return EEM_Event::instance()->get_all( |
|
562 | - [ |
|
563 | - $this->queryWhereParams(), |
|
564 | - 'limit' => '0,' . $this->limit, |
|
565 | - 'order_by' => 'Datetime.DTT_EVT_start', |
|
566 | - 'order' => $this->order, |
|
567 | - 'group_by' => 'EVT_ID', |
|
568 | - ] |
|
569 | - ); |
|
570 | - } |
|
571 | - |
|
572 | - |
|
573 | - /** |
|
574 | - * @return mixed|void |
|
575 | - * @throws EE_Error |
|
576 | - * @since 4.10.14.p |
|
577 | - */ |
|
578 | - private function queryWhereParams() |
|
579 | - { |
|
580 | - // start to build our where clause |
|
581 | - $where = [ |
|
582 | - 'status' => ['IN', ['publish', 'sold_out']], |
|
583 | - ]; |
|
584 | - // add category |
|
585 | - if ($this->events_category) { |
|
586 | - $where['Term_Taxonomy.taxonomy'] = 'espresso_event_categories'; |
|
587 | - $where['Term_Taxonomy.Term.slug'] = $this->events_category; |
|
588 | - } |
|
589 | - // if NOT expired then we want events that start today or in the future |
|
590 | - // if NOT show expired then we want events that start today or in the future |
|
591 | - if ($this->show_expired == 0) { |
|
592 | - $where['Datetime.DTT_EVT_end'] = [ |
|
593 | - '>=', |
|
594 | - EEM_Datetime::instance()->current_time_for_query('DTT_EVT_end'), |
|
595 | - ]; |
|
596 | - } |
|
597 | - // if show ONLY expired we want events that ended prior to today |
|
598 | - if ($this->show_expired == 2) { |
|
599 | - $where['Datetime.DTT_EVT_end'] = [ |
|
600 | - '<=', |
|
601 | - EEM_Datetime::instance()->current_time_for_query('DTT_EVT_start'), |
|
602 | - ]; |
|
603 | - } |
|
604 | - // allow $where to be filtered |
|
605 | - return apply_filters('FHEE__EEW_Upcoming_Events__widget__where', $where, $this->events_category, $this->show_expired); |
|
606 | - } |
|
607 | - |
|
608 | - |
|
609 | - /** |
|
610 | - * @param EE_Event $event |
|
611 | - * @return string |
|
612 | - * @throws EE_Error |
|
613 | - * @throws ReflectionException |
|
614 | - * @since 4.10.14.p |
|
615 | - */ |
|
616 | - private function linkClass(EE_Event $event) |
|
617 | - { |
|
618 | - // how big is the event name ? |
|
619 | - $name_length = strlen($event->name()); |
|
620 | - switch ($name_length) { |
|
621 | - case $name_length > 70: |
|
622 | - return ' three-line'; |
|
623 | - case $name_length > 35: |
|
624 | - return ' two-line'; |
|
625 | - } |
|
626 | - return ' one-line'; |
|
627 | - } |
|
628 | - |
|
629 | - |
|
630 | - /** |
|
631 | - * @param EE_Event $event |
|
632 | - * @param string $event_url |
|
633 | - * @return mixed|string|void |
|
634 | - * @throws EE_Error |
|
635 | - * @throws ReflectionException |
|
636 | - * @since 4.10.14.p |
|
637 | - */ |
|
638 | - private function eventWidgetContent(EE_Event $event, $event_url = '') |
|
639 | - { |
|
640 | - if (post_password_required($event->ID())) { |
|
641 | - return apply_filters( |
|
642 | - 'FHEE_EEW_Upcoming_Events__widget__password_form', |
|
643 | - get_the_password_form($event->ID()), |
|
644 | - $event |
|
645 | - ); |
|
646 | - } |
|
647 | - |
|
648 | - $content = ''; |
|
649 | - if (has_post_thumbnail($event->ID()) && $this->image_size != 'none') { |
|
650 | - $content .= ' |
|
534 | + } |
|
535 | + |
|
536 | + |
|
537 | + /** |
|
538 | + * @param EE_Event $event |
|
539 | + * @return string|null |
|
540 | + * @throws EE_Error |
|
541 | + * @since 4.10.14.p |
|
542 | + */ |
|
543 | + private function eventUrl(EE_Event $event) |
|
544 | + { |
|
545 | + return esc_url_raw( |
|
546 | + apply_filters( |
|
547 | + 'FHEE_EEW_Upcoming_Events__widget__event_url', |
|
548 | + $event->get_permalink(), |
|
549 | + $event |
|
550 | + ) |
|
551 | + ); |
|
552 | + } |
|
553 | + |
|
554 | + |
|
555 | + /** |
|
556 | + * @return EE_Base_Class[] |
|
557 | + * @throws EE_Error |
|
558 | + */ |
|
559 | + private function getUpcomingEvents() |
|
560 | + { |
|
561 | + return EEM_Event::instance()->get_all( |
|
562 | + [ |
|
563 | + $this->queryWhereParams(), |
|
564 | + 'limit' => '0,' . $this->limit, |
|
565 | + 'order_by' => 'Datetime.DTT_EVT_start', |
|
566 | + 'order' => $this->order, |
|
567 | + 'group_by' => 'EVT_ID', |
|
568 | + ] |
|
569 | + ); |
|
570 | + } |
|
571 | + |
|
572 | + |
|
573 | + /** |
|
574 | + * @return mixed|void |
|
575 | + * @throws EE_Error |
|
576 | + * @since 4.10.14.p |
|
577 | + */ |
|
578 | + private function queryWhereParams() |
|
579 | + { |
|
580 | + // start to build our where clause |
|
581 | + $where = [ |
|
582 | + 'status' => ['IN', ['publish', 'sold_out']], |
|
583 | + ]; |
|
584 | + // add category |
|
585 | + if ($this->events_category) { |
|
586 | + $where['Term_Taxonomy.taxonomy'] = 'espresso_event_categories'; |
|
587 | + $where['Term_Taxonomy.Term.slug'] = $this->events_category; |
|
588 | + } |
|
589 | + // if NOT expired then we want events that start today or in the future |
|
590 | + // if NOT show expired then we want events that start today or in the future |
|
591 | + if ($this->show_expired == 0) { |
|
592 | + $where['Datetime.DTT_EVT_end'] = [ |
|
593 | + '>=', |
|
594 | + EEM_Datetime::instance()->current_time_for_query('DTT_EVT_end'), |
|
595 | + ]; |
|
596 | + } |
|
597 | + // if show ONLY expired we want events that ended prior to today |
|
598 | + if ($this->show_expired == 2) { |
|
599 | + $where['Datetime.DTT_EVT_end'] = [ |
|
600 | + '<=', |
|
601 | + EEM_Datetime::instance()->current_time_for_query('DTT_EVT_start'), |
|
602 | + ]; |
|
603 | + } |
|
604 | + // allow $where to be filtered |
|
605 | + return apply_filters('FHEE__EEW_Upcoming_Events__widget__where', $where, $this->events_category, $this->show_expired); |
|
606 | + } |
|
607 | + |
|
608 | + |
|
609 | + /** |
|
610 | + * @param EE_Event $event |
|
611 | + * @return string |
|
612 | + * @throws EE_Error |
|
613 | + * @throws ReflectionException |
|
614 | + * @since 4.10.14.p |
|
615 | + */ |
|
616 | + private function linkClass(EE_Event $event) |
|
617 | + { |
|
618 | + // how big is the event name ? |
|
619 | + $name_length = strlen($event->name()); |
|
620 | + switch ($name_length) { |
|
621 | + case $name_length > 70: |
|
622 | + return ' three-line'; |
|
623 | + case $name_length > 35: |
|
624 | + return ' two-line'; |
|
625 | + } |
|
626 | + return ' one-line'; |
|
627 | + } |
|
628 | + |
|
629 | + |
|
630 | + /** |
|
631 | + * @param EE_Event $event |
|
632 | + * @param string $event_url |
|
633 | + * @return mixed|string|void |
|
634 | + * @throws EE_Error |
|
635 | + * @throws ReflectionException |
|
636 | + * @since 4.10.14.p |
|
637 | + */ |
|
638 | + private function eventWidgetContent(EE_Event $event, $event_url = '') |
|
639 | + { |
|
640 | + if (post_password_required($event->ID())) { |
|
641 | + return apply_filters( |
|
642 | + 'FHEE_EEW_Upcoming_Events__widget__password_form', |
|
643 | + get_the_password_form($event->ID()), |
|
644 | + $event |
|
645 | + ); |
|
646 | + } |
|
647 | + |
|
648 | + $content = ''; |
|
649 | + if (has_post_thumbnail($event->ID()) && $this->image_size != 'none') { |
|
650 | + $content .= ' |
|
651 | 651 | <div class="ee-upcoming-events-widget-img-dv"> |
652 | 652 | <a class="ee-upcoming-events-widget-img" href="' . $event_url . '"> |
653 | 653 | ' . get_the_post_thumbnail($event->ID(), $this->image_size) . ' |
654 | 654 | </a> |
655 | 655 | </div>'; |
656 | - } |
|
657 | - |
|
658 | - if ($this->show_dates) { |
|
659 | - $content .= $this->eventDates($event); |
|
660 | - } |
|
661 | - |
|
662 | - if ($this->show_desc) { |
|
663 | - global $allowedtags; |
|
664 | - $desc = $event->short_description(25); |
|
665 | - $content .= $desc ? '<p style="margin-top: .5em">' . wp_kses($desc, $allowedtags) . '</p>' : ''; |
|
666 | - } |
|
667 | - |
|
668 | - return $content; |
|
669 | - } |
|
670 | - |
|
671 | - |
|
672 | - /** |
|
673 | - * @param EE_Event $event |
|
674 | - * @return string |
|
675 | - * @throws EE_Error |
|
676 | - * @throws ReflectionException |
|
677 | - * @since 4.10.14.p |
|
678 | - */ |
|
679 | - private function eventDates(EE_Event $event) |
|
680 | - { |
|
681 | - $date_format = apply_filters( |
|
682 | - 'FHEE__espresso_event_date_range__date_format', |
|
683 | - get_option('date_format') |
|
684 | - ); |
|
685 | - $time_format = apply_filters( |
|
686 | - 'FHEE__espresso_event_date_range__time_format', |
|
687 | - get_option('time_format') |
|
688 | - ); |
|
689 | - $single_date_format = apply_filters( |
|
690 | - 'FHEE__espresso_event_date_range__single_date_format', |
|
691 | - get_option('date_format') |
|
692 | - ); |
|
693 | - $single_time_format = apply_filters( |
|
694 | - 'FHEE__espresso_event_date_range__single_time_format', |
|
695 | - get_option('time_format') |
|
696 | - ); |
|
697 | - if ($this->date_range == true) { |
|
698 | - return espresso_event_date_range( |
|
699 | - $date_format, |
|
700 | - $time_format, |
|
701 | - $single_date_format, |
|
702 | - $single_time_format, |
|
703 | - $event->ID(), |
|
704 | - false |
|
705 | - ); |
|
706 | - } |
|
707 | - return espresso_list_of_event_dates( |
|
708 | - $event->ID(), |
|
709 | - $date_format, |
|
710 | - $time_format, |
|
711 | - false, |
|
712 | - null, |
|
713 | - true, |
|
714 | - true, |
|
715 | - $this->date_limit |
|
716 | - ); |
|
717 | - } |
|
656 | + } |
|
657 | + |
|
658 | + if ($this->show_dates) { |
|
659 | + $content .= $this->eventDates($event); |
|
660 | + } |
|
661 | + |
|
662 | + if ($this->show_desc) { |
|
663 | + global $allowedtags; |
|
664 | + $desc = $event->short_description(25); |
|
665 | + $content .= $desc ? '<p style="margin-top: .5em">' . wp_kses($desc, $allowedtags) . '</p>' : ''; |
|
666 | + } |
|
667 | + |
|
668 | + return $content; |
|
669 | + } |
|
670 | + |
|
671 | + |
|
672 | + /** |
|
673 | + * @param EE_Event $event |
|
674 | + * @return string |
|
675 | + * @throws EE_Error |
|
676 | + * @throws ReflectionException |
|
677 | + * @since 4.10.14.p |
|
678 | + */ |
|
679 | + private function eventDates(EE_Event $event) |
|
680 | + { |
|
681 | + $date_format = apply_filters( |
|
682 | + 'FHEE__espresso_event_date_range__date_format', |
|
683 | + get_option('date_format') |
|
684 | + ); |
|
685 | + $time_format = apply_filters( |
|
686 | + 'FHEE__espresso_event_date_range__time_format', |
|
687 | + get_option('time_format') |
|
688 | + ); |
|
689 | + $single_date_format = apply_filters( |
|
690 | + 'FHEE__espresso_event_date_range__single_date_format', |
|
691 | + get_option('date_format') |
|
692 | + ); |
|
693 | + $single_time_format = apply_filters( |
|
694 | + 'FHEE__espresso_event_date_range__single_time_format', |
|
695 | + get_option('time_format') |
|
696 | + ); |
|
697 | + if ($this->date_range == true) { |
|
698 | + return espresso_event_date_range( |
|
699 | + $date_format, |
|
700 | + $time_format, |
|
701 | + $single_date_format, |
|
702 | + $single_time_format, |
|
703 | + $event->ID(), |
|
704 | + false |
|
705 | + ); |
|
706 | + } |
|
707 | + return espresso_list_of_event_dates( |
|
708 | + $event->ID(), |
|
709 | + $date_format, |
|
710 | + $time_format, |
|
711 | + false, |
|
712 | + null, |
|
713 | + true, |
|
714 | + true, |
|
715 | + $this->date_limit |
|
716 | + ); |
|
717 | + } |
|
718 | 718 | } |
@@ -83,8 +83,8 @@ discard block |
||
83 | 83 | */ |
84 | 84 | public static function set_definitions() |
85 | 85 | { |
86 | - define('EVENT_SINGLE_ASSETS_URL', plugin_dir_url(__FILE__) . 'assets/'); |
|
87 | - define('EVENT_SINGLE_TEMPLATES_PATH', plugin_dir_path(__FILE__) . 'templates/'); |
|
86 | + define('EVENT_SINGLE_ASSETS_URL', plugin_dir_url(__FILE__).'assets/'); |
|
87 | + define('EVENT_SINGLE_TEMPLATES_PATH', plugin_dir_path(__FILE__).'templates/'); |
|
88 | 88 | } |
89 | 89 | |
90 | 90 | |
@@ -225,7 +225,7 @@ discard block |
||
225 | 225 | { |
226 | 226 | global $post; |
227 | 227 | return ((function_exists('wp_is_block_theme') && wp_is_block_theme()) || in_the_loop()) && $post->ID === (int) $id |
228 | - ? espresso_event_status_banner($post->ID) . $title |
|
228 | + ? espresso_event_status_banner($post->ID).$title |
|
229 | 229 | : $title; |
230 | 230 | } |
231 | 231 | |
@@ -382,7 +382,7 @@ discard block |
||
382 | 382 | */ |
383 | 383 | public static function event_datetimes($content) |
384 | 384 | { |
385 | - return EEH_Template::locate_template('content-espresso_events-datetimes.php') . $content; |
|
385 | + return EEH_Template::locate_template('content-espresso_events-datetimes.php').$content; |
|
386 | 386 | } |
387 | 387 | |
388 | 388 | |
@@ -394,7 +394,7 @@ discard block |
||
394 | 394 | */ |
395 | 395 | public static function event_tickets($content) |
396 | 396 | { |
397 | - return EEH_Template::locate_template('content-espresso_events-tickets.php') . $content; |
|
397 | + return EEH_Template::locate_template('content-espresso_events-tickets.php').$content; |
|
398 | 398 | } |
399 | 399 | |
400 | 400 | |
@@ -418,7 +418,7 @@ discard block |
||
418 | 418 | */ |
419 | 419 | public static function event_venues($content) |
420 | 420 | { |
421 | - return $content . EEH_Template::locate_template('content-espresso_events-venues.php'); |
|
421 | + return $content.EEH_Template::locate_template('content-espresso_events-venues.php'); |
|
422 | 422 | } |
423 | 423 | |
424 | 424 | |
@@ -448,16 +448,16 @@ discard block |
||
448 | 448 | && apply_filters('FHEE__EED_Event_Single__wp_enqueue_scripts__enable_css', true) |
449 | 449 | ) { |
450 | 450 | // first check uploads folder |
451 | - if (is_readable(get_stylesheet_directory() . $this->theme . '/style.css')) { |
|
451 | + if (is_readable(get_stylesheet_directory().$this->theme.'/style.css')) { |
|
452 | 452 | wp_register_style( |
453 | 453 | $this->theme, |
454 | - get_stylesheet_directory_uri() . $this->theme . '/style.css', |
|
454 | + get_stylesheet_directory_uri().$this->theme.'/style.css', |
|
455 | 455 | array('dashicons', 'espresso_default') |
456 | 456 | ); |
457 | 457 | } else { |
458 | 458 | wp_register_style( |
459 | 459 | $this->theme, |
460 | - EE_TEMPLATES_URL . $this->theme . '/style.css', |
|
460 | + EE_TEMPLATES_URL.$this->theme.'/style.css', |
|
461 | 461 | array('dashicons', 'espresso_default') |
462 | 462 | ); |
463 | 463 | } |
@@ -14,475 +14,475 @@ discard block |
||
14 | 14 | class EED_Event_Single extends EED_Module |
15 | 15 | { |
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; |
|
21 | - |
|
22 | - /** |
|
23 | - * @type bool $using_get_the_excerpt |
|
24 | - */ |
|
25 | - protected static $using_get_the_excerpt = false; |
|
26 | - |
|
27 | - |
|
28 | - /** |
|
29 | - * @type EE_Template_Part_Manager $template_parts |
|
30 | - */ |
|
31 | - protected $template_parts; |
|
32 | - |
|
33 | - |
|
34 | - /** |
|
35 | - * @return EED_Module|EED_Event_Single |
|
36 | - */ |
|
37 | - public static function instance() |
|
38 | - { |
|
39 | - return parent::get_instance(__CLASS__); |
|
40 | - } |
|
41 | - |
|
42 | - |
|
43 | - /** |
|
44 | - * set_hooks - for hooking into EE Core, other modules, etc |
|
45 | - * |
|
46 | - * @return void |
|
47 | - * @throws InvalidArgumentException |
|
48 | - * @throws InvalidDataTypeException |
|
49 | - * @throws InvalidInterfaceException |
|
50 | - */ |
|
51 | - public static function set_hooks() |
|
52 | - { |
|
53 | - add_filter('FHEE_run_EE_wp', '__return_true'); |
|
54 | - add_action('wp_loaded', array('EED_Event_Single', 'set_definitions'), 2); |
|
55 | - /** @var EventEspresso\core\domain\entities\custom_post_types\CustomPostTypeDefinitions $custom_post_type_definitions */ |
|
56 | - $custom_post_type_definitions = LoaderFactory::getLoader()->getShared( |
|
57 | - 'EventEspresso\core\domain\entities\custom_post_types\CustomPostTypeDefinitions' |
|
58 | - ); |
|
59 | - $custom_post_types = $custom_post_type_definitions->getDefinitions(); |
|
60 | - EE_Config::register_route( |
|
61 | - $custom_post_types['espresso_events']['singular_slug'], |
|
62 | - 'Event_Single', |
|
63 | - 'run' |
|
64 | - ); |
|
65 | - } |
|
66 | - |
|
67 | - /** |
|
68 | - * set_hooks_admin - for hooking into EE Admin Core, other modules, etc |
|
69 | - * |
|
70 | - * @return void |
|
71 | - */ |
|
72 | - public static function set_hooks_admin() |
|
73 | - { |
|
74 | - add_action('wp_loaded', array('EED_Event_Single', 'set_definitions'), 2); |
|
75 | - } |
|
76 | - |
|
77 | - |
|
78 | - /** |
|
79 | - * set_definitions |
|
80 | - * |
|
81 | - * @static |
|
82 | - * @return void |
|
83 | - */ |
|
84 | - public static function set_definitions() |
|
85 | - { |
|
86 | - define('EVENT_SINGLE_ASSETS_URL', plugin_dir_url(__FILE__) . 'assets/'); |
|
87 | - define('EVENT_SINGLE_TEMPLATES_PATH', plugin_dir_path(__FILE__) . 'templates/'); |
|
88 | - } |
|
89 | - |
|
90 | - |
|
91 | - /** |
|
92 | - * set_config |
|
93 | - * |
|
94 | - * @void |
|
95 | - */ |
|
96 | - protected function set_config() |
|
97 | - { |
|
98 | - $this->set_config_section('template_settings'); |
|
99 | - $this->set_config_class('EE_Event_Single_Config'); |
|
100 | - $this->set_config_name('EED_Event_Single'); |
|
101 | - } |
|
102 | - |
|
103 | - |
|
104 | - /** |
|
105 | - * initialize_template_parts |
|
106 | - * |
|
107 | - * @param EE_Config_Base|EE_Event_Single_Config $config |
|
108 | - * @return EE_Template_Part_Manager |
|
109 | - * @throws EE_Error |
|
110 | - */ |
|
111 | - public function initialize_template_parts(EE_Event_Single_Config $config = null) |
|
112 | - { |
|
113 | - /** @type EE_Event_Single_Config $config */ |
|
114 | - $config = $config instanceof EE_Event_Single_Config ? $config : $this->config(); |
|
115 | - EEH_Autoloader::register_template_part_autoloaders(); |
|
116 | - $template_parts = new EE_Template_Part_Manager(); |
|
117 | - $template_parts->add_template_part( |
|
118 | - 'tickets', |
|
119 | - esc_html__('Ticket Selector', 'event_espresso'), |
|
120 | - 'content-espresso_events-tickets.php', |
|
121 | - $config->display_order_tickets |
|
122 | - ); |
|
123 | - $template_parts->add_template_part( |
|
124 | - 'datetimes', |
|
125 | - esc_html__('Dates and Times', 'event_espresso'), |
|
126 | - 'content-espresso_events-datetimes.php', |
|
127 | - $config->display_order_datetimes |
|
128 | - ); |
|
129 | - $template_parts->add_template_part( |
|
130 | - 'event', |
|
131 | - esc_html__('Event Description', 'event_espresso'), |
|
132 | - 'content-espresso_events-details.php', |
|
133 | - $config->display_order_event |
|
134 | - ); |
|
135 | - $template_parts->add_template_part( |
|
136 | - 'venue', |
|
137 | - esc_html__('Venue Information', 'event_espresso'), |
|
138 | - 'content-espresso_events-venues.php', |
|
139 | - $config->display_order_venue |
|
140 | - ); |
|
141 | - do_action('AHEE__EED_Event_Single__initialize_template_parts', $template_parts); |
|
142 | - return $template_parts; |
|
143 | - } |
|
144 | - |
|
145 | - |
|
146 | - /** |
|
147 | - * run - initial module setup |
|
148 | - * |
|
149 | - * @param WP $WP |
|
150 | - * @return void |
|
151 | - */ |
|
152 | - public function run($WP) |
|
153 | - { |
|
154 | - // ensure valid EE_Events_Single_Config() object exists |
|
155 | - $this->set_config(); |
|
156 | - // check what template is loaded |
|
157 | - add_filter('template_include', array($this, 'template_include'), 999, 1); |
|
158 | - add_filter('FHEE__EED_Ticket_Selector__load_tckt_slctr_assets', '__return_true'); |
|
159 | - // load css |
|
160 | - add_action('wp_enqueue_scripts', array($this, 'wp_enqueue_scripts'), 10); |
|
161 | - } |
|
162 | - |
|
163 | - |
|
164 | - /** |
|
165 | - * template_include |
|
166 | - * |
|
167 | - * @param string $template |
|
168 | - * @return string |
|
169 | - */ |
|
170 | - public function template_include($template) |
|
171 | - { |
|
172 | - global $post; |
|
173 | - /** @type EE_Event_Single_Config $config */ |
|
174 | - $config = $this->config(); |
|
175 | - if ($config->display_status_banner_single) { |
|
176 | - add_filter('the_title', array('EED_Event_Single', 'the_title'), 100, 2); |
|
177 | - } |
|
178 | - // not a custom template? |
|
179 | - if ( |
|
180 | - ! post_password_required($post) |
|
181 | - && ( |
|
182 | - apply_filters('FHEE__EED_Event_Single__template_include__allow_custom_selected_template', false) |
|
183 | - || EE_Registry::instance() |
|
184 | - ->load_core('Front_Controller') |
|
185 | - ->get_selected_template() !== 'single-espresso_events.php' |
|
186 | - ) |
|
187 | - ) { |
|
188 | - EEH_Template::load_espresso_theme_functions(); |
|
189 | - // then add extra event data via hooks |
|
190 | - add_action('loop_start', array('EED_Event_Single', 'loop_start')); |
|
191 | - add_filter('get_the_excerpt', array('EED_Event_Single', 'get_the_excerpt'), 1, 1); |
|
192 | - add_filter( |
|
193 | - 'the_content', |
|
194 | - array('EED_Event_Single', 'event_details'), |
|
195 | - EED_Event_Single::EVENT_DETAILS_PRIORITY |
|
196 | - ); |
|
197 | - add_action('loop_end', array('EED_Event_Single', 'loop_end')); |
|
198 | - // don't display entry meta because the existing theme will take car of that |
|
199 | - add_filter('FHEE__content_espresso_events_details_template__display_entry_meta', '__return_false'); |
|
200 | - } |
|
201 | - return $template; |
|
202 | - } |
|
203 | - |
|
204 | - |
|
205 | - /** |
|
206 | - * loop_start |
|
207 | - * |
|
208 | - * @param array $wp_query_array an array containing the WP_Query object |
|
209 | - * @return void |
|
210 | - */ |
|
211 | - public static function loop_start($wp_query_array) |
|
212 | - { |
|
213 | - global $post; |
|
214 | - do_action('AHEE_event_details_before_post', $post, $wp_query_array); |
|
215 | - } |
|
216 | - |
|
217 | - |
|
218 | - /** |
|
219 | - * the_title |
|
220 | - * |
|
221 | - * @param string $title |
|
222 | - * @param int $id |
|
223 | - * @return string |
|
224 | - */ |
|
225 | - public static function the_title($title = '', $id = 0) |
|
226 | - { |
|
227 | - global $post; |
|
228 | - return ((function_exists('wp_is_block_theme') && wp_is_block_theme()) || in_the_loop()) && $post->ID === (int) $id |
|
229 | - ? espresso_event_status_banner($post->ID) . $title |
|
230 | - : $title; |
|
231 | - } |
|
232 | - |
|
233 | - |
|
234 | - /** |
|
235 | - * get_the_excerpt |
|
236 | - * kinda hacky, but if a theme is using get_the_excerpt(), |
|
237 | - * then we need to remove our filters on the_content() |
|
238 | - * |
|
239 | - * @param string $excerpt |
|
240 | - * @return string |
|
241 | - */ |
|
242 | - public static function get_the_excerpt($excerpt = '') |
|
243 | - { |
|
244 | - EED_Event_Single::$using_get_the_excerpt = true; |
|
245 | - add_filter('wp_trim_excerpt', array('EED_Event_Single', 'end_get_the_excerpt'), 999, 1); |
|
246 | - return $excerpt; |
|
247 | - } |
|
248 | - |
|
249 | - |
|
250 | - /** |
|
251 | - * end_get_the_excerpt |
|
252 | - * |
|
253 | - * @param string $text |
|
254 | - * @return string |
|
255 | - */ |
|
256 | - public static function end_get_the_excerpt($text = '') |
|
257 | - { |
|
258 | - EED_Event_Single::$using_get_the_excerpt = false; |
|
259 | - return $text; |
|
260 | - } |
|
261 | - |
|
262 | - |
|
263 | - /** |
|
264 | - * event_details |
|
265 | - * |
|
266 | - * @param string $content |
|
267 | - * @return string |
|
268 | - */ |
|
269 | - public static function event_details($content) |
|
270 | - { |
|
271 | - global $post; |
|
272 | - static $current_post_ID = 0; |
|
273 | - if ( |
|
274 | - $current_post_ID !== $post->ID |
|
275 | - && $post->post_type === 'espresso_events' |
|
276 | - && ! EED_Event_Single::$using_get_the_excerpt |
|
277 | - && ! post_password_required() |
|
278 | - ) { |
|
279 | - // Set current post ID to prevent showing content twice, but only if headers have definitely been sent. |
|
280 | - // Reason being is that some plugins, like Yoast, need to run through a copy of the loop early |
|
281 | - // BEFORE headers are sent in order to examine the post content and generate content for the HTML header. |
|
282 | - // We want to allow those plugins to still do their thing and have access to our content, but depending on |
|
283 | - // how your event content is being displayed (shortcode, CPT route, etc), this filter can get applied twice, |
|
284 | - // so the following allows this filter to be applied multiple times, but only once for real |
|
285 | - $current_post_ID = did_action('loop_start') ? $post->ID : 0; |
|
286 | - if (EE_Registry::instance()->CFG->template_settings->EED_Event_Single->use_sortable_display_order) { |
|
287 | - // we need to first remove this callback from being applied to the_content() |
|
288 | - // (otherwise it will recurse and blow up the interweb) |
|
289 | - remove_filter( |
|
290 | - 'the_content', |
|
291 | - array('EED_Event_Single', 'event_details'), |
|
292 | - EED_Event_Single::EVENT_DETAILS_PRIORITY |
|
293 | - ); |
|
294 | - EED_Event_Single::instance()->template_parts = EED_Event_Single::instance()->initialize_template_parts( |
|
295 | - ); |
|
296 | - $content = EEH_Template::locate_template('content-espresso_events-details.php'); |
|
297 | - $content = EED_Event_Single::instance()->template_parts->apply_template_part_filters($content); |
|
298 | - add_filter( |
|
299 | - 'the_content', |
|
300 | - array('EED_Event_Single', 'event_details'), |
|
301 | - EED_Event_Single::EVENT_DETAILS_PRIORITY |
|
302 | - ); |
|
303 | - } else { |
|
304 | - $content = EED_Event_Single::use_filterable_display_order(); |
|
305 | - } |
|
306 | - } |
|
307 | - return $content; |
|
308 | - } |
|
309 | - |
|
310 | - |
|
311 | - /** |
|
312 | - * use_filterable_display_order |
|
313 | - * |
|
314 | - * @return string |
|
315 | - */ |
|
316 | - protected static function use_filterable_display_order() |
|
317 | - { |
|
318 | - // since the 'content-espresso_events-details.php' template might be used directly from within a theme, |
|
319 | - // it uses the_content() for displaying the $post->post_content |
|
320 | - // so in order to load a template that uses the_content() |
|
321 | - // from within a callback being used to filter the_content(), |
|
322 | - // we need to first remove this callback from being applied to the_content() |
|
323 | - // (otherwise it will recurse and blow up the interweb) |
|
324 | - remove_filter( |
|
325 | - 'the_content', |
|
326 | - array('EED_Event_Single', 'event_details'), |
|
327 | - EED_Event_Single::EVENT_DETAILS_PRIORITY |
|
328 | - ); |
|
329 | - // now add additional content |
|
330 | - add_filter( |
|
331 | - 'the_content', |
|
332 | - array('EED_Event_Single', 'event_datetimes'), |
|
333 | - EED_Event_Single::EVENT_DATETIMES_PRIORITY, |
|
334 | - 1 |
|
335 | - ); |
|
336 | - add_filter( |
|
337 | - 'the_content', |
|
338 | - array('EED_Event_Single', 'event_tickets'), |
|
339 | - EED_Event_Single::EVENT_TICKETS_PRIORITY, |
|
340 | - 1 |
|
341 | - ); |
|
342 | - add_filter( |
|
343 | - 'the_content', |
|
344 | - array('EED_Event_Single', 'event_venues'), |
|
345 | - EED_Event_Single::EVENT_VENUES_PRIORITY, |
|
346 | - 1 |
|
347 | - ); |
|
348 | - do_action('AHEE__EED_Event_Single__use_filterable_display_order__after_add_filters'); |
|
349 | - // now load our template |
|
350 | - $content = EEH_Template::locate_template('content-espresso_events-details.php'); |
|
351 | - // now add our filter back in, plus some others |
|
352 | - add_filter( |
|
353 | - 'the_content', |
|
354 | - array('EED_Event_Single', 'event_details'), |
|
355 | - EED_Event_Single::EVENT_DETAILS_PRIORITY |
|
356 | - ); |
|
357 | - remove_filter( |
|
358 | - 'the_content', |
|
359 | - array('EED_Event_Single', 'event_datetimes'), |
|
360 | - EED_Event_Single::EVENT_DATETIMES_PRIORITY |
|
361 | - ); |
|
362 | - remove_filter( |
|
363 | - 'the_content', |
|
364 | - array('EED_Event_Single', 'event_tickets'), |
|
365 | - EED_Event_Single::EVENT_TICKETS_PRIORITY |
|
366 | - ); |
|
367 | - remove_filter( |
|
368 | - 'the_content', |
|
369 | - array('EED_Event_Single', 'event_venues'), |
|
370 | - EED_Event_Single::EVENT_VENUES_PRIORITY |
|
371 | - ); |
|
372 | - do_action('AHEE__EED_Event_Single__use_filterable_display_order__after_remove_filters'); |
|
373 | - // we're not returning the $content directly because the template we are loading uses the_content (or the_excerpt) |
|
374 | - return $content; |
|
375 | - } |
|
376 | - |
|
377 | - |
|
378 | - /** |
|
379 | - * event_datetimes - adds datetimes ABOVE content |
|
380 | - * |
|
381 | - * @param string $content |
|
382 | - * @return string |
|
383 | - */ |
|
384 | - public static function event_datetimes($content) |
|
385 | - { |
|
386 | - return EEH_Template::locate_template('content-espresso_events-datetimes.php') . $content; |
|
387 | - } |
|
388 | - |
|
389 | - |
|
390 | - /** |
|
391 | - * event_tickets - adds tickets ABOVE content (which includes datetimes) |
|
392 | - * |
|
393 | - * @param string $content |
|
394 | - * @return string |
|
395 | - */ |
|
396 | - public static function event_tickets($content) |
|
397 | - { |
|
398 | - return EEH_Template::locate_template('content-espresso_events-tickets.php') . $content; |
|
399 | - } |
|
400 | - |
|
401 | - |
|
402 | - /** |
|
403 | - * event_venues |
|
404 | - * |
|
405 | - * @param string $content |
|
406 | - * @return string |
|
407 | - */ |
|
408 | - public static function event_venue($content) |
|
409 | - { |
|
410 | - return EED_Event_Single::event_venues($content); |
|
411 | - } |
|
412 | - |
|
413 | - |
|
414 | - /** |
|
415 | - * event_venues - adds venues BELOW content |
|
416 | - * |
|
417 | - * @param string $content |
|
418 | - * @return string |
|
419 | - */ |
|
420 | - public static function event_venues($content) |
|
421 | - { |
|
422 | - return $content . EEH_Template::locate_template('content-espresso_events-venues.php'); |
|
423 | - } |
|
424 | - |
|
425 | - |
|
426 | - /** |
|
427 | - * loop_end |
|
428 | - * |
|
429 | - * @param array $wp_query_array an array containing the WP_Query object |
|
430 | - * @return void |
|
431 | - */ |
|
432 | - public static function loop_end($wp_query_array) |
|
433 | - { |
|
434 | - global $post; |
|
435 | - do_action('AHEE_event_details_after_post', $post, $wp_query_array); |
|
436 | - } |
|
437 | - |
|
438 | - |
|
439 | - /** |
|
440 | - * wp_enqueue_scripts |
|
441 | - * |
|
442 | - * @return void |
|
443 | - */ |
|
444 | - public function wp_enqueue_scripts() |
|
445 | - { |
|
446 | - // get some style |
|
447 | - if ( |
|
448 | - apply_filters('FHEE_enable_default_espresso_css', true) |
|
449 | - && apply_filters('FHEE__EED_Event_Single__wp_enqueue_scripts__enable_css', true) |
|
450 | - ) { |
|
451 | - // first check uploads folder |
|
452 | - if (is_readable(get_stylesheet_directory() . $this->theme . '/style.css')) { |
|
453 | - wp_register_style( |
|
454 | - $this->theme, |
|
455 | - get_stylesheet_directory_uri() . $this->theme . '/style.css', |
|
456 | - array('dashicons', 'espresso_default') |
|
457 | - ); |
|
458 | - } else { |
|
459 | - wp_register_style( |
|
460 | - $this->theme, |
|
461 | - EE_TEMPLATES_URL . $this->theme . '/style.css', |
|
462 | - array('dashicons', 'espresso_default') |
|
463 | - ); |
|
464 | - } |
|
465 | - wp_enqueue_script($this->theme); |
|
466 | - if (EE_Registry::instance()->CFG->map_settings->use_google_maps) { |
|
467 | - add_action('wp_enqueue_scripts', array('EEH_Maps', 'espresso_google_map_js'), 11); |
|
468 | - } |
|
469 | - } |
|
470 | - } |
|
471 | - |
|
472 | - |
|
473 | - /** |
|
474 | - * display_venue |
|
475 | - * |
|
476 | - * @return bool |
|
477 | - */ |
|
478 | - public static function display_venue() |
|
479 | - { |
|
480 | - /** @type EE_Event_Single_Config $config */ |
|
481 | - $config = EED_Event_Single::instance()->config(); |
|
482 | - $display_venue = $config->display_venue === null ? true : $config->display_venue; |
|
483 | - $venue_name = EEH_Venue_View::venue_name(); |
|
484 | - return $display_venue && ! empty($venue_name); |
|
485 | - } |
|
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 | + |
|
22 | + /** |
|
23 | + * @type bool $using_get_the_excerpt |
|
24 | + */ |
|
25 | + protected static $using_get_the_excerpt = false; |
|
26 | + |
|
27 | + |
|
28 | + /** |
|
29 | + * @type EE_Template_Part_Manager $template_parts |
|
30 | + */ |
|
31 | + protected $template_parts; |
|
32 | + |
|
33 | + |
|
34 | + /** |
|
35 | + * @return EED_Module|EED_Event_Single |
|
36 | + */ |
|
37 | + public static function instance() |
|
38 | + { |
|
39 | + return parent::get_instance(__CLASS__); |
|
40 | + } |
|
41 | + |
|
42 | + |
|
43 | + /** |
|
44 | + * set_hooks - for hooking into EE Core, other modules, etc |
|
45 | + * |
|
46 | + * @return void |
|
47 | + * @throws InvalidArgumentException |
|
48 | + * @throws InvalidDataTypeException |
|
49 | + * @throws InvalidInterfaceException |
|
50 | + */ |
|
51 | + public static function set_hooks() |
|
52 | + { |
|
53 | + add_filter('FHEE_run_EE_wp', '__return_true'); |
|
54 | + add_action('wp_loaded', array('EED_Event_Single', 'set_definitions'), 2); |
|
55 | + /** @var EventEspresso\core\domain\entities\custom_post_types\CustomPostTypeDefinitions $custom_post_type_definitions */ |
|
56 | + $custom_post_type_definitions = LoaderFactory::getLoader()->getShared( |
|
57 | + 'EventEspresso\core\domain\entities\custom_post_types\CustomPostTypeDefinitions' |
|
58 | + ); |
|
59 | + $custom_post_types = $custom_post_type_definitions->getDefinitions(); |
|
60 | + EE_Config::register_route( |
|
61 | + $custom_post_types['espresso_events']['singular_slug'], |
|
62 | + 'Event_Single', |
|
63 | + 'run' |
|
64 | + ); |
|
65 | + } |
|
66 | + |
|
67 | + /** |
|
68 | + * set_hooks_admin - for hooking into EE Admin Core, other modules, etc |
|
69 | + * |
|
70 | + * @return void |
|
71 | + */ |
|
72 | + public static function set_hooks_admin() |
|
73 | + { |
|
74 | + add_action('wp_loaded', array('EED_Event_Single', 'set_definitions'), 2); |
|
75 | + } |
|
76 | + |
|
77 | + |
|
78 | + /** |
|
79 | + * set_definitions |
|
80 | + * |
|
81 | + * @static |
|
82 | + * @return void |
|
83 | + */ |
|
84 | + public static function set_definitions() |
|
85 | + { |
|
86 | + define('EVENT_SINGLE_ASSETS_URL', plugin_dir_url(__FILE__) . 'assets/'); |
|
87 | + define('EVENT_SINGLE_TEMPLATES_PATH', plugin_dir_path(__FILE__) . 'templates/'); |
|
88 | + } |
|
89 | + |
|
90 | + |
|
91 | + /** |
|
92 | + * set_config |
|
93 | + * |
|
94 | + * @void |
|
95 | + */ |
|
96 | + protected function set_config() |
|
97 | + { |
|
98 | + $this->set_config_section('template_settings'); |
|
99 | + $this->set_config_class('EE_Event_Single_Config'); |
|
100 | + $this->set_config_name('EED_Event_Single'); |
|
101 | + } |
|
102 | + |
|
103 | + |
|
104 | + /** |
|
105 | + * initialize_template_parts |
|
106 | + * |
|
107 | + * @param EE_Config_Base|EE_Event_Single_Config $config |
|
108 | + * @return EE_Template_Part_Manager |
|
109 | + * @throws EE_Error |
|
110 | + */ |
|
111 | + public function initialize_template_parts(EE_Event_Single_Config $config = null) |
|
112 | + { |
|
113 | + /** @type EE_Event_Single_Config $config */ |
|
114 | + $config = $config instanceof EE_Event_Single_Config ? $config : $this->config(); |
|
115 | + EEH_Autoloader::register_template_part_autoloaders(); |
|
116 | + $template_parts = new EE_Template_Part_Manager(); |
|
117 | + $template_parts->add_template_part( |
|
118 | + 'tickets', |
|
119 | + esc_html__('Ticket Selector', 'event_espresso'), |
|
120 | + 'content-espresso_events-tickets.php', |
|
121 | + $config->display_order_tickets |
|
122 | + ); |
|
123 | + $template_parts->add_template_part( |
|
124 | + 'datetimes', |
|
125 | + esc_html__('Dates and Times', 'event_espresso'), |
|
126 | + 'content-espresso_events-datetimes.php', |
|
127 | + $config->display_order_datetimes |
|
128 | + ); |
|
129 | + $template_parts->add_template_part( |
|
130 | + 'event', |
|
131 | + esc_html__('Event Description', 'event_espresso'), |
|
132 | + 'content-espresso_events-details.php', |
|
133 | + $config->display_order_event |
|
134 | + ); |
|
135 | + $template_parts->add_template_part( |
|
136 | + 'venue', |
|
137 | + esc_html__('Venue Information', 'event_espresso'), |
|
138 | + 'content-espresso_events-venues.php', |
|
139 | + $config->display_order_venue |
|
140 | + ); |
|
141 | + do_action('AHEE__EED_Event_Single__initialize_template_parts', $template_parts); |
|
142 | + return $template_parts; |
|
143 | + } |
|
144 | + |
|
145 | + |
|
146 | + /** |
|
147 | + * run - initial module setup |
|
148 | + * |
|
149 | + * @param WP $WP |
|
150 | + * @return void |
|
151 | + */ |
|
152 | + public function run($WP) |
|
153 | + { |
|
154 | + // ensure valid EE_Events_Single_Config() object exists |
|
155 | + $this->set_config(); |
|
156 | + // check what template is loaded |
|
157 | + add_filter('template_include', array($this, 'template_include'), 999, 1); |
|
158 | + add_filter('FHEE__EED_Ticket_Selector__load_tckt_slctr_assets', '__return_true'); |
|
159 | + // load css |
|
160 | + add_action('wp_enqueue_scripts', array($this, 'wp_enqueue_scripts'), 10); |
|
161 | + } |
|
162 | + |
|
163 | + |
|
164 | + /** |
|
165 | + * template_include |
|
166 | + * |
|
167 | + * @param string $template |
|
168 | + * @return string |
|
169 | + */ |
|
170 | + public function template_include($template) |
|
171 | + { |
|
172 | + global $post; |
|
173 | + /** @type EE_Event_Single_Config $config */ |
|
174 | + $config = $this->config(); |
|
175 | + if ($config->display_status_banner_single) { |
|
176 | + add_filter('the_title', array('EED_Event_Single', 'the_title'), 100, 2); |
|
177 | + } |
|
178 | + // not a custom template? |
|
179 | + if ( |
|
180 | + ! post_password_required($post) |
|
181 | + && ( |
|
182 | + apply_filters('FHEE__EED_Event_Single__template_include__allow_custom_selected_template', false) |
|
183 | + || EE_Registry::instance() |
|
184 | + ->load_core('Front_Controller') |
|
185 | + ->get_selected_template() !== 'single-espresso_events.php' |
|
186 | + ) |
|
187 | + ) { |
|
188 | + EEH_Template::load_espresso_theme_functions(); |
|
189 | + // then add extra event data via hooks |
|
190 | + add_action('loop_start', array('EED_Event_Single', 'loop_start')); |
|
191 | + add_filter('get_the_excerpt', array('EED_Event_Single', 'get_the_excerpt'), 1, 1); |
|
192 | + add_filter( |
|
193 | + 'the_content', |
|
194 | + array('EED_Event_Single', 'event_details'), |
|
195 | + EED_Event_Single::EVENT_DETAILS_PRIORITY |
|
196 | + ); |
|
197 | + add_action('loop_end', array('EED_Event_Single', 'loop_end')); |
|
198 | + // don't display entry meta because the existing theme will take car of that |
|
199 | + add_filter('FHEE__content_espresso_events_details_template__display_entry_meta', '__return_false'); |
|
200 | + } |
|
201 | + return $template; |
|
202 | + } |
|
203 | + |
|
204 | + |
|
205 | + /** |
|
206 | + * loop_start |
|
207 | + * |
|
208 | + * @param array $wp_query_array an array containing the WP_Query object |
|
209 | + * @return void |
|
210 | + */ |
|
211 | + public static function loop_start($wp_query_array) |
|
212 | + { |
|
213 | + global $post; |
|
214 | + do_action('AHEE_event_details_before_post', $post, $wp_query_array); |
|
215 | + } |
|
216 | + |
|
217 | + |
|
218 | + /** |
|
219 | + * the_title |
|
220 | + * |
|
221 | + * @param string $title |
|
222 | + * @param int $id |
|
223 | + * @return string |
|
224 | + */ |
|
225 | + public static function the_title($title = '', $id = 0) |
|
226 | + { |
|
227 | + global $post; |
|
228 | + return ((function_exists('wp_is_block_theme') && wp_is_block_theme()) || in_the_loop()) && $post->ID === (int) $id |
|
229 | + ? espresso_event_status_banner($post->ID) . $title |
|
230 | + : $title; |
|
231 | + } |
|
232 | + |
|
233 | + |
|
234 | + /** |
|
235 | + * get_the_excerpt |
|
236 | + * kinda hacky, but if a theme is using get_the_excerpt(), |
|
237 | + * then we need to remove our filters on the_content() |
|
238 | + * |
|
239 | + * @param string $excerpt |
|
240 | + * @return string |
|
241 | + */ |
|
242 | + public static function get_the_excerpt($excerpt = '') |
|
243 | + { |
|
244 | + EED_Event_Single::$using_get_the_excerpt = true; |
|
245 | + add_filter('wp_trim_excerpt', array('EED_Event_Single', 'end_get_the_excerpt'), 999, 1); |
|
246 | + return $excerpt; |
|
247 | + } |
|
248 | + |
|
249 | + |
|
250 | + /** |
|
251 | + * end_get_the_excerpt |
|
252 | + * |
|
253 | + * @param string $text |
|
254 | + * @return string |
|
255 | + */ |
|
256 | + public static function end_get_the_excerpt($text = '') |
|
257 | + { |
|
258 | + EED_Event_Single::$using_get_the_excerpt = false; |
|
259 | + return $text; |
|
260 | + } |
|
261 | + |
|
262 | + |
|
263 | + /** |
|
264 | + * event_details |
|
265 | + * |
|
266 | + * @param string $content |
|
267 | + * @return string |
|
268 | + */ |
|
269 | + public static function event_details($content) |
|
270 | + { |
|
271 | + global $post; |
|
272 | + static $current_post_ID = 0; |
|
273 | + if ( |
|
274 | + $current_post_ID !== $post->ID |
|
275 | + && $post->post_type === 'espresso_events' |
|
276 | + && ! EED_Event_Single::$using_get_the_excerpt |
|
277 | + && ! post_password_required() |
|
278 | + ) { |
|
279 | + // Set current post ID to prevent showing content twice, but only if headers have definitely been sent. |
|
280 | + // Reason being is that some plugins, like Yoast, need to run through a copy of the loop early |
|
281 | + // BEFORE headers are sent in order to examine the post content and generate content for the HTML header. |
|
282 | + // We want to allow those plugins to still do their thing and have access to our content, but depending on |
|
283 | + // how your event content is being displayed (shortcode, CPT route, etc), this filter can get applied twice, |
|
284 | + // so the following allows this filter to be applied multiple times, but only once for real |
|
285 | + $current_post_ID = did_action('loop_start') ? $post->ID : 0; |
|
286 | + if (EE_Registry::instance()->CFG->template_settings->EED_Event_Single->use_sortable_display_order) { |
|
287 | + // we need to first remove this callback from being applied to the_content() |
|
288 | + // (otherwise it will recurse and blow up the interweb) |
|
289 | + remove_filter( |
|
290 | + 'the_content', |
|
291 | + array('EED_Event_Single', 'event_details'), |
|
292 | + EED_Event_Single::EVENT_DETAILS_PRIORITY |
|
293 | + ); |
|
294 | + EED_Event_Single::instance()->template_parts = EED_Event_Single::instance()->initialize_template_parts( |
|
295 | + ); |
|
296 | + $content = EEH_Template::locate_template('content-espresso_events-details.php'); |
|
297 | + $content = EED_Event_Single::instance()->template_parts->apply_template_part_filters($content); |
|
298 | + add_filter( |
|
299 | + 'the_content', |
|
300 | + array('EED_Event_Single', 'event_details'), |
|
301 | + EED_Event_Single::EVENT_DETAILS_PRIORITY |
|
302 | + ); |
|
303 | + } else { |
|
304 | + $content = EED_Event_Single::use_filterable_display_order(); |
|
305 | + } |
|
306 | + } |
|
307 | + return $content; |
|
308 | + } |
|
309 | + |
|
310 | + |
|
311 | + /** |
|
312 | + * use_filterable_display_order |
|
313 | + * |
|
314 | + * @return string |
|
315 | + */ |
|
316 | + protected static function use_filterable_display_order() |
|
317 | + { |
|
318 | + // since the 'content-espresso_events-details.php' template might be used directly from within a theme, |
|
319 | + // it uses the_content() for displaying the $post->post_content |
|
320 | + // so in order to load a template that uses the_content() |
|
321 | + // from within a callback being used to filter the_content(), |
|
322 | + // we need to first remove this callback from being applied to the_content() |
|
323 | + // (otherwise it will recurse and blow up the interweb) |
|
324 | + remove_filter( |
|
325 | + 'the_content', |
|
326 | + array('EED_Event_Single', 'event_details'), |
|
327 | + EED_Event_Single::EVENT_DETAILS_PRIORITY |
|
328 | + ); |
|
329 | + // now add additional content |
|
330 | + add_filter( |
|
331 | + 'the_content', |
|
332 | + array('EED_Event_Single', 'event_datetimes'), |
|
333 | + EED_Event_Single::EVENT_DATETIMES_PRIORITY, |
|
334 | + 1 |
|
335 | + ); |
|
336 | + add_filter( |
|
337 | + 'the_content', |
|
338 | + array('EED_Event_Single', 'event_tickets'), |
|
339 | + EED_Event_Single::EVENT_TICKETS_PRIORITY, |
|
340 | + 1 |
|
341 | + ); |
|
342 | + add_filter( |
|
343 | + 'the_content', |
|
344 | + array('EED_Event_Single', 'event_venues'), |
|
345 | + EED_Event_Single::EVENT_VENUES_PRIORITY, |
|
346 | + 1 |
|
347 | + ); |
|
348 | + do_action('AHEE__EED_Event_Single__use_filterable_display_order__after_add_filters'); |
|
349 | + // now load our template |
|
350 | + $content = EEH_Template::locate_template('content-espresso_events-details.php'); |
|
351 | + // now add our filter back in, plus some others |
|
352 | + add_filter( |
|
353 | + 'the_content', |
|
354 | + array('EED_Event_Single', 'event_details'), |
|
355 | + EED_Event_Single::EVENT_DETAILS_PRIORITY |
|
356 | + ); |
|
357 | + remove_filter( |
|
358 | + 'the_content', |
|
359 | + array('EED_Event_Single', 'event_datetimes'), |
|
360 | + EED_Event_Single::EVENT_DATETIMES_PRIORITY |
|
361 | + ); |
|
362 | + remove_filter( |
|
363 | + 'the_content', |
|
364 | + array('EED_Event_Single', 'event_tickets'), |
|
365 | + EED_Event_Single::EVENT_TICKETS_PRIORITY |
|
366 | + ); |
|
367 | + remove_filter( |
|
368 | + 'the_content', |
|
369 | + array('EED_Event_Single', 'event_venues'), |
|
370 | + EED_Event_Single::EVENT_VENUES_PRIORITY |
|
371 | + ); |
|
372 | + do_action('AHEE__EED_Event_Single__use_filterable_display_order__after_remove_filters'); |
|
373 | + // we're not returning the $content directly because the template we are loading uses the_content (or the_excerpt) |
|
374 | + return $content; |
|
375 | + } |
|
376 | + |
|
377 | + |
|
378 | + /** |
|
379 | + * event_datetimes - adds datetimes ABOVE content |
|
380 | + * |
|
381 | + * @param string $content |
|
382 | + * @return string |
|
383 | + */ |
|
384 | + public static function event_datetimes($content) |
|
385 | + { |
|
386 | + return EEH_Template::locate_template('content-espresso_events-datetimes.php') . $content; |
|
387 | + } |
|
388 | + |
|
389 | + |
|
390 | + /** |
|
391 | + * event_tickets - adds tickets ABOVE content (which includes datetimes) |
|
392 | + * |
|
393 | + * @param string $content |
|
394 | + * @return string |
|
395 | + */ |
|
396 | + public static function event_tickets($content) |
|
397 | + { |
|
398 | + return EEH_Template::locate_template('content-espresso_events-tickets.php') . $content; |
|
399 | + } |
|
400 | + |
|
401 | + |
|
402 | + /** |
|
403 | + * event_venues |
|
404 | + * |
|
405 | + * @param string $content |
|
406 | + * @return string |
|
407 | + */ |
|
408 | + public static function event_venue($content) |
|
409 | + { |
|
410 | + return EED_Event_Single::event_venues($content); |
|
411 | + } |
|
412 | + |
|
413 | + |
|
414 | + /** |
|
415 | + * event_venues - adds venues BELOW content |
|
416 | + * |
|
417 | + * @param string $content |
|
418 | + * @return string |
|
419 | + */ |
|
420 | + public static function event_venues($content) |
|
421 | + { |
|
422 | + return $content . EEH_Template::locate_template('content-espresso_events-venues.php'); |
|
423 | + } |
|
424 | + |
|
425 | + |
|
426 | + /** |
|
427 | + * loop_end |
|
428 | + * |
|
429 | + * @param array $wp_query_array an array containing the WP_Query object |
|
430 | + * @return void |
|
431 | + */ |
|
432 | + public static function loop_end($wp_query_array) |
|
433 | + { |
|
434 | + global $post; |
|
435 | + do_action('AHEE_event_details_after_post', $post, $wp_query_array); |
|
436 | + } |
|
437 | + |
|
438 | + |
|
439 | + /** |
|
440 | + * wp_enqueue_scripts |
|
441 | + * |
|
442 | + * @return void |
|
443 | + */ |
|
444 | + public function wp_enqueue_scripts() |
|
445 | + { |
|
446 | + // get some style |
|
447 | + if ( |
|
448 | + apply_filters('FHEE_enable_default_espresso_css', true) |
|
449 | + && apply_filters('FHEE__EED_Event_Single__wp_enqueue_scripts__enable_css', true) |
|
450 | + ) { |
|
451 | + // first check uploads folder |
|
452 | + if (is_readable(get_stylesheet_directory() . $this->theme . '/style.css')) { |
|
453 | + wp_register_style( |
|
454 | + $this->theme, |
|
455 | + get_stylesheet_directory_uri() . $this->theme . '/style.css', |
|
456 | + array('dashicons', 'espresso_default') |
|
457 | + ); |
|
458 | + } else { |
|
459 | + wp_register_style( |
|
460 | + $this->theme, |
|
461 | + EE_TEMPLATES_URL . $this->theme . '/style.css', |
|
462 | + array('dashicons', 'espresso_default') |
|
463 | + ); |
|
464 | + } |
|
465 | + wp_enqueue_script($this->theme); |
|
466 | + if (EE_Registry::instance()->CFG->map_settings->use_google_maps) { |
|
467 | + add_action('wp_enqueue_scripts', array('EEH_Maps', 'espresso_google_map_js'), 11); |
|
468 | + } |
|
469 | + } |
|
470 | + } |
|
471 | + |
|
472 | + |
|
473 | + /** |
|
474 | + * display_venue |
|
475 | + * |
|
476 | + * @return bool |
|
477 | + */ |
|
478 | + public static function display_venue() |
|
479 | + { |
|
480 | + /** @type EE_Event_Single_Config $config */ |
|
481 | + $config = EED_Event_Single::instance()->config(); |
|
482 | + $display_venue = $config->display_venue === null ? true : $config->display_venue; |
|
483 | + $venue_name = EEH_Venue_View::venue_name(); |
|
484 | + return $display_venue && ! empty($venue_name); |
|
485 | + } |
|
486 | 486 | } |
487 | 487 | |
488 | 488 | |
@@ -494,5 +494,5 @@ discard block |
||
494 | 494 | */ |
495 | 495 | function espresso_display_venue_in_event_details() |
496 | 496 | { |
497 | - return EED_Event_Single::display_venue(); |
|
497 | + return EED_Event_Single::display_venue(); |
|
498 | 498 | } |
@@ -123,8 +123,8 @@ discard block |
||
123 | 123 | */ |
124 | 124 | public static function set_definitions() |
125 | 125 | { |
126 | - define('EVENTS_ARCHIVE_ASSETS_URL', plugin_dir_url(__FILE__) . 'assets/'); |
|
127 | - define('EVENTS_ARCHIVE_TEMPLATES_PATH', str_replace('\\', '/', plugin_dir_path(__FILE__)) . 'templates/'); |
|
126 | + define('EVENTS_ARCHIVE_ASSETS_URL', plugin_dir_url(__FILE__).'assets/'); |
|
127 | + define('EVENTS_ARCHIVE_TEMPLATES_PATH', str_replace('\\', '/', plugin_dir_path(__FILE__)).'templates/'); |
|
128 | 128 | } |
129 | 129 | |
130 | 130 | |
@@ -144,7 +144,7 @@ discard block |
||
144 | 144 | */ |
145 | 145 | public static function get_iframe_embed_button() |
146 | 146 | { |
147 | - if (! self::$_iframe_embed_button instanceof EventListIframeEmbedButton) { |
|
147 | + if ( ! self::$_iframe_embed_button instanceof EventListIframeEmbedButton) { |
|
148 | 148 | self::$_iframe_embed_button = new EventListIframeEmbedButton(); |
149 | 149 | } |
150 | 150 | return self::$_iframe_embed_button; |
@@ -227,10 +227,10 @@ discard block |
||
227 | 227 | EEH_Event_Query::add_query_filters(); |
228 | 228 | // set params that will get used by the filters |
229 | 229 | EEH_Event_Query::set_query_params( |
230 | - '', // month |
|
231 | - '', // category |
|
232 | - $config->display_expired_events, // show_expired |
|
233 | - 'start_date', // orderby |
|
230 | + '', // month |
|
231 | + '', // category |
|
232 | + $config->display_expired_events, // show_expired |
|
233 | + 'start_date', // orderby |
|
234 | 234 | 'ASC' // sort |
235 | 235 | ); |
236 | 236 | // check what template is loaded |
@@ -296,7 +296,7 @@ discard block |
||
296 | 296 | public function template_include($template = '') |
297 | 297 | { |
298 | 298 | // don't add content filter for dedicated EE child themes or private posts |
299 | - if (! EEH_Template::is_espresso_theme()) { |
|
299 | + if ( ! EEH_Template::is_espresso_theme()) { |
|
300 | 300 | /** @type EE_Events_Archive_Config $config */ |
301 | 301 | $config = $this->config(); |
302 | 302 | // add status banner ? |
@@ -396,7 +396,7 @@ discard block |
||
396 | 396 | global $post; |
397 | 397 | if ($post instanceof WP_Post) { |
398 | 398 | return ((function_exists('wp_is_block_theme') && wp_is_block_theme()) || in_the_loop()) && $post->ID == $id |
399 | - ? espresso_event_status_banner($post->ID) . $title |
|
399 | + ? espresso_event_status_banner($post->ID).$title |
|
400 | 400 | : $title; |
401 | 401 | } |
402 | 402 | return $title; |
@@ -548,7 +548,7 @@ discard block |
||
548 | 548 | if (post_password_required()) { |
549 | 549 | return $content; |
550 | 550 | } |
551 | - return EEH_Template::locate_template('content-espresso_events-datetimes.php') . $content; |
|
551 | + return EEH_Template::locate_template('content-espresso_events-datetimes.php').$content; |
|
552 | 552 | } |
553 | 553 | |
554 | 554 | |
@@ -564,7 +564,7 @@ discard block |
||
564 | 564 | if (post_password_required()) { |
565 | 565 | return $content; |
566 | 566 | } |
567 | - return EEH_Template::locate_template('content-espresso_events-tickets.php') . $content; |
|
567 | + return EEH_Template::locate_template('content-espresso_events-tickets.php').$content; |
|
568 | 568 | } |
569 | 569 | |
570 | 570 | |
@@ -593,7 +593,7 @@ discard block |
||
593 | 593 | if (post_password_required()) { |
594 | 594 | return $content; |
595 | 595 | } |
596 | - return $content . EEH_Template::locate_template('content-espresso_events-venues.php'); |
|
596 | + return $content.EEH_Template::locate_template('content-espresso_events-venues.php'); |
|
597 | 597 | } |
598 | 598 | |
599 | 599 | |
@@ -777,10 +777,10 @@ discard block |
||
777 | 777 | // get some style |
778 | 778 | if (apply_filters('FHEE_enable_default_espresso_css', false)) { |
779 | 779 | // first check uploads folder |
780 | - if (EEH_File::is_readable(get_stylesheet_directory() . $this->theme . '/style.css')) { |
|
780 | + if (EEH_File::is_readable(get_stylesheet_directory().$this->theme.'/style.css')) { |
|
781 | 781 | wp_register_style( |
782 | 782 | $this->theme, |
783 | - get_stylesheet_directory_uri() . $this->theme . '/style.css', |
|
783 | + get_stylesheet_directory_uri().$this->theme.'/style.css', |
|
784 | 784 | array('dashicons', 'espresso_default') |
785 | 785 | ); |
786 | 786 | } else { |
@@ -819,7 +819,7 @@ discard block |
||
819 | 819 | (array) $template_settings->EED_Events_Archive |
820 | 820 | ); |
821 | 821 | EEH_Template::display_template( |
822 | - EVENTS_ARCHIVE_TEMPLATES_PATH . 'admin-event-list-settings.template.php', |
|
822 | + EVENTS_ARCHIVE_TEMPLATES_PATH.'admin-event-list-settings.template.php', |
|
823 | 823 | $events_archive_settings |
824 | 824 | ); |
825 | 825 | } |
@@ -16,1110 +16,1110 @@ discard block |
||
16 | 16 | class EED_Events_Archive extends EED_Module |
17 | 17 | { |
18 | 18 | |
19 | - const EVENT_DETAILS_PRIORITY = 100; |
|
20 | - |
|
21 | - const EVENT_DATETIMES_PRIORITY = 110; |
|
22 | - |
|
23 | - const EVENT_TICKETS_PRIORITY = 120; |
|
24 | - |
|
25 | - const EVENT_VENUES_PRIORITY = 130; |
|
26 | - |
|
27 | - |
|
28 | - public static $espresso_event_list_ID = 0; |
|
29 | - |
|
30 | - public static $espresso_grid_event_lists = array(); |
|
31 | - |
|
32 | - /** |
|
33 | - * @type bool $using_get_the_excerpt |
|
34 | - */ |
|
35 | - protected static $using_get_the_excerpt = false; |
|
36 | - |
|
37 | - /** |
|
38 | - * Used to flag when the event list is being called from an external iframe. |
|
39 | - * |
|
40 | - * @var bool $iframe |
|
41 | - */ |
|
42 | - protected static $iframe = false; |
|
43 | - |
|
44 | - /** |
|
45 | - * @var EventListIframeEmbedButton $_iframe_embed_button |
|
46 | - */ |
|
47 | - private static $_iframe_embed_button; |
|
48 | - |
|
49 | - /** |
|
50 | - * @type EE_Template_Part_Manager $template_parts |
|
51 | - */ |
|
52 | - protected $template_parts; |
|
53 | - |
|
54 | - |
|
55 | - /** |
|
56 | - * @return EED_Events_Archive |
|
57 | - */ |
|
58 | - public static function instance() |
|
59 | - { |
|
60 | - return parent::get_instance(__CLASS__); |
|
61 | - } |
|
62 | - |
|
63 | - |
|
64 | - /** |
|
65 | - * set_hooks - for hooking into EE Core, other modules, etc |
|
66 | - * |
|
67 | - * @return void |
|
68 | - * @throws InvalidArgumentException |
|
69 | - * @throws InvalidDataTypeException |
|
70 | - * @throws InvalidInterfaceException |
|
71 | - */ |
|
72 | - public static function set_hooks() |
|
73 | - { |
|
74 | - /** @var EventEspresso\core\domain\entities\custom_post_types\CustomPostTypeDefinitions $custom_post_type_definitions */ |
|
75 | - $custom_post_type_definitions = LoaderFactory::getLoader()->getShared( |
|
76 | - 'EventEspresso\core\domain\entities\custom_post_types\CustomPostTypeDefinitions' |
|
77 | - ); |
|
78 | - $custom_post_types = $custom_post_type_definitions->getDefinitions(); |
|
79 | - EE_Config::register_route( |
|
80 | - $custom_post_types['espresso_events']['plural_slug'], |
|
81 | - 'Events_Archive', |
|
82 | - 'run' |
|
83 | - ); |
|
84 | - EE_Config::register_route( |
|
85 | - 'event_list', |
|
86 | - 'Events_Archive', |
|
87 | - 'event_list' |
|
88 | - ); |
|
89 | - EE_Config::register_route( |
|
90 | - 'iframe', |
|
91 | - 'Events_Archive', |
|
92 | - 'event_list_iframe', |
|
93 | - 'event_list' |
|
94 | - ); |
|
95 | - add_action('wp_loaded', array('EED_Events_Archive', 'set_definitions'), 2); |
|
96 | - } |
|
97 | - |
|
98 | - |
|
99 | - /** |
|
100 | - * set_hooks_admin - for hooking into EE Admin Core, other modules, etc |
|
101 | - * |
|
102 | - * @access public |
|
103 | - * @return void |
|
104 | - */ |
|
105 | - public static function set_hooks_admin() |
|
106 | - { |
|
107 | - add_action('wp_loaded', array('EED_Events_Archive', 'set_definitions'), 2); |
|
108 | - // hook into the end of the \EE_Admin_Page::_load_page_dependencies() |
|
109 | - // to load assets for "espresso_events" page on the "default" route (action) |
|
110 | - add_action( |
|
111 | - 'FHEE__EE_Admin_Page___load_page_dependencies__after_load__espresso_events__default', |
|
112 | - array('EED_Events_Archive', 'event_list_iframe_embed_button'), |
|
113 | - 10 |
|
114 | - ); |
|
115 | - } |
|
116 | - |
|
117 | - |
|
118 | - /** |
|
119 | - * set_definitions |
|
120 | - * |
|
121 | - * @access public |
|
122 | - * @return void |
|
123 | - */ |
|
124 | - public static function set_definitions() |
|
125 | - { |
|
126 | - define('EVENTS_ARCHIVE_ASSETS_URL', plugin_dir_url(__FILE__) . 'assets/'); |
|
127 | - define('EVENTS_ARCHIVE_TEMPLATES_PATH', str_replace('\\', '/', plugin_dir_path(__FILE__)) . 'templates/'); |
|
128 | - } |
|
129 | - |
|
130 | - |
|
131 | - /** |
|
132 | - * set up EE_Events_Archive_Config |
|
133 | - */ |
|
134 | - protected function set_config() |
|
135 | - { |
|
136 | - $this->set_config_section('template_settings'); |
|
137 | - $this->set_config_class('EE_Events_Archive_Config'); |
|
138 | - $this->set_config_name('EED_Events_Archive'); |
|
139 | - } |
|
140 | - |
|
141 | - |
|
142 | - /** |
|
143 | - * @return EventListIframeEmbedButton |
|
144 | - */ |
|
145 | - public static function get_iframe_embed_button() |
|
146 | - { |
|
147 | - if (! self::$_iframe_embed_button instanceof EventListIframeEmbedButton) { |
|
148 | - self::$_iframe_embed_button = new EventListIframeEmbedButton(); |
|
149 | - } |
|
150 | - return self::$_iframe_embed_button; |
|
151 | - } |
|
152 | - |
|
153 | - |
|
154 | - /** |
|
155 | - * event_list_iframe_embed_button |
|
156 | - * |
|
157 | - * @return void |
|
158 | - * @throws EE_Error |
|
159 | - */ |
|
160 | - public static function event_list_iframe_embed_button() |
|
161 | - { |
|
162 | - $iframe_embed_button = EED_Events_Archive::get_iframe_embed_button(); |
|
163 | - $iframe_embed_button->addEmbedButton(); |
|
164 | - } |
|
165 | - |
|
166 | - |
|
167 | - /** |
|
168 | - * initialize_template_parts |
|
169 | - * |
|
170 | - * @access public |
|
171 | - * @param EE_Events_Archive_Config $config |
|
172 | - * @return EE_Template_Part_Manager |
|
173 | - * @throws EE_Error |
|
174 | - */ |
|
175 | - public function initialize_template_parts(EE_Events_Archive_Config $config = null) |
|
176 | - { |
|
177 | - $config = $config instanceof EE_Events_Archive_Config ? $config : $this->config(); |
|
178 | - EEH_Autoloader::register_template_part_autoloaders(); |
|
179 | - $template_parts = new EE_Template_Part_Manager(); |
|
180 | - $template_parts->add_template_part( |
|
181 | - 'tickets', |
|
182 | - esc_html__('Ticket Selector', 'event_espresso'), |
|
183 | - 'content-espresso_events-tickets.php', |
|
184 | - $config->display_order_tickets |
|
185 | - ); |
|
186 | - $template_parts->add_template_part( |
|
187 | - 'datetimes', |
|
188 | - esc_html__('Dates and Times', 'event_espresso'), |
|
189 | - 'content-espresso_events-datetimes.php', |
|
190 | - $config->display_order_datetimes |
|
191 | - ); |
|
192 | - $template_parts->add_template_part( |
|
193 | - 'event', |
|
194 | - esc_html__('Event Description', 'event_espresso'), |
|
195 | - 'content-espresso_events-details.php', |
|
196 | - $config->display_order_event |
|
197 | - ); |
|
198 | - $template_parts->add_template_part( |
|
199 | - 'venue', |
|
200 | - esc_html__('Venue Information', 'event_espresso'), |
|
201 | - 'content-espresso_events-venues.php', |
|
202 | - $config->display_order_venue |
|
203 | - ); |
|
204 | - do_action('AHEE__EED_Event_Archive__initialize_template_parts', $template_parts); |
|
205 | - return $template_parts; |
|
206 | - } |
|
207 | - |
|
208 | - |
|
209 | - /** |
|
210 | - * run - initial module setup - this gets called by the EE_Front_Controller if the module route is found in the |
|
211 | - * incoming request |
|
212 | - * |
|
213 | - * @access public |
|
214 | - * @param WP $WP |
|
215 | - * @return void |
|
216 | - */ |
|
217 | - public function run($WP) |
|
218 | - { |
|
219 | - do_action('AHEE__EED_Events_Archive__before_run'); |
|
220 | - // ensure valid EE_Events_Archive_Config() object exists |
|
221 | - $this->set_config(); |
|
222 | - /** @type EE_Events_Archive_Config $config */ |
|
223 | - $config = $this->config(); |
|
224 | - // load other required components |
|
225 | - $this->load_event_list_assets(); |
|
226 | - // filter the WP posts_join, posts_where, and posts_orderby SQL clauses |
|
227 | - // add query filters |
|
228 | - EEH_Event_Query::add_query_filters(); |
|
229 | - // set params that will get used by the filters |
|
230 | - EEH_Event_Query::set_query_params( |
|
231 | - '', // month |
|
232 | - '', // category |
|
233 | - $config->display_expired_events, // show_expired |
|
234 | - 'start_date', // orderby |
|
235 | - 'ASC' // sort |
|
236 | - ); |
|
237 | - // check what template is loaded |
|
238 | - add_filter('template_include', array($this, 'template_include'), 999, 1); |
|
239 | - } |
|
240 | - |
|
241 | - |
|
242 | - /** |
|
243 | - * most likely called by the ESPRESSO_EVENTS shortcode which uses this module to do some of it's lifting |
|
244 | - * |
|
245 | - * @return void |
|
246 | - */ |
|
247 | - public function event_list() |
|
248 | - { |
|
249 | - // ensure valid EE_Events_Archive_Config() object exists |
|
250 | - $this->set_config(); |
|
251 | - // load other required components |
|
252 | - $this->load_event_list_assets(); |
|
253 | - } |
|
254 | - |
|
255 | - |
|
256 | - /** |
|
257 | - * @access public |
|
258 | - * @return void |
|
259 | - * @throws EE_Error |
|
260 | - * @throws DomainException |
|
261 | - */ |
|
262 | - public function event_list_iframe() |
|
263 | - { |
|
264 | - EED_Events_Archive::$iframe = true; |
|
265 | - $event_list_iframe = new EventsArchiveIframe($this); |
|
266 | - $event_list_iframe->display(); |
|
267 | - } |
|
268 | - |
|
269 | - |
|
270 | - /** |
|
271 | - * @access public |
|
272 | - * @return string |
|
273 | - */ |
|
274 | - public static function is_iframe() |
|
275 | - { |
|
276 | - return EED_Events_Archive::$iframe; |
|
277 | - } |
|
278 | - |
|
279 | - |
|
280 | - /** |
|
281 | - * @access public |
|
282 | - * @return string |
|
283 | - */ |
|
284 | - public static function link_target() |
|
285 | - { |
|
286 | - return EED_Events_Archive::$iframe ? ' target="_blank"' : ''; |
|
287 | - } |
|
288 | - |
|
289 | - |
|
290 | - /** |
|
291 | - * template_include |
|
292 | - * |
|
293 | - * @access public |
|
294 | - * @param string $template |
|
295 | - * @return string |
|
296 | - */ |
|
297 | - public function template_include($template = '') |
|
298 | - { |
|
299 | - // don't add content filter for dedicated EE child themes or private posts |
|
300 | - if (! EEH_Template::is_espresso_theme()) { |
|
301 | - /** @type EE_Events_Archive_Config $config */ |
|
302 | - $config = $this->config(); |
|
303 | - // add status banner ? |
|
304 | - if ($config->display_status_banner) { |
|
305 | - add_filter('the_title', array('EED_Events_Archive', 'the_title'), 100, 2); |
|
306 | - } |
|
307 | - // if NOT a custom template |
|
308 | - if ( |
|
309 | - apply_filters('FHEE__EED_Event_Archive__template_include__allow_custom_selected_template', false) |
|
310 | - || EE_Registry::instance() |
|
311 | - ->load_core('Front_Controller') |
|
312 | - ->get_selected_template() !== 'archive-espresso_events.php' |
|
313 | - ) { |
|
314 | - // don't display entry meta because the existing theme will take care of that |
|
315 | - add_filter('FHEE__EED_Events_Archive__template_include__events_list_active', '__return_true'); |
|
316 | - // load functions.php file for the theme (loaded by WP if using child theme) |
|
317 | - EEH_Template::load_espresso_theme_functions(); |
|
318 | - // because we don't know if the theme is using the_excerpt() |
|
319 | - add_filter( |
|
320 | - 'the_excerpt', |
|
321 | - array('EED_Events_Archive', 'event_details'), |
|
322 | - EED_Events_Archive::EVENT_DETAILS_PRIORITY |
|
323 | - ); |
|
324 | - // or the_content |
|
325 | - add_filter( |
|
326 | - 'the_content', |
|
327 | - array('EED_Events_Archive', 'event_details'), |
|
328 | - EED_Events_Archive::EVENT_DETAILS_PRIORITY |
|
329 | - ); |
|
330 | - // and just in case they are running get_the_excerpt() which DESTROYS things |
|
331 | - add_filter('get_the_excerpt', array('EED_Events_Archive', 'get_the_excerpt'), 1, 1); |
|
332 | - // don't display entry meta because the existing theme will take care of that |
|
333 | - add_filter('FHEE__content_espresso_events_details_template__display_entry_meta', '__return_false'); |
|
334 | - } |
|
335 | - } |
|
336 | - return $template; |
|
337 | - } |
|
338 | - |
|
339 | - |
|
340 | - /** |
|
341 | - * get_the_excerpt - kinda hacky, but if a theme is using get_the_excerpt(), then we need to remove our filters |
|
342 | - * on the_content() |
|
343 | - * |
|
344 | - * @access public |
|
345 | - * @param string $excerpt |
|
346 | - * @return string |
|
347 | - */ |
|
348 | - public static function get_the_excerpt($excerpt = '') |
|
349 | - { |
|
350 | - if (post_password_required()) { |
|
351 | - return $excerpt; |
|
352 | - } |
|
353 | - if (apply_filters('FHEE__EED_Events_Archive__get_the_excerpt__theme_uses_get_the_excerpt', false)) { |
|
354 | - remove_filter( |
|
355 | - 'the_excerpt', |
|
356 | - array('EED_Events_Archive', 'event_details'), |
|
357 | - EED_Events_Archive::EVENT_DETAILS_PRIORITY |
|
358 | - ); |
|
359 | - remove_filter( |
|
360 | - 'the_content', |
|
361 | - array('EED_Events_Archive', 'event_details'), |
|
362 | - EED_Events_Archive::EVENT_DETAILS_PRIORITY |
|
363 | - ); |
|
364 | - $excerpt = EED_Events_Archive::event_details($excerpt); |
|
365 | - } else { |
|
366 | - EED_Events_Archive::$using_get_the_excerpt = true; |
|
367 | - add_filter('wp_trim_excerpt', array('EED_Events_Archive', 'end_get_the_excerpt'), 999, 1); |
|
368 | - } |
|
369 | - return $excerpt; |
|
370 | - } |
|
371 | - |
|
372 | - |
|
373 | - /** |
|
374 | - * end_get_the_excerpt |
|
375 | - * |
|
376 | - * @access public |
|
377 | - * @param string $text |
|
378 | - * @return string |
|
379 | - */ |
|
380 | - public static function end_get_the_excerpt($text = '') |
|
381 | - { |
|
382 | - EED_Events_Archive::$using_get_the_excerpt = false; |
|
383 | - return $text; |
|
384 | - } |
|
385 | - |
|
386 | - |
|
387 | - /** |
|
388 | - * the_title |
|
389 | - * |
|
390 | - * @access public |
|
391 | - * @param string $title |
|
392 | - * @param string $id |
|
393 | - * @return string |
|
394 | - */ |
|
395 | - public static function the_title($title = '', $id = '') |
|
396 | - { |
|
397 | - global $post; |
|
398 | - if ($post instanceof WP_Post) { |
|
399 | - return ((function_exists('wp_is_block_theme') && wp_is_block_theme()) || in_the_loop()) && $post->ID == $id |
|
400 | - ? espresso_event_status_banner($post->ID) . $title |
|
401 | - : $title; |
|
402 | - } |
|
403 | - return $title; |
|
404 | - } |
|
405 | - |
|
406 | - |
|
407 | - /** |
|
408 | - * event_details |
|
409 | - * |
|
410 | - * @access public |
|
411 | - * @param string $content |
|
412 | - * @return string |
|
413 | - */ |
|
414 | - public static function event_details($content) |
|
415 | - { |
|
416 | - global $post; |
|
417 | - static $current_post_ID = 0; |
|
418 | - if ( |
|
419 | - $current_post_ID !== $post->ID |
|
420 | - && $post->post_type === 'espresso_events' |
|
421 | - && ! EED_Events_Archive::$using_get_the_excerpt |
|
422 | - && ! post_password_required() |
|
423 | - && ( |
|
424 | - apply_filters('FHEE__EES_Espresso_Events__process_shortcode__true', false) |
|
425 | - || ! apply_filters('FHEE__content_espresso_events__template_loaded', false) |
|
426 | - ) |
|
427 | - ) { |
|
428 | - // Set current post ID to prevent showing content twice, but only if headers have definitely been sent. |
|
429 | - // Reason being is that some plugins, like Yoast, need to run through a copy of the loop early |
|
430 | - // BEFORE headers are sent in order to examine the post content and generate content for the HTML header. |
|
431 | - // We want to allow those plugins to still do their thing and have access to our content, but depending on |
|
432 | - // how your event content is being displayed (shortcode, CPT route, etc), this filter can get applied twice, |
|
433 | - // so the following allows this filter to be applied multiple times, but only once for real |
|
434 | - $current_post_ID = did_action('loop_start') ? $post->ID : 0; |
|
435 | - if (EE_Registry::instance()->CFG->template_settings->EED_Events_Archive->use_sortable_display_order) { |
|
436 | - $content = EED_Events_Archive::use_sortable_display_order(); |
|
437 | - } else { |
|
438 | - $content = EED_Events_Archive::use_filterable_display_order(); |
|
439 | - } |
|
440 | - } |
|
441 | - return $content; |
|
442 | - } |
|
443 | - |
|
444 | - |
|
445 | - /** |
|
446 | - * use_sortable_display_order |
|
447 | - * |
|
448 | - * @access protected |
|
449 | - * @return string |
|
450 | - */ |
|
451 | - protected static function use_sortable_display_order() |
|
452 | - { |
|
453 | - // no further password checks required atm |
|
454 | - add_filter('FHEE__EED_Events_Archive__event_details__no_post_password_required', '__return_true'); |
|
455 | - // we need to first remove this callback from being applied to the_content() or the_excerpt() |
|
456 | - // (otherwise it will recurse and blow up the interweb) |
|
457 | - remove_filter( |
|
458 | - 'the_excerpt', |
|
459 | - array('EED_Events_Archive', 'event_details'), |
|
460 | - EED_Events_Archive::EVENT_DETAILS_PRIORITY |
|
461 | - ); |
|
462 | - remove_filter( |
|
463 | - 'the_content', |
|
464 | - array('EED_Events_Archive', 'event_details'), |
|
465 | - EED_Events_Archive::EVENT_DETAILS_PRIORITY |
|
466 | - ); |
|
467 | - remove_filter('get_the_excerpt', array('EED_Events_Archive', 'get_the_excerpt'), 1); |
|
468 | - // now add additional content depending on whether event is using the_excerpt() or the_content() |
|
469 | - EED_Events_Archive::instance()->template_parts = EED_Events_Archive::instance()->initialize_template_parts(); |
|
470 | - $content = EEH_Template::locate_template('content-espresso_events-details.php'); |
|
471 | - $content = EED_Events_Archive::instance()->template_parts->apply_template_part_filters($content); |
|
472 | - // re-add our main filters (or else the next event won't have them) |
|
473 | - add_filter( |
|
474 | - 'the_excerpt', |
|
475 | - array('EED_Events_Archive', 'event_details'), |
|
476 | - EED_Events_Archive::EVENT_DETAILS_PRIORITY |
|
477 | - ); |
|
478 | - add_filter( |
|
479 | - 'the_content', |
|
480 | - array('EED_Events_Archive', 'event_details'), |
|
481 | - EED_Events_Archive::EVENT_DETAILS_PRIORITY |
|
482 | - ); |
|
483 | - add_filter('get_the_excerpt', array('EED_Events_Archive', 'get_the_excerpt'), 1, 1); |
|
484 | - remove_filter( |
|
485 | - 'FHEE__EED_Events_Archive__event_details__no_post_password_required', |
|
486 | - '__return_true' |
|
487 | - ); |
|
488 | - return $content; |
|
489 | - } |
|
490 | - |
|
491 | - |
|
492 | - /** |
|
493 | - * use_filterable_display_order |
|
494 | - * |
|
495 | - * @access protected |
|
496 | - * @return string |
|
497 | - */ |
|
498 | - protected static function use_filterable_display_order() |
|
499 | - { |
|
500 | - // we need to first remove this callback from being applied to the_content() |
|
501 | - // (otherwise it will recurse and blow up the interweb) |
|
502 | - remove_filter( |
|
503 | - 'the_excerpt', |
|
504 | - array('EED_Events_Archive', 'event_details'), |
|
505 | - EED_Events_Archive::EVENT_DETAILS_PRIORITY |
|
506 | - ); |
|
507 | - remove_filter( |
|
508 | - 'the_content', |
|
509 | - array('EED_Events_Archive', 'event_details'), |
|
510 | - EED_Events_Archive::EVENT_DETAILS_PRIORITY |
|
511 | - ); |
|
512 | - remove_filter('get_the_excerpt', array('EED_Events_Archive', 'get_the_excerpt'), 1); |
|
513 | - // now add additional content depending on whether event is using the_excerpt() or the_content() |
|
514 | - EED_Events_Archive::_add_additional_excerpt_filters(); |
|
515 | - EED_Events_Archive::_add_additional_content_filters(); |
|
516 | - do_action('AHEE__EED_Events_Archive__use_filterable_display_order__after_add_filters'); |
|
517 | - // now load our template |
|
518 | - $content = EEH_Template::locate_template('content-espresso_events-details.php'); |
|
519 | - // re-add our main filters (or else the next event won't have them) |
|
520 | - add_filter( |
|
521 | - 'the_excerpt', |
|
522 | - array('EED_Events_Archive', 'event_details'), |
|
523 | - EED_Events_Archive::EVENT_DETAILS_PRIORITY |
|
524 | - ); |
|
525 | - add_filter( |
|
526 | - 'the_content', |
|
527 | - array('EED_Events_Archive', 'event_details'), |
|
528 | - EED_Events_Archive::EVENT_DETAILS_PRIORITY |
|
529 | - ); |
|
530 | - add_filter('get_the_excerpt', array('EED_Events_Archive', 'get_the_excerpt'), 1, 1); |
|
531 | - // but remove the other filters so that they don't get applied to the next post |
|
532 | - EED_Events_Archive::_remove_additional_events_archive_filters(); |
|
533 | - do_action('AHEE__EED_Events_Archive__use_filterable_display_order__after_remove_filters'); |
|
534 | - // we're not returning the $content directly because the template we are loading uses the_content (or the_excerpt) |
|
535 | - // return ! empty( $template ) ? $template : $content; |
|
536 | - return $content; |
|
537 | - } |
|
538 | - |
|
539 | - |
|
540 | - /** |
|
541 | - * event_datetimes - adds datetimes ABOVE content |
|
542 | - * |
|
543 | - * @access public |
|
544 | - * @param string $content |
|
545 | - * @return string |
|
546 | - */ |
|
547 | - public static function event_datetimes($content) |
|
548 | - { |
|
549 | - if (post_password_required()) { |
|
550 | - return $content; |
|
551 | - } |
|
552 | - return EEH_Template::locate_template('content-espresso_events-datetimes.php') . $content; |
|
553 | - } |
|
554 | - |
|
555 | - |
|
556 | - /** |
|
557 | - * event_tickets - adds tickets ABOVE content (which includes datetimes) |
|
558 | - * |
|
559 | - * @access public |
|
560 | - * @param string $content |
|
561 | - * @return string |
|
562 | - */ |
|
563 | - public static function event_tickets($content) |
|
564 | - { |
|
565 | - if (post_password_required()) { |
|
566 | - return $content; |
|
567 | - } |
|
568 | - return EEH_Template::locate_template('content-espresso_events-tickets.php') . $content; |
|
569 | - } |
|
570 | - |
|
571 | - |
|
572 | - /** |
|
573 | - * event_venues - adds venues BELOW content |
|
574 | - * |
|
575 | - * @access public |
|
576 | - * @param string $content |
|
577 | - * @return string |
|
578 | - */ |
|
579 | - public static function event_venue($content) |
|
580 | - { |
|
581 | - return EED_Events_Archive::event_venues($content); |
|
582 | - } |
|
583 | - |
|
584 | - |
|
585 | - /** |
|
586 | - * event_venues - adds venues BELOW content |
|
587 | - * |
|
588 | - * @access public |
|
589 | - * @param string $content |
|
590 | - * @return string |
|
591 | - */ |
|
592 | - public static function event_venues($content) |
|
593 | - { |
|
594 | - if (post_password_required()) { |
|
595 | - return $content; |
|
596 | - } |
|
597 | - return $content . EEH_Template::locate_template('content-espresso_events-venues.php'); |
|
598 | - } |
|
599 | - |
|
600 | - |
|
601 | - /** |
|
602 | - * _add_additional_content_filters |
|
603 | - * |
|
604 | - * @access private |
|
605 | - * @return void |
|
606 | - */ |
|
607 | - private static function _add_additional_excerpt_filters() |
|
608 | - { |
|
609 | - add_filter( |
|
610 | - 'the_excerpt', |
|
611 | - array('EED_Events_Archive', 'event_datetimes'), |
|
612 | - EED_Events_Archive::EVENT_DATETIMES_PRIORITY |
|
613 | - ); |
|
614 | - add_filter( |
|
615 | - 'the_excerpt', |
|
616 | - array('EED_Events_Archive', 'event_tickets'), |
|
617 | - EED_Events_Archive::EVENT_TICKETS_PRIORITY |
|
618 | - ); |
|
619 | - add_filter( |
|
620 | - 'the_excerpt', |
|
621 | - array('EED_Events_Archive', 'event_venues'), |
|
622 | - EED_Events_Archive::EVENT_VENUES_PRIORITY |
|
623 | - ); |
|
624 | - } |
|
625 | - |
|
626 | - |
|
627 | - /** |
|
628 | - * _add_additional_content_filters |
|
629 | - * |
|
630 | - * @access private |
|
631 | - * @return void |
|
632 | - */ |
|
633 | - private static function _add_additional_content_filters() |
|
634 | - { |
|
635 | - add_filter( |
|
636 | - 'the_content', |
|
637 | - array('EED_Events_Archive', 'event_datetimes'), |
|
638 | - EED_Events_Archive::EVENT_DATETIMES_PRIORITY |
|
639 | - ); |
|
640 | - add_filter( |
|
641 | - 'the_content', |
|
642 | - array('EED_Events_Archive', 'event_tickets'), |
|
643 | - EED_Events_Archive::EVENT_TICKETS_PRIORITY |
|
644 | - ); |
|
645 | - add_filter( |
|
646 | - 'the_content', |
|
647 | - array('EED_Events_Archive', 'event_venues'), |
|
648 | - EED_Events_Archive::EVENT_VENUES_PRIORITY |
|
649 | - ); |
|
650 | - } |
|
651 | - |
|
652 | - |
|
653 | - /** |
|
654 | - * _remove_additional_events_archive_filters |
|
655 | - * |
|
656 | - * @access private |
|
657 | - * @return void |
|
658 | - */ |
|
659 | - private static function _remove_additional_events_archive_filters() |
|
660 | - { |
|
661 | - remove_filter( |
|
662 | - 'the_excerpt', |
|
663 | - array('EED_Events_Archive', 'event_datetimes'), |
|
664 | - EED_Events_Archive::EVENT_DATETIMES_PRIORITY |
|
665 | - ); |
|
666 | - remove_filter( |
|
667 | - 'the_excerpt', |
|
668 | - array('EED_Events_Archive', 'event_tickets'), |
|
669 | - EED_Events_Archive::EVENT_TICKETS_PRIORITY |
|
670 | - ); |
|
671 | - remove_filter( |
|
672 | - 'the_excerpt', |
|
673 | - array('EED_Events_Archive', 'event_venues'), |
|
674 | - EED_Events_Archive::EVENT_VENUES_PRIORITY |
|
675 | - ); |
|
676 | - remove_filter( |
|
677 | - 'the_content', |
|
678 | - array('EED_Events_Archive', 'event_datetimes'), |
|
679 | - EED_Events_Archive::EVENT_DATETIMES_PRIORITY |
|
680 | - ); |
|
681 | - remove_filter( |
|
682 | - 'the_content', |
|
683 | - array('EED_Events_Archive', 'event_tickets'), |
|
684 | - EED_Events_Archive::EVENT_TICKETS_PRIORITY |
|
685 | - ); |
|
686 | - remove_filter( |
|
687 | - 'the_content', |
|
688 | - array('EED_Events_Archive', 'event_venues'), |
|
689 | - EED_Events_Archive::EVENT_VENUES_PRIORITY |
|
690 | - ); |
|
691 | - } |
|
692 | - |
|
693 | - |
|
694 | - /** |
|
695 | - * remove_all_events_archive_filters |
|
696 | - * |
|
697 | - * @access public |
|
698 | - * @return void |
|
699 | - */ |
|
700 | - public static function remove_all_events_archive_filters() |
|
701 | - { |
|
702 | - // remove_filter( 'get_the_excerpt', array( 'EED_Events_Archive', 'get_the_excerpt' ), 1 ); |
|
703 | - remove_filter('the_title', array('EED_Events_Archive', 'the_title'), 1); |
|
704 | - remove_filter( |
|
705 | - 'the_excerpt', |
|
706 | - array('EED_Events_Archive', 'event_details'), |
|
707 | - EED_Events_Archive::EVENT_DETAILS_PRIORITY |
|
708 | - ); |
|
709 | - remove_filter( |
|
710 | - 'the_excerpt', |
|
711 | - array('EED_Events_Archive', 'event_datetimes'), |
|
712 | - EED_Events_Archive::EVENT_DATETIMES_PRIORITY |
|
713 | - ); |
|
714 | - remove_filter( |
|
715 | - 'the_excerpt', |
|
716 | - array('EED_Events_Archive', 'event_tickets'), |
|
717 | - EED_Events_Archive::EVENT_TICKETS_PRIORITY |
|
718 | - ); |
|
719 | - remove_filter( |
|
720 | - 'the_excerpt', |
|
721 | - array('EED_Events_Archive', 'event_venues'), |
|
722 | - EED_Events_Archive::EVENT_VENUES_PRIORITY |
|
723 | - ); |
|
724 | - remove_filter( |
|
725 | - 'the_content', |
|
726 | - array('EED_Events_Archive', 'event_details'), |
|
727 | - EED_Events_Archive::EVENT_DETAILS_PRIORITY |
|
728 | - ); |
|
729 | - remove_filter( |
|
730 | - 'the_content', |
|
731 | - array('EED_Events_Archive', 'event_datetimes'), |
|
732 | - EED_Events_Archive::EVENT_DATETIMES_PRIORITY |
|
733 | - ); |
|
734 | - remove_filter( |
|
735 | - 'the_content', |
|
736 | - array('EED_Events_Archive', 'event_tickets'), |
|
737 | - EED_Events_Archive::EVENT_TICKETS_PRIORITY |
|
738 | - ); |
|
739 | - remove_filter( |
|
740 | - 'the_content', |
|
741 | - array('EED_Events_Archive', 'event_venues'), |
|
742 | - EED_Events_Archive::EVENT_VENUES_PRIORITY |
|
743 | - ); |
|
744 | - // don't display entry meta because the existing theme will take care of that |
|
745 | - remove_filter( |
|
746 | - 'FHEE__content_espresso_events_details_template__display_entry_meta', |
|
747 | - '__return_false' |
|
748 | - ); |
|
749 | - } |
|
750 | - |
|
751 | - |
|
752 | - /** |
|
753 | - * load_event_list_assets |
|
754 | - * |
|
755 | - * @access public |
|
756 | - * @return void |
|
757 | - */ |
|
758 | - public function load_event_list_assets() |
|
759 | - { |
|
760 | - do_action('AHEE__EED_Events_Archive__before_load_assets'); |
|
761 | - add_filter('FHEE_load_EE_Session', '__return_true'); |
|
762 | - add_filter('FHEE__EED_Ticket_Selector__load_tckt_slctr_assets', '__return_true'); |
|
763 | - add_action('wp_enqueue_scripts', array($this, 'wp_enqueue_scripts'), 10); |
|
764 | - if (EE_Registry::instance()->CFG->map_settings->use_google_maps) { |
|
765 | - add_action('wp_enqueue_scripts', array('EEH_Maps', 'espresso_google_map_js'), 11); |
|
766 | - } |
|
767 | - } |
|
768 | - |
|
769 | - |
|
770 | - /** |
|
771 | - * wp_enqueue_scripts |
|
772 | - * |
|
773 | - * @access public |
|
774 | - * @return void |
|
775 | - * @throws EE_Error |
|
776 | - */ |
|
777 | - public function wp_enqueue_scripts() |
|
778 | - { |
|
779 | - // get some style |
|
780 | - if (apply_filters('FHEE_enable_default_espresso_css', false)) { |
|
781 | - // first check uploads folder |
|
782 | - if (EEH_File::is_readable(get_stylesheet_directory() . $this->theme . '/style.css')) { |
|
783 | - wp_register_style( |
|
784 | - $this->theme, |
|
785 | - get_stylesheet_directory_uri() . $this->theme . '/style.css', |
|
786 | - array('dashicons', 'espresso_default') |
|
787 | - ); |
|
788 | - } else { |
|
789 | - } |
|
790 | - wp_enqueue_style($this->theme); |
|
791 | - } |
|
792 | - } |
|
793 | - |
|
794 | - |
|
795 | - /** |
|
796 | - * template_settings_form |
|
797 | - * |
|
798 | - * @access public |
|
799 | - * @static |
|
800 | - * @return string |
|
801 | - */ |
|
802 | - public static function template_settings_form() |
|
803 | - { |
|
804 | - $template_settings = EE_Registry::instance()->CFG->template_settings; |
|
805 | - $template_settings->EED_Events_Archive = isset($template_settings->EED_Events_Archive) |
|
806 | - ? $template_settings->EED_Events_Archive : new EE_Events_Archive_Config(); |
|
807 | - $template_settings->EED_Events_Archive = apply_filters( |
|
808 | - 'FHEE__EED_Events_Archive__template_settings_form__event_list_config', |
|
809 | - $template_settings->EED_Events_Archive |
|
810 | - ); |
|
811 | - $events_archive_settings = array( |
|
812 | - 'display_status_banner' => 0, |
|
813 | - 'display_description' => 1, |
|
814 | - 'display_ticket_selector' => 0, |
|
815 | - 'display_datetimes' => 1, |
|
816 | - 'display_venue' => 0, |
|
817 | - 'display_expired_events' => 0, |
|
818 | - ); |
|
819 | - $events_archive_settings = array_merge( |
|
820 | - $events_archive_settings, |
|
821 | - (array) $template_settings->EED_Events_Archive |
|
822 | - ); |
|
823 | - EEH_Template::display_template( |
|
824 | - EVENTS_ARCHIVE_TEMPLATES_PATH . 'admin-event-list-settings.template.php', |
|
825 | - $events_archive_settings |
|
826 | - ); |
|
827 | - } |
|
828 | - |
|
829 | - |
|
830 | - /** |
|
831 | - * update_template_settings |
|
832 | - * |
|
833 | - * @access public |
|
834 | - * @param EE_Template_Config $CFG |
|
835 | - * @param array $REQ |
|
836 | - * @return EE_Template_Config |
|
837 | - */ |
|
838 | - public static function update_template_settings($CFG, $REQ) |
|
839 | - { |
|
840 | - $CFG->EED_Events_Archive = new EE_Events_Archive_Config(); |
|
841 | - // unless we are resetting the config... |
|
842 | - if ( |
|
843 | - ! isset($REQ['EED_Events_Archive_reset_event_list_settings']) |
|
844 | - || absint($REQ['EED_Events_Archive_reset_event_list_settings']) !== 1 |
|
845 | - ) { |
|
846 | - $CFG->EED_Events_Archive->display_status_banner = isset($REQ['EED_Events_Archive_display_status_banner']) |
|
847 | - ? absint($REQ['EED_Events_Archive_display_status_banner']) : 0; |
|
848 | - $CFG->EED_Events_Archive->display_description = isset($REQ['EED_Events_Archive_display_description']) |
|
849 | - ? absint($REQ['EED_Events_Archive_display_description']) : 1; |
|
850 | - $CFG->EED_Events_Archive->display_ticket_selector = isset($REQ['EED_Events_Archive_display_ticket_selector']) |
|
851 | - ? absint($REQ['EED_Events_Archive_display_ticket_selector']) : 0; |
|
852 | - $CFG->EED_Events_Archive->display_datetimes = isset($REQ['EED_Events_Archive_display_datetimes']) ? absint( |
|
853 | - $REQ['EED_Events_Archive_display_datetimes'] |
|
854 | - ) : 1; |
|
855 | - $CFG->EED_Events_Archive->display_venue = isset($REQ['EED_Events_Archive_display_venue']) ? absint( |
|
856 | - $REQ['EED_Events_Archive_display_venue'] |
|
857 | - ) : 0; |
|
858 | - $CFG->EED_Events_Archive->display_expired_events = isset($REQ['EED_Events_Archive_display_expired_events']) |
|
859 | - ? absint($REQ['EED_Events_Archive_display_expired_events']) : 0; |
|
860 | - } |
|
861 | - return $CFG; |
|
862 | - } |
|
863 | - |
|
864 | - |
|
865 | - /** |
|
866 | - * event_list_css |
|
867 | - * |
|
868 | - * @access public |
|
869 | - * @param string $extra_class |
|
870 | - * @return string |
|
871 | - */ |
|
872 | - public static function event_list_css($extra_class = '') |
|
873 | - { |
|
874 | - $event_list_css = ! empty($extra_class) ? array($extra_class) : array(); |
|
875 | - $event_list_css[] = 'espresso-event-list-event'; |
|
876 | - return implode(' ', $event_list_css); |
|
877 | - } |
|
878 | - |
|
879 | - |
|
880 | - /** |
|
881 | - * event_categories |
|
882 | - * |
|
883 | - * @access public |
|
884 | - * @return array |
|
885 | - */ |
|
886 | - public static function event_categories() |
|
887 | - { |
|
888 | - return EE_Registry::instance()->load_model('Term')->get_all_ee_categories(); |
|
889 | - } |
|
890 | - |
|
891 | - |
|
892 | - /** |
|
893 | - * display_description |
|
894 | - * |
|
895 | - * @access public |
|
896 | - * @param $value |
|
897 | - * @return bool |
|
898 | - */ |
|
899 | - public static function display_description($value) |
|
900 | - { |
|
901 | - $config = EE_Registry::instance()->CFG->template_settings->EED_Events_Archive; |
|
902 | - $display_description = isset($config->display_description) ? $config->display_description : 1; |
|
903 | - return $display_description === $value ? true : false; |
|
904 | - } |
|
905 | - |
|
906 | - |
|
907 | - /** |
|
908 | - * display_ticket_selector |
|
909 | - * |
|
910 | - * @access public |
|
911 | - * @return bool |
|
912 | - */ |
|
913 | - public static function display_ticket_selector() |
|
914 | - { |
|
915 | - $config = EE_Registry::instance()->CFG->template_settings->EED_Events_Archive; |
|
916 | - return isset($config->display_ticket_selector) && $config->display_ticket_selector ? true : false; |
|
917 | - } |
|
918 | - |
|
919 | - |
|
920 | - /** |
|
921 | - * display_venue |
|
922 | - * |
|
923 | - * @access public |
|
924 | - * @return bool |
|
925 | - */ |
|
926 | - public static function display_venue() |
|
927 | - { |
|
928 | - $config = EE_Registry::instance()->CFG->template_settings->EED_Events_Archive; |
|
929 | - return isset($config->display_venue) && $config->display_venue && EEH_Venue_View::venue_name() ? true : false; |
|
930 | - } |
|
931 | - |
|
932 | - |
|
933 | - /** |
|
934 | - * display_datetimes |
|
935 | - * |
|
936 | - * @access public |
|
937 | - * @return bool |
|
938 | - */ |
|
939 | - public static function display_datetimes() |
|
940 | - { |
|
941 | - $config = EE_Registry::instance()->CFG->template_settings->EED_Events_Archive; |
|
942 | - return isset($config->display_datetimes) && $config->display_datetimes ? true : false; |
|
943 | - } |
|
944 | - |
|
945 | - |
|
946 | - /** |
|
947 | - * event_list_title |
|
948 | - * |
|
949 | - * @access public |
|
950 | - * @return string |
|
951 | - */ |
|
952 | - public static function event_list_title() |
|
953 | - { |
|
954 | - return apply_filters( |
|
955 | - 'FHEE__archive_espresso_events_template__upcoming_events_h1', |
|
956 | - esc_html__('Upcoming Events', 'event_espresso') |
|
957 | - ); |
|
958 | - } |
|
959 | - |
|
960 | - |
|
961 | - // GRAVEYARD |
|
962 | - |
|
963 | - |
|
964 | - /** |
|
965 | - * @since 4.4.0 |
|
966 | - */ |
|
967 | - public static function _doing_it_wrong_notice($function = '') |
|
968 | - { |
|
969 | - EE_Error::doing_it_wrong( |
|
970 | - __FUNCTION__, |
|
971 | - sprintf( |
|
972 | - esc_html__( |
|
973 | - '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', |
|
974 | - 'event_espresso' |
|
975 | - ), |
|
976 | - $function, |
|
977 | - '<br />', |
|
978 | - '4.6.0' |
|
979 | - ), |
|
980 | - '4.4.0' |
|
981 | - ); |
|
982 | - } |
|
983 | - |
|
984 | - |
|
985 | - /** |
|
986 | - * @deprecated |
|
987 | - * @since 4.4.0 |
|
988 | - */ |
|
989 | - public function get_post_data() |
|
990 | - { |
|
991 | - EEH_Event_Query::set_query_params(); |
|
992 | - } |
|
993 | - |
|
994 | - |
|
995 | - /** |
|
996 | - * @throws EE_Error |
|
997 | - * @since 4.4.0 |
|
998 | - * @deprecated |
|
999 | - */ |
|
1000 | - public function posts_fields($SQL, WP_Query $wp_query) |
|
1001 | - { |
|
1002 | - EED_Events_Archive::_doing_it_wrong_notice(__FUNCTION__); |
|
1003 | - return EEH_Event_Query::posts_fields($SQL, $wp_query); |
|
1004 | - } |
|
1005 | - |
|
1006 | - |
|
1007 | - /** |
|
1008 | - * @throws EE_Error |
|
1009 | - * @since 4.4.0 |
|
1010 | - * @deprecated |
|
1011 | - */ |
|
1012 | - public static function posts_fields_sql_for_orderby($orderby_params = array()) |
|
1013 | - { |
|
1014 | - EED_Events_Archive::_doing_it_wrong_notice(__FUNCTION__); |
|
1015 | - return EEH_Event_Query::posts_fields_sql_for_orderby($orderby_params); |
|
1016 | - } |
|
1017 | - |
|
1018 | - |
|
1019 | - /** |
|
1020 | - * @throws EE_Error |
|
1021 | - * @since 4.4.0 |
|
1022 | - * @deprecated |
|
1023 | - */ |
|
1024 | - public function posts_join($SQL, WP_Query $wp_query) |
|
1025 | - { |
|
1026 | - EED_Events_Archive::_doing_it_wrong_notice(__FUNCTION__); |
|
1027 | - return EEH_Event_Query::posts_join($SQL, $wp_query); |
|
1028 | - } |
|
1029 | - |
|
1030 | - |
|
1031 | - /** |
|
1032 | - * @deprecated |
|
1033 | - * @since 4.4.0 |
|
1034 | - */ |
|
1035 | - public static function posts_join_sql_for_terms($join_terms = null) |
|
1036 | - { |
|
1037 | - EED_Events_Archive::_doing_it_wrong_notice(__FUNCTION__); |
|
1038 | - return EEH_Event_Query::posts_join_sql_for_terms($join_terms); |
|
1039 | - } |
|
1040 | - |
|
1041 | - |
|
1042 | - /** |
|
1043 | - * @throws EE_Error |
|
1044 | - * @since 4.4.0 |
|
1045 | - * @deprecated |
|
1046 | - */ |
|
1047 | - public static function posts_join_for_orderby($orderby_params = array()) |
|
1048 | - { |
|
1049 | - EED_Events_Archive::_doing_it_wrong_notice(__FUNCTION__); |
|
1050 | - return EEH_Event_Query::posts_join_for_orderby($orderby_params); |
|
1051 | - } |
|
1052 | - |
|
1053 | - |
|
1054 | - /** |
|
1055 | - * @throws EE_Error |
|
1056 | - * @since 4.4.0 |
|
1057 | - * @deprecated |
|
1058 | - */ |
|
1059 | - public function posts_where($SQL, WP_Query $wp_query) |
|
1060 | - { |
|
1061 | - EED_Events_Archive::_doing_it_wrong_notice(__FUNCTION__); |
|
1062 | - return EEH_Event_Query::posts_where($SQL, $wp_query); |
|
1063 | - } |
|
1064 | - |
|
1065 | - |
|
1066 | - /** |
|
1067 | - * @throws EE_Error |
|
1068 | - * @since 4.4.0 |
|
1069 | - * @deprecated |
|
1070 | - */ |
|
1071 | - public static function posts_where_sql_for_show_expired($show_expired = false) |
|
1072 | - { |
|
1073 | - EED_Events_Archive::_doing_it_wrong_notice(__FUNCTION__); |
|
1074 | - return EEH_Event_Query::posts_where_sql_for_show_expired($show_expired); |
|
1075 | - } |
|
1076 | - |
|
1077 | - |
|
1078 | - /** |
|
1079 | - * @deprecated |
|
1080 | - * @since 4.4.0 |
|
1081 | - */ |
|
1082 | - public static function posts_where_sql_for_event_category_slug($event_category_slug = null) |
|
1083 | - { |
|
1084 | - EED_Events_Archive::_doing_it_wrong_notice(__FUNCTION__); |
|
1085 | - return EEH_Event_Query::posts_where_sql_for_event_category_slug($event_category_slug); |
|
1086 | - } |
|
1087 | - |
|
1088 | - |
|
1089 | - /** |
|
1090 | - * @throws EE_Error |
|
1091 | - * @since 4.4.0 |
|
1092 | - * @deprecated |
|
1093 | - */ |
|
1094 | - public static function posts_where_sql_for_event_list_month($month = null) |
|
1095 | - { |
|
1096 | - EED_Events_Archive::_doing_it_wrong_notice(__FUNCTION__); |
|
1097 | - return EEH_Event_Query::posts_where_sql_for_event_list_month($month); |
|
1098 | - } |
|
1099 | - |
|
1100 | - |
|
1101 | - /** |
|
1102 | - * @throws EE_Error |
|
1103 | - * @since 4.4.0 |
|
1104 | - * @deprecated |
|
1105 | - */ |
|
1106 | - public function posts_orderby($SQL, WP_Query $wp_query) |
|
1107 | - { |
|
1108 | - EED_Events_Archive::_doing_it_wrong_notice(__FUNCTION__); |
|
1109 | - return EEH_Event_Query::posts_orderby($SQL, $wp_query); |
|
1110 | - } |
|
1111 | - |
|
1112 | - |
|
1113 | - /** |
|
1114 | - * @throws EE_Error |
|
1115 | - * @since 4.4.0 |
|
1116 | - * @deprecated |
|
1117 | - */ |
|
1118 | - public static function posts_orderby_sql($orderby_params = array(), $sort = 'ASC') |
|
1119 | - { |
|
1120 | - EED_Events_Archive::_doing_it_wrong_notice(__FUNCTION__); |
|
1121 | - return EEH_Event_Query::posts_orderby_sql($orderby_params, $sort); |
|
1122 | - } |
|
19 | + const EVENT_DETAILS_PRIORITY = 100; |
|
20 | + |
|
21 | + const EVENT_DATETIMES_PRIORITY = 110; |
|
22 | + |
|
23 | + const EVENT_TICKETS_PRIORITY = 120; |
|
24 | + |
|
25 | + const EVENT_VENUES_PRIORITY = 130; |
|
26 | + |
|
27 | + |
|
28 | + public static $espresso_event_list_ID = 0; |
|
29 | + |
|
30 | + public static $espresso_grid_event_lists = array(); |
|
31 | + |
|
32 | + /** |
|
33 | + * @type bool $using_get_the_excerpt |
|
34 | + */ |
|
35 | + protected static $using_get_the_excerpt = false; |
|
36 | + |
|
37 | + /** |
|
38 | + * Used to flag when the event list is being called from an external iframe. |
|
39 | + * |
|
40 | + * @var bool $iframe |
|
41 | + */ |
|
42 | + protected static $iframe = false; |
|
43 | + |
|
44 | + /** |
|
45 | + * @var EventListIframeEmbedButton $_iframe_embed_button |
|
46 | + */ |
|
47 | + private static $_iframe_embed_button; |
|
48 | + |
|
49 | + /** |
|
50 | + * @type EE_Template_Part_Manager $template_parts |
|
51 | + */ |
|
52 | + protected $template_parts; |
|
53 | + |
|
54 | + |
|
55 | + /** |
|
56 | + * @return EED_Events_Archive |
|
57 | + */ |
|
58 | + public static function instance() |
|
59 | + { |
|
60 | + return parent::get_instance(__CLASS__); |
|
61 | + } |
|
62 | + |
|
63 | + |
|
64 | + /** |
|
65 | + * set_hooks - for hooking into EE Core, other modules, etc |
|
66 | + * |
|
67 | + * @return void |
|
68 | + * @throws InvalidArgumentException |
|
69 | + * @throws InvalidDataTypeException |
|
70 | + * @throws InvalidInterfaceException |
|
71 | + */ |
|
72 | + public static function set_hooks() |
|
73 | + { |
|
74 | + /** @var EventEspresso\core\domain\entities\custom_post_types\CustomPostTypeDefinitions $custom_post_type_definitions */ |
|
75 | + $custom_post_type_definitions = LoaderFactory::getLoader()->getShared( |
|
76 | + 'EventEspresso\core\domain\entities\custom_post_types\CustomPostTypeDefinitions' |
|
77 | + ); |
|
78 | + $custom_post_types = $custom_post_type_definitions->getDefinitions(); |
|
79 | + EE_Config::register_route( |
|
80 | + $custom_post_types['espresso_events']['plural_slug'], |
|
81 | + 'Events_Archive', |
|
82 | + 'run' |
|
83 | + ); |
|
84 | + EE_Config::register_route( |
|
85 | + 'event_list', |
|
86 | + 'Events_Archive', |
|
87 | + 'event_list' |
|
88 | + ); |
|
89 | + EE_Config::register_route( |
|
90 | + 'iframe', |
|
91 | + 'Events_Archive', |
|
92 | + 'event_list_iframe', |
|
93 | + 'event_list' |
|
94 | + ); |
|
95 | + add_action('wp_loaded', array('EED_Events_Archive', 'set_definitions'), 2); |
|
96 | + } |
|
97 | + |
|
98 | + |
|
99 | + /** |
|
100 | + * set_hooks_admin - for hooking into EE Admin Core, other modules, etc |
|
101 | + * |
|
102 | + * @access public |
|
103 | + * @return void |
|
104 | + */ |
|
105 | + public static function set_hooks_admin() |
|
106 | + { |
|
107 | + add_action('wp_loaded', array('EED_Events_Archive', 'set_definitions'), 2); |
|
108 | + // hook into the end of the \EE_Admin_Page::_load_page_dependencies() |
|
109 | + // to load assets for "espresso_events" page on the "default" route (action) |
|
110 | + add_action( |
|
111 | + 'FHEE__EE_Admin_Page___load_page_dependencies__after_load__espresso_events__default', |
|
112 | + array('EED_Events_Archive', 'event_list_iframe_embed_button'), |
|
113 | + 10 |
|
114 | + ); |
|
115 | + } |
|
116 | + |
|
117 | + |
|
118 | + /** |
|
119 | + * set_definitions |
|
120 | + * |
|
121 | + * @access public |
|
122 | + * @return void |
|
123 | + */ |
|
124 | + public static function set_definitions() |
|
125 | + { |
|
126 | + define('EVENTS_ARCHIVE_ASSETS_URL', plugin_dir_url(__FILE__) . 'assets/'); |
|
127 | + define('EVENTS_ARCHIVE_TEMPLATES_PATH', str_replace('\\', '/', plugin_dir_path(__FILE__)) . 'templates/'); |
|
128 | + } |
|
129 | + |
|
130 | + |
|
131 | + /** |
|
132 | + * set up EE_Events_Archive_Config |
|
133 | + */ |
|
134 | + protected function set_config() |
|
135 | + { |
|
136 | + $this->set_config_section('template_settings'); |
|
137 | + $this->set_config_class('EE_Events_Archive_Config'); |
|
138 | + $this->set_config_name('EED_Events_Archive'); |
|
139 | + } |
|
140 | + |
|
141 | + |
|
142 | + /** |
|
143 | + * @return EventListIframeEmbedButton |
|
144 | + */ |
|
145 | + public static function get_iframe_embed_button() |
|
146 | + { |
|
147 | + if (! self::$_iframe_embed_button instanceof EventListIframeEmbedButton) { |
|
148 | + self::$_iframe_embed_button = new EventListIframeEmbedButton(); |
|
149 | + } |
|
150 | + return self::$_iframe_embed_button; |
|
151 | + } |
|
152 | + |
|
153 | + |
|
154 | + /** |
|
155 | + * event_list_iframe_embed_button |
|
156 | + * |
|
157 | + * @return void |
|
158 | + * @throws EE_Error |
|
159 | + */ |
|
160 | + public static function event_list_iframe_embed_button() |
|
161 | + { |
|
162 | + $iframe_embed_button = EED_Events_Archive::get_iframe_embed_button(); |
|
163 | + $iframe_embed_button->addEmbedButton(); |
|
164 | + } |
|
165 | + |
|
166 | + |
|
167 | + /** |
|
168 | + * initialize_template_parts |
|
169 | + * |
|
170 | + * @access public |
|
171 | + * @param EE_Events_Archive_Config $config |
|
172 | + * @return EE_Template_Part_Manager |
|
173 | + * @throws EE_Error |
|
174 | + */ |
|
175 | + public function initialize_template_parts(EE_Events_Archive_Config $config = null) |
|
176 | + { |
|
177 | + $config = $config instanceof EE_Events_Archive_Config ? $config : $this->config(); |
|
178 | + EEH_Autoloader::register_template_part_autoloaders(); |
|
179 | + $template_parts = new EE_Template_Part_Manager(); |
|
180 | + $template_parts->add_template_part( |
|
181 | + 'tickets', |
|
182 | + esc_html__('Ticket Selector', 'event_espresso'), |
|
183 | + 'content-espresso_events-tickets.php', |
|
184 | + $config->display_order_tickets |
|
185 | + ); |
|
186 | + $template_parts->add_template_part( |
|
187 | + 'datetimes', |
|
188 | + esc_html__('Dates and Times', 'event_espresso'), |
|
189 | + 'content-espresso_events-datetimes.php', |
|
190 | + $config->display_order_datetimes |
|
191 | + ); |
|
192 | + $template_parts->add_template_part( |
|
193 | + 'event', |
|
194 | + esc_html__('Event Description', 'event_espresso'), |
|
195 | + 'content-espresso_events-details.php', |
|
196 | + $config->display_order_event |
|
197 | + ); |
|
198 | + $template_parts->add_template_part( |
|
199 | + 'venue', |
|
200 | + esc_html__('Venue Information', 'event_espresso'), |
|
201 | + 'content-espresso_events-venues.php', |
|
202 | + $config->display_order_venue |
|
203 | + ); |
|
204 | + do_action('AHEE__EED_Event_Archive__initialize_template_parts', $template_parts); |
|
205 | + return $template_parts; |
|
206 | + } |
|
207 | + |
|
208 | + |
|
209 | + /** |
|
210 | + * run - initial module setup - this gets called by the EE_Front_Controller if the module route is found in the |
|
211 | + * incoming request |
|
212 | + * |
|
213 | + * @access public |
|
214 | + * @param WP $WP |
|
215 | + * @return void |
|
216 | + */ |
|
217 | + public function run($WP) |
|
218 | + { |
|
219 | + do_action('AHEE__EED_Events_Archive__before_run'); |
|
220 | + // ensure valid EE_Events_Archive_Config() object exists |
|
221 | + $this->set_config(); |
|
222 | + /** @type EE_Events_Archive_Config $config */ |
|
223 | + $config = $this->config(); |
|
224 | + // load other required components |
|
225 | + $this->load_event_list_assets(); |
|
226 | + // filter the WP posts_join, posts_where, and posts_orderby SQL clauses |
|
227 | + // add query filters |
|
228 | + EEH_Event_Query::add_query_filters(); |
|
229 | + // set params that will get used by the filters |
|
230 | + EEH_Event_Query::set_query_params( |
|
231 | + '', // month |
|
232 | + '', // category |
|
233 | + $config->display_expired_events, // show_expired |
|
234 | + 'start_date', // orderby |
|
235 | + 'ASC' // sort |
|
236 | + ); |
|
237 | + // check what template is loaded |
|
238 | + add_filter('template_include', array($this, 'template_include'), 999, 1); |
|
239 | + } |
|
240 | + |
|
241 | + |
|
242 | + /** |
|
243 | + * most likely called by the ESPRESSO_EVENTS shortcode which uses this module to do some of it's lifting |
|
244 | + * |
|
245 | + * @return void |
|
246 | + */ |
|
247 | + public function event_list() |
|
248 | + { |
|
249 | + // ensure valid EE_Events_Archive_Config() object exists |
|
250 | + $this->set_config(); |
|
251 | + // load other required components |
|
252 | + $this->load_event_list_assets(); |
|
253 | + } |
|
254 | + |
|
255 | + |
|
256 | + /** |
|
257 | + * @access public |
|
258 | + * @return void |
|
259 | + * @throws EE_Error |
|
260 | + * @throws DomainException |
|
261 | + */ |
|
262 | + public function event_list_iframe() |
|
263 | + { |
|
264 | + EED_Events_Archive::$iframe = true; |
|
265 | + $event_list_iframe = new EventsArchiveIframe($this); |
|
266 | + $event_list_iframe->display(); |
|
267 | + } |
|
268 | + |
|
269 | + |
|
270 | + /** |
|
271 | + * @access public |
|
272 | + * @return string |
|
273 | + */ |
|
274 | + public static function is_iframe() |
|
275 | + { |
|
276 | + return EED_Events_Archive::$iframe; |
|
277 | + } |
|
278 | + |
|
279 | + |
|
280 | + /** |
|
281 | + * @access public |
|
282 | + * @return string |
|
283 | + */ |
|
284 | + public static function link_target() |
|
285 | + { |
|
286 | + return EED_Events_Archive::$iframe ? ' target="_blank"' : ''; |
|
287 | + } |
|
288 | + |
|
289 | + |
|
290 | + /** |
|
291 | + * template_include |
|
292 | + * |
|
293 | + * @access public |
|
294 | + * @param string $template |
|
295 | + * @return string |
|
296 | + */ |
|
297 | + public function template_include($template = '') |
|
298 | + { |
|
299 | + // don't add content filter for dedicated EE child themes or private posts |
|
300 | + if (! EEH_Template::is_espresso_theme()) { |
|
301 | + /** @type EE_Events_Archive_Config $config */ |
|
302 | + $config = $this->config(); |
|
303 | + // add status banner ? |
|
304 | + if ($config->display_status_banner) { |
|
305 | + add_filter('the_title', array('EED_Events_Archive', 'the_title'), 100, 2); |
|
306 | + } |
|
307 | + // if NOT a custom template |
|
308 | + if ( |
|
309 | + apply_filters('FHEE__EED_Event_Archive__template_include__allow_custom_selected_template', false) |
|
310 | + || EE_Registry::instance() |
|
311 | + ->load_core('Front_Controller') |
|
312 | + ->get_selected_template() !== 'archive-espresso_events.php' |
|
313 | + ) { |
|
314 | + // don't display entry meta because the existing theme will take care of that |
|
315 | + add_filter('FHEE__EED_Events_Archive__template_include__events_list_active', '__return_true'); |
|
316 | + // load functions.php file for the theme (loaded by WP if using child theme) |
|
317 | + EEH_Template::load_espresso_theme_functions(); |
|
318 | + // because we don't know if the theme is using the_excerpt() |
|
319 | + add_filter( |
|
320 | + 'the_excerpt', |
|
321 | + array('EED_Events_Archive', 'event_details'), |
|
322 | + EED_Events_Archive::EVENT_DETAILS_PRIORITY |
|
323 | + ); |
|
324 | + // or the_content |
|
325 | + add_filter( |
|
326 | + 'the_content', |
|
327 | + array('EED_Events_Archive', 'event_details'), |
|
328 | + EED_Events_Archive::EVENT_DETAILS_PRIORITY |
|
329 | + ); |
|
330 | + // and just in case they are running get_the_excerpt() which DESTROYS things |
|
331 | + add_filter('get_the_excerpt', array('EED_Events_Archive', 'get_the_excerpt'), 1, 1); |
|
332 | + // don't display entry meta because the existing theme will take care of that |
|
333 | + add_filter('FHEE__content_espresso_events_details_template__display_entry_meta', '__return_false'); |
|
334 | + } |
|
335 | + } |
|
336 | + return $template; |
|
337 | + } |
|
338 | + |
|
339 | + |
|
340 | + /** |
|
341 | + * get_the_excerpt - kinda hacky, but if a theme is using get_the_excerpt(), then we need to remove our filters |
|
342 | + * on the_content() |
|
343 | + * |
|
344 | + * @access public |
|
345 | + * @param string $excerpt |
|
346 | + * @return string |
|
347 | + */ |
|
348 | + public static function get_the_excerpt($excerpt = '') |
|
349 | + { |
|
350 | + if (post_password_required()) { |
|
351 | + return $excerpt; |
|
352 | + } |
|
353 | + if (apply_filters('FHEE__EED_Events_Archive__get_the_excerpt__theme_uses_get_the_excerpt', false)) { |
|
354 | + remove_filter( |
|
355 | + 'the_excerpt', |
|
356 | + array('EED_Events_Archive', 'event_details'), |
|
357 | + EED_Events_Archive::EVENT_DETAILS_PRIORITY |
|
358 | + ); |
|
359 | + remove_filter( |
|
360 | + 'the_content', |
|
361 | + array('EED_Events_Archive', 'event_details'), |
|
362 | + EED_Events_Archive::EVENT_DETAILS_PRIORITY |
|
363 | + ); |
|
364 | + $excerpt = EED_Events_Archive::event_details($excerpt); |
|
365 | + } else { |
|
366 | + EED_Events_Archive::$using_get_the_excerpt = true; |
|
367 | + add_filter('wp_trim_excerpt', array('EED_Events_Archive', 'end_get_the_excerpt'), 999, 1); |
|
368 | + } |
|
369 | + return $excerpt; |
|
370 | + } |
|
371 | + |
|
372 | + |
|
373 | + /** |
|
374 | + * end_get_the_excerpt |
|
375 | + * |
|
376 | + * @access public |
|
377 | + * @param string $text |
|
378 | + * @return string |
|
379 | + */ |
|
380 | + public static function end_get_the_excerpt($text = '') |
|
381 | + { |
|
382 | + EED_Events_Archive::$using_get_the_excerpt = false; |
|
383 | + return $text; |
|
384 | + } |
|
385 | + |
|
386 | + |
|
387 | + /** |
|
388 | + * the_title |
|
389 | + * |
|
390 | + * @access public |
|
391 | + * @param string $title |
|
392 | + * @param string $id |
|
393 | + * @return string |
|
394 | + */ |
|
395 | + public static function the_title($title = '', $id = '') |
|
396 | + { |
|
397 | + global $post; |
|
398 | + if ($post instanceof WP_Post) { |
|
399 | + return ((function_exists('wp_is_block_theme') && wp_is_block_theme()) || in_the_loop()) && $post->ID == $id |
|
400 | + ? espresso_event_status_banner($post->ID) . $title |
|
401 | + : $title; |
|
402 | + } |
|
403 | + return $title; |
|
404 | + } |
|
405 | + |
|
406 | + |
|
407 | + /** |
|
408 | + * event_details |
|
409 | + * |
|
410 | + * @access public |
|
411 | + * @param string $content |
|
412 | + * @return string |
|
413 | + */ |
|
414 | + public static function event_details($content) |
|
415 | + { |
|
416 | + global $post; |
|
417 | + static $current_post_ID = 0; |
|
418 | + if ( |
|
419 | + $current_post_ID !== $post->ID |
|
420 | + && $post->post_type === 'espresso_events' |
|
421 | + && ! EED_Events_Archive::$using_get_the_excerpt |
|
422 | + && ! post_password_required() |
|
423 | + && ( |
|
424 | + apply_filters('FHEE__EES_Espresso_Events__process_shortcode__true', false) |
|
425 | + || ! apply_filters('FHEE__content_espresso_events__template_loaded', false) |
|
426 | + ) |
|
427 | + ) { |
|
428 | + // Set current post ID to prevent showing content twice, but only if headers have definitely been sent. |
|
429 | + // Reason being is that some plugins, like Yoast, need to run through a copy of the loop early |
|
430 | + // BEFORE headers are sent in order to examine the post content and generate content for the HTML header. |
|
431 | + // We want to allow those plugins to still do their thing and have access to our content, but depending on |
|
432 | + // how your event content is being displayed (shortcode, CPT route, etc), this filter can get applied twice, |
|
433 | + // so the following allows this filter to be applied multiple times, but only once for real |
|
434 | + $current_post_ID = did_action('loop_start') ? $post->ID : 0; |
|
435 | + if (EE_Registry::instance()->CFG->template_settings->EED_Events_Archive->use_sortable_display_order) { |
|
436 | + $content = EED_Events_Archive::use_sortable_display_order(); |
|
437 | + } else { |
|
438 | + $content = EED_Events_Archive::use_filterable_display_order(); |
|
439 | + } |
|
440 | + } |
|
441 | + return $content; |
|
442 | + } |
|
443 | + |
|
444 | + |
|
445 | + /** |
|
446 | + * use_sortable_display_order |
|
447 | + * |
|
448 | + * @access protected |
|
449 | + * @return string |
|
450 | + */ |
|
451 | + protected static function use_sortable_display_order() |
|
452 | + { |
|
453 | + // no further password checks required atm |
|
454 | + add_filter('FHEE__EED_Events_Archive__event_details__no_post_password_required', '__return_true'); |
|
455 | + // we need to first remove this callback from being applied to the_content() or the_excerpt() |
|
456 | + // (otherwise it will recurse and blow up the interweb) |
|
457 | + remove_filter( |
|
458 | + 'the_excerpt', |
|
459 | + array('EED_Events_Archive', 'event_details'), |
|
460 | + EED_Events_Archive::EVENT_DETAILS_PRIORITY |
|
461 | + ); |
|
462 | + remove_filter( |
|
463 | + 'the_content', |
|
464 | + array('EED_Events_Archive', 'event_details'), |
|
465 | + EED_Events_Archive::EVENT_DETAILS_PRIORITY |
|
466 | + ); |
|
467 | + remove_filter('get_the_excerpt', array('EED_Events_Archive', 'get_the_excerpt'), 1); |
|
468 | + // now add additional content depending on whether event is using the_excerpt() or the_content() |
|
469 | + EED_Events_Archive::instance()->template_parts = EED_Events_Archive::instance()->initialize_template_parts(); |
|
470 | + $content = EEH_Template::locate_template('content-espresso_events-details.php'); |
|
471 | + $content = EED_Events_Archive::instance()->template_parts->apply_template_part_filters($content); |
|
472 | + // re-add our main filters (or else the next event won't have them) |
|
473 | + add_filter( |
|
474 | + 'the_excerpt', |
|
475 | + array('EED_Events_Archive', 'event_details'), |
|
476 | + EED_Events_Archive::EVENT_DETAILS_PRIORITY |
|
477 | + ); |
|
478 | + add_filter( |
|
479 | + 'the_content', |
|
480 | + array('EED_Events_Archive', 'event_details'), |
|
481 | + EED_Events_Archive::EVENT_DETAILS_PRIORITY |
|
482 | + ); |
|
483 | + add_filter('get_the_excerpt', array('EED_Events_Archive', 'get_the_excerpt'), 1, 1); |
|
484 | + remove_filter( |
|
485 | + 'FHEE__EED_Events_Archive__event_details__no_post_password_required', |
|
486 | + '__return_true' |
|
487 | + ); |
|
488 | + return $content; |
|
489 | + } |
|
490 | + |
|
491 | + |
|
492 | + /** |
|
493 | + * use_filterable_display_order |
|
494 | + * |
|
495 | + * @access protected |
|
496 | + * @return string |
|
497 | + */ |
|
498 | + protected static function use_filterable_display_order() |
|
499 | + { |
|
500 | + // we need to first remove this callback from being applied to the_content() |
|
501 | + // (otherwise it will recurse and blow up the interweb) |
|
502 | + remove_filter( |
|
503 | + 'the_excerpt', |
|
504 | + array('EED_Events_Archive', 'event_details'), |
|
505 | + EED_Events_Archive::EVENT_DETAILS_PRIORITY |
|
506 | + ); |
|
507 | + remove_filter( |
|
508 | + 'the_content', |
|
509 | + array('EED_Events_Archive', 'event_details'), |
|
510 | + EED_Events_Archive::EVENT_DETAILS_PRIORITY |
|
511 | + ); |
|
512 | + remove_filter('get_the_excerpt', array('EED_Events_Archive', 'get_the_excerpt'), 1); |
|
513 | + // now add additional content depending on whether event is using the_excerpt() or the_content() |
|
514 | + EED_Events_Archive::_add_additional_excerpt_filters(); |
|
515 | + EED_Events_Archive::_add_additional_content_filters(); |
|
516 | + do_action('AHEE__EED_Events_Archive__use_filterable_display_order__after_add_filters'); |
|
517 | + // now load our template |
|
518 | + $content = EEH_Template::locate_template('content-espresso_events-details.php'); |
|
519 | + // re-add our main filters (or else the next event won't have them) |
|
520 | + add_filter( |
|
521 | + 'the_excerpt', |
|
522 | + array('EED_Events_Archive', 'event_details'), |
|
523 | + EED_Events_Archive::EVENT_DETAILS_PRIORITY |
|
524 | + ); |
|
525 | + add_filter( |
|
526 | + 'the_content', |
|
527 | + array('EED_Events_Archive', 'event_details'), |
|
528 | + EED_Events_Archive::EVENT_DETAILS_PRIORITY |
|
529 | + ); |
|
530 | + add_filter('get_the_excerpt', array('EED_Events_Archive', 'get_the_excerpt'), 1, 1); |
|
531 | + // but remove the other filters so that they don't get applied to the next post |
|
532 | + EED_Events_Archive::_remove_additional_events_archive_filters(); |
|
533 | + do_action('AHEE__EED_Events_Archive__use_filterable_display_order__after_remove_filters'); |
|
534 | + // we're not returning the $content directly because the template we are loading uses the_content (or the_excerpt) |
|
535 | + // return ! empty( $template ) ? $template : $content; |
|
536 | + return $content; |
|
537 | + } |
|
538 | + |
|
539 | + |
|
540 | + /** |
|
541 | + * event_datetimes - adds datetimes ABOVE content |
|
542 | + * |
|
543 | + * @access public |
|
544 | + * @param string $content |
|
545 | + * @return string |
|
546 | + */ |
|
547 | + public static function event_datetimes($content) |
|
548 | + { |
|
549 | + if (post_password_required()) { |
|
550 | + return $content; |
|
551 | + } |
|
552 | + return EEH_Template::locate_template('content-espresso_events-datetimes.php') . $content; |
|
553 | + } |
|
554 | + |
|
555 | + |
|
556 | + /** |
|
557 | + * event_tickets - adds tickets ABOVE content (which includes datetimes) |
|
558 | + * |
|
559 | + * @access public |
|
560 | + * @param string $content |
|
561 | + * @return string |
|
562 | + */ |
|
563 | + public static function event_tickets($content) |
|
564 | + { |
|
565 | + if (post_password_required()) { |
|
566 | + return $content; |
|
567 | + } |
|
568 | + return EEH_Template::locate_template('content-espresso_events-tickets.php') . $content; |
|
569 | + } |
|
570 | + |
|
571 | + |
|
572 | + /** |
|
573 | + * event_venues - adds venues BELOW content |
|
574 | + * |
|
575 | + * @access public |
|
576 | + * @param string $content |
|
577 | + * @return string |
|
578 | + */ |
|
579 | + public static function event_venue($content) |
|
580 | + { |
|
581 | + return EED_Events_Archive::event_venues($content); |
|
582 | + } |
|
583 | + |
|
584 | + |
|
585 | + /** |
|
586 | + * event_venues - adds venues BELOW content |
|
587 | + * |
|
588 | + * @access public |
|
589 | + * @param string $content |
|
590 | + * @return string |
|
591 | + */ |
|
592 | + public static function event_venues($content) |
|
593 | + { |
|
594 | + if (post_password_required()) { |
|
595 | + return $content; |
|
596 | + } |
|
597 | + return $content . EEH_Template::locate_template('content-espresso_events-venues.php'); |
|
598 | + } |
|
599 | + |
|
600 | + |
|
601 | + /** |
|
602 | + * _add_additional_content_filters |
|
603 | + * |
|
604 | + * @access private |
|
605 | + * @return void |
|
606 | + */ |
|
607 | + private static function _add_additional_excerpt_filters() |
|
608 | + { |
|
609 | + add_filter( |
|
610 | + 'the_excerpt', |
|
611 | + array('EED_Events_Archive', 'event_datetimes'), |
|
612 | + EED_Events_Archive::EVENT_DATETIMES_PRIORITY |
|
613 | + ); |
|
614 | + add_filter( |
|
615 | + 'the_excerpt', |
|
616 | + array('EED_Events_Archive', 'event_tickets'), |
|
617 | + EED_Events_Archive::EVENT_TICKETS_PRIORITY |
|
618 | + ); |
|
619 | + add_filter( |
|
620 | + 'the_excerpt', |
|
621 | + array('EED_Events_Archive', 'event_venues'), |
|
622 | + EED_Events_Archive::EVENT_VENUES_PRIORITY |
|
623 | + ); |
|
624 | + } |
|
625 | + |
|
626 | + |
|
627 | + /** |
|
628 | + * _add_additional_content_filters |
|
629 | + * |
|
630 | + * @access private |
|
631 | + * @return void |
|
632 | + */ |
|
633 | + private static function _add_additional_content_filters() |
|
634 | + { |
|
635 | + add_filter( |
|
636 | + 'the_content', |
|
637 | + array('EED_Events_Archive', 'event_datetimes'), |
|
638 | + EED_Events_Archive::EVENT_DATETIMES_PRIORITY |
|
639 | + ); |
|
640 | + add_filter( |
|
641 | + 'the_content', |
|
642 | + array('EED_Events_Archive', 'event_tickets'), |
|
643 | + EED_Events_Archive::EVENT_TICKETS_PRIORITY |
|
644 | + ); |
|
645 | + add_filter( |
|
646 | + 'the_content', |
|
647 | + array('EED_Events_Archive', 'event_venues'), |
|
648 | + EED_Events_Archive::EVENT_VENUES_PRIORITY |
|
649 | + ); |
|
650 | + } |
|
651 | + |
|
652 | + |
|
653 | + /** |
|
654 | + * _remove_additional_events_archive_filters |
|
655 | + * |
|
656 | + * @access private |
|
657 | + * @return void |
|
658 | + */ |
|
659 | + private static function _remove_additional_events_archive_filters() |
|
660 | + { |
|
661 | + remove_filter( |
|
662 | + 'the_excerpt', |
|
663 | + array('EED_Events_Archive', 'event_datetimes'), |
|
664 | + EED_Events_Archive::EVENT_DATETIMES_PRIORITY |
|
665 | + ); |
|
666 | + remove_filter( |
|
667 | + 'the_excerpt', |
|
668 | + array('EED_Events_Archive', 'event_tickets'), |
|
669 | + EED_Events_Archive::EVENT_TICKETS_PRIORITY |
|
670 | + ); |
|
671 | + remove_filter( |
|
672 | + 'the_excerpt', |
|
673 | + array('EED_Events_Archive', 'event_venues'), |
|
674 | + EED_Events_Archive::EVENT_VENUES_PRIORITY |
|
675 | + ); |
|
676 | + remove_filter( |
|
677 | + 'the_content', |
|
678 | + array('EED_Events_Archive', 'event_datetimes'), |
|
679 | + EED_Events_Archive::EVENT_DATETIMES_PRIORITY |
|
680 | + ); |
|
681 | + remove_filter( |
|
682 | + 'the_content', |
|
683 | + array('EED_Events_Archive', 'event_tickets'), |
|
684 | + EED_Events_Archive::EVENT_TICKETS_PRIORITY |
|
685 | + ); |
|
686 | + remove_filter( |
|
687 | + 'the_content', |
|
688 | + array('EED_Events_Archive', 'event_venues'), |
|
689 | + EED_Events_Archive::EVENT_VENUES_PRIORITY |
|
690 | + ); |
|
691 | + } |
|
692 | + |
|
693 | + |
|
694 | + /** |
|
695 | + * remove_all_events_archive_filters |
|
696 | + * |
|
697 | + * @access public |
|
698 | + * @return void |
|
699 | + */ |
|
700 | + public static function remove_all_events_archive_filters() |
|
701 | + { |
|
702 | + // remove_filter( 'get_the_excerpt', array( 'EED_Events_Archive', 'get_the_excerpt' ), 1 ); |
|
703 | + remove_filter('the_title', array('EED_Events_Archive', 'the_title'), 1); |
|
704 | + remove_filter( |
|
705 | + 'the_excerpt', |
|
706 | + array('EED_Events_Archive', 'event_details'), |
|
707 | + EED_Events_Archive::EVENT_DETAILS_PRIORITY |
|
708 | + ); |
|
709 | + remove_filter( |
|
710 | + 'the_excerpt', |
|
711 | + array('EED_Events_Archive', 'event_datetimes'), |
|
712 | + EED_Events_Archive::EVENT_DATETIMES_PRIORITY |
|
713 | + ); |
|
714 | + remove_filter( |
|
715 | + 'the_excerpt', |
|
716 | + array('EED_Events_Archive', 'event_tickets'), |
|
717 | + EED_Events_Archive::EVENT_TICKETS_PRIORITY |
|
718 | + ); |
|
719 | + remove_filter( |
|
720 | + 'the_excerpt', |
|
721 | + array('EED_Events_Archive', 'event_venues'), |
|
722 | + EED_Events_Archive::EVENT_VENUES_PRIORITY |
|
723 | + ); |
|
724 | + remove_filter( |
|
725 | + 'the_content', |
|
726 | + array('EED_Events_Archive', 'event_details'), |
|
727 | + EED_Events_Archive::EVENT_DETAILS_PRIORITY |
|
728 | + ); |
|
729 | + remove_filter( |
|
730 | + 'the_content', |
|
731 | + array('EED_Events_Archive', 'event_datetimes'), |
|
732 | + EED_Events_Archive::EVENT_DATETIMES_PRIORITY |
|
733 | + ); |
|
734 | + remove_filter( |
|
735 | + 'the_content', |
|
736 | + array('EED_Events_Archive', 'event_tickets'), |
|
737 | + EED_Events_Archive::EVENT_TICKETS_PRIORITY |
|
738 | + ); |
|
739 | + remove_filter( |
|
740 | + 'the_content', |
|
741 | + array('EED_Events_Archive', 'event_venues'), |
|
742 | + EED_Events_Archive::EVENT_VENUES_PRIORITY |
|
743 | + ); |
|
744 | + // don't display entry meta because the existing theme will take care of that |
|
745 | + remove_filter( |
|
746 | + 'FHEE__content_espresso_events_details_template__display_entry_meta', |
|
747 | + '__return_false' |
|
748 | + ); |
|
749 | + } |
|
750 | + |
|
751 | + |
|
752 | + /** |
|
753 | + * load_event_list_assets |
|
754 | + * |
|
755 | + * @access public |
|
756 | + * @return void |
|
757 | + */ |
|
758 | + public function load_event_list_assets() |
|
759 | + { |
|
760 | + do_action('AHEE__EED_Events_Archive__before_load_assets'); |
|
761 | + add_filter('FHEE_load_EE_Session', '__return_true'); |
|
762 | + add_filter('FHEE__EED_Ticket_Selector__load_tckt_slctr_assets', '__return_true'); |
|
763 | + add_action('wp_enqueue_scripts', array($this, 'wp_enqueue_scripts'), 10); |
|
764 | + if (EE_Registry::instance()->CFG->map_settings->use_google_maps) { |
|
765 | + add_action('wp_enqueue_scripts', array('EEH_Maps', 'espresso_google_map_js'), 11); |
|
766 | + } |
|
767 | + } |
|
768 | + |
|
769 | + |
|
770 | + /** |
|
771 | + * wp_enqueue_scripts |
|
772 | + * |
|
773 | + * @access public |
|
774 | + * @return void |
|
775 | + * @throws EE_Error |
|
776 | + */ |
|
777 | + public function wp_enqueue_scripts() |
|
778 | + { |
|
779 | + // get some style |
|
780 | + if (apply_filters('FHEE_enable_default_espresso_css', false)) { |
|
781 | + // first check uploads folder |
|
782 | + if (EEH_File::is_readable(get_stylesheet_directory() . $this->theme . '/style.css')) { |
|
783 | + wp_register_style( |
|
784 | + $this->theme, |
|
785 | + get_stylesheet_directory_uri() . $this->theme . '/style.css', |
|
786 | + array('dashicons', 'espresso_default') |
|
787 | + ); |
|
788 | + } else { |
|
789 | + } |
|
790 | + wp_enqueue_style($this->theme); |
|
791 | + } |
|
792 | + } |
|
793 | + |
|
794 | + |
|
795 | + /** |
|
796 | + * template_settings_form |
|
797 | + * |
|
798 | + * @access public |
|
799 | + * @static |
|
800 | + * @return string |
|
801 | + */ |
|
802 | + public static function template_settings_form() |
|
803 | + { |
|
804 | + $template_settings = EE_Registry::instance()->CFG->template_settings; |
|
805 | + $template_settings->EED_Events_Archive = isset($template_settings->EED_Events_Archive) |
|
806 | + ? $template_settings->EED_Events_Archive : new EE_Events_Archive_Config(); |
|
807 | + $template_settings->EED_Events_Archive = apply_filters( |
|
808 | + 'FHEE__EED_Events_Archive__template_settings_form__event_list_config', |
|
809 | + $template_settings->EED_Events_Archive |
|
810 | + ); |
|
811 | + $events_archive_settings = array( |
|
812 | + 'display_status_banner' => 0, |
|
813 | + 'display_description' => 1, |
|
814 | + 'display_ticket_selector' => 0, |
|
815 | + 'display_datetimes' => 1, |
|
816 | + 'display_venue' => 0, |
|
817 | + 'display_expired_events' => 0, |
|
818 | + ); |
|
819 | + $events_archive_settings = array_merge( |
|
820 | + $events_archive_settings, |
|
821 | + (array) $template_settings->EED_Events_Archive |
|
822 | + ); |
|
823 | + EEH_Template::display_template( |
|
824 | + EVENTS_ARCHIVE_TEMPLATES_PATH . 'admin-event-list-settings.template.php', |
|
825 | + $events_archive_settings |
|
826 | + ); |
|
827 | + } |
|
828 | + |
|
829 | + |
|
830 | + /** |
|
831 | + * update_template_settings |
|
832 | + * |
|
833 | + * @access public |
|
834 | + * @param EE_Template_Config $CFG |
|
835 | + * @param array $REQ |
|
836 | + * @return EE_Template_Config |
|
837 | + */ |
|
838 | + public static function update_template_settings($CFG, $REQ) |
|
839 | + { |
|
840 | + $CFG->EED_Events_Archive = new EE_Events_Archive_Config(); |
|
841 | + // unless we are resetting the config... |
|
842 | + if ( |
|
843 | + ! isset($REQ['EED_Events_Archive_reset_event_list_settings']) |
|
844 | + || absint($REQ['EED_Events_Archive_reset_event_list_settings']) !== 1 |
|
845 | + ) { |
|
846 | + $CFG->EED_Events_Archive->display_status_banner = isset($REQ['EED_Events_Archive_display_status_banner']) |
|
847 | + ? absint($REQ['EED_Events_Archive_display_status_banner']) : 0; |
|
848 | + $CFG->EED_Events_Archive->display_description = isset($REQ['EED_Events_Archive_display_description']) |
|
849 | + ? absint($REQ['EED_Events_Archive_display_description']) : 1; |
|
850 | + $CFG->EED_Events_Archive->display_ticket_selector = isset($REQ['EED_Events_Archive_display_ticket_selector']) |
|
851 | + ? absint($REQ['EED_Events_Archive_display_ticket_selector']) : 0; |
|
852 | + $CFG->EED_Events_Archive->display_datetimes = isset($REQ['EED_Events_Archive_display_datetimes']) ? absint( |
|
853 | + $REQ['EED_Events_Archive_display_datetimes'] |
|
854 | + ) : 1; |
|
855 | + $CFG->EED_Events_Archive->display_venue = isset($REQ['EED_Events_Archive_display_venue']) ? absint( |
|
856 | + $REQ['EED_Events_Archive_display_venue'] |
|
857 | + ) : 0; |
|
858 | + $CFG->EED_Events_Archive->display_expired_events = isset($REQ['EED_Events_Archive_display_expired_events']) |
|
859 | + ? absint($REQ['EED_Events_Archive_display_expired_events']) : 0; |
|
860 | + } |
|
861 | + return $CFG; |
|
862 | + } |
|
863 | + |
|
864 | + |
|
865 | + /** |
|
866 | + * event_list_css |
|
867 | + * |
|
868 | + * @access public |
|
869 | + * @param string $extra_class |
|
870 | + * @return string |
|
871 | + */ |
|
872 | + public static function event_list_css($extra_class = '') |
|
873 | + { |
|
874 | + $event_list_css = ! empty($extra_class) ? array($extra_class) : array(); |
|
875 | + $event_list_css[] = 'espresso-event-list-event'; |
|
876 | + return implode(' ', $event_list_css); |
|
877 | + } |
|
878 | + |
|
879 | + |
|
880 | + /** |
|
881 | + * event_categories |
|
882 | + * |
|
883 | + * @access public |
|
884 | + * @return array |
|
885 | + */ |
|
886 | + public static function event_categories() |
|
887 | + { |
|
888 | + return EE_Registry::instance()->load_model('Term')->get_all_ee_categories(); |
|
889 | + } |
|
890 | + |
|
891 | + |
|
892 | + /** |
|
893 | + * display_description |
|
894 | + * |
|
895 | + * @access public |
|
896 | + * @param $value |
|
897 | + * @return bool |
|
898 | + */ |
|
899 | + public static function display_description($value) |
|
900 | + { |
|
901 | + $config = EE_Registry::instance()->CFG->template_settings->EED_Events_Archive; |
|
902 | + $display_description = isset($config->display_description) ? $config->display_description : 1; |
|
903 | + return $display_description === $value ? true : false; |
|
904 | + } |
|
905 | + |
|
906 | + |
|
907 | + /** |
|
908 | + * display_ticket_selector |
|
909 | + * |
|
910 | + * @access public |
|
911 | + * @return bool |
|
912 | + */ |
|
913 | + public static function display_ticket_selector() |
|
914 | + { |
|
915 | + $config = EE_Registry::instance()->CFG->template_settings->EED_Events_Archive; |
|
916 | + return isset($config->display_ticket_selector) && $config->display_ticket_selector ? true : false; |
|
917 | + } |
|
918 | + |
|
919 | + |
|
920 | + /** |
|
921 | + * display_venue |
|
922 | + * |
|
923 | + * @access public |
|
924 | + * @return bool |
|
925 | + */ |
|
926 | + public static function display_venue() |
|
927 | + { |
|
928 | + $config = EE_Registry::instance()->CFG->template_settings->EED_Events_Archive; |
|
929 | + return isset($config->display_venue) && $config->display_venue && EEH_Venue_View::venue_name() ? true : false; |
|
930 | + } |
|
931 | + |
|
932 | + |
|
933 | + /** |
|
934 | + * display_datetimes |
|
935 | + * |
|
936 | + * @access public |
|
937 | + * @return bool |
|
938 | + */ |
|
939 | + public static function display_datetimes() |
|
940 | + { |
|
941 | + $config = EE_Registry::instance()->CFG->template_settings->EED_Events_Archive; |
|
942 | + return isset($config->display_datetimes) && $config->display_datetimes ? true : false; |
|
943 | + } |
|
944 | + |
|
945 | + |
|
946 | + /** |
|
947 | + * event_list_title |
|
948 | + * |
|
949 | + * @access public |
|
950 | + * @return string |
|
951 | + */ |
|
952 | + public static function event_list_title() |
|
953 | + { |
|
954 | + return apply_filters( |
|
955 | + 'FHEE__archive_espresso_events_template__upcoming_events_h1', |
|
956 | + esc_html__('Upcoming Events', 'event_espresso') |
|
957 | + ); |
|
958 | + } |
|
959 | + |
|
960 | + |
|
961 | + // GRAVEYARD |
|
962 | + |
|
963 | + |
|
964 | + /** |
|
965 | + * @since 4.4.0 |
|
966 | + */ |
|
967 | + public static function _doing_it_wrong_notice($function = '') |
|
968 | + { |
|
969 | + EE_Error::doing_it_wrong( |
|
970 | + __FUNCTION__, |
|
971 | + sprintf( |
|
972 | + esc_html__( |
|
973 | + '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', |
|
974 | + 'event_espresso' |
|
975 | + ), |
|
976 | + $function, |
|
977 | + '<br />', |
|
978 | + '4.6.0' |
|
979 | + ), |
|
980 | + '4.4.0' |
|
981 | + ); |
|
982 | + } |
|
983 | + |
|
984 | + |
|
985 | + /** |
|
986 | + * @deprecated |
|
987 | + * @since 4.4.0 |
|
988 | + */ |
|
989 | + public function get_post_data() |
|
990 | + { |
|
991 | + EEH_Event_Query::set_query_params(); |
|
992 | + } |
|
993 | + |
|
994 | + |
|
995 | + /** |
|
996 | + * @throws EE_Error |
|
997 | + * @since 4.4.0 |
|
998 | + * @deprecated |
|
999 | + */ |
|
1000 | + public function posts_fields($SQL, WP_Query $wp_query) |
|
1001 | + { |
|
1002 | + EED_Events_Archive::_doing_it_wrong_notice(__FUNCTION__); |
|
1003 | + return EEH_Event_Query::posts_fields($SQL, $wp_query); |
|
1004 | + } |
|
1005 | + |
|
1006 | + |
|
1007 | + /** |
|
1008 | + * @throws EE_Error |
|
1009 | + * @since 4.4.0 |
|
1010 | + * @deprecated |
|
1011 | + */ |
|
1012 | + public static function posts_fields_sql_for_orderby($orderby_params = array()) |
|
1013 | + { |
|
1014 | + EED_Events_Archive::_doing_it_wrong_notice(__FUNCTION__); |
|
1015 | + return EEH_Event_Query::posts_fields_sql_for_orderby($orderby_params); |
|
1016 | + } |
|
1017 | + |
|
1018 | + |
|
1019 | + /** |
|
1020 | + * @throws EE_Error |
|
1021 | + * @since 4.4.0 |
|
1022 | + * @deprecated |
|
1023 | + */ |
|
1024 | + public function posts_join($SQL, WP_Query $wp_query) |
|
1025 | + { |
|
1026 | + EED_Events_Archive::_doing_it_wrong_notice(__FUNCTION__); |
|
1027 | + return EEH_Event_Query::posts_join($SQL, $wp_query); |
|
1028 | + } |
|
1029 | + |
|
1030 | + |
|
1031 | + /** |
|
1032 | + * @deprecated |
|
1033 | + * @since 4.4.0 |
|
1034 | + */ |
|
1035 | + public static function posts_join_sql_for_terms($join_terms = null) |
|
1036 | + { |
|
1037 | + EED_Events_Archive::_doing_it_wrong_notice(__FUNCTION__); |
|
1038 | + return EEH_Event_Query::posts_join_sql_for_terms($join_terms); |
|
1039 | + } |
|
1040 | + |
|
1041 | + |
|
1042 | + /** |
|
1043 | + * @throws EE_Error |
|
1044 | + * @since 4.4.0 |
|
1045 | + * @deprecated |
|
1046 | + */ |
|
1047 | + public static function posts_join_for_orderby($orderby_params = array()) |
|
1048 | + { |
|
1049 | + EED_Events_Archive::_doing_it_wrong_notice(__FUNCTION__); |
|
1050 | + return EEH_Event_Query::posts_join_for_orderby($orderby_params); |
|
1051 | + } |
|
1052 | + |
|
1053 | + |
|
1054 | + /** |
|
1055 | + * @throws EE_Error |
|
1056 | + * @since 4.4.0 |
|
1057 | + * @deprecated |
|
1058 | + */ |
|
1059 | + public function posts_where($SQL, WP_Query $wp_query) |
|
1060 | + { |
|
1061 | + EED_Events_Archive::_doing_it_wrong_notice(__FUNCTION__); |
|
1062 | + return EEH_Event_Query::posts_where($SQL, $wp_query); |
|
1063 | + } |
|
1064 | + |
|
1065 | + |
|
1066 | + /** |
|
1067 | + * @throws EE_Error |
|
1068 | + * @since 4.4.0 |
|
1069 | + * @deprecated |
|
1070 | + */ |
|
1071 | + public static function posts_where_sql_for_show_expired($show_expired = false) |
|
1072 | + { |
|
1073 | + EED_Events_Archive::_doing_it_wrong_notice(__FUNCTION__); |
|
1074 | + return EEH_Event_Query::posts_where_sql_for_show_expired($show_expired); |
|
1075 | + } |
|
1076 | + |
|
1077 | + |
|
1078 | + /** |
|
1079 | + * @deprecated |
|
1080 | + * @since 4.4.0 |
|
1081 | + */ |
|
1082 | + public static function posts_where_sql_for_event_category_slug($event_category_slug = null) |
|
1083 | + { |
|
1084 | + EED_Events_Archive::_doing_it_wrong_notice(__FUNCTION__); |
|
1085 | + return EEH_Event_Query::posts_where_sql_for_event_category_slug($event_category_slug); |
|
1086 | + } |
|
1087 | + |
|
1088 | + |
|
1089 | + /** |
|
1090 | + * @throws EE_Error |
|
1091 | + * @since 4.4.0 |
|
1092 | + * @deprecated |
|
1093 | + */ |
|
1094 | + public static function posts_where_sql_for_event_list_month($month = null) |
|
1095 | + { |
|
1096 | + EED_Events_Archive::_doing_it_wrong_notice(__FUNCTION__); |
|
1097 | + return EEH_Event_Query::posts_where_sql_for_event_list_month($month); |
|
1098 | + } |
|
1099 | + |
|
1100 | + |
|
1101 | + /** |
|
1102 | + * @throws EE_Error |
|
1103 | + * @since 4.4.0 |
|
1104 | + * @deprecated |
|
1105 | + */ |
|
1106 | + public function posts_orderby($SQL, WP_Query $wp_query) |
|
1107 | + { |
|
1108 | + EED_Events_Archive::_doing_it_wrong_notice(__FUNCTION__); |
|
1109 | + return EEH_Event_Query::posts_orderby($SQL, $wp_query); |
|
1110 | + } |
|
1111 | + |
|
1112 | + |
|
1113 | + /** |
|
1114 | + * @throws EE_Error |
|
1115 | + * @since 4.4.0 |
|
1116 | + * @deprecated |
|
1117 | + */ |
|
1118 | + public static function posts_orderby_sql($orderby_params = array(), $sort = 'ASC') |
|
1119 | + { |
|
1120 | + EED_Events_Archive::_doing_it_wrong_notice(__FUNCTION__); |
|
1121 | + return EEH_Event_Query::posts_orderby_sql($orderby_params, $sort); |
|
1122 | + } |
|
1123 | 1123 | } |
1124 | 1124 | |
1125 | 1125 | |
@@ -1128,9 +1128,9 @@ discard block |
||
1128 | 1128 | */ |
1129 | 1129 | function espresso_get_event_list_ID() |
1130 | 1130 | { |
1131 | - EED_Events_Archive::$espresso_event_list_ID++; |
|
1132 | - EED_Events_Archive::$espresso_grid_event_lists[] = EED_Events_Archive::$espresso_event_list_ID; |
|
1133 | - return EED_Events_Archive::$espresso_event_list_ID; |
|
1131 | + EED_Events_Archive::$espresso_event_list_ID++; |
|
1132 | + EED_Events_Archive::$espresso_grid_event_lists[] = EED_Events_Archive::$espresso_event_list_ID; |
|
1133 | + return EED_Events_Archive::$espresso_event_list_ID; |
|
1134 | 1134 | } |
1135 | 1135 | |
1136 | 1136 | /** |
@@ -1138,7 +1138,7 @@ discard block |
||
1138 | 1138 | */ |
1139 | 1139 | function espresso_event_list_title() |
1140 | 1140 | { |
1141 | - return EED_Events_Archive::event_list_title(); |
|
1141 | + return EED_Events_Archive::event_list_title(); |
|
1142 | 1142 | } |
1143 | 1143 | |
1144 | 1144 | /** |
@@ -1147,7 +1147,7 @@ discard block |
||
1147 | 1147 | */ |
1148 | 1148 | function espresso_event_list_css($extra_class = '') |
1149 | 1149 | { |
1150 | - return EED_Events_Archive::event_list_css($extra_class); |
|
1150 | + return EED_Events_Archive::event_list_css($extra_class); |
|
1151 | 1151 | } |
1152 | 1152 | |
1153 | 1153 | /** |
@@ -1155,7 +1155,7 @@ discard block |
||
1155 | 1155 | */ |
1156 | 1156 | function espresso_get_event_categories() |
1157 | 1157 | { |
1158 | - return EED_Events_Archive::event_categories(); |
|
1158 | + return EED_Events_Archive::event_categories(); |
|
1159 | 1159 | } |
1160 | 1160 | |
1161 | 1161 | /** |
@@ -1163,7 +1163,7 @@ discard block |
||
1163 | 1163 | */ |
1164 | 1164 | function espresso_display_full_description_in_event_list() |
1165 | 1165 | { |
1166 | - return EED_Events_Archive::display_description(2); |
|
1166 | + return EED_Events_Archive::display_description(2); |
|
1167 | 1167 | } |
1168 | 1168 | |
1169 | 1169 | /** |
@@ -1171,7 +1171,7 @@ discard block |
||
1171 | 1171 | */ |
1172 | 1172 | function espresso_display_excerpt_in_event_list() |
1173 | 1173 | { |
1174 | - return EED_Events_Archive::display_description(1); |
|
1174 | + return EED_Events_Archive::display_description(1); |
|
1175 | 1175 | } |
1176 | 1176 | |
1177 | 1177 | /** |
@@ -1179,7 +1179,7 @@ discard block |
||
1179 | 1179 | */ |
1180 | 1180 | function espresso_display_ticket_selector_in_event_list() |
1181 | 1181 | { |
1182 | - return EED_Events_Archive::display_ticket_selector(); |
|
1182 | + return EED_Events_Archive::display_ticket_selector(); |
|
1183 | 1183 | } |
1184 | 1184 | |
1185 | 1185 | /** |
@@ -1187,7 +1187,7 @@ discard block |
||
1187 | 1187 | */ |
1188 | 1188 | function espresso_display_venue_in_event_list() |
1189 | 1189 | { |
1190 | - return EED_Events_Archive::display_venue(); |
|
1190 | + return EED_Events_Archive::display_venue(); |
|
1191 | 1191 | } |
1192 | 1192 | |
1193 | 1193 | /** |
@@ -1195,5 +1195,5 @@ discard block |
||
1195 | 1195 | */ |
1196 | 1196 | function espresso_display_datetimes_in_event_list() |
1197 | 1197 | { |
1198 | - return EED_Events_Archive::display_datetimes(); |
|
1198 | + return EED_Events_Archive::display_datetimes(); |
|
1199 | 1199 | } |
@@ -23,1729 +23,1729 @@ |
||
23 | 23 | class EE_Registry implements ResettableInterface |
24 | 24 | { |
25 | 25 | |
26 | - /** |
|
27 | - * @var EE_Registry $_instance |
|
28 | - */ |
|
29 | - private static $_instance; |
|
30 | - |
|
31 | - /** |
|
32 | - * @var EE_Dependency_Map $_dependency_map |
|
33 | - */ |
|
34 | - protected $_dependency_map; |
|
35 | - |
|
36 | - /** |
|
37 | - * @var Mirror |
|
38 | - */ |
|
39 | - private $mirror; |
|
40 | - |
|
41 | - /** |
|
42 | - * @var ClassInterfaceCache $class_cache |
|
43 | - */ |
|
44 | - private $class_cache; |
|
45 | - |
|
46 | - /** |
|
47 | - * @var array $_class_abbreviations |
|
48 | - */ |
|
49 | - protected $_class_abbreviations = array(); |
|
50 | - |
|
51 | - /** |
|
52 | - * @var CommandBusInterface $BUS |
|
53 | - */ |
|
54 | - public $BUS; |
|
55 | - |
|
56 | - /** |
|
57 | - * @var EE_Cart $CART |
|
58 | - */ |
|
59 | - public $CART; |
|
60 | - |
|
61 | - /** |
|
62 | - * @var EE_Config $CFG |
|
63 | - */ |
|
64 | - public $CFG; |
|
65 | - |
|
66 | - /** |
|
67 | - * @var EE_Network_Config $NET_CFG |
|
68 | - */ |
|
69 | - public $NET_CFG; |
|
70 | - |
|
71 | - /** |
|
72 | - * RegistryContainer for storing library classes in |
|
73 | - * |
|
74 | - * @var RegistryContainer $LIB |
|
75 | - */ |
|
76 | - public $LIB; |
|
77 | - |
|
78 | - /** |
|
79 | - * @var EE_Request_Handler $REQ |
|
80 | - * @deprecated 4.10.14.p |
|
81 | - */ |
|
82 | - public $REQ; |
|
83 | - |
|
84 | - /** |
|
85 | - * @var EE_Session $SSN |
|
86 | - */ |
|
87 | - public $SSN; |
|
88 | - |
|
89 | - /** |
|
90 | - * @since 4.5.0 |
|
91 | - * @var EE_Capabilities $CAP |
|
92 | - */ |
|
93 | - public $CAP; |
|
94 | - |
|
95 | - /** |
|
96 | - * @since 4.9.0 |
|
97 | - * @var EE_Message_Resource_Manager $MRM |
|
98 | - */ |
|
99 | - public $MRM; |
|
100 | - |
|
101 | - /** |
|
102 | - * @var Registry $AssetsRegistry |
|
103 | - */ |
|
104 | - public $AssetsRegistry; |
|
105 | - |
|
106 | - /** |
|
107 | - * RegistryContainer for holding addons which have registered themselves to work with EE core |
|
108 | - * |
|
109 | - * @var EE_Addon[] $addons |
|
110 | - */ |
|
111 | - public $addons; |
|
112 | - |
|
113 | - /** |
|
114 | - * keys are 'short names' (eg Event), values are class names (eg 'EEM_Event') |
|
115 | - * |
|
116 | - * @var EEM_Base[] $models |
|
117 | - */ |
|
118 | - public $models = array(); |
|
119 | - |
|
120 | - /** |
|
121 | - * @var EED_Module[] $modules |
|
122 | - */ |
|
123 | - public $modules; |
|
124 | - |
|
125 | - /** |
|
126 | - * @var EES_Shortcode[] $shortcodes |
|
127 | - */ |
|
128 | - public $shortcodes; |
|
129 | - |
|
130 | - /** |
|
131 | - * @var WP_Widget[] $widgets |
|
132 | - */ |
|
133 | - public $widgets; |
|
134 | - |
|
135 | - /** |
|
136 | - * this is an array of all implemented model names (i.e. not the parent abstract models, or models |
|
137 | - * which don't actually fetch items from the DB in the normal way (ie, are not children of EEM_Base)). |
|
138 | - * Keys are model "short names" (eg "Event") as used in model relations, and values are |
|
139 | - * classnames (eg "EEM_Event") |
|
140 | - * |
|
141 | - * @var array $non_abstract_db_models |
|
142 | - */ |
|
143 | - public $non_abstract_db_models = array(); |
|
144 | - |
|
145 | - /** |
|
146 | - * internationalization for JS strings |
|
147 | - * usage: EE_Registry::i18n_js_strings['string_key'] = esc_html__( 'string to translate.', 'event_espresso' ); |
|
148 | - * in js file: var translatedString = eei18n.string_key; |
|
149 | - * |
|
150 | - * @var array $i18n_js_strings |
|
151 | - */ |
|
152 | - public static $i18n_js_strings = array(); |
|
153 | - |
|
154 | - /** |
|
155 | - * $main_file - path to espresso.php |
|
156 | - * |
|
157 | - * @var array $main_file |
|
158 | - */ |
|
159 | - public $main_file; |
|
160 | - |
|
161 | - /** |
|
162 | - * array of ReflectionClass objects where the key is the class name |
|
163 | - * |
|
164 | - * @deprecated 4.9.62.p |
|
165 | - * @var ReflectionClass[] $_reflectors |
|
166 | - */ |
|
167 | - public $_reflectors; |
|
168 | - |
|
169 | - /** |
|
170 | - * boolean flag to indicate whether or not to load/save dependencies from/to the cache |
|
171 | - * |
|
172 | - * @var boolean $_cache_on |
|
173 | - */ |
|
174 | - protected $_cache_on = true; |
|
175 | - |
|
176 | - /** |
|
177 | - * @var ObjectIdentifier |
|
178 | - */ |
|
179 | - private $object_identifier; |
|
180 | - |
|
181 | - |
|
182 | - /** |
|
183 | - * @singleton method used to instantiate class object |
|
184 | - * @param EE_Dependency_Map|null $dependency_map |
|
185 | - * @param Mirror|null $mirror |
|
186 | - * @param ClassInterfaceCache|null $class_cache |
|
187 | - * @param ObjectIdentifier|null $object_identifier |
|
188 | - * @return EE_Registry instance |
|
189 | - */ |
|
190 | - public static function instance( |
|
191 | - EE_Dependency_Map $dependency_map = null, |
|
192 | - Mirror $mirror = null, |
|
193 | - ClassInterfaceCache $class_cache = null, |
|
194 | - ObjectIdentifier $object_identifier = null |
|
195 | - ) { |
|
196 | - // check if class object is instantiated |
|
197 | - if ( |
|
198 | - ! self::$_instance instanceof EE_Registry |
|
199 | - && $dependency_map instanceof EE_Dependency_Map |
|
200 | - && $mirror instanceof Mirror |
|
201 | - && $class_cache instanceof ClassInterfaceCache |
|
202 | - && $object_identifier instanceof ObjectIdentifier |
|
203 | - ) { |
|
204 | - self::$_instance = new self( |
|
205 | - $dependency_map, |
|
206 | - $mirror, |
|
207 | - $class_cache, |
|
208 | - $object_identifier |
|
209 | - ); |
|
210 | - } |
|
211 | - return self::$_instance; |
|
212 | - } |
|
213 | - |
|
214 | - |
|
215 | - /** |
|
216 | - * protected constructor to prevent direct creation |
|
217 | - * |
|
218 | - * @Constructor |
|
219 | - * @param EE_Dependency_Map $dependency_map |
|
220 | - * @param Mirror $mirror |
|
221 | - * @param ClassInterfaceCache $class_cache |
|
222 | - * @param ObjectIdentifier $object_identifier |
|
223 | - */ |
|
224 | - protected function __construct( |
|
225 | - EE_Dependency_Map $dependency_map, |
|
226 | - Mirror $mirror, |
|
227 | - ClassInterfaceCache $class_cache, |
|
228 | - ObjectIdentifier $object_identifier |
|
229 | - ) { |
|
230 | - $this->_dependency_map = $dependency_map; |
|
231 | - $this->mirror = $mirror; |
|
232 | - $this->class_cache = $class_cache; |
|
233 | - $this->object_identifier = $object_identifier; |
|
234 | - // $registry_container = new RegistryContainer(); |
|
235 | - $this->LIB = new RegistryContainer(); |
|
236 | - $this->addons = new RegistryContainer(); |
|
237 | - $this->modules = new RegistryContainer(); |
|
238 | - $this->shortcodes = new RegistryContainer(); |
|
239 | - $this->widgets = new RegistryContainer(); |
|
240 | - add_action('EE_Load_Espresso_Core__handle_request__initialize_core_loading', array($this, 'initialize')); |
|
241 | - } |
|
242 | - |
|
243 | - |
|
244 | - /** |
|
245 | - * initialize |
|
246 | - * |
|
247 | - * @throws OutOfBoundsException |
|
248 | - * @throws InvalidArgumentException |
|
249 | - * @throws InvalidInterfaceException |
|
250 | - * @throws InvalidDataTypeException |
|
251 | - * @throws EE_Error |
|
252 | - * @throws ReflectionException |
|
253 | - */ |
|
254 | - public function initialize() |
|
255 | - { |
|
256 | - $this->_class_abbreviations = apply_filters( |
|
257 | - 'FHEE__EE_Registry____construct___class_abbreviations', |
|
258 | - array( |
|
259 | - 'EE_Config' => 'CFG', |
|
260 | - 'EE_Session' => 'SSN', |
|
261 | - 'EE_Capabilities' => 'CAP', |
|
262 | - 'EE_Cart' => 'CART', |
|
263 | - 'EE_Network_Config' => 'NET_CFG', |
|
264 | - 'EE_Request_Handler' => 'REQ', |
|
265 | - 'EE_Message_Resource_Manager' => 'MRM', |
|
266 | - 'EventEspresso\core\services\commands\CommandBus' => 'BUS', |
|
267 | - 'EventEspresso\core\services\assets\Registry' => 'AssetsRegistry', |
|
268 | - ) |
|
269 | - ); |
|
270 | - $this->load_core('Base', array(), true); |
|
271 | - // add our request and response objects to the cache |
|
272 | - $request_loader = $this->_dependency_map->class_loader( |
|
273 | - 'EventEspresso\core\services\request\Request' |
|
274 | - ); |
|
275 | - $this->_set_cached_class( |
|
276 | - $request_loader(), |
|
277 | - 'EventEspresso\core\services\request\Request' |
|
278 | - ); |
|
279 | - $response_loader = $this->_dependency_map->class_loader( |
|
280 | - 'EventEspresso\core\services\request\Response' |
|
281 | - ); |
|
282 | - $this->_set_cached_class( |
|
283 | - $response_loader(), |
|
284 | - 'EventEspresso\core\services\request\Response' |
|
285 | - ); |
|
286 | - add_action('AHEE__EE_System__set_hooks_for_core', array($this, 'init')); |
|
287 | - } |
|
288 | - |
|
289 | - |
|
290 | - /** |
|
291 | - * @return void |
|
292 | - */ |
|
293 | - public function init() |
|
294 | - { |
|
295 | - // Get current page protocol |
|
296 | - $protocol = is_ssl() ? 'https://' : 'http://'; |
|
297 | - // Output admin-ajax.php URL with same protocol as current page |
|
298 | - self::$i18n_js_strings['ajax_url'] = admin_url('admin-ajax.php', $protocol); |
|
299 | - self::$i18n_js_strings['wp_debug'] = defined('WP_DEBUG') && WP_DEBUG; |
|
300 | - } |
|
301 | - |
|
302 | - |
|
303 | - /** |
|
304 | - * @return array |
|
305 | - */ |
|
306 | - public static function sanitize_i18n_js_strings() |
|
307 | - { |
|
308 | - $i18n_js_strings = (array) self::$i18n_js_strings; |
|
309 | - foreach ($i18n_js_strings as $key => $value) { |
|
310 | - if (is_scalar($value)) { |
|
311 | - $decoded_value = html_entity_decode((string) $value, ENT_QUOTES, 'UTF-8'); |
|
312 | - $i18n_js_strings[ $key ] = wp_strip_all_tags($decoded_value); |
|
313 | - } |
|
314 | - } |
|
315 | - return $i18n_js_strings; |
|
316 | - } |
|
317 | - |
|
318 | - |
|
319 | - /** |
|
320 | - * localize_i18n_js_strings |
|
321 | - * |
|
322 | - * @return string |
|
323 | - */ |
|
324 | - public static function localize_i18n_js_strings() |
|
325 | - { |
|
326 | - $i18n_js_strings = EE_Registry::sanitize_i18n_js_strings(); |
|
327 | - return '/* <![CDATA[ */ var eei18n = ' . wp_json_encode($i18n_js_strings) . '; /* ]]> */'; |
|
328 | - } |
|
329 | - |
|
330 | - |
|
331 | - /** |
|
332 | - * @param mixed string | EED_Module $module |
|
333 | - * @throws OutOfBoundsException |
|
334 | - * @throws InvalidArgumentException |
|
335 | - * @throws InvalidInterfaceException |
|
336 | - * @throws InvalidDataTypeException |
|
337 | - * @throws EE_Error |
|
338 | - * @throws ReflectionException |
|
339 | - */ |
|
340 | - public function add_module($module) |
|
341 | - { |
|
342 | - if ($module instanceof EED_Module) { |
|
343 | - $module_class = get_class($module); |
|
344 | - $this->modules->add($module_class, $module); |
|
345 | - } else { |
|
346 | - if (! class_exists('EE_Module_Request_Router', false)) { |
|
347 | - $this->load_core('Module_Request_Router'); |
|
348 | - } |
|
349 | - EE_Module_Request_Router::module_factory($module); |
|
350 | - } |
|
351 | - } |
|
352 | - |
|
353 | - |
|
354 | - /** |
|
355 | - * @param string $module_name |
|
356 | - * @return mixed EED_Module | NULL |
|
357 | - */ |
|
358 | - public function get_module($module_name = '') |
|
359 | - { |
|
360 | - return $this->modules->get($module_name); |
|
361 | - } |
|
362 | - |
|
363 | - |
|
364 | - /** |
|
365 | - * loads core classes - must be singletons |
|
366 | - * |
|
367 | - * @param string $class_name - simple class name ie: session |
|
368 | - * @param mixed $arguments |
|
369 | - * @param bool $load_only |
|
370 | - * @return mixed |
|
371 | - * @throws InvalidInterfaceException |
|
372 | - * @throws InvalidDataTypeException |
|
373 | - * @throws EE_Error |
|
374 | - * @throws ReflectionException |
|
375 | - * @throws InvalidArgumentException |
|
376 | - */ |
|
377 | - public function load_core($class_name, $arguments = array(), $load_only = false) |
|
378 | - { |
|
379 | - $core_paths = apply_filters( |
|
380 | - 'FHEE__EE_Registry__load_core__core_paths', |
|
381 | - array( |
|
382 | - EE_CORE, |
|
383 | - EE_ADMIN, |
|
384 | - EE_CPTS, |
|
385 | - EE_CORE . 'CPTs/', |
|
386 | - EE_CORE . 'data_migration_scripts/', |
|
387 | - EE_CORE . 'request_stack/', |
|
388 | - EE_CORE . 'middleware/', |
|
389 | - ) |
|
390 | - ); |
|
391 | - // retrieve instantiated class |
|
392 | - return $this->_load( |
|
393 | - $core_paths, |
|
394 | - 'EE_', |
|
395 | - $class_name, |
|
396 | - 'core', |
|
397 | - $arguments, |
|
398 | - false, |
|
399 | - true, |
|
400 | - $load_only |
|
401 | - ); |
|
402 | - } |
|
403 | - |
|
404 | - |
|
405 | - /** |
|
406 | - * loads service classes |
|
407 | - * |
|
408 | - * @param string $class_name - simple class name ie: session |
|
409 | - * @param mixed $arguments |
|
410 | - * @param bool $load_only |
|
411 | - * @return mixed |
|
412 | - * @throws InvalidInterfaceException |
|
413 | - * @throws InvalidDataTypeException |
|
414 | - * @throws EE_Error |
|
415 | - * @throws ReflectionException |
|
416 | - * @throws InvalidArgumentException |
|
417 | - */ |
|
418 | - public function load_service($class_name, $arguments = array(), $load_only = false) |
|
419 | - { |
|
420 | - $service_paths = apply_filters( |
|
421 | - 'FHEE__EE_Registry__load_service__service_paths', |
|
422 | - array( |
|
423 | - EE_CORE . 'services/', |
|
424 | - ) |
|
425 | - ); |
|
426 | - // retrieve instantiated class |
|
427 | - return $this->_load( |
|
428 | - $service_paths, |
|
429 | - 'EE_', |
|
430 | - $class_name, |
|
431 | - 'class', |
|
432 | - $arguments, |
|
433 | - false, |
|
434 | - true, |
|
435 | - $load_only |
|
436 | - ); |
|
437 | - } |
|
438 | - |
|
439 | - |
|
440 | - /** |
|
441 | - * loads data_migration_scripts |
|
442 | - * |
|
443 | - * @param string $class_name - class name for the DMS ie: EE_DMS_Core_4_2_0 |
|
444 | - * @param mixed $arguments |
|
445 | - * @return EE_Data_Migration_Script_Base|mixed |
|
446 | - * @throws InvalidInterfaceException |
|
447 | - * @throws InvalidDataTypeException |
|
448 | - * @throws EE_Error |
|
449 | - * @throws ReflectionException |
|
450 | - * @throws InvalidArgumentException |
|
451 | - */ |
|
452 | - public function load_dms($class_name, $arguments = array()) |
|
453 | - { |
|
454 | - // retrieve instantiated class |
|
455 | - return $this->_load( |
|
456 | - EE_Data_Migration_Manager::instance()->get_data_migration_script_folders(), |
|
457 | - 'EE_DMS_', |
|
458 | - $class_name, |
|
459 | - 'dms', |
|
460 | - $arguments, |
|
461 | - false, |
|
462 | - false |
|
463 | - ); |
|
464 | - } |
|
465 | - |
|
466 | - |
|
467 | - /** |
|
468 | - * loads object creating classes - must be singletons |
|
469 | - * |
|
470 | - * @param string $class_name - simple class name ie: attendee |
|
471 | - * @param mixed $arguments - an array of arguments to pass to the class |
|
472 | - * @param bool $from_db - some classes are instantiated from the db and thus call a different method to |
|
473 | - * instantiate |
|
474 | - * @param bool $cache if you don't want the class to be stored in the internal cache (non-persistent) then |
|
475 | - * set this to FALSE (ie. when instantiating model objects from client in a loop) |
|
476 | - * @param bool $load_only whether or not to just load the file and NOT instantiate, or load AND instantiate |
|
477 | - * (default) |
|
478 | - * @return EE_Base_Class | bool |
|
479 | - * @throws InvalidInterfaceException |
|
480 | - * @throws InvalidDataTypeException |
|
481 | - * @throws EE_Error |
|
482 | - * @throws ReflectionException |
|
483 | - * @throws InvalidArgumentException |
|
484 | - */ |
|
485 | - public function load_class($class_name, $arguments = array(), $from_db = false, $cache = true, $load_only = false) |
|
486 | - { |
|
487 | - $paths = apply_filters( |
|
488 | - 'FHEE__EE_Registry__load_class__paths', |
|
489 | - array( |
|
490 | - EE_CORE, |
|
491 | - EE_CLASSES, |
|
492 | - EE_BUSINESS, |
|
493 | - ) |
|
494 | - ); |
|
495 | - // retrieve instantiated class |
|
496 | - return $this->_load( |
|
497 | - $paths, |
|
498 | - 'EE_', |
|
499 | - $class_name, |
|
500 | - 'class', |
|
501 | - $arguments, |
|
502 | - $from_db, |
|
503 | - $cache, |
|
504 | - $load_only |
|
505 | - ); |
|
506 | - } |
|
507 | - |
|
508 | - |
|
509 | - /** |
|
510 | - * loads helper classes - must be singletons |
|
511 | - * |
|
512 | - * @param string $class_name - simple class name ie: price |
|
513 | - * @param mixed $arguments |
|
514 | - * @param bool $load_only |
|
515 | - * @return EEH_Base | bool |
|
516 | - * @throws InvalidInterfaceException |
|
517 | - * @throws InvalidDataTypeException |
|
518 | - * @throws EE_Error |
|
519 | - * @throws ReflectionException |
|
520 | - * @throws InvalidArgumentException |
|
521 | - */ |
|
522 | - public function load_helper($class_name, $arguments = array(), $load_only = true) |
|
523 | - { |
|
524 | - // todo: add doing_it_wrong() in a few versions after all addons have had calls to this method removed |
|
525 | - $helper_paths = apply_filters('FHEE__EE_Registry__load_helper__helper_paths', array(EE_HELPERS)); |
|
526 | - // retrieve instantiated class |
|
527 | - return $this->_load( |
|
528 | - $helper_paths, |
|
529 | - 'EEH_', |
|
530 | - $class_name, |
|
531 | - 'helper', |
|
532 | - $arguments, |
|
533 | - false, |
|
534 | - true, |
|
535 | - $load_only |
|
536 | - ); |
|
537 | - } |
|
538 | - |
|
539 | - |
|
540 | - /** |
|
541 | - * loads core classes - must be singletons |
|
542 | - * |
|
543 | - * @param string $class_name - simple class name ie: session |
|
544 | - * @param mixed $arguments |
|
545 | - * @param bool $load_only |
|
546 | - * @param bool $cache whether to cache the object or not. |
|
547 | - * @return mixed |
|
548 | - * @throws InvalidInterfaceException |
|
549 | - * @throws InvalidDataTypeException |
|
550 | - * @throws EE_Error |
|
551 | - * @throws ReflectionException |
|
552 | - * @throws InvalidArgumentException |
|
553 | - */ |
|
554 | - public function load_lib($class_name, $arguments = array(), $load_only = false, $cache = true) |
|
555 | - { |
|
556 | - $paths = array( |
|
557 | - EE_LIBRARIES, |
|
558 | - EE_LIBRARIES . 'messages/', |
|
559 | - EE_LIBRARIES . 'shortcodes/', |
|
560 | - EE_LIBRARIES . 'qtips/', |
|
561 | - EE_LIBRARIES . 'payment_methods/', |
|
562 | - ); |
|
563 | - // retrieve instantiated class |
|
564 | - return $this->_load( |
|
565 | - $paths, |
|
566 | - 'EE_', |
|
567 | - $class_name, |
|
568 | - 'lib', |
|
569 | - $arguments, |
|
570 | - false, |
|
571 | - $cache, |
|
572 | - $load_only |
|
573 | - ); |
|
574 | - } |
|
575 | - |
|
576 | - |
|
577 | - /** |
|
578 | - * loads model classes - must be singletons |
|
579 | - * |
|
580 | - * @param string $class_name - simple class name ie: price |
|
581 | - * @param mixed $arguments |
|
582 | - * @param bool $load_only |
|
583 | - * @return EEM_Base | bool |
|
584 | - * @throws InvalidInterfaceException |
|
585 | - * @throws InvalidDataTypeException |
|
586 | - * @throws EE_Error |
|
587 | - * @throws ReflectionException |
|
588 | - * @throws InvalidArgumentException |
|
589 | - */ |
|
590 | - public function load_model($class_name, $arguments = array(), $load_only = false) |
|
591 | - { |
|
592 | - $paths = apply_filters( |
|
593 | - 'FHEE__EE_Registry__load_model__paths', |
|
594 | - array( |
|
595 | - EE_MODELS, |
|
596 | - EE_CORE, |
|
597 | - ) |
|
598 | - ); |
|
599 | - // retrieve instantiated class |
|
600 | - return $this->_load( |
|
601 | - $paths, |
|
602 | - 'EEM_', |
|
603 | - $class_name, |
|
604 | - 'model', |
|
605 | - $arguments, |
|
606 | - false, |
|
607 | - true, |
|
608 | - $load_only |
|
609 | - ); |
|
610 | - } |
|
611 | - |
|
612 | - |
|
613 | - /** |
|
614 | - * loads model classes - must be singletons |
|
615 | - * |
|
616 | - * @param string $class_name - simple class name ie: price |
|
617 | - * @param mixed $arguments |
|
618 | - * @param bool $load_only |
|
619 | - * @return mixed | bool |
|
620 | - * @throws InvalidInterfaceException |
|
621 | - * @throws InvalidDataTypeException |
|
622 | - * @throws EE_Error |
|
623 | - * @throws ReflectionException |
|
624 | - * @throws InvalidArgumentException |
|
625 | - */ |
|
626 | - public function load_model_class($class_name, $arguments = array(), $load_only = true) |
|
627 | - { |
|
628 | - $paths = array( |
|
629 | - EE_MODELS . 'fields/', |
|
630 | - EE_MODELS . 'helpers/', |
|
631 | - EE_MODELS . 'relations/', |
|
632 | - EE_MODELS . 'strategies/', |
|
633 | - ); |
|
634 | - // retrieve instantiated class |
|
635 | - return $this->_load( |
|
636 | - $paths, |
|
637 | - 'EE_', |
|
638 | - $class_name, |
|
639 | - '', |
|
640 | - $arguments, |
|
641 | - false, |
|
642 | - true, |
|
643 | - $load_only |
|
644 | - ); |
|
645 | - } |
|
646 | - |
|
647 | - |
|
648 | - /** |
|
649 | - * Determines if $model_name is the name of an actual EE model. |
|
650 | - * |
|
651 | - * @param string $model_name like Event, Attendee, Question_Group_Question, etc. |
|
652 | - * @return boolean |
|
653 | - */ |
|
654 | - public function is_model_name($model_name) |
|
655 | - { |
|
656 | - return isset($this->models[ $model_name ]); |
|
657 | - } |
|
658 | - |
|
659 | - |
|
660 | - /** |
|
661 | - * generic class loader |
|
662 | - * |
|
663 | - * @param string $path_to_file - directory path to file location, not including filename |
|
664 | - * @param string $file_name - file name ie: my_file.php, including extension |
|
665 | - * @param string $type - file type - core? class? helper? model? |
|
666 | - * @param mixed $arguments |
|
667 | - * @param bool $load_only |
|
668 | - * @return mixed |
|
669 | - * @throws InvalidInterfaceException |
|
670 | - * @throws InvalidDataTypeException |
|
671 | - * @throws EE_Error |
|
672 | - * @throws ReflectionException |
|
673 | - * @throws InvalidArgumentException |
|
674 | - */ |
|
675 | - public function load_file($path_to_file, $file_name, $type = '', $arguments = array(), $load_only = true) |
|
676 | - { |
|
677 | - // retrieve instantiated class |
|
678 | - return $this->_load( |
|
679 | - $path_to_file, |
|
680 | - '', |
|
681 | - $file_name, |
|
682 | - $type, |
|
683 | - $arguments, |
|
684 | - false, |
|
685 | - true, |
|
686 | - $load_only |
|
687 | - ); |
|
688 | - } |
|
689 | - |
|
690 | - |
|
691 | - /** |
|
692 | - * @param string $path_to_file - directory path to file location, not including filename |
|
693 | - * @param string $class_name - full class name ie: My_Class |
|
694 | - * @param string $type - file type - core? class? helper? model? |
|
695 | - * @param mixed $arguments |
|
696 | - * @param bool $load_only |
|
697 | - * @return bool|EE_Addon|object |
|
698 | - * @throws InvalidInterfaceException |
|
699 | - * @throws InvalidDataTypeException |
|
700 | - * @throws EE_Error |
|
701 | - * @throws ReflectionException |
|
702 | - * @throws InvalidArgumentException |
|
703 | - */ |
|
704 | - public function load_addon($path_to_file, $class_name, $type = 'class', $arguments = array(), $load_only = false) |
|
705 | - { |
|
706 | - // retrieve instantiated class |
|
707 | - return $this->_load( |
|
708 | - $path_to_file, |
|
709 | - 'addon', |
|
710 | - $class_name, |
|
711 | - $type, |
|
712 | - $arguments, |
|
713 | - false, |
|
714 | - true, |
|
715 | - $load_only |
|
716 | - ); |
|
717 | - } |
|
718 | - |
|
719 | - |
|
720 | - /** |
|
721 | - * instantiates, caches, and automatically resolves dependencies |
|
722 | - * for classes that use a Fully Qualified Class Name. |
|
723 | - * if the class is not capable of being loaded using PSR-4 autoloading, |
|
724 | - * then you need to use one of the existing load_*() methods |
|
725 | - * which can resolve the classname and filepath from the passed arguments |
|
726 | - * |
|
727 | - * @param bool|string $class_name Fully Qualified Class Name |
|
728 | - * @param array $arguments an argument, or array of arguments to pass to the class upon instantiation |
|
729 | - * @param bool $cache whether to cache the instantiated object for reuse |
|
730 | - * @param bool $from_db some classes are instantiated from the db |
|
731 | - * and thus call a different method to instantiate |
|
732 | - * @param bool $load_only if true, will only load the file, but will NOT instantiate an object |
|
733 | - * @param bool|string $addon if true, will cache the object in the EE_Registry->$addons array |
|
734 | - * @return bool|null|mixed null = failure to load or instantiate class object. |
|
735 | - * object = class loaded and instantiated successfully. |
|
736 | - * bool = fail or success when $load_only is true |
|
737 | - * @throws InvalidInterfaceException |
|
738 | - * @throws InvalidDataTypeException |
|
739 | - * @throws EE_Error |
|
740 | - * @throws ReflectionException |
|
741 | - * @throws InvalidArgumentException |
|
742 | - */ |
|
743 | - public function create( |
|
744 | - $class_name = false, |
|
745 | - $arguments = array(), |
|
746 | - $cache = false, |
|
747 | - $from_db = false, |
|
748 | - $load_only = false, |
|
749 | - $addon = false |
|
750 | - ) { |
|
751 | - $class_name = ltrim($class_name, '\\'); |
|
752 | - $class_name = $this->class_cache->getFqnForAlias($class_name); |
|
753 | - $class_exists = $this->loadOrVerifyClassExists($class_name, $arguments); |
|
754 | - // if a non-FQCN was passed, then |
|
755 | - // verifyClassExists() might return an object |
|
756 | - // or it could return null if the class just could not be found anywhere |
|
757 | - if ($class_exists instanceof $class_name || $class_exists === null) { |
|
758 | - // either way, return the results |
|
759 | - return $class_exists; |
|
760 | - } |
|
761 | - $class_name = $class_exists; |
|
762 | - // if we're only loading the class and it already exists, then let's just return true immediately |
|
763 | - if ($load_only) { |
|
764 | - return true; |
|
765 | - } |
|
766 | - $addon = $addon ? 'addon' : ''; |
|
767 | - // $this->_cache_on is toggled during the recursive loading that can occur with dependency injection |
|
768 | - // $cache is controlled by individual calls to separate Registry loader methods like load_class() |
|
769 | - // $load_only is also controlled by individual calls to separate Registry loader methods like load_file() |
|
770 | - if ($this->_cache_on && $cache && ! $load_only) { |
|
771 | - // return object if it's already cached |
|
772 | - $cached_class = $this->_get_cached_class($class_name, $addon, $arguments); |
|
773 | - if ($cached_class !== null) { |
|
774 | - return $cached_class; |
|
775 | - } |
|
776 | - }// obtain the loader method from the dependency map |
|
777 | - $loader = $this->_dependency_map->class_loader($class_name);// instantiate the requested object |
|
778 | - if ($loader instanceof Closure) { |
|
779 | - $class_obj = $loader($arguments); |
|
780 | - } else { |
|
781 | - if ($loader && method_exists($this, $loader)) { |
|
782 | - $class_obj = $this->{$loader}($class_name, $arguments); |
|
783 | - } else { |
|
784 | - $class_obj = $this->_create_object($class_name, $arguments, $addon, $from_db); |
|
785 | - } |
|
786 | - } |
|
787 | - if (($this->_cache_on && $cache) || $this->get_class_abbreviation($class_name, '')) { |
|
788 | - // save it for later... kinda like gum { : $ |
|
789 | - $this->_set_cached_class( |
|
790 | - $class_obj, |
|
791 | - $class_name, |
|
792 | - $addon, |
|
793 | - $from_db, |
|
794 | - $arguments |
|
795 | - ); |
|
796 | - } |
|
797 | - $this->_cache_on = true; |
|
798 | - return $class_obj; |
|
799 | - } |
|
800 | - |
|
801 | - |
|
802 | - /** |
|
803 | - * Recursively checks that a class exists and potentially attempts to load classes with non-FQCNs |
|
804 | - * |
|
805 | - * @param string|object $class_name |
|
806 | - * @param array $arguments |
|
807 | - * @param int $attempt |
|
808 | - * @return mixed |
|
809 | - */ |
|
810 | - private function loadOrVerifyClassExists($class_name, array $arguments, $attempt = 1) |
|
811 | - { |
|
812 | - if (is_object($class_name) || class_exists($class_name)) { |
|
813 | - return $class_name; |
|
814 | - } |
|
815 | - switch ($attempt) { |
|
816 | - case 1: |
|
817 | - // if it's a FQCN then maybe the class is registered with a preceding \ |
|
818 | - $class_name = strpos($class_name, '\\') !== false |
|
819 | - ? '\\' . ltrim($class_name, '\\') |
|
820 | - : $class_name; |
|
821 | - break; |
|
822 | - case 2: |
|
823 | - // |
|
824 | - $loader = $this->_dependency_map->class_loader($class_name); |
|
825 | - if ($loader && method_exists($this, $loader)) { |
|
826 | - return $this->{$loader}($class_name, $arguments); |
|
827 | - } |
|
828 | - break; |
|
829 | - case 3: |
|
830 | - default: |
|
831 | - return null; |
|
832 | - } |
|
833 | - $attempt++; |
|
834 | - return $this->loadOrVerifyClassExists($class_name, $arguments, $attempt); |
|
835 | - } |
|
836 | - |
|
837 | - |
|
838 | - /** |
|
839 | - * instantiates, caches, and injects dependencies for classes |
|
840 | - * |
|
841 | - * @param array $file_paths an array of paths to folders to look in |
|
842 | - * @param string $class_prefix EE or EEM or... ??? |
|
843 | - * @param bool|string $class_name $class name |
|
844 | - * @param string $type file type - core? class? helper? model? |
|
845 | - * @param mixed $arguments an argument or array of arguments to pass to the class upon instantiation |
|
846 | - * @param bool $from_db some classes are instantiated from the db |
|
847 | - * and thus call a different method to instantiate |
|
848 | - * @param bool $cache whether to cache the instantiated object for reuse |
|
849 | - * @param bool $load_only if true, will only load the file, but will NOT instantiate an object |
|
850 | - * @return bool|null|object null = failure to load or instantiate class object. |
|
851 | - * object = class loaded and instantiated successfully. |
|
852 | - * bool = fail or success when $load_only is true |
|
853 | - * @throws EE_Error |
|
854 | - * @throws ReflectionException |
|
855 | - * @throws InvalidInterfaceException |
|
856 | - * @throws InvalidDataTypeException |
|
857 | - * @throws InvalidArgumentException |
|
858 | - */ |
|
859 | - protected function _load( |
|
860 | - $file_paths = array(), |
|
861 | - $class_prefix = 'EE_', |
|
862 | - $class_name = false, |
|
863 | - $type = 'class', |
|
864 | - $arguments = array(), |
|
865 | - $from_db = false, |
|
866 | - $cache = true, |
|
867 | - $load_only = false |
|
868 | - ) { |
|
869 | - $class_name = ltrim($class_name, '\\'); |
|
870 | - // strip php file extension |
|
871 | - $class_name = str_replace('.php', '', trim($class_name)); |
|
872 | - // does the class have a prefix ? |
|
873 | - if (! empty($class_prefix) && $class_prefix !== 'addon') { |
|
874 | - // make sure $class_prefix is uppercase |
|
875 | - $class_prefix = strtoupper(trim($class_prefix)); |
|
876 | - // add class prefix ONCE!!! |
|
877 | - $class_name = $class_prefix . str_replace($class_prefix, '', $class_name); |
|
878 | - } |
|
879 | - $class_name = $this->class_cache->getFqnForAlias($class_name); |
|
880 | - $class_exists = class_exists($class_name, false); |
|
881 | - // if we're only loading the class and it already exists, then let's just return true immediately |
|
882 | - if ($load_only && $class_exists) { |
|
883 | - return true; |
|
884 | - } |
|
885 | - $arguments = is_array($arguments) ? $arguments : array($arguments); |
|
886 | - // $this->_cache_on is toggled during the recursive loading that can occur with dependency injection |
|
887 | - // $cache is controlled by individual calls to separate Registry loader methods like load_class() |
|
888 | - // $load_only is also controlled by individual calls to separate Registry loader methods like load_file() |
|
889 | - if ($this->_cache_on && $cache && ! $load_only) { |
|
890 | - // return object if it's already cached |
|
891 | - $cached_class = $this->_get_cached_class($class_name, $class_prefix, $arguments); |
|
892 | - if ($cached_class !== null) { |
|
893 | - return $cached_class; |
|
894 | - } |
|
895 | - } |
|
896 | - // if the class doesn't already exist.. then we need to try and find the file and load it |
|
897 | - if (! $class_exists) { |
|
898 | - // get full path to file |
|
899 | - $path = $this->_resolve_path($class_name, $type, $file_paths); |
|
900 | - // load the file |
|
901 | - $loaded = $this->_require_file($path, $class_name, $type, $file_paths); |
|
902 | - // if we are only loading a file but NOT instantiating an object |
|
903 | - // then return boolean for whether class was loaded or not |
|
904 | - if ($load_only) { |
|
905 | - return $loaded; |
|
906 | - } |
|
907 | - // if an object was expected but loading failed, then return nothing |
|
908 | - if (! $loaded) { |
|
909 | - return null; |
|
910 | - } |
|
911 | - } |
|
912 | - // instantiate the requested object |
|
913 | - $class_obj = $this->_create_object($class_name, $arguments, $type, $from_db); |
|
914 | - if ($this->_cache_on && $cache) { |
|
915 | - // save it for later... kinda like gum { : $ |
|
916 | - $this->_set_cached_class( |
|
917 | - $class_obj, |
|
918 | - $class_name, |
|
919 | - $class_prefix, |
|
920 | - $from_db, |
|
921 | - $arguments |
|
922 | - ); |
|
923 | - } |
|
924 | - $this->_cache_on = true; |
|
925 | - return $class_obj; |
|
926 | - } |
|
927 | - |
|
928 | - |
|
929 | - /** |
|
930 | - * @param string $class_name |
|
931 | - * @param string $default have to specify something, but not anything that will conflict |
|
932 | - * @return mixed|string |
|
933 | - */ |
|
934 | - protected function get_class_abbreviation($class_name, $default = 'FANCY_BATMAN_PANTS') |
|
935 | - { |
|
936 | - return isset($this->_class_abbreviations[ $class_name ]) |
|
937 | - ? $this->_class_abbreviations[ $class_name ] |
|
938 | - : $default; |
|
939 | - } |
|
940 | - |
|
941 | - |
|
942 | - /** |
|
943 | - * attempts to find a cached version of the requested class |
|
944 | - * by looking in the following places: |
|
945 | - * $this->{$class_abbreviation} ie: $this->CART |
|
946 | - * $this->{$class_name} ie: $this->Some_Class |
|
947 | - * $this->LIB->{$class_name} ie: $this->LIB->Some_Class |
|
948 | - * $this->addon->{$class_name} ie: $this->addon->Some_Addon_Class |
|
949 | - * |
|
950 | - * @param string $class_name |
|
951 | - * @param string $class_prefix |
|
952 | - * @param array $arguments |
|
953 | - * @return mixed |
|
954 | - */ |
|
955 | - protected function _get_cached_class( |
|
956 | - $class_name, |
|
957 | - $class_prefix = '', |
|
958 | - $arguments = array() |
|
959 | - ) { |
|
960 | - if ($class_name === 'EE_Registry') { |
|
961 | - return $this; |
|
962 | - } |
|
963 | - $class_abbreviation = $this->get_class_abbreviation($class_name); |
|
964 | - // check if class has already been loaded, and return it if it has been |
|
965 | - if (isset($this->{$class_abbreviation})) { |
|
966 | - return $this->{$class_abbreviation}; |
|
967 | - } |
|
968 | - $class_name = str_replace('\\', '_', $class_name); |
|
969 | - if (isset($this->{$class_name})) { |
|
970 | - return $this->{$class_name}; |
|
971 | - } |
|
972 | - if ($class_prefix === 'addon' && $this->addons->has($class_name)) { |
|
973 | - return $this->addons->get($class_name); |
|
974 | - } |
|
975 | - $object_identifier = $this->object_identifier->getIdentifier($class_name, $arguments); |
|
976 | - if ($this->LIB->has($object_identifier)) { |
|
977 | - return $this->LIB->get($object_identifier); |
|
978 | - } |
|
979 | - foreach ($this->LIB as $key => $object) { |
|
980 | - if ( |
|
26 | + /** |
|
27 | + * @var EE_Registry $_instance |
|
28 | + */ |
|
29 | + private static $_instance; |
|
30 | + |
|
31 | + /** |
|
32 | + * @var EE_Dependency_Map $_dependency_map |
|
33 | + */ |
|
34 | + protected $_dependency_map; |
|
35 | + |
|
36 | + /** |
|
37 | + * @var Mirror |
|
38 | + */ |
|
39 | + private $mirror; |
|
40 | + |
|
41 | + /** |
|
42 | + * @var ClassInterfaceCache $class_cache |
|
43 | + */ |
|
44 | + private $class_cache; |
|
45 | + |
|
46 | + /** |
|
47 | + * @var array $_class_abbreviations |
|
48 | + */ |
|
49 | + protected $_class_abbreviations = array(); |
|
50 | + |
|
51 | + /** |
|
52 | + * @var CommandBusInterface $BUS |
|
53 | + */ |
|
54 | + public $BUS; |
|
55 | + |
|
56 | + /** |
|
57 | + * @var EE_Cart $CART |
|
58 | + */ |
|
59 | + public $CART; |
|
60 | + |
|
61 | + /** |
|
62 | + * @var EE_Config $CFG |
|
63 | + */ |
|
64 | + public $CFG; |
|
65 | + |
|
66 | + /** |
|
67 | + * @var EE_Network_Config $NET_CFG |
|
68 | + */ |
|
69 | + public $NET_CFG; |
|
70 | + |
|
71 | + /** |
|
72 | + * RegistryContainer for storing library classes in |
|
73 | + * |
|
74 | + * @var RegistryContainer $LIB |
|
75 | + */ |
|
76 | + public $LIB; |
|
77 | + |
|
78 | + /** |
|
79 | + * @var EE_Request_Handler $REQ |
|
80 | + * @deprecated 4.10.14.p |
|
81 | + */ |
|
82 | + public $REQ; |
|
83 | + |
|
84 | + /** |
|
85 | + * @var EE_Session $SSN |
|
86 | + */ |
|
87 | + public $SSN; |
|
88 | + |
|
89 | + /** |
|
90 | + * @since 4.5.0 |
|
91 | + * @var EE_Capabilities $CAP |
|
92 | + */ |
|
93 | + public $CAP; |
|
94 | + |
|
95 | + /** |
|
96 | + * @since 4.9.0 |
|
97 | + * @var EE_Message_Resource_Manager $MRM |
|
98 | + */ |
|
99 | + public $MRM; |
|
100 | + |
|
101 | + /** |
|
102 | + * @var Registry $AssetsRegistry |
|
103 | + */ |
|
104 | + public $AssetsRegistry; |
|
105 | + |
|
106 | + /** |
|
107 | + * RegistryContainer for holding addons which have registered themselves to work with EE core |
|
108 | + * |
|
109 | + * @var EE_Addon[] $addons |
|
110 | + */ |
|
111 | + public $addons; |
|
112 | + |
|
113 | + /** |
|
114 | + * keys are 'short names' (eg Event), values are class names (eg 'EEM_Event') |
|
115 | + * |
|
116 | + * @var EEM_Base[] $models |
|
117 | + */ |
|
118 | + public $models = array(); |
|
119 | + |
|
120 | + /** |
|
121 | + * @var EED_Module[] $modules |
|
122 | + */ |
|
123 | + public $modules; |
|
124 | + |
|
125 | + /** |
|
126 | + * @var EES_Shortcode[] $shortcodes |
|
127 | + */ |
|
128 | + public $shortcodes; |
|
129 | + |
|
130 | + /** |
|
131 | + * @var WP_Widget[] $widgets |
|
132 | + */ |
|
133 | + public $widgets; |
|
134 | + |
|
135 | + /** |
|
136 | + * this is an array of all implemented model names (i.e. not the parent abstract models, or models |
|
137 | + * which don't actually fetch items from the DB in the normal way (ie, are not children of EEM_Base)). |
|
138 | + * Keys are model "short names" (eg "Event") as used in model relations, and values are |
|
139 | + * classnames (eg "EEM_Event") |
|
140 | + * |
|
141 | + * @var array $non_abstract_db_models |
|
142 | + */ |
|
143 | + public $non_abstract_db_models = array(); |
|
144 | + |
|
145 | + /** |
|
146 | + * internationalization for JS strings |
|
147 | + * usage: EE_Registry::i18n_js_strings['string_key'] = esc_html__( 'string to translate.', 'event_espresso' ); |
|
148 | + * in js file: var translatedString = eei18n.string_key; |
|
149 | + * |
|
150 | + * @var array $i18n_js_strings |
|
151 | + */ |
|
152 | + public static $i18n_js_strings = array(); |
|
153 | + |
|
154 | + /** |
|
155 | + * $main_file - path to espresso.php |
|
156 | + * |
|
157 | + * @var array $main_file |
|
158 | + */ |
|
159 | + public $main_file; |
|
160 | + |
|
161 | + /** |
|
162 | + * array of ReflectionClass objects where the key is the class name |
|
163 | + * |
|
164 | + * @deprecated 4.9.62.p |
|
165 | + * @var ReflectionClass[] $_reflectors |
|
166 | + */ |
|
167 | + public $_reflectors; |
|
168 | + |
|
169 | + /** |
|
170 | + * boolean flag to indicate whether or not to load/save dependencies from/to the cache |
|
171 | + * |
|
172 | + * @var boolean $_cache_on |
|
173 | + */ |
|
174 | + protected $_cache_on = true; |
|
175 | + |
|
176 | + /** |
|
177 | + * @var ObjectIdentifier |
|
178 | + */ |
|
179 | + private $object_identifier; |
|
180 | + |
|
181 | + |
|
182 | + /** |
|
183 | + * @singleton method used to instantiate class object |
|
184 | + * @param EE_Dependency_Map|null $dependency_map |
|
185 | + * @param Mirror|null $mirror |
|
186 | + * @param ClassInterfaceCache|null $class_cache |
|
187 | + * @param ObjectIdentifier|null $object_identifier |
|
188 | + * @return EE_Registry instance |
|
189 | + */ |
|
190 | + public static function instance( |
|
191 | + EE_Dependency_Map $dependency_map = null, |
|
192 | + Mirror $mirror = null, |
|
193 | + ClassInterfaceCache $class_cache = null, |
|
194 | + ObjectIdentifier $object_identifier = null |
|
195 | + ) { |
|
196 | + // check if class object is instantiated |
|
197 | + if ( |
|
198 | + ! self::$_instance instanceof EE_Registry |
|
199 | + && $dependency_map instanceof EE_Dependency_Map |
|
200 | + && $mirror instanceof Mirror |
|
201 | + && $class_cache instanceof ClassInterfaceCache |
|
202 | + && $object_identifier instanceof ObjectIdentifier |
|
203 | + ) { |
|
204 | + self::$_instance = new self( |
|
205 | + $dependency_map, |
|
206 | + $mirror, |
|
207 | + $class_cache, |
|
208 | + $object_identifier |
|
209 | + ); |
|
210 | + } |
|
211 | + return self::$_instance; |
|
212 | + } |
|
213 | + |
|
214 | + |
|
215 | + /** |
|
216 | + * protected constructor to prevent direct creation |
|
217 | + * |
|
218 | + * @Constructor |
|
219 | + * @param EE_Dependency_Map $dependency_map |
|
220 | + * @param Mirror $mirror |
|
221 | + * @param ClassInterfaceCache $class_cache |
|
222 | + * @param ObjectIdentifier $object_identifier |
|
223 | + */ |
|
224 | + protected function __construct( |
|
225 | + EE_Dependency_Map $dependency_map, |
|
226 | + Mirror $mirror, |
|
227 | + ClassInterfaceCache $class_cache, |
|
228 | + ObjectIdentifier $object_identifier |
|
229 | + ) { |
|
230 | + $this->_dependency_map = $dependency_map; |
|
231 | + $this->mirror = $mirror; |
|
232 | + $this->class_cache = $class_cache; |
|
233 | + $this->object_identifier = $object_identifier; |
|
234 | + // $registry_container = new RegistryContainer(); |
|
235 | + $this->LIB = new RegistryContainer(); |
|
236 | + $this->addons = new RegistryContainer(); |
|
237 | + $this->modules = new RegistryContainer(); |
|
238 | + $this->shortcodes = new RegistryContainer(); |
|
239 | + $this->widgets = new RegistryContainer(); |
|
240 | + add_action('EE_Load_Espresso_Core__handle_request__initialize_core_loading', array($this, 'initialize')); |
|
241 | + } |
|
242 | + |
|
243 | + |
|
244 | + /** |
|
245 | + * initialize |
|
246 | + * |
|
247 | + * @throws OutOfBoundsException |
|
248 | + * @throws InvalidArgumentException |
|
249 | + * @throws InvalidInterfaceException |
|
250 | + * @throws InvalidDataTypeException |
|
251 | + * @throws EE_Error |
|
252 | + * @throws ReflectionException |
|
253 | + */ |
|
254 | + public function initialize() |
|
255 | + { |
|
256 | + $this->_class_abbreviations = apply_filters( |
|
257 | + 'FHEE__EE_Registry____construct___class_abbreviations', |
|
258 | + array( |
|
259 | + 'EE_Config' => 'CFG', |
|
260 | + 'EE_Session' => 'SSN', |
|
261 | + 'EE_Capabilities' => 'CAP', |
|
262 | + 'EE_Cart' => 'CART', |
|
263 | + 'EE_Network_Config' => 'NET_CFG', |
|
264 | + 'EE_Request_Handler' => 'REQ', |
|
265 | + 'EE_Message_Resource_Manager' => 'MRM', |
|
266 | + 'EventEspresso\core\services\commands\CommandBus' => 'BUS', |
|
267 | + 'EventEspresso\core\services\assets\Registry' => 'AssetsRegistry', |
|
268 | + ) |
|
269 | + ); |
|
270 | + $this->load_core('Base', array(), true); |
|
271 | + // add our request and response objects to the cache |
|
272 | + $request_loader = $this->_dependency_map->class_loader( |
|
273 | + 'EventEspresso\core\services\request\Request' |
|
274 | + ); |
|
275 | + $this->_set_cached_class( |
|
276 | + $request_loader(), |
|
277 | + 'EventEspresso\core\services\request\Request' |
|
278 | + ); |
|
279 | + $response_loader = $this->_dependency_map->class_loader( |
|
280 | + 'EventEspresso\core\services\request\Response' |
|
281 | + ); |
|
282 | + $this->_set_cached_class( |
|
283 | + $response_loader(), |
|
284 | + 'EventEspresso\core\services\request\Response' |
|
285 | + ); |
|
286 | + add_action('AHEE__EE_System__set_hooks_for_core', array($this, 'init')); |
|
287 | + } |
|
288 | + |
|
289 | + |
|
290 | + /** |
|
291 | + * @return void |
|
292 | + */ |
|
293 | + public function init() |
|
294 | + { |
|
295 | + // Get current page protocol |
|
296 | + $protocol = is_ssl() ? 'https://' : 'http://'; |
|
297 | + // Output admin-ajax.php URL with same protocol as current page |
|
298 | + self::$i18n_js_strings['ajax_url'] = admin_url('admin-ajax.php', $protocol); |
|
299 | + self::$i18n_js_strings['wp_debug'] = defined('WP_DEBUG') && WP_DEBUG; |
|
300 | + } |
|
301 | + |
|
302 | + |
|
303 | + /** |
|
304 | + * @return array |
|
305 | + */ |
|
306 | + public static function sanitize_i18n_js_strings() |
|
307 | + { |
|
308 | + $i18n_js_strings = (array) self::$i18n_js_strings; |
|
309 | + foreach ($i18n_js_strings as $key => $value) { |
|
310 | + if (is_scalar($value)) { |
|
311 | + $decoded_value = html_entity_decode((string) $value, ENT_QUOTES, 'UTF-8'); |
|
312 | + $i18n_js_strings[ $key ] = wp_strip_all_tags($decoded_value); |
|
313 | + } |
|
314 | + } |
|
315 | + return $i18n_js_strings; |
|
316 | + } |
|
317 | + |
|
318 | + |
|
319 | + /** |
|
320 | + * localize_i18n_js_strings |
|
321 | + * |
|
322 | + * @return string |
|
323 | + */ |
|
324 | + public static function localize_i18n_js_strings() |
|
325 | + { |
|
326 | + $i18n_js_strings = EE_Registry::sanitize_i18n_js_strings(); |
|
327 | + return '/* <![CDATA[ */ var eei18n = ' . wp_json_encode($i18n_js_strings) . '; /* ]]> */'; |
|
328 | + } |
|
329 | + |
|
330 | + |
|
331 | + /** |
|
332 | + * @param mixed string | EED_Module $module |
|
333 | + * @throws OutOfBoundsException |
|
334 | + * @throws InvalidArgumentException |
|
335 | + * @throws InvalidInterfaceException |
|
336 | + * @throws InvalidDataTypeException |
|
337 | + * @throws EE_Error |
|
338 | + * @throws ReflectionException |
|
339 | + */ |
|
340 | + public function add_module($module) |
|
341 | + { |
|
342 | + if ($module instanceof EED_Module) { |
|
343 | + $module_class = get_class($module); |
|
344 | + $this->modules->add($module_class, $module); |
|
345 | + } else { |
|
346 | + if (! class_exists('EE_Module_Request_Router', false)) { |
|
347 | + $this->load_core('Module_Request_Router'); |
|
348 | + } |
|
349 | + EE_Module_Request_Router::module_factory($module); |
|
350 | + } |
|
351 | + } |
|
352 | + |
|
353 | + |
|
354 | + /** |
|
355 | + * @param string $module_name |
|
356 | + * @return mixed EED_Module | NULL |
|
357 | + */ |
|
358 | + public function get_module($module_name = '') |
|
359 | + { |
|
360 | + return $this->modules->get($module_name); |
|
361 | + } |
|
362 | + |
|
363 | + |
|
364 | + /** |
|
365 | + * loads core classes - must be singletons |
|
366 | + * |
|
367 | + * @param string $class_name - simple class name ie: session |
|
368 | + * @param mixed $arguments |
|
369 | + * @param bool $load_only |
|
370 | + * @return mixed |
|
371 | + * @throws InvalidInterfaceException |
|
372 | + * @throws InvalidDataTypeException |
|
373 | + * @throws EE_Error |
|
374 | + * @throws ReflectionException |
|
375 | + * @throws InvalidArgumentException |
|
376 | + */ |
|
377 | + public function load_core($class_name, $arguments = array(), $load_only = false) |
|
378 | + { |
|
379 | + $core_paths = apply_filters( |
|
380 | + 'FHEE__EE_Registry__load_core__core_paths', |
|
381 | + array( |
|
382 | + EE_CORE, |
|
383 | + EE_ADMIN, |
|
384 | + EE_CPTS, |
|
385 | + EE_CORE . 'CPTs/', |
|
386 | + EE_CORE . 'data_migration_scripts/', |
|
387 | + EE_CORE . 'request_stack/', |
|
388 | + EE_CORE . 'middleware/', |
|
389 | + ) |
|
390 | + ); |
|
391 | + // retrieve instantiated class |
|
392 | + return $this->_load( |
|
393 | + $core_paths, |
|
394 | + 'EE_', |
|
395 | + $class_name, |
|
396 | + 'core', |
|
397 | + $arguments, |
|
398 | + false, |
|
399 | + true, |
|
400 | + $load_only |
|
401 | + ); |
|
402 | + } |
|
403 | + |
|
404 | + |
|
405 | + /** |
|
406 | + * loads service classes |
|
407 | + * |
|
408 | + * @param string $class_name - simple class name ie: session |
|
409 | + * @param mixed $arguments |
|
410 | + * @param bool $load_only |
|
411 | + * @return mixed |
|
412 | + * @throws InvalidInterfaceException |
|
413 | + * @throws InvalidDataTypeException |
|
414 | + * @throws EE_Error |
|
415 | + * @throws ReflectionException |
|
416 | + * @throws InvalidArgumentException |
|
417 | + */ |
|
418 | + public function load_service($class_name, $arguments = array(), $load_only = false) |
|
419 | + { |
|
420 | + $service_paths = apply_filters( |
|
421 | + 'FHEE__EE_Registry__load_service__service_paths', |
|
422 | + array( |
|
423 | + EE_CORE . 'services/', |
|
424 | + ) |
|
425 | + ); |
|
426 | + // retrieve instantiated class |
|
427 | + return $this->_load( |
|
428 | + $service_paths, |
|
429 | + 'EE_', |
|
430 | + $class_name, |
|
431 | + 'class', |
|
432 | + $arguments, |
|
433 | + false, |
|
434 | + true, |
|
435 | + $load_only |
|
436 | + ); |
|
437 | + } |
|
438 | + |
|
439 | + |
|
440 | + /** |
|
441 | + * loads data_migration_scripts |
|
442 | + * |
|
443 | + * @param string $class_name - class name for the DMS ie: EE_DMS_Core_4_2_0 |
|
444 | + * @param mixed $arguments |
|
445 | + * @return EE_Data_Migration_Script_Base|mixed |
|
446 | + * @throws InvalidInterfaceException |
|
447 | + * @throws InvalidDataTypeException |
|
448 | + * @throws EE_Error |
|
449 | + * @throws ReflectionException |
|
450 | + * @throws InvalidArgumentException |
|
451 | + */ |
|
452 | + public function load_dms($class_name, $arguments = array()) |
|
453 | + { |
|
454 | + // retrieve instantiated class |
|
455 | + return $this->_load( |
|
456 | + EE_Data_Migration_Manager::instance()->get_data_migration_script_folders(), |
|
457 | + 'EE_DMS_', |
|
458 | + $class_name, |
|
459 | + 'dms', |
|
460 | + $arguments, |
|
461 | + false, |
|
462 | + false |
|
463 | + ); |
|
464 | + } |
|
465 | + |
|
466 | + |
|
467 | + /** |
|
468 | + * loads object creating classes - must be singletons |
|
469 | + * |
|
470 | + * @param string $class_name - simple class name ie: attendee |
|
471 | + * @param mixed $arguments - an array of arguments to pass to the class |
|
472 | + * @param bool $from_db - some classes are instantiated from the db and thus call a different method to |
|
473 | + * instantiate |
|
474 | + * @param bool $cache if you don't want the class to be stored in the internal cache (non-persistent) then |
|
475 | + * set this to FALSE (ie. when instantiating model objects from client in a loop) |
|
476 | + * @param bool $load_only whether or not to just load the file and NOT instantiate, or load AND instantiate |
|
477 | + * (default) |
|
478 | + * @return EE_Base_Class | bool |
|
479 | + * @throws InvalidInterfaceException |
|
480 | + * @throws InvalidDataTypeException |
|
481 | + * @throws EE_Error |
|
482 | + * @throws ReflectionException |
|
483 | + * @throws InvalidArgumentException |
|
484 | + */ |
|
485 | + public function load_class($class_name, $arguments = array(), $from_db = false, $cache = true, $load_only = false) |
|
486 | + { |
|
487 | + $paths = apply_filters( |
|
488 | + 'FHEE__EE_Registry__load_class__paths', |
|
489 | + array( |
|
490 | + EE_CORE, |
|
491 | + EE_CLASSES, |
|
492 | + EE_BUSINESS, |
|
493 | + ) |
|
494 | + ); |
|
495 | + // retrieve instantiated class |
|
496 | + return $this->_load( |
|
497 | + $paths, |
|
498 | + 'EE_', |
|
499 | + $class_name, |
|
500 | + 'class', |
|
501 | + $arguments, |
|
502 | + $from_db, |
|
503 | + $cache, |
|
504 | + $load_only |
|
505 | + ); |
|
506 | + } |
|
507 | + |
|
508 | + |
|
509 | + /** |
|
510 | + * loads helper classes - must be singletons |
|
511 | + * |
|
512 | + * @param string $class_name - simple class name ie: price |
|
513 | + * @param mixed $arguments |
|
514 | + * @param bool $load_only |
|
515 | + * @return EEH_Base | bool |
|
516 | + * @throws InvalidInterfaceException |
|
517 | + * @throws InvalidDataTypeException |
|
518 | + * @throws EE_Error |
|
519 | + * @throws ReflectionException |
|
520 | + * @throws InvalidArgumentException |
|
521 | + */ |
|
522 | + public function load_helper($class_name, $arguments = array(), $load_only = true) |
|
523 | + { |
|
524 | + // todo: add doing_it_wrong() in a few versions after all addons have had calls to this method removed |
|
525 | + $helper_paths = apply_filters('FHEE__EE_Registry__load_helper__helper_paths', array(EE_HELPERS)); |
|
526 | + // retrieve instantiated class |
|
527 | + return $this->_load( |
|
528 | + $helper_paths, |
|
529 | + 'EEH_', |
|
530 | + $class_name, |
|
531 | + 'helper', |
|
532 | + $arguments, |
|
533 | + false, |
|
534 | + true, |
|
535 | + $load_only |
|
536 | + ); |
|
537 | + } |
|
538 | + |
|
539 | + |
|
540 | + /** |
|
541 | + * loads core classes - must be singletons |
|
542 | + * |
|
543 | + * @param string $class_name - simple class name ie: session |
|
544 | + * @param mixed $arguments |
|
545 | + * @param bool $load_only |
|
546 | + * @param bool $cache whether to cache the object or not. |
|
547 | + * @return mixed |
|
548 | + * @throws InvalidInterfaceException |
|
549 | + * @throws InvalidDataTypeException |
|
550 | + * @throws EE_Error |
|
551 | + * @throws ReflectionException |
|
552 | + * @throws InvalidArgumentException |
|
553 | + */ |
|
554 | + public function load_lib($class_name, $arguments = array(), $load_only = false, $cache = true) |
|
555 | + { |
|
556 | + $paths = array( |
|
557 | + EE_LIBRARIES, |
|
558 | + EE_LIBRARIES . 'messages/', |
|
559 | + EE_LIBRARIES . 'shortcodes/', |
|
560 | + EE_LIBRARIES . 'qtips/', |
|
561 | + EE_LIBRARIES . 'payment_methods/', |
|
562 | + ); |
|
563 | + // retrieve instantiated class |
|
564 | + return $this->_load( |
|
565 | + $paths, |
|
566 | + 'EE_', |
|
567 | + $class_name, |
|
568 | + 'lib', |
|
569 | + $arguments, |
|
570 | + false, |
|
571 | + $cache, |
|
572 | + $load_only |
|
573 | + ); |
|
574 | + } |
|
575 | + |
|
576 | + |
|
577 | + /** |
|
578 | + * loads model classes - must be singletons |
|
579 | + * |
|
580 | + * @param string $class_name - simple class name ie: price |
|
581 | + * @param mixed $arguments |
|
582 | + * @param bool $load_only |
|
583 | + * @return EEM_Base | bool |
|
584 | + * @throws InvalidInterfaceException |
|
585 | + * @throws InvalidDataTypeException |
|
586 | + * @throws EE_Error |
|
587 | + * @throws ReflectionException |
|
588 | + * @throws InvalidArgumentException |
|
589 | + */ |
|
590 | + public function load_model($class_name, $arguments = array(), $load_only = false) |
|
591 | + { |
|
592 | + $paths = apply_filters( |
|
593 | + 'FHEE__EE_Registry__load_model__paths', |
|
594 | + array( |
|
595 | + EE_MODELS, |
|
596 | + EE_CORE, |
|
597 | + ) |
|
598 | + ); |
|
599 | + // retrieve instantiated class |
|
600 | + return $this->_load( |
|
601 | + $paths, |
|
602 | + 'EEM_', |
|
603 | + $class_name, |
|
604 | + 'model', |
|
605 | + $arguments, |
|
606 | + false, |
|
607 | + true, |
|
608 | + $load_only |
|
609 | + ); |
|
610 | + } |
|
611 | + |
|
612 | + |
|
613 | + /** |
|
614 | + * loads model classes - must be singletons |
|
615 | + * |
|
616 | + * @param string $class_name - simple class name ie: price |
|
617 | + * @param mixed $arguments |
|
618 | + * @param bool $load_only |
|
619 | + * @return mixed | bool |
|
620 | + * @throws InvalidInterfaceException |
|
621 | + * @throws InvalidDataTypeException |
|
622 | + * @throws EE_Error |
|
623 | + * @throws ReflectionException |
|
624 | + * @throws InvalidArgumentException |
|
625 | + */ |
|
626 | + public function load_model_class($class_name, $arguments = array(), $load_only = true) |
|
627 | + { |
|
628 | + $paths = array( |
|
629 | + EE_MODELS . 'fields/', |
|
630 | + EE_MODELS . 'helpers/', |
|
631 | + EE_MODELS . 'relations/', |
|
632 | + EE_MODELS . 'strategies/', |
|
633 | + ); |
|
634 | + // retrieve instantiated class |
|
635 | + return $this->_load( |
|
636 | + $paths, |
|
637 | + 'EE_', |
|
638 | + $class_name, |
|
639 | + '', |
|
640 | + $arguments, |
|
641 | + false, |
|
642 | + true, |
|
643 | + $load_only |
|
644 | + ); |
|
645 | + } |
|
646 | + |
|
647 | + |
|
648 | + /** |
|
649 | + * Determines if $model_name is the name of an actual EE model. |
|
650 | + * |
|
651 | + * @param string $model_name like Event, Attendee, Question_Group_Question, etc. |
|
652 | + * @return boolean |
|
653 | + */ |
|
654 | + public function is_model_name($model_name) |
|
655 | + { |
|
656 | + return isset($this->models[ $model_name ]); |
|
657 | + } |
|
658 | + |
|
659 | + |
|
660 | + /** |
|
661 | + * generic class loader |
|
662 | + * |
|
663 | + * @param string $path_to_file - directory path to file location, not including filename |
|
664 | + * @param string $file_name - file name ie: my_file.php, including extension |
|
665 | + * @param string $type - file type - core? class? helper? model? |
|
666 | + * @param mixed $arguments |
|
667 | + * @param bool $load_only |
|
668 | + * @return mixed |
|
669 | + * @throws InvalidInterfaceException |
|
670 | + * @throws InvalidDataTypeException |
|
671 | + * @throws EE_Error |
|
672 | + * @throws ReflectionException |
|
673 | + * @throws InvalidArgumentException |
|
674 | + */ |
|
675 | + public function load_file($path_to_file, $file_name, $type = '', $arguments = array(), $load_only = true) |
|
676 | + { |
|
677 | + // retrieve instantiated class |
|
678 | + return $this->_load( |
|
679 | + $path_to_file, |
|
680 | + '', |
|
681 | + $file_name, |
|
682 | + $type, |
|
683 | + $arguments, |
|
684 | + false, |
|
685 | + true, |
|
686 | + $load_only |
|
687 | + ); |
|
688 | + } |
|
689 | + |
|
690 | + |
|
691 | + /** |
|
692 | + * @param string $path_to_file - directory path to file location, not including filename |
|
693 | + * @param string $class_name - full class name ie: My_Class |
|
694 | + * @param string $type - file type - core? class? helper? model? |
|
695 | + * @param mixed $arguments |
|
696 | + * @param bool $load_only |
|
697 | + * @return bool|EE_Addon|object |
|
698 | + * @throws InvalidInterfaceException |
|
699 | + * @throws InvalidDataTypeException |
|
700 | + * @throws EE_Error |
|
701 | + * @throws ReflectionException |
|
702 | + * @throws InvalidArgumentException |
|
703 | + */ |
|
704 | + public function load_addon($path_to_file, $class_name, $type = 'class', $arguments = array(), $load_only = false) |
|
705 | + { |
|
706 | + // retrieve instantiated class |
|
707 | + return $this->_load( |
|
708 | + $path_to_file, |
|
709 | + 'addon', |
|
710 | + $class_name, |
|
711 | + $type, |
|
712 | + $arguments, |
|
713 | + false, |
|
714 | + true, |
|
715 | + $load_only |
|
716 | + ); |
|
717 | + } |
|
718 | + |
|
719 | + |
|
720 | + /** |
|
721 | + * instantiates, caches, and automatically resolves dependencies |
|
722 | + * for classes that use a Fully Qualified Class Name. |
|
723 | + * if the class is not capable of being loaded using PSR-4 autoloading, |
|
724 | + * then you need to use one of the existing load_*() methods |
|
725 | + * which can resolve the classname and filepath from the passed arguments |
|
726 | + * |
|
727 | + * @param bool|string $class_name Fully Qualified Class Name |
|
728 | + * @param array $arguments an argument, or array of arguments to pass to the class upon instantiation |
|
729 | + * @param bool $cache whether to cache the instantiated object for reuse |
|
730 | + * @param bool $from_db some classes are instantiated from the db |
|
731 | + * and thus call a different method to instantiate |
|
732 | + * @param bool $load_only if true, will only load the file, but will NOT instantiate an object |
|
733 | + * @param bool|string $addon if true, will cache the object in the EE_Registry->$addons array |
|
734 | + * @return bool|null|mixed null = failure to load or instantiate class object. |
|
735 | + * object = class loaded and instantiated successfully. |
|
736 | + * bool = fail or success when $load_only is true |
|
737 | + * @throws InvalidInterfaceException |
|
738 | + * @throws InvalidDataTypeException |
|
739 | + * @throws EE_Error |
|
740 | + * @throws ReflectionException |
|
741 | + * @throws InvalidArgumentException |
|
742 | + */ |
|
743 | + public function create( |
|
744 | + $class_name = false, |
|
745 | + $arguments = array(), |
|
746 | + $cache = false, |
|
747 | + $from_db = false, |
|
748 | + $load_only = false, |
|
749 | + $addon = false |
|
750 | + ) { |
|
751 | + $class_name = ltrim($class_name, '\\'); |
|
752 | + $class_name = $this->class_cache->getFqnForAlias($class_name); |
|
753 | + $class_exists = $this->loadOrVerifyClassExists($class_name, $arguments); |
|
754 | + // if a non-FQCN was passed, then |
|
755 | + // verifyClassExists() might return an object |
|
756 | + // or it could return null if the class just could not be found anywhere |
|
757 | + if ($class_exists instanceof $class_name || $class_exists === null) { |
|
758 | + // either way, return the results |
|
759 | + return $class_exists; |
|
760 | + } |
|
761 | + $class_name = $class_exists; |
|
762 | + // if we're only loading the class and it already exists, then let's just return true immediately |
|
763 | + if ($load_only) { |
|
764 | + return true; |
|
765 | + } |
|
766 | + $addon = $addon ? 'addon' : ''; |
|
767 | + // $this->_cache_on is toggled during the recursive loading that can occur with dependency injection |
|
768 | + // $cache is controlled by individual calls to separate Registry loader methods like load_class() |
|
769 | + // $load_only is also controlled by individual calls to separate Registry loader methods like load_file() |
|
770 | + if ($this->_cache_on && $cache && ! $load_only) { |
|
771 | + // return object if it's already cached |
|
772 | + $cached_class = $this->_get_cached_class($class_name, $addon, $arguments); |
|
773 | + if ($cached_class !== null) { |
|
774 | + return $cached_class; |
|
775 | + } |
|
776 | + }// obtain the loader method from the dependency map |
|
777 | + $loader = $this->_dependency_map->class_loader($class_name);// instantiate the requested object |
|
778 | + if ($loader instanceof Closure) { |
|
779 | + $class_obj = $loader($arguments); |
|
780 | + } else { |
|
781 | + if ($loader && method_exists($this, $loader)) { |
|
782 | + $class_obj = $this->{$loader}($class_name, $arguments); |
|
783 | + } else { |
|
784 | + $class_obj = $this->_create_object($class_name, $arguments, $addon, $from_db); |
|
785 | + } |
|
786 | + } |
|
787 | + if (($this->_cache_on && $cache) || $this->get_class_abbreviation($class_name, '')) { |
|
788 | + // save it for later... kinda like gum { : $ |
|
789 | + $this->_set_cached_class( |
|
790 | + $class_obj, |
|
791 | + $class_name, |
|
792 | + $addon, |
|
793 | + $from_db, |
|
794 | + $arguments |
|
795 | + ); |
|
796 | + } |
|
797 | + $this->_cache_on = true; |
|
798 | + return $class_obj; |
|
799 | + } |
|
800 | + |
|
801 | + |
|
802 | + /** |
|
803 | + * Recursively checks that a class exists and potentially attempts to load classes with non-FQCNs |
|
804 | + * |
|
805 | + * @param string|object $class_name |
|
806 | + * @param array $arguments |
|
807 | + * @param int $attempt |
|
808 | + * @return mixed |
|
809 | + */ |
|
810 | + private function loadOrVerifyClassExists($class_name, array $arguments, $attempt = 1) |
|
811 | + { |
|
812 | + if (is_object($class_name) || class_exists($class_name)) { |
|
813 | + return $class_name; |
|
814 | + } |
|
815 | + switch ($attempt) { |
|
816 | + case 1: |
|
817 | + // if it's a FQCN then maybe the class is registered with a preceding \ |
|
818 | + $class_name = strpos($class_name, '\\') !== false |
|
819 | + ? '\\' . ltrim($class_name, '\\') |
|
820 | + : $class_name; |
|
821 | + break; |
|
822 | + case 2: |
|
823 | + // |
|
824 | + $loader = $this->_dependency_map->class_loader($class_name); |
|
825 | + if ($loader && method_exists($this, $loader)) { |
|
826 | + return $this->{$loader}($class_name, $arguments); |
|
827 | + } |
|
828 | + break; |
|
829 | + case 3: |
|
830 | + default: |
|
831 | + return null; |
|
832 | + } |
|
833 | + $attempt++; |
|
834 | + return $this->loadOrVerifyClassExists($class_name, $arguments, $attempt); |
|
835 | + } |
|
836 | + |
|
837 | + |
|
838 | + /** |
|
839 | + * instantiates, caches, and injects dependencies for classes |
|
840 | + * |
|
841 | + * @param array $file_paths an array of paths to folders to look in |
|
842 | + * @param string $class_prefix EE or EEM or... ??? |
|
843 | + * @param bool|string $class_name $class name |
|
844 | + * @param string $type file type - core? class? helper? model? |
|
845 | + * @param mixed $arguments an argument or array of arguments to pass to the class upon instantiation |
|
846 | + * @param bool $from_db some classes are instantiated from the db |
|
847 | + * and thus call a different method to instantiate |
|
848 | + * @param bool $cache whether to cache the instantiated object for reuse |
|
849 | + * @param bool $load_only if true, will only load the file, but will NOT instantiate an object |
|
850 | + * @return bool|null|object null = failure to load or instantiate class object. |
|
851 | + * object = class loaded and instantiated successfully. |
|
852 | + * bool = fail or success when $load_only is true |
|
853 | + * @throws EE_Error |
|
854 | + * @throws ReflectionException |
|
855 | + * @throws InvalidInterfaceException |
|
856 | + * @throws InvalidDataTypeException |
|
857 | + * @throws InvalidArgumentException |
|
858 | + */ |
|
859 | + protected function _load( |
|
860 | + $file_paths = array(), |
|
861 | + $class_prefix = 'EE_', |
|
862 | + $class_name = false, |
|
863 | + $type = 'class', |
|
864 | + $arguments = array(), |
|
865 | + $from_db = false, |
|
866 | + $cache = true, |
|
867 | + $load_only = false |
|
868 | + ) { |
|
869 | + $class_name = ltrim($class_name, '\\'); |
|
870 | + // strip php file extension |
|
871 | + $class_name = str_replace('.php', '', trim($class_name)); |
|
872 | + // does the class have a prefix ? |
|
873 | + if (! empty($class_prefix) && $class_prefix !== 'addon') { |
|
874 | + // make sure $class_prefix is uppercase |
|
875 | + $class_prefix = strtoupper(trim($class_prefix)); |
|
876 | + // add class prefix ONCE!!! |
|
877 | + $class_name = $class_prefix . str_replace($class_prefix, '', $class_name); |
|
878 | + } |
|
879 | + $class_name = $this->class_cache->getFqnForAlias($class_name); |
|
880 | + $class_exists = class_exists($class_name, false); |
|
881 | + // if we're only loading the class and it already exists, then let's just return true immediately |
|
882 | + if ($load_only && $class_exists) { |
|
883 | + return true; |
|
884 | + } |
|
885 | + $arguments = is_array($arguments) ? $arguments : array($arguments); |
|
886 | + // $this->_cache_on is toggled during the recursive loading that can occur with dependency injection |
|
887 | + // $cache is controlled by individual calls to separate Registry loader methods like load_class() |
|
888 | + // $load_only is also controlled by individual calls to separate Registry loader methods like load_file() |
|
889 | + if ($this->_cache_on && $cache && ! $load_only) { |
|
890 | + // return object if it's already cached |
|
891 | + $cached_class = $this->_get_cached_class($class_name, $class_prefix, $arguments); |
|
892 | + if ($cached_class !== null) { |
|
893 | + return $cached_class; |
|
894 | + } |
|
895 | + } |
|
896 | + // if the class doesn't already exist.. then we need to try and find the file and load it |
|
897 | + if (! $class_exists) { |
|
898 | + // get full path to file |
|
899 | + $path = $this->_resolve_path($class_name, $type, $file_paths); |
|
900 | + // load the file |
|
901 | + $loaded = $this->_require_file($path, $class_name, $type, $file_paths); |
|
902 | + // if we are only loading a file but NOT instantiating an object |
|
903 | + // then return boolean for whether class was loaded or not |
|
904 | + if ($load_only) { |
|
905 | + return $loaded; |
|
906 | + } |
|
907 | + // if an object was expected but loading failed, then return nothing |
|
908 | + if (! $loaded) { |
|
909 | + return null; |
|
910 | + } |
|
911 | + } |
|
912 | + // instantiate the requested object |
|
913 | + $class_obj = $this->_create_object($class_name, $arguments, $type, $from_db); |
|
914 | + if ($this->_cache_on && $cache) { |
|
915 | + // save it for later... kinda like gum { : $ |
|
916 | + $this->_set_cached_class( |
|
917 | + $class_obj, |
|
918 | + $class_name, |
|
919 | + $class_prefix, |
|
920 | + $from_db, |
|
921 | + $arguments |
|
922 | + ); |
|
923 | + } |
|
924 | + $this->_cache_on = true; |
|
925 | + return $class_obj; |
|
926 | + } |
|
927 | + |
|
928 | + |
|
929 | + /** |
|
930 | + * @param string $class_name |
|
931 | + * @param string $default have to specify something, but not anything that will conflict |
|
932 | + * @return mixed|string |
|
933 | + */ |
|
934 | + protected function get_class_abbreviation($class_name, $default = 'FANCY_BATMAN_PANTS') |
|
935 | + { |
|
936 | + return isset($this->_class_abbreviations[ $class_name ]) |
|
937 | + ? $this->_class_abbreviations[ $class_name ] |
|
938 | + : $default; |
|
939 | + } |
|
940 | + |
|
941 | + |
|
942 | + /** |
|
943 | + * attempts to find a cached version of the requested class |
|
944 | + * by looking in the following places: |
|
945 | + * $this->{$class_abbreviation} ie: $this->CART |
|
946 | + * $this->{$class_name} ie: $this->Some_Class |
|
947 | + * $this->LIB->{$class_name} ie: $this->LIB->Some_Class |
|
948 | + * $this->addon->{$class_name} ie: $this->addon->Some_Addon_Class |
|
949 | + * |
|
950 | + * @param string $class_name |
|
951 | + * @param string $class_prefix |
|
952 | + * @param array $arguments |
|
953 | + * @return mixed |
|
954 | + */ |
|
955 | + protected function _get_cached_class( |
|
956 | + $class_name, |
|
957 | + $class_prefix = '', |
|
958 | + $arguments = array() |
|
959 | + ) { |
|
960 | + if ($class_name === 'EE_Registry') { |
|
961 | + return $this; |
|
962 | + } |
|
963 | + $class_abbreviation = $this->get_class_abbreviation($class_name); |
|
964 | + // check if class has already been loaded, and return it if it has been |
|
965 | + if (isset($this->{$class_abbreviation})) { |
|
966 | + return $this->{$class_abbreviation}; |
|
967 | + } |
|
968 | + $class_name = str_replace('\\', '_', $class_name); |
|
969 | + if (isset($this->{$class_name})) { |
|
970 | + return $this->{$class_name}; |
|
971 | + } |
|
972 | + if ($class_prefix === 'addon' && $this->addons->has($class_name)) { |
|
973 | + return $this->addons->get($class_name); |
|
974 | + } |
|
975 | + $object_identifier = $this->object_identifier->getIdentifier($class_name, $arguments); |
|
976 | + if ($this->LIB->has($object_identifier)) { |
|
977 | + return $this->LIB->get($object_identifier); |
|
978 | + } |
|
979 | + foreach ($this->LIB as $key => $object) { |
|
980 | + if ( |
|
981 | 981 | // request does not contain new arguments and therefore no args identifier |
982 | - ! $this->object_identifier->hasArguments($object_identifier) |
|
983 | - // but previously cached class with args was found |
|
984 | - && $this->object_identifier->fqcnMatchesObjectIdentifier($class_name, $key) |
|
985 | - ) { |
|
986 | - return $object; |
|
987 | - } |
|
988 | - } |
|
989 | - return null; |
|
990 | - } |
|
991 | - |
|
992 | - |
|
993 | - /** |
|
994 | - * removes a cached version of the requested class |
|
995 | - * |
|
996 | - * @param string $class_name |
|
997 | - * @param boolean $addon |
|
998 | - * @param array $arguments |
|
999 | - * @return boolean |
|
1000 | - */ |
|
1001 | - public function clear_cached_class( |
|
1002 | - $class_name, |
|
1003 | - $addon = false, |
|
1004 | - $arguments = array() |
|
1005 | - ) { |
|
1006 | - $class_abbreviation = $this->get_class_abbreviation($class_name); |
|
1007 | - // check if class has already been loaded, and return it if it has been |
|
1008 | - if (isset($this->{$class_abbreviation})) { |
|
1009 | - $this->{$class_abbreviation} = null; |
|
1010 | - return true; |
|
1011 | - } |
|
1012 | - $class_name = str_replace('\\', '_', $class_name); |
|
1013 | - if (isset($this->{$class_name})) { |
|
1014 | - $this->{$class_name} = null; |
|
1015 | - return true; |
|
1016 | - } |
|
1017 | - if ($addon && $this->addons->has($class_name)) { |
|
1018 | - $this->addons->remove($class_name); |
|
1019 | - return true; |
|
1020 | - } |
|
1021 | - $class_name = $this->object_identifier->getIdentifier($class_name, $arguments); |
|
1022 | - if ($this->LIB->has($class_name)) { |
|
1023 | - $this->LIB->remove($class_name); |
|
1024 | - return true; |
|
1025 | - } |
|
1026 | - return false; |
|
1027 | - } |
|
1028 | - |
|
1029 | - |
|
1030 | - /** |
|
1031 | - * _set_cached_class |
|
1032 | - * attempts to cache the instantiated class locally |
|
1033 | - * in one of the following places, in the following order: |
|
1034 | - * $this->{class_abbreviation} ie: $this->CART |
|
1035 | - * $this->{$class_name} ie: $this->Some_Class |
|
1036 | - * $this->addon->{$$class_name} ie: $this->addon->Some_Addon_Class |
|
1037 | - * $this->LIB->{$class_name} ie: $this->LIB->Some_Class |
|
1038 | - * |
|
1039 | - * @param object $class_obj |
|
1040 | - * @param string $class_name |
|
1041 | - * @param string $class_prefix |
|
1042 | - * @param bool $from_db |
|
1043 | - * @param array $arguments |
|
1044 | - * @return void |
|
1045 | - */ |
|
1046 | - protected function _set_cached_class( |
|
1047 | - $class_obj, |
|
1048 | - $class_name, |
|
1049 | - $class_prefix = '', |
|
1050 | - $from_db = false, |
|
1051 | - $arguments = array() |
|
1052 | - ) { |
|
1053 | - if ($class_name === 'EE_Registry' || empty($class_obj)) { |
|
1054 | - return; |
|
1055 | - } |
|
1056 | - // return newly instantiated class |
|
1057 | - $class_abbreviation = $this->get_class_abbreviation($class_name, ''); |
|
1058 | - if ($class_abbreviation) { |
|
1059 | - $this->{$class_abbreviation} = $class_obj; |
|
1060 | - return; |
|
1061 | - } |
|
1062 | - $class_name = str_replace('\\', '_', $class_name); |
|
1063 | - if (property_exists($this, $class_name)) { |
|
1064 | - $this->{$class_name} = $class_obj; |
|
1065 | - return; |
|
1066 | - } |
|
1067 | - if ($class_prefix === 'addon') { |
|
1068 | - $this->addons->add($class_name, $class_obj); |
|
1069 | - return; |
|
1070 | - } |
|
1071 | - if (! $from_db) { |
|
1072 | - $class_name = $this->object_identifier->getIdentifier($class_name, $arguments); |
|
1073 | - $this->LIB->add($class_name, $class_obj); |
|
1074 | - } |
|
1075 | - } |
|
1076 | - |
|
1077 | - |
|
1078 | - /** |
|
1079 | - * attempts to find a full valid filepath for the requested class. |
|
1080 | - * loops thru each of the base paths in the $file_paths array and appends : "{classname} . {file type} . php" |
|
1081 | - * then returns that path if the target file has been found and is readable |
|
1082 | - * |
|
1083 | - * @param string $class_name |
|
1084 | - * @param string $type |
|
1085 | - * @param array $file_paths |
|
1086 | - * @return string | bool |
|
1087 | - */ |
|
1088 | - protected function _resolve_path($class_name, $type = '', $file_paths = array()) |
|
1089 | - { |
|
1090 | - // make sure $file_paths is an array |
|
1091 | - $file_paths = is_array($file_paths) |
|
1092 | - ? $file_paths |
|
1093 | - : array($file_paths); |
|
1094 | - // cycle thru paths |
|
1095 | - foreach ($file_paths as $key => $file_path) { |
|
1096 | - // convert all separators to proper /, if no filepath, then use EE_CLASSES |
|
1097 | - $file_path = $file_path |
|
1098 | - ? str_replace(array('/', '\\'), '/', $file_path) |
|
1099 | - : EE_CLASSES; |
|
1100 | - // prep file type |
|
1101 | - $type = ! empty($type) |
|
1102 | - ? trim($type, '.') . '.' |
|
1103 | - : ''; |
|
1104 | - // build full file path |
|
1105 | - $file_paths[ $key ] = rtrim($file_path, '/') . '/' . $class_name . '.' . $type . 'php'; |
|
1106 | - // does the file exist and can be read ? |
|
1107 | - if (is_readable($file_paths[ $key ])) { |
|
1108 | - return $file_paths[ $key ]; |
|
1109 | - } |
|
1110 | - } |
|
1111 | - return false; |
|
1112 | - } |
|
1113 | - |
|
1114 | - |
|
1115 | - /** |
|
1116 | - * basically just performs a require_once() |
|
1117 | - * but with some error handling |
|
1118 | - * |
|
1119 | - * @param string $path |
|
1120 | - * @param string $class_name |
|
1121 | - * @param string $type |
|
1122 | - * @param array $file_paths |
|
1123 | - * @return bool |
|
1124 | - * @throws EE_Error |
|
1125 | - * @throws ReflectionException |
|
1126 | - */ |
|
1127 | - protected function _require_file($path, $class_name, $type = '', $file_paths = array()) |
|
1128 | - { |
|
1129 | - $this->resolve_legacy_class_parent($class_name); |
|
1130 | - // don't give up! you gotta... |
|
1131 | - try { |
|
1132 | - // does the file exist and can it be read ? |
|
1133 | - if (! $path) { |
|
1134 | - // just in case the file has already been autoloaded, |
|
1135 | - // but discrepancies in the naming schema are preventing it from |
|
1136 | - // being loaded via one of the EE_Registry::load_*() methods, |
|
1137 | - // then let's try one last hail mary before throwing an exception |
|
1138 | - // and call class_exists() again, but with autoloading turned ON |
|
1139 | - if (class_exists($class_name)) { |
|
1140 | - return true; |
|
1141 | - } |
|
1142 | - // so sorry, can't find the file |
|
1143 | - throw new EE_Error( |
|
1144 | - sprintf( |
|
1145 | - esc_html__( |
|
1146 | - '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', |
|
1147 | - 'event_espresso' |
|
1148 | - ), |
|
1149 | - trim($type, '.'), |
|
1150 | - $class_name, |
|
1151 | - '<br />' . implode(',<br />', $file_paths) |
|
1152 | - ) |
|
1153 | - ); |
|
1154 | - } |
|
1155 | - // get the file |
|
1156 | - require_once($path); |
|
1157 | - // if the class isn't already declared somewhere |
|
1158 | - if (class_exists($class_name, false) === false) { |
|
1159 | - // so sorry, not a class |
|
1160 | - throw new EE_Error( |
|
1161 | - sprintf( |
|
1162 | - esc_html__( |
|
1163 | - 'The %s file %s does not appear to contain the %s Class.', |
|
1164 | - 'event_espresso' |
|
1165 | - ), |
|
1166 | - $type, |
|
1167 | - $path, |
|
1168 | - $class_name |
|
1169 | - ) |
|
1170 | - ); |
|
1171 | - } |
|
1172 | - } catch (EE_Error $e) { |
|
1173 | - $e->get_error(); |
|
1174 | - return false; |
|
1175 | - } |
|
1176 | - return true; |
|
1177 | - } |
|
1178 | - |
|
1179 | - |
|
1180 | - /** |
|
1181 | - * Some of our legacy classes that extended a parent class would simply use a require() statement |
|
1182 | - * before their class declaration in order to ensure that the parent class was loaded. |
|
1183 | - * This is not ideal, but it's nearly impossible to determine the parent class of a non-namespaced class, |
|
1184 | - * without triggering a fatal error because the parent class has yet to be loaded and therefore doesn't exist. |
|
1185 | - * |
|
1186 | - * @param string $class_name |
|
1187 | - */ |
|
1188 | - protected function resolve_legacy_class_parent($class_name = '') |
|
1189 | - { |
|
1190 | - try { |
|
1191 | - $legacy_parent_class_map = array( |
|
1192 | - 'EE_Payment_Processor' => 'core/business/EE_Processor_Base.class.php', |
|
1193 | - ); |
|
1194 | - if (isset($legacy_parent_class_map[ $class_name ])) { |
|
1195 | - require_once EE_PLUGIN_DIR_PATH . $legacy_parent_class_map[ $class_name ]; |
|
1196 | - } |
|
1197 | - } catch (Exception $exception) { |
|
1198 | - } |
|
1199 | - } |
|
1200 | - |
|
1201 | - |
|
1202 | - /** |
|
1203 | - * _create_object |
|
1204 | - * Attempts to instantiate the requested class via any of the |
|
1205 | - * commonly used instantiation methods employed throughout EE. |
|
1206 | - * The priority for instantiation is as follows: |
|
1207 | - * - abstract classes or any class flagged as "load only" (no instantiation occurs) |
|
1208 | - * - model objects via their 'new_instance_from_db' method |
|
1209 | - * - model objects via their 'new_instance' method |
|
1210 | - * - "singleton" classes" via their 'instance' method |
|
1211 | - * - standard instantiable classes via their __constructor |
|
1212 | - * Prior to instantiation, if the classname exists in the dependency_map, |
|
1213 | - * then the constructor for the requested class will be examined to determine |
|
1214 | - * if any dependencies exist, and if they can be injected. |
|
1215 | - * If so, then those classes will be added to the array of arguments passed to the constructor |
|
1216 | - * |
|
1217 | - * @param string $class_name |
|
1218 | - * @param array $arguments |
|
1219 | - * @param string $type |
|
1220 | - * @param bool $from_db |
|
1221 | - * @return null|object|bool |
|
1222 | - * @throws InvalidArgumentException |
|
1223 | - * @throws InvalidInterfaceException |
|
1224 | - * @throws EE_Error |
|
1225 | - * @throws ReflectionException |
|
1226 | - * @throws InvalidDataTypeException |
|
1227 | - */ |
|
1228 | - protected function _create_object($class_name, $arguments = array(), $type = '', $from_db = false) |
|
1229 | - { |
|
1230 | - // create reflection |
|
1231 | - $reflector = $this->mirror->getReflectionClass($class_name); |
|
1232 | - // make sure arguments are an array |
|
1233 | - $arguments = is_array($arguments) |
|
1234 | - ? $arguments |
|
1235 | - : array($arguments); |
|
1236 | - // and if arguments array is numerically and sequentially indexed, then we want it to remain as is, |
|
1237 | - // else wrap it in an additional array so that it doesn't get split into multiple parameters |
|
1238 | - $arguments = $this->_array_is_numerically_and_sequentially_indexed($arguments) |
|
1239 | - ? $arguments |
|
1240 | - : array($arguments); |
|
1241 | - // attempt to inject dependencies ? |
|
1242 | - if ($this->_dependency_map->has($class_name)) { |
|
1243 | - $arguments = $this->_resolve_dependencies($reflector, $class_name, $arguments); |
|
1244 | - } |
|
1245 | - // instantiate the class if possible |
|
1246 | - if ($reflector->isAbstract()) { |
|
1247 | - // nothing to instantiate, loading file was enough |
|
1248 | - // does not throw an exception so $instantiation_mode is unused |
|
1249 | - // $instantiation_mode = "1) no constructor abstract class"; |
|
1250 | - return true; |
|
1251 | - } |
|
1252 | - if ( |
|
1253 | - empty($arguments) |
|
1254 | - && $this->mirror->getConstructorFromReflection($reflector) === null |
|
1255 | - && $reflector->isInstantiable() |
|
1256 | - ) { |
|
1257 | - // no constructor = static methods only... nothing to instantiate, loading file was enough |
|
1258 | - // $instantiation_mode = "2) no constructor but instantiable"; |
|
1259 | - return $reflector->newInstance(); |
|
1260 | - } |
|
1261 | - if ($from_db && method_exists($class_name, 'new_instance_from_db')) { |
|
1262 | - // $instantiation_mode = "3) new_instance_from_db()"; |
|
1263 | - return call_user_func_array(array($class_name, 'new_instance_from_db'), $arguments); |
|
1264 | - } |
|
1265 | - if (method_exists($class_name, 'new_instance')) { |
|
1266 | - // $instantiation_mode = "4) new_instance()"; |
|
1267 | - return call_user_func_array(array($class_name, 'new_instance'), $arguments); |
|
1268 | - } |
|
1269 | - if (method_exists($class_name, 'instance')) { |
|
1270 | - // $instantiation_mode = "5) instance()"; |
|
1271 | - return call_user_func_array(array($class_name, 'instance'), $arguments); |
|
1272 | - } |
|
1273 | - if ($reflector->isInstantiable()) { |
|
1274 | - $args_passed_count = count($arguments); |
|
1275 | - $args_required_count = count($this->mirror->getRequiredParameters($class_name)); |
|
1276 | - if ($args_passed_count < $args_required_count) { |
|
1277 | - throw new RuntimeException( |
|
1278 | - sprintf( |
|
1279 | - __( |
|
1280 | - 'Invalid arguments supplied for the %1$s class, %2$s were required but %3$s were passed.', |
|
1281 | - 'event_espresso' |
|
1282 | - ), |
|
1283 | - $class_name, |
|
1284 | - $args_required_count, |
|
1285 | - $args_passed_count |
|
1286 | - ) |
|
1287 | - ); |
|
1288 | - } |
|
1289 | - // $instantiation_mode = "6) constructor"; |
|
1290 | - return $reflector->newInstanceArgs($arguments); |
|
1291 | - } |
|
1292 | - // heh ? something's not right ! |
|
1293 | - throw new EE_Error( |
|
1294 | - sprintf( |
|
1295 | - esc_html__('The %s file %s could not be instantiated.', 'event_espresso'), |
|
1296 | - $type, |
|
1297 | - $class_name |
|
1298 | - ) |
|
1299 | - ); |
|
1300 | - } |
|
1301 | - |
|
1302 | - |
|
1303 | - /** |
|
1304 | - * @see http://stackoverflow.com/questions/173400/how-to-check-if-php-array-is-associative-or-sequential |
|
1305 | - * @param array $array |
|
1306 | - * @return bool |
|
1307 | - */ |
|
1308 | - protected function _array_is_numerically_and_sequentially_indexed(array $array) |
|
1309 | - { |
|
1310 | - return ! empty($array) |
|
1311 | - ? array_keys($array) === range(0, count($array) - 1) |
|
1312 | - : true; |
|
1313 | - } |
|
1314 | - |
|
1315 | - |
|
1316 | - /** |
|
1317 | - * _resolve_dependencies |
|
1318 | - * examines the constructor for the requested class to determine |
|
1319 | - * if any dependencies exist, and if they can be injected. |
|
1320 | - * If so, then those classes will be added to the array of arguments passed to the constructor |
|
1321 | - * PLZ NOTE: this is achieved by type hinting the constructor params |
|
1322 | - * For example: |
|
1323 | - * if attempting to load a class "Foo" with the following constructor: |
|
1324 | - * __construct( Bar $bar_class, Fighter $grohl_class ) |
|
1325 | - * then $bar_class and $grohl_class will be added to the $arguments array, |
|
1326 | - * but only IF they are NOT already present in the incoming arguments array, |
|
1327 | - * and the correct classes can be loaded |
|
1328 | - * |
|
1329 | - * @param ReflectionClass $reflector |
|
1330 | - * @param string $class_name |
|
1331 | - * @param array $arguments |
|
1332 | - * @return array |
|
1333 | - * @throws InvalidArgumentException |
|
1334 | - * @throws InvalidDataTypeException |
|
1335 | - * @throws InvalidInterfaceException |
|
1336 | - * @throws ReflectionException |
|
1337 | - */ |
|
1338 | - protected function _resolve_dependencies(ReflectionClass $reflector, $class_name, array $arguments = array()) |
|
1339 | - { |
|
1340 | - // let's examine the constructor |
|
1341 | - $constructor = $this->mirror->getConstructorFromReflection($reflector); |
|
1342 | - // whu? huh? nothing? |
|
1343 | - if (! $constructor) { |
|
1344 | - return $arguments; |
|
1345 | - } |
|
1346 | - // get constructor parameters |
|
1347 | - $params = $this->mirror->getParametersFromReflection($reflector); |
|
1348 | - // and the keys for the incoming arguments array so that we can compare existing arguments with what is expected |
|
1349 | - $argument_keys = array_keys($arguments); |
|
1350 | - // now loop thru all of the constructors expected parameters |
|
1351 | - foreach ($params as $index => $param) { |
|
1352 | - try { |
|
1353 | - // is this a dependency for a specific class ? |
|
1354 | - $param_class = $this->mirror->getParameterClassName($param, $class_name, $index); |
|
1355 | - } catch (ReflectionException $exception) { |
|
1356 | - // uh-oh... most likely a legacy class that has not been autoloaded |
|
1357 | - // let's try to derive the classname from what we have now |
|
1358 | - // and hope that the property var name is close to the class name |
|
1359 | - $param_class = $param->getName(); |
|
1360 | - $param_class = str_replace('_', ' ', $param_class); |
|
1361 | - $param_class = ucwords($param_class); |
|
1362 | - $param_class = str_replace(' ', '_', $param_class); |
|
1363 | - } |
|
1364 | - // BUT WAIT !!! This class may be an alias for something else (or getting replaced at runtime) |
|
1365 | - $param_class = $this->class_cache->isAlias($param_class, $class_name) |
|
1366 | - ? $this->class_cache->getFqnForAlias($param_class, $class_name) |
|
1367 | - : $param_class; |
|
1368 | - if ( |
|
1369 | - // param is not even a class |
|
1370 | - ($param_class === null || $this->parameterIsPrimitive($param_class)) |
|
1371 | - // and something already exists in the incoming arguments for this param |
|
1372 | - && array_key_exists($index, $argument_keys) |
|
1373 | - && array_key_exists($argument_keys[ $index ], $arguments) |
|
1374 | - ) { |
|
1375 | - // so let's skip this argument and move on to the next |
|
1376 | - continue; |
|
1377 | - } |
|
1378 | - if ( |
|
1379 | - // parameter is type hinted as a class, exists as an incoming argument, AND it's the correct class |
|
1380 | - $param_class !== null |
|
1381 | - && isset($argument_keys[ $index ], $arguments[ $argument_keys[ $index ] ]) |
|
1382 | - && $arguments[ $argument_keys[ $index ] ] instanceof $param_class |
|
1383 | - ) { |
|
1384 | - // skip this argument and move on to the next |
|
1385 | - continue; |
|
1386 | - } |
|
1387 | - if ( |
|
1388 | - // parameter is type hinted as a class, and should be injected |
|
1389 | - $param_class !== null |
|
1390 | - && $this->_dependency_map->has_dependency_for_class($class_name, $param_class) |
|
1391 | - ) { |
|
1392 | - $arguments = $this->_resolve_dependency( |
|
1393 | - $class_name, |
|
1394 | - $param_class, |
|
1395 | - $arguments, |
|
1396 | - $index |
|
1397 | - ); |
|
1398 | - } |
|
1399 | - if (empty($arguments[ $index ])) { |
|
1400 | - $default_value = $this->mirror->getParameterDefaultValue( |
|
1401 | - $param, |
|
1402 | - $class_name, |
|
1403 | - $index |
|
1404 | - ); |
|
1405 | - // if there's no default value, and the incoming argument is an array (albeit empty), then use that |
|
1406 | - $arguments[ $index ] = $default_value === null |
|
1407 | - && isset($arguments[ $index ]) |
|
1408 | - && is_array($arguments[ $index ]) |
|
1409 | - ? $arguments[ $index ] |
|
1410 | - : $default_value; |
|
1411 | - } |
|
1412 | - } |
|
1413 | - return $arguments; |
|
1414 | - } |
|
1415 | - |
|
1416 | - |
|
1417 | - /** |
|
1418 | - * @param string $class_name |
|
1419 | - * @param string $param_class |
|
1420 | - * @param array $arguments |
|
1421 | - * @param mixed $index |
|
1422 | - * @return array |
|
1423 | - * @throws InvalidArgumentException |
|
1424 | - * @throws InvalidInterfaceException |
|
1425 | - * @throws InvalidDataTypeException |
|
1426 | - */ |
|
1427 | - protected function _resolve_dependency($class_name, $param_class, $arguments, $index) |
|
1428 | - { |
|
1429 | - $dependency = null; |
|
1430 | - // should dependency be loaded from cache ? |
|
1431 | - $cache_on = $this->_dependency_map->loading_strategy_for_class_dependency( |
|
1432 | - $class_name, |
|
1433 | - $param_class |
|
1434 | - ); |
|
1435 | - $cache_on = $cache_on !== EE_Dependency_Map::load_new_object; |
|
1436 | - // we might have a dependency... |
|
1437 | - // let's MAYBE try and find it in our cache if that's what's been requested |
|
1438 | - $cached_class = $cache_on |
|
1439 | - ? $this->_get_cached_class($param_class) |
|
1440 | - : null; |
|
1441 | - // and grab it if it exists |
|
1442 | - if ($cached_class instanceof $param_class) { |
|
1443 | - $dependency = $cached_class; |
|
1444 | - } elseif ($param_class !== $class_name) { |
|
1445 | - // obtain the loader method from the dependency map |
|
1446 | - $loader = $this->_dependency_map->class_loader($param_class); |
|
1447 | - // is loader a custom closure ? |
|
1448 | - if ($loader instanceof Closure) { |
|
1449 | - $dependency = $loader($arguments); |
|
1450 | - } else { |
|
1451 | - // set the cache on property for the recursive loading call |
|
1452 | - $this->_cache_on = $cache_on; |
|
1453 | - // if not, then let's try and load it via the registry |
|
1454 | - if ($loader && method_exists($this, $loader)) { |
|
1455 | - $dependency = $this->{$loader}($param_class); |
|
1456 | - } else { |
|
1457 | - $dependency = LoaderFactory::getLoader()->load( |
|
1458 | - $param_class, |
|
1459 | - array(), |
|
1460 | - $cache_on |
|
1461 | - ); |
|
1462 | - } |
|
1463 | - } |
|
1464 | - } |
|
1465 | - // did we successfully find the correct dependency ? |
|
1466 | - if ($dependency instanceof $param_class) { |
|
1467 | - // then let's inject it into the incoming array of arguments at the correct location |
|
1468 | - $arguments[ $index ] = $dependency; |
|
1469 | - } |
|
1470 | - return $arguments; |
|
1471 | - } |
|
1472 | - |
|
1473 | - |
|
1474 | - /** |
|
1475 | - * call any loader that's been registered in the EE_Dependency_Map::$_class_loaders array |
|
1476 | - * |
|
1477 | - * @param string $classname PLEASE NOTE: the class name needs to match what's registered |
|
1478 | - * in the EE_Dependency_Map::$_class_loaders array, |
|
1479 | - * including the class prefix, ie: "EE_", "EEM_", "EEH_", etc |
|
1480 | - * @param array $arguments |
|
1481 | - * @return object |
|
1482 | - */ |
|
1483 | - public static function factory($classname, $arguments = array()) |
|
1484 | - { |
|
1485 | - $loader = self::instance()->_dependency_map->class_loader($classname); |
|
1486 | - if ($loader instanceof Closure) { |
|
1487 | - return $loader($arguments); |
|
1488 | - } |
|
1489 | - if (method_exists(self::instance(), $loader)) { |
|
1490 | - return self::instance()->{$loader}($classname, $arguments); |
|
1491 | - } |
|
1492 | - return null; |
|
1493 | - } |
|
1494 | - |
|
1495 | - |
|
1496 | - /** |
|
1497 | - * Gets the addon by its class name |
|
1498 | - * |
|
1499 | - * @param string $class_name |
|
1500 | - * @return EE_Addon |
|
1501 | - */ |
|
1502 | - public function getAddon($class_name) |
|
1503 | - { |
|
1504 | - $class_name = str_replace('\\', '_', $class_name); |
|
1505 | - if (isset($this->addons->{$class_name})) { |
|
1506 | - return $this->addons->{$class_name}; |
|
1507 | - } else { |
|
1508 | - return null; |
|
1509 | - } |
|
1510 | - } |
|
1511 | - |
|
1512 | - |
|
1513 | - /** |
|
1514 | - * removes the addon from the internal cache |
|
1515 | - * |
|
1516 | - * @param string $class_name |
|
1517 | - * @return void |
|
1518 | - */ |
|
1519 | - public function removeAddon($class_name) |
|
1520 | - { |
|
1521 | - $class_name = str_replace('\\', '_', $class_name); |
|
1522 | - $this->addons->remove($class_name); |
|
1523 | - } |
|
1524 | - |
|
1525 | - |
|
1526 | - /** |
|
1527 | - * Gets the addon by its name/slug (not classname. For that, just |
|
1528 | - * use the get_addon() method above |
|
1529 | - * |
|
1530 | - * @param string $name |
|
1531 | - * @return EE_Addon |
|
1532 | - */ |
|
1533 | - public function get_addon_by_name($name) |
|
1534 | - { |
|
1535 | - foreach ($this->addons as $addon) { |
|
1536 | - if ($addon->name() === $name) { |
|
1537 | - return $addon; |
|
1538 | - } |
|
1539 | - } |
|
1540 | - return null; |
|
1541 | - } |
|
1542 | - |
|
1543 | - |
|
1544 | - /** |
|
1545 | - * Gets an array of all the registered addons, where the keys are their names. |
|
1546 | - * (ie, what each returns for their name() function) |
|
1547 | - * They're already available on EE_Registry::instance()->addons as properties, |
|
1548 | - * where each property's name is the addon's classname, |
|
1549 | - * So if you just want to get the addon by classname, |
|
1550 | - * OR use the get_addon() method above. |
|
1551 | - * PLEASE NOTE: |
|
1552 | - * addons with Fully Qualified Class Names |
|
1553 | - * have had the namespace separators converted to underscores, |
|
1554 | - * so a classname like Fully\Qualified\ClassName |
|
1555 | - * would have been converted to Fully_Qualified_ClassName |
|
1556 | - * |
|
1557 | - * @return EE_Addon[] where the KEYS are the addon's name() |
|
1558 | - */ |
|
1559 | - public function get_addons_by_name() |
|
1560 | - { |
|
1561 | - $addons = array(); |
|
1562 | - foreach ($this->addons as $addon) { |
|
1563 | - $addons[ $addon->name() ] = $addon; |
|
1564 | - } |
|
1565 | - return $addons; |
|
1566 | - } |
|
1567 | - |
|
1568 | - |
|
1569 | - /** |
|
1570 | - * Resets the specified model's instance AND makes sure EE_Registry doesn't keep |
|
1571 | - * a stale copy of it around |
|
1572 | - * |
|
1573 | - * @param string $model_name |
|
1574 | - * @return \EEM_Base |
|
1575 | - * @throws \EE_Error |
|
1576 | - */ |
|
1577 | - public function reset_model($model_name) |
|
1578 | - { |
|
1579 | - $model_class_name = strpos($model_name, 'EEM_') !== 0 |
|
1580 | - ? "EEM_{$model_name}" |
|
1581 | - : $model_name; |
|
1582 | - if (! $this->LIB->has($model_class_name)) { |
|
1583 | - return null; |
|
1584 | - } |
|
1585 | - $model = $this->LIB->get($model_class_name); |
|
1586 | - if (! $model instanceof EEM_Base) { |
|
1587 | - return null; |
|
1588 | - } |
|
1589 | - // get that model reset it and make sure we nuke the old reference to it |
|
1590 | - if ($model instanceof $model_class_name && is_callable([$model_class_name, 'reset'])) { |
|
1591 | - $this->LIB->remove($model_class_name); |
|
1592 | - $this->LIB->add($model_class_name, $model->reset()); |
|
1593 | - } else { |
|
1594 | - throw new EE_Error( |
|
1595 | - sprintf( |
|
1596 | - esc_html__('Model %s does not have a method "reset"', 'event_espresso'), |
|
1597 | - $model_name |
|
1598 | - ) |
|
1599 | - ); |
|
1600 | - } |
|
1601 | - return $model; |
|
1602 | - } |
|
1603 | - |
|
1604 | - |
|
1605 | - /** |
|
1606 | - * Resets the registry. |
|
1607 | - * The criteria for what gets reset is based on what can be shared between sites on the same request when |
|
1608 | - * switch_to_blog is used in a multisite install. Here is a list of things that are NOT reset. |
|
1609 | - * - $_dependency_map |
|
1610 | - * - $_class_abbreviations |
|
1611 | - * - $NET_CFG (EE_Network_Config): The config is shared network wide so no need to reset. |
|
1612 | - * - $REQ: Still on the same request so no need to change. |
|
1613 | - * - $CAP: There is no site specific state in the EE_Capability class. |
|
1614 | - * - $SSN: Although ideally, the session should not be shared between site switches, we can't reset it because only |
|
1615 | - * one Session can be active in a single request. Resetting could resolve in "headers already sent" errors. |
|
1616 | - * - $addons: In multisite, the state of the addons is something controlled via hooks etc in a normal request. So |
|
1617 | - * for now, we won't reset the addons because it could break calls to an add-ons class/methods in the |
|
1618 | - * switch or on the restore. |
|
1619 | - * - $modules |
|
1620 | - * - $shortcodes |
|
1621 | - * - $widgets |
|
1622 | - * |
|
1623 | - * @param boolean $hard [deprecated] |
|
1624 | - * @param boolean $reinstantiate whether to create new instances of EE_Registry's singletons too, |
|
1625 | - * or just reset without re-instantiating (handy to set to FALSE if you're not |
|
1626 | - * sure if you CAN currently reinstantiate the singletons at the moment) |
|
1627 | - * @param bool $reset_models Defaults to true. When false, then the models are not reset. This is so |
|
1628 | - * client |
|
1629 | - * code instead can just change the model context to a different blog id if |
|
1630 | - * necessary |
|
1631 | - * @return EE_Registry |
|
1632 | - * @throws InvalidInterfaceException |
|
1633 | - * @throws InvalidDataTypeException |
|
1634 | - * @throws EE_Error |
|
1635 | - * @throws ReflectionException |
|
1636 | - * @throws InvalidArgumentException |
|
1637 | - */ |
|
1638 | - public static function reset($hard = false, $reinstantiate = true, $reset_models = true) |
|
1639 | - { |
|
1640 | - $instance = self::instance(); |
|
1641 | - $instance->_cache_on = true; |
|
1642 | - // reset some "special" classes |
|
1643 | - EEH_Activation::reset(); |
|
1644 | - $hard = apply_filters('FHEE__EE_Registry__reset__hard', $hard); |
|
1645 | - $instance->CFG = EE_Config::reset($hard, $reinstantiate); |
|
1646 | - $instance->CART = null; |
|
1647 | - $instance->MRM = null; |
|
1648 | - // messages reset |
|
1649 | - EED_Messages::reset(); |
|
1650 | - // handle of objects cached on LIB |
|
1651 | - foreach (array('LIB', 'modules') as $cache) { |
|
1652 | - foreach ($instance->{$cache} as $class_name => $class) { |
|
1653 | - if (self::_reset_and_unset_object($class, $reset_models)) { |
|
1654 | - unset($instance->{$cache}->{$class_name}); |
|
1655 | - } |
|
1656 | - } |
|
1657 | - } |
|
1658 | - return $instance; |
|
1659 | - } |
|
1660 | - |
|
1661 | - |
|
1662 | - /** |
|
1663 | - * if passed object implements ResettableInterface, then call it's reset() method |
|
1664 | - * if passed object implements InterminableInterface, then return false, |
|
1665 | - * to indicate that it should NOT be cleared from the Registry cache |
|
1666 | - * |
|
1667 | - * @param $object |
|
1668 | - * @param bool $reset_models |
|
1669 | - * @return bool returns true if cached object should be unset |
|
1670 | - */ |
|
1671 | - private static function _reset_and_unset_object($object, $reset_models) |
|
1672 | - { |
|
1673 | - if (! is_object($object)) { |
|
1674 | - // don't unset anything that's not an object |
|
1675 | - return false; |
|
1676 | - } |
|
1677 | - if ($object instanceof EED_Module) { |
|
1678 | - $object::reset(); |
|
1679 | - // don't unset modules |
|
1680 | - return false; |
|
1681 | - } |
|
1682 | - if ($object instanceof ResettableInterface) { |
|
1683 | - if ($object instanceof EEM_Base) { |
|
1684 | - if ($reset_models) { |
|
1685 | - $object->reset(); |
|
1686 | - return true; |
|
1687 | - } |
|
1688 | - return false; |
|
1689 | - } |
|
1690 | - $object->reset(); |
|
1691 | - return true; |
|
1692 | - } |
|
1693 | - if (! $object instanceof InterminableInterface) { |
|
1694 | - return true; |
|
1695 | - } |
|
1696 | - return false; |
|
1697 | - } |
|
1698 | - |
|
1699 | - |
|
1700 | - /** |
|
1701 | - * Gets all the custom post type models defined |
|
1702 | - * |
|
1703 | - * @return array keys are model "short names" (Eg "Event") and keys are classnames (eg "EEM_Event") |
|
1704 | - */ |
|
1705 | - public function cpt_models() |
|
1706 | - { |
|
1707 | - $cpt_models = array(); |
|
1708 | - foreach ($this->non_abstract_db_models as $short_name => $classname) { |
|
1709 | - if (is_subclass_of($classname, 'EEM_CPT_Base')) { |
|
1710 | - $cpt_models[ $short_name ] = $classname; |
|
1711 | - } |
|
1712 | - } |
|
1713 | - return $cpt_models; |
|
1714 | - } |
|
1715 | - |
|
1716 | - |
|
1717 | - /** |
|
1718 | - * @return \EE_Config |
|
1719 | - */ |
|
1720 | - public static function CFG() |
|
1721 | - { |
|
1722 | - return self::instance()->CFG; |
|
1723 | - } |
|
1724 | - |
|
1725 | - |
|
1726 | - /** |
|
1727 | - * @deprecated 4.9.62.p |
|
1728 | - * @param string $class_name |
|
1729 | - * @return ReflectionClass |
|
1730 | - * @throws ReflectionException |
|
1731 | - * @throws InvalidDataTypeException |
|
1732 | - */ |
|
1733 | - public function get_ReflectionClass($class_name) |
|
1734 | - { |
|
1735 | - return $this->mirror->getReflectionClass($class_name); |
|
1736 | - } |
|
1737 | - |
|
1738 | - private function parameterIsPrimitive(?string $param_class): bool |
|
1739 | - { |
|
1740 | - return in_array( |
|
1741 | - $param_class, |
|
1742 | - [ |
|
1743 | - 'array', |
|
1744 | - 'bool', |
|
1745 | - 'float', |
|
1746 | - 'int', |
|
1747 | - 'string', |
|
1748 | - ] |
|
1749 | - ); |
|
1750 | - } |
|
982 | + ! $this->object_identifier->hasArguments($object_identifier) |
|
983 | + // but previously cached class with args was found |
|
984 | + && $this->object_identifier->fqcnMatchesObjectIdentifier($class_name, $key) |
|
985 | + ) { |
|
986 | + return $object; |
|
987 | + } |
|
988 | + } |
|
989 | + return null; |
|
990 | + } |
|
991 | + |
|
992 | + |
|
993 | + /** |
|
994 | + * removes a cached version of the requested class |
|
995 | + * |
|
996 | + * @param string $class_name |
|
997 | + * @param boolean $addon |
|
998 | + * @param array $arguments |
|
999 | + * @return boolean |
|
1000 | + */ |
|
1001 | + public function clear_cached_class( |
|
1002 | + $class_name, |
|
1003 | + $addon = false, |
|
1004 | + $arguments = array() |
|
1005 | + ) { |
|
1006 | + $class_abbreviation = $this->get_class_abbreviation($class_name); |
|
1007 | + // check if class has already been loaded, and return it if it has been |
|
1008 | + if (isset($this->{$class_abbreviation})) { |
|
1009 | + $this->{$class_abbreviation} = null; |
|
1010 | + return true; |
|
1011 | + } |
|
1012 | + $class_name = str_replace('\\', '_', $class_name); |
|
1013 | + if (isset($this->{$class_name})) { |
|
1014 | + $this->{$class_name} = null; |
|
1015 | + return true; |
|
1016 | + } |
|
1017 | + if ($addon && $this->addons->has($class_name)) { |
|
1018 | + $this->addons->remove($class_name); |
|
1019 | + return true; |
|
1020 | + } |
|
1021 | + $class_name = $this->object_identifier->getIdentifier($class_name, $arguments); |
|
1022 | + if ($this->LIB->has($class_name)) { |
|
1023 | + $this->LIB->remove($class_name); |
|
1024 | + return true; |
|
1025 | + } |
|
1026 | + return false; |
|
1027 | + } |
|
1028 | + |
|
1029 | + |
|
1030 | + /** |
|
1031 | + * _set_cached_class |
|
1032 | + * attempts to cache the instantiated class locally |
|
1033 | + * in one of the following places, in the following order: |
|
1034 | + * $this->{class_abbreviation} ie: $this->CART |
|
1035 | + * $this->{$class_name} ie: $this->Some_Class |
|
1036 | + * $this->addon->{$$class_name} ie: $this->addon->Some_Addon_Class |
|
1037 | + * $this->LIB->{$class_name} ie: $this->LIB->Some_Class |
|
1038 | + * |
|
1039 | + * @param object $class_obj |
|
1040 | + * @param string $class_name |
|
1041 | + * @param string $class_prefix |
|
1042 | + * @param bool $from_db |
|
1043 | + * @param array $arguments |
|
1044 | + * @return void |
|
1045 | + */ |
|
1046 | + protected function _set_cached_class( |
|
1047 | + $class_obj, |
|
1048 | + $class_name, |
|
1049 | + $class_prefix = '', |
|
1050 | + $from_db = false, |
|
1051 | + $arguments = array() |
|
1052 | + ) { |
|
1053 | + if ($class_name === 'EE_Registry' || empty($class_obj)) { |
|
1054 | + return; |
|
1055 | + } |
|
1056 | + // return newly instantiated class |
|
1057 | + $class_abbreviation = $this->get_class_abbreviation($class_name, ''); |
|
1058 | + if ($class_abbreviation) { |
|
1059 | + $this->{$class_abbreviation} = $class_obj; |
|
1060 | + return; |
|
1061 | + } |
|
1062 | + $class_name = str_replace('\\', '_', $class_name); |
|
1063 | + if (property_exists($this, $class_name)) { |
|
1064 | + $this->{$class_name} = $class_obj; |
|
1065 | + return; |
|
1066 | + } |
|
1067 | + if ($class_prefix === 'addon') { |
|
1068 | + $this->addons->add($class_name, $class_obj); |
|
1069 | + return; |
|
1070 | + } |
|
1071 | + if (! $from_db) { |
|
1072 | + $class_name = $this->object_identifier->getIdentifier($class_name, $arguments); |
|
1073 | + $this->LIB->add($class_name, $class_obj); |
|
1074 | + } |
|
1075 | + } |
|
1076 | + |
|
1077 | + |
|
1078 | + /** |
|
1079 | + * attempts to find a full valid filepath for the requested class. |
|
1080 | + * loops thru each of the base paths in the $file_paths array and appends : "{classname} . {file type} . php" |
|
1081 | + * then returns that path if the target file has been found and is readable |
|
1082 | + * |
|
1083 | + * @param string $class_name |
|
1084 | + * @param string $type |
|
1085 | + * @param array $file_paths |
|
1086 | + * @return string | bool |
|
1087 | + */ |
|
1088 | + protected function _resolve_path($class_name, $type = '', $file_paths = array()) |
|
1089 | + { |
|
1090 | + // make sure $file_paths is an array |
|
1091 | + $file_paths = is_array($file_paths) |
|
1092 | + ? $file_paths |
|
1093 | + : array($file_paths); |
|
1094 | + // cycle thru paths |
|
1095 | + foreach ($file_paths as $key => $file_path) { |
|
1096 | + // convert all separators to proper /, if no filepath, then use EE_CLASSES |
|
1097 | + $file_path = $file_path |
|
1098 | + ? str_replace(array('/', '\\'), '/', $file_path) |
|
1099 | + : EE_CLASSES; |
|
1100 | + // prep file type |
|
1101 | + $type = ! empty($type) |
|
1102 | + ? trim($type, '.') . '.' |
|
1103 | + : ''; |
|
1104 | + // build full file path |
|
1105 | + $file_paths[ $key ] = rtrim($file_path, '/') . '/' . $class_name . '.' . $type . 'php'; |
|
1106 | + // does the file exist and can be read ? |
|
1107 | + if (is_readable($file_paths[ $key ])) { |
|
1108 | + return $file_paths[ $key ]; |
|
1109 | + } |
|
1110 | + } |
|
1111 | + return false; |
|
1112 | + } |
|
1113 | + |
|
1114 | + |
|
1115 | + /** |
|
1116 | + * basically just performs a require_once() |
|
1117 | + * but with some error handling |
|
1118 | + * |
|
1119 | + * @param string $path |
|
1120 | + * @param string $class_name |
|
1121 | + * @param string $type |
|
1122 | + * @param array $file_paths |
|
1123 | + * @return bool |
|
1124 | + * @throws EE_Error |
|
1125 | + * @throws ReflectionException |
|
1126 | + */ |
|
1127 | + protected function _require_file($path, $class_name, $type = '', $file_paths = array()) |
|
1128 | + { |
|
1129 | + $this->resolve_legacy_class_parent($class_name); |
|
1130 | + // don't give up! you gotta... |
|
1131 | + try { |
|
1132 | + // does the file exist and can it be read ? |
|
1133 | + if (! $path) { |
|
1134 | + // just in case the file has already been autoloaded, |
|
1135 | + // but discrepancies in the naming schema are preventing it from |
|
1136 | + // being loaded via one of the EE_Registry::load_*() methods, |
|
1137 | + // then let's try one last hail mary before throwing an exception |
|
1138 | + // and call class_exists() again, but with autoloading turned ON |
|
1139 | + if (class_exists($class_name)) { |
|
1140 | + return true; |
|
1141 | + } |
|
1142 | + // so sorry, can't find the file |
|
1143 | + throw new EE_Error( |
|
1144 | + sprintf( |
|
1145 | + esc_html__( |
|
1146 | + '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', |
|
1147 | + 'event_espresso' |
|
1148 | + ), |
|
1149 | + trim($type, '.'), |
|
1150 | + $class_name, |
|
1151 | + '<br />' . implode(',<br />', $file_paths) |
|
1152 | + ) |
|
1153 | + ); |
|
1154 | + } |
|
1155 | + // get the file |
|
1156 | + require_once($path); |
|
1157 | + // if the class isn't already declared somewhere |
|
1158 | + if (class_exists($class_name, false) === false) { |
|
1159 | + // so sorry, not a class |
|
1160 | + throw new EE_Error( |
|
1161 | + sprintf( |
|
1162 | + esc_html__( |
|
1163 | + 'The %s file %s does not appear to contain the %s Class.', |
|
1164 | + 'event_espresso' |
|
1165 | + ), |
|
1166 | + $type, |
|
1167 | + $path, |
|
1168 | + $class_name |
|
1169 | + ) |
|
1170 | + ); |
|
1171 | + } |
|
1172 | + } catch (EE_Error $e) { |
|
1173 | + $e->get_error(); |
|
1174 | + return false; |
|
1175 | + } |
|
1176 | + return true; |
|
1177 | + } |
|
1178 | + |
|
1179 | + |
|
1180 | + /** |
|
1181 | + * Some of our legacy classes that extended a parent class would simply use a require() statement |
|
1182 | + * before their class declaration in order to ensure that the parent class was loaded. |
|
1183 | + * This is not ideal, but it's nearly impossible to determine the parent class of a non-namespaced class, |
|
1184 | + * without triggering a fatal error because the parent class has yet to be loaded and therefore doesn't exist. |
|
1185 | + * |
|
1186 | + * @param string $class_name |
|
1187 | + */ |
|
1188 | + protected function resolve_legacy_class_parent($class_name = '') |
|
1189 | + { |
|
1190 | + try { |
|
1191 | + $legacy_parent_class_map = array( |
|
1192 | + 'EE_Payment_Processor' => 'core/business/EE_Processor_Base.class.php', |
|
1193 | + ); |
|
1194 | + if (isset($legacy_parent_class_map[ $class_name ])) { |
|
1195 | + require_once EE_PLUGIN_DIR_PATH . $legacy_parent_class_map[ $class_name ]; |
|
1196 | + } |
|
1197 | + } catch (Exception $exception) { |
|
1198 | + } |
|
1199 | + } |
|
1200 | + |
|
1201 | + |
|
1202 | + /** |
|
1203 | + * _create_object |
|
1204 | + * Attempts to instantiate the requested class via any of the |
|
1205 | + * commonly used instantiation methods employed throughout EE. |
|
1206 | + * The priority for instantiation is as follows: |
|
1207 | + * - abstract classes or any class flagged as "load only" (no instantiation occurs) |
|
1208 | + * - model objects via their 'new_instance_from_db' method |
|
1209 | + * - model objects via their 'new_instance' method |
|
1210 | + * - "singleton" classes" via their 'instance' method |
|
1211 | + * - standard instantiable classes via their __constructor |
|
1212 | + * Prior to instantiation, if the classname exists in the dependency_map, |
|
1213 | + * then the constructor for the requested class will be examined to determine |
|
1214 | + * if any dependencies exist, and if they can be injected. |
|
1215 | + * If so, then those classes will be added to the array of arguments passed to the constructor |
|
1216 | + * |
|
1217 | + * @param string $class_name |
|
1218 | + * @param array $arguments |
|
1219 | + * @param string $type |
|
1220 | + * @param bool $from_db |
|
1221 | + * @return null|object|bool |
|
1222 | + * @throws InvalidArgumentException |
|
1223 | + * @throws InvalidInterfaceException |
|
1224 | + * @throws EE_Error |
|
1225 | + * @throws ReflectionException |
|
1226 | + * @throws InvalidDataTypeException |
|
1227 | + */ |
|
1228 | + protected function _create_object($class_name, $arguments = array(), $type = '', $from_db = false) |
|
1229 | + { |
|
1230 | + // create reflection |
|
1231 | + $reflector = $this->mirror->getReflectionClass($class_name); |
|
1232 | + // make sure arguments are an array |
|
1233 | + $arguments = is_array($arguments) |
|
1234 | + ? $arguments |
|
1235 | + : array($arguments); |
|
1236 | + // and if arguments array is numerically and sequentially indexed, then we want it to remain as is, |
|
1237 | + // else wrap it in an additional array so that it doesn't get split into multiple parameters |
|
1238 | + $arguments = $this->_array_is_numerically_and_sequentially_indexed($arguments) |
|
1239 | + ? $arguments |
|
1240 | + : array($arguments); |
|
1241 | + // attempt to inject dependencies ? |
|
1242 | + if ($this->_dependency_map->has($class_name)) { |
|
1243 | + $arguments = $this->_resolve_dependencies($reflector, $class_name, $arguments); |
|
1244 | + } |
|
1245 | + // instantiate the class if possible |
|
1246 | + if ($reflector->isAbstract()) { |
|
1247 | + // nothing to instantiate, loading file was enough |
|
1248 | + // does not throw an exception so $instantiation_mode is unused |
|
1249 | + // $instantiation_mode = "1) no constructor abstract class"; |
|
1250 | + return true; |
|
1251 | + } |
|
1252 | + if ( |
|
1253 | + empty($arguments) |
|
1254 | + && $this->mirror->getConstructorFromReflection($reflector) === null |
|
1255 | + && $reflector->isInstantiable() |
|
1256 | + ) { |
|
1257 | + // no constructor = static methods only... nothing to instantiate, loading file was enough |
|
1258 | + // $instantiation_mode = "2) no constructor but instantiable"; |
|
1259 | + return $reflector->newInstance(); |
|
1260 | + } |
|
1261 | + if ($from_db && method_exists($class_name, 'new_instance_from_db')) { |
|
1262 | + // $instantiation_mode = "3) new_instance_from_db()"; |
|
1263 | + return call_user_func_array(array($class_name, 'new_instance_from_db'), $arguments); |
|
1264 | + } |
|
1265 | + if (method_exists($class_name, 'new_instance')) { |
|
1266 | + // $instantiation_mode = "4) new_instance()"; |
|
1267 | + return call_user_func_array(array($class_name, 'new_instance'), $arguments); |
|
1268 | + } |
|
1269 | + if (method_exists($class_name, 'instance')) { |
|
1270 | + // $instantiation_mode = "5) instance()"; |
|
1271 | + return call_user_func_array(array($class_name, 'instance'), $arguments); |
|
1272 | + } |
|
1273 | + if ($reflector->isInstantiable()) { |
|
1274 | + $args_passed_count = count($arguments); |
|
1275 | + $args_required_count = count($this->mirror->getRequiredParameters($class_name)); |
|
1276 | + if ($args_passed_count < $args_required_count) { |
|
1277 | + throw new RuntimeException( |
|
1278 | + sprintf( |
|
1279 | + __( |
|
1280 | + 'Invalid arguments supplied for the %1$s class, %2$s were required but %3$s were passed.', |
|
1281 | + 'event_espresso' |
|
1282 | + ), |
|
1283 | + $class_name, |
|
1284 | + $args_required_count, |
|
1285 | + $args_passed_count |
|
1286 | + ) |
|
1287 | + ); |
|
1288 | + } |
|
1289 | + // $instantiation_mode = "6) constructor"; |
|
1290 | + return $reflector->newInstanceArgs($arguments); |
|
1291 | + } |
|
1292 | + // heh ? something's not right ! |
|
1293 | + throw new EE_Error( |
|
1294 | + sprintf( |
|
1295 | + esc_html__('The %s file %s could not be instantiated.', 'event_espresso'), |
|
1296 | + $type, |
|
1297 | + $class_name |
|
1298 | + ) |
|
1299 | + ); |
|
1300 | + } |
|
1301 | + |
|
1302 | + |
|
1303 | + /** |
|
1304 | + * @see http://stackoverflow.com/questions/173400/how-to-check-if-php-array-is-associative-or-sequential |
|
1305 | + * @param array $array |
|
1306 | + * @return bool |
|
1307 | + */ |
|
1308 | + protected function _array_is_numerically_and_sequentially_indexed(array $array) |
|
1309 | + { |
|
1310 | + return ! empty($array) |
|
1311 | + ? array_keys($array) === range(0, count($array) - 1) |
|
1312 | + : true; |
|
1313 | + } |
|
1314 | + |
|
1315 | + |
|
1316 | + /** |
|
1317 | + * _resolve_dependencies |
|
1318 | + * examines the constructor for the requested class to determine |
|
1319 | + * if any dependencies exist, and if they can be injected. |
|
1320 | + * If so, then those classes will be added to the array of arguments passed to the constructor |
|
1321 | + * PLZ NOTE: this is achieved by type hinting the constructor params |
|
1322 | + * For example: |
|
1323 | + * if attempting to load a class "Foo" with the following constructor: |
|
1324 | + * __construct( Bar $bar_class, Fighter $grohl_class ) |
|
1325 | + * then $bar_class and $grohl_class will be added to the $arguments array, |
|
1326 | + * but only IF they are NOT already present in the incoming arguments array, |
|
1327 | + * and the correct classes can be loaded |
|
1328 | + * |
|
1329 | + * @param ReflectionClass $reflector |
|
1330 | + * @param string $class_name |
|
1331 | + * @param array $arguments |
|
1332 | + * @return array |
|
1333 | + * @throws InvalidArgumentException |
|
1334 | + * @throws InvalidDataTypeException |
|
1335 | + * @throws InvalidInterfaceException |
|
1336 | + * @throws ReflectionException |
|
1337 | + */ |
|
1338 | + protected function _resolve_dependencies(ReflectionClass $reflector, $class_name, array $arguments = array()) |
|
1339 | + { |
|
1340 | + // let's examine the constructor |
|
1341 | + $constructor = $this->mirror->getConstructorFromReflection($reflector); |
|
1342 | + // whu? huh? nothing? |
|
1343 | + if (! $constructor) { |
|
1344 | + return $arguments; |
|
1345 | + } |
|
1346 | + // get constructor parameters |
|
1347 | + $params = $this->mirror->getParametersFromReflection($reflector); |
|
1348 | + // and the keys for the incoming arguments array so that we can compare existing arguments with what is expected |
|
1349 | + $argument_keys = array_keys($arguments); |
|
1350 | + // now loop thru all of the constructors expected parameters |
|
1351 | + foreach ($params as $index => $param) { |
|
1352 | + try { |
|
1353 | + // is this a dependency for a specific class ? |
|
1354 | + $param_class = $this->mirror->getParameterClassName($param, $class_name, $index); |
|
1355 | + } catch (ReflectionException $exception) { |
|
1356 | + // uh-oh... most likely a legacy class that has not been autoloaded |
|
1357 | + // let's try to derive the classname from what we have now |
|
1358 | + // and hope that the property var name is close to the class name |
|
1359 | + $param_class = $param->getName(); |
|
1360 | + $param_class = str_replace('_', ' ', $param_class); |
|
1361 | + $param_class = ucwords($param_class); |
|
1362 | + $param_class = str_replace(' ', '_', $param_class); |
|
1363 | + } |
|
1364 | + // BUT WAIT !!! This class may be an alias for something else (or getting replaced at runtime) |
|
1365 | + $param_class = $this->class_cache->isAlias($param_class, $class_name) |
|
1366 | + ? $this->class_cache->getFqnForAlias($param_class, $class_name) |
|
1367 | + : $param_class; |
|
1368 | + if ( |
|
1369 | + // param is not even a class |
|
1370 | + ($param_class === null || $this->parameterIsPrimitive($param_class)) |
|
1371 | + // and something already exists in the incoming arguments for this param |
|
1372 | + && array_key_exists($index, $argument_keys) |
|
1373 | + && array_key_exists($argument_keys[ $index ], $arguments) |
|
1374 | + ) { |
|
1375 | + // so let's skip this argument and move on to the next |
|
1376 | + continue; |
|
1377 | + } |
|
1378 | + if ( |
|
1379 | + // parameter is type hinted as a class, exists as an incoming argument, AND it's the correct class |
|
1380 | + $param_class !== null |
|
1381 | + && isset($argument_keys[ $index ], $arguments[ $argument_keys[ $index ] ]) |
|
1382 | + && $arguments[ $argument_keys[ $index ] ] instanceof $param_class |
|
1383 | + ) { |
|
1384 | + // skip this argument and move on to the next |
|
1385 | + continue; |
|
1386 | + } |
|
1387 | + if ( |
|
1388 | + // parameter is type hinted as a class, and should be injected |
|
1389 | + $param_class !== null |
|
1390 | + && $this->_dependency_map->has_dependency_for_class($class_name, $param_class) |
|
1391 | + ) { |
|
1392 | + $arguments = $this->_resolve_dependency( |
|
1393 | + $class_name, |
|
1394 | + $param_class, |
|
1395 | + $arguments, |
|
1396 | + $index |
|
1397 | + ); |
|
1398 | + } |
|
1399 | + if (empty($arguments[ $index ])) { |
|
1400 | + $default_value = $this->mirror->getParameterDefaultValue( |
|
1401 | + $param, |
|
1402 | + $class_name, |
|
1403 | + $index |
|
1404 | + ); |
|
1405 | + // if there's no default value, and the incoming argument is an array (albeit empty), then use that |
|
1406 | + $arguments[ $index ] = $default_value === null |
|
1407 | + && isset($arguments[ $index ]) |
|
1408 | + && is_array($arguments[ $index ]) |
|
1409 | + ? $arguments[ $index ] |
|
1410 | + : $default_value; |
|
1411 | + } |
|
1412 | + } |
|
1413 | + return $arguments; |
|
1414 | + } |
|
1415 | + |
|
1416 | + |
|
1417 | + /** |
|
1418 | + * @param string $class_name |
|
1419 | + * @param string $param_class |
|
1420 | + * @param array $arguments |
|
1421 | + * @param mixed $index |
|
1422 | + * @return array |
|
1423 | + * @throws InvalidArgumentException |
|
1424 | + * @throws InvalidInterfaceException |
|
1425 | + * @throws InvalidDataTypeException |
|
1426 | + */ |
|
1427 | + protected function _resolve_dependency($class_name, $param_class, $arguments, $index) |
|
1428 | + { |
|
1429 | + $dependency = null; |
|
1430 | + // should dependency be loaded from cache ? |
|
1431 | + $cache_on = $this->_dependency_map->loading_strategy_for_class_dependency( |
|
1432 | + $class_name, |
|
1433 | + $param_class |
|
1434 | + ); |
|
1435 | + $cache_on = $cache_on !== EE_Dependency_Map::load_new_object; |
|
1436 | + // we might have a dependency... |
|
1437 | + // let's MAYBE try and find it in our cache if that's what's been requested |
|
1438 | + $cached_class = $cache_on |
|
1439 | + ? $this->_get_cached_class($param_class) |
|
1440 | + : null; |
|
1441 | + // and grab it if it exists |
|
1442 | + if ($cached_class instanceof $param_class) { |
|
1443 | + $dependency = $cached_class; |
|
1444 | + } elseif ($param_class !== $class_name) { |
|
1445 | + // obtain the loader method from the dependency map |
|
1446 | + $loader = $this->_dependency_map->class_loader($param_class); |
|
1447 | + // is loader a custom closure ? |
|
1448 | + if ($loader instanceof Closure) { |
|
1449 | + $dependency = $loader($arguments); |
|
1450 | + } else { |
|
1451 | + // set the cache on property for the recursive loading call |
|
1452 | + $this->_cache_on = $cache_on; |
|
1453 | + // if not, then let's try and load it via the registry |
|
1454 | + if ($loader && method_exists($this, $loader)) { |
|
1455 | + $dependency = $this->{$loader}($param_class); |
|
1456 | + } else { |
|
1457 | + $dependency = LoaderFactory::getLoader()->load( |
|
1458 | + $param_class, |
|
1459 | + array(), |
|
1460 | + $cache_on |
|
1461 | + ); |
|
1462 | + } |
|
1463 | + } |
|
1464 | + } |
|
1465 | + // did we successfully find the correct dependency ? |
|
1466 | + if ($dependency instanceof $param_class) { |
|
1467 | + // then let's inject it into the incoming array of arguments at the correct location |
|
1468 | + $arguments[ $index ] = $dependency; |
|
1469 | + } |
|
1470 | + return $arguments; |
|
1471 | + } |
|
1472 | + |
|
1473 | + |
|
1474 | + /** |
|
1475 | + * call any loader that's been registered in the EE_Dependency_Map::$_class_loaders array |
|
1476 | + * |
|
1477 | + * @param string $classname PLEASE NOTE: the class name needs to match what's registered |
|
1478 | + * in the EE_Dependency_Map::$_class_loaders array, |
|
1479 | + * including the class prefix, ie: "EE_", "EEM_", "EEH_", etc |
|
1480 | + * @param array $arguments |
|
1481 | + * @return object |
|
1482 | + */ |
|
1483 | + public static function factory($classname, $arguments = array()) |
|
1484 | + { |
|
1485 | + $loader = self::instance()->_dependency_map->class_loader($classname); |
|
1486 | + if ($loader instanceof Closure) { |
|
1487 | + return $loader($arguments); |
|
1488 | + } |
|
1489 | + if (method_exists(self::instance(), $loader)) { |
|
1490 | + return self::instance()->{$loader}($classname, $arguments); |
|
1491 | + } |
|
1492 | + return null; |
|
1493 | + } |
|
1494 | + |
|
1495 | + |
|
1496 | + /** |
|
1497 | + * Gets the addon by its class name |
|
1498 | + * |
|
1499 | + * @param string $class_name |
|
1500 | + * @return EE_Addon |
|
1501 | + */ |
|
1502 | + public function getAddon($class_name) |
|
1503 | + { |
|
1504 | + $class_name = str_replace('\\', '_', $class_name); |
|
1505 | + if (isset($this->addons->{$class_name})) { |
|
1506 | + return $this->addons->{$class_name}; |
|
1507 | + } else { |
|
1508 | + return null; |
|
1509 | + } |
|
1510 | + } |
|
1511 | + |
|
1512 | + |
|
1513 | + /** |
|
1514 | + * removes the addon from the internal cache |
|
1515 | + * |
|
1516 | + * @param string $class_name |
|
1517 | + * @return void |
|
1518 | + */ |
|
1519 | + public function removeAddon($class_name) |
|
1520 | + { |
|
1521 | + $class_name = str_replace('\\', '_', $class_name); |
|
1522 | + $this->addons->remove($class_name); |
|
1523 | + } |
|
1524 | + |
|
1525 | + |
|
1526 | + /** |
|
1527 | + * Gets the addon by its name/slug (not classname. For that, just |
|
1528 | + * use the get_addon() method above |
|
1529 | + * |
|
1530 | + * @param string $name |
|
1531 | + * @return EE_Addon |
|
1532 | + */ |
|
1533 | + public function get_addon_by_name($name) |
|
1534 | + { |
|
1535 | + foreach ($this->addons as $addon) { |
|
1536 | + if ($addon->name() === $name) { |
|
1537 | + return $addon; |
|
1538 | + } |
|
1539 | + } |
|
1540 | + return null; |
|
1541 | + } |
|
1542 | + |
|
1543 | + |
|
1544 | + /** |
|
1545 | + * Gets an array of all the registered addons, where the keys are their names. |
|
1546 | + * (ie, what each returns for their name() function) |
|
1547 | + * They're already available on EE_Registry::instance()->addons as properties, |
|
1548 | + * where each property's name is the addon's classname, |
|
1549 | + * So if you just want to get the addon by classname, |
|
1550 | + * OR use the get_addon() method above. |
|
1551 | + * PLEASE NOTE: |
|
1552 | + * addons with Fully Qualified Class Names |
|
1553 | + * have had the namespace separators converted to underscores, |
|
1554 | + * so a classname like Fully\Qualified\ClassName |
|
1555 | + * would have been converted to Fully_Qualified_ClassName |
|
1556 | + * |
|
1557 | + * @return EE_Addon[] where the KEYS are the addon's name() |
|
1558 | + */ |
|
1559 | + public function get_addons_by_name() |
|
1560 | + { |
|
1561 | + $addons = array(); |
|
1562 | + foreach ($this->addons as $addon) { |
|
1563 | + $addons[ $addon->name() ] = $addon; |
|
1564 | + } |
|
1565 | + return $addons; |
|
1566 | + } |
|
1567 | + |
|
1568 | + |
|
1569 | + /** |
|
1570 | + * Resets the specified model's instance AND makes sure EE_Registry doesn't keep |
|
1571 | + * a stale copy of it around |
|
1572 | + * |
|
1573 | + * @param string $model_name |
|
1574 | + * @return \EEM_Base |
|
1575 | + * @throws \EE_Error |
|
1576 | + */ |
|
1577 | + public function reset_model($model_name) |
|
1578 | + { |
|
1579 | + $model_class_name = strpos($model_name, 'EEM_') !== 0 |
|
1580 | + ? "EEM_{$model_name}" |
|
1581 | + : $model_name; |
|
1582 | + if (! $this->LIB->has($model_class_name)) { |
|
1583 | + return null; |
|
1584 | + } |
|
1585 | + $model = $this->LIB->get($model_class_name); |
|
1586 | + if (! $model instanceof EEM_Base) { |
|
1587 | + return null; |
|
1588 | + } |
|
1589 | + // get that model reset it and make sure we nuke the old reference to it |
|
1590 | + if ($model instanceof $model_class_name && is_callable([$model_class_name, 'reset'])) { |
|
1591 | + $this->LIB->remove($model_class_name); |
|
1592 | + $this->LIB->add($model_class_name, $model->reset()); |
|
1593 | + } else { |
|
1594 | + throw new EE_Error( |
|
1595 | + sprintf( |
|
1596 | + esc_html__('Model %s does not have a method "reset"', 'event_espresso'), |
|
1597 | + $model_name |
|
1598 | + ) |
|
1599 | + ); |
|
1600 | + } |
|
1601 | + return $model; |
|
1602 | + } |
|
1603 | + |
|
1604 | + |
|
1605 | + /** |
|
1606 | + * Resets the registry. |
|
1607 | + * The criteria for what gets reset is based on what can be shared between sites on the same request when |
|
1608 | + * switch_to_blog is used in a multisite install. Here is a list of things that are NOT reset. |
|
1609 | + * - $_dependency_map |
|
1610 | + * - $_class_abbreviations |
|
1611 | + * - $NET_CFG (EE_Network_Config): The config is shared network wide so no need to reset. |
|
1612 | + * - $REQ: Still on the same request so no need to change. |
|
1613 | + * - $CAP: There is no site specific state in the EE_Capability class. |
|
1614 | + * - $SSN: Although ideally, the session should not be shared between site switches, we can't reset it because only |
|
1615 | + * one Session can be active in a single request. Resetting could resolve in "headers already sent" errors. |
|
1616 | + * - $addons: In multisite, the state of the addons is something controlled via hooks etc in a normal request. So |
|
1617 | + * for now, we won't reset the addons because it could break calls to an add-ons class/methods in the |
|
1618 | + * switch or on the restore. |
|
1619 | + * - $modules |
|
1620 | + * - $shortcodes |
|
1621 | + * - $widgets |
|
1622 | + * |
|
1623 | + * @param boolean $hard [deprecated] |
|
1624 | + * @param boolean $reinstantiate whether to create new instances of EE_Registry's singletons too, |
|
1625 | + * or just reset without re-instantiating (handy to set to FALSE if you're not |
|
1626 | + * sure if you CAN currently reinstantiate the singletons at the moment) |
|
1627 | + * @param bool $reset_models Defaults to true. When false, then the models are not reset. This is so |
|
1628 | + * client |
|
1629 | + * code instead can just change the model context to a different blog id if |
|
1630 | + * necessary |
|
1631 | + * @return EE_Registry |
|
1632 | + * @throws InvalidInterfaceException |
|
1633 | + * @throws InvalidDataTypeException |
|
1634 | + * @throws EE_Error |
|
1635 | + * @throws ReflectionException |
|
1636 | + * @throws InvalidArgumentException |
|
1637 | + */ |
|
1638 | + public static function reset($hard = false, $reinstantiate = true, $reset_models = true) |
|
1639 | + { |
|
1640 | + $instance = self::instance(); |
|
1641 | + $instance->_cache_on = true; |
|
1642 | + // reset some "special" classes |
|
1643 | + EEH_Activation::reset(); |
|
1644 | + $hard = apply_filters('FHEE__EE_Registry__reset__hard', $hard); |
|
1645 | + $instance->CFG = EE_Config::reset($hard, $reinstantiate); |
|
1646 | + $instance->CART = null; |
|
1647 | + $instance->MRM = null; |
|
1648 | + // messages reset |
|
1649 | + EED_Messages::reset(); |
|
1650 | + // handle of objects cached on LIB |
|
1651 | + foreach (array('LIB', 'modules') as $cache) { |
|
1652 | + foreach ($instance->{$cache} as $class_name => $class) { |
|
1653 | + if (self::_reset_and_unset_object($class, $reset_models)) { |
|
1654 | + unset($instance->{$cache}->{$class_name}); |
|
1655 | + } |
|
1656 | + } |
|
1657 | + } |
|
1658 | + return $instance; |
|
1659 | + } |
|
1660 | + |
|
1661 | + |
|
1662 | + /** |
|
1663 | + * if passed object implements ResettableInterface, then call it's reset() method |
|
1664 | + * if passed object implements InterminableInterface, then return false, |
|
1665 | + * to indicate that it should NOT be cleared from the Registry cache |
|
1666 | + * |
|
1667 | + * @param $object |
|
1668 | + * @param bool $reset_models |
|
1669 | + * @return bool returns true if cached object should be unset |
|
1670 | + */ |
|
1671 | + private static function _reset_and_unset_object($object, $reset_models) |
|
1672 | + { |
|
1673 | + if (! is_object($object)) { |
|
1674 | + // don't unset anything that's not an object |
|
1675 | + return false; |
|
1676 | + } |
|
1677 | + if ($object instanceof EED_Module) { |
|
1678 | + $object::reset(); |
|
1679 | + // don't unset modules |
|
1680 | + return false; |
|
1681 | + } |
|
1682 | + if ($object instanceof ResettableInterface) { |
|
1683 | + if ($object instanceof EEM_Base) { |
|
1684 | + if ($reset_models) { |
|
1685 | + $object->reset(); |
|
1686 | + return true; |
|
1687 | + } |
|
1688 | + return false; |
|
1689 | + } |
|
1690 | + $object->reset(); |
|
1691 | + return true; |
|
1692 | + } |
|
1693 | + if (! $object instanceof InterminableInterface) { |
|
1694 | + return true; |
|
1695 | + } |
|
1696 | + return false; |
|
1697 | + } |
|
1698 | + |
|
1699 | + |
|
1700 | + /** |
|
1701 | + * Gets all the custom post type models defined |
|
1702 | + * |
|
1703 | + * @return array keys are model "short names" (Eg "Event") and keys are classnames (eg "EEM_Event") |
|
1704 | + */ |
|
1705 | + public function cpt_models() |
|
1706 | + { |
|
1707 | + $cpt_models = array(); |
|
1708 | + foreach ($this->non_abstract_db_models as $short_name => $classname) { |
|
1709 | + if (is_subclass_of($classname, 'EEM_CPT_Base')) { |
|
1710 | + $cpt_models[ $short_name ] = $classname; |
|
1711 | + } |
|
1712 | + } |
|
1713 | + return $cpt_models; |
|
1714 | + } |
|
1715 | + |
|
1716 | + |
|
1717 | + /** |
|
1718 | + * @return \EE_Config |
|
1719 | + */ |
|
1720 | + public static function CFG() |
|
1721 | + { |
|
1722 | + return self::instance()->CFG; |
|
1723 | + } |
|
1724 | + |
|
1725 | + |
|
1726 | + /** |
|
1727 | + * @deprecated 4.9.62.p |
|
1728 | + * @param string $class_name |
|
1729 | + * @return ReflectionClass |
|
1730 | + * @throws ReflectionException |
|
1731 | + * @throws InvalidDataTypeException |
|
1732 | + */ |
|
1733 | + public function get_ReflectionClass($class_name) |
|
1734 | + { |
|
1735 | + return $this->mirror->getReflectionClass($class_name); |
|
1736 | + } |
|
1737 | + |
|
1738 | + private function parameterIsPrimitive(?string $param_class): bool |
|
1739 | + { |
|
1740 | + return in_array( |
|
1741 | + $param_class, |
|
1742 | + [ |
|
1743 | + 'array', |
|
1744 | + 'bool', |
|
1745 | + 'float', |
|
1746 | + 'int', |
|
1747 | + 'string', |
|
1748 | + ] |
|
1749 | + ); |
|
1750 | + } |
|
1751 | 1751 | } |
@@ -309,7 +309,7 @@ discard block |
||
309 | 309 | foreach ($i18n_js_strings as $key => $value) { |
310 | 310 | if (is_scalar($value)) { |
311 | 311 | $decoded_value = html_entity_decode((string) $value, ENT_QUOTES, 'UTF-8'); |
312 | - $i18n_js_strings[ $key ] = wp_strip_all_tags($decoded_value); |
|
312 | + $i18n_js_strings[$key] = wp_strip_all_tags($decoded_value); |
|
313 | 313 | } |
314 | 314 | } |
315 | 315 | return $i18n_js_strings; |
@@ -324,7 +324,7 @@ discard block |
||
324 | 324 | public static function localize_i18n_js_strings() |
325 | 325 | { |
326 | 326 | $i18n_js_strings = EE_Registry::sanitize_i18n_js_strings(); |
327 | - return '/* <![CDATA[ */ var eei18n = ' . wp_json_encode($i18n_js_strings) . '; /* ]]> */'; |
|
327 | + return '/* <![CDATA[ */ var eei18n = '.wp_json_encode($i18n_js_strings).'; /* ]]> */'; |
|
328 | 328 | } |
329 | 329 | |
330 | 330 | |
@@ -343,7 +343,7 @@ discard block |
||
343 | 343 | $module_class = get_class($module); |
344 | 344 | $this->modules->add($module_class, $module); |
345 | 345 | } else { |
346 | - if (! class_exists('EE_Module_Request_Router', false)) { |
|
346 | + if ( ! class_exists('EE_Module_Request_Router', false)) { |
|
347 | 347 | $this->load_core('Module_Request_Router'); |
348 | 348 | } |
349 | 349 | EE_Module_Request_Router::module_factory($module); |
@@ -382,10 +382,10 @@ discard block |
||
382 | 382 | EE_CORE, |
383 | 383 | EE_ADMIN, |
384 | 384 | EE_CPTS, |
385 | - EE_CORE . 'CPTs/', |
|
386 | - EE_CORE . 'data_migration_scripts/', |
|
387 | - EE_CORE . 'request_stack/', |
|
388 | - EE_CORE . 'middleware/', |
|
385 | + EE_CORE.'CPTs/', |
|
386 | + EE_CORE.'data_migration_scripts/', |
|
387 | + EE_CORE.'request_stack/', |
|
388 | + EE_CORE.'middleware/', |
|
389 | 389 | ) |
390 | 390 | ); |
391 | 391 | // retrieve instantiated class |
@@ -420,7 +420,7 @@ discard block |
||
420 | 420 | $service_paths = apply_filters( |
421 | 421 | 'FHEE__EE_Registry__load_service__service_paths', |
422 | 422 | array( |
423 | - EE_CORE . 'services/', |
|
423 | + EE_CORE.'services/', |
|
424 | 424 | ) |
425 | 425 | ); |
426 | 426 | // retrieve instantiated class |
@@ -555,10 +555,10 @@ discard block |
||
555 | 555 | { |
556 | 556 | $paths = array( |
557 | 557 | EE_LIBRARIES, |
558 | - EE_LIBRARIES . 'messages/', |
|
559 | - EE_LIBRARIES . 'shortcodes/', |
|
560 | - EE_LIBRARIES . 'qtips/', |
|
561 | - EE_LIBRARIES . 'payment_methods/', |
|
558 | + EE_LIBRARIES.'messages/', |
|
559 | + EE_LIBRARIES.'shortcodes/', |
|
560 | + EE_LIBRARIES.'qtips/', |
|
561 | + EE_LIBRARIES.'payment_methods/', |
|
562 | 562 | ); |
563 | 563 | // retrieve instantiated class |
564 | 564 | return $this->_load( |
@@ -626,10 +626,10 @@ discard block |
||
626 | 626 | public function load_model_class($class_name, $arguments = array(), $load_only = true) |
627 | 627 | { |
628 | 628 | $paths = array( |
629 | - EE_MODELS . 'fields/', |
|
630 | - EE_MODELS . 'helpers/', |
|
631 | - EE_MODELS . 'relations/', |
|
632 | - EE_MODELS . 'strategies/', |
|
629 | + EE_MODELS.'fields/', |
|
630 | + EE_MODELS.'helpers/', |
|
631 | + EE_MODELS.'relations/', |
|
632 | + EE_MODELS.'strategies/', |
|
633 | 633 | ); |
634 | 634 | // retrieve instantiated class |
635 | 635 | return $this->_load( |
@@ -653,7 +653,7 @@ discard block |
||
653 | 653 | */ |
654 | 654 | public function is_model_name($model_name) |
655 | 655 | { |
656 | - return isset($this->models[ $model_name ]); |
|
656 | + return isset($this->models[$model_name]); |
|
657 | 657 | } |
658 | 658 | |
659 | 659 | |
@@ -774,7 +774,7 @@ discard block |
||
774 | 774 | return $cached_class; |
775 | 775 | } |
776 | 776 | }// obtain the loader method from the dependency map |
777 | - $loader = $this->_dependency_map->class_loader($class_name);// instantiate the requested object |
|
777 | + $loader = $this->_dependency_map->class_loader($class_name); // instantiate the requested object |
|
778 | 778 | if ($loader instanceof Closure) { |
779 | 779 | $class_obj = $loader($arguments); |
780 | 780 | } else { |
@@ -816,7 +816,7 @@ discard block |
||
816 | 816 | case 1: |
817 | 817 | // if it's a FQCN then maybe the class is registered with a preceding \ |
818 | 818 | $class_name = strpos($class_name, '\\') !== false |
819 | - ? '\\' . ltrim($class_name, '\\') |
|
819 | + ? '\\'.ltrim($class_name, '\\') |
|
820 | 820 | : $class_name; |
821 | 821 | break; |
822 | 822 | case 2: |
@@ -870,11 +870,11 @@ discard block |
||
870 | 870 | // strip php file extension |
871 | 871 | $class_name = str_replace('.php', '', trim($class_name)); |
872 | 872 | // does the class have a prefix ? |
873 | - if (! empty($class_prefix) && $class_prefix !== 'addon') { |
|
873 | + if ( ! empty($class_prefix) && $class_prefix !== 'addon') { |
|
874 | 874 | // make sure $class_prefix is uppercase |
875 | 875 | $class_prefix = strtoupper(trim($class_prefix)); |
876 | 876 | // add class prefix ONCE!!! |
877 | - $class_name = $class_prefix . str_replace($class_prefix, '', $class_name); |
|
877 | + $class_name = $class_prefix.str_replace($class_prefix, '', $class_name); |
|
878 | 878 | } |
879 | 879 | $class_name = $this->class_cache->getFqnForAlias($class_name); |
880 | 880 | $class_exists = class_exists($class_name, false); |
@@ -894,7 +894,7 @@ discard block |
||
894 | 894 | } |
895 | 895 | } |
896 | 896 | // if the class doesn't already exist.. then we need to try and find the file and load it |
897 | - if (! $class_exists) { |
|
897 | + if ( ! $class_exists) { |
|
898 | 898 | // get full path to file |
899 | 899 | $path = $this->_resolve_path($class_name, $type, $file_paths); |
900 | 900 | // load the file |
@@ -905,7 +905,7 @@ discard block |
||
905 | 905 | return $loaded; |
906 | 906 | } |
907 | 907 | // if an object was expected but loading failed, then return nothing |
908 | - if (! $loaded) { |
|
908 | + if ( ! $loaded) { |
|
909 | 909 | return null; |
910 | 910 | } |
911 | 911 | } |
@@ -933,8 +933,8 @@ discard block |
||
933 | 933 | */ |
934 | 934 | protected function get_class_abbreviation($class_name, $default = 'FANCY_BATMAN_PANTS') |
935 | 935 | { |
936 | - return isset($this->_class_abbreviations[ $class_name ]) |
|
937 | - ? $this->_class_abbreviations[ $class_name ] |
|
936 | + return isset($this->_class_abbreviations[$class_name]) |
|
937 | + ? $this->_class_abbreviations[$class_name] |
|
938 | 938 | : $default; |
939 | 939 | } |
940 | 940 | |
@@ -1068,7 +1068,7 @@ discard block |
||
1068 | 1068 | $this->addons->add($class_name, $class_obj); |
1069 | 1069 | return; |
1070 | 1070 | } |
1071 | - if (! $from_db) { |
|
1071 | + if ( ! $from_db) { |
|
1072 | 1072 | $class_name = $this->object_identifier->getIdentifier($class_name, $arguments); |
1073 | 1073 | $this->LIB->add($class_name, $class_obj); |
1074 | 1074 | } |
@@ -1099,13 +1099,13 @@ discard block |
||
1099 | 1099 | : EE_CLASSES; |
1100 | 1100 | // prep file type |
1101 | 1101 | $type = ! empty($type) |
1102 | - ? trim($type, '.') . '.' |
|
1102 | + ? trim($type, '.').'.' |
|
1103 | 1103 | : ''; |
1104 | 1104 | // build full file path |
1105 | - $file_paths[ $key ] = rtrim($file_path, '/') . '/' . $class_name . '.' . $type . 'php'; |
|
1105 | + $file_paths[$key] = rtrim($file_path, '/').'/'.$class_name.'.'.$type.'php'; |
|
1106 | 1106 | // does the file exist and can be read ? |
1107 | - if (is_readable($file_paths[ $key ])) { |
|
1108 | - return $file_paths[ $key ]; |
|
1107 | + if (is_readable($file_paths[$key])) { |
|
1108 | + return $file_paths[$key]; |
|
1109 | 1109 | } |
1110 | 1110 | } |
1111 | 1111 | return false; |
@@ -1130,7 +1130,7 @@ discard block |
||
1130 | 1130 | // don't give up! you gotta... |
1131 | 1131 | try { |
1132 | 1132 | // does the file exist and can it be read ? |
1133 | - if (! $path) { |
|
1133 | + if ( ! $path) { |
|
1134 | 1134 | // just in case the file has already been autoloaded, |
1135 | 1135 | // but discrepancies in the naming schema are preventing it from |
1136 | 1136 | // being loaded via one of the EE_Registry::load_*() methods, |
@@ -1148,7 +1148,7 @@ discard block |
||
1148 | 1148 | ), |
1149 | 1149 | trim($type, '.'), |
1150 | 1150 | $class_name, |
1151 | - '<br />' . implode(',<br />', $file_paths) |
|
1151 | + '<br />'.implode(',<br />', $file_paths) |
|
1152 | 1152 | ) |
1153 | 1153 | ); |
1154 | 1154 | } |
@@ -1191,8 +1191,8 @@ discard block |
||
1191 | 1191 | $legacy_parent_class_map = array( |
1192 | 1192 | 'EE_Payment_Processor' => 'core/business/EE_Processor_Base.class.php', |
1193 | 1193 | ); |
1194 | - if (isset($legacy_parent_class_map[ $class_name ])) { |
|
1195 | - require_once EE_PLUGIN_DIR_PATH . $legacy_parent_class_map[ $class_name ]; |
|
1194 | + if (isset($legacy_parent_class_map[$class_name])) { |
|
1195 | + require_once EE_PLUGIN_DIR_PATH.$legacy_parent_class_map[$class_name]; |
|
1196 | 1196 | } |
1197 | 1197 | } catch (Exception $exception) { |
1198 | 1198 | } |
@@ -1340,7 +1340,7 @@ discard block |
||
1340 | 1340 | // let's examine the constructor |
1341 | 1341 | $constructor = $this->mirror->getConstructorFromReflection($reflector); |
1342 | 1342 | // whu? huh? nothing? |
1343 | - if (! $constructor) { |
|
1343 | + if ( ! $constructor) { |
|
1344 | 1344 | return $arguments; |
1345 | 1345 | } |
1346 | 1346 | // get constructor parameters |
@@ -1370,7 +1370,7 @@ discard block |
||
1370 | 1370 | ($param_class === null || $this->parameterIsPrimitive($param_class)) |
1371 | 1371 | // and something already exists in the incoming arguments for this param |
1372 | 1372 | && array_key_exists($index, $argument_keys) |
1373 | - && array_key_exists($argument_keys[ $index ], $arguments) |
|
1373 | + && array_key_exists($argument_keys[$index], $arguments) |
|
1374 | 1374 | ) { |
1375 | 1375 | // so let's skip this argument and move on to the next |
1376 | 1376 | continue; |
@@ -1378,8 +1378,8 @@ discard block |
||
1378 | 1378 | if ( |
1379 | 1379 | // parameter is type hinted as a class, exists as an incoming argument, AND it's the correct class |
1380 | 1380 | $param_class !== null |
1381 | - && isset($argument_keys[ $index ], $arguments[ $argument_keys[ $index ] ]) |
|
1382 | - && $arguments[ $argument_keys[ $index ] ] instanceof $param_class |
|
1381 | + && isset($argument_keys[$index], $arguments[$argument_keys[$index]]) |
|
1382 | + && $arguments[$argument_keys[$index]] instanceof $param_class |
|
1383 | 1383 | ) { |
1384 | 1384 | // skip this argument and move on to the next |
1385 | 1385 | continue; |
@@ -1396,17 +1396,17 @@ discard block |
||
1396 | 1396 | $index |
1397 | 1397 | ); |
1398 | 1398 | } |
1399 | - if (empty($arguments[ $index ])) { |
|
1399 | + if (empty($arguments[$index])) { |
|
1400 | 1400 | $default_value = $this->mirror->getParameterDefaultValue( |
1401 | 1401 | $param, |
1402 | 1402 | $class_name, |
1403 | 1403 | $index |
1404 | 1404 | ); |
1405 | 1405 | // if there's no default value, and the incoming argument is an array (albeit empty), then use that |
1406 | - $arguments[ $index ] = $default_value === null |
|
1407 | - && isset($arguments[ $index ]) |
|
1408 | - && is_array($arguments[ $index ]) |
|
1409 | - ? $arguments[ $index ] |
|
1406 | + $arguments[$index] = $default_value === null |
|
1407 | + && isset($arguments[$index]) |
|
1408 | + && is_array($arguments[$index]) |
|
1409 | + ? $arguments[$index] |
|
1410 | 1410 | : $default_value; |
1411 | 1411 | } |
1412 | 1412 | } |
@@ -1465,7 +1465,7 @@ discard block |
||
1465 | 1465 | // did we successfully find the correct dependency ? |
1466 | 1466 | if ($dependency instanceof $param_class) { |
1467 | 1467 | // then let's inject it into the incoming array of arguments at the correct location |
1468 | - $arguments[ $index ] = $dependency; |
|
1468 | + $arguments[$index] = $dependency; |
|
1469 | 1469 | } |
1470 | 1470 | return $arguments; |
1471 | 1471 | } |
@@ -1560,7 +1560,7 @@ discard block |
||
1560 | 1560 | { |
1561 | 1561 | $addons = array(); |
1562 | 1562 | foreach ($this->addons as $addon) { |
1563 | - $addons[ $addon->name() ] = $addon; |
|
1563 | + $addons[$addon->name()] = $addon; |
|
1564 | 1564 | } |
1565 | 1565 | return $addons; |
1566 | 1566 | } |
@@ -1579,11 +1579,11 @@ discard block |
||
1579 | 1579 | $model_class_name = strpos($model_name, 'EEM_') !== 0 |
1580 | 1580 | ? "EEM_{$model_name}" |
1581 | 1581 | : $model_name; |
1582 | - if (! $this->LIB->has($model_class_name)) { |
|
1582 | + if ( ! $this->LIB->has($model_class_name)) { |
|
1583 | 1583 | return null; |
1584 | 1584 | } |
1585 | 1585 | $model = $this->LIB->get($model_class_name); |
1586 | - if (! $model instanceof EEM_Base) { |
|
1586 | + if ( ! $model instanceof EEM_Base) { |
|
1587 | 1587 | return null; |
1588 | 1588 | } |
1589 | 1589 | // get that model reset it and make sure we nuke the old reference to it |
@@ -1670,7 +1670,7 @@ discard block |
||
1670 | 1670 | */ |
1671 | 1671 | private static function _reset_and_unset_object($object, $reset_models) |
1672 | 1672 | { |
1673 | - if (! is_object($object)) { |
|
1673 | + if ( ! is_object($object)) { |
|
1674 | 1674 | // don't unset anything that's not an object |
1675 | 1675 | return false; |
1676 | 1676 | } |
@@ -1690,7 +1690,7 @@ discard block |
||
1690 | 1690 | $object->reset(); |
1691 | 1691 | return true; |
1692 | 1692 | } |
1693 | - if (! $object instanceof InterminableInterface) { |
|
1693 | + if ( ! $object instanceof InterminableInterface) { |
|
1694 | 1694 | return true; |
1695 | 1695 | } |
1696 | 1696 | return false; |
@@ -1707,7 +1707,7 @@ discard block |
||
1707 | 1707 | $cpt_models = array(); |
1708 | 1708 | foreach ($this->non_abstract_db_models as $short_name => $classname) { |
1709 | 1709 | if (is_subclass_of($classname, 'EEM_CPT_Base')) { |
1710 | - $cpt_models[ $short_name ] = $classname; |
|
1710 | + $cpt_models[$short_name] = $classname; |
|
1711 | 1711 | } |
1712 | 1712 | } |
1713 | 1713 | return $cpt_models; |
@@ -19,355 +19,355 @@ |
||
19 | 19 | class RegistrantData |
20 | 20 | { |
21 | 21 | |
22 | - /** |
|
23 | - * @var int |
|
24 | - */ |
|
25 | - private $attendee_counter = 0; |
|
26 | - |
|
27 | - /** |
|
28 | - * @var array |
|
29 | - */ |
|
30 | - private $registrant_data = []; |
|
31 | - |
|
32 | - /** |
|
33 | - * @var bool |
|
34 | - */ |
|
35 | - private $copy_primary = false; |
|
36 | - |
|
37 | - /** |
|
38 | - * @var array |
|
39 | - */ |
|
40 | - private $required_questions = []; |
|
41 | - |
|
42 | - /** |
|
43 | - * @var EE_Registration[] |
|
44 | - */ |
|
45 | - private $registrations = []; |
|
46 | - |
|
47 | - /** |
|
48 | - * @var EE_Answer[][] |
|
49 | - */ |
|
50 | - private $registrant_answers = []; |
|
51 | - |
|
52 | - /** |
|
53 | - * array for tracking reg form data for the primary registrant |
|
54 | - * |
|
55 | - * @var array |
|
56 | - */ |
|
57 | - private $primary_registrant_data; |
|
58 | - |
|
59 | - /** |
|
60 | - * the attendee object created for the primary registrant |
|
61 | - * |
|
62 | - * @var EE_Attendee |
|
63 | - */ |
|
64 | - private $primary_registrant; |
|
65 | - |
|
66 | - |
|
67 | - /** |
|
68 | - * RegistrantData constructor. |
|
69 | - */ |
|
70 | - public function __construct() |
|
71 | - { |
|
72 | - $this->primary_registrant_data = ['line_item_id' => null,]; |
|
73 | - } |
|
74 | - |
|
75 | - |
|
76 | - /** |
|
77 | - * @param EE_Registration $registration |
|
78 | - * @throws EE_Error |
|
79 | - */ |
|
80 | - public function initializeRegistrantData(EE_Registration $registration): void |
|
81 | - { |
|
82 | - $reg_url_link = $registration->reg_url_link(); |
|
83 | - $this->registrations[ $reg_url_link ] = $registration; |
|
84 | - $this->registrant_answers[ $reg_url_link ] = $registration->answers(); |
|
85 | - $this->registrant_data[ $reg_url_link ] = []; |
|
86 | - $this->attendee_counter++; |
|
87 | - } |
|
88 | - |
|
89 | - |
|
90 | - /** |
|
91 | - * @return int |
|
92 | - */ |
|
93 | - public function attendeeCount(): int |
|
94 | - { |
|
95 | - return $this->attendee_counter; |
|
96 | - } |
|
97 | - |
|
98 | - |
|
99 | - /** |
|
100 | - * @return bool |
|
101 | - */ |
|
102 | - public function copyPrimary(): bool |
|
103 | - { |
|
104 | - return $this->copy_primary; |
|
105 | - } |
|
106 | - |
|
107 | - |
|
108 | - /** |
|
109 | - * @param bool $copy_primary |
|
110 | - */ |
|
111 | - public function setCopyPrimary(bool $copy_primary): void |
|
112 | - { |
|
113 | - $this->copy_primary = filter_var($copy_primary, FILTER_VALIDATE_BOOLEAN); |
|
114 | - } |
|
115 | - |
|
116 | - |
|
117 | - /** |
|
118 | - * @param string $reg_url_link |
|
119 | - * @return array|null |
|
120 | - */ |
|
121 | - public function getRegistrant(string $reg_url_link): ?EE_Registration |
|
122 | - { |
|
123 | - return $this->registrations[ $reg_url_link ] ?? null; |
|
124 | - } |
|
125 | - |
|
126 | - |
|
127 | - /** |
|
128 | - * @param string $reg_url_link |
|
129 | - * @return array|null |
|
130 | - */ |
|
131 | - public function getRegistrantData(string $reg_url_link): ?array |
|
132 | - { |
|
133 | - return $this->registrant_data[ $reg_url_link ] ?? null; |
|
134 | - } |
|
135 | - |
|
136 | - |
|
137 | - /** |
|
138 | - * @param string $reg_url_link |
|
139 | - * @param string $key |
|
140 | - * @param mixed $value |
|
141 | - */ |
|
142 | - public function addRegistrantDataValue(string $reg_url_link, string $key, $value): void |
|
143 | - { |
|
144 | - $this->registrant_data[ $reg_url_link ][ $key ] = $value; |
|
145 | - } |
|
146 | - |
|
147 | - |
|
148 | - /** |
|
149 | - * ensures that all attendees at least have data for first name, last name, and email address |
|
150 | - * |
|
151 | - * @param string $reg_url_link |
|
152 | - * @throws EE_Error |
|
153 | - * @throws ReflectionException |
|
154 | - */ |
|
155 | - public function ensureCriticalRegistrantDataIsSet(string $reg_url_link): void |
|
156 | - { |
|
157 | - if ($this->currentRegistrantIsPrimary()) { |
|
158 | - return; |
|
159 | - } |
|
160 | - // bare minimum critical details include first name, last name, email address |
|
161 | - $critical_attendee_details = ['ATT_fname', 'ATT_lname', 'ATT_email']; |
|
162 | - // add address info to critical details? |
|
163 | - if ( |
|
164 | - apply_filters( |
|
165 | - 'FHEE__EventEspresso_core_domain_services_registration_form_v1_RegistrantData__ensureCriticalRegistrantDataIsSet', |
|
166 | - false |
|
167 | - ) |
|
168 | - ) { |
|
169 | - $critical_attendee_details += [ |
|
170 | - 'ATT_address', |
|
171 | - 'ATT_address2', |
|
172 | - 'ATT_city', |
|
173 | - 'STA_ID', |
|
174 | - 'CNT_ISO', |
|
175 | - 'ATT_zip', |
|
176 | - 'ATT_phone', |
|
177 | - ]; |
|
178 | - } |
|
179 | - foreach ($critical_attendee_details as $critical_attendee_detail) { |
|
180 | - if ( |
|
181 | - ! isset($this->registrant_data[ $reg_url_link ][ $critical_attendee_detail ]) |
|
182 | - || empty($this->registrant_data[ $reg_url_link ][ $critical_attendee_detail ]) |
|
183 | - ) { |
|
184 | - $this->registrant_data[ $reg_url_link ][ $critical_attendee_detail ] = $this->primary_registrant->get( |
|
185 | - $critical_attendee_detail |
|
186 | - ); |
|
187 | - } |
|
188 | - } |
|
189 | - } |
|
190 | - |
|
191 | - |
|
192 | - /** |
|
193 | - * @param string $reg_url_link |
|
194 | - * @param array $registrant_data |
|
195 | - */ |
|
196 | - public function setRegistrantData(string $reg_url_link, array $registrant_data): void |
|
197 | - { |
|
198 | - $this->registrant_data[ $reg_url_link ] = $registrant_data; |
|
199 | - } |
|
200 | - |
|
201 | - |
|
202 | - /** |
|
203 | - * @return array |
|
204 | - */ |
|
205 | - public function getRequiredQuestions(): array |
|
206 | - { |
|
207 | - return $this->required_questions; |
|
208 | - } |
|
209 | - |
|
210 | - |
|
211 | - /** |
|
212 | - * @param string $identifier |
|
213 | - * @param string $required_question |
|
214 | - */ |
|
215 | - public function addRequiredQuestion(string $identifier, string $required_question): void |
|
216 | - { |
|
217 | - $this->required_questions[ $identifier ] = $required_question; |
|
218 | - } |
|
219 | - |
|
220 | - |
|
221 | - /** |
|
222 | - * @return EE_Answer[] |
|
223 | - */ |
|
224 | - public function registrantAnswers(string $reg_url_link): array |
|
225 | - { |
|
226 | - return $this->registrant_answers[ $reg_url_link ] ?? []; |
|
227 | - } |
|
228 | - |
|
229 | - |
|
230 | - /** |
|
231 | - * @param string $reg_url_link |
|
232 | - * @param string $identifier the answer cache ID |
|
233 | - * @param EE_Answer $answer |
|
234 | - */ |
|
235 | - public function addRegistrantAnswer(string $reg_url_link, string $identifier, EE_Answer $answer): void |
|
236 | - { |
|
237 | - $this->registrant_answers[ $reg_url_link ][ $identifier ] = $answer; |
|
238 | - } |
|
239 | - |
|
240 | - |
|
241 | - /** |
|
242 | - * @param string $reg_url_link |
|
243 | - * @param string $identifier |
|
244 | - * @return EE_Answer|null |
|
245 | - */ |
|
246 | - public function getRegistrantAnswer(string $reg_url_link, string $identifier): ?EE_Answer |
|
247 | - { |
|
248 | - return $this->registrant_answers[ $reg_url_link ][ $identifier ] ?? null; |
|
249 | - } |
|
250 | - |
|
251 | - |
|
252 | - |
|
253 | - /** |
|
254 | - * @param string $reg_url_link |
|
255 | - * @param string $identifier |
|
256 | - * @return bool |
|
257 | - */ |
|
258 | - public function registrantAnswerIsObject(string $reg_url_link, string $identifier): bool |
|
259 | - { |
|
260 | - $registrant_answer = $this->getRegistrantAnswer($reg_url_link, $identifier); |
|
261 | - return $registrant_answer instanceof EE_Answer; |
|
262 | - } |
|
263 | - |
|
264 | - |
|
265 | - /** |
|
266 | - * @return array |
|
267 | - */ |
|
268 | - public function primaryRegistrantData(): array |
|
269 | - { |
|
270 | - return $this->primary_registrant_data; |
|
271 | - } |
|
272 | - |
|
273 | - |
|
274 | - /** |
|
275 | - * @param string $key |
|
276 | - * @param mixed $value |
|
277 | - */ |
|
278 | - public function addPrimaryRegistrantDataValue(string $key, $value): void |
|
279 | - { |
|
280 | - $this->primary_registrant_data[ $key ] = $value; |
|
281 | - } |
|
282 | - |
|
283 | - |
|
284 | - /** |
|
285 | - * @param string $key |
|
286 | - * @return mixed |
|
287 | - */ |
|
288 | - public function getPrimaryRegistrantDataValue(string $key) |
|
289 | - { |
|
290 | - return $this->primary_registrant_data[ $key ] ?? null; |
|
291 | - } |
|
292 | - |
|
293 | - |
|
294 | - /** |
|
295 | - * @param array $primary_registrant_data |
|
296 | - */ |
|
297 | - public function setPrimaryRegistrantData(array $primary_registrant_data): void |
|
298 | - { |
|
299 | - $this->primary_registrant_data = $primary_registrant_data; |
|
300 | - } |
|
301 | - |
|
302 | - |
|
303 | - /** |
|
304 | - * @return EE_Attendee |
|
305 | - */ |
|
306 | - public function primaryRegistrant(): EE_Attendee |
|
307 | - { |
|
308 | - return $this->primary_registrant; |
|
309 | - } |
|
310 | - |
|
311 | - |
|
312 | - /** |
|
313 | - * @return bool |
|
314 | - */ |
|
315 | - public function primaryRegistrantIsValid(): bool |
|
316 | - { |
|
317 | - return $this->primary_registrant instanceof EE_Attendee; |
|
318 | - } |
|
319 | - |
|
320 | - |
|
321 | - /** |
|
322 | - * @param EE_Attendee $primary_registrant |
|
323 | - */ |
|
324 | - public function setPrimaryRegistrant(EE_Attendee $primary_registrant): void |
|
325 | - { |
|
326 | - $this->primary_registrant = $primary_registrant; |
|
327 | - } |
|
328 | - |
|
329 | - |
|
330 | - /** |
|
331 | - * @param string $reg_url_link |
|
332 | - * @return bool |
|
333 | - */ |
|
334 | - public function currentRegistrantIsPrimary(string $reg_url_link = ''): bool |
|
335 | - { |
|
336 | - return $this->attendeeCount() === 1 |
|
337 | - || ( |
|
338 | - $this->attendeeCount() === 1 |
|
339 | - && $reg_url_link !== '' |
|
340 | - && $this->getPrimaryRegistrantDataValue('reg_url_link') === $reg_url_link |
|
341 | - ); |
|
342 | - } |
|
343 | - |
|
344 | - |
|
345 | - /** |
|
346 | - * @return bool |
|
347 | - */ |
|
348 | - public function currentRegistrantIsNotPrimary(): bool |
|
349 | - { |
|
350 | - return $this->attendeeCount() > 1; |
|
351 | - } |
|
352 | - |
|
353 | - |
|
354 | - /** |
|
355 | - * @param string $reg_url_link |
|
356 | - * @param string $form_input |
|
357 | - * @param mixed $input_value |
|
358 | - * @return mixed|null |
|
359 | - */ |
|
360 | - public function saveOrCopyPrimaryRegistrantData(string $reg_url_link, string $form_input, $input_value) |
|
361 | - { |
|
362 | - // store a bit of data about the primary attendee |
|
363 | - if (! empty($input_value) && $this->currentRegistrantIsPrimary($reg_url_link)) { |
|
364 | - $this->primary_registrant_data[ $form_input ] = $input_value; |
|
365 | - return $input_value; |
|
366 | - } |
|
367 | - // or copy value from primary if incoming value is not set |
|
368 | - if ($input_value === null && $this->copyPrimary()) { |
|
369 | - $input_value = $this->getPrimaryRegistrantDataValue($form_input); |
|
370 | - } |
|
371 | - return $input_value; |
|
372 | - } |
|
22 | + /** |
|
23 | + * @var int |
|
24 | + */ |
|
25 | + private $attendee_counter = 0; |
|
26 | + |
|
27 | + /** |
|
28 | + * @var array |
|
29 | + */ |
|
30 | + private $registrant_data = []; |
|
31 | + |
|
32 | + /** |
|
33 | + * @var bool |
|
34 | + */ |
|
35 | + private $copy_primary = false; |
|
36 | + |
|
37 | + /** |
|
38 | + * @var array |
|
39 | + */ |
|
40 | + private $required_questions = []; |
|
41 | + |
|
42 | + /** |
|
43 | + * @var EE_Registration[] |
|
44 | + */ |
|
45 | + private $registrations = []; |
|
46 | + |
|
47 | + /** |
|
48 | + * @var EE_Answer[][] |
|
49 | + */ |
|
50 | + private $registrant_answers = []; |
|
51 | + |
|
52 | + /** |
|
53 | + * array for tracking reg form data for the primary registrant |
|
54 | + * |
|
55 | + * @var array |
|
56 | + */ |
|
57 | + private $primary_registrant_data; |
|
58 | + |
|
59 | + /** |
|
60 | + * the attendee object created for the primary registrant |
|
61 | + * |
|
62 | + * @var EE_Attendee |
|
63 | + */ |
|
64 | + private $primary_registrant; |
|
65 | + |
|
66 | + |
|
67 | + /** |
|
68 | + * RegistrantData constructor. |
|
69 | + */ |
|
70 | + public function __construct() |
|
71 | + { |
|
72 | + $this->primary_registrant_data = ['line_item_id' => null,]; |
|
73 | + } |
|
74 | + |
|
75 | + |
|
76 | + /** |
|
77 | + * @param EE_Registration $registration |
|
78 | + * @throws EE_Error |
|
79 | + */ |
|
80 | + public function initializeRegistrantData(EE_Registration $registration): void |
|
81 | + { |
|
82 | + $reg_url_link = $registration->reg_url_link(); |
|
83 | + $this->registrations[ $reg_url_link ] = $registration; |
|
84 | + $this->registrant_answers[ $reg_url_link ] = $registration->answers(); |
|
85 | + $this->registrant_data[ $reg_url_link ] = []; |
|
86 | + $this->attendee_counter++; |
|
87 | + } |
|
88 | + |
|
89 | + |
|
90 | + /** |
|
91 | + * @return int |
|
92 | + */ |
|
93 | + public function attendeeCount(): int |
|
94 | + { |
|
95 | + return $this->attendee_counter; |
|
96 | + } |
|
97 | + |
|
98 | + |
|
99 | + /** |
|
100 | + * @return bool |
|
101 | + */ |
|
102 | + public function copyPrimary(): bool |
|
103 | + { |
|
104 | + return $this->copy_primary; |
|
105 | + } |
|
106 | + |
|
107 | + |
|
108 | + /** |
|
109 | + * @param bool $copy_primary |
|
110 | + */ |
|
111 | + public function setCopyPrimary(bool $copy_primary): void |
|
112 | + { |
|
113 | + $this->copy_primary = filter_var($copy_primary, FILTER_VALIDATE_BOOLEAN); |
|
114 | + } |
|
115 | + |
|
116 | + |
|
117 | + /** |
|
118 | + * @param string $reg_url_link |
|
119 | + * @return array|null |
|
120 | + */ |
|
121 | + public function getRegistrant(string $reg_url_link): ?EE_Registration |
|
122 | + { |
|
123 | + return $this->registrations[ $reg_url_link ] ?? null; |
|
124 | + } |
|
125 | + |
|
126 | + |
|
127 | + /** |
|
128 | + * @param string $reg_url_link |
|
129 | + * @return array|null |
|
130 | + */ |
|
131 | + public function getRegistrantData(string $reg_url_link): ?array |
|
132 | + { |
|
133 | + return $this->registrant_data[ $reg_url_link ] ?? null; |
|
134 | + } |
|
135 | + |
|
136 | + |
|
137 | + /** |
|
138 | + * @param string $reg_url_link |
|
139 | + * @param string $key |
|
140 | + * @param mixed $value |
|
141 | + */ |
|
142 | + public function addRegistrantDataValue(string $reg_url_link, string $key, $value): void |
|
143 | + { |
|
144 | + $this->registrant_data[ $reg_url_link ][ $key ] = $value; |
|
145 | + } |
|
146 | + |
|
147 | + |
|
148 | + /** |
|
149 | + * ensures that all attendees at least have data for first name, last name, and email address |
|
150 | + * |
|
151 | + * @param string $reg_url_link |
|
152 | + * @throws EE_Error |
|
153 | + * @throws ReflectionException |
|
154 | + */ |
|
155 | + public function ensureCriticalRegistrantDataIsSet(string $reg_url_link): void |
|
156 | + { |
|
157 | + if ($this->currentRegistrantIsPrimary()) { |
|
158 | + return; |
|
159 | + } |
|
160 | + // bare minimum critical details include first name, last name, email address |
|
161 | + $critical_attendee_details = ['ATT_fname', 'ATT_lname', 'ATT_email']; |
|
162 | + // add address info to critical details? |
|
163 | + if ( |
|
164 | + apply_filters( |
|
165 | + 'FHEE__EventEspresso_core_domain_services_registration_form_v1_RegistrantData__ensureCriticalRegistrantDataIsSet', |
|
166 | + false |
|
167 | + ) |
|
168 | + ) { |
|
169 | + $critical_attendee_details += [ |
|
170 | + 'ATT_address', |
|
171 | + 'ATT_address2', |
|
172 | + 'ATT_city', |
|
173 | + 'STA_ID', |
|
174 | + 'CNT_ISO', |
|
175 | + 'ATT_zip', |
|
176 | + 'ATT_phone', |
|
177 | + ]; |
|
178 | + } |
|
179 | + foreach ($critical_attendee_details as $critical_attendee_detail) { |
|
180 | + if ( |
|
181 | + ! isset($this->registrant_data[ $reg_url_link ][ $critical_attendee_detail ]) |
|
182 | + || empty($this->registrant_data[ $reg_url_link ][ $critical_attendee_detail ]) |
|
183 | + ) { |
|
184 | + $this->registrant_data[ $reg_url_link ][ $critical_attendee_detail ] = $this->primary_registrant->get( |
|
185 | + $critical_attendee_detail |
|
186 | + ); |
|
187 | + } |
|
188 | + } |
|
189 | + } |
|
190 | + |
|
191 | + |
|
192 | + /** |
|
193 | + * @param string $reg_url_link |
|
194 | + * @param array $registrant_data |
|
195 | + */ |
|
196 | + public function setRegistrantData(string $reg_url_link, array $registrant_data): void |
|
197 | + { |
|
198 | + $this->registrant_data[ $reg_url_link ] = $registrant_data; |
|
199 | + } |
|
200 | + |
|
201 | + |
|
202 | + /** |
|
203 | + * @return array |
|
204 | + */ |
|
205 | + public function getRequiredQuestions(): array |
|
206 | + { |
|
207 | + return $this->required_questions; |
|
208 | + } |
|
209 | + |
|
210 | + |
|
211 | + /** |
|
212 | + * @param string $identifier |
|
213 | + * @param string $required_question |
|
214 | + */ |
|
215 | + public function addRequiredQuestion(string $identifier, string $required_question): void |
|
216 | + { |
|
217 | + $this->required_questions[ $identifier ] = $required_question; |
|
218 | + } |
|
219 | + |
|
220 | + |
|
221 | + /** |
|
222 | + * @return EE_Answer[] |
|
223 | + */ |
|
224 | + public function registrantAnswers(string $reg_url_link): array |
|
225 | + { |
|
226 | + return $this->registrant_answers[ $reg_url_link ] ?? []; |
|
227 | + } |
|
228 | + |
|
229 | + |
|
230 | + /** |
|
231 | + * @param string $reg_url_link |
|
232 | + * @param string $identifier the answer cache ID |
|
233 | + * @param EE_Answer $answer |
|
234 | + */ |
|
235 | + public function addRegistrantAnswer(string $reg_url_link, string $identifier, EE_Answer $answer): void |
|
236 | + { |
|
237 | + $this->registrant_answers[ $reg_url_link ][ $identifier ] = $answer; |
|
238 | + } |
|
239 | + |
|
240 | + |
|
241 | + /** |
|
242 | + * @param string $reg_url_link |
|
243 | + * @param string $identifier |
|
244 | + * @return EE_Answer|null |
|
245 | + */ |
|
246 | + public function getRegistrantAnswer(string $reg_url_link, string $identifier): ?EE_Answer |
|
247 | + { |
|
248 | + return $this->registrant_answers[ $reg_url_link ][ $identifier ] ?? null; |
|
249 | + } |
|
250 | + |
|
251 | + |
|
252 | + |
|
253 | + /** |
|
254 | + * @param string $reg_url_link |
|
255 | + * @param string $identifier |
|
256 | + * @return bool |
|
257 | + */ |
|
258 | + public function registrantAnswerIsObject(string $reg_url_link, string $identifier): bool |
|
259 | + { |
|
260 | + $registrant_answer = $this->getRegistrantAnswer($reg_url_link, $identifier); |
|
261 | + return $registrant_answer instanceof EE_Answer; |
|
262 | + } |
|
263 | + |
|
264 | + |
|
265 | + /** |
|
266 | + * @return array |
|
267 | + */ |
|
268 | + public function primaryRegistrantData(): array |
|
269 | + { |
|
270 | + return $this->primary_registrant_data; |
|
271 | + } |
|
272 | + |
|
273 | + |
|
274 | + /** |
|
275 | + * @param string $key |
|
276 | + * @param mixed $value |
|
277 | + */ |
|
278 | + public function addPrimaryRegistrantDataValue(string $key, $value): void |
|
279 | + { |
|
280 | + $this->primary_registrant_data[ $key ] = $value; |
|
281 | + } |
|
282 | + |
|
283 | + |
|
284 | + /** |
|
285 | + * @param string $key |
|
286 | + * @return mixed |
|
287 | + */ |
|
288 | + public function getPrimaryRegistrantDataValue(string $key) |
|
289 | + { |
|
290 | + return $this->primary_registrant_data[ $key ] ?? null; |
|
291 | + } |
|
292 | + |
|
293 | + |
|
294 | + /** |
|
295 | + * @param array $primary_registrant_data |
|
296 | + */ |
|
297 | + public function setPrimaryRegistrantData(array $primary_registrant_data): void |
|
298 | + { |
|
299 | + $this->primary_registrant_data = $primary_registrant_data; |
|
300 | + } |
|
301 | + |
|
302 | + |
|
303 | + /** |
|
304 | + * @return EE_Attendee |
|
305 | + */ |
|
306 | + public function primaryRegistrant(): EE_Attendee |
|
307 | + { |
|
308 | + return $this->primary_registrant; |
|
309 | + } |
|
310 | + |
|
311 | + |
|
312 | + /** |
|
313 | + * @return bool |
|
314 | + */ |
|
315 | + public function primaryRegistrantIsValid(): bool |
|
316 | + { |
|
317 | + return $this->primary_registrant instanceof EE_Attendee; |
|
318 | + } |
|
319 | + |
|
320 | + |
|
321 | + /** |
|
322 | + * @param EE_Attendee $primary_registrant |
|
323 | + */ |
|
324 | + public function setPrimaryRegistrant(EE_Attendee $primary_registrant): void |
|
325 | + { |
|
326 | + $this->primary_registrant = $primary_registrant; |
|
327 | + } |
|
328 | + |
|
329 | + |
|
330 | + /** |
|
331 | + * @param string $reg_url_link |
|
332 | + * @return bool |
|
333 | + */ |
|
334 | + public function currentRegistrantIsPrimary(string $reg_url_link = ''): bool |
|
335 | + { |
|
336 | + return $this->attendeeCount() === 1 |
|
337 | + || ( |
|
338 | + $this->attendeeCount() === 1 |
|
339 | + && $reg_url_link !== '' |
|
340 | + && $this->getPrimaryRegistrantDataValue('reg_url_link') === $reg_url_link |
|
341 | + ); |
|
342 | + } |
|
343 | + |
|
344 | + |
|
345 | + /** |
|
346 | + * @return bool |
|
347 | + */ |
|
348 | + public function currentRegistrantIsNotPrimary(): bool |
|
349 | + { |
|
350 | + return $this->attendeeCount() > 1; |
|
351 | + } |
|
352 | + |
|
353 | + |
|
354 | + /** |
|
355 | + * @param string $reg_url_link |
|
356 | + * @param string $form_input |
|
357 | + * @param mixed $input_value |
|
358 | + * @return mixed|null |
|
359 | + */ |
|
360 | + public function saveOrCopyPrimaryRegistrantData(string $reg_url_link, string $form_input, $input_value) |
|
361 | + { |
|
362 | + // store a bit of data about the primary attendee |
|
363 | + if (! empty($input_value) && $this->currentRegistrantIsPrimary($reg_url_link)) { |
|
364 | + $this->primary_registrant_data[ $form_input ] = $input_value; |
|
365 | + return $input_value; |
|
366 | + } |
|
367 | + // or copy value from primary if incoming value is not set |
|
368 | + if ($input_value === null && $this->copyPrimary()) { |
|
369 | + $input_value = $this->getPrimaryRegistrantDataValue($form_input); |
|
370 | + } |
|
371 | + return $input_value; |
|
372 | + } |
|
373 | 373 | } |
@@ -7,62 +7,62 @@ |
||
7 | 7 | |
8 | 8 | class RegFormDependencyHandler extends DependencyHandler |
9 | 9 | { |
10 | - /** |
|
11 | - * @return void |
|
12 | - */ |
|
13 | - public function registerDependencies() |
|
14 | - { |
|
15 | - $reg_form_dependencies = [ |
|
16 | - 'EventEspresso\core\domain\services\registration\form\v1\RegForm' => [ |
|
17 | - null, |
|
18 | - 'EE_Registration_Config' => EE_Dependency_Map::load_from_cache, |
|
19 | - ], |
|
20 | - 'EventEspresso\core\domain\services\registration\form\v1\RegistrantForm' => [ |
|
21 | - null, |
|
22 | - null, |
|
23 | - null, |
|
24 | - null, |
|
25 | - null, |
|
26 | - 'EEM_Event_Question_Group' => EE_Dependency_Map::load_from_cache, |
|
27 | - ], |
|
28 | - 'EventEspresso\core\domain\services\registration\form\v1\RegFormQuestionFactory' => [ |
|
29 | - null, |
|
30 | - 'EEM_Answer' => EE_Dependency_Map::load_from_cache, |
|
31 | - ], |
|
32 | - 'EventEspresso\core\domain\services\registration\form\v1\RegFormQuestionGroup' => [ |
|
33 | - null, |
|
34 | - null, |
|
35 | - null, |
|
36 | - 'EventEspresso\core\domain\services\registration\form\v1\RegFormQuestionFactory' => EE_Dependency_Map::load_from_cache, |
|
37 | - ], |
|
38 | - 'EventEspresso\core\domain\services\registration\form\v1\CountryOptions' => [ |
|
39 | - null, |
|
40 | - 'EEM_Answer' => EE_Dependency_Map::load_from_cache, |
|
41 | - 'EEM_Country' => EE_Dependency_Map::load_from_cache, |
|
42 | - ], |
|
43 | - 'EventEspresso\core\domain\services\registration\form\v1\StateOptions' => [ |
|
44 | - null, |
|
45 | - 'EEM_State' => EE_Dependency_Map::load_from_cache, |
|
46 | - ], |
|
47 | - 'EventEspresso\core\domain\services\registration\form\v1\RegFormHandler' => [ |
|
48 | - null, |
|
49 | - 'EventEspresso\core\domain\services\registration\form\v1\RegistrantData' => EE_Dependency_Map::load_from_cache, |
|
50 | - 'EventEspresso\core\domain\services\registration\form\v1\RegFormAttendeeFactory' => EE_Dependency_Map::load_from_cache, |
|
51 | - 'EE_Registration_Processor' => EE_Dependency_Map::load_from_cache, |
|
52 | - ], |
|
53 | - 'EventEspresso\core\domain\services\registration\form\v1\RegFormInputHandler' => [ |
|
54 | - null, |
|
55 | - null, |
|
56 | - 'EEM_Attendee' => EE_Dependency_Map::load_from_cache, |
|
57 | - 'EventEspresso\core\domain\services\registration\form\v1\RegistrantData' => EE_Dependency_Map::load_from_cache, |
|
58 | - ], |
|
59 | - 'EventEspresso\core\domain\services\registration\form\v1\RegFormAttendeeFactory' => [ |
|
60 | - 'EventEspresso\core\services\commands\CommandBus' => EE_Dependency_Map::load_from_cache, |
|
61 | - 'EventEspresso\core\domain\services\registration\form\v1\RegistrantData' => EE_Dependency_Map::load_from_cache, |
|
62 | - ], |
|
63 | - ]; |
|
64 | - foreach ($reg_form_dependencies as $class => $dependencies) { |
|
65 | - $this->dependency_map->registerDependencies($class, $dependencies); |
|
66 | - } |
|
67 | - } |
|
10 | + /** |
|
11 | + * @return void |
|
12 | + */ |
|
13 | + public function registerDependencies() |
|
14 | + { |
|
15 | + $reg_form_dependencies = [ |
|
16 | + 'EventEspresso\core\domain\services\registration\form\v1\RegForm' => [ |
|
17 | + null, |
|
18 | + 'EE_Registration_Config' => EE_Dependency_Map::load_from_cache, |
|
19 | + ], |
|
20 | + 'EventEspresso\core\domain\services\registration\form\v1\RegistrantForm' => [ |
|
21 | + null, |
|
22 | + null, |
|
23 | + null, |
|
24 | + null, |
|
25 | + null, |
|
26 | + 'EEM_Event_Question_Group' => EE_Dependency_Map::load_from_cache, |
|
27 | + ], |
|
28 | + 'EventEspresso\core\domain\services\registration\form\v1\RegFormQuestionFactory' => [ |
|
29 | + null, |
|
30 | + 'EEM_Answer' => EE_Dependency_Map::load_from_cache, |
|
31 | + ], |
|
32 | + 'EventEspresso\core\domain\services\registration\form\v1\RegFormQuestionGroup' => [ |
|
33 | + null, |
|
34 | + null, |
|
35 | + null, |
|
36 | + 'EventEspresso\core\domain\services\registration\form\v1\RegFormQuestionFactory' => EE_Dependency_Map::load_from_cache, |
|
37 | + ], |
|
38 | + 'EventEspresso\core\domain\services\registration\form\v1\CountryOptions' => [ |
|
39 | + null, |
|
40 | + 'EEM_Answer' => EE_Dependency_Map::load_from_cache, |
|
41 | + 'EEM_Country' => EE_Dependency_Map::load_from_cache, |
|
42 | + ], |
|
43 | + 'EventEspresso\core\domain\services\registration\form\v1\StateOptions' => [ |
|
44 | + null, |
|
45 | + 'EEM_State' => EE_Dependency_Map::load_from_cache, |
|
46 | + ], |
|
47 | + 'EventEspresso\core\domain\services\registration\form\v1\RegFormHandler' => [ |
|
48 | + null, |
|
49 | + 'EventEspresso\core\domain\services\registration\form\v1\RegistrantData' => EE_Dependency_Map::load_from_cache, |
|
50 | + 'EventEspresso\core\domain\services\registration\form\v1\RegFormAttendeeFactory' => EE_Dependency_Map::load_from_cache, |
|
51 | + 'EE_Registration_Processor' => EE_Dependency_Map::load_from_cache, |
|
52 | + ], |
|
53 | + 'EventEspresso\core\domain\services\registration\form\v1\RegFormInputHandler' => [ |
|
54 | + null, |
|
55 | + null, |
|
56 | + 'EEM_Attendee' => EE_Dependency_Map::load_from_cache, |
|
57 | + 'EventEspresso\core\domain\services\registration\form\v1\RegistrantData' => EE_Dependency_Map::load_from_cache, |
|
58 | + ], |
|
59 | + 'EventEspresso\core\domain\services\registration\form\v1\RegFormAttendeeFactory' => [ |
|
60 | + 'EventEspresso\core\services\commands\CommandBus' => EE_Dependency_Map::load_from_cache, |
|
61 | + 'EventEspresso\core\domain\services\registration\form\v1\RegistrantData' => EE_Dependency_Map::load_from_cache, |
|
62 | + ], |
|
63 | + ]; |
|
64 | + foreach ($reg_form_dependencies as $class => $dependencies) { |
|
65 | + $this->dependency_map->registerDependencies($class, $dependencies); |
|
66 | + } |
|
67 | + } |
|
68 | 68 | } |
@@ -18,310 +18,310 @@ |
||
18 | 18 | class RegFormHandler |
19 | 19 | { |
20 | 20 | |
21 | - /** |
|
22 | - * @var EE_Checkout |
|
23 | - */ |
|
24 | - public $checkout; |
|
21 | + /** |
|
22 | + * @var EE_Checkout |
|
23 | + */ |
|
24 | + public $checkout; |
|
25 | 25 | |
26 | - /** |
|
27 | - * @var RegFormInputHandler |
|
28 | - */ |
|
29 | - public $input_handler; |
|
26 | + /** |
|
27 | + * @var RegFormInputHandler |
|
28 | + */ |
|
29 | + public $input_handler; |
|
30 | 30 | |
31 | - /** |
|
32 | - * @var array |
|
33 | - */ |
|
34 | - private $non_input_form_sections; |
|
31 | + /** |
|
32 | + * @var array |
|
33 | + */ |
|
34 | + private $non_input_form_sections; |
|
35 | 35 | |
36 | - /** |
|
37 | - * @var RegFormAttendeeFactory |
|
38 | - */ |
|
39 | - private $attendee_factory; |
|
36 | + /** |
|
37 | + * @var RegFormAttendeeFactory |
|
38 | + */ |
|
39 | + private $attendee_factory; |
|
40 | 40 | |
41 | - /** |
|
42 | - * @var RegistrantData |
|
43 | - */ |
|
44 | - private $registrant_data; |
|
41 | + /** |
|
42 | + * @var RegistrantData |
|
43 | + */ |
|
44 | + private $registrant_data; |
|
45 | 45 | |
46 | - /** |
|
47 | - * @var EE_Registration_Processor |
|
48 | - */ |
|
49 | - private $registration_processor; |
|
46 | + /** |
|
47 | + * @var EE_Registration_Processor |
|
48 | + */ |
|
49 | + private $registration_processor; |
|
50 | 50 | |
51 | - /** |
|
52 | - * @var bool |
|
53 | - */ |
|
54 | - private $valid; |
|
51 | + /** |
|
52 | + * @var bool |
|
53 | + */ |
|
54 | + private $valid; |
|
55 | 55 | |
56 | 56 | |
57 | - /** |
|
58 | - * RegFormHandler constructor. |
|
59 | - */ |
|
60 | - public function __construct( |
|
61 | - EE_Checkout $checkout, |
|
62 | - RegistrantData $registrant_data, |
|
63 | - RegFormAttendeeFactory $attendee_factory, |
|
64 | - EE_Registration_Processor $registration_processor |
|
65 | - ) { |
|
66 | - $this->checkout = $checkout; |
|
67 | - $this->registrant_data = $registrant_data; |
|
68 | - $this->attendee_factory = $attendee_factory; |
|
69 | - $this->registration_processor = $registration_processor; |
|
70 | - // reg form sections that do not contain inputs |
|
71 | - $this->non_input_form_sections = [ |
|
72 | - 'primary_registrant', |
|
73 | - 'additional_attendee_reg_info', |
|
74 | - 'spco_copy_attendee_chk', |
|
75 | - ]; |
|
76 | - $this->initializeInputHandler(); |
|
77 | - } |
|
57 | + /** |
|
58 | + * RegFormHandler constructor. |
|
59 | + */ |
|
60 | + public function __construct( |
|
61 | + EE_Checkout $checkout, |
|
62 | + RegistrantData $registrant_data, |
|
63 | + RegFormAttendeeFactory $attendee_factory, |
|
64 | + EE_Registration_Processor $registration_processor |
|
65 | + ) { |
|
66 | + $this->checkout = $checkout; |
|
67 | + $this->registrant_data = $registrant_data; |
|
68 | + $this->attendee_factory = $attendee_factory; |
|
69 | + $this->registration_processor = $registration_processor; |
|
70 | + // reg form sections that do not contain inputs |
|
71 | + $this->non_input_form_sections = [ |
|
72 | + 'primary_registrant', |
|
73 | + 'additional_attendee_reg_info', |
|
74 | + 'spco_copy_attendee_chk', |
|
75 | + ]; |
|
76 | + $this->initializeInputHandler(); |
|
77 | + } |
|
78 | 78 | |
79 | 79 | |
80 | - private function initializeInputHandler() |
|
81 | - { |
|
82 | - $reg_form = $this->checkout->current_step->reg_form; |
|
83 | - $required_questions = $reg_form instanceof RegForm ? $reg_form->requiredQuestions() : []; |
|
84 | - $this->input_handler = LoaderFactory::getShared( |
|
85 | - RegFormInputHandler::class, |
|
86 | - [ $this->checkout->reg_url_link, $required_questions ] |
|
87 | - ); |
|
88 | - } |
|
80 | + private function initializeInputHandler() |
|
81 | + { |
|
82 | + $reg_form = $this->checkout->current_step->reg_form; |
|
83 | + $required_questions = $reg_form instanceof RegForm ? $reg_form->requiredQuestions() : []; |
|
84 | + $this->input_handler = LoaderFactory::getShared( |
|
85 | + RegFormInputHandler::class, |
|
86 | + [ $this->checkout->reg_url_link, $required_questions ] |
|
87 | + ); |
|
88 | + } |
|
89 | 89 | |
90 | 90 | |
91 | - /** |
|
92 | - * @return int |
|
93 | - */ |
|
94 | - public function attendeeCount(): int |
|
95 | - { |
|
96 | - return $this->registrant_data->attendeeCount(); |
|
97 | - } |
|
91 | + /** |
|
92 | + * @return int |
|
93 | + */ |
|
94 | + public function attendeeCount(): int |
|
95 | + { |
|
96 | + return $this->registrant_data->attendeeCount(); |
|
97 | + } |
|
98 | 98 | |
99 | 99 | |
100 | - /** |
|
101 | - * @return bool |
|
102 | - */ |
|
103 | - private function isInvalid(): bool |
|
104 | - { |
|
105 | - $this->valid = false; |
|
106 | - return $this->valid; |
|
107 | - } |
|
100 | + /** |
|
101 | + * @return bool |
|
102 | + */ |
|
103 | + private function isInvalid(): bool |
|
104 | + { |
|
105 | + $this->valid = false; |
|
106 | + return $this->valid; |
|
107 | + } |
|
108 | 108 | |
109 | 109 | |
110 | - /** |
|
111 | - * @param EE_Registration[] $registrations |
|
112 | - * @param array[][] $reg_form_data |
|
113 | - * @return bool |
|
114 | - * @throws EntityNotFoundException |
|
115 | - * @throws EE_Error |
|
116 | - * @throws InvalidArgumentException |
|
117 | - * @throws ReflectionException |
|
118 | - * @throws RuntimeException |
|
119 | - * @throws InvalidDataTypeException |
|
120 | - * @throws InvalidInterfaceException |
|
121 | - */ |
|
122 | - public function processRegistrations(array $registrations, array $reg_form_data): bool |
|
123 | - { |
|
124 | - // start off optimistic, then trip this to false if anything goes wrong |
|
125 | - $this->valid = true; |
|
126 | - foreach ($registrations as $registration) { |
|
127 | - // verify EE_Registration object |
|
128 | - if (! $this->isValidRegistration($registration)) { |
|
129 | - return $this->isInvalid(); |
|
130 | - } |
|
131 | - $reg_url_link = $registration->reg_url_link(); |
|
132 | - // reg_url_link exists ? |
|
133 | - if (! $this->isValidRegUrlLink($reg_url_link)) { |
|
134 | - return $this->isInvalid(); |
|
135 | - } |
|
136 | - // should this registration be processed during this visit ? |
|
137 | - if (! $this->checkout->visit_allows_processing_of_this_registration($registration)) { |
|
138 | - continue; |
|
139 | - } |
|
140 | - // if NOT revisiting, then let's save the registration now, |
|
141 | - // so that we have a REG_ID to use when generating other objects |
|
142 | - if (! $this->checkout->revisit) { |
|
143 | - $registration->save(); |
|
144 | - } |
|
145 | - /** |
|
146 | - * This allows plugins to trigger a fail on processing of a |
|
147 | - * registration for any conditions they may have for it to pass. |
|
148 | - * |
|
149 | - * @var bool if true is returned by the plugin then the registration processing is halted. |
|
150 | - */ |
|
151 | - if ( |
|
152 | - apply_filters( |
|
153 | - 'FHEE__EventEspresso_core_domain_services_registration_form_v1_RegFormHandler__processRegistrations__bypass', |
|
154 | - false, |
|
155 | - $this->registrant_data->attendeeCount(), |
|
156 | - $registration, |
|
157 | - $registrations, |
|
158 | - $reg_form_data, |
|
159 | - $this |
|
160 | - ) |
|
161 | - ) { |
|
162 | - return $this->isInvalid(); |
|
163 | - } |
|
110 | + /** |
|
111 | + * @param EE_Registration[] $registrations |
|
112 | + * @param array[][] $reg_form_data |
|
113 | + * @return bool |
|
114 | + * @throws EntityNotFoundException |
|
115 | + * @throws EE_Error |
|
116 | + * @throws InvalidArgumentException |
|
117 | + * @throws ReflectionException |
|
118 | + * @throws RuntimeException |
|
119 | + * @throws InvalidDataTypeException |
|
120 | + * @throws InvalidInterfaceException |
|
121 | + */ |
|
122 | + public function processRegistrations(array $registrations, array $reg_form_data): bool |
|
123 | + { |
|
124 | + // start off optimistic, then trip this to false if anything goes wrong |
|
125 | + $this->valid = true; |
|
126 | + foreach ($registrations as $registration) { |
|
127 | + // verify EE_Registration object |
|
128 | + if (! $this->isValidRegistration($registration)) { |
|
129 | + return $this->isInvalid(); |
|
130 | + } |
|
131 | + $reg_url_link = $registration->reg_url_link(); |
|
132 | + // reg_url_link exists ? |
|
133 | + if (! $this->isValidRegUrlLink($reg_url_link)) { |
|
134 | + return $this->isInvalid(); |
|
135 | + } |
|
136 | + // should this registration be processed during this visit ? |
|
137 | + if (! $this->checkout->visit_allows_processing_of_this_registration($registration)) { |
|
138 | + continue; |
|
139 | + } |
|
140 | + // if NOT revisiting, then let's save the registration now, |
|
141 | + // so that we have a REG_ID to use when generating other objects |
|
142 | + if (! $this->checkout->revisit) { |
|
143 | + $registration->save(); |
|
144 | + } |
|
145 | + /** |
|
146 | + * This allows plugins to trigger a fail on processing of a |
|
147 | + * registration for any conditions they may have for it to pass. |
|
148 | + * |
|
149 | + * @var bool if true is returned by the plugin then the registration processing is halted. |
|
150 | + */ |
|
151 | + if ( |
|
152 | + apply_filters( |
|
153 | + 'FHEE__EventEspresso_core_domain_services_registration_form_v1_RegFormHandler__processRegistrations__bypass', |
|
154 | + false, |
|
155 | + $this->registrant_data->attendeeCount(), |
|
156 | + $registration, |
|
157 | + $registrations, |
|
158 | + $reg_form_data, |
|
159 | + $this |
|
160 | + ) |
|
161 | + ) { |
|
162 | + return $this->isInvalid(); |
|
163 | + } |
|
164 | 164 | |
165 | - // Houston, we have a registration! |
|
166 | - if (! $this->processRegistration($registration, $reg_url_link, $reg_form_data)) { |
|
167 | - return $this->isInvalid(); |
|
168 | - } |
|
169 | - } |
|
170 | - return $this->valid; |
|
171 | - } |
|
165 | + // Houston, we have a registration! |
|
166 | + if (! $this->processRegistration($registration, $reg_url_link, $reg_form_data)) { |
|
167 | + return $this->isInvalid(); |
|
168 | + } |
|
169 | + } |
|
170 | + return $this->valid; |
|
171 | + } |
|
172 | 172 | |
173 | 173 | |
174 | - /** |
|
175 | - * @param string $reg_url_link |
|
176 | - * @return bool |
|
177 | - */ |
|
178 | - private function isValidRegUrlLink(string $reg_url_link): bool |
|
179 | - { |
|
180 | - if (! empty($reg_url_link)) { |
|
181 | - return true; |
|
182 | - } |
|
183 | - EE_Error::add_error( |
|
184 | - esc_html__( |
|
185 | - 'An invalid or missing line item ID was encountered while attempting to process the registration form.', |
|
186 | - 'event_espresso' |
|
187 | - ), |
|
188 | - __FILE__, |
|
189 | - __FUNCTION__, |
|
190 | - __LINE__ |
|
191 | - ); |
|
192 | - return false; |
|
193 | - } |
|
174 | + /** |
|
175 | + * @param string $reg_url_link |
|
176 | + * @return bool |
|
177 | + */ |
|
178 | + private function isValidRegUrlLink(string $reg_url_link): bool |
|
179 | + { |
|
180 | + if (! empty($reg_url_link)) { |
|
181 | + return true; |
|
182 | + } |
|
183 | + EE_Error::add_error( |
|
184 | + esc_html__( |
|
185 | + 'An invalid or missing line item ID was encountered while attempting to process the registration form.', |
|
186 | + 'event_espresso' |
|
187 | + ), |
|
188 | + __FILE__, |
|
189 | + __FUNCTION__, |
|
190 | + __LINE__ |
|
191 | + ); |
|
192 | + return false; |
|
193 | + } |
|
194 | 194 | |
195 | 195 | |
196 | - /** |
|
197 | - * @param EE_Registration|null $registration |
|
198 | - * @return bool |
|
199 | - */ |
|
200 | - private function isValidRegistration(?EE_Registration $registration): bool |
|
201 | - { |
|
202 | - // verify EE_Registration object |
|
203 | - if ($registration instanceof EE_Registration) { |
|
204 | - return true; |
|
205 | - } |
|
206 | - EE_Error::add_error( |
|
207 | - esc_html__( |
|
208 | - 'An invalid Registration object was discovered when attempting to process your registration information.', |
|
209 | - 'event_espresso' |
|
210 | - ), |
|
211 | - __FILE__, |
|
212 | - __FUNCTION__, |
|
213 | - __LINE__ |
|
214 | - ); |
|
215 | - return false; |
|
216 | - } |
|
196 | + /** |
|
197 | + * @param EE_Registration|null $registration |
|
198 | + * @return bool |
|
199 | + */ |
|
200 | + private function isValidRegistration(?EE_Registration $registration): bool |
|
201 | + { |
|
202 | + // verify EE_Registration object |
|
203 | + if ($registration instanceof EE_Registration) { |
|
204 | + return true; |
|
205 | + } |
|
206 | + EE_Error::add_error( |
|
207 | + esc_html__( |
|
208 | + 'An invalid Registration object was discovered when attempting to process your registration information.', |
|
209 | + 'event_espresso' |
|
210 | + ), |
|
211 | + __FILE__, |
|
212 | + __FUNCTION__, |
|
213 | + __LINE__ |
|
214 | + ); |
|
215 | + return false; |
|
216 | + } |
|
217 | 217 | |
218 | 218 | |
219 | - /** |
|
220 | - * @param EE_Registration $registration |
|
221 | - * @param string $reg_url_link |
|
222 | - * @param array[][] $reg_form_data |
|
223 | - * @return bool |
|
224 | - * @throws EE_Error |
|
225 | - * @throws ReflectionException |
|
226 | - */ |
|
227 | - private function processRegistration( |
|
228 | - EE_Registration $registration, |
|
229 | - string $reg_url_link, |
|
230 | - array $reg_form_data |
|
231 | - ): bool { |
|
232 | - $this->registrant_data->initializeRegistrantData($registration); |
|
233 | - if (! $this->processRegFormData($registration, $reg_url_link, $reg_form_data)) { |
|
234 | - return false; |
|
235 | - } |
|
236 | - // RegFormAttendeeFactory |
|
237 | - if (! $this->attendee_factory->create($registration, $reg_url_link)) { |
|
238 | - return false; |
|
239 | - } |
|
240 | - // at this point, we should have enough details about the registrant to consider the registration |
|
241 | - // NOT incomplete |
|
242 | - $this->registration_processor->toggle_incomplete_registration_status_to_default( |
|
243 | - $registration, |
|
244 | - false, |
|
245 | - new Context( |
|
246 | - 'spco_reg_step_attendee_information_process_registrations', |
|
247 | - esc_html__( |
|
248 | - 'Finished populating registration with details from the registration form after submitting the Attendee Information Reg Step.', |
|
249 | - 'event_espresso' |
|
250 | - ) |
|
251 | - ) |
|
252 | - ); |
|
253 | - // we can also consider the TXN to not have been failed, so temporarily upgrade it's status to |
|
254 | - // abandoned |
|
255 | - $this->checkout->transaction->toggle_failed_transaction_status(); |
|
256 | - // if we've gotten this far, then let's save what we have |
|
257 | - $registration->save(); |
|
258 | - // add relation between TXN and registration |
|
259 | - $this->associateRegistrationWithTransaction($registration); |
|
260 | - return true; |
|
261 | - } |
|
219 | + /** |
|
220 | + * @param EE_Registration $registration |
|
221 | + * @param string $reg_url_link |
|
222 | + * @param array[][] $reg_form_data |
|
223 | + * @return bool |
|
224 | + * @throws EE_Error |
|
225 | + * @throws ReflectionException |
|
226 | + */ |
|
227 | + private function processRegistration( |
|
228 | + EE_Registration $registration, |
|
229 | + string $reg_url_link, |
|
230 | + array $reg_form_data |
|
231 | + ): bool { |
|
232 | + $this->registrant_data->initializeRegistrantData($registration); |
|
233 | + if (! $this->processRegFormData($registration, $reg_url_link, $reg_form_data)) { |
|
234 | + return false; |
|
235 | + } |
|
236 | + // RegFormAttendeeFactory |
|
237 | + if (! $this->attendee_factory->create($registration, $reg_url_link)) { |
|
238 | + return false; |
|
239 | + } |
|
240 | + // at this point, we should have enough details about the registrant to consider the registration |
|
241 | + // NOT incomplete |
|
242 | + $this->registration_processor->toggle_incomplete_registration_status_to_default( |
|
243 | + $registration, |
|
244 | + false, |
|
245 | + new Context( |
|
246 | + 'spco_reg_step_attendee_information_process_registrations', |
|
247 | + esc_html__( |
|
248 | + 'Finished populating registration with details from the registration form after submitting the Attendee Information Reg Step.', |
|
249 | + 'event_espresso' |
|
250 | + ) |
|
251 | + ) |
|
252 | + ); |
|
253 | + // we can also consider the TXN to not have been failed, so temporarily upgrade it's status to |
|
254 | + // abandoned |
|
255 | + $this->checkout->transaction->toggle_failed_transaction_status(); |
|
256 | + // if we've gotten this far, then let's save what we have |
|
257 | + $registration->save(); |
|
258 | + // add relation between TXN and registration |
|
259 | + $this->associateRegistrationWithTransaction($registration); |
|
260 | + return true; |
|
261 | + } |
|
262 | 262 | |
263 | 263 | |
264 | - /** |
|
265 | - * @param EE_Registration $registration |
|
266 | - * @param string $reg_url_link |
|
267 | - * @param array $reg_form_data |
|
268 | - * @return bool |
|
269 | - * @throws EE_Error |
|
270 | - * @throws ReflectionException |
|
271 | - */ |
|
272 | - private function processRegFormData(EE_Registration $registration, string $reg_url_link, array $reg_form_data): bool |
|
273 | - { |
|
274 | - if (isset($reg_form_data[ $reg_url_link ])) { |
|
275 | - // do we need to copy basic info from primary attendee ? |
|
276 | - $copy_primary = isset($reg_form_data[ $reg_url_link ]['additional_attendee_reg_info']) |
|
277 | - && absint($reg_form_data[ $reg_url_link ]['additional_attendee_reg_info']) === 0; |
|
278 | - $this->registrant_data->setCopyPrimary($copy_primary); |
|
279 | - // filter form input data for this registration |
|
280 | - $reg_form_data[ $reg_url_link ] = (array) apply_filters( |
|
281 | - 'FHEE__EventEspresso_core_domain_services_registration_form_v1_RegFormHandler__processRegFormData__registrant_form_data', |
|
282 | - $reg_form_data[ $reg_url_link ], |
|
283 | - $registration |
|
284 | - ); |
|
285 | - if (isset($reg_form_data['primary_attendee'])) { |
|
286 | - $primary_reg_url_link = $reg_form_data['primary_attendee'] ?? ''; |
|
287 | - $this->registrant_data->addPrimaryRegistrantDataValue('reg_url_link', $primary_reg_url_link); |
|
288 | - unset($reg_form_data['primary_attendee']); |
|
289 | - } |
|
290 | - // now loop through our array of valid post data && process attendee reg forms |
|
291 | - foreach ($reg_form_data[ $reg_url_link ] as $form_section => $form_inputs) { |
|
292 | - if (in_array($form_section, $this->non_input_form_sections, true)) { |
|
293 | - continue; |
|
294 | - } |
|
295 | - foreach ($form_inputs as $form_input => $input_value) { |
|
296 | - $input_processed = $this->input_handler->processFormInput( |
|
297 | - $registration, |
|
298 | - $reg_url_link, |
|
299 | - $form_input, |
|
300 | - $input_value |
|
301 | - ); |
|
302 | - if (! $input_processed) { |
|
303 | - return false; |
|
304 | - } |
|
305 | - } |
|
306 | - } |
|
307 | - } |
|
308 | - return true; |
|
309 | - } |
|
264 | + /** |
|
265 | + * @param EE_Registration $registration |
|
266 | + * @param string $reg_url_link |
|
267 | + * @param array $reg_form_data |
|
268 | + * @return bool |
|
269 | + * @throws EE_Error |
|
270 | + * @throws ReflectionException |
|
271 | + */ |
|
272 | + private function processRegFormData(EE_Registration $registration, string $reg_url_link, array $reg_form_data): bool |
|
273 | + { |
|
274 | + if (isset($reg_form_data[ $reg_url_link ])) { |
|
275 | + // do we need to copy basic info from primary attendee ? |
|
276 | + $copy_primary = isset($reg_form_data[ $reg_url_link ]['additional_attendee_reg_info']) |
|
277 | + && absint($reg_form_data[ $reg_url_link ]['additional_attendee_reg_info']) === 0; |
|
278 | + $this->registrant_data->setCopyPrimary($copy_primary); |
|
279 | + // filter form input data for this registration |
|
280 | + $reg_form_data[ $reg_url_link ] = (array) apply_filters( |
|
281 | + 'FHEE__EventEspresso_core_domain_services_registration_form_v1_RegFormHandler__processRegFormData__registrant_form_data', |
|
282 | + $reg_form_data[ $reg_url_link ], |
|
283 | + $registration |
|
284 | + ); |
|
285 | + if (isset($reg_form_data['primary_attendee'])) { |
|
286 | + $primary_reg_url_link = $reg_form_data['primary_attendee'] ?? ''; |
|
287 | + $this->registrant_data->addPrimaryRegistrantDataValue('reg_url_link', $primary_reg_url_link); |
|
288 | + unset($reg_form_data['primary_attendee']); |
|
289 | + } |
|
290 | + // now loop through our array of valid post data && process attendee reg forms |
|
291 | + foreach ($reg_form_data[ $reg_url_link ] as $form_section => $form_inputs) { |
|
292 | + if (in_array($form_section, $this->non_input_form_sections, true)) { |
|
293 | + continue; |
|
294 | + } |
|
295 | + foreach ($form_inputs as $form_input => $input_value) { |
|
296 | + $input_processed = $this->input_handler->processFormInput( |
|
297 | + $registration, |
|
298 | + $reg_url_link, |
|
299 | + $form_input, |
|
300 | + $input_value |
|
301 | + ); |
|
302 | + if (! $input_processed) { |
|
303 | + return false; |
|
304 | + } |
|
305 | + } |
|
306 | + } |
|
307 | + } |
|
308 | + return true; |
|
309 | + } |
|
310 | 310 | |
311 | 311 | |
312 | - /** |
|
313 | - * @param EE_Registration $registration |
|
314 | - * @return void |
|
315 | - * @throws EE_Error |
|
316 | - * @throws InvalidArgumentException |
|
317 | - * @throws ReflectionException |
|
318 | - * @throws InvalidDataTypeException |
|
319 | - * @throws InvalidInterfaceException |
|
320 | - */ |
|
321 | - private function associateRegistrationWithTransaction(EE_Registration $registration) |
|
322 | - { |
|
323 | - // add relation to registration |
|
324 | - $this->checkout->transaction->_add_relation_to($registration, 'Registration'); |
|
325 | - $this->checkout->transaction->update_cache_after_object_save('Registration', $registration); |
|
326 | - } |
|
312 | + /** |
|
313 | + * @param EE_Registration $registration |
|
314 | + * @return void |
|
315 | + * @throws EE_Error |
|
316 | + * @throws InvalidArgumentException |
|
317 | + * @throws ReflectionException |
|
318 | + * @throws InvalidDataTypeException |
|
319 | + * @throws InvalidInterfaceException |
|
320 | + */ |
|
321 | + private function associateRegistrationWithTransaction(EE_Registration $registration) |
|
322 | + { |
|
323 | + // add relation to registration |
|
324 | + $this->checkout->transaction->_add_relation_to($registration, 'Registration'); |
|
325 | + $this->checkout->transaction->update_cache_after_object_save('Registration', $registration); |
|
326 | + } |
|
327 | 327 | } |
@@ -83,7 +83,7 @@ discard block |
||
83 | 83 | $required_questions = $reg_form instanceof RegForm ? $reg_form->requiredQuestions() : []; |
84 | 84 | $this->input_handler = LoaderFactory::getShared( |
85 | 85 | RegFormInputHandler::class, |
86 | - [ $this->checkout->reg_url_link, $required_questions ] |
|
86 | + [$this->checkout->reg_url_link, $required_questions] |
|
87 | 87 | ); |
88 | 88 | } |
89 | 89 | |
@@ -125,21 +125,21 @@ discard block |
||
125 | 125 | $this->valid = true; |
126 | 126 | foreach ($registrations as $registration) { |
127 | 127 | // verify EE_Registration object |
128 | - if (! $this->isValidRegistration($registration)) { |
|
128 | + if ( ! $this->isValidRegistration($registration)) { |
|
129 | 129 | return $this->isInvalid(); |
130 | 130 | } |
131 | 131 | $reg_url_link = $registration->reg_url_link(); |
132 | 132 | // reg_url_link exists ? |
133 | - if (! $this->isValidRegUrlLink($reg_url_link)) { |
|
133 | + if ( ! $this->isValidRegUrlLink($reg_url_link)) { |
|
134 | 134 | return $this->isInvalid(); |
135 | 135 | } |
136 | 136 | // should this registration be processed during this visit ? |
137 | - if (! $this->checkout->visit_allows_processing_of_this_registration($registration)) { |
|
137 | + if ( ! $this->checkout->visit_allows_processing_of_this_registration($registration)) { |
|
138 | 138 | continue; |
139 | 139 | } |
140 | 140 | // if NOT revisiting, then let's save the registration now, |
141 | 141 | // so that we have a REG_ID to use when generating other objects |
142 | - if (! $this->checkout->revisit) { |
|
142 | + if ( ! $this->checkout->revisit) { |
|
143 | 143 | $registration->save(); |
144 | 144 | } |
145 | 145 | /** |
@@ -163,7 +163,7 @@ discard block |
||
163 | 163 | } |
164 | 164 | |
165 | 165 | // Houston, we have a registration! |
166 | - if (! $this->processRegistration($registration, $reg_url_link, $reg_form_data)) { |
|
166 | + if ( ! $this->processRegistration($registration, $reg_url_link, $reg_form_data)) { |
|
167 | 167 | return $this->isInvalid(); |
168 | 168 | } |
169 | 169 | } |
@@ -177,7 +177,7 @@ discard block |
||
177 | 177 | */ |
178 | 178 | private function isValidRegUrlLink(string $reg_url_link): bool |
179 | 179 | { |
180 | - if (! empty($reg_url_link)) { |
|
180 | + if ( ! empty($reg_url_link)) { |
|
181 | 181 | return true; |
182 | 182 | } |
183 | 183 | EE_Error::add_error( |
@@ -230,11 +230,11 @@ discard block |
||
230 | 230 | array $reg_form_data |
231 | 231 | ): bool { |
232 | 232 | $this->registrant_data->initializeRegistrantData($registration); |
233 | - if (! $this->processRegFormData($registration, $reg_url_link, $reg_form_data)) { |
|
233 | + if ( ! $this->processRegFormData($registration, $reg_url_link, $reg_form_data)) { |
|
234 | 234 | return false; |
235 | 235 | } |
236 | 236 | // RegFormAttendeeFactory |
237 | - if (! $this->attendee_factory->create($registration, $reg_url_link)) { |
|
237 | + if ( ! $this->attendee_factory->create($registration, $reg_url_link)) { |
|
238 | 238 | return false; |
239 | 239 | } |
240 | 240 | // at this point, we should have enough details about the registrant to consider the registration |
@@ -271,15 +271,15 @@ discard block |
||
271 | 271 | */ |
272 | 272 | private function processRegFormData(EE_Registration $registration, string $reg_url_link, array $reg_form_data): bool |
273 | 273 | { |
274 | - if (isset($reg_form_data[ $reg_url_link ])) { |
|
274 | + if (isset($reg_form_data[$reg_url_link])) { |
|
275 | 275 | // do we need to copy basic info from primary attendee ? |
276 | - $copy_primary = isset($reg_form_data[ $reg_url_link ]['additional_attendee_reg_info']) |
|
277 | - && absint($reg_form_data[ $reg_url_link ]['additional_attendee_reg_info']) === 0; |
|
276 | + $copy_primary = isset($reg_form_data[$reg_url_link]['additional_attendee_reg_info']) |
|
277 | + && absint($reg_form_data[$reg_url_link]['additional_attendee_reg_info']) === 0; |
|
278 | 278 | $this->registrant_data->setCopyPrimary($copy_primary); |
279 | 279 | // filter form input data for this registration |
280 | - $reg_form_data[ $reg_url_link ] = (array) apply_filters( |
|
280 | + $reg_form_data[$reg_url_link] = (array) apply_filters( |
|
281 | 281 | 'FHEE__EventEspresso_core_domain_services_registration_form_v1_RegFormHandler__processRegFormData__registrant_form_data', |
282 | - $reg_form_data[ $reg_url_link ], |
|
282 | + $reg_form_data[$reg_url_link], |
|
283 | 283 | $registration |
284 | 284 | ); |
285 | 285 | if (isset($reg_form_data['primary_attendee'])) { |
@@ -288,7 +288,7 @@ discard block |
||
288 | 288 | unset($reg_form_data['primary_attendee']); |
289 | 289 | } |
290 | 290 | // now loop through our array of valid post data && process attendee reg forms |
291 | - foreach ($reg_form_data[ $reg_url_link ] as $form_section => $form_inputs) { |
|
291 | + foreach ($reg_form_data[$reg_url_link] as $form_section => $form_inputs) { |
|
292 | 292 | if (in_array($form_section, $this->non_input_form_sections, true)) { |
293 | 293 | continue; |
294 | 294 | } |
@@ -299,7 +299,7 @@ discard block |
||
299 | 299 | $form_input, |
300 | 300 | $input_value |
301 | 301 | ); |
302 | - if (! $input_processed) { |
|
302 | + if ( ! $input_processed) { |
|
303 | 303 | return false; |
304 | 304 | } |
305 | 305 | } |
@@ -13,109 +13,109 @@ |
||
13 | 13 | |
14 | 14 | class CountryOptions |
15 | 15 | { |
16 | - /** |
|
17 | - * the action being performed on the current step |
|
18 | - * |
|
19 | - * @var string |
|
20 | - */ |
|
21 | - public $action = ''; |
|
16 | + /** |
|
17 | + * the action being performed on the current step |
|
18 | + * |
|
19 | + * @var string |
|
20 | + */ |
|
21 | + public $action = ''; |
|
22 | 22 | |
23 | - /** |
|
24 | - * @var EEM_Answer |
|
25 | - */ |
|
26 | - public $answer_model; |
|
23 | + /** |
|
24 | + * @var EEM_Answer |
|
25 | + */ |
|
26 | + public $answer_model; |
|
27 | 27 | |
28 | - /** |
|
29 | - * @var EEM_Country |
|
30 | - */ |
|
31 | - public $country_model; |
|
28 | + /** |
|
29 | + * @var EEM_Country |
|
30 | + */ |
|
31 | + public $country_model; |
|
32 | 32 | |
33 | - /** |
|
34 | - * @var [][] |
|
35 | - */ |
|
36 | - private $country_options = []; |
|
33 | + /** |
|
34 | + * @var [][] |
|
35 | + */ |
|
36 | + private $country_options = []; |
|
37 | 37 | |
38 | 38 | |
39 | - /** |
|
40 | - * CountryOptions constructor. |
|
41 | - * |
|
42 | - * @param string $action |
|
43 | - * @param EEM_Answer $answer_model |
|
44 | - * @param EEM_Country $country_model |
|
45 | - */ |
|
46 | - public function __construct(string $action, EEM_Answer $answer_model, EEM_Country $country_model) |
|
47 | - { |
|
48 | - $this->action = $action; |
|
49 | - $this->answer_model = $answer_model; |
|
50 | - $this->country_model = $country_model; |
|
51 | - add_filter( |
|
52 | - 'FHEE__EE_Question__generate_form_input__country_options', |
|
53 | - [$this, 'forLegacyFormInput'], |
|
54 | - 10, |
|
55 | - 4 |
|
56 | - ); |
|
57 | - } |
|
39 | + /** |
|
40 | + * CountryOptions constructor. |
|
41 | + * |
|
42 | + * @param string $action |
|
43 | + * @param EEM_Answer $answer_model |
|
44 | + * @param EEM_Country $country_model |
|
45 | + */ |
|
46 | + public function __construct(string $action, EEM_Answer $answer_model, EEM_Country $country_model) |
|
47 | + { |
|
48 | + $this->action = $action; |
|
49 | + $this->answer_model = $answer_model; |
|
50 | + $this->country_model = $country_model; |
|
51 | + add_filter( |
|
52 | + 'FHEE__EE_Question__generate_form_input__country_options', |
|
53 | + [$this, 'forLegacyFormInput'], |
|
54 | + 10, |
|
55 | + 4 |
|
56 | + ); |
|
57 | + } |
|
58 | 58 | |
59 | 59 | |
60 | - /** |
|
61 | - * Gets the list of countries for the form input |
|
62 | - * |
|
63 | - * @param array|null $countries_list deprecated prop from an old hook |
|
64 | - * @param EE_Question|null $question |
|
65 | - * @param EE_Registration|null $registration |
|
66 | - * @param EE_Answer|null $answer deprecated prop from an old hook |
|
67 | - * @return array 2d keys are country IDs, values are their names |
|
68 | - * @throws EE_Error |
|
69 | - * @throws ReflectionException |
|
70 | - */ |
|
71 | - public function forLegacyFormInput( |
|
72 | - array $countries_list = null, |
|
73 | - EE_Question $question = null, |
|
74 | - EE_Registration $registration = null, |
|
75 | - EE_Answer $answer = null |
|
76 | - ): array { |
|
77 | - if (! isset($this->country_options[ $this->action ])) { |
|
78 | - $this->generateLegacyCountryOptions($question, $registration); |
|
79 | - } |
|
80 | - return $this->country_options[ $this->action ]; |
|
81 | - } |
|
60 | + /** |
|
61 | + * Gets the list of countries for the form input |
|
62 | + * |
|
63 | + * @param array|null $countries_list deprecated prop from an old hook |
|
64 | + * @param EE_Question|null $question |
|
65 | + * @param EE_Registration|null $registration |
|
66 | + * @param EE_Answer|null $answer deprecated prop from an old hook |
|
67 | + * @return array 2d keys are country IDs, values are their names |
|
68 | + * @throws EE_Error |
|
69 | + * @throws ReflectionException |
|
70 | + */ |
|
71 | + public function forLegacyFormInput( |
|
72 | + array $countries_list = null, |
|
73 | + EE_Question $question = null, |
|
74 | + EE_Registration $registration = null, |
|
75 | + EE_Answer $answer = null |
|
76 | + ): array { |
|
77 | + if (! isset($this->country_options[ $this->action ])) { |
|
78 | + $this->generateLegacyCountryOptions($question, $registration); |
|
79 | + } |
|
80 | + return $this->country_options[ $this->action ]; |
|
81 | + } |
|
82 | 82 | |
83 | 83 | |
84 | - /** |
|
85 | - * @param EE_Question|null $question |
|
86 | - * @param EE_Registration|null $registration |
|
87 | - * @throws EE_Error |
|
88 | - * @throws ReflectionException |
|
89 | - */ |
|
90 | - private function generateLegacyCountryOptions(EE_Question $question = null, EE_Registration $registration = null) |
|
91 | - { |
|
92 | - // get possibly cached list of countries |
|
93 | - $countries = $this->action === 'process_reg_step' |
|
94 | - ? $this->country_model->get_all_countries() |
|
95 | - : $this->country_model->get_all_active_countries(); |
|
96 | - // start with an empty option |
|
97 | - $country_options = ['' => '']; |
|
98 | - if (! empty($countries)) { |
|
99 | - foreach ($countries as $country) { |
|
100 | - if ($country instanceof EE_Country) { |
|
101 | - $country_options[ $country->ID() ] = $country->name(); |
|
102 | - } |
|
103 | - } |
|
104 | - } |
|
105 | - if ($question instanceof EE_Question && $registration instanceof EE_Registration) { |
|
106 | - $answer = $this->answer_model->get_one( |
|
107 | - [['QST_ID' => $question->ID(), 'REG_ID' => $registration->ID()]] |
|
108 | - ); |
|
109 | - } else { |
|
110 | - $answer = EE_Answer::new_instance(); |
|
111 | - } |
|
112 | - $this->country_options[ $this->action ] = apply_filters( |
|
113 | - 'FHEE__EventEspresso_core_domain_services_registration_form_v1_CountryOptions__generateLegacyCountryOptions__country_options', |
|
114 | - $country_options, |
|
115 | - $registration, |
|
116 | - $question, |
|
117 | - $answer, |
|
118 | - $this |
|
119 | - ); |
|
120 | - } |
|
84 | + /** |
|
85 | + * @param EE_Question|null $question |
|
86 | + * @param EE_Registration|null $registration |
|
87 | + * @throws EE_Error |
|
88 | + * @throws ReflectionException |
|
89 | + */ |
|
90 | + private function generateLegacyCountryOptions(EE_Question $question = null, EE_Registration $registration = null) |
|
91 | + { |
|
92 | + // get possibly cached list of countries |
|
93 | + $countries = $this->action === 'process_reg_step' |
|
94 | + ? $this->country_model->get_all_countries() |
|
95 | + : $this->country_model->get_all_active_countries(); |
|
96 | + // start with an empty option |
|
97 | + $country_options = ['' => '']; |
|
98 | + if (! empty($countries)) { |
|
99 | + foreach ($countries as $country) { |
|
100 | + if ($country instanceof EE_Country) { |
|
101 | + $country_options[ $country->ID() ] = $country->name(); |
|
102 | + } |
|
103 | + } |
|
104 | + } |
|
105 | + if ($question instanceof EE_Question && $registration instanceof EE_Registration) { |
|
106 | + $answer = $this->answer_model->get_one( |
|
107 | + [['QST_ID' => $question->ID(), 'REG_ID' => $registration->ID()]] |
|
108 | + ); |
|
109 | + } else { |
|
110 | + $answer = EE_Answer::new_instance(); |
|
111 | + } |
|
112 | + $this->country_options[ $this->action ] = apply_filters( |
|
113 | + 'FHEE__EventEspresso_core_domain_services_registration_form_v1_CountryOptions__generateLegacyCountryOptions__country_options', |
|
114 | + $country_options, |
|
115 | + $registration, |
|
116 | + $question, |
|
117 | + $answer, |
|
118 | + $this |
|
119 | + ); |
|
120 | + } |
|
121 | 121 | } |
@@ -74,10 +74,10 @@ discard block |
||
74 | 74 | EE_Registration $registration = null, |
75 | 75 | EE_Answer $answer = null |
76 | 76 | ): array { |
77 | - if (! isset($this->country_options[ $this->action ])) { |
|
77 | + if ( ! isset($this->country_options[$this->action])) { |
|
78 | 78 | $this->generateLegacyCountryOptions($question, $registration); |
79 | 79 | } |
80 | - return $this->country_options[ $this->action ]; |
|
80 | + return $this->country_options[$this->action]; |
|
81 | 81 | } |
82 | 82 | |
83 | 83 | |
@@ -95,10 +95,10 @@ discard block |
||
95 | 95 | : $this->country_model->get_all_active_countries(); |
96 | 96 | // start with an empty option |
97 | 97 | $country_options = ['' => '']; |
98 | - if (! empty($countries)) { |
|
98 | + if ( ! empty($countries)) { |
|
99 | 99 | foreach ($countries as $country) { |
100 | 100 | if ($country instanceof EE_Country) { |
101 | - $country_options[ $country->ID() ] = $country->name(); |
|
101 | + $country_options[$country->ID()] = $country->name(); |
|
102 | 102 | } |
103 | 103 | } |
104 | 104 | } |
@@ -109,7 +109,7 @@ discard block |
||
109 | 109 | } else { |
110 | 110 | $answer = EE_Answer::new_instance(); |
111 | 111 | } |
112 | - $this->country_options[ $this->action ] = apply_filters( |
|
112 | + $this->country_options[$this->action] = apply_filters( |
|
113 | 113 | 'FHEE__EventEspresso_core_domain_services_registration_form_v1_CountryOptions__generateLegacyCountryOptions__country_options', |
114 | 114 | $country_options, |
115 | 115 | $registration, |
@@ -8,21 +8,21 @@ |
||
8 | 8 | class AutoCopyAttendeeInfoForm extends EE_Form_Section_HTML |
9 | 9 | { |
10 | 10 | |
11 | - /** |
|
12 | - * CopyAttendeeInfoForm constructor. |
|
13 | - */ |
|
14 | - public function __construct(string $slug) |
|
15 | - { |
|
16 | - parent::__construct( |
|
17 | - EEH_Template::locate_template( |
|
18 | - SPCO_REG_STEPS_PATH . $slug . '/_auto_copy_attendee_info.template.php', |
|
19 | - apply_filters( |
|
20 | - 'FHEE__EventEspresso_core_domain_services_registration_form_v1_AutoCopyAttendeeInfoForm__construct__template_args', |
|
21 | - [] |
|
22 | - ), |
|
23 | - true, |
|
24 | - true |
|
25 | - ) |
|
26 | - ); |
|
27 | - } |
|
11 | + /** |
|
12 | + * CopyAttendeeInfoForm constructor. |
|
13 | + */ |
|
14 | + public function __construct(string $slug) |
|
15 | + { |
|
16 | + parent::__construct( |
|
17 | + EEH_Template::locate_template( |
|
18 | + SPCO_REG_STEPS_PATH . $slug . '/_auto_copy_attendee_info.template.php', |
|
19 | + apply_filters( |
|
20 | + 'FHEE__EventEspresso_core_domain_services_registration_form_v1_AutoCopyAttendeeInfoForm__construct__template_args', |
|
21 | + [] |
|
22 | + ), |
|
23 | + true, |
|
24 | + true |
|
25 | + ) |
|
26 | + ); |
|
27 | + } |
|
28 | 28 | } |
@@ -15,7 +15,7 @@ |
||
15 | 15 | { |
16 | 16 | parent::__construct( |
17 | 17 | EEH_Template::locate_template( |
18 | - SPCO_REG_STEPS_PATH . $slug . '/_auto_copy_attendee_info.template.php', |
|
18 | + SPCO_REG_STEPS_PATH.$slug.'/_auto_copy_attendee_info.template.php', |
|
19 | 19 | apply_filters( |
20 | 20 | 'FHEE__EventEspresso_core_domain_services_registration_form_v1_AutoCopyAttendeeInfoForm__construct__template_args', |
21 | 21 | [] |