Completed
Branch fix/kses-8 (0ad23b)
by
unknown
02:28
created
core/helpers/EEH_Event_View.helper.php 1 patch
Indentation   +614 added lines, -614 removed lines patch added patch discarded remove patch
@@ -10,364 +10,364 @@  discard block
 block discarded – undo
10 10
 class EEH_Event_View extends EEH_Base
11 11
 {
12 12
 
13
-    /**
14
-     * @var EE_Event $_event
15
-     */
16
-    private static $_event = null;
17
-
18
-
19
-    /**
20
-     * get_event
21
-     * attempts to retrieve an EE_Event object any way it can
22
-     *
23
-     * @param int|WP_Post $EVT_ID
24
-     * @return EE_Event|null
25
-     * @throws EE_Error
26
-     * @throws ReflectionException
27
-     */
28
-    public static function get_event($EVT_ID = 0)
29
-    {
30
-        // international newspaper?
31
-        global $post;
32
-        $EVT_ID = $EVT_ID instanceof WP_Post && $EVT_ID->post_type === 'espresso_events'
33
-            ? $EVT_ID->ID
34
-            : absint($EVT_ID);
35
-        // do we already have the Event  you are looking for?
36
-        if (EEH_Event_View::$_event instanceof EE_Event && $EVT_ID && EEH_Event_View::$_event->ID() === $EVT_ID) {
37
-            return EEH_Event_View::$_event;
38
-        }
39
-        // reset property so that the new event is cached.
40
-        EEH_Event_View::$_event = null;
41
-        if (! $EVT_ID && $post instanceof EE_Event) {
42
-            EEH_Event_View::$_event = $post;
43
-            return EEH_Event_View::$_event;
44
-        }
45
-        // if the post type is for an event and it has a cached event and we don't have a different incoming $EVT_ID
46
-        // then let's just use that cached event on the $post object.
47
-        if (
48
-            $post instanceof WP_Post
49
-            && $post->post_type === 'espresso_events'
50
-            && isset($post->EE_Event)
51
-            && (
52
-                $EVT_ID === 0
53
-                || $EVT_ID === $post->ID
54
-            )
55
-        ) {
56
-            EEH_Event_View::$_event = $post->EE_Event;
57
-            return EEH_Event_View::$_event;
58
-        }
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) {
61
-            EEH_Event_View::$_event = EEM_Event::instance()->get_one_by_ID($EVT_ID);
62
-        }
63
-        return EEH_Event_View::$_event;
64
-    }
65
-
66
-
67
-    /**
68
-     *    display_ticket_selector
69
-     *
70
-     * @param int $EVT_ID
71
-     * @return    boolean
72
-     * @throws EE_Error
73
-     * @throws EE_Error
74
-     * @throws ReflectionException
75
-     */
76
-    public static function display_ticket_selector($EVT_ID = 0)
77
-    {
78
-        $event = EEH_Event_View::get_event($EVT_ID);
79
-        return $event instanceof EE_Event && $event->display_ticket_selector();
80
-    }
81
-
82
-
83
-    /**
84
-     *    event_status
85
-     *
86
-     * @param int $EVT_ID
87
-     * @return    string
88
-     * @throws EE_Error
89
-     * @throws EE_Error
90
-     * @throws ReflectionException
91
-     */
92
-    public static function event_status($EVT_ID = 0)
93
-    {
94
-        $event = EEH_Event_View::get_event($EVT_ID);
95
-        return $event instanceof EE_Event ? $event->pretty_active_status(false) : '';
96
-    }
97
-
98
-
99
-    /**
100
-     *  event_active_status
101
-     *
102
-     * @param int $EVT_ID
103
-     * @return     string
104
-     * @throws EE_Error
105
-     * @throws EE_Error
106
-     * @throws ReflectionException
107
-     */
108
-    public static function event_active_status($EVT_ID = 0, $echo = true)
109
-    {
110
-        $event = EEH_Event_View::get_event($EVT_ID);
111
-        return $event instanceof EE_Event ? $event->pretty_active_status($echo) : 'inactive';
112
-    }
113
-
114
-
115
-    /**
116
-     *  event_has_content_or_excerpt
117
-     *
118
-     * @param int $EVT_ID
119
-     * @return     bool
120
-     * @throws EE_Error
121
-     * @throws EE_Error
122
-     * @throws ReflectionException
123
-     */
124
-    public static function event_has_content_or_excerpt($EVT_ID = 0)
125
-    {
126
-        $event                  = EEH_Event_View::get_event($EVT_ID);
127
-        $has_content_or_excerpt = false;
128
-        if ($event instanceof EE_Event) {
129
-            $has_content_or_excerpt = $event->description() != '' || $event->short_description(null, null, true) != '';
130
-        }
131
-        if (
132
-            is_archive()
133
-            && ! (espresso_display_full_description_in_event_list()
134
-                  || espresso_display_excerpt_in_event_list())
135
-        ) {
136
-            $has_content_or_excerpt = false;
137
-        }
138
-        return $has_content_or_excerpt;
139
-    }
140
-
141
-
142
-    /**
143
-     *    event_active_status
144
-     *
145
-     * @param null $num_words
146
-     * @param null $more
147
-     * @return    string
148
-     */
149
-    public static function event_content_or_excerpt($num_words = null, $more = null)
150
-    {
151
-        global $post;
152
-        ob_start();
153
-        if ((is_single()) || (is_archive() && espresso_display_full_description_in_event_list())) {
154
-            // admin has chosen "full description"
155
-            // for the "Event Espresso - Events > Templates > Display Description" option
156
-            the_content();
157
-        } elseif ((is_archive() && espresso_display_excerpt_in_event_list())) {
158
-            if (has_excerpt($post->ID)) {
159
-                // admin has chosen "excerpt (short desc)"
160
-                // for the "Event Espresso - Events > Templates > Display Description" option
161
-                // AND an excerpt actually exists
162
-                the_excerpt();
163
-            } else {
164
-                // admin has chosen "excerpt (short desc)"
165
-                // for the "Event Espresso - Events > Templates > Display Description" option
166
-                // but NO excerpt actually exists, so we need to create one
167
-                if (! empty($num_words)) {
168
-                    if (empty($more)) {
169
-                        $more_link_text = esc_html__('(more…)', 'event_espresso');
170
-                        $more           = ' <a href="' . get_permalink() . '"';
171
-                        $more           .= ' class="more-link"';
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);
175
-                    }
176
-                    $content = str_replace('NOMORELINK', '', get_the_content('NOMORELINK'));
177
-
178
-                    $content = wp_trim_words($content, $num_words, ' ') . $more;
179
-                } else {
180
-                    $content = get_the_content();
181
-                }
182
-                global $allowedtags;
183
-                // make sure links are allowed
184
-                $allowedtags['a'] = isset($allowedtags['a'])
185
-                    ? $allowedtags['a']
186
-                    : [];
187
-                // as well as target attribute
188
-                $allowedtags['a']['target'] = isset($allowedtags['a']['target'])
189
-                    ? $allowedtags['a']['target']
190
-                    : false;
191
-                // but get previous value so we can reset it
192
-                $prev_value                 = $allowedtags['a']['target'];
193
-                $allowedtags['a']['target'] = true;
194
-                $content                    = wp_kses($content, $allowedtags);
195
-                $content                    = strip_shortcodes($content);
196
-                echo apply_filters('the_content', $content);
197
-                $allowedtags['a']['target'] = $prev_value;
198
-            }
199
-        } else {
200
-            // admin has chosen "none"
201
-            // for the "Event Espresso - Events > Templates > Display Description" option
202
-            echo apply_filters('the_content', '');
203
-        }
204
-        return ob_get_clean();
205
-    }
206
-
207
-
208
-    /**
209
-     *  event_tickets_available
210
-     *
211
-     * @param int $EVT_ID
212
-     * @return     EE_Ticket[]
213
-     * @throws EE_Error
214
-     * @throws ReflectionException
215
-     */
216
-    public static function event_tickets_available($EVT_ID = 0)
217
-    {
218
-        $event                          = EEH_Event_View::get_event($EVT_ID);
219
-        $tickets_available_for_purchase = [];
220
-        if ($event instanceof EE_Event) {
221
-            $datetimes = EEH_Event_View::get_all_date_obj($EVT_ID, false);
222
-            foreach ($datetimes as $datetime) {
223
-                $tickets_available_for_purchase =
224
-                    array_merge($tickets_available_for_purchase, $datetime->ticket_types_available_for_purchase());
225
-            }
226
-        }
227
-        return $tickets_available_for_purchase;
228
-    }
229
-
230
-
231
-    /**
232
-     *    the_event_date
233
-     *
234
-     * @param int  $EVT_ID
235
-     * @param bool $hide_uncategorized
236
-     * @return    string
237
-     * @throws EE_Error
238
-     * @throws ReflectionException
239
-     */
240
-    public static function event_categories($EVT_ID = 0, $hide_uncategorized = true)
241
-    {
242
-        $category_links = [];
243
-        $event          = EEH_Event_View::get_event($EVT_ID);
244
-        if ($event instanceof EE_Event) {
245
-            $event_categories = get_the_terms($event->ID(), 'espresso_event_categories');
246
-            if ($event_categories) {
247
-                // loop thru terms and create links
248
-                foreach ($event_categories as $term) {
249
-                    $url = get_term_link($term, 'espresso_venue_categories');
250
-                    if (
251
-                        ! is_wp_error($url)
252
-                        && (
253
-                            (
254
-                                $hide_uncategorized
255
-                                && strtolower($term->name) != esc_html__('uncategorized', 'event_espresso')
256
-                            )
257
-                            || ! $hide_uncategorized
258
-                        )
259
-                    ) {
260
-                        $category_links[] = '<a href="' . esc_url_raw($url) . '" '
261
-                                            . 'rel="tag" ' . EED_Events_Archive::link_target() . '>'
262
-                                            . esc_html($term->name)
263
-                                            . '</a>';
264
-                    }
265
-                }
266
-            }
267
-        }
268
-        return implode(', ', $category_links);
269
-    }
270
-
271
-
272
-    /**
273
-     *    the_event_date - first date by date order
274
-     *
275
-     * @param string $date_format
276
-     * @param string $time_format
277
-     * @param int    $EVT_ID
278
-     * @return    string
279
-     * @throws EE_Error
280
-     * @throws ReflectionException
281
-     */
282
-    public static function the_event_date($date_format = 'D M jS', $time_format = 'g:i a', $EVT_ID = 0)
283
-    {
284
-        $datetime = EEH_Event_View::get_primary_date_obj($EVT_ID);
285
-        $format   = ! empty($date_format) && ! empty($time_format)
286
-                ? $date_format . ' ' . $time_format
287
-                : $date_format . $time_format;
288
-        return $datetime instanceof EE_Datetime ? $datetime->get_i18n_datetime('DTT_EVT_start', $format) : '';
289
-    }
290
-
291
-
292
-    /**
293
-     *    the_event_end_date - last date by date order
294
-     *
295
-     * @param string $date_format
296
-     * @param string $time_format
297
-     * @param int    $EVT_ID
298
-     * @return    string
299
-     * @throws EE_Error
300
-     * @throws ReflectionException
301
-     */
302
-    public static function the_event_end_date($date_format = 'D M jS', $time_format = 'g:i a', $EVT_ID = 0)
303
-    {
304
-        $datetime = EEH_Event_View::get_last_date_obj($EVT_ID);
305
-        $format   =
306
-            ! empty($date_format) && ! empty($time_format)
307
-                ? $date_format . ' ' . $time_format
308
-                : $date_format
309
-                  . $time_format;
310
-        return $datetime instanceof EE_Datetime ? $datetime->get_i18n_datetime('DTT_EVT_end', $format) : '';
311
-    }
312
-
313
-
314
-    /**
315
-     *    the_earliest_event_date - first date chronologically
316
-     *
317
-     * @param string $date_format
318
-     * @param string $time_format
319
-     * @param int    $EVT_ID
320
-     * @return    string
321
-     * @throws EE_Error
322
-     * @throws ReflectionException
323
-     */
324
-    public static function the_earliest_event_date($date_format = 'D M jS', $time_format = 'g:i a', $EVT_ID = 0)
325
-    {
326
-        $datetime = EEH_Event_View::get_earliest_date_obj($EVT_ID);
327
-        $format   =
328
-            ! empty($date_format) && ! empty($time_format)
329
-                ? $date_format . ' ' . $time_format
330
-                : $date_format
331
-                  . $time_format;
332
-        return $datetime instanceof EE_Datetime ? $datetime->get_i18n_datetime('DTT_EVT_start', $format) : '';
333
-    }
334
-
335
-
336
-    /**
337
-     *    the_latest_event_date - latest date chronologically
338
-     *
339
-     * @param string $date_format
340
-     * @param string $time_format
341
-     * @param int    $EVT_ID
342
-     * @return    string
343
-     * @throws EE_Error
344
-     * @throws ReflectionException
345
-     */
346
-    public static function the_latest_event_date($date_format = 'D M jS', $time_format = 'g:i a', $EVT_ID = 0)
347
-    {
348
-        $datetime = EEH_Event_View::get_latest_date_obj($EVT_ID);
349
-        $format   =
350
-            ! empty($date_format) && ! empty($time_format)
351
-                ? $date_format . ' ' . $time_format
352
-                : $date_format
353
-                  . $time_format;
354
-        return $datetime instanceof EE_Datetime ? $datetime->get_i18n_datetime('DTT_EVT_end', $format) : '';
355
-    }
356
-
357
-
358
-    /**
359
-     *    event_date_as_calendar_page
360
-     *
361
-     * @param int $EVT_ID
362
-     * @return    void
363
-     * @throws EE_Error
364
-     * @throws ReflectionException
365
-     */
366
-    public static function event_date_as_calendar_page($EVT_ID = 0)
367
-    {
368
-        $datetime = EEH_Event_View::get_primary_date_obj($EVT_ID);
369
-        if ($datetime instanceof EE_Datetime) {
370
-            ?>
13
+	/**
14
+	 * @var EE_Event $_event
15
+	 */
16
+	private static $_event = null;
17
+
18
+
19
+	/**
20
+	 * get_event
21
+	 * attempts to retrieve an EE_Event object any way it can
22
+	 *
23
+	 * @param int|WP_Post $EVT_ID
24
+	 * @return EE_Event|null
25
+	 * @throws EE_Error
26
+	 * @throws ReflectionException
27
+	 */
28
+	public static function get_event($EVT_ID = 0)
29
+	{
30
+		// international newspaper?
31
+		global $post;
32
+		$EVT_ID = $EVT_ID instanceof WP_Post && $EVT_ID->post_type === 'espresso_events'
33
+			? $EVT_ID->ID
34
+			: absint($EVT_ID);
35
+		// do we already have the Event  you are looking for?
36
+		if (EEH_Event_View::$_event instanceof EE_Event && $EVT_ID && EEH_Event_View::$_event->ID() === $EVT_ID) {
37
+			return EEH_Event_View::$_event;
38
+		}
39
+		// reset property so that the new event is cached.
40
+		EEH_Event_View::$_event = null;
41
+		if (! $EVT_ID && $post instanceof EE_Event) {
42
+			EEH_Event_View::$_event = $post;
43
+			return EEH_Event_View::$_event;
44
+		}
45
+		// if the post type is for an event and it has a cached event and we don't have a different incoming $EVT_ID
46
+		// then let's just use that cached event on the $post object.
47
+		if (
48
+			$post instanceof WP_Post
49
+			&& $post->post_type === 'espresso_events'
50
+			&& isset($post->EE_Event)
51
+			&& (
52
+				$EVT_ID === 0
53
+				|| $EVT_ID === $post->ID
54
+			)
55
+		) {
56
+			EEH_Event_View::$_event = $post->EE_Event;
57
+			return EEH_Event_View::$_event;
58
+		}
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) {
61
+			EEH_Event_View::$_event = EEM_Event::instance()->get_one_by_ID($EVT_ID);
62
+		}
63
+		return EEH_Event_View::$_event;
64
+	}
65
+
66
+
67
+	/**
68
+	 *    display_ticket_selector
69
+	 *
70
+	 * @param int $EVT_ID
71
+	 * @return    boolean
72
+	 * @throws EE_Error
73
+	 * @throws EE_Error
74
+	 * @throws ReflectionException
75
+	 */
76
+	public static function display_ticket_selector($EVT_ID = 0)
77
+	{
78
+		$event = EEH_Event_View::get_event($EVT_ID);
79
+		return $event instanceof EE_Event && $event->display_ticket_selector();
80
+	}
81
+
82
+
83
+	/**
84
+	 *    event_status
85
+	 *
86
+	 * @param int $EVT_ID
87
+	 * @return    string
88
+	 * @throws EE_Error
89
+	 * @throws EE_Error
90
+	 * @throws ReflectionException
91
+	 */
92
+	public static function event_status($EVT_ID = 0)
93
+	{
94
+		$event = EEH_Event_View::get_event($EVT_ID);
95
+		return $event instanceof EE_Event ? $event->pretty_active_status(false) : '';
96
+	}
97
+
98
+
99
+	/**
100
+	 *  event_active_status
101
+	 *
102
+	 * @param int $EVT_ID
103
+	 * @return     string
104
+	 * @throws EE_Error
105
+	 * @throws EE_Error
106
+	 * @throws ReflectionException
107
+	 */
108
+	public static function event_active_status($EVT_ID = 0, $echo = true)
109
+	{
110
+		$event = EEH_Event_View::get_event($EVT_ID);
111
+		return $event instanceof EE_Event ? $event->pretty_active_status($echo) : 'inactive';
112
+	}
113
+
114
+
115
+	/**
116
+	 *  event_has_content_or_excerpt
117
+	 *
118
+	 * @param int $EVT_ID
119
+	 * @return     bool
120
+	 * @throws EE_Error
121
+	 * @throws EE_Error
122
+	 * @throws ReflectionException
123
+	 */
124
+	public static function event_has_content_or_excerpt($EVT_ID = 0)
125
+	{
126
+		$event                  = EEH_Event_View::get_event($EVT_ID);
127
+		$has_content_or_excerpt = false;
128
+		if ($event instanceof EE_Event) {
129
+			$has_content_or_excerpt = $event->description() != '' || $event->short_description(null, null, true) != '';
130
+		}
131
+		if (
132
+			is_archive()
133
+			&& ! (espresso_display_full_description_in_event_list()
134
+				  || espresso_display_excerpt_in_event_list())
135
+		) {
136
+			$has_content_or_excerpt = false;
137
+		}
138
+		return $has_content_or_excerpt;
139
+	}
140
+
141
+
142
+	/**
143
+	 *    event_active_status
144
+	 *
145
+	 * @param null $num_words
146
+	 * @param null $more
147
+	 * @return    string
148
+	 */
149
+	public static function event_content_or_excerpt($num_words = null, $more = null)
150
+	{
151
+		global $post;
152
+		ob_start();
153
+		if ((is_single()) || (is_archive() && espresso_display_full_description_in_event_list())) {
154
+			// admin has chosen "full description"
155
+			// for the "Event Espresso - Events > Templates > Display Description" option
156
+			the_content();
157
+		} elseif ((is_archive() && espresso_display_excerpt_in_event_list())) {
158
+			if (has_excerpt($post->ID)) {
159
+				// admin has chosen "excerpt (short desc)"
160
+				// for the "Event Espresso - Events > Templates > Display Description" option
161
+				// AND an excerpt actually exists
162
+				the_excerpt();
163
+			} else {
164
+				// admin has chosen "excerpt (short desc)"
165
+				// for the "Event Espresso - Events > Templates > Display Description" option
166
+				// but NO excerpt actually exists, so we need to create one
167
+				if (! empty($num_words)) {
168
+					if (empty($more)) {
169
+						$more_link_text = esc_html__('(more&hellip;)', 'event_espresso');
170
+						$more           = ' <a href="' . get_permalink() . '"';
171
+						$more           .= ' class="more-link"';
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);
175
+					}
176
+					$content = str_replace('NOMORELINK', '', get_the_content('NOMORELINK'));
177
+
178
+					$content = wp_trim_words($content, $num_words, ' ') . $more;
179
+				} else {
180
+					$content = get_the_content();
181
+				}
182
+				global $allowedtags;
183
+				// make sure links are allowed
184
+				$allowedtags['a'] = isset($allowedtags['a'])
185
+					? $allowedtags['a']
186
+					: [];
187
+				// as well as target attribute
188
+				$allowedtags['a']['target'] = isset($allowedtags['a']['target'])
189
+					? $allowedtags['a']['target']
190
+					: false;
191
+				// but get previous value so we can reset it
192
+				$prev_value                 = $allowedtags['a']['target'];
193
+				$allowedtags['a']['target'] = true;
194
+				$content                    = wp_kses($content, $allowedtags);
195
+				$content                    = strip_shortcodes($content);
196
+				echo apply_filters('the_content', $content);
197
+				$allowedtags['a']['target'] = $prev_value;
198
+			}
199
+		} else {
200
+			// admin has chosen "none"
201
+			// for the "Event Espresso - Events > Templates > Display Description" option
202
+			echo apply_filters('the_content', '');
203
+		}
204
+		return ob_get_clean();
205
+	}
206
+
207
+
208
+	/**
209
+	 *  event_tickets_available
210
+	 *
211
+	 * @param int $EVT_ID
212
+	 * @return     EE_Ticket[]
213
+	 * @throws EE_Error
214
+	 * @throws ReflectionException
215
+	 */
216
+	public static function event_tickets_available($EVT_ID = 0)
217
+	{
218
+		$event                          = EEH_Event_View::get_event($EVT_ID);
219
+		$tickets_available_for_purchase = [];
220
+		if ($event instanceof EE_Event) {
221
+			$datetimes = EEH_Event_View::get_all_date_obj($EVT_ID, false);
222
+			foreach ($datetimes as $datetime) {
223
+				$tickets_available_for_purchase =
224
+					array_merge($tickets_available_for_purchase, $datetime->ticket_types_available_for_purchase());
225
+			}
226
+		}
227
+		return $tickets_available_for_purchase;
228
+	}
229
+
230
+
231
+	/**
232
+	 *    the_event_date
233
+	 *
234
+	 * @param int  $EVT_ID
235
+	 * @param bool $hide_uncategorized
236
+	 * @return    string
237
+	 * @throws EE_Error
238
+	 * @throws ReflectionException
239
+	 */
240
+	public static function event_categories($EVT_ID = 0, $hide_uncategorized = true)
241
+	{
242
+		$category_links = [];
243
+		$event          = EEH_Event_View::get_event($EVT_ID);
244
+		if ($event instanceof EE_Event) {
245
+			$event_categories = get_the_terms($event->ID(), 'espresso_event_categories');
246
+			if ($event_categories) {
247
+				// loop thru terms and create links
248
+				foreach ($event_categories as $term) {
249
+					$url = get_term_link($term, 'espresso_venue_categories');
250
+					if (
251
+						! is_wp_error($url)
252
+						&& (
253
+							(
254
+								$hide_uncategorized
255
+								&& strtolower($term->name) != esc_html__('uncategorized', 'event_espresso')
256
+							)
257
+							|| ! $hide_uncategorized
258
+						)
259
+					) {
260
+						$category_links[] = '<a href="' . esc_url_raw($url) . '" '
261
+											. 'rel="tag" ' . EED_Events_Archive::link_target() . '>'
262
+											. esc_html($term->name)
263
+											. '</a>';
264
+					}
265
+				}
266
+			}
267
+		}
268
+		return implode(', ', $category_links);
269
+	}
270
+
271
+
272
+	/**
273
+	 *    the_event_date - first date by date order
274
+	 *
275
+	 * @param string $date_format
276
+	 * @param string $time_format
277
+	 * @param int    $EVT_ID
278
+	 * @return    string
279
+	 * @throws EE_Error
280
+	 * @throws ReflectionException
281
+	 */
282
+	public static function the_event_date($date_format = 'D M jS', $time_format = 'g:i a', $EVT_ID = 0)
283
+	{
284
+		$datetime = EEH_Event_View::get_primary_date_obj($EVT_ID);
285
+		$format   = ! empty($date_format) && ! empty($time_format)
286
+				? $date_format . ' ' . $time_format
287
+				: $date_format . $time_format;
288
+		return $datetime instanceof EE_Datetime ? $datetime->get_i18n_datetime('DTT_EVT_start', $format) : '';
289
+	}
290
+
291
+
292
+	/**
293
+	 *    the_event_end_date - last date by date order
294
+	 *
295
+	 * @param string $date_format
296
+	 * @param string $time_format
297
+	 * @param int    $EVT_ID
298
+	 * @return    string
299
+	 * @throws EE_Error
300
+	 * @throws ReflectionException
301
+	 */
302
+	public static function the_event_end_date($date_format = 'D M jS', $time_format = 'g:i a', $EVT_ID = 0)
303
+	{
304
+		$datetime = EEH_Event_View::get_last_date_obj($EVT_ID);
305
+		$format   =
306
+			! empty($date_format) && ! empty($time_format)
307
+				? $date_format . ' ' . $time_format
308
+				: $date_format
309
+				  . $time_format;
310
+		return $datetime instanceof EE_Datetime ? $datetime->get_i18n_datetime('DTT_EVT_end', $format) : '';
311
+	}
312
+
313
+
314
+	/**
315
+	 *    the_earliest_event_date - first date chronologically
316
+	 *
317
+	 * @param string $date_format
318
+	 * @param string $time_format
319
+	 * @param int    $EVT_ID
320
+	 * @return    string
321
+	 * @throws EE_Error
322
+	 * @throws ReflectionException
323
+	 */
324
+	public static function the_earliest_event_date($date_format = 'D M jS', $time_format = 'g:i a', $EVT_ID = 0)
325
+	{
326
+		$datetime = EEH_Event_View::get_earliest_date_obj($EVT_ID);
327
+		$format   =
328
+			! empty($date_format) && ! empty($time_format)
329
+				? $date_format . ' ' . $time_format
330
+				: $date_format
331
+				  . $time_format;
332
+		return $datetime instanceof EE_Datetime ? $datetime->get_i18n_datetime('DTT_EVT_start', $format) : '';
333
+	}
334
+
335
+
336
+	/**
337
+	 *    the_latest_event_date - latest date chronologically
338
+	 *
339
+	 * @param string $date_format
340
+	 * @param string $time_format
341
+	 * @param int    $EVT_ID
342
+	 * @return    string
343
+	 * @throws EE_Error
344
+	 * @throws ReflectionException
345
+	 */
346
+	public static function the_latest_event_date($date_format = 'D M jS', $time_format = 'g:i a', $EVT_ID = 0)
347
+	{
348
+		$datetime = EEH_Event_View::get_latest_date_obj($EVT_ID);
349
+		$format   =
350
+			! empty($date_format) && ! empty($time_format)
351
+				? $date_format . ' ' . $time_format
352
+				: $date_format
353
+				  . $time_format;
354
+		return $datetime instanceof EE_Datetime ? $datetime->get_i18n_datetime('DTT_EVT_end', $format) : '';
355
+	}
356
+
357
+
358
+	/**
359
+	 *    event_date_as_calendar_page
360
+	 *
361
+	 * @param int $EVT_ID
362
+	 * @return    void
363
+	 * @throws EE_Error
364
+	 * @throws ReflectionException
365
+	 */
366
+	public static function event_date_as_calendar_page($EVT_ID = 0)
367
+	{
368
+		$datetime = EEH_Event_View::get_primary_date_obj($EVT_ID);
369
+		if ($datetime instanceof EE_Datetime) {
370
+			?>
371 371
             <div class="event-date-calendar-page-dv">
372 372
                 <div class="event-date-calendar-page-month-dv">
373 373
                     <?php echo esc_html($datetime->get_i18n_datetime('DTT_EVT_start', 'M')); ?>
@@ -377,260 +377,260 @@  discard block
 block discarded – undo
377 377
                 </div>
378 378
             </div>
379 379
             <?php
380
-        }
381
-    }
382
-
383
-
384
-    /**
385
-     *    get_primary_date_obj - orders date by DTT_order
386
-     *
387
-     * @param int $EVT_ID
388
-     * @return EE_Datetime
389
-     * @throws EE_Error
390
-     * @throws ReflectionException
391
-     */
392
-    public static function get_primary_date_obj($EVT_ID = 0)
393
-    {
394
-        $event = EEH_Event_View::get_event($EVT_ID);
395
-        if ($event instanceof EE_Event) {
396
-            $datetimes = $event->get_many_related(
397
-                'Datetime',
398
-                [
399
-                    'limit'    => 1,
400
-                    'order_by' => ['DTT_order' => 'ASC'],
401
-                ]
402
-            );
403
-            return reset($datetimes);
404
-        }
405
-        return null;
406
-    }
407
-
408
-
409
-    /**
410
-     *    get_last_date_obj - orders date by DTT_order
411
-     *
412
-     * @param int $EVT_ID
413
-     * @return EE_Datetime
414
-     * @throws EE_Error
415
-     * @throws ReflectionException
416
-     */
417
-    public static function get_last_date_obj($EVT_ID = 0)
418
-    {
419
-        $event = EEH_Event_View::get_event($EVT_ID);
420
-        if ($event instanceof EE_Event) {
421
-            $datetimes = $event->get_many_related(
422
-                'Datetime',
423
-                [
424
-                    'limit'    => 1,
425
-                    'order_by' => ['DTT_order' => 'DESC'],
426
-                ]
427
-            );
428
-            return end($datetimes);
429
-        }
430
-        return null;
431
-    }
432
-
433
-
434
-    /**
435
-     *    get_earliest_date_obj - orders date chronologically
436
-     *
437
-     * @param int $EVT_ID
438
-     * @return EE_Datetime
439
-     * @throws EE_Error
440
-     * @throws ReflectionException
441
-     */
442
-    public static function get_earliest_date_obj($EVT_ID = 0)
443
-    {
444
-        $event = EEH_Event_View::get_event($EVT_ID);
445
-        if ($event instanceof EE_Event) {
446
-            $datetimes = $event->get_many_related(
447
-                'Datetime',
448
-                [
449
-                    'limit'    => 1,
450
-                    'order_by' => ['DTT_EVT_start' => 'ASC'],
451
-                ]
452
-            );
453
-            return reset($datetimes);
454
-        }
455
-        return null;
456
-    }
457
-
458
-
459
-    /**
460
-     *    get_latest_date_obj - orders date chronologically
461
-     *
462
-     * @param int $EVT_ID
463
-     * @return EE_Datetime
464
-     * @throws EE_Error
465
-     * @throws ReflectionException
466
-     */
467
-    public static function get_latest_date_obj($EVT_ID = 0)
468
-    {
469
-        $event = EEH_Event_View::get_event($EVT_ID);
470
-        if ($event instanceof EE_Event) {
471
-            $datetimes = $event->get_many_related(
472
-                'Datetime',
473
-                [
474
-                    'limit'    => 1,
475
-                    'order_by' => ['DTT_EVT_start' => 'DESC'],
476
-                ]
477
-            );
478
-            return end($datetimes);
479
-        }
480
-        return null;
481
-    }
482
-
483
-
484
-    /**
485
-     *    get_next_upcoming_date_obj - return the next upcoming datetime
486
-     *
487
-     * @param int $EVT_ID
488
-     * @return    EE_Datetime|null
489
-     * @throws EE_Error
490
-     * @throws EE_Error
491
-     */
492
-    public static function get_next_upcoming_date_obj($EVT_ID = 0)
493
-    {
494
-        $datetime = EEM_Datetime::instance()->get_one(
495
-            [
496
-                [
497
-                    'Event.EVT_ID'  => $EVT_ID,
498
-                    'DTT_EVT_start' => ['>=', current_time('mysql', true)],
499
-                ],
500
-                'order_by' => ['DTT_EVT_start' => 'asc'],
501
-            ]
502
-        );
503
-        return $datetime instanceof EE_Datetime ? $datetime : null;
504
-    }
505
-
506
-
507
-    /**
508
-     *    get_all_date_obj
509
-     *
510
-     * @param int  $EVT_ID
511
-     * @param null $include_expired
512
-     * @param bool $include_deleted
513
-     * @param null $limit
514
-     * @return EE_Datetime[]
515
-     * @throws EE_Error
516
-     * @throws EE_Error
517
-     * @throws ReflectionException
518
-     */
519
-    public static function get_all_date_obj(
520
-        $EVT_ID = 0,
521
-        $include_expired = null,
522
-        $include_deleted = false,
523
-        $limit = null
524
-    ) {
525
-        $event = EEH_Event_View::get_event($EVT_ID);
526
-        if ($include_expired === null) {
527
-            if ($event instanceof EE_Event && $event->is_expired()) {
528
-                $include_expired = true;
529
-            } else {
530
-                $include_expired = false;
531
-            }
532
-        }
533
-
534
-        if ($event instanceof EE_Event) {
535
-            return $event->datetimes_ordered($include_expired, $include_deleted, $limit);
536
-        }
537
-        return [];
538
-    }
539
-
540
-
541
-    /**
542
-     *    event_link_url
543
-     *
544
-     * @param int $EVT_ID
545
-     * @return string
546
-     * @throws EE_Error
547
-     * @throws ReflectionException
548
-     */
549
-    public static function event_link_url($EVT_ID = 0)
550
-    {
551
-        $event = EEH_Event_View::get_event($EVT_ID);
552
-        if ($event instanceof EE_Event) {
553
-            $url = $event->external_url() !== null && $event->external_url() !== ''
554
-                ? $event->external_url()
555
-                : get_permalink($event->ID());
556
-            $url = preg_match("~^(?:f|ht)tps?://~i", $url) ? $url : 'https://' . $url;
557
-            return esc_url_raw($url);
558
-        }
559
-        return '';
560
-    }
561
-
562
-
563
-    /**
564
-     *    event_phone
565
-     *
566
-     * @param int $EVT_ID
567
-     * @return    string
568
-     * @throws EE_Error
569
-     * @throws EE_Error
570
-     * @throws ReflectionException
571
-     */
572
-    public static function event_phone($EVT_ID = 0)
573
-    {
574
-        $event = EEH_Event_View::get_event($EVT_ID);
575
-        if ($event instanceof EE_Event) {
576
-            return EEH_Schema::telephone($event->phone());
577
-        }
578
-        return null;
579
-    }
580
-
581
-
582
-    /**
583
-     *    edit_event_link
584
-     *
585
-     * @param int    $EVT_ID
586
-     * @param string $link
587
-     * @param string $before
588
-     * @param string $after
589
-     * @return    string
590
-     * @throws EE_Error
591
-     * @throws ReflectionException
592
-     */
593
-    public static function edit_event_link($EVT_ID = 0, $link = '', $before = '', $after = '')
594
-    {
595
-        $event = EEH_Event_View::get_event($EVT_ID);
596
-        if ($event instanceof EE_Event) {
597
-            // can the user edit this post ?
598
-            if (current_user_can('edit_post', $event->ID())) {
599
-                // set link text
600
-                $link_text = ! empty($link) ? $link : esc_html__('edit this event', 'event_espresso');
601
-                // generate nonce
602
-                $nonce = wp_create_nonce('edit_nonce');
603
-                // generate url to event editor for this event
604
-                $url =
605
-                    add_query_arg(
606
-                        [
607
-                            'page'       => 'espresso_events',
608
-                            'action'     => 'edit',
609
-                            'post'       => $event->ID(),
610
-                            'edit_nonce' => $nonce,
611
-                        ],
612
-                        admin_url()
613
-                    );
614
-                // get edit CPT text
615
-                $post_type_obj = get_post_type_object('espresso_events');
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) . '"';
619
-                $link .= EED_Events_Archive::link_target();
620
-                $link .= '>' . $link_text . '</a>';
621
-                // put it all together
622
-                return $before . apply_filters('edit_post_link', $link, $event->ID()) . $after;
623
-            }
624
-        }
625
-        return '';
626
-    }
627
-
628
-
629
-    /**
630
-     * @return string
631
-     */
632
-    public static function event_archive_url()
633
-    {
634
-        return get_post_type_archive_link('espresso_events');
635
-    }
380
+		}
381
+	}
382
+
383
+
384
+	/**
385
+	 *    get_primary_date_obj - orders date by DTT_order
386
+	 *
387
+	 * @param int $EVT_ID
388
+	 * @return EE_Datetime
389
+	 * @throws EE_Error
390
+	 * @throws ReflectionException
391
+	 */
392
+	public static function get_primary_date_obj($EVT_ID = 0)
393
+	{
394
+		$event = EEH_Event_View::get_event($EVT_ID);
395
+		if ($event instanceof EE_Event) {
396
+			$datetimes = $event->get_many_related(
397
+				'Datetime',
398
+				[
399
+					'limit'    => 1,
400
+					'order_by' => ['DTT_order' => 'ASC'],
401
+				]
402
+			);
403
+			return reset($datetimes);
404
+		}
405
+		return null;
406
+	}
407
+
408
+
409
+	/**
410
+	 *    get_last_date_obj - orders date by DTT_order
411
+	 *
412
+	 * @param int $EVT_ID
413
+	 * @return EE_Datetime
414
+	 * @throws EE_Error
415
+	 * @throws ReflectionException
416
+	 */
417
+	public static function get_last_date_obj($EVT_ID = 0)
418
+	{
419
+		$event = EEH_Event_View::get_event($EVT_ID);
420
+		if ($event instanceof EE_Event) {
421
+			$datetimes = $event->get_many_related(
422
+				'Datetime',
423
+				[
424
+					'limit'    => 1,
425
+					'order_by' => ['DTT_order' => 'DESC'],
426
+				]
427
+			);
428
+			return end($datetimes);
429
+		}
430
+		return null;
431
+	}
432
+
433
+
434
+	/**
435
+	 *    get_earliest_date_obj - orders date chronologically
436
+	 *
437
+	 * @param int $EVT_ID
438
+	 * @return EE_Datetime
439
+	 * @throws EE_Error
440
+	 * @throws ReflectionException
441
+	 */
442
+	public static function get_earliest_date_obj($EVT_ID = 0)
443
+	{
444
+		$event = EEH_Event_View::get_event($EVT_ID);
445
+		if ($event instanceof EE_Event) {
446
+			$datetimes = $event->get_many_related(
447
+				'Datetime',
448
+				[
449
+					'limit'    => 1,
450
+					'order_by' => ['DTT_EVT_start' => 'ASC'],
451
+				]
452
+			);
453
+			return reset($datetimes);
454
+		}
455
+		return null;
456
+	}
457
+
458
+
459
+	/**
460
+	 *    get_latest_date_obj - orders date chronologically
461
+	 *
462
+	 * @param int $EVT_ID
463
+	 * @return EE_Datetime
464
+	 * @throws EE_Error
465
+	 * @throws ReflectionException
466
+	 */
467
+	public static function get_latest_date_obj($EVT_ID = 0)
468
+	{
469
+		$event = EEH_Event_View::get_event($EVT_ID);
470
+		if ($event instanceof EE_Event) {
471
+			$datetimes = $event->get_many_related(
472
+				'Datetime',
473
+				[
474
+					'limit'    => 1,
475
+					'order_by' => ['DTT_EVT_start' => 'DESC'],
476
+				]
477
+			);
478
+			return end($datetimes);
479
+		}
480
+		return null;
481
+	}
482
+
483
+
484
+	/**
485
+	 *    get_next_upcoming_date_obj - return the next upcoming datetime
486
+	 *
487
+	 * @param int $EVT_ID
488
+	 * @return    EE_Datetime|null
489
+	 * @throws EE_Error
490
+	 * @throws EE_Error
491
+	 */
492
+	public static function get_next_upcoming_date_obj($EVT_ID = 0)
493
+	{
494
+		$datetime = EEM_Datetime::instance()->get_one(
495
+			[
496
+				[
497
+					'Event.EVT_ID'  => $EVT_ID,
498
+					'DTT_EVT_start' => ['>=', current_time('mysql', true)],
499
+				],
500
+				'order_by' => ['DTT_EVT_start' => 'asc'],
501
+			]
502
+		);
503
+		return $datetime instanceof EE_Datetime ? $datetime : null;
504
+	}
505
+
506
+
507
+	/**
508
+	 *    get_all_date_obj
509
+	 *
510
+	 * @param int  $EVT_ID
511
+	 * @param null $include_expired
512
+	 * @param bool $include_deleted
513
+	 * @param null $limit
514
+	 * @return EE_Datetime[]
515
+	 * @throws EE_Error
516
+	 * @throws EE_Error
517
+	 * @throws ReflectionException
518
+	 */
519
+	public static function get_all_date_obj(
520
+		$EVT_ID = 0,
521
+		$include_expired = null,
522
+		$include_deleted = false,
523
+		$limit = null
524
+	) {
525
+		$event = EEH_Event_View::get_event($EVT_ID);
526
+		if ($include_expired === null) {
527
+			if ($event instanceof EE_Event && $event->is_expired()) {
528
+				$include_expired = true;
529
+			} else {
530
+				$include_expired = false;
531
+			}
532
+		}
533
+
534
+		if ($event instanceof EE_Event) {
535
+			return $event->datetimes_ordered($include_expired, $include_deleted, $limit);
536
+		}
537
+		return [];
538
+	}
539
+
540
+
541
+	/**
542
+	 *    event_link_url
543
+	 *
544
+	 * @param int $EVT_ID
545
+	 * @return string
546
+	 * @throws EE_Error
547
+	 * @throws ReflectionException
548
+	 */
549
+	public static function event_link_url($EVT_ID = 0)
550
+	{
551
+		$event = EEH_Event_View::get_event($EVT_ID);
552
+		if ($event instanceof EE_Event) {
553
+			$url = $event->external_url() !== null && $event->external_url() !== ''
554
+				? $event->external_url()
555
+				: get_permalink($event->ID());
556
+			$url = preg_match("~^(?:f|ht)tps?://~i", $url) ? $url : 'https://' . $url;
557
+			return esc_url_raw($url);
558
+		}
559
+		return '';
560
+	}
561
+
562
+
563
+	/**
564
+	 *    event_phone
565
+	 *
566
+	 * @param int $EVT_ID
567
+	 * @return    string
568
+	 * @throws EE_Error
569
+	 * @throws EE_Error
570
+	 * @throws ReflectionException
571
+	 */
572
+	public static function event_phone($EVT_ID = 0)
573
+	{
574
+		$event = EEH_Event_View::get_event($EVT_ID);
575
+		if ($event instanceof EE_Event) {
576
+			return EEH_Schema::telephone($event->phone());
577
+		}
578
+		return null;
579
+	}
580
+
581
+
582
+	/**
583
+	 *    edit_event_link
584
+	 *
585
+	 * @param int    $EVT_ID
586
+	 * @param string $link
587
+	 * @param string $before
588
+	 * @param string $after
589
+	 * @return    string
590
+	 * @throws EE_Error
591
+	 * @throws ReflectionException
592
+	 */
593
+	public static function edit_event_link($EVT_ID = 0, $link = '', $before = '', $after = '')
594
+	{
595
+		$event = EEH_Event_View::get_event($EVT_ID);
596
+		if ($event instanceof EE_Event) {
597
+			// can the user edit this post ?
598
+			if (current_user_can('edit_post', $event->ID())) {
599
+				// set link text
600
+				$link_text = ! empty($link) ? $link : esc_html__('edit this event', 'event_espresso');
601
+				// generate nonce
602
+				$nonce = wp_create_nonce('edit_nonce');
603
+				// generate url to event editor for this event
604
+				$url =
605
+					add_query_arg(
606
+						[
607
+							'page'       => 'espresso_events',
608
+							'action'     => 'edit',
609
+							'post'       => $event->ID(),
610
+							'edit_nonce' => $nonce,
611
+						],
612
+						admin_url()
613
+					);
614
+				// get edit CPT text
615
+				$post_type_obj = get_post_type_object('espresso_events');
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) . '"';
619
+				$link .= EED_Events_Archive::link_target();
620
+				$link .= '>' . $link_text . '</a>';
621
+				// put it all together
622
+				return $before . apply_filters('edit_post_link', $link, $event->ID()) . $after;
623
+			}
624
+		}
625
+		return '';
626
+	}
627
+
628
+
629
+	/**
630
+	 * @return string
631
+	 */
632
+	public static function event_archive_url()
633
+	{
634
+		return get_post_type_archive_link('espresso_events');
635
+	}
636 636
 }
Please login to merge, or discard this patch.