@@ -38,7 +38,7 @@ discard block |
||
38 | 38 | } |
39 | 39 | // reset property so that the new event is cached. |
40 | 40 | EEH_Event_View::$_event = null; |
41 | - if (! $EVT_ID && $post instanceof EE_Event) { |
|
41 | + if ( ! $EVT_ID && $post instanceof EE_Event) { |
|
42 | 42 | EEH_Event_View::$_event = $post; |
43 | 43 | return EEH_Event_View::$_event; |
44 | 44 | } |
@@ -57,7 +57,7 @@ discard block |
||
57 | 57 | return EEH_Event_View::$_event; |
58 | 58 | } |
59 | 59 | // If the event we have isn't an event but we do have an EVT_ID, let's try getting the event using the ID. |
60 | - if (! EEH_Event_View::$_event instanceof EE_Event && $EVT_ID) { |
|
60 | + if ( ! EEH_Event_View::$_event instanceof EE_Event && $EVT_ID) { |
|
61 | 61 | EEH_Event_View::$_event = EEM_Event::instance()->get_one_by_ID($EVT_ID); |
62 | 62 | } |
63 | 63 | return EEH_Event_View::$_event; |
@@ -164,18 +164,18 @@ discard block |
||
164 | 164 | // admin has chosen "excerpt (short desc)" |
165 | 165 | // for the "Event Espresso - Events > Templates > Display Description" option |
166 | 166 | // but NO excerpt actually exists, so we need to create one |
167 | - if (! empty($num_words)) { |
|
167 | + if ( ! empty($num_words)) { |
|
168 | 168 | if (empty($more)) { |
169 | 169 | $more_link_text = esc_html__('(more…)', 'event_espresso'); |
170 | - $more = ' <a href="' . get_permalink() . '"'; |
|
170 | + $more = ' <a href="'.get_permalink().'"'; |
|
171 | 171 | $more .= ' class="more-link"'; |
172 | 172 | $more .= EED_Events_Archive::link_target(); |
173 | - $more .= '>' . $more_link_text . '</a>'; |
|
174 | - $more = apply_filters('the_content_more_link', $more, $more_link_text); |
|
173 | + $more .= '>'.$more_link_text.'</a>'; |
|
174 | + $more = apply_filters('the_content_more_link', $more, $more_link_text); |
|
175 | 175 | } |
176 | 176 | $content = str_replace('NOMORELINK', '', get_the_content('NOMORELINK')); |
177 | 177 | |
178 | - $content = wp_trim_words($content, $num_words, ' ') . $more; |
|
178 | + $content = wp_trim_words($content, $num_words, ' ').$more; |
|
179 | 179 | } else { |
180 | 180 | $content = get_the_content(); |
181 | 181 | } |
@@ -257,8 +257,8 @@ discard block |
||
257 | 257 | || ! $hide_uncategorized |
258 | 258 | ) |
259 | 259 | ) { |
260 | - $category_links[] = '<a href="' . esc_url_raw($url) . '" ' |
|
261 | - . 'rel="tag" ' . EED_Events_Archive::link_target() . '>' |
|
260 | + $category_links[] = '<a href="'.esc_url_raw($url).'" ' |
|
261 | + . 'rel="tag" '.EED_Events_Archive::link_target().'>' |
|
262 | 262 | . esc_html($term->name) |
263 | 263 | . '</a>'; |
264 | 264 | } |
@@ -283,8 +283,8 @@ discard block |
||
283 | 283 | { |
284 | 284 | $datetime = EEH_Event_View::get_primary_date_obj($EVT_ID); |
285 | 285 | $format = ! empty($date_format) && ! empty($time_format) |
286 | - ? $date_format . ' ' . $time_format |
|
287 | - : $date_format . $time_format; |
|
286 | + ? $date_format.' '.$time_format |
|
287 | + : $date_format.$time_format; |
|
288 | 288 | return $datetime instanceof EE_Datetime ? $datetime->get_i18n_datetime('DTT_EVT_start', $format) : ''; |
289 | 289 | } |
290 | 290 | |
@@ -304,7 +304,7 @@ discard block |
||
304 | 304 | $datetime = EEH_Event_View::get_last_date_obj($EVT_ID); |
305 | 305 | $format = |
306 | 306 | ! empty($date_format) && ! empty($time_format) |
307 | - ? $date_format . ' ' . $time_format |
|
307 | + ? $date_format.' '.$time_format |
|
308 | 308 | : $date_format |
309 | 309 | . $time_format; |
310 | 310 | return $datetime instanceof EE_Datetime ? $datetime->get_i18n_datetime('DTT_EVT_end', $format) : ''; |
@@ -326,7 +326,7 @@ discard block |
||
326 | 326 | $datetime = EEH_Event_View::get_earliest_date_obj($EVT_ID); |
327 | 327 | $format = |
328 | 328 | ! empty($date_format) && ! empty($time_format) |
329 | - ? $date_format . ' ' . $time_format |
|
329 | + ? $date_format.' '.$time_format |
|
330 | 330 | : $date_format |
331 | 331 | . $time_format; |
332 | 332 | return $datetime instanceof EE_Datetime ? $datetime->get_i18n_datetime('DTT_EVT_start', $format) : ''; |
@@ -348,7 +348,7 @@ discard block |
||
348 | 348 | $datetime = EEH_Event_View::get_latest_date_obj($EVT_ID); |
349 | 349 | $format = |
350 | 350 | ! empty($date_format) && ! empty($time_format) |
351 | - ? $date_format . ' ' . $time_format |
|
351 | + ? $date_format.' '.$time_format |
|
352 | 352 | : $date_format |
353 | 353 | . $time_format; |
354 | 354 | return $datetime instanceof EE_Datetime ? $datetime->get_i18n_datetime('DTT_EVT_end', $format) : ''; |
@@ -553,7 +553,7 @@ discard block |
||
553 | 553 | $url = $event->external_url() !== null && $event->external_url() !== '' |
554 | 554 | ? $event->external_url() |
555 | 555 | : get_permalink($event->ID()); |
556 | - $url = preg_match("~^(?:f|ht)tps?://~i", $url) ? $url : 'https://' . $url; |
|
556 | + $url = preg_match("~^(?:f|ht)tps?://~i", $url) ? $url : 'https://'.$url; |
|
557 | 557 | return esc_url_raw($url); |
558 | 558 | } |
559 | 559 | return ''; |
@@ -614,12 +614,12 @@ discard block |
||
614 | 614 | // get edit CPT text |
615 | 615 | $post_type_obj = get_post_type_object('espresso_events'); |
616 | 616 | // build final link html |
617 | - $link = '<a class="post-edit-link" href="' . $url . '" '; |
|
618 | - $link .= ' title="' . esc_attr($post_type_obj->labels->edit_item) . '"'; |
|
617 | + $link = '<a class="post-edit-link" href="'.$url.'" '; |
|
618 | + $link .= ' title="'.esc_attr($post_type_obj->labels->edit_item).'"'; |
|
619 | 619 | $link .= EED_Events_Archive::link_target(); |
620 | - $link .= '>' . $link_text . '</a>'; |
|
620 | + $link .= '>'.$link_text.'</a>'; |
|
621 | 621 | // put it all together |
622 | - return $before . apply_filters('edit_post_link', $link, $event->ID()) . $after; |
|
622 | + return $before.apply_filters('edit_post_link', $link, $event->ID()).$after; |
|
623 | 623 | } |
624 | 624 | } |
625 | 625 | return ''; |
@@ -9,364 +9,364 @@ discard block |
||
9 | 9 | */ |
10 | 10 | class EEH_Event_View extends EEH_Base |
11 | 11 | { |
12 | - /** |
|
13 | - * @var EE_Event $_event |
|
14 | - */ |
|
15 | - private static $_event = null; |
|
16 | - |
|
17 | - |
|
18 | - /** |
|
19 | - * get_event |
|
20 | - * attempts to retrieve an EE_Event object any way it can |
|
21 | - * |
|
22 | - * @param int|WP_Post $EVT_ID |
|
23 | - * @return EE_Event|null |
|
24 | - * @throws EE_Error |
|
25 | - * @throws ReflectionException |
|
26 | - */ |
|
27 | - public static function get_event($EVT_ID = 0) |
|
28 | - { |
|
29 | - // international newspaper? |
|
30 | - global $post; |
|
31 | - $EVT_ID = $EVT_ID instanceof WP_Post && $EVT_ID->post_type === 'espresso_events' |
|
32 | - ? $EVT_ID->ID |
|
33 | - : absint($EVT_ID); |
|
34 | - // do we already have the Event you are looking for? |
|
35 | - if (EEH_Event_View::$_event instanceof EE_Event && $EVT_ID && EEH_Event_View::$_event->ID() === $EVT_ID) { |
|
36 | - return EEH_Event_View::$_event; |
|
37 | - } |
|
38 | - // reset property so that the new event is cached. |
|
39 | - EEH_Event_View::$_event = null; |
|
40 | - if (! $EVT_ID && $post instanceof EE_Event) { |
|
41 | - EEH_Event_View::$_event = $post; |
|
42 | - return EEH_Event_View::$_event; |
|
43 | - } |
|
44 | - // if the post type is for an event and it has a cached event and we don't have a different incoming $EVT_ID |
|
45 | - // then let's just use that cached event on the $post object. |
|
46 | - if ( |
|
47 | - $post instanceof WP_Post |
|
48 | - && $post->post_type === 'espresso_events' |
|
49 | - && isset($post->EE_Event) |
|
50 | - && ( |
|
51 | - $EVT_ID === 0 |
|
52 | - || $EVT_ID === $post->ID |
|
53 | - ) |
|
54 | - ) { |
|
55 | - EEH_Event_View::$_event = $post->EE_Event; |
|
56 | - return EEH_Event_View::$_event; |
|
57 | - } |
|
58 | - // If the event we have isn't an event but we do have an EVT_ID, let's try getting the event using the ID. |
|
59 | - if (! EEH_Event_View::$_event instanceof EE_Event && $EVT_ID) { |
|
60 | - EEH_Event_View::$_event = EEM_Event::instance()->get_one_by_ID($EVT_ID); |
|
61 | - } |
|
62 | - return EEH_Event_View::$_event; |
|
63 | - } |
|
64 | - |
|
65 | - |
|
66 | - /** |
|
67 | - * display_ticket_selector |
|
68 | - * |
|
69 | - * @param int $EVT_ID |
|
70 | - * @return boolean |
|
71 | - * @throws EE_Error |
|
72 | - * @throws EE_Error |
|
73 | - * @throws ReflectionException |
|
74 | - */ |
|
75 | - public static function display_ticket_selector($EVT_ID = 0) |
|
76 | - { |
|
77 | - $event = EEH_Event_View::get_event($EVT_ID); |
|
78 | - return $event instanceof EE_Event && $event->display_ticket_selector(); |
|
79 | - } |
|
80 | - |
|
81 | - |
|
82 | - /** |
|
83 | - * event_status |
|
84 | - * |
|
85 | - * @param int $EVT_ID |
|
86 | - * @return string |
|
87 | - * @throws EE_Error |
|
88 | - * @throws EE_Error |
|
89 | - * @throws ReflectionException |
|
90 | - */ |
|
91 | - public static function event_status($EVT_ID = 0) |
|
92 | - { |
|
93 | - $event = EEH_Event_View::get_event($EVT_ID); |
|
94 | - return $event instanceof EE_Event ? $event->pretty_active_status(false) : ''; |
|
95 | - } |
|
96 | - |
|
97 | - |
|
98 | - /** |
|
99 | - * event_active_status |
|
100 | - * |
|
101 | - * @param int $EVT_ID |
|
102 | - * @return string |
|
103 | - * @throws EE_Error |
|
104 | - * @throws EE_Error |
|
105 | - * @throws ReflectionException |
|
106 | - */ |
|
107 | - public static function event_active_status($EVT_ID = 0, $echo = true) |
|
108 | - { |
|
109 | - $event = EEH_Event_View::get_event($EVT_ID); |
|
110 | - return $event instanceof EE_Event ? $event->pretty_active_status($echo) : 'inactive'; |
|
111 | - } |
|
112 | - |
|
113 | - |
|
114 | - /** |
|
115 | - * event_has_content_or_excerpt |
|
116 | - * |
|
117 | - * @param int $EVT_ID |
|
118 | - * @return bool |
|
119 | - * @throws EE_Error |
|
120 | - * @throws EE_Error |
|
121 | - * @throws ReflectionException |
|
122 | - */ |
|
123 | - public static function event_has_content_or_excerpt($EVT_ID = 0) |
|
124 | - { |
|
125 | - $event = EEH_Event_View::get_event($EVT_ID); |
|
126 | - $has_content_or_excerpt = false; |
|
127 | - if ($event instanceof EE_Event) { |
|
128 | - $has_content_or_excerpt = $event->description() != '' || $event->short_description(null, null, true) != ''; |
|
129 | - } |
|
130 | - if ( |
|
131 | - is_archive() |
|
132 | - && ! (espresso_display_full_description_in_event_list() |
|
133 | - || espresso_display_excerpt_in_event_list()) |
|
134 | - ) { |
|
135 | - $has_content_or_excerpt = false; |
|
136 | - } |
|
137 | - return $has_content_or_excerpt; |
|
138 | - } |
|
139 | - |
|
140 | - |
|
141 | - /** |
|
142 | - * event_active_status |
|
143 | - * |
|
144 | - * @param null $num_words |
|
145 | - * @param null $more |
|
146 | - * @return string |
|
147 | - */ |
|
148 | - public static function event_content_or_excerpt($num_words = null, $more = null) |
|
149 | - { |
|
150 | - global $post; |
|
151 | - ob_start(); |
|
152 | - if ((is_single()) || (is_archive() && espresso_display_full_description_in_event_list())) { |
|
153 | - // admin has chosen "full description" |
|
154 | - // for the "Event Espresso - Events > Templates > Display Description" option |
|
155 | - the_content(); |
|
156 | - } elseif ((is_archive() && espresso_display_excerpt_in_event_list())) { |
|
157 | - if (has_excerpt($post->ID)) { |
|
158 | - // admin has chosen "excerpt (short desc)" |
|
159 | - // for the "Event Espresso - Events > Templates > Display Description" option |
|
160 | - // AND an excerpt actually exists |
|
161 | - the_excerpt(); |
|
162 | - } else { |
|
163 | - // admin has chosen "excerpt (short desc)" |
|
164 | - // for the "Event Espresso - Events > Templates > Display Description" option |
|
165 | - // but NO excerpt actually exists, so we need to create one |
|
166 | - if (! empty($num_words)) { |
|
167 | - if (empty($more)) { |
|
168 | - $more_link_text = esc_html__('(more…)', 'event_espresso'); |
|
169 | - $more = ' <a href="' . get_permalink() . '"'; |
|
170 | - $more .= ' class="more-link"'; |
|
171 | - $more .= EED_Events_Archive::link_target(); |
|
172 | - $more .= '>' . $more_link_text . '</a>'; |
|
173 | - $more = apply_filters('the_content_more_link', $more, $more_link_text); |
|
174 | - } |
|
175 | - $content = str_replace('NOMORELINK', '', get_the_content('NOMORELINK')); |
|
176 | - |
|
177 | - $content = wp_trim_words($content, $num_words, ' ') . $more; |
|
178 | - } else { |
|
179 | - $content = get_the_content(); |
|
180 | - } |
|
181 | - global $allowedtags; |
|
182 | - // make sure links are allowed |
|
183 | - $allowedtags['a'] = isset($allowedtags['a']) |
|
184 | - ? $allowedtags['a'] |
|
185 | - : []; |
|
186 | - // as well as target attribute |
|
187 | - $allowedtags['a']['target'] = isset($allowedtags['a']['target']) |
|
188 | - ? $allowedtags['a']['target'] |
|
189 | - : false; |
|
190 | - // but get previous value so we can reset it |
|
191 | - $prev_value = $allowedtags['a']['target']; |
|
192 | - $allowedtags['a']['target'] = true; |
|
193 | - $content = wp_kses($content, $allowedtags); |
|
194 | - $content = strip_shortcodes($content); |
|
195 | - echo apply_filters('the_content', $content); |
|
196 | - $allowedtags['a']['target'] = $prev_value; |
|
197 | - } |
|
198 | - } else { |
|
199 | - // admin has chosen "none" |
|
200 | - // for the "Event Espresso - Events > Templates > Display Description" option |
|
201 | - echo apply_filters('the_content', ''); |
|
202 | - } |
|
203 | - return ob_get_clean(); |
|
204 | - } |
|
205 | - |
|
206 | - |
|
207 | - /** |
|
208 | - * event_tickets_available |
|
209 | - * |
|
210 | - * @param int $EVT_ID |
|
211 | - * @return EE_Ticket[] |
|
212 | - * @throws EE_Error |
|
213 | - * @throws ReflectionException |
|
214 | - */ |
|
215 | - public static function event_tickets_available($EVT_ID = 0) |
|
216 | - { |
|
217 | - $event = EEH_Event_View::get_event($EVT_ID); |
|
218 | - $tickets_available_for_purchase = []; |
|
219 | - if ($event instanceof EE_Event) { |
|
220 | - $datetimes = EEH_Event_View::get_all_date_obj($EVT_ID, false); |
|
221 | - foreach ($datetimes as $datetime) { |
|
222 | - $tickets_available_for_purchase = |
|
223 | - array_merge($tickets_available_for_purchase, $datetime->ticket_types_available_for_purchase()); |
|
224 | - } |
|
225 | - } |
|
226 | - return $tickets_available_for_purchase; |
|
227 | - } |
|
228 | - |
|
229 | - |
|
230 | - /** |
|
231 | - * the_event_date |
|
232 | - * |
|
233 | - * @param int $EVT_ID |
|
234 | - * @param bool $hide_uncategorized |
|
235 | - * @return string |
|
236 | - * @throws EE_Error |
|
237 | - * @throws ReflectionException |
|
238 | - */ |
|
239 | - public static function event_categories($EVT_ID = 0, $hide_uncategorized = true) |
|
240 | - { |
|
241 | - $category_links = []; |
|
242 | - $event = EEH_Event_View::get_event($EVT_ID); |
|
243 | - if ($event instanceof EE_Event) { |
|
244 | - $event_categories = get_the_terms($event->ID(), 'espresso_event_categories'); |
|
245 | - if ($event_categories) { |
|
246 | - // loop thru terms and create links |
|
247 | - foreach ($event_categories as $term) { |
|
248 | - $url = get_term_link($term, 'espresso_venue_categories'); |
|
249 | - if ( |
|
250 | - ! is_wp_error($url) |
|
251 | - && ( |
|
252 | - ( |
|
253 | - $hide_uncategorized |
|
254 | - && strtolower($term->name) != esc_html__('uncategorized', 'event_espresso') |
|
255 | - ) |
|
256 | - || ! $hide_uncategorized |
|
257 | - ) |
|
258 | - ) { |
|
259 | - $category_links[] = '<a href="' . esc_url_raw($url) . '" ' |
|
260 | - . 'rel="tag" ' . EED_Events_Archive::link_target() . '>' |
|
261 | - . esc_html($term->name) |
|
262 | - . '</a>'; |
|
263 | - } |
|
264 | - } |
|
265 | - } |
|
266 | - } |
|
267 | - return implode(', ', $category_links); |
|
268 | - } |
|
269 | - |
|
270 | - |
|
271 | - /** |
|
272 | - * the_event_date - first date by date order |
|
273 | - * |
|
274 | - * @param string $date_format |
|
275 | - * @param string $time_format |
|
276 | - * @param int $EVT_ID |
|
277 | - * @return string |
|
278 | - * @throws EE_Error |
|
279 | - * @throws ReflectionException |
|
280 | - */ |
|
281 | - public static function the_event_date($date_format = 'D M jS', $time_format = 'g:i a', $EVT_ID = 0) |
|
282 | - { |
|
283 | - $datetime = EEH_Event_View::get_primary_date_obj($EVT_ID); |
|
284 | - $format = ! empty($date_format) && ! empty($time_format) |
|
285 | - ? $date_format . ' ' . $time_format |
|
286 | - : $date_format . $time_format; |
|
287 | - return $datetime instanceof EE_Datetime ? $datetime->get_i18n_datetime('DTT_EVT_start', $format) : ''; |
|
288 | - } |
|
289 | - |
|
290 | - |
|
291 | - /** |
|
292 | - * the_event_end_date - last date by date order |
|
293 | - * |
|
294 | - * @param string $date_format |
|
295 | - * @param string $time_format |
|
296 | - * @param int $EVT_ID |
|
297 | - * @return string |
|
298 | - * @throws EE_Error |
|
299 | - * @throws ReflectionException |
|
300 | - */ |
|
301 | - public static function the_event_end_date($date_format = 'D M jS', $time_format = 'g:i a', $EVT_ID = 0) |
|
302 | - { |
|
303 | - $datetime = EEH_Event_View::get_last_date_obj($EVT_ID); |
|
304 | - $format = |
|
305 | - ! empty($date_format) && ! empty($time_format) |
|
306 | - ? $date_format . ' ' . $time_format |
|
307 | - : $date_format |
|
308 | - . $time_format; |
|
309 | - return $datetime instanceof EE_Datetime ? $datetime->get_i18n_datetime('DTT_EVT_end', $format) : ''; |
|
310 | - } |
|
311 | - |
|
312 | - |
|
313 | - /** |
|
314 | - * the_earliest_event_date - first date chronologically |
|
315 | - * |
|
316 | - * @param string $date_format |
|
317 | - * @param string $time_format |
|
318 | - * @param int $EVT_ID |
|
319 | - * @return string |
|
320 | - * @throws EE_Error |
|
321 | - * @throws ReflectionException |
|
322 | - */ |
|
323 | - public static function the_earliest_event_date($date_format = 'D M jS', $time_format = 'g:i a', $EVT_ID = 0) |
|
324 | - { |
|
325 | - $datetime = EEH_Event_View::get_earliest_date_obj($EVT_ID); |
|
326 | - $format = |
|
327 | - ! empty($date_format) && ! empty($time_format) |
|
328 | - ? $date_format . ' ' . $time_format |
|
329 | - : $date_format |
|
330 | - . $time_format; |
|
331 | - return $datetime instanceof EE_Datetime ? $datetime->get_i18n_datetime('DTT_EVT_start', $format) : ''; |
|
332 | - } |
|
333 | - |
|
334 | - |
|
335 | - /** |
|
336 | - * the_latest_event_date - latest date chronologically |
|
337 | - * |
|
338 | - * @param string $date_format |
|
339 | - * @param string $time_format |
|
340 | - * @param int $EVT_ID |
|
341 | - * @return string |
|
342 | - * @throws EE_Error |
|
343 | - * @throws ReflectionException |
|
344 | - */ |
|
345 | - public static function the_latest_event_date($date_format = 'D M jS', $time_format = 'g:i a', $EVT_ID = 0) |
|
346 | - { |
|
347 | - $datetime = EEH_Event_View::get_latest_date_obj($EVT_ID); |
|
348 | - $format = |
|
349 | - ! empty($date_format) && ! empty($time_format) |
|
350 | - ? $date_format . ' ' . $time_format |
|
351 | - : $date_format |
|
352 | - . $time_format; |
|
353 | - return $datetime instanceof EE_Datetime ? $datetime->get_i18n_datetime('DTT_EVT_end', $format) : ''; |
|
354 | - } |
|
355 | - |
|
356 | - |
|
357 | - /** |
|
358 | - * event_date_as_calendar_page |
|
359 | - * |
|
360 | - * @param int $EVT_ID |
|
361 | - * @return void |
|
362 | - * @throws EE_Error |
|
363 | - * @throws ReflectionException |
|
364 | - */ |
|
365 | - public static function event_date_as_calendar_page($EVT_ID = 0) |
|
366 | - { |
|
367 | - $datetime = EEH_Event_View::get_primary_date_obj($EVT_ID); |
|
368 | - if ($datetime instanceof EE_Datetime) { |
|
369 | - ?> |
|
12 | + /** |
|
13 | + * @var EE_Event $_event |
|
14 | + */ |
|
15 | + private static $_event = null; |
|
16 | + |
|
17 | + |
|
18 | + /** |
|
19 | + * get_event |
|
20 | + * attempts to retrieve an EE_Event object any way it can |
|
21 | + * |
|
22 | + * @param int|WP_Post $EVT_ID |
|
23 | + * @return EE_Event|null |
|
24 | + * @throws EE_Error |
|
25 | + * @throws ReflectionException |
|
26 | + */ |
|
27 | + public static function get_event($EVT_ID = 0) |
|
28 | + { |
|
29 | + // international newspaper? |
|
30 | + global $post; |
|
31 | + $EVT_ID = $EVT_ID instanceof WP_Post && $EVT_ID->post_type === 'espresso_events' |
|
32 | + ? $EVT_ID->ID |
|
33 | + : absint($EVT_ID); |
|
34 | + // do we already have the Event you are looking for? |
|
35 | + if (EEH_Event_View::$_event instanceof EE_Event && $EVT_ID && EEH_Event_View::$_event->ID() === $EVT_ID) { |
|
36 | + return EEH_Event_View::$_event; |
|
37 | + } |
|
38 | + // reset property so that the new event is cached. |
|
39 | + EEH_Event_View::$_event = null; |
|
40 | + if (! $EVT_ID && $post instanceof EE_Event) { |
|
41 | + EEH_Event_View::$_event = $post; |
|
42 | + return EEH_Event_View::$_event; |
|
43 | + } |
|
44 | + // if the post type is for an event and it has a cached event and we don't have a different incoming $EVT_ID |
|
45 | + // then let's just use that cached event on the $post object. |
|
46 | + if ( |
|
47 | + $post instanceof WP_Post |
|
48 | + && $post->post_type === 'espresso_events' |
|
49 | + && isset($post->EE_Event) |
|
50 | + && ( |
|
51 | + $EVT_ID === 0 |
|
52 | + || $EVT_ID === $post->ID |
|
53 | + ) |
|
54 | + ) { |
|
55 | + EEH_Event_View::$_event = $post->EE_Event; |
|
56 | + return EEH_Event_View::$_event; |
|
57 | + } |
|
58 | + // If the event we have isn't an event but we do have an EVT_ID, let's try getting the event using the ID. |
|
59 | + if (! EEH_Event_View::$_event instanceof EE_Event && $EVT_ID) { |
|
60 | + EEH_Event_View::$_event = EEM_Event::instance()->get_one_by_ID($EVT_ID); |
|
61 | + } |
|
62 | + return EEH_Event_View::$_event; |
|
63 | + } |
|
64 | + |
|
65 | + |
|
66 | + /** |
|
67 | + * display_ticket_selector |
|
68 | + * |
|
69 | + * @param int $EVT_ID |
|
70 | + * @return boolean |
|
71 | + * @throws EE_Error |
|
72 | + * @throws EE_Error |
|
73 | + * @throws ReflectionException |
|
74 | + */ |
|
75 | + public static function display_ticket_selector($EVT_ID = 0) |
|
76 | + { |
|
77 | + $event = EEH_Event_View::get_event($EVT_ID); |
|
78 | + return $event instanceof EE_Event && $event->display_ticket_selector(); |
|
79 | + } |
|
80 | + |
|
81 | + |
|
82 | + /** |
|
83 | + * event_status |
|
84 | + * |
|
85 | + * @param int $EVT_ID |
|
86 | + * @return string |
|
87 | + * @throws EE_Error |
|
88 | + * @throws EE_Error |
|
89 | + * @throws ReflectionException |
|
90 | + */ |
|
91 | + public static function event_status($EVT_ID = 0) |
|
92 | + { |
|
93 | + $event = EEH_Event_View::get_event($EVT_ID); |
|
94 | + return $event instanceof EE_Event ? $event->pretty_active_status(false) : ''; |
|
95 | + } |
|
96 | + |
|
97 | + |
|
98 | + /** |
|
99 | + * event_active_status |
|
100 | + * |
|
101 | + * @param int $EVT_ID |
|
102 | + * @return string |
|
103 | + * @throws EE_Error |
|
104 | + * @throws EE_Error |
|
105 | + * @throws ReflectionException |
|
106 | + */ |
|
107 | + public static function event_active_status($EVT_ID = 0, $echo = true) |
|
108 | + { |
|
109 | + $event = EEH_Event_View::get_event($EVT_ID); |
|
110 | + return $event instanceof EE_Event ? $event->pretty_active_status($echo) : 'inactive'; |
|
111 | + } |
|
112 | + |
|
113 | + |
|
114 | + /** |
|
115 | + * event_has_content_or_excerpt |
|
116 | + * |
|
117 | + * @param int $EVT_ID |
|
118 | + * @return bool |
|
119 | + * @throws EE_Error |
|
120 | + * @throws EE_Error |
|
121 | + * @throws ReflectionException |
|
122 | + */ |
|
123 | + public static function event_has_content_or_excerpt($EVT_ID = 0) |
|
124 | + { |
|
125 | + $event = EEH_Event_View::get_event($EVT_ID); |
|
126 | + $has_content_or_excerpt = false; |
|
127 | + if ($event instanceof EE_Event) { |
|
128 | + $has_content_or_excerpt = $event->description() != '' || $event->short_description(null, null, true) != ''; |
|
129 | + } |
|
130 | + if ( |
|
131 | + is_archive() |
|
132 | + && ! (espresso_display_full_description_in_event_list() |
|
133 | + || espresso_display_excerpt_in_event_list()) |
|
134 | + ) { |
|
135 | + $has_content_or_excerpt = false; |
|
136 | + } |
|
137 | + return $has_content_or_excerpt; |
|
138 | + } |
|
139 | + |
|
140 | + |
|
141 | + /** |
|
142 | + * event_active_status |
|
143 | + * |
|
144 | + * @param null $num_words |
|
145 | + * @param null $more |
|
146 | + * @return string |
|
147 | + */ |
|
148 | + public static function event_content_or_excerpt($num_words = null, $more = null) |
|
149 | + { |
|
150 | + global $post; |
|
151 | + ob_start(); |
|
152 | + if ((is_single()) || (is_archive() && espresso_display_full_description_in_event_list())) { |
|
153 | + // admin has chosen "full description" |
|
154 | + // for the "Event Espresso - Events > Templates > Display Description" option |
|
155 | + the_content(); |
|
156 | + } elseif ((is_archive() && espresso_display_excerpt_in_event_list())) { |
|
157 | + if (has_excerpt($post->ID)) { |
|
158 | + // admin has chosen "excerpt (short desc)" |
|
159 | + // for the "Event Espresso - Events > Templates > Display Description" option |
|
160 | + // AND an excerpt actually exists |
|
161 | + the_excerpt(); |
|
162 | + } else { |
|
163 | + // admin has chosen "excerpt (short desc)" |
|
164 | + // for the "Event Espresso - Events > Templates > Display Description" option |
|
165 | + // but NO excerpt actually exists, so we need to create one |
|
166 | + if (! empty($num_words)) { |
|
167 | + if (empty($more)) { |
|
168 | + $more_link_text = esc_html__('(more…)', 'event_espresso'); |
|
169 | + $more = ' <a href="' . get_permalink() . '"'; |
|
170 | + $more .= ' class="more-link"'; |
|
171 | + $more .= EED_Events_Archive::link_target(); |
|
172 | + $more .= '>' . $more_link_text . '</a>'; |
|
173 | + $more = apply_filters('the_content_more_link', $more, $more_link_text); |
|
174 | + } |
|
175 | + $content = str_replace('NOMORELINK', '', get_the_content('NOMORELINK')); |
|
176 | + |
|
177 | + $content = wp_trim_words($content, $num_words, ' ') . $more; |
|
178 | + } else { |
|
179 | + $content = get_the_content(); |
|
180 | + } |
|
181 | + global $allowedtags; |
|
182 | + // make sure links are allowed |
|
183 | + $allowedtags['a'] = isset($allowedtags['a']) |
|
184 | + ? $allowedtags['a'] |
|
185 | + : []; |
|
186 | + // as well as target attribute |
|
187 | + $allowedtags['a']['target'] = isset($allowedtags['a']['target']) |
|
188 | + ? $allowedtags['a']['target'] |
|
189 | + : false; |
|
190 | + // but get previous value so we can reset it |
|
191 | + $prev_value = $allowedtags['a']['target']; |
|
192 | + $allowedtags['a']['target'] = true; |
|
193 | + $content = wp_kses($content, $allowedtags); |
|
194 | + $content = strip_shortcodes($content); |
|
195 | + echo apply_filters('the_content', $content); |
|
196 | + $allowedtags['a']['target'] = $prev_value; |
|
197 | + } |
|
198 | + } else { |
|
199 | + // admin has chosen "none" |
|
200 | + // for the "Event Espresso - Events > Templates > Display Description" option |
|
201 | + echo apply_filters('the_content', ''); |
|
202 | + } |
|
203 | + return ob_get_clean(); |
|
204 | + } |
|
205 | + |
|
206 | + |
|
207 | + /** |
|
208 | + * event_tickets_available |
|
209 | + * |
|
210 | + * @param int $EVT_ID |
|
211 | + * @return EE_Ticket[] |
|
212 | + * @throws EE_Error |
|
213 | + * @throws ReflectionException |
|
214 | + */ |
|
215 | + public static function event_tickets_available($EVT_ID = 0) |
|
216 | + { |
|
217 | + $event = EEH_Event_View::get_event($EVT_ID); |
|
218 | + $tickets_available_for_purchase = []; |
|
219 | + if ($event instanceof EE_Event) { |
|
220 | + $datetimes = EEH_Event_View::get_all_date_obj($EVT_ID, false); |
|
221 | + foreach ($datetimes as $datetime) { |
|
222 | + $tickets_available_for_purchase = |
|
223 | + array_merge($tickets_available_for_purchase, $datetime->ticket_types_available_for_purchase()); |
|
224 | + } |
|
225 | + } |
|
226 | + return $tickets_available_for_purchase; |
|
227 | + } |
|
228 | + |
|
229 | + |
|
230 | + /** |
|
231 | + * the_event_date |
|
232 | + * |
|
233 | + * @param int $EVT_ID |
|
234 | + * @param bool $hide_uncategorized |
|
235 | + * @return string |
|
236 | + * @throws EE_Error |
|
237 | + * @throws ReflectionException |
|
238 | + */ |
|
239 | + public static function event_categories($EVT_ID = 0, $hide_uncategorized = true) |
|
240 | + { |
|
241 | + $category_links = []; |
|
242 | + $event = EEH_Event_View::get_event($EVT_ID); |
|
243 | + if ($event instanceof EE_Event) { |
|
244 | + $event_categories = get_the_terms($event->ID(), 'espresso_event_categories'); |
|
245 | + if ($event_categories) { |
|
246 | + // loop thru terms and create links |
|
247 | + foreach ($event_categories as $term) { |
|
248 | + $url = get_term_link($term, 'espresso_venue_categories'); |
|
249 | + if ( |
|
250 | + ! is_wp_error($url) |
|
251 | + && ( |
|
252 | + ( |
|
253 | + $hide_uncategorized |
|
254 | + && strtolower($term->name) != esc_html__('uncategorized', 'event_espresso') |
|
255 | + ) |
|
256 | + || ! $hide_uncategorized |
|
257 | + ) |
|
258 | + ) { |
|
259 | + $category_links[] = '<a href="' . esc_url_raw($url) . '" ' |
|
260 | + . 'rel="tag" ' . EED_Events_Archive::link_target() . '>' |
|
261 | + . esc_html($term->name) |
|
262 | + . '</a>'; |
|
263 | + } |
|
264 | + } |
|
265 | + } |
|
266 | + } |
|
267 | + return implode(', ', $category_links); |
|
268 | + } |
|
269 | + |
|
270 | + |
|
271 | + /** |
|
272 | + * the_event_date - first date by date order |
|
273 | + * |
|
274 | + * @param string $date_format |
|
275 | + * @param string $time_format |
|
276 | + * @param int $EVT_ID |
|
277 | + * @return string |
|
278 | + * @throws EE_Error |
|
279 | + * @throws ReflectionException |
|
280 | + */ |
|
281 | + public static function the_event_date($date_format = 'D M jS', $time_format = 'g:i a', $EVT_ID = 0) |
|
282 | + { |
|
283 | + $datetime = EEH_Event_View::get_primary_date_obj($EVT_ID); |
|
284 | + $format = ! empty($date_format) && ! empty($time_format) |
|
285 | + ? $date_format . ' ' . $time_format |
|
286 | + : $date_format . $time_format; |
|
287 | + return $datetime instanceof EE_Datetime ? $datetime->get_i18n_datetime('DTT_EVT_start', $format) : ''; |
|
288 | + } |
|
289 | + |
|
290 | + |
|
291 | + /** |
|
292 | + * the_event_end_date - last date by date order |
|
293 | + * |
|
294 | + * @param string $date_format |
|
295 | + * @param string $time_format |
|
296 | + * @param int $EVT_ID |
|
297 | + * @return string |
|
298 | + * @throws EE_Error |
|
299 | + * @throws ReflectionException |
|
300 | + */ |
|
301 | + public static function the_event_end_date($date_format = 'D M jS', $time_format = 'g:i a', $EVT_ID = 0) |
|
302 | + { |
|
303 | + $datetime = EEH_Event_View::get_last_date_obj($EVT_ID); |
|
304 | + $format = |
|
305 | + ! empty($date_format) && ! empty($time_format) |
|
306 | + ? $date_format . ' ' . $time_format |
|
307 | + : $date_format |
|
308 | + . $time_format; |
|
309 | + return $datetime instanceof EE_Datetime ? $datetime->get_i18n_datetime('DTT_EVT_end', $format) : ''; |
|
310 | + } |
|
311 | + |
|
312 | + |
|
313 | + /** |
|
314 | + * the_earliest_event_date - first date chronologically |
|
315 | + * |
|
316 | + * @param string $date_format |
|
317 | + * @param string $time_format |
|
318 | + * @param int $EVT_ID |
|
319 | + * @return string |
|
320 | + * @throws EE_Error |
|
321 | + * @throws ReflectionException |
|
322 | + */ |
|
323 | + public static function the_earliest_event_date($date_format = 'D M jS', $time_format = 'g:i a', $EVT_ID = 0) |
|
324 | + { |
|
325 | + $datetime = EEH_Event_View::get_earliest_date_obj($EVT_ID); |
|
326 | + $format = |
|
327 | + ! empty($date_format) && ! empty($time_format) |
|
328 | + ? $date_format . ' ' . $time_format |
|
329 | + : $date_format |
|
330 | + . $time_format; |
|
331 | + return $datetime instanceof EE_Datetime ? $datetime->get_i18n_datetime('DTT_EVT_start', $format) : ''; |
|
332 | + } |
|
333 | + |
|
334 | + |
|
335 | + /** |
|
336 | + * the_latest_event_date - latest date chronologically |
|
337 | + * |
|
338 | + * @param string $date_format |
|
339 | + * @param string $time_format |
|
340 | + * @param int $EVT_ID |
|
341 | + * @return string |
|
342 | + * @throws EE_Error |
|
343 | + * @throws ReflectionException |
|
344 | + */ |
|
345 | + public static function the_latest_event_date($date_format = 'D M jS', $time_format = 'g:i a', $EVT_ID = 0) |
|
346 | + { |
|
347 | + $datetime = EEH_Event_View::get_latest_date_obj($EVT_ID); |
|
348 | + $format = |
|
349 | + ! empty($date_format) && ! empty($time_format) |
|
350 | + ? $date_format . ' ' . $time_format |
|
351 | + : $date_format |
|
352 | + . $time_format; |
|
353 | + return $datetime instanceof EE_Datetime ? $datetime->get_i18n_datetime('DTT_EVT_end', $format) : ''; |
|
354 | + } |
|
355 | + |
|
356 | + |
|
357 | + /** |
|
358 | + * event_date_as_calendar_page |
|
359 | + * |
|
360 | + * @param int $EVT_ID |
|
361 | + * @return void |
|
362 | + * @throws EE_Error |
|
363 | + * @throws ReflectionException |
|
364 | + */ |
|
365 | + public static function event_date_as_calendar_page($EVT_ID = 0) |
|
366 | + { |
|
367 | + $datetime = EEH_Event_View::get_primary_date_obj($EVT_ID); |
|
368 | + if ($datetime instanceof EE_Datetime) { |
|
369 | + ?> |
|
370 | 370 | <div class="event-date-calendar-page-dv"> |
371 | 371 | <div class="event-date-calendar-page-month-dv"> |
372 | 372 | <?php echo esc_html($datetime->get_i18n_datetime('DTT_EVT_start', 'M')); ?> |
@@ -376,260 +376,260 @@ discard block |
||
376 | 376 | </div> |
377 | 377 | </div> |
378 | 378 | <?php |
379 | - } |
|
380 | - } |
|
381 | - |
|
382 | - |
|
383 | - /** |
|
384 | - * get_primary_date_obj - orders date by DTT_order |
|
385 | - * |
|
386 | - * @param int $EVT_ID |
|
387 | - * @return EE_Datetime |
|
388 | - * @throws EE_Error |
|
389 | - * @throws ReflectionException |
|
390 | - */ |
|
391 | - public static function get_primary_date_obj($EVT_ID = 0) |
|
392 | - { |
|
393 | - $event = EEH_Event_View::get_event($EVT_ID); |
|
394 | - if ($event instanceof EE_Event) { |
|
395 | - $datetimes = $event->get_many_related( |
|
396 | - 'Datetime', |
|
397 | - [ |
|
398 | - 'limit' => 1, |
|
399 | - 'order_by' => ['DTT_order' => 'ASC'], |
|
400 | - ] |
|
401 | - ); |
|
402 | - return reset($datetimes); |
|
403 | - } |
|
404 | - return null; |
|
405 | - } |
|
406 | - |
|
407 | - |
|
408 | - /** |
|
409 | - * get_last_date_obj - orders date by DTT_order |
|
410 | - * |
|
411 | - * @param int $EVT_ID |
|
412 | - * @return EE_Datetime |
|
413 | - * @throws EE_Error |
|
414 | - * @throws ReflectionException |
|
415 | - */ |
|
416 | - public static function get_last_date_obj($EVT_ID = 0) |
|
417 | - { |
|
418 | - $event = EEH_Event_View::get_event($EVT_ID); |
|
419 | - if ($event instanceof EE_Event) { |
|
420 | - $datetimes = $event->get_many_related( |
|
421 | - 'Datetime', |
|
422 | - [ |
|
423 | - 'limit' => 1, |
|
424 | - 'order_by' => ['DTT_order' => 'DESC'], |
|
425 | - ] |
|
426 | - ); |
|
427 | - return end($datetimes); |
|
428 | - } |
|
429 | - return null; |
|
430 | - } |
|
431 | - |
|
432 | - |
|
433 | - /** |
|
434 | - * get_earliest_date_obj - orders date chronologically |
|
435 | - * |
|
436 | - * @param int $EVT_ID |
|
437 | - * @return EE_Datetime |
|
438 | - * @throws EE_Error |
|
439 | - * @throws ReflectionException |
|
440 | - */ |
|
441 | - public static function get_earliest_date_obj($EVT_ID = 0) |
|
442 | - { |
|
443 | - $event = EEH_Event_View::get_event($EVT_ID); |
|
444 | - if ($event instanceof EE_Event) { |
|
445 | - $datetimes = $event->get_many_related( |
|
446 | - 'Datetime', |
|
447 | - [ |
|
448 | - 'limit' => 1, |
|
449 | - 'order_by' => ['DTT_EVT_start' => 'ASC'], |
|
450 | - ] |
|
451 | - ); |
|
452 | - return reset($datetimes); |
|
453 | - } |
|
454 | - return null; |
|
455 | - } |
|
456 | - |
|
457 | - |
|
458 | - /** |
|
459 | - * get_latest_date_obj - orders date chronologically |
|
460 | - * |
|
461 | - * @param int $EVT_ID |
|
462 | - * @return EE_Datetime |
|
463 | - * @throws EE_Error |
|
464 | - * @throws ReflectionException |
|
465 | - */ |
|
466 | - public static function get_latest_date_obj($EVT_ID = 0) |
|
467 | - { |
|
468 | - $event = EEH_Event_View::get_event($EVT_ID); |
|
469 | - if ($event instanceof EE_Event) { |
|
470 | - $datetimes = $event->get_many_related( |
|
471 | - 'Datetime', |
|
472 | - [ |
|
473 | - 'limit' => 1, |
|
474 | - 'order_by' => ['DTT_EVT_start' => 'DESC'], |
|
475 | - ] |
|
476 | - ); |
|
477 | - return end($datetimes); |
|
478 | - } |
|
479 | - return null; |
|
480 | - } |
|
481 | - |
|
482 | - |
|
483 | - /** |
|
484 | - * get_next_upcoming_date_obj - return the next upcoming datetime |
|
485 | - * |
|
486 | - * @param int $EVT_ID |
|
487 | - * @return EE_Datetime|null |
|
488 | - * @throws EE_Error |
|
489 | - * @throws EE_Error |
|
490 | - */ |
|
491 | - public static function get_next_upcoming_date_obj($EVT_ID = 0) |
|
492 | - { |
|
493 | - $datetime = EEM_Datetime::instance()->get_one( |
|
494 | - [ |
|
495 | - [ |
|
496 | - 'Event.EVT_ID' => $EVT_ID, |
|
497 | - 'DTT_EVT_start' => ['>=', current_time('mysql', true)], |
|
498 | - ], |
|
499 | - 'order_by' => ['DTT_EVT_start' => 'asc'], |
|
500 | - ] |
|
501 | - ); |
|
502 | - return $datetime instanceof EE_Datetime ? $datetime : null; |
|
503 | - } |
|
504 | - |
|
505 | - |
|
506 | - /** |
|
507 | - * get_all_date_obj |
|
508 | - * |
|
509 | - * @param int $EVT_ID |
|
510 | - * @param null $include_expired |
|
511 | - * @param bool $include_deleted |
|
512 | - * @param null $limit |
|
513 | - * @return EE_Datetime[] |
|
514 | - * @throws EE_Error |
|
515 | - * @throws EE_Error |
|
516 | - * @throws ReflectionException |
|
517 | - */ |
|
518 | - public static function get_all_date_obj( |
|
519 | - $EVT_ID = 0, |
|
520 | - $include_expired = null, |
|
521 | - $include_deleted = false, |
|
522 | - $limit = null |
|
523 | - ) { |
|
524 | - $event = EEH_Event_View::get_event($EVT_ID); |
|
525 | - if ($include_expired === null) { |
|
526 | - if ($event instanceof EE_Event && $event->is_expired()) { |
|
527 | - $include_expired = true; |
|
528 | - } else { |
|
529 | - $include_expired = false; |
|
530 | - } |
|
531 | - } |
|
532 | - |
|
533 | - if ($event instanceof EE_Event) { |
|
534 | - return $event->datetimes_ordered($include_expired, $include_deleted, $limit); |
|
535 | - } |
|
536 | - return []; |
|
537 | - } |
|
538 | - |
|
539 | - |
|
540 | - /** |
|
541 | - * event_link_url |
|
542 | - * |
|
543 | - * @param int $EVT_ID |
|
544 | - * @return string |
|
545 | - * @throws EE_Error |
|
546 | - * @throws ReflectionException |
|
547 | - */ |
|
548 | - public static function event_link_url($EVT_ID = 0) |
|
549 | - { |
|
550 | - $event = EEH_Event_View::get_event($EVT_ID); |
|
551 | - if ($event instanceof EE_Event) { |
|
552 | - $url = $event->external_url() !== null && $event->external_url() !== '' |
|
553 | - ? $event->external_url() |
|
554 | - : get_permalink($event->ID()); |
|
555 | - $url = preg_match("~^(?:f|ht)tps?://~i", $url) ? $url : 'https://' . $url; |
|
556 | - return esc_url_raw($url); |
|
557 | - } |
|
558 | - return ''; |
|
559 | - } |
|
560 | - |
|
561 | - |
|
562 | - /** |
|
563 | - * event_phone |
|
564 | - * |
|
565 | - * @param int $EVT_ID |
|
566 | - * @return string |
|
567 | - * @throws EE_Error |
|
568 | - * @throws EE_Error |
|
569 | - * @throws ReflectionException |
|
570 | - */ |
|
571 | - public static function event_phone($EVT_ID = 0) |
|
572 | - { |
|
573 | - $event = EEH_Event_View::get_event($EVT_ID); |
|
574 | - if ($event instanceof EE_Event) { |
|
575 | - return EEH_Schema::telephone($event->phone()); |
|
576 | - } |
|
577 | - return null; |
|
578 | - } |
|
579 | - |
|
580 | - |
|
581 | - /** |
|
582 | - * edit_event_link |
|
583 | - * |
|
584 | - * @param int $EVT_ID |
|
585 | - * @param string $link |
|
586 | - * @param string $before |
|
587 | - * @param string $after |
|
588 | - * @return string |
|
589 | - * @throws EE_Error |
|
590 | - * @throws ReflectionException |
|
591 | - */ |
|
592 | - public static function edit_event_link($EVT_ID = 0, $link = '', $before = '', $after = '') |
|
593 | - { |
|
594 | - $event = EEH_Event_View::get_event($EVT_ID); |
|
595 | - if ($event instanceof EE_Event) { |
|
596 | - // can the user edit this post ? |
|
597 | - if (current_user_can('edit_post', $event->ID())) { |
|
598 | - // set link text |
|
599 | - $link_text = ! empty($link) ? $link : esc_html__('edit this event', 'event_espresso'); |
|
600 | - // generate nonce |
|
601 | - $nonce = wp_create_nonce('edit_nonce'); |
|
602 | - // generate url to event editor for this event |
|
603 | - $url = |
|
604 | - add_query_arg( |
|
605 | - [ |
|
606 | - 'page' => 'espresso_events', |
|
607 | - 'action' => 'edit', |
|
608 | - 'post' => $event->ID(), |
|
609 | - 'edit_nonce' => $nonce, |
|
610 | - ], |
|
611 | - admin_url() |
|
612 | - ); |
|
613 | - // get edit CPT text |
|
614 | - $post_type_obj = get_post_type_object('espresso_events'); |
|
615 | - // build final link html |
|
616 | - $link = '<a class="post-edit-link" href="' . $url . '" '; |
|
617 | - $link .= ' title="' . esc_attr($post_type_obj->labels->edit_item) . '"'; |
|
618 | - $link .= EED_Events_Archive::link_target(); |
|
619 | - $link .= '>' . $link_text . '</a>'; |
|
620 | - // put it all together |
|
621 | - return $before . apply_filters('edit_post_link', $link, $event->ID()) . $after; |
|
622 | - } |
|
623 | - } |
|
624 | - return ''; |
|
625 | - } |
|
626 | - |
|
627 | - |
|
628 | - /** |
|
629 | - * @return string |
|
630 | - */ |
|
631 | - public static function event_archive_url() |
|
632 | - { |
|
633 | - return get_post_type_archive_link('espresso_events'); |
|
634 | - } |
|
379 | + } |
|
380 | + } |
|
381 | + |
|
382 | + |
|
383 | + /** |
|
384 | + * get_primary_date_obj - orders date by DTT_order |
|
385 | + * |
|
386 | + * @param int $EVT_ID |
|
387 | + * @return EE_Datetime |
|
388 | + * @throws EE_Error |
|
389 | + * @throws ReflectionException |
|
390 | + */ |
|
391 | + public static function get_primary_date_obj($EVT_ID = 0) |
|
392 | + { |
|
393 | + $event = EEH_Event_View::get_event($EVT_ID); |
|
394 | + if ($event instanceof EE_Event) { |
|
395 | + $datetimes = $event->get_many_related( |
|
396 | + 'Datetime', |
|
397 | + [ |
|
398 | + 'limit' => 1, |
|
399 | + 'order_by' => ['DTT_order' => 'ASC'], |
|
400 | + ] |
|
401 | + ); |
|
402 | + return reset($datetimes); |
|
403 | + } |
|
404 | + return null; |
|
405 | + } |
|
406 | + |
|
407 | + |
|
408 | + /** |
|
409 | + * get_last_date_obj - orders date by DTT_order |
|
410 | + * |
|
411 | + * @param int $EVT_ID |
|
412 | + * @return EE_Datetime |
|
413 | + * @throws EE_Error |
|
414 | + * @throws ReflectionException |
|
415 | + */ |
|
416 | + public static function get_last_date_obj($EVT_ID = 0) |
|
417 | + { |
|
418 | + $event = EEH_Event_View::get_event($EVT_ID); |
|
419 | + if ($event instanceof EE_Event) { |
|
420 | + $datetimes = $event->get_many_related( |
|
421 | + 'Datetime', |
|
422 | + [ |
|
423 | + 'limit' => 1, |
|
424 | + 'order_by' => ['DTT_order' => 'DESC'], |
|
425 | + ] |
|
426 | + ); |
|
427 | + return end($datetimes); |
|
428 | + } |
|
429 | + return null; |
|
430 | + } |
|
431 | + |
|
432 | + |
|
433 | + /** |
|
434 | + * get_earliest_date_obj - orders date chronologically |
|
435 | + * |
|
436 | + * @param int $EVT_ID |
|
437 | + * @return EE_Datetime |
|
438 | + * @throws EE_Error |
|
439 | + * @throws ReflectionException |
|
440 | + */ |
|
441 | + public static function get_earliest_date_obj($EVT_ID = 0) |
|
442 | + { |
|
443 | + $event = EEH_Event_View::get_event($EVT_ID); |
|
444 | + if ($event instanceof EE_Event) { |
|
445 | + $datetimes = $event->get_many_related( |
|
446 | + 'Datetime', |
|
447 | + [ |
|
448 | + 'limit' => 1, |
|
449 | + 'order_by' => ['DTT_EVT_start' => 'ASC'], |
|
450 | + ] |
|
451 | + ); |
|
452 | + return reset($datetimes); |
|
453 | + } |
|
454 | + return null; |
|
455 | + } |
|
456 | + |
|
457 | + |
|
458 | + /** |
|
459 | + * get_latest_date_obj - orders date chronologically |
|
460 | + * |
|
461 | + * @param int $EVT_ID |
|
462 | + * @return EE_Datetime |
|
463 | + * @throws EE_Error |
|
464 | + * @throws ReflectionException |
|
465 | + */ |
|
466 | + public static function get_latest_date_obj($EVT_ID = 0) |
|
467 | + { |
|
468 | + $event = EEH_Event_View::get_event($EVT_ID); |
|
469 | + if ($event instanceof EE_Event) { |
|
470 | + $datetimes = $event->get_many_related( |
|
471 | + 'Datetime', |
|
472 | + [ |
|
473 | + 'limit' => 1, |
|
474 | + 'order_by' => ['DTT_EVT_start' => 'DESC'], |
|
475 | + ] |
|
476 | + ); |
|
477 | + return end($datetimes); |
|
478 | + } |
|
479 | + return null; |
|
480 | + } |
|
481 | + |
|
482 | + |
|
483 | + /** |
|
484 | + * get_next_upcoming_date_obj - return the next upcoming datetime |
|
485 | + * |
|
486 | + * @param int $EVT_ID |
|
487 | + * @return EE_Datetime|null |
|
488 | + * @throws EE_Error |
|
489 | + * @throws EE_Error |
|
490 | + */ |
|
491 | + public static function get_next_upcoming_date_obj($EVT_ID = 0) |
|
492 | + { |
|
493 | + $datetime = EEM_Datetime::instance()->get_one( |
|
494 | + [ |
|
495 | + [ |
|
496 | + 'Event.EVT_ID' => $EVT_ID, |
|
497 | + 'DTT_EVT_start' => ['>=', current_time('mysql', true)], |
|
498 | + ], |
|
499 | + 'order_by' => ['DTT_EVT_start' => 'asc'], |
|
500 | + ] |
|
501 | + ); |
|
502 | + return $datetime instanceof EE_Datetime ? $datetime : null; |
|
503 | + } |
|
504 | + |
|
505 | + |
|
506 | + /** |
|
507 | + * get_all_date_obj |
|
508 | + * |
|
509 | + * @param int $EVT_ID |
|
510 | + * @param null $include_expired |
|
511 | + * @param bool $include_deleted |
|
512 | + * @param null $limit |
|
513 | + * @return EE_Datetime[] |
|
514 | + * @throws EE_Error |
|
515 | + * @throws EE_Error |
|
516 | + * @throws ReflectionException |
|
517 | + */ |
|
518 | + public static function get_all_date_obj( |
|
519 | + $EVT_ID = 0, |
|
520 | + $include_expired = null, |
|
521 | + $include_deleted = false, |
|
522 | + $limit = null |
|
523 | + ) { |
|
524 | + $event = EEH_Event_View::get_event($EVT_ID); |
|
525 | + if ($include_expired === null) { |
|
526 | + if ($event instanceof EE_Event && $event->is_expired()) { |
|
527 | + $include_expired = true; |
|
528 | + } else { |
|
529 | + $include_expired = false; |
|
530 | + } |
|
531 | + } |
|
532 | + |
|
533 | + if ($event instanceof EE_Event) { |
|
534 | + return $event->datetimes_ordered($include_expired, $include_deleted, $limit); |
|
535 | + } |
|
536 | + return []; |
|
537 | + } |
|
538 | + |
|
539 | + |
|
540 | + /** |
|
541 | + * event_link_url |
|
542 | + * |
|
543 | + * @param int $EVT_ID |
|
544 | + * @return string |
|
545 | + * @throws EE_Error |
|
546 | + * @throws ReflectionException |
|
547 | + */ |
|
548 | + public static function event_link_url($EVT_ID = 0) |
|
549 | + { |
|
550 | + $event = EEH_Event_View::get_event($EVT_ID); |
|
551 | + if ($event instanceof EE_Event) { |
|
552 | + $url = $event->external_url() !== null && $event->external_url() !== '' |
|
553 | + ? $event->external_url() |
|
554 | + : get_permalink($event->ID()); |
|
555 | + $url = preg_match("~^(?:f|ht)tps?://~i", $url) ? $url : 'https://' . $url; |
|
556 | + return esc_url_raw($url); |
|
557 | + } |
|
558 | + return ''; |
|
559 | + } |
|
560 | + |
|
561 | + |
|
562 | + /** |
|
563 | + * event_phone |
|
564 | + * |
|
565 | + * @param int $EVT_ID |
|
566 | + * @return string |
|
567 | + * @throws EE_Error |
|
568 | + * @throws EE_Error |
|
569 | + * @throws ReflectionException |
|
570 | + */ |
|
571 | + public static function event_phone($EVT_ID = 0) |
|
572 | + { |
|
573 | + $event = EEH_Event_View::get_event($EVT_ID); |
|
574 | + if ($event instanceof EE_Event) { |
|
575 | + return EEH_Schema::telephone($event->phone()); |
|
576 | + } |
|
577 | + return null; |
|
578 | + } |
|
579 | + |
|
580 | + |
|
581 | + /** |
|
582 | + * edit_event_link |
|
583 | + * |
|
584 | + * @param int $EVT_ID |
|
585 | + * @param string $link |
|
586 | + * @param string $before |
|
587 | + * @param string $after |
|
588 | + * @return string |
|
589 | + * @throws EE_Error |
|
590 | + * @throws ReflectionException |
|
591 | + */ |
|
592 | + public static function edit_event_link($EVT_ID = 0, $link = '', $before = '', $after = '') |
|
593 | + { |
|
594 | + $event = EEH_Event_View::get_event($EVT_ID); |
|
595 | + if ($event instanceof EE_Event) { |
|
596 | + // can the user edit this post ? |
|
597 | + if (current_user_can('edit_post', $event->ID())) { |
|
598 | + // set link text |
|
599 | + $link_text = ! empty($link) ? $link : esc_html__('edit this event', 'event_espresso'); |
|
600 | + // generate nonce |
|
601 | + $nonce = wp_create_nonce('edit_nonce'); |
|
602 | + // generate url to event editor for this event |
|
603 | + $url = |
|
604 | + add_query_arg( |
|
605 | + [ |
|
606 | + 'page' => 'espresso_events', |
|
607 | + 'action' => 'edit', |
|
608 | + 'post' => $event->ID(), |
|
609 | + 'edit_nonce' => $nonce, |
|
610 | + ], |
|
611 | + admin_url() |
|
612 | + ); |
|
613 | + // get edit CPT text |
|
614 | + $post_type_obj = get_post_type_object('espresso_events'); |
|
615 | + // build final link html |
|
616 | + $link = '<a class="post-edit-link" href="' . $url . '" '; |
|
617 | + $link .= ' title="' . esc_attr($post_type_obj->labels->edit_item) . '"'; |
|
618 | + $link .= EED_Events_Archive::link_target(); |
|
619 | + $link .= '>' . $link_text . '</a>'; |
|
620 | + // put it all together |
|
621 | + return $before . apply_filters('edit_post_link', $link, $event->ID()) . $after; |
|
622 | + } |
|
623 | + } |
|
624 | + return ''; |
|
625 | + } |
|
626 | + |
|
627 | + |
|
628 | + /** |
|
629 | + * @return string |
|
630 | + */ |
|
631 | + public static function event_archive_url() |
|
632 | + { |
|
633 | + return get_post_type_archive_link('espresso_events'); |
|
634 | + } |
|
635 | 635 | } |
@@ -51,7 +51,7 @@ discard block |
||
51 | 51 | ? esc_url_raw($ee_gmaps_opts['ee_static_url']) |
52 | 52 | : false; |
53 | 53 | |
54 | - if (! empty($ee_gmaps_opts['ee_map_align'])) { |
|
54 | + if ( ! empty($ee_gmaps_opts['ee_map_align'])) { |
|
55 | 55 | switch ($ee_gmaps_opts['ee_map_align']) { |
56 | 56 | case "left": |
57 | 57 | $map_align = 'ee-gmap-align-left left'; |
@@ -75,18 +75,18 @@ discard block |
||
75 | 75 | // if so display a Google static iframe map else run V3 api |
76 | 76 | if ($static_url) { |
77 | 77 | $html = ' |
78 | - <div class="ee-gmap-iframewrap ee-gmap-wrapper ' . $map_align . '"> |
|
79 | - <iframe src="' . $static_url . '&output=embed" |
|
80 | - style="width: ' . $ee_map_width . 'px; height: ' . $ee_map_height . 'px;" |
|
78 | + <div class="ee-gmap-iframewrap ee-gmap-wrapper ' . $map_align.'"> |
|
79 | + <iframe src="' . $static_url.'&output=embed" |
|
80 | + style="width: ' . $ee_map_width.'px; height: '.$ee_map_height.'px;" |
|
81 | 81 | frameborder="0" |
82 | 82 | scrolling="no" |
83 | 83 | > |
84 | 84 | </iframe> |
85 | - <a href="' . $static_url . '">' . esc_html__('View Large map', 'event_espresso') . '</a> |
|
85 | + <a href="' . $static_url.'">'.esc_html__('View Large map', 'event_espresso').'</a> |
|
86 | 86 | </div> |
87 | 87 | '; |
88 | 88 | } else { |
89 | - EEH_Maps::$gmap_vars[ $ee_gmaps_opts['map_ID'] ] = [ |
|
89 | + EEH_Maps::$gmap_vars[$ee_gmaps_opts['map_ID']] = [ |
|
90 | 90 | 'map_ID' => $ee_gmaps_opts['map_ID'], |
91 | 91 | 'ee_map_zoom' => $ee_map_zoom, |
92 | 92 | 'ee_map_nav_display' => $ee_map_nav_display, |
@@ -95,12 +95,12 @@ discard block |
||
95 | 95 | 'location' => $ee_gmaps_opts['location'], |
96 | 96 | ]; |
97 | 97 | |
98 | - $style = 'width: ' . $ee_map_width . 'px; height: ' . $ee_map_height . 'px;'; |
|
98 | + $style = 'width: '.$ee_map_width.'px; height: '.$ee_map_height.'px;'; |
|
99 | 99 | $html = ' |
100 | - <div class="ee-gmap-wrapper ' . esc_attr($map_align) . '"> |
|
100 | + <div class="ee-gmap-wrapper ' . esc_attr($map_align).'"> |
|
101 | 101 | <div class="ee-gmap" |
102 | - id="map_canvas_' . esc_attr($ee_gmaps_opts['map_ID']) . '" |
|
103 | - style="' . esc_attr($style) . '" |
|
102 | + id="map_canvas_' . esc_attr($ee_gmaps_opts['map_ID']).'" |
|
103 | + style="' . esc_attr($style).'" |
|
104 | 104 | ></div> |
105 | 105 | </div>'; |
106 | 106 | |
@@ -144,7 +144,7 @@ discard block |
||
144 | 144 | ); |
145 | 145 | wp_register_script( |
146 | 146 | 'ee_gmap', |
147 | - plugin_dir_url(__FILE__) . 'assets/ee_gmap.js', |
|
147 | + plugin_dir_url(__FILE__).'assets/ee_gmap.js', |
|
148 | 148 | ['gmap_api'], |
149 | 149 | '1.0', |
150 | 150 | true |
@@ -180,12 +180,12 @@ discard block |
||
180 | 180 | $map_image_class = isset($map_image_class) ? $map_image_class : 'ee_google_map_view'; |
181 | 181 | |
182 | 182 | $address_string = ($address != '' ? $address : '') |
183 | - . ($city != '' ? ',' . $city : '') |
|
184 | - . ($state != '' ? ',' . $state : '') |
|
185 | - . ($zip != '' ? ',' . $zip : '') |
|
186 | - . ($country != '' ? ',' . $country : ''); |
|
183 | + . ($city != '' ? ','.$city : '') |
|
184 | + . ($state != '' ? ','.$state : '') |
|
185 | + . ($zip != '' ? ','.$zip : '') |
|
186 | + . ($country != '' ? ','.$country : ''); |
|
187 | 187 | |
188 | - $google_map = htmlentities2('https://maps.google.com/maps?q=' . urlencode($address_string)); |
|
188 | + $google_map = htmlentities2('https://maps.google.com/maps?q='.urlencode($address_string)); |
|
189 | 189 | |
190 | 190 | switch ($type) { |
191 | 191 | case 'text': |
@@ -208,31 +208,31 @@ discard block |
||
208 | 208 | |
209 | 209 | return ' |
210 | 210 | <a class="a_map_image_link" |
211 | - href="' . esc_url_raw($google_map) . '" |
|
211 | + href="' . esc_url_raw($google_map).'" |
|
212 | 212 | target="_blank" |
213 | 213 | rel="noopener noreferrer" |
214 | 214 | > |
215 | - <img alt="' . esc_html__('Map and Directions', 'event_espresso') . '" |
|
215 | + <img alt="' . esc_html__('Map and Directions', 'event_espresso').'" |
|
216 | 216 | class="map_image_link" |
217 | - id="venue_map_' . $id . '" ' . $map_image_class . ' |
|
217 | + id="venue_map_' . $id.'" '.$map_image_class.' |
|
218 | 218 | src="' |
219 | 219 | . htmlentities2( |
220 | 220 | $scheme |
221 | 221 | . 'maps.googleapis.com/maps/api/staticmap?center=' |
222 | 222 | . urlencode($address_string) |
223 | 223 | . '&zoom=14&size=' |
224 | - . $map_w . 'x' . $map_h |
|
224 | + . $map_w.'x'.$map_h |
|
225 | 225 | . '&markers=color:green|label:|' |
226 | 226 | . urlencode($address_string) |
227 | 227 | . '&sensor=false&key=' |
228 | 228 | . $api_key |
229 | - ) . '" |
|
229 | + ).'" |
|
230 | 230 | /> |
231 | 231 | </a>'; |
232 | 232 | } |
233 | 233 | |
234 | 234 | return $type === 'url_only' |
235 | 235 | ? $text |
236 | - : '<a href="' . esc_url_raw($google_map) . '" target="_blank" rel="noopener noreferrer">' . $text . '</a>'; |
|
236 | + : '<a href="'.esc_url_raw($google_map).'" target="_blank" rel="noopener noreferrer">'.$text.'</a>'; |
|
237 | 237 | } |
238 | 238 | } |
@@ -11,69 +11,69 @@ discard block |
||
11 | 11 | */ |
12 | 12 | class EEH_Maps |
13 | 13 | { |
14 | - // array of map settings |
|
15 | - public static $gmap_vars = []; |
|
16 | - |
|
17 | - |
|
18 | - /** |
|
19 | - * google_map - creates a Google Map Link |
|
20 | - * |
|
21 | - * @param array $ee_gmaps_opts array of attributes required for the map link generation |
|
22 | - * @return string (link to map!) |
|
23 | - */ |
|
24 | - public static function google_map($ee_gmaps_opts) |
|
25 | - { |
|
26 | - |
|
27 | - $ee_map_width = ! empty($ee_gmaps_opts['ee_map_width']) |
|
28 | - ? absint($ee_gmaps_opts['ee_map_width']) |
|
29 | - : 300; |
|
30 | - |
|
31 | - $ee_map_height = ! empty($ee_gmaps_opts['ee_map_height']) |
|
32 | - ? absint($ee_gmaps_opts['ee_map_height']) |
|
33 | - : 185; |
|
34 | - |
|
35 | - $ee_map_zoom = ! empty($ee_gmaps_opts['ee_map_zoom']) |
|
36 | - ? absint($ee_gmaps_opts['ee_map_zoom']) |
|
37 | - : 12; |
|
38 | - |
|
39 | - $ee_map_nav_display = ! empty($ee_gmaps_opts['ee_map_nav_display']) ? 'true' : 'false'; |
|
40 | - |
|
41 | - $ee_map_nav_size = ! empty($ee_gmaps_opts['ee_map_nav_size']) |
|
42 | - ? sanitize_text_field($ee_gmaps_opts['ee_map_nav_size']) |
|
43 | - : 'default'; |
|
44 | - |
|
45 | - $ee_map_type_control = ! empty($ee_gmaps_opts['ee_map_type_control']) |
|
46 | - ? sanitize_text_field($ee_gmaps_opts['ee_map_type_control']) |
|
47 | - : 'default'; |
|
48 | - |
|
49 | - $static_url = ! empty($ee_gmaps_opts['ee_static_url']) |
|
50 | - ? esc_url_raw($ee_gmaps_opts['ee_static_url']) |
|
51 | - : false; |
|
52 | - |
|
53 | - if (! empty($ee_gmaps_opts['ee_map_align'])) { |
|
54 | - switch ($ee_gmaps_opts['ee_map_align']) { |
|
55 | - case "left": |
|
56 | - $map_align = 'ee-gmap-align-left left'; |
|
57 | - break; |
|
58 | - case "right": |
|
59 | - $map_align = 'ee-gmap-align-right right'; |
|
60 | - break; |
|
61 | - case "center": |
|
62 | - $map_align = 'ee-gmap-align-center center'; |
|
63 | - break; |
|
64 | - case "none": |
|
65 | - default: |
|
66 | - $map_align = 'ee-gmap-align-none'; |
|
67 | - } |
|
68 | - } else { |
|
69 | - $map_align = 'ee-gmap-align-none'; |
|
70 | - } |
|
71 | - |
|
72 | - |
|
73 | - // Determine whether user has set a hardcoded url to use and |
|
74 | - // if so display a Google static iframe map else run V3 api |
|
75 | - if ($static_url) { |
|
76 | - $html = ' |
|
14 | + // array of map settings |
|
15 | + public static $gmap_vars = []; |
|
16 | + |
|
17 | + |
|
18 | + /** |
|
19 | + * google_map - creates a Google Map Link |
|
20 | + * |
|
21 | + * @param array $ee_gmaps_opts array of attributes required for the map link generation |
|
22 | + * @return string (link to map!) |
|
23 | + */ |
|
24 | + public static function google_map($ee_gmaps_opts) |
|
25 | + { |
|
26 | + |
|
27 | + $ee_map_width = ! empty($ee_gmaps_opts['ee_map_width']) |
|
28 | + ? absint($ee_gmaps_opts['ee_map_width']) |
|
29 | + : 300; |
|
30 | + |
|
31 | + $ee_map_height = ! empty($ee_gmaps_opts['ee_map_height']) |
|
32 | + ? absint($ee_gmaps_opts['ee_map_height']) |
|
33 | + : 185; |
|
34 | + |
|
35 | + $ee_map_zoom = ! empty($ee_gmaps_opts['ee_map_zoom']) |
|
36 | + ? absint($ee_gmaps_opts['ee_map_zoom']) |
|
37 | + : 12; |
|
38 | + |
|
39 | + $ee_map_nav_display = ! empty($ee_gmaps_opts['ee_map_nav_display']) ? 'true' : 'false'; |
|
40 | + |
|
41 | + $ee_map_nav_size = ! empty($ee_gmaps_opts['ee_map_nav_size']) |
|
42 | + ? sanitize_text_field($ee_gmaps_opts['ee_map_nav_size']) |
|
43 | + : 'default'; |
|
44 | + |
|
45 | + $ee_map_type_control = ! empty($ee_gmaps_opts['ee_map_type_control']) |
|
46 | + ? sanitize_text_field($ee_gmaps_opts['ee_map_type_control']) |
|
47 | + : 'default'; |
|
48 | + |
|
49 | + $static_url = ! empty($ee_gmaps_opts['ee_static_url']) |
|
50 | + ? esc_url_raw($ee_gmaps_opts['ee_static_url']) |
|
51 | + : false; |
|
52 | + |
|
53 | + if (! empty($ee_gmaps_opts['ee_map_align'])) { |
|
54 | + switch ($ee_gmaps_opts['ee_map_align']) { |
|
55 | + case "left": |
|
56 | + $map_align = 'ee-gmap-align-left left'; |
|
57 | + break; |
|
58 | + case "right": |
|
59 | + $map_align = 'ee-gmap-align-right right'; |
|
60 | + break; |
|
61 | + case "center": |
|
62 | + $map_align = 'ee-gmap-align-center center'; |
|
63 | + break; |
|
64 | + case "none": |
|
65 | + default: |
|
66 | + $map_align = 'ee-gmap-align-none'; |
|
67 | + } |
|
68 | + } else { |
|
69 | + $map_align = 'ee-gmap-align-none'; |
|
70 | + } |
|
71 | + |
|
72 | + |
|
73 | + // Determine whether user has set a hardcoded url to use and |
|
74 | + // if so display a Google static iframe map else run V3 api |
|
75 | + if ($static_url) { |
|
76 | + $html = ' |
|
77 | 77 | <div class="ee-gmap-iframewrap ee-gmap-wrapper ' . $map_align . '"> |
78 | 78 | <iframe src="' . $static_url . '&output=embed" |
79 | 79 | style="width: ' . $ee_map_width . 'px; height: ' . $ee_map_height . 'px;" |
@@ -84,18 +84,18 @@ discard block |
||
84 | 84 | <a href="' . $static_url . '">' . esc_html__('View Large map', 'event_espresso') . '</a> |
85 | 85 | </div> |
86 | 86 | '; |
87 | - } else { |
|
88 | - EEH_Maps::$gmap_vars[ $ee_gmaps_opts['map_ID'] ] = [ |
|
89 | - 'map_ID' => $ee_gmaps_opts['map_ID'], |
|
90 | - 'ee_map_zoom' => $ee_map_zoom, |
|
91 | - 'ee_map_nav_display' => $ee_map_nav_display, |
|
92 | - 'ee_map_nav_size' => $ee_map_nav_size, |
|
93 | - 'ee_map_type_control' => $ee_map_type_control, |
|
94 | - 'location' => $ee_gmaps_opts['location'], |
|
95 | - ]; |
|
96 | - |
|
97 | - $style = 'width: ' . $ee_map_width . 'px; height: ' . $ee_map_height . 'px;'; |
|
98 | - $html = ' |
|
87 | + } else { |
|
88 | + EEH_Maps::$gmap_vars[ $ee_gmaps_opts['map_ID'] ] = [ |
|
89 | + 'map_ID' => $ee_gmaps_opts['map_ID'], |
|
90 | + 'ee_map_zoom' => $ee_map_zoom, |
|
91 | + 'ee_map_nav_display' => $ee_map_nav_display, |
|
92 | + 'ee_map_nav_size' => $ee_map_nav_size, |
|
93 | + 'ee_map_type_control' => $ee_map_type_control, |
|
94 | + 'location' => $ee_gmaps_opts['location'], |
|
95 | + ]; |
|
96 | + |
|
97 | + $style = 'width: ' . $ee_map_width . 'px; height: ' . $ee_map_height . 'px;'; |
|
98 | + $html = ' |
|
99 | 99 | <div class="ee-gmap-wrapper ' . esc_attr($map_align) . '"> |
100 | 100 | <div class="ee-gmap" |
101 | 101 | id="map_canvas_' . esc_attr($ee_gmaps_opts['map_ID']) . '" |
@@ -103,109 +103,109 @@ discard block |
||
103 | 103 | ></div> |
104 | 104 | </div>'; |
105 | 105 | |
106 | - wp_enqueue_script('gmap_api'); |
|
107 | - wp_enqueue_script('ee_gmap'); |
|
108 | - add_action('wp_footer', ['EEH_Maps', 'footer_enqueue_script']); |
|
109 | - } |
|
110 | - return $html; // end auto map or static url map check |
|
111 | - } |
|
112 | - |
|
113 | - |
|
114 | - /** |
|
115 | - * enqueue_script |
|
116 | - * |
|
117 | - * @return void |
|
118 | - */ |
|
119 | - public static function footer_enqueue_script() |
|
120 | - { |
|
121 | - wp_localize_script('ee_gmap', 'ee_gmap_vars', EEH_Maps::$gmap_vars); |
|
122 | - } |
|
123 | - |
|
124 | - |
|
125 | - /** |
|
126 | - * registers scripts for maps |
|
127 | - */ |
|
128 | - public static function espresso_google_map_js() |
|
129 | - { |
|
130 | - $api_url = sprintf( |
|
131 | - "https://maps.googleapis.com/maps/api/js?key=%s", |
|
132 | - apply_filters( |
|
133 | - 'FHEE__EEH_Maps__espresso_google_maps_js__api_key', |
|
134 | - EE_Registry::instance()->CFG->map_settings->google_map_api_key |
|
135 | - ) |
|
136 | - ); |
|
137 | - wp_register_script( |
|
138 | - 'gmap_api', |
|
139 | - esc_url_raw($api_url), |
|
140 | - ['jquery'], |
|
141 | - null, |
|
142 | - true |
|
143 | - ); |
|
144 | - wp_register_script( |
|
145 | - 'ee_gmap', |
|
146 | - plugin_dir_url(__FILE__) . 'assets/ee_gmap.js', |
|
147 | - ['gmap_api'], |
|
148 | - '1.0', |
|
149 | - true |
|
150 | - ); |
|
151 | - } |
|
152 | - |
|
153 | - |
|
154 | - /** |
|
155 | - * creates a Google Map Link |
|
156 | - * |
|
157 | - * @param array $atts array of attributes required for the map link generation |
|
158 | - * @return string (link to map!) |
|
159 | - */ |
|
160 | - public static function google_map_link($atts) |
|
161 | - { |
|
162 | - do_action('AHEE_log', __FILE__, __FUNCTION__, ''); |
|
163 | - extract($atts); |
|
164 | - /** @var string $address */ |
|
165 | - /** @var string $city */ |
|
166 | - /** @var string $state */ |
|
167 | - /** @var string $zip */ |
|
168 | - /** @var string $country */ |
|
169 | - $address = "{$address}"; |
|
170 | - $city = "{$city}"; |
|
171 | - $state = "{$state}"; |
|
172 | - $zip = "{$zip}"; |
|
173 | - $country = "{$country}"; |
|
174 | - $text = isset($text) ? "{$text}" : ""; |
|
175 | - $type = isset($type) ? "{$type}" : ""; |
|
176 | - $map_w = isset($map_w) ? "{$map_w}" : 400; |
|
177 | - $map_h = isset($map_h) ? "{$map_h}" : 400; |
|
178 | - $id = isset($id) ? $id : 'not_set'; |
|
179 | - $map_image_class = isset($map_image_class) ? $map_image_class : 'ee_google_map_view'; |
|
180 | - |
|
181 | - $address_string = ($address != '' ? $address : '') |
|
182 | - . ($city != '' ? ',' . $city : '') |
|
183 | - . ($state != '' ? ',' . $state : '') |
|
184 | - . ($zip != '' ? ',' . $zip : '') |
|
185 | - . ($country != '' ? ',' . $country : ''); |
|
186 | - |
|
187 | - $google_map = htmlentities2('https://maps.google.com/maps?q=' . urlencode($address_string)); |
|
188 | - |
|
189 | - switch ($type) { |
|
190 | - case 'text': |
|
191 | - default: |
|
192 | - $text = $text == '' ? esc_html__('Map and Directions', 'event_espresso') : $text; |
|
193 | - break; |
|
194 | - |
|
195 | - case 'url_only': |
|
196 | - case 'url': |
|
197 | - $text = $google_map; |
|
198 | - break; |
|
199 | - |
|
200 | - case 'map': |
|
201 | - $scheme = is_ssl() ? 'https://' : 'http://'; |
|
202 | - |
|
203 | - $api_key = apply_filters( |
|
204 | - 'FHEE__EEH_Maps__espresso_google_maps_link__api_key', |
|
205 | - EE_Registry::instance()->CFG->map_settings->google_map_api_key |
|
206 | - ); |
|
207 | - |
|
208 | - return ' |
|
106 | + wp_enqueue_script('gmap_api'); |
|
107 | + wp_enqueue_script('ee_gmap'); |
|
108 | + add_action('wp_footer', ['EEH_Maps', 'footer_enqueue_script']); |
|
109 | + } |
|
110 | + return $html; // end auto map or static url map check |
|
111 | + } |
|
112 | + |
|
113 | + |
|
114 | + /** |
|
115 | + * enqueue_script |
|
116 | + * |
|
117 | + * @return void |
|
118 | + */ |
|
119 | + public static function footer_enqueue_script() |
|
120 | + { |
|
121 | + wp_localize_script('ee_gmap', 'ee_gmap_vars', EEH_Maps::$gmap_vars); |
|
122 | + } |
|
123 | + |
|
124 | + |
|
125 | + /** |
|
126 | + * registers scripts for maps |
|
127 | + */ |
|
128 | + public static function espresso_google_map_js() |
|
129 | + { |
|
130 | + $api_url = sprintf( |
|
131 | + "https://maps.googleapis.com/maps/api/js?key=%s", |
|
132 | + apply_filters( |
|
133 | + 'FHEE__EEH_Maps__espresso_google_maps_js__api_key', |
|
134 | + EE_Registry::instance()->CFG->map_settings->google_map_api_key |
|
135 | + ) |
|
136 | + ); |
|
137 | + wp_register_script( |
|
138 | + 'gmap_api', |
|
139 | + esc_url_raw($api_url), |
|
140 | + ['jquery'], |
|
141 | + null, |
|
142 | + true |
|
143 | + ); |
|
144 | + wp_register_script( |
|
145 | + 'ee_gmap', |
|
146 | + plugin_dir_url(__FILE__) . 'assets/ee_gmap.js', |
|
147 | + ['gmap_api'], |
|
148 | + '1.0', |
|
149 | + true |
|
150 | + ); |
|
151 | + } |
|
152 | + |
|
153 | + |
|
154 | + /** |
|
155 | + * creates a Google Map Link |
|
156 | + * |
|
157 | + * @param array $atts array of attributes required for the map link generation |
|
158 | + * @return string (link to map!) |
|
159 | + */ |
|
160 | + public static function google_map_link($atts) |
|
161 | + { |
|
162 | + do_action('AHEE_log', __FILE__, __FUNCTION__, ''); |
|
163 | + extract($atts); |
|
164 | + /** @var string $address */ |
|
165 | + /** @var string $city */ |
|
166 | + /** @var string $state */ |
|
167 | + /** @var string $zip */ |
|
168 | + /** @var string $country */ |
|
169 | + $address = "{$address}"; |
|
170 | + $city = "{$city}"; |
|
171 | + $state = "{$state}"; |
|
172 | + $zip = "{$zip}"; |
|
173 | + $country = "{$country}"; |
|
174 | + $text = isset($text) ? "{$text}" : ""; |
|
175 | + $type = isset($type) ? "{$type}" : ""; |
|
176 | + $map_w = isset($map_w) ? "{$map_w}" : 400; |
|
177 | + $map_h = isset($map_h) ? "{$map_h}" : 400; |
|
178 | + $id = isset($id) ? $id : 'not_set'; |
|
179 | + $map_image_class = isset($map_image_class) ? $map_image_class : 'ee_google_map_view'; |
|
180 | + |
|
181 | + $address_string = ($address != '' ? $address : '') |
|
182 | + . ($city != '' ? ',' . $city : '') |
|
183 | + . ($state != '' ? ',' . $state : '') |
|
184 | + . ($zip != '' ? ',' . $zip : '') |
|
185 | + . ($country != '' ? ',' . $country : ''); |
|
186 | + |
|
187 | + $google_map = htmlentities2('https://maps.google.com/maps?q=' . urlencode($address_string)); |
|
188 | + |
|
189 | + switch ($type) { |
|
190 | + case 'text': |
|
191 | + default: |
|
192 | + $text = $text == '' ? esc_html__('Map and Directions', 'event_espresso') : $text; |
|
193 | + break; |
|
194 | + |
|
195 | + case 'url_only': |
|
196 | + case 'url': |
|
197 | + $text = $google_map; |
|
198 | + break; |
|
199 | + |
|
200 | + case 'map': |
|
201 | + $scheme = is_ssl() ? 'https://' : 'http://'; |
|
202 | + |
|
203 | + $api_key = apply_filters( |
|
204 | + 'FHEE__EEH_Maps__espresso_google_maps_link__api_key', |
|
205 | + EE_Registry::instance()->CFG->map_settings->google_map_api_key |
|
206 | + ); |
|
207 | + |
|
208 | + return ' |
|
209 | 209 | <a class="a_map_image_link" |
210 | 210 | href="' . esc_url_raw($google_map) . '" |
211 | 211 | target="_blank" |
@@ -215,23 +215,23 @@ discard block |
||
215 | 215 | class="map_image_link" |
216 | 216 | id="venue_map_' . $id . '" ' . $map_image_class . ' |
217 | 217 | src="' |
218 | - . htmlentities2( |
|
219 | - $scheme |
|
220 | - . 'maps.googleapis.com/maps/api/staticmap?center=' |
|
221 | - . urlencode($address_string) |
|
222 | - . '&zoom=14&size=' |
|
223 | - . $map_w . 'x' . $map_h |
|
224 | - . '&markers=color:green|label:|' |
|
225 | - . urlencode($address_string) |
|
226 | - . '&sensor=false&key=' |
|
227 | - . $api_key |
|
228 | - ) . '" |
|
218 | + . htmlentities2( |
|
219 | + $scheme |
|
220 | + . 'maps.googleapis.com/maps/api/staticmap?center=' |
|
221 | + . urlencode($address_string) |
|
222 | + . '&zoom=14&size=' |
|
223 | + . $map_w . 'x' . $map_h |
|
224 | + . '&markers=color:green|label:|' |
|
225 | + . urlencode($address_string) |
|
226 | + . '&sensor=false&key=' |
|
227 | + . $api_key |
|
228 | + ) . '" |
|
229 | 229 | /> |
230 | 230 | </a>'; |
231 | - } |
|
231 | + } |
|
232 | 232 | |
233 | - return $type === 'url_only' |
|
234 | - ? $text |
|
235 | - : '<a href="' . esc_url_raw($google_map) . '" target="_blank" rel="noopener noreferrer">' . $text . '</a>'; |
|
236 | - } |
|
233 | + return $type === 'url_only' |
|
234 | + ? $text |
|
235 | + : '<a href="' . esc_url_raw($google_map) . '" target="_blank" rel="noopener noreferrer">' . $text . '</a>'; |
|
236 | + } |
|
237 | 237 | } |
@@ -38,7 +38,7 @@ discard block |
||
38 | 38 | public static function instance() |
39 | 39 | { |
40 | 40 | // check if class object is instantiated, and instantiated properly |
41 | - if (! self::$_instance instanceof EEH_Debug_Tools) { |
|
41 | + if ( ! self::$_instance instanceof EEH_Debug_Tools) { |
|
42 | 42 | self::$_instance = new self(); |
43 | 43 | } |
44 | 44 | return self::$_instance; |
@@ -55,14 +55,14 @@ discard block |
||
55 | 55 | if ( |
56 | 56 | defined('EE_LOAD_KINT') |
57 | 57 | && ! class_exists('Kint') |
58 | - && file_exists(EE_PLUGIN_DIR_PATH . 'tests/kint/Kint.class.php') |
|
58 | + && file_exists(EE_PLUGIN_DIR_PATH.'tests/kint/Kint.class.php') |
|
59 | 59 | ) { |
60 | 60 | // despite EE4 having a check for an existing copy of the Kint debugging class, |
61 | 61 | // if another plugin was loaded AFTER EE4 and they did NOT perform a similar check, |
62 | 62 | // then hilarity would ensue as PHP throws a "Cannot redeclare class Kint" error |
63 | 63 | // so we've moved it to our test folder so that it is not included with production releases |
64 | 64 | // plz use https://wordpress.org/plugins/kint-debugger/ if testing production versions of EE |
65 | - require_once(EE_PLUGIN_DIR_PATH . 'tests/kint/Kint.class.php'); |
|
65 | + require_once(EE_PLUGIN_DIR_PATH.'tests/kint/Kint.class.php'); |
|
66 | 66 | } |
67 | 67 | $plugin = basename(EE_PLUGIN_DIR_PATH); |
68 | 68 | add_action("activate_{$plugin}", array('EEH_Debug_Tools', 'ee_plugin_activation_errors')); |
@@ -79,7 +79,7 @@ discard block |
||
79 | 79 | */ |
80 | 80 | public static function show_db_name() |
81 | 81 | { |
82 | - if (! defined('DOING_AJAX') && (defined('EE_ERROR_EMAILS') && EE_ERROR_EMAILS)) { |
|
82 | + if ( ! defined('DOING_AJAX') && (defined('EE_ERROR_EMAILS') && EE_ERROR_EMAILS)) { |
|
83 | 83 | echo '<p style="font-size:10px;font-weight:normal;color:#E76700;margin: 1em 2em; text-align: right;">DB_NAME: ' |
84 | 84 | . DB_NAME |
85 | 85 | . '</p>'; |
@@ -129,12 +129,12 @@ discard block |
||
129 | 129 | global $wp_filter; |
130 | 130 | echo '<br/><br/><br/><h3>Hooked Functions</h3>'; |
131 | 131 | if ($tag) { |
132 | - $hook[ $tag ] = $wp_filter[ $tag ]; |
|
133 | - if (! is_array($hook[ $tag ])) { |
|
132 | + $hook[$tag] = $wp_filter[$tag]; |
|
133 | + if ( ! is_array($hook[$tag])) { |
|
134 | 134 | trigger_error("Nothing found for '$tag' hook", E_USER_WARNING); |
135 | 135 | return; |
136 | 136 | } |
137 | - echo '<h5>For Tag: ' . esc_html($tag) . '</h5>'; |
|
137 | + echo '<h5>For Tag: '.esc_html($tag).'</h5>'; |
|
138 | 138 | } else { |
139 | 139 | $hook = is_array($wp_filter) ? $wp_filter : array($wp_filter); |
140 | 140 | ksort($hook); |
@@ -164,12 +164,12 @@ discard block |
||
164 | 164 | { |
165 | 165 | $filters = array(); |
166 | 166 | global $wp_filter; |
167 | - if (isset($wp_filter[ $hook_name ])) { |
|
168 | - $filters[ $hook_name ] = array(); |
|
169 | - foreach ($wp_filter[ $hook_name ] as $priority => $callbacks) { |
|
170 | - $filters[ $hook_name ][ $priority ] = array(); |
|
167 | + if (isset($wp_filter[$hook_name])) { |
|
168 | + $filters[$hook_name] = array(); |
|
169 | + foreach ($wp_filter[$hook_name] as $priority => $callbacks) { |
|
170 | + $filters[$hook_name][$priority] = array(); |
|
171 | 171 | foreach ($callbacks as $callback) { |
172 | - $filters[ $hook_name ][ $priority ][] = $callback['function']; |
|
172 | + $filters[$hook_name][$priority][] = $callback['function']; |
|
173 | 173 | } |
174 | 174 | } |
175 | 175 | } |
@@ -188,17 +188,17 @@ discard block |
||
188 | 188 | { |
189 | 189 | if (WP_DEBUG) { |
190 | 190 | $activation_errors = ob_get_contents(); |
191 | - if (! empty($activation_errors)) { |
|
192 | - $activation_errors = date('Y-m-d H:i:s') . "\n" . $activation_errors; |
|
191 | + if ( ! empty($activation_errors)) { |
|
192 | + $activation_errors = date('Y-m-d H:i:s')."\n".$activation_errors; |
|
193 | 193 | } |
194 | - espresso_load_required('EEH_File', EE_HELPERS . 'EEH_File.helper.php'); |
|
194 | + espresso_load_required('EEH_File', EE_HELPERS.'EEH_File.helper.php'); |
|
195 | 195 | if (class_exists('EEH_File')) { |
196 | 196 | try { |
197 | 197 | EEH_File::ensure_file_exists_and_is_writable( |
198 | - EVENT_ESPRESSO_UPLOAD_DIR . 'logs/espresso_plugin_activation_errors.html' |
|
198 | + EVENT_ESPRESSO_UPLOAD_DIR.'logs/espresso_plugin_activation_errors.html' |
|
199 | 199 | ); |
200 | 200 | EEH_File::write_to_file( |
201 | - EVENT_ESPRESSO_UPLOAD_DIR . 'logs/espresso_plugin_activation_errors.html', |
|
201 | + EVENT_ESPRESSO_UPLOAD_DIR.'logs/espresso_plugin_activation_errors.html', |
|
202 | 202 | $activation_errors |
203 | 203 | ); |
204 | 204 | } catch (EE_Error $e) { |
@@ -218,11 +218,11 @@ discard block |
||
218 | 218 | } else { |
219 | 219 | // old school attempt |
220 | 220 | file_put_contents( |
221 | - EVENT_ESPRESSO_UPLOAD_DIR . 'logs/espresso_plugin_activation_errors.html', |
|
221 | + EVENT_ESPRESSO_UPLOAD_DIR.'logs/espresso_plugin_activation_errors.html', |
|
222 | 222 | $activation_errors |
223 | 223 | ); |
224 | 224 | } |
225 | - $activation_errors = get_option('ee_plugin_activation_errors', '') . $activation_errors; |
|
225 | + $activation_errors = get_option('ee_plugin_activation_errors', '').$activation_errors; |
|
226 | 226 | update_option('ee_plugin_activation_errors', $activation_errors); |
227 | 227 | } |
228 | 228 | } |
@@ -282,7 +282,7 @@ discard block |
||
282 | 282 | // don't trigger error if doing ajax, |
283 | 283 | // instead we'll add a transient EE_Error notice that in theory should show on the next request. |
284 | 284 | if (defined('DOING_AJAX') && DOING_AJAX) { |
285 | - $error_message .= ' ' . esc_html__( |
|
285 | + $error_message .= ' '.esc_html__( |
|
286 | 286 | 'This is a doing_it_wrong message that was triggered during an ajax request. The request params on this request were: ', |
287 | 287 | 'event_espresso' |
288 | 288 | ); |
@@ -325,18 +325,18 @@ discard block |
||
325 | 325 | $debug_key = 'EE_DEBUG_SPCO' |
326 | 326 | ) { |
327 | 327 | if (WP_DEBUG) { |
328 | - $debug_key = $debug_key . '_' . EE_Session::instance()->id(); |
|
328 | + $debug_key = $debug_key.'_'.EE_Session::instance()->id(); |
|
329 | 329 | $debug_data = get_option($debug_key, array()); |
330 | 330 | $default_data = array( |
331 | - $class => $func . '() : ' . $line, |
|
331 | + $class => $func.'() : '.$line, |
|
332 | 332 | ); |
333 | 333 | // don't serialize objects |
334 | 334 | $info = self::strip_objects($info); |
335 | 335 | $index = ! empty($debug_index) ? $debug_index : 0; |
336 | - if (! isset($debug_data[ $index ])) { |
|
337 | - $debug_data[ $index ] = array(); |
|
336 | + if ( ! isset($debug_data[$index])) { |
|
337 | + $debug_data[$index] = array(); |
|
338 | 338 | } |
339 | - $debug_data[ $index ][ microtime() ] = array_merge($default_data, $info); |
|
339 | + $debug_data[$index][microtime()] = array_merge($default_data, $info); |
|
340 | 340 | update_option($debug_key, $debug_data); |
341 | 341 | } |
342 | 342 | } |
@@ -353,20 +353,20 @@ discard block |
||
353 | 353 | { |
354 | 354 | foreach ($info as $key => $value) { |
355 | 355 | if (is_array($value)) { |
356 | - $info[ $key ] = self::strip_objects($value); |
|
356 | + $info[$key] = self::strip_objects($value); |
|
357 | 357 | } elseif (is_object($value)) { |
358 | 358 | $object_class = get_class($value); |
359 | - $info[ $object_class ] = array(); |
|
360 | - $info[ $object_class ]['ID'] = method_exists($value, 'ID') ? $value->ID() : spl_object_hash($value); |
|
359 | + $info[$object_class] = array(); |
|
360 | + $info[$object_class]['ID'] = method_exists($value, 'ID') ? $value->ID() : spl_object_hash($value); |
|
361 | 361 | if (method_exists($value, 'ID')) { |
362 | - $info[ $object_class ]['ID'] = $value->ID(); |
|
362 | + $info[$object_class]['ID'] = $value->ID(); |
|
363 | 363 | } |
364 | 364 | if (method_exists($value, 'status')) { |
365 | - $info[ $object_class ]['status'] = $value->status(); |
|
365 | + $info[$object_class]['status'] = $value->status(); |
|
366 | 366 | } elseif (method_exists($value, 'status_ID')) { |
367 | - $info[ $object_class ]['status'] = $value->status_ID(); |
|
367 | + $info[$object_class]['status'] = $value->status_ID(); |
|
368 | 368 | } |
369 | - unset($info[ $key ]); |
|
369 | + unset($info[$key]); |
|
370 | 370 | } |
371 | 371 | } |
372 | 372 | return (array) $info; |
@@ -400,8 +400,8 @@ discard block |
||
400 | 400 | $result = EEH_Debug_Tools::headingSpacer($heading_tag); |
401 | 401 | $result .= EEH_Debug_Tools::heading($var_name, $heading_tag, $margin, $line); |
402 | 402 | $result .= $is_method |
403 | - ? EEH_Debug_Tools::grey_span('::') . EEH_Debug_Tools::orange_span($var . '()') |
|
404 | - : EEH_Debug_Tools::grey_span(' : ') . EEH_Debug_Tools::orange_span($var); |
|
403 | + ? EEH_Debug_Tools::grey_span('::').EEH_Debug_Tools::orange_span($var.'()') |
|
404 | + : EEH_Debug_Tools::grey_span(' : ').EEH_Debug_Tools::orange_span($var); |
|
405 | 405 | $result .= EEH_Debug_Tools::file_and_line($file, $line, $heading_tag); |
406 | 406 | $result .= EEH_Debug_Tools::headingX($heading_tag); |
407 | 407 | if ($die) { |
@@ -456,11 +456,11 @@ discard block |
||
456 | 456 | if ($heading_tag === 'h1' || $heading_tag === 'h2') { |
457 | 457 | $heading .= self::lineBreak(); |
458 | 458 | } |
459 | - $heading .= self::lineBreak() . "{$line}) {$var_name}"; |
|
459 | + $heading .= self::lineBreak()."{$line}) {$var_name}"; |
|
460 | 460 | return $heading; |
461 | 461 | } |
462 | 462 | $margin = "25px 0 0 {$margin}"; |
463 | - return '<' . $heading_tag . ' style="color:#2EA2CC; margin:' . $margin . ';"><b>' . $var_name . '</b>'; |
|
463 | + return '<'.$heading_tag.' style="color:#2EA2CC; margin:'.$margin.';"><b>'.$var_name.'</b>'; |
|
464 | 464 | } |
465 | 465 | |
466 | 466 | |
@@ -474,7 +474,7 @@ discard block |
||
474 | 474 | if (EEH_Debug_Tools::plainOutput()) { |
475 | 475 | return ''; |
476 | 476 | } |
477 | - return '</' . $heading_tag . '>'; |
|
477 | + return '</'.$heading_tag.'>'; |
|
478 | 478 | } |
479 | 479 | |
480 | 480 | |
@@ -488,7 +488,7 @@ discard block |
||
488 | 488 | if (EEH_Debug_Tools::plainOutput()) { |
489 | 489 | return $content; |
490 | 490 | } |
491 | - return '<span style="color:#999">' . $content . '</span>'; |
|
491 | + return '<span style="color:#999">'.$content.'</span>'; |
|
492 | 492 | } |
493 | 493 | |
494 | 494 | |
@@ -528,7 +528,7 @@ discard block |
||
528 | 528 | if (EEH_Debug_Tools::plainOutput()) { |
529 | 529 | return $content; |
530 | 530 | } |
531 | - return '<span style="color:#E76700">' . $content . '</span>'; |
|
531 | + return '<span style="color:#E76700">'.$content.'</span>'; |
|
532 | 532 | } |
533 | 533 | |
534 | 534 | |
@@ -545,7 +545,7 @@ discard block |
||
545 | 545 | if (EEH_Debug_Tools::plainOutput()) { |
546 | 546 | return str_replace("\n", '', $var); |
547 | 547 | } |
548 | - return '<pre style="color:#999; padding:1em; background: #fff">' . $var . '</pre>'; |
|
548 | + return '<pre style="color:#999; padding:1em; background: #fff">'.$var.'</pre>'; |
|
549 | 549 | } |
550 | 550 | |
551 | 551 | |
@@ -586,7 +586,7 @@ discard block |
||
586 | 586 | $heading_tag = EEH_Debug_Tools::headingTag($heading_tag); |
587 | 587 | $result = EEH_Debug_Tools::headingSpacer($heading_tag); |
588 | 588 | $result .= EEH_Debug_Tools::heading($var_name, $heading_tag, $margin, $line); |
589 | - $result .= EEH_Debug_Tools::grey_span(' : ') . EEH_Debug_Tools::orange_span( |
|
589 | + $result .= EEH_Debug_Tools::grey_span(' : ').EEH_Debug_Tools::orange_span( |
|
590 | 590 | EEH_Debug_Tools::pre_span($var) |
591 | 591 | ); |
592 | 592 | $result .= EEH_Debug_Tools::file_and_line($file, $line, $heading_tag); |
@@ -15,673 +15,673 @@ discard block |
||
15 | 15 | */ |
16 | 16 | class EEH_Debug_Tools |
17 | 17 | { |
18 | - /** |
|
19 | - * instance of the EEH_Autoloader object |
|
20 | - * |
|
21 | - * @var $_instance |
|
22 | - * @access private |
|
23 | - */ |
|
24 | - private static $_instance; |
|
25 | - |
|
26 | - /** |
|
27 | - * @var array |
|
28 | - */ |
|
29 | - protected $_memory_usage_points = array(); |
|
30 | - |
|
31 | - |
|
32 | - |
|
33 | - /** |
|
34 | - * @singleton method used to instantiate class object |
|
35 | - * @access public |
|
36 | - * @return EEH_Debug_Tools |
|
37 | - */ |
|
38 | - public static function instance() |
|
39 | - { |
|
40 | - // check if class object is instantiated, and instantiated properly |
|
41 | - if (! self::$_instance instanceof EEH_Debug_Tools) { |
|
42 | - self::$_instance = new self(); |
|
43 | - } |
|
44 | - return self::$_instance; |
|
45 | - } |
|
46 | - |
|
47 | - |
|
48 | - |
|
49 | - /** |
|
50 | - * private class constructor |
|
51 | - */ |
|
52 | - private function __construct() |
|
53 | - { |
|
54 | - // load Kint PHP debugging library |
|
55 | - if ( |
|
56 | - defined('EE_LOAD_KINT') |
|
57 | - && ! class_exists('Kint') |
|
58 | - && file_exists(EE_PLUGIN_DIR_PATH . 'tests/kint/Kint.class.php') |
|
59 | - ) { |
|
60 | - // despite EE4 having a check for an existing copy of the Kint debugging class, |
|
61 | - // if another plugin was loaded AFTER EE4 and they did NOT perform a similar check, |
|
62 | - // then hilarity would ensue as PHP throws a "Cannot redeclare class Kint" error |
|
63 | - // so we've moved it to our test folder so that it is not included with production releases |
|
64 | - // plz use https://wordpress.org/plugins/kint-debugger/ if testing production versions of EE |
|
65 | - require_once(EE_PLUGIN_DIR_PATH . 'tests/kint/Kint.class.php'); |
|
66 | - } |
|
67 | - $plugin = basename(EE_PLUGIN_DIR_PATH); |
|
68 | - add_action("activate_{$plugin}", array('EEH_Debug_Tools', 'ee_plugin_activation_errors')); |
|
69 | - add_action('activated_plugin', array('EEH_Debug_Tools', 'ee_plugin_activation_errors')); |
|
70 | - add_action('shutdown', array('EEH_Debug_Tools', 'show_db_name')); |
|
71 | - } |
|
72 | - |
|
73 | - |
|
74 | - |
|
75 | - /** |
|
76 | - * show_db_name |
|
77 | - * |
|
78 | - * @return void |
|
79 | - */ |
|
80 | - public static function show_db_name() |
|
81 | - { |
|
82 | - if (! defined('DOING_AJAX') && (defined('EE_ERROR_EMAILS') && EE_ERROR_EMAILS)) { |
|
83 | - echo '<p style="font-size:10px;font-weight:normal;color:#E76700;margin: 1em 2em; text-align: right;">DB_NAME: ' |
|
84 | - . DB_NAME |
|
85 | - . '</p>'; |
|
86 | - } |
|
87 | - if (EE_DEBUG) { |
|
88 | - Benchmark::displayResults(); |
|
89 | - } |
|
90 | - } |
|
91 | - |
|
92 | - |
|
93 | - |
|
94 | - /** |
|
95 | - * dump EE_Session object at bottom of page after everything else has happened |
|
96 | - * |
|
97 | - * @return void |
|
98 | - */ |
|
99 | - public function espresso_session_footer_dump() |
|
100 | - { |
|
101 | - if ( |
|
102 | - (defined('WP_DEBUG') && WP_DEBUG) |
|
103 | - && ! defined('DOING_AJAX') |
|
104 | - && class_exists('Kint') |
|
105 | - && function_exists('wp_get_current_user') |
|
106 | - && current_user_can('update_core') |
|
107 | - && class_exists('EE_Registry') |
|
108 | - ) { |
|
109 | - Kint::dump(EE_Registry::instance()->SSN->id()); |
|
110 | - Kint::dump(EE_Registry::instance()->SSN); |
|
111 | - // Kint::dump( EE_Registry::instance()->SSN->get_session_data('cart')->get_tickets() ); |
|
112 | - $this->espresso_list_hooked_functions(); |
|
113 | - Benchmark::displayResults(); |
|
114 | - } |
|
115 | - } |
|
116 | - |
|
117 | - |
|
118 | - |
|
119 | - /** |
|
120 | - * List All Hooked Functions |
|
121 | - * to list all functions for a specific hook, add ee_list_hooks={hook-name} to URL |
|
122 | - * http://wp.smashingmagazine.com/2009/08/18/10-useful-wordpress-hook-hacks/ |
|
123 | - * |
|
124 | - * @param string $tag |
|
125 | - * @return void |
|
126 | - */ |
|
127 | - public function espresso_list_hooked_functions($tag = '') |
|
128 | - { |
|
129 | - global $wp_filter; |
|
130 | - echo '<br/><br/><br/><h3>Hooked Functions</h3>'; |
|
131 | - if ($tag) { |
|
132 | - $hook[ $tag ] = $wp_filter[ $tag ]; |
|
133 | - if (! is_array($hook[ $tag ])) { |
|
134 | - trigger_error("Nothing found for '$tag' hook", E_USER_WARNING); |
|
135 | - return; |
|
136 | - } |
|
137 | - echo '<h5>For Tag: ' . esc_html($tag) . '</h5>'; |
|
138 | - } else { |
|
139 | - $hook = is_array($wp_filter) ? $wp_filter : array($wp_filter); |
|
140 | - ksort($hook); |
|
141 | - } |
|
142 | - foreach ($hook as $tag_name => $priorities) { |
|
143 | - echo "<br />>>>>>\t<strong>esc_html($tag_name)</strong><br />"; |
|
144 | - ksort($priorities); |
|
145 | - foreach ($priorities as $priority => $function) { |
|
146 | - echo esc_html($priority); |
|
147 | - foreach ($function as $name => $properties) { |
|
148 | - $name = esc_html($name); |
|
149 | - echo "\t$name<br />"; |
|
150 | - } |
|
151 | - } |
|
152 | - } |
|
153 | - } |
|
154 | - |
|
155 | - |
|
156 | - |
|
157 | - /** |
|
158 | - * registered_filter_callbacks |
|
159 | - * |
|
160 | - * @param string $hook_name |
|
161 | - * @return array |
|
162 | - */ |
|
163 | - public static function registered_filter_callbacks($hook_name = '') |
|
164 | - { |
|
165 | - $filters = array(); |
|
166 | - global $wp_filter; |
|
167 | - if (isset($wp_filter[ $hook_name ])) { |
|
168 | - $filters[ $hook_name ] = array(); |
|
169 | - foreach ($wp_filter[ $hook_name ] as $priority => $callbacks) { |
|
170 | - $filters[ $hook_name ][ $priority ] = array(); |
|
171 | - foreach ($callbacks as $callback) { |
|
172 | - $filters[ $hook_name ][ $priority ][] = $callback['function']; |
|
173 | - } |
|
174 | - } |
|
175 | - } |
|
176 | - return $filters; |
|
177 | - } |
|
178 | - |
|
179 | - |
|
180 | - |
|
181 | - /** |
|
182 | - * captures plugin activation errors for debugging |
|
183 | - * |
|
184 | - * @return void |
|
185 | - * @throws EE_Error |
|
186 | - */ |
|
187 | - public static function ee_plugin_activation_errors() |
|
188 | - { |
|
189 | - if (WP_DEBUG) { |
|
190 | - $activation_errors = ob_get_contents(); |
|
191 | - if (! empty($activation_errors)) { |
|
192 | - $activation_errors = date('Y-m-d H:i:s') . "\n" . $activation_errors; |
|
193 | - } |
|
194 | - espresso_load_required('EEH_File', EE_HELPERS . 'EEH_File.helper.php'); |
|
195 | - if (class_exists('EEH_File')) { |
|
196 | - try { |
|
197 | - EEH_File::ensure_file_exists_and_is_writable( |
|
198 | - EVENT_ESPRESSO_UPLOAD_DIR . 'logs/espresso_plugin_activation_errors.html' |
|
199 | - ); |
|
200 | - EEH_File::write_to_file( |
|
201 | - EVENT_ESPRESSO_UPLOAD_DIR . 'logs/espresso_plugin_activation_errors.html', |
|
202 | - $activation_errors |
|
203 | - ); |
|
204 | - } catch (EE_Error $e) { |
|
205 | - EE_Error::add_error( |
|
206 | - sprintf( |
|
207 | - esc_html__( |
|
208 | - 'The Event Espresso activation errors file could not be setup because: %s', |
|
209 | - 'event_espresso' |
|
210 | - ), |
|
211 | - $e->getMessage() |
|
212 | - ), |
|
213 | - __FILE__, |
|
214 | - __FUNCTION__, |
|
215 | - __LINE__ |
|
216 | - ); |
|
217 | - } |
|
218 | - } else { |
|
219 | - // old school attempt |
|
220 | - file_put_contents( |
|
221 | - EVENT_ESPRESSO_UPLOAD_DIR . 'logs/espresso_plugin_activation_errors.html', |
|
222 | - $activation_errors |
|
223 | - ); |
|
224 | - } |
|
225 | - $activation_errors = get_option('ee_plugin_activation_errors', '') . $activation_errors; |
|
226 | - update_option('ee_plugin_activation_errors', $activation_errors); |
|
227 | - } |
|
228 | - } |
|
229 | - |
|
230 | - |
|
231 | - |
|
232 | - /** |
|
233 | - * This basically mimics the WordPress _doing_it_wrong() function except adds our own messaging etc. |
|
234 | - * Very useful for providing helpful messages to developers when the method of doing something has been deprecated, |
|
235 | - * or we want to make sure they use something the right way. |
|
236 | - * |
|
237 | - * @access public |
|
238 | - * @param string $function The function that was called |
|
239 | - * @param string $message A message explaining what has been done incorrectly |
|
240 | - * @param string $version The version of Event Espresso where the error was added |
|
241 | - * @param string $applies_when a version string for when you want the doing_it_wrong notice to begin appearing |
|
242 | - * for a deprecated function. This allows deprecation to occur during one version, |
|
243 | - * but not have any notices appear until a later version. This allows developers |
|
244 | - * extra time to update their code before notices appear. |
|
245 | - * @param int $error_type |
|
246 | - * @uses trigger_error() |
|
247 | - */ |
|
248 | - public function doing_it_wrong( |
|
249 | - $function, |
|
250 | - $message, |
|
251 | - $version, |
|
252 | - $applies_when = '', |
|
253 | - $error_type = null |
|
254 | - ) { |
|
255 | - $applies_when = ! empty($applies_when) ? $applies_when : espresso_version(); |
|
256 | - $error_type = $error_type !== null ? $error_type : E_USER_NOTICE; |
|
257 | - // because we swapped the parameter order around for the last two params, |
|
258 | - // let's verify that some third party isn't still passing an error type value for the third param |
|
259 | - if (is_int($applies_when)) { |
|
260 | - $error_type = $applies_when; |
|
261 | - $applies_when = espresso_version(); |
|
262 | - } |
|
263 | - // if not displaying notices yet, then just leave |
|
264 | - if (version_compare(espresso_version(), $applies_when, '<')) { |
|
265 | - return; |
|
266 | - } |
|
267 | - do_action('AHEE__EEH_Debug_Tools__doing_it_wrong_run', $function, $message, $version); |
|
268 | - $version = $version === null |
|
269 | - ? '' |
|
270 | - : sprintf( |
|
271 | - esc_html__('(This message was added in version %s of Event Espresso)', 'event_espresso'), |
|
272 | - $version |
|
273 | - ); |
|
274 | - $error_message = sprintf( |
|
275 | - esc_html__('%1$s was called %2$sincorrectly%3$s. %4$s %5$s', 'event_espresso'), |
|
276 | - $function, |
|
277 | - '<strong>', |
|
278 | - '</strong>', |
|
279 | - $message, |
|
280 | - $version |
|
281 | - ); |
|
282 | - // don't trigger error if doing ajax, |
|
283 | - // instead we'll add a transient EE_Error notice that in theory should show on the next request. |
|
284 | - if (defined('DOING_AJAX') && DOING_AJAX) { |
|
285 | - $error_message .= ' ' . esc_html__( |
|
286 | - 'This is a doing_it_wrong message that was triggered during an ajax request. The request params on this request were: ', |
|
287 | - 'event_espresso' |
|
288 | - ); |
|
289 | - $request = LoaderFactory::getLoader()->getShared(RequestInterface::class); |
|
290 | - $error_message .= '<ul><li>'; |
|
291 | - $error_message .= implode('</li><li>', $request->requestParams()); |
|
292 | - $error_message .= '</ul>'; |
|
293 | - EE_Error::add_error($error_message, 'debug::doing_it_wrong', $function, '42'); |
|
294 | - // now we set this on the transient so it shows up on the next request. |
|
295 | - EE_Error::get_notices(false, true); |
|
296 | - } else { |
|
297 | - trigger_error($error_message, $error_type); |
|
298 | - } |
|
299 | - } |
|
300 | - |
|
301 | - |
|
302 | - |
|
303 | - |
|
304 | - /** |
|
305 | - * Logger helpers |
|
306 | - */ |
|
307 | - /** |
|
308 | - * debug |
|
309 | - * |
|
310 | - * @param string $class |
|
311 | - * @param string $func |
|
312 | - * @param string $line |
|
313 | - * @param array $info |
|
314 | - * @param bool $display_request |
|
315 | - * @param string $debug_index |
|
316 | - * @param string $debug_key |
|
317 | - */ |
|
318 | - public static function log( |
|
319 | - $class = '', |
|
320 | - $func = '', |
|
321 | - $line = '', |
|
322 | - $info = array(), |
|
323 | - $display_request = false, |
|
324 | - $debug_index = '', |
|
325 | - $debug_key = 'EE_DEBUG_SPCO' |
|
326 | - ) { |
|
327 | - if (WP_DEBUG) { |
|
328 | - $debug_key = $debug_key . '_' . EE_Session::instance()->id(); |
|
329 | - $debug_data = get_option($debug_key, array()); |
|
330 | - $default_data = array( |
|
331 | - $class => $func . '() : ' . $line, |
|
332 | - ); |
|
333 | - // don't serialize objects |
|
334 | - $info = self::strip_objects($info); |
|
335 | - $index = ! empty($debug_index) ? $debug_index : 0; |
|
336 | - if (! isset($debug_data[ $index ])) { |
|
337 | - $debug_data[ $index ] = array(); |
|
338 | - } |
|
339 | - $debug_data[ $index ][ microtime() ] = array_merge($default_data, $info); |
|
340 | - update_option($debug_key, $debug_data); |
|
341 | - } |
|
342 | - } |
|
343 | - |
|
344 | - |
|
345 | - |
|
346 | - /** |
|
347 | - * strip_objects |
|
348 | - * |
|
349 | - * @param array $info |
|
350 | - * @return array |
|
351 | - */ |
|
352 | - public static function strip_objects($info = array()) |
|
353 | - { |
|
354 | - foreach ($info as $key => $value) { |
|
355 | - if (is_array($value)) { |
|
356 | - $info[ $key ] = self::strip_objects($value); |
|
357 | - } elseif (is_object($value)) { |
|
358 | - $object_class = get_class($value); |
|
359 | - $info[ $object_class ] = array(); |
|
360 | - $info[ $object_class ]['ID'] = method_exists($value, 'ID') ? $value->ID() : spl_object_hash($value); |
|
361 | - if (method_exists($value, 'ID')) { |
|
362 | - $info[ $object_class ]['ID'] = $value->ID(); |
|
363 | - } |
|
364 | - if (method_exists($value, 'status')) { |
|
365 | - $info[ $object_class ]['status'] = $value->status(); |
|
366 | - } elseif (method_exists($value, 'status_ID')) { |
|
367 | - $info[ $object_class ]['status'] = $value->status_ID(); |
|
368 | - } |
|
369 | - unset($info[ $key ]); |
|
370 | - } |
|
371 | - } |
|
372 | - return (array) $info; |
|
373 | - } |
|
374 | - |
|
375 | - |
|
376 | - |
|
377 | - /** |
|
378 | - * @param mixed $var |
|
379 | - * @param string $var_name |
|
380 | - * @param string $file |
|
381 | - * @param int|string $line |
|
382 | - * @param int|string $heading_tag |
|
383 | - * @param bool $die |
|
384 | - * @param string $margin |
|
385 | - */ |
|
386 | - public static function printv( |
|
387 | - $var, |
|
388 | - $var_name = '', |
|
389 | - $file = '', |
|
390 | - $line = '', |
|
391 | - $heading_tag = 5, |
|
392 | - $die = false, |
|
393 | - $margin = '' |
|
394 | - ) { |
|
395 | - $var_name = ! $var_name ? 'string' : $var_name; |
|
396 | - $var_name = ucwords(str_replace('$', '', $var_name)); |
|
397 | - $is_method = method_exists($var_name, $var); |
|
398 | - $var_name = ucwords(str_replace('_', ' ', $var_name)); |
|
399 | - $heading_tag = EEH_Debug_Tools::headingTag($heading_tag); |
|
400 | - $result = EEH_Debug_Tools::headingSpacer($heading_tag); |
|
401 | - $result .= EEH_Debug_Tools::heading($var_name, $heading_tag, $margin, $line); |
|
402 | - $result .= $is_method |
|
403 | - ? EEH_Debug_Tools::grey_span('::') . EEH_Debug_Tools::orange_span($var . '()') |
|
404 | - : EEH_Debug_Tools::grey_span(' : ') . EEH_Debug_Tools::orange_span($var); |
|
405 | - $result .= EEH_Debug_Tools::file_and_line($file, $line, $heading_tag); |
|
406 | - $result .= EEH_Debug_Tools::headingX($heading_tag); |
|
407 | - if ($die) { |
|
408 | - die($result); |
|
409 | - } |
|
410 | - echo wp_kses($result, AllowedTags::getWithFormTags()); |
|
411 | - } |
|
412 | - |
|
413 | - |
|
414 | - protected static function headingTag($heading_tag) |
|
415 | - { |
|
416 | - $heading_tag = absint($heading_tag); |
|
417 | - return $heading_tag > 0 && $heading_tag < 7 ? "h{$heading_tag}" : 'h5'; |
|
418 | - } |
|
419 | - |
|
420 | - protected static function headingSpacer($heading_tag) |
|
421 | - { |
|
422 | - return EEH_Debug_Tools::plainOutput() && ($heading_tag === 'h1' || $heading_tag === 'h2') |
|
423 | - ? self::lineBreak() |
|
424 | - : ''; |
|
425 | - } |
|
426 | - |
|
427 | - |
|
428 | - protected static function lineBreak() |
|
429 | - { |
|
430 | - return defined('DOING_AJAX') && DOING_AJAX ? '<br />' : "\n"; |
|
431 | - } |
|
432 | - |
|
433 | - |
|
434 | - protected static function plainOutput() |
|
435 | - { |
|
436 | - return defined('EE_TESTS_DIR') |
|
437 | - || (defined('DOING_AJAX') && DOING_AJAX) |
|
438 | - || ( |
|
439 | - isset($_SERVER['REQUEST_URI']) |
|
440 | - && strpos(parse_url($_SERVER['REQUEST_URI'], PHP_URL_PATH), 'wp-json') !== false |
|
441 | - ); |
|
442 | - } |
|
443 | - |
|
444 | - |
|
445 | - /** |
|
446 | - * @param string $var_name |
|
447 | - * @param string $heading_tag |
|
448 | - * @param string $margin |
|
449 | - * @param int $line |
|
450 | - * @return string |
|
451 | - */ |
|
452 | - protected static function heading($var_name = '', $heading_tag = 'h5', $margin = '', $line = 0) |
|
453 | - { |
|
454 | - if (EEH_Debug_Tools::plainOutput()) { |
|
455 | - $heading = ''; |
|
456 | - if ($heading_tag === 'h1' || $heading_tag === 'h2') { |
|
457 | - $heading .= self::lineBreak(); |
|
458 | - } |
|
459 | - $heading .= self::lineBreak() . "{$line}) {$var_name}"; |
|
460 | - return $heading; |
|
461 | - } |
|
462 | - $margin = "25px 0 0 {$margin}"; |
|
463 | - return '<' . $heading_tag . ' style="color:#2EA2CC; margin:' . $margin . ';"><b>' . $var_name . '</b>'; |
|
464 | - } |
|
465 | - |
|
466 | - |
|
467 | - |
|
468 | - /** |
|
469 | - * @param string $heading_tag |
|
470 | - * @return string |
|
471 | - */ |
|
472 | - protected static function headingX($heading_tag = 'h5') |
|
473 | - { |
|
474 | - if (EEH_Debug_Tools::plainOutput()) { |
|
475 | - return ''; |
|
476 | - } |
|
477 | - return '</' . $heading_tag . '>'; |
|
478 | - } |
|
479 | - |
|
480 | - |
|
481 | - |
|
482 | - /** |
|
483 | - * @param string $content |
|
484 | - * @return string |
|
485 | - */ |
|
486 | - protected static function grey_span($content = '') |
|
487 | - { |
|
488 | - if (EEH_Debug_Tools::plainOutput()) { |
|
489 | - return $content; |
|
490 | - } |
|
491 | - return '<span style="color:#999">' . $content . '</span>'; |
|
492 | - } |
|
493 | - |
|
494 | - |
|
495 | - |
|
496 | - /** |
|
497 | - * @param string $file |
|
498 | - * @param int $line |
|
499 | - * @return string |
|
500 | - */ |
|
501 | - protected static function file_and_line($file, $line, $heading_tag) |
|
502 | - { |
|
503 | - if ($file === '' || $line === '') { |
|
504 | - return ''; |
|
505 | - } |
|
506 | - $file = str_replace(EE_PLUGIN_DIR_PATH, '/', $file); |
|
507 | - if (EEH_Debug_Tools::plainOutput()) { |
|
508 | - if ($heading_tag === 'h1' || $heading_tag === 'h2') { |
|
509 | - return " ({$file})"; |
|
510 | - } |
|
511 | - return ''; |
|
512 | - } |
|
513 | - return '<br /><span style="font-size:9px;font-weight:normal;color:#666;line-height: 12px;">' |
|
514 | - . $file |
|
515 | - . '<br />line no: ' |
|
516 | - . $line |
|
517 | - . '</span>'; |
|
518 | - } |
|
519 | - |
|
520 | - |
|
521 | - |
|
522 | - /** |
|
523 | - * @param string $content |
|
524 | - * @return string |
|
525 | - */ |
|
526 | - protected static function orange_span($content = '') |
|
527 | - { |
|
528 | - if (EEH_Debug_Tools::plainOutput()) { |
|
529 | - return $content; |
|
530 | - } |
|
531 | - return '<span style="color:#E76700">' . $content . '</span>'; |
|
532 | - } |
|
533 | - |
|
534 | - |
|
535 | - |
|
536 | - /** |
|
537 | - * @param mixed $var |
|
538 | - * @return string |
|
539 | - */ |
|
540 | - protected static function pre_span($var) |
|
541 | - { |
|
542 | - ob_start(); |
|
543 | - var_dump($var); |
|
544 | - $var = ob_get_clean(); |
|
545 | - if (EEH_Debug_Tools::plainOutput()) { |
|
546 | - return str_replace("\n", '', $var); |
|
547 | - } |
|
548 | - return '<pre style="color:#999; padding:1em; background: #fff">' . $var . '</pre>'; |
|
549 | - } |
|
550 | - |
|
551 | - |
|
552 | - |
|
553 | - /** |
|
554 | - * @param mixed $var |
|
555 | - * @param string $var_name |
|
556 | - * @param string $file |
|
557 | - * @param int|string $line |
|
558 | - * @param int|string $heading_tag |
|
559 | - * @param bool $die |
|
560 | - */ |
|
561 | - public static function printr( |
|
562 | - $var, |
|
563 | - $var_name = '', |
|
564 | - $file = '', |
|
565 | - $line = '', |
|
566 | - $heading_tag = 5, |
|
567 | - $die = false |
|
568 | - ) { |
|
569 | - // return; |
|
570 | - $file = str_replace(rtrim(ABSPATH, '\\/'), '', $file); |
|
571 | - $margin = is_admin() ? ' 180px' : '0'; |
|
572 | - if (is_string($var)) { |
|
573 | - EEH_Debug_Tools::printv($var, $var_name, $file, $line, $heading_tag, $die, $margin); |
|
574 | - return; |
|
575 | - } |
|
576 | - if (is_object($var)) { |
|
577 | - $var_name = ! $var_name ? 'object' : $var_name; |
|
578 | - } elseif (is_array($var)) { |
|
579 | - $var_name = ! $var_name ? 'array' : $var_name; |
|
580 | - } elseif (is_numeric($var)) { |
|
581 | - $var_name = ! $var_name ? 'numeric' : $var_name; |
|
582 | - } elseif ($var === null) { |
|
583 | - $var_name = ! $var_name ? 'null' : $var_name; |
|
584 | - } |
|
585 | - $var_name = ucwords(str_replace(array('$', '_'), array('', ' '), $var_name)); |
|
586 | - $heading_tag = EEH_Debug_Tools::headingTag($heading_tag); |
|
587 | - $result = EEH_Debug_Tools::headingSpacer($heading_tag); |
|
588 | - $result .= EEH_Debug_Tools::heading($var_name, $heading_tag, $margin, $line); |
|
589 | - $result .= EEH_Debug_Tools::grey_span(' : ') . EEH_Debug_Tools::orange_span( |
|
590 | - EEH_Debug_Tools::pre_span($var) |
|
591 | - ); |
|
592 | - $result .= EEH_Debug_Tools::file_and_line($file, $line, $heading_tag); |
|
593 | - $result .= EEH_Debug_Tools::headingX($heading_tag); |
|
594 | - if ($die) { |
|
595 | - die($result); |
|
596 | - } |
|
597 | - echo wp_kses($result, AllowedTags::getWithFormTags()); |
|
598 | - } |
|
599 | - |
|
600 | - |
|
601 | - |
|
602 | - /******************** deprecated ********************/ |
|
603 | - |
|
604 | - |
|
605 | - |
|
606 | - /** |
|
607 | - * @deprecated 4.9.39.rc.034 |
|
608 | - */ |
|
609 | - public function reset_times() |
|
610 | - { |
|
611 | - Benchmark::resetTimes(); |
|
612 | - } |
|
613 | - |
|
614 | - |
|
615 | - |
|
616 | - /** |
|
617 | - * @deprecated 4.9.39.rc.034 |
|
618 | - * @param null $timer_name |
|
619 | - */ |
|
620 | - public function start_timer($timer_name = null) |
|
621 | - { |
|
622 | - Benchmark::startTimer($timer_name); |
|
623 | - } |
|
624 | - |
|
625 | - |
|
626 | - |
|
627 | - /** |
|
628 | - * @deprecated 4.9.39.rc.034 |
|
629 | - * @param string $timer_name |
|
630 | - */ |
|
631 | - public function stop_timer($timer_name = '') |
|
632 | - { |
|
633 | - Benchmark::stopTimer($timer_name); |
|
634 | - } |
|
635 | - |
|
636 | - |
|
637 | - |
|
638 | - /** |
|
639 | - * @deprecated 4.9.39.rc.034 |
|
640 | - * @param string $label The label to show for this time eg "Start of calling Some_Class::some_function" |
|
641 | - * @param boolean $output_now whether to echo now, or wait until EEH_Debug_Tools::show_times() is called |
|
642 | - * @return void |
|
643 | - */ |
|
644 | - public function measure_memory($label, $output_now = false) |
|
645 | - { |
|
646 | - Benchmark::measureMemory($label, $output_now); |
|
647 | - } |
|
648 | - |
|
649 | - |
|
650 | - |
|
651 | - /** |
|
652 | - * @deprecated 4.9.39.rc.034 |
|
653 | - * @param int $size |
|
654 | - * @return string |
|
655 | - */ |
|
656 | - public function convert($size) |
|
657 | - { |
|
658 | - return Benchmark::convert($size); |
|
659 | - } |
|
660 | - |
|
661 | - |
|
662 | - |
|
663 | - /** |
|
664 | - * @deprecated 4.9.39.rc.034 |
|
665 | - * @param bool $output_now |
|
666 | - * @return string |
|
667 | - */ |
|
668 | - public function show_times($output_now = true) |
|
669 | - { |
|
670 | - return Benchmark::displayResults($output_now); |
|
671 | - } |
|
672 | - |
|
673 | - |
|
674 | - |
|
675 | - /** |
|
676 | - * @deprecated 4.9.39.rc.034 |
|
677 | - * @param string $timer_name |
|
678 | - * @param float $total_time |
|
679 | - * @return string |
|
680 | - */ |
|
681 | - public function format_time($timer_name, $total_time) |
|
682 | - { |
|
683 | - return Benchmark::formatTime($timer_name, $total_time); |
|
684 | - } |
|
18 | + /** |
|
19 | + * instance of the EEH_Autoloader object |
|
20 | + * |
|
21 | + * @var $_instance |
|
22 | + * @access private |
|
23 | + */ |
|
24 | + private static $_instance; |
|
25 | + |
|
26 | + /** |
|
27 | + * @var array |
|
28 | + */ |
|
29 | + protected $_memory_usage_points = array(); |
|
30 | + |
|
31 | + |
|
32 | + |
|
33 | + /** |
|
34 | + * @singleton method used to instantiate class object |
|
35 | + * @access public |
|
36 | + * @return EEH_Debug_Tools |
|
37 | + */ |
|
38 | + public static function instance() |
|
39 | + { |
|
40 | + // check if class object is instantiated, and instantiated properly |
|
41 | + if (! self::$_instance instanceof EEH_Debug_Tools) { |
|
42 | + self::$_instance = new self(); |
|
43 | + } |
|
44 | + return self::$_instance; |
|
45 | + } |
|
46 | + |
|
47 | + |
|
48 | + |
|
49 | + /** |
|
50 | + * private class constructor |
|
51 | + */ |
|
52 | + private function __construct() |
|
53 | + { |
|
54 | + // load Kint PHP debugging library |
|
55 | + if ( |
|
56 | + defined('EE_LOAD_KINT') |
|
57 | + && ! class_exists('Kint') |
|
58 | + && file_exists(EE_PLUGIN_DIR_PATH . 'tests/kint/Kint.class.php') |
|
59 | + ) { |
|
60 | + // despite EE4 having a check for an existing copy of the Kint debugging class, |
|
61 | + // if another plugin was loaded AFTER EE4 and they did NOT perform a similar check, |
|
62 | + // then hilarity would ensue as PHP throws a "Cannot redeclare class Kint" error |
|
63 | + // so we've moved it to our test folder so that it is not included with production releases |
|
64 | + // plz use https://wordpress.org/plugins/kint-debugger/ if testing production versions of EE |
|
65 | + require_once(EE_PLUGIN_DIR_PATH . 'tests/kint/Kint.class.php'); |
|
66 | + } |
|
67 | + $plugin = basename(EE_PLUGIN_DIR_PATH); |
|
68 | + add_action("activate_{$plugin}", array('EEH_Debug_Tools', 'ee_plugin_activation_errors')); |
|
69 | + add_action('activated_plugin', array('EEH_Debug_Tools', 'ee_plugin_activation_errors')); |
|
70 | + add_action('shutdown', array('EEH_Debug_Tools', 'show_db_name')); |
|
71 | + } |
|
72 | + |
|
73 | + |
|
74 | + |
|
75 | + /** |
|
76 | + * show_db_name |
|
77 | + * |
|
78 | + * @return void |
|
79 | + */ |
|
80 | + public static function show_db_name() |
|
81 | + { |
|
82 | + if (! defined('DOING_AJAX') && (defined('EE_ERROR_EMAILS') && EE_ERROR_EMAILS)) { |
|
83 | + echo '<p style="font-size:10px;font-weight:normal;color:#E76700;margin: 1em 2em; text-align: right;">DB_NAME: ' |
|
84 | + . DB_NAME |
|
85 | + . '</p>'; |
|
86 | + } |
|
87 | + if (EE_DEBUG) { |
|
88 | + Benchmark::displayResults(); |
|
89 | + } |
|
90 | + } |
|
91 | + |
|
92 | + |
|
93 | + |
|
94 | + /** |
|
95 | + * dump EE_Session object at bottom of page after everything else has happened |
|
96 | + * |
|
97 | + * @return void |
|
98 | + */ |
|
99 | + public function espresso_session_footer_dump() |
|
100 | + { |
|
101 | + if ( |
|
102 | + (defined('WP_DEBUG') && WP_DEBUG) |
|
103 | + && ! defined('DOING_AJAX') |
|
104 | + && class_exists('Kint') |
|
105 | + && function_exists('wp_get_current_user') |
|
106 | + && current_user_can('update_core') |
|
107 | + && class_exists('EE_Registry') |
|
108 | + ) { |
|
109 | + Kint::dump(EE_Registry::instance()->SSN->id()); |
|
110 | + Kint::dump(EE_Registry::instance()->SSN); |
|
111 | + // Kint::dump( EE_Registry::instance()->SSN->get_session_data('cart')->get_tickets() ); |
|
112 | + $this->espresso_list_hooked_functions(); |
|
113 | + Benchmark::displayResults(); |
|
114 | + } |
|
115 | + } |
|
116 | + |
|
117 | + |
|
118 | + |
|
119 | + /** |
|
120 | + * List All Hooked Functions |
|
121 | + * to list all functions for a specific hook, add ee_list_hooks={hook-name} to URL |
|
122 | + * http://wp.smashingmagazine.com/2009/08/18/10-useful-wordpress-hook-hacks/ |
|
123 | + * |
|
124 | + * @param string $tag |
|
125 | + * @return void |
|
126 | + */ |
|
127 | + public function espresso_list_hooked_functions($tag = '') |
|
128 | + { |
|
129 | + global $wp_filter; |
|
130 | + echo '<br/><br/><br/><h3>Hooked Functions</h3>'; |
|
131 | + if ($tag) { |
|
132 | + $hook[ $tag ] = $wp_filter[ $tag ]; |
|
133 | + if (! is_array($hook[ $tag ])) { |
|
134 | + trigger_error("Nothing found for '$tag' hook", E_USER_WARNING); |
|
135 | + return; |
|
136 | + } |
|
137 | + echo '<h5>For Tag: ' . esc_html($tag) . '</h5>'; |
|
138 | + } else { |
|
139 | + $hook = is_array($wp_filter) ? $wp_filter : array($wp_filter); |
|
140 | + ksort($hook); |
|
141 | + } |
|
142 | + foreach ($hook as $tag_name => $priorities) { |
|
143 | + echo "<br />>>>>>\t<strong>esc_html($tag_name)</strong><br />"; |
|
144 | + ksort($priorities); |
|
145 | + foreach ($priorities as $priority => $function) { |
|
146 | + echo esc_html($priority); |
|
147 | + foreach ($function as $name => $properties) { |
|
148 | + $name = esc_html($name); |
|
149 | + echo "\t$name<br />"; |
|
150 | + } |
|
151 | + } |
|
152 | + } |
|
153 | + } |
|
154 | + |
|
155 | + |
|
156 | + |
|
157 | + /** |
|
158 | + * registered_filter_callbacks |
|
159 | + * |
|
160 | + * @param string $hook_name |
|
161 | + * @return array |
|
162 | + */ |
|
163 | + public static function registered_filter_callbacks($hook_name = '') |
|
164 | + { |
|
165 | + $filters = array(); |
|
166 | + global $wp_filter; |
|
167 | + if (isset($wp_filter[ $hook_name ])) { |
|
168 | + $filters[ $hook_name ] = array(); |
|
169 | + foreach ($wp_filter[ $hook_name ] as $priority => $callbacks) { |
|
170 | + $filters[ $hook_name ][ $priority ] = array(); |
|
171 | + foreach ($callbacks as $callback) { |
|
172 | + $filters[ $hook_name ][ $priority ][] = $callback['function']; |
|
173 | + } |
|
174 | + } |
|
175 | + } |
|
176 | + return $filters; |
|
177 | + } |
|
178 | + |
|
179 | + |
|
180 | + |
|
181 | + /** |
|
182 | + * captures plugin activation errors for debugging |
|
183 | + * |
|
184 | + * @return void |
|
185 | + * @throws EE_Error |
|
186 | + */ |
|
187 | + public static function ee_plugin_activation_errors() |
|
188 | + { |
|
189 | + if (WP_DEBUG) { |
|
190 | + $activation_errors = ob_get_contents(); |
|
191 | + if (! empty($activation_errors)) { |
|
192 | + $activation_errors = date('Y-m-d H:i:s') . "\n" . $activation_errors; |
|
193 | + } |
|
194 | + espresso_load_required('EEH_File', EE_HELPERS . 'EEH_File.helper.php'); |
|
195 | + if (class_exists('EEH_File')) { |
|
196 | + try { |
|
197 | + EEH_File::ensure_file_exists_and_is_writable( |
|
198 | + EVENT_ESPRESSO_UPLOAD_DIR . 'logs/espresso_plugin_activation_errors.html' |
|
199 | + ); |
|
200 | + EEH_File::write_to_file( |
|
201 | + EVENT_ESPRESSO_UPLOAD_DIR . 'logs/espresso_plugin_activation_errors.html', |
|
202 | + $activation_errors |
|
203 | + ); |
|
204 | + } catch (EE_Error $e) { |
|
205 | + EE_Error::add_error( |
|
206 | + sprintf( |
|
207 | + esc_html__( |
|
208 | + 'The Event Espresso activation errors file could not be setup because: %s', |
|
209 | + 'event_espresso' |
|
210 | + ), |
|
211 | + $e->getMessage() |
|
212 | + ), |
|
213 | + __FILE__, |
|
214 | + __FUNCTION__, |
|
215 | + __LINE__ |
|
216 | + ); |
|
217 | + } |
|
218 | + } else { |
|
219 | + // old school attempt |
|
220 | + file_put_contents( |
|
221 | + EVENT_ESPRESSO_UPLOAD_DIR . 'logs/espresso_plugin_activation_errors.html', |
|
222 | + $activation_errors |
|
223 | + ); |
|
224 | + } |
|
225 | + $activation_errors = get_option('ee_plugin_activation_errors', '') . $activation_errors; |
|
226 | + update_option('ee_plugin_activation_errors', $activation_errors); |
|
227 | + } |
|
228 | + } |
|
229 | + |
|
230 | + |
|
231 | + |
|
232 | + /** |
|
233 | + * This basically mimics the WordPress _doing_it_wrong() function except adds our own messaging etc. |
|
234 | + * Very useful for providing helpful messages to developers when the method of doing something has been deprecated, |
|
235 | + * or we want to make sure they use something the right way. |
|
236 | + * |
|
237 | + * @access public |
|
238 | + * @param string $function The function that was called |
|
239 | + * @param string $message A message explaining what has been done incorrectly |
|
240 | + * @param string $version The version of Event Espresso where the error was added |
|
241 | + * @param string $applies_when a version string for when you want the doing_it_wrong notice to begin appearing |
|
242 | + * for a deprecated function. This allows deprecation to occur during one version, |
|
243 | + * but not have any notices appear until a later version. This allows developers |
|
244 | + * extra time to update their code before notices appear. |
|
245 | + * @param int $error_type |
|
246 | + * @uses trigger_error() |
|
247 | + */ |
|
248 | + public function doing_it_wrong( |
|
249 | + $function, |
|
250 | + $message, |
|
251 | + $version, |
|
252 | + $applies_when = '', |
|
253 | + $error_type = null |
|
254 | + ) { |
|
255 | + $applies_when = ! empty($applies_when) ? $applies_when : espresso_version(); |
|
256 | + $error_type = $error_type !== null ? $error_type : E_USER_NOTICE; |
|
257 | + // because we swapped the parameter order around for the last two params, |
|
258 | + // let's verify that some third party isn't still passing an error type value for the third param |
|
259 | + if (is_int($applies_when)) { |
|
260 | + $error_type = $applies_when; |
|
261 | + $applies_when = espresso_version(); |
|
262 | + } |
|
263 | + // if not displaying notices yet, then just leave |
|
264 | + if (version_compare(espresso_version(), $applies_when, '<')) { |
|
265 | + return; |
|
266 | + } |
|
267 | + do_action('AHEE__EEH_Debug_Tools__doing_it_wrong_run', $function, $message, $version); |
|
268 | + $version = $version === null |
|
269 | + ? '' |
|
270 | + : sprintf( |
|
271 | + esc_html__('(This message was added in version %s of Event Espresso)', 'event_espresso'), |
|
272 | + $version |
|
273 | + ); |
|
274 | + $error_message = sprintf( |
|
275 | + esc_html__('%1$s was called %2$sincorrectly%3$s. %4$s %5$s', 'event_espresso'), |
|
276 | + $function, |
|
277 | + '<strong>', |
|
278 | + '</strong>', |
|
279 | + $message, |
|
280 | + $version |
|
281 | + ); |
|
282 | + // don't trigger error if doing ajax, |
|
283 | + // instead we'll add a transient EE_Error notice that in theory should show on the next request. |
|
284 | + if (defined('DOING_AJAX') && DOING_AJAX) { |
|
285 | + $error_message .= ' ' . esc_html__( |
|
286 | + 'This is a doing_it_wrong message that was triggered during an ajax request. The request params on this request were: ', |
|
287 | + 'event_espresso' |
|
288 | + ); |
|
289 | + $request = LoaderFactory::getLoader()->getShared(RequestInterface::class); |
|
290 | + $error_message .= '<ul><li>'; |
|
291 | + $error_message .= implode('</li><li>', $request->requestParams()); |
|
292 | + $error_message .= '</ul>'; |
|
293 | + EE_Error::add_error($error_message, 'debug::doing_it_wrong', $function, '42'); |
|
294 | + // now we set this on the transient so it shows up on the next request. |
|
295 | + EE_Error::get_notices(false, true); |
|
296 | + } else { |
|
297 | + trigger_error($error_message, $error_type); |
|
298 | + } |
|
299 | + } |
|
300 | + |
|
301 | + |
|
302 | + |
|
303 | + |
|
304 | + /** |
|
305 | + * Logger helpers |
|
306 | + */ |
|
307 | + /** |
|
308 | + * debug |
|
309 | + * |
|
310 | + * @param string $class |
|
311 | + * @param string $func |
|
312 | + * @param string $line |
|
313 | + * @param array $info |
|
314 | + * @param bool $display_request |
|
315 | + * @param string $debug_index |
|
316 | + * @param string $debug_key |
|
317 | + */ |
|
318 | + public static function log( |
|
319 | + $class = '', |
|
320 | + $func = '', |
|
321 | + $line = '', |
|
322 | + $info = array(), |
|
323 | + $display_request = false, |
|
324 | + $debug_index = '', |
|
325 | + $debug_key = 'EE_DEBUG_SPCO' |
|
326 | + ) { |
|
327 | + if (WP_DEBUG) { |
|
328 | + $debug_key = $debug_key . '_' . EE_Session::instance()->id(); |
|
329 | + $debug_data = get_option($debug_key, array()); |
|
330 | + $default_data = array( |
|
331 | + $class => $func . '() : ' . $line, |
|
332 | + ); |
|
333 | + // don't serialize objects |
|
334 | + $info = self::strip_objects($info); |
|
335 | + $index = ! empty($debug_index) ? $debug_index : 0; |
|
336 | + if (! isset($debug_data[ $index ])) { |
|
337 | + $debug_data[ $index ] = array(); |
|
338 | + } |
|
339 | + $debug_data[ $index ][ microtime() ] = array_merge($default_data, $info); |
|
340 | + update_option($debug_key, $debug_data); |
|
341 | + } |
|
342 | + } |
|
343 | + |
|
344 | + |
|
345 | + |
|
346 | + /** |
|
347 | + * strip_objects |
|
348 | + * |
|
349 | + * @param array $info |
|
350 | + * @return array |
|
351 | + */ |
|
352 | + public static function strip_objects($info = array()) |
|
353 | + { |
|
354 | + foreach ($info as $key => $value) { |
|
355 | + if (is_array($value)) { |
|
356 | + $info[ $key ] = self::strip_objects($value); |
|
357 | + } elseif (is_object($value)) { |
|
358 | + $object_class = get_class($value); |
|
359 | + $info[ $object_class ] = array(); |
|
360 | + $info[ $object_class ]['ID'] = method_exists($value, 'ID') ? $value->ID() : spl_object_hash($value); |
|
361 | + if (method_exists($value, 'ID')) { |
|
362 | + $info[ $object_class ]['ID'] = $value->ID(); |
|
363 | + } |
|
364 | + if (method_exists($value, 'status')) { |
|
365 | + $info[ $object_class ]['status'] = $value->status(); |
|
366 | + } elseif (method_exists($value, 'status_ID')) { |
|
367 | + $info[ $object_class ]['status'] = $value->status_ID(); |
|
368 | + } |
|
369 | + unset($info[ $key ]); |
|
370 | + } |
|
371 | + } |
|
372 | + return (array) $info; |
|
373 | + } |
|
374 | + |
|
375 | + |
|
376 | + |
|
377 | + /** |
|
378 | + * @param mixed $var |
|
379 | + * @param string $var_name |
|
380 | + * @param string $file |
|
381 | + * @param int|string $line |
|
382 | + * @param int|string $heading_tag |
|
383 | + * @param bool $die |
|
384 | + * @param string $margin |
|
385 | + */ |
|
386 | + public static function printv( |
|
387 | + $var, |
|
388 | + $var_name = '', |
|
389 | + $file = '', |
|
390 | + $line = '', |
|
391 | + $heading_tag = 5, |
|
392 | + $die = false, |
|
393 | + $margin = '' |
|
394 | + ) { |
|
395 | + $var_name = ! $var_name ? 'string' : $var_name; |
|
396 | + $var_name = ucwords(str_replace('$', '', $var_name)); |
|
397 | + $is_method = method_exists($var_name, $var); |
|
398 | + $var_name = ucwords(str_replace('_', ' ', $var_name)); |
|
399 | + $heading_tag = EEH_Debug_Tools::headingTag($heading_tag); |
|
400 | + $result = EEH_Debug_Tools::headingSpacer($heading_tag); |
|
401 | + $result .= EEH_Debug_Tools::heading($var_name, $heading_tag, $margin, $line); |
|
402 | + $result .= $is_method |
|
403 | + ? EEH_Debug_Tools::grey_span('::') . EEH_Debug_Tools::orange_span($var . '()') |
|
404 | + : EEH_Debug_Tools::grey_span(' : ') . EEH_Debug_Tools::orange_span($var); |
|
405 | + $result .= EEH_Debug_Tools::file_and_line($file, $line, $heading_tag); |
|
406 | + $result .= EEH_Debug_Tools::headingX($heading_tag); |
|
407 | + if ($die) { |
|
408 | + die($result); |
|
409 | + } |
|
410 | + echo wp_kses($result, AllowedTags::getWithFormTags()); |
|
411 | + } |
|
412 | + |
|
413 | + |
|
414 | + protected static function headingTag($heading_tag) |
|
415 | + { |
|
416 | + $heading_tag = absint($heading_tag); |
|
417 | + return $heading_tag > 0 && $heading_tag < 7 ? "h{$heading_tag}" : 'h5'; |
|
418 | + } |
|
419 | + |
|
420 | + protected static function headingSpacer($heading_tag) |
|
421 | + { |
|
422 | + return EEH_Debug_Tools::plainOutput() && ($heading_tag === 'h1' || $heading_tag === 'h2') |
|
423 | + ? self::lineBreak() |
|
424 | + : ''; |
|
425 | + } |
|
426 | + |
|
427 | + |
|
428 | + protected static function lineBreak() |
|
429 | + { |
|
430 | + return defined('DOING_AJAX') && DOING_AJAX ? '<br />' : "\n"; |
|
431 | + } |
|
432 | + |
|
433 | + |
|
434 | + protected static function plainOutput() |
|
435 | + { |
|
436 | + return defined('EE_TESTS_DIR') |
|
437 | + || (defined('DOING_AJAX') && DOING_AJAX) |
|
438 | + || ( |
|
439 | + isset($_SERVER['REQUEST_URI']) |
|
440 | + && strpos(parse_url($_SERVER['REQUEST_URI'], PHP_URL_PATH), 'wp-json') !== false |
|
441 | + ); |
|
442 | + } |
|
443 | + |
|
444 | + |
|
445 | + /** |
|
446 | + * @param string $var_name |
|
447 | + * @param string $heading_tag |
|
448 | + * @param string $margin |
|
449 | + * @param int $line |
|
450 | + * @return string |
|
451 | + */ |
|
452 | + protected static function heading($var_name = '', $heading_tag = 'h5', $margin = '', $line = 0) |
|
453 | + { |
|
454 | + if (EEH_Debug_Tools::plainOutput()) { |
|
455 | + $heading = ''; |
|
456 | + if ($heading_tag === 'h1' || $heading_tag === 'h2') { |
|
457 | + $heading .= self::lineBreak(); |
|
458 | + } |
|
459 | + $heading .= self::lineBreak() . "{$line}) {$var_name}"; |
|
460 | + return $heading; |
|
461 | + } |
|
462 | + $margin = "25px 0 0 {$margin}"; |
|
463 | + return '<' . $heading_tag . ' style="color:#2EA2CC; margin:' . $margin . ';"><b>' . $var_name . '</b>'; |
|
464 | + } |
|
465 | + |
|
466 | + |
|
467 | + |
|
468 | + /** |
|
469 | + * @param string $heading_tag |
|
470 | + * @return string |
|
471 | + */ |
|
472 | + protected static function headingX($heading_tag = 'h5') |
|
473 | + { |
|
474 | + if (EEH_Debug_Tools::plainOutput()) { |
|
475 | + return ''; |
|
476 | + } |
|
477 | + return '</' . $heading_tag . '>'; |
|
478 | + } |
|
479 | + |
|
480 | + |
|
481 | + |
|
482 | + /** |
|
483 | + * @param string $content |
|
484 | + * @return string |
|
485 | + */ |
|
486 | + protected static function grey_span($content = '') |
|
487 | + { |
|
488 | + if (EEH_Debug_Tools::plainOutput()) { |
|
489 | + return $content; |
|
490 | + } |
|
491 | + return '<span style="color:#999">' . $content . '</span>'; |
|
492 | + } |
|
493 | + |
|
494 | + |
|
495 | + |
|
496 | + /** |
|
497 | + * @param string $file |
|
498 | + * @param int $line |
|
499 | + * @return string |
|
500 | + */ |
|
501 | + protected static function file_and_line($file, $line, $heading_tag) |
|
502 | + { |
|
503 | + if ($file === '' || $line === '') { |
|
504 | + return ''; |
|
505 | + } |
|
506 | + $file = str_replace(EE_PLUGIN_DIR_PATH, '/', $file); |
|
507 | + if (EEH_Debug_Tools::plainOutput()) { |
|
508 | + if ($heading_tag === 'h1' || $heading_tag === 'h2') { |
|
509 | + return " ({$file})"; |
|
510 | + } |
|
511 | + return ''; |
|
512 | + } |
|
513 | + return '<br /><span style="font-size:9px;font-weight:normal;color:#666;line-height: 12px;">' |
|
514 | + . $file |
|
515 | + . '<br />line no: ' |
|
516 | + . $line |
|
517 | + . '</span>'; |
|
518 | + } |
|
519 | + |
|
520 | + |
|
521 | + |
|
522 | + /** |
|
523 | + * @param string $content |
|
524 | + * @return string |
|
525 | + */ |
|
526 | + protected static function orange_span($content = '') |
|
527 | + { |
|
528 | + if (EEH_Debug_Tools::plainOutput()) { |
|
529 | + return $content; |
|
530 | + } |
|
531 | + return '<span style="color:#E76700">' . $content . '</span>'; |
|
532 | + } |
|
533 | + |
|
534 | + |
|
535 | + |
|
536 | + /** |
|
537 | + * @param mixed $var |
|
538 | + * @return string |
|
539 | + */ |
|
540 | + protected static function pre_span($var) |
|
541 | + { |
|
542 | + ob_start(); |
|
543 | + var_dump($var); |
|
544 | + $var = ob_get_clean(); |
|
545 | + if (EEH_Debug_Tools::plainOutput()) { |
|
546 | + return str_replace("\n", '', $var); |
|
547 | + } |
|
548 | + return '<pre style="color:#999; padding:1em; background: #fff">' . $var . '</pre>'; |
|
549 | + } |
|
550 | + |
|
551 | + |
|
552 | + |
|
553 | + /** |
|
554 | + * @param mixed $var |
|
555 | + * @param string $var_name |
|
556 | + * @param string $file |
|
557 | + * @param int|string $line |
|
558 | + * @param int|string $heading_tag |
|
559 | + * @param bool $die |
|
560 | + */ |
|
561 | + public static function printr( |
|
562 | + $var, |
|
563 | + $var_name = '', |
|
564 | + $file = '', |
|
565 | + $line = '', |
|
566 | + $heading_tag = 5, |
|
567 | + $die = false |
|
568 | + ) { |
|
569 | + // return; |
|
570 | + $file = str_replace(rtrim(ABSPATH, '\\/'), '', $file); |
|
571 | + $margin = is_admin() ? ' 180px' : '0'; |
|
572 | + if (is_string($var)) { |
|
573 | + EEH_Debug_Tools::printv($var, $var_name, $file, $line, $heading_tag, $die, $margin); |
|
574 | + return; |
|
575 | + } |
|
576 | + if (is_object($var)) { |
|
577 | + $var_name = ! $var_name ? 'object' : $var_name; |
|
578 | + } elseif (is_array($var)) { |
|
579 | + $var_name = ! $var_name ? 'array' : $var_name; |
|
580 | + } elseif (is_numeric($var)) { |
|
581 | + $var_name = ! $var_name ? 'numeric' : $var_name; |
|
582 | + } elseif ($var === null) { |
|
583 | + $var_name = ! $var_name ? 'null' : $var_name; |
|
584 | + } |
|
585 | + $var_name = ucwords(str_replace(array('$', '_'), array('', ' '), $var_name)); |
|
586 | + $heading_tag = EEH_Debug_Tools::headingTag($heading_tag); |
|
587 | + $result = EEH_Debug_Tools::headingSpacer($heading_tag); |
|
588 | + $result .= EEH_Debug_Tools::heading($var_name, $heading_tag, $margin, $line); |
|
589 | + $result .= EEH_Debug_Tools::grey_span(' : ') . EEH_Debug_Tools::orange_span( |
|
590 | + EEH_Debug_Tools::pre_span($var) |
|
591 | + ); |
|
592 | + $result .= EEH_Debug_Tools::file_and_line($file, $line, $heading_tag); |
|
593 | + $result .= EEH_Debug_Tools::headingX($heading_tag); |
|
594 | + if ($die) { |
|
595 | + die($result); |
|
596 | + } |
|
597 | + echo wp_kses($result, AllowedTags::getWithFormTags()); |
|
598 | + } |
|
599 | + |
|
600 | + |
|
601 | + |
|
602 | + /******************** deprecated ********************/ |
|
603 | + |
|
604 | + |
|
605 | + |
|
606 | + /** |
|
607 | + * @deprecated 4.9.39.rc.034 |
|
608 | + */ |
|
609 | + public function reset_times() |
|
610 | + { |
|
611 | + Benchmark::resetTimes(); |
|
612 | + } |
|
613 | + |
|
614 | + |
|
615 | + |
|
616 | + /** |
|
617 | + * @deprecated 4.9.39.rc.034 |
|
618 | + * @param null $timer_name |
|
619 | + */ |
|
620 | + public function start_timer($timer_name = null) |
|
621 | + { |
|
622 | + Benchmark::startTimer($timer_name); |
|
623 | + } |
|
624 | + |
|
625 | + |
|
626 | + |
|
627 | + /** |
|
628 | + * @deprecated 4.9.39.rc.034 |
|
629 | + * @param string $timer_name |
|
630 | + */ |
|
631 | + public function stop_timer($timer_name = '') |
|
632 | + { |
|
633 | + Benchmark::stopTimer($timer_name); |
|
634 | + } |
|
635 | + |
|
636 | + |
|
637 | + |
|
638 | + /** |
|
639 | + * @deprecated 4.9.39.rc.034 |
|
640 | + * @param string $label The label to show for this time eg "Start of calling Some_Class::some_function" |
|
641 | + * @param boolean $output_now whether to echo now, or wait until EEH_Debug_Tools::show_times() is called |
|
642 | + * @return void |
|
643 | + */ |
|
644 | + public function measure_memory($label, $output_now = false) |
|
645 | + { |
|
646 | + Benchmark::measureMemory($label, $output_now); |
|
647 | + } |
|
648 | + |
|
649 | + |
|
650 | + |
|
651 | + /** |
|
652 | + * @deprecated 4.9.39.rc.034 |
|
653 | + * @param int $size |
|
654 | + * @return string |
|
655 | + */ |
|
656 | + public function convert($size) |
|
657 | + { |
|
658 | + return Benchmark::convert($size); |
|
659 | + } |
|
660 | + |
|
661 | + |
|
662 | + |
|
663 | + /** |
|
664 | + * @deprecated 4.9.39.rc.034 |
|
665 | + * @param bool $output_now |
|
666 | + * @return string |
|
667 | + */ |
|
668 | + public function show_times($output_now = true) |
|
669 | + { |
|
670 | + return Benchmark::displayResults($output_now); |
|
671 | + } |
|
672 | + |
|
673 | + |
|
674 | + |
|
675 | + /** |
|
676 | + * @deprecated 4.9.39.rc.034 |
|
677 | + * @param string $timer_name |
|
678 | + * @param float $total_time |
|
679 | + * @return string |
|
680 | + */ |
|
681 | + public function format_time($timer_name, $total_time) |
|
682 | + { |
|
683 | + return Benchmark::formatTime($timer_name, $total_time); |
|
684 | + } |
|
685 | 685 | } |
686 | 686 | |
687 | 687 | |
@@ -691,31 +691,31 @@ discard block |
||
691 | 691 | * Plugin URI: http://upthemes.com/plugins/kint-debugger/ |
692 | 692 | */ |
693 | 693 | if (class_exists('Kint') && ! function_exists('dump_wp_query')) { |
694 | - function dump_wp_query() |
|
695 | - { |
|
696 | - global $wp_query; |
|
697 | - d($wp_query); |
|
698 | - } |
|
694 | + function dump_wp_query() |
|
695 | + { |
|
696 | + global $wp_query; |
|
697 | + d($wp_query); |
|
698 | + } |
|
699 | 699 | } |
700 | 700 | /** |
701 | 701 | * borrowed from Kint Debugger |
702 | 702 | * Plugin URI: http://upthemes.com/plugins/kint-debugger/ |
703 | 703 | */ |
704 | 704 | if (class_exists('Kint') && ! function_exists('dump_wp')) { |
705 | - function dump_wp() |
|
706 | - { |
|
707 | - global $wp; |
|
708 | - d($wp); |
|
709 | - } |
|
705 | + function dump_wp() |
|
706 | + { |
|
707 | + global $wp; |
|
708 | + d($wp); |
|
709 | + } |
|
710 | 710 | } |
711 | 711 | /** |
712 | 712 | * borrowed from Kint Debugger |
713 | 713 | * Plugin URI: http://upthemes.com/plugins/kint-debugger/ |
714 | 714 | */ |
715 | 715 | if (class_exists('Kint') && ! function_exists('dump_post')) { |
716 | - function dump_post() |
|
717 | - { |
|
718 | - global $post; |
|
719 | - d($post); |
|
720 | - } |
|
716 | + function dump_post() |
|
717 | + { |
|
718 | + global $post; |
|
719 | + d($post); |
|
720 | + } |
|
721 | 721 | } |
@@ -73,7 +73,7 @@ discard block |
||
73 | 73 | */ |
74 | 74 | public function getAvailableSpacesCalculator() |
75 | 75 | { |
76 | - if (! $this->available_spaces_calculator instanceof EventSpacesCalculator) { |
|
76 | + if ( ! $this->available_spaces_calculator instanceof EventSpacesCalculator) { |
|
77 | 77 | $this->available_spaces_calculator = new EventSpacesCalculator($this); |
78 | 78 | } |
79 | 79 | return $this->available_spaces_calculator; |
@@ -223,7 +223,7 @@ discard block |
||
223 | 223 | */ |
224 | 224 | public function primary_datetime($try_to_exclude_expired = true, $try_to_exclude_deleted = true) |
225 | 225 | { |
226 | - if (! empty($this->_Primary_Datetime)) { |
|
226 | + if ( ! empty($this->_Primary_Datetime)) { |
|
227 | 227 | return $this->_Primary_Datetime; |
228 | 228 | } |
229 | 229 | $this->_Primary_Datetime = EEM_Datetime::instance($this->_timezone)->get_primary_datetime_for_event( |
@@ -248,7 +248,7 @@ discard block |
||
248 | 248 | { |
249 | 249 | // first get all datetimes |
250 | 250 | $datetimes = $this->datetimes_ordered(); |
251 | - if (! $datetimes) { |
|
251 | + if ( ! $datetimes) { |
|
252 | 252 | return array(); |
253 | 253 | } |
254 | 254 | $datetime_ids = array(); |
@@ -456,7 +456,7 @@ discard block |
||
456 | 456 | public function short_description($num_words = 55, $more = null, $not_full_desc = false) |
457 | 457 | { |
458 | 458 | $short_desc = $this->get('EVT_short_desc'); |
459 | - if (! empty($short_desc) || $not_full_desc) { |
|
459 | + if ( ! empty($short_desc) || $not_full_desc) { |
|
460 | 460 | return $short_desc; |
461 | 461 | } |
462 | 462 | $full_desc = $this->get('EVT_desc'); |
@@ -924,7 +924,7 @@ discard block |
||
924 | 924 | ); |
925 | 925 | $all_expired = true; |
926 | 926 | foreach ($tickets as $ticket) { |
927 | - if (! $ticket->is_expired()) { |
|
927 | + if ( ! $ticket->is_expired()) { |
|
928 | 928 | $all_expired = false; |
929 | 929 | break; |
930 | 930 | } |
@@ -1015,7 +1015,7 @@ discard block |
||
1015 | 1015 | */ |
1016 | 1016 | public function is_sold_out($actual = false) |
1017 | 1017 | { |
1018 | - if (! $actual) { |
|
1018 | + if ( ! $actual) { |
|
1019 | 1019 | return $this->status() === EEM_Event::sold_out; |
1020 | 1020 | } |
1021 | 1021 | return $this->perform_sold_out_status_check(); |
@@ -1061,11 +1061,11 @@ discard block |
||
1061 | 1061 | public function get_active_status($reset = false) |
1062 | 1062 | { |
1063 | 1063 | // if the active status has already been set, then just use that value (unless we are resetting it) |
1064 | - if (! empty($this->_active_status) && ! $reset) { |
|
1064 | + if ( ! empty($this->_active_status) && ! $reset) { |
|
1065 | 1065 | return $this->_active_status; |
1066 | 1066 | } |
1067 | 1067 | // first check if event id is present on this object |
1068 | - if (! $this->ID()) { |
|
1068 | + if ( ! $this->ID()) { |
|
1069 | 1069 | return false; |
1070 | 1070 | } |
1071 | 1071 | $where_params_for_event = array(array('EVT_ID' => $this->ID())); |
@@ -1136,7 +1136,7 @@ discard block |
||
1136 | 1136 | public function pretty_active_status($echo = true) |
1137 | 1137 | { |
1138 | 1138 | $active_status = $this->get_active_status(); |
1139 | - $status = '<span class="ee-status event-active-status-' . esc_attr($active_status) . '">' |
|
1139 | + $status = '<span class="ee-status event-active-status-'.esc_attr($active_status).'">' |
|
1140 | 1140 | . EEH_Template::pretty_status($active_status, false, 'sentence') |
1141 | 1141 | . '</span>'; |
1142 | 1142 | if ($echo) { |
@@ -1155,7 +1155,7 @@ discard block |
||
1155 | 1155 | public function get_number_of_tickets_sold() |
1156 | 1156 | { |
1157 | 1157 | $tkt_sold = 0; |
1158 | - if (! $this->ID()) { |
|
1158 | + if ( ! $this->ID()) { |
|
1159 | 1159 | return 0; |
1160 | 1160 | } |
1161 | 1161 | $datetimes = $this->datetimes(); |
@@ -1345,7 +1345,7 @@ discard block |
||
1345 | 1345 | ] |
1346 | 1346 | ); |
1347 | 1347 | $field_to_update = EEM_Event_Question_Group::instance()->fieldNameForContext($for_primary); |
1348 | - $other_field = EEM_Event_Question_Group::instance()->fieldNameForContext(! $for_primary); |
|
1348 | + $other_field = EEM_Event_Question_Group::instance()->fieldNameForContext( ! $for_primary); |
|
1349 | 1349 | if ($existing_relation->get($other_field) === false) { |
1350 | 1350 | // Delete it. It's now no longer for primary or additional question groups. |
1351 | 1351 | return $this->_remove_relation_to($question_group_id_or_obj, 'Question_Group'); |
@@ -15,1443 +15,1443 @@ |
||
15 | 15 | */ |
16 | 16 | class EE_Event extends EE_CPT_Base implements EEI_Line_Item_Object, EEI_Admin_Links, EEI_Has_Icon, EEI_Event |
17 | 17 | { |
18 | - /** |
|
19 | - * cached value for the the logical active status for the event |
|
20 | - * |
|
21 | - * @see get_active_status() |
|
22 | - * @var string |
|
23 | - */ |
|
24 | - protected $_active_status = ''; |
|
25 | - |
|
26 | - /** |
|
27 | - * This is just used for caching the Primary Datetime for the Event on initial retrieval |
|
28 | - * |
|
29 | - * @var EE_Datetime |
|
30 | - */ |
|
31 | - protected $_Primary_Datetime; |
|
32 | - |
|
33 | - /** |
|
34 | - * @var EventSpacesCalculator $available_spaces_calculator |
|
35 | - */ |
|
36 | - protected $available_spaces_calculator; |
|
37 | - |
|
38 | - |
|
39 | - /** |
|
40 | - * @param array $props_n_values incoming values |
|
41 | - * @param string $timezone incoming timezone (if not set the timezone set for the website will be |
|
42 | - * used.) |
|
43 | - * @param array $date_formats incoming date_formats in an array where the first value is the |
|
44 | - * date_format and the second value is the time format |
|
45 | - * @return EE_Event |
|
46 | - * @throws EE_Error |
|
47 | - * @throws ReflectionException |
|
48 | - */ |
|
49 | - public static function new_instance($props_n_values = array(), $timezone = null, $date_formats = array()) |
|
50 | - { |
|
51 | - $has_object = parent::_check_for_object($props_n_values, __CLASS__, $timezone, $date_formats); |
|
52 | - return $has_object ? $has_object : new self($props_n_values, false, $timezone, $date_formats); |
|
53 | - } |
|
54 | - |
|
55 | - |
|
56 | - /** |
|
57 | - * @param array $props_n_values incoming values from the database |
|
58 | - * @param string $timezone incoming timezone as set by the model. If not set the timezone for |
|
59 | - * the website will be used. |
|
60 | - * @return EE_Event |
|
61 | - * @throws EE_Error |
|
62 | - * @throws ReflectionException |
|
63 | - */ |
|
64 | - public static function new_instance_from_db($props_n_values = array(), $timezone = null) |
|
65 | - { |
|
66 | - return new self($props_n_values, true, $timezone); |
|
67 | - } |
|
68 | - |
|
69 | - |
|
70 | - /** |
|
71 | - * @return EventSpacesCalculator |
|
72 | - * @throws \EE_Error |
|
73 | - */ |
|
74 | - public function getAvailableSpacesCalculator() |
|
75 | - { |
|
76 | - if (! $this->available_spaces_calculator instanceof EventSpacesCalculator) { |
|
77 | - $this->available_spaces_calculator = new EventSpacesCalculator($this); |
|
78 | - } |
|
79 | - return $this->available_spaces_calculator; |
|
80 | - } |
|
81 | - |
|
82 | - |
|
83 | - /** |
|
84 | - * Overrides parent set() method so that all calls to set( 'status', $status ) can be routed to internal methods |
|
85 | - * |
|
86 | - * @param string $field_name |
|
87 | - * @param mixed $field_value |
|
88 | - * @param bool $use_default |
|
89 | - * @throws EE_Error |
|
90 | - * @throws ReflectionException |
|
91 | - */ |
|
92 | - public function set($field_name, $field_value, $use_default = false) |
|
93 | - { |
|
94 | - switch ($field_name) { |
|
95 | - case 'status': |
|
96 | - $this->set_status($field_value, $use_default); |
|
97 | - break; |
|
98 | - default: |
|
99 | - parent::set($field_name, $field_value, $use_default); |
|
100 | - } |
|
101 | - } |
|
102 | - |
|
103 | - |
|
104 | - /** |
|
105 | - * set_status |
|
106 | - * Checks if event status is being changed to SOLD OUT |
|
107 | - * and updates event meta data with previous event status |
|
108 | - * so that we can revert things if/when the event is no longer sold out |
|
109 | - * |
|
110 | - * @access public |
|
111 | - * @param string $new_status |
|
112 | - * @param bool $use_default |
|
113 | - * @return void |
|
114 | - * @throws EE_Error |
|
115 | - * @throws ReflectionException |
|
116 | - */ |
|
117 | - public function set_status($new_status = null, $use_default = false) |
|
118 | - { |
|
119 | - // if nothing is set, and we aren't explicitly wanting to reset the status, then just leave |
|
120 | - if (empty($new_status) && ! $use_default) { |
|
121 | - return; |
|
122 | - } |
|
123 | - // get current Event status |
|
124 | - $old_status = $this->status(); |
|
125 | - // if status has changed |
|
126 | - if ($old_status !== $new_status) { |
|
127 | - // TO sold_out |
|
128 | - if ($new_status === EEM_Event::sold_out) { |
|
129 | - // save the previous event status so that we can revert if the event is no longer sold out |
|
130 | - $this->add_post_meta('_previous_event_status', $old_status); |
|
131 | - do_action('AHEE__EE_Event__set_status__to_sold_out', $this, $old_status, $new_status); |
|
132 | - // OR FROM sold_out |
|
133 | - } elseif ($old_status === EEM_Event::sold_out) { |
|
134 | - $this->delete_post_meta('_previous_event_status'); |
|
135 | - do_action('AHEE__EE_Event__set_status__from_sold_out', $this, $old_status, $new_status); |
|
136 | - } |
|
137 | - // clear out the active status so that it gets reset the next time it is requested |
|
138 | - $this->_active_status = null; |
|
139 | - // update status |
|
140 | - parent::set('status', $new_status, $use_default); |
|
141 | - do_action('AHEE__EE_Event__set_status__after_update', $this); |
|
142 | - return; |
|
143 | - } |
|
144 | - // even though the old value matches the new value, it's still good to |
|
145 | - // allow the parent set method to have a say |
|
146 | - parent::set('status', $new_status, $use_default); |
|
147 | - } |
|
148 | - |
|
149 | - |
|
150 | - /** |
|
151 | - * Gets all the datetimes for this event |
|
152 | - * |
|
153 | - * @param array $query_params @see |
|
154 | - * https://github.com/eventespresso/event-espresso-core/tree/master/docs/G--Model-System/model-query-params.md |
|
155 | - * @return EE_Base_Class[]|EE_Datetime[] |
|
156 | - * @throws EE_Error |
|
157 | - * @throws ReflectionException |
|
158 | - */ |
|
159 | - public function datetimes($query_params = array()) |
|
160 | - { |
|
161 | - return $this->get_many_related('Datetime', $query_params); |
|
162 | - } |
|
163 | - |
|
164 | - |
|
165 | - /** |
|
166 | - * Gets all the datetimes for this event, ordered by DTT_EVT_start in ascending order |
|
167 | - * |
|
168 | - * @return EE_Base_Class[]|EE_Datetime[] |
|
169 | - * @throws EE_Error |
|
170 | - * @throws ReflectionException |
|
171 | - */ |
|
172 | - public function datetimes_in_chronological_order() |
|
173 | - { |
|
174 | - return $this->get_many_related('Datetime', array('order_by' => array('DTT_EVT_start' => 'ASC'))); |
|
175 | - } |
|
176 | - |
|
177 | - |
|
178 | - /** |
|
179 | - * Gets all the datetimes for this event, ordered by the DTT_order on the datetime. |
|
180 | - * @darren, we should probably UNSET timezone on the EEM_Datetime model |
|
181 | - * after running our query, so that this timezone isn't set for EVERY query |
|
182 | - * on EEM_Datetime for the rest of the request, no? |
|
183 | - * |
|
184 | - * @param boolean $show_expired whether or not to include expired events |
|
185 | - * @param boolean $show_deleted whether or not to include deleted events |
|
186 | - * @param null $limit |
|
187 | - * @return EE_Datetime[] |
|
188 | - * @throws EE_Error |
|
189 | - * @throws ReflectionException |
|
190 | - */ |
|
191 | - public function datetimes_ordered($show_expired = true, $show_deleted = false, $limit = null) |
|
192 | - { |
|
193 | - return EEM_Datetime::instance($this->_timezone)->get_datetimes_for_event_ordered_by_DTT_order( |
|
194 | - $this->ID(), |
|
195 | - $show_expired, |
|
196 | - $show_deleted, |
|
197 | - $limit |
|
198 | - ); |
|
199 | - } |
|
200 | - |
|
201 | - |
|
202 | - /** |
|
203 | - * Returns one related datetime. Mostly only used by some legacy code. |
|
204 | - * |
|
205 | - * @return EE_Base_Class|EE_Datetime |
|
206 | - * @throws EE_Error |
|
207 | - * @throws ReflectionException |
|
208 | - */ |
|
209 | - public function first_datetime() |
|
210 | - { |
|
211 | - return $this->get_first_related('Datetime'); |
|
212 | - } |
|
213 | - |
|
214 | - |
|
215 | - /** |
|
216 | - * Returns the 'primary' datetime for the event |
|
217 | - * |
|
218 | - * @param bool $try_to_exclude_expired |
|
219 | - * @param bool $try_to_exclude_deleted |
|
220 | - * @return EE_Datetime |
|
221 | - * @throws EE_Error |
|
222 | - * @throws ReflectionException |
|
223 | - */ |
|
224 | - public function primary_datetime($try_to_exclude_expired = true, $try_to_exclude_deleted = true) |
|
225 | - { |
|
226 | - if (! empty($this->_Primary_Datetime)) { |
|
227 | - return $this->_Primary_Datetime; |
|
228 | - } |
|
229 | - $this->_Primary_Datetime = EEM_Datetime::instance($this->_timezone)->get_primary_datetime_for_event( |
|
230 | - $this->ID(), |
|
231 | - $try_to_exclude_expired, |
|
232 | - $try_to_exclude_deleted |
|
233 | - ); |
|
234 | - return $this->_Primary_Datetime; |
|
235 | - } |
|
236 | - |
|
237 | - |
|
238 | - /** |
|
239 | - * Gets all the tickets available for purchase of this event |
|
240 | - * |
|
241 | - * @param array $query_params @see |
|
242 | - * https://github.com/eventespresso/event-espresso-core/tree/master/docs/G--Model-System/model-query-params.md |
|
243 | - * @return EE_Base_Class[]|EE_Ticket[] |
|
244 | - * @throws EE_Error |
|
245 | - * @throws ReflectionException |
|
246 | - */ |
|
247 | - public function tickets($query_params = array()) |
|
248 | - { |
|
249 | - // first get all datetimes |
|
250 | - $datetimes = $this->datetimes_ordered(); |
|
251 | - if (! $datetimes) { |
|
252 | - return array(); |
|
253 | - } |
|
254 | - $datetime_ids = array(); |
|
255 | - foreach ($datetimes as $datetime) { |
|
256 | - $datetime_ids[] = $datetime->ID(); |
|
257 | - } |
|
258 | - $where_params = array('Datetime.DTT_ID' => array('IN', $datetime_ids)); |
|
259 | - // if incoming $query_params has where conditions let's merge but not override existing. |
|
260 | - if (is_array($query_params) && isset($query_params[0])) { |
|
261 | - $where_params = array_merge($query_params[0], $where_params); |
|
262 | - unset($query_params[0]); |
|
263 | - } |
|
264 | - // now add $where_params to $query_params |
|
265 | - $query_params[0] = $where_params; |
|
266 | - return EEM_Ticket::instance()->get_all($query_params); |
|
267 | - } |
|
268 | - |
|
269 | - |
|
270 | - /** |
|
271 | - * get all unexpired untrashed tickets |
|
272 | - * |
|
273 | - * @return EE_Ticket[] |
|
274 | - * @throws EE_Error |
|
275 | - */ |
|
276 | - public function active_tickets() |
|
277 | - { |
|
278 | - return $this->tickets( |
|
279 | - array( |
|
280 | - array( |
|
281 | - 'TKT_end_date' => array('>=', EEM_Ticket::instance()->current_time_for_query('TKT_end_date')), |
|
282 | - 'TKT_deleted' => false, |
|
283 | - ), |
|
284 | - ) |
|
285 | - ); |
|
286 | - } |
|
287 | - |
|
288 | - |
|
289 | - /** |
|
290 | - * @return bool |
|
291 | - * @throws EE_Error |
|
292 | - * @throws ReflectionException |
|
293 | - */ |
|
294 | - public function additional_limit() |
|
295 | - { |
|
296 | - return $this->get('EVT_additional_limit'); |
|
297 | - } |
|
298 | - |
|
299 | - |
|
300 | - /** |
|
301 | - * @return bool |
|
302 | - * @throws EE_Error |
|
303 | - * @throws ReflectionException |
|
304 | - */ |
|
305 | - public function allow_overflow() |
|
306 | - { |
|
307 | - return $this->get('EVT_allow_overflow'); |
|
308 | - } |
|
309 | - |
|
310 | - |
|
311 | - /** |
|
312 | - * @return bool |
|
313 | - * @throws EE_Error |
|
314 | - * @throws ReflectionException |
|
315 | - */ |
|
316 | - public function created() |
|
317 | - { |
|
318 | - return $this->get('EVT_created'); |
|
319 | - } |
|
320 | - |
|
321 | - |
|
322 | - /** |
|
323 | - * @return bool |
|
324 | - * @throws EE_Error |
|
325 | - * @throws ReflectionException |
|
326 | - */ |
|
327 | - public function description() |
|
328 | - { |
|
329 | - return $this->get('EVT_desc'); |
|
330 | - } |
|
331 | - |
|
332 | - |
|
333 | - /** |
|
334 | - * Runs do_shortcode and wpautop on the description |
|
335 | - * |
|
336 | - * @return string of html |
|
337 | - * @throws EE_Error |
|
338 | - * @throws ReflectionException |
|
339 | - */ |
|
340 | - public function description_filtered() |
|
341 | - { |
|
342 | - return $this->get_pretty('EVT_desc'); |
|
343 | - } |
|
344 | - |
|
345 | - |
|
346 | - /** |
|
347 | - * @return bool |
|
348 | - * @throws EE_Error |
|
349 | - * @throws ReflectionException |
|
350 | - */ |
|
351 | - public function display_description() |
|
352 | - { |
|
353 | - return $this->get('EVT_display_desc'); |
|
354 | - } |
|
355 | - |
|
356 | - |
|
357 | - /** |
|
358 | - * @return bool |
|
359 | - * @throws EE_Error |
|
360 | - * @throws ReflectionException |
|
361 | - */ |
|
362 | - public function display_ticket_selector() |
|
363 | - { |
|
364 | - return (bool) $this->get('EVT_display_ticket_selector'); |
|
365 | - } |
|
366 | - |
|
367 | - |
|
368 | - /** |
|
369 | - * @return string |
|
370 | - * @throws EE_Error |
|
371 | - * @throws ReflectionException |
|
372 | - */ |
|
373 | - public function external_url() |
|
374 | - { |
|
375 | - return $this->get('EVT_external_URL'); |
|
376 | - } |
|
377 | - |
|
378 | - |
|
379 | - /** |
|
380 | - * @return bool |
|
381 | - * @throws EE_Error |
|
382 | - * @throws ReflectionException |
|
383 | - */ |
|
384 | - public function member_only() |
|
385 | - { |
|
386 | - return $this->get('EVT_member_only'); |
|
387 | - } |
|
388 | - |
|
389 | - |
|
390 | - /** |
|
391 | - * @return bool |
|
392 | - * @throws EE_Error |
|
393 | - * @throws ReflectionException |
|
394 | - */ |
|
395 | - public function phone() |
|
396 | - { |
|
397 | - return $this->get('EVT_phone'); |
|
398 | - } |
|
399 | - |
|
400 | - |
|
401 | - /** |
|
402 | - * @return bool |
|
403 | - * @throws EE_Error |
|
404 | - * @throws ReflectionException |
|
405 | - */ |
|
406 | - public function modified() |
|
407 | - { |
|
408 | - return $this->get('EVT_modified'); |
|
409 | - } |
|
410 | - |
|
411 | - |
|
412 | - /** |
|
413 | - * @return bool |
|
414 | - * @throws EE_Error |
|
415 | - * @throws ReflectionException |
|
416 | - */ |
|
417 | - public function name() |
|
418 | - { |
|
419 | - return $this->get('EVT_name'); |
|
420 | - } |
|
421 | - |
|
422 | - |
|
423 | - /** |
|
424 | - * @return bool |
|
425 | - * @throws EE_Error |
|
426 | - * @throws ReflectionException |
|
427 | - */ |
|
428 | - public function order() |
|
429 | - { |
|
430 | - return $this->get('EVT_order'); |
|
431 | - } |
|
432 | - |
|
433 | - |
|
434 | - /** |
|
435 | - * @return bool|string |
|
436 | - * @throws EE_Error |
|
437 | - * @throws ReflectionException |
|
438 | - */ |
|
439 | - public function default_registration_status() |
|
440 | - { |
|
441 | - $event_default_registration_status = $this->get('EVT_default_registration_status'); |
|
442 | - return ! empty($event_default_registration_status) |
|
443 | - ? $event_default_registration_status |
|
444 | - : EE_Registry::instance()->CFG->registration->default_STS_ID; |
|
445 | - } |
|
446 | - |
|
447 | - |
|
448 | - /** |
|
449 | - * @param int $num_words |
|
450 | - * @param null $more |
|
451 | - * @param bool $not_full_desc |
|
452 | - * @return bool|string |
|
453 | - * @throws EE_Error |
|
454 | - * @throws ReflectionException |
|
455 | - */ |
|
456 | - public function short_description($num_words = 55, $more = null, $not_full_desc = false) |
|
457 | - { |
|
458 | - $short_desc = $this->get('EVT_short_desc'); |
|
459 | - if (! empty($short_desc) || $not_full_desc) { |
|
460 | - return $short_desc; |
|
461 | - } |
|
462 | - $full_desc = $this->get('EVT_desc'); |
|
463 | - return wp_trim_words($full_desc, $num_words, $more); |
|
464 | - } |
|
465 | - |
|
466 | - |
|
467 | - /** |
|
468 | - * @return bool |
|
469 | - * @throws EE_Error |
|
470 | - * @throws ReflectionException |
|
471 | - */ |
|
472 | - public function slug() |
|
473 | - { |
|
474 | - return $this->get('EVT_slug'); |
|
475 | - } |
|
476 | - |
|
477 | - |
|
478 | - /** |
|
479 | - * @return bool |
|
480 | - * @throws EE_Error |
|
481 | - * @throws ReflectionException |
|
482 | - */ |
|
483 | - public function timezone_string() |
|
484 | - { |
|
485 | - return $this->get('EVT_timezone_string'); |
|
486 | - } |
|
487 | - |
|
488 | - |
|
489 | - /** |
|
490 | - * @return bool |
|
491 | - * @throws EE_Error |
|
492 | - * @throws ReflectionException |
|
493 | - */ |
|
494 | - public function visible_on() |
|
495 | - { |
|
496 | - return $this->get('EVT_visible_on'); |
|
497 | - } |
|
498 | - |
|
499 | - |
|
500 | - /** |
|
501 | - * @return int |
|
502 | - * @throws EE_Error |
|
503 | - * @throws ReflectionException |
|
504 | - */ |
|
505 | - public function wp_user() |
|
506 | - { |
|
507 | - return $this->get('EVT_wp_user'); |
|
508 | - } |
|
509 | - |
|
510 | - |
|
511 | - /** |
|
512 | - * @return bool |
|
513 | - * @throws EE_Error |
|
514 | - * @throws ReflectionException |
|
515 | - */ |
|
516 | - public function donations() |
|
517 | - { |
|
518 | - return $this->get('EVT_donations'); |
|
519 | - } |
|
520 | - |
|
521 | - |
|
522 | - /** |
|
523 | - * @param $limit |
|
524 | - * @throws EE_Error |
|
525 | - */ |
|
526 | - public function set_additional_limit($limit) |
|
527 | - { |
|
528 | - $this->set('EVT_additional_limit', $limit); |
|
529 | - } |
|
530 | - |
|
531 | - |
|
532 | - /** |
|
533 | - * @param $created |
|
534 | - * @throws EE_Error |
|
535 | - */ |
|
536 | - public function set_created($created) |
|
537 | - { |
|
538 | - $this->set('EVT_created', $created); |
|
539 | - } |
|
540 | - |
|
541 | - |
|
542 | - /** |
|
543 | - * @param $desc |
|
544 | - * @throws EE_Error |
|
545 | - */ |
|
546 | - public function set_description($desc) |
|
547 | - { |
|
548 | - $this->set('EVT_desc', $desc); |
|
549 | - } |
|
550 | - |
|
551 | - |
|
552 | - /** |
|
553 | - * @param $display_desc |
|
554 | - * @throws EE_Error |
|
555 | - */ |
|
556 | - public function set_display_description($display_desc) |
|
557 | - { |
|
558 | - $this->set('EVT_display_desc', $display_desc); |
|
559 | - } |
|
560 | - |
|
561 | - |
|
562 | - /** |
|
563 | - * @param $display_ticket_selector |
|
564 | - * @throws EE_Error |
|
565 | - */ |
|
566 | - public function set_display_ticket_selector($display_ticket_selector) |
|
567 | - { |
|
568 | - $this->set('EVT_display_ticket_selector', $display_ticket_selector); |
|
569 | - } |
|
570 | - |
|
571 | - |
|
572 | - /** |
|
573 | - * @param $external_url |
|
574 | - * @throws EE_Error |
|
575 | - */ |
|
576 | - public function set_external_url($external_url) |
|
577 | - { |
|
578 | - $this->set('EVT_external_URL', $external_url); |
|
579 | - } |
|
580 | - |
|
581 | - |
|
582 | - /** |
|
583 | - * @param $member_only |
|
584 | - * @throws EE_Error |
|
585 | - */ |
|
586 | - public function set_member_only($member_only) |
|
587 | - { |
|
588 | - $this->set('EVT_member_only', $member_only); |
|
589 | - } |
|
590 | - |
|
591 | - |
|
592 | - /** |
|
593 | - * @param $event_phone |
|
594 | - * @throws EE_Error |
|
595 | - */ |
|
596 | - public function set_event_phone($event_phone) |
|
597 | - { |
|
598 | - $this->set('EVT_phone', $event_phone); |
|
599 | - } |
|
600 | - |
|
601 | - |
|
602 | - /** |
|
603 | - * @param $modified |
|
604 | - * @throws EE_Error |
|
605 | - */ |
|
606 | - public function set_modified($modified) |
|
607 | - { |
|
608 | - $this->set('EVT_modified', $modified); |
|
609 | - } |
|
610 | - |
|
611 | - |
|
612 | - /** |
|
613 | - * @param $name |
|
614 | - * @throws EE_Error |
|
615 | - */ |
|
616 | - public function set_name($name) |
|
617 | - { |
|
618 | - $this->set('EVT_name', $name); |
|
619 | - } |
|
620 | - |
|
621 | - |
|
622 | - /** |
|
623 | - * @param $order |
|
624 | - * @throws EE_Error |
|
625 | - */ |
|
626 | - public function set_order($order) |
|
627 | - { |
|
628 | - $this->set('EVT_order', $order); |
|
629 | - } |
|
630 | - |
|
631 | - |
|
632 | - /** |
|
633 | - * @param $short_desc |
|
634 | - * @throws EE_Error |
|
635 | - */ |
|
636 | - public function set_short_description($short_desc) |
|
637 | - { |
|
638 | - $this->set('EVT_short_desc', $short_desc); |
|
639 | - } |
|
640 | - |
|
641 | - |
|
642 | - /** |
|
643 | - * @param $slug |
|
644 | - * @throws EE_Error |
|
645 | - */ |
|
646 | - public function set_slug($slug) |
|
647 | - { |
|
648 | - $this->set('EVT_slug', $slug); |
|
649 | - } |
|
650 | - |
|
651 | - |
|
652 | - /** |
|
653 | - * @param $timezone_string |
|
654 | - * @throws EE_Error |
|
655 | - */ |
|
656 | - public function set_timezone_string($timezone_string) |
|
657 | - { |
|
658 | - $this->set('EVT_timezone_string', $timezone_string); |
|
659 | - } |
|
660 | - |
|
661 | - |
|
662 | - /** |
|
663 | - * @param $visible_on |
|
664 | - * @throws EE_Error |
|
665 | - */ |
|
666 | - public function set_visible_on($visible_on) |
|
667 | - { |
|
668 | - $this->set('EVT_visible_on', $visible_on); |
|
669 | - } |
|
670 | - |
|
671 | - |
|
672 | - /** |
|
673 | - * @param $wp_user |
|
674 | - * @throws EE_Error |
|
675 | - */ |
|
676 | - public function set_wp_user($wp_user) |
|
677 | - { |
|
678 | - $this->set('EVT_wp_user', $wp_user); |
|
679 | - } |
|
680 | - |
|
681 | - |
|
682 | - /** |
|
683 | - * @param $default_registration_status |
|
684 | - * @throws EE_Error |
|
685 | - */ |
|
686 | - public function set_default_registration_status($default_registration_status) |
|
687 | - { |
|
688 | - $this->set('EVT_default_registration_status', $default_registration_status); |
|
689 | - } |
|
690 | - |
|
691 | - |
|
692 | - /** |
|
693 | - * @param $donations |
|
694 | - * @throws EE_Error |
|
695 | - */ |
|
696 | - public function set_donations($donations) |
|
697 | - { |
|
698 | - $this->set('EVT_donations', $donations); |
|
699 | - } |
|
700 | - |
|
701 | - |
|
702 | - /** |
|
703 | - * Adds a venue to this event |
|
704 | - * |
|
705 | - * @param EE_Venue /int $venue_id_or_obj |
|
706 | - * @return EE_Base_Class|EE_Venue |
|
707 | - * @throws EE_Error |
|
708 | - * @throws ReflectionException |
|
709 | - */ |
|
710 | - public function add_venue($venue_id_or_obj) |
|
711 | - { |
|
712 | - return $this->_add_relation_to($venue_id_or_obj, 'Venue'); |
|
713 | - } |
|
714 | - |
|
715 | - |
|
716 | - /** |
|
717 | - * Removes a venue from the event |
|
718 | - * |
|
719 | - * @param EE_Venue /int $venue_id_or_obj |
|
720 | - * @return EE_Base_Class|EE_Venue |
|
721 | - * @throws EE_Error |
|
722 | - * @throws ReflectionException |
|
723 | - */ |
|
724 | - public function remove_venue($venue_id_or_obj) |
|
725 | - { |
|
726 | - return $this->_remove_relation_to($venue_id_or_obj, 'Venue'); |
|
727 | - } |
|
728 | - |
|
729 | - |
|
730 | - /** |
|
731 | - * Gets all the venues related ot the event. May provide additional $query_params if desired |
|
732 | - * |
|
733 | - * @param array $query_params @see |
|
734 | - * https://github.com/eventespresso/event-espresso-core/tree/master/docs/G--Model-System/model-query-params.md |
|
735 | - * @return EE_Base_Class[]|EE_Venue[] |
|
736 | - * @throws EE_Error |
|
737 | - * @throws ReflectionException |
|
738 | - */ |
|
739 | - public function venues($query_params = array()) |
|
740 | - { |
|
741 | - return $this->get_many_related('Venue', $query_params); |
|
742 | - } |
|
743 | - |
|
744 | - |
|
745 | - /** |
|
746 | - * check if event id is present and if event is published |
|
747 | - * |
|
748 | - * @access public |
|
749 | - * @return boolean true yes, false no |
|
750 | - * @throws EE_Error |
|
751 | - * @throws ReflectionException |
|
752 | - */ |
|
753 | - private function _has_ID_and_is_published() |
|
754 | - { |
|
755 | - // first check if event id is present and not NULL, |
|
756 | - // then check if this event is published (or any of the equivalent "published" statuses) |
|
757 | - return |
|
758 | - $this->ID() && $this->ID() !== null |
|
759 | - && ( |
|
760 | - $this->status() === 'publish' |
|
761 | - || $this->status() === EEM_Event::sold_out |
|
762 | - || $this->status() === EEM_Event::postponed |
|
763 | - || $this->status() === EEM_Event::cancelled |
|
764 | - ); |
|
765 | - } |
|
766 | - |
|
767 | - |
|
768 | - /** |
|
769 | - * This simply compares the internal dates with NOW and determines if the event is upcoming or not. |
|
770 | - * |
|
771 | - * @access public |
|
772 | - * @return boolean true yes, false no |
|
773 | - * @throws EE_Error |
|
774 | - * @throws ReflectionException |
|
775 | - */ |
|
776 | - public function is_upcoming() |
|
777 | - { |
|
778 | - // check if event id is present and if this event is published |
|
779 | - if ($this->is_inactive()) { |
|
780 | - return false; |
|
781 | - } |
|
782 | - // set initial value |
|
783 | - $upcoming = false; |
|
784 | - // next let's get all datetimes and loop through them |
|
785 | - $datetimes = $this->datetimes_in_chronological_order(); |
|
786 | - foreach ($datetimes as $datetime) { |
|
787 | - if ($datetime instanceof EE_Datetime) { |
|
788 | - // if this dtt is expired then we continue cause one of the other datetimes might be upcoming. |
|
789 | - if ($datetime->is_expired()) { |
|
790 | - continue; |
|
791 | - } |
|
792 | - // if this dtt is active then we return false. |
|
793 | - if ($datetime->is_active()) { |
|
794 | - return false; |
|
795 | - } |
|
796 | - // otherwise let's check upcoming status |
|
797 | - $upcoming = $datetime->is_upcoming(); |
|
798 | - } |
|
799 | - } |
|
800 | - return $upcoming; |
|
801 | - } |
|
802 | - |
|
803 | - |
|
804 | - /** |
|
805 | - * @return bool |
|
806 | - * @throws EE_Error |
|
807 | - * @throws ReflectionException |
|
808 | - */ |
|
809 | - public function is_active() |
|
810 | - { |
|
811 | - // check if event id is present and if this event is published |
|
812 | - if ($this->is_inactive()) { |
|
813 | - return false; |
|
814 | - } |
|
815 | - // set initial value |
|
816 | - $active = false; |
|
817 | - // next let's get all datetimes and loop through them |
|
818 | - $datetimes = $this->datetimes_in_chronological_order(); |
|
819 | - foreach ($datetimes as $datetime) { |
|
820 | - if ($datetime instanceof EE_Datetime) { |
|
821 | - // if this dtt is expired then we continue cause one of the other datetimes might be active. |
|
822 | - if ($datetime->is_expired()) { |
|
823 | - continue; |
|
824 | - } |
|
825 | - // if this dtt is upcoming then we return false. |
|
826 | - if ($datetime->is_upcoming()) { |
|
827 | - return false; |
|
828 | - } |
|
829 | - // otherwise let's check active status |
|
830 | - $active = $datetime->is_active(); |
|
831 | - } |
|
832 | - } |
|
833 | - return $active; |
|
834 | - } |
|
835 | - |
|
836 | - |
|
837 | - /** |
|
838 | - * @return bool |
|
839 | - * @throws EE_Error |
|
840 | - * @throws ReflectionException |
|
841 | - */ |
|
842 | - public function is_expired() |
|
843 | - { |
|
844 | - // check if event id is present and if this event is published |
|
845 | - if ($this->is_inactive()) { |
|
846 | - return false; |
|
847 | - } |
|
848 | - // set initial value |
|
849 | - $expired = false; |
|
850 | - // first let's get all datetimes and loop through them |
|
851 | - $datetimes = $this->datetimes_in_chronological_order(); |
|
852 | - foreach ($datetimes as $datetime) { |
|
853 | - if ($datetime instanceof EE_Datetime) { |
|
854 | - // if this dtt is upcoming or active then we return false. |
|
855 | - if ($datetime->is_upcoming() || $datetime->is_active()) { |
|
856 | - return false; |
|
857 | - } |
|
858 | - // otherwise let's check active status |
|
859 | - $expired = $datetime->is_expired(); |
|
860 | - } |
|
861 | - } |
|
862 | - return $expired; |
|
863 | - } |
|
864 | - |
|
865 | - |
|
866 | - /** |
|
867 | - * @return bool |
|
868 | - * @throws EE_Error |
|
869 | - */ |
|
870 | - public function is_inactive() |
|
871 | - { |
|
872 | - // check if event id is present and if this event is published |
|
873 | - if ($this->_has_ID_and_is_published()) { |
|
874 | - return false; |
|
875 | - } |
|
876 | - return true; |
|
877 | - } |
|
878 | - |
|
879 | - |
|
880 | - /** |
|
881 | - * calculate spaces remaining based on "saleable" tickets |
|
882 | - * |
|
883 | - * @param array $tickets |
|
884 | - * @param bool $filtered |
|
885 | - * @return int|float |
|
886 | - * @throws EE_Error |
|
887 | - * @throws DomainException |
|
888 | - * @throws UnexpectedEntityException |
|
889 | - */ |
|
890 | - public function spaces_remaining($tickets = array(), $filtered = true) |
|
891 | - { |
|
892 | - $this->getAvailableSpacesCalculator()->setActiveTickets($tickets); |
|
893 | - $spaces_remaining = $this->getAvailableSpacesCalculator()->spacesRemaining(); |
|
894 | - return $filtered |
|
895 | - ? apply_filters( |
|
896 | - 'FHEE_EE_Event__spaces_remaining', |
|
897 | - $spaces_remaining, |
|
898 | - $this, |
|
899 | - $tickets |
|
900 | - ) |
|
901 | - : $spaces_remaining; |
|
902 | - } |
|
903 | - |
|
904 | - |
|
905 | - /** |
|
906 | - * perform_sold_out_status_check |
|
907 | - * checks all of this events's datetime reg_limit - sold values to determine if ANY datetimes have spaces |
|
908 | - * available... if NOT, then the event status will get toggled to 'sold_out' |
|
909 | - * |
|
910 | - * @return bool return the ACTUAL sold out state. |
|
911 | - * @throws EE_Error |
|
912 | - * @throws DomainException |
|
913 | - * @throws UnexpectedEntityException |
|
914 | - * @throws ReflectionException |
|
915 | - */ |
|
916 | - public function perform_sold_out_status_check() |
|
917 | - { |
|
918 | - // get all tickets |
|
919 | - $tickets = $this->tickets( |
|
920 | - array( |
|
921 | - 'default_where_conditions' => 'none', |
|
922 | - 'order_by' => array('TKT_qty' => 'ASC'), |
|
923 | - ) |
|
924 | - ); |
|
925 | - $all_expired = true; |
|
926 | - foreach ($tickets as $ticket) { |
|
927 | - if (! $ticket->is_expired()) { |
|
928 | - $all_expired = false; |
|
929 | - break; |
|
930 | - } |
|
931 | - } |
|
932 | - // if all the tickets are just expired, then don't update the event status to sold out |
|
933 | - if ($all_expired) { |
|
934 | - return true; |
|
935 | - } |
|
936 | - $spaces_remaining = $this->spaces_remaining($tickets); |
|
937 | - if ($spaces_remaining < 1) { |
|
938 | - if ($this->status() !== EEM_Event::post_status_private) { |
|
939 | - $this->set_status(EEM_Event::sold_out); |
|
940 | - $this->save(); |
|
941 | - } |
|
942 | - $sold_out = true; |
|
943 | - } else { |
|
944 | - $sold_out = false; |
|
945 | - // was event previously marked as sold out ? |
|
946 | - if ($this->status() === EEM_Event::sold_out) { |
|
947 | - // revert status to previous value, if it was set |
|
948 | - $previous_event_status = $this->get_post_meta('_previous_event_status', true); |
|
949 | - if ($previous_event_status) { |
|
950 | - $this->set_status($previous_event_status); |
|
951 | - $this->save(); |
|
952 | - } |
|
953 | - } |
|
954 | - } |
|
955 | - do_action('AHEE__EE_Event__perform_sold_out_status_check__end', $this, $sold_out, $spaces_remaining, $tickets); |
|
956 | - return $sold_out; |
|
957 | - } |
|
958 | - |
|
959 | - |
|
960 | - /** |
|
961 | - * This returns the total remaining spaces for sale on this event. |
|
962 | - * |
|
963 | - * @uses EE_Event::total_available_spaces() |
|
964 | - * @return float|int |
|
965 | - * @throws EE_Error |
|
966 | - * @throws DomainException |
|
967 | - * @throws UnexpectedEntityException |
|
968 | - */ |
|
969 | - public function spaces_remaining_for_sale() |
|
970 | - { |
|
971 | - return $this->total_available_spaces(true); |
|
972 | - } |
|
973 | - |
|
974 | - |
|
975 | - /** |
|
976 | - * This returns the total spaces available for an event |
|
977 | - * while considering all the qtys on the tickets and the reg limits |
|
978 | - * on the datetimes attached to this event. |
|
979 | - * |
|
980 | - * @param bool $consider_sold Whether to consider any tickets that have already sold in our calculation. |
|
981 | - * If this is false, then we return the most tickets that could ever be sold |
|
982 | - * for this event with the datetime and tickets setup on the event under optimal |
|
983 | - * selling conditions. Otherwise we return a live calculation of spaces available |
|
984 | - * based on tickets sold. Depending on setup and stage of sales, this |
|
985 | - * may appear to equal remaining tickets. However, the more tickets are |
|
986 | - * sold out, the more accurate the "live" total is. |
|
987 | - * @return float|int |
|
988 | - * @throws EE_Error |
|
989 | - * @throws DomainException |
|
990 | - * @throws UnexpectedEntityException |
|
991 | - */ |
|
992 | - public function total_available_spaces($consider_sold = false) |
|
993 | - { |
|
994 | - $spaces_available = $consider_sold |
|
995 | - ? $this->getAvailableSpacesCalculator()->spacesRemaining() |
|
996 | - : $this->getAvailableSpacesCalculator()->totalSpacesAvailable(); |
|
997 | - return apply_filters( |
|
998 | - 'FHEE_EE_Event__total_available_spaces__spaces_available', |
|
999 | - $spaces_available, |
|
1000 | - $this, |
|
1001 | - $this->getAvailableSpacesCalculator()->getDatetimes(), |
|
1002 | - $this->getAvailableSpacesCalculator()->getActiveTickets() |
|
1003 | - ); |
|
1004 | - } |
|
1005 | - |
|
1006 | - |
|
1007 | - /** |
|
1008 | - * Checks if the event is set to sold out |
|
1009 | - * |
|
1010 | - * @param bool $actual whether or not to perform calculations to not only figure the |
|
1011 | - * actual status but also to flip the status if necessary to sold |
|
1012 | - * out If false, we just check the existing status of the event |
|
1013 | - * @return boolean |
|
1014 | - * @throws EE_Error |
|
1015 | - */ |
|
1016 | - public function is_sold_out($actual = false) |
|
1017 | - { |
|
1018 | - if (! $actual) { |
|
1019 | - return $this->status() === EEM_Event::sold_out; |
|
1020 | - } |
|
1021 | - return $this->perform_sold_out_status_check(); |
|
1022 | - } |
|
1023 | - |
|
1024 | - |
|
1025 | - /** |
|
1026 | - * Checks if the event is marked as postponed |
|
1027 | - * |
|
1028 | - * @return boolean |
|
1029 | - */ |
|
1030 | - public function is_postponed() |
|
1031 | - { |
|
1032 | - return $this->status() === EEM_Event::postponed; |
|
1033 | - } |
|
1034 | - |
|
1035 | - |
|
1036 | - /** |
|
1037 | - * Checks if the event is marked as cancelled |
|
1038 | - * |
|
1039 | - * @return boolean |
|
1040 | - */ |
|
1041 | - public function is_cancelled() |
|
1042 | - { |
|
1043 | - return $this->status() === EEM_Event::cancelled; |
|
1044 | - } |
|
1045 | - |
|
1046 | - |
|
1047 | - /** |
|
1048 | - * Get the logical active status in a hierarchical order for all the datetimes. Note |
|
1049 | - * Basically, we order the datetimes by EVT_start_date. Then first test on whether the event is published. If its |
|
1050 | - * NOT published then we test for whether its expired or not. IF it IS published then we test first on whether an |
|
1051 | - * event has any active dates. If no active dates then we check for any upcoming dates. If no upcoming dates then |
|
1052 | - * the event is considered expired. |
|
1053 | - * NOTE: this method does NOT calculate whether the datetimes are sold out when event is published. Sold Out is a |
|
1054 | - * status set on the EVENT when it is not published and thus is done |
|
1055 | - * |
|
1056 | - * @param bool $reset |
|
1057 | - * @return bool | string - based on EE_Datetime active constants or FALSE if error. |
|
1058 | - * @throws EE_Error |
|
1059 | - * @throws ReflectionException |
|
1060 | - */ |
|
1061 | - public function get_active_status($reset = false) |
|
1062 | - { |
|
1063 | - // if the active status has already been set, then just use that value (unless we are resetting it) |
|
1064 | - if (! empty($this->_active_status) && ! $reset) { |
|
1065 | - return $this->_active_status; |
|
1066 | - } |
|
1067 | - // first check if event id is present on this object |
|
1068 | - if (! $this->ID()) { |
|
1069 | - return false; |
|
1070 | - } |
|
1071 | - $where_params_for_event = array(array('EVT_ID' => $this->ID())); |
|
1072 | - // if event is published: |
|
1073 | - if ($this->status() === EEM_Event::post_status_publish || $this->status() === EEM_Event::post_status_private) { |
|
1074 | - // active? |
|
1075 | - if ( |
|
1076 | - EEM_Datetime::instance()->get_datetime_count_for_status( |
|
1077 | - EE_Datetime::active, |
|
1078 | - $where_params_for_event |
|
1079 | - ) > 0 |
|
1080 | - ) { |
|
1081 | - $this->_active_status = EE_Datetime::active; |
|
1082 | - } else { |
|
1083 | - // upcoming? |
|
1084 | - if ( |
|
1085 | - EEM_Datetime::instance()->get_datetime_count_for_status( |
|
1086 | - EE_Datetime::upcoming, |
|
1087 | - $where_params_for_event |
|
1088 | - ) > 0 |
|
1089 | - ) { |
|
1090 | - $this->_active_status = EE_Datetime::upcoming; |
|
1091 | - } else { |
|
1092 | - // expired? |
|
1093 | - if ( |
|
1094 | - EEM_Datetime::instance()->get_datetime_count_for_status( |
|
1095 | - EE_Datetime::expired, |
|
1096 | - $where_params_for_event |
|
1097 | - ) > 0 |
|
1098 | - ) { |
|
1099 | - $this->_active_status = EE_Datetime::expired; |
|
1100 | - } else { |
|
1101 | - // it would be odd if things make it this far because it basically means there are no datetime's |
|
1102 | - // attached to the event. So in this case it will just be considered inactive. |
|
1103 | - $this->_active_status = EE_Datetime::inactive; |
|
1104 | - } |
|
1105 | - } |
|
1106 | - } |
|
1107 | - } else { |
|
1108 | - // the event is not published, so let's just set it's active status according to its' post status |
|
1109 | - switch ($this->status()) { |
|
1110 | - case EEM_Event::sold_out: |
|
1111 | - $this->_active_status = EE_Datetime::sold_out; |
|
1112 | - break; |
|
1113 | - case EEM_Event::cancelled: |
|
1114 | - $this->_active_status = EE_Datetime::cancelled; |
|
1115 | - break; |
|
1116 | - case EEM_Event::postponed: |
|
1117 | - $this->_active_status = EE_Datetime::postponed; |
|
1118 | - break; |
|
1119 | - default: |
|
1120 | - $this->_active_status = EE_Datetime::inactive; |
|
1121 | - } |
|
1122 | - } |
|
1123 | - return $this->_active_status; |
|
1124 | - } |
|
1125 | - |
|
1126 | - |
|
1127 | - /** |
|
1128 | - * pretty_active_status |
|
1129 | - * |
|
1130 | - * @access public |
|
1131 | - * @param boolean $echo whether to return (FALSE), or echo out the result (TRUE) |
|
1132 | - * @return mixed void|string |
|
1133 | - * @throws EE_Error |
|
1134 | - * @throws ReflectionException |
|
1135 | - */ |
|
1136 | - public function pretty_active_status($echo = true) |
|
1137 | - { |
|
1138 | - $active_status = $this->get_active_status(); |
|
1139 | - $status = '<span class="ee-status event-active-status-' . esc_attr($active_status) . '">' |
|
1140 | - . EEH_Template::pretty_status($active_status, false, 'sentence') |
|
1141 | - . '</span>'; |
|
1142 | - if ($echo) { |
|
1143 | - echo wp_kses($status, AllowedTags::getAllowedTags()); |
|
1144 | - return ''; |
|
1145 | - } |
|
1146 | - return $status; // already escaped |
|
1147 | - } |
|
1148 | - |
|
1149 | - |
|
1150 | - /** |
|
1151 | - * @return bool|int |
|
1152 | - * @throws EE_Error |
|
1153 | - * @throws ReflectionException |
|
1154 | - */ |
|
1155 | - public function get_number_of_tickets_sold() |
|
1156 | - { |
|
1157 | - $tkt_sold = 0; |
|
1158 | - if (! $this->ID()) { |
|
1159 | - return 0; |
|
1160 | - } |
|
1161 | - $datetimes = $this->datetimes(); |
|
1162 | - foreach ($datetimes as $datetime) { |
|
1163 | - if ($datetime instanceof EE_Datetime) { |
|
1164 | - $tkt_sold += $datetime->sold(); |
|
1165 | - } |
|
1166 | - } |
|
1167 | - return $tkt_sold; |
|
1168 | - } |
|
1169 | - |
|
1170 | - |
|
1171 | - /** |
|
1172 | - * This just returns a count of all the registrations for this event |
|
1173 | - * |
|
1174 | - * @access public |
|
1175 | - * @return int |
|
1176 | - * @throws EE_Error |
|
1177 | - */ |
|
1178 | - public function get_count_of_all_registrations() |
|
1179 | - { |
|
1180 | - return EEM_Event::instance()->count_related($this, 'Registration'); |
|
1181 | - } |
|
1182 | - |
|
1183 | - |
|
1184 | - /** |
|
1185 | - * This returns the ticket with the earliest start time that is |
|
1186 | - * available for this event (across all datetimes attached to the event) |
|
1187 | - * |
|
1188 | - * @return EE_Base_Class|EE_Ticket|null |
|
1189 | - * @throws EE_Error |
|
1190 | - * @throws ReflectionException |
|
1191 | - */ |
|
1192 | - public function get_ticket_with_earliest_start_time() |
|
1193 | - { |
|
1194 | - $where['Datetime.EVT_ID'] = $this->ID(); |
|
1195 | - $query_params = array($where, 'order_by' => array('TKT_start_date' => 'ASC')); |
|
1196 | - return EE_Registry::instance()->load_model('Ticket')->get_one($query_params); |
|
1197 | - } |
|
1198 | - |
|
1199 | - |
|
1200 | - /** |
|
1201 | - * This returns the ticket with the latest end time that is available |
|
1202 | - * for this event (across all datetimes attached to the event) |
|
1203 | - * |
|
1204 | - * @return EE_Base_Class|EE_Ticket|null |
|
1205 | - * @throws EE_Error |
|
1206 | - * @throws ReflectionException |
|
1207 | - */ |
|
1208 | - public function get_ticket_with_latest_end_time() |
|
1209 | - { |
|
1210 | - $where['Datetime.EVT_ID'] = $this->ID(); |
|
1211 | - $query_params = array($where, 'order_by' => array('TKT_end_date' => 'DESC')); |
|
1212 | - return EE_Registry::instance()->load_model('Ticket')->get_one($query_params); |
|
1213 | - } |
|
1214 | - |
|
1215 | - |
|
1216 | - /** |
|
1217 | - * This returns the number of different ticket types currently on sale for this event. |
|
1218 | - * |
|
1219 | - * @return int |
|
1220 | - * @throws EE_Error |
|
1221 | - * @throws ReflectionException |
|
1222 | - */ |
|
1223 | - public function countTicketsOnSale() |
|
1224 | - { |
|
1225 | - $where = array( |
|
1226 | - 'Datetime.EVT_ID' => $this->ID(), |
|
1227 | - 'TKT_start_date' => array('<', time()), |
|
1228 | - 'TKT_end_date' => array('>', time()), |
|
1229 | - ); |
|
1230 | - return EEM_Ticket::instance()->count(array($where)); |
|
1231 | - } |
|
1232 | - |
|
1233 | - |
|
1234 | - /** |
|
1235 | - * This returns whether there are any tickets on sale for this event. |
|
1236 | - * |
|
1237 | - * @return bool true = YES tickets on sale. |
|
1238 | - * @throws EE_Error |
|
1239 | - */ |
|
1240 | - public function tickets_on_sale() |
|
1241 | - { |
|
1242 | - return $this->countTicketsOnSale() > 0; |
|
1243 | - } |
|
1244 | - |
|
1245 | - |
|
1246 | - /** |
|
1247 | - * Gets the URL for viewing this event on the front-end. Overrides parent |
|
1248 | - * to check for an external URL first |
|
1249 | - * |
|
1250 | - * @return string |
|
1251 | - * @throws EE_Error |
|
1252 | - */ |
|
1253 | - public function get_permalink() |
|
1254 | - { |
|
1255 | - if ($this->external_url()) { |
|
1256 | - return $this->external_url(); |
|
1257 | - } |
|
1258 | - return parent::get_permalink(); |
|
1259 | - } |
|
1260 | - |
|
1261 | - |
|
1262 | - /** |
|
1263 | - * Gets the first term for 'espresso_event_categories' we can find |
|
1264 | - * |
|
1265 | - * @param array $query_params @see |
|
1266 | - * https://github.com/eventespresso/event-espresso-core/tree/master/docs/G--Model-System/model-query-params.md |
|
1267 | - * @return EE_Base_Class|EE_Term|null |
|
1268 | - * @throws EE_Error |
|
1269 | - * @throws ReflectionException |
|
1270 | - */ |
|
1271 | - public function first_event_category($query_params = array()) |
|
1272 | - { |
|
1273 | - $query_params[0]['Term_Taxonomy.taxonomy'] = 'espresso_event_categories'; |
|
1274 | - $query_params[0]['Term_Taxonomy.Event.EVT_ID'] = $this->ID(); |
|
1275 | - return EEM_Term::instance()->get_one($query_params); |
|
1276 | - } |
|
1277 | - |
|
1278 | - |
|
1279 | - /** |
|
1280 | - * Gets all terms for 'espresso_event_categories' we can find |
|
1281 | - * |
|
1282 | - * @param array $query_params |
|
1283 | - * @return EE_Base_Class[]|EE_Term[] |
|
1284 | - * @throws EE_Error |
|
1285 | - * @throws ReflectionException |
|
1286 | - */ |
|
1287 | - public function get_all_event_categories($query_params = array()) |
|
1288 | - { |
|
1289 | - $query_params[0]['Term_Taxonomy.taxonomy'] = 'espresso_event_categories'; |
|
1290 | - $query_params[0]['Term_Taxonomy.Event.EVT_ID'] = $this->ID(); |
|
1291 | - return EEM_Term::instance()->get_all($query_params); |
|
1292 | - } |
|
1293 | - |
|
1294 | - |
|
1295 | - /** |
|
1296 | - * Adds a question group to this event |
|
1297 | - * |
|
1298 | - * @param EE_Question_Group|int $question_group_id_or_obj |
|
1299 | - * @param bool $for_primary if true, the question group will be added for the primary |
|
1300 | - * registrant, if false will be added for others. default: false |
|
1301 | - * @return EE_Base_Class|EE_Question_Group |
|
1302 | - * @throws EE_Error |
|
1303 | - * @throws InvalidArgumentException |
|
1304 | - * @throws InvalidDataTypeException |
|
1305 | - * @throws InvalidInterfaceException |
|
1306 | - * @throws ReflectionException |
|
1307 | - */ |
|
1308 | - public function add_question_group($question_group_id_or_obj, $for_primary = false) |
|
1309 | - { |
|
1310 | - // If the row already exists, it will be updated. If it doesn't, it will be inserted. |
|
1311 | - // That's in EE_HABTM_Relation::add_relation_to(). |
|
1312 | - return $this->_add_relation_to( |
|
1313 | - $question_group_id_or_obj, |
|
1314 | - 'Question_Group', |
|
1315 | - [ |
|
1316 | - EEM_Event_Question_Group::instance()->fieldNameForContext($for_primary) => true |
|
1317 | - ] |
|
1318 | - ); |
|
1319 | - } |
|
1320 | - |
|
1321 | - |
|
1322 | - /** |
|
1323 | - * Removes a question group from the event |
|
1324 | - * |
|
1325 | - * @param EE_Question_Group|int $question_group_id_or_obj |
|
1326 | - * @param bool $for_primary if true, the question group will be removed from the primary |
|
1327 | - * registrant, if false will be removed from others. default: false |
|
1328 | - * @return EE_Base_Class|EE_Question_Group |
|
1329 | - * @throws EE_Error |
|
1330 | - * @throws InvalidArgumentException |
|
1331 | - * @throws ReflectionException |
|
1332 | - * @throws InvalidDataTypeException |
|
1333 | - * @throws InvalidInterfaceException |
|
1334 | - */ |
|
1335 | - public function remove_question_group($question_group_id_or_obj, $for_primary = false) |
|
1336 | - { |
|
1337 | - // If the question group is used for the other type (primary or additional) |
|
1338 | - // then just update it. If not, delete it outright. |
|
1339 | - $existing_relation = $this->get_first_related( |
|
1340 | - 'Event_Question_Group', |
|
1341 | - [ |
|
1342 | - [ |
|
1343 | - 'QSG_ID' => EEM_Question_Group::instance()->ensure_is_ID($question_group_id_or_obj) |
|
1344 | - ] |
|
1345 | - ] |
|
1346 | - ); |
|
1347 | - $field_to_update = EEM_Event_Question_Group::instance()->fieldNameForContext($for_primary); |
|
1348 | - $other_field = EEM_Event_Question_Group::instance()->fieldNameForContext(! $for_primary); |
|
1349 | - if ($existing_relation->get($other_field) === false) { |
|
1350 | - // Delete it. It's now no longer for primary or additional question groups. |
|
1351 | - return $this->_remove_relation_to($question_group_id_or_obj, 'Question_Group'); |
|
1352 | - } |
|
1353 | - // Just update it. They'll still use this question group for the other category |
|
1354 | - $existing_relation->save( |
|
1355 | - [ |
|
1356 | - $field_to_update => false |
|
1357 | - ] |
|
1358 | - ); |
|
1359 | - } |
|
1360 | - |
|
1361 | - |
|
1362 | - /** |
|
1363 | - * Gets all the question groups, ordering them by QSG_order ascending |
|
1364 | - * |
|
1365 | - * @param array $query_params @see |
|
1366 | - * https://github.com/eventespresso/event-espresso-core/tree/master/docs/G--Model-System/model-query-params.md |
|
1367 | - * @return EE_Base_Class[]|EE_Question_Group[] |
|
1368 | - * @throws EE_Error |
|
1369 | - * @throws ReflectionException |
|
1370 | - */ |
|
1371 | - public function question_groups($query_params = array()) |
|
1372 | - { |
|
1373 | - $query_params = ! empty($query_params) ? $query_params : array('order_by' => array('QSG_order' => 'ASC')); |
|
1374 | - return $this->get_many_related('Question_Group', $query_params); |
|
1375 | - } |
|
1376 | - |
|
1377 | - |
|
1378 | - /** |
|
1379 | - * Implementation for EEI_Has_Icon interface method. |
|
1380 | - * |
|
1381 | - * @see EEI_Visual_Representation for comments |
|
1382 | - * @return string |
|
1383 | - */ |
|
1384 | - public function get_icon() |
|
1385 | - { |
|
1386 | - return '<span class="dashicons dashicons-flag"></span>'; |
|
1387 | - } |
|
1388 | - |
|
1389 | - |
|
1390 | - /** |
|
1391 | - * Implementation for EEI_Admin_Links interface method. |
|
1392 | - * |
|
1393 | - * @see EEI_Admin_Links for comments |
|
1394 | - * @return string |
|
1395 | - * @throws EE_Error |
|
1396 | - */ |
|
1397 | - public function get_admin_details_link() |
|
1398 | - { |
|
1399 | - return $this->get_admin_edit_link(); |
|
1400 | - } |
|
1401 | - |
|
1402 | - |
|
1403 | - /** |
|
1404 | - * Implementation for EEI_Admin_Links interface method. |
|
1405 | - * |
|
1406 | - * @return string |
|
1407 | - * @throws EE_Error*@throws ReflectionException |
|
1408 | - * @see EEI_Admin_Links for comments |
|
1409 | - */ |
|
1410 | - public function get_admin_edit_link() |
|
1411 | - { |
|
1412 | - return EEH_URL::add_query_args_and_nonce( |
|
1413 | - array( |
|
1414 | - 'page' => 'espresso_events', |
|
1415 | - 'action' => 'edit', |
|
1416 | - 'post' => $this->ID(), |
|
1417 | - ), |
|
1418 | - admin_url('admin.php') |
|
1419 | - ); |
|
1420 | - } |
|
1421 | - |
|
1422 | - |
|
1423 | - /** |
|
1424 | - * Implementation for EEI_Admin_Links interface method. |
|
1425 | - * |
|
1426 | - * @see EEI_Admin_Links for comments |
|
1427 | - * @return string |
|
1428 | - */ |
|
1429 | - public function get_admin_settings_link() |
|
1430 | - { |
|
1431 | - return EEH_URL::add_query_args_and_nonce( |
|
1432 | - array( |
|
1433 | - 'page' => 'espresso_events', |
|
1434 | - 'action' => 'default_event_settings', |
|
1435 | - ), |
|
1436 | - admin_url('admin.php') |
|
1437 | - ); |
|
1438 | - } |
|
1439 | - |
|
1440 | - |
|
1441 | - /** |
|
1442 | - * Implementation for EEI_Admin_Links interface method. |
|
1443 | - * |
|
1444 | - * @see EEI_Admin_Links for comments |
|
1445 | - * @return string |
|
1446 | - */ |
|
1447 | - public function get_admin_overview_link() |
|
1448 | - { |
|
1449 | - return EEH_URL::add_query_args_and_nonce( |
|
1450 | - array( |
|
1451 | - 'page' => 'espresso_events', |
|
1452 | - 'action' => 'default', |
|
1453 | - ), |
|
1454 | - admin_url('admin.php') |
|
1455 | - ); |
|
1456 | - } |
|
18 | + /** |
|
19 | + * cached value for the the logical active status for the event |
|
20 | + * |
|
21 | + * @see get_active_status() |
|
22 | + * @var string |
|
23 | + */ |
|
24 | + protected $_active_status = ''; |
|
25 | + |
|
26 | + /** |
|
27 | + * This is just used for caching the Primary Datetime for the Event on initial retrieval |
|
28 | + * |
|
29 | + * @var EE_Datetime |
|
30 | + */ |
|
31 | + protected $_Primary_Datetime; |
|
32 | + |
|
33 | + /** |
|
34 | + * @var EventSpacesCalculator $available_spaces_calculator |
|
35 | + */ |
|
36 | + protected $available_spaces_calculator; |
|
37 | + |
|
38 | + |
|
39 | + /** |
|
40 | + * @param array $props_n_values incoming values |
|
41 | + * @param string $timezone incoming timezone (if not set the timezone set for the website will be |
|
42 | + * used.) |
|
43 | + * @param array $date_formats incoming date_formats in an array where the first value is the |
|
44 | + * date_format and the second value is the time format |
|
45 | + * @return EE_Event |
|
46 | + * @throws EE_Error |
|
47 | + * @throws ReflectionException |
|
48 | + */ |
|
49 | + public static function new_instance($props_n_values = array(), $timezone = null, $date_formats = array()) |
|
50 | + { |
|
51 | + $has_object = parent::_check_for_object($props_n_values, __CLASS__, $timezone, $date_formats); |
|
52 | + return $has_object ? $has_object : new self($props_n_values, false, $timezone, $date_formats); |
|
53 | + } |
|
54 | + |
|
55 | + |
|
56 | + /** |
|
57 | + * @param array $props_n_values incoming values from the database |
|
58 | + * @param string $timezone incoming timezone as set by the model. If not set the timezone for |
|
59 | + * the website will be used. |
|
60 | + * @return EE_Event |
|
61 | + * @throws EE_Error |
|
62 | + * @throws ReflectionException |
|
63 | + */ |
|
64 | + public static function new_instance_from_db($props_n_values = array(), $timezone = null) |
|
65 | + { |
|
66 | + return new self($props_n_values, true, $timezone); |
|
67 | + } |
|
68 | + |
|
69 | + |
|
70 | + /** |
|
71 | + * @return EventSpacesCalculator |
|
72 | + * @throws \EE_Error |
|
73 | + */ |
|
74 | + public function getAvailableSpacesCalculator() |
|
75 | + { |
|
76 | + if (! $this->available_spaces_calculator instanceof EventSpacesCalculator) { |
|
77 | + $this->available_spaces_calculator = new EventSpacesCalculator($this); |
|
78 | + } |
|
79 | + return $this->available_spaces_calculator; |
|
80 | + } |
|
81 | + |
|
82 | + |
|
83 | + /** |
|
84 | + * Overrides parent set() method so that all calls to set( 'status', $status ) can be routed to internal methods |
|
85 | + * |
|
86 | + * @param string $field_name |
|
87 | + * @param mixed $field_value |
|
88 | + * @param bool $use_default |
|
89 | + * @throws EE_Error |
|
90 | + * @throws ReflectionException |
|
91 | + */ |
|
92 | + public function set($field_name, $field_value, $use_default = false) |
|
93 | + { |
|
94 | + switch ($field_name) { |
|
95 | + case 'status': |
|
96 | + $this->set_status($field_value, $use_default); |
|
97 | + break; |
|
98 | + default: |
|
99 | + parent::set($field_name, $field_value, $use_default); |
|
100 | + } |
|
101 | + } |
|
102 | + |
|
103 | + |
|
104 | + /** |
|
105 | + * set_status |
|
106 | + * Checks if event status is being changed to SOLD OUT |
|
107 | + * and updates event meta data with previous event status |
|
108 | + * so that we can revert things if/when the event is no longer sold out |
|
109 | + * |
|
110 | + * @access public |
|
111 | + * @param string $new_status |
|
112 | + * @param bool $use_default |
|
113 | + * @return void |
|
114 | + * @throws EE_Error |
|
115 | + * @throws ReflectionException |
|
116 | + */ |
|
117 | + public function set_status($new_status = null, $use_default = false) |
|
118 | + { |
|
119 | + // if nothing is set, and we aren't explicitly wanting to reset the status, then just leave |
|
120 | + if (empty($new_status) && ! $use_default) { |
|
121 | + return; |
|
122 | + } |
|
123 | + // get current Event status |
|
124 | + $old_status = $this->status(); |
|
125 | + // if status has changed |
|
126 | + if ($old_status !== $new_status) { |
|
127 | + // TO sold_out |
|
128 | + if ($new_status === EEM_Event::sold_out) { |
|
129 | + // save the previous event status so that we can revert if the event is no longer sold out |
|
130 | + $this->add_post_meta('_previous_event_status', $old_status); |
|
131 | + do_action('AHEE__EE_Event__set_status__to_sold_out', $this, $old_status, $new_status); |
|
132 | + // OR FROM sold_out |
|
133 | + } elseif ($old_status === EEM_Event::sold_out) { |
|
134 | + $this->delete_post_meta('_previous_event_status'); |
|
135 | + do_action('AHEE__EE_Event__set_status__from_sold_out', $this, $old_status, $new_status); |
|
136 | + } |
|
137 | + // clear out the active status so that it gets reset the next time it is requested |
|
138 | + $this->_active_status = null; |
|
139 | + // update status |
|
140 | + parent::set('status', $new_status, $use_default); |
|
141 | + do_action('AHEE__EE_Event__set_status__after_update', $this); |
|
142 | + return; |
|
143 | + } |
|
144 | + // even though the old value matches the new value, it's still good to |
|
145 | + // allow the parent set method to have a say |
|
146 | + parent::set('status', $new_status, $use_default); |
|
147 | + } |
|
148 | + |
|
149 | + |
|
150 | + /** |
|
151 | + * Gets all the datetimes for this event |
|
152 | + * |
|
153 | + * @param array $query_params @see |
|
154 | + * https://github.com/eventespresso/event-espresso-core/tree/master/docs/G--Model-System/model-query-params.md |
|
155 | + * @return EE_Base_Class[]|EE_Datetime[] |
|
156 | + * @throws EE_Error |
|
157 | + * @throws ReflectionException |
|
158 | + */ |
|
159 | + public function datetimes($query_params = array()) |
|
160 | + { |
|
161 | + return $this->get_many_related('Datetime', $query_params); |
|
162 | + } |
|
163 | + |
|
164 | + |
|
165 | + /** |
|
166 | + * Gets all the datetimes for this event, ordered by DTT_EVT_start in ascending order |
|
167 | + * |
|
168 | + * @return EE_Base_Class[]|EE_Datetime[] |
|
169 | + * @throws EE_Error |
|
170 | + * @throws ReflectionException |
|
171 | + */ |
|
172 | + public function datetimes_in_chronological_order() |
|
173 | + { |
|
174 | + return $this->get_many_related('Datetime', array('order_by' => array('DTT_EVT_start' => 'ASC'))); |
|
175 | + } |
|
176 | + |
|
177 | + |
|
178 | + /** |
|
179 | + * Gets all the datetimes for this event, ordered by the DTT_order on the datetime. |
|
180 | + * @darren, we should probably UNSET timezone on the EEM_Datetime model |
|
181 | + * after running our query, so that this timezone isn't set for EVERY query |
|
182 | + * on EEM_Datetime for the rest of the request, no? |
|
183 | + * |
|
184 | + * @param boolean $show_expired whether or not to include expired events |
|
185 | + * @param boolean $show_deleted whether or not to include deleted events |
|
186 | + * @param null $limit |
|
187 | + * @return EE_Datetime[] |
|
188 | + * @throws EE_Error |
|
189 | + * @throws ReflectionException |
|
190 | + */ |
|
191 | + public function datetimes_ordered($show_expired = true, $show_deleted = false, $limit = null) |
|
192 | + { |
|
193 | + return EEM_Datetime::instance($this->_timezone)->get_datetimes_for_event_ordered_by_DTT_order( |
|
194 | + $this->ID(), |
|
195 | + $show_expired, |
|
196 | + $show_deleted, |
|
197 | + $limit |
|
198 | + ); |
|
199 | + } |
|
200 | + |
|
201 | + |
|
202 | + /** |
|
203 | + * Returns one related datetime. Mostly only used by some legacy code. |
|
204 | + * |
|
205 | + * @return EE_Base_Class|EE_Datetime |
|
206 | + * @throws EE_Error |
|
207 | + * @throws ReflectionException |
|
208 | + */ |
|
209 | + public function first_datetime() |
|
210 | + { |
|
211 | + return $this->get_first_related('Datetime'); |
|
212 | + } |
|
213 | + |
|
214 | + |
|
215 | + /** |
|
216 | + * Returns the 'primary' datetime for the event |
|
217 | + * |
|
218 | + * @param bool $try_to_exclude_expired |
|
219 | + * @param bool $try_to_exclude_deleted |
|
220 | + * @return EE_Datetime |
|
221 | + * @throws EE_Error |
|
222 | + * @throws ReflectionException |
|
223 | + */ |
|
224 | + public function primary_datetime($try_to_exclude_expired = true, $try_to_exclude_deleted = true) |
|
225 | + { |
|
226 | + if (! empty($this->_Primary_Datetime)) { |
|
227 | + return $this->_Primary_Datetime; |
|
228 | + } |
|
229 | + $this->_Primary_Datetime = EEM_Datetime::instance($this->_timezone)->get_primary_datetime_for_event( |
|
230 | + $this->ID(), |
|
231 | + $try_to_exclude_expired, |
|
232 | + $try_to_exclude_deleted |
|
233 | + ); |
|
234 | + return $this->_Primary_Datetime; |
|
235 | + } |
|
236 | + |
|
237 | + |
|
238 | + /** |
|
239 | + * Gets all the tickets available for purchase of this event |
|
240 | + * |
|
241 | + * @param array $query_params @see |
|
242 | + * https://github.com/eventespresso/event-espresso-core/tree/master/docs/G--Model-System/model-query-params.md |
|
243 | + * @return EE_Base_Class[]|EE_Ticket[] |
|
244 | + * @throws EE_Error |
|
245 | + * @throws ReflectionException |
|
246 | + */ |
|
247 | + public function tickets($query_params = array()) |
|
248 | + { |
|
249 | + // first get all datetimes |
|
250 | + $datetimes = $this->datetimes_ordered(); |
|
251 | + if (! $datetimes) { |
|
252 | + return array(); |
|
253 | + } |
|
254 | + $datetime_ids = array(); |
|
255 | + foreach ($datetimes as $datetime) { |
|
256 | + $datetime_ids[] = $datetime->ID(); |
|
257 | + } |
|
258 | + $where_params = array('Datetime.DTT_ID' => array('IN', $datetime_ids)); |
|
259 | + // if incoming $query_params has where conditions let's merge but not override existing. |
|
260 | + if (is_array($query_params) && isset($query_params[0])) { |
|
261 | + $where_params = array_merge($query_params[0], $where_params); |
|
262 | + unset($query_params[0]); |
|
263 | + } |
|
264 | + // now add $where_params to $query_params |
|
265 | + $query_params[0] = $where_params; |
|
266 | + return EEM_Ticket::instance()->get_all($query_params); |
|
267 | + } |
|
268 | + |
|
269 | + |
|
270 | + /** |
|
271 | + * get all unexpired untrashed tickets |
|
272 | + * |
|
273 | + * @return EE_Ticket[] |
|
274 | + * @throws EE_Error |
|
275 | + */ |
|
276 | + public function active_tickets() |
|
277 | + { |
|
278 | + return $this->tickets( |
|
279 | + array( |
|
280 | + array( |
|
281 | + 'TKT_end_date' => array('>=', EEM_Ticket::instance()->current_time_for_query('TKT_end_date')), |
|
282 | + 'TKT_deleted' => false, |
|
283 | + ), |
|
284 | + ) |
|
285 | + ); |
|
286 | + } |
|
287 | + |
|
288 | + |
|
289 | + /** |
|
290 | + * @return bool |
|
291 | + * @throws EE_Error |
|
292 | + * @throws ReflectionException |
|
293 | + */ |
|
294 | + public function additional_limit() |
|
295 | + { |
|
296 | + return $this->get('EVT_additional_limit'); |
|
297 | + } |
|
298 | + |
|
299 | + |
|
300 | + /** |
|
301 | + * @return bool |
|
302 | + * @throws EE_Error |
|
303 | + * @throws ReflectionException |
|
304 | + */ |
|
305 | + public function allow_overflow() |
|
306 | + { |
|
307 | + return $this->get('EVT_allow_overflow'); |
|
308 | + } |
|
309 | + |
|
310 | + |
|
311 | + /** |
|
312 | + * @return bool |
|
313 | + * @throws EE_Error |
|
314 | + * @throws ReflectionException |
|
315 | + */ |
|
316 | + public function created() |
|
317 | + { |
|
318 | + return $this->get('EVT_created'); |
|
319 | + } |
|
320 | + |
|
321 | + |
|
322 | + /** |
|
323 | + * @return bool |
|
324 | + * @throws EE_Error |
|
325 | + * @throws ReflectionException |
|
326 | + */ |
|
327 | + public function description() |
|
328 | + { |
|
329 | + return $this->get('EVT_desc'); |
|
330 | + } |
|
331 | + |
|
332 | + |
|
333 | + /** |
|
334 | + * Runs do_shortcode and wpautop on the description |
|
335 | + * |
|
336 | + * @return string of html |
|
337 | + * @throws EE_Error |
|
338 | + * @throws ReflectionException |
|
339 | + */ |
|
340 | + public function description_filtered() |
|
341 | + { |
|
342 | + return $this->get_pretty('EVT_desc'); |
|
343 | + } |
|
344 | + |
|
345 | + |
|
346 | + /** |
|
347 | + * @return bool |
|
348 | + * @throws EE_Error |
|
349 | + * @throws ReflectionException |
|
350 | + */ |
|
351 | + public function display_description() |
|
352 | + { |
|
353 | + return $this->get('EVT_display_desc'); |
|
354 | + } |
|
355 | + |
|
356 | + |
|
357 | + /** |
|
358 | + * @return bool |
|
359 | + * @throws EE_Error |
|
360 | + * @throws ReflectionException |
|
361 | + */ |
|
362 | + public function display_ticket_selector() |
|
363 | + { |
|
364 | + return (bool) $this->get('EVT_display_ticket_selector'); |
|
365 | + } |
|
366 | + |
|
367 | + |
|
368 | + /** |
|
369 | + * @return string |
|
370 | + * @throws EE_Error |
|
371 | + * @throws ReflectionException |
|
372 | + */ |
|
373 | + public function external_url() |
|
374 | + { |
|
375 | + return $this->get('EVT_external_URL'); |
|
376 | + } |
|
377 | + |
|
378 | + |
|
379 | + /** |
|
380 | + * @return bool |
|
381 | + * @throws EE_Error |
|
382 | + * @throws ReflectionException |
|
383 | + */ |
|
384 | + public function member_only() |
|
385 | + { |
|
386 | + return $this->get('EVT_member_only'); |
|
387 | + } |
|
388 | + |
|
389 | + |
|
390 | + /** |
|
391 | + * @return bool |
|
392 | + * @throws EE_Error |
|
393 | + * @throws ReflectionException |
|
394 | + */ |
|
395 | + public function phone() |
|
396 | + { |
|
397 | + return $this->get('EVT_phone'); |
|
398 | + } |
|
399 | + |
|
400 | + |
|
401 | + /** |
|
402 | + * @return bool |
|
403 | + * @throws EE_Error |
|
404 | + * @throws ReflectionException |
|
405 | + */ |
|
406 | + public function modified() |
|
407 | + { |
|
408 | + return $this->get('EVT_modified'); |
|
409 | + } |
|
410 | + |
|
411 | + |
|
412 | + /** |
|
413 | + * @return bool |
|
414 | + * @throws EE_Error |
|
415 | + * @throws ReflectionException |
|
416 | + */ |
|
417 | + public function name() |
|
418 | + { |
|
419 | + return $this->get('EVT_name'); |
|
420 | + } |
|
421 | + |
|
422 | + |
|
423 | + /** |
|
424 | + * @return bool |
|
425 | + * @throws EE_Error |
|
426 | + * @throws ReflectionException |
|
427 | + */ |
|
428 | + public function order() |
|
429 | + { |
|
430 | + return $this->get('EVT_order'); |
|
431 | + } |
|
432 | + |
|
433 | + |
|
434 | + /** |
|
435 | + * @return bool|string |
|
436 | + * @throws EE_Error |
|
437 | + * @throws ReflectionException |
|
438 | + */ |
|
439 | + public function default_registration_status() |
|
440 | + { |
|
441 | + $event_default_registration_status = $this->get('EVT_default_registration_status'); |
|
442 | + return ! empty($event_default_registration_status) |
|
443 | + ? $event_default_registration_status |
|
444 | + : EE_Registry::instance()->CFG->registration->default_STS_ID; |
|
445 | + } |
|
446 | + |
|
447 | + |
|
448 | + /** |
|
449 | + * @param int $num_words |
|
450 | + * @param null $more |
|
451 | + * @param bool $not_full_desc |
|
452 | + * @return bool|string |
|
453 | + * @throws EE_Error |
|
454 | + * @throws ReflectionException |
|
455 | + */ |
|
456 | + public function short_description($num_words = 55, $more = null, $not_full_desc = false) |
|
457 | + { |
|
458 | + $short_desc = $this->get('EVT_short_desc'); |
|
459 | + if (! empty($short_desc) || $not_full_desc) { |
|
460 | + return $short_desc; |
|
461 | + } |
|
462 | + $full_desc = $this->get('EVT_desc'); |
|
463 | + return wp_trim_words($full_desc, $num_words, $more); |
|
464 | + } |
|
465 | + |
|
466 | + |
|
467 | + /** |
|
468 | + * @return bool |
|
469 | + * @throws EE_Error |
|
470 | + * @throws ReflectionException |
|
471 | + */ |
|
472 | + public function slug() |
|
473 | + { |
|
474 | + return $this->get('EVT_slug'); |
|
475 | + } |
|
476 | + |
|
477 | + |
|
478 | + /** |
|
479 | + * @return bool |
|
480 | + * @throws EE_Error |
|
481 | + * @throws ReflectionException |
|
482 | + */ |
|
483 | + public function timezone_string() |
|
484 | + { |
|
485 | + return $this->get('EVT_timezone_string'); |
|
486 | + } |
|
487 | + |
|
488 | + |
|
489 | + /** |
|
490 | + * @return bool |
|
491 | + * @throws EE_Error |
|
492 | + * @throws ReflectionException |
|
493 | + */ |
|
494 | + public function visible_on() |
|
495 | + { |
|
496 | + return $this->get('EVT_visible_on'); |
|
497 | + } |
|
498 | + |
|
499 | + |
|
500 | + /** |
|
501 | + * @return int |
|
502 | + * @throws EE_Error |
|
503 | + * @throws ReflectionException |
|
504 | + */ |
|
505 | + public function wp_user() |
|
506 | + { |
|
507 | + return $this->get('EVT_wp_user'); |
|
508 | + } |
|
509 | + |
|
510 | + |
|
511 | + /** |
|
512 | + * @return bool |
|
513 | + * @throws EE_Error |
|
514 | + * @throws ReflectionException |
|
515 | + */ |
|
516 | + public function donations() |
|
517 | + { |
|
518 | + return $this->get('EVT_donations'); |
|
519 | + } |
|
520 | + |
|
521 | + |
|
522 | + /** |
|
523 | + * @param $limit |
|
524 | + * @throws EE_Error |
|
525 | + */ |
|
526 | + public function set_additional_limit($limit) |
|
527 | + { |
|
528 | + $this->set('EVT_additional_limit', $limit); |
|
529 | + } |
|
530 | + |
|
531 | + |
|
532 | + /** |
|
533 | + * @param $created |
|
534 | + * @throws EE_Error |
|
535 | + */ |
|
536 | + public function set_created($created) |
|
537 | + { |
|
538 | + $this->set('EVT_created', $created); |
|
539 | + } |
|
540 | + |
|
541 | + |
|
542 | + /** |
|
543 | + * @param $desc |
|
544 | + * @throws EE_Error |
|
545 | + */ |
|
546 | + public function set_description($desc) |
|
547 | + { |
|
548 | + $this->set('EVT_desc', $desc); |
|
549 | + } |
|
550 | + |
|
551 | + |
|
552 | + /** |
|
553 | + * @param $display_desc |
|
554 | + * @throws EE_Error |
|
555 | + */ |
|
556 | + public function set_display_description($display_desc) |
|
557 | + { |
|
558 | + $this->set('EVT_display_desc', $display_desc); |
|
559 | + } |
|
560 | + |
|
561 | + |
|
562 | + /** |
|
563 | + * @param $display_ticket_selector |
|
564 | + * @throws EE_Error |
|
565 | + */ |
|
566 | + public function set_display_ticket_selector($display_ticket_selector) |
|
567 | + { |
|
568 | + $this->set('EVT_display_ticket_selector', $display_ticket_selector); |
|
569 | + } |
|
570 | + |
|
571 | + |
|
572 | + /** |
|
573 | + * @param $external_url |
|
574 | + * @throws EE_Error |
|
575 | + */ |
|
576 | + public function set_external_url($external_url) |
|
577 | + { |
|
578 | + $this->set('EVT_external_URL', $external_url); |
|
579 | + } |
|
580 | + |
|
581 | + |
|
582 | + /** |
|
583 | + * @param $member_only |
|
584 | + * @throws EE_Error |
|
585 | + */ |
|
586 | + public function set_member_only($member_only) |
|
587 | + { |
|
588 | + $this->set('EVT_member_only', $member_only); |
|
589 | + } |
|
590 | + |
|
591 | + |
|
592 | + /** |
|
593 | + * @param $event_phone |
|
594 | + * @throws EE_Error |
|
595 | + */ |
|
596 | + public function set_event_phone($event_phone) |
|
597 | + { |
|
598 | + $this->set('EVT_phone', $event_phone); |
|
599 | + } |
|
600 | + |
|
601 | + |
|
602 | + /** |
|
603 | + * @param $modified |
|
604 | + * @throws EE_Error |
|
605 | + */ |
|
606 | + public function set_modified($modified) |
|
607 | + { |
|
608 | + $this->set('EVT_modified', $modified); |
|
609 | + } |
|
610 | + |
|
611 | + |
|
612 | + /** |
|
613 | + * @param $name |
|
614 | + * @throws EE_Error |
|
615 | + */ |
|
616 | + public function set_name($name) |
|
617 | + { |
|
618 | + $this->set('EVT_name', $name); |
|
619 | + } |
|
620 | + |
|
621 | + |
|
622 | + /** |
|
623 | + * @param $order |
|
624 | + * @throws EE_Error |
|
625 | + */ |
|
626 | + public function set_order($order) |
|
627 | + { |
|
628 | + $this->set('EVT_order', $order); |
|
629 | + } |
|
630 | + |
|
631 | + |
|
632 | + /** |
|
633 | + * @param $short_desc |
|
634 | + * @throws EE_Error |
|
635 | + */ |
|
636 | + public function set_short_description($short_desc) |
|
637 | + { |
|
638 | + $this->set('EVT_short_desc', $short_desc); |
|
639 | + } |
|
640 | + |
|
641 | + |
|
642 | + /** |
|
643 | + * @param $slug |
|
644 | + * @throws EE_Error |
|
645 | + */ |
|
646 | + public function set_slug($slug) |
|
647 | + { |
|
648 | + $this->set('EVT_slug', $slug); |
|
649 | + } |
|
650 | + |
|
651 | + |
|
652 | + /** |
|
653 | + * @param $timezone_string |
|
654 | + * @throws EE_Error |
|
655 | + */ |
|
656 | + public function set_timezone_string($timezone_string) |
|
657 | + { |
|
658 | + $this->set('EVT_timezone_string', $timezone_string); |
|
659 | + } |
|
660 | + |
|
661 | + |
|
662 | + /** |
|
663 | + * @param $visible_on |
|
664 | + * @throws EE_Error |
|
665 | + */ |
|
666 | + public function set_visible_on($visible_on) |
|
667 | + { |
|
668 | + $this->set('EVT_visible_on', $visible_on); |
|
669 | + } |
|
670 | + |
|
671 | + |
|
672 | + /** |
|
673 | + * @param $wp_user |
|
674 | + * @throws EE_Error |
|
675 | + */ |
|
676 | + public function set_wp_user($wp_user) |
|
677 | + { |
|
678 | + $this->set('EVT_wp_user', $wp_user); |
|
679 | + } |
|
680 | + |
|
681 | + |
|
682 | + /** |
|
683 | + * @param $default_registration_status |
|
684 | + * @throws EE_Error |
|
685 | + */ |
|
686 | + public function set_default_registration_status($default_registration_status) |
|
687 | + { |
|
688 | + $this->set('EVT_default_registration_status', $default_registration_status); |
|
689 | + } |
|
690 | + |
|
691 | + |
|
692 | + /** |
|
693 | + * @param $donations |
|
694 | + * @throws EE_Error |
|
695 | + */ |
|
696 | + public function set_donations($donations) |
|
697 | + { |
|
698 | + $this->set('EVT_donations', $donations); |
|
699 | + } |
|
700 | + |
|
701 | + |
|
702 | + /** |
|
703 | + * Adds a venue to this event |
|
704 | + * |
|
705 | + * @param EE_Venue /int $venue_id_or_obj |
|
706 | + * @return EE_Base_Class|EE_Venue |
|
707 | + * @throws EE_Error |
|
708 | + * @throws ReflectionException |
|
709 | + */ |
|
710 | + public function add_venue($venue_id_or_obj) |
|
711 | + { |
|
712 | + return $this->_add_relation_to($venue_id_or_obj, 'Venue'); |
|
713 | + } |
|
714 | + |
|
715 | + |
|
716 | + /** |
|
717 | + * Removes a venue from the event |
|
718 | + * |
|
719 | + * @param EE_Venue /int $venue_id_or_obj |
|
720 | + * @return EE_Base_Class|EE_Venue |
|
721 | + * @throws EE_Error |
|
722 | + * @throws ReflectionException |
|
723 | + */ |
|
724 | + public function remove_venue($venue_id_or_obj) |
|
725 | + { |
|
726 | + return $this->_remove_relation_to($venue_id_or_obj, 'Venue'); |
|
727 | + } |
|
728 | + |
|
729 | + |
|
730 | + /** |
|
731 | + * Gets all the venues related ot the event. May provide additional $query_params if desired |
|
732 | + * |
|
733 | + * @param array $query_params @see |
|
734 | + * https://github.com/eventespresso/event-espresso-core/tree/master/docs/G--Model-System/model-query-params.md |
|
735 | + * @return EE_Base_Class[]|EE_Venue[] |
|
736 | + * @throws EE_Error |
|
737 | + * @throws ReflectionException |
|
738 | + */ |
|
739 | + public function venues($query_params = array()) |
|
740 | + { |
|
741 | + return $this->get_many_related('Venue', $query_params); |
|
742 | + } |
|
743 | + |
|
744 | + |
|
745 | + /** |
|
746 | + * check if event id is present and if event is published |
|
747 | + * |
|
748 | + * @access public |
|
749 | + * @return boolean true yes, false no |
|
750 | + * @throws EE_Error |
|
751 | + * @throws ReflectionException |
|
752 | + */ |
|
753 | + private function _has_ID_and_is_published() |
|
754 | + { |
|
755 | + // first check if event id is present and not NULL, |
|
756 | + // then check if this event is published (or any of the equivalent "published" statuses) |
|
757 | + return |
|
758 | + $this->ID() && $this->ID() !== null |
|
759 | + && ( |
|
760 | + $this->status() === 'publish' |
|
761 | + || $this->status() === EEM_Event::sold_out |
|
762 | + || $this->status() === EEM_Event::postponed |
|
763 | + || $this->status() === EEM_Event::cancelled |
|
764 | + ); |
|
765 | + } |
|
766 | + |
|
767 | + |
|
768 | + /** |
|
769 | + * This simply compares the internal dates with NOW and determines if the event is upcoming or not. |
|
770 | + * |
|
771 | + * @access public |
|
772 | + * @return boolean true yes, false no |
|
773 | + * @throws EE_Error |
|
774 | + * @throws ReflectionException |
|
775 | + */ |
|
776 | + public function is_upcoming() |
|
777 | + { |
|
778 | + // check if event id is present and if this event is published |
|
779 | + if ($this->is_inactive()) { |
|
780 | + return false; |
|
781 | + } |
|
782 | + // set initial value |
|
783 | + $upcoming = false; |
|
784 | + // next let's get all datetimes and loop through them |
|
785 | + $datetimes = $this->datetimes_in_chronological_order(); |
|
786 | + foreach ($datetimes as $datetime) { |
|
787 | + if ($datetime instanceof EE_Datetime) { |
|
788 | + // if this dtt is expired then we continue cause one of the other datetimes might be upcoming. |
|
789 | + if ($datetime->is_expired()) { |
|
790 | + continue; |
|
791 | + } |
|
792 | + // if this dtt is active then we return false. |
|
793 | + if ($datetime->is_active()) { |
|
794 | + return false; |
|
795 | + } |
|
796 | + // otherwise let's check upcoming status |
|
797 | + $upcoming = $datetime->is_upcoming(); |
|
798 | + } |
|
799 | + } |
|
800 | + return $upcoming; |
|
801 | + } |
|
802 | + |
|
803 | + |
|
804 | + /** |
|
805 | + * @return bool |
|
806 | + * @throws EE_Error |
|
807 | + * @throws ReflectionException |
|
808 | + */ |
|
809 | + public function is_active() |
|
810 | + { |
|
811 | + // check if event id is present and if this event is published |
|
812 | + if ($this->is_inactive()) { |
|
813 | + return false; |
|
814 | + } |
|
815 | + // set initial value |
|
816 | + $active = false; |
|
817 | + // next let's get all datetimes and loop through them |
|
818 | + $datetimes = $this->datetimes_in_chronological_order(); |
|
819 | + foreach ($datetimes as $datetime) { |
|
820 | + if ($datetime instanceof EE_Datetime) { |
|
821 | + // if this dtt is expired then we continue cause one of the other datetimes might be active. |
|
822 | + if ($datetime->is_expired()) { |
|
823 | + continue; |
|
824 | + } |
|
825 | + // if this dtt is upcoming then we return false. |
|
826 | + if ($datetime->is_upcoming()) { |
|
827 | + return false; |
|
828 | + } |
|
829 | + // otherwise let's check active status |
|
830 | + $active = $datetime->is_active(); |
|
831 | + } |
|
832 | + } |
|
833 | + return $active; |
|
834 | + } |
|
835 | + |
|
836 | + |
|
837 | + /** |
|
838 | + * @return bool |
|
839 | + * @throws EE_Error |
|
840 | + * @throws ReflectionException |
|
841 | + */ |
|
842 | + public function is_expired() |
|
843 | + { |
|
844 | + // check if event id is present and if this event is published |
|
845 | + if ($this->is_inactive()) { |
|
846 | + return false; |
|
847 | + } |
|
848 | + // set initial value |
|
849 | + $expired = false; |
|
850 | + // first let's get all datetimes and loop through them |
|
851 | + $datetimes = $this->datetimes_in_chronological_order(); |
|
852 | + foreach ($datetimes as $datetime) { |
|
853 | + if ($datetime instanceof EE_Datetime) { |
|
854 | + // if this dtt is upcoming or active then we return false. |
|
855 | + if ($datetime->is_upcoming() || $datetime->is_active()) { |
|
856 | + return false; |
|
857 | + } |
|
858 | + // otherwise let's check active status |
|
859 | + $expired = $datetime->is_expired(); |
|
860 | + } |
|
861 | + } |
|
862 | + return $expired; |
|
863 | + } |
|
864 | + |
|
865 | + |
|
866 | + /** |
|
867 | + * @return bool |
|
868 | + * @throws EE_Error |
|
869 | + */ |
|
870 | + public function is_inactive() |
|
871 | + { |
|
872 | + // check if event id is present and if this event is published |
|
873 | + if ($this->_has_ID_and_is_published()) { |
|
874 | + return false; |
|
875 | + } |
|
876 | + return true; |
|
877 | + } |
|
878 | + |
|
879 | + |
|
880 | + /** |
|
881 | + * calculate spaces remaining based on "saleable" tickets |
|
882 | + * |
|
883 | + * @param array $tickets |
|
884 | + * @param bool $filtered |
|
885 | + * @return int|float |
|
886 | + * @throws EE_Error |
|
887 | + * @throws DomainException |
|
888 | + * @throws UnexpectedEntityException |
|
889 | + */ |
|
890 | + public function spaces_remaining($tickets = array(), $filtered = true) |
|
891 | + { |
|
892 | + $this->getAvailableSpacesCalculator()->setActiveTickets($tickets); |
|
893 | + $spaces_remaining = $this->getAvailableSpacesCalculator()->spacesRemaining(); |
|
894 | + return $filtered |
|
895 | + ? apply_filters( |
|
896 | + 'FHEE_EE_Event__spaces_remaining', |
|
897 | + $spaces_remaining, |
|
898 | + $this, |
|
899 | + $tickets |
|
900 | + ) |
|
901 | + : $spaces_remaining; |
|
902 | + } |
|
903 | + |
|
904 | + |
|
905 | + /** |
|
906 | + * perform_sold_out_status_check |
|
907 | + * checks all of this events's datetime reg_limit - sold values to determine if ANY datetimes have spaces |
|
908 | + * available... if NOT, then the event status will get toggled to 'sold_out' |
|
909 | + * |
|
910 | + * @return bool return the ACTUAL sold out state. |
|
911 | + * @throws EE_Error |
|
912 | + * @throws DomainException |
|
913 | + * @throws UnexpectedEntityException |
|
914 | + * @throws ReflectionException |
|
915 | + */ |
|
916 | + public function perform_sold_out_status_check() |
|
917 | + { |
|
918 | + // get all tickets |
|
919 | + $tickets = $this->tickets( |
|
920 | + array( |
|
921 | + 'default_where_conditions' => 'none', |
|
922 | + 'order_by' => array('TKT_qty' => 'ASC'), |
|
923 | + ) |
|
924 | + ); |
|
925 | + $all_expired = true; |
|
926 | + foreach ($tickets as $ticket) { |
|
927 | + if (! $ticket->is_expired()) { |
|
928 | + $all_expired = false; |
|
929 | + break; |
|
930 | + } |
|
931 | + } |
|
932 | + // if all the tickets are just expired, then don't update the event status to sold out |
|
933 | + if ($all_expired) { |
|
934 | + return true; |
|
935 | + } |
|
936 | + $spaces_remaining = $this->spaces_remaining($tickets); |
|
937 | + if ($spaces_remaining < 1) { |
|
938 | + if ($this->status() !== EEM_Event::post_status_private) { |
|
939 | + $this->set_status(EEM_Event::sold_out); |
|
940 | + $this->save(); |
|
941 | + } |
|
942 | + $sold_out = true; |
|
943 | + } else { |
|
944 | + $sold_out = false; |
|
945 | + // was event previously marked as sold out ? |
|
946 | + if ($this->status() === EEM_Event::sold_out) { |
|
947 | + // revert status to previous value, if it was set |
|
948 | + $previous_event_status = $this->get_post_meta('_previous_event_status', true); |
|
949 | + if ($previous_event_status) { |
|
950 | + $this->set_status($previous_event_status); |
|
951 | + $this->save(); |
|
952 | + } |
|
953 | + } |
|
954 | + } |
|
955 | + do_action('AHEE__EE_Event__perform_sold_out_status_check__end', $this, $sold_out, $spaces_remaining, $tickets); |
|
956 | + return $sold_out; |
|
957 | + } |
|
958 | + |
|
959 | + |
|
960 | + /** |
|
961 | + * This returns the total remaining spaces for sale on this event. |
|
962 | + * |
|
963 | + * @uses EE_Event::total_available_spaces() |
|
964 | + * @return float|int |
|
965 | + * @throws EE_Error |
|
966 | + * @throws DomainException |
|
967 | + * @throws UnexpectedEntityException |
|
968 | + */ |
|
969 | + public function spaces_remaining_for_sale() |
|
970 | + { |
|
971 | + return $this->total_available_spaces(true); |
|
972 | + } |
|
973 | + |
|
974 | + |
|
975 | + /** |
|
976 | + * This returns the total spaces available for an event |
|
977 | + * while considering all the qtys on the tickets and the reg limits |
|
978 | + * on the datetimes attached to this event. |
|
979 | + * |
|
980 | + * @param bool $consider_sold Whether to consider any tickets that have already sold in our calculation. |
|
981 | + * If this is false, then we return the most tickets that could ever be sold |
|
982 | + * for this event with the datetime and tickets setup on the event under optimal |
|
983 | + * selling conditions. Otherwise we return a live calculation of spaces available |
|
984 | + * based on tickets sold. Depending on setup and stage of sales, this |
|
985 | + * may appear to equal remaining tickets. However, the more tickets are |
|
986 | + * sold out, the more accurate the "live" total is. |
|
987 | + * @return float|int |
|
988 | + * @throws EE_Error |
|
989 | + * @throws DomainException |
|
990 | + * @throws UnexpectedEntityException |
|
991 | + */ |
|
992 | + public function total_available_spaces($consider_sold = false) |
|
993 | + { |
|
994 | + $spaces_available = $consider_sold |
|
995 | + ? $this->getAvailableSpacesCalculator()->spacesRemaining() |
|
996 | + : $this->getAvailableSpacesCalculator()->totalSpacesAvailable(); |
|
997 | + return apply_filters( |
|
998 | + 'FHEE_EE_Event__total_available_spaces__spaces_available', |
|
999 | + $spaces_available, |
|
1000 | + $this, |
|
1001 | + $this->getAvailableSpacesCalculator()->getDatetimes(), |
|
1002 | + $this->getAvailableSpacesCalculator()->getActiveTickets() |
|
1003 | + ); |
|
1004 | + } |
|
1005 | + |
|
1006 | + |
|
1007 | + /** |
|
1008 | + * Checks if the event is set to sold out |
|
1009 | + * |
|
1010 | + * @param bool $actual whether or not to perform calculations to not only figure the |
|
1011 | + * actual status but also to flip the status if necessary to sold |
|
1012 | + * out If false, we just check the existing status of the event |
|
1013 | + * @return boolean |
|
1014 | + * @throws EE_Error |
|
1015 | + */ |
|
1016 | + public function is_sold_out($actual = false) |
|
1017 | + { |
|
1018 | + if (! $actual) { |
|
1019 | + return $this->status() === EEM_Event::sold_out; |
|
1020 | + } |
|
1021 | + return $this->perform_sold_out_status_check(); |
|
1022 | + } |
|
1023 | + |
|
1024 | + |
|
1025 | + /** |
|
1026 | + * Checks if the event is marked as postponed |
|
1027 | + * |
|
1028 | + * @return boolean |
|
1029 | + */ |
|
1030 | + public function is_postponed() |
|
1031 | + { |
|
1032 | + return $this->status() === EEM_Event::postponed; |
|
1033 | + } |
|
1034 | + |
|
1035 | + |
|
1036 | + /** |
|
1037 | + * Checks if the event is marked as cancelled |
|
1038 | + * |
|
1039 | + * @return boolean |
|
1040 | + */ |
|
1041 | + public function is_cancelled() |
|
1042 | + { |
|
1043 | + return $this->status() === EEM_Event::cancelled; |
|
1044 | + } |
|
1045 | + |
|
1046 | + |
|
1047 | + /** |
|
1048 | + * Get the logical active status in a hierarchical order for all the datetimes. Note |
|
1049 | + * Basically, we order the datetimes by EVT_start_date. Then first test on whether the event is published. If its |
|
1050 | + * NOT published then we test for whether its expired or not. IF it IS published then we test first on whether an |
|
1051 | + * event has any active dates. If no active dates then we check for any upcoming dates. If no upcoming dates then |
|
1052 | + * the event is considered expired. |
|
1053 | + * NOTE: this method does NOT calculate whether the datetimes are sold out when event is published. Sold Out is a |
|
1054 | + * status set on the EVENT when it is not published and thus is done |
|
1055 | + * |
|
1056 | + * @param bool $reset |
|
1057 | + * @return bool | string - based on EE_Datetime active constants or FALSE if error. |
|
1058 | + * @throws EE_Error |
|
1059 | + * @throws ReflectionException |
|
1060 | + */ |
|
1061 | + public function get_active_status($reset = false) |
|
1062 | + { |
|
1063 | + // if the active status has already been set, then just use that value (unless we are resetting it) |
|
1064 | + if (! empty($this->_active_status) && ! $reset) { |
|
1065 | + return $this->_active_status; |
|
1066 | + } |
|
1067 | + // first check if event id is present on this object |
|
1068 | + if (! $this->ID()) { |
|
1069 | + return false; |
|
1070 | + } |
|
1071 | + $where_params_for_event = array(array('EVT_ID' => $this->ID())); |
|
1072 | + // if event is published: |
|
1073 | + if ($this->status() === EEM_Event::post_status_publish || $this->status() === EEM_Event::post_status_private) { |
|
1074 | + // active? |
|
1075 | + if ( |
|
1076 | + EEM_Datetime::instance()->get_datetime_count_for_status( |
|
1077 | + EE_Datetime::active, |
|
1078 | + $where_params_for_event |
|
1079 | + ) > 0 |
|
1080 | + ) { |
|
1081 | + $this->_active_status = EE_Datetime::active; |
|
1082 | + } else { |
|
1083 | + // upcoming? |
|
1084 | + if ( |
|
1085 | + EEM_Datetime::instance()->get_datetime_count_for_status( |
|
1086 | + EE_Datetime::upcoming, |
|
1087 | + $where_params_for_event |
|
1088 | + ) > 0 |
|
1089 | + ) { |
|
1090 | + $this->_active_status = EE_Datetime::upcoming; |
|
1091 | + } else { |
|
1092 | + // expired? |
|
1093 | + if ( |
|
1094 | + EEM_Datetime::instance()->get_datetime_count_for_status( |
|
1095 | + EE_Datetime::expired, |
|
1096 | + $where_params_for_event |
|
1097 | + ) > 0 |
|
1098 | + ) { |
|
1099 | + $this->_active_status = EE_Datetime::expired; |
|
1100 | + } else { |
|
1101 | + // it would be odd if things make it this far because it basically means there are no datetime's |
|
1102 | + // attached to the event. So in this case it will just be considered inactive. |
|
1103 | + $this->_active_status = EE_Datetime::inactive; |
|
1104 | + } |
|
1105 | + } |
|
1106 | + } |
|
1107 | + } else { |
|
1108 | + // the event is not published, so let's just set it's active status according to its' post status |
|
1109 | + switch ($this->status()) { |
|
1110 | + case EEM_Event::sold_out: |
|
1111 | + $this->_active_status = EE_Datetime::sold_out; |
|
1112 | + break; |
|
1113 | + case EEM_Event::cancelled: |
|
1114 | + $this->_active_status = EE_Datetime::cancelled; |
|
1115 | + break; |
|
1116 | + case EEM_Event::postponed: |
|
1117 | + $this->_active_status = EE_Datetime::postponed; |
|
1118 | + break; |
|
1119 | + default: |
|
1120 | + $this->_active_status = EE_Datetime::inactive; |
|
1121 | + } |
|
1122 | + } |
|
1123 | + return $this->_active_status; |
|
1124 | + } |
|
1125 | + |
|
1126 | + |
|
1127 | + /** |
|
1128 | + * pretty_active_status |
|
1129 | + * |
|
1130 | + * @access public |
|
1131 | + * @param boolean $echo whether to return (FALSE), or echo out the result (TRUE) |
|
1132 | + * @return mixed void|string |
|
1133 | + * @throws EE_Error |
|
1134 | + * @throws ReflectionException |
|
1135 | + */ |
|
1136 | + public function pretty_active_status($echo = true) |
|
1137 | + { |
|
1138 | + $active_status = $this->get_active_status(); |
|
1139 | + $status = '<span class="ee-status event-active-status-' . esc_attr($active_status) . '">' |
|
1140 | + . EEH_Template::pretty_status($active_status, false, 'sentence') |
|
1141 | + . '</span>'; |
|
1142 | + if ($echo) { |
|
1143 | + echo wp_kses($status, AllowedTags::getAllowedTags()); |
|
1144 | + return ''; |
|
1145 | + } |
|
1146 | + return $status; // already escaped |
|
1147 | + } |
|
1148 | + |
|
1149 | + |
|
1150 | + /** |
|
1151 | + * @return bool|int |
|
1152 | + * @throws EE_Error |
|
1153 | + * @throws ReflectionException |
|
1154 | + */ |
|
1155 | + public function get_number_of_tickets_sold() |
|
1156 | + { |
|
1157 | + $tkt_sold = 0; |
|
1158 | + if (! $this->ID()) { |
|
1159 | + return 0; |
|
1160 | + } |
|
1161 | + $datetimes = $this->datetimes(); |
|
1162 | + foreach ($datetimes as $datetime) { |
|
1163 | + if ($datetime instanceof EE_Datetime) { |
|
1164 | + $tkt_sold += $datetime->sold(); |
|
1165 | + } |
|
1166 | + } |
|
1167 | + return $tkt_sold; |
|
1168 | + } |
|
1169 | + |
|
1170 | + |
|
1171 | + /** |
|
1172 | + * This just returns a count of all the registrations for this event |
|
1173 | + * |
|
1174 | + * @access public |
|
1175 | + * @return int |
|
1176 | + * @throws EE_Error |
|
1177 | + */ |
|
1178 | + public function get_count_of_all_registrations() |
|
1179 | + { |
|
1180 | + return EEM_Event::instance()->count_related($this, 'Registration'); |
|
1181 | + } |
|
1182 | + |
|
1183 | + |
|
1184 | + /** |
|
1185 | + * This returns the ticket with the earliest start time that is |
|
1186 | + * available for this event (across all datetimes attached to the event) |
|
1187 | + * |
|
1188 | + * @return EE_Base_Class|EE_Ticket|null |
|
1189 | + * @throws EE_Error |
|
1190 | + * @throws ReflectionException |
|
1191 | + */ |
|
1192 | + public function get_ticket_with_earliest_start_time() |
|
1193 | + { |
|
1194 | + $where['Datetime.EVT_ID'] = $this->ID(); |
|
1195 | + $query_params = array($where, 'order_by' => array('TKT_start_date' => 'ASC')); |
|
1196 | + return EE_Registry::instance()->load_model('Ticket')->get_one($query_params); |
|
1197 | + } |
|
1198 | + |
|
1199 | + |
|
1200 | + /** |
|
1201 | + * This returns the ticket with the latest end time that is available |
|
1202 | + * for this event (across all datetimes attached to the event) |
|
1203 | + * |
|
1204 | + * @return EE_Base_Class|EE_Ticket|null |
|
1205 | + * @throws EE_Error |
|
1206 | + * @throws ReflectionException |
|
1207 | + */ |
|
1208 | + public function get_ticket_with_latest_end_time() |
|
1209 | + { |
|
1210 | + $where['Datetime.EVT_ID'] = $this->ID(); |
|
1211 | + $query_params = array($where, 'order_by' => array('TKT_end_date' => 'DESC')); |
|
1212 | + return EE_Registry::instance()->load_model('Ticket')->get_one($query_params); |
|
1213 | + } |
|
1214 | + |
|
1215 | + |
|
1216 | + /** |
|
1217 | + * This returns the number of different ticket types currently on sale for this event. |
|
1218 | + * |
|
1219 | + * @return int |
|
1220 | + * @throws EE_Error |
|
1221 | + * @throws ReflectionException |
|
1222 | + */ |
|
1223 | + public function countTicketsOnSale() |
|
1224 | + { |
|
1225 | + $where = array( |
|
1226 | + 'Datetime.EVT_ID' => $this->ID(), |
|
1227 | + 'TKT_start_date' => array('<', time()), |
|
1228 | + 'TKT_end_date' => array('>', time()), |
|
1229 | + ); |
|
1230 | + return EEM_Ticket::instance()->count(array($where)); |
|
1231 | + } |
|
1232 | + |
|
1233 | + |
|
1234 | + /** |
|
1235 | + * This returns whether there are any tickets on sale for this event. |
|
1236 | + * |
|
1237 | + * @return bool true = YES tickets on sale. |
|
1238 | + * @throws EE_Error |
|
1239 | + */ |
|
1240 | + public function tickets_on_sale() |
|
1241 | + { |
|
1242 | + return $this->countTicketsOnSale() > 0; |
|
1243 | + } |
|
1244 | + |
|
1245 | + |
|
1246 | + /** |
|
1247 | + * Gets the URL for viewing this event on the front-end. Overrides parent |
|
1248 | + * to check for an external URL first |
|
1249 | + * |
|
1250 | + * @return string |
|
1251 | + * @throws EE_Error |
|
1252 | + */ |
|
1253 | + public function get_permalink() |
|
1254 | + { |
|
1255 | + if ($this->external_url()) { |
|
1256 | + return $this->external_url(); |
|
1257 | + } |
|
1258 | + return parent::get_permalink(); |
|
1259 | + } |
|
1260 | + |
|
1261 | + |
|
1262 | + /** |
|
1263 | + * Gets the first term for 'espresso_event_categories' we can find |
|
1264 | + * |
|
1265 | + * @param array $query_params @see |
|
1266 | + * https://github.com/eventespresso/event-espresso-core/tree/master/docs/G--Model-System/model-query-params.md |
|
1267 | + * @return EE_Base_Class|EE_Term|null |
|
1268 | + * @throws EE_Error |
|
1269 | + * @throws ReflectionException |
|
1270 | + */ |
|
1271 | + public function first_event_category($query_params = array()) |
|
1272 | + { |
|
1273 | + $query_params[0]['Term_Taxonomy.taxonomy'] = 'espresso_event_categories'; |
|
1274 | + $query_params[0]['Term_Taxonomy.Event.EVT_ID'] = $this->ID(); |
|
1275 | + return EEM_Term::instance()->get_one($query_params); |
|
1276 | + } |
|
1277 | + |
|
1278 | + |
|
1279 | + /** |
|
1280 | + * Gets all terms for 'espresso_event_categories' we can find |
|
1281 | + * |
|
1282 | + * @param array $query_params |
|
1283 | + * @return EE_Base_Class[]|EE_Term[] |
|
1284 | + * @throws EE_Error |
|
1285 | + * @throws ReflectionException |
|
1286 | + */ |
|
1287 | + public function get_all_event_categories($query_params = array()) |
|
1288 | + { |
|
1289 | + $query_params[0]['Term_Taxonomy.taxonomy'] = 'espresso_event_categories'; |
|
1290 | + $query_params[0]['Term_Taxonomy.Event.EVT_ID'] = $this->ID(); |
|
1291 | + return EEM_Term::instance()->get_all($query_params); |
|
1292 | + } |
|
1293 | + |
|
1294 | + |
|
1295 | + /** |
|
1296 | + * Adds a question group to this event |
|
1297 | + * |
|
1298 | + * @param EE_Question_Group|int $question_group_id_or_obj |
|
1299 | + * @param bool $for_primary if true, the question group will be added for the primary |
|
1300 | + * registrant, if false will be added for others. default: false |
|
1301 | + * @return EE_Base_Class|EE_Question_Group |
|
1302 | + * @throws EE_Error |
|
1303 | + * @throws InvalidArgumentException |
|
1304 | + * @throws InvalidDataTypeException |
|
1305 | + * @throws InvalidInterfaceException |
|
1306 | + * @throws ReflectionException |
|
1307 | + */ |
|
1308 | + public function add_question_group($question_group_id_or_obj, $for_primary = false) |
|
1309 | + { |
|
1310 | + // If the row already exists, it will be updated. If it doesn't, it will be inserted. |
|
1311 | + // That's in EE_HABTM_Relation::add_relation_to(). |
|
1312 | + return $this->_add_relation_to( |
|
1313 | + $question_group_id_or_obj, |
|
1314 | + 'Question_Group', |
|
1315 | + [ |
|
1316 | + EEM_Event_Question_Group::instance()->fieldNameForContext($for_primary) => true |
|
1317 | + ] |
|
1318 | + ); |
|
1319 | + } |
|
1320 | + |
|
1321 | + |
|
1322 | + /** |
|
1323 | + * Removes a question group from the event |
|
1324 | + * |
|
1325 | + * @param EE_Question_Group|int $question_group_id_or_obj |
|
1326 | + * @param bool $for_primary if true, the question group will be removed from the primary |
|
1327 | + * registrant, if false will be removed from others. default: false |
|
1328 | + * @return EE_Base_Class|EE_Question_Group |
|
1329 | + * @throws EE_Error |
|
1330 | + * @throws InvalidArgumentException |
|
1331 | + * @throws ReflectionException |
|
1332 | + * @throws InvalidDataTypeException |
|
1333 | + * @throws InvalidInterfaceException |
|
1334 | + */ |
|
1335 | + public function remove_question_group($question_group_id_or_obj, $for_primary = false) |
|
1336 | + { |
|
1337 | + // If the question group is used for the other type (primary or additional) |
|
1338 | + // then just update it. If not, delete it outright. |
|
1339 | + $existing_relation = $this->get_first_related( |
|
1340 | + 'Event_Question_Group', |
|
1341 | + [ |
|
1342 | + [ |
|
1343 | + 'QSG_ID' => EEM_Question_Group::instance()->ensure_is_ID($question_group_id_or_obj) |
|
1344 | + ] |
|
1345 | + ] |
|
1346 | + ); |
|
1347 | + $field_to_update = EEM_Event_Question_Group::instance()->fieldNameForContext($for_primary); |
|
1348 | + $other_field = EEM_Event_Question_Group::instance()->fieldNameForContext(! $for_primary); |
|
1349 | + if ($existing_relation->get($other_field) === false) { |
|
1350 | + // Delete it. It's now no longer for primary or additional question groups. |
|
1351 | + return $this->_remove_relation_to($question_group_id_or_obj, 'Question_Group'); |
|
1352 | + } |
|
1353 | + // Just update it. They'll still use this question group for the other category |
|
1354 | + $existing_relation->save( |
|
1355 | + [ |
|
1356 | + $field_to_update => false |
|
1357 | + ] |
|
1358 | + ); |
|
1359 | + } |
|
1360 | + |
|
1361 | + |
|
1362 | + /** |
|
1363 | + * Gets all the question groups, ordering them by QSG_order ascending |
|
1364 | + * |
|
1365 | + * @param array $query_params @see |
|
1366 | + * https://github.com/eventespresso/event-espresso-core/tree/master/docs/G--Model-System/model-query-params.md |
|
1367 | + * @return EE_Base_Class[]|EE_Question_Group[] |
|
1368 | + * @throws EE_Error |
|
1369 | + * @throws ReflectionException |
|
1370 | + */ |
|
1371 | + public function question_groups($query_params = array()) |
|
1372 | + { |
|
1373 | + $query_params = ! empty($query_params) ? $query_params : array('order_by' => array('QSG_order' => 'ASC')); |
|
1374 | + return $this->get_many_related('Question_Group', $query_params); |
|
1375 | + } |
|
1376 | + |
|
1377 | + |
|
1378 | + /** |
|
1379 | + * Implementation for EEI_Has_Icon interface method. |
|
1380 | + * |
|
1381 | + * @see EEI_Visual_Representation for comments |
|
1382 | + * @return string |
|
1383 | + */ |
|
1384 | + public function get_icon() |
|
1385 | + { |
|
1386 | + return '<span class="dashicons dashicons-flag"></span>'; |
|
1387 | + } |
|
1388 | + |
|
1389 | + |
|
1390 | + /** |
|
1391 | + * Implementation for EEI_Admin_Links interface method. |
|
1392 | + * |
|
1393 | + * @see EEI_Admin_Links for comments |
|
1394 | + * @return string |
|
1395 | + * @throws EE_Error |
|
1396 | + */ |
|
1397 | + public function get_admin_details_link() |
|
1398 | + { |
|
1399 | + return $this->get_admin_edit_link(); |
|
1400 | + } |
|
1401 | + |
|
1402 | + |
|
1403 | + /** |
|
1404 | + * Implementation for EEI_Admin_Links interface method. |
|
1405 | + * |
|
1406 | + * @return string |
|
1407 | + * @throws EE_Error*@throws ReflectionException |
|
1408 | + * @see EEI_Admin_Links for comments |
|
1409 | + */ |
|
1410 | + public function get_admin_edit_link() |
|
1411 | + { |
|
1412 | + return EEH_URL::add_query_args_and_nonce( |
|
1413 | + array( |
|
1414 | + 'page' => 'espresso_events', |
|
1415 | + 'action' => 'edit', |
|
1416 | + 'post' => $this->ID(), |
|
1417 | + ), |
|
1418 | + admin_url('admin.php') |
|
1419 | + ); |
|
1420 | + } |
|
1421 | + |
|
1422 | + |
|
1423 | + /** |
|
1424 | + * Implementation for EEI_Admin_Links interface method. |
|
1425 | + * |
|
1426 | + * @see EEI_Admin_Links for comments |
|
1427 | + * @return string |
|
1428 | + */ |
|
1429 | + public function get_admin_settings_link() |
|
1430 | + { |
|
1431 | + return EEH_URL::add_query_args_and_nonce( |
|
1432 | + array( |
|
1433 | + 'page' => 'espresso_events', |
|
1434 | + 'action' => 'default_event_settings', |
|
1435 | + ), |
|
1436 | + admin_url('admin.php') |
|
1437 | + ); |
|
1438 | + } |
|
1439 | + |
|
1440 | + |
|
1441 | + /** |
|
1442 | + * Implementation for EEI_Admin_Links interface method. |
|
1443 | + * |
|
1444 | + * @see EEI_Admin_Links for comments |
|
1445 | + * @return string |
|
1446 | + */ |
|
1447 | + public function get_admin_overview_link() |
|
1448 | + { |
|
1449 | + return EEH_URL::add_query_args_and_nonce( |
|
1450 | + array( |
|
1451 | + 'page' => 'espresso_events', |
|
1452 | + 'action' => 'default', |
|
1453 | + ), |
|
1454 | + admin_url('admin.php') |
|
1455 | + ); |
|
1456 | + } |
|
1457 | 1457 | } |
@@ -49,7 +49,7 @@ discard block |
||
49 | 49 | new DateTimeZone($timezone_string); |
50 | 50 | } catch (Exception $e) { |
51 | 51 | // sometimes we take exception to exceptions |
52 | - if (! $throw_error) { |
|
52 | + if ( ! $throw_error) { |
|
53 | 53 | return false; |
54 | 54 | } |
55 | 55 | throw new EE_Error( |
@@ -101,7 +101,7 @@ discard block |
||
101 | 101 | public function getTimezoneOffset(DateTimeZone $date_time_zone, $time = null) |
102 | 102 | { |
103 | 103 | $transition = $this->getTimezoneTransitions($date_time_zone, $time); |
104 | - if (! isset($transition['offset'])) { |
|
104 | + if ( ! isset($transition['offset'])) { |
|
105 | 105 | throw new DomainException( |
106 | 106 | sprintf( |
107 | 107 | esc_html__('An invalid timezone transition was received %1$s', 'event_espresso'), |
@@ -123,7 +123,7 @@ discard block |
||
123 | 123 | public function timezoneSelectInput($timezone_string = '') |
124 | 124 | { |
125 | 125 | // get WP date time format |
126 | - $datetime_format = get_option('date_format') . ' ' . get_option('time_format'); |
|
126 | + $datetime_format = get_option('date_format').' '.get_option('time_format'); |
|
127 | 127 | // if passed a value, then use that, else get WP option |
128 | 128 | $timezone_string = ! empty($timezone_string) ? $timezone_string : (string) get_option('timezone_string'); |
129 | 129 | // check if the timezone is valid but don't throw any errors if it isn't |
@@ -137,9 +137,9 @@ discard block |
||
137 | 137 | $timezone_string = 'UTC'; |
138 | 138 | $check_zone_info = false; |
139 | 139 | if ($gmt_offset > 0) { |
140 | - $timezone_string = 'UTC+' . $gmt_offset; |
|
140 | + $timezone_string = 'UTC+'.$gmt_offset; |
|
141 | 141 | } elseif ($gmt_offset < 0) { |
142 | - $timezone_string = 'UTC' . $gmt_offset; |
|
142 | + $timezone_string = 'UTC'.$gmt_offset; |
|
143 | 143 | } |
144 | 144 | } |
145 | 145 | ?> |
@@ -159,12 +159,12 @@ discard block |
||
159 | 159 | esc_html__('%1$sUTC%2$s time is %3$s', 'event_espresso'), |
160 | 160 | '<abbr title="Coordinated Universal Time">', |
161 | 161 | '</abbr>', |
162 | - '<code>' . date_i18n($datetime_format, false, true) . '</code>' |
|
162 | + '<code>'.date_i18n($datetime_format, false, true).'</code>' |
|
163 | 163 | ); |
164 | 164 | ?></span> |
165 | 165 | <?php |
166 | - if (! empty($timezone_string) || ! empty($gmt_offset)) : ?> |
|
167 | - <br/><span><?php printf(esc_html__('Local time is %1$s', 'event_espresso'), '<code>' . date_i18n($datetime_format) . '</code>'); ?></span> |
|
166 | + if ( ! empty($timezone_string) || ! empty($gmt_offset)) : ?> |
|
167 | + <br/><span><?php printf(esc_html__('Local time is %1$s', 'event_espresso'), '<code>'.date_i18n($datetime_format).'</code>'); ?></span> |
|
168 | 168 | <?php |
169 | 169 | endif; ?> |
170 | 170 | |
@@ -204,7 +204,7 @@ discard block |
||
204 | 204 | // transition time from date_i18n(). |
205 | 205 | printf( |
206 | 206 | $message, |
207 | - '<code >' . date_i18n($datetime_format, $tr['ts'] + ($tz_offset - $tr['offset'])) . '</code >' |
|
207 | + '<code >'.date_i18n($datetime_format, $tr['ts'] + ($tz_offset - $tr['offset'])).'</code >' |
|
208 | 208 | ); |
209 | 209 | } else { |
210 | 210 | esc_html_e('This timezone does not observe daylight saving time.', 'event_espresso'); |
@@ -237,7 +237,7 @@ discard block |
||
237 | 237 | $unix_timestamp = $unix_timestamp === 0 ? time() : (int) $unix_timestamp; |
238 | 238 | $timezone_string = $this->getValidTimezoneString($timezone_string); |
239 | 239 | $TimeZone = new DateTimeZone($timezone_string); |
240 | - $DateTime = new DateTime('@' . $unix_timestamp, $TimeZone); |
|
240 | + $DateTime = new DateTime('@'.$unix_timestamp, $TimeZone); |
|
241 | 241 | $offset = timezone_offset_get($TimeZone, $DateTime); |
242 | 242 | return (int) $DateTime->format('U') + (int) $offset; |
243 | 243 | } |
@@ -11,136 +11,136 @@ discard block |
||
11 | 11 | |
12 | 12 | abstract class AbstractHelper implements HelperInterface |
13 | 13 | { |
14 | - /** |
|
15 | - * Ensures that a valid timezone string is returned. |
|
16 | - * |
|
17 | - * @param string $timezone_string When not provided then attempt to use the timezone_string set in the WP Time |
|
18 | - * settings (or derive from set UTC offset). |
|
19 | - * @return string |
|
20 | - * @throws EE_Error |
|
21 | - */ |
|
22 | - public function getValidTimezoneString($timezone_string = '') |
|
23 | - { |
|
24 | - $timezone_string = ! empty($timezone_string) ? $timezone_string : (string) get_option('timezone_string'); |
|
25 | - $timezone_string = ! empty($timezone_string) |
|
26 | - ? $timezone_string |
|
27 | - : $this->getTimezoneStringFromGmtOffset(); |
|
28 | - $this->validateTimezone($timezone_string); |
|
29 | - return $timezone_string; |
|
30 | - } |
|
14 | + /** |
|
15 | + * Ensures that a valid timezone string is returned. |
|
16 | + * |
|
17 | + * @param string $timezone_string When not provided then attempt to use the timezone_string set in the WP Time |
|
18 | + * settings (or derive from set UTC offset). |
|
19 | + * @return string |
|
20 | + * @throws EE_Error |
|
21 | + */ |
|
22 | + public function getValidTimezoneString($timezone_string = '') |
|
23 | + { |
|
24 | + $timezone_string = ! empty($timezone_string) ? $timezone_string : (string) get_option('timezone_string'); |
|
25 | + $timezone_string = ! empty($timezone_string) |
|
26 | + ? $timezone_string |
|
27 | + : $this->getTimezoneStringFromGmtOffset(); |
|
28 | + $this->validateTimezone($timezone_string); |
|
29 | + return $timezone_string; |
|
30 | + } |
|
31 | 31 | |
32 | 32 | |
33 | 33 | |
34 | - /** |
|
35 | - * The only purpose for this static method is to validate that the incoming timezone is a valid php timezone. |
|
36 | - * |
|
37 | - * @param string $timezone_string |
|
38 | - * @param bool $throw_error |
|
39 | - * @return bool |
|
40 | - * @throws EE_Error |
|
41 | - */ |
|
42 | - public function validateTimezone($timezone_string, $throw_error = true) |
|
43 | - { |
|
44 | - // easiest way to test a timezone string is just see if it throws an error when you try to create a |
|
45 | - // DateTimeZone object with it |
|
46 | - try { |
|
47 | - new DateTimeZone($timezone_string); |
|
48 | - } catch (Exception $e) { |
|
49 | - // sometimes we take exception to exceptions |
|
50 | - if (! $throw_error) { |
|
51 | - return false; |
|
52 | - } |
|
53 | - throw new EE_Error( |
|
54 | - sprintf( |
|
55 | - esc_html__( |
|
56 | - 'The timezone given (%1$s), is invalid, please check with %2$sthis list%3$s for what valid timezones can be used', |
|
57 | - 'event_espresso' |
|
58 | - ), |
|
59 | - $timezone_string, |
|
60 | - '<a href="http://www.php.net/manual/en/timezones.php">', |
|
61 | - '</a>' |
|
62 | - ) |
|
63 | - ); |
|
64 | - } |
|
65 | - return true; |
|
66 | - } |
|
34 | + /** |
|
35 | + * The only purpose for this static method is to validate that the incoming timezone is a valid php timezone. |
|
36 | + * |
|
37 | + * @param string $timezone_string |
|
38 | + * @param bool $throw_error |
|
39 | + * @return bool |
|
40 | + * @throws EE_Error |
|
41 | + */ |
|
42 | + public function validateTimezone($timezone_string, $throw_error = true) |
|
43 | + { |
|
44 | + // easiest way to test a timezone string is just see if it throws an error when you try to create a |
|
45 | + // DateTimeZone object with it |
|
46 | + try { |
|
47 | + new DateTimeZone($timezone_string); |
|
48 | + } catch (Exception $e) { |
|
49 | + // sometimes we take exception to exceptions |
|
50 | + if (! $throw_error) { |
|
51 | + return false; |
|
52 | + } |
|
53 | + throw new EE_Error( |
|
54 | + sprintf( |
|
55 | + esc_html__( |
|
56 | + 'The timezone given (%1$s), is invalid, please check with %2$sthis list%3$s for what valid timezones can be used', |
|
57 | + 'event_espresso' |
|
58 | + ), |
|
59 | + $timezone_string, |
|
60 | + '<a href="http://www.php.net/manual/en/timezones.php">', |
|
61 | + '</a>' |
|
62 | + ) |
|
63 | + ); |
|
64 | + } |
|
65 | + return true; |
|
66 | + } |
|
67 | 67 | |
68 | 68 | |
69 | - /** |
|
70 | - * Gets the site's GMT offset based on either the timezone string |
|
71 | - * (in which case the gmt offset will vary depending on the location's |
|
72 | - * observance of daylight savings time) or the gmt_offset wp option |
|
73 | - * |
|
74 | - * @return int seconds offset |
|
75 | - */ |
|
76 | - public function getSiteTimezoneGmtOffset() |
|
77 | - { |
|
78 | - $timezone_string = (string) get_option('timezone_string'); |
|
79 | - if ($timezone_string) { |
|
80 | - try { |
|
81 | - $timezone = new DateTimeZone($timezone_string); |
|
82 | - return $timezone->getOffset(new DateTime()); // in WordPress DateTime defaults to UTC |
|
83 | - } catch (Exception $e) { |
|
84 | - } |
|
85 | - } |
|
86 | - $offset = get_option('gmt_offset'); |
|
87 | - return (int) ($offset * HOUR_IN_SECONDS); |
|
88 | - } |
|
69 | + /** |
|
70 | + * Gets the site's GMT offset based on either the timezone string |
|
71 | + * (in which case the gmt offset will vary depending on the location's |
|
72 | + * observance of daylight savings time) or the gmt_offset wp option |
|
73 | + * |
|
74 | + * @return int seconds offset |
|
75 | + */ |
|
76 | + public function getSiteTimezoneGmtOffset() |
|
77 | + { |
|
78 | + $timezone_string = (string) get_option('timezone_string'); |
|
79 | + if ($timezone_string) { |
|
80 | + try { |
|
81 | + $timezone = new DateTimeZone($timezone_string); |
|
82 | + return $timezone->getOffset(new DateTime()); // in WordPress DateTime defaults to UTC |
|
83 | + } catch (Exception $e) { |
|
84 | + } |
|
85 | + } |
|
86 | + $offset = get_option('gmt_offset'); |
|
87 | + return (int) ($offset * HOUR_IN_SECONDS); |
|
88 | + } |
|
89 | 89 | |
90 | 90 | |
91 | - /** |
|
92 | - * Get Timezone offset for given timezone object |
|
93 | - * |
|
94 | - * @param DateTimeZone $date_time_zone |
|
95 | - * @param null|int $time |
|
96 | - * @return int |
|
97 | - * @throws DomainException |
|
98 | - */ |
|
99 | - public function getTimezoneOffset(DateTimeZone $date_time_zone, $time = null) |
|
100 | - { |
|
101 | - $transition = $this->getTimezoneTransitions($date_time_zone, $time); |
|
102 | - if (! isset($transition['offset'])) { |
|
103 | - throw new DomainException( |
|
104 | - sprintf( |
|
105 | - esc_html__('An invalid timezone transition was received %1$s', 'event_espresso'), |
|
106 | - print_r($transition, true) |
|
107 | - ) |
|
108 | - ); |
|
109 | - } |
|
110 | - return $transition['offset']; |
|
111 | - } |
|
91 | + /** |
|
92 | + * Get Timezone offset for given timezone object |
|
93 | + * |
|
94 | + * @param DateTimeZone $date_time_zone |
|
95 | + * @param null|int $time |
|
96 | + * @return int |
|
97 | + * @throws DomainException |
|
98 | + */ |
|
99 | + public function getTimezoneOffset(DateTimeZone $date_time_zone, $time = null) |
|
100 | + { |
|
101 | + $transition = $this->getTimezoneTransitions($date_time_zone, $time); |
|
102 | + if (! isset($transition['offset'])) { |
|
103 | + throw new DomainException( |
|
104 | + sprintf( |
|
105 | + esc_html__('An invalid timezone transition was received %1$s', 'event_espresso'), |
|
106 | + print_r($transition, true) |
|
107 | + ) |
|
108 | + ); |
|
109 | + } |
|
110 | + return $transition['offset']; |
|
111 | + } |
|
112 | 112 | |
113 | 113 | |
114 | - /** |
|
115 | - * Provide a timezone select input |
|
116 | - * |
|
117 | - * @param string $timezone_string |
|
118 | - * @return string |
|
119 | - * @throws EE_Error |
|
120 | - */ |
|
121 | - public function timezoneSelectInput($timezone_string = '') |
|
122 | - { |
|
123 | - // get WP date time format |
|
124 | - $datetime_format = get_option('date_format') . ' ' . get_option('time_format'); |
|
125 | - // if passed a value, then use that, else get WP option |
|
126 | - $timezone_string = ! empty($timezone_string) ? $timezone_string : (string) get_option('timezone_string'); |
|
127 | - // check if the timezone is valid but don't throw any errors if it isn't |
|
128 | - $timezone_string = $this->validateTimezone($timezone_string, false) |
|
129 | - ? $timezone_string |
|
130 | - : ''; |
|
131 | - $gmt_offset = get_option('gmt_offset'); |
|
132 | - $check_zone_info = true; |
|
133 | - if (empty($timezone_string)) { |
|
134 | - // Create a UTC+- zone if no timezone string exists |
|
135 | - $timezone_string = 'UTC'; |
|
136 | - $check_zone_info = false; |
|
137 | - if ($gmt_offset > 0) { |
|
138 | - $timezone_string = 'UTC+' . $gmt_offset; |
|
139 | - } elseif ($gmt_offset < 0) { |
|
140 | - $timezone_string = 'UTC' . $gmt_offset; |
|
141 | - } |
|
142 | - } |
|
143 | - ?> |
|
114 | + /** |
|
115 | + * Provide a timezone select input |
|
116 | + * |
|
117 | + * @param string $timezone_string |
|
118 | + * @return string |
|
119 | + * @throws EE_Error |
|
120 | + */ |
|
121 | + public function timezoneSelectInput($timezone_string = '') |
|
122 | + { |
|
123 | + // get WP date time format |
|
124 | + $datetime_format = get_option('date_format') . ' ' . get_option('time_format'); |
|
125 | + // if passed a value, then use that, else get WP option |
|
126 | + $timezone_string = ! empty($timezone_string) ? $timezone_string : (string) get_option('timezone_string'); |
|
127 | + // check if the timezone is valid but don't throw any errors if it isn't |
|
128 | + $timezone_string = $this->validateTimezone($timezone_string, false) |
|
129 | + ? $timezone_string |
|
130 | + : ''; |
|
131 | + $gmt_offset = get_option('gmt_offset'); |
|
132 | + $check_zone_info = true; |
|
133 | + if (empty($timezone_string)) { |
|
134 | + // Create a UTC+- zone if no timezone string exists |
|
135 | + $timezone_string = 'UTC'; |
|
136 | + $check_zone_info = false; |
|
137 | + if ($gmt_offset > 0) { |
|
138 | + $timezone_string = 'UTC+' . $gmt_offset; |
|
139 | + } elseif ($gmt_offset < 0) { |
|
140 | + $timezone_string = 'UTC' . $gmt_offset; |
|
141 | + } |
|
142 | + } |
|
143 | + ?> |
|
144 | 144 | <p> |
145 | 145 | <label for="timezone_string"><?php esc_html_e('timezone', 'event_espresso'); ?></label> |
146 | 146 | <select id="timezone_string" name="timezone_string"> |
@@ -153,150 +153,150 @@ discard block |
||
153 | 153 | <p> |
154 | 154 | <span> |
155 | 155 | <?php |
156 | - printf( |
|
157 | - esc_html__('%1$sUTC%2$s time is %3$s', 'event_espresso'), |
|
158 | - '<abbr title="Coordinated Universal Time">', |
|
159 | - '</abbr>', |
|
160 | - '<code>' . date_i18n($datetime_format, false, true) . '</code>' |
|
161 | - ); |
|
162 | - ?></span> |
|
156 | + printf( |
|
157 | + esc_html__('%1$sUTC%2$s time is %3$s', 'event_espresso'), |
|
158 | + '<abbr title="Coordinated Universal Time">', |
|
159 | + '</abbr>', |
|
160 | + '<code>' . date_i18n($datetime_format, false, true) . '</code>' |
|
161 | + ); |
|
162 | + ?></span> |
|
163 | 163 | <?php |
164 | - if (! empty($timezone_string) || ! empty($gmt_offset)) : ?> |
|
164 | + if (! empty($timezone_string) || ! empty($gmt_offset)) : ?> |
|
165 | 165 | <br/><span><?php printf(esc_html__('Local time is %1$s', 'event_espresso'), '<code>' . date_i18n($datetime_format) . '</code>'); ?></span> |
166 | 166 | <?php |
167 | - endif; ?> |
|
167 | + endif; ?> |
|
168 | 168 | |
169 | 169 | <?php |
170 | - if ($check_zone_info && $timezone_string) : ?> |
|
170 | + if ($check_zone_info && $timezone_string) : ?> |
|
171 | 171 | <br/> |
172 | 172 | <span> |
173 | 173 | <?php |
174 | - // Set TZ so localtime works. |
|
175 | - date_default_timezone_set($timezone_string); |
|
176 | - $now = localtime(time(), true); |
|
177 | - if ($now['tm_isdst']) { |
|
178 | - esc_html_e('This timezone is currently in daylight saving time.', 'event_espresso'); |
|
179 | - } else { |
|
180 | - esc_html_e('This timezone is currently in standard time.', 'event_espresso'); |
|
181 | - } |
|
182 | - ?> |
|
174 | + // Set TZ so localtime works. |
|
175 | + date_default_timezone_set($timezone_string); |
|
176 | + $now = localtime(time(), true); |
|
177 | + if ($now['tm_isdst']) { |
|
178 | + esc_html_e('This timezone is currently in daylight saving time.', 'event_espresso'); |
|
179 | + } else { |
|
180 | + esc_html_e('This timezone is currently in standard time.', 'event_espresso'); |
|
181 | + } |
|
182 | + ?> |
|
183 | 183 | <br/> |
184 | 184 | <?php |
185 | - if (function_exists('timezone_transitions_get')) { |
|
186 | - $found = false; |
|
187 | - $date_time_zone_selected = new DateTimeZone($timezone_string); |
|
188 | - $tz_offset = timezone_offset_get($date_time_zone_selected, date_create()); |
|
189 | - $right_now = time(); |
|
190 | - $tr['isdst'] = false; |
|
191 | - foreach (timezone_transitions_get($date_time_zone_selected) as $tr) { |
|
192 | - if ($tr['ts'] > $right_now) { |
|
193 | - $found = true; |
|
194 | - break; |
|
195 | - } |
|
196 | - } |
|
197 | - if ($found) { |
|
198 | - $message = $tr['isdst'] |
|
199 | - ? esc_html__(' Daylight saving time begins on: %s.', 'event_espresso') |
|
200 | - : esc_html__(' Standard time begins on: %s.', 'event_espresso'); |
|
201 | - // Add the difference between the current offset and the new offset to ts to get the correct |
|
202 | - // transition time from date_i18n(). |
|
203 | - printf( |
|
204 | - $message, |
|
205 | - '<code >' . date_i18n($datetime_format, $tr['ts'] + ($tz_offset - $tr['offset'])) . '</code >' |
|
206 | - ); |
|
207 | - } else { |
|
208 | - esc_html_e('This timezone does not observe daylight saving time.', 'event_espresso'); |
|
209 | - } |
|
210 | - } |
|
211 | - // Set back to UTC. |
|
212 | - date_default_timezone_set('UTC'); |
|
213 | - ?> |
|
185 | + if (function_exists('timezone_transitions_get')) { |
|
186 | + $found = false; |
|
187 | + $date_time_zone_selected = new DateTimeZone($timezone_string); |
|
188 | + $tz_offset = timezone_offset_get($date_time_zone_selected, date_create()); |
|
189 | + $right_now = time(); |
|
190 | + $tr['isdst'] = false; |
|
191 | + foreach (timezone_transitions_get($date_time_zone_selected) as $tr) { |
|
192 | + if ($tr['ts'] > $right_now) { |
|
193 | + $found = true; |
|
194 | + break; |
|
195 | + } |
|
196 | + } |
|
197 | + if ($found) { |
|
198 | + $message = $tr['isdst'] |
|
199 | + ? esc_html__(' Daylight saving time begins on: %s.', 'event_espresso') |
|
200 | + : esc_html__(' Standard time begins on: %s.', 'event_espresso'); |
|
201 | + // Add the difference between the current offset and the new offset to ts to get the correct |
|
202 | + // transition time from date_i18n(). |
|
203 | + printf( |
|
204 | + $message, |
|
205 | + '<code >' . date_i18n($datetime_format, $tr['ts'] + ($tz_offset - $tr['offset'])) . '</code >' |
|
206 | + ); |
|
207 | + } else { |
|
208 | + esc_html_e('This timezone does not observe daylight saving time.', 'event_espresso'); |
|
209 | + } |
|
210 | + } |
|
211 | + // Set back to UTC. |
|
212 | + date_default_timezone_set('UTC'); |
|
213 | + ?> |
|
214 | 214 | </span></p> |
215 | 215 | <?php |
216 | - endif; |
|
217 | - } |
|
216 | + endif; |
|
217 | + } |
|
218 | 218 | |
219 | 219 | |
220 | - /** |
|
221 | - * This method will take an incoming unix timestamp and add the offset to it for the given timezone_string. |
|
222 | - * If no unix timestamp is given then time() is used. If no timezone is given then the set timezone string for |
|
223 | - * the site is used. |
|
224 | - * This is used typically when using a Unix timestamp any core WP functions that expect their specially |
|
225 | - * computed timestamp (i.e. date_i18n() ) |
|
226 | - * |
|
227 | - * @param int $unix_timestamp if 0, then time() will be used. |
|
228 | - * @param string $timezone_string timezone_string. If empty, then the current set timezone for the |
|
229 | - * site will be used. |
|
230 | - * @return int unix_timestamp value with the offset applied for the given timezone. |
|
231 | - * @throws EE_Error |
|
232 | - */ |
|
233 | - public function getTimestampWithOffset($unix_timestamp = 0, $timezone_string = '') |
|
234 | - { |
|
235 | - $unix_timestamp = $unix_timestamp === 0 ? time() : (int) $unix_timestamp; |
|
236 | - $timezone_string = $this->getValidTimezoneString($timezone_string); |
|
237 | - $TimeZone = new DateTimeZone($timezone_string); |
|
238 | - $DateTime = new DateTime('@' . $unix_timestamp, $TimeZone); |
|
239 | - $offset = timezone_offset_get($TimeZone, $DateTime); |
|
240 | - return (int) $DateTime->format('U') + (int) $offset; |
|
241 | - } |
|
220 | + /** |
|
221 | + * This method will take an incoming unix timestamp and add the offset to it for the given timezone_string. |
|
222 | + * If no unix timestamp is given then time() is used. If no timezone is given then the set timezone string for |
|
223 | + * the site is used. |
|
224 | + * This is used typically when using a Unix timestamp any core WP functions that expect their specially |
|
225 | + * computed timestamp (i.e. date_i18n() ) |
|
226 | + * |
|
227 | + * @param int $unix_timestamp if 0, then time() will be used. |
|
228 | + * @param string $timezone_string timezone_string. If empty, then the current set timezone for the |
|
229 | + * site will be used. |
|
230 | + * @return int unix_timestamp value with the offset applied for the given timezone. |
|
231 | + * @throws EE_Error |
|
232 | + */ |
|
233 | + public function getTimestampWithOffset($unix_timestamp = 0, $timezone_string = '') |
|
234 | + { |
|
235 | + $unix_timestamp = $unix_timestamp === 0 ? time() : (int) $unix_timestamp; |
|
236 | + $timezone_string = $this->getValidTimezoneString($timezone_string); |
|
237 | + $TimeZone = new DateTimeZone($timezone_string); |
|
238 | + $DateTime = new DateTime('@' . $unix_timestamp, $TimeZone); |
|
239 | + $offset = timezone_offset_get($TimeZone, $DateTime); |
|
240 | + return (int) $DateTime->format('U') + (int) $offset; |
|
241 | + } |
|
242 | 242 | |
243 | 243 | |
244 | - /** |
|
245 | - * Get Timezone Transitions |
|
246 | - * |
|
247 | - * @param DateTimeZone $date_time_zone |
|
248 | - * @param int|null $time |
|
249 | - * @param bool $first_only |
|
250 | - * @return array|mixed |
|
251 | - */ |
|
252 | - public function getTimezoneTransitions(DateTimeZone $date_time_zone, $time = null, $first_only = true) |
|
253 | - { |
|
254 | - $time = is_int($time) || $time === null ? $time : (int) strtotime($time); |
|
255 | - $time = preg_match(EE_Datetime_Field::unix_timestamp_regex, $time) ? $time : time(); |
|
256 | - $transitions = $date_time_zone->getTransitions($time); |
|
257 | - return $first_only && ! isset($transitions['ts']) ? reset($transitions) : $transitions; |
|
258 | - } |
|
244 | + /** |
|
245 | + * Get Timezone Transitions |
|
246 | + * |
|
247 | + * @param DateTimeZone $date_time_zone |
|
248 | + * @param int|null $time |
|
249 | + * @param bool $first_only |
|
250 | + * @return array|mixed |
|
251 | + */ |
|
252 | + public function getTimezoneTransitions(DateTimeZone $date_time_zone, $time = null, $first_only = true) |
|
253 | + { |
|
254 | + $time = is_int($time) || $time === null ? $time : (int) strtotime($time); |
|
255 | + $time = preg_match(EE_Datetime_Field::unix_timestamp_regex, $time) ? $time : time(); |
|
256 | + $transitions = $date_time_zone->getTransitions($time); |
|
257 | + return $first_only && ! isset($transitions['ts']) ? reset($transitions) : $transitions; |
|
258 | + } |
|
259 | 259 | |
260 | 260 | |
261 | 261 | |
262 | - /** |
|
263 | - * Default to just returning the provided $gmt_offset. Children can override if adjustment needed. |
|
264 | - * |
|
265 | - * @param int $gmt_offset |
|
266 | - * @return int |
|
267 | - */ |
|
268 | - public function adjustInvalidGmtOffsets($gmt_offset = 0) |
|
269 | - { |
|
270 | - return $gmt_offset; |
|
271 | - } |
|
262 | + /** |
|
263 | + * Default to just returning the provided $gmt_offset. Children can override if adjustment needed. |
|
264 | + * |
|
265 | + * @param int $gmt_offset |
|
266 | + * @return int |
|
267 | + */ |
|
268 | + public function adjustInvalidGmtOffsets($gmt_offset = 0) |
|
269 | + { |
|
270 | + return $gmt_offset; |
|
271 | + } |
|
272 | 272 | |
273 | 273 | |
274 | 274 | |
275 | - /** |
|
276 | - * This receives an incoming gmt_offset and santizes it. If the provide value is an empty string, then this will |
|
277 | - * attempt to get the offset from the timezone string. If this returns a string, then a timezone string was |
|
278 | - * successfully derived from existing timezone_string in the db. If not, then a float is returned for the provided |
|
279 | - * offset. |
|
280 | - * @param float|string $gmt_offset |
|
281 | - * @return float|string |
|
282 | - */ |
|
283 | - protected function sanitizeInitialIncomingGmtOffsetForGettingTimezoneString($gmt_offset) |
|
284 | - { |
|
285 | - // if there is no incoming gmt_offset, then because WP hooks in on timezone_string, we need to see if that is |
|
286 | - // set because it will override `gmt_offset` via `pre_get_option` filter. If that's set, then let's just use |
|
287 | - // that! Otherwise we'll leave timezone_string at the default of 'UTC' before doing other logic. |
|
288 | - if ($gmt_offset === '') { |
|
289 | - // autoloaded so no need to set to a variable. There will not be multiple hits to the db. |
|
290 | - if (get_option('timezone_string')) { |
|
291 | - return (string) get_option('timezone_string'); |
|
292 | - } |
|
293 | - } |
|
294 | - $gmt_offset = $gmt_offset !== '' ? $gmt_offset : (string) get_option('gmt_offset'); |
|
295 | - $gmt_offset = (float) $gmt_offset; |
|
296 | - // if $gmt_offset is 0 or is still an empty string, then just return UTC |
|
297 | - if ($gmt_offset === (float) 0) { |
|
298 | - return 'UTC'; |
|
299 | - } |
|
300 | - return $gmt_offset; |
|
301 | - } |
|
275 | + /** |
|
276 | + * This receives an incoming gmt_offset and santizes it. If the provide value is an empty string, then this will |
|
277 | + * attempt to get the offset from the timezone string. If this returns a string, then a timezone string was |
|
278 | + * successfully derived from existing timezone_string in the db. If not, then a float is returned for the provided |
|
279 | + * offset. |
|
280 | + * @param float|string $gmt_offset |
|
281 | + * @return float|string |
|
282 | + */ |
|
283 | + protected function sanitizeInitialIncomingGmtOffsetForGettingTimezoneString($gmt_offset) |
|
284 | + { |
|
285 | + // if there is no incoming gmt_offset, then because WP hooks in on timezone_string, we need to see if that is |
|
286 | + // set because it will override `gmt_offset` via `pre_get_option` filter. If that's set, then let's just use |
|
287 | + // that! Otherwise we'll leave timezone_string at the default of 'UTC' before doing other logic. |
|
288 | + if ($gmt_offset === '') { |
|
289 | + // autoloaded so no need to set to a variable. There will not be multiple hits to the db. |
|
290 | + if (get_option('timezone_string')) { |
|
291 | + return (string) get_option('timezone_string'); |
|
292 | + } |
|
293 | + } |
|
294 | + $gmt_offset = $gmt_offset !== '' ? $gmt_offset : (string) get_option('gmt_offset'); |
|
295 | + $gmt_offset = (float) $gmt_offset; |
|
296 | + // if $gmt_offset is 0 or is still an empty string, then just return UTC |
|
297 | + if ($gmt_offset === (float) 0) { |
|
298 | + return 'UTC'; |
|
299 | + } |
|
300 | + return $gmt_offset; |
|
301 | + } |
|
302 | 302 | } |
@@ -121,7 +121,7 @@ discard block |
||
121 | 121 | */ |
122 | 122 | protected function setId($id = '') |
123 | 123 | { |
124 | - if (! is_string($id)) { |
|
124 | + if ( ! is_string($id)) { |
|
125 | 125 | throw new InvalidDataTypeException('$id', $id, 'string'); |
126 | 126 | } |
127 | 127 | $this->id = $id; |
@@ -144,7 +144,7 @@ discard block |
||
144 | 144 | */ |
145 | 145 | protected function setOrder($order = 0) |
146 | 146 | { |
147 | - if (! is_int($order)) { |
|
147 | + if ( ! is_int($order)) { |
|
148 | 148 | throw new InvalidDataTypeException('$order', $order, 'integer'); |
149 | 149 | } |
150 | 150 | $this->order = absint($order); |
@@ -173,11 +173,11 @@ discard block |
||
173 | 173 | */ |
174 | 174 | protected function setHtmlClass($html_class) |
175 | 175 | { |
176 | - if (! is_string($html_class)) { |
|
176 | + if ( ! is_string($html_class)) { |
|
177 | 177 | throw new InvalidDataTypeException('$html_class', $html_class, 'string'); |
178 | 178 | } |
179 | 179 | if (strpos($html_class, 'progress-step-') === false) { |
180 | - $html_class = 'progress-step-' . $html_class; |
|
180 | + $html_class = 'progress-step-'.$html_class; |
|
181 | 181 | } |
182 | 182 | $this->html_class = $html_class; |
183 | 183 | } |
@@ -199,7 +199,7 @@ discard block |
||
199 | 199 | */ |
200 | 200 | protected function setText($text) |
201 | 201 | { |
202 | - if (! is_string($text)) { |
|
202 | + if ( ! is_string($text)) { |
|
203 | 203 | throw new InvalidDataTypeException('$text', $text, 'string'); |
204 | 204 | } |
205 | 205 | $this->text = sanitize_text_field($text); |
@@ -16,190 +16,190 @@ |
||
16 | 16 | */ |
17 | 17 | class ProgressStep implements ProgressStepInterface |
18 | 18 | { |
19 | - /** |
|
20 | - * @var boolean $current |
|
21 | - */ |
|
22 | - private $current = false; |
|
23 | - |
|
24 | - |
|
25 | - /** |
|
26 | - * @var boolean $completed |
|
27 | - */ |
|
28 | - private $completed = false; |
|
29 | - |
|
30 | - |
|
31 | - /** |
|
32 | - * @var string $html_class |
|
33 | - */ |
|
34 | - private $html_class; |
|
35 | - |
|
36 | - /** |
|
37 | - * @var string $id |
|
38 | - */ |
|
39 | - private $id = ''; |
|
40 | - |
|
41 | - /** |
|
42 | - * @var int $order |
|
43 | - */ |
|
44 | - private $order = 0; |
|
45 | - |
|
46 | - /** |
|
47 | - * @var string $text |
|
48 | - */ |
|
49 | - private $text = ''; |
|
50 | - |
|
51 | - |
|
52 | - /** |
|
53 | - * ProgressStep constructor |
|
54 | - * |
|
55 | - * @param int $order |
|
56 | - * @param string $id |
|
57 | - * @param string $html_class |
|
58 | - * @param string $text |
|
59 | - * @throws InvalidDataTypeException |
|
60 | - */ |
|
61 | - public function __construct($order, $id, $html_class, $text) |
|
62 | - { |
|
63 | - $this->setOrder($order); |
|
64 | - $this->setId($id); |
|
65 | - $this->setHtmlClass($html_class); |
|
66 | - $this->setText($text); |
|
67 | - } |
|
68 | - |
|
69 | - |
|
70 | - /** |
|
71 | - * @return boolean |
|
72 | - */ |
|
73 | - public function isCurrent() |
|
74 | - { |
|
75 | - return $this->current; |
|
76 | - } |
|
77 | - |
|
78 | - |
|
79 | - /** |
|
80 | - * @param boolean $current |
|
81 | - */ |
|
82 | - public function setIsCurrent($current = true) |
|
83 | - { |
|
84 | - $this->current = filter_var($current, FILTER_VALIDATE_BOOLEAN); |
|
85 | - } |
|
86 | - |
|
87 | - |
|
88 | - /** |
|
89 | - * @return boolean |
|
90 | - */ |
|
91 | - public function isCompleted() |
|
92 | - { |
|
93 | - return $this->completed; |
|
94 | - } |
|
95 | - |
|
96 | - |
|
97 | - /** |
|
98 | - * @param boolean $completed |
|
99 | - */ |
|
100 | - public function setIsCompleted($completed = true) |
|
101 | - { |
|
102 | - $this->completed = filter_var($completed, FILTER_VALIDATE_BOOLEAN); |
|
103 | - } |
|
104 | - |
|
105 | - |
|
106 | - /** |
|
107 | - * @return string |
|
108 | - */ |
|
109 | - public function id() |
|
110 | - { |
|
111 | - return $this->id; |
|
112 | - } |
|
113 | - |
|
114 | - |
|
115 | - /** |
|
116 | - * @access protected |
|
117 | - * @param string $id |
|
118 | - * @throws InvalidDataTypeException |
|
119 | - */ |
|
120 | - protected function setId($id = '') |
|
121 | - { |
|
122 | - if (! is_string($id)) { |
|
123 | - throw new InvalidDataTypeException('$id', $id, 'string'); |
|
124 | - } |
|
125 | - $this->id = $id; |
|
126 | - } |
|
127 | - |
|
128 | - |
|
129 | - /** |
|
130 | - * @return int |
|
131 | - */ |
|
132 | - public function order() |
|
133 | - { |
|
134 | - return $this->order; |
|
135 | - } |
|
136 | - |
|
137 | - |
|
138 | - /** |
|
139 | - * @access protected |
|
140 | - * @param int $order |
|
141 | - * @throws InvalidDataTypeException |
|
142 | - */ |
|
143 | - protected function setOrder($order = 0) |
|
144 | - { |
|
145 | - if (! is_int($order)) { |
|
146 | - throw new InvalidDataTypeException('$order', $order, 'integer'); |
|
147 | - } |
|
148 | - $this->order = absint($order); |
|
149 | - } |
|
150 | - |
|
151 | - |
|
152 | - /** |
|
153 | - * @return string |
|
154 | - */ |
|
155 | - public function htmlClass() |
|
156 | - { |
|
157 | - $html_class = $this->html_class; |
|
158 | - if ($this->isCurrent()) { |
|
159 | - $html_class .= ' progress-step-active'; |
|
160 | - } elseif ($this->isCompleted()) { |
|
161 | - $html_class .= ' progress-step-completed'; |
|
162 | - } |
|
163 | - return $html_class; |
|
164 | - } |
|
165 | - |
|
166 | - |
|
167 | - /** |
|
168 | - * @access protected |
|
169 | - * @param string $html_class |
|
170 | - * @throws InvalidDataTypeException |
|
171 | - */ |
|
172 | - protected function setHtmlClass($html_class) |
|
173 | - { |
|
174 | - if (! is_string($html_class)) { |
|
175 | - throw new InvalidDataTypeException('$html_class', $html_class, 'string'); |
|
176 | - } |
|
177 | - if (strpos($html_class, 'progress-step-') === false) { |
|
178 | - $html_class = 'progress-step-' . $html_class; |
|
179 | - } |
|
180 | - $this->html_class = $html_class; |
|
181 | - } |
|
182 | - |
|
183 | - |
|
184 | - /** |
|
185 | - * @return string |
|
186 | - */ |
|
187 | - public function text() |
|
188 | - { |
|
189 | - return $this->text; |
|
190 | - } |
|
191 | - |
|
192 | - |
|
193 | - /** |
|
194 | - * @access protected |
|
195 | - * @param string $text |
|
196 | - * @throws InvalidDataTypeException |
|
197 | - */ |
|
198 | - protected function setText($text) |
|
199 | - { |
|
200 | - if (! is_string($text)) { |
|
201 | - throw new InvalidDataTypeException('$text', $text, 'string'); |
|
202 | - } |
|
203 | - $this->text = sanitize_text_field($text); |
|
204 | - } |
|
19 | + /** |
|
20 | + * @var boolean $current |
|
21 | + */ |
|
22 | + private $current = false; |
|
23 | + |
|
24 | + |
|
25 | + /** |
|
26 | + * @var boolean $completed |
|
27 | + */ |
|
28 | + private $completed = false; |
|
29 | + |
|
30 | + |
|
31 | + /** |
|
32 | + * @var string $html_class |
|
33 | + */ |
|
34 | + private $html_class; |
|
35 | + |
|
36 | + /** |
|
37 | + * @var string $id |
|
38 | + */ |
|
39 | + private $id = ''; |
|
40 | + |
|
41 | + /** |
|
42 | + * @var int $order |
|
43 | + */ |
|
44 | + private $order = 0; |
|
45 | + |
|
46 | + /** |
|
47 | + * @var string $text |
|
48 | + */ |
|
49 | + private $text = ''; |
|
50 | + |
|
51 | + |
|
52 | + /** |
|
53 | + * ProgressStep constructor |
|
54 | + * |
|
55 | + * @param int $order |
|
56 | + * @param string $id |
|
57 | + * @param string $html_class |
|
58 | + * @param string $text |
|
59 | + * @throws InvalidDataTypeException |
|
60 | + */ |
|
61 | + public function __construct($order, $id, $html_class, $text) |
|
62 | + { |
|
63 | + $this->setOrder($order); |
|
64 | + $this->setId($id); |
|
65 | + $this->setHtmlClass($html_class); |
|
66 | + $this->setText($text); |
|
67 | + } |
|
68 | + |
|
69 | + |
|
70 | + /** |
|
71 | + * @return boolean |
|
72 | + */ |
|
73 | + public function isCurrent() |
|
74 | + { |
|
75 | + return $this->current; |
|
76 | + } |
|
77 | + |
|
78 | + |
|
79 | + /** |
|
80 | + * @param boolean $current |
|
81 | + */ |
|
82 | + public function setIsCurrent($current = true) |
|
83 | + { |
|
84 | + $this->current = filter_var($current, FILTER_VALIDATE_BOOLEAN); |
|
85 | + } |
|
86 | + |
|
87 | + |
|
88 | + /** |
|
89 | + * @return boolean |
|
90 | + */ |
|
91 | + public function isCompleted() |
|
92 | + { |
|
93 | + return $this->completed; |
|
94 | + } |
|
95 | + |
|
96 | + |
|
97 | + /** |
|
98 | + * @param boolean $completed |
|
99 | + */ |
|
100 | + public function setIsCompleted($completed = true) |
|
101 | + { |
|
102 | + $this->completed = filter_var($completed, FILTER_VALIDATE_BOOLEAN); |
|
103 | + } |
|
104 | + |
|
105 | + |
|
106 | + /** |
|
107 | + * @return string |
|
108 | + */ |
|
109 | + public function id() |
|
110 | + { |
|
111 | + return $this->id; |
|
112 | + } |
|
113 | + |
|
114 | + |
|
115 | + /** |
|
116 | + * @access protected |
|
117 | + * @param string $id |
|
118 | + * @throws InvalidDataTypeException |
|
119 | + */ |
|
120 | + protected function setId($id = '') |
|
121 | + { |
|
122 | + if (! is_string($id)) { |
|
123 | + throw new InvalidDataTypeException('$id', $id, 'string'); |
|
124 | + } |
|
125 | + $this->id = $id; |
|
126 | + } |
|
127 | + |
|
128 | + |
|
129 | + /** |
|
130 | + * @return int |
|
131 | + */ |
|
132 | + public function order() |
|
133 | + { |
|
134 | + return $this->order; |
|
135 | + } |
|
136 | + |
|
137 | + |
|
138 | + /** |
|
139 | + * @access protected |
|
140 | + * @param int $order |
|
141 | + * @throws InvalidDataTypeException |
|
142 | + */ |
|
143 | + protected function setOrder($order = 0) |
|
144 | + { |
|
145 | + if (! is_int($order)) { |
|
146 | + throw new InvalidDataTypeException('$order', $order, 'integer'); |
|
147 | + } |
|
148 | + $this->order = absint($order); |
|
149 | + } |
|
150 | + |
|
151 | + |
|
152 | + /** |
|
153 | + * @return string |
|
154 | + */ |
|
155 | + public function htmlClass() |
|
156 | + { |
|
157 | + $html_class = $this->html_class; |
|
158 | + if ($this->isCurrent()) { |
|
159 | + $html_class .= ' progress-step-active'; |
|
160 | + } elseif ($this->isCompleted()) { |
|
161 | + $html_class .= ' progress-step-completed'; |
|
162 | + } |
|
163 | + return $html_class; |
|
164 | + } |
|
165 | + |
|
166 | + |
|
167 | + /** |
|
168 | + * @access protected |
|
169 | + * @param string $html_class |
|
170 | + * @throws InvalidDataTypeException |
|
171 | + */ |
|
172 | + protected function setHtmlClass($html_class) |
|
173 | + { |
|
174 | + if (! is_string($html_class)) { |
|
175 | + throw new InvalidDataTypeException('$html_class', $html_class, 'string'); |
|
176 | + } |
|
177 | + if (strpos($html_class, 'progress-step-') === false) { |
|
178 | + $html_class = 'progress-step-' . $html_class; |
|
179 | + } |
|
180 | + $this->html_class = $html_class; |
|
181 | + } |
|
182 | + |
|
183 | + |
|
184 | + /** |
|
185 | + * @return string |
|
186 | + */ |
|
187 | + public function text() |
|
188 | + { |
|
189 | + return $this->text; |
|
190 | + } |
|
191 | + |
|
192 | + |
|
193 | + /** |
|
194 | + * @access protected |
|
195 | + * @param string $text |
|
196 | + * @throws InvalidDataTypeException |
|
197 | + */ |
|
198 | + protected function setText($text) |
|
199 | + { |
|
200 | + if (! is_string($text)) { |
|
201 | + throw new InvalidDataTypeException('$text', $text, 'string'); |
|
202 | + } |
|
203 | + $this->text = sanitize_text_field($text); |
|
204 | + } |
|
205 | 205 | } |
@@ -62,12 +62,12 @@ |
||
62 | 62 | <div class="notice inline notice-alt"> |
63 | 63 | <div class="ee-upsell-container"> |
64 | 64 | <div class="ee-upsell-inner-container"> |
65 | - <a href="' . esc_url_raw($button_url) . '"> |
|
66 | - ' . $button_text /* already escaped */ . ' |
|
65 | + <a href="' . esc_url_raw($button_url).'"> |
|
66 | + ' . $button_text /* already escaped */.' |
|
67 | 67 | </a> |
68 | 68 | </div> |
69 | 69 | <div class="ee-upsell-inner-container"> |
70 | - <p>' . $upsell_text /* already escaped */ . '</p> |
|
70 | + <p>' . $upsell_text /* already escaped */.'</p> |
|
71 | 71 | </div> |
72 | 72 | <div style="clear:both"></div> |
73 | 73 | </div> |
@@ -16,47 +16,47 @@ discard block |
||
16 | 16 | */ |
17 | 17 | class PluginUpsells |
18 | 18 | { |
19 | - /** |
|
20 | - * @var DomainInterface |
|
21 | - */ |
|
22 | - private $domain; |
|
19 | + /** |
|
20 | + * @var DomainInterface |
|
21 | + */ |
|
22 | + private $domain; |
|
23 | 23 | |
24 | 24 | |
25 | - /** |
|
26 | - * PluginUpsells constructor. |
|
27 | - * |
|
28 | - * @param DomainInterface $domain |
|
29 | - */ |
|
30 | - public function __construct(DomainInterface $domain) |
|
31 | - { |
|
32 | - $this->domain = $domain; |
|
33 | - } |
|
25 | + /** |
|
26 | + * PluginUpsells constructor. |
|
27 | + * |
|
28 | + * @param DomainInterface $domain |
|
29 | + */ |
|
30 | + public function __construct(DomainInterface $domain) |
|
31 | + { |
|
32 | + $this->domain = $domain; |
|
33 | + } |
|
34 | 34 | |
35 | 35 | |
36 | - /** |
|
37 | - * Hook in various upsells for the decaf version of EE. |
|
38 | - */ |
|
39 | - public function decafUpsells() |
|
40 | - { |
|
41 | - if ($this->domain instanceof CaffeinatedInterface && ! $this->domain->isCaffeinated()) { |
|
42 | - add_action('after_plugin_row', array($this, 'doPremiumUpsell'), 10, 3); |
|
43 | - } |
|
44 | - } |
|
36 | + /** |
|
37 | + * Hook in various upsells for the decaf version of EE. |
|
38 | + */ |
|
39 | + public function decafUpsells() |
|
40 | + { |
|
41 | + if ($this->domain instanceof CaffeinatedInterface && ! $this->domain->isCaffeinated()) { |
|
42 | + add_action('after_plugin_row', array($this, 'doPremiumUpsell'), 10, 3); |
|
43 | + } |
|
44 | + } |
|
45 | 45 | |
46 | 46 | |
47 | - /** |
|
48 | - * Callback for `after_plugin_row` to add upsell info |
|
49 | - * |
|
50 | - * @param string $plugin_file |
|
51 | - * @param array $plugin_data |
|
52 | - * @param string $status |
|
53 | - * @throws DomainException |
|
54 | - */ |
|
55 | - public function doPremiumUpsell($plugin_file, $plugin_data, $status) |
|
56 | - { |
|
57 | - if ($plugin_file === $this->domain->pluginBasename()) { |
|
58 | - list($button_text, $button_url, $upsell_text) = $this->getAfterPluginRowDetails(); |
|
59 | - echo '<tr class="plugin-update-tr ee-upsell-plugin-list-table active"> |
|
47 | + /** |
|
48 | + * Callback for `after_plugin_row` to add upsell info |
|
49 | + * |
|
50 | + * @param string $plugin_file |
|
51 | + * @param array $plugin_data |
|
52 | + * @param string $status |
|
53 | + * @throws DomainException |
|
54 | + */ |
|
55 | + public function doPremiumUpsell($plugin_file, $plugin_data, $status) |
|
56 | + { |
|
57 | + if ($plugin_file === $this->domain->pluginBasename()) { |
|
58 | + list($button_text, $button_url, $upsell_text) = $this->getAfterPluginRowDetails(); |
|
59 | + echo '<tr class="plugin-update-tr ee-upsell-plugin-list-table active"> |
|
60 | 60 | <td colspan="3" class="plugin-update colspanchange"> |
61 | 61 | <div class="notice inline notice-alt"> |
62 | 62 | <div class="ee-upsell-container"> |
@@ -73,27 +73,27 @@ discard block |
||
73 | 73 | </div> |
74 | 74 | </td> |
75 | 75 | </tr>'; |
76 | - } |
|
77 | - } |
|
76 | + } |
|
77 | + } |
|
78 | 78 | |
79 | - /** |
|
80 | - * Provide the details used for the upsell container. |
|
81 | - * |
|
82 | - * @return array |
|
83 | - */ |
|
84 | - protected function getAfterPluginRowDetails() |
|
85 | - { |
|
86 | - return array( |
|
87 | - esc_html__('Upgrade for Support', 'event_espresso'), |
|
88 | - 'https://eventespresso.com/purchase/?slug=ee4-license-personal&utm_source=wp_admin_plugins_screen&utm_medium=link&utm_campaign=plugins_screen_upgrade_link" class="button button-primary', |
|
89 | - sprintf( |
|
90 | - esc_html__( |
|
91 | - 'You\'re missing out on %1$sexpert support%2$s and %1$sone-click updates%2$s! Don\'t have an Event Espresso support license key? Support the project and buy one today!', |
|
92 | - 'event_espresso' |
|
93 | - ), |
|
94 | - '<strong>', |
|
95 | - '</strong>' |
|
96 | - ), |
|
97 | - ); |
|
98 | - } |
|
79 | + /** |
|
80 | + * Provide the details used for the upsell container. |
|
81 | + * |
|
82 | + * @return array |
|
83 | + */ |
|
84 | + protected function getAfterPluginRowDetails() |
|
85 | + { |
|
86 | + return array( |
|
87 | + esc_html__('Upgrade for Support', 'event_espresso'), |
|
88 | + 'https://eventespresso.com/purchase/?slug=ee4-license-personal&utm_source=wp_admin_plugins_screen&utm_medium=link&utm_campaign=plugins_screen_upgrade_link" class="button button-primary', |
|
89 | + sprintf( |
|
90 | + esc_html__( |
|
91 | + 'You\'re missing out on %1$sexpert support%2$s and %1$sone-click updates%2$s! Don\'t have an Event Espresso support license key? Support the project and buy one today!', |
|
92 | + 'event_espresso' |
|
93 | + ), |
|
94 | + '<strong>', |
|
95 | + '</strong>' |
|
96 | + ), |
|
97 | + ); |
|
98 | + } |
|
99 | 99 | } |
@@ -146,7 +146,7 @@ discard block |
||
146 | 146 | |
147 | 147 | public function get_shortcode_helper() |
148 | 148 | { |
149 | - if (! $this->_shortcode_helper instanceof EEH_Parse_Shortcodes) { |
|
149 | + if ( ! $this->_shortcode_helper instanceof EEH_Parse_Shortcodes) { |
|
150 | 150 | $this->_set_shortcode_helper(); |
151 | 151 | } |
152 | 152 | return $this->_shortcode_helper; |
@@ -170,17 +170,17 @@ discard block |
||
170 | 170 | |
171 | 171 | // we need to setup any dynamic shortcodes so that they work with the array_key_exists |
172 | 172 | preg_match_all('/(\[[A-Za-z0-9\_]+_\*)/', $shortcode, $matches); |
173 | - $sc_to_verify = ! empty($matches[0]) ? $matches[0][0] . ']' : $shortcode; |
|
173 | + $sc_to_verify = ! empty($matches[0]) ? $matches[0][0].']' : $shortcode; |
|
174 | 174 | |
175 | 175 | // first we want to make sure this is a valid shortcode |
176 | - if (! array_key_exists($sc_to_verify, $this->_shortcodes)) { |
|
176 | + if ( ! array_key_exists($sc_to_verify, $this->_shortcodes)) { |
|
177 | 177 | return false; |
178 | 178 | } //get out, this parser doesn't handle the incoming shortcode. |
179 | 179 | $this->_data = $data; |
180 | 180 | $this->_extra_data = $extra_data; |
181 | 181 | $this->_set_messages_properties(); |
182 | 182 | $parsed = apply_filters( |
183 | - 'FHEE__' . get_class($this) . '__parser_after', |
|
183 | + 'FHEE__'.get_class($this).'__parser_after', |
|
184 | 184 | $this->_parser($shortcode), |
185 | 185 | $shortcode, |
186 | 186 | $data, |
@@ -201,7 +201,7 @@ discard block |
||
201 | 201 | */ |
202 | 202 | public function get_shortcodes() |
203 | 203 | { |
204 | - $this->_shortcodes = apply_filters('FHEE__' . get_class($this) . '__shortcodes', $this->_shortcodes, $this); |
|
204 | + $this->_shortcodes = apply_filters('FHEE__'.get_class($this).'__shortcodes', $this->_shortcodes, $this); |
|
205 | 205 | |
206 | 206 | // note the below filter applies to ALL shortcode parsers... be careful! |
207 | 207 | $this->_shortcodes = apply_filters('FHEE__EE_Shortcodes__shortcodes', $this->_shortcodes, $this); |
@@ -248,7 +248,7 @@ discard block |
||
248 | 248 | { |
249 | 249 | |
250 | 250 | // first test to make sure we've got an array! |
251 | - if (! is_array($this->_data)) { |
|
251 | + if ( ! is_array($this->_data)) { |
|
252 | 252 | throw new EE_Error( |
253 | 253 | sprintf( |
254 | 254 | esc_html__( |
@@ -262,7 +262,7 @@ discard block |
||
262 | 262 | } |
263 | 263 | |
264 | 264 | // next test to make sure we've got the required template in the index! |
265 | - if (! isset($this->_data['template'])) { |
|
265 | + if ( ! isset($this->_data['template'])) { |
|
266 | 266 | throw new EE_Error( |
267 | 267 | sprintf( |
268 | 268 | esc_html__( |
@@ -274,7 +274,7 @@ discard block |
||
274 | 274 | } |
275 | 275 | |
276 | 276 | // next test to make sure we've got got a data index in the incoming data array |
277 | - if (! isset($this->_data['data'])) { |
|
277 | + if ( ! isset($this->_data['data'])) { |
|
278 | 278 | throw new EE_Error( |
279 | 279 | esc_html__( |
280 | 280 | 'The incoming data does not have the required data index in its array', |
@@ -303,8 +303,8 @@ discard block |
||
303 | 303 | { |
304 | 304 | // make sure the required wp helper function is present |
305 | 305 | // require the shortcode file if necessary |
306 | - if (! function_exists('shortcode_parse_atts')) { |
|
307 | - require_once(ABSPATH . WPINC . '/shortcodes.php'); |
|
306 | + if ( ! function_exists('shortcode_parse_atts')) { |
|
307 | + require_once(ABSPATH.WPINC.'/shortcodes.php'); |
|
308 | 308 | } |
309 | 309 | |
310 | 310 | // let's get any attributes that may be present and set the defaults. |
@@ -329,15 +329,15 @@ discard block |
||
329 | 329 | protected function _mutate_conditional_block_in_template($shortcode, $show = true) |
330 | 330 | { |
331 | 331 | // first let's get all the matches in the template for this particular shortcode. |
332 | - preg_match_all('~' . $this->_get_conditional_block_regex($shortcode) . '~', $this->_data['template'], $matches); |
|
332 | + preg_match_all('~'.$this->_get_conditional_block_regex($shortcode).'~', $this->_data['template'], $matches); |
|
333 | 333 | |
334 | 334 | if ($matches && is_array($matches[0]) && ! empty($matches[0])) { |
335 | 335 | // we need to hide all instances of the matches |
336 | 336 | foreach ($matches[0] as $index => $content_to_show_or_hide) { |
337 | 337 | $content_to_show_or_hide = preg_quote($content_to_show_or_hide); |
338 | - $replacement = $show ? $matches[4][ $index ] : ''; |
|
338 | + $replacement = $show ? $matches[4][$index] : ''; |
|
339 | 339 | $this->_data['template'] = preg_replace( |
340 | - '~' . $content_to_show_or_hide . '~', |
|
340 | + '~'.$content_to_show_or_hide.'~', |
|
341 | 341 | $replacement, |
342 | 342 | $this->_data['template'] |
343 | 343 | ); |
@@ -16,456 +16,456 @@ |
||
16 | 16 | */ |
17 | 17 | abstract class EE_Shortcodes extends EE_Base |
18 | 18 | { |
19 | - /** |
|
20 | - * holds label for library |
|
21 | - * This is used for referencing the library label |
|
22 | - * |
|
23 | - * @access public |
|
24 | - * @var string |
|
25 | - */ |
|
26 | - public $label; |
|
27 | - |
|
28 | - |
|
29 | - /** |
|
30 | - * This property is used for referencing a short description of the library |
|
31 | - * |
|
32 | - * @access public |
|
33 | - * @var string |
|
34 | - */ |
|
35 | - public $description; |
|
36 | - |
|
37 | - |
|
38 | - /** |
|
39 | - * This will hold an array of shortcodes with the key as the shortcode ([shortcode]) and the value as a |
|
40 | - * label/description for the shortcode. |
|
41 | - * |
|
42 | - * @access protected |
|
43 | - * @var array |
|
44 | - */ |
|
45 | - protected $_shortcodes; |
|
46 | - |
|
47 | - |
|
48 | - /** |
|
49 | - * This will hold the incoming data item sent to the parser method |
|
50 | - * |
|
51 | - * @access protected |
|
52 | - * @var mixed (array|object) |
|
53 | - */ |
|
54 | - protected $_data; |
|
55 | - |
|
56 | - |
|
57 | - /** |
|
58 | - * some shortcodes may require extra data to parse. This property is provided for that. |
|
59 | - * |
|
60 | - * @var array |
|
61 | - */ |
|
62 | - protected $_extra_data; |
|
63 | - |
|
64 | - |
|
65 | - /** |
|
66 | - * EE_messenger used to generate the template being parsed. |
|
67 | - * |
|
68 | - * @since 4.5.0 |
|
69 | - * @var EE_messenger |
|
70 | - */ |
|
71 | - protected $_messenger; |
|
72 | - |
|
73 | - |
|
74 | - /** |
|
75 | - * message type used to generate the template being parsed. |
|
76 | - * |
|
77 | - * @since 4.5.0 |
|
78 | - * @var EE_message_type |
|
79 | - */ |
|
80 | - protected $_message_type; |
|
81 | - |
|
82 | - |
|
83 | - /** |
|
84 | - * context used for the template being parsed |
|
85 | - * |
|
86 | - * @since 4.5.0 |
|
87 | - * @var string |
|
88 | - */ |
|
89 | - protected $_context; |
|
90 | - |
|
91 | - |
|
92 | - /** |
|
93 | - * Specific Message Template Group ID |
|
94 | - * |
|
95 | - * @since 4.5.0 |
|
96 | - * @var int |
|
97 | - */ |
|
98 | - protected $_GRP_ID; |
|
99 | - |
|
100 | - |
|
101 | - /** |
|
102 | - * @since 4.9.0 |
|
103 | - * @type EE_Message |
|
104 | - */ |
|
105 | - protected $_message; |
|
106 | - |
|
107 | - |
|
108 | - /** |
|
109 | - * This will hold an instance of the EEH_Parse_Shortcodes helper that will be used when handling list type |
|
110 | - * shortcodes |
|
111 | - * |
|
112 | - * @var EEH_Parse_Shortcodes |
|
113 | - */ |
|
114 | - protected $_shortcode_helper; |
|
115 | - |
|
116 | - |
|
117 | - public function __construct() |
|
118 | - { |
|
119 | - $this->_set_defaults(); |
|
120 | - $this->_init_props(); |
|
121 | - } |
|
122 | - |
|
123 | - |
|
124 | - /** |
|
125 | - * This sets the defaults for the properties. Child classes will override these properties in their _init_props |
|
126 | - * method |
|
127 | - */ |
|
128 | - private function _set_defaults() |
|
129 | - { |
|
130 | - $this->name = $this->description = ''; |
|
131 | - $this->_shortcodes = array(); |
|
132 | - $this->_set_shortcode_helper(); |
|
133 | - } |
|
134 | - |
|
135 | - |
|
136 | - /** |
|
137 | - * loads an instance of the EE_Shortcode_Parser helper when requested |
|
138 | - */ |
|
139 | - protected function _set_shortcode_helper() |
|
140 | - { |
|
141 | - // get shortcode_replace instance- set when _get_messages is called in child... |
|
142 | - $this->_shortcode_helper = new EEH_Parse_Shortcodes(); |
|
143 | - } |
|
144 | - |
|
145 | - |
|
146 | - public function get_shortcode_helper() |
|
147 | - { |
|
148 | - if (! $this->_shortcode_helper instanceof EEH_Parse_Shortcodes) { |
|
149 | - $this->_set_shortcode_helper(); |
|
150 | - } |
|
151 | - return $this->_shortcode_helper; |
|
152 | - } |
|
153 | - |
|
154 | - |
|
155 | - /** |
|
156 | - * This is the public method for kicking of the parser included with each child. It can be overridden by child |
|
157 | - * classes if necessary (see EE_Questions_Answers for example) |
|
158 | - * |
|
159 | - * @param string $shortcode incoming shortcode to be parsed |
|
160 | - * @param mixed (object|array) $data incoming data to be be used for parsing |
|
161 | - * @param mixed (object|array) $extra_data extra incoming data (usually EE_Messages_Addressee) |
|
162 | - * @return string parsed shortcode. |
|
163 | - */ |
|
164 | - public function parser($shortcode, $data, $extra_data = array()) |
|
165 | - { |
|
166 | - |
|
167 | - // filter setup shortcodes |
|
168 | - $this->_shortcodes = $this->get_shortcodes(); |
|
169 | - |
|
170 | - // we need to setup any dynamic shortcodes so that they work with the array_key_exists |
|
171 | - preg_match_all('/(\[[A-Za-z0-9\_]+_\*)/', $shortcode, $matches); |
|
172 | - $sc_to_verify = ! empty($matches[0]) ? $matches[0][0] . ']' : $shortcode; |
|
173 | - |
|
174 | - // first we want to make sure this is a valid shortcode |
|
175 | - if (! array_key_exists($sc_to_verify, $this->_shortcodes)) { |
|
176 | - return false; |
|
177 | - } //get out, this parser doesn't handle the incoming shortcode. |
|
178 | - $this->_data = $data; |
|
179 | - $this->_extra_data = $extra_data; |
|
180 | - $this->_set_messages_properties(); |
|
181 | - $parsed = apply_filters( |
|
182 | - 'FHEE__' . get_class($this) . '__parser_after', |
|
183 | - $this->_parser($shortcode), |
|
184 | - $shortcode, |
|
185 | - $data, |
|
186 | - $extra_data, |
|
187 | - $this |
|
188 | - ); |
|
189 | - |
|
190 | - // note the below filter applies to ALL shortcode parsers... be careful! |
|
191 | - return apply_filters('FHEE__EE_Shortcodes__parser_after', $parsed, $shortcode, $data, $extra_data, $this); |
|
192 | - } |
|
193 | - |
|
194 | - |
|
195 | - /** |
|
196 | - * This method just returns the shortcodes in the $_shortcodes array property. |
|
197 | - * |
|
198 | - * @access public |
|
199 | - * @return array array of shortcodes => description pairs |
|
200 | - */ |
|
201 | - public function get_shortcodes() |
|
202 | - { |
|
203 | - $this->_shortcodes = apply_filters('FHEE__' . get_class($this) . '__shortcodes', $this->_shortcodes, $this); |
|
204 | - |
|
205 | - // note the below filter applies to ALL shortcode parsers... be careful! |
|
206 | - $this->_shortcodes = apply_filters('FHEE__EE_Shortcodes__shortcodes', $this->_shortcodes, $this); |
|
207 | - |
|
208 | - return $this->_shortcodes; |
|
209 | - } |
|
210 | - |
|
211 | - |
|
212 | - /** |
|
213 | - * Child classes use this method to set the $name, $description, and $_shortcodes properties. |
|
214 | - * |
|
215 | - * @abstract |
|
216 | - * @access protected |
|
217 | - * @return void |
|
218 | - */ |
|
219 | - abstract protected function _init_props(); |
|
220 | - |
|
221 | - |
|
222 | - /** |
|
223 | - * This method will give parsing instructions for each shortcode defined in the _shortcodes array. Child methods |
|
224 | - * will have to take care of handling. |
|
225 | - * |
|
226 | - * @abstract |
|
227 | - * @access protected |
|
228 | - * @param string $shortcode the shortcode to be parsed. |
|
229 | - * @param mixed (object|array) $data incoming data for the parser. The data could be either an object or |
|
230 | - * array because there are some shortcodes that might be replaced by prepared data that |
|
231 | - * has multiple items in a list (i.e. list of attendees in an event and we're showing |
|
232 | - * fname/lname for each attendee). In this case data will be in an array. Otherwise |
|
233 | - * the data shoudl be in a properly formatted object. The |
|
234 | - * EEH_Parse_Shortcodes.helper.php describes the data object we're expecting. |
|
235 | - * @return string parsed shortcode |
|
236 | - */ |
|
237 | - abstract protected function _parser($shortcode); |
|
238 | - |
|
239 | - |
|
240 | - /** |
|
241 | - * This just validates incoming data for list type shortcode parsers (and they call this method) to make sure it |
|
242 | - * meets their requirements |
|
243 | - * |
|
244 | - * @return mixed (void|exception) If validation fails we'll throw an exception. |
|
245 | - */ |
|
246 | - protected function _validate_list_requirements() |
|
247 | - { |
|
248 | - |
|
249 | - // first test to make sure we've got an array! |
|
250 | - if (! is_array($this->_data)) { |
|
251 | - throw new EE_Error( |
|
252 | - sprintf( |
|
253 | - esc_html__( |
|
254 | - 'Expecting an array for the data sent to %s. Instead it was %s', |
|
255 | - 'event_espresso' |
|
256 | - ), |
|
257 | - get_class($this), |
|
258 | - gettype($this->_data) |
|
259 | - ) |
|
260 | - ); |
|
261 | - } |
|
262 | - |
|
263 | - // next test to make sure we've got the required template in the index! |
|
264 | - if (! isset($this->_data['template'])) { |
|
265 | - throw new EE_Error( |
|
266 | - sprintf( |
|
267 | - esc_html__( |
|
268 | - 'The incoming data does not have the required template index in its array', |
|
269 | - 'event_espresso' |
|
270 | - ) |
|
271 | - ) |
|
272 | - ); |
|
273 | - } |
|
274 | - |
|
275 | - // next test to make sure we've got got a data index in the incoming data array |
|
276 | - if (! isset($this->_data['data'])) { |
|
277 | - throw new EE_Error( |
|
278 | - esc_html__( |
|
279 | - 'The incoming data does not have the required data index in its array', |
|
280 | - 'event_espresso' |
|
281 | - ) |
|
282 | - ); |
|
283 | - } |
|
284 | - |
|
285 | - // all is well let's make sure _extra_data always has the values needed. |
|
286 | - // let's make sure that extra_data includes all templates (for later parsing if necessary) |
|
287 | - if (empty($this->_extra_data) || (empty($this->_extra_data['data']) && empty($this->_extra_data['template']))) { |
|
288 | - $this->_extra_data['data'] = $this->_data['data']; |
|
289 | - $this->_extra_data['template'] = $this->_data['template']; |
|
290 | - } |
|
291 | - } |
|
292 | - |
|
293 | - |
|
294 | - /** |
|
295 | - * This returns any attributes that may be existing on an EE_Shortcode |
|
296 | - * |
|
297 | - * @since 4.5.0 |
|
298 | - * @param string $shortcode incoming shortcode |
|
299 | - * @return array An array with the attributes |
|
300 | - */ |
|
301 | - protected function _get_shortcode_attrs($shortcode) |
|
302 | - { |
|
303 | - // make sure the required wp helper function is present |
|
304 | - // require the shortcode file if necessary |
|
305 | - if (! function_exists('shortcode_parse_atts')) { |
|
306 | - require_once(ABSPATH . WPINC . '/shortcodes.php'); |
|
307 | - } |
|
308 | - |
|
309 | - // let's get any attributes that may be present and set the defaults. |
|
310 | - $shortcode_to_parse = str_replace('[', '', str_replace(']', '', $shortcode)); |
|
311 | - return shortcode_parse_atts($shortcode_to_parse); |
|
312 | - } |
|
313 | - |
|
314 | - |
|
315 | - /** |
|
316 | - * Conditional blocks are shortcode patterns with an opening conditional tag `[IF_*]` and a corresponding |
|
317 | - * closing tag (eg `[/IF_*]`). The content within the tags will be displayed/hidden depending on whatever |
|
318 | - * conditions existed in the opening tag. This method handles parsing the actual template to show/hide this |
|
319 | - * conditional content. |
|
320 | - * |
|
321 | - * @since 4.9.32 |
|
322 | - * |
|
323 | - * @param string $shortcode This should be original shortcode as used in the template and passed to the parser. |
|
324 | - * @param bool $show true means the opening and closing tags are removed and the content is left showing, |
|
325 | - * false means the opening and closing tags and the contained content are removed. |
|
326 | - * @return string The template for the shortcode is returned. |
|
327 | - */ |
|
328 | - protected function _mutate_conditional_block_in_template($shortcode, $show = true) |
|
329 | - { |
|
330 | - // first let's get all the matches in the template for this particular shortcode. |
|
331 | - preg_match_all('~' . $this->_get_conditional_block_regex($shortcode) . '~', $this->_data['template'], $matches); |
|
332 | - |
|
333 | - if ($matches && is_array($matches[0]) && ! empty($matches[0])) { |
|
334 | - // we need to hide all instances of the matches |
|
335 | - foreach ($matches[0] as $index => $content_to_show_or_hide) { |
|
336 | - $content_to_show_or_hide = preg_quote($content_to_show_or_hide); |
|
337 | - $replacement = $show ? $matches[4][ $index ] : ''; |
|
338 | - $this->_data['template'] = preg_replace( |
|
339 | - '~' . $content_to_show_or_hide . '~', |
|
340 | - $replacement, |
|
341 | - $this->_data['template'] |
|
342 | - ); |
|
343 | - } |
|
344 | - } |
|
345 | - // return $template |
|
346 | - return $this->_data['template']; |
|
347 | - } |
|
348 | - |
|
349 | - |
|
350 | - /** |
|
351 | - * This returns the regex pattern to use for conditional shortcodes parsing. |
|
352 | - * |
|
353 | - * Note: regex comes in part from the WP `get_shortcode_regex` expression in \wp-includes\shortcodes.php |
|
354 | - * |
|
355 | - * @param $shortcode |
|
356 | - * @since 4.9.32 |
|
357 | - * @return string |
|
358 | - */ |
|
359 | - private function _get_conditional_block_regex($shortcode) |
|
360 | - { |
|
361 | - // get just the shortcode tag for the match |
|
362 | - preg_match('@\[([^<>&/\[\]\x00-\x20=]++)@', $shortcode, $shortcode_tag_matches); |
|
363 | - if (empty($shortcode_tag_matches[1])) { |
|
364 | - return $this->_data['template']; |
|
365 | - } |
|
366 | - |
|
367 | - $shortcode_tag = $shortcode_tag_matches[1]; |
|
368 | - // get attributes_part_of_tag |
|
369 | - $attributes_part = preg_quote(str_replace(array($shortcode_tag, '[', ']'), '', $shortcode)); |
|
370 | - // escape |
|
371 | - $shortcode_tag = preg_quote($shortcode_tag); |
|
372 | - |
|
373 | - return |
|
374 | - '\[' // Opening Bracket |
|
375 | - . "($shortcode_tag)$attributes_part" // 1: Shortcode Name |
|
376 | - . '(?![\w-])' // Not followed by word character or hyphen |
|
377 | - . '(' // 2: Unroll the loop: Inside the opening shortcode tag |
|
378 | - . '[^\]\/]*' // Not a closing bracket or forward slash |
|
379 | - . '(?:' |
|
380 | - . '\/(?!\])' // A forward slash not followed by a closing bracket |
|
381 | - . '[^\]\/]*' // Not a closing bracket or forward slash. |
|
382 | - . ')*?' |
|
383 | - . ')' |
|
384 | - . '(?:' |
|
385 | - . '(\/)' // 3. Self closing tag ... |
|
386 | - . '\]' // ... and closing bracket |
|
387 | - . '|' |
|
388 | - . '\]' // Closing bracket |
|
389 | - . '(?:' |
|
390 | - . '(' // 4: Unroll the loop: Optionally, anything between the opening and closing brackets |
|
391 | - . '[^\[]*+' // Not an opening bracket |
|
392 | - . '(?:' |
|
393 | - . '\[(?!\/\1\])' // An opening bracket not followed by the closing shortcode tag. |
|
394 | - . '[^\[]*+' // Not an opening bracket |
|
395 | - . ')*+' |
|
396 | - . ')' |
|
397 | - . '\[\/\1\]' // Closing shortcode tag |
|
398 | - . ')?' |
|
399 | - . ')'; |
|
400 | - } |
|
401 | - |
|
402 | - |
|
403 | - /** |
|
404 | - * This sets the properties related to the messages system |
|
405 | - * |
|
406 | - * @since 4.5.0 |
|
407 | - * @return void |
|
408 | - */ |
|
409 | - protected function _set_messages_properties() |
|
410 | - { |
|
411 | - // should be in _extra_data |
|
412 | - if (isset($this->_extra_data['messenger'])) { |
|
413 | - $this->_messenger = $this->_extra_data['messenger']; |
|
414 | - $this->_message_type = $this->_extra_data['message_type']; |
|
415 | - $this->_context = $this->_extra_data['message'] instanceof EE_Message |
|
416 | - ? $this->_extra_data['message']->context() : ''; |
|
417 | - $this->_GRP_ID = $this->_extra_data['message'] instanceof EE_Message |
|
418 | - ? $this->_extra_data['message']->GRP_ID() : 0; |
|
419 | - $this->_message = $this->_extra_data['message'] instanceof EE_Message ? $this->_extra_data['message'] |
|
420 | - : null; |
|
421 | - } |
|
422 | - } |
|
423 | - |
|
424 | - |
|
425 | - /** |
|
426 | - * This returns whatever the set message type object is that was set on this shortcode parser. |
|
427 | - * |
|
428 | - * @since 4.5.0 |
|
429 | - * @return EE_message_type |
|
430 | - */ |
|
431 | - public function get_set_message_type() |
|
432 | - { |
|
433 | - return $this->_message_type; |
|
434 | - } |
|
435 | - |
|
436 | - |
|
437 | - /** |
|
438 | - * This returns whatever the set messenger object is that was set on this shortcode parser |
|
439 | - * |
|
440 | - * @since 4.5.0 |
|
441 | - * @return EE_messenger |
|
442 | - */ |
|
443 | - public function get_set_messenger() |
|
444 | - { |
|
445 | - return $this->_messenger; |
|
446 | - } |
|
447 | - |
|
448 | - |
|
449 | - /** |
|
450 | - * This returns whatever the set context string is on this shortcode parser. |
|
451 | - * |
|
452 | - * @since 4.5.0 |
|
453 | - * @return string |
|
454 | - */ |
|
455 | - public function get_set_context() |
|
456 | - { |
|
457 | - return $this->_context; |
|
458 | - } |
|
459 | - |
|
460 | - |
|
461 | - /** |
|
462 | - * This returns whatever the set EE_Message object is on this shortcode. |
|
463 | - * |
|
464 | - * @since 4.9.0 |
|
465 | - * @return EE_Message |
|
466 | - */ |
|
467 | - public function get_set_message() |
|
468 | - { |
|
469 | - return $this->_message; |
|
470 | - } |
|
19 | + /** |
|
20 | + * holds label for library |
|
21 | + * This is used for referencing the library label |
|
22 | + * |
|
23 | + * @access public |
|
24 | + * @var string |
|
25 | + */ |
|
26 | + public $label; |
|
27 | + |
|
28 | + |
|
29 | + /** |
|
30 | + * This property is used for referencing a short description of the library |
|
31 | + * |
|
32 | + * @access public |
|
33 | + * @var string |
|
34 | + */ |
|
35 | + public $description; |
|
36 | + |
|
37 | + |
|
38 | + /** |
|
39 | + * This will hold an array of shortcodes with the key as the shortcode ([shortcode]) and the value as a |
|
40 | + * label/description for the shortcode. |
|
41 | + * |
|
42 | + * @access protected |
|
43 | + * @var array |
|
44 | + */ |
|
45 | + protected $_shortcodes; |
|
46 | + |
|
47 | + |
|
48 | + /** |
|
49 | + * This will hold the incoming data item sent to the parser method |
|
50 | + * |
|
51 | + * @access protected |
|
52 | + * @var mixed (array|object) |
|
53 | + */ |
|
54 | + protected $_data; |
|
55 | + |
|
56 | + |
|
57 | + /** |
|
58 | + * some shortcodes may require extra data to parse. This property is provided for that. |
|
59 | + * |
|
60 | + * @var array |
|
61 | + */ |
|
62 | + protected $_extra_data; |
|
63 | + |
|
64 | + |
|
65 | + /** |
|
66 | + * EE_messenger used to generate the template being parsed. |
|
67 | + * |
|
68 | + * @since 4.5.0 |
|
69 | + * @var EE_messenger |
|
70 | + */ |
|
71 | + protected $_messenger; |
|
72 | + |
|
73 | + |
|
74 | + /** |
|
75 | + * message type used to generate the template being parsed. |
|
76 | + * |
|
77 | + * @since 4.5.0 |
|
78 | + * @var EE_message_type |
|
79 | + */ |
|
80 | + protected $_message_type; |
|
81 | + |
|
82 | + |
|
83 | + /** |
|
84 | + * context used for the template being parsed |
|
85 | + * |
|
86 | + * @since 4.5.0 |
|
87 | + * @var string |
|
88 | + */ |
|
89 | + protected $_context; |
|
90 | + |
|
91 | + |
|
92 | + /** |
|
93 | + * Specific Message Template Group ID |
|
94 | + * |
|
95 | + * @since 4.5.0 |
|
96 | + * @var int |
|
97 | + */ |
|
98 | + protected $_GRP_ID; |
|
99 | + |
|
100 | + |
|
101 | + /** |
|
102 | + * @since 4.9.0 |
|
103 | + * @type EE_Message |
|
104 | + */ |
|
105 | + protected $_message; |
|
106 | + |
|
107 | + |
|
108 | + /** |
|
109 | + * This will hold an instance of the EEH_Parse_Shortcodes helper that will be used when handling list type |
|
110 | + * shortcodes |
|
111 | + * |
|
112 | + * @var EEH_Parse_Shortcodes |
|
113 | + */ |
|
114 | + protected $_shortcode_helper; |
|
115 | + |
|
116 | + |
|
117 | + public function __construct() |
|
118 | + { |
|
119 | + $this->_set_defaults(); |
|
120 | + $this->_init_props(); |
|
121 | + } |
|
122 | + |
|
123 | + |
|
124 | + /** |
|
125 | + * This sets the defaults for the properties. Child classes will override these properties in their _init_props |
|
126 | + * method |
|
127 | + */ |
|
128 | + private function _set_defaults() |
|
129 | + { |
|
130 | + $this->name = $this->description = ''; |
|
131 | + $this->_shortcodes = array(); |
|
132 | + $this->_set_shortcode_helper(); |
|
133 | + } |
|
134 | + |
|
135 | + |
|
136 | + /** |
|
137 | + * loads an instance of the EE_Shortcode_Parser helper when requested |
|
138 | + */ |
|
139 | + protected function _set_shortcode_helper() |
|
140 | + { |
|
141 | + // get shortcode_replace instance- set when _get_messages is called in child... |
|
142 | + $this->_shortcode_helper = new EEH_Parse_Shortcodes(); |
|
143 | + } |
|
144 | + |
|
145 | + |
|
146 | + public function get_shortcode_helper() |
|
147 | + { |
|
148 | + if (! $this->_shortcode_helper instanceof EEH_Parse_Shortcodes) { |
|
149 | + $this->_set_shortcode_helper(); |
|
150 | + } |
|
151 | + return $this->_shortcode_helper; |
|
152 | + } |
|
153 | + |
|
154 | + |
|
155 | + /** |
|
156 | + * This is the public method for kicking of the parser included with each child. It can be overridden by child |
|
157 | + * classes if necessary (see EE_Questions_Answers for example) |
|
158 | + * |
|
159 | + * @param string $shortcode incoming shortcode to be parsed |
|
160 | + * @param mixed (object|array) $data incoming data to be be used for parsing |
|
161 | + * @param mixed (object|array) $extra_data extra incoming data (usually EE_Messages_Addressee) |
|
162 | + * @return string parsed shortcode. |
|
163 | + */ |
|
164 | + public function parser($shortcode, $data, $extra_data = array()) |
|
165 | + { |
|
166 | + |
|
167 | + // filter setup shortcodes |
|
168 | + $this->_shortcodes = $this->get_shortcodes(); |
|
169 | + |
|
170 | + // we need to setup any dynamic shortcodes so that they work with the array_key_exists |
|
171 | + preg_match_all('/(\[[A-Za-z0-9\_]+_\*)/', $shortcode, $matches); |
|
172 | + $sc_to_verify = ! empty($matches[0]) ? $matches[0][0] . ']' : $shortcode; |
|
173 | + |
|
174 | + // first we want to make sure this is a valid shortcode |
|
175 | + if (! array_key_exists($sc_to_verify, $this->_shortcodes)) { |
|
176 | + return false; |
|
177 | + } //get out, this parser doesn't handle the incoming shortcode. |
|
178 | + $this->_data = $data; |
|
179 | + $this->_extra_data = $extra_data; |
|
180 | + $this->_set_messages_properties(); |
|
181 | + $parsed = apply_filters( |
|
182 | + 'FHEE__' . get_class($this) . '__parser_after', |
|
183 | + $this->_parser($shortcode), |
|
184 | + $shortcode, |
|
185 | + $data, |
|
186 | + $extra_data, |
|
187 | + $this |
|
188 | + ); |
|
189 | + |
|
190 | + // note the below filter applies to ALL shortcode parsers... be careful! |
|
191 | + return apply_filters('FHEE__EE_Shortcodes__parser_after', $parsed, $shortcode, $data, $extra_data, $this); |
|
192 | + } |
|
193 | + |
|
194 | + |
|
195 | + /** |
|
196 | + * This method just returns the shortcodes in the $_shortcodes array property. |
|
197 | + * |
|
198 | + * @access public |
|
199 | + * @return array array of shortcodes => description pairs |
|
200 | + */ |
|
201 | + public function get_shortcodes() |
|
202 | + { |
|
203 | + $this->_shortcodes = apply_filters('FHEE__' . get_class($this) . '__shortcodes', $this->_shortcodes, $this); |
|
204 | + |
|
205 | + // note the below filter applies to ALL shortcode parsers... be careful! |
|
206 | + $this->_shortcodes = apply_filters('FHEE__EE_Shortcodes__shortcodes', $this->_shortcodes, $this); |
|
207 | + |
|
208 | + return $this->_shortcodes; |
|
209 | + } |
|
210 | + |
|
211 | + |
|
212 | + /** |
|
213 | + * Child classes use this method to set the $name, $description, and $_shortcodes properties. |
|
214 | + * |
|
215 | + * @abstract |
|
216 | + * @access protected |
|
217 | + * @return void |
|
218 | + */ |
|
219 | + abstract protected function _init_props(); |
|
220 | + |
|
221 | + |
|
222 | + /** |
|
223 | + * This method will give parsing instructions for each shortcode defined in the _shortcodes array. Child methods |
|
224 | + * will have to take care of handling. |
|
225 | + * |
|
226 | + * @abstract |
|
227 | + * @access protected |
|
228 | + * @param string $shortcode the shortcode to be parsed. |
|
229 | + * @param mixed (object|array) $data incoming data for the parser. The data could be either an object or |
|
230 | + * array because there are some shortcodes that might be replaced by prepared data that |
|
231 | + * has multiple items in a list (i.e. list of attendees in an event and we're showing |
|
232 | + * fname/lname for each attendee). In this case data will be in an array. Otherwise |
|
233 | + * the data shoudl be in a properly formatted object. The |
|
234 | + * EEH_Parse_Shortcodes.helper.php describes the data object we're expecting. |
|
235 | + * @return string parsed shortcode |
|
236 | + */ |
|
237 | + abstract protected function _parser($shortcode); |
|
238 | + |
|
239 | + |
|
240 | + /** |
|
241 | + * This just validates incoming data for list type shortcode parsers (and they call this method) to make sure it |
|
242 | + * meets their requirements |
|
243 | + * |
|
244 | + * @return mixed (void|exception) If validation fails we'll throw an exception. |
|
245 | + */ |
|
246 | + protected function _validate_list_requirements() |
|
247 | + { |
|
248 | + |
|
249 | + // first test to make sure we've got an array! |
|
250 | + if (! is_array($this->_data)) { |
|
251 | + throw new EE_Error( |
|
252 | + sprintf( |
|
253 | + esc_html__( |
|
254 | + 'Expecting an array for the data sent to %s. Instead it was %s', |
|
255 | + 'event_espresso' |
|
256 | + ), |
|
257 | + get_class($this), |
|
258 | + gettype($this->_data) |
|
259 | + ) |
|
260 | + ); |
|
261 | + } |
|
262 | + |
|
263 | + // next test to make sure we've got the required template in the index! |
|
264 | + if (! isset($this->_data['template'])) { |
|
265 | + throw new EE_Error( |
|
266 | + sprintf( |
|
267 | + esc_html__( |
|
268 | + 'The incoming data does not have the required template index in its array', |
|
269 | + 'event_espresso' |
|
270 | + ) |
|
271 | + ) |
|
272 | + ); |
|
273 | + } |
|
274 | + |
|
275 | + // next test to make sure we've got got a data index in the incoming data array |
|
276 | + if (! isset($this->_data['data'])) { |
|
277 | + throw new EE_Error( |
|
278 | + esc_html__( |
|
279 | + 'The incoming data does not have the required data index in its array', |
|
280 | + 'event_espresso' |
|
281 | + ) |
|
282 | + ); |
|
283 | + } |
|
284 | + |
|
285 | + // all is well let's make sure _extra_data always has the values needed. |
|
286 | + // let's make sure that extra_data includes all templates (for later parsing if necessary) |
|
287 | + if (empty($this->_extra_data) || (empty($this->_extra_data['data']) && empty($this->_extra_data['template']))) { |
|
288 | + $this->_extra_data['data'] = $this->_data['data']; |
|
289 | + $this->_extra_data['template'] = $this->_data['template']; |
|
290 | + } |
|
291 | + } |
|
292 | + |
|
293 | + |
|
294 | + /** |
|
295 | + * This returns any attributes that may be existing on an EE_Shortcode |
|
296 | + * |
|
297 | + * @since 4.5.0 |
|
298 | + * @param string $shortcode incoming shortcode |
|
299 | + * @return array An array with the attributes |
|
300 | + */ |
|
301 | + protected function _get_shortcode_attrs($shortcode) |
|
302 | + { |
|
303 | + // make sure the required wp helper function is present |
|
304 | + // require the shortcode file if necessary |
|
305 | + if (! function_exists('shortcode_parse_atts')) { |
|
306 | + require_once(ABSPATH . WPINC . '/shortcodes.php'); |
|
307 | + } |
|
308 | + |
|
309 | + // let's get any attributes that may be present and set the defaults. |
|
310 | + $shortcode_to_parse = str_replace('[', '', str_replace(']', '', $shortcode)); |
|
311 | + return shortcode_parse_atts($shortcode_to_parse); |
|
312 | + } |
|
313 | + |
|
314 | + |
|
315 | + /** |
|
316 | + * Conditional blocks are shortcode patterns with an opening conditional tag `[IF_*]` and a corresponding |
|
317 | + * closing tag (eg `[/IF_*]`). The content within the tags will be displayed/hidden depending on whatever |
|
318 | + * conditions existed in the opening tag. This method handles parsing the actual template to show/hide this |
|
319 | + * conditional content. |
|
320 | + * |
|
321 | + * @since 4.9.32 |
|
322 | + * |
|
323 | + * @param string $shortcode This should be original shortcode as used in the template and passed to the parser. |
|
324 | + * @param bool $show true means the opening and closing tags are removed and the content is left showing, |
|
325 | + * false means the opening and closing tags and the contained content are removed. |
|
326 | + * @return string The template for the shortcode is returned. |
|
327 | + */ |
|
328 | + protected function _mutate_conditional_block_in_template($shortcode, $show = true) |
|
329 | + { |
|
330 | + // first let's get all the matches in the template for this particular shortcode. |
|
331 | + preg_match_all('~' . $this->_get_conditional_block_regex($shortcode) . '~', $this->_data['template'], $matches); |
|
332 | + |
|
333 | + if ($matches && is_array($matches[0]) && ! empty($matches[0])) { |
|
334 | + // we need to hide all instances of the matches |
|
335 | + foreach ($matches[0] as $index => $content_to_show_or_hide) { |
|
336 | + $content_to_show_or_hide = preg_quote($content_to_show_or_hide); |
|
337 | + $replacement = $show ? $matches[4][ $index ] : ''; |
|
338 | + $this->_data['template'] = preg_replace( |
|
339 | + '~' . $content_to_show_or_hide . '~', |
|
340 | + $replacement, |
|
341 | + $this->_data['template'] |
|
342 | + ); |
|
343 | + } |
|
344 | + } |
|
345 | + // return $template |
|
346 | + return $this->_data['template']; |
|
347 | + } |
|
348 | + |
|
349 | + |
|
350 | + /** |
|
351 | + * This returns the regex pattern to use for conditional shortcodes parsing. |
|
352 | + * |
|
353 | + * Note: regex comes in part from the WP `get_shortcode_regex` expression in \wp-includes\shortcodes.php |
|
354 | + * |
|
355 | + * @param $shortcode |
|
356 | + * @since 4.9.32 |
|
357 | + * @return string |
|
358 | + */ |
|
359 | + private function _get_conditional_block_regex($shortcode) |
|
360 | + { |
|
361 | + // get just the shortcode tag for the match |
|
362 | + preg_match('@\[([^<>&/\[\]\x00-\x20=]++)@', $shortcode, $shortcode_tag_matches); |
|
363 | + if (empty($shortcode_tag_matches[1])) { |
|
364 | + return $this->_data['template']; |
|
365 | + } |
|
366 | + |
|
367 | + $shortcode_tag = $shortcode_tag_matches[1]; |
|
368 | + // get attributes_part_of_tag |
|
369 | + $attributes_part = preg_quote(str_replace(array($shortcode_tag, '[', ']'), '', $shortcode)); |
|
370 | + // escape |
|
371 | + $shortcode_tag = preg_quote($shortcode_tag); |
|
372 | + |
|
373 | + return |
|
374 | + '\[' // Opening Bracket |
|
375 | + . "($shortcode_tag)$attributes_part" // 1: Shortcode Name |
|
376 | + . '(?![\w-])' // Not followed by word character or hyphen |
|
377 | + . '(' // 2: Unroll the loop: Inside the opening shortcode tag |
|
378 | + . '[^\]\/]*' // Not a closing bracket or forward slash |
|
379 | + . '(?:' |
|
380 | + . '\/(?!\])' // A forward slash not followed by a closing bracket |
|
381 | + . '[^\]\/]*' // Not a closing bracket or forward slash. |
|
382 | + . ')*?' |
|
383 | + . ')' |
|
384 | + . '(?:' |
|
385 | + . '(\/)' // 3. Self closing tag ... |
|
386 | + . '\]' // ... and closing bracket |
|
387 | + . '|' |
|
388 | + . '\]' // Closing bracket |
|
389 | + . '(?:' |
|
390 | + . '(' // 4: Unroll the loop: Optionally, anything between the opening and closing brackets |
|
391 | + . '[^\[]*+' // Not an opening bracket |
|
392 | + . '(?:' |
|
393 | + . '\[(?!\/\1\])' // An opening bracket not followed by the closing shortcode tag. |
|
394 | + . '[^\[]*+' // Not an opening bracket |
|
395 | + . ')*+' |
|
396 | + . ')' |
|
397 | + . '\[\/\1\]' // Closing shortcode tag |
|
398 | + . ')?' |
|
399 | + . ')'; |
|
400 | + } |
|
401 | + |
|
402 | + |
|
403 | + /** |
|
404 | + * This sets the properties related to the messages system |
|
405 | + * |
|
406 | + * @since 4.5.0 |
|
407 | + * @return void |
|
408 | + */ |
|
409 | + protected function _set_messages_properties() |
|
410 | + { |
|
411 | + // should be in _extra_data |
|
412 | + if (isset($this->_extra_data['messenger'])) { |
|
413 | + $this->_messenger = $this->_extra_data['messenger']; |
|
414 | + $this->_message_type = $this->_extra_data['message_type']; |
|
415 | + $this->_context = $this->_extra_data['message'] instanceof EE_Message |
|
416 | + ? $this->_extra_data['message']->context() : ''; |
|
417 | + $this->_GRP_ID = $this->_extra_data['message'] instanceof EE_Message |
|
418 | + ? $this->_extra_data['message']->GRP_ID() : 0; |
|
419 | + $this->_message = $this->_extra_data['message'] instanceof EE_Message ? $this->_extra_data['message'] |
|
420 | + : null; |
|
421 | + } |
|
422 | + } |
|
423 | + |
|
424 | + |
|
425 | + /** |
|
426 | + * This returns whatever the set message type object is that was set on this shortcode parser. |
|
427 | + * |
|
428 | + * @since 4.5.0 |
|
429 | + * @return EE_message_type |
|
430 | + */ |
|
431 | + public function get_set_message_type() |
|
432 | + { |
|
433 | + return $this->_message_type; |
|
434 | + } |
|
435 | + |
|
436 | + |
|
437 | + /** |
|
438 | + * This returns whatever the set messenger object is that was set on this shortcode parser |
|
439 | + * |
|
440 | + * @since 4.5.0 |
|
441 | + * @return EE_messenger |
|
442 | + */ |
|
443 | + public function get_set_messenger() |
|
444 | + { |
|
445 | + return $this->_messenger; |
|
446 | + } |
|
447 | + |
|
448 | + |
|
449 | + /** |
|
450 | + * This returns whatever the set context string is on this shortcode parser. |
|
451 | + * |
|
452 | + * @since 4.5.0 |
|
453 | + * @return string |
|
454 | + */ |
|
455 | + public function get_set_context() |
|
456 | + { |
|
457 | + return $this->_context; |
|
458 | + } |
|
459 | + |
|
460 | + |
|
461 | + /** |
|
462 | + * This returns whatever the set EE_Message object is on this shortcode. |
|
463 | + * |
|
464 | + * @since 4.9.0 |
|
465 | + * @return EE_Message |
|
466 | + */ |
|
467 | + public function get_set_message() |
|
468 | + { |
|
469 | + return $this->_message; |
|
470 | + } |
|
471 | 471 | } |
@@ -96,7 +96,7 @@ discard block |
||
96 | 96 | $id |
97 | 97 | ) { |
98 | 98 | // make sure this is ONLY when editing and the event id has been set. |
99 | - if (! empty($id)) { |
|
99 | + if ( ! empty($id)) { |
|
100 | 100 | $post = get_post($id); |
101 | 101 | // if NOT event then let's get out. |
102 | 102 | if ($post->post_type !== 'espresso_events') { |
@@ -169,8 +169,8 @@ discard block |
||
169 | 169 | : array($this->route_name => $embedButtonHtml) + $filterable_content; |
170 | 170 | } else { |
171 | 171 | $filterable_content = $this->append_filterable_content |
172 | - ? $filterable_content . $embedButtonHtml |
|
173 | - : $embedButtonHtml . $filterable_content; |
|
172 | + ? $filterable_content.$embedButtonHtml |
|
173 | + : $embedButtonHtml.$filterable_content; |
|
174 | 174 | } |
175 | 175 | return $filterable_content; |
176 | 176 | } |
@@ -195,7 +195,7 @@ discard block |
||
195 | 195 | $iframe_module_routes = isset(\EE_Registry::$i18n_js_strings['iframe_module_routes']) |
196 | 196 | ? \EE_Registry::$i18n_js_strings['iframe_module_routes'] |
197 | 197 | : array(); |
198 | - $iframe_module_routes[ $this->route_name ] = $this->route_name; |
|
198 | + $iframe_module_routes[$this->route_name] = $this->route_name; |
|
199 | 199 | \EE_Registry::$i18n_js_strings['iframe_module_routes'] = $iframe_module_routes; |
200 | 200 | $iframe_embed_html = \EEH_HTML::link( |
201 | 201 | '#', |
@@ -207,20 +207,20 @@ discard block |
||
207 | 207 | ), |
208 | 208 | \EEH_Inflector::add_indefinite_article($this->iframe_name) |
209 | 209 | ), |
210 | - esc_attr($this->route_name) . "-iframe-embed-trigger-js", |
|
211 | - 'iframe-embed-trigger-js button ' . esc_attr($button_class), |
|
210 | + esc_attr($this->route_name)."-iframe-embed-trigger-js", |
|
211 | + 'iframe-embed-trigger-js button '.esc_attr($button_class), |
|
212 | 212 | '', |
213 | - ' data-iframe_embed_button="#' . esc_attr($this->route_name) . '-iframe-js" tabindex="-1"' |
|
213 | + ' data-iframe_embed_button="#'.esc_attr($this->route_name).'-iframe-js" tabindex="-1"' |
|
214 | 214 | ); |
215 | 215 | $iframe_embed_html .= \EEH_HTML::div( |
216 | 216 | '', |
217 | - esc_attr($this->route_name) . "-iframe-js", |
|
217 | + esc_attr($this->route_name)."-iframe-js", |
|
218 | 218 | 'iframe-embed-wrapper-js', |
219 | 219 | 'display:none;' |
220 | 220 | ); |
221 | 221 | $iframe_embed_html .= esc_html( |
222 | 222 | \EEH_HTML::div( |
223 | - '<iframe src="' . esc_url_raw(add_query_arg($query_args, site_url())) . '" width="100%" height="100%"></iframe>', |
|
223 | + '<iframe src="'.esc_url_raw(add_query_arg($query_args, site_url())).'" width="100%" height="100%"></iframe>', |
|
224 | 224 | '', |
225 | 225 | '', |
226 | 226 | 'width:100%; height: 500px;' |
@@ -246,7 +246,7 @@ discard block |
||
246 | 246 | ); |
247 | 247 | wp_register_script( |
248 | 248 | 'iframe_embed_button', |
249 | - plugin_dir_url(__FILE__) . 'iframe-embed-button.js', |
|
249 | + plugin_dir_url(__FILE__).'iframe-embed-button.js', |
|
250 | 250 | array('ee-dialog'), |
251 | 251 | EVENT_ESPRESSO_VERSION, |
252 | 252 | true |
@@ -279,7 +279,7 @@ discard block |
||
279 | 279 | 'event_espresso' |
280 | 280 | ) |
281 | 281 | ); |
282 | - $html .= ' ' . implode(' ', $embed_buttons) . ' '; |
|
282 | + $html .= ' '.implode(' ', $embed_buttons).' '; |
|
283 | 283 | $html .= \EEH_HTML::br(2); |
284 | 284 | return $html; |
285 | 285 | } |
@@ -13,274 +13,274 @@ |
||
13 | 13 | */ |
14 | 14 | abstract class IframeEmbedButton |
15 | 15 | { |
16 | - /** |
|
17 | - * @var string $iframe_name |
|
18 | - */ |
|
19 | - private $iframe_name; |
|
16 | + /** |
|
17 | + * @var string $iframe_name |
|
18 | + */ |
|
19 | + private $iframe_name; |
|
20 | 20 | |
21 | - /** |
|
22 | - * @var string $route_name |
|
23 | - */ |
|
24 | - private $route_name; |
|
21 | + /** |
|
22 | + * @var string $route_name |
|
23 | + */ |
|
24 | + private $route_name; |
|
25 | 25 | |
26 | - /** |
|
27 | - * @var string $slug |
|
28 | - */ |
|
29 | - private $slug; |
|
26 | + /** |
|
27 | + * @var string $slug |
|
28 | + */ |
|
29 | + private $slug; |
|
30 | 30 | |
31 | - /** |
|
32 | - * @var boolean $append_filterable_content |
|
33 | - */ |
|
34 | - private $append_filterable_content; |
|
31 | + /** |
|
32 | + * @var boolean $append_filterable_content |
|
33 | + */ |
|
34 | + private $append_filterable_content; |
|
35 | 35 | |
36 | 36 | |
37 | - /** |
|
38 | - * IframeEmbedButton constructor. |
|
39 | - * |
|
40 | - * @param string $iframe_name i18n name for the iframe. This will be used in HTML |
|
41 | - * @param string $route_name the name of the registered route |
|
42 | - * @param string $slug URL slug used for the thing the iframe button is being embedded in. |
|
43 | - * will most likely be "event" since that's the only usage atm |
|
44 | - */ |
|
45 | - public function __construct($iframe_name, $route_name, $slug = 'event') |
|
46 | - { |
|
47 | - $this->iframe_name = $iframe_name; |
|
48 | - $this->route_name = $route_name; |
|
49 | - $this->slug = $slug; |
|
50 | - } |
|
37 | + /** |
|
38 | + * IframeEmbedButton constructor. |
|
39 | + * |
|
40 | + * @param string $iframe_name i18n name for the iframe. This will be used in HTML |
|
41 | + * @param string $route_name the name of the registered route |
|
42 | + * @param string $slug URL slug used for the thing the iframe button is being embedded in. |
|
43 | + * will most likely be "event" since that's the only usage atm |
|
44 | + */ |
|
45 | + public function __construct($iframe_name, $route_name, $slug = 'event') |
|
46 | + { |
|
47 | + $this->iframe_name = $iframe_name; |
|
48 | + $this->route_name = $route_name; |
|
49 | + $this->slug = $slug; |
|
50 | + } |
|
51 | 51 | |
52 | 52 | |
53 | - /** |
|
54 | - * Adds an iframe embed code button to the Event editor. |
|
55 | - */ |
|
56 | - public function addEventEditorIframeEmbedButtonFilter() |
|
57 | - { |
|
58 | - // add button for iframe code to event editor. |
|
59 | - add_filter( |
|
60 | - 'get_sample_permalink_html', |
|
61 | - array($this, 'appendIframeEmbedButtonToSamplePermalinkHtml'), |
|
62 | - 10, |
|
63 | - 2 |
|
64 | - ); |
|
65 | - add_action( |
|
66 | - 'admin_enqueue_scripts', |
|
67 | - array($this, 'embedButtonAssets'), |
|
68 | - 10 |
|
69 | - ); |
|
70 | - } |
|
53 | + /** |
|
54 | + * Adds an iframe embed code button to the Event editor. |
|
55 | + */ |
|
56 | + public function addEventEditorIframeEmbedButtonFilter() |
|
57 | + { |
|
58 | + // add button for iframe code to event editor. |
|
59 | + add_filter( |
|
60 | + 'get_sample_permalink_html', |
|
61 | + array($this, 'appendIframeEmbedButtonToSamplePermalinkHtml'), |
|
62 | + 10, |
|
63 | + 2 |
|
64 | + ); |
|
65 | + add_action( |
|
66 | + 'admin_enqueue_scripts', |
|
67 | + array($this, 'embedButtonAssets'), |
|
68 | + 10 |
|
69 | + ); |
|
70 | + } |
|
71 | 71 | |
72 | 72 | |
73 | - /** |
|
74 | - * @param $permalink_string |
|
75 | - * @param $id |
|
76 | - * @return string |
|
77 | - */ |
|
78 | - public function appendIframeEmbedButtonToSamplePermalinkHtml($permalink_string, $id) |
|
79 | - { |
|
80 | - return $this->eventEditorIframeEmbedButton( |
|
81 | - $permalink_string, |
|
82 | - $id |
|
83 | - ); |
|
84 | - } |
|
73 | + /** |
|
74 | + * @param $permalink_string |
|
75 | + * @param $id |
|
76 | + * @return string |
|
77 | + */ |
|
78 | + public function appendIframeEmbedButtonToSamplePermalinkHtml($permalink_string, $id) |
|
79 | + { |
|
80 | + return $this->eventEditorIframeEmbedButton( |
|
81 | + $permalink_string, |
|
82 | + $id |
|
83 | + ); |
|
84 | + } |
|
85 | 85 | |
86 | 86 | |
87 | - /** |
|
88 | - * iframe embed code button to the Event editor. |
|
89 | - * |
|
90 | - * @param string $permalink_string |
|
91 | - * @param int $id |
|
92 | - * @return string |
|
93 | - */ |
|
94 | - public function eventEditorIframeEmbedButton( |
|
95 | - $permalink_string, |
|
96 | - $id |
|
97 | - ) { |
|
98 | - // make sure this is ONLY when editing and the event id has been set. |
|
99 | - if (! empty($id)) { |
|
100 | - $post = get_post($id); |
|
101 | - // if NOT event then let's get out. |
|
102 | - if ($post->post_type !== 'espresso_events') { |
|
103 | - return $permalink_string; |
|
104 | - } |
|
105 | - $permalink_string .= $this->embedButtonHtml( |
|
106 | - array($this->slug => $id), |
|
107 | - 'button-small' |
|
108 | - ); |
|
109 | - } |
|
110 | - return $permalink_string; |
|
111 | - } |
|
87 | + /** |
|
88 | + * iframe embed code button to the Event editor. |
|
89 | + * |
|
90 | + * @param string $permalink_string |
|
91 | + * @param int $id |
|
92 | + * @return string |
|
93 | + */ |
|
94 | + public function eventEditorIframeEmbedButton( |
|
95 | + $permalink_string, |
|
96 | + $id |
|
97 | + ) { |
|
98 | + // make sure this is ONLY when editing and the event id has been set. |
|
99 | + if (! empty($id)) { |
|
100 | + $post = get_post($id); |
|
101 | + // if NOT event then let's get out. |
|
102 | + if ($post->post_type !== 'espresso_events') { |
|
103 | + return $permalink_string; |
|
104 | + } |
|
105 | + $permalink_string .= $this->embedButtonHtml( |
|
106 | + array($this->slug => $id), |
|
107 | + 'button-small' |
|
108 | + ); |
|
109 | + } |
|
110 | + return $permalink_string; |
|
111 | + } |
|
112 | 112 | |
113 | 113 | |
114 | - /** |
|
115 | - * Adds an iframe embed code button via a WP do_action() as determined by the first parameter |
|
116 | - * |
|
117 | - * @param string $action name of the WP do_action() to hook into |
|
118 | - */ |
|
119 | - public function addActionIframeEmbedButton($action) |
|
120 | - { |
|
121 | - // add button for iframe code to event editor. |
|
122 | - add_action( |
|
123 | - $action, |
|
124 | - array($this, 'addActionIframeEmbedButtonCallback'), |
|
125 | - 10, |
|
126 | - 2 |
|
127 | - ); |
|
128 | - } |
|
114 | + /** |
|
115 | + * Adds an iframe embed code button via a WP do_action() as determined by the first parameter |
|
116 | + * |
|
117 | + * @param string $action name of the WP do_action() to hook into |
|
118 | + */ |
|
119 | + public function addActionIframeEmbedButton($action) |
|
120 | + { |
|
121 | + // add button for iframe code to event editor. |
|
122 | + add_action( |
|
123 | + $action, |
|
124 | + array($this, 'addActionIframeEmbedButtonCallback'), |
|
125 | + 10, |
|
126 | + 2 |
|
127 | + ); |
|
128 | + } |
|
129 | 129 | |
130 | 130 | |
131 | - /** |
|
132 | - * @return void |
|
133 | - */ |
|
134 | - public function addActionIframeEmbedButtonCallback() |
|
135 | - { |
|
136 | - echo wp_kses($this->embedButtonHtml(), AllowedTags::getWithFormTags()); |
|
137 | - } |
|
131 | + /** |
|
132 | + * @return void |
|
133 | + */ |
|
134 | + public function addActionIframeEmbedButtonCallback() |
|
135 | + { |
|
136 | + echo wp_kses($this->embedButtonHtml(), AllowedTags::getWithFormTags()); |
|
137 | + } |
|
138 | 138 | |
139 | 139 | |
140 | - /** |
|
141 | - * Adds an iframe embed code button via a WP apply_filters() as determined by the first parameter |
|
142 | - * |
|
143 | - * @param string $filter name of the WP apply_filters() to hook into |
|
144 | - * @param bool $append if true, will add iframe embed button to end of content, |
|
145 | - * else if false, will add to the beginning of the content |
|
146 | - */ |
|
147 | - public function addFilterIframeEmbedButton($filter, $append = true) |
|
148 | - { |
|
149 | - $this->append_filterable_content = $append; |
|
150 | - // add button for iframe code to event editor. |
|
151 | - add_filter( |
|
152 | - $filter, |
|
153 | - array($this, 'addFilterIframeEmbedButtonCallback'), |
|
154 | - 10 |
|
155 | - ); |
|
156 | - } |
|
140 | + /** |
|
141 | + * Adds an iframe embed code button via a WP apply_filters() as determined by the first parameter |
|
142 | + * |
|
143 | + * @param string $filter name of the WP apply_filters() to hook into |
|
144 | + * @param bool $append if true, will add iframe embed button to end of content, |
|
145 | + * else if false, will add to the beginning of the content |
|
146 | + */ |
|
147 | + public function addFilterIframeEmbedButton($filter, $append = true) |
|
148 | + { |
|
149 | + $this->append_filterable_content = $append; |
|
150 | + // add button for iframe code to event editor. |
|
151 | + add_filter( |
|
152 | + $filter, |
|
153 | + array($this, 'addFilterIframeEmbedButtonCallback'), |
|
154 | + 10 |
|
155 | + ); |
|
156 | + } |
|
157 | 157 | |
158 | 158 | |
159 | - /** |
|
160 | - * @param array|string $filterable_content |
|
161 | - * @return array|string |
|
162 | - */ |
|
163 | - public function addFilterIframeEmbedButtonCallback($filterable_content) |
|
164 | - { |
|
165 | - $embedButtonHtml = $this->embedButtonHtml(); |
|
166 | - if (is_array($filterable_content)) { |
|
167 | - $filterable_content = $this->append_filterable_content |
|
168 | - ? $filterable_content + array($this->route_name => $embedButtonHtml) |
|
169 | - : array($this->route_name => $embedButtonHtml) + $filterable_content; |
|
170 | - } else { |
|
171 | - $filterable_content = $this->append_filterable_content |
|
172 | - ? $filterable_content . $embedButtonHtml |
|
173 | - : $embedButtonHtml . $filterable_content; |
|
174 | - } |
|
175 | - return $filterable_content; |
|
176 | - } |
|
159 | + /** |
|
160 | + * @param array|string $filterable_content |
|
161 | + * @return array|string |
|
162 | + */ |
|
163 | + public function addFilterIframeEmbedButtonCallback($filterable_content) |
|
164 | + { |
|
165 | + $embedButtonHtml = $this->embedButtonHtml(); |
|
166 | + if (is_array($filterable_content)) { |
|
167 | + $filterable_content = $this->append_filterable_content |
|
168 | + ? $filterable_content + array($this->route_name => $embedButtonHtml) |
|
169 | + : array($this->route_name => $embedButtonHtml) + $filterable_content; |
|
170 | + } else { |
|
171 | + $filterable_content = $this->append_filterable_content |
|
172 | + ? $filterable_content . $embedButtonHtml |
|
173 | + : $embedButtonHtml . $filterable_content; |
|
174 | + } |
|
175 | + return $filterable_content; |
|
176 | + } |
|
177 | 177 | |
178 | 178 | |
179 | - /** |
|
180 | - * iframe_embed_html |
|
181 | - * |
|
182 | - * @param array $query_args |
|
183 | - * @param string $button_class |
|
184 | - * @return string |
|
185 | - */ |
|
186 | - public function embedButtonHtml($query_args = array(), $button_class = '') |
|
187 | - { |
|
188 | - // incoming args will replace the defaults listed here in the second array (union preserves first array) |
|
189 | - $query_args = (array) $query_args + array($this->route_name => 'iframe'); |
|
190 | - $query_args = (array) apply_filters( |
|
191 | - 'FHEE__EventEspresso_core_libraries_iframe_display_IframeEmbedButton__embedButtonHtml__query_args', |
|
192 | - $query_args |
|
193 | - ); |
|
194 | - // add this route to our localized vars |
|
195 | - $iframe_module_routes = isset(\EE_Registry::$i18n_js_strings['iframe_module_routes']) |
|
196 | - ? \EE_Registry::$i18n_js_strings['iframe_module_routes'] |
|
197 | - : array(); |
|
198 | - $iframe_module_routes[ $this->route_name ] = $this->route_name; |
|
199 | - \EE_Registry::$i18n_js_strings['iframe_module_routes'] = $iframe_module_routes; |
|
200 | - $iframe_embed_html = \EEH_HTML::link( |
|
201 | - '#', |
|
202 | - sprintf(esc_html__('Embed %1$s', 'event_espresso'), $this->iframe_name), |
|
203 | - sprintf( |
|
204 | - esc_html__( |
|
205 | - 'click here to generate code for embedding %1$s iframe into another site.', |
|
206 | - 'event_espresso' |
|
207 | - ), |
|
208 | - \EEH_Inflector::add_indefinite_article($this->iframe_name) |
|
209 | - ), |
|
210 | - esc_attr($this->route_name) . "-iframe-embed-trigger-js", |
|
211 | - 'iframe-embed-trigger-js button ' . esc_attr($button_class), |
|
212 | - '', |
|
213 | - ' data-iframe_embed_button="#' . esc_attr($this->route_name) . '-iframe-js" tabindex="-1"' |
|
214 | - ); |
|
215 | - $iframe_embed_html .= \EEH_HTML::div( |
|
216 | - '', |
|
217 | - esc_attr($this->route_name) . "-iframe-js", |
|
218 | - 'iframe-embed-wrapper-js', |
|
219 | - 'display:none;' |
|
220 | - ); |
|
221 | - $iframe_embed_html .= esc_html( |
|
222 | - \EEH_HTML::div( |
|
223 | - '<iframe src="' . esc_url_raw(add_query_arg($query_args, site_url())) . '" width="100%" height="100%"></iframe>', |
|
224 | - '', |
|
225 | - '', |
|
226 | - 'width:100%; height: 500px;' |
|
227 | - ) |
|
228 | - ); |
|
229 | - $iframe_embed_html .= \EEH_HTML::divx(); |
|
230 | - return $iframe_embed_html; |
|
231 | - } |
|
179 | + /** |
|
180 | + * iframe_embed_html |
|
181 | + * |
|
182 | + * @param array $query_args |
|
183 | + * @param string $button_class |
|
184 | + * @return string |
|
185 | + */ |
|
186 | + public function embedButtonHtml($query_args = array(), $button_class = '') |
|
187 | + { |
|
188 | + // incoming args will replace the defaults listed here in the second array (union preserves first array) |
|
189 | + $query_args = (array) $query_args + array($this->route_name => 'iframe'); |
|
190 | + $query_args = (array) apply_filters( |
|
191 | + 'FHEE__EventEspresso_core_libraries_iframe_display_IframeEmbedButton__embedButtonHtml__query_args', |
|
192 | + $query_args |
|
193 | + ); |
|
194 | + // add this route to our localized vars |
|
195 | + $iframe_module_routes = isset(\EE_Registry::$i18n_js_strings['iframe_module_routes']) |
|
196 | + ? \EE_Registry::$i18n_js_strings['iframe_module_routes'] |
|
197 | + : array(); |
|
198 | + $iframe_module_routes[ $this->route_name ] = $this->route_name; |
|
199 | + \EE_Registry::$i18n_js_strings['iframe_module_routes'] = $iframe_module_routes; |
|
200 | + $iframe_embed_html = \EEH_HTML::link( |
|
201 | + '#', |
|
202 | + sprintf(esc_html__('Embed %1$s', 'event_espresso'), $this->iframe_name), |
|
203 | + sprintf( |
|
204 | + esc_html__( |
|
205 | + 'click here to generate code for embedding %1$s iframe into another site.', |
|
206 | + 'event_espresso' |
|
207 | + ), |
|
208 | + \EEH_Inflector::add_indefinite_article($this->iframe_name) |
|
209 | + ), |
|
210 | + esc_attr($this->route_name) . "-iframe-embed-trigger-js", |
|
211 | + 'iframe-embed-trigger-js button ' . esc_attr($button_class), |
|
212 | + '', |
|
213 | + ' data-iframe_embed_button="#' . esc_attr($this->route_name) . '-iframe-js" tabindex="-1"' |
|
214 | + ); |
|
215 | + $iframe_embed_html .= \EEH_HTML::div( |
|
216 | + '', |
|
217 | + esc_attr($this->route_name) . "-iframe-js", |
|
218 | + 'iframe-embed-wrapper-js', |
|
219 | + 'display:none;' |
|
220 | + ); |
|
221 | + $iframe_embed_html .= esc_html( |
|
222 | + \EEH_HTML::div( |
|
223 | + '<iframe src="' . esc_url_raw(add_query_arg($query_args, site_url())) . '" width="100%" height="100%"></iframe>', |
|
224 | + '', |
|
225 | + '', |
|
226 | + 'width:100%; height: 500px;' |
|
227 | + ) |
|
228 | + ); |
|
229 | + $iframe_embed_html .= \EEH_HTML::divx(); |
|
230 | + return $iframe_embed_html; |
|
231 | + } |
|
232 | 232 | |
233 | 233 | |
234 | - /** |
|
235 | - * enqueue iframe button js |
|
236 | - */ |
|
237 | - public function embedButtonAssets() |
|
238 | - { |
|
239 | - \EE_Registry::$i18n_js_strings['iframe_embed_title'] = esc_html__( |
|
240 | - 'copy and paste the following into any other site\'s content to display this event:', |
|
241 | - 'event_espresso' |
|
242 | - ); |
|
243 | - \EE_Registry::$i18n_js_strings['iframe_embed_close_msg'] = esc_html__( |
|
244 | - 'click anywhere outside of this window to close it.', |
|
245 | - 'event_espresso' |
|
246 | - ); |
|
247 | - wp_register_script( |
|
248 | - 'iframe_embed_button', |
|
249 | - plugin_dir_url(__FILE__) . 'iframe-embed-button.js', |
|
250 | - array('ee-dialog'), |
|
251 | - EVENT_ESPRESSO_VERSION, |
|
252 | - true |
|
253 | - ); |
|
254 | - wp_enqueue_script('iframe_embed_button'); |
|
255 | - } |
|
234 | + /** |
|
235 | + * enqueue iframe button js |
|
236 | + */ |
|
237 | + public function embedButtonAssets() |
|
238 | + { |
|
239 | + \EE_Registry::$i18n_js_strings['iframe_embed_title'] = esc_html__( |
|
240 | + 'copy and paste the following into any other site\'s content to display this event:', |
|
241 | + 'event_espresso' |
|
242 | + ); |
|
243 | + \EE_Registry::$i18n_js_strings['iframe_embed_close_msg'] = esc_html__( |
|
244 | + 'click anywhere outside of this window to close it.', |
|
245 | + 'event_espresso' |
|
246 | + ); |
|
247 | + wp_register_script( |
|
248 | + 'iframe_embed_button', |
|
249 | + plugin_dir_url(__FILE__) . 'iframe-embed-button.js', |
|
250 | + array('ee-dialog'), |
|
251 | + EVENT_ESPRESSO_VERSION, |
|
252 | + true |
|
253 | + ); |
|
254 | + wp_enqueue_script('iframe_embed_button'); |
|
255 | + } |
|
256 | 256 | |
257 | 257 | |
258 | - /** |
|
259 | - * generates embed button sections for admin pages |
|
260 | - * |
|
261 | - * @param array $embed_buttons |
|
262 | - * @return string |
|
263 | - */ |
|
264 | - public function addIframeEmbedButtonsSection(array $embed_buttons) |
|
265 | - { |
|
266 | - $embed_buttons = (array) apply_filters( |
|
267 | - 'FHEE__EventEspresso_core_libraries_iframe_display_IframeEmbedButton__addIframeEmbedButtonsSection__embed_buttons', |
|
268 | - $embed_buttons |
|
269 | - ); |
|
270 | - if (empty($embed_buttons)) { |
|
271 | - return ''; |
|
272 | - } |
|
273 | - // add button for iframe code to event editor. |
|
274 | - $html = \EEH_HTML::br(2); |
|
275 | - $html .= \EEH_HTML::h3(esc_html__('iFrame Embed Code', 'event_espresso')); |
|
276 | - $html .= \EEH_HTML::p( |
|
277 | - esc_html__( |
|
278 | - 'Click the following button(s) to generate iframe HTML that will allow you to embed your event content within the content of other websites.', |
|
279 | - 'event_espresso' |
|
280 | - ) |
|
281 | - ); |
|
282 | - $html .= ' ' . implode(' ', $embed_buttons) . ' '; |
|
283 | - $html .= \EEH_HTML::br(2); |
|
284 | - return $html; |
|
285 | - } |
|
258 | + /** |
|
259 | + * generates embed button sections for admin pages |
|
260 | + * |
|
261 | + * @param array $embed_buttons |
|
262 | + * @return string |
|
263 | + */ |
|
264 | + public function addIframeEmbedButtonsSection(array $embed_buttons) |
|
265 | + { |
|
266 | + $embed_buttons = (array) apply_filters( |
|
267 | + 'FHEE__EventEspresso_core_libraries_iframe_display_IframeEmbedButton__addIframeEmbedButtonsSection__embed_buttons', |
|
268 | + $embed_buttons |
|
269 | + ); |
|
270 | + if (empty($embed_buttons)) { |
|
271 | + return ''; |
|
272 | + } |
|
273 | + // add button for iframe code to event editor. |
|
274 | + $html = \EEH_HTML::br(2); |
|
275 | + $html .= \EEH_HTML::h3(esc_html__('iFrame Embed Code', 'event_espresso')); |
|
276 | + $html .= \EEH_HTML::p( |
|
277 | + esc_html__( |
|
278 | + 'Click the following button(s) to generate iframe HTML that will allow you to embed your event content within the content of other websites.', |
|
279 | + 'event_espresso' |
|
280 | + ) |
|
281 | + ); |
|
282 | + $html .= ' ' . implode(' ', $embed_buttons) . ' '; |
|
283 | + $html .= \EEH_HTML::br(2); |
|
284 | + return $html; |
|
285 | + } |
|
286 | 286 | } |