conditionals.php
4.14 KB
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
<?php
/**
* Conditional functions. Boolean functions testing calendar and event conditions.
*
* @category Utilities
* @package My Calendar
* @author Joe Dolson
* @license GPLv2 or later
* @link https://www.joedolson.com/my-calendar/
*/
if ( ! defined( 'ABSPATH' ) ) {
exit;
}
/**
* Determine whether an event is recurring.
*
* @param object $event Event object.
*
* @return bool
*/
function mc_is_recurring( $event ) {
$is_recurring = ( ! ( 'S' === $event->event_recur || 'S1' === $event->event_recur ) ) ? true : false;
return $is_recurring;
}
/**
* Test an event and see if it's an all day event.
*
* @param object $event Event object.
*
* @return boolean
*/
function mc_is_all_day( $event ) {
return ( '00:00:00' === $event->event_time && '23:59:59' === $event->event_endtime ) ? true : false;
}
/**
* Check whether using custom or stock icons.
*
* @return boolean
*/
function mc_is_custom_icon() {
$on = ( WP_DEBUG ) ? false : get_transient( 'mc_custom_icons' );
$dir = trailingslashit( dirname( __FILE__, 2 ) );
$base = trailingslashit( basename( $dir ) );
$custom = ( file_exists( str_replace( $base, '', $dir ) . 'my-calendar-custom/icons' ) );
if ( ! $custom ) {
// backcompat for old icon directories.
$custom = ( file_exists( str_replace( $base, '', $dir ) . 'my-calendar-custom/icons' ) );
}
$return = false;
if ( $on && $custom ) {
$return = true;
} else {
$dir = trailingslashit( dirname( __FILE__, 2 ) );
$base = trailingslashit( basename( $dir ) );
if ( $custom ) {
$results = mc_directory_list( str_replace( $base, '', $dir ) . 'my-calendar-custom/icons' );
if ( empty( $results ) ) {
$results = mc_directory_list( str_replace( $base, '', $dir ) . 'my-calendar-custom' );
if ( empty( $results ) ) {
$return = false;
}
} else {
$return = true;
}
set_transient( 'mc_custom_icons', true, HOUR_IN_SECONDS );
}
}
return $return;
}
/**
* Test whether currently mobile using wp_is_mobile() with custom filter
*
* @return boolean
*/
function mc_is_mobile() {
$mobile = false;
if ( function_exists( 'wp_is_mobile' ) ) {
$mobile = wp_is_mobile();
}
return apply_filters( 'mc_is_mobile', $mobile );
}
/**
* Provides a filter for custom dev. Not used in core.
*
* @return boolean
*/
function mc_is_tablet() {
return apply_filters( 'mc_is_tablet', false );
}
/**
* Check whether this is a valid preview scenario.
*
* @return boolean
*/
function mc_is_preview() {
if ( isset( $_GET['preview'] ) && 'true' === $_GET['preview'] && current_user_can( 'mc_manage_events' ) ) {
return true;
}
return false;
}
/**
* Check whether this event is targeted for an iFrame.
*
* @return boolean
*/
function mc_is_iframe() {
if ( isset( $_GET['iframe'] ) && 'true' === $_GET['iframe'] && isset( $_GET['mc_id'] ) ) {
return true;
}
return false;
}
/**
* Check whether this event is supposed to show template output.
*
* @return boolean
*/
function mc_is_tag_view() {
if ( isset( $_GET['showtags'] ) && 'true' === $_GET['showtags'] && current_user_can( 'mc_add_events' ) ) {
return true;
}
return false;
}
/**
* Identify whether a given file is a custom style or a core style
*
* @param string $filename File name..
*
* @return boolean
*/
function mc_is_custom_style( $filename ) {
if ( 0 === strpos( $filename, 'mc_custom_' ) ) {
return true;
} else {
return false;
}
}
/**
* Check whether the current key refers to a core template
*
* @param string $key Template unique key.
*
* @return boolean
*/
function mc_is_core_template( $key ) {
switch ( $key ) {
case 'grid':
case 'details':
case 'list':
case 'mini':
$return = true;
break;
default:
$return = false;
}
return $return;
}
/**
* Check whether a view is a singular event view.
*
* @return bool
*/
function mc_is_single_event() {
if ( is_singular( 'mc-events' ) ) {
return true;
}
if ( isset( $_GET['mc_id'] ) && mc_valid_id( $_GET['mc_id'] ) ) {
return true;
}
return false;
}