@@ -11,630 +11,630 @@ |
||
11 | 11 | */ |
12 | 12 | class EEH_Venue_View extends EEH_Base |
13 | 13 | { |
14 | - /** |
|
15 | - * @access private |
|
16 | - * @var EE_Venue |
|
17 | - */ |
|
18 | - private static $_venue = null; |
|
19 | - |
|
20 | - |
|
21 | - /** |
|
22 | - * get_venue |
|
23 | - * attempts to retrieve an EE_Venue object any way it can |
|
24 | - * |
|
25 | - * @access public |
|
26 | - * @param int $VNU_ID |
|
27 | - * @param bool $look_in_event |
|
28 | - * @param bool $privacy_check Defaults to true. |
|
29 | - * When false, means even if the venue is private we return it regardless of access. |
|
30 | - * @param bool $password_check |
|
31 | - * @return EE_Venue|null |
|
32 | - * @throws EE_Error |
|
33 | - * @throws ReflectionException |
|
34 | - */ |
|
35 | - public static function get_venue($VNU_ID = 0, $look_in_event = true, $privacy_check = true, $password_check = true) |
|
36 | - { |
|
37 | - $VNU_ID = absint($VNU_ID); |
|
38 | - // do we already have the Venue you are looking for? |
|
39 | - if (EEH_Venue_View::$_venue instanceof EE_Venue && $VNU_ID) { |
|
40 | - // If the Venue ID matches $VNU_ID, return the venue. |
|
41 | - if (EEH_Venue_View::$_venue->ID() === $VNU_ID) { |
|
42 | - return EEH_Venue_View::_get_venue($privacy_check); |
|
43 | - } |
|
44 | - // If the Venue ID does not match, try pulling a venue using $VNU_ID. |
|
45 | - $venue = EEM_Venue::instance()->get_one_by_ID($VNU_ID); |
|
46 | - if ($venue instanceof EE_Venue) { |
|
47 | - EEH_Venue_View::$_venue = $venue; |
|
48 | - return EEH_Venue_View::_get_venue($privacy_check); |
|
49 | - } |
|
50 | - } |
|
51 | - // international newspaper? |
|
52 | - global $post; |
|
53 | - if ($post instanceof WP_Post) { |
|
54 | - switch ($post->post_type) { |
|
55 | - // if this is being called from an EE_Venue post, |
|
56 | - // and the EE_Venue post corresponds to the EE_Venue that is being asked for, |
|
57 | - // then we can try to just grab the attached EE_Venue object |
|
58 | - case EspressoPostType::VENUES: |
|
59 | - // the post already contains the related EE_Venue object AND one of the following is TRUE: |
|
60 | - // the requested Venue ID matches the post ID OR... |
|
61 | - // there was no specific Venue ID requested |
|
62 | - if (isset($post->EE_Venue) && ($VNU_ID == $post->ID || ! $VNU_ID)) { |
|
63 | - // use existing related EE_Venue object |
|
64 | - EEH_Venue_View::$_venue = $post->EE_Venue; |
|
65 | - } elseif ($VNU_ID) { |
|
66 | - // there WAS a specific Venue ID requested, but it's NOT the current post object |
|
67 | - EEH_Venue_View::$_venue = EEM_Venue::instance()->get_one_by_ID($VNU_ID); |
|
68 | - } else { |
|
69 | - // no specific Venue ID requested, so use post ID to generate EE_Venue object |
|
70 | - EEH_Venue_View::$_venue = EEM_Venue::instance()->get_one_by_ID($post->ID); |
|
71 | - } |
|
72 | - break; |
|
73 | - |
|
74 | - case EspressoPostType::EVENTS: |
|
75 | - if ($look_in_event) { |
|
76 | - // grab the events related venues |
|
77 | - $venues = EEH_Venue_View::get_event_venues(); |
|
78 | - // make sure the result is an array |
|
79 | - $venues = is_array($venues) ? $venues : [$venues]; |
|
80 | - // do we have an ID for a specific venue? |
|
81 | - if ($VNU_ID) { |
|
82 | - // loop thru the related venues |
|
83 | - foreach ($venues as $venue) { |
|
84 | - if ($venue instanceof EE_Venue) { |
|
85 | - // until we find the venue we're looking for |
|
86 | - if ($venue->ID() == $VNU_ID) { |
|
87 | - EEH_Venue_View::$_venue = $venue; |
|
88 | - break; |
|
89 | - } |
|
90 | - } |
|
91 | - } |
|
92 | - // no venue ID ? |
|
93 | - // then the global post is an events post and this function was called with no argument |
|
94 | - } else { |
|
95 | - // just grab the first related event venue |
|
96 | - EEH_Venue_View::$_venue = reset($venues); |
|
97 | - } |
|
98 | - } |
|
99 | - break; |
|
100 | - } |
|
101 | - } |
|
102 | - // now if we STILL do NOT have an EE_Venue model object, BUT we have a Venue ID... |
|
103 | - if (! EEH_Venue_View::$_venue instanceof EE_Venue && $VNU_ID) { |
|
104 | - // sigh... pull it from the db |
|
105 | - EEH_Venue_View::$_venue = EEM_Venue::instance()->get_one_by_ID($VNU_ID); |
|
106 | - } |
|
107 | - return EEH_Venue_View::_get_venue($privacy_check, $password_check); |
|
108 | - } |
|
109 | - |
|
110 | - |
|
111 | - /** |
|
112 | - * return a single venue |
|
113 | - * |
|
114 | - * @param bool $privacy_check Defaults to true. |
|
115 | - * When false, means even if the venue is private we return it regardless of access. |
|
116 | - * @param bool $password_check |
|
117 | - * @return EE_Venue |
|
118 | - * @throws EE_Error |
|
119 | - * @throws ReflectionException |
|
120 | - */ |
|
121 | - protected static function _get_venue($privacy_check = true, $password_check = true) |
|
122 | - { |
|
123 | - // check for private venues. |
|
124 | - if ( |
|
125 | - EEH_Venue_View::$_venue instanceof EE_Venue |
|
126 | - && EEH_Venue_View::$_venue->status() == 'private' |
|
127 | - && $privacy_check |
|
128 | - && ! EE_Registry::instance()->CAP->current_user_can('ee_read_private_venues', 'get_venues') |
|
129 | - ) { |
|
130 | - return null; |
|
131 | - } |
|
132 | - // check for password protected venues |
|
133 | - if ( |
|
134 | - EEH_Venue_View::$_venue instanceof EE_Venue |
|
135 | - && $password_check |
|
136 | - && post_password_required(EEH_Venue_View::$_venue->ID()) |
|
137 | - ) { |
|
138 | - return null; |
|
139 | - } |
|
140 | - return EEH_Venue_View::$_venue instanceof EE_Venue ? EEH_Venue_View::$_venue : null; |
|
141 | - } |
|
142 | - |
|
143 | - |
|
144 | - /** |
|
145 | - * get_event_venues |
|
146 | - * |
|
147 | - * @access public |
|
148 | - * @return EE_Venue[] |
|
149 | - * @throws EE_Error |
|
150 | - * @throws ReflectionException |
|
151 | - */ |
|
152 | - public static function get_event_venues() |
|
153 | - { |
|
154 | - global $post; |
|
155 | - if ($post->post_type == EspressoPostType::EVENTS) { |
|
156 | - if (isset($post->EE_Event) && $post->EE_Event instanceof EE_Event) { |
|
157 | - return $post->EE_Event->venue(); |
|
158 | - } |
|
159 | - } |
|
160 | - return []; |
|
161 | - } |
|
162 | - |
|
163 | - |
|
164 | - /** |
|
165 | - * Simply checks whether a venue for the given ID (or the internally derived venue is private). |
|
166 | - * |
|
167 | - * Note: This will return true if its private, null if the venue doesn't exist, and false, if the venue exists but |
|
168 | - * is not private. So it is important to do explicit boolean checks when using this conditional. |
|
169 | - * |
|
170 | - * @param bool $VNU_ID venue to check (optional). If not included will use internally derived venue object. |
|
171 | - * |
|
172 | - * @return bool|null |
|
173 | - * @throws EE_Error |
|
174 | - * @throws ReflectionException |
|
175 | - */ |
|
176 | - public static function is_venue_private($VNU_ID = false) |
|
177 | - { |
|
178 | - $venue = EEH_Venue_View::get_venue($VNU_ID); |
|
179 | - if (! $venue instanceof EE_Venue) { |
|
180 | - return null; |
|
181 | - } |
|
182 | - |
|
183 | - return $venue->status() == 'private'; |
|
184 | - } |
|
185 | - |
|
186 | - |
|
187 | - /** |
|
188 | - * returns true or false if a venue is password protected or not |
|
189 | - * |
|
190 | - * @param bool $VNU_ID venue to check (optional). If not included will use internally derived venue object. |
|
191 | - * @return bool |
|
192 | - * @throws EE_Error |
|
193 | - * @throws ReflectionException |
|
194 | - */ |
|
195 | - public static function is_venue_password_protected($VNU_ID = false) |
|
196 | - { |
|
197 | - $venue = EEH_Venue_View::get_venue($VNU_ID, true, true, false); |
|
198 | - if ( |
|
199 | - $venue instanceof EE_Venue |
|
200 | - && post_password_required($venue->ID()) |
|
201 | - ) { |
|
202 | - return true; |
|
203 | - } |
|
204 | - return false; |
|
205 | - } |
|
206 | - |
|
207 | - |
|
208 | - /** |
|
209 | - * If a venue is password protected, this will return the password form for gaining access |
|
210 | - * returns an empty string otherwise |
|
211 | - * |
|
212 | - * @param bool $VNU_ID venue to check (optional). If not included will use internally derived venue object. |
|
213 | - * |
|
214 | - * @return string |
|
215 | - * @throws EE_Error |
|
216 | - * @throws ReflectionException |
|
217 | - */ |
|
218 | - public static function password_protected_venue_form($VNU_ID = false) |
|
219 | - { |
|
220 | - $venue = EEH_Venue_View::get_venue($VNU_ID, true, true, false); |
|
221 | - if ( |
|
222 | - $venue instanceof EE_Venue |
|
223 | - && post_password_required($venue->ID()) |
|
224 | - ) { |
|
225 | - return get_the_password_form($venue->ID()); |
|
226 | - } |
|
227 | - return ''; |
|
228 | - } |
|
229 | - |
|
230 | - |
|
231 | - /** |
|
232 | - * venue_description |
|
233 | - * |
|
234 | - * @access public |
|
235 | - * @param int $VNU_ID |
|
236 | - * @return string |
|
237 | - * @throws EE_Error |
|
238 | - * @throws ReflectionException |
|
239 | - */ |
|
240 | - public static function venue_description($VNU_ID = 0) |
|
241 | - { |
|
242 | - $venue = EEH_Venue_View::get_venue($VNU_ID); |
|
243 | - if ($venue instanceof EE_Venue) { |
|
244 | - return $venue->get_pretty('VNU_desc'); |
|
245 | - } |
|
246 | - return ''; |
|
247 | - } |
|
248 | - |
|
249 | - |
|
250 | - /** |
|
251 | - * venue_excerpt |
|
252 | - * |
|
253 | - * @access public |
|
254 | - * @param int $VNU_ID |
|
255 | - * @return string |
|
256 | - * @throws EE_Error |
|
257 | - * @throws ReflectionException |
|
258 | - */ |
|
259 | - public static function venue_excerpt($VNU_ID = 0) |
|
260 | - { |
|
261 | - $venue = EEH_Venue_View::get_venue($VNU_ID); |
|
262 | - if ($venue instanceof EE_Venue) { |
|
263 | - $excerpt = $venue->excerpt() != null && $venue->excerpt() ? $venue->excerpt() : $venue->description(); |
|
264 | - $venue_link = ' ' . EEH_Venue_View::venue_details_link( |
|
265 | - $venue->ID(), |
|
266 | - esc_html__('more', 'event_espresso') . '…' |
|
267 | - ); |
|
268 | - return ! empty($excerpt) ? wp_trim_words($excerpt, 25, '') . $venue_link : ''; |
|
269 | - } |
|
270 | - return ''; |
|
271 | - } |
|
272 | - |
|
273 | - |
|
274 | - /** |
|
275 | - * venue_categories |
|
276 | - * |
|
277 | - * @access public |
|
278 | - * @param int $VNU_ID |
|
279 | - * @param bool $hide_uncategorized |
|
280 | - * @return string |
|
281 | - * @throws EE_Error |
|
282 | - * @throws ReflectionException |
|
283 | - */ |
|
284 | - public static function venue_categories($VNU_ID = 0, $hide_uncategorized = true) |
|
285 | - { |
|
286 | - $category_links = []; |
|
287 | - $venue = EEH_Venue_View::get_venue($VNU_ID); |
|
288 | - if ($venue instanceof EE_Venue) { |
|
289 | - // get category terms |
|
290 | - if ($venue_categories = get_the_terms($venue->ID(), 'espresso_venue_categories')) { |
|
291 | - // loop thru terms and create links |
|
292 | - foreach ($venue_categories as $term) { |
|
293 | - $url = get_term_link($term, 'espresso_venue_categories'); |
|
294 | - if ( |
|
295 | - ! is_wp_error($url) |
|
296 | - && (($hide_uncategorized |
|
297 | - && strtolower($term->name) != esc_html__( |
|
298 | - 'uncategorized', |
|
299 | - 'event_espresso' |
|
300 | - )) |
|
301 | - || ! $hide_uncategorized) |
|
302 | - ) { |
|
303 | - $category_links[] = '<a href="' . esc_url($url) . '" rel="tag">' . $term->name . '</a> '; |
|
304 | - } |
|
305 | - } |
|
306 | - } |
|
307 | - } |
|
308 | - return implode(', ', $category_links); |
|
309 | - } |
|
310 | - |
|
311 | - |
|
312 | - /** |
|
313 | - * venue_address |
|
314 | - * |
|
315 | - * @access public |
|
316 | - * @param string $type |
|
317 | - * @param int $VNU_ID |
|
318 | - * @param bool $use_schema |
|
319 | - * @param bool $add_wrapper |
|
320 | - * @return string |
|
321 | - * @throws EE_Error |
|
322 | - * @throws ReflectionException |
|
323 | - */ |
|
324 | - public static function venue_address($type = 'multiline', $VNU_ID = 0, $use_schema = true, $add_wrapper = true) |
|
325 | - { |
|
326 | - $venue = EEH_Venue_View::get_venue($VNU_ID); |
|
327 | - if ($venue instanceof EE_Venue) { |
|
328 | - return EEH_Address::format($venue, $type, $use_schema, $add_wrapper); |
|
329 | - } |
|
330 | - return ''; |
|
331 | - } |
|
332 | - |
|
333 | - |
|
334 | - /** |
|
335 | - * venue_has_address |
|
336 | - * |
|
337 | - * @access public |
|
338 | - * @param int $VNU_ID |
|
339 | - * @return bool|string |
|
340 | - * @throws EE_Error |
|
341 | - * @throws ReflectionException |
|
342 | - */ |
|
343 | - public static function venue_has_address($VNU_ID = 0) |
|
344 | - { |
|
345 | - $venue = EEH_Venue_View::get_venue($VNU_ID); |
|
346 | - if ($venue instanceof EE_Venue) { |
|
347 | - return EEH_Address::format($venue, 'inline', false, false); |
|
348 | - } |
|
349 | - return false; |
|
350 | - } |
|
351 | - |
|
352 | - |
|
353 | - /** |
|
354 | - * venue_name |
|
355 | - * |
|
356 | - * @access public |
|
357 | - * @param string $link_to - options( details, website, none ) whether to turn Venue name into a clickable link to |
|
358 | - * the Venue's details page or website |
|
359 | - * @param int $VNU_ID |
|
360 | - * @return string |
|
361 | - * @throws EE_Error |
|
362 | - * @throws ReflectionException |
|
363 | - */ |
|
364 | - public static function venue_name($link_to = 'details', $VNU_ID = 0) |
|
365 | - { |
|
366 | - $venue = EEH_Venue_View::get_venue($VNU_ID); |
|
367 | - if ($venue instanceof EE_Venue) { |
|
368 | - $venue_name = apply_filters( |
|
369 | - 'FHEE__EEH_Venue__venue_name__append_private_venue_name', |
|
370 | - EEH_Venue_View::is_venue_private() |
|
371 | - ? EEH_Venue_View::$_venue->name() . " " . esc_html__('(Private)', 'event_espresso') |
|
372 | - : EEH_Venue_View::$_venue->name(), |
|
373 | - EEH_Venue_View::$_venue |
|
374 | - ); |
|
375 | - $venue_name = EEH_Schema::name($venue_name); |
|
376 | - |
|
377 | - // if venue is trashed then ignore the "link to" setting because the venue is trashed. |
|
378 | - if ($venue->get('status') == 'trash') { |
|
379 | - $link_to = ''; |
|
380 | - } |
|
381 | - switch ($link_to) { |
|
382 | - case 'details': |
|
383 | - return EEH_Venue_View::venue_details_link($venue->ID(), $venue_name); |
|
384 | - |
|
385 | - case 'website': |
|
386 | - return EEH_Venue_View::venue_website_link($venue->ID(), $venue_name); |
|
387 | - |
|
388 | - default: |
|
389 | - return $venue_name; |
|
390 | - } |
|
391 | - } |
|
392 | - return ''; |
|
393 | - } |
|
394 | - |
|
395 | - |
|
396 | - /** |
|
397 | - * venue_details_link |
|
398 | - * |
|
399 | - * @access public |
|
400 | - * @param int $VNU_ID |
|
401 | - * @param string $text |
|
402 | - * @return string |
|
403 | - * @throws EE_Error |
|
404 | - * @throws ReflectionException |
|
405 | - */ |
|
406 | - public static function venue_details_link($VNU_ID = 0, $text = '') |
|
407 | - { |
|
408 | - $venue = EEH_Venue_View::get_venue($VNU_ID); |
|
409 | - if ($venue instanceof EE_Venue) { |
|
410 | - return EEH_Schema::url(get_permalink($venue->ID()), $text); |
|
411 | - } |
|
412 | - return ''; |
|
413 | - } |
|
414 | - |
|
415 | - |
|
416 | - /** |
|
417 | - * venue_website_link |
|
418 | - * |
|
419 | - * @access public |
|
420 | - * @param int $VNU_ID |
|
421 | - * @param string $text |
|
422 | - * @return string |
|
423 | - * @throws EE_Error |
|
424 | - * @throws ReflectionException |
|
425 | - */ |
|
426 | - public static function venue_website_link($VNU_ID = 0, $text = '') |
|
427 | - { |
|
428 | - $venue = EEH_Venue_View::get_venue($VNU_ID); |
|
429 | - if ($venue instanceof EE_Venue) { |
|
430 | - $url = $venue->venue_url(); |
|
431 | - $text = ! empty($text) ? $text : $url; |
|
432 | - return ! empty($url) ? EEH_Schema::url($url, $text, ['target' => '_blank']) : ''; |
|
433 | - } |
|
434 | - return ''; |
|
435 | - } |
|
436 | - |
|
437 | - |
|
438 | - /** |
|
439 | - * venue_phone |
|
440 | - * |
|
441 | - * @access public |
|
442 | - * @param int $VNU_ID |
|
443 | - * @return string |
|
444 | - * @throws EE_Error |
|
445 | - * @throws ReflectionException |
|
446 | - */ |
|
447 | - public static function venue_phone($VNU_ID = 0) |
|
448 | - { |
|
449 | - $venue = EEH_Venue_View::get_venue($VNU_ID); |
|
450 | - if ($venue instanceof EE_Venue) { |
|
451 | - return EEH_Schema::telephone($venue->phone()); |
|
452 | - } |
|
453 | - return ''; |
|
454 | - } |
|
455 | - |
|
456 | - |
|
457 | - /** |
|
458 | - * venue_gmap |
|
459 | - * |
|
460 | - * @access public |
|
461 | - * @param int $VNU_ID |
|
462 | - * @param bool|string $map_ID a unique identifier for this map |
|
463 | - * @param array $gmap map options |
|
464 | - * @return string |
|
465 | - * @throws EE_Error |
|
466 | - * @throws ReflectionException |
|
467 | - */ |
|
468 | - public static function venue_gmap($VNU_ID = 0, $map_ID = false, $gmap = []) |
|
469 | - { |
|
470 | - |
|
471 | - $venue = EEH_Venue_View::get_venue($VNU_ID); |
|
472 | - if ($venue instanceof EE_Venue) { |
|
473 | - // check for global espresso_events post and use its ID if no map_ID is set |
|
474 | - global $post; |
|
475 | - $map_ID = empty($map_ID) && $post->post_type == EspressoPostType::EVENTS ? $post->ID : $map_ID; |
|
476 | - // grab map settings |
|
477 | - $map_cfg = EE_Registry::instance()->CFG->map_settings; |
|
478 | - // are maps enabled ? |
|
479 | - if ($map_cfg->use_google_maps && $venue->enable_for_gmap()) { |
|
480 | - $details_page = is_single(); |
|
481 | - $options = []; |
|
482 | - |
|
483 | - $options['map_ID'] = $map_ID && $map_ID != $venue->ID() |
|
484 | - ? $map_ID . '-' . $venue->ID() |
|
485 | - : $venue->ID(); |
|
486 | - |
|
487 | - $options['location'] = EEH_Address::format($venue, 'inline', false, false); |
|
488 | - |
|
489 | - $options['ee_map_width'] = $details_page |
|
490 | - ? $map_cfg->event_details_map_width |
|
491 | - : $map_cfg->event_list_map_width; |
|
492 | - |
|
493 | - $options['ee_map_width'] = isset($gmap['ee_map_width']) && ! empty($gmap['ee_map_width']) |
|
494 | - ? $gmap['ee_map_width'] |
|
495 | - : $options['ee_map_width']; |
|
496 | - |
|
497 | - $options['ee_map_height'] = $details_page |
|
498 | - ? $map_cfg->event_details_map_height |
|
499 | - : $map_cfg->event_list_map_height; |
|
500 | - |
|
501 | - $options['ee_map_height'] = isset($gmap['ee_map_height']) && ! empty($gmap['ee_map_height']) |
|
502 | - ? $gmap['ee_map_height'] |
|
503 | - : $options['ee_map_height']; |
|
504 | - |
|
505 | - $options['ee_map_zoom'] = $details_page |
|
506 | - ? $map_cfg->event_details_map_zoom |
|
507 | - : $map_cfg->event_list_map_zoom; |
|
508 | - |
|
509 | - $options['ee_map_zoom'] = isset($gmap['ee_map_zoom']) && ! empty($gmap['ee_map_zoom']) |
|
510 | - ? $gmap['ee_map_zoom'] |
|
511 | - : $options['ee_map_zoom']; |
|
512 | - |
|
513 | - $options['ee_map_nav_display'] = $details_page |
|
514 | - ? $map_cfg->event_details_display_nav |
|
515 | - : $map_cfg->event_list_display_nav; |
|
516 | - |
|
517 | - $options['ee_map_nav_display'] = |
|
518 | - isset($gmap['ee_map_nav_display']) && ! empty($gmap['ee_map_nav_display']) |
|
519 | - ? 'true' |
|
520 | - : $options['ee_map_nav_display']; |
|
521 | - |
|
522 | - $options['ee_map_nav_size'] = $details_page |
|
523 | - ? $map_cfg->event_details_nav_size |
|
524 | - : $map_cfg->event_list_nav_size; |
|
525 | - |
|
526 | - $options['ee_map_nav_size'] = isset($gmap['ee_map_nav_size']) && ! empty($gmap['ee_map_nav_size']) |
|
527 | - ? $gmap['ee_map_nav_size'] |
|
528 | - : $options['ee_map_nav_size']; |
|
529 | - |
|
530 | - $options['ee_map_type_control'] = $details_page |
|
531 | - ? $map_cfg->event_details_control_type |
|
532 | - : $map_cfg->event_list_control_type; |
|
533 | - |
|
534 | - $options['ee_map_type_control'] = |
|
535 | - isset($gmap['ee_map_type_control']) && ! empty($gmap['ee_map_type_control']) |
|
536 | - ? $gmap['ee_map_type_control'] |
|
537 | - : $options['ee_map_type_control']; |
|
538 | - |
|
539 | - $options['ee_map_align'] = $details_page |
|
540 | - ? $map_cfg->event_details_map_align |
|
541 | - : $map_cfg->event_list_map_align; |
|
542 | - |
|
543 | - $options['ee_map_align'] = isset($gmap['ee_map_align']) && ! empty($gmap['ee_map_align']) |
|
544 | - ? $gmap['ee_map_align'] |
|
545 | - : $options['ee_map_align']; |
|
546 | - |
|
547 | - $options['ee_static_url'] = isset($gmap['ee_static_url']) && ! empty($gmap['ee_static_url']) |
|
548 | - ? (bool) absint($gmap['ee_static_url']) |
|
549 | - : $venue->google_map_link(); |
|
550 | - |
|
551 | - return EEH_Maps::google_map($options); |
|
552 | - } |
|
553 | - } |
|
554 | - |
|
555 | - return ''; |
|
556 | - } |
|
557 | - |
|
558 | - |
|
559 | - /** |
|
560 | - * Gets the HTML to display a static map of the venue |
|
561 | - * |
|
562 | - * @param EE_Venue $venue |
|
563 | - * @param array $attributes like EEH_Maps::google_map_link |
|
564 | - * @return string |
|
565 | - * @throws EE_Error |
|
566 | - * @throws ReflectionException |
|
567 | - */ |
|
568 | - public static function espresso_google_static_map(EE_Venue $venue, $attributes = []) |
|
569 | - { |
|
570 | - $state = $venue->state_obj(); |
|
571 | - $country = $venue->country_obj(); |
|
572 | - $attributes = shortcode_atts( |
|
573 | - [ |
|
574 | - 'id' => $venue->ID(), |
|
575 | - 'address' => $venue->get('VNU_address'), |
|
576 | - 'city' => $venue->get('VNU_city'), |
|
577 | - 'state' => $state instanceof EE_State ? $state->name() : '', |
|
578 | - 'zip' => $venue->get('VNU_zip'), |
|
579 | - 'country' => $country instanceof EE_Country ? $country->name() : '', |
|
580 | - 'type' => 'map', |
|
581 | - 'map_w' => 200, |
|
582 | - 'map_h' => 200, |
|
583 | - ], |
|
584 | - $attributes |
|
585 | - ); |
|
586 | - return EEH_Maps::google_map_link($attributes); |
|
587 | - } |
|
588 | - |
|
589 | - |
|
590 | - /** |
|
591 | - * edit_venue_link |
|
592 | - * |
|
593 | - * @access public |
|
594 | - * @param int $VNU_ID |
|
595 | - * @param string $link |
|
596 | - * @param string $before |
|
597 | - * @param string $after |
|
598 | - * @return string |
|
599 | - * @throws EE_Error |
|
600 | - * @throws ReflectionException |
|
601 | - */ |
|
602 | - public static function edit_venue_link( |
|
603 | - $VNU_ID = 0, |
|
604 | - $link = '', |
|
605 | - $before = '<p class="edit-venue-lnk small-txt">', |
|
606 | - $after = '</p>' |
|
607 | - ) { |
|
608 | - $venue = EEH_Venue_View::get_venue($VNU_ID); |
|
609 | - if ($venue instanceof EE_Venue) { |
|
610 | - // can the user edit this post ? |
|
611 | - if (current_user_can('edit_post', $venue->ID())) { |
|
612 | - // set link text |
|
613 | - $link = ! empty($link) ? $link : esc_html__('edit this venue', 'event_espresso'); |
|
614 | - // generate nonce |
|
615 | - $nonce = wp_create_nonce('edit_nonce'); |
|
616 | - // generate url to venue editor for this venue |
|
617 | - $url = |
|
618 | - add_query_arg( |
|
619 | - [ |
|
620 | - 'page' => 'espresso_venues', |
|
621 | - 'action' => 'edit', |
|
622 | - 'post' => $venue->ID(), |
|
623 | - 'edit_nonce' => $nonce, |
|
624 | - ], |
|
625 | - admin_url('admin.php') |
|
626 | - ); |
|
627 | - // get edit CPT text |
|
628 | - $post_type_obj = get_post_type_object(EspressoPostType::VENUES); |
|
629 | - // build final link html |
|
630 | - $link = |
|
631 | - '<a class="post-edit-link" href="' . $url . '" title="' . esc_attr( |
|
632 | - $post_type_obj->labels->edit_item |
|
633 | - ) . '">' . $link . '</a>'; |
|
634 | - // put it all together |
|
635 | - return $before . apply_filters('edit_post_link', $link, $venue->ID()) . $after; |
|
636 | - } |
|
637 | - } |
|
638 | - return ''; |
|
639 | - } |
|
14 | + /** |
|
15 | + * @access private |
|
16 | + * @var EE_Venue |
|
17 | + */ |
|
18 | + private static $_venue = null; |
|
19 | + |
|
20 | + |
|
21 | + /** |
|
22 | + * get_venue |
|
23 | + * attempts to retrieve an EE_Venue object any way it can |
|
24 | + * |
|
25 | + * @access public |
|
26 | + * @param int $VNU_ID |
|
27 | + * @param bool $look_in_event |
|
28 | + * @param bool $privacy_check Defaults to true. |
|
29 | + * When false, means even if the venue is private we return it regardless of access. |
|
30 | + * @param bool $password_check |
|
31 | + * @return EE_Venue|null |
|
32 | + * @throws EE_Error |
|
33 | + * @throws ReflectionException |
|
34 | + */ |
|
35 | + public static function get_venue($VNU_ID = 0, $look_in_event = true, $privacy_check = true, $password_check = true) |
|
36 | + { |
|
37 | + $VNU_ID = absint($VNU_ID); |
|
38 | + // do we already have the Venue you are looking for? |
|
39 | + if (EEH_Venue_View::$_venue instanceof EE_Venue && $VNU_ID) { |
|
40 | + // If the Venue ID matches $VNU_ID, return the venue. |
|
41 | + if (EEH_Venue_View::$_venue->ID() === $VNU_ID) { |
|
42 | + return EEH_Venue_View::_get_venue($privacy_check); |
|
43 | + } |
|
44 | + // If the Venue ID does not match, try pulling a venue using $VNU_ID. |
|
45 | + $venue = EEM_Venue::instance()->get_one_by_ID($VNU_ID); |
|
46 | + if ($venue instanceof EE_Venue) { |
|
47 | + EEH_Venue_View::$_venue = $venue; |
|
48 | + return EEH_Venue_View::_get_venue($privacy_check); |
|
49 | + } |
|
50 | + } |
|
51 | + // international newspaper? |
|
52 | + global $post; |
|
53 | + if ($post instanceof WP_Post) { |
|
54 | + switch ($post->post_type) { |
|
55 | + // if this is being called from an EE_Venue post, |
|
56 | + // and the EE_Venue post corresponds to the EE_Venue that is being asked for, |
|
57 | + // then we can try to just grab the attached EE_Venue object |
|
58 | + case EspressoPostType::VENUES: |
|
59 | + // the post already contains the related EE_Venue object AND one of the following is TRUE: |
|
60 | + // the requested Venue ID matches the post ID OR... |
|
61 | + // there was no specific Venue ID requested |
|
62 | + if (isset($post->EE_Venue) && ($VNU_ID == $post->ID || ! $VNU_ID)) { |
|
63 | + // use existing related EE_Venue object |
|
64 | + EEH_Venue_View::$_venue = $post->EE_Venue; |
|
65 | + } elseif ($VNU_ID) { |
|
66 | + // there WAS a specific Venue ID requested, but it's NOT the current post object |
|
67 | + EEH_Venue_View::$_venue = EEM_Venue::instance()->get_one_by_ID($VNU_ID); |
|
68 | + } else { |
|
69 | + // no specific Venue ID requested, so use post ID to generate EE_Venue object |
|
70 | + EEH_Venue_View::$_venue = EEM_Venue::instance()->get_one_by_ID($post->ID); |
|
71 | + } |
|
72 | + break; |
|
73 | + |
|
74 | + case EspressoPostType::EVENTS: |
|
75 | + if ($look_in_event) { |
|
76 | + // grab the events related venues |
|
77 | + $venues = EEH_Venue_View::get_event_venues(); |
|
78 | + // make sure the result is an array |
|
79 | + $venues = is_array($venues) ? $venues : [$venues]; |
|
80 | + // do we have an ID for a specific venue? |
|
81 | + if ($VNU_ID) { |
|
82 | + // loop thru the related venues |
|
83 | + foreach ($venues as $venue) { |
|
84 | + if ($venue instanceof EE_Venue) { |
|
85 | + // until we find the venue we're looking for |
|
86 | + if ($venue->ID() == $VNU_ID) { |
|
87 | + EEH_Venue_View::$_venue = $venue; |
|
88 | + break; |
|
89 | + } |
|
90 | + } |
|
91 | + } |
|
92 | + // no venue ID ? |
|
93 | + // then the global post is an events post and this function was called with no argument |
|
94 | + } else { |
|
95 | + // just grab the first related event venue |
|
96 | + EEH_Venue_View::$_venue = reset($venues); |
|
97 | + } |
|
98 | + } |
|
99 | + break; |
|
100 | + } |
|
101 | + } |
|
102 | + // now if we STILL do NOT have an EE_Venue model object, BUT we have a Venue ID... |
|
103 | + if (! EEH_Venue_View::$_venue instanceof EE_Venue && $VNU_ID) { |
|
104 | + // sigh... pull it from the db |
|
105 | + EEH_Venue_View::$_venue = EEM_Venue::instance()->get_one_by_ID($VNU_ID); |
|
106 | + } |
|
107 | + return EEH_Venue_View::_get_venue($privacy_check, $password_check); |
|
108 | + } |
|
109 | + |
|
110 | + |
|
111 | + /** |
|
112 | + * return a single venue |
|
113 | + * |
|
114 | + * @param bool $privacy_check Defaults to true. |
|
115 | + * When false, means even if the venue is private we return it regardless of access. |
|
116 | + * @param bool $password_check |
|
117 | + * @return EE_Venue |
|
118 | + * @throws EE_Error |
|
119 | + * @throws ReflectionException |
|
120 | + */ |
|
121 | + protected static function _get_venue($privacy_check = true, $password_check = true) |
|
122 | + { |
|
123 | + // check for private venues. |
|
124 | + if ( |
|
125 | + EEH_Venue_View::$_venue instanceof EE_Venue |
|
126 | + && EEH_Venue_View::$_venue->status() == 'private' |
|
127 | + && $privacy_check |
|
128 | + && ! EE_Registry::instance()->CAP->current_user_can('ee_read_private_venues', 'get_venues') |
|
129 | + ) { |
|
130 | + return null; |
|
131 | + } |
|
132 | + // check for password protected venues |
|
133 | + if ( |
|
134 | + EEH_Venue_View::$_venue instanceof EE_Venue |
|
135 | + && $password_check |
|
136 | + && post_password_required(EEH_Venue_View::$_venue->ID()) |
|
137 | + ) { |
|
138 | + return null; |
|
139 | + } |
|
140 | + return EEH_Venue_View::$_venue instanceof EE_Venue ? EEH_Venue_View::$_venue : null; |
|
141 | + } |
|
142 | + |
|
143 | + |
|
144 | + /** |
|
145 | + * get_event_venues |
|
146 | + * |
|
147 | + * @access public |
|
148 | + * @return EE_Venue[] |
|
149 | + * @throws EE_Error |
|
150 | + * @throws ReflectionException |
|
151 | + */ |
|
152 | + public static function get_event_venues() |
|
153 | + { |
|
154 | + global $post; |
|
155 | + if ($post->post_type == EspressoPostType::EVENTS) { |
|
156 | + if (isset($post->EE_Event) && $post->EE_Event instanceof EE_Event) { |
|
157 | + return $post->EE_Event->venue(); |
|
158 | + } |
|
159 | + } |
|
160 | + return []; |
|
161 | + } |
|
162 | + |
|
163 | + |
|
164 | + /** |
|
165 | + * Simply checks whether a venue for the given ID (or the internally derived venue is private). |
|
166 | + * |
|
167 | + * Note: This will return true if its private, null if the venue doesn't exist, and false, if the venue exists but |
|
168 | + * is not private. So it is important to do explicit boolean checks when using this conditional. |
|
169 | + * |
|
170 | + * @param bool $VNU_ID venue to check (optional). If not included will use internally derived venue object. |
|
171 | + * |
|
172 | + * @return bool|null |
|
173 | + * @throws EE_Error |
|
174 | + * @throws ReflectionException |
|
175 | + */ |
|
176 | + public static function is_venue_private($VNU_ID = false) |
|
177 | + { |
|
178 | + $venue = EEH_Venue_View::get_venue($VNU_ID); |
|
179 | + if (! $venue instanceof EE_Venue) { |
|
180 | + return null; |
|
181 | + } |
|
182 | + |
|
183 | + return $venue->status() == 'private'; |
|
184 | + } |
|
185 | + |
|
186 | + |
|
187 | + /** |
|
188 | + * returns true or false if a venue is password protected or not |
|
189 | + * |
|
190 | + * @param bool $VNU_ID venue to check (optional). If not included will use internally derived venue object. |
|
191 | + * @return bool |
|
192 | + * @throws EE_Error |
|
193 | + * @throws ReflectionException |
|
194 | + */ |
|
195 | + public static function is_venue_password_protected($VNU_ID = false) |
|
196 | + { |
|
197 | + $venue = EEH_Venue_View::get_venue($VNU_ID, true, true, false); |
|
198 | + if ( |
|
199 | + $venue instanceof EE_Venue |
|
200 | + && post_password_required($venue->ID()) |
|
201 | + ) { |
|
202 | + return true; |
|
203 | + } |
|
204 | + return false; |
|
205 | + } |
|
206 | + |
|
207 | + |
|
208 | + /** |
|
209 | + * If a venue is password protected, this will return the password form for gaining access |
|
210 | + * returns an empty string otherwise |
|
211 | + * |
|
212 | + * @param bool $VNU_ID venue to check (optional). If not included will use internally derived venue object. |
|
213 | + * |
|
214 | + * @return string |
|
215 | + * @throws EE_Error |
|
216 | + * @throws ReflectionException |
|
217 | + */ |
|
218 | + public static function password_protected_venue_form($VNU_ID = false) |
|
219 | + { |
|
220 | + $venue = EEH_Venue_View::get_venue($VNU_ID, true, true, false); |
|
221 | + if ( |
|
222 | + $venue instanceof EE_Venue |
|
223 | + && post_password_required($venue->ID()) |
|
224 | + ) { |
|
225 | + return get_the_password_form($venue->ID()); |
|
226 | + } |
|
227 | + return ''; |
|
228 | + } |
|
229 | + |
|
230 | + |
|
231 | + /** |
|
232 | + * venue_description |
|
233 | + * |
|
234 | + * @access public |
|
235 | + * @param int $VNU_ID |
|
236 | + * @return string |
|
237 | + * @throws EE_Error |
|
238 | + * @throws ReflectionException |
|
239 | + */ |
|
240 | + public static function venue_description($VNU_ID = 0) |
|
241 | + { |
|
242 | + $venue = EEH_Venue_View::get_venue($VNU_ID); |
|
243 | + if ($venue instanceof EE_Venue) { |
|
244 | + return $venue->get_pretty('VNU_desc'); |
|
245 | + } |
|
246 | + return ''; |
|
247 | + } |
|
248 | + |
|
249 | + |
|
250 | + /** |
|
251 | + * venue_excerpt |
|
252 | + * |
|
253 | + * @access public |
|
254 | + * @param int $VNU_ID |
|
255 | + * @return string |
|
256 | + * @throws EE_Error |
|
257 | + * @throws ReflectionException |
|
258 | + */ |
|
259 | + public static function venue_excerpt($VNU_ID = 0) |
|
260 | + { |
|
261 | + $venue = EEH_Venue_View::get_venue($VNU_ID); |
|
262 | + if ($venue instanceof EE_Venue) { |
|
263 | + $excerpt = $venue->excerpt() != null && $venue->excerpt() ? $venue->excerpt() : $venue->description(); |
|
264 | + $venue_link = ' ' . EEH_Venue_View::venue_details_link( |
|
265 | + $venue->ID(), |
|
266 | + esc_html__('more', 'event_espresso') . '…' |
|
267 | + ); |
|
268 | + return ! empty($excerpt) ? wp_trim_words($excerpt, 25, '') . $venue_link : ''; |
|
269 | + } |
|
270 | + return ''; |
|
271 | + } |
|
272 | + |
|
273 | + |
|
274 | + /** |
|
275 | + * venue_categories |
|
276 | + * |
|
277 | + * @access public |
|
278 | + * @param int $VNU_ID |
|
279 | + * @param bool $hide_uncategorized |
|
280 | + * @return string |
|
281 | + * @throws EE_Error |
|
282 | + * @throws ReflectionException |
|
283 | + */ |
|
284 | + public static function venue_categories($VNU_ID = 0, $hide_uncategorized = true) |
|
285 | + { |
|
286 | + $category_links = []; |
|
287 | + $venue = EEH_Venue_View::get_venue($VNU_ID); |
|
288 | + if ($venue instanceof EE_Venue) { |
|
289 | + // get category terms |
|
290 | + if ($venue_categories = get_the_terms($venue->ID(), 'espresso_venue_categories')) { |
|
291 | + // loop thru terms and create links |
|
292 | + foreach ($venue_categories as $term) { |
|
293 | + $url = get_term_link($term, 'espresso_venue_categories'); |
|
294 | + if ( |
|
295 | + ! is_wp_error($url) |
|
296 | + && (($hide_uncategorized |
|
297 | + && strtolower($term->name) != esc_html__( |
|
298 | + 'uncategorized', |
|
299 | + 'event_espresso' |
|
300 | + )) |
|
301 | + || ! $hide_uncategorized) |
|
302 | + ) { |
|
303 | + $category_links[] = '<a href="' . esc_url($url) . '" rel="tag">' . $term->name . '</a> '; |
|
304 | + } |
|
305 | + } |
|
306 | + } |
|
307 | + } |
|
308 | + return implode(', ', $category_links); |
|
309 | + } |
|
310 | + |
|
311 | + |
|
312 | + /** |
|
313 | + * venue_address |
|
314 | + * |
|
315 | + * @access public |
|
316 | + * @param string $type |
|
317 | + * @param int $VNU_ID |
|
318 | + * @param bool $use_schema |
|
319 | + * @param bool $add_wrapper |
|
320 | + * @return string |
|
321 | + * @throws EE_Error |
|
322 | + * @throws ReflectionException |
|
323 | + */ |
|
324 | + public static function venue_address($type = 'multiline', $VNU_ID = 0, $use_schema = true, $add_wrapper = true) |
|
325 | + { |
|
326 | + $venue = EEH_Venue_View::get_venue($VNU_ID); |
|
327 | + if ($venue instanceof EE_Venue) { |
|
328 | + return EEH_Address::format($venue, $type, $use_schema, $add_wrapper); |
|
329 | + } |
|
330 | + return ''; |
|
331 | + } |
|
332 | + |
|
333 | + |
|
334 | + /** |
|
335 | + * venue_has_address |
|
336 | + * |
|
337 | + * @access public |
|
338 | + * @param int $VNU_ID |
|
339 | + * @return bool|string |
|
340 | + * @throws EE_Error |
|
341 | + * @throws ReflectionException |
|
342 | + */ |
|
343 | + public static function venue_has_address($VNU_ID = 0) |
|
344 | + { |
|
345 | + $venue = EEH_Venue_View::get_venue($VNU_ID); |
|
346 | + if ($venue instanceof EE_Venue) { |
|
347 | + return EEH_Address::format($venue, 'inline', false, false); |
|
348 | + } |
|
349 | + return false; |
|
350 | + } |
|
351 | + |
|
352 | + |
|
353 | + /** |
|
354 | + * venue_name |
|
355 | + * |
|
356 | + * @access public |
|
357 | + * @param string $link_to - options( details, website, none ) whether to turn Venue name into a clickable link to |
|
358 | + * the Venue's details page or website |
|
359 | + * @param int $VNU_ID |
|
360 | + * @return string |
|
361 | + * @throws EE_Error |
|
362 | + * @throws ReflectionException |
|
363 | + */ |
|
364 | + public static function venue_name($link_to = 'details', $VNU_ID = 0) |
|
365 | + { |
|
366 | + $venue = EEH_Venue_View::get_venue($VNU_ID); |
|
367 | + if ($venue instanceof EE_Venue) { |
|
368 | + $venue_name = apply_filters( |
|
369 | + 'FHEE__EEH_Venue__venue_name__append_private_venue_name', |
|
370 | + EEH_Venue_View::is_venue_private() |
|
371 | + ? EEH_Venue_View::$_venue->name() . " " . esc_html__('(Private)', 'event_espresso') |
|
372 | + : EEH_Venue_View::$_venue->name(), |
|
373 | + EEH_Venue_View::$_venue |
|
374 | + ); |
|
375 | + $venue_name = EEH_Schema::name($venue_name); |
|
376 | + |
|
377 | + // if venue is trashed then ignore the "link to" setting because the venue is trashed. |
|
378 | + if ($venue->get('status') == 'trash') { |
|
379 | + $link_to = ''; |
|
380 | + } |
|
381 | + switch ($link_to) { |
|
382 | + case 'details': |
|
383 | + return EEH_Venue_View::venue_details_link($venue->ID(), $venue_name); |
|
384 | + |
|
385 | + case 'website': |
|
386 | + return EEH_Venue_View::venue_website_link($venue->ID(), $venue_name); |
|
387 | + |
|
388 | + default: |
|
389 | + return $venue_name; |
|
390 | + } |
|
391 | + } |
|
392 | + return ''; |
|
393 | + } |
|
394 | + |
|
395 | + |
|
396 | + /** |
|
397 | + * venue_details_link |
|
398 | + * |
|
399 | + * @access public |
|
400 | + * @param int $VNU_ID |
|
401 | + * @param string $text |
|
402 | + * @return string |
|
403 | + * @throws EE_Error |
|
404 | + * @throws ReflectionException |
|
405 | + */ |
|
406 | + public static function venue_details_link($VNU_ID = 0, $text = '') |
|
407 | + { |
|
408 | + $venue = EEH_Venue_View::get_venue($VNU_ID); |
|
409 | + if ($venue instanceof EE_Venue) { |
|
410 | + return EEH_Schema::url(get_permalink($venue->ID()), $text); |
|
411 | + } |
|
412 | + return ''; |
|
413 | + } |
|
414 | + |
|
415 | + |
|
416 | + /** |
|
417 | + * venue_website_link |
|
418 | + * |
|
419 | + * @access public |
|
420 | + * @param int $VNU_ID |
|
421 | + * @param string $text |
|
422 | + * @return string |
|
423 | + * @throws EE_Error |
|
424 | + * @throws ReflectionException |
|
425 | + */ |
|
426 | + public static function venue_website_link($VNU_ID = 0, $text = '') |
|
427 | + { |
|
428 | + $venue = EEH_Venue_View::get_venue($VNU_ID); |
|
429 | + if ($venue instanceof EE_Venue) { |
|
430 | + $url = $venue->venue_url(); |
|
431 | + $text = ! empty($text) ? $text : $url; |
|
432 | + return ! empty($url) ? EEH_Schema::url($url, $text, ['target' => '_blank']) : ''; |
|
433 | + } |
|
434 | + return ''; |
|
435 | + } |
|
436 | + |
|
437 | + |
|
438 | + /** |
|
439 | + * venue_phone |
|
440 | + * |
|
441 | + * @access public |
|
442 | + * @param int $VNU_ID |
|
443 | + * @return string |
|
444 | + * @throws EE_Error |
|
445 | + * @throws ReflectionException |
|
446 | + */ |
|
447 | + public static function venue_phone($VNU_ID = 0) |
|
448 | + { |
|
449 | + $venue = EEH_Venue_View::get_venue($VNU_ID); |
|
450 | + if ($venue instanceof EE_Venue) { |
|
451 | + return EEH_Schema::telephone($venue->phone()); |
|
452 | + } |
|
453 | + return ''; |
|
454 | + } |
|
455 | + |
|
456 | + |
|
457 | + /** |
|
458 | + * venue_gmap |
|
459 | + * |
|
460 | + * @access public |
|
461 | + * @param int $VNU_ID |
|
462 | + * @param bool|string $map_ID a unique identifier for this map |
|
463 | + * @param array $gmap map options |
|
464 | + * @return string |
|
465 | + * @throws EE_Error |
|
466 | + * @throws ReflectionException |
|
467 | + */ |
|
468 | + public static function venue_gmap($VNU_ID = 0, $map_ID = false, $gmap = []) |
|
469 | + { |
|
470 | + |
|
471 | + $venue = EEH_Venue_View::get_venue($VNU_ID); |
|
472 | + if ($venue instanceof EE_Venue) { |
|
473 | + // check for global espresso_events post and use its ID if no map_ID is set |
|
474 | + global $post; |
|
475 | + $map_ID = empty($map_ID) && $post->post_type == EspressoPostType::EVENTS ? $post->ID : $map_ID; |
|
476 | + // grab map settings |
|
477 | + $map_cfg = EE_Registry::instance()->CFG->map_settings; |
|
478 | + // are maps enabled ? |
|
479 | + if ($map_cfg->use_google_maps && $venue->enable_for_gmap()) { |
|
480 | + $details_page = is_single(); |
|
481 | + $options = []; |
|
482 | + |
|
483 | + $options['map_ID'] = $map_ID && $map_ID != $venue->ID() |
|
484 | + ? $map_ID . '-' . $venue->ID() |
|
485 | + : $venue->ID(); |
|
486 | + |
|
487 | + $options['location'] = EEH_Address::format($venue, 'inline', false, false); |
|
488 | + |
|
489 | + $options['ee_map_width'] = $details_page |
|
490 | + ? $map_cfg->event_details_map_width |
|
491 | + : $map_cfg->event_list_map_width; |
|
492 | + |
|
493 | + $options['ee_map_width'] = isset($gmap['ee_map_width']) && ! empty($gmap['ee_map_width']) |
|
494 | + ? $gmap['ee_map_width'] |
|
495 | + : $options['ee_map_width']; |
|
496 | + |
|
497 | + $options['ee_map_height'] = $details_page |
|
498 | + ? $map_cfg->event_details_map_height |
|
499 | + : $map_cfg->event_list_map_height; |
|
500 | + |
|
501 | + $options['ee_map_height'] = isset($gmap['ee_map_height']) && ! empty($gmap['ee_map_height']) |
|
502 | + ? $gmap['ee_map_height'] |
|
503 | + : $options['ee_map_height']; |
|
504 | + |
|
505 | + $options['ee_map_zoom'] = $details_page |
|
506 | + ? $map_cfg->event_details_map_zoom |
|
507 | + : $map_cfg->event_list_map_zoom; |
|
508 | + |
|
509 | + $options['ee_map_zoom'] = isset($gmap['ee_map_zoom']) && ! empty($gmap['ee_map_zoom']) |
|
510 | + ? $gmap['ee_map_zoom'] |
|
511 | + : $options['ee_map_zoom']; |
|
512 | + |
|
513 | + $options['ee_map_nav_display'] = $details_page |
|
514 | + ? $map_cfg->event_details_display_nav |
|
515 | + : $map_cfg->event_list_display_nav; |
|
516 | + |
|
517 | + $options['ee_map_nav_display'] = |
|
518 | + isset($gmap['ee_map_nav_display']) && ! empty($gmap['ee_map_nav_display']) |
|
519 | + ? 'true' |
|
520 | + : $options['ee_map_nav_display']; |
|
521 | + |
|
522 | + $options['ee_map_nav_size'] = $details_page |
|
523 | + ? $map_cfg->event_details_nav_size |
|
524 | + : $map_cfg->event_list_nav_size; |
|
525 | + |
|
526 | + $options['ee_map_nav_size'] = isset($gmap['ee_map_nav_size']) && ! empty($gmap['ee_map_nav_size']) |
|
527 | + ? $gmap['ee_map_nav_size'] |
|
528 | + : $options['ee_map_nav_size']; |
|
529 | + |
|
530 | + $options['ee_map_type_control'] = $details_page |
|
531 | + ? $map_cfg->event_details_control_type |
|
532 | + : $map_cfg->event_list_control_type; |
|
533 | + |
|
534 | + $options['ee_map_type_control'] = |
|
535 | + isset($gmap['ee_map_type_control']) && ! empty($gmap['ee_map_type_control']) |
|
536 | + ? $gmap['ee_map_type_control'] |
|
537 | + : $options['ee_map_type_control']; |
|
538 | + |
|
539 | + $options['ee_map_align'] = $details_page |
|
540 | + ? $map_cfg->event_details_map_align |
|
541 | + : $map_cfg->event_list_map_align; |
|
542 | + |
|
543 | + $options['ee_map_align'] = isset($gmap['ee_map_align']) && ! empty($gmap['ee_map_align']) |
|
544 | + ? $gmap['ee_map_align'] |
|
545 | + : $options['ee_map_align']; |
|
546 | + |
|
547 | + $options['ee_static_url'] = isset($gmap['ee_static_url']) && ! empty($gmap['ee_static_url']) |
|
548 | + ? (bool) absint($gmap['ee_static_url']) |
|
549 | + : $venue->google_map_link(); |
|
550 | + |
|
551 | + return EEH_Maps::google_map($options); |
|
552 | + } |
|
553 | + } |
|
554 | + |
|
555 | + return ''; |
|
556 | + } |
|
557 | + |
|
558 | + |
|
559 | + /** |
|
560 | + * Gets the HTML to display a static map of the venue |
|
561 | + * |
|
562 | + * @param EE_Venue $venue |
|
563 | + * @param array $attributes like EEH_Maps::google_map_link |
|
564 | + * @return string |
|
565 | + * @throws EE_Error |
|
566 | + * @throws ReflectionException |
|
567 | + */ |
|
568 | + public static function espresso_google_static_map(EE_Venue $venue, $attributes = []) |
|
569 | + { |
|
570 | + $state = $venue->state_obj(); |
|
571 | + $country = $venue->country_obj(); |
|
572 | + $attributes = shortcode_atts( |
|
573 | + [ |
|
574 | + 'id' => $venue->ID(), |
|
575 | + 'address' => $venue->get('VNU_address'), |
|
576 | + 'city' => $venue->get('VNU_city'), |
|
577 | + 'state' => $state instanceof EE_State ? $state->name() : '', |
|
578 | + 'zip' => $venue->get('VNU_zip'), |
|
579 | + 'country' => $country instanceof EE_Country ? $country->name() : '', |
|
580 | + 'type' => 'map', |
|
581 | + 'map_w' => 200, |
|
582 | + 'map_h' => 200, |
|
583 | + ], |
|
584 | + $attributes |
|
585 | + ); |
|
586 | + return EEH_Maps::google_map_link($attributes); |
|
587 | + } |
|
588 | + |
|
589 | + |
|
590 | + /** |
|
591 | + * edit_venue_link |
|
592 | + * |
|
593 | + * @access public |
|
594 | + * @param int $VNU_ID |
|
595 | + * @param string $link |
|
596 | + * @param string $before |
|
597 | + * @param string $after |
|
598 | + * @return string |
|
599 | + * @throws EE_Error |
|
600 | + * @throws ReflectionException |
|
601 | + */ |
|
602 | + public static function edit_venue_link( |
|
603 | + $VNU_ID = 0, |
|
604 | + $link = '', |
|
605 | + $before = '<p class="edit-venue-lnk small-txt">', |
|
606 | + $after = '</p>' |
|
607 | + ) { |
|
608 | + $venue = EEH_Venue_View::get_venue($VNU_ID); |
|
609 | + if ($venue instanceof EE_Venue) { |
|
610 | + // can the user edit this post ? |
|
611 | + if (current_user_can('edit_post', $venue->ID())) { |
|
612 | + // set link text |
|
613 | + $link = ! empty($link) ? $link : esc_html__('edit this venue', 'event_espresso'); |
|
614 | + // generate nonce |
|
615 | + $nonce = wp_create_nonce('edit_nonce'); |
|
616 | + // generate url to venue editor for this venue |
|
617 | + $url = |
|
618 | + add_query_arg( |
|
619 | + [ |
|
620 | + 'page' => 'espresso_venues', |
|
621 | + 'action' => 'edit', |
|
622 | + 'post' => $venue->ID(), |
|
623 | + 'edit_nonce' => $nonce, |
|
624 | + ], |
|
625 | + admin_url('admin.php') |
|
626 | + ); |
|
627 | + // get edit CPT text |
|
628 | + $post_type_obj = get_post_type_object(EspressoPostType::VENUES); |
|
629 | + // build final link html |
|
630 | + $link = |
|
631 | + '<a class="post-edit-link" href="' . $url . '" title="' . esc_attr( |
|
632 | + $post_type_obj->labels->edit_item |
|
633 | + ) . '">' . $link . '</a>'; |
|
634 | + // put it all together |
|
635 | + return $before . apply_filters('edit_post_link', $link, $venue->ID()) . $after; |
|
636 | + } |
|
637 | + } |
|
638 | + return ''; |
|
639 | + } |
|
640 | 640 | } |
@@ -100,7 +100,7 @@ discard block |
||
100 | 100 | } |
101 | 101 | } |
102 | 102 | // now if we STILL do NOT have an EE_Venue model object, BUT we have a Venue ID... |
103 | - if (! EEH_Venue_View::$_venue instanceof EE_Venue && $VNU_ID) { |
|
103 | + if ( ! EEH_Venue_View::$_venue instanceof EE_Venue && $VNU_ID) { |
|
104 | 104 | // sigh... pull it from the db |
105 | 105 | EEH_Venue_View::$_venue = EEM_Venue::instance()->get_one_by_ID($VNU_ID); |
106 | 106 | } |
@@ -176,7 +176,7 @@ discard block |
||
176 | 176 | public static function is_venue_private($VNU_ID = false) |
177 | 177 | { |
178 | 178 | $venue = EEH_Venue_View::get_venue($VNU_ID); |
179 | - if (! $venue instanceof EE_Venue) { |
|
179 | + if ( ! $venue instanceof EE_Venue) { |
|
180 | 180 | return null; |
181 | 181 | } |
182 | 182 | |
@@ -261,11 +261,11 @@ discard block |
||
261 | 261 | $venue = EEH_Venue_View::get_venue($VNU_ID); |
262 | 262 | if ($venue instanceof EE_Venue) { |
263 | 263 | $excerpt = $venue->excerpt() != null && $venue->excerpt() ? $venue->excerpt() : $venue->description(); |
264 | - $venue_link = ' ' . EEH_Venue_View::venue_details_link( |
|
264 | + $venue_link = ' '.EEH_Venue_View::venue_details_link( |
|
265 | 265 | $venue->ID(), |
266 | - esc_html__('more', 'event_espresso') . '…' |
|
266 | + esc_html__('more', 'event_espresso').'…' |
|
267 | 267 | ); |
268 | - return ! empty($excerpt) ? wp_trim_words($excerpt, 25, '') . $venue_link : ''; |
|
268 | + return ! empty($excerpt) ? wp_trim_words($excerpt, 25, '').$venue_link : ''; |
|
269 | 269 | } |
270 | 270 | return ''; |
271 | 271 | } |
@@ -300,7 +300,7 @@ discard block |
||
300 | 300 | )) |
301 | 301 | || ! $hide_uncategorized) |
302 | 302 | ) { |
303 | - $category_links[] = '<a href="' . esc_url($url) . '" rel="tag">' . $term->name . '</a> '; |
|
303 | + $category_links[] = '<a href="'.esc_url($url).'" rel="tag">'.$term->name.'</a> '; |
|
304 | 304 | } |
305 | 305 | } |
306 | 306 | } |
@@ -368,7 +368,7 @@ discard block |
||
368 | 368 | $venue_name = apply_filters( |
369 | 369 | 'FHEE__EEH_Venue__venue_name__append_private_venue_name', |
370 | 370 | EEH_Venue_View::is_venue_private() |
371 | - ? EEH_Venue_View::$_venue->name() . " " . esc_html__('(Private)', 'event_espresso') |
|
371 | + ? EEH_Venue_View::$_venue->name()." ".esc_html__('(Private)', 'event_espresso') |
|
372 | 372 | : EEH_Venue_View::$_venue->name(), |
373 | 373 | EEH_Venue_View::$_venue |
374 | 374 | ); |
@@ -481,7 +481,7 @@ discard block |
||
481 | 481 | $options = []; |
482 | 482 | |
483 | 483 | $options['map_ID'] = $map_ID && $map_ID != $venue->ID() |
484 | - ? $map_ID . '-' . $venue->ID() |
|
484 | + ? $map_ID.'-'.$venue->ID() |
|
485 | 485 | : $venue->ID(); |
486 | 486 | |
487 | 487 | $options['location'] = EEH_Address::format($venue, 'inline', false, false); |
@@ -628,11 +628,11 @@ discard block |
||
628 | 628 | $post_type_obj = get_post_type_object(EspressoPostType::VENUES); |
629 | 629 | // build final link html |
630 | 630 | $link = |
631 | - '<a class="post-edit-link" href="' . $url . '" title="' . esc_attr( |
|
631 | + '<a class="post-edit-link" href="'.$url.'" title="'.esc_attr( |
|
632 | 632 | $post_type_obj->labels->edit_item |
633 | - ) . '">' . $link . '</a>'; |
|
633 | + ).'">'.$link.'</a>'; |
|
634 | 634 | // put it all together |
635 | - return $before . apply_filters('edit_post_link', $link, $venue->ID()) . $after; |
|
635 | + return $before.apply_filters('edit_post_link', $link, $venue->ID()).$after; |
|
636 | 636 | } |
637 | 637 | } |
638 | 638 | return ''; |
@@ -11,200 +11,200 @@ |
||
11 | 11 | */ |
12 | 12 | class EEH_Export |
13 | 13 | { |
14 | - /** |
|
15 | - * Gets the 'normal' column named for fields |
|
16 | - * |
|
17 | - * @param EE_Model_Field_Base $field |
|
18 | - * @return string |
|
19 | - * @throws EE_Error |
|
20 | - */ |
|
21 | - public static function get_column_name_for_field(EE_Model_Field_Base $field): string |
|
22 | - { |
|
23 | - $column_name = wp_specialchars_decode($field->get_nicename(), ENT_QUOTES); |
|
24 | - if ( |
|
25 | - apply_filters( |
|
26 | - 'FHEE__EEH_Export__get_column_name_for_field__add_field_name', |
|
27 | - false, |
|
28 | - $column_name, |
|
29 | - $field |
|
30 | - ) |
|
31 | - ) { |
|
32 | - $column_name .= "[" |
|
33 | - . wp_specialchars_decode($field->get_name(), ENT_QUOTES) |
|
34 | - . "]"; |
|
35 | - } |
|
36 | - return $column_name; |
|
37 | - } |
|
14 | + /** |
|
15 | + * Gets the 'normal' column named for fields |
|
16 | + * |
|
17 | + * @param EE_Model_Field_Base $field |
|
18 | + * @return string |
|
19 | + * @throws EE_Error |
|
20 | + */ |
|
21 | + public static function get_column_name_for_field(EE_Model_Field_Base $field): string |
|
22 | + { |
|
23 | + $column_name = wp_specialchars_decode($field->get_nicename(), ENT_QUOTES); |
|
24 | + if ( |
|
25 | + apply_filters( |
|
26 | + 'FHEE__EEH_Export__get_column_name_for_field__add_field_name', |
|
27 | + false, |
|
28 | + $column_name, |
|
29 | + $field |
|
30 | + ) |
|
31 | + ) { |
|
32 | + $column_name .= "[" |
|
33 | + . wp_specialchars_decode($field->get_name(), ENT_QUOTES) |
|
34 | + . "]"; |
|
35 | + } |
|
36 | + return $column_name; |
|
37 | + } |
|
38 | 38 | |
39 | 39 | |
40 | - /** |
|
41 | - * Writes $data to the csv file open in $filehandle. uses the array indices of $data for column headers |
|
42 | - * |
|
43 | - * @param string $filepath |
|
44 | - * @param array $data 2D array,first numerically-indexed, |
|
45 | - * and next-level-down preferably indexed by string |
|
46 | - * @param bool $write_column_headers whether or not we should add the keys in the bottom-most array |
|
47 | - * as a row for headers in the CSV. |
|
48 | - * Eg, if $data looked like: |
|
49 | - * array( |
|
50 | - * 0=>array('EVT_ID'=>1,'EVT_name'=>'monkey'...), |
|
51 | - * 1=>array(...,...) |
|
52 | - * ) |
|
53 | - * @param bool $headers_only if true then we won't print any data, just headers. defaults to |
|
54 | - * false |
|
55 | - * @return boolean if we successfully wrote to the CSV or not. If there's no $data, |
|
56 | - * we consider that a success (because we wrote everything there |
|
57 | - * was...nothing) |
|
58 | - * @throws EE_Error |
|
59 | - */ |
|
60 | - public static function write_data_array_to_csv( |
|
61 | - string $filepath, |
|
62 | - array $data, |
|
63 | - bool $write_column_headers = true, |
|
64 | - bool $headers_only = false |
|
65 | - ): bool { |
|
66 | - // determine if $data is actually a 2d array |
|
67 | - if ($data && is_array(EEH_Array::get_one_item_from_array($data))) { |
|
68 | - // make sure top level is numerically indexed, |
|
69 | - if (EEH_Array::is_associative_array($data)) { |
|
70 | - throw new EE_Error( |
|
71 | - sprintf( |
|
72 | - esc_html__( |
|
73 | - "top-level array must be numerically indexed. Does these look like numbers to you? %s", |
|
74 | - "event_espresso" |
|
75 | - ), |
|
76 | - implode(",", array_keys($data)) |
|
77 | - ) |
|
78 | - ); |
|
79 | - } |
|
80 | - $new_file_contents = ''; |
|
81 | - $item_in_top_level_array = EEH_Array::get_one_item_from_array($data); |
|
82 | - // now, is the last item in the top-level array of $data an associative or numeric array? |
|
83 | - if ($write_column_headers && EEH_Array::is_associative_array($item_in_top_level_array)) { |
|
84 | - // its associative, so we want to output its keys as column headers |
|
85 | - $keys = array_keys($item_in_top_level_array); |
|
86 | - $new_file_contents .= EEH_Export::get_csv_row($keys); |
|
87 | - if ($headers_only) { |
|
88 | - return EEH_File::write_to_file( |
|
89 | - $filepath, |
|
90 | - EEH_File::get_file_contents($filepath) . $new_file_contents |
|
91 | - ); |
|
92 | - } |
|
93 | - } |
|
94 | - // start writing data |
|
95 | - foreach ($data as $data_row) { |
|
96 | - $new_row = EEH_Export::get_csv_row($data_row); |
|
97 | - $new_file_contents .= $new_row ?: ''; |
|
98 | - } |
|
99 | - return EEH_File::write_to_file($filepath, EEH_File::get_file_contents($filepath) . $new_file_contents); |
|
100 | - } |
|
101 | - // no data TO write... so we can assume that's a success |
|
102 | - return true; |
|
103 | - } |
|
40 | + /** |
|
41 | + * Writes $data to the csv file open in $filehandle. uses the array indices of $data for column headers |
|
42 | + * |
|
43 | + * @param string $filepath |
|
44 | + * @param array $data 2D array,first numerically-indexed, |
|
45 | + * and next-level-down preferably indexed by string |
|
46 | + * @param bool $write_column_headers whether or not we should add the keys in the bottom-most array |
|
47 | + * as a row for headers in the CSV. |
|
48 | + * Eg, if $data looked like: |
|
49 | + * array( |
|
50 | + * 0=>array('EVT_ID'=>1,'EVT_name'=>'monkey'...), |
|
51 | + * 1=>array(...,...) |
|
52 | + * ) |
|
53 | + * @param bool $headers_only if true then we won't print any data, just headers. defaults to |
|
54 | + * false |
|
55 | + * @return boolean if we successfully wrote to the CSV or not. If there's no $data, |
|
56 | + * we consider that a success (because we wrote everything there |
|
57 | + * was...nothing) |
|
58 | + * @throws EE_Error |
|
59 | + */ |
|
60 | + public static function write_data_array_to_csv( |
|
61 | + string $filepath, |
|
62 | + array $data, |
|
63 | + bool $write_column_headers = true, |
|
64 | + bool $headers_only = false |
|
65 | + ): bool { |
|
66 | + // determine if $data is actually a 2d array |
|
67 | + if ($data && is_array(EEH_Array::get_one_item_from_array($data))) { |
|
68 | + // make sure top level is numerically indexed, |
|
69 | + if (EEH_Array::is_associative_array($data)) { |
|
70 | + throw new EE_Error( |
|
71 | + sprintf( |
|
72 | + esc_html__( |
|
73 | + "top-level array must be numerically indexed. Does these look like numbers to you? %s", |
|
74 | + "event_espresso" |
|
75 | + ), |
|
76 | + implode(",", array_keys($data)) |
|
77 | + ) |
|
78 | + ); |
|
79 | + } |
|
80 | + $new_file_contents = ''; |
|
81 | + $item_in_top_level_array = EEH_Array::get_one_item_from_array($data); |
|
82 | + // now, is the last item in the top-level array of $data an associative or numeric array? |
|
83 | + if ($write_column_headers && EEH_Array::is_associative_array($item_in_top_level_array)) { |
|
84 | + // its associative, so we want to output its keys as column headers |
|
85 | + $keys = array_keys($item_in_top_level_array); |
|
86 | + $new_file_contents .= EEH_Export::get_csv_row($keys); |
|
87 | + if ($headers_only) { |
|
88 | + return EEH_File::write_to_file( |
|
89 | + $filepath, |
|
90 | + EEH_File::get_file_contents($filepath) . $new_file_contents |
|
91 | + ); |
|
92 | + } |
|
93 | + } |
|
94 | + // start writing data |
|
95 | + foreach ($data as $data_row) { |
|
96 | + $new_row = EEH_Export::get_csv_row($data_row); |
|
97 | + $new_file_contents .= $new_row ?: ''; |
|
98 | + } |
|
99 | + return EEH_File::write_to_file($filepath, EEH_File::get_file_contents($filepath) . $new_file_contents); |
|
100 | + } |
|
101 | + // no data TO write... so we can assume that's a success |
|
102 | + return true; |
|
103 | + } |
|
104 | 104 | |
105 | 105 | |
106 | - /** |
|
107 | - * |
|
108 | - * Writes a row to the csv file |
|
109 | - * |
|
110 | - * @param array $row - individual row of csv data |
|
111 | - * @param string $delimiter - csv delimiter |
|
112 | - * @param string $enclosure - csv enclosure |
|
113 | - * @param bool $mysql_null - allows php NULL to be overridden with MySQl's insertable NULL value |
|
114 | - * @return string of text for teh csv file |
|
115 | - */ |
|
116 | - public static function get_csv_row( |
|
117 | - array $row, |
|
118 | - string $delimiter = ',', |
|
119 | - string $enclosure = '"', |
|
120 | - bool $mysql_null = false |
|
121 | - ): string { |
|
122 | - // Allow user to filter the csv delimiter and enclosure for other countries csv standards |
|
123 | - $delimiter = apply_filters('FHEE__EE_CSV__fputcsv2__delimiter', $delimiter); |
|
124 | - $enclosure = apply_filters('FHEE__EE_CSV__fputcsv2__enclosure', $enclosure); |
|
106 | + /** |
|
107 | + * |
|
108 | + * Writes a row to the csv file |
|
109 | + * |
|
110 | + * @param array $row - individual row of csv data |
|
111 | + * @param string $delimiter - csv delimiter |
|
112 | + * @param string $enclosure - csv enclosure |
|
113 | + * @param bool $mysql_null - allows php NULL to be overridden with MySQl's insertable NULL value |
|
114 | + * @return string of text for teh csv file |
|
115 | + */ |
|
116 | + public static function get_csv_row( |
|
117 | + array $row, |
|
118 | + string $delimiter = ',', |
|
119 | + string $enclosure = '"', |
|
120 | + bool $mysql_null = false |
|
121 | + ): string { |
|
122 | + // Allow user to filter the csv delimiter and enclosure for other countries csv standards |
|
123 | + $delimiter = apply_filters('FHEE__EE_CSV__fputcsv2__delimiter', $delimiter); |
|
124 | + $enclosure = apply_filters('FHEE__EE_CSV__fputcsv2__enclosure', $enclosure); |
|
125 | 125 | |
126 | - $delimiter_esc = preg_quote($delimiter, '/'); |
|
127 | - $enclosure_esc = preg_quote($enclosure, '/'); |
|
126 | + $delimiter_esc = preg_quote($delimiter, '/'); |
|
127 | + $enclosure_esc = preg_quote($enclosure, '/'); |
|
128 | 128 | |
129 | - $output = []; |
|
130 | - foreach ($row as $field_value) { |
|
131 | - if (is_object($field_value) || is_array($field_value)) { |
|
132 | - $field_value = serialize($field_value); |
|
133 | - } |
|
134 | - if ($field_value === null && $mysql_null) { |
|
135 | - $output[] = 'NULL'; |
|
136 | - continue; |
|
137 | - } |
|
129 | + $output = []; |
|
130 | + foreach ($row as $field_value) { |
|
131 | + if (is_object($field_value) || is_array($field_value)) { |
|
132 | + $field_value = serialize($field_value); |
|
133 | + } |
|
134 | + if ($field_value === null && $mysql_null) { |
|
135 | + $output[] = 'NULL'; |
|
136 | + continue; |
|
137 | + } |
|
138 | 138 | |
139 | - $output[] = $field_value && preg_match("/(?:$delimiter_esc|$enclosure_esc|\s)/", $field_value) |
|
140 | - ? ($enclosure . str_replace($enclosure, $enclosure . $enclosure, $field_value) . $enclosure) |
|
141 | - : $field_value; |
|
142 | - } |
|
139 | + $output[] = $field_value && preg_match("/(?:$delimiter_esc|$enclosure_esc|\s)/", $field_value) |
|
140 | + ? ($enclosure . str_replace($enclosure, $enclosure . $enclosure, $field_value) . $enclosure) |
|
141 | + : $field_value; |
|
142 | + } |
|
143 | 143 | |
144 | - return implode($delimiter, $output) . PHP_EOL; |
|
145 | - } |
|
144 | + return implode($delimiter, $output) . PHP_EOL; |
|
145 | + } |
|
146 | 146 | |
147 | 147 | |
148 | - /** |
|
149 | - * Shortcut for preparing a database result for display |
|
150 | - * |
|
151 | - * @param EEM_Base $model |
|
152 | - * @param string $field_name |
|
153 | - * @param int|float|string $raw_db_value |
|
154 | - * @param boolean|string $pretty_schema true to display pretty, |
|
155 | - * a string to use a specific "Schema", |
|
156 | - * or false to NOT display pretty |
|
157 | - * @return string |
|
158 | - * @throws EE_Error |
|
159 | - */ |
|
160 | - public static function prepare_value_from_db_for_display( |
|
161 | - EEM_Base $model, |
|
162 | - string $field_name, |
|
163 | - $raw_db_value, |
|
164 | - $pretty_schema = true |
|
165 | - ): string { |
|
166 | - $field_obj = $model->field_settings_for($field_name); |
|
167 | - $value_on_model_obj = $field_obj->prepare_for_set_from_db($raw_db_value); |
|
168 | - if ($field_obj instanceof EE_Datetime_Field) { |
|
169 | - $field_obj->set_date_format( |
|
170 | - EEH_Export::get_date_format_for_export($field_obj->get_date_format($pretty_schema)), |
|
171 | - $pretty_schema |
|
172 | - ); |
|
173 | - $field_obj->set_time_format( |
|
174 | - EEH_Export::get_time_format_for_export($field_obj->get_time_format($pretty_schema)), |
|
175 | - $pretty_schema |
|
176 | - ); |
|
177 | - } |
|
178 | - if ($pretty_schema === true) { |
|
179 | - return $field_obj->prepare_for_pretty_echoing($value_on_model_obj); |
|
180 | - } |
|
181 | - if (is_string($pretty_schema)) { |
|
182 | - return $field_obj->prepare_for_pretty_echoing($value_on_model_obj, $pretty_schema); |
|
183 | - } |
|
184 | - return $field_obj->prepare_for_get($value_on_model_obj); |
|
185 | - } |
|
148 | + /** |
|
149 | + * Shortcut for preparing a database result for display |
|
150 | + * |
|
151 | + * @param EEM_Base $model |
|
152 | + * @param string $field_name |
|
153 | + * @param int|float|string $raw_db_value |
|
154 | + * @param boolean|string $pretty_schema true to display pretty, |
|
155 | + * a string to use a specific "Schema", |
|
156 | + * or false to NOT display pretty |
|
157 | + * @return string |
|
158 | + * @throws EE_Error |
|
159 | + */ |
|
160 | + public static function prepare_value_from_db_for_display( |
|
161 | + EEM_Base $model, |
|
162 | + string $field_name, |
|
163 | + $raw_db_value, |
|
164 | + $pretty_schema = true |
|
165 | + ): string { |
|
166 | + $field_obj = $model->field_settings_for($field_name); |
|
167 | + $value_on_model_obj = $field_obj->prepare_for_set_from_db($raw_db_value); |
|
168 | + if ($field_obj instanceof EE_Datetime_Field) { |
|
169 | + $field_obj->set_date_format( |
|
170 | + EEH_Export::get_date_format_for_export($field_obj->get_date_format($pretty_schema)), |
|
171 | + $pretty_schema |
|
172 | + ); |
|
173 | + $field_obj->set_time_format( |
|
174 | + EEH_Export::get_time_format_for_export($field_obj->get_time_format($pretty_schema)), |
|
175 | + $pretty_schema |
|
176 | + ); |
|
177 | + } |
|
178 | + if ($pretty_schema === true) { |
|
179 | + return $field_obj->prepare_for_pretty_echoing($value_on_model_obj); |
|
180 | + } |
|
181 | + if (is_string($pretty_schema)) { |
|
182 | + return $field_obj->prepare_for_pretty_echoing($value_on_model_obj, $pretty_schema); |
|
183 | + } |
|
184 | + return $field_obj->prepare_for_get($value_on_model_obj); |
|
185 | + } |
|
186 | 186 | |
187 | 187 | |
188 | - /** |
|
189 | - * Gets the date format to use in exports. filterable |
|
190 | - * |
|
191 | - * @param string|null $current_format |
|
192 | - * @return string |
|
193 | - */ |
|
194 | - public static function get_date_format_for_export(?string $current_format = null): string |
|
195 | - { |
|
196 | - return apply_filters('FHEE__EE_CSV__get_date_format_for_csv__format', 'Y-m-d', $current_format); |
|
197 | - } |
|
188 | + /** |
|
189 | + * Gets the date format to use in exports. filterable |
|
190 | + * |
|
191 | + * @param string|null $current_format |
|
192 | + * @return string |
|
193 | + */ |
|
194 | + public static function get_date_format_for_export(?string $current_format = null): string |
|
195 | + { |
|
196 | + return apply_filters('FHEE__EE_CSV__get_date_format_for_csv__format', 'Y-m-d', $current_format); |
|
197 | + } |
|
198 | 198 | |
199 | 199 | |
200 | - /** |
|
201 | - * Gets the time format we want to use in exports. Filterable |
|
202 | - * |
|
203 | - * @param string|null $current_format |
|
204 | - * @return string |
|
205 | - */ |
|
206 | - public static function get_time_format_for_export(?string $current_format = null): string |
|
207 | - { |
|
208 | - return apply_filters('FHEE__EE_CSV__get_time_format_for_csv__format', 'H:i:s', $current_format); |
|
209 | - } |
|
200 | + /** |
|
201 | + * Gets the time format we want to use in exports. Filterable |
|
202 | + * |
|
203 | + * @param string|null $current_format |
|
204 | + * @return string |
|
205 | + */ |
|
206 | + public static function get_time_format_for_export(?string $current_format = null): string |
|
207 | + { |
|
208 | + return apply_filters('FHEE__EE_CSV__get_time_format_for_csv__format', 'H:i:s', $current_format); |
|
209 | + } |
|
210 | 210 | } |
@@ -82,21 +82,21 @@ discard block |
||
82 | 82 | // now, is the last item in the top-level array of $data an associative or numeric array? |
83 | 83 | if ($write_column_headers && EEH_Array::is_associative_array($item_in_top_level_array)) { |
84 | 84 | // its associative, so we want to output its keys as column headers |
85 | - $keys = array_keys($item_in_top_level_array); |
|
85 | + $keys = array_keys($item_in_top_level_array); |
|
86 | 86 | $new_file_contents .= EEH_Export::get_csv_row($keys); |
87 | 87 | if ($headers_only) { |
88 | 88 | return EEH_File::write_to_file( |
89 | 89 | $filepath, |
90 | - EEH_File::get_file_contents($filepath) . $new_file_contents |
|
90 | + EEH_File::get_file_contents($filepath).$new_file_contents |
|
91 | 91 | ); |
92 | 92 | } |
93 | 93 | } |
94 | 94 | // start writing data |
95 | 95 | foreach ($data as $data_row) { |
96 | - $new_row = EEH_Export::get_csv_row($data_row); |
|
96 | + $new_row = EEH_Export::get_csv_row($data_row); |
|
97 | 97 | $new_file_contents .= $new_row ?: ''; |
98 | 98 | } |
99 | - return EEH_File::write_to_file($filepath, EEH_File::get_file_contents($filepath) . $new_file_contents); |
|
99 | + return EEH_File::write_to_file($filepath, EEH_File::get_file_contents($filepath).$new_file_contents); |
|
100 | 100 | } |
101 | 101 | // no data TO write... so we can assume that's a success |
102 | 102 | return true; |
@@ -137,11 +137,11 @@ discard block |
||
137 | 137 | } |
138 | 138 | |
139 | 139 | $output[] = $field_value && preg_match("/(?:$delimiter_esc|$enclosure_esc|\s)/", $field_value) |
140 | - ? ($enclosure . str_replace($enclosure, $enclosure . $enclosure, $field_value) . $enclosure) |
|
140 | + ? ($enclosure.str_replace($enclosure, $enclosure.$enclosure, $field_value).$enclosure) |
|
141 | 141 | : $field_value; |
142 | 142 | } |
143 | 143 | |
144 | - return implode($delimiter, $output) . PHP_EOL; |
|
144 | + return implode($delimiter, $output).PHP_EOL; |
|
145 | 145 | } |
146 | 146 | |
147 | 147 |
@@ -42,610 +42,610 @@ |
||
42 | 42 | */ |
43 | 43 | class RegistrationsReport extends JobHandlerFile |
44 | 44 | { |
45 | - // phpcs:disable PSR1.Methods.CamelCapsMethodName.NotCamelCaps |
|
46 | - // phpcs:disable PSR2.Methods.MethodDeclaration.Underscore |
|
47 | - /** |
|
48 | - * Performs any necessary setup for starting the job. This is also a good |
|
49 | - * place to setup the $job_arguments which will be used for subsequent HTTP requests |
|
50 | - * when continue_job will be called |
|
51 | - * |
|
52 | - * @param JobParameters $job_parameters |
|
53 | - * @return JobStepResponse |
|
54 | - * @throws BatchRequestException |
|
55 | - * @throws EE_Error |
|
56 | - * @throws ReflectionException |
|
57 | - */ |
|
58 | - public function create_job(JobParameters $job_parameters): JobStepResponse |
|
59 | - { |
|
60 | - $event_id = absint($job_parameters->request_datum('EVT_ID', '0')); |
|
61 | - $DTT_ID = absint($job_parameters->request_datum('DTT_ID', '0')); |
|
62 | - if (! EE_Capabilities::instance()->current_user_can('ee_read_registrations', 'generating_report')) { |
|
63 | - throw new BatchRequestException( |
|
64 | - esc_html__('You do not have permission to view registrations', 'event_espresso') |
|
65 | - ); |
|
66 | - } |
|
67 | - $filepath = $this->create_file_from_job_with_name( |
|
68 | - $job_parameters->job_id(), |
|
69 | - $this->get_filename() |
|
70 | - ); |
|
71 | - $job_parameters->add_extra_data('filepath', $filepath); |
|
72 | - |
|
73 | - if ($job_parameters->request_datum('use_filters', false)) { |
|
74 | - $query_params = maybe_unserialize($job_parameters->request_datum('filters', [])); |
|
75 | - } else { |
|
76 | - $query_params = [ |
|
77 | - [ 'Ticket.TKT_deleted' => ['IN', [true, false]] ], |
|
78 | - 'order_by' => ['Transaction.TXN_ID' => 'asc', 'REG_count' => 'asc'], |
|
79 | - 'force_join' => ['Transaction', 'Ticket', 'Attendee'], |
|
80 | - 'caps' => EEM_Base::caps_read_admin, |
|
81 | - ]; |
|
82 | - if ($event_id) { |
|
83 | - $query_params[0]['EVT_ID'] = $event_id; |
|
84 | - } else { |
|
85 | - $query_params['force_join'][] = 'Event'; |
|
86 | - } |
|
87 | - } |
|
88 | - // unless the query params already include a status, |
|
89 | - // we want to exclude registrations from failed or abandoned transactions |
|
90 | - if (! isset($query_params[0]['Transaction.STS_ID'])) { |
|
91 | - $query_params[0]['OR'] = [ |
|
92 | - // don't include registrations from failed or abandoned transactions... |
|
93 | - 'Transaction.STS_ID' => [ |
|
94 | - 'NOT IN', |
|
95 | - [ |
|
96 | - EEM_Transaction::failed_status_code, |
|
97 | - EEM_Transaction::abandoned_status_code, |
|
98 | - ], |
|
99 | - ], |
|
100 | - // unless the registration is approved, |
|
101 | - // in which case include it regardless of transaction status |
|
102 | - 'STS_ID' => EEM_Registration::status_id_approved, |
|
103 | - ]; |
|
104 | - } |
|
105 | - |
|
106 | - if (! isset($query_params['force_join'])) { |
|
107 | - $query_params['force_join'] = ['Event', 'Transaction', 'Ticket', 'Attendee']; |
|
108 | - } |
|
109 | - |
|
110 | - $return_url_args = []; |
|
111 | - parse_str( |
|
112 | - parse_url( |
|
113 | - $job_parameters->request_datum('return_url', ''), |
|
114 | - PHP_URL_QUERY |
|
115 | - ), |
|
116 | - $return_url_args |
|
117 | - ); |
|
118 | - |
|
119 | - if ( |
|
120 | - isset($return_url_args['orderby'], $return_url_args['order']) |
|
121 | - && $return_url_args['orderby'] === 'ATT_lname' |
|
122 | - ) { |
|
123 | - $query_params['order_by'] = [ |
|
124 | - 'Attendee.ATT_lname' => $return_url_args['order'], |
|
125 | - 'Attendee.ATT_fname' => $return_url_args['order'], |
|
126 | - 'REG_ID' => $return_url_args['order'] |
|
127 | - ]; |
|
128 | - } |
|
129 | - |
|
130 | - $query_params = apply_filters( |
|
131 | - 'FHEE__EE_Export__report_registration_for_event', |
|
132 | - $query_params, |
|
133 | - $event_id |
|
134 | - ); |
|
135 | - |
|
136 | - $job_parameters->add_extra_data('query_params', $query_params); |
|
137 | - $question_labels = $this->_get_question_labels($query_params); |
|
138 | - $job_parameters->add_extra_data('question_labels', $question_labels); |
|
139 | - $job_parameters->set_job_size($this->count_units_to_process($query_params)); |
|
140 | - // we need to set the header columns |
|
141 | - // but to do that we need to process one row so that we can extract ALL of the column headers |
|
142 | - $csv_data_for_row = $this->get_csv_data_for( |
|
143 | - $event_id, |
|
144 | - 0, |
|
145 | - 1, |
|
146 | - $question_labels, |
|
147 | - $query_params, |
|
148 | - $DTT_ID |
|
149 | - ); |
|
150 | - // but we don't want to write any actual data yet... |
|
151 | - // so let's blank out all the values for that first row |
|
152 | - array_walk( |
|
153 | - $csv_data_for_row[0], |
|
154 | - function (&$value) { |
|
155 | - $value = null; |
|
156 | - } |
|
157 | - ); |
|
158 | - |
|
159 | - EEH_Export::write_data_array_to_csv($filepath, $csv_data_for_row, true, true); |
|
160 | - $this->updateTextHeader( |
|
161 | - esc_html__('Registrations report started successfully...', 'event_espresso') |
|
162 | - ); |
|
163 | - return new JobStepResponse($job_parameters, $this->feedback); |
|
164 | - } |
|
165 | - |
|
166 | - |
|
167 | - /** |
|
168 | - * Gets the filename |
|
169 | - * |
|
170 | - * @return string |
|
171 | - */ |
|
172 | - protected function get_filename(): string |
|
173 | - { |
|
174 | - return apply_filters( |
|
175 | - 'FHEE__EventEspressoBatchRequest__JobHandlers__RegistrationsReport__get_filename', |
|
176 | - sprintf( |
|
177 | - 'event-espresso-registrations-%s.csv', |
|
178 | - str_replace([':', ' '], '-', current_time('mysql')) |
|
179 | - ) |
|
180 | - ); |
|
181 | - } |
|
182 | - |
|
183 | - |
|
184 | - /** |
|
185 | - * Gets the questions which are to be used for this report, |
|
186 | - * so they can be remembered for later |
|
187 | - * |
|
188 | - * @param array $registration_query_params |
|
189 | - * @return array question admin labels to be used for this report |
|
190 | - * @throws EE_Error |
|
191 | - * @throws ReflectionException |
|
192 | - */ |
|
193 | - protected function _get_question_labels(array $registration_query_params): array |
|
194 | - { |
|
195 | - $where = $registration_query_params[0] ?? null; |
|
196 | - $question_query_params = []; |
|
197 | - if ($where !== null) { |
|
198 | - $question_query_params = [ |
|
199 | - $this->_change_registration_where_params_to_question_where_params($registration_query_params[0]), |
|
200 | - ]; |
|
201 | - } |
|
202 | - // Make sure it's not a system question |
|
203 | - $question_query_params[0]['OR*not-system-questions'] = [ |
|
204 | - 'QST_system' => '', |
|
205 | - 'QST_system*null' => ['IS_NULL'] |
|
206 | - ]; |
|
207 | - if ( |
|
208 | - apply_filters( |
|
209 | - 'FHEE__EventEspressoBatchRequest__JobHandlers__RegistrationsReport___get_question_labels__only_include_answered_questions', |
|
210 | - false, |
|
211 | - $registration_query_params |
|
212 | - ) |
|
213 | - ) { |
|
214 | - $question_query_params[0]['Answer.ANS_ID'] = ['IS_NOT_NULL']; |
|
215 | - } |
|
216 | - $question_query_params['order_by'] = [ |
|
217 | - 'Question_Group_Question.QGQ_order' => 'ASC', |
|
218 | - 'QST_order' => 'ASC', |
|
219 | - 'QST_admin_label' => 'ASC' |
|
220 | - ]; |
|
221 | - $question_query_params['group_by'] = ['QST_ID']; |
|
222 | - return array_unique(EEM_Question::instance()->get_col($question_query_params, 'QST_admin_label')); |
|
223 | - } |
|
224 | - |
|
225 | - |
|
226 | - /** |
|
227 | - * Takes where params meant for registrations and changes them to work for questions |
|
228 | - * |
|
229 | - * @param array $reg_where_params |
|
230 | - * @return array |
|
231 | - * @throws EE_Error |
|
232 | - * @throws ReflectionException |
|
233 | - */ |
|
234 | - protected function _change_registration_where_params_to_question_where_params(array $reg_where_params): array |
|
235 | - { |
|
236 | - $question_where_params = []; |
|
237 | - foreach ($reg_where_params as $key => $val) { |
|
238 | - if (EEM_Registration::instance()->is_logic_query_param_key($key)) { |
|
239 | - $question_where_params[ $key ] = |
|
240 | - $this->_change_registration_where_params_to_question_where_params($val); |
|
241 | - } else { |
|
242 | - // it's a normal where condition |
|
243 | - $question_where_params[ 'Question_Group.Event.Registration.' . $key ] = $val; |
|
244 | - } |
|
245 | - } |
|
246 | - return $question_where_params; |
|
247 | - } |
|
248 | - |
|
249 | - |
|
250 | - /** |
|
251 | - * Performs another step of the job |
|
252 | - * |
|
253 | - * @param JobParameters $job_parameters |
|
254 | - * @param int $batch_size |
|
255 | - * @return JobStepResponse |
|
256 | - * @throws EE_Error |
|
257 | - * @throws ReflectionException |
|
258 | - */ |
|
259 | - public function continue_job(JobParameters $job_parameters, int $batch_size = 50): JobStepResponse |
|
260 | - { |
|
261 | - if ($job_parameters->units_processed() < $job_parameters->job_size()) { |
|
262 | - $csv_data = $this->get_csv_data_for( |
|
263 | - (int) $job_parameters->request_datum('EVT_ID', '0'), |
|
264 | - $job_parameters->units_processed(), |
|
265 | - $batch_size, |
|
266 | - $job_parameters->extra_datum('question_labels'), |
|
267 | - $job_parameters->extra_datum('query_params'), |
|
268 | - (int) $job_parameters->request_datum('DTT_ID', '0') |
|
269 | - ); |
|
270 | - EEH_Export::write_data_array_to_csv( |
|
271 | - $job_parameters->extra_datum('filepath'), |
|
272 | - $csv_data, |
|
273 | - false |
|
274 | - ); |
|
275 | - $units_processed = count($csv_data); |
|
276 | - if ($units_processed) { |
|
277 | - $job_parameters->mark_processed($units_processed); |
|
278 | - $this->updateText( |
|
279 | - sprintf( |
|
280 | - esc_html__('Wrote %1$s rows to report CSV file...', 'event_espresso'), |
|
281 | - $units_processed |
|
282 | - ) |
|
283 | - ); |
|
284 | - } |
|
285 | - } |
|
286 | - $extra_response_data = ['file_url' => '']; |
|
287 | - if ($job_parameters->units_processed() >= $job_parameters->job_size()) { |
|
288 | - $job_parameters->set_status(JobParameters::status_complete); |
|
289 | - $extra_response_data['file_url'] = $this->get_url_to_file($job_parameters->extra_datum('filepath')); |
|
290 | - $this->displayJobFinalResults($job_parameters); |
|
291 | - } else { |
|
292 | - $job_parameters->set_status(JobParameters::status_continue); |
|
293 | - } |
|
294 | - return new JobStepResponse($job_parameters, $this->feedback, $extra_response_data); |
|
295 | - } |
|
296 | - |
|
297 | - |
|
298 | - /** |
|
299 | - * Gets the csv data for a batch of registrations |
|
300 | - * |
|
301 | - * @param int|null $event_id |
|
302 | - * @param int $offset |
|
303 | - * @param int $limit |
|
304 | - * @param array $question_labels the IDs for all the questions which were answered by someone in this selection |
|
305 | - * @param array $query_params for using where querying the model |
|
306 | - * @param int $DTT_ID |
|
307 | - * @return array top-level keys are numeric, next-level keys are column headers |
|
308 | - * @throws EE_Error |
|
309 | - * @throws ReflectionException |
|
310 | - */ |
|
311 | - public function get_csv_data_for( |
|
312 | - ?int $event_id, |
|
313 | - int $offset, |
|
314 | - int $limit, |
|
315 | - array $question_labels, |
|
316 | - array $query_params, |
|
317 | - int $DTT_ID = 0 |
|
318 | - ): array { |
|
319 | - $reg_fields_to_include = [ |
|
320 | - 'TXN_ID', |
|
321 | - 'ATT_ID', |
|
322 | - 'REG_ID', |
|
323 | - 'REG_date', |
|
324 | - 'REG_code', |
|
325 | - 'REG_count', |
|
326 | - 'REG_final_price', |
|
327 | - ]; |
|
328 | - $att_fields_to_include = [ |
|
329 | - 'ATT_fname', |
|
330 | - 'ATT_lname', |
|
331 | - 'ATT_email', |
|
332 | - 'ATT_address', |
|
333 | - 'ATT_address2', |
|
334 | - 'ATT_city', |
|
335 | - 'STA_ID', |
|
336 | - 'CNT_ISO', |
|
337 | - 'ATT_zip', |
|
338 | - 'ATT_phone', |
|
339 | - ]; |
|
340 | - |
|
341 | - // get models |
|
342 | - $event_model = EEM_Event::instance(); |
|
343 | - $date_model = EEM_Datetime::instance(); |
|
344 | - $ticket_model = EEM_Ticket::instance(); |
|
345 | - $txn_model = EEM_Transaction::instance(); |
|
346 | - $reg_model = EEM_Registration::instance(); |
|
347 | - $pay_model = EEM_Payment::instance(); |
|
348 | - $status_model = EEM_Status::instance(); |
|
349 | - |
|
350 | - $registrations_csv_ready_array = []; |
|
351 | - $query_params['limit'] = [$offset, $limit]; |
|
352 | - $registration_rows = $reg_model->get_all_wpdb_results($query_params); |
|
353 | - |
|
354 | - foreach ($registration_rows as $reg_row) { |
|
355 | - if (! is_array($reg_row)) { |
|
356 | - continue; |
|
357 | - } |
|
358 | - $reg_csv_array = []; |
|
359 | - // registration ID |
|
360 | - $reg_id_field = $reg_model->field_settings_for('REG_ID'); |
|
361 | - $reg_csv_array[ EEH_Export::get_column_name_for_field($reg_id_field) ] = |
|
362 | - EEH_Export::prepare_value_from_db_for_display( |
|
363 | - $reg_model, |
|
364 | - 'REG_ID', |
|
365 | - $reg_row[ $reg_id_field->get_qualified_column() ] |
|
366 | - ); |
|
367 | - // ALL registrations, or is list filtered to just one? |
|
368 | - if (! $event_id) { |
|
369 | - // ALL registrations, so get each event's name and ID |
|
370 | - $reg_csv_array[ esc_html__('Event', 'event_espresso') ] = sprintf( |
|
371 | - /* translators: 1: event name, 2: event ID */ |
|
372 | - esc_html__('%1$s (%2$s)', 'event_espresso'), |
|
373 | - EEH_Export::prepare_value_from_db_for_display( |
|
374 | - $event_model, |
|
375 | - 'EVT_name', |
|
376 | - $reg_row['Event_CPT.post_title'] |
|
377 | - ), |
|
378 | - $reg_row['Event_CPT.ID'] |
|
379 | - ); |
|
380 | - } |
|
381 | - // add attendee columns |
|
382 | - $reg_csv_array = AttendeeCSV::addAttendeeColumns($att_fields_to_include, $reg_row, $reg_csv_array); |
|
383 | - // add registration columns |
|
384 | - $reg_csv_array = RegistrationCSV::addRegistrationColumns($reg_fields_to_include, $reg_row, $reg_csv_array); |
|
385 | - // get pretty status |
|
386 | - $stati = $status_model->localized_status( |
|
387 | - [ |
|
388 | - $reg_row['Registration.STS_ID'] => esc_html__('unknown', 'event_espresso'), |
|
389 | - $reg_row['TransactionTable.STS_ID'] => esc_html__('unknown', 'event_espresso'), |
|
390 | - ], |
|
391 | - false, |
|
392 | - 'sentence' |
|
393 | - ); |
|
394 | - $is_primary_reg = $reg_row['Registration.REG_count'] == '1'; |
|
395 | - |
|
396 | - $reg_csv_array[ esc_html__('Registration Status', 'event_espresso') ] = |
|
397 | - $stati[ $reg_row['Registration.STS_ID'] ]; |
|
398 | - // get pretty transaction status |
|
399 | - $reg_csv_array[ esc_html__('Transaction Status', 'event_espresso') ] = |
|
400 | - $stati[ $reg_row['TransactionTable.STS_ID'] ]; |
|
401 | - $reg_csv_array[ esc_html__('Transaction Amount Due', 'event_espresso') ] = $is_primary_reg |
|
402 | - ? EEH_Export::prepare_value_from_db_for_display( |
|
403 | - $txn_model, |
|
404 | - 'TXN_total', |
|
405 | - $reg_row['TransactionTable.TXN_total'], |
|
406 | - 'localized_float' |
|
407 | - ) |
|
408 | - : '0.00'; |
|
409 | - |
|
410 | - $reg_csv_array[ esc_html__('Amount Paid', 'event_espresso') ] = $is_primary_reg |
|
411 | - ? EEH_Export::prepare_value_from_db_for_display( |
|
412 | - $txn_model, |
|
413 | - 'TXN_paid', |
|
414 | - $reg_row['TransactionTable.TXN_paid'], |
|
415 | - 'localized_float' |
|
416 | - ) |
|
417 | - : '0.00'; |
|
418 | - |
|
419 | - $payment_methods = []; |
|
420 | - $gateway_txn_ids_etc = []; |
|
421 | - $payment_times = []; |
|
422 | - if ($is_primary_reg && $reg_row['TransactionTable.TXN_ID']) { |
|
423 | - $payments_info = $pay_model->get_all_wpdb_results( |
|
424 | - [ |
|
425 | - [ |
|
426 | - 'TXN_ID' => $reg_row['TransactionTable.TXN_ID'], |
|
427 | - 'STS_ID' => EEM_Payment::status_id_approved, |
|
428 | - ], |
|
429 | - 'force_join' => ['Payment_Method'], |
|
430 | - ], |
|
431 | - ARRAY_A, |
|
432 | - 'Payment_Method.PMD_admin_name as name, Payment.PAY_txn_id_chq_nmbr as gateway_txn_id, Payment.PAY_timestamp as payment_time' |
|
433 | - ); |
|
434 | - [$payment_methods, $gateway_txn_ids_etc, $payment_times] = PaymentsInfoCSV::extractPaymentInfo( |
|
435 | - $payments_info |
|
436 | - ); |
|
437 | - } |
|
438 | - |
|
439 | - $reg_csv_array[ esc_html__('Payment Date(s)', 'event_espresso') ] = implode( |
|
440 | - ',', |
|
441 | - $payment_times |
|
442 | - ); |
|
443 | - |
|
444 | - $reg_csv_array[ esc_html__('Payment Method(s)', 'event_espresso') ] = implode( |
|
445 | - ',', |
|
446 | - $payment_methods |
|
447 | - ); |
|
448 | - |
|
449 | - $reg_csv_array[ esc_html__('Gateway Transaction ID(s)', 'event_espresso') ] = implode( |
|
450 | - ',', |
|
451 | - $gateway_txn_ids_etc |
|
452 | - ); |
|
453 | - |
|
454 | - $ticket_name = esc_html__('Unknown', 'event_espresso'); |
|
455 | - $datetime_strings = [esc_html__('Unknown', 'event_espresso')]; |
|
456 | - if ($reg_row['Ticket.TKT_ID']) { |
|
457 | - $ticket_name = EEH_Export::prepare_value_from_db_for_display( |
|
458 | - $ticket_model, |
|
459 | - 'TKT_name', |
|
460 | - $reg_row['Ticket.TKT_name'] |
|
461 | - ); |
|
462 | - $datetime_strings = []; |
|
463 | - $datetimes = $date_model->get_all_wpdb_results( |
|
464 | - [ |
|
465 | - ['Ticket.TKT_ID' => $reg_row['Ticket.TKT_ID']], |
|
466 | - 'order_by' => ['DTT_EVT_start' => 'ASC'], |
|
467 | - 'default_where_conditions' => 'none', |
|
468 | - ] |
|
469 | - ); |
|
470 | - foreach ($datetimes as $datetime) { |
|
471 | - $datetime_strings[] = EEH_Export::prepare_value_from_db_for_display( |
|
472 | - $date_model, |
|
473 | - 'DTT_EVT_start', |
|
474 | - $datetime['Datetime.DTT_EVT_start'] |
|
475 | - ); |
|
476 | - } |
|
477 | - } |
|
478 | - |
|
479 | - $reg_csv_array[ $ticket_model->field_settings_for('TKT_name')->get_nicename() ] = $ticket_name; |
|
480 | - |
|
481 | - |
|
482 | - $reg_csv_array[ esc_html__('Ticket Datetimes', 'event_espresso') ] = implode( |
|
483 | - ', ', |
|
484 | - $datetime_strings |
|
485 | - ); |
|
486 | - |
|
487 | - // add answer columns |
|
488 | - $reg_csv_array = AnswersCSV::addAnswerColumns($reg_row, $reg_csv_array, $question_labels); |
|
489 | - // Include check-in data |
|
490 | - if ($event_id && $DTT_ID) { |
|
491 | - // get whether or not the user has checked in |
|
492 | - $reg_csv_array[ esc_html__('Datetime Check-ins #', 'event_espresso') ] = |
|
493 | - $reg_model->count_related( |
|
494 | - $reg_row['Registration.REG_ID'], |
|
495 | - 'Checkin', |
|
496 | - [ |
|
497 | - [ |
|
498 | - 'DTT_ID' => $DTT_ID |
|
499 | - ] |
|
500 | - ] |
|
501 | - ); |
|
502 | - $datetime = $date_model->get_one_by_ID($DTT_ID); |
|
503 | - $checkin_rows = EEM_Checkin::instance()->get_all( |
|
504 | - [ |
|
505 | - [ |
|
506 | - 'REG_ID' => $reg_row['Registration.REG_ID'], |
|
507 | - 'DTT_ID' => $datetime->get('DTT_ID'), |
|
508 | - ], |
|
509 | - ] |
|
510 | - ); |
|
511 | - $checkins = []; |
|
512 | - foreach ($checkin_rows as $checkin_row) { |
|
513 | - /** @var EE_Checkin $checkin_row */ |
|
514 | - $checkin_value = CheckinsCSV::getCheckinValue($checkin_row); |
|
515 | - if ($checkin_value) { |
|
516 | - $checkins[] = $checkin_value; |
|
517 | - } |
|
518 | - } |
|
519 | - $datetime_name = CheckinsCSV::getDatetimeLabel($datetime); |
|
520 | - $reg_csv_array[ $datetime_name ] = implode(' --- ', $checkins); |
|
521 | - } elseif ($event_id) { |
|
522 | - // get whether or not the user has checked in |
|
523 | - $reg_csv_array[ esc_html__('Event Check-ins #', 'event_espresso') ] = |
|
524 | - $reg_model->count_related( |
|
525 | - $reg_row['Registration.REG_ID'], |
|
526 | - 'Checkin' |
|
527 | - ); |
|
528 | - |
|
529 | - $datetimes = $date_model->get_all( |
|
530 | - [ |
|
531 | - [ |
|
532 | - 'Ticket.TKT_ID' => $reg_row['Ticket.TKT_ID'], |
|
533 | - ], |
|
534 | - 'order_by' => ['DTT_EVT_start' => 'ASC'], |
|
535 | - 'default_where_conditions' => 'none', |
|
536 | - ] |
|
537 | - ); |
|
538 | - foreach ($datetimes as $datetime) { |
|
539 | - if (! $datetime instanceof EE_Datetime) { |
|
540 | - continue; |
|
541 | - } |
|
542 | - |
|
543 | - /** @var EE_Checkin $checkin_row */ |
|
544 | - $checkin_row = EEM_Checkin::instance()->get_one( |
|
545 | - [ |
|
546 | - [ |
|
547 | - 'REG_ID' => $reg_row['Registration.REG_ID'], |
|
548 | - 'DTT_ID' => $datetime->get('DTT_ID'), |
|
549 | - ], |
|
550 | - 'limit' => 1, |
|
551 | - 'order_by' => [ |
|
552 | - 'CHK_ID' => 'DESC' |
|
553 | - ] |
|
554 | - ] |
|
555 | - ); |
|
556 | - |
|
557 | - $checkin_value = CheckinsCSV::getCheckinValue($checkin_row); |
|
558 | - $datetime_name = CheckinsCSV::getDatetimeLabel($datetime); |
|
559 | - |
|
560 | - $reg_csv_array[ $datetime_name ] = $checkin_value; |
|
561 | - } |
|
562 | - } |
|
563 | - /** |
|
564 | - * Filter to change the contents of each row of the registrations report CSV file. |
|
565 | - * This can be used to add or remote columns from the CSV file, or change their values. |
|
566 | - * Note when using: all rows in the CSV should have the same columns. |
|
567 | - * |
|
568 | - * @param array $reg_csv_array keys are the column names, values are their cell values |
|
569 | - * @param array $reg_row one entry from EEM_Registration::get_all_wpdb_results() |
|
570 | - */ |
|
571 | - $registrations_csv_ready_array[] = apply_filters( |
|
572 | - 'FHEE__EventEspressoBatchRequest__JobHandlers__RegistrationsReport__reg_csv_array', |
|
573 | - $reg_csv_array, |
|
574 | - $reg_row |
|
575 | - ); |
|
576 | - } |
|
577 | - // if we couldn't export anything, we want to at least show the column headers |
|
578 | - if (empty($registrations_csv_ready_array)) { |
|
579 | - $reg_csv_array = []; |
|
580 | - $model_and_fields_to_include = [ |
|
581 | - 'Registration' => $reg_fields_to_include, |
|
582 | - 'Attendee' => $att_fields_to_include, |
|
583 | - ]; |
|
584 | - foreach ($model_and_fields_to_include as $model_name => $field_list) { |
|
585 | - $model = EE_Registry::instance()->load_model($model_name); |
|
586 | - foreach ($field_list as $field_name) { |
|
587 | - $field = |
|
588 | - $model->field_settings_for($field_name); |
|
589 | - $reg_csv_array[ EEH_Export::get_column_name_for_field($field) ] = null; |
|
590 | - } |
|
591 | - } |
|
592 | - $registrations_csv_ready_array[] = $reg_csv_array; |
|
593 | - } |
|
594 | - return $registrations_csv_ready_array; |
|
595 | - } |
|
596 | - |
|
597 | - |
|
598 | - /** |
|
599 | - * Counts total unit to process |
|
600 | - * |
|
601 | - * @param array $query_params |
|
602 | - * @return int |
|
603 | - * @throws EE_Error |
|
604 | - * @throws ReflectionException |
|
605 | - */ |
|
606 | - public function count_units_to_process(array $query_params): int |
|
607 | - { |
|
608 | - return EEM_Registration::instance()->count( |
|
609 | - array_diff_key( |
|
610 | - $query_params, |
|
611 | - array_flip( |
|
612 | - ['limit'] |
|
613 | - ) |
|
614 | - ) |
|
615 | - ); |
|
616 | - } |
|
617 | - |
|
618 | - |
|
619 | - /** |
|
620 | - * Performs any clean-up logic when we know the job is completed. |
|
621 | - * In this case, we delete the temporary file |
|
622 | - * |
|
623 | - * @param JobParameters $job_parameters |
|
624 | - * @return JobStepResponse |
|
625 | - */ |
|
626 | - public function cleanup_job(JobParameters $job_parameters): JobStepResponse |
|
627 | - { |
|
628 | - $this->updateText(esc_html__('File Generation complete and downloaded', 'event_espresso')); |
|
629 | - |
|
630 | - $this->_file_helper->delete( |
|
631 | - EEH_File::remove_filename_from_filepath($job_parameters->extra_datum('filepath')), |
|
632 | - true, |
|
633 | - 'd' |
|
634 | - ); |
|
635 | - $this->updateText(esc_html__('Cleaned up temporary file', 'event_espresso')); |
|
636 | - $this->updateText( |
|
637 | - $this->infoWrapper( |
|
638 | - sprintf( |
|
639 | - esc_html__( |
|
640 | - 'If not automatically redirected in %1$s seconds, click here to return to the %2$sRegistrations List Table%3$s', |
|
641 | - 'event_espresso' |
|
642 | - ), |
|
643 | - '<span id="ee-redirect-timer">10</span>', |
|
644 | - '<a href="' . $job_parameters->request_datum('return_url') . '">', |
|
645 | - '</a>' |
|
646 | - ) |
|
647 | - ) |
|
648 | - ); |
|
649 | - return new JobStepResponse($job_parameters, $this->feedback); |
|
650 | - } |
|
45 | + // phpcs:disable PSR1.Methods.CamelCapsMethodName.NotCamelCaps |
|
46 | + // phpcs:disable PSR2.Methods.MethodDeclaration.Underscore |
|
47 | + /** |
|
48 | + * Performs any necessary setup for starting the job. This is also a good |
|
49 | + * place to setup the $job_arguments which will be used for subsequent HTTP requests |
|
50 | + * when continue_job will be called |
|
51 | + * |
|
52 | + * @param JobParameters $job_parameters |
|
53 | + * @return JobStepResponse |
|
54 | + * @throws BatchRequestException |
|
55 | + * @throws EE_Error |
|
56 | + * @throws ReflectionException |
|
57 | + */ |
|
58 | + public function create_job(JobParameters $job_parameters): JobStepResponse |
|
59 | + { |
|
60 | + $event_id = absint($job_parameters->request_datum('EVT_ID', '0')); |
|
61 | + $DTT_ID = absint($job_parameters->request_datum('DTT_ID', '0')); |
|
62 | + if (! EE_Capabilities::instance()->current_user_can('ee_read_registrations', 'generating_report')) { |
|
63 | + throw new BatchRequestException( |
|
64 | + esc_html__('You do not have permission to view registrations', 'event_espresso') |
|
65 | + ); |
|
66 | + } |
|
67 | + $filepath = $this->create_file_from_job_with_name( |
|
68 | + $job_parameters->job_id(), |
|
69 | + $this->get_filename() |
|
70 | + ); |
|
71 | + $job_parameters->add_extra_data('filepath', $filepath); |
|
72 | + |
|
73 | + if ($job_parameters->request_datum('use_filters', false)) { |
|
74 | + $query_params = maybe_unserialize($job_parameters->request_datum('filters', [])); |
|
75 | + } else { |
|
76 | + $query_params = [ |
|
77 | + [ 'Ticket.TKT_deleted' => ['IN', [true, false]] ], |
|
78 | + 'order_by' => ['Transaction.TXN_ID' => 'asc', 'REG_count' => 'asc'], |
|
79 | + 'force_join' => ['Transaction', 'Ticket', 'Attendee'], |
|
80 | + 'caps' => EEM_Base::caps_read_admin, |
|
81 | + ]; |
|
82 | + if ($event_id) { |
|
83 | + $query_params[0]['EVT_ID'] = $event_id; |
|
84 | + } else { |
|
85 | + $query_params['force_join'][] = 'Event'; |
|
86 | + } |
|
87 | + } |
|
88 | + // unless the query params already include a status, |
|
89 | + // we want to exclude registrations from failed or abandoned transactions |
|
90 | + if (! isset($query_params[0]['Transaction.STS_ID'])) { |
|
91 | + $query_params[0]['OR'] = [ |
|
92 | + // don't include registrations from failed or abandoned transactions... |
|
93 | + 'Transaction.STS_ID' => [ |
|
94 | + 'NOT IN', |
|
95 | + [ |
|
96 | + EEM_Transaction::failed_status_code, |
|
97 | + EEM_Transaction::abandoned_status_code, |
|
98 | + ], |
|
99 | + ], |
|
100 | + // unless the registration is approved, |
|
101 | + // in which case include it regardless of transaction status |
|
102 | + 'STS_ID' => EEM_Registration::status_id_approved, |
|
103 | + ]; |
|
104 | + } |
|
105 | + |
|
106 | + if (! isset($query_params['force_join'])) { |
|
107 | + $query_params['force_join'] = ['Event', 'Transaction', 'Ticket', 'Attendee']; |
|
108 | + } |
|
109 | + |
|
110 | + $return_url_args = []; |
|
111 | + parse_str( |
|
112 | + parse_url( |
|
113 | + $job_parameters->request_datum('return_url', ''), |
|
114 | + PHP_URL_QUERY |
|
115 | + ), |
|
116 | + $return_url_args |
|
117 | + ); |
|
118 | + |
|
119 | + if ( |
|
120 | + isset($return_url_args['orderby'], $return_url_args['order']) |
|
121 | + && $return_url_args['orderby'] === 'ATT_lname' |
|
122 | + ) { |
|
123 | + $query_params['order_by'] = [ |
|
124 | + 'Attendee.ATT_lname' => $return_url_args['order'], |
|
125 | + 'Attendee.ATT_fname' => $return_url_args['order'], |
|
126 | + 'REG_ID' => $return_url_args['order'] |
|
127 | + ]; |
|
128 | + } |
|
129 | + |
|
130 | + $query_params = apply_filters( |
|
131 | + 'FHEE__EE_Export__report_registration_for_event', |
|
132 | + $query_params, |
|
133 | + $event_id |
|
134 | + ); |
|
135 | + |
|
136 | + $job_parameters->add_extra_data('query_params', $query_params); |
|
137 | + $question_labels = $this->_get_question_labels($query_params); |
|
138 | + $job_parameters->add_extra_data('question_labels', $question_labels); |
|
139 | + $job_parameters->set_job_size($this->count_units_to_process($query_params)); |
|
140 | + // we need to set the header columns |
|
141 | + // but to do that we need to process one row so that we can extract ALL of the column headers |
|
142 | + $csv_data_for_row = $this->get_csv_data_for( |
|
143 | + $event_id, |
|
144 | + 0, |
|
145 | + 1, |
|
146 | + $question_labels, |
|
147 | + $query_params, |
|
148 | + $DTT_ID |
|
149 | + ); |
|
150 | + // but we don't want to write any actual data yet... |
|
151 | + // so let's blank out all the values for that first row |
|
152 | + array_walk( |
|
153 | + $csv_data_for_row[0], |
|
154 | + function (&$value) { |
|
155 | + $value = null; |
|
156 | + } |
|
157 | + ); |
|
158 | + |
|
159 | + EEH_Export::write_data_array_to_csv($filepath, $csv_data_for_row, true, true); |
|
160 | + $this->updateTextHeader( |
|
161 | + esc_html__('Registrations report started successfully...', 'event_espresso') |
|
162 | + ); |
|
163 | + return new JobStepResponse($job_parameters, $this->feedback); |
|
164 | + } |
|
165 | + |
|
166 | + |
|
167 | + /** |
|
168 | + * Gets the filename |
|
169 | + * |
|
170 | + * @return string |
|
171 | + */ |
|
172 | + protected function get_filename(): string |
|
173 | + { |
|
174 | + return apply_filters( |
|
175 | + 'FHEE__EventEspressoBatchRequest__JobHandlers__RegistrationsReport__get_filename', |
|
176 | + sprintf( |
|
177 | + 'event-espresso-registrations-%s.csv', |
|
178 | + str_replace([':', ' '], '-', current_time('mysql')) |
|
179 | + ) |
|
180 | + ); |
|
181 | + } |
|
182 | + |
|
183 | + |
|
184 | + /** |
|
185 | + * Gets the questions which are to be used for this report, |
|
186 | + * so they can be remembered for later |
|
187 | + * |
|
188 | + * @param array $registration_query_params |
|
189 | + * @return array question admin labels to be used for this report |
|
190 | + * @throws EE_Error |
|
191 | + * @throws ReflectionException |
|
192 | + */ |
|
193 | + protected function _get_question_labels(array $registration_query_params): array |
|
194 | + { |
|
195 | + $where = $registration_query_params[0] ?? null; |
|
196 | + $question_query_params = []; |
|
197 | + if ($where !== null) { |
|
198 | + $question_query_params = [ |
|
199 | + $this->_change_registration_where_params_to_question_where_params($registration_query_params[0]), |
|
200 | + ]; |
|
201 | + } |
|
202 | + // Make sure it's not a system question |
|
203 | + $question_query_params[0]['OR*not-system-questions'] = [ |
|
204 | + 'QST_system' => '', |
|
205 | + 'QST_system*null' => ['IS_NULL'] |
|
206 | + ]; |
|
207 | + if ( |
|
208 | + apply_filters( |
|
209 | + 'FHEE__EventEspressoBatchRequest__JobHandlers__RegistrationsReport___get_question_labels__only_include_answered_questions', |
|
210 | + false, |
|
211 | + $registration_query_params |
|
212 | + ) |
|
213 | + ) { |
|
214 | + $question_query_params[0]['Answer.ANS_ID'] = ['IS_NOT_NULL']; |
|
215 | + } |
|
216 | + $question_query_params['order_by'] = [ |
|
217 | + 'Question_Group_Question.QGQ_order' => 'ASC', |
|
218 | + 'QST_order' => 'ASC', |
|
219 | + 'QST_admin_label' => 'ASC' |
|
220 | + ]; |
|
221 | + $question_query_params['group_by'] = ['QST_ID']; |
|
222 | + return array_unique(EEM_Question::instance()->get_col($question_query_params, 'QST_admin_label')); |
|
223 | + } |
|
224 | + |
|
225 | + |
|
226 | + /** |
|
227 | + * Takes where params meant for registrations and changes them to work for questions |
|
228 | + * |
|
229 | + * @param array $reg_where_params |
|
230 | + * @return array |
|
231 | + * @throws EE_Error |
|
232 | + * @throws ReflectionException |
|
233 | + */ |
|
234 | + protected function _change_registration_where_params_to_question_where_params(array $reg_where_params): array |
|
235 | + { |
|
236 | + $question_where_params = []; |
|
237 | + foreach ($reg_where_params as $key => $val) { |
|
238 | + if (EEM_Registration::instance()->is_logic_query_param_key($key)) { |
|
239 | + $question_where_params[ $key ] = |
|
240 | + $this->_change_registration_where_params_to_question_where_params($val); |
|
241 | + } else { |
|
242 | + // it's a normal where condition |
|
243 | + $question_where_params[ 'Question_Group.Event.Registration.' . $key ] = $val; |
|
244 | + } |
|
245 | + } |
|
246 | + return $question_where_params; |
|
247 | + } |
|
248 | + |
|
249 | + |
|
250 | + /** |
|
251 | + * Performs another step of the job |
|
252 | + * |
|
253 | + * @param JobParameters $job_parameters |
|
254 | + * @param int $batch_size |
|
255 | + * @return JobStepResponse |
|
256 | + * @throws EE_Error |
|
257 | + * @throws ReflectionException |
|
258 | + */ |
|
259 | + public function continue_job(JobParameters $job_parameters, int $batch_size = 50): JobStepResponse |
|
260 | + { |
|
261 | + if ($job_parameters->units_processed() < $job_parameters->job_size()) { |
|
262 | + $csv_data = $this->get_csv_data_for( |
|
263 | + (int) $job_parameters->request_datum('EVT_ID', '0'), |
|
264 | + $job_parameters->units_processed(), |
|
265 | + $batch_size, |
|
266 | + $job_parameters->extra_datum('question_labels'), |
|
267 | + $job_parameters->extra_datum('query_params'), |
|
268 | + (int) $job_parameters->request_datum('DTT_ID', '0') |
|
269 | + ); |
|
270 | + EEH_Export::write_data_array_to_csv( |
|
271 | + $job_parameters->extra_datum('filepath'), |
|
272 | + $csv_data, |
|
273 | + false |
|
274 | + ); |
|
275 | + $units_processed = count($csv_data); |
|
276 | + if ($units_processed) { |
|
277 | + $job_parameters->mark_processed($units_processed); |
|
278 | + $this->updateText( |
|
279 | + sprintf( |
|
280 | + esc_html__('Wrote %1$s rows to report CSV file...', 'event_espresso'), |
|
281 | + $units_processed |
|
282 | + ) |
|
283 | + ); |
|
284 | + } |
|
285 | + } |
|
286 | + $extra_response_data = ['file_url' => '']; |
|
287 | + if ($job_parameters->units_processed() >= $job_parameters->job_size()) { |
|
288 | + $job_parameters->set_status(JobParameters::status_complete); |
|
289 | + $extra_response_data['file_url'] = $this->get_url_to_file($job_parameters->extra_datum('filepath')); |
|
290 | + $this->displayJobFinalResults($job_parameters); |
|
291 | + } else { |
|
292 | + $job_parameters->set_status(JobParameters::status_continue); |
|
293 | + } |
|
294 | + return new JobStepResponse($job_parameters, $this->feedback, $extra_response_data); |
|
295 | + } |
|
296 | + |
|
297 | + |
|
298 | + /** |
|
299 | + * Gets the csv data for a batch of registrations |
|
300 | + * |
|
301 | + * @param int|null $event_id |
|
302 | + * @param int $offset |
|
303 | + * @param int $limit |
|
304 | + * @param array $question_labels the IDs for all the questions which were answered by someone in this selection |
|
305 | + * @param array $query_params for using where querying the model |
|
306 | + * @param int $DTT_ID |
|
307 | + * @return array top-level keys are numeric, next-level keys are column headers |
|
308 | + * @throws EE_Error |
|
309 | + * @throws ReflectionException |
|
310 | + */ |
|
311 | + public function get_csv_data_for( |
|
312 | + ?int $event_id, |
|
313 | + int $offset, |
|
314 | + int $limit, |
|
315 | + array $question_labels, |
|
316 | + array $query_params, |
|
317 | + int $DTT_ID = 0 |
|
318 | + ): array { |
|
319 | + $reg_fields_to_include = [ |
|
320 | + 'TXN_ID', |
|
321 | + 'ATT_ID', |
|
322 | + 'REG_ID', |
|
323 | + 'REG_date', |
|
324 | + 'REG_code', |
|
325 | + 'REG_count', |
|
326 | + 'REG_final_price', |
|
327 | + ]; |
|
328 | + $att_fields_to_include = [ |
|
329 | + 'ATT_fname', |
|
330 | + 'ATT_lname', |
|
331 | + 'ATT_email', |
|
332 | + 'ATT_address', |
|
333 | + 'ATT_address2', |
|
334 | + 'ATT_city', |
|
335 | + 'STA_ID', |
|
336 | + 'CNT_ISO', |
|
337 | + 'ATT_zip', |
|
338 | + 'ATT_phone', |
|
339 | + ]; |
|
340 | + |
|
341 | + // get models |
|
342 | + $event_model = EEM_Event::instance(); |
|
343 | + $date_model = EEM_Datetime::instance(); |
|
344 | + $ticket_model = EEM_Ticket::instance(); |
|
345 | + $txn_model = EEM_Transaction::instance(); |
|
346 | + $reg_model = EEM_Registration::instance(); |
|
347 | + $pay_model = EEM_Payment::instance(); |
|
348 | + $status_model = EEM_Status::instance(); |
|
349 | + |
|
350 | + $registrations_csv_ready_array = []; |
|
351 | + $query_params['limit'] = [$offset, $limit]; |
|
352 | + $registration_rows = $reg_model->get_all_wpdb_results($query_params); |
|
353 | + |
|
354 | + foreach ($registration_rows as $reg_row) { |
|
355 | + if (! is_array($reg_row)) { |
|
356 | + continue; |
|
357 | + } |
|
358 | + $reg_csv_array = []; |
|
359 | + // registration ID |
|
360 | + $reg_id_field = $reg_model->field_settings_for('REG_ID'); |
|
361 | + $reg_csv_array[ EEH_Export::get_column_name_for_field($reg_id_field) ] = |
|
362 | + EEH_Export::prepare_value_from_db_for_display( |
|
363 | + $reg_model, |
|
364 | + 'REG_ID', |
|
365 | + $reg_row[ $reg_id_field->get_qualified_column() ] |
|
366 | + ); |
|
367 | + // ALL registrations, or is list filtered to just one? |
|
368 | + if (! $event_id) { |
|
369 | + // ALL registrations, so get each event's name and ID |
|
370 | + $reg_csv_array[ esc_html__('Event', 'event_espresso') ] = sprintf( |
|
371 | + /* translators: 1: event name, 2: event ID */ |
|
372 | + esc_html__('%1$s (%2$s)', 'event_espresso'), |
|
373 | + EEH_Export::prepare_value_from_db_for_display( |
|
374 | + $event_model, |
|
375 | + 'EVT_name', |
|
376 | + $reg_row['Event_CPT.post_title'] |
|
377 | + ), |
|
378 | + $reg_row['Event_CPT.ID'] |
|
379 | + ); |
|
380 | + } |
|
381 | + // add attendee columns |
|
382 | + $reg_csv_array = AttendeeCSV::addAttendeeColumns($att_fields_to_include, $reg_row, $reg_csv_array); |
|
383 | + // add registration columns |
|
384 | + $reg_csv_array = RegistrationCSV::addRegistrationColumns($reg_fields_to_include, $reg_row, $reg_csv_array); |
|
385 | + // get pretty status |
|
386 | + $stati = $status_model->localized_status( |
|
387 | + [ |
|
388 | + $reg_row['Registration.STS_ID'] => esc_html__('unknown', 'event_espresso'), |
|
389 | + $reg_row['TransactionTable.STS_ID'] => esc_html__('unknown', 'event_espresso'), |
|
390 | + ], |
|
391 | + false, |
|
392 | + 'sentence' |
|
393 | + ); |
|
394 | + $is_primary_reg = $reg_row['Registration.REG_count'] == '1'; |
|
395 | + |
|
396 | + $reg_csv_array[ esc_html__('Registration Status', 'event_espresso') ] = |
|
397 | + $stati[ $reg_row['Registration.STS_ID'] ]; |
|
398 | + // get pretty transaction status |
|
399 | + $reg_csv_array[ esc_html__('Transaction Status', 'event_espresso') ] = |
|
400 | + $stati[ $reg_row['TransactionTable.STS_ID'] ]; |
|
401 | + $reg_csv_array[ esc_html__('Transaction Amount Due', 'event_espresso') ] = $is_primary_reg |
|
402 | + ? EEH_Export::prepare_value_from_db_for_display( |
|
403 | + $txn_model, |
|
404 | + 'TXN_total', |
|
405 | + $reg_row['TransactionTable.TXN_total'], |
|
406 | + 'localized_float' |
|
407 | + ) |
|
408 | + : '0.00'; |
|
409 | + |
|
410 | + $reg_csv_array[ esc_html__('Amount Paid', 'event_espresso') ] = $is_primary_reg |
|
411 | + ? EEH_Export::prepare_value_from_db_for_display( |
|
412 | + $txn_model, |
|
413 | + 'TXN_paid', |
|
414 | + $reg_row['TransactionTable.TXN_paid'], |
|
415 | + 'localized_float' |
|
416 | + ) |
|
417 | + : '0.00'; |
|
418 | + |
|
419 | + $payment_methods = []; |
|
420 | + $gateway_txn_ids_etc = []; |
|
421 | + $payment_times = []; |
|
422 | + if ($is_primary_reg && $reg_row['TransactionTable.TXN_ID']) { |
|
423 | + $payments_info = $pay_model->get_all_wpdb_results( |
|
424 | + [ |
|
425 | + [ |
|
426 | + 'TXN_ID' => $reg_row['TransactionTable.TXN_ID'], |
|
427 | + 'STS_ID' => EEM_Payment::status_id_approved, |
|
428 | + ], |
|
429 | + 'force_join' => ['Payment_Method'], |
|
430 | + ], |
|
431 | + ARRAY_A, |
|
432 | + 'Payment_Method.PMD_admin_name as name, Payment.PAY_txn_id_chq_nmbr as gateway_txn_id, Payment.PAY_timestamp as payment_time' |
|
433 | + ); |
|
434 | + [$payment_methods, $gateway_txn_ids_etc, $payment_times] = PaymentsInfoCSV::extractPaymentInfo( |
|
435 | + $payments_info |
|
436 | + ); |
|
437 | + } |
|
438 | + |
|
439 | + $reg_csv_array[ esc_html__('Payment Date(s)', 'event_espresso') ] = implode( |
|
440 | + ',', |
|
441 | + $payment_times |
|
442 | + ); |
|
443 | + |
|
444 | + $reg_csv_array[ esc_html__('Payment Method(s)', 'event_espresso') ] = implode( |
|
445 | + ',', |
|
446 | + $payment_methods |
|
447 | + ); |
|
448 | + |
|
449 | + $reg_csv_array[ esc_html__('Gateway Transaction ID(s)', 'event_espresso') ] = implode( |
|
450 | + ',', |
|
451 | + $gateway_txn_ids_etc |
|
452 | + ); |
|
453 | + |
|
454 | + $ticket_name = esc_html__('Unknown', 'event_espresso'); |
|
455 | + $datetime_strings = [esc_html__('Unknown', 'event_espresso')]; |
|
456 | + if ($reg_row['Ticket.TKT_ID']) { |
|
457 | + $ticket_name = EEH_Export::prepare_value_from_db_for_display( |
|
458 | + $ticket_model, |
|
459 | + 'TKT_name', |
|
460 | + $reg_row['Ticket.TKT_name'] |
|
461 | + ); |
|
462 | + $datetime_strings = []; |
|
463 | + $datetimes = $date_model->get_all_wpdb_results( |
|
464 | + [ |
|
465 | + ['Ticket.TKT_ID' => $reg_row['Ticket.TKT_ID']], |
|
466 | + 'order_by' => ['DTT_EVT_start' => 'ASC'], |
|
467 | + 'default_where_conditions' => 'none', |
|
468 | + ] |
|
469 | + ); |
|
470 | + foreach ($datetimes as $datetime) { |
|
471 | + $datetime_strings[] = EEH_Export::prepare_value_from_db_for_display( |
|
472 | + $date_model, |
|
473 | + 'DTT_EVT_start', |
|
474 | + $datetime['Datetime.DTT_EVT_start'] |
|
475 | + ); |
|
476 | + } |
|
477 | + } |
|
478 | + |
|
479 | + $reg_csv_array[ $ticket_model->field_settings_for('TKT_name')->get_nicename() ] = $ticket_name; |
|
480 | + |
|
481 | + |
|
482 | + $reg_csv_array[ esc_html__('Ticket Datetimes', 'event_espresso') ] = implode( |
|
483 | + ', ', |
|
484 | + $datetime_strings |
|
485 | + ); |
|
486 | + |
|
487 | + // add answer columns |
|
488 | + $reg_csv_array = AnswersCSV::addAnswerColumns($reg_row, $reg_csv_array, $question_labels); |
|
489 | + // Include check-in data |
|
490 | + if ($event_id && $DTT_ID) { |
|
491 | + // get whether or not the user has checked in |
|
492 | + $reg_csv_array[ esc_html__('Datetime Check-ins #', 'event_espresso') ] = |
|
493 | + $reg_model->count_related( |
|
494 | + $reg_row['Registration.REG_ID'], |
|
495 | + 'Checkin', |
|
496 | + [ |
|
497 | + [ |
|
498 | + 'DTT_ID' => $DTT_ID |
|
499 | + ] |
|
500 | + ] |
|
501 | + ); |
|
502 | + $datetime = $date_model->get_one_by_ID($DTT_ID); |
|
503 | + $checkin_rows = EEM_Checkin::instance()->get_all( |
|
504 | + [ |
|
505 | + [ |
|
506 | + 'REG_ID' => $reg_row['Registration.REG_ID'], |
|
507 | + 'DTT_ID' => $datetime->get('DTT_ID'), |
|
508 | + ], |
|
509 | + ] |
|
510 | + ); |
|
511 | + $checkins = []; |
|
512 | + foreach ($checkin_rows as $checkin_row) { |
|
513 | + /** @var EE_Checkin $checkin_row */ |
|
514 | + $checkin_value = CheckinsCSV::getCheckinValue($checkin_row); |
|
515 | + if ($checkin_value) { |
|
516 | + $checkins[] = $checkin_value; |
|
517 | + } |
|
518 | + } |
|
519 | + $datetime_name = CheckinsCSV::getDatetimeLabel($datetime); |
|
520 | + $reg_csv_array[ $datetime_name ] = implode(' --- ', $checkins); |
|
521 | + } elseif ($event_id) { |
|
522 | + // get whether or not the user has checked in |
|
523 | + $reg_csv_array[ esc_html__('Event Check-ins #', 'event_espresso') ] = |
|
524 | + $reg_model->count_related( |
|
525 | + $reg_row['Registration.REG_ID'], |
|
526 | + 'Checkin' |
|
527 | + ); |
|
528 | + |
|
529 | + $datetimes = $date_model->get_all( |
|
530 | + [ |
|
531 | + [ |
|
532 | + 'Ticket.TKT_ID' => $reg_row['Ticket.TKT_ID'], |
|
533 | + ], |
|
534 | + 'order_by' => ['DTT_EVT_start' => 'ASC'], |
|
535 | + 'default_where_conditions' => 'none', |
|
536 | + ] |
|
537 | + ); |
|
538 | + foreach ($datetimes as $datetime) { |
|
539 | + if (! $datetime instanceof EE_Datetime) { |
|
540 | + continue; |
|
541 | + } |
|
542 | + |
|
543 | + /** @var EE_Checkin $checkin_row */ |
|
544 | + $checkin_row = EEM_Checkin::instance()->get_one( |
|
545 | + [ |
|
546 | + [ |
|
547 | + 'REG_ID' => $reg_row['Registration.REG_ID'], |
|
548 | + 'DTT_ID' => $datetime->get('DTT_ID'), |
|
549 | + ], |
|
550 | + 'limit' => 1, |
|
551 | + 'order_by' => [ |
|
552 | + 'CHK_ID' => 'DESC' |
|
553 | + ] |
|
554 | + ] |
|
555 | + ); |
|
556 | + |
|
557 | + $checkin_value = CheckinsCSV::getCheckinValue($checkin_row); |
|
558 | + $datetime_name = CheckinsCSV::getDatetimeLabel($datetime); |
|
559 | + |
|
560 | + $reg_csv_array[ $datetime_name ] = $checkin_value; |
|
561 | + } |
|
562 | + } |
|
563 | + /** |
|
564 | + * Filter to change the contents of each row of the registrations report CSV file. |
|
565 | + * This can be used to add or remote columns from the CSV file, or change their values. |
|
566 | + * Note when using: all rows in the CSV should have the same columns. |
|
567 | + * |
|
568 | + * @param array $reg_csv_array keys are the column names, values are their cell values |
|
569 | + * @param array $reg_row one entry from EEM_Registration::get_all_wpdb_results() |
|
570 | + */ |
|
571 | + $registrations_csv_ready_array[] = apply_filters( |
|
572 | + 'FHEE__EventEspressoBatchRequest__JobHandlers__RegistrationsReport__reg_csv_array', |
|
573 | + $reg_csv_array, |
|
574 | + $reg_row |
|
575 | + ); |
|
576 | + } |
|
577 | + // if we couldn't export anything, we want to at least show the column headers |
|
578 | + if (empty($registrations_csv_ready_array)) { |
|
579 | + $reg_csv_array = []; |
|
580 | + $model_and_fields_to_include = [ |
|
581 | + 'Registration' => $reg_fields_to_include, |
|
582 | + 'Attendee' => $att_fields_to_include, |
|
583 | + ]; |
|
584 | + foreach ($model_and_fields_to_include as $model_name => $field_list) { |
|
585 | + $model = EE_Registry::instance()->load_model($model_name); |
|
586 | + foreach ($field_list as $field_name) { |
|
587 | + $field = |
|
588 | + $model->field_settings_for($field_name); |
|
589 | + $reg_csv_array[ EEH_Export::get_column_name_for_field($field) ] = null; |
|
590 | + } |
|
591 | + } |
|
592 | + $registrations_csv_ready_array[] = $reg_csv_array; |
|
593 | + } |
|
594 | + return $registrations_csv_ready_array; |
|
595 | + } |
|
596 | + |
|
597 | + |
|
598 | + /** |
|
599 | + * Counts total unit to process |
|
600 | + * |
|
601 | + * @param array $query_params |
|
602 | + * @return int |
|
603 | + * @throws EE_Error |
|
604 | + * @throws ReflectionException |
|
605 | + */ |
|
606 | + public function count_units_to_process(array $query_params): int |
|
607 | + { |
|
608 | + return EEM_Registration::instance()->count( |
|
609 | + array_diff_key( |
|
610 | + $query_params, |
|
611 | + array_flip( |
|
612 | + ['limit'] |
|
613 | + ) |
|
614 | + ) |
|
615 | + ); |
|
616 | + } |
|
617 | + |
|
618 | + |
|
619 | + /** |
|
620 | + * Performs any clean-up logic when we know the job is completed. |
|
621 | + * In this case, we delete the temporary file |
|
622 | + * |
|
623 | + * @param JobParameters $job_parameters |
|
624 | + * @return JobStepResponse |
|
625 | + */ |
|
626 | + public function cleanup_job(JobParameters $job_parameters): JobStepResponse |
|
627 | + { |
|
628 | + $this->updateText(esc_html__('File Generation complete and downloaded', 'event_espresso')); |
|
629 | + |
|
630 | + $this->_file_helper->delete( |
|
631 | + EEH_File::remove_filename_from_filepath($job_parameters->extra_datum('filepath')), |
|
632 | + true, |
|
633 | + 'd' |
|
634 | + ); |
|
635 | + $this->updateText(esc_html__('Cleaned up temporary file', 'event_espresso')); |
|
636 | + $this->updateText( |
|
637 | + $this->infoWrapper( |
|
638 | + sprintf( |
|
639 | + esc_html__( |
|
640 | + 'If not automatically redirected in %1$s seconds, click here to return to the %2$sRegistrations List Table%3$s', |
|
641 | + 'event_espresso' |
|
642 | + ), |
|
643 | + '<span id="ee-redirect-timer">10</span>', |
|
644 | + '<a href="' . $job_parameters->request_datum('return_url') . '">', |
|
645 | + '</a>' |
|
646 | + ) |
|
647 | + ) |
|
648 | + ); |
|
649 | + return new JobStepResponse($job_parameters, $this->feedback); |
|
650 | + } |
|
651 | 651 | } |
@@ -59,7 +59,7 @@ discard block |
||
59 | 59 | { |
60 | 60 | $event_id = absint($job_parameters->request_datum('EVT_ID', '0')); |
61 | 61 | $DTT_ID = absint($job_parameters->request_datum('DTT_ID', '0')); |
62 | - if (! EE_Capabilities::instance()->current_user_can('ee_read_registrations', 'generating_report')) { |
|
62 | + if ( ! EE_Capabilities::instance()->current_user_can('ee_read_registrations', 'generating_report')) { |
|
63 | 63 | throw new BatchRequestException( |
64 | 64 | esc_html__('You do not have permission to view registrations', 'event_espresso') |
65 | 65 | ); |
@@ -74,7 +74,7 @@ discard block |
||
74 | 74 | $query_params = maybe_unserialize($job_parameters->request_datum('filters', [])); |
75 | 75 | } else { |
76 | 76 | $query_params = [ |
77 | - [ 'Ticket.TKT_deleted' => ['IN', [true, false]] ], |
|
77 | + ['Ticket.TKT_deleted' => ['IN', [true, false]]], |
|
78 | 78 | 'order_by' => ['Transaction.TXN_ID' => 'asc', 'REG_count' => 'asc'], |
79 | 79 | 'force_join' => ['Transaction', 'Ticket', 'Attendee'], |
80 | 80 | 'caps' => EEM_Base::caps_read_admin, |
@@ -87,7 +87,7 @@ discard block |
||
87 | 87 | } |
88 | 88 | // unless the query params already include a status, |
89 | 89 | // we want to exclude registrations from failed or abandoned transactions |
90 | - if (! isset($query_params[0]['Transaction.STS_ID'])) { |
|
90 | + if ( ! isset($query_params[0]['Transaction.STS_ID'])) { |
|
91 | 91 | $query_params[0]['OR'] = [ |
92 | 92 | // don't include registrations from failed or abandoned transactions... |
93 | 93 | 'Transaction.STS_ID' => [ |
@@ -103,7 +103,7 @@ discard block |
||
103 | 103 | ]; |
104 | 104 | } |
105 | 105 | |
106 | - if (! isset($query_params['force_join'])) { |
|
106 | + if ( ! isset($query_params['force_join'])) { |
|
107 | 107 | $query_params['force_join'] = ['Event', 'Transaction', 'Ticket', 'Attendee']; |
108 | 108 | } |
109 | 109 | |
@@ -151,7 +151,7 @@ discard block |
||
151 | 151 | // so let's blank out all the values for that first row |
152 | 152 | array_walk( |
153 | 153 | $csv_data_for_row[0], |
154 | - function (&$value) { |
|
154 | + function(&$value) { |
|
155 | 155 | $value = null; |
156 | 156 | } |
157 | 157 | ); |
@@ -236,11 +236,11 @@ discard block |
||
236 | 236 | $question_where_params = []; |
237 | 237 | foreach ($reg_where_params as $key => $val) { |
238 | 238 | if (EEM_Registration::instance()->is_logic_query_param_key($key)) { |
239 | - $question_where_params[ $key ] = |
|
239 | + $question_where_params[$key] = |
|
240 | 240 | $this->_change_registration_where_params_to_question_where_params($val); |
241 | 241 | } else { |
242 | 242 | // it's a normal where condition |
243 | - $question_where_params[ 'Question_Group.Event.Registration.' . $key ] = $val; |
|
243 | + $question_where_params['Question_Group.Event.Registration.'.$key] = $val; |
|
244 | 244 | } |
245 | 245 | } |
246 | 246 | return $question_where_params; |
@@ -352,22 +352,22 @@ discard block |
||
352 | 352 | $registration_rows = $reg_model->get_all_wpdb_results($query_params); |
353 | 353 | |
354 | 354 | foreach ($registration_rows as $reg_row) { |
355 | - if (! is_array($reg_row)) { |
|
355 | + if ( ! is_array($reg_row)) { |
|
356 | 356 | continue; |
357 | 357 | } |
358 | 358 | $reg_csv_array = []; |
359 | 359 | // registration ID |
360 | 360 | $reg_id_field = $reg_model->field_settings_for('REG_ID'); |
361 | - $reg_csv_array[ EEH_Export::get_column_name_for_field($reg_id_field) ] = |
|
361 | + $reg_csv_array[EEH_Export::get_column_name_for_field($reg_id_field)] = |
|
362 | 362 | EEH_Export::prepare_value_from_db_for_display( |
363 | 363 | $reg_model, |
364 | 364 | 'REG_ID', |
365 | - $reg_row[ $reg_id_field->get_qualified_column() ] |
|
365 | + $reg_row[$reg_id_field->get_qualified_column()] |
|
366 | 366 | ); |
367 | 367 | // ALL registrations, or is list filtered to just one? |
368 | - if (! $event_id) { |
|
368 | + if ( ! $event_id) { |
|
369 | 369 | // ALL registrations, so get each event's name and ID |
370 | - $reg_csv_array[ esc_html__('Event', 'event_espresso') ] = sprintf( |
|
370 | + $reg_csv_array[esc_html__('Event', 'event_espresso')] = sprintf( |
|
371 | 371 | /* translators: 1: event name, 2: event ID */ |
372 | 372 | esc_html__('%1$s (%2$s)', 'event_espresso'), |
373 | 373 | EEH_Export::prepare_value_from_db_for_display( |
@@ -393,12 +393,12 @@ discard block |
||
393 | 393 | ); |
394 | 394 | $is_primary_reg = $reg_row['Registration.REG_count'] == '1'; |
395 | 395 | |
396 | - $reg_csv_array[ esc_html__('Registration Status', 'event_espresso') ] = |
|
397 | - $stati[ $reg_row['Registration.STS_ID'] ]; |
|
396 | + $reg_csv_array[esc_html__('Registration Status', 'event_espresso')] = |
|
397 | + $stati[$reg_row['Registration.STS_ID']]; |
|
398 | 398 | // get pretty transaction status |
399 | - $reg_csv_array[ esc_html__('Transaction Status', 'event_espresso') ] = |
|
400 | - $stati[ $reg_row['TransactionTable.STS_ID'] ]; |
|
401 | - $reg_csv_array[ esc_html__('Transaction Amount Due', 'event_espresso') ] = $is_primary_reg |
|
399 | + $reg_csv_array[esc_html__('Transaction Status', 'event_espresso')] = |
|
400 | + $stati[$reg_row['TransactionTable.STS_ID']]; |
|
401 | + $reg_csv_array[esc_html__('Transaction Amount Due', 'event_espresso')] = $is_primary_reg |
|
402 | 402 | ? EEH_Export::prepare_value_from_db_for_display( |
403 | 403 | $txn_model, |
404 | 404 | 'TXN_total', |
@@ -407,7 +407,7 @@ discard block |
||
407 | 407 | ) |
408 | 408 | : '0.00'; |
409 | 409 | |
410 | - $reg_csv_array[ esc_html__('Amount Paid', 'event_espresso') ] = $is_primary_reg |
|
410 | + $reg_csv_array[esc_html__('Amount Paid', 'event_espresso')] = $is_primary_reg |
|
411 | 411 | ? EEH_Export::prepare_value_from_db_for_display( |
412 | 412 | $txn_model, |
413 | 413 | 'TXN_paid', |
@@ -436,17 +436,17 @@ discard block |
||
436 | 436 | ); |
437 | 437 | } |
438 | 438 | |
439 | - $reg_csv_array[ esc_html__('Payment Date(s)', 'event_espresso') ] = implode( |
|
439 | + $reg_csv_array[esc_html__('Payment Date(s)', 'event_espresso')] = implode( |
|
440 | 440 | ',', |
441 | 441 | $payment_times |
442 | 442 | ); |
443 | 443 | |
444 | - $reg_csv_array[ esc_html__('Payment Method(s)', 'event_espresso') ] = implode( |
|
444 | + $reg_csv_array[esc_html__('Payment Method(s)', 'event_espresso')] = implode( |
|
445 | 445 | ',', |
446 | 446 | $payment_methods |
447 | 447 | ); |
448 | 448 | |
449 | - $reg_csv_array[ esc_html__('Gateway Transaction ID(s)', 'event_espresso') ] = implode( |
|
449 | + $reg_csv_array[esc_html__('Gateway Transaction ID(s)', 'event_espresso')] = implode( |
|
450 | 450 | ',', |
451 | 451 | $gateway_txn_ids_etc |
452 | 452 | ); |
@@ -454,7 +454,7 @@ discard block |
||
454 | 454 | $ticket_name = esc_html__('Unknown', 'event_espresso'); |
455 | 455 | $datetime_strings = [esc_html__('Unknown', 'event_espresso')]; |
456 | 456 | if ($reg_row['Ticket.TKT_ID']) { |
457 | - $ticket_name = EEH_Export::prepare_value_from_db_for_display( |
|
457 | + $ticket_name = EEH_Export::prepare_value_from_db_for_display( |
|
458 | 458 | $ticket_model, |
459 | 459 | 'TKT_name', |
460 | 460 | $reg_row['Ticket.TKT_name'] |
@@ -476,10 +476,10 @@ discard block |
||
476 | 476 | } |
477 | 477 | } |
478 | 478 | |
479 | - $reg_csv_array[ $ticket_model->field_settings_for('TKT_name')->get_nicename() ] = $ticket_name; |
|
479 | + $reg_csv_array[$ticket_model->field_settings_for('TKT_name')->get_nicename()] = $ticket_name; |
|
480 | 480 | |
481 | 481 | |
482 | - $reg_csv_array[ esc_html__('Ticket Datetimes', 'event_espresso') ] = implode( |
|
482 | + $reg_csv_array[esc_html__('Ticket Datetimes', 'event_espresso')] = implode( |
|
483 | 483 | ', ', |
484 | 484 | $datetime_strings |
485 | 485 | ); |
@@ -489,7 +489,7 @@ discard block |
||
489 | 489 | // Include check-in data |
490 | 490 | if ($event_id && $DTT_ID) { |
491 | 491 | // get whether or not the user has checked in |
492 | - $reg_csv_array[ esc_html__('Datetime Check-ins #', 'event_espresso') ] = |
|
492 | + $reg_csv_array[esc_html__('Datetime Check-ins #', 'event_espresso')] = |
|
493 | 493 | $reg_model->count_related( |
494 | 494 | $reg_row['Registration.REG_ID'], |
495 | 495 | 'Checkin', |
@@ -508,7 +508,7 @@ discard block |
||
508 | 508 | ], |
509 | 509 | ] |
510 | 510 | ); |
511 | - $checkins = []; |
|
511 | + $checkins = []; |
|
512 | 512 | foreach ($checkin_rows as $checkin_row) { |
513 | 513 | /** @var EE_Checkin $checkin_row */ |
514 | 514 | $checkin_value = CheckinsCSV::getCheckinValue($checkin_row); |
@@ -517,10 +517,10 @@ discard block |
||
517 | 517 | } |
518 | 518 | } |
519 | 519 | $datetime_name = CheckinsCSV::getDatetimeLabel($datetime); |
520 | - $reg_csv_array[ $datetime_name ] = implode(' --- ', $checkins); |
|
520 | + $reg_csv_array[$datetime_name] = implode(' --- ', $checkins); |
|
521 | 521 | } elseif ($event_id) { |
522 | 522 | // get whether or not the user has checked in |
523 | - $reg_csv_array[ esc_html__('Event Check-ins #', 'event_espresso') ] = |
|
523 | + $reg_csv_array[esc_html__('Event Check-ins #', 'event_espresso')] = |
|
524 | 524 | $reg_model->count_related( |
525 | 525 | $reg_row['Registration.REG_ID'], |
526 | 526 | 'Checkin' |
@@ -536,7 +536,7 @@ discard block |
||
536 | 536 | ] |
537 | 537 | ); |
538 | 538 | foreach ($datetimes as $datetime) { |
539 | - if (! $datetime instanceof EE_Datetime) { |
|
539 | + if ( ! $datetime instanceof EE_Datetime) { |
|
540 | 540 | continue; |
541 | 541 | } |
542 | 542 | |
@@ -557,7 +557,7 @@ discard block |
||
557 | 557 | $checkin_value = CheckinsCSV::getCheckinValue($checkin_row); |
558 | 558 | $datetime_name = CheckinsCSV::getDatetimeLabel($datetime); |
559 | 559 | |
560 | - $reg_csv_array[ $datetime_name ] = $checkin_value; |
|
560 | + $reg_csv_array[$datetime_name] = $checkin_value; |
|
561 | 561 | } |
562 | 562 | } |
563 | 563 | /** |
@@ -586,7 +586,7 @@ discard block |
||
586 | 586 | foreach ($field_list as $field_name) { |
587 | 587 | $field = |
588 | 588 | $model->field_settings_for($field_name); |
589 | - $reg_csv_array[ EEH_Export::get_column_name_for_field($field) ] = null; |
|
589 | + $reg_csv_array[EEH_Export::get_column_name_for_field($field)] = null; |
|
590 | 590 | } |
591 | 591 | } |
592 | 592 | $registrations_csv_ready_array[] = $reg_csv_array; |
@@ -641,7 +641,7 @@ discard block |
||
641 | 641 | 'event_espresso' |
642 | 642 | ), |
643 | 643 | '<span id="ee-redirect-timer">10</span>', |
644 | - '<a href="' . $job_parameters->request_datum('return_url') . '">', |
|
644 | + '<a href="'.$job_parameters->request_datum('return_url').'">', |
|
645 | 645 | '</a>' |
646 | 646 | ) |
647 | 647 | ) |
@@ -11,175 +11,175 @@ discard block |
||
11 | 11 | */ |
12 | 12 | abstract class EE_Form_Section_Layout_Base |
13 | 13 | { |
14 | - /** |
|
15 | - * Form section to lay out |
|
16 | - * |
|
17 | - * @var EE_Form_Section_Proper |
|
18 | - */ |
|
19 | - protected $_form_section; |
|
20 | - |
|
21 | - |
|
22 | - |
|
23 | - /** |
|
24 | - * __construct |
|
25 | - */ |
|
26 | - public function __construct() |
|
27 | - { |
|
28 | - } |
|
29 | - |
|
30 | - |
|
31 | - |
|
32 | - /** |
|
33 | - * The form section on which this strategy is to perform |
|
34 | - * |
|
35 | - * @param EE_Form_Section_Proper $form |
|
36 | - */ |
|
37 | - public function _construct_finalize(EE_Form_Section_Proper $form) |
|
38 | - { |
|
39 | - $this->_form_section = $form; |
|
40 | - } |
|
41 | - |
|
42 | - |
|
43 | - |
|
44 | - /** |
|
45 | - * @return EE_Form_Section_Proper |
|
46 | - */ |
|
47 | - public function form_section() |
|
48 | - { |
|
49 | - return $this->_form_section; |
|
50 | - } |
|
51 | - |
|
52 | - |
|
53 | - |
|
54 | - /** |
|
55 | - * Also has teh side effect of enqueuing any needed JS and CSS for |
|
56 | - * this form. |
|
57 | - * Creates all the HTML necessary for displaying this form, its inputs, and |
|
58 | - * proper subsections. |
|
59 | - * Returns the HTML |
|
60 | - * |
|
61 | - * @return string HTML for displaying |
|
62 | - * @throws EE_Error |
|
63 | - */ |
|
64 | - public function layout_form() |
|
65 | - { |
|
66 | - $html = ''; |
|
67 | - // layout_form_begin |
|
68 | - $html .= apply_filters( |
|
69 | - 'FHEE__EE_Form_Section_Layout_Base__layout_form__start__for_' . $this->_form_section->name(), |
|
70 | - $this->layout_form_begin(), |
|
71 | - $this->_form_section |
|
72 | - ); |
|
73 | - // layout_form_loop |
|
74 | - $html .= apply_filters( |
|
75 | - 'FHEE__EE_Form_Section_Layout_Base__layout_form__loop__for_' . $this->_form_section->name(), |
|
76 | - $this->layout_form_loop(), |
|
77 | - $this->_form_section |
|
78 | - ); |
|
79 | - // layout_form_end |
|
80 | - $html .= apply_filters( |
|
81 | - 'FHEE__EE_Form_Section_Layout_Base__layout_form__end__for_' . $this->_form_section->name(), |
|
82 | - $this->layout_form_end(), |
|
83 | - $this->_form_section |
|
84 | - ); |
|
85 | - return $this->add_form_section_hooks_and_filters($html); |
|
86 | - } |
|
87 | - |
|
88 | - |
|
89 | - |
|
90 | - /** |
|
91 | - * @return string |
|
92 | - * @throws EE_Error |
|
93 | - */ |
|
94 | - public function layout_form_loop() |
|
95 | - { |
|
96 | - $html = ''; |
|
97 | - foreach ($this->_form_section->subsections() as $name => $subsection) { |
|
98 | - if ($subsection instanceof EE_Form_Input_Base) { |
|
99 | - $html .= apply_filters( |
|
100 | - 'FHEE__EE_Form_Section_Layout_Base__layout_form__loop_for_input_' |
|
101 | - . $name . '__in_' . $this->_form_section->name(), |
|
102 | - $this->layout_input($subsection), |
|
103 | - $this->_form_section, |
|
104 | - $subsection |
|
105 | - ); |
|
106 | - } elseif ($subsection instanceof EE_Form_Section_Base) { |
|
107 | - $html .= apply_filters( |
|
108 | - 'FHEE__EE_Form_Section_Layout_Base__layout_form__loop_for_non_input_' |
|
109 | - . $name . '__in_' . $this->_form_section->name(), |
|
110 | - $this->layout_subsection($subsection), |
|
111 | - $this->_form_section, |
|
112 | - $subsection |
|
113 | - ); |
|
114 | - } |
|
115 | - } |
|
116 | - return $html; |
|
117 | - } |
|
118 | - |
|
119 | - |
|
120 | - |
|
121 | - /** |
|
122 | - * Should be used to start teh form section (Eg a table tag, or a div tag, etc.) |
|
123 | - * |
|
124 | - * @return string |
|
125 | - */ |
|
126 | - abstract public function layout_form_begin(); |
|
127 | - |
|
128 | - |
|
129 | - |
|
130 | - /** |
|
131 | - * Should be used to end the form section (eg a /table tag, or a /div tag, etc.) |
|
132 | - * |
|
133 | - * @return string |
|
134 | - */ |
|
135 | - abstract public function layout_form_end(); |
|
136 | - |
|
137 | - |
|
138 | - |
|
139 | - /** |
|
140 | - * Should be used internally by layout_form() to lay out each input (eg, if this layout |
|
141 | - * is putting each input in a row of its own, this should probably be called by a |
|
142 | - * foreach loop in layout_form() (WITHOUT adding any content directly within layout_form()'s foreach loop. |
|
143 | - * Eg, this method should add the tr and td tags). This method is exposed in case you want to completely |
|
144 | - * customize the form's layout, but would like to make use of it for laying out |
|
145 | - * 'easy-to-layout' inputs |
|
146 | - * |
|
147 | - * @param EE_Form_Input_Base $input |
|
148 | - * @return string html |
|
149 | - */ |
|
150 | - abstract public function layout_input($input); |
|
151 | - |
|
152 | - |
|
153 | - |
|
154 | - /** |
|
155 | - * Similar to layout_input(), should be used internally by layout_form() within a |
|
156 | - * loop to lay out each proper subsection. Unlike layout_input(), however, it is assumed |
|
157 | - * that the proper subsection will lay out its container, label, etc on its own. |
|
158 | - * |
|
159 | - * @param EE_Form_Section_Base $subsection |
|
160 | - * @return string html |
|
161 | - */ |
|
162 | - abstract public function layout_subsection($subsection); |
|
163 | - |
|
164 | - |
|
165 | - /** |
|
166 | - * Gets the HTML for the label tag and its contents for the input |
|
167 | - * |
|
168 | - * @param EE_Form_Input_Base $input |
|
169 | - * @return string |
|
170 | - * @throws EE_Error |
|
171 | - */ |
|
172 | - public function display_label($input) |
|
173 | - { |
|
174 | - $label_text = $input->html_label_text(); |
|
175 | - if (! $label_text || $input->get_display_strategy() instanceof EE_Hidden_Display_Strategy) { |
|
176 | - return ''; |
|
177 | - } |
|
178 | - $class = $input->required() |
|
179 | - ? 'ee-required-label ' . $input->html_label_class() |
|
180 | - : $input->html_label_class(); |
|
181 | - $label_text .= $input->required() ? '<span class="ee-asterisk">*</span>' : ''; |
|
182 | - return ' |
|
14 | + /** |
|
15 | + * Form section to lay out |
|
16 | + * |
|
17 | + * @var EE_Form_Section_Proper |
|
18 | + */ |
|
19 | + protected $_form_section; |
|
20 | + |
|
21 | + |
|
22 | + |
|
23 | + /** |
|
24 | + * __construct |
|
25 | + */ |
|
26 | + public function __construct() |
|
27 | + { |
|
28 | + } |
|
29 | + |
|
30 | + |
|
31 | + |
|
32 | + /** |
|
33 | + * The form section on which this strategy is to perform |
|
34 | + * |
|
35 | + * @param EE_Form_Section_Proper $form |
|
36 | + */ |
|
37 | + public function _construct_finalize(EE_Form_Section_Proper $form) |
|
38 | + { |
|
39 | + $this->_form_section = $form; |
|
40 | + } |
|
41 | + |
|
42 | + |
|
43 | + |
|
44 | + /** |
|
45 | + * @return EE_Form_Section_Proper |
|
46 | + */ |
|
47 | + public function form_section() |
|
48 | + { |
|
49 | + return $this->_form_section; |
|
50 | + } |
|
51 | + |
|
52 | + |
|
53 | + |
|
54 | + /** |
|
55 | + * Also has teh side effect of enqueuing any needed JS and CSS for |
|
56 | + * this form. |
|
57 | + * Creates all the HTML necessary for displaying this form, its inputs, and |
|
58 | + * proper subsections. |
|
59 | + * Returns the HTML |
|
60 | + * |
|
61 | + * @return string HTML for displaying |
|
62 | + * @throws EE_Error |
|
63 | + */ |
|
64 | + public function layout_form() |
|
65 | + { |
|
66 | + $html = ''; |
|
67 | + // layout_form_begin |
|
68 | + $html .= apply_filters( |
|
69 | + 'FHEE__EE_Form_Section_Layout_Base__layout_form__start__for_' . $this->_form_section->name(), |
|
70 | + $this->layout_form_begin(), |
|
71 | + $this->_form_section |
|
72 | + ); |
|
73 | + // layout_form_loop |
|
74 | + $html .= apply_filters( |
|
75 | + 'FHEE__EE_Form_Section_Layout_Base__layout_form__loop__for_' . $this->_form_section->name(), |
|
76 | + $this->layout_form_loop(), |
|
77 | + $this->_form_section |
|
78 | + ); |
|
79 | + // layout_form_end |
|
80 | + $html .= apply_filters( |
|
81 | + 'FHEE__EE_Form_Section_Layout_Base__layout_form__end__for_' . $this->_form_section->name(), |
|
82 | + $this->layout_form_end(), |
|
83 | + $this->_form_section |
|
84 | + ); |
|
85 | + return $this->add_form_section_hooks_and_filters($html); |
|
86 | + } |
|
87 | + |
|
88 | + |
|
89 | + |
|
90 | + /** |
|
91 | + * @return string |
|
92 | + * @throws EE_Error |
|
93 | + */ |
|
94 | + public function layout_form_loop() |
|
95 | + { |
|
96 | + $html = ''; |
|
97 | + foreach ($this->_form_section->subsections() as $name => $subsection) { |
|
98 | + if ($subsection instanceof EE_Form_Input_Base) { |
|
99 | + $html .= apply_filters( |
|
100 | + 'FHEE__EE_Form_Section_Layout_Base__layout_form__loop_for_input_' |
|
101 | + . $name . '__in_' . $this->_form_section->name(), |
|
102 | + $this->layout_input($subsection), |
|
103 | + $this->_form_section, |
|
104 | + $subsection |
|
105 | + ); |
|
106 | + } elseif ($subsection instanceof EE_Form_Section_Base) { |
|
107 | + $html .= apply_filters( |
|
108 | + 'FHEE__EE_Form_Section_Layout_Base__layout_form__loop_for_non_input_' |
|
109 | + . $name . '__in_' . $this->_form_section->name(), |
|
110 | + $this->layout_subsection($subsection), |
|
111 | + $this->_form_section, |
|
112 | + $subsection |
|
113 | + ); |
|
114 | + } |
|
115 | + } |
|
116 | + return $html; |
|
117 | + } |
|
118 | + |
|
119 | + |
|
120 | + |
|
121 | + /** |
|
122 | + * Should be used to start teh form section (Eg a table tag, or a div tag, etc.) |
|
123 | + * |
|
124 | + * @return string |
|
125 | + */ |
|
126 | + abstract public function layout_form_begin(); |
|
127 | + |
|
128 | + |
|
129 | + |
|
130 | + /** |
|
131 | + * Should be used to end the form section (eg a /table tag, or a /div tag, etc.) |
|
132 | + * |
|
133 | + * @return string |
|
134 | + */ |
|
135 | + abstract public function layout_form_end(); |
|
136 | + |
|
137 | + |
|
138 | + |
|
139 | + /** |
|
140 | + * Should be used internally by layout_form() to lay out each input (eg, if this layout |
|
141 | + * is putting each input in a row of its own, this should probably be called by a |
|
142 | + * foreach loop in layout_form() (WITHOUT adding any content directly within layout_form()'s foreach loop. |
|
143 | + * Eg, this method should add the tr and td tags). This method is exposed in case you want to completely |
|
144 | + * customize the form's layout, but would like to make use of it for laying out |
|
145 | + * 'easy-to-layout' inputs |
|
146 | + * |
|
147 | + * @param EE_Form_Input_Base $input |
|
148 | + * @return string html |
|
149 | + */ |
|
150 | + abstract public function layout_input($input); |
|
151 | + |
|
152 | + |
|
153 | + |
|
154 | + /** |
|
155 | + * Similar to layout_input(), should be used internally by layout_form() within a |
|
156 | + * loop to lay out each proper subsection. Unlike layout_input(), however, it is assumed |
|
157 | + * that the proper subsection will lay out its container, label, etc on its own. |
|
158 | + * |
|
159 | + * @param EE_Form_Section_Base $subsection |
|
160 | + * @return string html |
|
161 | + */ |
|
162 | + abstract public function layout_subsection($subsection); |
|
163 | + |
|
164 | + |
|
165 | + /** |
|
166 | + * Gets the HTML for the label tag and its contents for the input |
|
167 | + * |
|
168 | + * @param EE_Form_Input_Base $input |
|
169 | + * @return string |
|
170 | + * @throws EE_Error |
|
171 | + */ |
|
172 | + public function display_label($input) |
|
173 | + { |
|
174 | + $label_text = $input->html_label_text(); |
|
175 | + if (! $label_text || $input->get_display_strategy() instanceof EE_Hidden_Display_Strategy) { |
|
176 | + return ''; |
|
177 | + } |
|
178 | + $class = $input->required() |
|
179 | + ? 'ee-required-label ' . $input->html_label_class() |
|
180 | + : $input->html_label_class(); |
|
181 | + $label_text .= $input->required() ? '<span class="ee-asterisk">*</span>' : ''; |
|
182 | + return ' |
|
183 | 183 | <label id="' . $input->html_label_id() . '" |
184 | 184 | class="' . $class . '" |
185 | 185 | style="' . $input->html_label_style() . '" |
@@ -187,108 +187,108 @@ discard block |
||
187 | 187 | > |
188 | 188 | ' . $label_text . ' |
189 | 189 | </label>'; |
190 | - } |
|
191 | - |
|
192 | - |
|
193 | - |
|
194 | - /** |
|
195 | - * Gets the HTML for all the form's form-wide errors (ie, errors which |
|
196 | - * are not for specific inputs. E.g., if two inputs somehow disagree, |
|
197 | - * those errors would probably be on the form section, not one of its inputs) |
|
198 | - * @return string |
|
199 | - */ |
|
200 | - public function display_form_wide_errors() |
|
201 | - { |
|
202 | - $html = ''; |
|
203 | - if ($this->_form_section->get_validation_errors()) { |
|
204 | - $html .= "<div class='ee-form-wide-errors'>"; |
|
205 | - // get all the errors on THIS form section (errors which aren't |
|
206 | - // for specific inputs, but instead for the entire form section) |
|
207 | - foreach ($this->_form_section->get_validation_errors() as $error) { |
|
208 | - $html .= $error->getMessage() . '<br>'; |
|
209 | - } |
|
210 | - $html .= '</div>'; |
|
211 | - } |
|
212 | - return apply_filters( |
|
213 | - 'FHEE__EE_Form_Section_Layout_Base__display_form_wide_errors', |
|
214 | - $html, |
|
215 | - $this |
|
216 | - ); |
|
217 | - } |
|
218 | - |
|
219 | - |
|
220 | - /** |
|
221 | - * returns the HTML for the server-side validation errors for the specified input |
|
222 | - * Note that if JS is enabled, it should remove these and instead |
|
223 | - * populate the form's errors in the jquery validate fashion |
|
224 | - * using the localized data provided to the JS |
|
225 | - * |
|
226 | - * @param EE_Form_Input_Base $input |
|
227 | - * @return string |
|
228 | - * @throws EE_Error |
|
229 | - */ |
|
230 | - public function display_errors($input) |
|
231 | - { |
|
232 | - if ($input->get_validation_errors()) { |
|
233 | - return "<label id='" |
|
234 | - . $input->html_id() |
|
235 | - . "-error' class='error' for='{$input->html_name()}'>" |
|
236 | - . $input->get_validation_error_string() |
|
237 | - . '</label>'; |
|
238 | - } |
|
239 | - return ''; |
|
240 | - } |
|
241 | - |
|
242 | - |
|
243 | - /** |
|
244 | - * Displays the help span for the specified input |
|
245 | - * |
|
246 | - * @param EE_Form_Input_Base $input |
|
247 | - * @return string |
|
248 | - * @throws EE_Error |
|
249 | - */ |
|
250 | - public function display_help_text($input) |
|
251 | - { |
|
252 | - $help_text = $input->html_help_text(); |
|
253 | - if ($help_text !== '' && $help_text !== null) { |
|
254 | - $tag = is_admin() ? 'p' : 'span'; |
|
255 | - return '<' |
|
256 | - . $tag |
|
257 | - . ' id="' |
|
258 | - . $input->html_id() |
|
259 | - . '-help" class="' |
|
260 | - . $input->html_help_class() |
|
261 | - . '" style="' |
|
262 | - . $input->html_help_style() |
|
263 | - . '">' |
|
264 | - . $help_text |
|
265 | - . '</' |
|
266 | - . $tag |
|
267 | - . '>'; |
|
268 | - } |
|
269 | - return ''; |
|
270 | - } |
|
271 | - |
|
272 | - |
|
273 | - /** |
|
274 | - * Does an action and hook onto the end of teh form |
|
275 | - * |
|
276 | - * @param string $html |
|
277 | - * @return string |
|
278 | - * @throws EE_Error |
|
279 | - */ |
|
280 | - public function add_form_section_hooks_and_filters($html) |
|
281 | - { |
|
282 | - // replace dashes and spaces with underscores |
|
283 | - $hook_name = str_replace(array('-', ' '), '_', $this->_form_section->html_id()); |
|
284 | - do_action('AHEE__Form_Section_Layout__' . $hook_name, $this->_form_section); |
|
285 | - $html = (string) apply_filters( |
|
286 | - 'AFEE__Form_Section_Layout__' . $hook_name . '__html', |
|
287 | - $html, |
|
288 | - $this->_form_section |
|
289 | - ); |
|
290 | - $html .= EEH_HTML::nl() . '<!-- AHEE__Form_Section_Layout__' . $hook_name . '__html -->'; |
|
291 | - $html .= EEH_HTML::nl() . '<!-- AFEE__Form_Section_Layout__' . $hook_name . ' -->'; |
|
292 | - return $html; |
|
293 | - } |
|
190 | + } |
|
191 | + |
|
192 | + |
|
193 | + |
|
194 | + /** |
|
195 | + * Gets the HTML for all the form's form-wide errors (ie, errors which |
|
196 | + * are not for specific inputs. E.g., if two inputs somehow disagree, |
|
197 | + * those errors would probably be on the form section, not one of its inputs) |
|
198 | + * @return string |
|
199 | + */ |
|
200 | + public function display_form_wide_errors() |
|
201 | + { |
|
202 | + $html = ''; |
|
203 | + if ($this->_form_section->get_validation_errors()) { |
|
204 | + $html .= "<div class='ee-form-wide-errors'>"; |
|
205 | + // get all the errors on THIS form section (errors which aren't |
|
206 | + // for specific inputs, but instead for the entire form section) |
|
207 | + foreach ($this->_form_section->get_validation_errors() as $error) { |
|
208 | + $html .= $error->getMessage() . '<br>'; |
|
209 | + } |
|
210 | + $html .= '</div>'; |
|
211 | + } |
|
212 | + return apply_filters( |
|
213 | + 'FHEE__EE_Form_Section_Layout_Base__display_form_wide_errors', |
|
214 | + $html, |
|
215 | + $this |
|
216 | + ); |
|
217 | + } |
|
218 | + |
|
219 | + |
|
220 | + /** |
|
221 | + * returns the HTML for the server-side validation errors for the specified input |
|
222 | + * Note that if JS is enabled, it should remove these and instead |
|
223 | + * populate the form's errors in the jquery validate fashion |
|
224 | + * using the localized data provided to the JS |
|
225 | + * |
|
226 | + * @param EE_Form_Input_Base $input |
|
227 | + * @return string |
|
228 | + * @throws EE_Error |
|
229 | + */ |
|
230 | + public function display_errors($input) |
|
231 | + { |
|
232 | + if ($input->get_validation_errors()) { |
|
233 | + return "<label id='" |
|
234 | + . $input->html_id() |
|
235 | + . "-error' class='error' for='{$input->html_name()}'>" |
|
236 | + . $input->get_validation_error_string() |
|
237 | + . '</label>'; |
|
238 | + } |
|
239 | + return ''; |
|
240 | + } |
|
241 | + |
|
242 | + |
|
243 | + /** |
|
244 | + * Displays the help span for the specified input |
|
245 | + * |
|
246 | + * @param EE_Form_Input_Base $input |
|
247 | + * @return string |
|
248 | + * @throws EE_Error |
|
249 | + */ |
|
250 | + public function display_help_text($input) |
|
251 | + { |
|
252 | + $help_text = $input->html_help_text(); |
|
253 | + if ($help_text !== '' && $help_text !== null) { |
|
254 | + $tag = is_admin() ? 'p' : 'span'; |
|
255 | + return '<' |
|
256 | + . $tag |
|
257 | + . ' id="' |
|
258 | + . $input->html_id() |
|
259 | + . '-help" class="' |
|
260 | + . $input->html_help_class() |
|
261 | + . '" style="' |
|
262 | + . $input->html_help_style() |
|
263 | + . '">' |
|
264 | + . $help_text |
|
265 | + . '</' |
|
266 | + . $tag |
|
267 | + . '>'; |
|
268 | + } |
|
269 | + return ''; |
|
270 | + } |
|
271 | + |
|
272 | + |
|
273 | + /** |
|
274 | + * Does an action and hook onto the end of teh form |
|
275 | + * |
|
276 | + * @param string $html |
|
277 | + * @return string |
|
278 | + * @throws EE_Error |
|
279 | + */ |
|
280 | + public function add_form_section_hooks_and_filters($html) |
|
281 | + { |
|
282 | + // replace dashes and spaces with underscores |
|
283 | + $hook_name = str_replace(array('-', ' '), '_', $this->_form_section->html_id()); |
|
284 | + do_action('AHEE__Form_Section_Layout__' . $hook_name, $this->_form_section); |
|
285 | + $html = (string) apply_filters( |
|
286 | + 'AFEE__Form_Section_Layout__' . $hook_name . '__html', |
|
287 | + $html, |
|
288 | + $this->_form_section |
|
289 | + ); |
|
290 | + $html .= EEH_HTML::nl() . '<!-- AHEE__Form_Section_Layout__' . $hook_name . '__html -->'; |
|
291 | + $html .= EEH_HTML::nl() . '<!-- AFEE__Form_Section_Layout__' . $hook_name . ' -->'; |
|
292 | + return $html; |
|
293 | + } |
|
294 | 294 | } |
@@ -66,19 +66,19 @@ discard block |
||
66 | 66 | $html = ''; |
67 | 67 | // layout_form_begin |
68 | 68 | $html .= apply_filters( |
69 | - 'FHEE__EE_Form_Section_Layout_Base__layout_form__start__for_' . $this->_form_section->name(), |
|
69 | + 'FHEE__EE_Form_Section_Layout_Base__layout_form__start__for_'.$this->_form_section->name(), |
|
70 | 70 | $this->layout_form_begin(), |
71 | 71 | $this->_form_section |
72 | 72 | ); |
73 | 73 | // layout_form_loop |
74 | 74 | $html .= apply_filters( |
75 | - 'FHEE__EE_Form_Section_Layout_Base__layout_form__loop__for_' . $this->_form_section->name(), |
|
75 | + 'FHEE__EE_Form_Section_Layout_Base__layout_form__loop__for_'.$this->_form_section->name(), |
|
76 | 76 | $this->layout_form_loop(), |
77 | 77 | $this->_form_section |
78 | 78 | ); |
79 | 79 | // layout_form_end |
80 | 80 | $html .= apply_filters( |
81 | - 'FHEE__EE_Form_Section_Layout_Base__layout_form__end__for_' . $this->_form_section->name(), |
|
81 | + 'FHEE__EE_Form_Section_Layout_Base__layout_form__end__for_'.$this->_form_section->name(), |
|
82 | 82 | $this->layout_form_end(), |
83 | 83 | $this->_form_section |
84 | 84 | ); |
@@ -98,7 +98,7 @@ discard block |
||
98 | 98 | if ($subsection instanceof EE_Form_Input_Base) { |
99 | 99 | $html .= apply_filters( |
100 | 100 | 'FHEE__EE_Form_Section_Layout_Base__layout_form__loop_for_input_' |
101 | - . $name . '__in_' . $this->_form_section->name(), |
|
101 | + . $name.'__in_'.$this->_form_section->name(), |
|
102 | 102 | $this->layout_input($subsection), |
103 | 103 | $this->_form_section, |
104 | 104 | $subsection |
@@ -106,7 +106,7 @@ discard block |
||
106 | 106 | } elseif ($subsection instanceof EE_Form_Section_Base) { |
107 | 107 | $html .= apply_filters( |
108 | 108 | 'FHEE__EE_Form_Section_Layout_Base__layout_form__loop_for_non_input_' |
109 | - . $name . '__in_' . $this->_form_section->name(), |
|
109 | + . $name.'__in_'.$this->_form_section->name(), |
|
110 | 110 | $this->layout_subsection($subsection), |
111 | 111 | $this->_form_section, |
112 | 112 | $subsection |
@@ -172,20 +172,20 @@ discard block |
||
172 | 172 | public function display_label($input) |
173 | 173 | { |
174 | 174 | $label_text = $input->html_label_text(); |
175 | - if (! $label_text || $input->get_display_strategy() instanceof EE_Hidden_Display_Strategy) { |
|
175 | + if ( ! $label_text || $input->get_display_strategy() instanceof EE_Hidden_Display_Strategy) { |
|
176 | 176 | return ''; |
177 | 177 | } |
178 | 178 | $class = $input->required() |
179 | - ? 'ee-required-label ' . $input->html_label_class() |
|
179 | + ? 'ee-required-label '.$input->html_label_class() |
|
180 | 180 | : $input->html_label_class(); |
181 | 181 | $label_text .= $input->required() ? '<span class="ee-asterisk">*</span>' : ''; |
182 | 182 | return ' |
183 | - <label id="' . $input->html_label_id() . '" |
|
184 | - class="' . $class . '" |
|
185 | - style="' . $input->html_label_style() . '" |
|
186 | - for="' . $input->html_id() . '" |
|
183 | + <label id="' . $input->html_label_id().'" |
|
184 | + class="' . $class.'" |
|
185 | + style="' . $input->html_label_style().'" |
|
186 | + for="' . $input->html_id().'" |
|
187 | 187 | > |
188 | - ' . $label_text . ' |
|
188 | + ' . $label_text.' |
|
189 | 189 | </label>'; |
190 | 190 | } |
191 | 191 | |
@@ -205,7 +205,7 @@ discard block |
||
205 | 205 | // get all the errors on THIS form section (errors which aren't |
206 | 206 | // for specific inputs, but instead for the entire form section) |
207 | 207 | foreach ($this->_form_section->get_validation_errors() as $error) { |
208 | - $html .= $error->getMessage() . '<br>'; |
|
208 | + $html .= $error->getMessage().'<br>'; |
|
209 | 209 | } |
210 | 210 | $html .= '</div>'; |
211 | 211 | } |
@@ -249,7 +249,7 @@ discard block |
||
249 | 249 | */ |
250 | 250 | public function display_help_text($input) |
251 | 251 | { |
252 | - $help_text = $input->html_help_text(); |
|
252 | + $help_text = $input->html_help_text(); |
|
253 | 253 | if ($help_text !== '' && $help_text !== null) { |
254 | 254 | $tag = is_admin() ? 'p' : 'span'; |
255 | 255 | return '<' |
@@ -281,14 +281,14 @@ discard block |
||
281 | 281 | { |
282 | 282 | // replace dashes and spaces with underscores |
283 | 283 | $hook_name = str_replace(array('-', ' '), '_', $this->_form_section->html_id()); |
284 | - do_action('AHEE__Form_Section_Layout__' . $hook_name, $this->_form_section); |
|
284 | + do_action('AHEE__Form_Section_Layout__'.$hook_name, $this->_form_section); |
|
285 | 285 | $html = (string) apply_filters( |
286 | - 'AFEE__Form_Section_Layout__' . $hook_name . '__html', |
|
286 | + 'AFEE__Form_Section_Layout__'.$hook_name.'__html', |
|
287 | 287 | $html, |
288 | 288 | $this->_form_section |
289 | 289 | ); |
290 | - $html .= EEH_HTML::nl() . '<!-- AHEE__Form_Section_Layout__' . $hook_name . '__html -->'; |
|
291 | - $html .= EEH_HTML::nl() . '<!-- AFEE__Form_Section_Layout__' . $hook_name . ' -->'; |
|
290 | + $html .= EEH_HTML::nl().'<!-- AHEE__Form_Section_Layout__'.$hook_name.'__html -->'; |
|
291 | + $html .= EEH_HTML::nl().'<!-- AFEE__Form_Section_Layout__'.$hook_name.' -->'; |
|
292 | 292 | return $html; |
293 | 293 | } |
294 | 294 | } |
@@ -14,1227 +14,1227 @@ |
||
14 | 14 | */ |
15 | 15 | abstract class EE_Form_Input_Base extends EE_Form_Section_Validatable |
16 | 16 | { |
17 | - /** |
|
18 | - * the input's name attribute |
|
19 | - * |
|
20 | - * @var string |
|
21 | - */ |
|
22 | - protected $_html_name; |
|
23 | - |
|
24 | - /** |
|
25 | - * id for the html label tag |
|
26 | - * |
|
27 | - * @var string |
|
28 | - */ |
|
29 | - protected $_html_label_id; |
|
30 | - |
|
31 | - /** |
|
32 | - * class for teh html label tag |
|
33 | - * |
|
34 | - * @var string |
|
35 | - */ |
|
36 | - protected $_html_label_class; |
|
37 | - |
|
38 | - /** |
|
39 | - * style for teh html label tag |
|
40 | - * |
|
41 | - * @var string |
|
42 | - */ |
|
43 | - protected $_html_label_style; |
|
44 | - |
|
45 | - /** |
|
46 | - * text to be placed in the html label |
|
47 | - * |
|
48 | - * @var string |
|
49 | - */ |
|
50 | - protected $_html_label_text; |
|
51 | - |
|
52 | - /** |
|
53 | - * the full html label. If used, all other html_label_* properties are invalid |
|
54 | - * |
|
55 | - * @var string |
|
56 | - */ |
|
57 | - protected $_html_label; |
|
58 | - |
|
59 | - /** |
|
60 | - * HTML to use for help text (normally placed below form input), in a span which normally |
|
61 | - * has a class of 'description' |
|
62 | - * |
|
63 | - * @var string |
|
64 | - */ |
|
65 | - protected $_html_help_text; |
|
66 | - |
|
67 | - /** |
|
68 | - * CSS classes for displaying the help span |
|
69 | - * |
|
70 | - * @var string |
|
71 | - */ |
|
72 | - protected $_html_help_class = 'description'; |
|
73 | - |
|
74 | - /** |
|
75 | - * CSS to put in the style attribute on the help span |
|
76 | - * |
|
77 | - * @var string |
|
78 | - */ |
|
79 | - protected $_html_help_style; |
|
80 | - |
|
81 | - /** |
|
82 | - * Stores whether or not this input's response is required. |
|
83 | - * Because certain styling elements may also want to know that this |
|
84 | - * input is required etc. |
|
85 | - * |
|
86 | - * @var boolean |
|
87 | - */ |
|
88 | - protected $_required; |
|
89 | - |
|
90 | - /** |
|
91 | - * css class added to required inputs |
|
92 | - * |
|
93 | - * @var string |
|
94 | - */ |
|
95 | - protected $_required_css_class = 'ee-required'; |
|
96 | - |
|
97 | - /** |
|
98 | - * css styles applied to button type inputs |
|
99 | - * |
|
100 | - * @var string |
|
101 | - */ |
|
102 | - protected $_button_css_attributes; |
|
103 | - |
|
104 | - /** |
|
105 | - * The raw post data submitted for this |
|
106 | - * Generally unsafe for usage in client code |
|
107 | - * |
|
108 | - * @var mixed string or array |
|
109 | - */ |
|
110 | - protected $_raw_value; |
|
111 | - |
|
112 | - /** |
|
113 | - * Value normalized according to the input's normalization strategy. |
|
114 | - * The normalization strategy dictates whether this is a string, int, float, |
|
115 | - * boolean, or array of any of those. |
|
116 | - * |
|
117 | - * @var mixed |
|
118 | - */ |
|
119 | - protected $_normalized_value; |
|
120 | - |
|
121 | - |
|
122 | - /** |
|
123 | - * Normalized default value either initially set on the input, or provided by calling |
|
124 | - * set_default(). |
|
125 | - * |
|
126 | - * @var mixed |
|
127 | - */ |
|
128 | - protected $_default; |
|
129 | - |
|
130 | - /** |
|
131 | - * Strategy used for displaying this field. |
|
132 | - * Child classes must use _get_display_strategy to access it. |
|
133 | - * |
|
134 | - * @var EE_Display_Strategy_Base |
|
135 | - */ |
|
136 | - private $_display_strategy; |
|
137 | - |
|
138 | - /** |
|
139 | - * Gets all the validation strategies used on this field |
|
140 | - * |
|
141 | - * @var EE_Validation_Strategy_Base[] |
|
142 | - */ |
|
143 | - private $_validation_strategies = []; |
|
144 | - |
|
145 | - /** |
|
146 | - * The normalization strategy for this field |
|
147 | - * |
|
148 | - * @var EE_Normalization_Strategy_Base |
|
149 | - */ |
|
150 | - private $_normalization_strategy; |
|
151 | - |
|
152 | - /** |
|
153 | - * Strategy for removing sensitive data after we're done with the form input |
|
154 | - * |
|
155 | - * @var EE_Sensitive_Data_Removal_Base |
|
156 | - */ |
|
157 | - protected $_sensitive_data_removal_strategy; |
|
158 | - |
|
159 | - /** |
|
160 | - * Whether this input has been disabled or not. |
|
161 | - * If it's disabled while rendering, an extra hidden input is added that indicates it has been knowingly disabled. |
|
162 | - * (Client-side code that wants to dynamically disable it must also add this hidden input). |
|
163 | - * When the form is submitted, if the input is disabled in the PHP form section, then input is ignored. |
|
164 | - * If the input is missing from the request data but the hidden input indicating the input is disabled, then the |
|
165 | - * input is again ignored. |
|
166 | - * |
|
167 | - * @var boolean |
|
168 | - */ |
|
169 | - protected $disabled = false; |
|
170 | - |
|
171 | - |
|
172 | - protected bool $_no_label = false; // if true, then no hrml label will be displayed for this input |
|
173 | - |
|
174 | - |
|
175 | - /** |
|
176 | - * @param array $input_args { |
|
177 | - * @type string $html_name the html name for the input |
|
178 | - * @type string $html_label_id the id attribute to give to the html label tag |
|
179 | - * @type string $html_label_class the class attribute to give to the html label tag |
|
180 | - * @type string $html_label_style the style attribute to give ot teh label tag |
|
181 | - * @type string $html_label_text the text to put in the label tag |
|
182 | - * @type string $html_label the full html label. If used, |
|
183 | - * all other html_label_* args are invalid |
|
184 | - * @type string $html_help_text text to put in help element |
|
185 | - * @type string $html_help_style style attribute to give to teh help element |
|
186 | - * @type string $html_help_class class attribute to give to the help element |
|
187 | - * @type string $default default value NORMALIZED (eg, if providing the default |
|
188 | - * for a Yes_No_Input, you should provide TRUE or FALSE, not |
|
189 | - * '1' or '0') |
|
190 | - * @type EE_Display_Strategy_Base $display strategy |
|
191 | - * @type EE_Normalization_Strategy_Base $normalization_strategy |
|
192 | - * @type EE_Validation_Strategy_Base[] $validation_strategies |
|
193 | - * @type boolean $ignore_input special argument which can be used to avoid adding any |
|
194 | - * validation strategies, and sets the normalization |
|
195 | - * strategy to the Null normalization. This is good when you |
|
196 | - * want the input to be totally ignored server-side (like |
|
197 | - * when using React.js form inputs) |
|
198 | - * } |
|
199 | - */ |
|
200 | - public function __construct($input_args = []) |
|
201 | - { |
|
202 | - $input_args = (array) apply_filters('FHEE__EE_Form_Input_Base___construct__input_args', $input_args, $this); |
|
203 | - // the following properties must be cast as arrays |
|
204 | - if (isset($input_args['validation_strategies'])) { |
|
205 | - foreach ((array) $input_args['validation_strategies'] as $validation_strategy) { |
|
206 | - if ($validation_strategy instanceof EE_Validation_Strategy_Base && empty($input_args['ignore_input'])) { |
|
207 | - $this->_validation_strategies[ get_class($validation_strategy) ] = $validation_strategy; |
|
208 | - } |
|
209 | - } |
|
210 | - unset($input_args['validation_strategies']); |
|
211 | - } |
|
212 | - if (isset($input_args['ignore_input'])) { |
|
213 | - $this->_validation_strategies = []; |
|
214 | - } |
|
215 | - // loop thru incoming options |
|
216 | - foreach ($input_args as $key => $value) { |
|
217 | - if ($key === 'disabled') { |
|
218 | - $this->disable($value); |
|
219 | - continue; |
|
220 | - } |
|
221 | - // add underscore to $key to match property names |
|
222 | - $_key = '_' . $key; |
|
223 | - if (property_exists($this, $_key)) { |
|
224 | - $this->{$_key} = $value; |
|
225 | - } |
|
226 | - } |
|
227 | - // ensure that "required" is set correctly |
|
228 | - $this->set_required( |
|
229 | - $this->_required, |
|
230 | - $input_args['required_validation_error_message'] ?? null |
|
231 | - ); |
|
232 | - // $this->_html_name_specified = isset( $input_args['html_name'] ) ? TRUE : FALSE; |
|
233 | - $this->_display_strategy->_construct_finalize($this); |
|
234 | - foreach ($this->_validation_strategies as $validation_strategy) { |
|
235 | - $validation_strategy->_construct_finalize($this); |
|
236 | - } |
|
237 | - if (isset($input_args['ignore_input'])) { |
|
238 | - $this->_normalization_strategy = new EE_Null_Normalization(); |
|
239 | - } |
|
240 | - if (! $this->_normalization_strategy) { |
|
241 | - $this->_normalization_strategy = new EE_Text_Normalization(); |
|
242 | - } |
|
243 | - $this->_normalization_strategy->_construct_finalize($this); |
|
244 | - // at least we can use the normalization strategy to populate the default |
|
245 | - if (isset($input_args['default'])) { |
|
246 | - $this->set_default($input_args['default']); |
|
247 | - unset($input_args['default']); |
|
248 | - } |
|
249 | - if (! $this->_sensitive_data_removal_strategy) { |
|
250 | - $this->_sensitive_data_removal_strategy = new EE_No_Sensitive_Data_Removal(); |
|
251 | - } |
|
252 | - $this->_sensitive_data_removal_strategy->_construct_finalize($this); |
|
253 | - parent::__construct($input_args); |
|
254 | - } |
|
255 | - |
|
256 | - |
|
257 | - /** |
|
258 | - * Sets the html_name to its default value, if none was specified in teh constructor. |
|
259 | - * Calculation involves using the name and the parent's html_name |
|
260 | - * |
|
261 | - * @throws EE_Error |
|
262 | - */ |
|
263 | - protected function _set_default_html_name_if_empty() |
|
264 | - { |
|
265 | - if (! $this->_html_name) { |
|
266 | - $this->_html_name = $this->name(); |
|
267 | - if ($this->_parent_section && $this->_parent_section instanceof EE_Form_Section_Proper) { |
|
268 | - $this->_html_name = $this->_parent_section->html_name_prefix() . "[{$this->name()}]"; |
|
269 | - } |
|
270 | - } |
|
271 | - } |
|
272 | - |
|
273 | - |
|
274 | - /** |
|
275 | - * @param $parent_form_section |
|
276 | - * @param $name |
|
277 | - * @throws EE_Error |
|
278 | - */ |
|
279 | - public function _construct_finalize($parent_form_section, $name) |
|
280 | - { |
|
281 | - parent::_construct_finalize($parent_form_section, $name); |
|
282 | - if ($this->_html_label === null && $this->_html_label_text === null && ! $this->_no_label) { |
|
283 | - $this->_html_label_text = ucwords(str_replace("_", " ", $name)); |
|
284 | - } |
|
285 | - do_action('AHEE__EE_Form_Input_Base___construct_finalize__end', $this, $parent_form_section, $name); |
|
286 | - } |
|
287 | - |
|
288 | - |
|
289 | - /** |
|
290 | - * Returns the strategy for displaying this form input. If none is set, throws an exception. |
|
291 | - * |
|
292 | - * @return EE_Display_Strategy_Base |
|
293 | - * @throws EE_Error |
|
294 | - */ |
|
295 | - protected function _get_display_strategy() |
|
296 | - { |
|
297 | - $this->ensure_construct_finalized_called(); |
|
298 | - if (! $this->_display_strategy || ! $this->_display_strategy instanceof EE_Display_Strategy_Base) { |
|
299 | - throw new EE_Error( |
|
300 | - sprintf( |
|
301 | - esc_html__( |
|
302 | - "Cannot get display strategy for form input with name %s and id %s, because it has not been set in the constructor", |
|
303 | - "event_espresso" |
|
304 | - ), |
|
305 | - $this->html_name(), |
|
306 | - $this->html_id() |
|
307 | - ) |
|
308 | - ); |
|
309 | - } else { |
|
310 | - return $this->_display_strategy; |
|
311 | - } |
|
312 | - } |
|
313 | - |
|
314 | - |
|
315 | - /** |
|
316 | - * Sets the display strategy. |
|
317 | - * |
|
318 | - * @param EE_Display_Strategy_Base $strategy |
|
319 | - */ |
|
320 | - protected function _set_display_strategy(EE_Display_Strategy_Base $strategy) |
|
321 | - { |
|
322 | - $this->_display_strategy = $strategy; |
|
323 | - } |
|
324 | - |
|
325 | - |
|
326 | - /** |
|
327 | - * Sets the sanitization strategy |
|
328 | - * |
|
329 | - * @param EE_Normalization_Strategy_Base $strategy |
|
330 | - */ |
|
331 | - protected function _set_normalization_strategy(EE_Normalization_Strategy_Base $strategy) |
|
332 | - { |
|
333 | - $this->_normalization_strategy = $strategy; |
|
334 | - } |
|
335 | - |
|
336 | - |
|
337 | - /** |
|
338 | - * Gets sensitive_data_removal_strategy |
|
339 | - * |
|
340 | - * @return EE_Sensitive_Data_Removal_Base |
|
341 | - */ |
|
342 | - public function get_sensitive_data_removal_strategy() |
|
343 | - { |
|
344 | - return $this->_sensitive_data_removal_strategy; |
|
345 | - } |
|
346 | - |
|
347 | - |
|
348 | - /** |
|
349 | - * Sets sensitive_data_removal_strategy |
|
350 | - * |
|
351 | - * @param EE_Sensitive_Data_Removal_Base $sensitive_data_removal_strategy |
|
352 | - * @return void |
|
353 | - */ |
|
354 | - public function set_sensitive_data_removal_strategy($sensitive_data_removal_strategy) |
|
355 | - { |
|
356 | - $this->_sensitive_data_removal_strategy = $sensitive_data_removal_strategy; |
|
357 | - } |
|
358 | - |
|
359 | - |
|
360 | - /** |
|
361 | - * Gets the display strategy for this input |
|
362 | - * |
|
363 | - * @return EE_Display_Strategy_Base |
|
364 | - */ |
|
365 | - public function get_display_strategy() |
|
366 | - { |
|
367 | - return $this->_display_strategy; |
|
368 | - } |
|
369 | - |
|
370 | - |
|
371 | - /** |
|
372 | - * Overwrites the display strategy |
|
373 | - * |
|
374 | - * @param EE_Display_Strategy_Base $display_strategy |
|
375 | - */ |
|
376 | - public function set_display_strategy($display_strategy) |
|
377 | - { |
|
378 | - $this->_display_strategy = $display_strategy; |
|
379 | - $this->_display_strategy->_construct_finalize($this); |
|
380 | - } |
|
381 | - |
|
382 | - |
|
383 | - /** |
|
384 | - * Gets the normalization strategy set on this input |
|
385 | - * |
|
386 | - * @return EE_Normalization_Strategy_Base |
|
387 | - */ |
|
388 | - public function get_normalization_strategy() |
|
389 | - { |
|
390 | - return $this->_normalization_strategy; |
|
391 | - } |
|
392 | - |
|
393 | - |
|
394 | - /** |
|
395 | - * Overwrites the normalization strategy |
|
396 | - * |
|
397 | - * @param EE_Normalization_Strategy_Base $normalization_strategy |
|
398 | - */ |
|
399 | - public function set_normalization_strategy($normalization_strategy) |
|
400 | - { |
|
401 | - $this->_normalization_strategy = $normalization_strategy; |
|
402 | - $this->_normalization_strategy->_construct_finalize($this); |
|
403 | - } |
|
404 | - |
|
405 | - |
|
406 | - /** |
|
407 | - * Returns all teh validation strategies which apply to this field, numerically indexed |
|
408 | - * |
|
409 | - * @return EE_Validation_Strategy_Base[] |
|
410 | - */ |
|
411 | - public function get_validation_strategies() |
|
412 | - { |
|
413 | - return $this->_validation_strategies; |
|
414 | - } |
|
415 | - |
|
416 | - |
|
417 | - /** |
|
418 | - * Adds this strategy to the field so it will be used in both JS validation and server-side validation |
|
419 | - * |
|
420 | - * @param EE_Validation_Strategy_Base $validation_strategy |
|
421 | - * @return void |
|
422 | - */ |
|
423 | - protected function _add_validation_strategy(EE_Validation_Strategy_Base $validation_strategy) |
|
424 | - { |
|
425 | - $validation_strategy->_construct_finalize($this); |
|
426 | - $this->_validation_strategies[] = $validation_strategy; |
|
427 | - } |
|
428 | - |
|
429 | - |
|
430 | - /** |
|
431 | - * Adds a new validation strategy onto the form input |
|
432 | - * |
|
433 | - * @param EE_Validation_Strategy_Base $validation_strategy |
|
434 | - * @return void |
|
435 | - */ |
|
436 | - public function add_validation_strategy(EE_Validation_Strategy_Base $validation_strategy) |
|
437 | - { |
|
438 | - $this->_add_validation_strategy($validation_strategy); |
|
439 | - } |
|
440 | - |
|
441 | - |
|
442 | - /** |
|
443 | - * The classname of the validation strategy to remove |
|
444 | - * |
|
445 | - * @param string $validation_strategy_classname |
|
446 | - */ |
|
447 | - public function remove_validation_strategy($validation_strategy_classname) |
|
448 | - { |
|
449 | - foreach ($this->_validation_strategies as $key => $validation_strategy) { |
|
450 | - if ( |
|
451 | - $validation_strategy instanceof $validation_strategy_classname |
|
452 | - || is_subclass_of($validation_strategy, $validation_strategy_classname) |
|
453 | - ) { |
|
454 | - unset($this->_validation_strategies[ $key ]); |
|
455 | - } |
|
456 | - } |
|
457 | - } |
|
458 | - |
|
459 | - |
|
460 | - /** |
|
461 | - * returns true if input employs any of the validation strategy defined by the supplied array of classnames |
|
462 | - * |
|
463 | - * @param array $validation_strategy_classnames |
|
464 | - * @return bool |
|
465 | - */ |
|
466 | - public function has_validation_strategy($validation_strategy_classnames) |
|
467 | - { |
|
468 | - $validation_strategy_classnames = is_array($validation_strategy_classnames) |
|
469 | - ? $validation_strategy_classnames |
|
470 | - : [$validation_strategy_classnames]; |
|
471 | - foreach ($this->_validation_strategies as $key => $validation_strategy) { |
|
472 | - if (in_array($key, $validation_strategy_classnames)) { |
|
473 | - return true; |
|
474 | - } |
|
475 | - } |
|
476 | - return false; |
|
477 | - } |
|
478 | - |
|
479 | - |
|
480 | - /** |
|
481 | - * Gets the HTML |
|
482 | - * |
|
483 | - * @return string |
|
484 | - */ |
|
485 | - public function get_html() |
|
486 | - { |
|
487 | - return $this->_parent_section->get_html_for_input($this); |
|
488 | - } |
|
489 | - |
|
490 | - |
|
491 | - /** |
|
492 | - * Gets the HTML for the input itself (no label or errors) according to the |
|
493 | - * input's display strategy |
|
494 | - * Makes sure the JS and CSS are enqueued for it |
|
495 | - * |
|
496 | - * @return string |
|
497 | - * @throws EE_Error |
|
498 | - */ |
|
499 | - public function get_html_for_input() |
|
500 | - { |
|
501 | - return $this->_form_html_filter |
|
502 | - ? $this->_form_html_filter->filterHtml( |
|
503 | - $this->_get_display_strategy()->display(), |
|
504 | - $this |
|
505 | - ) |
|
506 | - : $this->_get_display_strategy()->display(); |
|
507 | - } |
|
508 | - |
|
509 | - |
|
510 | - /** |
|
511 | - * @return string |
|
512 | - */ |
|
513 | - public function html_other_attributes() |
|
514 | - { |
|
515 | - EE_Error::doing_it_wrong( |
|
516 | - __METHOD__, |
|
517 | - sprintf( |
|
518 | - esc_html__( |
|
519 | - 'This method is no longer in use. You should replace it by %s', |
|
520 | - 'event_espresso' |
|
521 | - ), |
|
522 | - 'EE_Form_Section_Base::other_html_attributes()' |
|
523 | - ), |
|
524 | - '4.10.2.p' |
|
525 | - ); |
|
526 | - |
|
527 | - return $this->other_html_attributes(); |
|
528 | - } |
|
529 | - |
|
530 | - |
|
531 | - /** |
|
532 | - * @param string $html_other_attributes |
|
533 | - */ |
|
534 | - public function set_html_other_attributes($html_other_attributes) |
|
535 | - { |
|
536 | - EE_Error::doing_it_wrong( |
|
537 | - __METHOD__, |
|
538 | - sprintf( |
|
539 | - esc_html__( |
|
540 | - 'This method is no longer in use. You should replace it by %s', |
|
541 | - 'event_espresso' |
|
542 | - ), |
|
543 | - 'EE_Form_Section_Base::set_other_html_attributes()' |
|
544 | - ), |
|
545 | - '4.10.2.p' |
|
546 | - ); |
|
547 | - |
|
548 | - $this->set_other_html_attributes($html_other_attributes); |
|
549 | - } |
|
550 | - |
|
551 | - |
|
552 | - /** |
|
553 | - * Gets the HTML for displaying the label for this form input |
|
554 | - * according to the form section's layout strategy |
|
555 | - * |
|
556 | - * @return string |
|
557 | - */ |
|
558 | - public function get_html_for_label() |
|
559 | - { |
|
560 | - return $this->_parent_section->get_layout_strategy()->display_label($this); |
|
561 | - } |
|
562 | - |
|
563 | - |
|
564 | - /** |
|
565 | - * Gets the HTML for displaying the errors section for this form input |
|
566 | - * according to the form section's layout strategy |
|
567 | - * |
|
568 | - * @return string |
|
569 | - */ |
|
570 | - public function get_html_for_errors() |
|
571 | - { |
|
572 | - return $this->_parent_section->get_layout_strategy()->display_errors($this); |
|
573 | - } |
|
574 | - |
|
575 | - |
|
576 | - /** |
|
577 | - * Gets the HTML for displaying the help text for this form input |
|
578 | - * according to the form section's layout strategy |
|
579 | - * |
|
580 | - * @return string |
|
581 | - */ |
|
582 | - public function get_html_for_help() |
|
583 | - { |
|
584 | - return $this->_parent_section->get_layout_strategy()->display_help_text($this); |
|
585 | - } |
|
586 | - |
|
587 | - |
|
588 | - /** |
|
589 | - * Validates the input's sanitized value (assumes _sanitize() has already been called) |
|
590 | - * and returns whether or not the form input's submitted value is value |
|
591 | - * |
|
592 | - * @return boolean |
|
593 | - */ |
|
594 | - protected function _validate() |
|
595 | - { |
|
596 | - if ($this->isDisabled()) { |
|
597 | - return true; |
|
598 | - } |
|
599 | - foreach ($this->_validation_strategies as $validation_strategy) { |
|
600 | - if ($validation_strategy instanceof EE_Validation_Strategy_Base) { |
|
601 | - try { |
|
602 | - $validation_strategy->validate($this->normalized_value()); |
|
603 | - } catch (EE_Validation_Error $e) { |
|
604 | - $this->add_validation_error($e); |
|
605 | - } |
|
606 | - } |
|
607 | - } |
|
608 | - if ($this->get_validation_errors()) { |
|
609 | - return false; |
|
610 | - } else { |
|
611 | - return true; |
|
612 | - } |
|
613 | - } |
|
614 | - |
|
615 | - |
|
616 | - /** |
|
617 | - * Performs basic sanitization on this value. But what sanitization can be performed anyways? |
|
618 | - * This value MIGHT be allowed to have tags, so we can't really remove them. |
|
619 | - * |
|
620 | - * @param string $value |
|
621 | - * @return null|string |
|
622 | - */ |
|
623 | - protected function _sanitize($value) |
|
624 | - { |
|
625 | - return $value !== null |
|
626 | - ? stripslashes(html_entity_decode(trim((string) $value))) |
|
627 | - : null; |
|
628 | - } |
|
629 | - |
|
630 | - |
|
631 | - /** |
|
632 | - * Picks out the form value that relates to this form input, |
|
633 | - * and stores it as the sanitized value on the form input, and sets the normalized value. |
|
634 | - * Returns whether or not any validation errors occurred |
|
635 | - * |
|
636 | - * @param array $req_data |
|
637 | - * @return boolean whether or not there was an error |
|
638 | - * @throws EE_Error |
|
639 | - */ |
|
640 | - protected function _normalize($req_data) |
|
641 | - { |
|
642 | - // any existing validation errors don't apply so clear them |
|
643 | - $this->_validation_errors = []; |
|
644 | - // if the input is disabled, ignore whatever input was sent in |
|
645 | - if ($this->isDisabled()) { |
|
646 | - $this->_set_raw_value(null); |
|
647 | - $this->_set_normalized_value($this->get_default()); |
|
648 | - return false; |
|
649 | - } |
|
650 | - try { |
|
651 | - $raw_input = $this->find_form_data_for_this_section($req_data); |
|
652 | - // super simple sanitization for now |
|
653 | - if (is_array($raw_input)) { |
|
654 | - $raw_value = []; |
|
655 | - foreach ($raw_input as $key => $value) { |
|
656 | - $raw_value[ $key ] = $this->_sanitize($value); |
|
657 | - } |
|
658 | - $this->_set_raw_value($raw_value); |
|
659 | - } else { |
|
660 | - $this->_set_raw_value($this->_sanitize($raw_input)); |
|
661 | - } |
|
662 | - // we want to mostly leave the input alone in case we need to re-display it to the user |
|
663 | - $this->_set_normalized_value($this->_normalization_strategy->normalize($this->raw_value())); |
|
664 | - return false; |
|
665 | - } catch (EE_Validation_Error $e) { |
|
666 | - $this->add_validation_error($e); |
|
667 | - return true; |
|
668 | - } |
|
669 | - } |
|
670 | - |
|
671 | - |
|
672 | - /** |
|
673 | - * @return string |
|
674 | - * @throws EE_Error |
|
675 | - */ |
|
676 | - public function html_name() |
|
677 | - { |
|
678 | - $this->_set_default_html_name_if_empty(); |
|
679 | - return $this->_html_name ?? ''; |
|
680 | - } |
|
681 | - |
|
682 | - |
|
683 | - /** |
|
684 | - * @return string |
|
685 | - * @throws EE_Error |
|
686 | - */ |
|
687 | - public function html_label_id() |
|
688 | - { |
|
689 | - return ! empty($this->_html_label_id) |
|
690 | - ? $this->_html_label_id |
|
691 | - : $this->html_id() . '-lbl'; |
|
692 | - } |
|
693 | - |
|
694 | - |
|
695 | - /** |
|
696 | - * @return string |
|
697 | - */ |
|
698 | - public function html_label_class() |
|
699 | - { |
|
700 | - return $this->_html_label_class ?? ''; |
|
701 | - } |
|
702 | - |
|
703 | - |
|
704 | - /** |
|
705 | - * @param string $html_class |
|
706 | - */ |
|
707 | - public function add_html_label_class(string $html_class) |
|
708 | - { |
|
709 | - $this->_html_label_class .= ' ' . trim($html_class); |
|
710 | - } |
|
711 | - |
|
712 | - |
|
713 | - /** |
|
714 | - * @return string |
|
715 | - */ |
|
716 | - public function html_label_style() |
|
717 | - { |
|
718 | - return $this->_html_label_style ?? ''; |
|
719 | - } |
|
720 | - |
|
721 | - |
|
722 | - /** |
|
723 | - * @return string |
|
724 | - */ |
|
725 | - public function html_label_text() |
|
726 | - { |
|
727 | - return $this->_html_label_text ?? ''; |
|
728 | - } |
|
729 | - |
|
730 | - |
|
731 | - /** |
|
732 | - * @return string |
|
733 | - */ |
|
734 | - public function html_help_text() |
|
735 | - { |
|
736 | - return $this->_html_help_text ?? ''; |
|
737 | - } |
|
738 | - |
|
739 | - |
|
740 | - /** |
|
741 | - * @return string |
|
742 | - */ |
|
743 | - public function html_help_class() |
|
744 | - { |
|
745 | - return $this->_html_help_class ?? ''; |
|
746 | - } |
|
747 | - |
|
748 | - |
|
749 | - /** |
|
750 | - * @return string |
|
751 | - */ |
|
752 | - public function html_help_style() |
|
753 | - { |
|
754 | - return $this->_html_style ?? ''; |
|
755 | - } |
|
756 | - |
|
757 | - |
|
758 | - /** |
|
759 | - * returns the raw, UNSAFE, input, almost exactly as the user submitted it. |
|
760 | - * Please note that almost all client code should instead use the normalized_value; |
|
761 | - * or possibly raw_value_in_form (which prepares the string for displaying in an HTML attribute on a tag, |
|
762 | - * mostly by escaping quotes) |
|
763 | - * Note, we do not store the exact original value sent in the user's request because |
|
764 | - * it may have malicious content, and we MIGHT want to store the form input in a transient or something... |
|
765 | - * in which case, we would have stored the malicious content to our database. |
|
766 | - * |
|
767 | - * @return mixed |
|
768 | - */ |
|
769 | - public function raw_value() |
|
770 | - { |
|
771 | - return $this->_raw_value; |
|
772 | - } |
|
773 | - |
|
774 | - |
|
775 | - /** |
|
776 | - * Returns a string safe to usage in form inputs when displaying, because |
|
777 | - * it escapes all html entities |
|
778 | - * |
|
779 | - * @return string |
|
780 | - */ |
|
781 | - public function raw_value_in_form(): string |
|
782 | - { |
|
783 | - return htmlentities((string) $this->raw_value(), ENT_QUOTES, 'UTF-8'); |
|
784 | - } |
|
785 | - |
|
786 | - |
|
787 | - /** |
|
788 | - * returns the value after it's been sanitized, and then converted into it's proper type |
|
789 | - * in PHP. Eg, a string, an int, an array, |
|
790 | - * |
|
791 | - * @return mixed |
|
792 | - */ |
|
793 | - public function normalized_value() |
|
794 | - { |
|
795 | - return $this->_normalized_value; |
|
796 | - } |
|
797 | - |
|
798 | - |
|
799 | - /** |
|
800 | - * Returns the normalized value is a presentable way. By default this is just |
|
801 | - * the normalized value by itself, but it can be overridden for when that's not |
|
802 | - * the best thing to display |
|
803 | - * |
|
804 | - * @return mixed |
|
805 | - */ |
|
806 | - public function pretty_value() |
|
807 | - { |
|
808 | - return $this->_normalized_value; |
|
809 | - } |
|
810 | - |
|
811 | - |
|
812 | - /** |
|
813 | - * When generating the JS for the jquery validation rules like<br> |
|
814 | - * <code>$( "#myform" ).validate({ |
|
815 | - * rules: { |
|
816 | - * password: "required", |
|
817 | - * password_again: { |
|
818 | - * equalTo: "#password" |
|
819 | - * } |
|
820 | - * } |
|
821 | - * });</code> |
|
822 | - * if this field had the name 'password_again', it should return |
|
823 | - * <br><code>password_again: { |
|
824 | - * equalTo: "#password" |
|
825 | - * }</code> |
|
826 | - * |
|
827 | - * @return array |
|
828 | - */ |
|
829 | - public function get_jquery_validation_rules(): array |
|
830 | - { |
|
831 | - $jquery_validation_js = []; |
|
832 | - $jquery_validation_rules = []; |
|
833 | - foreach ($this->get_validation_strategies() as $validation_strategy) { |
|
834 | - $jquery_validation_rules = array_replace_recursive( |
|
835 | - $jquery_validation_rules, |
|
836 | - $validation_strategy->get_jquery_validation_rule_array() |
|
837 | - ); |
|
838 | - } |
|
839 | - if (! empty($jquery_validation_rules)) { |
|
840 | - foreach ($this->get_display_strategy()->get_html_input_ids(true) as $html_id_with_pound_sign) { |
|
841 | - $jquery_validation_js[ $html_id_with_pound_sign ] = $jquery_validation_rules; |
|
842 | - } |
|
843 | - } |
|
844 | - return $jquery_validation_js; |
|
845 | - } |
|
846 | - |
|
847 | - |
|
848 | - /** |
|
849 | - * Sets the input's default value for use in displaying in the form. Note: value should be |
|
850 | - * normalized (Eg, if providing a default of ra Yes_NO_Input you would provide TRUE or FALSE, not '1' or '0') |
|
851 | - * |
|
852 | - * @param mixed $value |
|
853 | - * @return void |
|
854 | - */ |
|
855 | - public function set_default($value) |
|
856 | - { |
|
857 | - $this->_default = $value; |
|
858 | - $this->_set_normalized_value($value); |
|
859 | - $this->_set_raw_value($value); |
|
860 | - } |
|
861 | - |
|
862 | - |
|
863 | - /** |
|
864 | - * Sets the normalized value on this input |
|
865 | - * |
|
866 | - * @param mixed $value |
|
867 | - */ |
|
868 | - protected function _set_normalized_value($value) |
|
869 | - { |
|
870 | - $this->_normalized_value = $value; |
|
871 | - } |
|
872 | - |
|
873 | - |
|
874 | - /** |
|
875 | - * Sets the raw value on this input (ie, exactly as the user submitted it) |
|
876 | - * |
|
877 | - * @param mixed $value |
|
878 | - */ |
|
879 | - protected function _set_raw_value($value) |
|
880 | - { |
|
881 | - $this->_raw_value = $this->_normalization_strategy->unnormalize($value); |
|
882 | - } |
|
883 | - |
|
884 | - |
|
885 | - /** |
|
886 | - * Sets the HTML label text after it has already been defined |
|
887 | - * |
|
888 | - * @param string $label |
|
889 | - * @return void |
|
890 | - */ |
|
891 | - public function set_html_label_text($label) |
|
892 | - { |
|
893 | - $this->_html_label_text = $label; |
|
894 | - } |
|
895 | - |
|
896 | - |
|
897 | - /** |
|
898 | - * Sets whether or not this field is required, and adjusts the validation strategy. |
|
899 | - * If you want to use the EE_Conditionally_Required_Validation_Strategy, |
|
900 | - * please add it as a validation strategy using add_validation_strategy as normal |
|
901 | - * |
|
902 | - * @param boolean $required boolean |
|
903 | - * @param null $required_text |
|
904 | - */ |
|
905 | - public function set_required($required = true, $required_text = null) |
|
906 | - { |
|
907 | - $required = filter_var($required, FILTER_VALIDATE_BOOLEAN); |
|
908 | - // whether $required is a string or a boolean, we want to add a required validation strategy |
|
909 | - if ($required) { |
|
910 | - $this->_add_validation_strategy(new EE_Required_Validation_Strategy($required_text)); |
|
911 | - } else { |
|
912 | - $this->remove_validation_strategy('EE_Required_Validation_Strategy'); |
|
913 | - } |
|
914 | - $this->_required = $required; |
|
915 | - } |
|
916 | - |
|
917 | - |
|
918 | - /** |
|
919 | - * Returns whether or not this field is required |
|
920 | - * |
|
921 | - * @return boolean |
|
922 | - */ |
|
923 | - public function required() |
|
924 | - { |
|
925 | - return $this->_required; |
|
926 | - } |
|
927 | - |
|
928 | - |
|
929 | - /** |
|
930 | - * @param string $required_css_class |
|
931 | - */ |
|
932 | - public function set_required_css_class($required_css_class) |
|
933 | - { |
|
934 | - $this->_required_css_class = $required_css_class; |
|
935 | - } |
|
936 | - |
|
937 | - |
|
938 | - /** |
|
939 | - * @return string |
|
940 | - */ |
|
941 | - public function required_css_class() |
|
942 | - { |
|
943 | - return $this->_required_css_class; |
|
944 | - } |
|
945 | - |
|
946 | - |
|
947 | - /** |
|
948 | - * @param bool $add_required |
|
949 | - * @return string |
|
950 | - */ |
|
951 | - public function html_class($add_required = false) |
|
952 | - { |
|
953 | - return $add_required && $this->required() |
|
954 | - ? $this->required_css_class() . ' ' . $this->_html_class |
|
955 | - : $this->_html_class; |
|
956 | - } |
|
957 | - |
|
958 | - |
|
959 | - /** |
|
960 | - * Sets the help text, in case |
|
961 | - * |
|
962 | - * @param string $text |
|
963 | - */ |
|
964 | - public function set_html_help_text($text) |
|
965 | - { |
|
966 | - $this->_html_help_text = $text; |
|
967 | - } |
|
968 | - |
|
969 | - |
|
970 | - /** |
|
971 | - * Uses the sensitive data removal strategy to remove the sensitive data from this |
|
972 | - * input. If there is any kind of sensitive data removal on this input, we clear |
|
973 | - * out the raw value completely |
|
974 | - * |
|
975 | - * @return void |
|
976 | - */ |
|
977 | - public function clean_sensitive_data() |
|
978 | - { |
|
979 | - // if we do ANY kind of sensitive data removal on this, then just clear out the raw value |
|
980 | - // if we need more logic than this we'll make a strategy for it |
|
981 | - if ( |
|
982 | - $this->_sensitive_data_removal_strategy |
|
983 | - && ! $this->_sensitive_data_removal_strategy instanceof EE_No_Sensitive_Data_Removal |
|
984 | - ) { |
|
985 | - $this->_set_raw_value(null); |
|
986 | - } |
|
987 | - // and clean the normalized value according to the appropriate strategy |
|
988 | - $this->_set_normalized_value( |
|
989 | - $this->get_sensitive_data_removal_strategy()->remove_sensitive_data( |
|
990 | - $this->_normalized_value |
|
991 | - ) |
|
992 | - ); |
|
993 | - } |
|
994 | - |
|
995 | - |
|
996 | - /** |
|
997 | - * @param bool $primary |
|
998 | - * @param string $button_size |
|
999 | - * @param string $other_attributes |
|
1000 | - */ |
|
1001 | - public function set_button_css_attributes($primary = true, $button_size = '', $other_attributes = '') |
|
1002 | - { |
|
1003 | - $button_css_attributes = 'button'; |
|
1004 | - $button_css_attributes .= $primary === true |
|
1005 | - ? ' button--primary' |
|
1006 | - : ' button--secondary'; |
|
1007 | - switch ($button_size) { |
|
1008 | - case 'xs': |
|
1009 | - case 'extra-small': |
|
1010 | - $button_css_attributes .= ' button-xs'; |
|
1011 | - break; |
|
1012 | - case 'sm': |
|
1013 | - case 'small': |
|
1014 | - $button_css_attributes .= ' button-sm'; |
|
1015 | - break; |
|
1016 | - case 'lg': |
|
1017 | - case 'large': |
|
1018 | - $button_css_attributes .= ' button-lg'; |
|
1019 | - break; |
|
1020 | - case 'block': |
|
1021 | - $button_css_attributes .= ' button-block'; |
|
1022 | - break; |
|
1023 | - case 'md': |
|
1024 | - case 'medium': |
|
1025 | - default: |
|
1026 | - $button_css_attributes .= ''; |
|
1027 | - } |
|
1028 | - $this->_button_css_attributes .= ! empty($other_attributes) |
|
1029 | - ? $button_css_attributes . ' ' . $other_attributes |
|
1030 | - : $button_css_attributes; |
|
1031 | - } |
|
1032 | - |
|
1033 | - |
|
1034 | - /** |
|
1035 | - * @return string |
|
1036 | - */ |
|
1037 | - public function button_css_attributes() |
|
1038 | - { |
|
1039 | - if (empty($this->_button_css_attributes)) { |
|
1040 | - $this->set_button_css_attributes(); |
|
1041 | - } |
|
1042 | - return $this->_button_css_attributes; |
|
1043 | - } |
|
1044 | - |
|
1045 | - |
|
1046 | - /** |
|
1047 | - * find_form_data_for_this_section |
|
1048 | - * using this section's name and its parents, finds the value of the form data that corresponds to it. |
|
1049 | - * For example, if this form section's HTML name is my_form[subform][form_input_1], |
|
1050 | - * then it's value should be in request at request['my_form']['subform']['form_input_1']. |
|
1051 | - * (If that doesn't exist, we also check for this subsection's name |
|
1052 | - * at the TOP LEVEL of the request data. Eg request['form_input_1'].) |
|
1053 | - * This function finds its value in the form. |
|
1054 | - * |
|
1055 | - * @param array $req_data |
|
1056 | - * @return mixed whatever the raw value of this form section is in the request data |
|
1057 | - * @throws EE_Error |
|
1058 | - */ |
|
1059 | - public function find_form_data_for_this_section($req_data) |
|
1060 | - { |
|
1061 | - $name_parts = $this->getInputNameParts(); |
|
1062 | - // now get the value for the input |
|
1063 | - $value = $this->findRequestForSectionUsingNameParts($name_parts, $req_data); |
|
1064 | - // check if this thing's name is at the TOP level of the request data |
|
1065 | - if ($value === null && isset($req_data[ $this->name() ])) { |
|
1066 | - $value = $req_data[ $this->name() ]; |
|
1067 | - } |
|
1068 | - return $value; |
|
1069 | - } |
|
1070 | - |
|
1071 | - |
|
1072 | - /** |
|
1073 | - * If this input's name is something like "foo[bar][baz]" |
|
1074 | - * returns an array like `array('foo','bar',baz')` |
|
1075 | - * |
|
1076 | - * @return array |
|
1077 | - * @throws EE_Error |
|
1078 | - */ |
|
1079 | - protected function getInputNameParts() |
|
1080 | - { |
|
1081 | - // break up the html name by "[]" |
|
1082 | - if (strpos($this->html_name(), '[') !== false) { |
|
1083 | - $before_any_brackets = substr($this->html_name(), 0, strpos($this->html_name(), '[')); |
|
1084 | - } else { |
|
1085 | - $before_any_brackets = $this->html_name(); |
|
1086 | - } |
|
1087 | - // grab all of the segments |
|
1088 | - preg_match_all('~\[([^]]*)\]~', $this->html_name(), $matches); |
|
1089 | - if (isset($matches[1]) && is_array($matches[1])) { |
|
1090 | - $name_parts = $matches[1]; |
|
1091 | - array_unshift($name_parts, $before_any_brackets); |
|
1092 | - } else { |
|
1093 | - $name_parts = [$before_any_brackets]; |
|
1094 | - } |
|
1095 | - return $name_parts; |
|
1096 | - } |
|
1097 | - |
|
1098 | - |
|
1099 | - /** |
|
1100 | - * @param array $html_name_parts |
|
1101 | - * @param array $req_data |
|
1102 | - * @return array | NULL |
|
1103 | - */ |
|
1104 | - public function findRequestForSectionUsingNameParts($html_name_parts, $req_data) |
|
1105 | - { |
|
1106 | - $first_part_to_consider = array_shift($html_name_parts); |
|
1107 | - if (isset($req_data[ $first_part_to_consider ])) { |
|
1108 | - if (empty($html_name_parts)) { |
|
1109 | - return $req_data[ $first_part_to_consider ]; |
|
1110 | - } else { |
|
1111 | - return $this->findRequestForSectionUsingNameParts( |
|
1112 | - $html_name_parts, |
|
1113 | - $req_data[ $first_part_to_consider ] |
|
1114 | - ); |
|
1115 | - } |
|
1116 | - } else { |
|
1117 | - return null; |
|
1118 | - } |
|
1119 | - } |
|
1120 | - |
|
1121 | - |
|
1122 | - /** |
|
1123 | - * Checks if this form input's data is in the request data |
|
1124 | - * |
|
1125 | - * @param array $req_data |
|
1126 | - * @return boolean |
|
1127 | - * @throws EE_Error |
|
1128 | - */ |
|
1129 | - public function form_data_present_in($req_data = null) |
|
1130 | - { |
|
1131 | - if ($req_data === null) { |
|
1132 | - /** @var RequestInterface $request */ |
|
1133 | - $request = LoaderFactory::getLoader()->getShared(RequestInterface::class); |
|
1134 | - $req_data = $request->postParams(); |
|
1135 | - } |
|
1136 | - $checked_value = $this->find_form_data_for_this_section($req_data); |
|
1137 | - if ($checked_value !== null) { |
|
1138 | - return true; |
|
1139 | - } else { |
|
1140 | - return false; |
|
1141 | - } |
|
1142 | - } |
|
1143 | - |
|
1144 | - |
|
1145 | - /** |
|
1146 | - * Overrides parent to add js data from validation and display strategies |
|
1147 | - * |
|
1148 | - * @param array $form_other_js_data |
|
1149 | - * @return array |
|
1150 | - */ |
|
1151 | - public function get_other_js_data($form_other_js_data = []) |
|
1152 | - { |
|
1153 | - return $this->get_other_js_data_from_strategies($form_other_js_data); |
|
1154 | - } |
|
1155 | - |
|
1156 | - |
|
1157 | - /** |
|
1158 | - * Gets other JS data for localization from this input's strategies, like |
|
1159 | - * the validation strategies and the display strategy |
|
1160 | - * |
|
1161 | - * @param array $form_other_js_data |
|
1162 | - * @return array |
|
1163 | - */ |
|
1164 | - public function get_other_js_data_from_strategies($form_other_js_data = []) |
|
1165 | - { |
|
1166 | - $form_other_js_data = $this->get_display_strategy()->get_other_js_data($form_other_js_data); |
|
1167 | - foreach ($this->get_validation_strategies() as $validation_strategy) { |
|
1168 | - $form_other_js_data = $validation_strategy->get_other_js_data($form_other_js_data); |
|
1169 | - } |
|
1170 | - return $form_other_js_data; |
|
1171 | - } |
|
1172 | - |
|
1173 | - |
|
1174 | - /** |
|
1175 | - * Override parent because we want to give our strategies an opportunity to enqueue some js and css |
|
1176 | - * |
|
1177 | - * @return void |
|
1178 | - */ |
|
1179 | - public function enqueue_js() |
|
1180 | - { |
|
1181 | - // ask our display strategy and validation strategies if they have js to enqueue |
|
1182 | - $this->enqueue_js_from_strategies(); |
|
1183 | - } |
|
1184 | - |
|
1185 | - |
|
1186 | - /** |
|
1187 | - * Tells strategies when its ok to enqueue their js and css |
|
1188 | - * |
|
1189 | - * @return void |
|
1190 | - */ |
|
1191 | - public function enqueue_js_from_strategies() |
|
1192 | - { |
|
1193 | - $this->get_display_strategy()->enqueue_js(); |
|
1194 | - foreach ($this->get_validation_strategies() as $validation_strategy) { |
|
1195 | - $validation_strategy->enqueue_js(); |
|
1196 | - } |
|
1197 | - } |
|
1198 | - |
|
1199 | - |
|
1200 | - /** |
|
1201 | - * Gets the default value set on the input (not the current value, which may have been |
|
1202 | - * changed because of a form submission). If no default was set, this us null. |
|
1203 | - * |
|
1204 | - * @return mixed |
|
1205 | - */ |
|
1206 | - public function get_default() |
|
1207 | - { |
|
1208 | - return $this->_default; |
|
1209 | - } |
|
1210 | - |
|
1211 | - |
|
1212 | - /** |
|
1213 | - * Makes this input disabled. That means it will have the HTML attribute 'disabled="disabled"', |
|
1214 | - * and server-side if any input was received it will be ignored |
|
1215 | - */ |
|
1216 | - public function disable($disable = true) |
|
1217 | - { |
|
1218 | - $disabled_attribute = ' disabled="disabled"'; |
|
1219 | - $this->disabled = filter_var($disable, FILTER_VALIDATE_BOOLEAN); |
|
1220 | - if ($this->disabled) { |
|
1221 | - if (strpos($this->_other_html_attributes, $disabled_attribute) === false) { |
|
1222 | - $this->_other_html_attributes .= $disabled_attribute; |
|
1223 | - } |
|
1224 | - $this->_set_normalized_value($this->get_default()); |
|
1225 | - } else { |
|
1226 | - $this->_other_html_attributes = str_replace($disabled_attribute, '', $this->_other_html_attributes); |
|
1227 | - } |
|
1228 | - } |
|
1229 | - |
|
1230 | - |
|
1231 | - /** |
|
1232 | - * Returns whether this input is currently disabled. |
|
1233 | - * |
|
1234 | - * @return bool |
|
1235 | - */ |
|
1236 | - public function isDisabled() |
|
1237 | - { |
|
1238 | - return $this->disabled; |
|
1239 | - } |
|
17 | + /** |
|
18 | + * the input's name attribute |
|
19 | + * |
|
20 | + * @var string |
|
21 | + */ |
|
22 | + protected $_html_name; |
|
23 | + |
|
24 | + /** |
|
25 | + * id for the html label tag |
|
26 | + * |
|
27 | + * @var string |
|
28 | + */ |
|
29 | + protected $_html_label_id; |
|
30 | + |
|
31 | + /** |
|
32 | + * class for teh html label tag |
|
33 | + * |
|
34 | + * @var string |
|
35 | + */ |
|
36 | + protected $_html_label_class; |
|
37 | + |
|
38 | + /** |
|
39 | + * style for teh html label tag |
|
40 | + * |
|
41 | + * @var string |
|
42 | + */ |
|
43 | + protected $_html_label_style; |
|
44 | + |
|
45 | + /** |
|
46 | + * text to be placed in the html label |
|
47 | + * |
|
48 | + * @var string |
|
49 | + */ |
|
50 | + protected $_html_label_text; |
|
51 | + |
|
52 | + /** |
|
53 | + * the full html label. If used, all other html_label_* properties are invalid |
|
54 | + * |
|
55 | + * @var string |
|
56 | + */ |
|
57 | + protected $_html_label; |
|
58 | + |
|
59 | + /** |
|
60 | + * HTML to use for help text (normally placed below form input), in a span which normally |
|
61 | + * has a class of 'description' |
|
62 | + * |
|
63 | + * @var string |
|
64 | + */ |
|
65 | + protected $_html_help_text; |
|
66 | + |
|
67 | + /** |
|
68 | + * CSS classes for displaying the help span |
|
69 | + * |
|
70 | + * @var string |
|
71 | + */ |
|
72 | + protected $_html_help_class = 'description'; |
|
73 | + |
|
74 | + /** |
|
75 | + * CSS to put in the style attribute on the help span |
|
76 | + * |
|
77 | + * @var string |
|
78 | + */ |
|
79 | + protected $_html_help_style; |
|
80 | + |
|
81 | + /** |
|
82 | + * Stores whether or not this input's response is required. |
|
83 | + * Because certain styling elements may also want to know that this |
|
84 | + * input is required etc. |
|
85 | + * |
|
86 | + * @var boolean |
|
87 | + */ |
|
88 | + protected $_required; |
|
89 | + |
|
90 | + /** |
|
91 | + * css class added to required inputs |
|
92 | + * |
|
93 | + * @var string |
|
94 | + */ |
|
95 | + protected $_required_css_class = 'ee-required'; |
|
96 | + |
|
97 | + /** |
|
98 | + * css styles applied to button type inputs |
|
99 | + * |
|
100 | + * @var string |
|
101 | + */ |
|
102 | + protected $_button_css_attributes; |
|
103 | + |
|
104 | + /** |
|
105 | + * The raw post data submitted for this |
|
106 | + * Generally unsafe for usage in client code |
|
107 | + * |
|
108 | + * @var mixed string or array |
|
109 | + */ |
|
110 | + protected $_raw_value; |
|
111 | + |
|
112 | + /** |
|
113 | + * Value normalized according to the input's normalization strategy. |
|
114 | + * The normalization strategy dictates whether this is a string, int, float, |
|
115 | + * boolean, or array of any of those. |
|
116 | + * |
|
117 | + * @var mixed |
|
118 | + */ |
|
119 | + protected $_normalized_value; |
|
120 | + |
|
121 | + |
|
122 | + /** |
|
123 | + * Normalized default value either initially set on the input, or provided by calling |
|
124 | + * set_default(). |
|
125 | + * |
|
126 | + * @var mixed |
|
127 | + */ |
|
128 | + protected $_default; |
|
129 | + |
|
130 | + /** |
|
131 | + * Strategy used for displaying this field. |
|
132 | + * Child classes must use _get_display_strategy to access it. |
|
133 | + * |
|
134 | + * @var EE_Display_Strategy_Base |
|
135 | + */ |
|
136 | + private $_display_strategy; |
|
137 | + |
|
138 | + /** |
|
139 | + * Gets all the validation strategies used on this field |
|
140 | + * |
|
141 | + * @var EE_Validation_Strategy_Base[] |
|
142 | + */ |
|
143 | + private $_validation_strategies = []; |
|
144 | + |
|
145 | + /** |
|
146 | + * The normalization strategy for this field |
|
147 | + * |
|
148 | + * @var EE_Normalization_Strategy_Base |
|
149 | + */ |
|
150 | + private $_normalization_strategy; |
|
151 | + |
|
152 | + /** |
|
153 | + * Strategy for removing sensitive data after we're done with the form input |
|
154 | + * |
|
155 | + * @var EE_Sensitive_Data_Removal_Base |
|
156 | + */ |
|
157 | + protected $_sensitive_data_removal_strategy; |
|
158 | + |
|
159 | + /** |
|
160 | + * Whether this input has been disabled or not. |
|
161 | + * If it's disabled while rendering, an extra hidden input is added that indicates it has been knowingly disabled. |
|
162 | + * (Client-side code that wants to dynamically disable it must also add this hidden input). |
|
163 | + * When the form is submitted, if the input is disabled in the PHP form section, then input is ignored. |
|
164 | + * If the input is missing from the request data but the hidden input indicating the input is disabled, then the |
|
165 | + * input is again ignored. |
|
166 | + * |
|
167 | + * @var boolean |
|
168 | + */ |
|
169 | + protected $disabled = false; |
|
170 | + |
|
171 | + |
|
172 | + protected bool $_no_label = false; // if true, then no hrml label will be displayed for this input |
|
173 | + |
|
174 | + |
|
175 | + /** |
|
176 | + * @param array $input_args { |
|
177 | + * @type string $html_name the html name for the input |
|
178 | + * @type string $html_label_id the id attribute to give to the html label tag |
|
179 | + * @type string $html_label_class the class attribute to give to the html label tag |
|
180 | + * @type string $html_label_style the style attribute to give ot teh label tag |
|
181 | + * @type string $html_label_text the text to put in the label tag |
|
182 | + * @type string $html_label the full html label. If used, |
|
183 | + * all other html_label_* args are invalid |
|
184 | + * @type string $html_help_text text to put in help element |
|
185 | + * @type string $html_help_style style attribute to give to teh help element |
|
186 | + * @type string $html_help_class class attribute to give to the help element |
|
187 | + * @type string $default default value NORMALIZED (eg, if providing the default |
|
188 | + * for a Yes_No_Input, you should provide TRUE or FALSE, not |
|
189 | + * '1' or '0') |
|
190 | + * @type EE_Display_Strategy_Base $display strategy |
|
191 | + * @type EE_Normalization_Strategy_Base $normalization_strategy |
|
192 | + * @type EE_Validation_Strategy_Base[] $validation_strategies |
|
193 | + * @type boolean $ignore_input special argument which can be used to avoid adding any |
|
194 | + * validation strategies, and sets the normalization |
|
195 | + * strategy to the Null normalization. This is good when you |
|
196 | + * want the input to be totally ignored server-side (like |
|
197 | + * when using React.js form inputs) |
|
198 | + * } |
|
199 | + */ |
|
200 | + public function __construct($input_args = []) |
|
201 | + { |
|
202 | + $input_args = (array) apply_filters('FHEE__EE_Form_Input_Base___construct__input_args', $input_args, $this); |
|
203 | + // the following properties must be cast as arrays |
|
204 | + if (isset($input_args['validation_strategies'])) { |
|
205 | + foreach ((array) $input_args['validation_strategies'] as $validation_strategy) { |
|
206 | + if ($validation_strategy instanceof EE_Validation_Strategy_Base && empty($input_args['ignore_input'])) { |
|
207 | + $this->_validation_strategies[ get_class($validation_strategy) ] = $validation_strategy; |
|
208 | + } |
|
209 | + } |
|
210 | + unset($input_args['validation_strategies']); |
|
211 | + } |
|
212 | + if (isset($input_args['ignore_input'])) { |
|
213 | + $this->_validation_strategies = []; |
|
214 | + } |
|
215 | + // loop thru incoming options |
|
216 | + foreach ($input_args as $key => $value) { |
|
217 | + if ($key === 'disabled') { |
|
218 | + $this->disable($value); |
|
219 | + continue; |
|
220 | + } |
|
221 | + // add underscore to $key to match property names |
|
222 | + $_key = '_' . $key; |
|
223 | + if (property_exists($this, $_key)) { |
|
224 | + $this->{$_key} = $value; |
|
225 | + } |
|
226 | + } |
|
227 | + // ensure that "required" is set correctly |
|
228 | + $this->set_required( |
|
229 | + $this->_required, |
|
230 | + $input_args['required_validation_error_message'] ?? null |
|
231 | + ); |
|
232 | + // $this->_html_name_specified = isset( $input_args['html_name'] ) ? TRUE : FALSE; |
|
233 | + $this->_display_strategy->_construct_finalize($this); |
|
234 | + foreach ($this->_validation_strategies as $validation_strategy) { |
|
235 | + $validation_strategy->_construct_finalize($this); |
|
236 | + } |
|
237 | + if (isset($input_args['ignore_input'])) { |
|
238 | + $this->_normalization_strategy = new EE_Null_Normalization(); |
|
239 | + } |
|
240 | + if (! $this->_normalization_strategy) { |
|
241 | + $this->_normalization_strategy = new EE_Text_Normalization(); |
|
242 | + } |
|
243 | + $this->_normalization_strategy->_construct_finalize($this); |
|
244 | + // at least we can use the normalization strategy to populate the default |
|
245 | + if (isset($input_args['default'])) { |
|
246 | + $this->set_default($input_args['default']); |
|
247 | + unset($input_args['default']); |
|
248 | + } |
|
249 | + if (! $this->_sensitive_data_removal_strategy) { |
|
250 | + $this->_sensitive_data_removal_strategy = new EE_No_Sensitive_Data_Removal(); |
|
251 | + } |
|
252 | + $this->_sensitive_data_removal_strategy->_construct_finalize($this); |
|
253 | + parent::__construct($input_args); |
|
254 | + } |
|
255 | + |
|
256 | + |
|
257 | + /** |
|
258 | + * Sets the html_name to its default value, if none was specified in teh constructor. |
|
259 | + * Calculation involves using the name and the parent's html_name |
|
260 | + * |
|
261 | + * @throws EE_Error |
|
262 | + */ |
|
263 | + protected function _set_default_html_name_if_empty() |
|
264 | + { |
|
265 | + if (! $this->_html_name) { |
|
266 | + $this->_html_name = $this->name(); |
|
267 | + if ($this->_parent_section && $this->_parent_section instanceof EE_Form_Section_Proper) { |
|
268 | + $this->_html_name = $this->_parent_section->html_name_prefix() . "[{$this->name()}]"; |
|
269 | + } |
|
270 | + } |
|
271 | + } |
|
272 | + |
|
273 | + |
|
274 | + /** |
|
275 | + * @param $parent_form_section |
|
276 | + * @param $name |
|
277 | + * @throws EE_Error |
|
278 | + */ |
|
279 | + public function _construct_finalize($parent_form_section, $name) |
|
280 | + { |
|
281 | + parent::_construct_finalize($parent_form_section, $name); |
|
282 | + if ($this->_html_label === null && $this->_html_label_text === null && ! $this->_no_label) { |
|
283 | + $this->_html_label_text = ucwords(str_replace("_", " ", $name)); |
|
284 | + } |
|
285 | + do_action('AHEE__EE_Form_Input_Base___construct_finalize__end', $this, $parent_form_section, $name); |
|
286 | + } |
|
287 | + |
|
288 | + |
|
289 | + /** |
|
290 | + * Returns the strategy for displaying this form input. If none is set, throws an exception. |
|
291 | + * |
|
292 | + * @return EE_Display_Strategy_Base |
|
293 | + * @throws EE_Error |
|
294 | + */ |
|
295 | + protected function _get_display_strategy() |
|
296 | + { |
|
297 | + $this->ensure_construct_finalized_called(); |
|
298 | + if (! $this->_display_strategy || ! $this->_display_strategy instanceof EE_Display_Strategy_Base) { |
|
299 | + throw new EE_Error( |
|
300 | + sprintf( |
|
301 | + esc_html__( |
|
302 | + "Cannot get display strategy for form input with name %s and id %s, because it has not been set in the constructor", |
|
303 | + "event_espresso" |
|
304 | + ), |
|
305 | + $this->html_name(), |
|
306 | + $this->html_id() |
|
307 | + ) |
|
308 | + ); |
|
309 | + } else { |
|
310 | + return $this->_display_strategy; |
|
311 | + } |
|
312 | + } |
|
313 | + |
|
314 | + |
|
315 | + /** |
|
316 | + * Sets the display strategy. |
|
317 | + * |
|
318 | + * @param EE_Display_Strategy_Base $strategy |
|
319 | + */ |
|
320 | + protected function _set_display_strategy(EE_Display_Strategy_Base $strategy) |
|
321 | + { |
|
322 | + $this->_display_strategy = $strategy; |
|
323 | + } |
|
324 | + |
|
325 | + |
|
326 | + /** |
|
327 | + * Sets the sanitization strategy |
|
328 | + * |
|
329 | + * @param EE_Normalization_Strategy_Base $strategy |
|
330 | + */ |
|
331 | + protected function _set_normalization_strategy(EE_Normalization_Strategy_Base $strategy) |
|
332 | + { |
|
333 | + $this->_normalization_strategy = $strategy; |
|
334 | + } |
|
335 | + |
|
336 | + |
|
337 | + /** |
|
338 | + * Gets sensitive_data_removal_strategy |
|
339 | + * |
|
340 | + * @return EE_Sensitive_Data_Removal_Base |
|
341 | + */ |
|
342 | + public function get_sensitive_data_removal_strategy() |
|
343 | + { |
|
344 | + return $this->_sensitive_data_removal_strategy; |
|
345 | + } |
|
346 | + |
|
347 | + |
|
348 | + /** |
|
349 | + * Sets sensitive_data_removal_strategy |
|
350 | + * |
|
351 | + * @param EE_Sensitive_Data_Removal_Base $sensitive_data_removal_strategy |
|
352 | + * @return void |
|
353 | + */ |
|
354 | + public function set_sensitive_data_removal_strategy($sensitive_data_removal_strategy) |
|
355 | + { |
|
356 | + $this->_sensitive_data_removal_strategy = $sensitive_data_removal_strategy; |
|
357 | + } |
|
358 | + |
|
359 | + |
|
360 | + /** |
|
361 | + * Gets the display strategy for this input |
|
362 | + * |
|
363 | + * @return EE_Display_Strategy_Base |
|
364 | + */ |
|
365 | + public function get_display_strategy() |
|
366 | + { |
|
367 | + return $this->_display_strategy; |
|
368 | + } |
|
369 | + |
|
370 | + |
|
371 | + /** |
|
372 | + * Overwrites the display strategy |
|
373 | + * |
|
374 | + * @param EE_Display_Strategy_Base $display_strategy |
|
375 | + */ |
|
376 | + public function set_display_strategy($display_strategy) |
|
377 | + { |
|
378 | + $this->_display_strategy = $display_strategy; |
|
379 | + $this->_display_strategy->_construct_finalize($this); |
|
380 | + } |
|
381 | + |
|
382 | + |
|
383 | + /** |
|
384 | + * Gets the normalization strategy set on this input |
|
385 | + * |
|
386 | + * @return EE_Normalization_Strategy_Base |
|
387 | + */ |
|
388 | + public function get_normalization_strategy() |
|
389 | + { |
|
390 | + return $this->_normalization_strategy; |
|
391 | + } |
|
392 | + |
|
393 | + |
|
394 | + /** |
|
395 | + * Overwrites the normalization strategy |
|
396 | + * |
|
397 | + * @param EE_Normalization_Strategy_Base $normalization_strategy |
|
398 | + */ |
|
399 | + public function set_normalization_strategy($normalization_strategy) |
|
400 | + { |
|
401 | + $this->_normalization_strategy = $normalization_strategy; |
|
402 | + $this->_normalization_strategy->_construct_finalize($this); |
|
403 | + } |
|
404 | + |
|
405 | + |
|
406 | + /** |
|
407 | + * Returns all teh validation strategies which apply to this field, numerically indexed |
|
408 | + * |
|
409 | + * @return EE_Validation_Strategy_Base[] |
|
410 | + */ |
|
411 | + public function get_validation_strategies() |
|
412 | + { |
|
413 | + return $this->_validation_strategies; |
|
414 | + } |
|
415 | + |
|
416 | + |
|
417 | + /** |
|
418 | + * Adds this strategy to the field so it will be used in both JS validation and server-side validation |
|
419 | + * |
|
420 | + * @param EE_Validation_Strategy_Base $validation_strategy |
|
421 | + * @return void |
|
422 | + */ |
|
423 | + protected function _add_validation_strategy(EE_Validation_Strategy_Base $validation_strategy) |
|
424 | + { |
|
425 | + $validation_strategy->_construct_finalize($this); |
|
426 | + $this->_validation_strategies[] = $validation_strategy; |
|
427 | + } |
|
428 | + |
|
429 | + |
|
430 | + /** |
|
431 | + * Adds a new validation strategy onto the form input |
|
432 | + * |
|
433 | + * @param EE_Validation_Strategy_Base $validation_strategy |
|
434 | + * @return void |
|
435 | + */ |
|
436 | + public function add_validation_strategy(EE_Validation_Strategy_Base $validation_strategy) |
|
437 | + { |
|
438 | + $this->_add_validation_strategy($validation_strategy); |
|
439 | + } |
|
440 | + |
|
441 | + |
|
442 | + /** |
|
443 | + * The classname of the validation strategy to remove |
|
444 | + * |
|
445 | + * @param string $validation_strategy_classname |
|
446 | + */ |
|
447 | + public function remove_validation_strategy($validation_strategy_classname) |
|
448 | + { |
|
449 | + foreach ($this->_validation_strategies as $key => $validation_strategy) { |
|
450 | + if ( |
|
451 | + $validation_strategy instanceof $validation_strategy_classname |
|
452 | + || is_subclass_of($validation_strategy, $validation_strategy_classname) |
|
453 | + ) { |
|
454 | + unset($this->_validation_strategies[ $key ]); |
|
455 | + } |
|
456 | + } |
|
457 | + } |
|
458 | + |
|
459 | + |
|
460 | + /** |
|
461 | + * returns true if input employs any of the validation strategy defined by the supplied array of classnames |
|
462 | + * |
|
463 | + * @param array $validation_strategy_classnames |
|
464 | + * @return bool |
|
465 | + */ |
|
466 | + public function has_validation_strategy($validation_strategy_classnames) |
|
467 | + { |
|
468 | + $validation_strategy_classnames = is_array($validation_strategy_classnames) |
|
469 | + ? $validation_strategy_classnames |
|
470 | + : [$validation_strategy_classnames]; |
|
471 | + foreach ($this->_validation_strategies as $key => $validation_strategy) { |
|
472 | + if (in_array($key, $validation_strategy_classnames)) { |
|
473 | + return true; |
|
474 | + } |
|
475 | + } |
|
476 | + return false; |
|
477 | + } |
|
478 | + |
|
479 | + |
|
480 | + /** |
|
481 | + * Gets the HTML |
|
482 | + * |
|
483 | + * @return string |
|
484 | + */ |
|
485 | + public function get_html() |
|
486 | + { |
|
487 | + return $this->_parent_section->get_html_for_input($this); |
|
488 | + } |
|
489 | + |
|
490 | + |
|
491 | + /** |
|
492 | + * Gets the HTML for the input itself (no label or errors) according to the |
|
493 | + * input's display strategy |
|
494 | + * Makes sure the JS and CSS are enqueued for it |
|
495 | + * |
|
496 | + * @return string |
|
497 | + * @throws EE_Error |
|
498 | + */ |
|
499 | + public function get_html_for_input() |
|
500 | + { |
|
501 | + return $this->_form_html_filter |
|
502 | + ? $this->_form_html_filter->filterHtml( |
|
503 | + $this->_get_display_strategy()->display(), |
|
504 | + $this |
|
505 | + ) |
|
506 | + : $this->_get_display_strategy()->display(); |
|
507 | + } |
|
508 | + |
|
509 | + |
|
510 | + /** |
|
511 | + * @return string |
|
512 | + */ |
|
513 | + public function html_other_attributes() |
|
514 | + { |
|
515 | + EE_Error::doing_it_wrong( |
|
516 | + __METHOD__, |
|
517 | + sprintf( |
|
518 | + esc_html__( |
|
519 | + 'This method is no longer in use. You should replace it by %s', |
|
520 | + 'event_espresso' |
|
521 | + ), |
|
522 | + 'EE_Form_Section_Base::other_html_attributes()' |
|
523 | + ), |
|
524 | + '4.10.2.p' |
|
525 | + ); |
|
526 | + |
|
527 | + return $this->other_html_attributes(); |
|
528 | + } |
|
529 | + |
|
530 | + |
|
531 | + /** |
|
532 | + * @param string $html_other_attributes |
|
533 | + */ |
|
534 | + public function set_html_other_attributes($html_other_attributes) |
|
535 | + { |
|
536 | + EE_Error::doing_it_wrong( |
|
537 | + __METHOD__, |
|
538 | + sprintf( |
|
539 | + esc_html__( |
|
540 | + 'This method is no longer in use. You should replace it by %s', |
|
541 | + 'event_espresso' |
|
542 | + ), |
|
543 | + 'EE_Form_Section_Base::set_other_html_attributes()' |
|
544 | + ), |
|
545 | + '4.10.2.p' |
|
546 | + ); |
|
547 | + |
|
548 | + $this->set_other_html_attributes($html_other_attributes); |
|
549 | + } |
|
550 | + |
|
551 | + |
|
552 | + /** |
|
553 | + * Gets the HTML for displaying the label for this form input |
|
554 | + * according to the form section's layout strategy |
|
555 | + * |
|
556 | + * @return string |
|
557 | + */ |
|
558 | + public function get_html_for_label() |
|
559 | + { |
|
560 | + return $this->_parent_section->get_layout_strategy()->display_label($this); |
|
561 | + } |
|
562 | + |
|
563 | + |
|
564 | + /** |
|
565 | + * Gets the HTML for displaying the errors section for this form input |
|
566 | + * according to the form section's layout strategy |
|
567 | + * |
|
568 | + * @return string |
|
569 | + */ |
|
570 | + public function get_html_for_errors() |
|
571 | + { |
|
572 | + return $this->_parent_section->get_layout_strategy()->display_errors($this); |
|
573 | + } |
|
574 | + |
|
575 | + |
|
576 | + /** |
|
577 | + * Gets the HTML for displaying the help text for this form input |
|
578 | + * according to the form section's layout strategy |
|
579 | + * |
|
580 | + * @return string |
|
581 | + */ |
|
582 | + public function get_html_for_help() |
|
583 | + { |
|
584 | + return $this->_parent_section->get_layout_strategy()->display_help_text($this); |
|
585 | + } |
|
586 | + |
|
587 | + |
|
588 | + /** |
|
589 | + * Validates the input's sanitized value (assumes _sanitize() has already been called) |
|
590 | + * and returns whether or not the form input's submitted value is value |
|
591 | + * |
|
592 | + * @return boolean |
|
593 | + */ |
|
594 | + protected function _validate() |
|
595 | + { |
|
596 | + if ($this->isDisabled()) { |
|
597 | + return true; |
|
598 | + } |
|
599 | + foreach ($this->_validation_strategies as $validation_strategy) { |
|
600 | + if ($validation_strategy instanceof EE_Validation_Strategy_Base) { |
|
601 | + try { |
|
602 | + $validation_strategy->validate($this->normalized_value()); |
|
603 | + } catch (EE_Validation_Error $e) { |
|
604 | + $this->add_validation_error($e); |
|
605 | + } |
|
606 | + } |
|
607 | + } |
|
608 | + if ($this->get_validation_errors()) { |
|
609 | + return false; |
|
610 | + } else { |
|
611 | + return true; |
|
612 | + } |
|
613 | + } |
|
614 | + |
|
615 | + |
|
616 | + /** |
|
617 | + * Performs basic sanitization on this value. But what sanitization can be performed anyways? |
|
618 | + * This value MIGHT be allowed to have tags, so we can't really remove them. |
|
619 | + * |
|
620 | + * @param string $value |
|
621 | + * @return null|string |
|
622 | + */ |
|
623 | + protected function _sanitize($value) |
|
624 | + { |
|
625 | + return $value !== null |
|
626 | + ? stripslashes(html_entity_decode(trim((string) $value))) |
|
627 | + : null; |
|
628 | + } |
|
629 | + |
|
630 | + |
|
631 | + /** |
|
632 | + * Picks out the form value that relates to this form input, |
|
633 | + * and stores it as the sanitized value on the form input, and sets the normalized value. |
|
634 | + * Returns whether or not any validation errors occurred |
|
635 | + * |
|
636 | + * @param array $req_data |
|
637 | + * @return boolean whether or not there was an error |
|
638 | + * @throws EE_Error |
|
639 | + */ |
|
640 | + protected function _normalize($req_data) |
|
641 | + { |
|
642 | + // any existing validation errors don't apply so clear them |
|
643 | + $this->_validation_errors = []; |
|
644 | + // if the input is disabled, ignore whatever input was sent in |
|
645 | + if ($this->isDisabled()) { |
|
646 | + $this->_set_raw_value(null); |
|
647 | + $this->_set_normalized_value($this->get_default()); |
|
648 | + return false; |
|
649 | + } |
|
650 | + try { |
|
651 | + $raw_input = $this->find_form_data_for_this_section($req_data); |
|
652 | + // super simple sanitization for now |
|
653 | + if (is_array($raw_input)) { |
|
654 | + $raw_value = []; |
|
655 | + foreach ($raw_input as $key => $value) { |
|
656 | + $raw_value[ $key ] = $this->_sanitize($value); |
|
657 | + } |
|
658 | + $this->_set_raw_value($raw_value); |
|
659 | + } else { |
|
660 | + $this->_set_raw_value($this->_sanitize($raw_input)); |
|
661 | + } |
|
662 | + // we want to mostly leave the input alone in case we need to re-display it to the user |
|
663 | + $this->_set_normalized_value($this->_normalization_strategy->normalize($this->raw_value())); |
|
664 | + return false; |
|
665 | + } catch (EE_Validation_Error $e) { |
|
666 | + $this->add_validation_error($e); |
|
667 | + return true; |
|
668 | + } |
|
669 | + } |
|
670 | + |
|
671 | + |
|
672 | + /** |
|
673 | + * @return string |
|
674 | + * @throws EE_Error |
|
675 | + */ |
|
676 | + public function html_name() |
|
677 | + { |
|
678 | + $this->_set_default_html_name_if_empty(); |
|
679 | + return $this->_html_name ?? ''; |
|
680 | + } |
|
681 | + |
|
682 | + |
|
683 | + /** |
|
684 | + * @return string |
|
685 | + * @throws EE_Error |
|
686 | + */ |
|
687 | + public function html_label_id() |
|
688 | + { |
|
689 | + return ! empty($this->_html_label_id) |
|
690 | + ? $this->_html_label_id |
|
691 | + : $this->html_id() . '-lbl'; |
|
692 | + } |
|
693 | + |
|
694 | + |
|
695 | + /** |
|
696 | + * @return string |
|
697 | + */ |
|
698 | + public function html_label_class() |
|
699 | + { |
|
700 | + return $this->_html_label_class ?? ''; |
|
701 | + } |
|
702 | + |
|
703 | + |
|
704 | + /** |
|
705 | + * @param string $html_class |
|
706 | + */ |
|
707 | + public function add_html_label_class(string $html_class) |
|
708 | + { |
|
709 | + $this->_html_label_class .= ' ' . trim($html_class); |
|
710 | + } |
|
711 | + |
|
712 | + |
|
713 | + /** |
|
714 | + * @return string |
|
715 | + */ |
|
716 | + public function html_label_style() |
|
717 | + { |
|
718 | + return $this->_html_label_style ?? ''; |
|
719 | + } |
|
720 | + |
|
721 | + |
|
722 | + /** |
|
723 | + * @return string |
|
724 | + */ |
|
725 | + public function html_label_text() |
|
726 | + { |
|
727 | + return $this->_html_label_text ?? ''; |
|
728 | + } |
|
729 | + |
|
730 | + |
|
731 | + /** |
|
732 | + * @return string |
|
733 | + */ |
|
734 | + public function html_help_text() |
|
735 | + { |
|
736 | + return $this->_html_help_text ?? ''; |
|
737 | + } |
|
738 | + |
|
739 | + |
|
740 | + /** |
|
741 | + * @return string |
|
742 | + */ |
|
743 | + public function html_help_class() |
|
744 | + { |
|
745 | + return $this->_html_help_class ?? ''; |
|
746 | + } |
|
747 | + |
|
748 | + |
|
749 | + /** |
|
750 | + * @return string |
|
751 | + */ |
|
752 | + public function html_help_style() |
|
753 | + { |
|
754 | + return $this->_html_style ?? ''; |
|
755 | + } |
|
756 | + |
|
757 | + |
|
758 | + /** |
|
759 | + * returns the raw, UNSAFE, input, almost exactly as the user submitted it. |
|
760 | + * Please note that almost all client code should instead use the normalized_value; |
|
761 | + * or possibly raw_value_in_form (which prepares the string for displaying in an HTML attribute on a tag, |
|
762 | + * mostly by escaping quotes) |
|
763 | + * Note, we do not store the exact original value sent in the user's request because |
|
764 | + * it may have malicious content, and we MIGHT want to store the form input in a transient or something... |
|
765 | + * in which case, we would have stored the malicious content to our database. |
|
766 | + * |
|
767 | + * @return mixed |
|
768 | + */ |
|
769 | + public function raw_value() |
|
770 | + { |
|
771 | + return $this->_raw_value; |
|
772 | + } |
|
773 | + |
|
774 | + |
|
775 | + /** |
|
776 | + * Returns a string safe to usage in form inputs when displaying, because |
|
777 | + * it escapes all html entities |
|
778 | + * |
|
779 | + * @return string |
|
780 | + */ |
|
781 | + public function raw_value_in_form(): string |
|
782 | + { |
|
783 | + return htmlentities((string) $this->raw_value(), ENT_QUOTES, 'UTF-8'); |
|
784 | + } |
|
785 | + |
|
786 | + |
|
787 | + /** |
|
788 | + * returns the value after it's been sanitized, and then converted into it's proper type |
|
789 | + * in PHP. Eg, a string, an int, an array, |
|
790 | + * |
|
791 | + * @return mixed |
|
792 | + */ |
|
793 | + public function normalized_value() |
|
794 | + { |
|
795 | + return $this->_normalized_value; |
|
796 | + } |
|
797 | + |
|
798 | + |
|
799 | + /** |
|
800 | + * Returns the normalized value is a presentable way. By default this is just |
|
801 | + * the normalized value by itself, but it can be overridden for when that's not |
|
802 | + * the best thing to display |
|
803 | + * |
|
804 | + * @return mixed |
|
805 | + */ |
|
806 | + public function pretty_value() |
|
807 | + { |
|
808 | + return $this->_normalized_value; |
|
809 | + } |
|
810 | + |
|
811 | + |
|
812 | + /** |
|
813 | + * When generating the JS for the jquery validation rules like<br> |
|
814 | + * <code>$( "#myform" ).validate({ |
|
815 | + * rules: { |
|
816 | + * password: "required", |
|
817 | + * password_again: { |
|
818 | + * equalTo: "#password" |
|
819 | + * } |
|
820 | + * } |
|
821 | + * });</code> |
|
822 | + * if this field had the name 'password_again', it should return |
|
823 | + * <br><code>password_again: { |
|
824 | + * equalTo: "#password" |
|
825 | + * }</code> |
|
826 | + * |
|
827 | + * @return array |
|
828 | + */ |
|
829 | + public function get_jquery_validation_rules(): array |
|
830 | + { |
|
831 | + $jquery_validation_js = []; |
|
832 | + $jquery_validation_rules = []; |
|
833 | + foreach ($this->get_validation_strategies() as $validation_strategy) { |
|
834 | + $jquery_validation_rules = array_replace_recursive( |
|
835 | + $jquery_validation_rules, |
|
836 | + $validation_strategy->get_jquery_validation_rule_array() |
|
837 | + ); |
|
838 | + } |
|
839 | + if (! empty($jquery_validation_rules)) { |
|
840 | + foreach ($this->get_display_strategy()->get_html_input_ids(true) as $html_id_with_pound_sign) { |
|
841 | + $jquery_validation_js[ $html_id_with_pound_sign ] = $jquery_validation_rules; |
|
842 | + } |
|
843 | + } |
|
844 | + return $jquery_validation_js; |
|
845 | + } |
|
846 | + |
|
847 | + |
|
848 | + /** |
|
849 | + * Sets the input's default value for use in displaying in the form. Note: value should be |
|
850 | + * normalized (Eg, if providing a default of ra Yes_NO_Input you would provide TRUE or FALSE, not '1' or '0') |
|
851 | + * |
|
852 | + * @param mixed $value |
|
853 | + * @return void |
|
854 | + */ |
|
855 | + public function set_default($value) |
|
856 | + { |
|
857 | + $this->_default = $value; |
|
858 | + $this->_set_normalized_value($value); |
|
859 | + $this->_set_raw_value($value); |
|
860 | + } |
|
861 | + |
|
862 | + |
|
863 | + /** |
|
864 | + * Sets the normalized value on this input |
|
865 | + * |
|
866 | + * @param mixed $value |
|
867 | + */ |
|
868 | + protected function _set_normalized_value($value) |
|
869 | + { |
|
870 | + $this->_normalized_value = $value; |
|
871 | + } |
|
872 | + |
|
873 | + |
|
874 | + /** |
|
875 | + * Sets the raw value on this input (ie, exactly as the user submitted it) |
|
876 | + * |
|
877 | + * @param mixed $value |
|
878 | + */ |
|
879 | + protected function _set_raw_value($value) |
|
880 | + { |
|
881 | + $this->_raw_value = $this->_normalization_strategy->unnormalize($value); |
|
882 | + } |
|
883 | + |
|
884 | + |
|
885 | + /** |
|
886 | + * Sets the HTML label text after it has already been defined |
|
887 | + * |
|
888 | + * @param string $label |
|
889 | + * @return void |
|
890 | + */ |
|
891 | + public function set_html_label_text($label) |
|
892 | + { |
|
893 | + $this->_html_label_text = $label; |
|
894 | + } |
|
895 | + |
|
896 | + |
|
897 | + /** |
|
898 | + * Sets whether or not this field is required, and adjusts the validation strategy. |
|
899 | + * If you want to use the EE_Conditionally_Required_Validation_Strategy, |
|
900 | + * please add it as a validation strategy using add_validation_strategy as normal |
|
901 | + * |
|
902 | + * @param boolean $required boolean |
|
903 | + * @param null $required_text |
|
904 | + */ |
|
905 | + public function set_required($required = true, $required_text = null) |
|
906 | + { |
|
907 | + $required = filter_var($required, FILTER_VALIDATE_BOOLEAN); |
|
908 | + // whether $required is a string or a boolean, we want to add a required validation strategy |
|
909 | + if ($required) { |
|
910 | + $this->_add_validation_strategy(new EE_Required_Validation_Strategy($required_text)); |
|
911 | + } else { |
|
912 | + $this->remove_validation_strategy('EE_Required_Validation_Strategy'); |
|
913 | + } |
|
914 | + $this->_required = $required; |
|
915 | + } |
|
916 | + |
|
917 | + |
|
918 | + /** |
|
919 | + * Returns whether or not this field is required |
|
920 | + * |
|
921 | + * @return boolean |
|
922 | + */ |
|
923 | + public function required() |
|
924 | + { |
|
925 | + return $this->_required; |
|
926 | + } |
|
927 | + |
|
928 | + |
|
929 | + /** |
|
930 | + * @param string $required_css_class |
|
931 | + */ |
|
932 | + public function set_required_css_class($required_css_class) |
|
933 | + { |
|
934 | + $this->_required_css_class = $required_css_class; |
|
935 | + } |
|
936 | + |
|
937 | + |
|
938 | + /** |
|
939 | + * @return string |
|
940 | + */ |
|
941 | + public function required_css_class() |
|
942 | + { |
|
943 | + return $this->_required_css_class; |
|
944 | + } |
|
945 | + |
|
946 | + |
|
947 | + /** |
|
948 | + * @param bool $add_required |
|
949 | + * @return string |
|
950 | + */ |
|
951 | + public function html_class($add_required = false) |
|
952 | + { |
|
953 | + return $add_required && $this->required() |
|
954 | + ? $this->required_css_class() . ' ' . $this->_html_class |
|
955 | + : $this->_html_class; |
|
956 | + } |
|
957 | + |
|
958 | + |
|
959 | + /** |
|
960 | + * Sets the help text, in case |
|
961 | + * |
|
962 | + * @param string $text |
|
963 | + */ |
|
964 | + public function set_html_help_text($text) |
|
965 | + { |
|
966 | + $this->_html_help_text = $text; |
|
967 | + } |
|
968 | + |
|
969 | + |
|
970 | + /** |
|
971 | + * Uses the sensitive data removal strategy to remove the sensitive data from this |
|
972 | + * input. If there is any kind of sensitive data removal on this input, we clear |
|
973 | + * out the raw value completely |
|
974 | + * |
|
975 | + * @return void |
|
976 | + */ |
|
977 | + public function clean_sensitive_data() |
|
978 | + { |
|
979 | + // if we do ANY kind of sensitive data removal on this, then just clear out the raw value |
|
980 | + // if we need more logic than this we'll make a strategy for it |
|
981 | + if ( |
|
982 | + $this->_sensitive_data_removal_strategy |
|
983 | + && ! $this->_sensitive_data_removal_strategy instanceof EE_No_Sensitive_Data_Removal |
|
984 | + ) { |
|
985 | + $this->_set_raw_value(null); |
|
986 | + } |
|
987 | + // and clean the normalized value according to the appropriate strategy |
|
988 | + $this->_set_normalized_value( |
|
989 | + $this->get_sensitive_data_removal_strategy()->remove_sensitive_data( |
|
990 | + $this->_normalized_value |
|
991 | + ) |
|
992 | + ); |
|
993 | + } |
|
994 | + |
|
995 | + |
|
996 | + /** |
|
997 | + * @param bool $primary |
|
998 | + * @param string $button_size |
|
999 | + * @param string $other_attributes |
|
1000 | + */ |
|
1001 | + public function set_button_css_attributes($primary = true, $button_size = '', $other_attributes = '') |
|
1002 | + { |
|
1003 | + $button_css_attributes = 'button'; |
|
1004 | + $button_css_attributes .= $primary === true |
|
1005 | + ? ' button--primary' |
|
1006 | + : ' button--secondary'; |
|
1007 | + switch ($button_size) { |
|
1008 | + case 'xs': |
|
1009 | + case 'extra-small': |
|
1010 | + $button_css_attributes .= ' button-xs'; |
|
1011 | + break; |
|
1012 | + case 'sm': |
|
1013 | + case 'small': |
|
1014 | + $button_css_attributes .= ' button-sm'; |
|
1015 | + break; |
|
1016 | + case 'lg': |
|
1017 | + case 'large': |
|
1018 | + $button_css_attributes .= ' button-lg'; |
|
1019 | + break; |
|
1020 | + case 'block': |
|
1021 | + $button_css_attributes .= ' button-block'; |
|
1022 | + break; |
|
1023 | + case 'md': |
|
1024 | + case 'medium': |
|
1025 | + default: |
|
1026 | + $button_css_attributes .= ''; |
|
1027 | + } |
|
1028 | + $this->_button_css_attributes .= ! empty($other_attributes) |
|
1029 | + ? $button_css_attributes . ' ' . $other_attributes |
|
1030 | + : $button_css_attributes; |
|
1031 | + } |
|
1032 | + |
|
1033 | + |
|
1034 | + /** |
|
1035 | + * @return string |
|
1036 | + */ |
|
1037 | + public function button_css_attributes() |
|
1038 | + { |
|
1039 | + if (empty($this->_button_css_attributes)) { |
|
1040 | + $this->set_button_css_attributes(); |
|
1041 | + } |
|
1042 | + return $this->_button_css_attributes; |
|
1043 | + } |
|
1044 | + |
|
1045 | + |
|
1046 | + /** |
|
1047 | + * find_form_data_for_this_section |
|
1048 | + * using this section's name and its parents, finds the value of the form data that corresponds to it. |
|
1049 | + * For example, if this form section's HTML name is my_form[subform][form_input_1], |
|
1050 | + * then it's value should be in request at request['my_form']['subform']['form_input_1']. |
|
1051 | + * (If that doesn't exist, we also check for this subsection's name |
|
1052 | + * at the TOP LEVEL of the request data. Eg request['form_input_1'].) |
|
1053 | + * This function finds its value in the form. |
|
1054 | + * |
|
1055 | + * @param array $req_data |
|
1056 | + * @return mixed whatever the raw value of this form section is in the request data |
|
1057 | + * @throws EE_Error |
|
1058 | + */ |
|
1059 | + public function find_form_data_for_this_section($req_data) |
|
1060 | + { |
|
1061 | + $name_parts = $this->getInputNameParts(); |
|
1062 | + // now get the value for the input |
|
1063 | + $value = $this->findRequestForSectionUsingNameParts($name_parts, $req_data); |
|
1064 | + // check if this thing's name is at the TOP level of the request data |
|
1065 | + if ($value === null && isset($req_data[ $this->name() ])) { |
|
1066 | + $value = $req_data[ $this->name() ]; |
|
1067 | + } |
|
1068 | + return $value; |
|
1069 | + } |
|
1070 | + |
|
1071 | + |
|
1072 | + /** |
|
1073 | + * If this input's name is something like "foo[bar][baz]" |
|
1074 | + * returns an array like `array('foo','bar',baz')` |
|
1075 | + * |
|
1076 | + * @return array |
|
1077 | + * @throws EE_Error |
|
1078 | + */ |
|
1079 | + protected function getInputNameParts() |
|
1080 | + { |
|
1081 | + // break up the html name by "[]" |
|
1082 | + if (strpos($this->html_name(), '[') !== false) { |
|
1083 | + $before_any_brackets = substr($this->html_name(), 0, strpos($this->html_name(), '[')); |
|
1084 | + } else { |
|
1085 | + $before_any_brackets = $this->html_name(); |
|
1086 | + } |
|
1087 | + // grab all of the segments |
|
1088 | + preg_match_all('~\[([^]]*)\]~', $this->html_name(), $matches); |
|
1089 | + if (isset($matches[1]) && is_array($matches[1])) { |
|
1090 | + $name_parts = $matches[1]; |
|
1091 | + array_unshift($name_parts, $before_any_brackets); |
|
1092 | + } else { |
|
1093 | + $name_parts = [$before_any_brackets]; |
|
1094 | + } |
|
1095 | + return $name_parts; |
|
1096 | + } |
|
1097 | + |
|
1098 | + |
|
1099 | + /** |
|
1100 | + * @param array $html_name_parts |
|
1101 | + * @param array $req_data |
|
1102 | + * @return array | NULL |
|
1103 | + */ |
|
1104 | + public function findRequestForSectionUsingNameParts($html_name_parts, $req_data) |
|
1105 | + { |
|
1106 | + $first_part_to_consider = array_shift($html_name_parts); |
|
1107 | + if (isset($req_data[ $first_part_to_consider ])) { |
|
1108 | + if (empty($html_name_parts)) { |
|
1109 | + return $req_data[ $first_part_to_consider ]; |
|
1110 | + } else { |
|
1111 | + return $this->findRequestForSectionUsingNameParts( |
|
1112 | + $html_name_parts, |
|
1113 | + $req_data[ $first_part_to_consider ] |
|
1114 | + ); |
|
1115 | + } |
|
1116 | + } else { |
|
1117 | + return null; |
|
1118 | + } |
|
1119 | + } |
|
1120 | + |
|
1121 | + |
|
1122 | + /** |
|
1123 | + * Checks if this form input's data is in the request data |
|
1124 | + * |
|
1125 | + * @param array $req_data |
|
1126 | + * @return boolean |
|
1127 | + * @throws EE_Error |
|
1128 | + */ |
|
1129 | + public function form_data_present_in($req_data = null) |
|
1130 | + { |
|
1131 | + if ($req_data === null) { |
|
1132 | + /** @var RequestInterface $request */ |
|
1133 | + $request = LoaderFactory::getLoader()->getShared(RequestInterface::class); |
|
1134 | + $req_data = $request->postParams(); |
|
1135 | + } |
|
1136 | + $checked_value = $this->find_form_data_for_this_section($req_data); |
|
1137 | + if ($checked_value !== null) { |
|
1138 | + return true; |
|
1139 | + } else { |
|
1140 | + return false; |
|
1141 | + } |
|
1142 | + } |
|
1143 | + |
|
1144 | + |
|
1145 | + /** |
|
1146 | + * Overrides parent to add js data from validation and display strategies |
|
1147 | + * |
|
1148 | + * @param array $form_other_js_data |
|
1149 | + * @return array |
|
1150 | + */ |
|
1151 | + public function get_other_js_data($form_other_js_data = []) |
|
1152 | + { |
|
1153 | + return $this->get_other_js_data_from_strategies($form_other_js_data); |
|
1154 | + } |
|
1155 | + |
|
1156 | + |
|
1157 | + /** |
|
1158 | + * Gets other JS data for localization from this input's strategies, like |
|
1159 | + * the validation strategies and the display strategy |
|
1160 | + * |
|
1161 | + * @param array $form_other_js_data |
|
1162 | + * @return array |
|
1163 | + */ |
|
1164 | + public function get_other_js_data_from_strategies($form_other_js_data = []) |
|
1165 | + { |
|
1166 | + $form_other_js_data = $this->get_display_strategy()->get_other_js_data($form_other_js_data); |
|
1167 | + foreach ($this->get_validation_strategies() as $validation_strategy) { |
|
1168 | + $form_other_js_data = $validation_strategy->get_other_js_data($form_other_js_data); |
|
1169 | + } |
|
1170 | + return $form_other_js_data; |
|
1171 | + } |
|
1172 | + |
|
1173 | + |
|
1174 | + /** |
|
1175 | + * Override parent because we want to give our strategies an opportunity to enqueue some js and css |
|
1176 | + * |
|
1177 | + * @return void |
|
1178 | + */ |
|
1179 | + public function enqueue_js() |
|
1180 | + { |
|
1181 | + // ask our display strategy and validation strategies if they have js to enqueue |
|
1182 | + $this->enqueue_js_from_strategies(); |
|
1183 | + } |
|
1184 | + |
|
1185 | + |
|
1186 | + /** |
|
1187 | + * Tells strategies when its ok to enqueue their js and css |
|
1188 | + * |
|
1189 | + * @return void |
|
1190 | + */ |
|
1191 | + public function enqueue_js_from_strategies() |
|
1192 | + { |
|
1193 | + $this->get_display_strategy()->enqueue_js(); |
|
1194 | + foreach ($this->get_validation_strategies() as $validation_strategy) { |
|
1195 | + $validation_strategy->enqueue_js(); |
|
1196 | + } |
|
1197 | + } |
|
1198 | + |
|
1199 | + |
|
1200 | + /** |
|
1201 | + * Gets the default value set on the input (not the current value, which may have been |
|
1202 | + * changed because of a form submission). If no default was set, this us null. |
|
1203 | + * |
|
1204 | + * @return mixed |
|
1205 | + */ |
|
1206 | + public function get_default() |
|
1207 | + { |
|
1208 | + return $this->_default; |
|
1209 | + } |
|
1210 | + |
|
1211 | + |
|
1212 | + /** |
|
1213 | + * Makes this input disabled. That means it will have the HTML attribute 'disabled="disabled"', |
|
1214 | + * and server-side if any input was received it will be ignored |
|
1215 | + */ |
|
1216 | + public function disable($disable = true) |
|
1217 | + { |
|
1218 | + $disabled_attribute = ' disabled="disabled"'; |
|
1219 | + $this->disabled = filter_var($disable, FILTER_VALIDATE_BOOLEAN); |
|
1220 | + if ($this->disabled) { |
|
1221 | + if (strpos($this->_other_html_attributes, $disabled_attribute) === false) { |
|
1222 | + $this->_other_html_attributes .= $disabled_attribute; |
|
1223 | + } |
|
1224 | + $this->_set_normalized_value($this->get_default()); |
|
1225 | + } else { |
|
1226 | + $this->_other_html_attributes = str_replace($disabled_attribute, '', $this->_other_html_attributes); |
|
1227 | + } |
|
1228 | + } |
|
1229 | + |
|
1230 | + |
|
1231 | + /** |
|
1232 | + * Returns whether this input is currently disabled. |
|
1233 | + * |
|
1234 | + * @return bool |
|
1235 | + */ |
|
1236 | + public function isDisabled() |
|
1237 | + { |
|
1238 | + return $this->disabled; |
|
1239 | + } |
|
1240 | 1240 | } |
@@ -17,281 +17,281 @@ |
||
17 | 17 | */ |
18 | 18 | abstract class IframeEmbedButton |
19 | 19 | { |
20 | - /** |
|
21 | - * @var string $iframe_name |
|
22 | - */ |
|
23 | - private $iframe_name; |
|
20 | + /** |
|
21 | + * @var string $iframe_name |
|
22 | + */ |
|
23 | + private $iframe_name; |
|
24 | 24 | |
25 | - /** |
|
26 | - * @var string $route_name |
|
27 | - */ |
|
28 | - private $route_name; |
|
25 | + /** |
|
26 | + * @var string $route_name |
|
27 | + */ |
|
28 | + private $route_name; |
|
29 | 29 | |
30 | - /** |
|
31 | - * @var string $slug |
|
32 | - */ |
|
33 | - private $slug; |
|
30 | + /** |
|
31 | + * @var string $slug |
|
32 | + */ |
|
33 | + private $slug; |
|
34 | 34 | |
35 | - /** |
|
36 | - * @var boolean $append_filterable_content |
|
37 | - */ |
|
38 | - private $append_filterable_content; |
|
35 | + /** |
|
36 | + * @var boolean $append_filterable_content |
|
37 | + */ |
|
38 | + private $append_filterable_content; |
|
39 | 39 | |
40 | 40 | |
41 | - /** |
|
42 | - * IframeEmbedButton constructor. |
|
43 | - * |
|
44 | - * @param string $iframe_name i18n name for the iframe. This will be used in HTML |
|
45 | - * @param string $route_name the name of the registered route |
|
46 | - * @param string $slug URL slug used for the thing the iframe button is being embedded in. |
|
47 | - * will most likely be "event" since that's the only usage atm |
|
48 | - */ |
|
49 | - public function __construct($iframe_name, $route_name, $slug = 'event') |
|
50 | - { |
|
51 | - $this->iframe_name = $iframe_name; |
|
52 | - $this->route_name = $route_name; |
|
53 | - $this->slug = $slug; |
|
54 | - } |
|
41 | + /** |
|
42 | + * IframeEmbedButton constructor. |
|
43 | + * |
|
44 | + * @param string $iframe_name i18n name for the iframe. This will be used in HTML |
|
45 | + * @param string $route_name the name of the registered route |
|
46 | + * @param string $slug URL slug used for the thing the iframe button is being embedded in. |
|
47 | + * will most likely be "event" since that's the only usage atm |
|
48 | + */ |
|
49 | + public function __construct($iframe_name, $route_name, $slug = 'event') |
|
50 | + { |
|
51 | + $this->iframe_name = $iframe_name; |
|
52 | + $this->route_name = $route_name; |
|
53 | + $this->slug = $slug; |
|
54 | + } |
|
55 | 55 | |
56 | 56 | |
57 | - /** |
|
58 | - * Adds an iframe embed code button to the Event editor. |
|
59 | - */ |
|
60 | - public function addEventEditorIframeEmbedButtonFilter() |
|
61 | - { |
|
62 | - add_filter( |
|
63 | - 'get_sample_permalink_html', |
|
64 | - array($this, 'appendIframeEmbedButtonToSamplePermalinkHtml'), |
|
65 | - 15, |
|
66 | - 2 |
|
67 | - ); |
|
68 | - } |
|
57 | + /** |
|
58 | + * Adds an iframe embed code button to the Event editor. |
|
59 | + */ |
|
60 | + public function addEventEditorIframeEmbedButtonFilter() |
|
61 | + { |
|
62 | + add_filter( |
|
63 | + 'get_sample_permalink_html', |
|
64 | + array($this, 'appendIframeEmbedButtonToSamplePermalinkHtml'), |
|
65 | + 15, |
|
66 | + 2 |
|
67 | + ); |
|
68 | + } |
|
69 | 69 | |
70 | - /** |
|
71 | - * Adds assets of iframe embed code button. |
|
72 | - */ |
|
73 | - public function addEventEditorIframeEmbedButtonAssets() |
|
74 | - { |
|
75 | - add_action( |
|
76 | - 'admin_enqueue_scripts', |
|
77 | - array($this, 'embedButtonAssets'), |
|
78 | - 10 |
|
79 | - ); |
|
80 | - } |
|
70 | + /** |
|
71 | + * Adds assets of iframe embed code button. |
|
72 | + */ |
|
73 | + public function addEventEditorIframeEmbedButtonAssets() |
|
74 | + { |
|
75 | + add_action( |
|
76 | + 'admin_enqueue_scripts', |
|
77 | + array($this, 'embedButtonAssets'), |
|
78 | + 10 |
|
79 | + ); |
|
80 | + } |
|
81 | 81 | |
82 | 82 | |
83 | - /** |
|
84 | - * @param $permalink_string |
|
85 | - * @param $id |
|
86 | - * @return string |
|
87 | - */ |
|
88 | - public function appendIframeEmbedButtonToSamplePermalinkHtml($permalink_string, $id) |
|
89 | - { |
|
90 | - return $this->eventEditorIframeEmbedButton( |
|
91 | - $permalink_string, |
|
92 | - $id |
|
93 | - ); |
|
94 | - } |
|
83 | + /** |
|
84 | + * @param $permalink_string |
|
85 | + * @param $id |
|
86 | + * @return string |
|
87 | + */ |
|
88 | + public function appendIframeEmbedButtonToSamplePermalinkHtml($permalink_string, $id) |
|
89 | + { |
|
90 | + return $this->eventEditorIframeEmbedButton( |
|
91 | + $permalink_string, |
|
92 | + $id |
|
93 | + ); |
|
94 | + } |
|
95 | 95 | |
96 | 96 | |
97 | - /** |
|
98 | - * iframe embed code button to the Event editor. |
|
99 | - * |
|
100 | - * @param string $permalink_string |
|
101 | - * @param int $id |
|
102 | - * @return string |
|
103 | - */ |
|
104 | - public function eventEditorIframeEmbedButton( |
|
105 | - $permalink_string, |
|
106 | - $id |
|
107 | - ) { |
|
108 | - // make sure this is ONLY when editing and the event id has been set. |
|
109 | - if (! empty($id)) { |
|
110 | - $post = get_post($id); |
|
111 | - // if NOT event then let's get out. |
|
112 | - if ($post->post_type !== EspressoPostType::EVENTS) { |
|
113 | - return $permalink_string; |
|
114 | - } |
|
115 | - $permalink_string .= $this->embedButtonHtml([$this->slug => $id]); |
|
116 | - } |
|
117 | - return $permalink_string; |
|
118 | - } |
|
97 | + /** |
|
98 | + * iframe embed code button to the Event editor. |
|
99 | + * |
|
100 | + * @param string $permalink_string |
|
101 | + * @param int $id |
|
102 | + * @return string |
|
103 | + */ |
|
104 | + public function eventEditorIframeEmbedButton( |
|
105 | + $permalink_string, |
|
106 | + $id |
|
107 | + ) { |
|
108 | + // make sure this is ONLY when editing and the event id has been set. |
|
109 | + if (! empty($id)) { |
|
110 | + $post = get_post($id); |
|
111 | + // if NOT event then let's get out. |
|
112 | + if ($post->post_type !== EspressoPostType::EVENTS) { |
|
113 | + return $permalink_string; |
|
114 | + } |
|
115 | + $permalink_string .= $this->embedButtonHtml([$this->slug => $id]); |
|
116 | + } |
|
117 | + return $permalink_string; |
|
118 | + } |
|
119 | 119 | |
120 | 120 | |
121 | - /** |
|
122 | - * Adds an iframe embed code button via a WP do_action() as determined by the first parameter |
|
123 | - * |
|
124 | - * @param string $action name of the WP do_action() to hook into |
|
125 | - */ |
|
126 | - public function addActionIframeEmbedButton($action) |
|
127 | - { |
|
128 | - // add button for iframe code to event editor. |
|
129 | - add_action( |
|
130 | - $action, |
|
131 | - array($this, 'addActionIframeEmbedButtonCallback'), |
|
132 | - 10, |
|
133 | - 2 |
|
134 | - ); |
|
135 | - } |
|
121 | + /** |
|
122 | + * Adds an iframe embed code button via a WP do_action() as determined by the first parameter |
|
123 | + * |
|
124 | + * @param string $action name of the WP do_action() to hook into |
|
125 | + */ |
|
126 | + public function addActionIframeEmbedButton($action) |
|
127 | + { |
|
128 | + // add button for iframe code to event editor. |
|
129 | + add_action( |
|
130 | + $action, |
|
131 | + array($this, 'addActionIframeEmbedButtonCallback'), |
|
132 | + 10, |
|
133 | + 2 |
|
134 | + ); |
|
135 | + } |
|
136 | 136 | |
137 | 137 | |
138 | - /** |
|
139 | - * @return void |
|
140 | - */ |
|
141 | - public function addActionIframeEmbedButtonCallback() |
|
142 | - { |
|
143 | - echo wp_kses($this->embedButtonHtml(), AllowedTags::getWithFullTags()); |
|
144 | - } |
|
138 | + /** |
|
139 | + * @return void |
|
140 | + */ |
|
141 | + public function addActionIframeEmbedButtonCallback() |
|
142 | + { |
|
143 | + echo wp_kses($this->embedButtonHtml(), AllowedTags::getWithFullTags()); |
|
144 | + } |
|
145 | 145 | |
146 | 146 | |
147 | - /** |
|
148 | - * Adds an iframe embed code button via a WP apply_filters() as determined by the first parameter |
|
149 | - * |
|
150 | - * @param string $filter name of the WP apply_filters() to hook into |
|
151 | - * @param bool $append if true, will add iframe embed button to end of content, |
|
152 | - * else if false, will add to the beginning of the content |
|
153 | - */ |
|
154 | - public function addFilterIframeEmbedButton($filter, $append = true) |
|
155 | - { |
|
156 | - $this->append_filterable_content = $append; |
|
157 | - // add button for iframe code to event editor. |
|
158 | - add_filter( |
|
159 | - $filter, |
|
160 | - array($this, 'addFilterIframeEmbedButtonCallback'), |
|
161 | - 10 |
|
162 | - ); |
|
163 | - } |
|
147 | + /** |
|
148 | + * Adds an iframe embed code button via a WP apply_filters() as determined by the first parameter |
|
149 | + * |
|
150 | + * @param string $filter name of the WP apply_filters() to hook into |
|
151 | + * @param bool $append if true, will add iframe embed button to end of content, |
|
152 | + * else if false, will add to the beginning of the content |
|
153 | + */ |
|
154 | + public function addFilterIframeEmbedButton($filter, $append = true) |
|
155 | + { |
|
156 | + $this->append_filterable_content = $append; |
|
157 | + // add button for iframe code to event editor. |
|
158 | + add_filter( |
|
159 | + $filter, |
|
160 | + array($this, 'addFilterIframeEmbedButtonCallback'), |
|
161 | + 10 |
|
162 | + ); |
|
163 | + } |
|
164 | 164 | |
165 | 165 | |
166 | - /** |
|
167 | - * @param array|string $filterable_content |
|
168 | - * @return array|string |
|
169 | - */ |
|
170 | - public function addFilterIframeEmbedButtonCallback($filterable_content) |
|
171 | - { |
|
172 | - $embedButtonHtml = $this->embedButtonHtml(); |
|
173 | - if (is_array($filterable_content)) { |
|
174 | - $filterable_content = $this->append_filterable_content |
|
175 | - ? $filterable_content + array($this->route_name => $embedButtonHtml) |
|
176 | - : array($this->route_name => $embedButtonHtml) + $filterable_content; |
|
177 | - } else { |
|
178 | - $filterable_content = $this->append_filterable_content |
|
179 | - ? $filterable_content . $embedButtonHtml |
|
180 | - : $embedButtonHtml . $filterable_content; |
|
181 | - } |
|
182 | - return $filterable_content; |
|
183 | - } |
|
166 | + /** |
|
167 | + * @param array|string $filterable_content |
|
168 | + * @return array|string |
|
169 | + */ |
|
170 | + public function addFilterIframeEmbedButtonCallback($filterable_content) |
|
171 | + { |
|
172 | + $embedButtonHtml = $this->embedButtonHtml(); |
|
173 | + if (is_array($filterable_content)) { |
|
174 | + $filterable_content = $this->append_filterable_content |
|
175 | + ? $filterable_content + array($this->route_name => $embedButtonHtml) |
|
176 | + : array($this->route_name => $embedButtonHtml) + $filterable_content; |
|
177 | + } else { |
|
178 | + $filterable_content = $this->append_filterable_content |
|
179 | + ? $filterable_content . $embedButtonHtml |
|
180 | + : $embedButtonHtml . $filterable_content; |
|
181 | + } |
|
182 | + return $filterable_content; |
|
183 | + } |
|
184 | 184 | |
185 | 185 | |
186 | - /** |
|
187 | - * iframe_embed_html |
|
188 | - * |
|
189 | - * @param array $query_args |
|
190 | - * @param string $button_class |
|
191 | - * @return string |
|
192 | - */ |
|
193 | - public function embedButtonHtml($query_args = array(), $button_class = '') |
|
194 | - { |
|
195 | - // incoming args will replace the defaults listed here in the second array (union preserves first array) |
|
196 | - $query_args = (array) $query_args + array($this->route_name => 'iframe'); |
|
197 | - $query_args = (array) apply_filters( |
|
198 | - 'FHEE__EventEspresso_core_libraries_iframe_display_IframeEmbedButton__embedButtonHtml__query_args', |
|
199 | - $query_args |
|
200 | - ); |
|
201 | - // add this route to our localized vars |
|
202 | - $iframe_module_routes = EE_Registry::$i18n_js_strings['iframe_module_routes'] ?? []; |
|
203 | - $iframe_module_routes[ $this->route_name ] = $this->route_name; |
|
204 | - EE_Registry::$i18n_js_strings['iframe_module_routes'] = $iframe_module_routes; |
|
205 | - $route_name = esc_attr($this->route_name); |
|
206 | - $iframe_url = esc_url_raw(add_query_arg($query_args, site_url())); |
|
186 | + /** |
|
187 | + * iframe_embed_html |
|
188 | + * |
|
189 | + * @param array $query_args |
|
190 | + * @param string $button_class |
|
191 | + * @return string |
|
192 | + */ |
|
193 | + public function embedButtonHtml($query_args = array(), $button_class = '') |
|
194 | + { |
|
195 | + // incoming args will replace the defaults listed here in the second array (union preserves first array) |
|
196 | + $query_args = (array) $query_args + array($this->route_name => 'iframe'); |
|
197 | + $query_args = (array) apply_filters( |
|
198 | + 'FHEE__EventEspresso_core_libraries_iframe_display_IframeEmbedButton__embedButtonHtml__query_args', |
|
199 | + $query_args |
|
200 | + ); |
|
201 | + // add this route to our localized vars |
|
202 | + $iframe_module_routes = EE_Registry::$i18n_js_strings['iframe_module_routes'] ?? []; |
|
203 | + $iframe_module_routes[ $this->route_name ] = $this->route_name; |
|
204 | + EE_Registry::$i18n_js_strings['iframe_module_routes'] = $iframe_module_routes; |
|
205 | + $route_name = esc_attr($this->route_name); |
|
206 | + $iframe_url = esc_url_raw(add_query_arg($query_args, site_url())); |
|
207 | 207 | |
208 | - return EEH_HTML::div( |
|
209 | - EEH_HTML::link( |
|
210 | - '#', |
|
211 | - sprintf( |
|
212 | - esc_html__('%1$s Embed %2$s iFrame', 'event_espresso'), |
|
213 | - '<span class="dashicons dashicons-embed-post"></span>', |
|
214 | - $this->iframe_name |
|
215 | - ), |
|
216 | - sprintf( |
|
217 | - esc_html__( |
|
218 | - 'click here to generate code for embedding %1$s iframe into another site.', |
|
219 | - 'event_espresso' |
|
220 | - ), |
|
221 | - EEH_Inflector::add_indefinite_article($this->iframe_name) |
|
222 | - ), |
|
223 | - $route_name . '-iframe-embed-trigger-js', |
|
224 | - 'iframe-embed-trigger-js button button--small button--secondary ' . esc_attr($button_class), |
|
225 | - '', |
|
226 | - ' data-iframe_embed_button="#' . $route_name . '-iframe-js" tabindex="-1"' |
|
227 | - ), |
|
228 | - '', |
|
229 | - 'ee-admin-button-row ee-admin-button-row--align-start' |
|
230 | - ) |
|
231 | - . EEH_HTML::div( |
|
232 | - EEH_HTML::div( |
|
233 | - '<iframe src="' . $iframe_url . '" width="100%" height="100%"></iframe>', |
|
234 | - '', |
|
235 | - '', |
|
236 | - 'width:100%; height: 500px;' |
|
237 | - ), |
|
238 | - $route_name . '-iframe-js', |
|
239 | - 'iframe-embed-wrapper-js', |
|
240 | - 'display:none;' |
|
241 | - ); |
|
242 | - } |
|
208 | + return EEH_HTML::div( |
|
209 | + EEH_HTML::link( |
|
210 | + '#', |
|
211 | + sprintf( |
|
212 | + esc_html__('%1$s Embed %2$s iFrame', 'event_espresso'), |
|
213 | + '<span class="dashicons dashicons-embed-post"></span>', |
|
214 | + $this->iframe_name |
|
215 | + ), |
|
216 | + sprintf( |
|
217 | + esc_html__( |
|
218 | + 'click here to generate code for embedding %1$s iframe into another site.', |
|
219 | + 'event_espresso' |
|
220 | + ), |
|
221 | + EEH_Inflector::add_indefinite_article($this->iframe_name) |
|
222 | + ), |
|
223 | + $route_name . '-iframe-embed-trigger-js', |
|
224 | + 'iframe-embed-trigger-js button button--small button--secondary ' . esc_attr($button_class), |
|
225 | + '', |
|
226 | + ' data-iframe_embed_button="#' . $route_name . '-iframe-js" tabindex="-1"' |
|
227 | + ), |
|
228 | + '', |
|
229 | + 'ee-admin-button-row ee-admin-button-row--align-start' |
|
230 | + ) |
|
231 | + . EEH_HTML::div( |
|
232 | + EEH_HTML::div( |
|
233 | + '<iframe src="' . $iframe_url . '" width="100%" height="100%"></iframe>', |
|
234 | + '', |
|
235 | + '', |
|
236 | + 'width:100%; height: 500px;' |
|
237 | + ), |
|
238 | + $route_name . '-iframe-js', |
|
239 | + 'iframe-embed-wrapper-js', |
|
240 | + 'display:none;' |
|
241 | + ); |
|
242 | + } |
|
243 | 243 | |
244 | 244 | |
245 | - /** |
|
246 | - * enqueue iframe button js |
|
247 | - */ |
|
248 | - public function embedButtonAssets() |
|
249 | - { |
|
250 | - EE_Registry::$i18n_js_strings['iframe_embed_title'] = esc_html__( |
|
251 | - 'copy and paste the following into any other site\'s content to display this event:', |
|
252 | - 'event_espresso' |
|
253 | - ); |
|
254 | - EE_Registry::$i18n_js_strings['iframe_embed_close_msg'] = esc_html__( |
|
255 | - 'click anywhere outside of this window to close it.', |
|
256 | - 'event_espresso' |
|
257 | - ); |
|
258 | - wp_register_script( |
|
259 | - 'iframe_embed_button', |
|
260 | - plugin_dir_url(__FILE__) . 'iframe-embed-button.js', |
|
261 | - array('ee-dialog'), |
|
262 | - EVENT_ESPRESSO_VERSION, |
|
263 | - true |
|
264 | - ); |
|
265 | - wp_enqueue_script('iframe_embed_button'); |
|
266 | - } |
|
245 | + /** |
|
246 | + * enqueue iframe button js |
|
247 | + */ |
|
248 | + public function embedButtonAssets() |
|
249 | + { |
|
250 | + EE_Registry::$i18n_js_strings['iframe_embed_title'] = esc_html__( |
|
251 | + 'copy and paste the following into any other site\'s content to display this event:', |
|
252 | + 'event_espresso' |
|
253 | + ); |
|
254 | + EE_Registry::$i18n_js_strings['iframe_embed_close_msg'] = esc_html__( |
|
255 | + 'click anywhere outside of this window to close it.', |
|
256 | + 'event_espresso' |
|
257 | + ); |
|
258 | + wp_register_script( |
|
259 | + 'iframe_embed_button', |
|
260 | + plugin_dir_url(__FILE__) . 'iframe-embed-button.js', |
|
261 | + array('ee-dialog'), |
|
262 | + EVENT_ESPRESSO_VERSION, |
|
263 | + true |
|
264 | + ); |
|
265 | + wp_enqueue_script('iframe_embed_button'); |
|
266 | + } |
|
267 | 267 | |
268 | 268 | |
269 | - /** |
|
270 | - * generates embed button sections for admin pages |
|
271 | - * |
|
272 | - * @param array $embed_buttons |
|
273 | - * @return string |
|
274 | - */ |
|
275 | - public function addIframeEmbedButtonsSection(array $embed_buttons) |
|
276 | - { |
|
277 | - $embed_buttons = (array) apply_filters( |
|
278 | - 'FHEE__EventEspresso_core_libraries_iframe_display_IframeEmbedButton__addIframeEmbedButtonsSection__embed_buttons', |
|
279 | - $embed_buttons |
|
280 | - ); |
|
281 | - if (empty($embed_buttons)) { |
|
282 | - return ''; |
|
283 | - } |
|
284 | - // add button for iframe code to event editor. |
|
285 | - $html = EEH_HTML::div('', '', 'ee-admin-section ee-iframe-embed-buttons'); |
|
286 | - $html .= EEH_HTML::h3(esc_html__('iFrame Embed Code', 'event_espresso')); |
|
287 | - $html .= EEH_HTML::p( |
|
288 | - esc_html__( |
|
289 | - 'Click the following button(s) to generate iframe HTML that will allow you to embed your event content within the content of other websites.', |
|
290 | - 'event_espresso' |
|
291 | - ) |
|
292 | - ); |
|
293 | - $html .= ' ' . implode(' ', $embed_buttons) . ' '; |
|
294 | - $html .= EEH_HTML::divx(); |
|
295 | - return $html; |
|
296 | - } |
|
269 | + /** |
|
270 | + * generates embed button sections for admin pages |
|
271 | + * |
|
272 | + * @param array $embed_buttons |
|
273 | + * @return string |
|
274 | + */ |
|
275 | + public function addIframeEmbedButtonsSection(array $embed_buttons) |
|
276 | + { |
|
277 | + $embed_buttons = (array) apply_filters( |
|
278 | + 'FHEE__EventEspresso_core_libraries_iframe_display_IframeEmbedButton__addIframeEmbedButtonsSection__embed_buttons', |
|
279 | + $embed_buttons |
|
280 | + ); |
|
281 | + if (empty($embed_buttons)) { |
|
282 | + return ''; |
|
283 | + } |
|
284 | + // add button for iframe code to event editor. |
|
285 | + $html = EEH_HTML::div('', '', 'ee-admin-section ee-iframe-embed-buttons'); |
|
286 | + $html .= EEH_HTML::h3(esc_html__('iFrame Embed Code', 'event_espresso')); |
|
287 | + $html .= EEH_HTML::p( |
|
288 | + esc_html__( |
|
289 | + 'Click the following button(s) to generate iframe HTML that will allow you to embed your event content within the content of other websites.', |
|
290 | + 'event_espresso' |
|
291 | + ) |
|
292 | + ); |
|
293 | + $html .= ' ' . implode(' ', $embed_buttons) . ' '; |
|
294 | + $html .= EEH_HTML::divx(); |
|
295 | + return $html; |
|
296 | + } |
|
297 | 297 | } |
@@ -106,7 +106,7 @@ discard block |
||
106 | 106 | $id |
107 | 107 | ) { |
108 | 108 | // make sure this is ONLY when editing and the event id has been set. |
109 | - if (! empty($id)) { |
|
109 | + if ( ! empty($id)) { |
|
110 | 110 | $post = get_post($id); |
111 | 111 | // if NOT event then let's get out. |
112 | 112 | if ($post->post_type !== EspressoPostType::EVENTS) { |
@@ -176,8 +176,8 @@ discard block |
||
176 | 176 | : array($this->route_name => $embedButtonHtml) + $filterable_content; |
177 | 177 | } else { |
178 | 178 | $filterable_content = $this->append_filterable_content |
179 | - ? $filterable_content . $embedButtonHtml |
|
180 | - : $embedButtonHtml . $filterable_content; |
|
179 | + ? $filterable_content.$embedButtonHtml |
|
180 | + : $embedButtonHtml.$filterable_content; |
|
181 | 181 | } |
182 | 182 | return $filterable_content; |
183 | 183 | } |
@@ -200,7 +200,7 @@ discard block |
||
200 | 200 | ); |
201 | 201 | // add this route to our localized vars |
202 | 202 | $iframe_module_routes = EE_Registry::$i18n_js_strings['iframe_module_routes'] ?? []; |
203 | - $iframe_module_routes[ $this->route_name ] = $this->route_name; |
|
203 | + $iframe_module_routes[$this->route_name] = $this->route_name; |
|
204 | 204 | EE_Registry::$i18n_js_strings['iframe_module_routes'] = $iframe_module_routes; |
205 | 205 | $route_name = esc_attr($this->route_name); |
206 | 206 | $iframe_url = esc_url_raw(add_query_arg($query_args, site_url())); |
@@ -220,22 +220,22 @@ discard block |
||
220 | 220 | ), |
221 | 221 | EEH_Inflector::add_indefinite_article($this->iframe_name) |
222 | 222 | ), |
223 | - $route_name . '-iframe-embed-trigger-js', |
|
224 | - 'iframe-embed-trigger-js button button--small button--secondary ' . esc_attr($button_class), |
|
223 | + $route_name.'-iframe-embed-trigger-js', |
|
224 | + 'iframe-embed-trigger-js button button--small button--secondary '.esc_attr($button_class), |
|
225 | 225 | '', |
226 | - ' data-iframe_embed_button="#' . $route_name . '-iframe-js" tabindex="-1"' |
|
226 | + ' data-iframe_embed_button="#'.$route_name.'-iframe-js" tabindex="-1"' |
|
227 | 227 | ), |
228 | 228 | '', |
229 | 229 | 'ee-admin-button-row ee-admin-button-row--align-start' |
230 | 230 | ) |
231 | 231 | . EEH_HTML::div( |
232 | 232 | EEH_HTML::div( |
233 | - '<iframe src="' . $iframe_url . '" width="100%" height="100%"></iframe>', |
|
233 | + '<iframe src="'.$iframe_url.'" width="100%" height="100%"></iframe>', |
|
234 | 234 | '', |
235 | 235 | '', |
236 | 236 | 'width:100%; height: 500px;' |
237 | 237 | ), |
238 | - $route_name . '-iframe-js', |
|
238 | + $route_name.'-iframe-js', |
|
239 | 239 | 'iframe-embed-wrapper-js', |
240 | 240 | 'display:none;' |
241 | 241 | ); |
@@ -257,7 +257,7 @@ discard block |
||
257 | 257 | ); |
258 | 258 | wp_register_script( |
259 | 259 | 'iframe_embed_button', |
260 | - plugin_dir_url(__FILE__) . 'iframe-embed-button.js', |
|
260 | + plugin_dir_url(__FILE__).'iframe-embed-button.js', |
|
261 | 261 | array('ee-dialog'), |
262 | 262 | EVENT_ESPRESSO_VERSION, |
263 | 263 | true |
@@ -290,7 +290,7 @@ discard block |
||
290 | 290 | 'event_espresso' |
291 | 291 | ) |
292 | 292 | ); |
293 | - $html .= ' ' . implode(' ', $embed_buttons) . ' '; |
|
293 | + $html .= ' '.implode(' ', $embed_buttons).' '; |
|
294 | 294 | $html .= EEH_HTML::divx(); |
295 | 295 | return $html; |
296 | 296 | } |