-
Notifications
You must be signed in to change notification settings - Fork 0
/
em-template-tags.php
673 lines (642 loc) · 24.4 KB
/
em-template-tags.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
<?php
/*
* Template Tags
* If you know what you're doing, you're probably better off using the EM Objects directly.
*/
/*
* ---------------------------------------------------------------------
* Displaying Functions - Displays Lists, Page Links/URLs, etc.
* ---------------------------------------------------------------------
*/
/**
* Returns a html list of events filtered by the array or query-string of arguments supplied.
* @param array|string $args
* @return string
*/
function em_get_events( $args = array() ){
if ( is_string($args) && strpos ( $args, "=" )) {
// allows the use of arguments without breaking the legacy code
$args = wp_parse_args ( $args, array() );
}else{
$args = (array) $args;
}
$args['ajax'] = isset($args['ajax']) ? $args['ajax']:(!defined('EM_AJAX') || EM_AJAX );
$args['limit'] = !empty($args['limit']) ? $args['limit'] : get_option('dbem_events_default_limit');
if( empty($args['format']) && empty($args['format_header']) && empty($args['format_footer']) ){
ob_start();
if( !empty($args['ajax']) ){ echo '<div class="em-search-ajax">'; } //open AJAX wrapper
em_locate_template('templates/events-list.php', true, array('args'=>$args));
if( !empty($args['ajax']) ) echo "</div>"; //close AJAX wrapper
$return = ob_get_clean();
}else{
$return = EM_Events::output( $args );
}
return $return;
}
/**
* Prints out a list of events, takes same arguments as em_get_events.
* @param array|string $args
* @uses em_get_events()
*/
function em_events( $args = array() ){ echo em_get_events($args); }
/**
* Returns a html list of locations filtered by the array or query-string of arguments supplied.
* @param array|string $args
* @return string
*/
function em_get_locations( $args = array() ){
if ( is_string($args) && strpos ( $args, "=" )) {
// allows the use of arguments without breaking the legacy code
$args = wp_parse_args ( $args, array() );
}else{
$args = (array) $args;
}
$args['ajax'] = isset($args['ajax']) ? $args['ajax']:(!defined('EM_AJAX') || EM_AJAX );
$args['limit'] = !empty($args['limit']) ? $args['limit'] : get_option('dbem_locations_default_limit');
if( empty($args['format']) && empty($args['format_header']) && empty($args['format_footer']) ){
ob_start();
if( !empty($args['ajax']) ){ echo '<div class="em-search-ajax">'; } //open AJAX wrapper
em_locate_template('templates/locations-list.php', true, array('args'=>$args));
if( !empty($args['ajax']) ) echo "</div>"; //close AJAX wrapper
$return = ob_get_clean();
}else{
//no ajax allowed with custom on-the-fly formats
$return = EM_Locations::output( $args );
}
return $return;
}
/**
* Prints out a list of locations, takes same arguments as em_get_locations.
* @param array|string $args
* @uses em_get_locations()
*/
function em_locations( $args = array() ){ echo em_get_locations($args); }
/**
* Returns an html calendar of events filtered by the array or query-string of arguments supplied.
* @param array|string $args
* @return string
*/
function em_get_calendar( $args = array() ){
if ( !is_array($args) && strpos ( $args, "=" )) {
// allows the use of arguments without breaking the legacy code
$defaults = EM_Calendar::get_default_search();
$args = wp_parse_args ( $args, $defaults );
}
return EM_Calendar::output($args);
}
/**
* Prints out an html calendar, takes same arguments as em_get_calendar.
* @param array|string $args
* @uses em_get_calendar()
*/
function em_calendar( $args = array() ){ echo em_get_calendar($args); }
/**
* Generate a grouped list of events by year, month, week or day.
* @since 4.213
* @param array $args
* @return string
*/
function em_get_events_list_grouped( $args = array() ){
if ( is_string($args) && strpos ( $args, "=" )) {
// allows the use of arguments without breaking the legacy code
$args = wp_parse_args ( $args, array() );
}else{
$args = (array) $args;
}
$args['ajax'] = isset($args['ajax']) ? $args['ajax']:(!defined('EM_AJAX') || EM_AJAX );
if( empty($args['format']) && empty($args['format_header']) && empty($args['format_footer']) ){
ob_start();
if( !empty($args['ajax']) ){ echo '<div class="em-search-ajax">'; } //open AJAX wrapper
em_locate_template('templates/events-list-grouped.php', true, array('args'=>$args));
if( !empty($args['ajax']) ) echo "</div>"; //close AJAX wrapper
$return = ob_get_clean();
}else{
$return = EM_Events::output_grouped( $args );
}
return $return;
}
/**
* Print a grouped list of events by year, month, week or day.
* @since 4.213
* @param array $args
* @param string $format
* @return string
*/
function em_events_list_grouped( $args = array() ){ echo em_get_events_list_grouped($args); }
/**
* Creates an html link to the events page.
* @param string $text
* @return string
*/
function em_get_link( $text = '' ) {
$text = ($text == '') ? get_option ( "dbem_events_page_title" ) : $text;
$text = ($text == '') ? __('Events','events-manager') : $text; //In case options aren't there....
return '<a href="'.esc_url(EM_URI).'" title="'.esc_attr($text).'">'.esc_html($text).'</a>';
}
/**
* Prints the result of em_get_link()
* @param string $text
* @uses em_get_link()
*/
function em_link($text = ''){ echo em_get_link($text); }
/**
* Creates an html link to the RSS feed
* @param string $text
* @return string
*/
function em_get_rss_link($text = "RSS") {
$text = ($text == '') ? 'RSS' : $text;
return '<a href="'.esc_url(EM_RSS_URI).'">'.esc_html($text).'</a>';
}
/**
* Prints the result of em_get_rss_link()
* @param string $text
* @uses em_get_rss_link()
*/
function em_rss_link($text = "RSS"){ echo em_get_rss_link($text); }
/*
* ---------------------------------------------------------------------
* User Interfaces - Forms, Tables etc.
* ---------------------------------------------------------------------
*/
//Event Forms
/**
* Outputs the event submission form for guests and members.
* @param array $args
*/
function em_event_form($args = array()){
global $EM_Event;
if( get_option('dbem_css_editors') ) echo '<div class="css-event-form">';
if( !is_user_logged_in() && get_option('dbem_events_anonymous_submissions') && em_locate_template('forms/event-editor-guest.php') ){
em_locate_template('forms/event-editor-guest.php',true, array('args'=>$args));
}else{
if( !empty($_REQUEST['success']) ){
$EM_Event = new EM_Event(); //reset the event
}
if( empty($EM_Event->event_id) ){
$EM_Event = ( is_object($EM_Event) && get_class($EM_Event) == 'EM_Event') ? $EM_Event : new EM_Event();
//Give a default location & category
$default_cat = get_option('dbem_default_category');
$default_loc = get_option('dbem_default_location');
if( get_option('dbem_categories_enabled') && is_numeric($default_cat) && $default_cat > 0 && !empty($EM_Event->get_categories()->categories) ){
$EM_Category = new EM_Category($default_cat);
$EM_Event->get_categories()->categories[] = $EM_Category;
}
if( is_numeric($default_loc) && $default_loc > 0 && ( empty($EM_Event->get_location()->location_id) && empty($EM_Event->get_location()->location_name) && empty($EM_Event->get_location()->location_address) && empty($EM_Event->get_location()->location_town) ) ){
$EM_Event->location_id = $default_loc;
$EM_Event->location = new EM_Location($default_loc);
}
}
em_locate_template('forms/event-editor.php',true, array('args'=>$args));
}
if( get_option('dbem_css_editors') ) echo '</div>';
wp_enqueue_style('dashicons');
}
/**
* Retreives the event submission form for guests and members.
* @param array $args
*/
function em_get_event_form( $args = array() ){
ob_start();
em_event_form($args);
return ob_get_clean();
}
/**
* Outputs table of events belonging to user
* Additional search arguments:
* * show_add_new - passes argument to template as $show_add_new whether to show the add new event button
* @param array $args
*/
function em_events_admin($args = array()){
global $EM_Event, $EM_Notices, $bp;
if( is_user_logged_in() && current_user_can('edit_events') ){
if( (!empty($_GET['action']) && $_GET['action']=='edit') || (!empty($_POST['action']) && $_POST['action']=='event_save') ){
if( empty($_REQUEST['redirect_to']) ){
$_REQUEST['redirect_to'] = em_add_get_params($_SERVER['REQUEST_URI'], array('action'=>null, 'event_id'=>null));
}
em_event_form();
}else{
if( get_option('dbem_css_editors') ) echo '<div class="css-events-admin">';
//get listing options for $args
$limit = ( !empty($_REQUEST['limit']) ) ? $_REQUEST['limit'] : 20;//Default limit
$page = ( !empty($_REQUEST['pno']) ) ? $_REQUEST['pno']:1;
$offset = ( $page > 1 ) ? ($page-1)*$limit : 0;
$order = ( !empty($_REQUEST ['order']) ) ? $_REQUEST ['order']:'ASC';
$search = ( !empty($_REQUEST['em_search']) ) ? $_REQUEST['em_search']:'';
//deal with view or scope/status combinations
$show_add_new = isset($args['show_add_new']) ? $args['show_add_new']:true;
$args = array('order' => $order, 'search' => $search, 'owner' => get_current_user_id());
if( current_user_can('edit_others_events') && !empty($_GET['admin_mode']) ){
$args['owner'] = false;
}
if( !empty($_REQUEST['recurrence_id']) ){
$Event = em_get_event( absint($_REQUEST['recurrence_id']) );
$EM_Notices->add_alert(sprintf(esc_html__('You are viewing individual recurrences of recurring event %s.', 'events-manager'), '<a href="'.$Event->get_edit_url().'">'.$Event->event_name.'</a>'));
$EM_Notices->add_alert(esc_html__('You can edit individual recurrences and disassociate them with this recurring event.', 'events-manager'));
$args['recurrence_id'] = absint($_REQUEST['recurrence_id']);
}
$args = apply_filters('em_events_admin_args', $args);
//template $args for different views
$args_views = array();
$args_views['pending'] = array_merge($args, array('status'=>0, 'scope' => 'all', 'recurring'=>'include'));
$args_views['draft'] = array_merge($args, array('status'=>null, 'scope' => 'all', 'recurring'=>'include'));
$args_views['past'] = array_merge($args, array('status'=>'all', 'scope' => 'past'));
$args_views['future'] = array_merge($args, array('status'=>'1', 'scope' => 'future'));
//modify $args for current view
if( !empty($_REQUEST['view']) && in_array($_REQUEST['view'], array('future','draft','past','pending')) ){
$args = array_merge($args, $args_views[$_REQUEST['view']]);
}else{
$scope_names = em_get_scopes();
$args['scope'] = ( !empty($_REQUEST ['scope']) && array_key_exists($_REQUEST ['scope'], $scope_names) ) ? $_REQUEST ['scope']:'future';
if( array_key_exists('status', $_REQUEST) ){
$status = ($_REQUEST['status']) ? 1:0;
if($_REQUEST['status'] == 'all') $status = 'all';
if($_REQUEST['status'] == 'draft') $status = null;
}else{
$status = false;
}
$args['status'] = $status;
}
//reset the limit and offset to allow for filter
unset($args['limit']); unset($args['offset']);
$events_count = EM_Events::count( $args ); //count events without limits for pagination
//add limit and offset again to args
$args['limit'] = $limit;
$args['offset'] = $offset;
$EM_Events = EM_Events::get( $args ); //now get the limited events to display
$future_count = EM_Events::count( $args_views['future'] );
$pending_count = EM_Events::count( $args_views['pending'] );
$draft_count = EM_Events::count( $args_views['draft'] );
$past_count = EM_Events::count( $args_views['past'] );
em_locate_template('tables/events.php',true, array(
'args'=>$args,
'EM_Events'=>$EM_Events,
'events_count'=>$events_count,
'future_count'=>$future_count,
'pending_count'=>$pending_count,
'draft_count'=>$draft_count,
'past_count'=>$past_count,
'page' => $page,
'limit' => $limit,
'offset' => $offset,
'show_add_new' => $show_add_new
));
if( get_option('dbem_css_editors') ) echo '</div>';
}
}elseif( !is_user_logged_in() && get_option('dbem_events_anonymous_submissions') ){
em_event_form($args);
}else{
if( get_option('dbem_css_editors') ) echo '<div class="css-events-admin">';
echo '<div class="css-events-admin-login">'. apply_filters('em_event_submission_login', __("You must log in to view and manage your events.",'events-manager')) . '</div>';
if( get_option('dbem_css_editors') ) echo '</div>';
}
}
/**
* Retreives table of events belonging to user
* @param array $args
*/
function em_get_events_admin( $args = array() ){
ob_start();
em_events_admin($args);
return ob_get_clean();
}
/**
* Outputs the event search form.
* @param array $args
*/
function em_event_search_form($args = array()){
$args = em_get_search_form_defaults($args);
$args['ajax'] = isset($args['ajax']) ? $args['ajax']:(!defined('EM_AJAX') || EM_AJAX );
em_locate_template('templates/events-search.php',true, array('args'=>$args));
}
/**
* Retreives the event search form.
* @param array $args
*/
function em_get_event_search_form( $args = array() ){
ob_start();
em_event_search_form($args);
return ob_get_clean();
}
//Location Forms
/**
* Outputs the location submission form for guests and members.
* @param array $args
*/
function em_location_form($args = array()){
global $EM_Location;
if( get_option('dbem_css_editors') ) echo '<div class="css-location-form">';
$EM_Location = ( is_object($EM_Location) && get_class($EM_Location) == 'EM_Location') ? $EM_Location : new EM_Location();
em_locate_template('forms/location-editor.php',true);
if( get_option('dbem_css_editors') ) echo '</div>';
}
/**
* Retreives the location submission form for guests and members.
* @param array $args
*/
function em_get_location_form( $args = array() ){
ob_start();
em_location_form($args);
return ob_get_clean();
}
/**
* Outputs table of locations belonging to user
* @param array $args
*/
function em_locations_admin($args = array()){
global $EM_Location;
if( is_user_logged_in() && current_user_can('edit_locations') ){
if( !empty($_GET['action']) && $_GET['action']=='edit' ){
if( empty($_REQUEST['redirect_to']) ){
$_REQUEST['redirect_to'] = em_add_get_params($_SERVER['REQUEST_URI'], array('action'=>null, 'location_id'=>null));
}
em_location_form();
}else{
if( get_option('dbem_css_editors') ) echo '<div class="css-locations-admin">';
$limit = ( !empty($_REQUEST['limit']) ) ? $_REQUEST['limit'] : 20;//Default limit
$page = ( !empty($_REQUEST['pno']) ) ? $_REQUEST['pno']:1;
$offset = ( $page > 1 ) ? ($page-1)*$limit : 0;
$order = ( !empty($_REQUEST ['order']) ) ? $_REQUEST ['order']:'ASC';
if( array_key_exists('status', $_REQUEST) ){
$status = ($_REQUEST['status']) ? 1:0;
}else{
$status = false;
}
$blog = false;
if( EM_MS_GLOBAL && !get_site_option('dbem_ms_mainblog_locations') && !is_main_site() ){
//set current blog id if not on main site and using global mode whilst not forcing all locations to be on main blog
$blog = get_current_blog_id();
}
$args = array('limit'=>$limit, 'offset'=>$offset, 'status'=>$status, 'blog'=>$blog);
//count locations
$locations_mine_count = EM_Locations::count( array('owner'=>get_current_user_id(), 'blog'=>$blog, 'status'=>false) );
$locations_all_count = current_user_can('read_others_locations') ? EM_Locations::count(array('blog'=>$blog, 'status'=>false, 'owner'=>false)):0;
//get set of locations
if( !empty($_REQUEST['view']) && $_REQUEST['view'] == 'others' && current_user_can('read_others_locations') ){
$locations = EM_Locations::get($args);
$locations_count = $locations_all_count;
}else{
$locations = EM_Locations::get( array_merge($args, array('owner'=>get_current_user_id())) );
$locations_count = $locations_mine_count;
}
em_locate_template('tables/locations.php',true, array(
'args'=>$args,
'locations'=>$locations,
'locations_count'=>$locations_count,
'locations_mine_count'=>$locations_mine_count,
'locations_all_count'=>$locations_all_count,
'page' => $page,
'limit' => $limit,
'offset' => $offset,
'show_add_new' => true
));
if( get_option('dbem_css_editors') ) echo '</div>';
}
}else{
if( get_option('dbem_css_editors') ) echo '<div class="css-locations-admin">';
echo '<div class="css-locations-admin-login">'. __("You must log in to view and manage your locations.",'events-manager') .'</div>';
if( get_option('dbem_css_editors') ) echo '</div>';
}
}
/**
* Retreives table of locations belonging to user
* @param array $args
*/
function em_get_locations_admin( $args = array() ){
ob_start();
em_locations_admin($args);
return ob_get_clean();
}
/**
* Outputs the location search form.
* @param array $args
*/
function em_location_search_form($args = array()){
$args = em_get_search_form_defaults($args, 'locations');
$args['ajax'] = isset($args['ajax']) ? $args['ajax']:(!defined('EM_AJAX') || EM_AJAX );
em_locate_template('templates/locations-search.php',true, array('args'=>$args));
}
/**
* Retreives the event search form.
* @param array $args
*/
function em_get_location_search_form( $args = array() ){
ob_start();
em_location_search_form($args);
return ob_get_clean();
}
//Bookings Pages
function em_bookings_admin(){
if( get_option('dbem_css_rsvpadmin') ) echo '<div class="css-bookings-admin">';
if( is_user_logged_in() && current_user_can('manage_bookings') ){
global $wpdb, $current_user, $EM_Notices;
include_once(EM_DIR.'/admin/em-bookings.php');
include_once(EM_DIR.'/admin/em-admin.php');
include_once(EM_DIR.'/admin/bookings/em-cancelled.php');
include_once(EM_DIR.'/admin/bookings/em-confirmed.php');
include_once(EM_DIR.'/admin/bookings/em-events.php');
include_once(EM_DIR.'/admin/bookings/em-pending.php');
include_once(EM_DIR.'/admin/bookings/em-person.php');
include_once(EM_DIR.'/admin/bookings/em-rejected.php');
em_bookings_page();
}else{
echo '<div class="css-bookings-admin-login">'. __("You must log in to view and manage your bookings.",'events-manager') .'</div>';
}
if( get_option('dbem_css_rsvpadmin') ) echo '</div>';
}
function em_get_bookings_admin(){
ob_start();
em_bookings_admin();
return ob_get_clean();
}
function em_my_bookings(){
if( get_option('dbem_css_rsvp') ) echo '<div class="css-my-bookings">';
em_locate_template('templates/my-bookings.php', true);
if( get_option('dbem_css_rsvp') ) echo '</div>';
}
function em_get_my_bookings(){
ob_start();
em_my_bookings();
return ob_get_clean();
}
/*
* ---------------------------------------------------------------------
* Conditionals - Yes/No functions
* ---------------------------------------------------------------------
*/
/**
* Returns whether or not this object is an event or not. This can be a loose verification method by supplying an EM_Event object, post object, post_id, or simply the post type.
* If you want to ensure this is an EM_Event or child of EM_Event, pass the second parameter $require_object as true to force an EM_Event object check.
* @param EM_Event|WP_Post|string|int $data
* @param bool $object_required
* @return bool
* @since 5.9.7
*/
function em_is_event( $data, $object_required = false ){
if( is_object($data) && !empty($data->post_type) ){
// we assume it's either a EM_Event class type or just a WP_Post object
$post_type = $data->post_type;
$is_event_object = get_class($data) == 'EM_Event' || is_subclass_of($data, 'EM_Object');
}elseif( is_numeric($data) ){
// we assume we were passed a post_id
$post_type = get_post_type($data);
}elseif( is_string($data) ){
// we assume we were passed a post type
$post_type = $data;
}
if( !empty($post_type) ){
$is_event_post_type = $post_type == EM_POST_TYPE_EVENT || $post_type == 'event-recurring';
return $is_event_post_type && (!$object_required || !empty($is_event_object));
}
return false;
}
/**
* Returns whether or not this object is an location or not. This can be a loose verification method by supplying an EM_Location object, post object, post_id or simply the post type.
* If you want to ensure this is an EM_Location or child of EM_Location, pass the second parameter $require_object as true to force an EM_Location object check.
* @param EM_Location|WP_Post|string|int $data
* @param bool $object_required
* @return bool
* @since 5.9.7
*/
function em_is_location( $data, $object_required = false ){
if( is_object($data) && !empty($data->post_type) ){
// we assume it's either a EM_Location class type or just a WP_Post object
$post_type = $data->post_type;
$is_location_object = get_class($data) == 'EM_Location' || is_subclass_of($data, 'EM_Object');
}elseif( is_numeric($data) ){
// we assume we were passed a post_id
$post_type = get_post_type($data);
}elseif( is_string($data) ){
// we assume we were passed a post type
$post_type = $data;
}
if( !empty($post_type) ){
$is_location_post_type = $post_type == EM_POST_TYPE_LOCATION;
return $is_location_post_type && (!$object_required || !empty($is_location_object));
}
return false;
}
/**
* Returns true if there are any events that exist in the given scope (default is future events).
* @param string $scope
* @return boolean
*/
function em_are_events_available($scope = "future") {
$scope = ($scope == "") ? "future":$scope;
$events = EM_Events::get( array('limit'=>1, 'scope'=>$scope) );
return ( count($events) > 0 );
}
/**
* Returns true if the page is the events page. this is now only an events page, before v4.0.83 this would be true for any multiple page (e.g. locations)
* @return boolean
*/
function em_is_events_page() {
global $post;
return em_get_page_type() == 'events';
}
/**
* Is this a a single event page?
* @return boolean
*/
function em_is_event_page(){
return em_get_page_type() == 'event';
}
/**
* Is this a a single calendar day page?
* @return boolean
*/
function em_is_calendar_day_page(){
return em_get_page_type() == 'calendar_day';
}
/**
* Is this a a single category page?
* @return boolean
*/
function em_is_category_page( $category = false ){
if( !empty($category) ){
global $wp_query, $post, $em_category_id;
if( is_tax(EM_TAXONOMY_CATEGORY, $category) ){ return true; }
if( !empty($wp_query->em_category_id) || ($post->ID == get_option('dbem_categories_page') && !empty($em_category_id)) ){
$cat_id = !empty($wp_query->em_category_id) ? $wp_query->em_category_id:$em_category_id;
$EM_Category = em_get_category($cat_id);
if( is_array($category) ){
$is_category = array();
foreach( $category as $id_or_term ){
$is_category[] = is_numeric($id_or_term) ? $EM_Category->id == $id_or_term : ($EM_Category->slug == $id_or_term || $EM_Category->name == $id_or_term);
}
return in_array(true, $is_category);
}else{
$is_category = is_numeric($category) ? $EM_Category->id == $category : ($EM_Category->slug == $category || $EM_Category->name == $category);
return $is_category;
}
return false;
}
return false;
}
return em_get_page_type() == 'category';
}
/**
* Is this a categories list page?
* @return boolean
*/
function em_is_categories_page(){
return em_get_page_type() == 'categories';
}
/**
* Is this a a single category page?
* @return boolean
*/
function em_is_tag_page( $tag = false ){
if( !empty($tag) ){
global $wp_query, $post, $em_tag_id;
if( is_tax(EM_TAXONOMY_TAG, $tag) ){ return true; }
if( !empty($wp_query->em_tag_id) || !empty($em_tag_id) ){
$tag_id = !empty($wp_query->em_tag_id) ? $wp_query->em_tag_id:$em_tag_id;
$EM_Tag = em_get_tag($tag_id);
if( is_array($tag) ){
$is_tag = array();
foreach( $tag as $id_or_term ){
$is_tag[] = is_numeric($id_or_term) ? $EM_Tag->id == $id_or_term : ($EM_Tag->slug == $id_or_term || $EM_Tag->name == $id_or_term);
}
return in_array(true, $is_tag);
}else{
$is_tag = is_numeric($tag) ? $EM_Tag->id == $tag : ($EM_Tag->slug == $tag || $EM_Tag->name == $tag);
return $is_tag;
}
return false;
}
return false;
}
return em_get_page_type() == 'tag';
}
/**
* Is this a a single location page?
* @return boolean
*/
function em_is_location_page(){
return em_get_page_type() == 'location';
}
/**
* Is this a locations list page?
* @return boolean
*/
function em_is_locations_page(){
return em_get_page_type() == 'locations';
}
/**
* Is this my bookings page?
* @return boolean
*/
function em_is_my_bookings_page(){
return em_get_page_type() == 'my_bookings';
}
/**
* Returns true if this is a single events page and the event is RSVPable
* @return boolean
*/
function em_is_event_rsvpable() {
//We assume that we're on a single event (or recurring event) page here, so $EM_Event must be loaded
global $EM_Event;
return ( em_is_event_page() && $EM_Event->rsvp );
}
?>