@@ -14,24 +14,24 @@ discard block |
||
14 | 14 | */ |
15 | 15 | |
16 | 16 | // Exit if accessed directly. |
17 | -if ( ! defined( 'ABSPATH' ) ) { |
|
17 | +if ( ! defined('ABSPATH')) { |
|
18 | 18 | exit; |
19 | 19 | } |
20 | 20 | |
21 | 21 | // Plugin constants. |
22 | -$this_plugin_path = trailingslashit( dirname( __FILE__ ) ); |
|
23 | -$this_plugin_dir = plugin_dir_url( __FILE__ ); |
|
22 | +$this_plugin_path = trailingslashit(dirname(__FILE__)); |
|
23 | +$this_plugin_dir = plugin_dir_url(__FILE__); |
|
24 | 24 | $this_plugin_constants = array( |
25 | 25 | 'SIMPLE_CALENDAR_VERSION' => '3.0.15', |
26 | 26 | 'SIMPLE_CALENDAR_MAIN_FILE' => __FILE__, |
27 | 27 | 'SIMPLE_CALENDAR_URL' => $this_plugin_dir, |
28 | - 'SIMPLE_CALENDAR_ASSETS' => $this_plugin_dir . 'assets/', |
|
28 | + 'SIMPLE_CALENDAR_ASSETS' => $this_plugin_dir.'assets/', |
|
29 | 29 | 'SIMPLE_CALENDAR_PATH' => $this_plugin_path, |
30 | - 'SIMPLE_CALENDAR_INC' => $this_plugin_path . 'includes/', |
|
30 | + 'SIMPLE_CALENDAR_INC' => $this_plugin_path.'includes/', |
|
31 | 31 | ); |
32 | -foreach ( $this_plugin_constants as $constant => $value ) { |
|
33 | - if ( ! defined( $constant ) ) { |
|
34 | - define( $constant, $value ); |
|
32 | +foreach ($this_plugin_constants as $constant => $value) { |
|
33 | + if ( ! defined($constant)) { |
|
34 | + define($constant, $value); |
|
35 | 35 | } |
36 | 36 | } |
37 | 37 | |
@@ -40,7 +40,7 @@ discard block |
||
40 | 40 | include_once 'includes/wp-requirements.php'; |
41 | 41 | |
42 | 42 | // Check plugin requirements before loading plugin. |
43 | -$this_plugin_checks = new SimCal_WP_Requirements( 'Simple Calendar', plugin_basename( __FILE__ ), array( |
|
43 | +$this_plugin_checks = new SimCal_WP_Requirements('Simple Calendar', plugin_basename(__FILE__), array( |
|
44 | 44 | 'PHP' => '5.3.3', |
45 | 45 | 'WordPress' => '4.1', |
46 | 46 | 'Extensions' => array( |
@@ -49,8 +49,8 @@ discard block |
||
49 | 49 | 'json', |
50 | 50 | 'mbstring', |
51 | 51 | ), |
52 | - ) ); |
|
53 | -if ( $this_plugin_checks->pass() === false ) { |
|
52 | + )); |
|
53 | +if ($this_plugin_checks->pass() === false) { |
|
54 | 54 | $this_plugin_checks->halt(); |
55 | 55 | |
56 | 56 | return; |
@@ -12,7 +12,7 @@ discard block |
||
12 | 12 | use SimpleCalendar\Abstracts\Feed; |
13 | 13 | use SimpleCalendar\Feeds\Admin\Google_Admin as Admin; |
14 | 14 | |
15 | -if ( ! defined( 'ABSPATH' ) ) { |
|
15 | +if ( ! defined('ABSPATH')) { |
|
16 | 16 | exit; |
17 | 17 | } |
18 | 18 | |
@@ -90,35 +90,35 @@ discard block |
||
90 | 90 | * @param string|Calendar $calendar |
91 | 91 | * @param bool $load_admin |
92 | 92 | */ |
93 | - public function __construct( $calendar = '', $load_admin = true ) { |
|
93 | + public function __construct($calendar = '', $load_admin = true) { |
|
94 | 94 | |
95 | - parent::__construct( $calendar ); |
|
95 | + parent::__construct($calendar); |
|
96 | 96 | |
97 | 97 | $this->type = 'google'; |
98 | - $this->name = __( 'Google Calendar', 'google-calendar-events' ); |
|
98 | + $this->name = __('Google Calendar', 'google-calendar-events'); |
|
99 | 99 | |
100 | 100 | // Google client config. |
101 | - $settings = get_option( 'simple-calendar_settings_feeds' ); |
|
102 | - $this->google_api_key = isset( $settings['google']['api_key'] ) ? esc_attr( $settings['google']['api_key'] ) : ''; |
|
103 | - $this->google_client_scopes = array( \Google_Service_Calendar::CALENDAR_READONLY ); |
|
101 | + $settings = get_option('simple-calendar_settings_feeds'); |
|
102 | + $this->google_api_key = isset($settings['google']['api_key']) ? esc_attr($settings['google']['api_key']) : ''; |
|
103 | + $this->google_client_scopes = array(\Google_Service_Calendar::CALENDAR_READONLY); |
|
104 | 104 | $this->google_client = $this->get_client(); |
105 | 105 | |
106 | - if ( $this->post_id > 0 ) { |
|
106 | + if ($this->post_id > 0) { |
|
107 | 107 | |
108 | 108 | // Google query args. |
109 | - $this->google_calendar_id = $this->esc_google_calendar_id( get_post_meta( $this->post_id, '_google_calendar_id', true ) ); |
|
110 | - $this->google_events_recurring = esc_attr( get_post_meta( $this->post_id, '_google_events_recurring', true ) ); |
|
109 | + $this->google_calendar_id = $this->esc_google_calendar_id(get_post_meta($this->post_id, '_google_calendar_id', true)); |
|
110 | + $this->google_events_recurring = esc_attr(get_post_meta($this->post_id, '_google_events_recurring', true)); |
|
111 | 111 | // note that google_search_query is used in a URL param and not as HTML output, so don't use esc_attr() on it |
112 | - $this->google_search_query = get_post_meta( $this->post_id, '_google_events_search_query', true ); |
|
113 | - $this->google_max_results = max( absint( get_post_meta( $this->post_id, '_google_events_max_results', true ) ), 1 ); |
|
112 | + $this->google_search_query = get_post_meta($this->post_id, '_google_events_search_query', true); |
|
113 | + $this->google_max_results = max(absint(get_post_meta($this->post_id, '_google_events_max_results', true)), 1); |
|
114 | 114 | |
115 | - if ( ! is_admin() || defined( 'DOING_AJAX' ) ) { |
|
116 | - $this->events = ! empty( $this->google_api_key ) ? $this->get_events() : array(); |
|
115 | + if ( ! is_admin() || defined('DOING_AJAX')) { |
|
116 | + $this->events = ! empty($this->google_api_key) ? $this->get_events() : array(); |
|
117 | 117 | } |
118 | 118 | } |
119 | 119 | |
120 | - if ( is_admin() && $load_admin ) { |
|
121 | - $admin = new Admin( $this, $this->google_api_key, $this->google_calendar_id ); |
|
120 | + if (is_admin() && $load_admin) { |
|
121 | + $admin = new Admin($this, $this->google_api_key, $this->google_calendar_id); |
|
122 | 122 | $this->settings = $admin->settings_fields(); |
123 | 123 | } |
124 | 124 | } |
@@ -132,8 +132,8 @@ discard block |
||
132 | 132 | * |
133 | 133 | * @return string |
134 | 134 | */ |
135 | - public function esc_google_calendar_id( $id ) { |
|
136 | - return base64_decode( $id ); |
|
135 | + public function esc_google_calendar_id($id) { |
|
136 | + return base64_decode($id); |
|
137 | 137 | } |
138 | 138 | |
139 | 139 | /** |
@@ -147,85 +147,85 @@ discard block |
||
147 | 147 | */ |
148 | 148 | public function get_events() { |
149 | 149 | |
150 | - $calendar = get_transient( '_simple-calendar_feed_id_' . strval( $this->post_id ) . '_' . $this->type ); |
|
150 | + $calendar = get_transient('_simple-calendar_feed_id_'.strval($this->post_id).'_'.$this->type); |
|
151 | 151 | |
152 | - if ( empty( $calendar ) && ! empty( $this->google_calendar_id ) ) { |
|
152 | + if (empty($calendar) && ! empty($this->google_calendar_id)) { |
|
153 | 153 | |
154 | 154 | $error = ''; |
155 | 155 | |
156 | 156 | try { |
157 | - $response = $this->make_request( $this->google_calendar_id ); |
|
158 | - } catch ( \Exception $e ) { |
|
157 | + $response = $this->make_request($this->google_calendar_id); |
|
158 | + } catch (\Exception $e) { |
|
159 | 159 | $error .= $e->getMessage(); |
160 | 160 | } |
161 | 161 | |
162 | - if ( empty( $error ) && isset( $response['events'] ) && isset( $response['timezone'] ) ) { |
|
162 | + if (empty($error) && isset($response['events']) && isset($response['timezone'])) { |
|
163 | 163 | |
164 | - $calendar = array_merge( $response, array( 'events' => array() ) ); |
|
164 | + $calendar = array_merge($response, array('events' => array())); |
|
165 | 165 | |
166 | 166 | // If no timezone has been set, use calendar feed. |
167 | - if ( 'use_calendar' == $this->timezone_setting ) { |
|
167 | + if ('use_calendar' == $this->timezone_setting) { |
|
168 | 168 | $this->timezone = $calendar['timezone']; |
169 | 169 | } |
170 | 170 | |
171 | - $source = isset( $response['title'] ) ? sanitize_text_field( $response['title'] ) : ''; |
|
171 | + $source = isset($response['title']) ? sanitize_text_field($response['title']) : ''; |
|
172 | 172 | |
173 | - if ( ! empty( $response['events'] ) && is_array( $response['events'] ) ) { |
|
174 | - foreach ( $response['events'] as $event ) { |
|
175 | - if ( $event instanceof \Google_Service_Calendar_Event ) { |
|
173 | + if ( ! empty($response['events']) && is_array($response['events'])) { |
|
174 | + foreach ($response['events'] as $event) { |
|
175 | + if ($event instanceof \Google_Service_Calendar_Event) { |
|
176 | 176 | |
177 | 177 | // Visibility and status. |
178 | 178 | // Public calendars may have private events which can't be properly accessed by simple api key method. |
179 | 179 | // Also want to skip cancelled events (single occurences deleted from repeating events) |
180 | 180 | $visibility = $event->getVisibility(); |
181 | 181 | $status = $event->getStatus(); |
182 | - if ( $this->type == 'google' && ( $visibility == 'private' || $visibility == 'confidential' || $status == 'cancelled' ) ) { |
|
182 | + if ($this->type == 'google' && ($visibility == 'private' || $visibility == 'confidential' || $status == 'cancelled')) { |
|
183 | 183 | continue; |
184 | 184 | } |
185 | 185 | |
186 | 186 | // Event title & description. |
187 | - $title = strip_tags( $event->getSummary() ); |
|
188 | - $title = sanitize_text_field( iconv( mb_detect_encoding( $title, mb_detect_order(), true ), 'UTF-8', $title ) ); |
|
189 | - $description = wp_kses_post( iconv( mb_detect_encoding( $event->getDescription(), mb_detect_order(), true ), 'UTF-8', $event->getDescription() ) ); |
|
187 | + $title = strip_tags($event->getSummary()); |
|
188 | + $title = sanitize_text_field(iconv(mb_detect_encoding($title, mb_detect_order(), true), 'UTF-8', $title)); |
|
189 | + $description = wp_kses_post(iconv(mb_detect_encoding($event->getDescription(), mb_detect_order(), true), 'UTF-8', $event->getDescription())); |
|
190 | 190 | |
191 | 191 | $whole_day = false; |
192 | 192 | |
193 | 193 | // Event start properties. |
194 | - if( 'use_calendar' == $this->timezone_setting ) { |
|
194 | + if ('use_calendar' == $this->timezone_setting) { |
|
195 | 195 | $start_timezone = ! $event->getStart()->timeZone ? $calendar['timezone'] : $event->getStart()->timeZone; |
196 | 196 | } else { |
197 | 197 | $start_timezone = $this->timezone; |
198 | 198 | } |
199 | 199 | |
200 | - if ( is_null( $event->getStart()->dateTime ) ) { |
|
200 | + if (is_null($event->getStart()->dateTime)) { |
|
201 | 201 | // Whole day event. |
202 | - $date = Carbon::parse( $event->getStart()->date ); |
|
203 | - $google_start = Carbon::createFromDate( $date->year, $date->month, $date->day, $start_timezone )->startOfDay()->addSeconds( 59 ); |
|
204 | - $google_start_utc = Carbon::createFromDate( $date->year, $date->month, $date->day, 'UTC' )->startOfDay()->addSeconds( 59 ); |
|
202 | + $date = Carbon::parse($event->getStart()->date); |
|
203 | + $google_start = Carbon::createFromDate($date->year, $date->month, $date->day, $start_timezone)->startOfDay()->addSeconds(59); |
|
204 | + $google_start_utc = Carbon::createFromDate($date->year, $date->month, $date->day, 'UTC')->startOfDay()->addSeconds(59); |
|
205 | 205 | $whole_day = true; |
206 | 206 | } else { |
207 | - $date = Carbon::parse( $event->getStart()->dateTime ); |
|
207 | + $date = Carbon::parse($event->getStart()->dateTime); |
|
208 | 208 | |
209 | 209 | // Check if there is an event level timezone |
210 | - if( $event->getStart()->timeZone && 'use_calendar' == $this->timezone_setting ) { |
|
210 | + if ($event->getStart()->timeZone && 'use_calendar' == $this->timezone_setting) { |
|
211 | 211 | |
212 | 212 | // Get the two different times with the separate timezones so we can check the offsets next |
213 | - $google_start1 = Carbon::create( $date->year, $date->month, $date->day, $date->hour, $date->minute, $date->second, $date->timezone ); |
|
214 | - $google_start2 = Carbon::create( $date->year, $date->month, $date->day, $date->hour, $date->minute, $date->second, $event->getStart()->timeZone ); |
|
213 | + $google_start1 = Carbon::create($date->year, $date->month, $date->day, $date->hour, $date->minute, $date->second, $date->timezone); |
|
214 | + $google_start2 = Carbon::create($date->year, $date->month, $date->day, $date->hour, $date->minute, $date->second, $event->getStart()->timeZone); |
|
215 | 215 | |
216 | 216 | // Get the offset in hours |
217 | 217 | $offset1 = $google_start1->offsetHours; |
218 | 218 | $offset2 = $google_start2->offsetHours; |
219 | 219 | |
220 | 220 | // Get the difference between the two timezones |
221 | - $total_offset = ( $offset2 - $offset1 ); |
|
221 | + $total_offset = ($offset2 - $offset1); |
|
222 | 222 | |
223 | 223 | // Add the hours offset to the date hour |
224 | 224 | $date->hour += $total_offset; |
225 | 225 | } |
226 | 226 | |
227 | - $google_start = Carbon::create( $date->year, $date->month, $date->day, $date->hour, $date->minute, $date->second, $start_timezone ); |
|
228 | - $google_start_utc = Carbon::create( $date->year, $date->month, $date->day, $date->hour, $date->minute, $date->second, 'UTC' ); |
|
227 | + $google_start = Carbon::create($date->year, $date->month, $date->day, $date->hour, $date->minute, $date->second, $start_timezone); |
|
228 | + $google_start_utc = Carbon::create($date->year, $date->month, $date->day, $date->hour, $date->minute, $date->second, 'UTC'); |
|
229 | 229 | |
230 | 230 | $this->timezone = $start_timezone; |
231 | 231 | } |
@@ -236,43 +236,43 @@ discard block |
||
236 | 236 | |
237 | 237 | $end = $end_utc = $end_timezone = ''; |
238 | 238 | $span = 0; |
239 | - if ( false == $event->getEndTimeUnspecified() ) { |
|
239 | + if (false == $event->getEndTimeUnspecified()) { |
|
240 | 240 | |
241 | 241 | // Event end properties. |
242 | - if( 'use_calendar' == $this->timezone_setting ) { |
|
242 | + if ('use_calendar' == $this->timezone_setting) { |
|
243 | 243 | $end_timezone = ! $event->getEnd()->timeZone ? $calendar['timezone'] : $event->getEnd()->timeZone; |
244 | 244 | } else { |
245 | 245 | $end_timezone = $this->timezone; |
246 | 246 | } |
247 | 247 | |
248 | - if ( is_null( $event->getEnd()->dateTime ) ) { |
|
248 | + if (is_null($event->getEnd()->dateTime)) { |
|
249 | 249 | // Whole day event. |
250 | - $date = Carbon::parse( $event->getEnd()->date ); |
|
251 | - $google_end = Carbon::createFromDate( $date->year, $date->month, $date->day, $end_timezone )->startOfDay()->subSeconds( 59 ); |
|
252 | - $google_end_utc = Carbon::createFromDate( $date->year, $date->month, $date->day, 'UTC' )->startOfDay()->subSeconds( 59 ); |
|
250 | + $date = Carbon::parse($event->getEnd()->date); |
|
251 | + $google_end = Carbon::createFromDate($date->year, $date->month, $date->day, $end_timezone)->startOfDay()->subSeconds(59); |
|
252 | + $google_end_utc = Carbon::createFromDate($date->year, $date->month, $date->day, 'UTC')->startOfDay()->subSeconds(59); |
|
253 | 253 | } else { |
254 | - $date = Carbon::parse( $event->getEnd()->dateTime ); |
|
254 | + $date = Carbon::parse($event->getEnd()->dateTime); |
|
255 | 255 | |
256 | 256 | // Check if there is an event level timezone |
257 | - if( $event->getEnd()->timeZone && 'use_calendar' == $this->timezone_setting ) { |
|
257 | + if ($event->getEnd()->timeZone && 'use_calendar' == $this->timezone_setting) { |
|
258 | 258 | |
259 | 259 | // Get the two different times with the separate timezones so we can check the offsets next |
260 | - $google_start1 = Carbon::create( $date->year, $date->month, $date->day, $date->hour, $date->minute, $date->second, $date->timezone ); |
|
261 | - $google_start2 = Carbon::create( $date->year, $date->month, $date->day, $date->hour, $date->minute, $date->second, $event->getEnd()->timeZone ); |
|
260 | + $google_start1 = Carbon::create($date->year, $date->month, $date->day, $date->hour, $date->minute, $date->second, $date->timezone); |
|
261 | + $google_start2 = Carbon::create($date->year, $date->month, $date->day, $date->hour, $date->minute, $date->second, $event->getEnd()->timeZone); |
|
262 | 262 | |
263 | 263 | // Get the offset in hours |
264 | 264 | $offset1 = $google_start1->offsetHours; |
265 | 265 | $offset2 = $google_start2->offsetHours; |
266 | 266 | |
267 | 267 | // Get the difference between the two timezones |
268 | - $total_offset = ( $offset2 - $offset1 ); |
|
268 | + $total_offset = ($offset2 - $offset1); |
|
269 | 269 | |
270 | 270 | // Add the hours offset to the date hour |
271 | 271 | $date->hour += $total_offset; |
272 | 272 | } |
273 | 273 | |
274 | - $google_end = Carbon::create( $date->year, $date->month, $date->day, $date->hour, $date->minute, $date->second, $end_timezone ); |
|
275 | - $google_end_utc = Carbon::create( $date->year, $date->month, $date->day, $date->hour, $date->minute, $date->second, 'UTC' ); |
|
274 | + $google_end = Carbon::create($date->year, $date->month, $date->day, $date->hour, $date->minute, $date->second, $end_timezone); |
|
275 | + $google_end_utc = Carbon::create($date->year, $date->month, $date->day, $date->hour, $date->minute, $date->second, 'UTC'); |
|
276 | 276 | } |
277 | 277 | // End. |
278 | 278 | $end = $google_end->getTimestamp(); |
@@ -280,10 +280,10 @@ discard block |
||
280 | 280 | $end_utc = $google_end_utc->getTimestamp(); |
281 | 281 | |
282 | 282 | // Count multiple days. |
283 | - $span = $google_start->setTimezone( $calendar['timezone'] )->diffInDays( $google_end->setTimezone( $calendar['timezone'] ) ); |
|
283 | + $span = $google_start->setTimezone($calendar['timezone'])->diffInDays($google_end->setTimezone($calendar['timezone'])); |
|
284 | 284 | |
285 | - if ( $span == 0 ) { |
|
286 | - if ( $google_start->toDateString() !== $google_end->toDateString() ) { |
|
285 | + if ($span == 0) { |
|
286 | + if ($google_start->toDateString() !== $google_end->toDateString()) { |
|
287 | 287 | $span = 1; |
288 | 288 | } |
289 | 289 | } |
@@ -298,19 +298,19 @@ discard block |
||
298 | 298 | // Recurring event. |
299 | 299 | $recurrence = $event->getRecurrence(); |
300 | 300 | $recurring_id = $event->getRecurringEventId(); |
301 | - if ( ! $recurrence && $recurring_id ) { |
|
301 | + if ( ! $recurrence && $recurring_id) { |
|
302 | 302 | $recurrence = true; |
303 | 303 | } |
304 | 304 | |
305 | 305 | // Event link. |
306 | - if ( 'use_calendar' == $this->timezone_setting ) { |
|
307 | - $link = add_query_arg( array( 'ctz' => $this->timezone ), $event->getHtmlLink() ); |
|
306 | + if ('use_calendar' == $this->timezone_setting) { |
|
307 | + $link = add_query_arg(array('ctz' => $this->timezone), $event->getHtmlLink()); |
|
308 | 308 | } else { |
309 | 309 | $link = $event->getHtmlLink(); |
310 | 310 | } |
311 | 311 | |
312 | 312 | // Build the event. |
313 | - $calendar['events'][ intval( $start ) ][] = array( |
|
313 | + $calendar['events'][intval($start)][] = array( |
|
314 | 314 | 'type' => 'google-calendar', |
315 | 315 | 'source' => $source, |
316 | 316 | 'title' => $title, |
@@ -337,24 +337,24 @@ discard block |
||
337 | 337 | } |
338 | 338 | } |
339 | 339 | |
340 | - if ( ! empty( $calendar['events'] ) ) { |
|
340 | + if ( ! empty($calendar['events'])) { |
|
341 | 341 | |
342 | - ksort( $calendar['events'], SORT_NUMERIC ); |
|
342 | + ksort($calendar['events'], SORT_NUMERIC); |
|
343 | 343 | |
344 | 344 | set_transient( |
345 | - '_simple-calendar_feed_id_' . strval( $this->post_id ) . '_' . $this->type, |
|
345 | + '_simple-calendar_feed_id_'.strval($this->post_id).'_'.$this->type, |
|
346 | 346 | $calendar, |
347 | - max( absint( $this->cache ), 1 ) // Since a value of 0 means forever we set the minimum here to 1 if the user has set it to be 0 |
|
347 | + max(absint($this->cache), 1) // Since a value of 0 means forever we set the minimum here to 1 if the user has set it to be 0 |
|
348 | 348 | ); |
349 | 349 | } |
350 | 350 | } |
351 | 351 | |
352 | 352 | } else { |
353 | 353 | |
354 | - $message = __( 'While trying to retrieve events, Google returned an error:', 'google-calendar-events' ); |
|
355 | - $message .= '<br><br>' . $error . '<br><br>'; |
|
356 | - $message .= __( 'Please ensure that both your Google Calendar ID and API Key are valid and that the Google Calendar you want to display is public.', 'google-calendar-events' ) . '<br><br>'; |
|
357 | - $message .= __( 'Only you can see this notice.', 'google-calendar-events' ); |
|
354 | + $message = __('While trying to retrieve events, Google returned an error:', 'google-calendar-events'); |
|
355 | + $message .= '<br><br>'.$error.'<br><br>'; |
|
356 | + $message .= __('Please ensure that both your Google Calendar ID and API Key are valid and that the Google Calendar you want to display is public.', 'google-calendar-events').'<br><br>'; |
|
357 | + $message .= __('Only you can see this notice.', 'google-calendar-events'); |
|
358 | 358 | |
359 | 359 | return $message; |
360 | 360 | } |
@@ -362,11 +362,11 @@ discard block |
||
362 | 362 | } |
363 | 363 | |
364 | 364 | // If no timezone has been set, use calendar feed. |
365 | - if ( 'use_calendar' == $this->timezone_setting && isset( $calendar['timezone'] ) ) { |
|
365 | + if ('use_calendar' == $this->timezone_setting && isset($calendar['timezone'])) { |
|
366 | 366 | $this->timezone = $calendar['timezone']; |
367 | 367 | } |
368 | 368 | |
369 | - return isset( $calendar['events'] ) ? $calendar['events'] : array(); |
|
369 | + return isset($calendar['events']) ? $calendar['events'] : array(); |
|
370 | 370 | } |
371 | 371 | |
372 | 372 | /** |
@@ -382,67 +382,67 @@ discard block |
||
382 | 382 | * |
383 | 383 | * @throws \Exception On request failure will throw an exception from Google. |
384 | 384 | */ |
385 | - public function make_request( $id = '', $time_min = 0, $time_max = 0 ) { |
|
385 | + public function make_request($id = '', $time_min = 0, $time_max = 0) { |
|
386 | 386 | |
387 | 387 | $calendar = array(); |
388 | 388 | $google = $this->get_service(); |
389 | 389 | |
390 | - if ( ! is_null( $google ) && ! empty( $id ) ) { |
|
390 | + if ( ! is_null($google) && ! empty($id)) { |
|
391 | 391 | |
392 | 392 | // Build the request args. |
393 | 393 | $args = array(); |
394 | 394 | |
395 | 395 | // Expand recurring events. |
396 | - if ( $this->google_events_recurring == 'show' ) { |
|
396 | + if ($this->google_events_recurring == 'show') { |
|
397 | 397 | $args['singleEvents'] = true; |
398 | 398 | } |
399 | 399 | |
400 | 400 | // Query events using search terms. |
401 | - if ( ! empty( $this->google_search_query ) ) { |
|
402 | - $args['q'] = rawurlencode( $this->google_search_query ); |
|
401 | + if ( ! empty($this->google_search_query)) { |
|
402 | + $args['q'] = rawurlencode($this->google_search_query); |
|
403 | 403 | } |
404 | 404 | |
405 | 405 | // Max results to query. |
406 | - $args['maxResults'] = strval( min( absint( $this->google_max_results ), 2500 ) ); |
|
406 | + $args['maxResults'] = strval(min(absint($this->google_max_results), 2500)); |
|
407 | 407 | |
408 | 408 | // Specify a timezone. |
409 | 409 | $timezone = ''; |
410 | - if ( 'use_calendar' != get_post_meta( $this->post_id, '_feed_timezone_setting', true ) ) { |
|
410 | + if ('use_calendar' != get_post_meta($this->post_id, '_feed_timezone_setting', true)) { |
|
411 | 411 | $args['timeZone'] = $timezone = $this->timezone; |
412 | 412 | } |
413 | 413 | |
414 | 414 | // Lower bound (inclusive) for an event's end time to filter by. |
415 | - $earliest_event = intval( $this->time_min ); |
|
416 | - if ( $earliest_event > 0 ) { |
|
415 | + $earliest_event = intval($this->time_min); |
|
416 | + if ($earliest_event > 0) { |
|
417 | 417 | $timeMin = Carbon::now(); |
418 | - if ( ! empty( $timezone ) ) { |
|
419 | - $timeMin->setTimezone( $timezone ); |
|
418 | + if ( ! empty($timezone)) { |
|
419 | + $timeMin->setTimezone($timezone); |
|
420 | 420 | } |
421 | - $timeMin->setTimestamp( $earliest_event ); |
|
421 | + $timeMin->setTimestamp($earliest_event); |
|
422 | 422 | $args['timeMin'] = $timeMin->toRfc3339String(); |
423 | 423 | } |
424 | 424 | |
425 | 425 | // Upper bound (exclusive) for an event's start time to filter by. |
426 | - $latest_event = intval( $this->time_max ); |
|
427 | - if ( $latest_event > 0 ) { |
|
426 | + $latest_event = intval($this->time_max); |
|
427 | + if ($latest_event > 0) { |
|
428 | 428 | $timeMax = Carbon::now(); |
429 | - if ( ! empty( $timezone ) ) { |
|
430 | - $timeMax->setTimezone( $timezone ); |
|
429 | + if ( ! empty($timezone)) { |
|
430 | + $timeMax->setTimezone($timezone); |
|
431 | 431 | } |
432 | - $timeMax->setTimestamp( $latest_event ); |
|
432 | + $timeMax->setTimestamp($latest_event); |
|
433 | 433 | $args['timeMax'] = $timeMax->toRfc3339String(); |
434 | 434 | } |
435 | 435 | |
436 | 436 | // Query events in calendar. |
437 | - $response = $google->events->listEvents( $id, $args ); |
|
437 | + $response = $google->events->listEvents($id, $args); |
|
438 | 438 | |
439 | - if ( $response instanceof \Google_Service_Calendar_Events ) { |
|
439 | + if ($response instanceof \Google_Service_Calendar_Events) { |
|
440 | 440 | $calendar = array( |
441 | 441 | 'id' => $id, |
442 | 442 | 'title' => $response->getSummary(), |
443 | 443 | 'description' => $response->getDescription(), |
444 | 444 | 'timezone' => $response->getTimeZone(), |
445 | - 'url' => esc_url( '//www.google.com/calendar/embed?src=' . $id ), |
|
445 | + 'url' => esc_url('//www.google.com/calendar/embed?src='.$id), |
|
446 | 446 | 'events' => $response->getItems(), |
447 | 447 | ); |
448 | 448 | } |
@@ -462,10 +462,10 @@ discard block |
||
462 | 462 | private function get_client() { |
463 | 463 | |
464 | 464 | $client = new \Google_Client(); |
465 | - $client->setApplicationName( 'Simple Calendar' ); |
|
466 | - $client->setScopes( $this->google_client_scopes ); |
|
467 | - $client->setDeveloperKey( $this->google_api_key ); |
|
468 | - $client->setAccessType( 'online' ); |
|
465 | + $client->setApplicationName('Simple Calendar'); |
|
466 | + $client->setScopes($this->google_client_scopes); |
|
467 | + $client->setDeveloperKey($this->google_api_key); |
|
468 | + $client->setAccessType('online'); |
|
469 | 469 | |
470 | 470 | return $client; |
471 | 471 | } |
@@ -479,7 +479,7 @@ discard block |
||
479 | 479 | * @return null|\Google_Service_Calendar |
480 | 480 | */ |
481 | 481 | protected function get_service() { |
482 | - return $this->google_client instanceof \Google_Client ? new \Google_Service_Calendar( $this->google_client ) : null; |
|
482 | + return $this->google_client instanceof \Google_Client ? new \Google_Service_Calendar($this->google_client) : null; |
|
483 | 483 | } |
484 | 484 | |
485 | 485 | } |
@@ -13,7 +13,7 @@ discard block |
||
13 | 13 | use SimpleCalendar\Events\Event; |
14 | 14 | use SimpleCalendar\Calendars\Default_Calendar; |
15 | 15 | |
16 | -if ( ! defined( 'ABSPATH' ) ) { |
|
16 | +if ( ! defined('ABSPATH')) { |
|
17 | 17 | exit; |
18 | 18 | } |
19 | 19 | |
@@ -55,7 +55,7 @@ discard block |
||
55 | 55 | * |
56 | 56 | * @param string|Calendar $calendar |
57 | 57 | */ |
58 | - public function __construct( $calendar = '' ) { |
|
58 | + public function __construct($calendar = '') { |
|
59 | 59 | $this->calendar = $calendar; |
60 | 60 | } |
61 | 61 | |
@@ -89,7 +89,7 @@ discard block |
||
89 | 89 | * @return string |
90 | 90 | */ |
91 | 91 | public function get_name() { |
92 | - return __( 'Grid', 'google-calendar-events' ); |
|
92 | + return __('Grid', 'google-calendar-events'); |
|
93 | 93 | } |
94 | 94 | |
95 | 95 | /** |
@@ -98,8 +98,8 @@ discard block |
||
98 | 98 | * @since 3.0.0 |
99 | 99 | */ |
100 | 100 | public function add_ajax_actions() { |
101 | - add_action( 'wp_ajax_simcal_default_calendar_draw_grid', array( $this, 'draw_grid_ajax' ) ); |
|
102 | - add_action( 'wp_ajax_nopriv_simcal_default_calendar_draw_grid', array( $this, 'draw_grid_ajax' ) ); |
|
101 | + add_action('wp_ajax_simcal_default_calendar_draw_grid', array($this, 'draw_grid_ajax')); |
|
102 | + add_action('wp_ajax_nopriv_simcal_default_calendar_draw_grid', array($this, 'draw_grid_ajax')); |
|
103 | 103 | } |
104 | 104 | |
105 | 105 | /** |
@@ -113,16 +113,16 @@ discard block |
||
113 | 113 | * |
114 | 114 | * @return array |
115 | 115 | */ |
116 | - public function scripts( $min = '' ) { |
|
116 | + public function scripts($min = '') { |
|
117 | 117 | return array( |
118 | 118 | 'simcal-qtip' => array( |
119 | - 'src' => SIMPLE_CALENDAR_ASSETS . 'js/vendor/qtip' . $min . '.js', |
|
120 | - 'deps' => array( 'jquery' ), |
|
119 | + 'src' => SIMPLE_CALENDAR_ASSETS.'js/vendor/qtip'.$min.'.js', |
|
120 | + 'deps' => array('jquery'), |
|
121 | 121 | 'ver' => '2.2.1', |
122 | 122 | 'in_footer' => true, |
123 | 123 | ), |
124 | 124 | 'simcal-default-calendar' => array( |
125 | - 'src' => SIMPLE_CALENDAR_ASSETS . 'js/default-calendar' . $min . '.js', |
|
125 | + 'src' => SIMPLE_CALENDAR_ASSETS.'js/default-calendar'.$min.'.js', |
|
126 | 126 | 'deps' => array( |
127 | 127 | 'jquery', |
128 | 128 | 'simcal-qtip', |
@@ -147,15 +147,15 @@ discard block |
||
147 | 147 | * |
148 | 148 | * @return array |
149 | 149 | */ |
150 | - public function styles( $min = '' ) { |
|
150 | + public function styles($min = '') { |
|
151 | 151 | return array( |
152 | 152 | 'simcal-qtip' => array( |
153 | - 'src' => SIMPLE_CALENDAR_ASSETS . 'css/vendor/qtip' . $min . '.css', |
|
153 | + 'src' => SIMPLE_CALENDAR_ASSETS.'css/vendor/qtip'.$min.'.css', |
|
154 | 154 | 'ver' => '2.2.1', |
155 | 155 | 'media' => 'all', |
156 | 156 | ), |
157 | 157 | 'simcal-default-calendar-grid' => array( |
158 | - 'src' => SIMPLE_CALENDAR_ASSETS . 'css/default-calendar-grid' . $min . '.css', |
|
158 | + 'src' => SIMPLE_CALENDAR_ASSETS.'css/default-calendar-grid'.$min.'.css', |
|
159 | 159 | 'deps' => array( |
160 | 160 | 'simcal-qtip', |
161 | 161 | ), |
@@ -174,22 +174,22 @@ discard block |
||
174 | 174 | |
175 | 175 | $calendar = $this->calendar; |
176 | 176 | |
177 | - if ( $calendar instanceof Default_Calendar ) { |
|
177 | + if ($calendar instanceof Default_Calendar) { |
|
178 | 178 | |
179 | 179 | ?> |
180 | 180 | |
181 | - <?php edit_post_link( __( 'Edit Calendar', 'google-calendar-events' ), '<p class="simcal-align-right"><small>', '</small></p>', $calendar->id ); ?> |
|
181 | + <?php edit_post_link(__('Edit Calendar', 'google-calendar-events'), '<p class="simcal-align-right"><small>', '</small></p>', $calendar->id); ?> |
|
182 | 182 | |
183 | 183 | <table class="simcal-calendar-grid" |
184 | 184 | data-event-bubble-trigger="<?php echo $calendar->event_bubble_trigger; ?>"> |
185 | 185 | <thead class="simcal-calendar-head"> |
186 | 186 | <tr> |
187 | - <?php if ( ! $calendar->static ) { ?> |
|
188 | - <th class="simcal-nav simcal-prev-wrapper" colspan=colspan="<?php echo apply_filters( 'simcal_prev_cols', '1' ); ?>"> |
|
189 | - <button class="simcal-nav-button simcal-month-nav simcal-prev" title="<?php _e( 'Previous Month', 'google-calendar-events' ); ?>"><i class="simcal-icon-left"></i></button> |
|
187 | + <?php if ( ! $calendar->static) { ?> |
|
188 | + <th class="simcal-nav simcal-prev-wrapper" colspan=colspan="<?php echo apply_filters('simcal_prev_cols', '1'); ?>"> |
|
189 | + <button class="simcal-nav-button simcal-month-nav simcal-prev" title="<?php _e('Previous Month', 'google-calendar-events'); ?>"><i class="simcal-icon-left"></i></button> |
|
190 | 190 | </th> |
191 | 191 | <?php } ?> |
192 | - <th colspan="<?php echo apply_filters( 'simcal_current_cols', $calendar->static ? '7' : '5' ); ?>" |
|
192 | + <th colspan="<?php echo apply_filters('simcal_current_cols', $calendar->static ? '7' : '5'); ?>" |
|
193 | 193 | class="simcal-nav simcal-current" |
194 | 194 | data-calendar-current="<?php echo $calendar->start; ?>"> |
195 | 195 | <?php |
@@ -198,26 +198,26 @@ discard block |
||
198 | 198 | |
199 | 199 | // Display month and year according to user date format preference. |
200 | 200 | |
201 | - $year_pos = strcspn( $calendar->date_format, 'Y y' ); |
|
202 | - $month_pos = strcspn( $calendar->date_format, 'F M m n' ); |
|
201 | + $year_pos = strcspn($calendar->date_format, 'Y y'); |
|
202 | + $month_pos = strcspn($calendar->date_format, 'F M m n'); |
|
203 | 203 | |
204 | - $current = array( 'month' => 'F', 'year' => 'Y' ); |
|
204 | + $current = array('month' => 'F', 'year' => 'Y'); |
|
205 | 205 | |
206 | - if ( $year_pos < $month_pos ) { |
|
207 | - $current = array_reverse( $current ); |
|
206 | + if ($year_pos < $month_pos) { |
|
207 | + $current = array_reverse($current); |
|
208 | 208 | } |
209 | 209 | |
210 | - foreach ( $current as $k => $v ) { |
|
211 | - echo ' <span class="simcal-current-' . $k , '">' . date_i18n( $v, $calendar->start ) . '</span> '; |
|
210 | + foreach ($current as $k => $v) { |
|
211 | + echo ' <span class="simcal-current-'.$k, '">'.date_i18n($v, $calendar->start).'</span> '; |
|
212 | 212 | } |
213 | 213 | |
214 | 214 | echo '</h3>'; |
215 | 215 | |
216 | 216 | ?> |
217 | 217 | </th> |
218 | - <?php if ( ! $calendar->static ) { ?> |
|
219 | - <th class="simcal-nav simcal-next-wrapper" colspan="<?php echo apply_filters( 'simcal_next_cols', '1' ); ?>"> |
|
220 | - <button class="simcal-nav-button simcal-month-nav simcal-next" title="<?php _e( 'Next Month', 'google-calendar-events' ); ?>"><i class="simcal-icon-right"></i></button> |
|
218 | + <?php if ( ! $calendar->static) { ?> |
|
219 | + <th class="simcal-nav simcal-next-wrapper" colspan="<?php echo apply_filters('simcal_next_cols', '1'); ?>"> |
|
220 | + <button class="simcal-nav-button simcal-month-nav simcal-next" title="<?php _e('Next Month', 'google-calendar-events'); ?>"><i class="simcal-icon-right"></i></button> |
|
221 | 221 | </th> |
222 | 222 | <?php } ?> |
223 | 223 | </tr> |
@@ -227,28 +227,28 @@ discard block |
||
227 | 227 | // Print day names in short or long form for different viewport sizes. |
228 | 228 | |
229 | 229 | $week_starts = $calendar->week_starts; |
230 | - $week_days_short = simcal_get_calendar_names_i18n( 'day', 'short' ); |
|
231 | - $week_days_full = simcal_get_calendar_names_i18n( 'day', 'full' ); |
|
230 | + $week_days_short = simcal_get_calendar_names_i18n('day', 'short'); |
|
231 | + $week_days_full = simcal_get_calendar_names_i18n('day', 'full'); |
|
232 | 232 | |
233 | - for ( $i = $week_starts; $i <= 6; $i ++ ) : |
|
233 | + for ($i = $week_starts; $i <= 6; $i++) : |
|
234 | 234 | |
235 | 235 | ?> |
236 | 236 | <th class="simcal-week-day simcal-week-day-<?php echo $i ?>" |
237 | - data-screen-small="<?php echo mb_substr( $week_days_short[ $i ], 0, 1, 'UTF-8' ); ?>" |
|
238 | - data-screen-medium="<?php echo $week_days_short[ $i ]; ?>" |
|
239 | - data-screen-large="<?php echo $week_days_full[ $i ]; ?>"><?php echo $week_days_short[ $i ]; ?></th> |
|
237 | + data-screen-small="<?php echo mb_substr($week_days_short[$i], 0, 1, 'UTF-8'); ?>" |
|
238 | + data-screen-medium="<?php echo $week_days_short[$i]; ?>" |
|
239 | + data-screen-large="<?php echo $week_days_full[$i]; ?>"><?php echo $week_days_short[$i]; ?></th> |
|
240 | 240 | <?php |
241 | 241 | |
242 | 242 | endfor; |
243 | 243 | |
244 | - if ( $week_starts !== 0 ) : |
|
245 | - for ( $i = 0; $i < $week_starts; $i ++ ) : |
|
244 | + if ($week_starts !== 0) : |
|
245 | + for ($i = 0; $i < $week_starts; $i++) : |
|
246 | 246 | |
247 | 247 | ?> |
248 | 248 | <th class="simcal-week-day simcal-week-day-<?php echo $i ?>" |
249 | - data-screen-small="<?php echo mb_substr( $week_days_short[ $i ], 0, 1, 'UTF-8' ); ?>" |
|
250 | - data-screen-medium="<?php echo $week_days_short[ $i ]; ?>" |
|
251 | - data-screen-large="<?php echo $week_days_full[ $i ]; ?>"><?php echo $week_days_short[ $i ]; ?></th> |
|
249 | + data-screen-small="<?php echo mb_substr($week_days_short[$i], 0, 1, 'UTF-8'); ?>" |
|
250 | + data-screen-medium="<?php echo $week_days_short[$i]; ?>" |
|
251 | + data-screen-large="<?php echo $week_days_full[$i]; ?>"><?php echo $week_days_short[$i]; ?></th> |
|
252 | 252 | <?php |
253 | 253 | |
254 | 254 | endfor; |
@@ -258,7 +258,7 @@ discard block |
||
258 | 258 | </tr> |
259 | 259 | </thead> |
260 | 260 | |
261 | - <?php echo $this->draw_month( date( 'n', $calendar->start ), date( 'Y', $calendar->start ) ); ?> |
|
261 | + <?php echo $this->draw_month(date('n', $calendar->start), date('Y', $calendar->start)); ?> |
|
262 | 262 | |
263 | 263 | </table> |
264 | 264 | |
@@ -284,85 +284,85 @@ discard block |
||
284 | 284 | * |
285 | 285 | * @return string |
286 | 286 | */ |
287 | - private function draw_month( $month, $year, $id = 0 ) { |
|
287 | + private function draw_month($month, $year, $id = 0) { |
|
288 | 288 | |
289 | 289 | $calendar = $this->calendar; |
290 | - if ( empty( $calendar ) ) { |
|
291 | - $calendar = simcal_get_calendar( intval( $id ) ); |
|
292 | - if ( ! $calendar ) { |
|
290 | + if (empty($calendar)) { |
|
291 | + $calendar = simcal_get_calendar(intval($id)); |
|
292 | + if ( ! $calendar) { |
|
293 | 293 | return ''; |
294 | 294 | } |
295 | 295 | } |
296 | 296 | |
297 | 297 | $events = $calendar->events; |
298 | 298 | |
299 | - $feed = simcal_get_feed( $calendar ); |
|
300 | - $feed_timezone = get_post_meta( $feed->post_id, '_feed_timezone', true ); |
|
299 | + $feed = simcal_get_feed($calendar); |
|
300 | + $feed_timezone = get_post_meta($feed->post_id, '_feed_timezone', true); |
|
301 | 301 | |
302 | 302 | // Variables to cycle days in current month and find today in calendar. |
303 | 303 | $now = $calendar->now; |
304 | - $current = Carbon::create( $year, $month, 1, 0, 0, 0, $calendar->timezone ); |
|
304 | + $current = Carbon::create($year, $month, 1, 0, 0, 0, $calendar->timezone); |
|
305 | 305 | $current_min = $current->getTimestamp(); |
306 | 306 | $current_max = $current->endOfDay()->getTimestamp(); |
307 | 307 | |
308 | 308 | // Calendar grid variables. |
309 | 309 | $week_starts = $calendar->week_starts; |
310 | - $week_of_year = $current->weekOfYear; // Relative count of the week number of the year. |
|
311 | - $month_starts = $current->dayOfWeek; // Day upon which the month starts. |
|
312 | - $days_in_month = $current->daysInMonth; // Number of days in the given month. |
|
310 | + $week_of_year = $current->weekOfYear; // Relative count of the week number of the year. |
|
311 | + $month_starts = $current->dayOfWeek; // Day upon which the month starts. |
|
312 | + $days_in_month = $current->daysInMonth; // Number of days in the given month. |
|
313 | 313 | |
314 | 314 | // Set current month events timestamp boundaries. |
315 | 315 | $this->start = $current_min; |
316 | 316 | $this->end = $current->endOfMonth()->timestamp; |
317 | 317 | |
318 | 318 | // Get daily events for this month. |
319 | - if ( $events && is_array( $events ) ) { |
|
319 | + if ($events && is_array($events)) { |
|
320 | 320 | |
321 | 321 | // Filter events within the boundaries previously set above. |
322 | - $timestamps = array_keys( $events ); |
|
323 | - $lower_bound = array_filter( $timestamps, array( $this, 'filter_events_before' ) ); |
|
324 | - $higher_bound = array_filter( $lower_bound, array( $this, 'filter_events_after' ) ); |
|
325 | - $filtered = ( is_array( $events ) && is_array( $higher_bound) ) && ! empty( $events ) && ! empty( $higher_bound ) ? array_intersect_key( $events, array_combine( $higher_bound, $higher_bound ) ) : array(); |
|
322 | + $timestamps = array_keys($events); |
|
323 | + $lower_bound = array_filter($timestamps, array($this, 'filter_events_before')); |
|
324 | + $higher_bound = array_filter($lower_bound, array($this, 'filter_events_after')); |
|
325 | + $filtered = (is_array($events) && is_array($higher_bound)) && ! empty($events) && ! empty($higher_bound) ? array_intersect_key($events, array_combine($higher_bound, $higher_bound)) : array(); |
|
326 | 326 | |
327 | 327 | // Put resulting events in an associative array, with day of the month as key for easy retrieval in calendar days loop. |
328 | 328 | $day_events = array(); |
329 | - foreach ( $filtered as $timestamp => $events_in_day ) { |
|
330 | - foreach ( $events_in_day as $event ) { |
|
331 | - if ( $event instanceof Event ){ |
|
332 | - $day = intval( Carbon::createFromTimestamp( $timestamp, $event->timezone )->endOfDay()->day ); |
|
333 | - $day_events[ $day ][] = $event; |
|
329 | + foreach ($filtered as $timestamp => $events_in_day) { |
|
330 | + foreach ($events_in_day as $event) { |
|
331 | + if ($event instanceof Event) { |
|
332 | + $day = intval(Carbon::createFromTimestamp($timestamp, $event->timezone)->endOfDay()->day); |
|
333 | + $day_events[$day][] = $event; |
|
334 | 334 | } |
335 | 335 | } |
336 | 336 | } |
337 | 337 | |
338 | - ksort( $day_events, SORT_NUMERIC ); |
|
338 | + ksort($day_events, SORT_NUMERIC); |
|
339 | 339 | } |
340 | 340 | |
341 | 341 | ob_start(); |
342 | 342 | |
343 | - echo '<tbody class="simcal-month simcal-month-' . $month . '">' . "\n"; |
|
344 | - echo "\t" . '<tr class="simcal-week simcal-week-' . $week_of_year . '">'; |
|
343 | + echo '<tbody class="simcal-month simcal-month-'.$month.'">'."\n"; |
|
344 | + echo "\t".'<tr class="simcal-week simcal-week-'.$week_of_year.'">'; |
|
345 | 345 | |
346 | 346 | $days_in_row = 0; |
347 | 347 | // Week may start on an arbitrary day (sun, 0 - sat, 6). |
348 | 348 | $week_day = $week_starts; |
349 | 349 | |
350 | 350 | // This fixes a possible bug when a month starts by Sunday (0). |
351 | - if ( 0 !== $week_starts ) { |
|
351 | + if (0 !== $week_starts) { |
|
352 | 352 | $b = $month_starts === 0 ? 7 : $month_starts; |
353 | 353 | } else { |
354 | 354 | $b = $month_starts; |
355 | 355 | } |
356 | 356 | |
357 | 357 | // Void days in first week. |
358 | - for ( $a = $week_starts; $a < $b; $a++ ) : |
|
358 | + for ($a = $week_starts; $a < $b; $a++) : |
|
359 | 359 | |
360 | - $last_void_day_class = ( $a === ( $b - 1 ) ) ? 'simcal-day-void-last' : ''; |
|
360 | + $last_void_day_class = ($a === ($b - 1)) ? 'simcal-day-void-last' : ''; |
|
361 | 361 | |
362 | - echo '<td class="simcal-day simcal-day-void ' . $last_void_day_class . '"></td>' . "\n"; |
|
362 | + echo '<td class="simcal-day simcal-day-void '.$last_void_day_class.'"></td>'."\n"; |
|
363 | 363 | |
364 | 364 | // Reset day of the week count (sun, 0 - sat, 6). |
365 | - if ( $week_day === 6 ) { |
|
365 | + if ($week_day === 6) { |
|
366 | 366 | $week_day = -1; |
367 | 367 | } |
368 | 368 | $week_day++; |
@@ -372,97 +372,97 @@ discard block |
||
372 | 372 | endfor; |
373 | 373 | |
374 | 374 | // Actual days of the month. |
375 | - for ( $day = 1; $day <= $days_in_month; $day++ ) : |
|
375 | + for ($day = 1; $day <= $days_in_month; $day++) : |
|
376 | 376 | |
377 | 377 | $count = 0; |
378 | 378 | $calendar_classes = array(); |
379 | - $day_classes = 'simcal-day-' . $day . ' simcal-weekday-' . $week_day; |
|
379 | + $day_classes = 'simcal-day-'.$day.' simcal-weekday-'.$week_day; |
|
380 | 380 | |
381 | 381 | $border_style = $bg_color = $color = ''; |
382 | 382 | |
383 | 383 | // Is this the present, the past or the future, Doc? |
384 | - if ( $current_min <= $now && $current_max >= $now ) { |
|
384 | + if ($current_min <= $now && $current_max >= $now) { |
|
385 | 385 | $day_classes .= ' simcal-today simcal-present simcal-day'; |
386 | - $the_color = new Color( $calendar->today_color ); |
|
387 | - $bg_color = '#' . $the_color->getHex(); |
|
386 | + $the_color = new Color($calendar->today_color); |
|
387 | + $bg_color = '#'.$the_color->getHex(); |
|
388 | 388 | $color = $the_color->isDark() ? '#ffffff' : '#000000'; |
389 | - $border_style = ' style="border: 1px solid ' . $bg_color . ';"'; |
|
390 | - } elseif ( $current_max < $now ) { |
|
389 | + $border_style = ' style="border: 1px solid '.$bg_color.';"'; |
|
390 | + } elseif ($current_max < $now) { |
|
391 | 391 | $day_classes .= ' simcal-past simcal-day'; |
392 | - } elseif ( $current_min > $now ) { |
|
392 | + } elseif ($current_min > $now) { |
|
393 | 393 | $day_classes .= ' simcal-future simcal-day'; |
394 | 394 | } |
395 | 395 | |
396 | 396 | // Print events for the current day in loop, if found any. |
397 | - if ( isset( $day_events[ $day ] ) ) : |
|
397 | + if (isset($day_events[$day])) : |
|
398 | 398 | |
399 | 399 | $list_events = '<ul class="simcal-events">'; |
400 | 400 | |
401 | - foreach ( $day_events[ $day ] as $event ) : |
|
401 | + foreach ($day_events[$day] as $event) : |
|
402 | 402 | |
403 | 403 | $event_classes = $event_visibility = ''; |
404 | 404 | |
405 | - if ( $event instanceof Event ) : |
|
405 | + if ($event instanceof Event) : |
|
406 | 406 | |
407 | - if ( $feed->type == 'grouped-calendars' ) { |
|
408 | - date_default_timezone_set( $feed_timezone ); |
|
407 | + if ($feed->type == 'grouped-calendars') { |
|
408 | + date_default_timezone_set($feed_timezone); |
|
409 | 409 | } else { |
410 | - date_default_timezone_set( $event->timezone ); |
|
410 | + date_default_timezone_set($event->timezone); |
|
411 | 411 | } |
412 | 412 | |
413 | 413 | // Store the calendar id where the event belongs (useful in grouped calendar feeds) |
414 | - $calendar_class = 'simcal-events-calendar-' . strval( $event->calendar ); |
|
415 | - $calendar_classes[] = $calendar_class ; |
|
414 | + $calendar_class = 'simcal-events-calendar-'.strval($event->calendar); |
|
415 | + $calendar_classes[] = $calendar_class; |
|
416 | 416 | |
417 | 417 | $recurring = $event->recurrence ? 'simcal-event-recurring ' : ''; |
418 | 418 | $has_location = $event->venue ? 'simcal-event-has-location ' : ''; |
419 | 419 | |
420 | - $event_classes .= 'simcal-event ' . $recurring . $has_location . $calendar_class . ' simcal-tooltip'; |
|
420 | + $event_classes .= 'simcal-event '.$recurring.$has_location.$calendar_class.' simcal-tooltip'; |
|
421 | 421 | |
422 | 422 | // Toggle some events visibility if more than optional limit. |
423 | - if ( ( $calendar->events_limit > -1 ) && ( $count >= $calendar->events_limit ) ) : |
|
423 | + if (($calendar->events_limit > -1) && ($count >= $calendar->events_limit)) : |
|
424 | 424 | $event_classes .= ' simcal-event-toggled'; |
425 | 425 | $event_visibility = ' style="display: none"'; |
426 | 426 | endif; |
427 | 427 | |
428 | 428 | // Event title in list. |
429 | - $title = ! empty( $event->title ) ? trim( $event->title ) : __( 'Event', 'google-calendar-events' ); |
|
430 | - if ( $calendar->trim_titles >= 1 ) { |
|
431 | - $title = strlen( $title ) > $calendar->trim_titles ? mb_substr( $title, 0, $calendar->trim_titles ) . '…' : $title; |
|
429 | + $title = ! empty($event->title) ? trim($event->title) : __('Event', 'google-calendar-events'); |
|
430 | + if ($calendar->trim_titles >= 1) { |
|
431 | + $title = strlen($title) > $calendar->trim_titles ? mb_substr($title, 0, $calendar->trim_titles).'…' : $title; |
|
432 | 432 | } |
433 | 433 | |
434 | 434 | // Event color. |
435 | 435 | $bullet = ''; |
436 | 436 | $event_color = $event->get_color(); |
437 | - if ( ! empty( $event_color ) ) { |
|
438 | - $bullet = '<span style="color: ' . $event_color . ';">■</span> '; |
|
437 | + if ( ! empty($event_color)) { |
|
438 | + $bullet = '<span style="color: '.$event_color.';">■</span> '; |
|
439 | 439 | } |
440 | 440 | |
441 | 441 | // Event contents. |
442 | - $list_events .= "\t" . '<li class="' . $event_classes . '"' . $event_visibility . ' itemscope itemtype="http://schema.org/Event">' . "\n"; |
|
443 | - $list_events .= "\t\t" . '<span class="simcal-event-title">' . $bullet . $title . '</span>' . "\n"; |
|
444 | - $list_events .= "\t\t" . '<div class="simcal-event-details simcal-tooltip-content" style="display: none;">' . $calendar->get_event_html( $event ) . '</div>' . "\n"; |
|
445 | - $list_events .= "\t" . '</li>' . "\n"; |
|
442 | + $list_events .= "\t".'<li class="'.$event_classes.'"'.$event_visibility.' itemscope itemtype="http://schema.org/Event">'."\n"; |
|
443 | + $list_events .= "\t\t".'<span class="simcal-event-title">'.$bullet.$title.'</span>'."\n"; |
|
444 | + $list_events .= "\t\t".'<div class="simcal-event-details simcal-tooltip-content" style="display: none;">'.$calendar->get_event_html($event).'</div>'."\n"; |
|
445 | + $list_events .= "\t".'</li>'."\n"; |
|
446 | 446 | |
447 | - $count ++; |
|
447 | + $count++; |
|
448 | 448 | |
449 | 449 | endif; |
450 | 450 | |
451 | 451 | endforeach; |
452 | 452 | |
453 | - if ( ( $current_min <= $now ) && ( $current_max >= $now ) ) { |
|
453 | + if (($current_min <= $now) && ($current_max >= $now)) { |
|
454 | 454 | $day_classes .= ' simcal-today-has-events'; |
455 | 455 | } |
456 | - $day_classes .= ' simcal-day-has-events simcal-day-has-' . strval( $count ) . '-events'; |
|
456 | + $day_classes .= ' simcal-day-has-events simcal-day-has-'.strval($count).'-events'; |
|
457 | 457 | |
458 | - if ( $calendar_classes ) { |
|
459 | - $day_classes .= ' ' . trim( implode( ' ', array_unique( $calendar_classes ) ) ); |
|
458 | + if ($calendar_classes) { |
|
459 | + $day_classes .= ' '.trim(implode(' ', array_unique($calendar_classes))); |
|
460 | 460 | } |
461 | 461 | |
462 | - $list_events .= '</ul>' . "\n"; |
|
462 | + $list_events .= '</ul>'."\n"; |
|
463 | 463 | |
464 | 464 | // Optional button to toggle hidden events in list. |
465 | - if ( ( $calendar->events_limit > -1 ) && ( $count > $calendar->events_limit ) ) : |
|
465 | + if (($calendar->events_limit > -1) && ($count > $calendar->events_limit)) : |
|
466 | 466 | $list_events .= '<button class="simcal-events-toggle"><i class="simcal-icon-down simcal-icon-animate"></i></button>'; |
467 | 467 | endif; |
468 | 468 | |
@@ -474,49 +474,49 @@ discard block |
||
474 | 474 | endif; |
475 | 475 | |
476 | 476 | // The actual days with numbers and events in each row cell. |
477 | - echo '<td class="' . $day_classes . '" data-events-count="' . strval( $count ) . '">' . "\n"; |
|
478 | - |
|
479 | - if ( $color ) { |
|
480 | - $day_style = ' style="background-color: ' . $bg_color . '; color: ' . $color .'"'; |
|
481 | - } elseif ( $count > 0 ) { |
|
482 | - $the_color = new Color( $calendar->days_events_color ); |
|
483 | - $color = ! $color ? ( $the_color->isDark() ? '#ffffff' : '#000000' ) : $color; |
|
484 | - $bg_color = ! $bg_color ? '#' . $the_color->getHex() : $bg_color; |
|
485 | - $day_style = ' style="background-color: ' . $bg_color . '; color: ' . $color .'"'; |
|
477 | + echo '<td class="'.$day_classes.'" data-events-count="'.strval($count).'">'."\n"; |
|
478 | + |
|
479 | + if ($color) { |
|
480 | + $day_style = ' style="background-color: '.$bg_color.'; color: '.$color.'"'; |
|
481 | + } elseif ($count > 0) { |
|
482 | + $the_color = new Color($calendar->days_events_color); |
|
483 | + $color = ! $color ? ($the_color->isDark() ? '#ffffff' : '#000000') : $color; |
|
484 | + $bg_color = ! $bg_color ? '#'.$the_color->getHex() : $bg_color; |
|
485 | + $day_style = ' style="background-color: '.$bg_color.'; color: '.$color.'"'; |
|
486 | 486 | } else { |
487 | 487 | $day_style = ''; |
488 | 488 | } |
489 | 489 | |
490 | - echo "\t" . '<div' . $border_style . '>' . "\n"; |
|
491 | - echo "\t\t" . '<span class="simcal-day-label simcal-day-number"' . $day_style . '>' . $day . '</span>' . "\n"; |
|
492 | - echo "\t\t" . $list_events . "\n"; |
|
490 | + echo "\t".'<div'.$border_style.'>'."\n"; |
|
491 | + echo "\t\t".'<span class="simcal-day-label simcal-day-number"'.$day_style.'>'.$day.'</span>'."\n"; |
|
492 | + echo "\t\t".$list_events."\n"; |
|
493 | 493 | echo "\t\t"; |
494 | 494 | echo '<span class="simcal-events-dots" style="display: none;">'; |
495 | 495 | |
496 | 496 | // Event bullets for calendar mobile mode. |
497 | - for( $i = 0; $i < $count; $i++ ) { |
|
497 | + for ($i = 0; $i < $count; $i++) { |
|
498 | 498 | echo '<b> • </b>'; |
499 | 499 | } |
500 | 500 | |
501 | - echo '</span>' . "\n"; |
|
502 | - echo "\t" . '</div>' . "\n"; |
|
503 | - echo '</td>' . "\n"; |
|
501 | + echo '</span>'."\n"; |
|
502 | + echo "\t".'</div>'."\n"; |
|
503 | + echo '</td>'."\n"; |
|
504 | 504 | |
505 | 505 | // Reset day of the week count (sun, 0 - sat, 6). |
506 | - if ( $week_day === 6 ) { |
|
506 | + if ($week_day === 6) { |
|
507 | 507 | $week_day = - 1; |
508 | 508 | } |
509 | 509 | $week_day++; |
510 | 510 | |
511 | 511 | // Reset count of days for this row (0-6). |
512 | - if ( $days_in_row === 6 ) : |
|
512 | + if ($days_in_row === 6) : |
|
513 | 513 | |
514 | 514 | // Close the week row. |
515 | 515 | echo '</tr>'; |
516 | 516 | |
517 | 517 | // Open a new week row. |
518 | - if ( $day < $days_in_month ) { |
|
519 | - echo '<tr class="simcal-week simcal-week-' . $week_of_year++ . '">' . "\n"; |
|
518 | + if ($day < $days_in_month) { |
|
519 | + echo '<tr class="simcal-week simcal-week-'.$week_of_year++.'">'."\n"; |
|
520 | 520 | } |
521 | 521 | |
522 | 522 | $days_in_row = -1; |
@@ -525,27 +525,27 @@ discard block |
||
525 | 525 | |
526 | 526 | $days_in_row++; |
527 | 527 | |
528 | - $current_min = Carbon::createFromTimestamp( $current_min, $calendar->timezone )->addDay()->getTimestamp(); |
|
529 | - $current_max = Carbon::createFromTimestamp( $current_max, $calendar->timezone )->addDay()->getTimestamp(); |
|
528 | + $current_min = Carbon::createFromTimestamp($current_min, $calendar->timezone)->addDay()->getTimestamp(); |
|
529 | + $current_max = Carbon::createFromTimestamp($current_max, $calendar->timezone)->addDay()->getTimestamp(); |
|
530 | 530 | |
531 | 531 | endfor; |
532 | 532 | |
533 | 533 | // Void days at the end of the month. |
534 | - $remainder_days = ( 6 - $days_in_row ); |
|
534 | + $remainder_days = (6 - $days_in_row); |
|
535 | 535 | |
536 | - for ( $i = 0; $i <= $remainder_days; $i ++ ) { |
|
536 | + for ($i = 0; $i <= $remainder_days; $i++) { |
|
537 | 537 | |
538 | - $last_void_day_class = ( $i == $remainder_days ) ? 'simcal-day-void-last' : ''; |
|
538 | + $last_void_day_class = ($i == $remainder_days) ? 'simcal-day-void-last' : ''; |
|
539 | 539 | |
540 | - echo '<td class="simcal-day simcal-day-void ' . $last_void_day_class . '"></td>' . "\n"; |
|
540 | + echo '<td class="simcal-day simcal-day-void '.$last_void_day_class.'"></td>'."\n"; |
|
541 | 541 | |
542 | 542 | $week_day++; |
543 | 543 | } |
544 | 544 | |
545 | - echo "\t" . '</tr>' . "\n"; |
|
546 | - echo '</tbody>' . "\n"; |
|
545 | + echo "\t".'</tr>'."\n"; |
|
546 | + echo '</tbody>'."\n"; |
|
547 | 547 | |
548 | - date_default_timezone_set( $calendar->site_timezone ); |
|
548 | + date_default_timezone_set($calendar->site_timezone); |
|
549 | 549 | |
550 | 550 | return ob_get_clean(); |
551 | 551 | } |
@@ -557,17 +557,17 @@ discard block |
||
557 | 557 | */ |
558 | 558 | public function draw_grid_ajax() { |
559 | 559 | |
560 | - if ( isset( $_POST['month'] ) && isset( $_POST['year'] ) && isset( $_POST['id'] ) ) { |
|
560 | + if (isset($_POST['month']) && isset($_POST['year']) && isset($_POST['id'])) { |
|
561 | 561 | |
562 | - $month = absint( $_POST['month'] ); |
|
563 | - $year = absint( $_POST['year'] ); |
|
564 | - $id = absint( $_POST['id'] ); |
|
562 | + $month = absint($_POST['month']); |
|
563 | + $year = absint($_POST['year']); |
|
564 | + $id = absint($_POST['id']); |
|
565 | 565 | |
566 | - wp_send_json_success( $this->draw_month( $month, $year, $id ) ); |
|
566 | + wp_send_json_success($this->draw_month($month, $year, $id)); |
|
567 | 567 | |
568 | 568 | } else { |
569 | 569 | |
570 | - wp_send_json_error( 'Missing arguments in default calendar grid ajax request.' ); |
|
570 | + wp_send_json_error('Missing arguments in default calendar grid ajax request.'); |
|
571 | 571 | |
572 | 572 | } |
573 | 573 | |
@@ -583,8 +583,8 @@ discard block |
||
583 | 583 | * |
584 | 584 | * @return bool |
585 | 585 | */ |
586 | - private function filter_events_before( $event ) { |
|
587 | - return intval( $event ) >= intval( $this->start ); |
|
586 | + private function filter_events_before($event) { |
|
587 | + return intval($event) >= intval($this->start); |
|
588 | 588 | } |
589 | 589 | |
590 | 590 | /** |
@@ -597,8 +597,8 @@ discard block |
||
597 | 597 | * |
598 | 598 | * @return bool |
599 | 599 | */ |
600 | - private function filter_events_after( $event ) { |
|
601 | - return intval( $event ) < intval( $this->end ); |
|
600 | + private function filter_events_after($event) { |
|
601 | + return intval($event) < intval($this->end); |
|
602 | 602 | } |
603 | 603 | |
604 | 604 | } |
@@ -13,7 +13,7 @@ discard block |
||
13 | 13 | use SimpleCalendar\Calendars\Default_Calendar; |
14 | 14 | use SimpleCalendar\Events\Event; |
15 | 15 | |
16 | -if ( ! defined( 'ABSPATH' ) ) { |
|
16 | +if ( ! defined('ABSPATH')) { |
|
17 | 17 | exit; |
18 | 18 | } |
19 | 19 | |
@@ -71,7 +71,7 @@ discard block |
||
71 | 71 | * |
72 | 72 | * @param string|Calendar $calendar |
73 | 73 | */ |
74 | - public function __construct( $calendar = '' ) { |
|
74 | + public function __construct($calendar = '') { |
|
75 | 75 | $this->calendar = $calendar; |
76 | 76 | } |
77 | 77 | |
@@ -105,7 +105,7 @@ discard block |
||
105 | 105 | * @return string |
106 | 106 | */ |
107 | 107 | public function get_name() { |
108 | - return __( 'List', 'google-calendar-events' ); |
|
108 | + return __('List', 'google-calendar-events'); |
|
109 | 109 | } |
110 | 110 | |
111 | 111 | /** |
@@ -114,8 +114,8 @@ discard block |
||
114 | 114 | * @since 3.0.0 |
115 | 115 | */ |
116 | 116 | public function add_ajax_actions() { |
117 | - add_action( 'wp_ajax_simcal_default_calendar_draw_list', array( $this, 'draw_list_ajax' ) ); |
|
118 | - add_action( 'wp_ajax_nopriv_simcal_default_calendar_draw_list', array( $this, 'draw_list_ajax' ) ); |
|
117 | + add_action('wp_ajax_simcal_default_calendar_draw_list', array($this, 'draw_list_ajax')); |
|
118 | + add_action('wp_ajax_nopriv_simcal_default_calendar_draw_list', array($this, 'draw_list_ajax')); |
|
119 | 119 | } |
120 | 120 | |
121 | 121 | /** |
@@ -129,16 +129,16 @@ discard block |
||
129 | 129 | * |
130 | 130 | * @return array |
131 | 131 | */ |
132 | - public function scripts( $min = '' ) { |
|
132 | + public function scripts($min = '') { |
|
133 | 133 | return array( |
134 | 134 | 'simcal-qtip' => array( |
135 | - 'src' => SIMPLE_CALENDAR_ASSETS . 'js/vendor/qtip' . $min . '.js', |
|
136 | - 'deps' => array( 'jquery' ), |
|
135 | + 'src' => SIMPLE_CALENDAR_ASSETS.'js/vendor/qtip'.$min.'.js', |
|
136 | + 'deps' => array('jquery'), |
|
137 | 137 | 'ver' => '2.2.1', |
138 | 138 | 'in_footer' => true, |
139 | 139 | ), |
140 | 140 | 'simcal-default-calendar' => array( |
141 | - 'src' => SIMPLE_CALENDAR_ASSETS . 'js/default-calendar' . $min . '.js', |
|
141 | + 'src' => SIMPLE_CALENDAR_ASSETS.'js/default-calendar'.$min.'.js', |
|
142 | 142 | 'deps' => array( |
143 | 143 | 'jquery', |
144 | 144 | 'simcal-qtip', |
@@ -163,10 +163,10 @@ discard block |
||
163 | 163 | * |
164 | 164 | * @return array |
165 | 165 | */ |
166 | - public function styles( $min = '' ) { |
|
166 | + public function styles($min = '') { |
|
167 | 167 | return array( |
168 | 168 | 'simcal-default-calendar-list' => array( |
169 | - 'src' => SIMPLE_CALENDAR_ASSETS . 'css/default-calendar-list' . $min . '.css', |
|
169 | + 'src' => SIMPLE_CALENDAR_ASSETS.'css/default-calendar-list'.$min.'.css', |
|
170 | 170 | 'ver' => SIMPLE_CALENDAR_VERSION, |
171 | 171 | 'media' => 'all', |
172 | 172 | ), |
@@ -182,49 +182,49 @@ discard block |
||
182 | 182 | |
183 | 183 | $calendar = $this->calendar; |
184 | 184 | |
185 | - if ( $calendar instanceof Default_Calendar ) { |
|
185 | + if ($calendar instanceof Default_Calendar) { |
|
186 | 186 | |
187 | 187 | $disabled = $calendar->static === true ? ' disabled="disabled"' : ''; |
188 | 188 | |
189 | 189 | |
190 | - $hide_header = get_post_meta( $this->calendar->id, '_default_calendar_list_header', true ) == 'yes' ? true : false; |
|
191 | - $static_calendar = get_post_meta( $this->calendar->id, '_calendar_is_static', true ) == 'yes' ? true : false; |
|
190 | + $hide_header = get_post_meta($this->calendar->id, '_default_calendar_list_header', true) == 'yes' ? true : false; |
|
191 | + $static_calendar = get_post_meta($this->calendar->id, '_calendar_is_static', true) == 'yes' ? true : false; |
|
192 | 192 | |
193 | 193 | $header_class = ''; |
194 | 194 | $compact_list_class = $calendar->compact_list ? 'simcal-calendar-list-compact' : ''; |
195 | 195 | |
196 | - edit_post_link( __( 'Edit Calendar', 'google-calendar-events' ), '<p class="simcal-align-right"><small>', '</small></p>', $calendar->id ); |
|
196 | + edit_post_link(__('Edit Calendar', 'google-calendar-events'), '<p class="simcal-align-right"><small>', '</small></p>', $calendar->id); |
|
197 | 197 | |
198 | - echo '<div class="simcal-calendar-list ' . $compact_list_class . '">'; |
|
198 | + echo '<div class="simcal-calendar-list '.$compact_list_class.'">'; |
|
199 | 199 | |
200 | - if ( ! $hide_header && ! $static_calendar ) { |
|
201 | - echo '<nav class="simcal-calendar-head">' . "\n"; |
|
200 | + if ( ! $hide_header && ! $static_calendar) { |
|
201 | + echo '<nav class="simcal-calendar-head">'."\n"; |
|
202 | 202 | |
203 | - echo "\t" . '<div class="simcal-nav">' . "\n"; |
|
204 | - echo "\t\t" . '<button class="simcal-nav-button simcal-prev" title="' . __('Previous', 'google-calendar-events') . '"' . $disabled . '>' . "\n"; |
|
205 | - echo "\t\t\t" . '<i class="simcal-icon-left"></i>' . "\n"; |
|
206 | - echo "\t\t" . '</button>' . "\n"; |
|
207 | - echo "\t" . '</div>' . "\n"; |
|
203 | + echo "\t".'<div class="simcal-nav">'."\n"; |
|
204 | + echo "\t\t".'<button class="simcal-nav-button simcal-prev" title="'.__('Previous', 'google-calendar-events').'"'.$disabled.'>'."\n"; |
|
205 | + echo "\t\t\t".'<i class="simcal-icon-left"></i>'."\n"; |
|
206 | + echo "\t\t".'</button>'."\n"; |
|
207 | + echo "\t".'</div>'."\n"; |
|
208 | 208 | |
209 | - if ( $hide_header ) { |
|
209 | + if ($hide_header) { |
|
210 | 210 | $header_class = 'simcal-hide-header'; |
211 | 211 | } |
212 | 212 | |
213 | 213 | |
214 | - echo "\t" . '<div class="simcal-nav simcal-current ' . $header_class . '" data-calendar-current="' . $calendar->start . '">' . "\n"; |
|
215 | - echo "\t\t" . '<h3 class="simcal-current-label"> </h3>' . "\n"; |
|
216 | - echo "\t" . '</div>' . "\n"; |
|
214 | + echo "\t".'<div class="simcal-nav simcal-current '.$header_class.'" data-calendar-current="'.$calendar->start.'">'."\n"; |
|
215 | + echo "\t\t".'<h3 class="simcal-current-label"> </h3>'."\n"; |
|
216 | + echo "\t".'</div>'."\n"; |
|
217 | 217 | |
218 | - echo "\t" . '<div class="simcal-nav">'; |
|
219 | - echo "\t\t" . '<button class="simcal-nav-button simcal-next" title="' . __('Next', 'google-calendar-events') . '"' . $disabled . '>'; |
|
220 | - echo "\t\t\t" . '<i class="simcal-icon-right"></i>' . "\n"; |
|
221 | - echo "\t\t" . '</button>' . "\n"; |
|
222 | - echo "\t" . '</div>' . "\n"; |
|
218 | + echo "\t".'<div class="simcal-nav">'; |
|
219 | + echo "\t\t".'<button class="simcal-nav-button simcal-next" title="'.__('Next', 'google-calendar-events').'"'.$disabled.'>'; |
|
220 | + echo "\t\t\t".'<i class="simcal-icon-right"></i>'."\n"; |
|
221 | + echo "\t\t".'</button>'."\n"; |
|
222 | + echo "\t".'</div>'."\n"; |
|
223 | 223 | |
224 | - echo '</nav>' . "\n"; |
|
224 | + echo '</nav>'."\n"; |
|
225 | 225 | } |
226 | 226 | |
227 | - echo $this->draw_list( $calendar->start ); |
|
227 | + echo $this->draw_list($calendar->start); |
|
228 | 228 | |
229 | 229 | echo '<div class="simcal-ajax-loader simcal-spinner-top" style="display: none;"><i class="simcal-icon-spinner simcal-icon-spin"></i></div>'; |
230 | 230 | |
@@ -244,92 +244,92 @@ discard block |
||
244 | 244 | * |
245 | 245 | * @return array |
246 | 246 | */ |
247 | - private function get_events( $timestamp ) { |
|
247 | + private function get_events($timestamp) { |
|
248 | 248 | |
249 | 249 | $calendar = $this->calendar; |
250 | 250 | $timezone = $calendar->timezone; |
251 | 251 | |
252 | - if ( ! $calendar->group_type || ! $calendar->group_span ) { |
|
252 | + if ( ! $calendar->group_type || ! $calendar->group_span) { |
|
253 | 253 | return array(); |
254 | 254 | } |
255 | 255 | |
256 | - $current = Carbon::createFromTimestamp( $timestamp, $timezone ); |
|
256 | + $current = Carbon::createFromTimestamp($timestamp, $timezone); |
|
257 | 257 | $prev = clone $current; |
258 | 258 | $next = clone $current; |
259 | 259 | |
260 | 260 | $this->start = $current->getTimestamp(); |
261 | 261 | |
262 | - $interval = $span = max( absint( $calendar->group_span ), 1 ); |
|
263 | - |
|
264 | - if ( 'monthly' == $calendar->group_type ) { |
|
265 | - $this->prev = $prev->subMonths( $span )->getTimestamp(); |
|
266 | - $this->next = $next->addMonths( $span )->getTimestamp(); |
|
267 | - } elseif ( 'weekly' == $calendar->group_type ) { |
|
268 | - $week = new Carbon( $calendar->timezone ); |
|
269 | - $week->setTimestamp( $timestamp ); |
|
270 | - $week->setWeekStartsAt( $calendar->week_starts ); |
|
271 | - $this->prev = $prev->subWeeks( $span )->getTimestamp(); |
|
272 | - $this->next = $next->addWeeks( $span )->getTimestamp(); |
|
273 | - } elseif ( 'daily' == $calendar->group_type ) { |
|
274 | - $this->prev = $prev->subDays( $span )->getTimestamp(); |
|
275 | - $this->next = $next->addDays( $span )->getTimestamp(); |
|
262 | + $interval = $span = max(absint($calendar->group_span), 1); |
|
263 | + |
|
264 | + if ('monthly' == $calendar->group_type) { |
|
265 | + $this->prev = $prev->subMonths($span)->getTimestamp(); |
|
266 | + $this->next = $next->addMonths($span)->getTimestamp(); |
|
267 | + } elseif ('weekly' == $calendar->group_type) { |
|
268 | + $week = new Carbon($calendar->timezone); |
|
269 | + $week->setTimestamp($timestamp); |
|
270 | + $week->setWeekStartsAt($calendar->week_starts); |
|
271 | + $this->prev = $prev->subWeeks($span)->getTimestamp(); |
|
272 | + $this->next = $next->addWeeks($span)->getTimestamp(); |
|
273 | + } elseif ('daily' == $calendar->group_type) { |
|
274 | + $this->prev = $prev->subDays($span)->getTimestamp(); |
|
275 | + $this->next = $next->addDays($span)->getTimestamp(); |
|
276 | 276 | } |
277 | 277 | |
278 | 278 | $events = $calendar->events; |
279 | 279 | $daily_events = $paged_events = $flattened_events = array(); |
280 | 280 | |
281 | - if ( 'events' != $calendar->group_type ) { |
|
281 | + if ('events' != $calendar->group_type) { |
|
282 | 282 | |
283 | - $this->end = $this->next - 1; |
|
283 | + $this->end = $this->next - 1; |
|
284 | 284 | |
285 | - $timestamps = array_keys( $events ); |
|
286 | - $lower_bound = array_filter( $timestamps, array( $this, 'filter_events_before' ) ); |
|
287 | - $higher_bound = array_filter( $lower_bound, array( $this, 'filter_events_after' ) ); |
|
285 | + $timestamps = array_keys($events); |
|
286 | + $lower_bound = array_filter($timestamps, array($this, 'filter_events_before')); |
|
287 | + $higher_bound = array_filter($lower_bound, array($this, 'filter_events_after')); |
|
288 | 288 | |
289 | - if ( is_array( $higher_bound ) && !empty( $higher_bound ) ) { |
|
290 | - $filtered = array_intersect_key( $events, array_combine( $higher_bound, $higher_bound ) ); |
|
291 | - foreach ( $filtered as $timestamp => $events ) { |
|
292 | - $paged_events[ intval( $timestamp ) ] = $events; |
|
289 | + if (is_array($higher_bound) && ! empty($higher_bound)) { |
|
290 | + $filtered = array_intersect_key($events, array_combine($higher_bound, $higher_bound)); |
|
291 | + foreach ($filtered as $timestamp => $events) { |
|
292 | + $paged_events[intval($timestamp)] = $events; |
|
293 | 293 | } |
294 | 294 | } |
295 | 295 | |
296 | 296 | } else { |
297 | 297 | |
298 | - foreach ( $events as $timestamp => $e ) { |
|
298 | + foreach ($events as $timestamp => $e) { |
|
299 | 299 | $second = 0; |
300 | - foreach ( $e as $event ) { |
|
301 | - $flattened_events[ intval( $timestamp + $second ) ][] = $event; |
|
300 | + foreach ($e as $event) { |
|
301 | + $flattened_events[intval($timestamp + $second)][] = $event; |
|
302 | 302 | $second++; |
303 | 303 | } |
304 | 304 | } |
305 | - ksort( $flattened_events, SORT_NUMERIC ); |
|
305 | + ksort($flattened_events, SORT_NUMERIC); |
|
306 | 306 | |
307 | - $keys = array_keys( $flattened_events ); |
|
307 | + $keys = array_keys($flattened_events); |
|
308 | 308 | $current = 0; |
309 | - foreach ( $keys as $timestamp ) { |
|
310 | - if ( $timestamp <= $this->start ) { |
|
309 | + foreach ($keys as $timestamp) { |
|
310 | + if ($timestamp <= $this->start) { |
|
311 | 311 | $current++; |
312 | 312 | } |
313 | 313 | } |
314 | 314 | |
315 | - $paged_events = array_slice( $flattened_events, $current, $interval, true ); |
|
315 | + $paged_events = array_slice($flattened_events, $current, $interval, true); |
|
316 | 316 | |
317 | - $events_end = isset( $keys[ $current + $interval ] ) ? $keys[ $current + $interval ] : $calendar->end; |
|
317 | + $events_end = isset($keys[$current + $interval]) ? $keys[$current + $interval] : $calendar->end; |
|
318 | 318 | $this->end = $events_end > $calendar->end ? $calendar->end : $events_end; |
319 | 319 | // -1 adjusts the interval count to index count, which starts at 0. |
320 | - $this->prev = isset( $keys[ $current - $interval - 1 ] ) ? $keys[ $current - $interval - 1 ] : $calendar->earliest_event; |
|
321 | - $this->next = isset( $keys[ $current + $interval - 1 ] ) ? $keys[ $current + $interval - 1 ] : $this->end; |
|
320 | + $this->prev = isset($keys[$current - $interval - 1]) ? $keys[$current - $interval - 1] : $calendar->earliest_event; |
|
321 | + $this->next = isset($keys[$current + $interval - 1]) ? $keys[$current + $interval - 1] : $this->end; |
|
322 | 322 | |
323 | 323 | } |
324 | 324 | |
325 | 325 | // Put resulting events in an associative array, with Ymd date as key for easy retrieval in calendar days loop. |
326 | - foreach ( $paged_events as $timestamp => $events ) { |
|
327 | - if ( $timestamp <= $this->end ) { |
|
328 | - $date = Carbon::createFromTimestamp( $timestamp, $calendar->timezone )->endOfDay()->format( 'Ymd' ); |
|
329 | - $daily_events[ intval( $date ) ][] = $events; |
|
326 | + foreach ($paged_events as $timestamp => $events) { |
|
327 | + if ($timestamp <= $this->end) { |
|
328 | + $date = Carbon::createFromTimestamp($timestamp, $calendar->timezone)->endOfDay()->format('Ymd'); |
|
329 | + $daily_events[intval($date)][] = $events; |
|
330 | 330 | } |
331 | 331 | } |
332 | - ksort( $daily_events, SORT_NUMERIC ); |
|
332 | + ksort($daily_events, SORT_NUMERIC); |
|
333 | 333 | |
334 | 334 | return $daily_events; |
335 | 335 | } |
@@ -347,71 +347,71 @@ discard block |
||
347 | 347 | private function get_heading() { |
348 | 348 | |
349 | 349 | $calendar = $this->calendar; |
350 | - $start = Carbon::createFromTimestamp( $this->start, $calendar->timezone ); |
|
351 | - $end = Carbon::createFromTimestamp( $this->end, $calendar->timezone ); |
|
350 | + $start = Carbon::createFromTimestamp($this->start, $calendar->timezone); |
|
351 | + $end = Carbon::createFromTimestamp($this->end, $calendar->timezone); |
|
352 | 352 | $date_format = $this->calendar->date_format; |
353 | - $date_order = simcal_get_date_format_order( $date_format ); |
|
353 | + $date_order = simcal_get_date_format_order($date_format); |
|
354 | 354 | |
355 | - if ( ( $start->day == $end->day ) && ( $start->month == $end->month ) && ( $start->year == $end->year ) ) { |
|
355 | + if (($start->day == $end->day) && ($start->month == $end->month) && ($start->year == $end->year)) { |
|
356 | 356 | // Start and end on the same day. |
357 | 357 | // e.g. 1 February 2020 |
358 | - $large = $small = date_i18n( $calendar->date_format , $this->start ); |
|
359 | - if ( ( $date_order['d'] !== false ) && ( $date_order['m'] !== false ) ) { |
|
360 | - if ( $date_order['m'] > $date_order['d'] ) { |
|
361 | - if ( $date_order['y'] !== false && $date_order['y'] > $date_order['m'] ) { |
|
362 | - $small = date_i18n( 'Y, d M', $this->start ); |
|
358 | + $large = $small = date_i18n($calendar->date_format, $this->start); |
|
359 | + if (($date_order['d'] !== false) && ($date_order['m'] !== false)) { |
|
360 | + if ($date_order['m'] > $date_order['d']) { |
|
361 | + if ($date_order['y'] !== false && $date_order['y'] > $date_order['m']) { |
|
362 | + $small = date_i18n('Y, d M', $this->start); |
|
363 | 363 | } else { |
364 | - $small = date_i18n( 'd M Y', $this->start ); |
|
364 | + $small = date_i18n('d M Y', $this->start); |
|
365 | 365 | } |
366 | 366 | } else { |
367 | - if ( $date_order['y'] !== false && $date_order['y'] > $date_order['m'] ) { |
|
368 | - $small = date_i18n( 'Y, M d', $this->start ); |
|
367 | + if ($date_order['y'] !== false && $date_order['y'] > $date_order['m']) { |
|
368 | + $small = date_i18n('Y, M d', $this->start); |
|
369 | 369 | } else { |
370 | - $small = date_i18n( 'M d Y', $this->start ); |
|
370 | + $small = date_i18n('M d Y', $this->start); |
|
371 | 371 | } |
372 | 372 | } |
373 | 373 | } |
374 | - } elseif ( ( $start->month == $end->month ) && ( $start->year == $end->year ) ) { |
|
374 | + } elseif (($start->month == $end->month) && ($start->year == $end->year)) { |
|
375 | 375 | // Start and end days on the same month. |
376 | 376 | // e.g. August 2020 |
377 | - if ( $date_order['y'] === false ) { |
|
377 | + if ($date_order['y'] === false) { |
|
378 | 378 | // August. |
379 | - $large = $small = date_i18n( 'F', $this->start ); |
|
379 | + $large = $small = date_i18n('F', $this->start); |
|
380 | 380 | } else { |
381 | - if ( $date_order['y'] < $date_order['m'] ) { |
|
381 | + if ($date_order['y'] < $date_order['m']) { |
|
382 | 382 | // 2020 August. |
383 | - $large = date_i18n( 'Y F', $this->start ); |
|
384 | - $small = date_i18n( 'Y M', $this->start ); |
|
383 | + $large = date_i18n('Y F', $this->start); |
|
384 | + $small = date_i18n('Y M', $this->start); |
|
385 | 385 | } else { |
386 | 386 | // August 2020. |
387 | - $large = date_i18n( 'F Y', $this->start ); |
|
388 | - $small = date_i18n( 'M Y', $this->start ); |
|
387 | + $large = date_i18n('F Y', $this->start); |
|
388 | + $small = date_i18n('M Y', $this->start); |
|
389 | 389 | } |
390 | 390 | } |
391 | - } elseif ( $start->year == $end->year ) { |
|
391 | + } elseif ($start->year == $end->year) { |
|
392 | 392 | // Start and end days on months of the same year. |
393 | 393 | // e.g. August - September 2020 |
394 | - if ( $date_order['y'] === false ) { |
|
394 | + if ($date_order['y'] === false) { |
|
395 | 395 | // August - September. |
396 | - $large = date_i18n( 'F', $this->start ) . ' - ' . date_i18n( 'F', $this->end ); |
|
397 | - $small = date_i18n( 'M', $this->start ) . ' - ' . date_i18n( 'M', $this->end ); |
|
396 | + $large = date_i18n('F', $this->start).' - '.date_i18n('F', $this->end); |
|
397 | + $small = date_i18n('M', $this->start).' - '.date_i18n('M', $this->end); |
|
398 | 398 | } else { |
399 | - if ( $date_order['y'] < $date_order['m'] ) { |
|
399 | + if ($date_order['y'] < $date_order['m']) { |
|
400 | 400 | // 2020, August - September. |
401 | - $large = $small = date( 'Y', $this->start ) . ', '; |
|
402 | - $large .= date_i18n( 'F', $this->start ) . ' - ' . date_i18n( 'F', $this->end ); |
|
403 | - $small .= date_i18n( 'M', $this->start ) . ' - ' . date_i18n( 'M', $this->end ); |
|
401 | + $large = $small = date('Y', $this->start).', '; |
|
402 | + $large .= date_i18n('F', $this->start).' - '.date_i18n('F', $this->end); |
|
403 | + $small .= date_i18n('M', $this->start).' - '.date_i18n('M', $this->end); |
|
404 | 404 | } else { |
405 | 405 | // August - September, 2020. |
406 | - $large = date_i18n( 'F', $this->start ) . ' - ' . date_i18n( 'F', $this->end ) . ', '; |
|
407 | - $small = date_i18n( 'M', $this->start ) . ' - ' . date_i18n( 'M', $this->end ) . ' '; |
|
408 | - $year = date( 'Y', $this->start ); |
|
406 | + $large = date_i18n('F', $this->start).' - '.date_i18n('F', $this->end).', '; |
|
407 | + $small = date_i18n('M', $this->start).' - '.date_i18n('M', $this->end).' '; |
|
408 | + $year = date('Y', $this->start); |
|
409 | 409 | $large .= $year; |
410 | 410 | $small .= $year; |
411 | 411 | } |
412 | 412 | } |
413 | 413 | } else { |
414 | - $large = $small = date( 'Y', $this->start ) . ' - ' . date( 'Y', $this->end ); |
|
414 | + $large = $small = date('Y', $this->start).' - '.date('Y', $this->end); |
|
415 | 415 | } |
416 | 416 | |
417 | 417 | return array( |
@@ -433,133 +433,133 @@ discard block |
||
433 | 433 | * |
434 | 434 | * @return string |
435 | 435 | */ |
436 | - private function draw_list( $timestamp, $id = 0 ) { |
|
436 | + private function draw_list($timestamp, $id = 0) { |
|
437 | 437 | |
438 | 438 | $calendar = $this->calendar; |
439 | 439 | |
440 | - if ( empty( $calendar ) ) { |
|
441 | - $calendar = $this->calendar = simcal_get_calendar( intval( $id ) ); |
|
442 | - if ( ! $calendar instanceof Default_Calendar ) { |
|
440 | + if (empty($calendar)) { |
|
441 | + $calendar = $this->calendar = simcal_get_calendar(intval($id)); |
|
442 | + if ( ! $calendar instanceof Default_Calendar) { |
|
443 | 443 | return ''; |
444 | 444 | } |
445 | 445 | } |
446 | 446 | |
447 | - $feed = simcal_get_feed( $calendar ); |
|
448 | - $feed_timezone = get_post_meta( $feed->post_id, '_feed_timezone', true ); |
|
447 | + $feed = simcal_get_feed($calendar); |
|
448 | + $feed_timezone = get_post_meta($feed->post_id, '_feed_timezone', true); |
|
449 | 449 | |
450 | 450 | $now = $calendar->now; |
451 | - $current_events = $this->get_events( $timestamp ); |
|
452 | - $day_format = explode( ' ', $calendar->date_format ); |
|
451 | + $current_events = $this->get_events($timestamp); |
|
452 | + $day_format = explode(' ', $calendar->date_format); |
|
453 | 453 | |
454 | 454 | ob_start(); |
455 | 455 | |
456 | 456 | // Draw the events. |
457 | 457 | |
458 | - $block_tag = $calendar->compact_list && ! empty( $current_events ) ? 'div' : 'dl'; |
|
458 | + $block_tag = $calendar->compact_list && ! empty($current_events) ? 'div' : 'dl'; |
|
459 | 459 | |
460 | 460 | $data_heading = ''; |
461 | 461 | $heading = $this->get_heading(); |
462 | - foreach ( $heading as $k => $v ) { |
|
463 | - $data_heading .= ' data-heading-' . $k . '="' . $v . '"'; |
|
462 | + foreach ($heading as $k => $v) { |
|
463 | + $data_heading .= ' data-heading-'.$k.'="'.$v.'"'; |
|
464 | 464 | } |
465 | 465 | |
466 | - echo '<' . $block_tag . ' class="simcal-events-list-container"' . |
|
467 | - ' data-prev="' . $this->prev . '"' . |
|
468 | - ' data-next="' . $this->next . '"' . |
|
469 | - $data_heading . '>'; |
|
466 | + echo '<'.$block_tag.' class="simcal-events-list-container"'. |
|
467 | + ' data-prev="'.$this->prev.'"'. |
|
468 | + ' data-next="'.$this->next.'"'. |
|
469 | + $data_heading.'>'; |
|
470 | 470 | |
471 | - if ( ! empty( $current_events ) && is_array( $current_events ) ) : |
|
471 | + if ( ! empty($current_events) && is_array($current_events)) : |
|
472 | 472 | |
473 | - foreach ( $current_events as $ymd => $events ) : |
|
473 | + foreach ($current_events as $ymd => $events) : |
|
474 | 474 | |
475 | 475 | |
476 | 476 | |
477 | 477 | // This is where we can find out if an event is a multi-day event and if it needs to be shown. |
478 | 478 | // Since this is for list view we are showing the event on the day viewed if it is part of that day even when |
479 | 479 | // expand multi-day events are turned off. |
480 | - if ( isset( $events[0][0]->multiple_days ) && $events[0][0]->multiple_days > 0 ) { |
|
481 | - if ( 'current_day_only' == get_post_meta($calendar->id, '_default_calendar_expand_multi_day_events', true ) ) { |
|
480 | + if (isset($events[0][0]->multiple_days) && $events[0][0]->multiple_days > 0) { |
|
481 | + if ('current_day_only' == get_post_meta($calendar->id, '_default_calendar_expand_multi_day_events', true)) { |
|
482 | 482 | |
483 | - $year = substr( $ymd, 0, 4 ); |
|
484 | - $month = substr( $ymd, 4, 2 ); |
|
485 | - $day = substr( $ymd, 6, 2 ); |
|
483 | + $year = substr($ymd, 0, 4); |
|
484 | + $month = substr($ymd, 4, 2); |
|
485 | + $day = substr($ymd, 6, 2); |
|
486 | 486 | |
487 | - $temp_date = Carbon::createFromDate( $year, $month, $day ); |
|
487 | + $temp_date = Carbon::createFromDate($year, $month, $day); |
|
488 | 488 | |
489 | - if( ! ( $temp_date < Carbon::now()->endOfDay() ) ) { |
|
489 | + if ( ! ($temp_date < Carbon::now()->endOfDay())) { |
|
490 | 490 | continue; |
491 | 491 | } |
492 | 492 | } |
493 | 493 | } |
494 | 494 | |
495 | - $day_ts = Carbon::createFromFormat( 'Ymd', $ymd, $calendar->timezone )->getTimestamp(); |
|
495 | + $day_ts = Carbon::createFromFormat('Ymd', $ymd, $calendar->timezone)->getTimestamp(); |
|
496 | 496 | |
497 | - if ( ! $calendar->compact_list ) : |
|
497 | + if ( ! $calendar->compact_list) : |
|
498 | 498 | |
499 | - $date = new Carbon( 'now', $calendar->timezone ); |
|
500 | - $date->setLocale( substr( get_locale(), 0, 2 ) ); |
|
501 | - $date->setTimestamp( $day_ts ); |
|
499 | + $date = new Carbon('now', $calendar->timezone); |
|
500 | + $date->setLocale(substr(get_locale(), 0, 2)); |
|
501 | + $date->setTimestamp($day_ts); |
|
502 | 502 | |
503 | - if ( $date->isToday() ) { |
|
504 | - $the_color = new Color( $calendar->today_color ); |
|
503 | + if ($date->isToday()) { |
|
504 | + $the_color = new Color($calendar->today_color); |
|
505 | 505 | } else { |
506 | - $the_color = new Color( $calendar->days_events_color ); |
|
506 | + $the_color = new Color($calendar->days_events_color); |
|
507 | 507 | } |
508 | 508 | |
509 | - $bg_color = '#' . $the_color->getHex(); |
|
509 | + $bg_color = '#'.$the_color->getHex(); |
|
510 | 510 | $color = $the_color->isDark() ? '#ffffff' : '#000000'; |
511 | - $border_style = ' style="border-bottom: 1px solid ' . $bg_color . ';" '; |
|
512 | - $bg_style = ' style="background-color: ' . $bg_color . '; color: ' . $color . ';"'; |
|
511 | + $border_style = ' style="border-bottom: 1px solid '.$bg_color.';" '; |
|
512 | + $bg_style = ' style="background-color: '.$bg_color.'; color: '.$color.';"'; |
|
513 | 513 | |
514 | - echo "\t" . '<dt class="simcal-day-label"' . $border_style . '>'; |
|
515 | - echo '<span' . $bg_style .'>'; |
|
516 | - foreach ( $day_format as $format ) { |
|
517 | - echo $format ? '<span class="simcal-date-format" data-date-format="' . $format . '">' . date_i18n( $format, $day_ts ) . '</span> ' : ' '; |
|
514 | + echo "\t".'<dt class="simcal-day-label"'.$border_style.'>'; |
|
515 | + echo '<span'.$bg_style.'>'; |
|
516 | + foreach ($day_format as $format) { |
|
517 | + echo $format ? '<span class="simcal-date-format" data-date-format="'.$format.'">'.date_i18n($format, $day_ts).'</span> ' : ' '; |
|
518 | 518 | } |
519 | 519 | echo '</span>'; |
520 | - echo '</dt>' . "\n"; |
|
520 | + echo '</dt>'."\n"; |
|
521 | 521 | |
522 | 522 | endif; |
523 | 523 | |
524 | - $list_events = '<ul class="simcal-events">' . "\n"; |
|
524 | + $list_events = '<ul class="simcal-events">'."\n"; |
|
525 | 525 | |
526 | 526 | $calendar_classes = array(); |
527 | - $day_classes = 'simcal-weekday-' . date( 'w', $day_ts ); |
|
527 | + $day_classes = 'simcal-weekday-'.date('w', $day_ts); |
|
528 | 528 | |
529 | 529 | // Is this the present, the past or the future, Doc? |
530 | - if ( $timestamp <= $now && $timestamp >= $now ) { |
|
530 | + if ($timestamp <= $now && $timestamp >= $now) { |
|
531 | 531 | $day_classes .= ' simcal-today simcal-present simcal-day'; |
532 | - } elseif ( $timestamp < $now ) { |
|
532 | + } elseif ($timestamp < $now) { |
|
533 | 533 | $day_classes .= ' simcal-past simcal-day'; |
534 | - } elseif ( $this->end > $now ) { |
|
534 | + } elseif ($this->end > $now) { |
|
535 | 535 | $day_classes .= ' simcal-future simcal-day'; |
536 | 536 | } |
537 | 537 | |
538 | 538 | $count = 0; |
539 | 539 | |
540 | - foreach ( $events as $day_events ) : |
|
541 | - foreach ( $day_events as $event ) : |
|
540 | + foreach ($events as $day_events) : |
|
541 | + foreach ($day_events as $event) : |
|
542 | 542 | |
543 | - if ( $event instanceof Event ) : |
|
543 | + if ($event instanceof Event) : |
|
544 | 544 | |
545 | - if ( $feed->type == 'grouped-calendars' ) { |
|
546 | - date_default_timezone_set( $feed_timezone ); |
|
545 | + if ($feed->type == 'grouped-calendars') { |
|
546 | + date_default_timezone_set($feed_timezone); |
|
547 | 547 | } else { |
548 | - date_default_timezone_set( $event->timezone ); |
|
548 | + date_default_timezone_set($event->timezone); |
|
549 | 549 | } |
550 | 550 | |
551 | 551 | $event_classes = $event_visibility = ''; |
552 | 552 | |
553 | - $calendar_class = 'simcal-events-calendar-' . strval( $event->calendar ); |
|
553 | + $calendar_class = 'simcal-events-calendar-'.strval($event->calendar); |
|
554 | 554 | $calendar_classes[] = $calendar_class; |
555 | 555 | |
556 | 556 | $recurring = $event->recurrence ? 'simcal-event-recurring ' : ''; |
557 | 557 | $has_location = $event->venue ? 'simcal-event-has-location ' : ''; |
558 | 558 | |
559 | - $event_classes .= 'simcal-event ' . $recurring . $has_location . $calendar_class; |
|
559 | + $event_classes .= 'simcal-event '.$recurring.$has_location.$calendar_class; |
|
560 | 560 | |
561 | 561 | // Toggle some events visibility if more than optional limit. |
562 | - if ( ( $calendar->events_limit > - 1 ) && ( $count >= $calendar->events_limit ) ) : |
|
562 | + if (($calendar->events_limit > - 1) && ($count >= $calendar->events_limit)) : |
|
563 | 563 | $event_classes .= ' simcal-event-toggled'; |
564 | 564 | $event_visibility = ' style="display: none"'; |
565 | 565 | endif; |
@@ -567,75 +567,75 @@ discard block |
||
567 | 567 | $event_color = ''; |
568 | 568 | $bullet = ''; |
569 | 569 | $event_color = $event->get_color(); |
570 | - if ( ! empty( $event_color ) ) { |
|
570 | + if ( ! empty($event_color)) { |
|
571 | 571 | $side = is_rtl() ? 'right' : 'left'; |
572 | - $event_color = ' style="border-' . $side . ': 4px solid ' . $event_color . '; padding-' . $side . ': 8px;"'; |
|
572 | + $event_color = ' style="border-'.$side.': 4px solid '.$event_color.'; padding-'.$side.': 8px;"'; |
|
573 | 573 | } |
574 | 574 | |
575 | - $list_events .= "\t" . '<li class="' . $event_classes . '"' . $event_visibility . $event_color . ' itemscope itemtype="http://schema.org/Event">' . "\n"; |
|
576 | - $list_events .= "\t\t" . '<div class="simcal-event-details">' . $calendar->get_event_html( $event ) . '</div>' . "\n"; |
|
577 | - $list_events .= "\t" . '</li>' . "\n"; |
|
575 | + $list_events .= "\t".'<li class="'.$event_classes.'"'.$event_visibility.$event_color.' itemscope itemtype="http://schema.org/Event">'."\n"; |
|
576 | + $list_events .= "\t\t".'<div class="simcal-event-details">'.$calendar->get_event_html($event).'</div>'."\n"; |
|
577 | + $list_events .= "\t".'</li>'."\n"; |
|
578 | 578 | |
579 | - $count ++; |
|
579 | + $count++; |
|
580 | 580 | |
581 | 581 | // Event falls within today. |
582 | - if ( ( $this->end <= $now ) && ( $this->start >= $now ) ) : |
|
582 | + if (($this->end <= $now) && ($this->start >= $now)) : |
|
583 | 583 | $day_classes .= ' simcal-today-has-events'; |
584 | 584 | endif; |
585 | - $day_classes .= ' simcal-day-has-events simcal-day-has-' . strval( $count ) . '-events'; |
|
585 | + $day_classes .= ' simcal-day-has-events simcal-day-has-'.strval($count).'-events'; |
|
586 | 586 | |
587 | - if ( $calendar_classes ) : |
|
588 | - $day_classes .= ' ' . trim( implode( ' ', array_unique( $calendar_classes ) ) ); |
|
587 | + if ($calendar_classes) : |
|
588 | + $day_classes .= ' '.trim(implode(' ', array_unique($calendar_classes))); |
|
589 | 589 | endif; |
590 | 590 | |
591 | 591 | endif; |
592 | 592 | endforeach; |
593 | 593 | endforeach; |
594 | 594 | |
595 | - $list_events .= '</ul>' . "\n"; |
|
595 | + $list_events .= '</ul>'."\n"; |
|
596 | 596 | |
597 | 597 | // If events visibility is limited, print the button toggle. |
598 | - if ( ( $calendar->events_limit > -1 ) && ( $count > $calendar->events_limit ) ) : |
|
598 | + if (($calendar->events_limit > -1) && ($count > $calendar->events_limit)) : |
|
599 | 599 | $list_events .= '<button class="simcal-events-toggle"><i class="simcal-icon-down simcal-icon-animate"></i></button>'; |
600 | 600 | endif; |
601 | 601 | |
602 | 602 | // Print final list of events for the current day. |
603 | 603 | $tag = $calendar->compact_list ? 'div' : 'dd'; |
604 | - echo '<' . $tag . ' class="' . $day_classes . '" data-events-count="' . strval( $count ) . '">' . "\n"; |
|
605 | - echo "\t" . $list_events . "\n"; |
|
606 | - echo '</' . $tag . '>' . "\n"; |
|
604 | + echo '<'.$tag.' class="'.$day_classes.'" data-events-count="'.strval($count).'">'."\n"; |
|
605 | + echo "\t".$list_events."\n"; |
|
606 | + echo '</'.$tag.'>'."\n"; |
|
607 | 607 | |
608 | 608 | endforeach; |
609 | 609 | |
610 | 610 | else : |
611 | 611 | |
612 | - echo "\t" . '<p>'; |
|
612 | + echo "\t".'<p>'; |
|
613 | 613 | |
614 | - $message = get_post_meta( $calendar->id, '_no_events_message', true ); |
|
614 | + $message = get_post_meta($calendar->id, '_no_events_message', true); |
|
615 | 615 | |
616 | - if ( 'events' == $calendar->group_type ) { |
|
617 | - echo ! empty( $message ) ? $message : __( 'Nothing to show.', 'google-calendar-events' ); |
|
616 | + if ('events' == $calendar->group_type) { |
|
617 | + echo ! empty($message) ? $message : __('Nothing to show.', 'google-calendar-events'); |
|
618 | 618 | } else { |
619 | - if ( ! empty( $message ) ) { |
|
619 | + if ( ! empty($message)) { |
|
620 | 620 | echo $message; |
621 | 621 | } else { |
622 | - $from = Carbon::createFromTimestamp( $this->start, $calendar->timezone )->getTimestamp(); |
|
623 | - $to = Carbon::createFromTimestamp( $this->end, $calendar->timezone )->getTimestamp(); |
|
624 | - echo apply_filters( 'simcal_no_events_message', sprintf( |
|
625 | - __( 'Nothing from %1$s to %2$s.', 'google-calendar-events' ), |
|
626 | - date_i18n( $calendar->date_format, $from ), |
|
627 | - date_i18n( $calendar->date_format, $to ) |
|
628 | - ), $calendar->id, $from, $to ); |
|
622 | + $from = Carbon::createFromTimestamp($this->start, $calendar->timezone)->getTimestamp(); |
|
623 | + $to = Carbon::createFromTimestamp($this->end, $calendar->timezone)->getTimestamp(); |
|
624 | + echo apply_filters('simcal_no_events_message', sprintf( |
|
625 | + __('Nothing from %1$s to %2$s.', 'google-calendar-events'), |
|
626 | + date_i18n($calendar->date_format, $from), |
|
627 | + date_i18n($calendar->date_format, $to) |
|
628 | + ), $calendar->id, $from, $to); |
|
629 | 629 | } |
630 | 630 | } |
631 | 631 | |
632 | - echo "\t" . '</p>' . "\n"; |
|
632 | + echo "\t".'</p>'."\n"; |
|
633 | 633 | |
634 | 634 | endif; |
635 | 635 | |
636 | - echo '</' . $block_tag . '>'; |
|
636 | + echo '</'.$block_tag.'>'; |
|
637 | 637 | |
638 | - date_default_timezone_set( $calendar->site_timezone ); |
|
638 | + date_default_timezone_set($calendar->site_timezone); |
|
639 | 639 | |
640 | 640 | return ob_get_clean(); |
641 | 641 | } |
@@ -647,16 +647,16 @@ discard block |
||
647 | 647 | */ |
648 | 648 | public function draw_list_ajax() { |
649 | 649 | |
650 | - if ( isset( $_POST['ts'] ) && isset( $_POST['id'] ) ) { |
|
650 | + if (isset($_POST['ts']) && isset($_POST['id'])) { |
|
651 | 651 | |
652 | - $ts = absint( $_POST['ts'] ); |
|
653 | - $id = absint( $_POST['id'] ); |
|
652 | + $ts = absint($_POST['ts']); |
|
653 | + $id = absint($_POST['id']); |
|
654 | 654 | |
655 | - wp_send_json_success( $this->draw_list( $ts, $id ) ); |
|
655 | + wp_send_json_success($this->draw_list($ts, $id)); |
|
656 | 656 | |
657 | 657 | } else { |
658 | 658 | |
659 | - wp_send_json_error( 'Missing arguments in default calendar list ajax request.' ); |
|
659 | + wp_send_json_error('Missing arguments in default calendar list ajax request.'); |
|
660 | 660 | |
661 | 661 | } |
662 | 662 | } |
@@ -671,8 +671,8 @@ discard block |
||
671 | 671 | * |
672 | 672 | * @return bool |
673 | 673 | */ |
674 | - private function filter_events_before( $event ) { |
|
675 | - return intval( $event ) >= intval( $this->start ); |
|
674 | + private function filter_events_before($event) { |
|
675 | + return intval($event) >= intval($this->start); |
|
676 | 676 | } |
677 | 677 | |
678 | 678 | /** |
@@ -685,8 +685,8 @@ discard block |
||
685 | 685 | * |
686 | 686 | * @return bool |
687 | 687 | */ |
688 | - private function filter_events_after( $event ) { |
|
689 | - return intval( $event ) < intval( $this->end ); |
|
688 | + private function filter_events_after($event) { |
|
689 | + return intval($event) < intval($this->end); |
|
690 | 690 | } |
691 | 691 | |
692 | 692 | } |
@@ -6,7 +6,7 @@ discard block |
||
6 | 6 | */ |
7 | 7 | namespace SimpleCalendar\Calendars\Admin; |
8 | 8 | |
9 | -if ( ! defined( 'ABSPATH' ) ) { |
|
9 | +if ( ! defined('ABSPATH')) { |
|
10 | 10 | exit; |
11 | 11 | } |
12 | 12 | |
@@ -24,10 +24,10 @@ discard block |
||
24 | 24 | */ |
25 | 25 | public function __construct() { |
26 | 26 | |
27 | - if ( simcal_is_admin_screen() !== false ) { |
|
28 | - add_action( 'simcal_settings_meta_calendar_panel', array( $this, 'add_settings_meta_calendar_panel' ), 10, 1 ); |
|
27 | + if (simcal_is_admin_screen() !== false) { |
|
28 | + add_action('simcal_settings_meta_calendar_panel', array($this, 'add_settings_meta_calendar_panel'), 10, 1); |
|
29 | 29 | } |
30 | - add_action( 'simcal_process_settings_meta', array( $this, 'process_meta' ), 10, 1 ); |
|
30 | + add_action('simcal_process_settings_meta', array($this, 'process_meta'), 10, 1); |
|
31 | 31 | } |
32 | 32 | |
33 | 33 | /** |
@@ -76,47 +76,47 @@ discard block |
||
76 | 76 | * |
77 | 77 | * @param int $post_id |
78 | 78 | */ |
79 | - public function add_settings_meta_calendar_panel( $post_id ) { |
|
79 | + public function add_settings_meta_calendar_panel($post_id) { |
|
80 | 80 | |
81 | 81 | ?> |
82 | 82 | <table id="default-calendar-settings"> |
83 | 83 | <thead> |
84 | - <tr><th colspan="2"><?php _e( 'Default calendar', 'google-calendar-events' ); ?></th></tr> |
|
84 | + <tr><th colspan="2"><?php _e('Default calendar', 'google-calendar-events'); ?></th></tr> |
|
85 | 85 | </thead> |
86 | 86 | <tbody class="simcal-panel-section"> |
87 | 87 | |
88 | 88 | <tr class="simcal-panel-field simcal-default-calendar-grid" style="display: none;"> |
89 | - <th><label for="_default_calendar_event_bubbles_action"><?php _e( 'Event bubbles', 'google-calendar-events' ); ?></label></th> |
|
89 | + <th><label for="_default_calendar_event_bubbles_action"><?php _e('Event bubbles', 'google-calendar-events'); ?></label></th> |
|
90 | 90 | <td> |
91 | 91 | <?php |
92 | 92 | |
93 | - $bubbles = get_post_meta( $post_id, '_default_calendar_event_bubble_trigger', true ); |
|
93 | + $bubbles = get_post_meta($post_id, '_default_calendar_event_bubble_trigger', true); |
|
94 | 94 | |
95 | - simcal_print_field( array( |
|
95 | + simcal_print_field(array( |
|
96 | 96 | 'type' => 'radio', |
97 | 97 | 'inline' => 'inline', |
98 | 98 | 'name' => '_default_calendar_event_bubble_trigger', |
99 | 99 | 'id' => '_default_calendar_event_bubble_trigger', |
100 | - 'tooltip' => __( 'Open event bubbles in calendar grid by clicking or hovering on event titles. On mobile devices it will always default to tapping.', 'google-calendar-events' ), |
|
100 | + 'tooltip' => __('Open event bubbles in calendar grid by clicking or hovering on event titles. On mobile devices it will always default to tapping.', 'google-calendar-events'), |
|
101 | 101 | 'value' => $bubbles ? $bubbles : 'hover', |
102 | 102 | 'default' => 'hover', |
103 | 103 | 'options' => array( |
104 | - 'click' => __( 'Click', 'google-calendar-events' ), |
|
105 | - 'hover' => __( 'Hover', 'google-calendar-events' ), |
|
104 | + 'click' => __('Click', 'google-calendar-events'), |
|
105 | + 'hover' => __('Hover', 'google-calendar-events'), |
|
106 | 106 | ), |
107 | - ) ); |
|
107 | + )); |
|
108 | 108 | |
109 | 109 | ?> |
110 | 110 | </td> |
111 | 111 | </tr> |
112 | 112 | <tr class="simcal-panel-field simcal-default-calendar-grid" style="display: none;"> |
113 | - <th><label for="_default_calendar_trim_titles"><?php _e( 'Trim event titles', 'google-calendar-events' ); ?></label></th> |
|
113 | + <th><label for="_default_calendar_trim_titles"><?php _e('Trim event titles', 'google-calendar-events'); ?></label></th> |
|
114 | 114 | <td> |
115 | 115 | <?php |
116 | 116 | |
117 | - $trim = get_post_meta( $post_id, '_default_calendar_trim_titles', true ); |
|
117 | + $trim = get_post_meta($post_id, '_default_calendar_trim_titles', true); |
|
118 | 118 | |
119 | - simcal_print_field( array( |
|
119 | + simcal_print_field(array( |
|
120 | 120 | 'type' => 'checkbox', |
121 | 121 | 'name' => '_default_calendar_trim_titles', |
122 | 122 | 'id' => '_default_calendar_trim_titles', |
@@ -127,34 +127,34 @@ discard block |
||
127 | 127 | 'attributes' => array( |
128 | 128 | 'data-show-next-if-value' => 'yes', |
129 | 129 | ), |
130 | - ) ); |
|
130 | + )); |
|
131 | 131 | |
132 | - simcal_print_field( array( |
|
132 | + simcal_print_field(array( |
|
133 | 133 | 'type' => 'standard', |
134 | 134 | 'subtype' => 'number', |
135 | 135 | 'name' => '_default_calendar_trim_titles_chars', |
136 | 136 | 'id' => '_default_calendar_trim_titles_chars', |
137 | - 'tooltip' => __( 'Shorten event titles in calendar grid to a specified length in characters.', 'google-calendar-events' ), |
|
137 | + 'tooltip' => __('Shorten event titles in calendar grid to a specified length in characters.', 'google-calendar-events'), |
|
138 | 138 | 'class' => array( |
139 | 139 | 'simcal-field-tiny', |
140 | 140 | ), |
141 | - 'value' => 'yes' == $trim ? strval( max( absint( get_post_meta( $post_id, '_default_calendar_trim_titles_chars', true ) ), 1 ) ) : '20', |
|
141 | + 'value' => 'yes' == $trim ? strval(max(absint(get_post_meta($post_id, '_default_calendar_trim_titles_chars', true)), 1)) : '20', |
|
142 | 142 | 'attributes' => array( |
143 | 143 | 'min' => '1', |
144 | 144 | ), |
145 | - ) ); |
|
145 | + )); |
|
146 | 146 | |
147 | 147 | ?> |
148 | 148 | </td> |
149 | 149 | </tr> |
150 | 150 | <tr class="simcal-panel-field simcal-default-calendar-list" style="display: none;"> |
151 | - <th><label for="_default_calendar_list_grouped_span"><?php _e( 'Span', 'google-calendar-events' ); ?></label></th> |
|
151 | + <th><label for="_default_calendar_list_grouped_span"><?php _e('Span', 'google-calendar-events'); ?></label></th> |
|
152 | 152 | <td> |
153 | 153 | <?php |
154 | 154 | |
155 | - $list_span = max( absint( get_post_meta( $post_id, '_default_calendar_list_range_span', true ) ), 1 ); |
|
155 | + $list_span = max(absint(get_post_meta($post_id, '_default_calendar_list_range_span', true)), 1); |
|
156 | 156 | |
157 | - simcal_print_field( array( |
|
157 | + simcal_print_field(array( |
|
158 | 158 | 'type' => 'standard', |
159 | 159 | 'subtype' => 'number', |
160 | 160 | 'name' => '_default_calendar_list_range_span', |
@@ -163,78 +163,78 @@ discard block |
||
163 | 163 | 'simcal-field-tiny', |
164 | 164 | 'simcal-field-inline', |
165 | 165 | ), |
166 | - 'value' => strval( $list_span ), |
|
166 | + 'value' => strval($list_span), |
|
167 | 167 | 'attributes' => array( |
168 | 168 | 'min' => '1', |
169 | 169 | ), |
170 | - ) ); |
|
170 | + )); |
|
171 | 171 | |
172 | - $list_type = get_post_meta( $post_id, '_default_calendar_list_range_type', true ); |
|
172 | + $list_type = get_post_meta($post_id, '_default_calendar_list_range_type', true); |
|
173 | 173 | |
174 | - simcal_print_field( array( |
|
174 | + simcal_print_field(array( |
|
175 | 175 | 'type' => 'select', |
176 | 176 | 'name' => '_default_calendar_list_range_type', |
177 | 177 | 'id' => '_default_calendar_list_range_type', |
178 | - 'tooltip' => __( 'Range of events to show on each calendar page.', 'google-calendar-events' ), |
|
178 | + 'tooltip' => __('Range of events to show on each calendar page.', 'google-calendar-events'), |
|
179 | 179 | 'class' => array( |
180 | 180 | 'simcal-field-inline', |
181 | 181 | ), |
182 | 182 | 'value' => $list_type, |
183 | 183 | 'options' => array( |
184 | - 'monthly' => __( 'Month(s)', 'google-calendar-events' ), |
|
185 | - 'weekly' => __( 'Week(s)', 'google-calendar-events' ), |
|
186 | - 'daily' => __( 'Day(s)', 'google-calendar-events' ), |
|
187 | - 'events' => __( 'Event(s)', 'google-calendar-events' ), |
|
184 | + 'monthly' => __('Month(s)', 'google-calendar-events'), |
|
185 | + 'weekly' => __('Week(s)', 'google-calendar-events'), |
|
186 | + 'daily' => __('Day(s)', 'google-calendar-events'), |
|
187 | + 'events' => __('Event(s)', 'google-calendar-events'), |
|
188 | 188 | ), |
189 | - ) ); |
|
189 | + )); |
|
190 | 190 | |
191 | 191 | ?> |
192 | 192 | </td> |
193 | 193 | </tr> |
194 | 194 | <tr class="simcal-panel-field simcal-default-calendar-list" style="display: none;"> |
195 | - <th><label for="_default_calendar_list_header"><?php _e( 'Hide header', 'google-calendar-events' ); ?></label></th> |
|
195 | + <th><label for="_default_calendar_list_header"><?php _e('Hide header', 'google-calendar-events'); ?></label></th> |
|
196 | 196 | <td> |
197 | 197 | <?php |
198 | 198 | |
199 | - $header = get_post_meta( $post_id, '_default_calendar_list_header', true ); |
|
199 | + $header = get_post_meta($post_id, '_default_calendar_list_header', true); |
|
200 | 200 | |
201 | - simcal_print_field( array( |
|
201 | + simcal_print_field(array( |
|
202 | 202 | 'type' => 'checkbox', |
203 | 203 | 'name' => '_default_calendar_list_header', |
204 | 204 | 'id' => '_default_calendar_list_header', |
205 | - 'tooltip' => __( 'You can use this to hide the month header for this calendar.', 'google-calendar-events' ), |
|
205 | + 'tooltip' => __('You can use this to hide the month header for this calendar.', 'google-calendar-events'), |
|
206 | 206 | 'value' => 'yes' == $header ? 'yes' : 'no', |
207 | - ) ); |
|
207 | + )); |
|
208 | 208 | |
209 | 209 | ?> |
210 | 210 | </td> |
211 | 211 | </tr> |
212 | 212 | <tr class="simcal-panel-field simcal-default-calendar-list" style="display: none;"> |
213 | - <th><label for="_default_calendar_compact_list"><?php _e( 'Compact list', 'google-calendar-events' ); ?></label></th> |
|
213 | + <th><label for="_default_calendar_compact_list"><?php _e('Compact list', 'google-calendar-events'); ?></label></th> |
|
214 | 214 | <td> |
215 | 215 | <?php |
216 | 216 | |
217 | - $compact = get_post_meta( $post_id, '_default_calendar_compact_list', true ); |
|
217 | + $compact = get_post_meta($post_id, '_default_calendar_compact_list', true); |
|
218 | 218 | |
219 | - simcal_print_field( array( |
|
219 | + simcal_print_field(array( |
|
220 | 220 | 'type' => 'checkbox', |
221 | 221 | 'name' => '_default_calendar_compact_list', |
222 | 222 | 'id' => '_default_calendar_compact_list', |
223 | - 'tooltip' => __( 'Make an events list more compact by grouping together events from different days in a single list.', 'google-calendar-events' ), |
|
223 | + 'tooltip' => __('Make an events list more compact by grouping together events from different days in a single list.', 'google-calendar-events'), |
|
224 | 224 | 'value' => 'yes' == $compact ? 'yes' : 'no', |
225 | - ) ); |
|
225 | + )); |
|
226 | 226 | |
227 | 227 | ?> |
228 | 228 | </td> |
229 | 229 | </tr> |
230 | 230 | <tr class="simcal-panel-field simcal-default-calendar-grid simcal-default-calendar-list" style="display: none;"> |
231 | - <th><label for="_default_calendar_limit_visible_events"><?php _e( 'Limit visible events', 'google-calendar-events' ); ?></label></th> |
|
231 | + <th><label for="_default_calendar_limit_visible_events"><?php _e('Limit visible events', 'google-calendar-events'); ?></label></th> |
|
232 | 232 | <td> |
233 | 233 | <?php |
234 | 234 | |
235 | - $limit = get_post_meta( $post_id, '_default_calendar_limit_visible_events', true ); |
|
235 | + $limit = get_post_meta($post_id, '_default_calendar_limit_visible_events', true); |
|
236 | 236 | |
237 | - simcal_print_field( array( |
|
237 | + simcal_print_field(array( |
|
238 | 238 | 'type' => 'checkbox', |
239 | 239 | 'name' => '_default_calendar_limit_visible_events', |
240 | 240 | 'id' => '_default_calendar_limit_visible_events', |
@@ -245,17 +245,17 @@ discard block |
||
245 | 245 | 'attributes' => array( |
246 | 246 | 'data-show-next-if-value' => 'yes', |
247 | 247 | ) |
248 | - ) ); |
|
248 | + )); |
|
249 | 249 | |
250 | - $visible_events = absint( get_post_meta( $post_id, '_default_calendar_visible_events', true ) ); |
|
250 | + $visible_events = absint(get_post_meta($post_id, '_default_calendar_visible_events', true)); |
|
251 | 251 | $visible_events = $visible_events > 0 ? $visible_events : 3; |
252 | 252 | |
253 | - simcal_print_field( array( |
|
253 | + simcal_print_field(array( |
|
254 | 254 | 'type' => 'standard', |
255 | 255 | 'subtype' => 'number', |
256 | 256 | 'name' => '_default_calendar_visible_events', |
257 | 257 | 'id' => '_default_calendar_visible_events', |
258 | - 'tooltip' => __( 'Limit the number of initial visible events on each day to a set maximum.', 'google-calendar-events' ), |
|
258 | + 'tooltip' => __('Limit the number of initial visible events on each day to a set maximum.', 'google-calendar-events'), |
|
259 | 259 | 'class' => array( |
260 | 260 | 'simcal-field-tiny', |
261 | 261 | ), |
@@ -263,39 +263,39 @@ discard block |
||
263 | 263 | 'attributes' => array( |
264 | 264 | 'min' => '1', |
265 | 265 | ) |
266 | - ) ); |
|
266 | + )); |
|
267 | 267 | |
268 | 268 | ?> |
269 | 269 | </td> |
270 | 270 | </tr> |
271 | 271 | <tr class="simcal-panel-field simcal-default-calendar-grid simcal-default-calendar-list" style="display: none;"> |
272 | - <th><label for="_default_calendar_event_bubbles_action"><?php _e( 'Expand multi-day events', 'google-calendar-events' ); ?></label></th> |
|
272 | + <th><label for="_default_calendar_event_bubbles_action"><?php _e('Expand multi-day events', 'google-calendar-events'); ?></label></th> |
|
273 | 273 | <td> |
274 | 274 | <?php |
275 | 275 | |
276 | - $post_meta = get_post_meta( $post_id ); |
|
276 | + $post_meta = get_post_meta($post_id); |
|
277 | 277 | |
278 | - if ( ! is_array( $post_meta ) && ! empty( $post_meta ) ) { |
|
278 | + if ( ! is_array($post_meta) && ! empty($post_meta)) { |
|
279 | 279 | $multi_day_value = 'current_day_only'; |
280 | 280 | } else { |
281 | - $multi_day_value = get_post_meta( $post_id, '_default_calendar_expand_multi_day_events', true ); |
|
281 | + $multi_day_value = get_post_meta($post_id, '_default_calendar_expand_multi_day_events', true); |
|
282 | 282 | } |
283 | 283 | |
284 | - simcal_print_field( array( |
|
284 | + simcal_print_field(array( |
|
285 | 285 | 'type' => 'select', |
286 | 286 | 'name' => '_default_calendar_expand_multi_day_events', |
287 | 287 | 'id' => '_default_calendar_expand_multi_day_events', |
288 | - 'tooltip' => __( 'For events spanning multiple days, you can display them on each day of the event, ' . |
|
289 | - 'only on the first day of the event, or on all days of the event, but only up to the current day. ' . |
|
290 | - 'Third option applies to list views only.', 'google-calendar-events' ), |
|
288 | + 'tooltip' => __('For events spanning multiple days, you can display them on each day of the event, '. |
|
289 | + 'only on the first day of the event, or on all days of the event, but only up to the current day. '. |
|
290 | + 'Third option applies to list views only.', 'google-calendar-events'), |
|
291 | 291 | 'value' => $multi_day_value, |
292 | 292 | 'options' => array( |
293 | - 'yes' => __( 'Yes, display on all days of event', 'google-calendar-events' ), |
|
294 | - 'no' => __( 'No, display only on first day of event', 'google-calendar-events' ), |
|
295 | - 'current_day_only' => __( 'No, display on all days of event up to current day (list view only)', 'google-calendar-events' ), |
|
293 | + 'yes' => __('Yes, display on all days of event', 'google-calendar-events'), |
|
294 | + 'no' => __('No, display only on first day of event', 'google-calendar-events'), |
|
295 | + 'current_day_only' => __('No, display on all days of event up to current day (list view only)', 'google-calendar-events'), |
|
296 | 296 | ), |
297 | 297 | 'default' => 'current_day_only', |
298 | - ) ); |
|
298 | + )); |
|
299 | 299 | |
300 | 300 | ?> |
301 | 301 | </td> |
@@ -303,70 +303,70 @@ discard block |
||
303 | 303 | </tbody> |
304 | 304 | <?php |
305 | 305 | |
306 | - $settings = get_option( 'simple-calendar_settings_calendars' ); |
|
307 | - $default_theme = isset( $settings['default-calendar']['theme'] ) ? $settings['default-calendar']['theme'] : 'light'; |
|
306 | + $settings = get_option('simple-calendar_settings_calendars'); |
|
307 | + $default_theme = isset($settings['default-calendar']['theme']) ? $settings['default-calendar']['theme'] : 'light'; |
|
308 | 308 | $default_today_color = /*isset( $settings['default-calendar']['today_color'] ) ? $settings['default-calendar']['today_color'] :*/ '#1e73be'; |
309 | 309 | $default_days_events_color = /*isset( $settings['default-calendar']['days_events_color'] ) ? $settings['default-calendar']['days_events_color'] :*/ '#000000'; |
310 | 310 | |
311 | 311 | ?> |
312 | 312 | <tbody class="simcal-panel-section"> |
313 | 313 | <tr class="simcal-panel-field simcal-default-calendar-grid simcal-default-calendar-list" style="display: none;"> |
314 | - <th><label for="_default_calendar_style_theme"><?php _e( 'Theme', 'google-calendar-events' ); ?></label></th> |
|
314 | + <th><label for="_default_calendar_style_theme"><?php _e('Theme', 'google-calendar-events'); ?></label></th> |
|
315 | 315 | <td> |
316 | 316 | <?php |
317 | 317 | |
318 | - $saved = get_post_meta( $post_id, '_default_calendar_style_theme', true ); |
|
318 | + $saved = get_post_meta($post_id, '_default_calendar_style_theme', true); |
|
319 | 319 | $value = ! $saved ? $default_theme : $saved; |
320 | 320 | |
321 | - simcal_print_field( array( |
|
321 | + simcal_print_field(array( |
|
322 | 322 | 'type' => 'select', |
323 | 323 | 'name' => '_default_calendar_style_theme', |
324 | 324 | 'id' => '_default_calendar_style_theme', |
325 | 325 | 'value' => $value, |
326 | - 'tooltip' => __( 'Choose a calendar theme to match your site theme.', 'google-calendar-events' ), |
|
326 | + 'tooltip' => __('Choose a calendar theme to match your site theme.', 'google-calendar-events'), |
|
327 | 327 | 'options' => array( |
328 | - 'light' => __( 'Light', 'google-calendar-events' ), |
|
329 | - 'dark' => __( 'Dark', 'google-calendar-events' ), |
|
328 | + 'light' => __('Light', 'google-calendar-events'), |
|
329 | + 'dark' => __('Dark', 'google-calendar-events'), |
|
330 | 330 | ), |
331 | - ) ); |
|
331 | + )); |
|
332 | 332 | |
333 | 333 | ?> |
334 | 334 | </td> |
335 | 335 | </tr> |
336 | 336 | <tr class="simcal-panel-field simcal-default-calendar-grid simcal-default-calendar-list" style="display: none;"> |
337 | - <th><label for="_default_calendar_style_today"><?php _e( 'Today', 'google-calendar-events' ); ?></label></th> |
|
337 | + <th><label for="_default_calendar_style_today"><?php _e('Today', 'google-calendar-events'); ?></label></th> |
|
338 | 338 | <td> |
339 | 339 | <?php |
340 | 340 | |
341 | - $saved = get_post_meta( $post_id, '_default_calendar_style_today', true ); |
|
341 | + $saved = get_post_meta($post_id, '_default_calendar_style_today', true); |
|
342 | 342 | $value = ! $saved ? $default_today_color : $saved; |
343 | 343 | |
344 | - simcal_print_field( array( |
|
344 | + simcal_print_field(array( |
|
345 | 345 | 'type' => 'standard', |
346 | 346 | 'subtype' => 'color-picker', |
347 | 347 | 'name' => '_default_calendar_style_today', |
348 | 348 | 'id' => '_default_calendar_style_today', |
349 | 349 | 'value' => $value, |
350 | - ) ); |
|
350 | + )); |
|
351 | 351 | |
352 | 352 | ?> |
353 | 353 | </td> |
354 | 354 | </tr> |
355 | 355 | <tr class="simcal-panel-field simcal-default-calendar-grid simcal-default-calendar-list" style="display: none;"> |
356 | - <th><label for="_default_calendar_style_days_events"><?php _e( 'Days with events', 'google-calendar-events' ); ?></label></th> |
|
356 | + <th><label for="_default_calendar_style_days_events"><?php _e('Days with events', 'google-calendar-events'); ?></label></th> |
|
357 | 357 | <td> |
358 | 358 | <?php |
359 | 359 | |
360 | - $saved = get_post_meta( $post_id, '_default_calendar_style_days_events', true ); |
|
360 | + $saved = get_post_meta($post_id, '_default_calendar_style_days_events', true); |
|
361 | 361 | $value = ! $saved ? $default_days_events_color : $saved; |
362 | 362 | |
363 | - simcal_print_field( array( |
|
363 | + simcal_print_field(array( |
|
364 | 364 | 'type' => 'standard', |
365 | 365 | 'subtype' => 'color-picker', |
366 | 366 | 'name' => '_default_calendar_style_days_events', |
367 | 367 | 'id' => '_default_calendar_style_days_events', |
368 | 368 | 'value' => $value, |
369 | - ) ); |
|
369 | + )); |
|
370 | 370 | |
371 | 371 | ?> |
372 | 372 | </td> |
@@ -388,55 +388,55 @@ discard block |
||
388 | 388 | * |
389 | 389 | * @param int $post_id |
390 | 390 | */ |
391 | - public function process_meta( $post_id ) { |
|
391 | + public function process_meta($post_id) { |
|
392 | 392 | |
393 | 393 | // Theme. |
394 | - $theme = isset( $_POST['_default_calendar_style_theme'] ) ? sanitize_key( $_POST['_default_calendar_style_theme'] ) : 'light'; |
|
395 | - update_post_meta( $post_id, '_default_calendar_style_theme', $theme ); |
|
394 | + $theme = isset($_POST['_default_calendar_style_theme']) ? sanitize_key($_POST['_default_calendar_style_theme']) : 'light'; |
|
395 | + update_post_meta($post_id, '_default_calendar_style_theme', $theme); |
|
396 | 396 | |
397 | 397 | // Today color. |
398 | - $today_color = isset( $_POST['_default_calendar_style_today'] ) ? sanitize_text_field( $_POST['_default_calendar_style_today'] ) : '#FF000'; |
|
399 | - update_post_meta( $post_id, '_default_calendar_style_today', $today_color ); |
|
398 | + $today_color = isset($_POST['_default_calendar_style_today']) ? sanitize_text_field($_POST['_default_calendar_style_today']) : '#FF000'; |
|
399 | + update_post_meta($post_id, '_default_calendar_style_today', $today_color); |
|
400 | 400 | |
401 | 401 | // Days with events color. |
402 | - $days_events_color = isset( $_POST['_default_calendar_style_days_events'] ) ? sanitize_text_field( $_POST['_default_calendar_style_days_events'] ) : '#000000'; |
|
403 | - update_post_meta( $post_id, '_default_calendar_style_days_events', $days_events_color ); |
|
402 | + $days_events_color = isset($_POST['_default_calendar_style_days_events']) ? sanitize_text_field($_POST['_default_calendar_style_days_events']) : '#000000'; |
|
403 | + update_post_meta($post_id, '_default_calendar_style_days_events', $days_events_color); |
|
404 | 404 | |
405 | 405 | // List range span. |
406 | - $span = isset( $_POST['_default_calendar_list_range_span'] ) ? max( absint( $_POST['_default_calendar_list_range_span'] ), 1 ) : 1; |
|
407 | - update_post_meta( $post_id, '_default_calendar_list_range_span', $span ); |
|
406 | + $span = isset($_POST['_default_calendar_list_range_span']) ? max(absint($_POST['_default_calendar_list_range_span']), 1) : 1; |
|
407 | + update_post_meta($post_id, '_default_calendar_list_range_span', $span); |
|
408 | 408 | |
409 | 409 | // List range type. |
410 | - $group = isset( $_POST['_default_calendar_list_range_type'] ) ? sanitize_key( $_POST['_default_calendar_list_range_type'] ) : 'monthly'; |
|
411 | - update_post_meta( $post_id, '_default_calendar_list_range_type', $group ); |
|
410 | + $group = isset($_POST['_default_calendar_list_range_type']) ? sanitize_key($_POST['_default_calendar_list_range_type']) : 'monthly'; |
|
411 | + update_post_meta($post_id, '_default_calendar_list_range_type', $group); |
|
412 | 412 | |
413 | 413 | // Hide header. |
414 | - $header = isset( $_POST['_default_calendar_list_header'] ) ? 'yes' : 'no'; |
|
415 | - update_post_meta( $post_id, '_default_calendar_list_header', $header ); |
|
414 | + $header = isset($_POST['_default_calendar_list_header']) ? 'yes' : 'no'; |
|
415 | + update_post_meta($post_id, '_default_calendar_list_header', $header); |
|
416 | 416 | |
417 | 417 | // Compact list. |
418 | - $compact = isset( $_POST['_default_calendar_compact_list'] ) ? 'yes' : 'no'; |
|
419 | - update_post_meta( $post_id, '_default_calendar_compact_list', $compact ); |
|
418 | + $compact = isset($_POST['_default_calendar_compact_list']) ? 'yes' : 'no'; |
|
419 | + update_post_meta($post_id, '_default_calendar_compact_list', $compact); |
|
420 | 420 | |
421 | 421 | // Limit number of initially visible daily events. |
422 | - $limit = isset( $_POST['_default_calendar_limit_visible_events'] ) ? 'yes' : 'no'; |
|
423 | - update_post_meta( $post_id, '_default_calendar_limit_visible_events', $limit ); |
|
424 | - $number = isset( $_POST['_default_calendar_visible_events'] ) ? absint( $_POST['_default_calendar_visible_events'] ) : 3; |
|
425 | - update_post_meta( $post_id, '_default_calendar_visible_events', $number ); |
|
422 | + $limit = isset($_POST['_default_calendar_limit_visible_events']) ? 'yes' : 'no'; |
|
423 | + update_post_meta($post_id, '_default_calendar_limit_visible_events', $limit); |
|
424 | + $number = isset($_POST['_default_calendar_visible_events']) ? absint($_POST['_default_calendar_visible_events']) : 3; |
|
425 | + update_post_meta($post_id, '_default_calendar_visible_events', $number); |
|
426 | 426 | |
427 | 427 | // Grid event bubbles action. |
428 | - $bubbles = isset( $_POST['_default_calendar_event_bubble_trigger'] ) ? esc_attr( $_POST['_default_calendar_event_bubble_trigger'] ) : 'hover'; |
|
429 | - update_post_meta( $post_id, '_default_calendar_event_bubble_trigger', $bubbles ); |
|
428 | + $bubbles = isset($_POST['_default_calendar_event_bubble_trigger']) ? esc_attr($_POST['_default_calendar_event_bubble_trigger']) : 'hover'; |
|
429 | + update_post_meta($post_id, '_default_calendar_event_bubble_trigger', $bubbles); |
|
430 | 430 | |
431 | 431 | // Trim event titles characters length. |
432 | - $trim = isset( $_POST['_default_calendar_trim_titles'] ) ? 'yes' : 'no'; |
|
433 | - update_post_meta( $post_id, '_default_calendar_trim_titles', $trim ); |
|
434 | - $chars = isset( $_POST['_default_calendar_trim_titles_chars'] ) ? max( absint( $_POST['_default_calendar_trim_titles_chars'] ), 1 ) : 20; |
|
435 | - update_post_meta( $post_id, '_default_calendar_trim_titles_chars', $chars ); |
|
432 | + $trim = isset($_POST['_default_calendar_trim_titles']) ? 'yes' : 'no'; |
|
433 | + update_post_meta($post_id, '_default_calendar_trim_titles', $trim); |
|
434 | + $chars = isset($_POST['_default_calendar_trim_titles_chars']) ? max(absint($_POST['_default_calendar_trim_titles_chars']), 1) : 20; |
|
435 | + update_post_meta($post_id, '_default_calendar_trim_titles_chars', $chars); |
|
436 | 436 | |
437 | 437 | // Expand multiple day events on each day. |
438 | - $multi_day = isset( $_POST['_default_calendar_expand_multi_day_events'] ) && ! empty( $_POST['_default_calendar_expand_multi_day_events'] ) ? sanitize_key( $_POST['_default_calendar_expand_multi_day_events'] ) : 'current_day_only'; |
|
439 | - update_post_meta( $post_id, '_default_calendar_expand_multi_day_events', $multi_day ); |
|
438 | + $multi_day = isset($_POST['_default_calendar_expand_multi_day_events']) && ! empty($_POST['_default_calendar_expand_multi_day_events']) ? sanitize_key($_POST['_default_calendar_expand_multi_day_events']) : 'current_day_only'; |
|
439 | + update_post_meta($post_id, '_default_calendar_expand_multi_day_events', $multi_day); |
|
440 | 440 | |
441 | 441 | } |
442 | 442 |
@@ -42,1214 +42,1214 @@ |
||
42 | 42 | |
43 | 43 | |
44 | 44 | |
45 | - class Browser |
|
46 | - { |
|
47 | - private $_agent = ''; |
|
48 | - private $_browser_name = ''; |
|
49 | - private $_version = ''; |
|
50 | - private $_platform = ''; |
|
51 | - private $_os = ''; |
|
52 | - private $_is_aol = false; |
|
53 | - private $_is_mobile = false; |
|
54 | - private $_is_tablet = false; |
|
55 | - private $_is_robot = false; |
|
56 | - private $_is_facebook = false; |
|
57 | - private $_aol_version = ''; |
|
58 | - |
|
59 | - const BROWSER_UNKNOWN = 'unknown'; |
|
60 | - const VERSION_UNKNOWN = 'unknown'; |
|
61 | - |
|
62 | - const BROWSER_OPERA = 'Opera'; // http://www.opera.com/ |
|
63 | - const BROWSER_OPERA_MINI = 'Opera Mini'; // http://www.opera.com/mini/ |
|
64 | - const BROWSER_WEBTV = 'WebTV'; // http://www.webtv.net/pc/ |
|
65 | - const BROWSER_IE = 'Internet Explorer'; // http://www.microsoft.com/ie/ |
|
66 | - const BROWSER_POCKET_IE = 'Pocket Internet Explorer'; // http://en.wikipedia.org/wiki/Internet_Explorer_Mobile |
|
67 | - const BROWSER_KONQUEROR = 'Konqueror'; // http://www.konqueror.org/ |
|
68 | - const BROWSER_ICAB = 'iCab'; // http://www.icab.de/ |
|
69 | - const BROWSER_OMNIWEB = 'OmniWeb'; // http://www.omnigroup.com/applications/omniweb/ |
|
70 | - const BROWSER_FIREBIRD = 'Firebird'; // http://www.ibphoenix.com/ |
|
71 | - const BROWSER_FIREFOX = 'Firefox'; // http://www.mozilla.com/en-US/firefox/firefox.html |
|
72 | - const BROWSER_ICEWEASEL = 'Iceweasel'; // http://www.geticeweasel.org/ |
|
73 | - const BROWSER_SHIRETOKO = 'Shiretoko'; // http://wiki.mozilla.org/Projects/shiretoko |
|
74 | - const BROWSER_MOZILLA = 'Mozilla'; // http://www.mozilla.com/en-US/ |
|
75 | - const BROWSER_AMAYA = 'Amaya'; // http://www.w3.org/Amaya/ |
|
76 | - const BROWSER_LYNX = 'Lynx'; // http://en.wikipedia.org/wiki/Lynx |
|
77 | - const BROWSER_SAFARI = 'Safari'; // http://apple.com |
|
78 | - const BROWSER_IPHONE = 'iPhone'; // http://apple.com |
|
79 | - const BROWSER_IPOD = 'iPod'; // http://apple.com |
|
80 | - const BROWSER_IPAD = 'iPad'; // http://apple.com |
|
81 | - const BROWSER_CHROME = 'Chrome'; // http://www.google.com/chrome |
|
82 | - const BROWSER_ANDROID = 'Android'; // http://www.android.com/ |
|
83 | - const BROWSER_GOOGLEBOT = 'GoogleBot'; // http://en.wikipedia.org/wiki/Googlebot |
|
84 | - const BROWSER_SLURP = 'Yahoo! Slurp'; // http://en.wikipedia.org/wiki/Yahoo!_Slurp |
|
85 | - const BROWSER_W3CVALIDATOR = 'W3C Validator'; // http://validator.w3.org/ |
|
86 | - const BROWSER_BLACKBERRY = 'BlackBerry'; // http://www.blackberry.com/ |
|
87 | - const BROWSER_ICECAT = 'IceCat'; // http://en.wikipedia.org/wiki/GNU_IceCat |
|
88 | - const BROWSER_NOKIA_S60 = 'Nokia S60 OSS Browser'; // http://en.wikipedia.org/wiki/Web_Browser_for_S60 |
|
89 | - const BROWSER_NOKIA = 'Nokia Browser'; // * all other WAP-based browsers on the Nokia Platform |
|
90 | - const BROWSER_MSN = 'MSN Browser'; // http://explorer.msn.com/ |
|
91 | - const BROWSER_MSNBOT = 'MSN Bot'; // http://search.msn.com/msnbot.htm |
|
92 | - const BROWSER_BINGBOT = 'Bing Bot'; // http://en.wikipedia.org/wiki/Bingbot |
|
93 | - |
|
94 | - const BROWSER_NETSCAPE_NAVIGATOR = 'Netscape Navigator'; // http://browser.netscape.com/ (DEPRECATED) |
|
95 | - const BROWSER_GALEON = 'Galeon'; // http://galeon.sourceforge.net/ (DEPRECATED) |
|
96 | - const BROWSER_NETPOSITIVE = 'NetPositive'; // http://en.wikipedia.org/wiki/NetPositive (DEPRECATED) |
|
97 | - const BROWSER_PHOENIX = 'Phoenix'; // http://en.wikipedia.org/wiki/History_of_Mozilla_Firefox (DEPRECATED) |
|
98 | - |
|
99 | - const PLATFORM_UNKNOWN = 'unknown'; |
|
100 | - const PLATFORM_WINDOWS = 'Windows'; |
|
101 | - const PLATFORM_WINDOWS_CE = 'Windows CE'; |
|
102 | - const PLATFORM_APPLE = 'Apple'; |
|
103 | - const PLATFORM_LINUX = 'Linux'; |
|
104 | - const PLATFORM_OS2 = 'OS/2'; |
|
105 | - const PLATFORM_BEOS = 'BeOS'; |
|
106 | - const PLATFORM_IPHONE = 'iPhone'; |
|
107 | - const PLATFORM_IPOD = 'iPod'; |
|
108 | - const PLATFORM_IPAD = 'iPad'; |
|
109 | - const PLATFORM_BLACKBERRY = 'BlackBerry'; |
|
110 | - const PLATFORM_NOKIA = 'Nokia'; |
|
111 | - const PLATFORM_FREEBSD = 'FreeBSD'; |
|
112 | - const PLATFORM_OPENBSD = 'OpenBSD'; |
|
113 | - const PLATFORM_NETBSD = 'NetBSD'; |
|
114 | - const PLATFORM_SUNOS = 'SunOS'; |
|
115 | - const PLATFORM_OPENSOLARIS = 'OpenSolaris'; |
|
116 | - const PLATFORM_ANDROID = 'Android'; |
|
117 | - |
|
118 | - const OPERATING_SYSTEM_UNKNOWN = 'unknown'; |
|
119 | - |
|
120 | - public function __construct($userAgent = "") |
|
121 | - { |
|
122 | - $this->reset(); |
|
123 | - if ($userAgent != "") { |
|
124 | - $this->setUserAgent($userAgent); |
|
125 | - } else { |
|
126 | - $this->determine(); |
|
127 | - } |
|
128 | - } |
|
129 | - |
|
130 | - /** |
|
131 | - * Reset all properties |
|
132 | - */ |
|
133 | - public function reset() |
|
134 | - { |
|
135 | - $this->_agent = isset($_SERVER['HTTP_USER_AGENT']) ? $_SERVER['HTTP_USER_AGENT'] : ""; |
|
136 | - $this->_browser_name = self::BROWSER_UNKNOWN; |
|
137 | - $this->_version = self::VERSION_UNKNOWN; |
|
138 | - $this->_platform = self::PLATFORM_UNKNOWN; |
|
139 | - $this->_os = self::OPERATING_SYSTEM_UNKNOWN; |
|
140 | - $this->_is_aol = false; |
|
141 | - $this->_is_mobile = false; |
|
142 | - $this->_is_tablet = false; |
|
143 | - $this->_is_robot = false; |
|
144 | - $this->_is_facebook = false; |
|
145 | - $this->_aol_version = self::VERSION_UNKNOWN; |
|
146 | - } |
|
147 | - |
|
148 | - /** |
|
149 | - * Check to see if the specific browser is valid |
|
150 | - * @param string $browserName |
|
151 | - * @return bool True if the browser is the specified browser |
|
152 | - */ |
|
153 | - function isBrowser($browserName) |
|
154 | - { |
|
155 | - return (0 == strcasecmp($this->_browser_name, trim($browserName))); |
|
156 | - } |
|
157 | - |
|
158 | - /** |
|
159 | - * The name of the browser. All return types are from the class contants |
|
160 | - * @return string Name of the browser |
|
161 | - */ |
|
162 | - public function getBrowser() |
|
163 | - { |
|
164 | - return $this->_browser_name; |
|
165 | - } |
|
166 | - |
|
167 | - /** |
|
168 | - * Set the name of the browser |
|
169 | - * @param $browser string The name of the Browser |
|
170 | - */ |
|
171 | - public function setBrowser($browser) |
|
172 | - { |
|
173 | - $this->_browser_name = $browser; |
|
174 | - } |
|
175 | - |
|
176 | - /** |
|
177 | - * The name of the platform. All return types are from the class contants |
|
178 | - * @return string Name of the browser |
|
179 | - */ |
|
180 | - public function getPlatform() |
|
181 | - { |
|
182 | - return $this->_platform; |
|
183 | - } |
|
184 | - |
|
185 | - /** |
|
186 | - * Set the name of the platform |
|
187 | - * @param string $platform The name of the Platform |
|
188 | - */ |
|
189 | - public function setPlatform($platform) |
|
190 | - { |
|
191 | - $this->_platform = $platform; |
|
192 | - } |
|
193 | - |
|
194 | - /** |
|
195 | - * The version of the browser. |
|
196 | - * @return string Version of the browser (will only contain alpha-numeric characters and a period) |
|
197 | - */ |
|
198 | - public function getVersion() |
|
199 | - { |
|
200 | - return $this->_version; |
|
201 | - } |
|
202 | - |
|
203 | - /** |
|
204 | - * Set the version of the browser |
|
205 | - * @param string $version The version of the Browser |
|
206 | - */ |
|
207 | - public function setVersion($version) |
|
208 | - { |
|
209 | - $this->_version = preg_replace('/[^0-9,.,a-z,A-Z-]/', '', $version); |
|
210 | - } |
|
211 | - |
|
212 | - /** |
|
213 | - * The version of AOL. |
|
214 | - * @return string Version of AOL (will only contain alpha-numeric characters and a period) |
|
215 | - */ |
|
216 | - public function getAolVersion() |
|
217 | - { |
|
218 | - return $this->_aol_version; |
|
219 | - } |
|
220 | - |
|
221 | - /** |
|
222 | - * Set the version of AOL |
|
223 | - * @param string $version The version of AOL |
|
224 | - */ |
|
225 | - public function setAolVersion($version) |
|
226 | - { |
|
227 | - $this->_aol_version = preg_replace('/[^0-9,.,a-z,A-Z]/', '', $version); |
|
228 | - } |
|
229 | - |
|
230 | - /** |
|
231 | - * Is the browser from AOL? |
|
232 | - * @return boolean True if the browser is from AOL otherwise false |
|
233 | - */ |
|
234 | - public function isAol() |
|
235 | - { |
|
236 | - return $this->_is_aol; |
|
237 | - } |
|
238 | - |
|
239 | - /** |
|
240 | - * Is the browser from a mobile device? |
|
241 | - * @return boolean True if the browser is from a mobile device otherwise false |
|
242 | - */ |
|
243 | - public function isMobile() |
|
244 | - { |
|
245 | - return $this->_is_mobile; |
|
246 | - } |
|
247 | - |
|
248 | - /** |
|
249 | - * Is the browser from a tablet device? |
|
250 | - * @return boolean True if the browser is from a tablet device otherwise false |
|
251 | - */ |
|
252 | - public function isTablet() |
|
253 | - { |
|
254 | - return $this->_is_tablet; |
|
255 | - } |
|
256 | - |
|
257 | - /** |
|
258 | - * Is the browser from a robot (ex Slurp,GoogleBot)? |
|
259 | - * @return boolean True if the browser is from a robot otherwise false |
|
260 | - */ |
|
261 | - public function isRobot() |
|
262 | - { |
|
263 | - return $this->_is_robot; |
|
264 | - } |
|
265 | - |
|
266 | - /** |
|
267 | - * Is the browser from facebook? |
|
268 | - * @return boolean True if the browser is from facebook otherwise false |
|
269 | - */ |
|
270 | - public function isFacebook() |
|
271 | - { |
|
272 | - return $this->_is_facebook; |
|
273 | - } |
|
274 | - |
|
275 | - /** |
|
276 | - * Set the browser to be from AOL |
|
277 | - * @param $isAol |
|
278 | - */ |
|
279 | - public function setAol($isAol) |
|
280 | - { |
|
281 | - $this->_is_aol = $isAol; |
|
282 | - } |
|
283 | - |
|
284 | - /** |
|
285 | - * Set the Browser to be mobile |
|
286 | - * @param boolean $value is the browser a mobile browser or not |
|
287 | - */ |
|
288 | - protected function setMobile($value = true) |
|
289 | - { |
|
290 | - $this->_is_mobile = $value; |
|
291 | - } |
|
292 | - |
|
293 | - /** |
|
294 | - * Set the Browser to be tablet |
|
295 | - * @param boolean $value is the browser a tablet browser or not |
|
296 | - */ |
|
297 | - protected function setTablet($value = true) |
|
298 | - { |
|
299 | - $this->_is_tablet = $value; |
|
300 | - } |
|
301 | - |
|
302 | - /** |
|
303 | - * Set the Browser to be a robot |
|
304 | - * @param boolean $value is the browser a robot or not |
|
305 | - */ |
|
306 | - protected function setRobot($value = true) |
|
307 | - { |
|
308 | - $this->_is_robot = $value; |
|
309 | - } |
|
310 | - |
|
311 | - /** |
|
312 | - * Set the Browser to be a Facebook request |
|
313 | - * @param boolean $value is the browser a robot or not |
|
314 | - */ |
|
315 | - protected function setFacebook($value = true) |
|
316 | - { |
|
317 | - $this->_is_facebook = $value; |
|
318 | - } |
|
319 | - |
|
320 | - /** |
|
321 | - * Get the user agent value in use to determine the browser |
|
322 | - * @return string The user agent from the HTTP header |
|
323 | - */ |
|
324 | - public function getUserAgent() |
|
325 | - { |
|
326 | - return $this->_agent; |
|
327 | - } |
|
328 | - |
|
329 | - /** |
|
330 | - * Set the user agent value (the construction will use the HTTP header value - this will overwrite it) |
|
331 | - * @param string $agent_string The value for the User Agent |
|
332 | - */ |
|
333 | - public function setUserAgent($agent_string) |
|
334 | - { |
|
335 | - $this->reset(); |
|
336 | - $this->_agent = $agent_string; |
|
337 | - $this->determine(); |
|
338 | - } |
|
339 | - |
|
340 | - /** |
|
341 | - * Used to determine if the browser is actually "chromeframe" |
|
342 | - * @since 1.7 |
|
343 | - * @return boolean True if the browser is using chromeframe |
|
344 | - */ |
|
345 | - public function isChromeFrame() |
|
346 | - { |
|
347 | - return (strpos($this->_agent, "chromeframe") !== false); |
|
348 | - } |
|
349 | - |
|
350 | - /** |
|
351 | - * Returns a formatted string with a summary of the details of the browser. |
|
352 | - * @return string formatted string with a summary of the browser |
|
353 | - */ |
|
354 | - public function __toString() |
|
355 | - { |
|
356 | - return "<strong>Browser Name:</strong> {$this->getBrowser()}<br/>\n" . |
|
357 | - "<strong>Browser Version:</strong> {$this->getVersion()}<br/>\n" . |
|
358 | - "<strong>Browser User Agent String:</strong> {$this->getUserAgent()}<br/>\n" . |
|
359 | - "<strong>Platform:</strong> {$this->getPlatform()}<br/>"; |
|
360 | - } |
|
361 | - |
|
362 | - /** |
|
363 | - * Protected routine to calculate and determine what the browser is in use (including platform) |
|
364 | - */ |
|
365 | - protected function determine() |
|
366 | - { |
|
367 | - $this->checkPlatform(); |
|
368 | - $this->checkBrowsers(); |
|
369 | - $this->checkForAol(); |
|
370 | - } |
|
371 | - |
|
372 | - /** |
|
373 | - * Protected routine to determine the browser type |
|
374 | - * @return boolean True if the browser was detected otherwise false |
|
375 | - */ |
|
376 | - protected function checkBrowsers() |
|
377 | - { |
|
378 | - return ( |
|
379 | - // well-known, well-used |
|
380 | - // Special Notes: |
|
381 | - // (1) Opera must be checked before FireFox due to the odd |
|
382 | - // user agents used in some older versions of Opera |
|
383 | - // (2) WebTV is strapped onto Internet Explorer so we must |
|
384 | - // check for WebTV before IE |
|
385 | - // (3) (deprecated) Galeon is based on Firefox and needs to be |
|
386 | - // tested before Firefox is tested |
|
387 | - // (4) OmniWeb is based on Safari so OmniWeb check must occur |
|
388 | - // before Safari |
|
389 | - // (5) Netscape 9+ is based on Firefox so Netscape checks |
|
390 | - // before FireFox are necessary |
|
391 | - $this->checkBrowserWebTv() || |
|
392 | - $this->checkBrowserInternetExplorer() || |
|
393 | - $this->checkBrowserOpera() || |
|
394 | - $this->checkBrowserGaleon() || |
|
395 | - $this->checkBrowserNetscapeNavigator9Plus() || |
|
396 | - $this->checkBrowserFirefox() || |
|
397 | - $this->checkBrowserChrome() || |
|
398 | - $this->checkBrowserOmniWeb() || |
|
399 | - |
|
400 | - // common mobile |
|
401 | - $this->checkBrowserAndroid() || |
|
402 | - $this->checkBrowseriPad() || |
|
403 | - $this->checkBrowseriPod() || |
|
404 | - $this->checkBrowseriPhone() || |
|
405 | - $this->checkBrowserBlackBerry() || |
|
406 | - $this->checkBrowserNokia() || |
|
407 | - |
|
408 | - // common bots |
|
409 | - $this->checkBrowserGoogleBot() || |
|
410 | - $this->checkBrowserMSNBot() || |
|
411 | - $this->checkBrowserBingBot() || |
|
412 | - $this->checkBrowserSlurp() || |
|
413 | - |
|
414 | - // check for facebook external hit when loading URL |
|
415 | - $this->checkFacebookExternalHit() || |
|
416 | - |
|
417 | - // WebKit base check (post mobile and others) |
|
418 | - $this->checkBrowserSafari() || |
|
419 | - |
|
420 | - // everyone else |
|
421 | - $this->checkBrowserNetPositive() || |
|
422 | - $this->checkBrowserFirebird() || |
|
423 | - $this->checkBrowserKonqueror() || |
|
424 | - $this->checkBrowserIcab() || |
|
425 | - $this->checkBrowserPhoenix() || |
|
426 | - $this->checkBrowserAmaya() || |
|
427 | - $this->checkBrowserLynx() || |
|
428 | - $this->checkBrowserShiretoko() || |
|
429 | - $this->checkBrowserIceCat() || |
|
430 | - $this->checkBrowserIceweasel() || |
|
431 | - $this->checkBrowserW3CValidator() || |
|
432 | - $this->checkBrowserMozilla() /* Mozilla is such an open standard that you must check it last */ |
|
433 | - ); |
|
434 | - } |
|
435 | - |
|
436 | - /** |
|
437 | - * Determine if the user is using a BlackBerry (last updated 1.7) |
|
438 | - * @return boolean True if the browser is the BlackBerry browser otherwise false |
|
439 | - */ |
|
440 | - protected function checkBrowserBlackBerry() |
|
441 | - { |
|
442 | - if (stripos($this->_agent, 'blackberry') !== false) { |
|
443 | - $aresult = explode("/", stristr($this->_agent, "BlackBerry")); |
|
444 | - if (isset($aresult[1])) { |
|
445 | - $aversion = explode(' ', $aresult[1]); |
|
446 | - $this->setVersion($aversion[0]); |
|
447 | - $this->_browser_name = self::BROWSER_BLACKBERRY; |
|
448 | - $this->setMobile(true); |
|
449 | - return true; |
|
450 | - } |
|
451 | - } |
|
452 | - return false; |
|
453 | - } |
|
454 | - |
|
455 | - /** |
|
456 | - * Determine if the user is using an AOL User Agent (last updated 1.7) |
|
457 | - * @return boolean True if the browser is from AOL otherwise false |
|
458 | - */ |
|
459 | - protected function checkForAol() |
|
460 | - { |
|
461 | - $this->setAol(false); |
|
462 | - $this->setAolVersion(self::VERSION_UNKNOWN); |
|
463 | - |
|
464 | - if (stripos($this->_agent, 'aol') !== false) { |
|
465 | - $aversion = explode(' ', stristr($this->_agent, 'AOL')); |
|
466 | - if (isset($aversion[1])) { |
|
467 | - $this->setAol(true); |
|
468 | - $this->setAolVersion(preg_replace('/[^0-9\.a-z]/i', '', $aversion[1])); |
|
469 | - return true; |
|
470 | - } |
|
471 | - } |
|
472 | - return false; |
|
473 | - } |
|
474 | - |
|
475 | - /** |
|
476 | - * Determine if the browser is the GoogleBot or not (last updated 1.7) |
|
477 | - * @return boolean True if the browser is the GoogletBot otherwise false |
|
478 | - */ |
|
479 | - protected function checkBrowserGoogleBot() |
|
480 | - { |
|
481 | - if (stripos($this->_agent, 'googlebot') !== false) { |
|
482 | - $aresult = explode('/', stristr($this->_agent, 'googlebot')); |
|
483 | - if (isset($aresult[1])) { |
|
484 | - $aversion = explode(' ', $aresult[1]); |
|
485 | - $this->setVersion(str_replace(';', '', $aversion[0])); |
|
486 | - $this->_browser_name = self::BROWSER_GOOGLEBOT; |
|
487 | - $this->setRobot(true); |
|
488 | - return true; |
|
489 | - } |
|
490 | - } |
|
491 | - return false; |
|
492 | - } |
|
493 | - |
|
494 | - /** |
|
495 | - * Determine if the browser is the MSNBot or not (last updated 1.9) |
|
496 | - * @return boolean True if the browser is the MSNBot otherwise false |
|
497 | - */ |
|
498 | - protected function checkBrowserMSNBot() |
|
499 | - { |
|
500 | - if (stripos($this->_agent, "msnbot") !== false) { |
|
501 | - $aresult = explode("/", stristr($this->_agent, "msnbot")); |
|
502 | - if (isset($aresult[1])) { |
|
503 | - $aversion = explode(" ", $aresult[1]); |
|
504 | - $this->setVersion(str_replace(";", "", $aversion[0])); |
|
505 | - $this->_browser_name = self::BROWSER_MSNBOT; |
|
506 | - $this->setRobot(true); |
|
507 | - return true; |
|
508 | - } |
|
509 | - } |
|
510 | - return false; |
|
511 | - } |
|
512 | - |
|
513 | - /** |
|
514 | - * Determine if the browser is the BingBot or not (last updated 1.9) |
|
515 | - * @return boolean True if the browser is the BingBot otherwise false |
|
516 | - */ |
|
517 | - protected function checkBrowserBingBot() |
|
518 | - { |
|
519 | - if (stripos($this->_agent, "bingbot") !== false) { |
|
520 | - $aresult = explode("/", stristr($this->_agent, "bingbot")); |
|
521 | - if (isset($aresult[1])) { |
|
522 | - $aversion = explode(" ", $aresult[1]); |
|
523 | - $this->setVersion(str_replace(";", "", $aversion[0])); |
|
524 | - $this->_browser_name = self::BROWSER_BINGBOT; |
|
525 | - $this->setRobot(true); |
|
526 | - return true; |
|
527 | - } |
|
528 | - } |
|
529 | - return false; |
|
530 | - } |
|
531 | - |
|
532 | - /** |
|
533 | - * Determine if the browser is the W3C Validator or not (last updated 1.7) |
|
534 | - * @return boolean True if the browser is the W3C Validator otherwise false |
|
535 | - */ |
|
536 | - protected function checkBrowserW3CValidator() |
|
537 | - { |
|
538 | - if (stripos($this->_agent, 'W3C-checklink') !== false) { |
|
539 | - $aresult = explode('/', stristr($this->_agent, 'W3C-checklink')); |
|
540 | - if (isset($aresult[1])) { |
|
541 | - $aversion = explode(' ', $aresult[1]); |
|
542 | - $this->setVersion($aversion[0]); |
|
543 | - $this->_browser_name = self::BROWSER_W3CVALIDATOR; |
|
544 | - return true; |
|
545 | - } |
|
546 | - } else if (stripos($this->_agent, 'W3C_Validator') !== false) { |
|
547 | - // Some of the Validator versions do not delineate w/ a slash - add it back in |
|
548 | - $ua = str_replace("W3C_Validator ", "W3C_Validator/", $this->_agent); |
|
549 | - $aresult = explode('/', stristr($ua, 'W3C_Validator')); |
|
550 | - if (isset($aresult[1])) { |
|
551 | - $aversion = explode(' ', $aresult[1]); |
|
552 | - $this->setVersion($aversion[0]); |
|
553 | - $this->_browser_name = self::BROWSER_W3CVALIDATOR; |
|
554 | - return true; |
|
555 | - } |
|
556 | - } else if (stripos($this->_agent, 'W3C-mobileOK') !== false) { |
|
557 | - $this->_browser_name = self::BROWSER_W3CVALIDATOR; |
|
558 | - $this->setMobile(true); |
|
559 | - return true; |
|
560 | - } |
|
561 | - return false; |
|
562 | - } |
|
563 | - |
|
564 | - /** |
|
565 | - * Determine if the browser is the Yahoo! Slurp Robot or not (last updated 1.7) |
|
566 | - * @return boolean True if the browser is the Yahoo! Slurp Robot otherwise false |
|
567 | - */ |
|
568 | - protected function checkBrowserSlurp() |
|
569 | - { |
|
570 | - if (stripos($this->_agent, 'slurp') !== false) { |
|
571 | - $aresult = explode('/', stristr($this->_agent, 'Slurp')); |
|
572 | - if (isset($aresult[1])) { |
|
573 | - $aversion = explode(' ', $aresult[1]); |
|
574 | - $this->setVersion($aversion[0]); |
|
575 | - $this->_browser_name = self::BROWSER_SLURP; |
|
576 | - $this->setRobot(true); |
|
577 | - $this->setMobile(false); |
|
578 | - return true; |
|
579 | - } |
|
580 | - } |
|
581 | - return false; |
|
582 | - } |
|
583 | - |
|
584 | - /** |
|
585 | - * Determine if the browser is Internet Explorer or not (last updated 1.7) |
|
586 | - * @return boolean True if the browser is Internet Explorer otherwise false |
|
587 | - */ |
|
588 | - protected function checkBrowserInternetExplorer() |
|
589 | - { |
|
590 | - // Test for IE11 |
|
591 | - if (stripos($this->_agent, 'Trident/7.0; rv:11.0') !== false) { |
|
592 | - $this->setBrowser(self::BROWSER_IE); |
|
593 | - $this->setVersion('11.0'); |
|
594 | - return true; |
|
595 | - } // Test for v1 - v1.5 IE |
|
596 | - else if (stripos($this->_agent, 'microsoft internet explorer') !== false) { |
|
597 | - $this->setBrowser(self::BROWSER_IE); |
|
598 | - $this->setVersion('1.0'); |
|
599 | - $aresult = stristr($this->_agent, '/'); |
|
600 | - if (preg_match('/308|425|426|474|0b1/i', $aresult)) { |
|
601 | - $this->setVersion('1.5'); |
|
602 | - } |
|
603 | - return true; |
|
604 | - } // Test for versions > 1.5 |
|
605 | - else if (stripos($this->_agent, 'msie') !== false && stripos($this->_agent, 'opera') === false) { |
|
606 | - // See if the browser is the odd MSN Explorer |
|
607 | - if (stripos($this->_agent, 'msnb') !== false) { |
|
608 | - $aresult = explode(' ', stristr(str_replace(';', '; ', $this->_agent), 'MSN')); |
|
609 | - if (isset($aresult[1])) { |
|
610 | - $this->setBrowser(self::BROWSER_MSN); |
|
611 | - $this->setVersion(str_replace(array('(', ')', ';'), '', $aresult[1])); |
|
612 | - return true; |
|
613 | - } |
|
614 | - } |
|
615 | - $aresult = explode(' ', stristr(str_replace(';', '; ', $this->_agent), 'msie')); |
|
616 | - if (isset($aresult[1])) { |
|
617 | - $this->setBrowser(self::BROWSER_IE); |
|
618 | - $this->setVersion(str_replace(array('(', ')', ';'), '', $aresult[1])); |
|
619 | - if (stripos($this->_agent, 'IEMobile') !== false) { |
|
620 | - $this->setBrowser(self::BROWSER_POCKET_IE); |
|
621 | - $this->setMobile(true); |
|
622 | - } |
|
623 | - return true; |
|
624 | - } |
|
625 | - } // Test for versions > IE 10 |
|
626 | - else if (stripos($this->_agent, 'trident') !== false) { |
|
627 | - $this->setBrowser(self::BROWSER_IE); |
|
628 | - $result = explode('rv:', $this->_agent); |
|
629 | - if (isset($result[1])) { |
|
630 | - $this->setVersion(preg_replace('/[^0-9.]+/', '', $result[1])); |
|
631 | - $this->_agent = str_replace(array("Mozilla", "Gecko"), "MSIE", $this->_agent); |
|
632 | - } |
|
633 | - } // Test for Pocket IE |
|
634 | - else if (stripos($this->_agent, 'mspie') !== false || stripos($this->_agent, 'pocket') !== false) { |
|
635 | - $aresult = explode(' ', stristr($this->_agent, 'mspie')); |
|
636 | - if (isset($aresult[1])) { |
|
637 | - $this->setPlatform(self::PLATFORM_WINDOWS_CE); |
|
638 | - $this->setBrowser(self::BROWSER_POCKET_IE); |
|
639 | - $this->setMobile(true); |
|
640 | - |
|
641 | - if (stripos($this->_agent, 'mspie') !== false) { |
|
642 | - $this->setVersion($aresult[1]); |
|
643 | - } else { |
|
644 | - $aversion = explode('/', $this->_agent); |
|
645 | - if (isset($aversion[1])) { |
|
646 | - $this->setVersion($aversion[1]); |
|
647 | - } |
|
648 | - } |
|
649 | - return true; |
|
650 | - } |
|
651 | - } |
|
652 | - return false; |
|
653 | - } |
|
654 | - |
|
655 | - /** |
|
656 | - * Determine if the browser is Opera or not (last updated 1.7) |
|
657 | - * @return boolean True if the browser is Opera otherwise false |
|
658 | - */ |
|
659 | - protected function checkBrowserOpera() |
|
660 | - { |
|
661 | - if (stripos($this->_agent, 'opera mini') !== false) { |
|
662 | - $resultant = stristr($this->_agent, 'opera mini'); |
|
663 | - if (preg_match('/\//', $resultant)) { |
|
664 | - $aresult = explode('/', $resultant); |
|
665 | - if (isset($aresult[1])) { |
|
666 | - $aversion = explode(' ', $aresult[1]); |
|
667 | - $this->setVersion($aversion[0]); |
|
668 | - } |
|
669 | - } else { |
|
670 | - $aversion = explode(' ', stristr($resultant, 'opera mini')); |
|
671 | - if (isset($aversion[1])) { |
|
672 | - $this->setVersion($aversion[1]); |
|
673 | - } |
|
674 | - } |
|
675 | - $this->_browser_name = self::BROWSER_OPERA_MINI; |
|
676 | - $this->setMobile(true); |
|
677 | - return true; |
|
678 | - } else if (stripos($this->_agent, 'opera') !== false) { |
|
679 | - $resultant = stristr($this->_agent, 'opera'); |
|
680 | - if (preg_match('/Version\/(1*.*)$/', $resultant, $matches)) { |
|
681 | - $this->setVersion($matches[1]); |
|
682 | - } else if (preg_match('/\//', $resultant)) { |
|
683 | - $aresult = explode('/', str_replace("(", " ", $resultant)); |
|
684 | - if (isset($aresult[1])) { |
|
685 | - $aversion = explode(' ', $aresult[1]); |
|
686 | - $this->setVersion($aversion[0]); |
|
687 | - } |
|
688 | - } else { |
|
689 | - $aversion = explode(' ', stristr($resultant, 'opera')); |
|
690 | - $this->setVersion(isset($aversion[1]) ? $aversion[1] : ""); |
|
691 | - } |
|
692 | - if (stripos($this->_agent, 'Opera Mobi') !== false) { |
|
693 | - $this->setMobile(true); |
|
694 | - } |
|
695 | - $this->_browser_name = self::BROWSER_OPERA; |
|
696 | - return true; |
|
697 | - } else if (stripos($this->_agent, 'OPR') !== false) { |
|
698 | - $resultant = stristr($this->_agent, 'OPR'); |
|
699 | - if (preg_match('/\//', $resultant)) { |
|
700 | - $aresult = explode('/', str_replace("(", " ", $resultant)); |
|
701 | - if (isset($aresult[1])) { |
|
702 | - $aversion = explode(' ', $aresult[1]); |
|
703 | - $this->setVersion($aversion[0]); |
|
704 | - } |
|
705 | - } |
|
706 | - if (stripos($this->_agent, 'Mobile') !== false) { |
|
707 | - $this->setMobile(true); |
|
708 | - } |
|
709 | - $this->_browser_name = self::BROWSER_OPERA; |
|
710 | - return true; |
|
711 | - } |
|
712 | - return false; |
|
713 | - } |
|
714 | - |
|
715 | - /** |
|
716 | - * Determine if the browser is Chrome or not (last updated 1.7) |
|
717 | - * @return boolean True if the browser is Chrome otherwise false |
|
718 | - */ |
|
719 | - protected function checkBrowserChrome() |
|
720 | - { |
|
721 | - if (stripos($this->_agent, 'Chrome') !== false) { |
|
722 | - $aresult = explode('/', stristr($this->_agent, 'Chrome')); |
|
723 | - if (isset($aresult[1])) { |
|
724 | - $aversion = explode(' ', $aresult[1]); |
|
725 | - $this->setVersion($aversion[0]); |
|
726 | - $this->setBrowser(self::BROWSER_CHROME); |
|
727 | - //Chrome on Android |
|
728 | - if (stripos($this->_agent, 'Android') !== false) { |
|
729 | - if (stripos($this->_agent, 'Mobile') !== false) { |
|
730 | - $this->setMobile(true); |
|
731 | - } else { |
|
732 | - $this->setTablet(true); |
|
733 | - } |
|
734 | - } |
|
735 | - return true; |
|
736 | - } |
|
737 | - } |
|
738 | - return false; |
|
739 | - } |
|
740 | - |
|
741 | - |
|
742 | - /** |
|
743 | - * Determine if the browser is WebTv or not (last updated 1.7) |
|
744 | - * @return boolean True if the browser is WebTv otherwise false |
|
745 | - */ |
|
746 | - protected function checkBrowserWebTv() |
|
747 | - { |
|
748 | - if (stripos($this->_agent, 'webtv') !== false) { |
|
749 | - $aresult = explode('/', stristr($this->_agent, 'webtv')); |
|
750 | - if (isset($aresult[1])) { |
|
751 | - $aversion = explode(' ', $aresult[1]); |
|
752 | - $this->setVersion($aversion[0]); |
|
753 | - $this->setBrowser(self::BROWSER_WEBTV); |
|
754 | - return true; |
|
755 | - } |
|
756 | - } |
|
757 | - return false; |
|
758 | - } |
|
759 | - |
|
760 | - /** |
|
761 | - * Determine if the browser is NetPositive or not (last updated 1.7) |
|
762 | - * @return boolean True if the browser is NetPositive otherwise false |
|
763 | - */ |
|
764 | - protected function checkBrowserNetPositive() |
|
765 | - { |
|
766 | - if (stripos($this->_agent, 'NetPositive') !== false) { |
|
767 | - $aresult = explode('/', stristr($this->_agent, 'NetPositive')); |
|
768 | - if (isset($aresult[1])) { |
|
769 | - $aversion = explode(' ', $aresult[1]); |
|
770 | - $this->setVersion(str_replace(array('(', ')', ';'), '', $aversion[0])); |
|
771 | - $this->setBrowser(self::BROWSER_NETPOSITIVE); |
|
772 | - return true; |
|
773 | - } |
|
774 | - } |
|
775 | - return false; |
|
776 | - } |
|
777 | - |
|
778 | - /** |
|
779 | - * Determine if the browser is Galeon or not (last updated 1.7) |
|
780 | - * @return boolean True if the browser is Galeon otherwise false |
|
781 | - */ |
|
782 | - protected function checkBrowserGaleon() |
|
783 | - { |
|
784 | - if (stripos($this->_agent, 'galeon') !== false) { |
|
785 | - $aresult = explode(' ', stristr($this->_agent, 'galeon')); |
|
786 | - $aversion = explode('/', $aresult[0]); |
|
787 | - if (isset($aversion[1])) { |
|
788 | - $this->setVersion($aversion[1]); |
|
789 | - $this->setBrowser(self::BROWSER_GALEON); |
|
790 | - return true; |
|
791 | - } |
|
792 | - } |
|
793 | - return false; |
|
794 | - } |
|
795 | - |
|
796 | - /** |
|
797 | - * Determine if the browser is Konqueror or not (last updated 1.7) |
|
798 | - * @return boolean True if the browser is Konqueror otherwise false |
|
799 | - */ |
|
800 | - protected function checkBrowserKonqueror() |
|
801 | - { |
|
802 | - if (stripos($this->_agent, 'Konqueror') !== false) { |
|
803 | - $aresult = explode(' ', stristr($this->_agent, 'Konqueror')); |
|
804 | - $aversion = explode('/', $aresult[0]); |
|
805 | - if (isset($aversion[1])) { |
|
806 | - $this->setVersion($aversion[1]); |
|
807 | - $this->setBrowser(self::BROWSER_KONQUEROR); |
|
808 | - return true; |
|
809 | - } |
|
810 | - } |
|
811 | - return false; |
|
812 | - } |
|
813 | - |
|
814 | - /** |
|
815 | - * Determine if the browser is iCab or not (last updated 1.7) |
|
816 | - * @return boolean True if the browser is iCab otherwise false |
|
817 | - */ |
|
818 | - protected function checkBrowserIcab() |
|
819 | - { |
|
820 | - if (stripos($this->_agent, 'icab') !== false) { |
|
821 | - $aversion = explode(' ', stristr(str_replace('/', ' ', $this->_agent), 'icab')); |
|
822 | - if (isset($aversion[1])) { |
|
823 | - $this->setVersion($aversion[1]); |
|
824 | - $this->setBrowser(self::BROWSER_ICAB); |
|
825 | - return true; |
|
826 | - } |
|
827 | - } |
|
828 | - return false; |
|
829 | - } |
|
830 | - |
|
831 | - /** |
|
832 | - * Determine if the browser is OmniWeb or not (last updated 1.7) |
|
833 | - * @return boolean True if the browser is OmniWeb otherwise false |
|
834 | - */ |
|
835 | - protected function checkBrowserOmniWeb() |
|
836 | - { |
|
837 | - if (stripos($this->_agent, 'omniweb') !== false) { |
|
838 | - $aresult = explode('/', stristr($this->_agent, 'omniweb')); |
|
839 | - $aversion = explode(' ', isset($aresult[1]) ? $aresult[1] : ""); |
|
840 | - $this->setVersion($aversion[0]); |
|
841 | - $this->setBrowser(self::BROWSER_OMNIWEB); |
|
842 | - return true; |
|
843 | - } |
|
844 | - return false; |
|
845 | - } |
|
846 | - |
|
847 | - /** |
|
848 | - * Determine if the browser is Phoenix or not (last updated 1.7) |
|
849 | - * @return boolean True if the browser is Phoenix otherwise false |
|
850 | - */ |
|
851 | - protected function checkBrowserPhoenix() |
|
852 | - { |
|
853 | - if (stripos($this->_agent, 'Phoenix') !== false) { |
|
854 | - $aversion = explode('/', stristr($this->_agent, 'Phoenix')); |
|
855 | - if (isset($aversion[1])) { |
|
856 | - $this->setVersion($aversion[1]); |
|
857 | - $this->setBrowser(self::BROWSER_PHOENIX); |
|
858 | - return true; |
|
859 | - } |
|
860 | - } |
|
861 | - return false; |
|
862 | - } |
|
863 | - |
|
864 | - /** |
|
865 | - * Determine if the browser is Firebird or not (last updated 1.7) |
|
866 | - * @return boolean True if the browser is Firebird otherwise false |
|
867 | - */ |
|
868 | - protected function checkBrowserFirebird() |
|
869 | - { |
|
870 | - if (stripos($this->_agent, 'Firebird') !== false) { |
|
871 | - $aversion = explode('/', stristr($this->_agent, 'Firebird')); |
|
872 | - if (isset($aversion[1])) { |
|
873 | - $this->setVersion($aversion[1]); |
|
874 | - $this->setBrowser(self::BROWSER_FIREBIRD); |
|
875 | - return true; |
|
876 | - } |
|
877 | - } |
|
878 | - return false; |
|
879 | - } |
|
880 | - |
|
881 | - /** |
|
882 | - * Determine if the browser is Netscape Navigator 9+ or not (last updated 1.7) |
|
883 | - * NOTE: (http://browser.netscape.com/ - Official support ended on March 1st, 2008) |
|
884 | - * @return boolean True if the browser is Netscape Navigator 9+ otherwise false |
|
885 | - */ |
|
886 | - protected function checkBrowserNetscapeNavigator9Plus() |
|
887 | - { |
|
888 | - if (stripos($this->_agent, 'Firefox') !== false && preg_match('/Navigator\/([^ ]*)/i', $this->_agent, $matches)) { |
|
889 | - $this->setVersion($matches[1]); |
|
890 | - $this->setBrowser(self::BROWSER_NETSCAPE_NAVIGATOR); |
|
891 | - return true; |
|
892 | - } else if (stripos($this->_agent, 'Firefox') === false && preg_match('/Netscape6?\/([^ ]*)/i', $this->_agent, $matches)) { |
|
893 | - $this->setVersion($matches[1]); |
|
894 | - $this->setBrowser(self::BROWSER_NETSCAPE_NAVIGATOR); |
|
895 | - return true; |
|
896 | - } |
|
897 | - return false; |
|
898 | - } |
|
899 | - |
|
900 | - /** |
|
901 | - * Determine if the browser is Shiretoko or not (https://wiki.mozilla.org/Projects/shiretoko) (last updated 1.7) |
|
902 | - * @return boolean True if the browser is Shiretoko otherwise false |
|
903 | - */ |
|
904 | - protected function checkBrowserShiretoko() |
|
905 | - { |
|
906 | - if (stripos($this->_agent, 'Mozilla') !== false && preg_match('/Shiretoko\/([^ ]*)/i', $this->_agent, $matches)) { |
|
907 | - $this->setVersion($matches[1]); |
|
908 | - $this->setBrowser(self::BROWSER_SHIRETOKO); |
|
909 | - return true; |
|
910 | - } |
|
911 | - return false; |
|
912 | - } |
|
913 | - |
|
914 | - /** |
|
915 | - * Determine if the browser is Ice Cat or not (http://en.wikipedia.org/wiki/GNU_IceCat) (last updated 1.7) |
|
916 | - * @return boolean True if the browser is Ice Cat otherwise false |
|
917 | - */ |
|
918 | - protected function checkBrowserIceCat() |
|
919 | - { |
|
920 | - if (stripos($this->_agent, 'Mozilla') !== false && preg_match('/IceCat\/([^ ]*)/i', $this->_agent, $matches)) { |
|
921 | - $this->setVersion($matches[1]); |
|
922 | - $this->setBrowser(self::BROWSER_ICECAT); |
|
923 | - return true; |
|
924 | - } |
|
925 | - return false; |
|
926 | - } |
|
927 | - |
|
928 | - /** |
|
929 | - * Determine if the browser is Nokia or not (last updated 1.7) |
|
930 | - * @return boolean True if the browser is Nokia otherwise false |
|
931 | - */ |
|
932 | - protected function checkBrowserNokia() |
|
933 | - { |
|
934 | - if (preg_match("/Nokia([^\/]+)\/([^ SP]+)/i", $this->_agent, $matches)) { |
|
935 | - $this->setVersion($matches[2]); |
|
936 | - if (stripos($this->_agent, 'Series60') !== false || strpos($this->_agent, 'S60') !== false) { |
|
937 | - $this->setBrowser(self::BROWSER_NOKIA_S60); |
|
938 | - } else { |
|
939 | - $this->setBrowser(self::BROWSER_NOKIA); |
|
940 | - } |
|
941 | - $this->setMobile(true); |
|
942 | - return true; |
|
943 | - } |
|
944 | - return false; |
|
945 | - } |
|
946 | - |
|
947 | - /** |
|
948 | - * Determine if the browser is Firefox or not (last updated 1.7) |
|
949 | - * @return boolean True if the browser is Firefox otherwise false |
|
950 | - */ |
|
951 | - protected function checkBrowserFirefox() |
|
952 | - { |
|
953 | - if (stripos($this->_agent, 'safari') === false) { |
|
954 | - if (preg_match("/Firefox[\/ \(]([^ ;\)]+)/i", $this->_agent, $matches)) { |
|
955 | - $this->setVersion($matches[1]); |
|
956 | - $this->setBrowser(self::BROWSER_FIREFOX); |
|
957 | - //Firefox on Android |
|
958 | - if (stripos($this->_agent, 'Android') !== false) { |
|
959 | - if (stripos($this->_agent, 'Mobile') !== false) { |
|
960 | - $this->setMobile(true); |
|
961 | - } else { |
|
962 | - $this->setTablet(true); |
|
963 | - } |
|
964 | - } |
|
965 | - return true; |
|
966 | - } else if (preg_match("/Firefox$/i", $this->_agent, $matches)) { |
|
967 | - $this->setVersion(""); |
|
968 | - $this->setBrowser(self::BROWSER_FIREFOX); |
|
969 | - return true; |
|
970 | - } |
|
971 | - } |
|
972 | - return false; |
|
973 | - } |
|
974 | - |
|
975 | - /** |
|
976 | - * Determine if the browser is Firefox or not (last updated 1.7) |
|
977 | - * @return boolean True if the browser is Firefox otherwise false |
|
978 | - */ |
|
979 | - protected function checkBrowserIceweasel() |
|
980 | - { |
|
981 | - if (stripos($this->_agent, 'Iceweasel') !== false) { |
|
982 | - $aresult = explode('/', stristr($this->_agent, 'Iceweasel')); |
|
983 | - if (isset($aresult[1])) { |
|
984 | - $aversion = explode(' ', $aresult[1]); |
|
985 | - $this->setVersion($aversion[0]); |
|
986 | - $this->setBrowser(self::BROWSER_ICEWEASEL); |
|
987 | - return true; |
|
988 | - } |
|
989 | - } |
|
990 | - return false; |
|
991 | - } |
|
992 | - |
|
993 | - /** |
|
994 | - * Determine if the browser is Mozilla or not (last updated 1.7) |
|
995 | - * @return boolean True if the browser is Mozilla otherwise false |
|
996 | - */ |
|
997 | - protected function checkBrowserMozilla() |
|
998 | - { |
|
999 | - if (stripos($this->_agent, 'mozilla') !== false && preg_match('/rv:[0-9].[0-9][a-b]?/i', $this->_agent) && stripos($this->_agent, 'netscape') === false) { |
|
1000 | - $aversion = explode(' ', stristr($this->_agent, 'rv:')); |
|
1001 | - preg_match('/rv:[0-9].[0-9][a-b]?/i', $this->_agent, $aversion); |
|
1002 | - $this->setVersion(str_replace('rv:', '', $aversion[0])); |
|
1003 | - $this->setBrowser(self::BROWSER_MOZILLA); |
|
1004 | - return true; |
|
1005 | - } else if (stripos($this->_agent, 'mozilla') !== false && preg_match('/rv:[0-9]\.[0-9]/i', $this->_agent) && stripos($this->_agent, 'netscape') === false) { |
|
1006 | - $aversion = explode('', stristr($this->_agent, 'rv:')); |
|
1007 | - $this->setVersion(str_replace('rv:', '', $aversion[0])); |
|
1008 | - $this->setBrowser(self::BROWSER_MOZILLA); |
|
1009 | - return true; |
|
1010 | - } else if (stripos($this->_agent, 'mozilla') !== false && preg_match('/mozilla\/([^ ]*)/i', $this->_agent, $matches) && stripos($this->_agent, 'netscape') === false) { |
|
1011 | - $this->setVersion($matches[1]); |
|
1012 | - $this->setBrowser(self::BROWSER_MOZILLA); |
|
1013 | - return true; |
|
1014 | - } |
|
1015 | - return false; |
|
1016 | - } |
|
1017 | - |
|
1018 | - /** |
|
1019 | - * Determine if the browser is Lynx or not (last updated 1.7) |
|
1020 | - * @return boolean True if the browser is Lynx otherwise false |
|
1021 | - */ |
|
1022 | - protected function checkBrowserLynx() |
|
1023 | - { |
|
1024 | - if (stripos($this->_agent, 'lynx') !== false) { |
|
1025 | - $aresult = explode('/', stristr($this->_agent, 'Lynx')); |
|
1026 | - $aversion = explode(' ', (isset($aresult[1]) ? $aresult[1] : "")); |
|
1027 | - $this->setVersion($aversion[0]); |
|
1028 | - $this->setBrowser(self::BROWSER_LYNX); |
|
1029 | - return true; |
|
1030 | - } |
|
1031 | - return false; |
|
1032 | - } |
|
1033 | - |
|
1034 | - /** |
|
1035 | - * Determine if the browser is Amaya or not (last updated 1.7) |
|
1036 | - * @return boolean True if the browser is Amaya otherwise false |
|
1037 | - */ |
|
1038 | - protected function checkBrowserAmaya() |
|
1039 | - { |
|
1040 | - if (stripos($this->_agent, 'amaya') !== false) { |
|
1041 | - $aresult = explode('/', stristr($this->_agent, 'Amaya')); |
|
1042 | - if (isset($aresult[1])) { |
|
1043 | - $aversion = explode(' ', $aresult[1]); |
|
1044 | - $this->setVersion($aversion[0]); |
|
1045 | - $this->setBrowser(self::BROWSER_AMAYA); |
|
1046 | - return true; |
|
1047 | - } |
|
1048 | - } |
|
1049 | - return false; |
|
1050 | - } |
|
1051 | - |
|
1052 | - /** |
|
1053 | - * Determine if the browser is Safari or not (last updated 1.7) |
|
1054 | - * @return boolean True if the browser is Safari otherwise false |
|
1055 | - */ |
|
1056 | - protected function checkBrowserSafari() |
|
1057 | - { |
|
1058 | - if (stripos($this->_agent, 'Safari') !== false |
|
1059 | - && stripos($this->_agent, 'iPhone') === false |
|
1060 | - && stripos($this->_agent, 'iPod') === false |
|
1061 | - ) { |
|
1062 | - |
|
1063 | - $aresult = explode('/', stristr($this->_agent, 'Version')); |
|
1064 | - if (isset($aresult[1])) { |
|
1065 | - $aversion = explode(' ', $aresult[1]); |
|
1066 | - $this->setVersion($aversion[0]); |
|
1067 | - } else { |
|
1068 | - $this->setVersion(self::VERSION_UNKNOWN); |
|
1069 | - } |
|
1070 | - $this->setBrowser(self::BROWSER_SAFARI); |
|
1071 | - return true; |
|
1072 | - } |
|
1073 | - return false; |
|
1074 | - } |
|
1075 | - |
|
1076 | - /** |
|
1077 | - * Detect if URL is loaded from FacebookExternalHit |
|
1078 | - * @return boolean True if it detects FacebookExternalHit otherwise false |
|
1079 | - */ |
|
1080 | - protected function checkFacebookExternalHit() |
|
1081 | - { |
|
1082 | - if (stristr($this->_agent, 'FacebookExternalHit')) { |
|
1083 | - $this->setRobot(true); |
|
1084 | - $this->setFacebook(true); |
|
1085 | - return true; |
|
1086 | - } |
|
1087 | - return false; |
|
1088 | - } |
|
1089 | - |
|
1090 | - /** |
|
1091 | - * Detect if URL is being loaded from internal Facebook browser |
|
1092 | - * @return boolean True if it detects internal Facebook browser otherwise false |
|
1093 | - */ |
|
1094 | - protected function checkForFacebookIos() |
|
1095 | - { |
|
1096 | - if (stristr($this->_agent, 'FBIOS')) { |
|
1097 | - $this->setFacebook(true); |
|
1098 | - return true; |
|
1099 | - } |
|
1100 | - return false; |
|
1101 | - } |
|
1102 | - |
|
1103 | - /** |
|
1104 | - * Detect Version for the Safari browser on iOS devices |
|
1105 | - * @return boolean True if it detects the version correctly otherwise false |
|
1106 | - */ |
|
1107 | - protected function getSafariVersionOnIos() |
|
1108 | - { |
|
1109 | - $aresult = explode('/', stristr($this->_agent, 'Version')); |
|
1110 | - if (isset($aresult[1])) { |
|
1111 | - $aversion = explode(' ', $aresult[1]); |
|
1112 | - $this->setVersion($aversion[0]); |
|
1113 | - return true; |
|
1114 | - } |
|
1115 | - return false; |
|
1116 | - } |
|
1117 | - |
|
1118 | - /** |
|
1119 | - * Detect Version for the Chrome browser on iOS devices |
|
1120 | - * @return boolean True if it detects the version correctly otherwise false |
|
1121 | - */ |
|
1122 | - protected function getChromeVersionOnIos() |
|
1123 | - { |
|
1124 | - $aresult = explode('/', stristr($this->_agent, 'CriOS')); |
|
1125 | - if (isset($aresult[1])) { |
|
1126 | - $aversion = explode(' ', $aresult[1]); |
|
1127 | - $this->setVersion($aversion[0]); |
|
1128 | - $this->setBrowser(self::BROWSER_CHROME); |
|
1129 | - return true; |
|
1130 | - } |
|
1131 | - return false; |
|
1132 | - } |
|
1133 | - |
|
1134 | - /** |
|
1135 | - * Determine if the browser is iPhone or not (last updated 1.7) |
|
1136 | - * @return boolean True if the browser is iPhone otherwise false |
|
1137 | - */ |
|
1138 | - protected function checkBrowseriPhone() |
|
1139 | - { |
|
1140 | - if (stripos($this->_agent, 'iPhone') !== false) { |
|
1141 | - $this->setVersion(self::VERSION_UNKNOWN); |
|
1142 | - $this->setBrowser(self::BROWSER_IPHONE); |
|
1143 | - $this->getSafariVersionOnIos(); |
|
1144 | - $this->getChromeVersionOnIos(); |
|
1145 | - $this->checkForFacebookIos(); |
|
1146 | - $this->setMobile(true); |
|
1147 | - return true; |
|
1148 | - } |
|
1149 | - return false; |
|
1150 | - } |
|
1151 | - |
|
1152 | - /** |
|
1153 | - * Determine if the browser is iPad or not (last updated 1.7) |
|
1154 | - * @return boolean True if the browser is iPad otherwise false |
|
1155 | - */ |
|
1156 | - protected function checkBrowseriPad() |
|
1157 | - { |
|
1158 | - if (stripos($this->_agent, 'iPad') !== false) { |
|
1159 | - $this->setVersion(self::VERSION_UNKNOWN); |
|
1160 | - $this->setBrowser(self::BROWSER_IPAD); |
|
1161 | - $this->getSafariVersionOnIos(); |
|
1162 | - $this->getChromeVersionOnIos(); |
|
1163 | - $this->checkForFacebookIos(); |
|
1164 | - $this->setTablet(true); |
|
1165 | - return true; |
|
1166 | - } |
|
1167 | - return false; |
|
1168 | - } |
|
1169 | - |
|
1170 | - /** |
|
1171 | - * Determine if the browser is iPod or not (last updated 1.7) |
|
1172 | - * @return boolean True if the browser is iPod otherwise false |
|
1173 | - */ |
|
1174 | - protected function checkBrowseriPod() |
|
1175 | - { |
|
1176 | - if (stripos($this->_agent, 'iPod') !== false) { |
|
1177 | - $this->setVersion(self::VERSION_UNKNOWN); |
|
1178 | - $this->setBrowser(self::BROWSER_IPOD); |
|
1179 | - $this->getSafariVersionOnIos(); |
|
1180 | - $this->getChromeVersionOnIos(); |
|
1181 | - $this->checkForFacebookIos(); |
|
1182 | - $this->setMobile(true); |
|
1183 | - return true; |
|
1184 | - } |
|
1185 | - return false; |
|
1186 | - } |
|
1187 | - |
|
1188 | - /** |
|
1189 | - * Determine if the browser is Android or not (last updated 1.7) |
|
1190 | - * @return boolean True if the browser is Android otherwise false |
|
1191 | - */ |
|
1192 | - protected function checkBrowserAndroid() |
|
1193 | - { |
|
1194 | - if (stripos($this->_agent, 'Android') !== false) { |
|
1195 | - $aresult = explode(' ', stristr($this->_agent, 'Android')); |
|
1196 | - if (isset($aresult[1])) { |
|
1197 | - $aversion = explode(' ', $aresult[1]); |
|
1198 | - $this->setVersion($aversion[0]); |
|
1199 | - } else { |
|
1200 | - $this->setVersion(self::VERSION_UNKNOWN); |
|
1201 | - } |
|
1202 | - if (stripos($this->_agent, 'Mobile') !== false) { |
|
1203 | - $this->setMobile(true); |
|
1204 | - } else { |
|
1205 | - $this->setTablet(true); |
|
1206 | - } |
|
1207 | - $this->setBrowser(self::BROWSER_ANDROID); |
|
1208 | - return true; |
|
1209 | - } |
|
1210 | - return false; |
|
1211 | - } |
|
1212 | - |
|
1213 | - /** |
|
1214 | - * Determine the user's platform (last updated 1.7) |
|
1215 | - */ |
|
1216 | - protected function checkPlatform() |
|
1217 | - { |
|
1218 | - if (stripos($this->_agent, 'windows') !== false) { |
|
1219 | - $this->_platform = self::PLATFORM_WINDOWS; |
|
1220 | - } else if (stripos($this->_agent, 'iPad') !== false) { |
|
1221 | - $this->_platform = self::PLATFORM_IPAD; |
|
1222 | - } else if (stripos($this->_agent, 'iPod') !== false) { |
|
1223 | - $this->_platform = self::PLATFORM_IPOD; |
|
1224 | - } else if (stripos($this->_agent, 'iPhone') !== false) { |
|
1225 | - $this->_platform = self::PLATFORM_IPHONE; |
|
1226 | - } elseif (stripos($this->_agent, 'mac') !== false) { |
|
1227 | - $this->_platform = self::PLATFORM_APPLE; |
|
1228 | - } elseif (stripos($this->_agent, 'android') !== false) { |
|
1229 | - $this->_platform = self::PLATFORM_ANDROID; |
|
1230 | - } elseif (stripos($this->_agent, 'linux') !== false) { |
|
1231 | - $this->_platform = self::PLATFORM_LINUX; |
|
1232 | - } else if (stripos($this->_agent, 'Nokia') !== false) { |
|
1233 | - $this->_platform = self::PLATFORM_NOKIA; |
|
1234 | - } else if (stripos($this->_agent, 'BlackBerry') !== false) { |
|
1235 | - $this->_platform = self::PLATFORM_BLACKBERRY; |
|
1236 | - } elseif (stripos($this->_agent, 'FreeBSD') !== false) { |
|
1237 | - $this->_platform = self::PLATFORM_FREEBSD; |
|
1238 | - } elseif (stripos($this->_agent, 'OpenBSD') !== false) { |
|
1239 | - $this->_platform = self::PLATFORM_OPENBSD; |
|
1240 | - } elseif (stripos($this->_agent, 'NetBSD') !== false) { |
|
1241 | - $this->_platform = self::PLATFORM_NETBSD; |
|
1242 | - } elseif (stripos($this->_agent, 'OpenSolaris') !== false) { |
|
1243 | - $this->_platform = self::PLATFORM_OPENSOLARIS; |
|
1244 | - } elseif (stripos($this->_agent, 'SunOS') !== false) { |
|
1245 | - $this->_platform = self::PLATFORM_SUNOS; |
|
1246 | - } elseif (stripos($this->_agent, 'OS\/2') !== false) { |
|
1247 | - $this->_platform = self::PLATFORM_OS2; |
|
1248 | - } elseif (stripos($this->_agent, 'BeOS') !== false) { |
|
1249 | - $this->_platform = self::PLATFORM_BEOS; |
|
1250 | - } elseif (stripos($this->_agent, 'win') !== false) { |
|
1251 | - $this->_platform = self::PLATFORM_WINDOWS; |
|
1252 | - } |
|
1253 | - |
|
1254 | - } |
|
1255 | - } |
|
1256 | 45 | \ No newline at end of file |
46 | + class Browser |
|
47 | + { |
|
48 | + private $_agent = ''; |
|
49 | + private $_browser_name = ''; |
|
50 | + private $_version = ''; |
|
51 | + private $_platform = ''; |
|
52 | + private $_os = ''; |
|
53 | + private $_is_aol = false; |
|
54 | + private $_is_mobile = false; |
|
55 | + private $_is_tablet = false; |
|
56 | + private $_is_robot = false; |
|
57 | + private $_is_facebook = false; |
|
58 | + private $_aol_version = ''; |
|
59 | + |
|
60 | + const BROWSER_UNKNOWN = 'unknown'; |
|
61 | + const VERSION_UNKNOWN = 'unknown'; |
|
62 | + |
|
63 | + const BROWSER_OPERA = 'Opera'; // http://www.opera.com/ |
|
64 | + const BROWSER_OPERA_MINI = 'Opera Mini'; // http://www.opera.com/mini/ |
|
65 | + const BROWSER_WEBTV = 'WebTV'; // http://www.webtv.net/pc/ |
|
66 | + const BROWSER_IE = 'Internet Explorer'; // http://www.microsoft.com/ie/ |
|
67 | + const BROWSER_POCKET_IE = 'Pocket Internet Explorer'; // http://en.wikipedia.org/wiki/Internet_Explorer_Mobile |
|
68 | + const BROWSER_KONQUEROR = 'Konqueror'; // http://www.konqueror.org/ |
|
69 | + const BROWSER_ICAB = 'iCab'; // http://www.icab.de/ |
|
70 | + const BROWSER_OMNIWEB = 'OmniWeb'; // http://www.omnigroup.com/applications/omniweb/ |
|
71 | + const BROWSER_FIREBIRD = 'Firebird'; // http://www.ibphoenix.com/ |
|
72 | + const BROWSER_FIREFOX = 'Firefox'; // http://www.mozilla.com/en-US/firefox/firefox.html |
|
73 | + const BROWSER_ICEWEASEL = 'Iceweasel'; // http://www.geticeweasel.org/ |
|
74 | + const BROWSER_SHIRETOKO = 'Shiretoko'; // http://wiki.mozilla.org/Projects/shiretoko |
|
75 | + const BROWSER_MOZILLA = 'Mozilla'; // http://www.mozilla.com/en-US/ |
|
76 | + const BROWSER_AMAYA = 'Amaya'; // http://www.w3.org/Amaya/ |
|
77 | + const BROWSER_LYNX = 'Lynx'; // http://en.wikipedia.org/wiki/Lynx |
|
78 | + const BROWSER_SAFARI = 'Safari'; // http://apple.com |
|
79 | + const BROWSER_IPHONE = 'iPhone'; // http://apple.com |
|
80 | + const BROWSER_IPOD = 'iPod'; // http://apple.com |
|
81 | + const BROWSER_IPAD = 'iPad'; // http://apple.com |
|
82 | + const BROWSER_CHROME = 'Chrome'; // http://www.google.com/chrome |
|
83 | + const BROWSER_ANDROID = 'Android'; // http://www.android.com/ |
|
84 | + const BROWSER_GOOGLEBOT = 'GoogleBot'; // http://en.wikipedia.org/wiki/Googlebot |
|
85 | + const BROWSER_SLURP = 'Yahoo! Slurp'; // http://en.wikipedia.org/wiki/Yahoo!_Slurp |
|
86 | + const BROWSER_W3CVALIDATOR = 'W3C Validator'; // http://validator.w3.org/ |
|
87 | + const BROWSER_BLACKBERRY = 'BlackBerry'; // http://www.blackberry.com/ |
|
88 | + const BROWSER_ICECAT = 'IceCat'; // http://en.wikipedia.org/wiki/GNU_IceCat |
|
89 | + const BROWSER_NOKIA_S60 = 'Nokia S60 OSS Browser'; // http://en.wikipedia.org/wiki/Web_Browser_for_S60 |
|
90 | + const BROWSER_NOKIA = 'Nokia Browser'; // * all other WAP-based browsers on the Nokia Platform |
|
91 | + const BROWSER_MSN = 'MSN Browser'; // http://explorer.msn.com/ |
|
92 | + const BROWSER_MSNBOT = 'MSN Bot'; // http://search.msn.com/msnbot.htm |
|
93 | + const BROWSER_BINGBOT = 'Bing Bot'; // http://en.wikipedia.org/wiki/Bingbot |
|
94 | + |
|
95 | + const BROWSER_NETSCAPE_NAVIGATOR = 'Netscape Navigator'; // http://browser.netscape.com/ (DEPRECATED) |
|
96 | + const BROWSER_GALEON = 'Galeon'; // http://galeon.sourceforge.net/ (DEPRECATED) |
|
97 | + const BROWSER_NETPOSITIVE = 'NetPositive'; // http://en.wikipedia.org/wiki/NetPositive (DEPRECATED) |
|
98 | + const BROWSER_PHOENIX = 'Phoenix'; // http://en.wikipedia.org/wiki/History_of_Mozilla_Firefox (DEPRECATED) |
|
99 | + |
|
100 | + const PLATFORM_UNKNOWN = 'unknown'; |
|
101 | + const PLATFORM_WINDOWS = 'Windows'; |
|
102 | + const PLATFORM_WINDOWS_CE = 'Windows CE'; |
|
103 | + const PLATFORM_APPLE = 'Apple'; |
|
104 | + const PLATFORM_LINUX = 'Linux'; |
|
105 | + const PLATFORM_OS2 = 'OS/2'; |
|
106 | + const PLATFORM_BEOS = 'BeOS'; |
|
107 | + const PLATFORM_IPHONE = 'iPhone'; |
|
108 | + const PLATFORM_IPOD = 'iPod'; |
|
109 | + const PLATFORM_IPAD = 'iPad'; |
|
110 | + const PLATFORM_BLACKBERRY = 'BlackBerry'; |
|
111 | + const PLATFORM_NOKIA = 'Nokia'; |
|
112 | + const PLATFORM_FREEBSD = 'FreeBSD'; |
|
113 | + const PLATFORM_OPENBSD = 'OpenBSD'; |
|
114 | + const PLATFORM_NETBSD = 'NetBSD'; |
|
115 | + const PLATFORM_SUNOS = 'SunOS'; |
|
116 | + const PLATFORM_OPENSOLARIS = 'OpenSolaris'; |
|
117 | + const PLATFORM_ANDROID = 'Android'; |
|
118 | + |
|
119 | + const OPERATING_SYSTEM_UNKNOWN = 'unknown'; |
|
120 | + |
|
121 | + public function __construct($userAgent = "") |
|
122 | + { |
|
123 | + $this->reset(); |
|
124 | + if ($userAgent != "") { |
|
125 | + $this->setUserAgent($userAgent); |
|
126 | + } else { |
|
127 | + $this->determine(); |
|
128 | + } |
|
129 | + } |
|
130 | + |
|
131 | + /** |
|
132 | + * Reset all properties |
|
133 | + */ |
|
134 | + public function reset() |
|
135 | + { |
|
136 | + $this->_agent = isset($_SERVER['HTTP_USER_AGENT']) ? $_SERVER['HTTP_USER_AGENT'] : ""; |
|
137 | + $this->_browser_name = self::BROWSER_UNKNOWN; |
|
138 | + $this->_version = self::VERSION_UNKNOWN; |
|
139 | + $this->_platform = self::PLATFORM_UNKNOWN; |
|
140 | + $this->_os = self::OPERATING_SYSTEM_UNKNOWN; |
|
141 | + $this->_is_aol = false; |
|
142 | + $this->_is_mobile = false; |
|
143 | + $this->_is_tablet = false; |
|
144 | + $this->_is_robot = false; |
|
145 | + $this->_is_facebook = false; |
|
146 | + $this->_aol_version = self::VERSION_UNKNOWN; |
|
147 | + } |
|
148 | + |
|
149 | + /** |
|
150 | + * Check to see if the specific browser is valid |
|
151 | + * @param string $browserName |
|
152 | + * @return bool True if the browser is the specified browser |
|
153 | + */ |
|
154 | + function isBrowser($browserName) |
|
155 | + { |
|
156 | + return (0 == strcasecmp($this->_browser_name, trim($browserName))); |
|
157 | + } |
|
158 | + |
|
159 | + /** |
|
160 | + * The name of the browser. All return types are from the class contants |
|
161 | + * @return string Name of the browser |
|
162 | + */ |
|
163 | + public function getBrowser() |
|
164 | + { |
|
165 | + return $this->_browser_name; |
|
166 | + } |
|
167 | + |
|
168 | + /** |
|
169 | + * Set the name of the browser |
|
170 | + * @param $browser string The name of the Browser |
|
171 | + */ |
|
172 | + public function setBrowser($browser) |
|
173 | + { |
|
174 | + $this->_browser_name = $browser; |
|
175 | + } |
|
176 | + |
|
177 | + /** |
|
178 | + * The name of the platform. All return types are from the class contants |
|
179 | + * @return string Name of the browser |
|
180 | + */ |
|
181 | + public function getPlatform() |
|
182 | + { |
|
183 | + return $this->_platform; |
|
184 | + } |
|
185 | + |
|
186 | + /** |
|
187 | + * Set the name of the platform |
|
188 | + * @param string $platform The name of the Platform |
|
189 | + */ |
|
190 | + public function setPlatform($platform) |
|
191 | + { |
|
192 | + $this->_platform = $platform; |
|
193 | + } |
|
194 | + |
|
195 | + /** |
|
196 | + * The version of the browser. |
|
197 | + * @return string Version of the browser (will only contain alpha-numeric characters and a period) |
|
198 | + */ |
|
199 | + public function getVersion() |
|
200 | + { |
|
201 | + return $this->_version; |
|
202 | + } |
|
203 | + |
|
204 | + /** |
|
205 | + * Set the version of the browser |
|
206 | + * @param string $version The version of the Browser |
|
207 | + */ |
|
208 | + public function setVersion($version) |
|
209 | + { |
|
210 | + $this->_version = preg_replace('/[^0-9,.,a-z,A-Z-]/', '', $version); |
|
211 | + } |
|
212 | + |
|
213 | + /** |
|
214 | + * The version of AOL. |
|
215 | + * @return string Version of AOL (will only contain alpha-numeric characters and a period) |
|
216 | + */ |
|
217 | + public function getAolVersion() |
|
218 | + { |
|
219 | + return $this->_aol_version; |
|
220 | + } |
|
221 | + |
|
222 | + /** |
|
223 | + * Set the version of AOL |
|
224 | + * @param string $version The version of AOL |
|
225 | + */ |
|
226 | + public function setAolVersion($version) |
|
227 | + { |
|
228 | + $this->_aol_version = preg_replace('/[^0-9,.,a-z,A-Z]/', '', $version); |
|
229 | + } |
|
230 | + |
|
231 | + /** |
|
232 | + * Is the browser from AOL? |
|
233 | + * @return boolean True if the browser is from AOL otherwise false |
|
234 | + */ |
|
235 | + public function isAol() |
|
236 | + { |
|
237 | + return $this->_is_aol; |
|
238 | + } |
|
239 | + |
|
240 | + /** |
|
241 | + * Is the browser from a mobile device? |
|
242 | + * @return boolean True if the browser is from a mobile device otherwise false |
|
243 | + */ |
|
244 | + public function isMobile() |
|
245 | + { |
|
246 | + return $this->_is_mobile; |
|
247 | + } |
|
248 | + |
|
249 | + /** |
|
250 | + * Is the browser from a tablet device? |
|
251 | + * @return boolean True if the browser is from a tablet device otherwise false |
|
252 | + */ |
|
253 | + public function isTablet() |
|
254 | + { |
|
255 | + return $this->_is_tablet; |
|
256 | + } |
|
257 | + |
|
258 | + /** |
|
259 | + * Is the browser from a robot (ex Slurp,GoogleBot)? |
|
260 | + * @return boolean True if the browser is from a robot otherwise false |
|
261 | + */ |
|
262 | + public function isRobot() |
|
263 | + { |
|
264 | + return $this->_is_robot; |
|
265 | + } |
|
266 | + |
|
267 | + /** |
|
268 | + * Is the browser from facebook? |
|
269 | + * @return boolean True if the browser is from facebook otherwise false |
|
270 | + */ |
|
271 | + public function isFacebook() |
|
272 | + { |
|
273 | + return $this->_is_facebook; |
|
274 | + } |
|
275 | + |
|
276 | + /** |
|
277 | + * Set the browser to be from AOL |
|
278 | + * @param $isAol |
|
279 | + */ |
|
280 | + public function setAol($isAol) |
|
281 | + { |
|
282 | + $this->_is_aol = $isAol; |
|
283 | + } |
|
284 | + |
|
285 | + /** |
|
286 | + * Set the Browser to be mobile |
|
287 | + * @param boolean $value is the browser a mobile browser or not |
|
288 | + */ |
|
289 | + protected function setMobile($value = true) |
|
290 | + { |
|
291 | + $this->_is_mobile = $value; |
|
292 | + } |
|
293 | + |
|
294 | + /** |
|
295 | + * Set the Browser to be tablet |
|
296 | + * @param boolean $value is the browser a tablet browser or not |
|
297 | + */ |
|
298 | + protected function setTablet($value = true) |
|
299 | + { |
|
300 | + $this->_is_tablet = $value; |
|
301 | + } |
|
302 | + |
|
303 | + /** |
|
304 | + * Set the Browser to be a robot |
|
305 | + * @param boolean $value is the browser a robot or not |
|
306 | + */ |
|
307 | + protected function setRobot($value = true) |
|
308 | + { |
|
309 | + $this->_is_robot = $value; |
|
310 | + } |
|
311 | + |
|
312 | + /** |
|
313 | + * Set the Browser to be a Facebook request |
|
314 | + * @param boolean $value is the browser a robot or not |
|
315 | + */ |
|
316 | + protected function setFacebook($value = true) |
|
317 | + { |
|
318 | + $this->_is_facebook = $value; |
|
319 | + } |
|
320 | + |
|
321 | + /** |
|
322 | + * Get the user agent value in use to determine the browser |
|
323 | + * @return string The user agent from the HTTP header |
|
324 | + */ |
|
325 | + public function getUserAgent() |
|
326 | + { |
|
327 | + return $this->_agent; |
|
328 | + } |
|
329 | + |
|
330 | + /** |
|
331 | + * Set the user agent value (the construction will use the HTTP header value - this will overwrite it) |
|
332 | + * @param string $agent_string The value for the User Agent |
|
333 | + */ |
|
334 | + public function setUserAgent($agent_string) |
|
335 | + { |
|
336 | + $this->reset(); |
|
337 | + $this->_agent = $agent_string; |
|
338 | + $this->determine(); |
|
339 | + } |
|
340 | + |
|
341 | + /** |
|
342 | + * Used to determine if the browser is actually "chromeframe" |
|
343 | + * @since 1.7 |
|
344 | + * @return boolean True if the browser is using chromeframe |
|
345 | + */ |
|
346 | + public function isChromeFrame() |
|
347 | + { |
|
348 | + return (strpos($this->_agent, "chromeframe") !== false); |
|
349 | + } |
|
350 | + |
|
351 | + /** |
|
352 | + * Returns a formatted string with a summary of the details of the browser. |
|
353 | + * @return string formatted string with a summary of the browser |
|
354 | + */ |
|
355 | + public function __toString() |
|
356 | + { |
|
357 | + return "<strong>Browser Name:</strong> {$this->getBrowser()}<br/>\n" . |
|
358 | + "<strong>Browser Version:</strong> {$this->getVersion()}<br/>\n" . |
|
359 | + "<strong>Browser User Agent String:</strong> {$this->getUserAgent()}<br/>\n" . |
|
360 | + "<strong>Platform:</strong> {$this->getPlatform()}<br/>"; |
|
361 | + } |
|
362 | + |
|
363 | + /** |
|
364 | + * Protected routine to calculate and determine what the browser is in use (including platform) |
|
365 | + */ |
|
366 | + protected function determine() |
|
367 | + { |
|
368 | + $this->checkPlatform(); |
|
369 | + $this->checkBrowsers(); |
|
370 | + $this->checkForAol(); |
|
371 | + } |
|
372 | + |
|
373 | + /** |
|
374 | + * Protected routine to determine the browser type |
|
375 | + * @return boolean True if the browser was detected otherwise false |
|
376 | + */ |
|
377 | + protected function checkBrowsers() |
|
378 | + { |
|
379 | + return ( |
|
380 | + // well-known, well-used |
|
381 | + // Special Notes: |
|
382 | + // (1) Opera must be checked before FireFox due to the odd |
|
383 | + // user agents used in some older versions of Opera |
|
384 | + // (2) WebTV is strapped onto Internet Explorer so we must |
|
385 | + // check for WebTV before IE |
|
386 | + // (3) (deprecated) Galeon is based on Firefox and needs to be |
|
387 | + // tested before Firefox is tested |
|
388 | + // (4) OmniWeb is based on Safari so OmniWeb check must occur |
|
389 | + // before Safari |
|
390 | + // (5) Netscape 9+ is based on Firefox so Netscape checks |
|
391 | + // before FireFox are necessary |
|
392 | + $this->checkBrowserWebTv() || |
|
393 | + $this->checkBrowserInternetExplorer() || |
|
394 | + $this->checkBrowserOpera() || |
|
395 | + $this->checkBrowserGaleon() || |
|
396 | + $this->checkBrowserNetscapeNavigator9Plus() || |
|
397 | + $this->checkBrowserFirefox() || |
|
398 | + $this->checkBrowserChrome() || |
|
399 | + $this->checkBrowserOmniWeb() || |
|
400 | + |
|
401 | + // common mobile |
|
402 | + $this->checkBrowserAndroid() || |
|
403 | + $this->checkBrowseriPad() || |
|
404 | + $this->checkBrowseriPod() || |
|
405 | + $this->checkBrowseriPhone() || |
|
406 | + $this->checkBrowserBlackBerry() || |
|
407 | + $this->checkBrowserNokia() || |
|
408 | + |
|
409 | + // common bots |
|
410 | + $this->checkBrowserGoogleBot() || |
|
411 | + $this->checkBrowserMSNBot() || |
|
412 | + $this->checkBrowserBingBot() || |
|
413 | + $this->checkBrowserSlurp() || |
|
414 | + |
|
415 | + // check for facebook external hit when loading URL |
|
416 | + $this->checkFacebookExternalHit() || |
|
417 | + |
|
418 | + // WebKit base check (post mobile and others) |
|
419 | + $this->checkBrowserSafari() || |
|
420 | + |
|
421 | + // everyone else |
|
422 | + $this->checkBrowserNetPositive() || |
|
423 | + $this->checkBrowserFirebird() || |
|
424 | + $this->checkBrowserKonqueror() || |
|
425 | + $this->checkBrowserIcab() || |
|
426 | + $this->checkBrowserPhoenix() || |
|
427 | + $this->checkBrowserAmaya() || |
|
428 | + $this->checkBrowserLynx() || |
|
429 | + $this->checkBrowserShiretoko() || |
|
430 | + $this->checkBrowserIceCat() || |
|
431 | + $this->checkBrowserIceweasel() || |
|
432 | + $this->checkBrowserW3CValidator() || |
|
433 | + $this->checkBrowserMozilla() /* Mozilla is such an open standard that you must check it last */ |
|
434 | + ); |
|
435 | + } |
|
436 | + |
|
437 | + /** |
|
438 | + * Determine if the user is using a BlackBerry (last updated 1.7) |
|
439 | + * @return boolean True if the browser is the BlackBerry browser otherwise false |
|
440 | + */ |
|
441 | + protected function checkBrowserBlackBerry() |
|
442 | + { |
|
443 | + if (stripos($this->_agent, 'blackberry') !== false) { |
|
444 | + $aresult = explode("/", stristr($this->_agent, "BlackBerry")); |
|
445 | + if (isset($aresult[1])) { |
|
446 | + $aversion = explode(' ', $aresult[1]); |
|
447 | + $this->setVersion($aversion[0]); |
|
448 | + $this->_browser_name = self::BROWSER_BLACKBERRY; |
|
449 | + $this->setMobile(true); |
|
450 | + return true; |
|
451 | + } |
|
452 | + } |
|
453 | + return false; |
|
454 | + } |
|
455 | + |
|
456 | + /** |
|
457 | + * Determine if the user is using an AOL User Agent (last updated 1.7) |
|
458 | + * @return boolean True if the browser is from AOL otherwise false |
|
459 | + */ |
|
460 | + protected function checkForAol() |
|
461 | + { |
|
462 | + $this->setAol(false); |
|
463 | + $this->setAolVersion(self::VERSION_UNKNOWN); |
|
464 | + |
|
465 | + if (stripos($this->_agent, 'aol') !== false) { |
|
466 | + $aversion = explode(' ', stristr($this->_agent, 'AOL')); |
|
467 | + if (isset($aversion[1])) { |
|
468 | + $this->setAol(true); |
|
469 | + $this->setAolVersion(preg_replace('/[^0-9\.a-z]/i', '', $aversion[1])); |
|
470 | + return true; |
|
471 | + } |
|
472 | + } |
|
473 | + return false; |
|
474 | + } |
|
475 | + |
|
476 | + /** |
|
477 | + * Determine if the browser is the GoogleBot or not (last updated 1.7) |
|
478 | + * @return boolean True if the browser is the GoogletBot otherwise false |
|
479 | + */ |
|
480 | + protected function checkBrowserGoogleBot() |
|
481 | + { |
|
482 | + if (stripos($this->_agent, 'googlebot') !== false) { |
|
483 | + $aresult = explode('/', stristr($this->_agent, 'googlebot')); |
|
484 | + if (isset($aresult[1])) { |
|
485 | + $aversion = explode(' ', $aresult[1]); |
|
486 | + $this->setVersion(str_replace(';', '', $aversion[0])); |
|
487 | + $this->_browser_name = self::BROWSER_GOOGLEBOT; |
|
488 | + $this->setRobot(true); |
|
489 | + return true; |
|
490 | + } |
|
491 | + } |
|
492 | + return false; |
|
493 | + } |
|
494 | + |
|
495 | + /** |
|
496 | + * Determine if the browser is the MSNBot or not (last updated 1.9) |
|
497 | + * @return boolean True if the browser is the MSNBot otherwise false |
|
498 | + */ |
|
499 | + protected function checkBrowserMSNBot() |
|
500 | + { |
|
501 | + if (stripos($this->_agent, "msnbot") !== false) { |
|
502 | + $aresult = explode("/", stristr($this->_agent, "msnbot")); |
|
503 | + if (isset($aresult[1])) { |
|
504 | + $aversion = explode(" ", $aresult[1]); |
|
505 | + $this->setVersion(str_replace(";", "", $aversion[0])); |
|
506 | + $this->_browser_name = self::BROWSER_MSNBOT; |
|
507 | + $this->setRobot(true); |
|
508 | + return true; |
|
509 | + } |
|
510 | + } |
|
511 | + return false; |
|
512 | + } |
|
513 | + |
|
514 | + /** |
|
515 | + * Determine if the browser is the BingBot or not (last updated 1.9) |
|
516 | + * @return boolean True if the browser is the BingBot otherwise false |
|
517 | + */ |
|
518 | + protected function checkBrowserBingBot() |
|
519 | + { |
|
520 | + if (stripos($this->_agent, "bingbot") !== false) { |
|
521 | + $aresult = explode("/", stristr($this->_agent, "bingbot")); |
|
522 | + if (isset($aresult[1])) { |
|
523 | + $aversion = explode(" ", $aresult[1]); |
|
524 | + $this->setVersion(str_replace(";", "", $aversion[0])); |
|
525 | + $this->_browser_name = self::BROWSER_BINGBOT; |
|
526 | + $this->setRobot(true); |
|
527 | + return true; |
|
528 | + } |
|
529 | + } |
|
530 | + return false; |
|
531 | + } |
|
532 | + |
|
533 | + /** |
|
534 | + * Determine if the browser is the W3C Validator or not (last updated 1.7) |
|
535 | + * @return boolean True if the browser is the W3C Validator otherwise false |
|
536 | + */ |
|
537 | + protected function checkBrowserW3CValidator() |
|
538 | + { |
|
539 | + if (stripos($this->_agent, 'W3C-checklink') !== false) { |
|
540 | + $aresult = explode('/', stristr($this->_agent, 'W3C-checklink')); |
|
541 | + if (isset($aresult[1])) { |
|
542 | + $aversion = explode(' ', $aresult[1]); |
|
543 | + $this->setVersion($aversion[0]); |
|
544 | + $this->_browser_name = self::BROWSER_W3CVALIDATOR; |
|
545 | + return true; |
|
546 | + } |
|
547 | + } else if (stripos($this->_agent, 'W3C_Validator') !== false) { |
|
548 | + // Some of the Validator versions do not delineate w/ a slash - add it back in |
|
549 | + $ua = str_replace("W3C_Validator ", "W3C_Validator/", $this->_agent); |
|
550 | + $aresult = explode('/', stristr($ua, 'W3C_Validator')); |
|
551 | + if (isset($aresult[1])) { |
|
552 | + $aversion = explode(' ', $aresult[1]); |
|
553 | + $this->setVersion($aversion[0]); |
|
554 | + $this->_browser_name = self::BROWSER_W3CVALIDATOR; |
|
555 | + return true; |
|
556 | + } |
|
557 | + } else if (stripos($this->_agent, 'W3C-mobileOK') !== false) { |
|
558 | + $this->_browser_name = self::BROWSER_W3CVALIDATOR; |
|
559 | + $this->setMobile(true); |
|
560 | + return true; |
|
561 | + } |
|
562 | + return false; |
|
563 | + } |
|
564 | + |
|
565 | + /** |
|
566 | + * Determine if the browser is the Yahoo! Slurp Robot or not (last updated 1.7) |
|
567 | + * @return boolean True if the browser is the Yahoo! Slurp Robot otherwise false |
|
568 | + */ |
|
569 | + protected function checkBrowserSlurp() |
|
570 | + { |
|
571 | + if (stripos($this->_agent, 'slurp') !== false) { |
|
572 | + $aresult = explode('/', stristr($this->_agent, 'Slurp')); |
|
573 | + if (isset($aresult[1])) { |
|
574 | + $aversion = explode(' ', $aresult[1]); |
|
575 | + $this->setVersion($aversion[0]); |
|
576 | + $this->_browser_name = self::BROWSER_SLURP; |
|
577 | + $this->setRobot(true); |
|
578 | + $this->setMobile(false); |
|
579 | + return true; |
|
580 | + } |
|
581 | + } |
|
582 | + return false; |
|
583 | + } |
|
584 | + |
|
585 | + /** |
|
586 | + * Determine if the browser is Internet Explorer or not (last updated 1.7) |
|
587 | + * @return boolean True if the browser is Internet Explorer otherwise false |
|
588 | + */ |
|
589 | + protected function checkBrowserInternetExplorer() |
|
590 | + { |
|
591 | + // Test for IE11 |
|
592 | + if (stripos($this->_agent, 'Trident/7.0; rv:11.0') !== false) { |
|
593 | + $this->setBrowser(self::BROWSER_IE); |
|
594 | + $this->setVersion('11.0'); |
|
595 | + return true; |
|
596 | + } // Test for v1 - v1.5 IE |
|
597 | + else if (stripos($this->_agent, 'microsoft internet explorer') !== false) { |
|
598 | + $this->setBrowser(self::BROWSER_IE); |
|
599 | + $this->setVersion('1.0'); |
|
600 | + $aresult = stristr($this->_agent, '/'); |
|
601 | + if (preg_match('/308|425|426|474|0b1/i', $aresult)) { |
|
602 | + $this->setVersion('1.5'); |
|
603 | + } |
|
604 | + return true; |
|
605 | + } // Test for versions > 1.5 |
|
606 | + else if (stripos($this->_agent, 'msie') !== false && stripos($this->_agent, 'opera') === false) { |
|
607 | + // See if the browser is the odd MSN Explorer |
|
608 | + if (stripos($this->_agent, 'msnb') !== false) { |
|
609 | + $aresult = explode(' ', stristr(str_replace(';', '; ', $this->_agent), 'MSN')); |
|
610 | + if (isset($aresult[1])) { |
|
611 | + $this->setBrowser(self::BROWSER_MSN); |
|
612 | + $this->setVersion(str_replace(array('(', ')', ';'), '', $aresult[1])); |
|
613 | + return true; |
|
614 | + } |
|
615 | + } |
|
616 | + $aresult = explode(' ', stristr(str_replace(';', '; ', $this->_agent), 'msie')); |
|
617 | + if (isset($aresult[1])) { |
|
618 | + $this->setBrowser(self::BROWSER_IE); |
|
619 | + $this->setVersion(str_replace(array('(', ')', ';'), '', $aresult[1])); |
|
620 | + if (stripos($this->_agent, 'IEMobile') !== false) { |
|
621 | + $this->setBrowser(self::BROWSER_POCKET_IE); |
|
622 | + $this->setMobile(true); |
|
623 | + } |
|
624 | + return true; |
|
625 | + } |
|
626 | + } // Test for versions > IE 10 |
|
627 | + else if (stripos($this->_agent, 'trident') !== false) { |
|
628 | + $this->setBrowser(self::BROWSER_IE); |
|
629 | + $result = explode('rv:', $this->_agent); |
|
630 | + if (isset($result[1])) { |
|
631 | + $this->setVersion(preg_replace('/[^0-9.]+/', '', $result[1])); |
|
632 | + $this->_agent = str_replace(array("Mozilla", "Gecko"), "MSIE", $this->_agent); |
|
633 | + } |
|
634 | + } // Test for Pocket IE |
|
635 | + else if (stripos($this->_agent, 'mspie') !== false || stripos($this->_agent, 'pocket') !== false) { |
|
636 | + $aresult = explode(' ', stristr($this->_agent, 'mspie')); |
|
637 | + if (isset($aresult[1])) { |
|
638 | + $this->setPlatform(self::PLATFORM_WINDOWS_CE); |
|
639 | + $this->setBrowser(self::BROWSER_POCKET_IE); |
|
640 | + $this->setMobile(true); |
|
641 | + |
|
642 | + if (stripos($this->_agent, 'mspie') !== false) { |
|
643 | + $this->setVersion($aresult[1]); |
|
644 | + } else { |
|
645 | + $aversion = explode('/', $this->_agent); |
|
646 | + if (isset($aversion[1])) { |
|
647 | + $this->setVersion($aversion[1]); |
|
648 | + } |
|
649 | + } |
|
650 | + return true; |
|
651 | + } |
|
652 | + } |
|
653 | + return false; |
|
654 | + } |
|
655 | + |
|
656 | + /** |
|
657 | + * Determine if the browser is Opera or not (last updated 1.7) |
|
658 | + * @return boolean True if the browser is Opera otherwise false |
|
659 | + */ |
|
660 | + protected function checkBrowserOpera() |
|
661 | + { |
|
662 | + if (stripos($this->_agent, 'opera mini') !== false) { |
|
663 | + $resultant = stristr($this->_agent, 'opera mini'); |
|
664 | + if (preg_match('/\//', $resultant)) { |
|
665 | + $aresult = explode('/', $resultant); |
|
666 | + if (isset($aresult[1])) { |
|
667 | + $aversion = explode(' ', $aresult[1]); |
|
668 | + $this->setVersion($aversion[0]); |
|
669 | + } |
|
670 | + } else { |
|
671 | + $aversion = explode(' ', stristr($resultant, 'opera mini')); |
|
672 | + if (isset($aversion[1])) { |
|
673 | + $this->setVersion($aversion[1]); |
|
674 | + } |
|
675 | + } |
|
676 | + $this->_browser_name = self::BROWSER_OPERA_MINI; |
|
677 | + $this->setMobile(true); |
|
678 | + return true; |
|
679 | + } else if (stripos($this->_agent, 'opera') !== false) { |
|
680 | + $resultant = stristr($this->_agent, 'opera'); |
|
681 | + if (preg_match('/Version\/(1*.*)$/', $resultant, $matches)) { |
|
682 | + $this->setVersion($matches[1]); |
|
683 | + } else if (preg_match('/\//', $resultant)) { |
|
684 | + $aresult = explode('/', str_replace("(", " ", $resultant)); |
|
685 | + if (isset($aresult[1])) { |
|
686 | + $aversion = explode(' ', $aresult[1]); |
|
687 | + $this->setVersion($aversion[0]); |
|
688 | + } |
|
689 | + } else { |
|
690 | + $aversion = explode(' ', stristr($resultant, 'opera')); |
|
691 | + $this->setVersion(isset($aversion[1]) ? $aversion[1] : ""); |
|
692 | + } |
|
693 | + if (stripos($this->_agent, 'Opera Mobi') !== false) { |
|
694 | + $this->setMobile(true); |
|
695 | + } |
|
696 | + $this->_browser_name = self::BROWSER_OPERA; |
|
697 | + return true; |
|
698 | + } else if (stripos($this->_agent, 'OPR') !== false) { |
|
699 | + $resultant = stristr($this->_agent, 'OPR'); |
|
700 | + if (preg_match('/\//', $resultant)) { |
|
701 | + $aresult = explode('/', str_replace("(", " ", $resultant)); |
|
702 | + if (isset($aresult[1])) { |
|
703 | + $aversion = explode(' ', $aresult[1]); |
|
704 | + $this->setVersion($aversion[0]); |
|
705 | + } |
|
706 | + } |
|
707 | + if (stripos($this->_agent, 'Mobile') !== false) { |
|
708 | + $this->setMobile(true); |
|
709 | + } |
|
710 | + $this->_browser_name = self::BROWSER_OPERA; |
|
711 | + return true; |
|
712 | + } |
|
713 | + return false; |
|
714 | + } |
|
715 | + |
|
716 | + /** |
|
717 | + * Determine if the browser is Chrome or not (last updated 1.7) |
|
718 | + * @return boolean True if the browser is Chrome otherwise false |
|
719 | + */ |
|
720 | + protected function checkBrowserChrome() |
|
721 | + { |
|
722 | + if (stripos($this->_agent, 'Chrome') !== false) { |
|
723 | + $aresult = explode('/', stristr($this->_agent, 'Chrome')); |
|
724 | + if (isset($aresult[1])) { |
|
725 | + $aversion = explode(' ', $aresult[1]); |
|
726 | + $this->setVersion($aversion[0]); |
|
727 | + $this->setBrowser(self::BROWSER_CHROME); |
|
728 | + //Chrome on Android |
|
729 | + if (stripos($this->_agent, 'Android') !== false) { |
|
730 | + if (stripos($this->_agent, 'Mobile') !== false) { |
|
731 | + $this->setMobile(true); |
|
732 | + } else { |
|
733 | + $this->setTablet(true); |
|
734 | + } |
|
735 | + } |
|
736 | + return true; |
|
737 | + } |
|
738 | + } |
|
739 | + return false; |
|
740 | + } |
|
741 | + |
|
742 | + |
|
743 | + /** |
|
744 | + * Determine if the browser is WebTv or not (last updated 1.7) |
|
745 | + * @return boolean True if the browser is WebTv otherwise false |
|
746 | + */ |
|
747 | + protected function checkBrowserWebTv() |
|
748 | + { |
|
749 | + if (stripos($this->_agent, 'webtv') !== false) { |
|
750 | + $aresult = explode('/', stristr($this->_agent, 'webtv')); |
|
751 | + if (isset($aresult[1])) { |
|
752 | + $aversion = explode(' ', $aresult[1]); |
|
753 | + $this->setVersion($aversion[0]); |
|
754 | + $this->setBrowser(self::BROWSER_WEBTV); |
|
755 | + return true; |
|
756 | + } |
|
757 | + } |
|
758 | + return false; |
|
759 | + } |
|
760 | + |
|
761 | + /** |
|
762 | + * Determine if the browser is NetPositive or not (last updated 1.7) |
|
763 | + * @return boolean True if the browser is NetPositive otherwise false |
|
764 | + */ |
|
765 | + protected function checkBrowserNetPositive() |
|
766 | + { |
|
767 | + if (stripos($this->_agent, 'NetPositive') !== false) { |
|
768 | + $aresult = explode('/', stristr($this->_agent, 'NetPositive')); |
|
769 | + if (isset($aresult[1])) { |
|
770 | + $aversion = explode(' ', $aresult[1]); |
|
771 | + $this->setVersion(str_replace(array('(', ')', ';'), '', $aversion[0])); |
|
772 | + $this->setBrowser(self::BROWSER_NETPOSITIVE); |
|
773 | + return true; |
|
774 | + } |
|
775 | + } |
|
776 | + return false; |
|
777 | + } |
|
778 | + |
|
779 | + /** |
|
780 | + * Determine if the browser is Galeon or not (last updated 1.7) |
|
781 | + * @return boolean True if the browser is Galeon otherwise false |
|
782 | + */ |
|
783 | + protected function checkBrowserGaleon() |
|
784 | + { |
|
785 | + if (stripos($this->_agent, 'galeon') !== false) { |
|
786 | + $aresult = explode(' ', stristr($this->_agent, 'galeon')); |
|
787 | + $aversion = explode('/', $aresult[0]); |
|
788 | + if (isset($aversion[1])) { |
|
789 | + $this->setVersion($aversion[1]); |
|
790 | + $this->setBrowser(self::BROWSER_GALEON); |
|
791 | + return true; |
|
792 | + } |
|
793 | + } |
|
794 | + return false; |
|
795 | + } |
|
796 | + |
|
797 | + /** |
|
798 | + * Determine if the browser is Konqueror or not (last updated 1.7) |
|
799 | + * @return boolean True if the browser is Konqueror otherwise false |
|
800 | + */ |
|
801 | + protected function checkBrowserKonqueror() |
|
802 | + { |
|
803 | + if (stripos($this->_agent, 'Konqueror') !== false) { |
|
804 | + $aresult = explode(' ', stristr($this->_agent, 'Konqueror')); |
|
805 | + $aversion = explode('/', $aresult[0]); |
|
806 | + if (isset($aversion[1])) { |
|
807 | + $this->setVersion($aversion[1]); |
|
808 | + $this->setBrowser(self::BROWSER_KONQUEROR); |
|
809 | + return true; |
|
810 | + } |
|
811 | + } |
|
812 | + return false; |
|
813 | + } |
|
814 | + |
|
815 | + /** |
|
816 | + * Determine if the browser is iCab or not (last updated 1.7) |
|
817 | + * @return boolean True if the browser is iCab otherwise false |
|
818 | + */ |
|
819 | + protected function checkBrowserIcab() |
|
820 | + { |
|
821 | + if (stripos($this->_agent, 'icab') !== false) { |
|
822 | + $aversion = explode(' ', stristr(str_replace('/', ' ', $this->_agent), 'icab')); |
|
823 | + if (isset($aversion[1])) { |
|
824 | + $this->setVersion($aversion[1]); |
|
825 | + $this->setBrowser(self::BROWSER_ICAB); |
|
826 | + return true; |
|
827 | + } |
|
828 | + } |
|
829 | + return false; |
|
830 | + } |
|
831 | + |
|
832 | + /** |
|
833 | + * Determine if the browser is OmniWeb or not (last updated 1.7) |
|
834 | + * @return boolean True if the browser is OmniWeb otherwise false |
|
835 | + */ |
|
836 | + protected function checkBrowserOmniWeb() |
|
837 | + { |
|
838 | + if (stripos($this->_agent, 'omniweb') !== false) { |
|
839 | + $aresult = explode('/', stristr($this->_agent, 'omniweb')); |
|
840 | + $aversion = explode(' ', isset($aresult[1]) ? $aresult[1] : ""); |
|
841 | + $this->setVersion($aversion[0]); |
|
842 | + $this->setBrowser(self::BROWSER_OMNIWEB); |
|
843 | + return true; |
|
844 | + } |
|
845 | + return false; |
|
846 | + } |
|
847 | + |
|
848 | + /** |
|
849 | + * Determine if the browser is Phoenix or not (last updated 1.7) |
|
850 | + * @return boolean True if the browser is Phoenix otherwise false |
|
851 | + */ |
|
852 | + protected function checkBrowserPhoenix() |
|
853 | + { |
|
854 | + if (stripos($this->_agent, 'Phoenix') !== false) { |
|
855 | + $aversion = explode('/', stristr($this->_agent, 'Phoenix')); |
|
856 | + if (isset($aversion[1])) { |
|
857 | + $this->setVersion($aversion[1]); |
|
858 | + $this->setBrowser(self::BROWSER_PHOENIX); |
|
859 | + return true; |
|
860 | + } |
|
861 | + } |
|
862 | + return false; |
|
863 | + } |
|
864 | + |
|
865 | + /** |
|
866 | + * Determine if the browser is Firebird or not (last updated 1.7) |
|
867 | + * @return boolean True if the browser is Firebird otherwise false |
|
868 | + */ |
|
869 | + protected function checkBrowserFirebird() |
|
870 | + { |
|
871 | + if (stripos($this->_agent, 'Firebird') !== false) { |
|
872 | + $aversion = explode('/', stristr($this->_agent, 'Firebird')); |
|
873 | + if (isset($aversion[1])) { |
|
874 | + $this->setVersion($aversion[1]); |
|
875 | + $this->setBrowser(self::BROWSER_FIREBIRD); |
|
876 | + return true; |
|
877 | + } |
|
878 | + } |
|
879 | + return false; |
|
880 | + } |
|
881 | + |
|
882 | + /** |
|
883 | + * Determine if the browser is Netscape Navigator 9+ or not (last updated 1.7) |
|
884 | + * NOTE: (http://browser.netscape.com/ - Official support ended on March 1st, 2008) |
|
885 | + * @return boolean True if the browser is Netscape Navigator 9+ otherwise false |
|
886 | + */ |
|
887 | + protected function checkBrowserNetscapeNavigator9Plus() |
|
888 | + { |
|
889 | + if (stripos($this->_agent, 'Firefox') !== false && preg_match('/Navigator\/([^ ]*)/i', $this->_agent, $matches)) { |
|
890 | + $this->setVersion($matches[1]); |
|
891 | + $this->setBrowser(self::BROWSER_NETSCAPE_NAVIGATOR); |
|
892 | + return true; |
|
893 | + } else if (stripos($this->_agent, 'Firefox') === false && preg_match('/Netscape6?\/([^ ]*)/i', $this->_agent, $matches)) { |
|
894 | + $this->setVersion($matches[1]); |
|
895 | + $this->setBrowser(self::BROWSER_NETSCAPE_NAVIGATOR); |
|
896 | + return true; |
|
897 | + } |
|
898 | + return false; |
|
899 | + } |
|
900 | + |
|
901 | + /** |
|
902 | + * Determine if the browser is Shiretoko or not (https://wiki.mozilla.org/Projects/shiretoko) (last updated 1.7) |
|
903 | + * @return boolean True if the browser is Shiretoko otherwise false |
|
904 | + */ |
|
905 | + protected function checkBrowserShiretoko() |
|
906 | + { |
|
907 | + if (stripos($this->_agent, 'Mozilla') !== false && preg_match('/Shiretoko\/([^ ]*)/i', $this->_agent, $matches)) { |
|
908 | + $this->setVersion($matches[1]); |
|
909 | + $this->setBrowser(self::BROWSER_SHIRETOKO); |
|
910 | + return true; |
|
911 | + } |
|
912 | + return false; |
|
913 | + } |
|
914 | + |
|
915 | + /** |
|
916 | + * Determine if the browser is Ice Cat or not (http://en.wikipedia.org/wiki/GNU_IceCat) (last updated 1.7) |
|
917 | + * @return boolean True if the browser is Ice Cat otherwise false |
|
918 | + */ |
|
919 | + protected function checkBrowserIceCat() |
|
920 | + { |
|
921 | + if (stripos($this->_agent, 'Mozilla') !== false && preg_match('/IceCat\/([^ ]*)/i', $this->_agent, $matches)) { |
|
922 | + $this->setVersion($matches[1]); |
|
923 | + $this->setBrowser(self::BROWSER_ICECAT); |
|
924 | + return true; |
|
925 | + } |
|
926 | + return false; |
|
927 | + } |
|
928 | + |
|
929 | + /** |
|
930 | + * Determine if the browser is Nokia or not (last updated 1.7) |
|
931 | + * @return boolean True if the browser is Nokia otherwise false |
|
932 | + */ |
|
933 | + protected function checkBrowserNokia() |
|
934 | + { |
|
935 | + if (preg_match("/Nokia([^\/]+)\/([^ SP]+)/i", $this->_agent, $matches)) { |
|
936 | + $this->setVersion($matches[2]); |
|
937 | + if (stripos($this->_agent, 'Series60') !== false || strpos($this->_agent, 'S60') !== false) { |
|
938 | + $this->setBrowser(self::BROWSER_NOKIA_S60); |
|
939 | + } else { |
|
940 | + $this->setBrowser(self::BROWSER_NOKIA); |
|
941 | + } |
|
942 | + $this->setMobile(true); |
|
943 | + return true; |
|
944 | + } |
|
945 | + return false; |
|
946 | + } |
|
947 | + |
|
948 | + /** |
|
949 | + * Determine if the browser is Firefox or not (last updated 1.7) |
|
950 | + * @return boolean True if the browser is Firefox otherwise false |
|
951 | + */ |
|
952 | + protected function checkBrowserFirefox() |
|
953 | + { |
|
954 | + if (stripos($this->_agent, 'safari') === false) { |
|
955 | + if (preg_match("/Firefox[\/ \(]([^ ;\)]+)/i", $this->_agent, $matches)) { |
|
956 | + $this->setVersion($matches[1]); |
|
957 | + $this->setBrowser(self::BROWSER_FIREFOX); |
|
958 | + //Firefox on Android |
|
959 | + if (stripos($this->_agent, 'Android') !== false) { |
|
960 | + if (stripos($this->_agent, 'Mobile') !== false) { |
|
961 | + $this->setMobile(true); |
|
962 | + } else { |
|
963 | + $this->setTablet(true); |
|
964 | + } |
|
965 | + } |
|
966 | + return true; |
|
967 | + } else if (preg_match("/Firefox$/i", $this->_agent, $matches)) { |
|
968 | + $this->setVersion(""); |
|
969 | + $this->setBrowser(self::BROWSER_FIREFOX); |
|
970 | + return true; |
|
971 | + } |
|
972 | + } |
|
973 | + return false; |
|
974 | + } |
|
975 | + |
|
976 | + /** |
|
977 | + * Determine if the browser is Firefox or not (last updated 1.7) |
|
978 | + * @return boolean True if the browser is Firefox otherwise false |
|
979 | + */ |
|
980 | + protected function checkBrowserIceweasel() |
|
981 | + { |
|
982 | + if (stripos($this->_agent, 'Iceweasel') !== false) { |
|
983 | + $aresult = explode('/', stristr($this->_agent, 'Iceweasel')); |
|
984 | + if (isset($aresult[1])) { |
|
985 | + $aversion = explode(' ', $aresult[1]); |
|
986 | + $this->setVersion($aversion[0]); |
|
987 | + $this->setBrowser(self::BROWSER_ICEWEASEL); |
|
988 | + return true; |
|
989 | + } |
|
990 | + } |
|
991 | + return false; |
|
992 | + } |
|
993 | + |
|
994 | + /** |
|
995 | + * Determine if the browser is Mozilla or not (last updated 1.7) |
|
996 | + * @return boolean True if the browser is Mozilla otherwise false |
|
997 | + */ |
|
998 | + protected function checkBrowserMozilla() |
|
999 | + { |
|
1000 | + if (stripos($this->_agent, 'mozilla') !== false && preg_match('/rv:[0-9].[0-9][a-b]?/i', $this->_agent) && stripos($this->_agent, 'netscape') === false) { |
|
1001 | + $aversion = explode(' ', stristr($this->_agent, 'rv:')); |
|
1002 | + preg_match('/rv:[0-9].[0-9][a-b]?/i', $this->_agent, $aversion); |
|
1003 | + $this->setVersion(str_replace('rv:', '', $aversion[0])); |
|
1004 | + $this->setBrowser(self::BROWSER_MOZILLA); |
|
1005 | + return true; |
|
1006 | + } else if (stripos($this->_agent, 'mozilla') !== false && preg_match('/rv:[0-9]\.[0-9]/i', $this->_agent) && stripos($this->_agent, 'netscape') === false) { |
|
1007 | + $aversion = explode('', stristr($this->_agent, 'rv:')); |
|
1008 | + $this->setVersion(str_replace('rv:', '', $aversion[0])); |
|
1009 | + $this->setBrowser(self::BROWSER_MOZILLA); |
|
1010 | + return true; |
|
1011 | + } else if (stripos($this->_agent, 'mozilla') !== false && preg_match('/mozilla\/([^ ]*)/i', $this->_agent, $matches) && stripos($this->_agent, 'netscape') === false) { |
|
1012 | + $this->setVersion($matches[1]); |
|
1013 | + $this->setBrowser(self::BROWSER_MOZILLA); |
|
1014 | + return true; |
|
1015 | + } |
|
1016 | + return false; |
|
1017 | + } |
|
1018 | + |
|
1019 | + /** |
|
1020 | + * Determine if the browser is Lynx or not (last updated 1.7) |
|
1021 | + * @return boolean True if the browser is Lynx otherwise false |
|
1022 | + */ |
|
1023 | + protected function checkBrowserLynx() |
|
1024 | + { |
|
1025 | + if (stripos($this->_agent, 'lynx') !== false) { |
|
1026 | + $aresult = explode('/', stristr($this->_agent, 'Lynx')); |
|
1027 | + $aversion = explode(' ', (isset($aresult[1]) ? $aresult[1] : "")); |
|
1028 | + $this->setVersion($aversion[0]); |
|
1029 | + $this->setBrowser(self::BROWSER_LYNX); |
|
1030 | + return true; |
|
1031 | + } |
|
1032 | + return false; |
|
1033 | + } |
|
1034 | + |
|
1035 | + /** |
|
1036 | + * Determine if the browser is Amaya or not (last updated 1.7) |
|
1037 | + * @return boolean True if the browser is Amaya otherwise false |
|
1038 | + */ |
|
1039 | + protected function checkBrowserAmaya() |
|
1040 | + { |
|
1041 | + if (stripos($this->_agent, 'amaya') !== false) { |
|
1042 | + $aresult = explode('/', stristr($this->_agent, 'Amaya')); |
|
1043 | + if (isset($aresult[1])) { |
|
1044 | + $aversion = explode(' ', $aresult[1]); |
|
1045 | + $this->setVersion($aversion[0]); |
|
1046 | + $this->setBrowser(self::BROWSER_AMAYA); |
|
1047 | + return true; |
|
1048 | + } |
|
1049 | + } |
|
1050 | + return false; |
|
1051 | + } |
|
1052 | + |
|
1053 | + /** |
|
1054 | + * Determine if the browser is Safari or not (last updated 1.7) |
|
1055 | + * @return boolean True if the browser is Safari otherwise false |
|
1056 | + */ |
|
1057 | + protected function checkBrowserSafari() |
|
1058 | + { |
|
1059 | + if (stripos($this->_agent, 'Safari') !== false |
|
1060 | + && stripos($this->_agent, 'iPhone') === false |
|
1061 | + && stripos($this->_agent, 'iPod') === false |
|
1062 | + ) { |
|
1063 | + |
|
1064 | + $aresult = explode('/', stristr($this->_agent, 'Version')); |
|
1065 | + if (isset($aresult[1])) { |
|
1066 | + $aversion = explode(' ', $aresult[1]); |
|
1067 | + $this->setVersion($aversion[0]); |
|
1068 | + } else { |
|
1069 | + $this->setVersion(self::VERSION_UNKNOWN); |
|
1070 | + } |
|
1071 | + $this->setBrowser(self::BROWSER_SAFARI); |
|
1072 | + return true; |
|
1073 | + } |
|
1074 | + return false; |
|
1075 | + } |
|
1076 | + |
|
1077 | + /** |
|
1078 | + * Detect if URL is loaded from FacebookExternalHit |
|
1079 | + * @return boolean True if it detects FacebookExternalHit otherwise false |
|
1080 | + */ |
|
1081 | + protected function checkFacebookExternalHit() |
|
1082 | + { |
|
1083 | + if (stristr($this->_agent, 'FacebookExternalHit')) { |
|
1084 | + $this->setRobot(true); |
|
1085 | + $this->setFacebook(true); |
|
1086 | + return true; |
|
1087 | + } |
|
1088 | + return false; |
|
1089 | + } |
|
1090 | + |
|
1091 | + /** |
|
1092 | + * Detect if URL is being loaded from internal Facebook browser |
|
1093 | + * @return boolean True if it detects internal Facebook browser otherwise false |
|
1094 | + */ |
|
1095 | + protected function checkForFacebookIos() |
|
1096 | + { |
|
1097 | + if (stristr($this->_agent, 'FBIOS')) { |
|
1098 | + $this->setFacebook(true); |
|
1099 | + return true; |
|
1100 | + } |
|
1101 | + return false; |
|
1102 | + } |
|
1103 | + |
|
1104 | + /** |
|
1105 | + * Detect Version for the Safari browser on iOS devices |
|
1106 | + * @return boolean True if it detects the version correctly otherwise false |
|
1107 | + */ |
|
1108 | + protected function getSafariVersionOnIos() |
|
1109 | + { |
|
1110 | + $aresult = explode('/', stristr($this->_agent, 'Version')); |
|
1111 | + if (isset($aresult[1])) { |
|
1112 | + $aversion = explode(' ', $aresult[1]); |
|
1113 | + $this->setVersion($aversion[0]); |
|
1114 | + return true; |
|
1115 | + } |
|
1116 | + return false; |
|
1117 | + } |
|
1118 | + |
|
1119 | + /** |
|
1120 | + * Detect Version for the Chrome browser on iOS devices |
|
1121 | + * @return boolean True if it detects the version correctly otherwise false |
|
1122 | + */ |
|
1123 | + protected function getChromeVersionOnIos() |
|
1124 | + { |
|
1125 | + $aresult = explode('/', stristr($this->_agent, 'CriOS')); |
|
1126 | + if (isset($aresult[1])) { |
|
1127 | + $aversion = explode(' ', $aresult[1]); |
|
1128 | + $this->setVersion($aversion[0]); |
|
1129 | + $this->setBrowser(self::BROWSER_CHROME); |
|
1130 | + return true; |
|
1131 | + } |
|
1132 | + return false; |
|
1133 | + } |
|
1134 | + |
|
1135 | + /** |
|
1136 | + * Determine if the browser is iPhone or not (last updated 1.7) |
|
1137 | + * @return boolean True if the browser is iPhone otherwise false |
|
1138 | + */ |
|
1139 | + protected function checkBrowseriPhone() |
|
1140 | + { |
|
1141 | + if (stripos($this->_agent, 'iPhone') !== false) { |
|
1142 | + $this->setVersion(self::VERSION_UNKNOWN); |
|
1143 | + $this->setBrowser(self::BROWSER_IPHONE); |
|
1144 | + $this->getSafariVersionOnIos(); |
|
1145 | + $this->getChromeVersionOnIos(); |
|
1146 | + $this->checkForFacebookIos(); |
|
1147 | + $this->setMobile(true); |
|
1148 | + return true; |
|
1149 | + } |
|
1150 | + return false; |
|
1151 | + } |
|
1152 | + |
|
1153 | + /** |
|
1154 | + * Determine if the browser is iPad or not (last updated 1.7) |
|
1155 | + * @return boolean True if the browser is iPad otherwise false |
|
1156 | + */ |
|
1157 | + protected function checkBrowseriPad() |
|
1158 | + { |
|
1159 | + if (stripos($this->_agent, 'iPad') !== false) { |
|
1160 | + $this->setVersion(self::VERSION_UNKNOWN); |
|
1161 | + $this->setBrowser(self::BROWSER_IPAD); |
|
1162 | + $this->getSafariVersionOnIos(); |
|
1163 | + $this->getChromeVersionOnIos(); |
|
1164 | + $this->checkForFacebookIos(); |
|
1165 | + $this->setTablet(true); |
|
1166 | + return true; |
|
1167 | + } |
|
1168 | + return false; |
|
1169 | + } |
|
1170 | + |
|
1171 | + /** |
|
1172 | + * Determine if the browser is iPod or not (last updated 1.7) |
|
1173 | + * @return boolean True if the browser is iPod otherwise false |
|
1174 | + */ |
|
1175 | + protected function checkBrowseriPod() |
|
1176 | + { |
|
1177 | + if (stripos($this->_agent, 'iPod') !== false) { |
|
1178 | + $this->setVersion(self::VERSION_UNKNOWN); |
|
1179 | + $this->setBrowser(self::BROWSER_IPOD); |
|
1180 | + $this->getSafariVersionOnIos(); |
|
1181 | + $this->getChromeVersionOnIos(); |
|
1182 | + $this->checkForFacebookIos(); |
|
1183 | + $this->setMobile(true); |
|
1184 | + return true; |
|
1185 | + } |
|
1186 | + return false; |
|
1187 | + } |
|
1188 | + |
|
1189 | + /** |
|
1190 | + * Determine if the browser is Android or not (last updated 1.7) |
|
1191 | + * @return boolean True if the browser is Android otherwise false |
|
1192 | + */ |
|
1193 | + protected function checkBrowserAndroid() |
|
1194 | + { |
|
1195 | + if (stripos($this->_agent, 'Android') !== false) { |
|
1196 | + $aresult = explode(' ', stristr($this->_agent, 'Android')); |
|
1197 | + if (isset($aresult[1])) { |
|
1198 | + $aversion = explode(' ', $aresult[1]); |
|
1199 | + $this->setVersion($aversion[0]); |
|
1200 | + } else { |
|
1201 | + $this->setVersion(self::VERSION_UNKNOWN); |
|
1202 | + } |
|
1203 | + if (stripos($this->_agent, 'Mobile') !== false) { |
|
1204 | + $this->setMobile(true); |
|
1205 | + } else { |
|
1206 | + $this->setTablet(true); |
|
1207 | + } |
|
1208 | + $this->setBrowser(self::BROWSER_ANDROID); |
|
1209 | + return true; |
|
1210 | + } |
|
1211 | + return false; |
|
1212 | + } |
|
1213 | + |
|
1214 | + /** |
|
1215 | + * Determine the user's platform (last updated 1.7) |
|
1216 | + */ |
|
1217 | + protected function checkPlatform() |
|
1218 | + { |
|
1219 | + if (stripos($this->_agent, 'windows') !== false) { |
|
1220 | + $this->_platform = self::PLATFORM_WINDOWS; |
|
1221 | + } else if (stripos($this->_agent, 'iPad') !== false) { |
|
1222 | + $this->_platform = self::PLATFORM_IPAD; |
|
1223 | + } else if (stripos($this->_agent, 'iPod') !== false) { |
|
1224 | + $this->_platform = self::PLATFORM_IPOD; |
|
1225 | + } else if (stripos($this->_agent, 'iPhone') !== false) { |
|
1226 | + $this->_platform = self::PLATFORM_IPHONE; |
|
1227 | + } elseif (stripos($this->_agent, 'mac') !== false) { |
|
1228 | + $this->_platform = self::PLATFORM_APPLE; |
|
1229 | + } elseif (stripos($this->_agent, 'android') !== false) { |
|
1230 | + $this->_platform = self::PLATFORM_ANDROID; |
|
1231 | + } elseif (stripos($this->_agent, 'linux') !== false) { |
|
1232 | + $this->_platform = self::PLATFORM_LINUX; |
|
1233 | + } else if (stripos($this->_agent, 'Nokia') !== false) { |
|
1234 | + $this->_platform = self::PLATFORM_NOKIA; |
|
1235 | + } else if (stripos($this->_agent, 'BlackBerry') !== false) { |
|
1236 | + $this->_platform = self::PLATFORM_BLACKBERRY; |
|
1237 | + } elseif (stripos($this->_agent, 'FreeBSD') !== false) { |
|
1238 | + $this->_platform = self::PLATFORM_FREEBSD; |
|
1239 | + } elseif (stripos($this->_agent, 'OpenBSD') !== false) { |
|
1240 | + $this->_platform = self::PLATFORM_OPENBSD; |
|
1241 | + } elseif (stripos($this->_agent, 'NetBSD') !== false) { |
|
1242 | + $this->_platform = self::PLATFORM_NETBSD; |
|
1243 | + } elseif (stripos($this->_agent, 'OpenSolaris') !== false) { |
|
1244 | + $this->_platform = self::PLATFORM_OPENSOLARIS; |
|
1245 | + } elseif (stripos($this->_agent, 'SunOS') !== false) { |
|
1246 | + $this->_platform = self::PLATFORM_SUNOS; |
|
1247 | + } elseif (stripos($this->_agent, 'OS\/2') !== false) { |
|
1248 | + $this->_platform = self::PLATFORM_OS2; |
|
1249 | + } elseif (stripos($this->_agent, 'BeOS') !== false) { |
|
1250 | + $this->_platform = self::PLATFORM_BEOS; |
|
1251 | + } elseif (stripos($this->_agent, 'win') !== false) { |
|
1252 | + $this->_platform = self::PLATFORM_WINDOWS; |
|
1253 | + } |
|
1254 | + |
|
1255 | + } |
|
1256 | + } |
|
1257 | 1257 | \ No newline at end of file |
@@ -353,9 +353,9 @@ |
||
353 | 353 | */ |
354 | 354 | public function __toString() |
355 | 355 | { |
356 | - return "<strong>Browser Name:</strong> {$this->getBrowser()}<br/>\n" . |
|
357 | - "<strong>Browser Version:</strong> {$this->getVersion()}<br/>\n" . |
|
358 | - "<strong>Browser User Agent String:</strong> {$this->getUserAgent()}<br/>\n" . |
|
356 | + return "<strong>Browser Name:</strong> {$this->getBrowser()}<br/>\n". |
|
357 | + "<strong>Browser Version:</strong> {$this->getVersion()}<br/>\n". |
|
358 | + "<strong>Browser User Agent String:</strong> {$this->getUserAgent()}<br/>\n". |
|
359 | 359 | "<strong>Platform:</strong> {$this->getPlatform()}<br/>"; |
360 | 360 | } |
361 | 361 |
@@ -11,7 +11,7 @@ discard block |
||
11 | 11 | use SimpleCalendar\Events\Event_Builder; |
12 | 12 | use SimpleCalendar\Events\Events; |
13 | 13 | |
14 | -if ( ! defined( 'ABSPATH' ) ) { |
|
14 | +if ( ! defined('ABSPATH')) { |
|
15 | 15 | exit; |
16 | 16 | } |
17 | 17 | |
@@ -234,12 +234,12 @@ discard block |
||
234 | 234 | * @param int|object|\WP_Post|Calendar $calendar |
235 | 235 | * @param string $view |
236 | 236 | */ |
237 | - public function __construct( $calendar, $view = '' ) { |
|
237 | + public function __construct($calendar, $view = '') { |
|
238 | 238 | |
239 | 239 | // Set the post object. |
240 | - $this->set_post_object( $calendar ); |
|
240 | + $this->set_post_object($calendar); |
|
241 | 241 | |
242 | - if ( ! is_null( $this->post ) ) { |
|
242 | + if ( ! is_null($this->post)) { |
|
243 | 243 | |
244 | 244 | // Set calendar type and events source. |
245 | 245 | $this->set_taxonomies(); |
@@ -256,23 +256,23 @@ discard block |
||
256 | 256 | $this->set_events_template(); |
257 | 257 | |
258 | 258 | // Get events source data. |
259 | - $feed = simcal_get_feed( $this ); |
|
260 | - if ( $feed instanceof Feed ) { |
|
261 | - if ( ! empty( $feed->events ) ) { |
|
262 | - if ( is_array( $feed->events ) ) { |
|
263 | - $this->set_events( $feed->events ); |
|
264 | - if ( 'use_calendar' == get_post_meta( $this->id, '_feed_timezone_setting', true ) ) { |
|
259 | + $feed = simcal_get_feed($this); |
|
260 | + if ($feed instanceof Feed) { |
|
261 | + if ( ! empty($feed->events)) { |
|
262 | + if (is_array($feed->events)) { |
|
263 | + $this->set_events($feed->events); |
|
264 | + if ('use_calendar' == get_post_meta($this->id, '_feed_timezone_setting', true)) { |
|
265 | 265 | $this->timezone = $feed->timezone; |
266 | 266 | $this->set_start(); |
267 | 267 | } |
268 | - } elseif ( is_string( $feed->events ) ) { |
|
268 | + } elseif (is_string($feed->events)) { |
|
269 | 269 | $this->errors[] = $feed->events; |
270 | 270 | } |
271 | 271 | } |
272 | 272 | } |
273 | 273 | |
274 | 274 | // Set general purpose timestamps. |
275 | - $now = Carbon::now( $this->timezone ); |
|
275 | + $now = Carbon::now($this->timezone); |
|
276 | 276 | $this->now = $now->getTimestamp(); |
277 | 277 | $this->today = $now->startOfDay()->getTimestamp(); |
278 | 278 | $this->offset = $now->getOffset(); |
@@ -283,26 +283,26 @@ discard block |
||
283 | 283 | $this->set_datetime_separator(); |
284 | 284 | |
285 | 285 | // Set earliest and latest event timestamps. |
286 | - if ( $this->events && is_array( $this->events ) ) { |
|
287 | - $this->earliest_event = intval( current( array_keys( $this->events ) ) ); |
|
288 | - $this->latest_event = intval( key( array_slice( $this->events, -1, 1, true ) ) ); |
|
286 | + if ($this->events && is_array($this->events)) { |
|
287 | + $this->earliest_event = intval(current(array_keys($this->events))); |
|
288 | + $this->latest_event = intval(key(array_slice($this->events, -1, 1, true))); |
|
289 | 289 | } |
290 | 290 | |
291 | 291 | // Set calendar end. |
292 | 292 | $this->set_end(); |
293 | 293 | |
294 | 294 | // Set view. |
295 | - if ( ! $view ) { |
|
295 | + if ( ! $view) { |
|
296 | 296 | |
297 | - $calendar_view = get_post_meta( $this->id, '_calendar_view', true ); |
|
298 | - $calendar_view = isset( $calendar_view[ $this->type ] ) ? $calendar_view[ $this->type ] : ''; |
|
297 | + $calendar_view = get_post_meta($this->id, '_calendar_view', true); |
|
298 | + $calendar_view = isset($calendar_view[$this->type]) ? $calendar_view[$this->type] : ''; |
|
299 | 299 | |
300 | - $view = esc_attr( $calendar_view ); |
|
300 | + $view = esc_attr($calendar_view); |
|
301 | 301 | } |
302 | 302 | } |
303 | 303 | |
304 | 304 | // Get view. |
305 | - $this->view = $this->get_view( $view ); |
|
305 | + $this->view = $this->get_view($view); |
|
306 | 306 | } |
307 | 307 | |
308 | 308 | /** |
@@ -314,8 +314,8 @@ discard block |
||
314 | 314 | * |
315 | 315 | * @return bool |
316 | 316 | */ |
317 | - public function __isset( $key ) { |
|
318 | - return metadata_exists( 'post', $this->id, '_' . $key ); |
|
317 | + public function __isset($key) { |
|
318 | + return metadata_exists('post', $this->id, '_'.$key); |
|
319 | 319 | } |
320 | 320 | |
321 | 321 | /** |
@@ -327,9 +327,9 @@ discard block |
||
327 | 327 | * |
328 | 328 | * @return mixed |
329 | 329 | */ |
330 | - public function __get( $key ) { |
|
331 | - $value = get_post_meta( $this->id, '_' . $key, true ); |
|
332 | - if ( ! empty( $value ) ) { |
|
330 | + public function __get($key) { |
|
331 | + $value = get_post_meta($this->id, '_'.$key, true); |
|
332 | + if ( ! empty($value)) { |
|
333 | 333 | $this->$key = $value; |
334 | 334 | } |
335 | 335 | return $value; |
@@ -342,17 +342,17 @@ discard block |
||
342 | 342 | * |
343 | 343 | * @param int|object|\WP_Post|Calendar $calendar |
344 | 344 | */ |
345 | - public function set_post_object( $calendar ) { |
|
346 | - if ( is_numeric( $calendar ) ) { |
|
347 | - $this->id = absint( $calendar ); |
|
348 | - $this->post = get_post( $this->id ); |
|
349 | - } elseif ( $calendar instanceof Calendar ) { |
|
350 | - $this->id = absint( $calendar->id ); |
|
345 | + public function set_post_object($calendar) { |
|
346 | + if (is_numeric($calendar)) { |
|
347 | + $this->id = absint($calendar); |
|
348 | + $this->post = get_post($this->id); |
|
349 | + } elseif ($calendar instanceof Calendar) { |
|
350 | + $this->id = absint($calendar->id); |
|
351 | 351 | $this->post = $calendar->post; |
352 | - } elseif ( $calendar instanceof \WP_Post ) { |
|
353 | - $this->id = absint( $calendar->ID ); |
|
352 | + } elseif ($calendar instanceof \WP_Post) { |
|
353 | + $this->id = absint($calendar->ID); |
|
354 | 354 | $this->post = $calendar; |
355 | - } elseif ( isset( $calendar->id ) && isset( $calendar->post ) ) { |
|
355 | + } elseif (isset($calendar->id) && isset($calendar->post)) { |
|
356 | 356 | $this->id = $calendar->id; |
357 | 357 | $this->post = $calendar->post; |
358 | 358 | } |
@@ -366,8 +366,8 @@ discard block |
||
366 | 366 | * @return string |
367 | 367 | */ |
368 | 368 | public function get_title() { |
369 | - $title = isset( $this->post->post_title ) ? $this->post->post_title : ''; |
|
370 | - return apply_filters( 'simcal_calendar_title', $title ); |
|
369 | + $title = isset($this->post->post_title) ? $this->post->post_title : ''; |
|
370 | + return apply_filters('simcal_calendar_title', $title); |
|
371 | 371 | } |
372 | 372 | |
373 | 373 | /** |
@@ -389,16 +389,16 @@ discard block |
||
389 | 389 | */ |
390 | 390 | protected function set_taxonomies() { |
391 | 391 | // Set calendar type. |
392 | - if ( $type = wp_get_object_terms( $this->id, 'calendar_type' ) ) { |
|
393 | - $this->type = sanitize_title( current( $type )->name ); |
|
392 | + if ($type = wp_get_object_terms($this->id, 'calendar_type')) { |
|
393 | + $this->type = sanitize_title(current($type)->name); |
|
394 | 394 | } else { |
395 | - $this->type = apply_filters( 'simcal_calendar_default_type', 'default-calendar' ); |
|
395 | + $this->type = apply_filters('simcal_calendar_default_type', 'default-calendar'); |
|
396 | 396 | } |
397 | 397 | // Set feed type. |
398 | - if ( $feed_type = wp_get_object_terms( $this->id, 'calendar_feed' ) ) { |
|
399 | - $this->feed = sanitize_title( current( $feed_type )->name ); |
|
398 | + if ($feed_type = wp_get_object_terms($this->id, 'calendar_feed')) { |
|
399 | + $this->feed = sanitize_title(current($feed_type)->name); |
|
400 | 400 | } else { |
401 | - $this->feed = apply_filters( 'simcal_calendar_default_feed', 'google' ); |
|
401 | + $this->feed = apply_filters('simcal_calendar_default_feed', 'google'); |
|
402 | 402 | } |
403 | 403 | } |
404 | 404 | |
@@ -410,7 +410,7 @@ discard block |
||
410 | 410 | * @return Events |
411 | 411 | */ |
412 | 412 | public function get_events() { |
413 | - return new Events( $this->events, $this->timezone ); |
|
413 | + return new Events($this->events, $this->timezone); |
|
414 | 414 | } |
415 | 415 | |
416 | 416 | /** |
@@ -420,14 +420,14 @@ discard block |
||
420 | 420 | * |
421 | 421 | * @param array $array |
422 | 422 | */ |
423 | - public function set_events( array $array ) { |
|
423 | + public function set_events(array $array) { |
|
424 | 424 | |
425 | 425 | $events = array(); |
426 | 426 | |
427 | - if ( ! empty( $array ) ) { |
|
428 | - foreach ( $array as $tz => $e ) { |
|
429 | - foreach ( $e as $event ) { |
|
430 | - $events[ $tz ][] = $event instanceof Event ? $event : new Event( $event ); |
|
427 | + if ( ! empty($array)) { |
|
428 | + foreach ($array as $tz => $e) { |
|
429 | + foreach ($e as $event) { |
|
430 | + $events[$tz][] = $event instanceof Event ? $event : new Event($event); |
|
431 | 431 | } |
432 | 432 | } |
433 | 433 | } |
@@ -444,24 +444,24 @@ discard block |
||
444 | 444 | * |
445 | 445 | * @return string |
446 | 446 | */ |
447 | - public function set_events_template( $template = '' ) { |
|
448 | - if ( empty( $template ) ) { |
|
449 | - $template = isset( $this->post->post_content ) ? $this->post->post_content : ''; |
|
447 | + public function set_events_template($template = '') { |
|
448 | + if (empty($template)) { |
|
449 | + $template = isset($this->post->post_content) ? $this->post->post_content : ''; |
|
450 | 450 | } |
451 | 451 | |
452 | 452 | // TODO: Removed wpautop() call. |
453 | 453 | |
454 | - $event_formatting = get_post_meta( $this->id, '_event_formatting', true ); |
|
454 | + $event_formatting = get_post_meta($this->id, '_event_formatting', true); |
|
455 | 455 | |
456 | - switch( $event_formatting ) { |
|
456 | + switch ($event_formatting) { |
|
457 | 457 | case 'none': |
458 | - $this->events_template = wp_kses_post( trim( $template ) ); |
|
458 | + $this->events_template = wp_kses_post(trim($template)); |
|
459 | 459 | break; |
460 | 460 | case 'no_linebreaks': |
461 | - $this->events_template = wpautop( wp_kses_post( trim( $template ) ), false ); |
|
461 | + $this->events_template = wpautop(wp_kses_post(trim($template)), false); |
|
462 | 462 | break; |
463 | 463 | default: |
464 | - $this->events_template = wpautop( wp_kses_post( trim( $template ) ), true ); |
|
464 | + $this->events_template = wpautop(wp_kses_post(trim($template)), true); |
|
465 | 465 | } |
466 | 466 | |
467 | 467 | //$this->events_template = wpautop( wp_kses_post( trim( $template ) ), true ); |
@@ -474,37 +474,37 @@ discard block |
||
474 | 474 | * |
475 | 475 | * @param string $tz Timezone. |
476 | 476 | */ |
477 | - public function set_timezone( $tz = '' ) { |
|
477 | + public function set_timezone($tz = '') { |
|
478 | 478 | |
479 | - $site_tz = esc_attr( simcal_get_wp_timezone() ); |
|
479 | + $site_tz = esc_attr(simcal_get_wp_timezone()); |
|
480 | 480 | |
481 | - if ( $this->feed === 'grouped-calendars' ) { |
|
481 | + if ($this->feed === 'grouped-calendars') { |
|
482 | 482 | $this->timezone = $site_tz; |
483 | 483 | return; |
484 | 484 | } |
485 | 485 | |
486 | - if ( empty( $tz ) ) { |
|
486 | + if (empty($tz)) { |
|
487 | 487 | |
488 | - $timezone_setting = get_post_meta( $this->id, '_feed_timezone_setting', true ); |
|
488 | + $timezone_setting = get_post_meta($this->id, '_feed_timezone_setting', true); |
|
489 | 489 | |
490 | - if ( 'use_site' == $timezone_setting ) { |
|
490 | + if ('use_site' == $timezone_setting) { |
|
491 | 491 | $tz = $site_tz; |
492 | - } elseif ( 'use_custom' == $timezone_setting ) { |
|
493 | - $custom_timezone = esc_attr( get_post_meta( $this->id, '_feed_timezone', true ) ); |
|
492 | + } elseif ('use_custom' == $timezone_setting) { |
|
493 | + $custom_timezone = esc_attr(get_post_meta($this->id, '_feed_timezone', true)); |
|
494 | 494 | // One may be using a non standard timezone in GMT (UTC) offset format. |
495 | - if ( ( strpos( $custom_timezone, 'UTC+' ) === 0 ) || ( strpos( $custom_timezone, 'UTC-' ) === 0 ) ) { |
|
496 | - $tz = simcal_get_timezone_from_gmt_offset( substr( $custom_timezone, 3 ) ); |
|
495 | + if ((strpos($custom_timezone, 'UTC+') === 0) || (strpos($custom_timezone, 'UTC-') === 0)) { |
|
496 | + $tz = simcal_get_timezone_from_gmt_offset(substr($custom_timezone, 3)); |
|
497 | 497 | } else { |
498 | - $tz = ! empty( $custom_timezone ) ? $custom_timezone : 'UTC'; |
|
498 | + $tz = ! empty($custom_timezone) ? $custom_timezone : 'UTC'; |
|
499 | 499 | } |
500 | 500 | } |
501 | 501 | |
502 | - $this->timezone = empty( $tz ) ? 'UTC' : $tz; |
|
502 | + $this->timezone = empty($tz) ? 'UTC' : $tz; |
|
503 | 503 | return; |
504 | 504 | } |
505 | 505 | |
506 | 506 | $this->site_timezone = $site_tz; |
507 | - $this->timezone = simcal_esc_timezone( $tz, $this->timezone ); |
|
507 | + $this->timezone = simcal_esc_timezone($tz, $this->timezone); |
|
508 | 508 | } |
509 | 509 | |
510 | 510 | /** |
@@ -514,20 +514,20 @@ discard block |
||
514 | 514 | * |
515 | 515 | * @param string $format PHP datetime format. |
516 | 516 | */ |
517 | - public function set_date_format( $format = '' ) { |
|
517 | + public function set_date_format($format = '') { |
|
518 | 518 | |
519 | 519 | $date_format_custom = $date_format_default = $format; |
520 | 520 | |
521 | - if ( empty( $date_format_custom ) ) { |
|
521 | + if (empty($date_format_custom)) { |
|
522 | 522 | |
523 | - $date_format_option = esc_attr( get_post_meta( $this->id, '_calendar_date_format_setting', true ) ); |
|
524 | - $date_format_default = esc_attr( get_option( 'date_format' ) ); |
|
523 | + $date_format_option = esc_attr(get_post_meta($this->id, '_calendar_date_format_setting', true)); |
|
524 | + $date_format_default = esc_attr(get_option('date_format')); |
|
525 | 525 | $date_format_custom = ''; |
526 | 526 | |
527 | - if ( 'use_custom' == $date_format_option ) { |
|
528 | - $date_format_custom = esc_attr( get_post_meta( $this->id, '_calendar_date_format', true ) ); |
|
529 | - } elseif ( 'use_custom_php' == $date_format_option ) { |
|
530 | - $date_format_custom = esc_attr( get_post_meta( $this->id, '_calendar_date_format_php', true ) ); |
|
527 | + if ('use_custom' == $date_format_option) { |
|
528 | + $date_format_custom = esc_attr(get_post_meta($this->id, '_calendar_date_format', true)); |
|
529 | + } elseif ('use_custom_php' == $date_format_option) { |
|
530 | + $date_format_custom = esc_attr(get_post_meta($this->id, '_calendar_date_format_php', true)); |
|
531 | 531 | } |
532 | 532 | } |
533 | 533 | |
@@ -541,20 +541,20 @@ discard block |
||
541 | 541 | * |
542 | 542 | * @param string $format PHP datetime format. |
543 | 543 | */ |
544 | - public function set_time_format( $format = '' ) { |
|
544 | + public function set_time_format($format = '') { |
|
545 | 545 | |
546 | 546 | $time_format_custom = $time_format_default = $format; |
547 | 547 | |
548 | - if ( empty( $time_format_custom ) ) { |
|
548 | + if (empty($time_format_custom)) { |
|
549 | 549 | |
550 | - $time_format_option = esc_attr( get_post_meta( $this->id, '_calendar_time_format_setting', true ) ); |
|
551 | - $time_format_default = esc_attr( get_option( 'time_format' ) ); |
|
550 | + $time_format_option = esc_attr(get_post_meta($this->id, '_calendar_time_format_setting', true)); |
|
551 | + $time_format_default = esc_attr(get_option('time_format')); |
|
552 | 552 | $time_format_custom = ''; |
553 | 553 | |
554 | - if ( 'use_custom' == $time_format_option ) { |
|
555 | - $time_format_custom = esc_attr( get_post_meta( $this->id, '_calendar_time_format', true ) ); |
|
556 | - } elseif ( 'use_custom_php' == $time_format_option ) { |
|
557 | - $time_format_custom = esc_attr( get_post_meta( $this->id, '_calendar_time_format_php', true ) ); |
|
554 | + if ('use_custom' == $time_format_option) { |
|
555 | + $time_format_custom = esc_attr(get_post_meta($this->id, '_calendar_time_format', true)); |
|
556 | + } elseif ('use_custom_php' == $time_format_option) { |
|
557 | + $time_format_custom = esc_attr(get_post_meta($this->id, '_calendar_time_format_php', true)); |
|
558 | 558 | } |
559 | 559 | } |
560 | 560 | |
@@ -568,13 +568,13 @@ discard block |
||
568 | 568 | * |
569 | 569 | * @param string $separator A UTF8 character used as separator. |
570 | 570 | */ |
571 | - public function set_datetime_separator( $separator = '' ) { |
|
571 | + public function set_datetime_separator($separator = '') { |
|
572 | 572 | |
573 | - if ( empty( $separator ) ) { |
|
574 | - $separator = get_post_meta( $this->id, '_calendar_datetime_separator', true ); |
|
573 | + if (empty($separator)) { |
|
574 | + $separator = get_post_meta($this->id, '_calendar_datetime_separator', true); |
|
575 | 575 | } |
576 | 576 | |
577 | - $this->datetime_separator = esc_attr( $separator ); |
|
577 | + $this->datetime_separator = esc_attr($separator); |
|
578 | 578 | } |
579 | 579 | |
580 | 580 | /** |
@@ -584,18 +584,18 @@ discard block |
||
584 | 584 | * |
585 | 585 | * @param int $weekday From 0 (Sunday) to 6 (Friday). |
586 | 586 | */ |
587 | - public function set_start_of_week( $weekday = -1 ) { |
|
587 | + public function set_start_of_week($weekday = -1) { |
|
588 | 588 | |
589 | - $week_starts = is_int( $weekday ) ? $weekday : -1; |
|
589 | + $week_starts = is_int($weekday) ? $weekday : -1; |
|
590 | 590 | |
591 | - if ( $week_starts < 0 || $week_starts > 6 ) { |
|
591 | + if ($week_starts < 0 || $week_starts > 6) { |
|
592 | 592 | |
593 | - $week_starts_setting = get_post_meta( $this->id, '_calendar_week_starts_on_setting', true ); |
|
594 | - $week_starts = intval( get_option( 'start_of_week' ) ); |
|
593 | + $week_starts_setting = get_post_meta($this->id, '_calendar_week_starts_on_setting', true); |
|
594 | + $week_starts = intval(get_option('start_of_week')); |
|
595 | 595 | |
596 | - if ( 'use_custom' == $week_starts_setting ) { |
|
597 | - $week_starts_on = get_post_meta( $this->id, '_calendar_week_starts_on', true ); |
|
598 | - $week_starts = is_numeric( $week_starts_on ) ? intval( $week_starts_on ) : $week_starts; |
|
596 | + if ('use_custom' == $week_starts_setting) { |
|
597 | + $week_starts_on = get_post_meta($this->id, '_calendar_week_starts_on', true); |
|
598 | + $week_starts = is_numeric($week_starts_on) ? intval($week_starts_on) : $week_starts; |
|
599 | 599 | } |
600 | 600 | } |
601 | 601 | |
@@ -609,51 +609,51 @@ discard block |
||
609 | 609 | * |
610 | 610 | * @param int $timestamp |
611 | 611 | */ |
612 | - public function set_start( $timestamp = 0 ) { |
|
612 | + public function set_start($timestamp = 0) { |
|
613 | 613 | |
614 | - if ( is_int( $timestamp ) && $timestamp !== 0 ) { |
|
614 | + if (is_int($timestamp) && $timestamp !== 0) { |
|
615 | 615 | $this->start = $timestamp; |
616 | 616 | return; |
617 | 617 | } |
618 | 618 | |
619 | - $this->start = Carbon::now( $this->timezone )->getTimestamp(); |
|
619 | + $this->start = Carbon::now($this->timezone)->getTimestamp(); |
|
620 | 620 | |
621 | - $calendar_begins = esc_attr( get_post_meta( $this->id, '_calendar_begins', true ) ); |
|
622 | - $nth = max( absint( get_post_meta( $this->id, '_calendar_begins_nth', true ) ), 1 ); |
|
621 | + $calendar_begins = esc_attr(get_post_meta($this->id, '_calendar_begins', true)); |
|
622 | + $nth = max(absint(get_post_meta($this->id, '_calendar_begins_nth', true)), 1); |
|
623 | 623 | |
624 | - if ( 'today' == $calendar_begins ) { |
|
625 | - $this->start = Carbon::today( $this->timezone )->getTimestamp(); |
|
626 | - } elseif ( 'days_before' == $calendar_begins ) { |
|
627 | - $this->start = Carbon::today( $this->timezone )->subDays( $nth )->getTimestamp(); |
|
628 | - } elseif ( 'days_after' == $calendar_begins ) { |
|
629 | - $this->start = Carbon::today( $this->timezone )->addDays( $nth )->getTimestamp(); |
|
630 | - } elseif ( 'this_week' == $calendar_begins ) { |
|
631 | - $week = new Carbon( 'now', $this->timezone ); |
|
632 | - $week->setWeekStartsAt( $this->week_starts ); |
|
624 | + if ('today' == $calendar_begins) { |
|
625 | + $this->start = Carbon::today($this->timezone)->getTimestamp(); |
|
626 | + } elseif ('days_before' == $calendar_begins) { |
|
627 | + $this->start = Carbon::today($this->timezone)->subDays($nth)->getTimestamp(); |
|
628 | + } elseif ('days_after' == $calendar_begins) { |
|
629 | + $this->start = Carbon::today($this->timezone)->addDays($nth)->getTimestamp(); |
|
630 | + } elseif ('this_week' == $calendar_begins) { |
|
631 | + $week = new Carbon('now', $this->timezone); |
|
632 | + $week->setWeekStartsAt($this->week_starts); |
|
633 | 633 | $this->start = $week->startOfWeek()->getTimestamp(); |
634 | - } elseif ( 'weeks_before' == $calendar_begins ) { |
|
635 | - $week = new Carbon( 'now', $this->timezone ); |
|
636 | - $week->setWeekStartsAt( $this->week_starts ); |
|
637 | - $this->start = $week->startOfWeek()->subWeeks( $nth )->getTimestamp(); |
|
638 | - } elseif ( 'weeks_after' == $calendar_begins ) { |
|
639 | - $week = new Carbon( 'now', $this->timezone ); |
|
640 | - $week->setWeekStartsAt( $this->week_starts ); |
|
641 | - $this->start = $week->startOfWeek()->addWeeks( $nth )->getTimestamp(); |
|
642 | - } elseif ( 'this_month' == $calendar_begins ) { |
|
643 | - $this->start = Carbon::today( $this->timezone )->startOfMonth()->getTimeStamp(); |
|
644 | - } elseif ( 'months_before' == $calendar_begins ) { |
|
645 | - $this->start = Carbon::today( $this->timezone )->subMonths( $nth )->startOfMonth()->getTimeStamp(); |
|
646 | - } elseif ( 'months_after' == $calendar_begins ) { |
|
647 | - $this->start = Carbon::today( $this->timezone )->addMonths( $nth )->startOfMonth()->getTimeStamp(); |
|
648 | - } elseif ( 'this_year' == $calendar_begins ) { |
|
649 | - $this->start = Carbon::today( $this->timezone )->startOfYear()->getTimestamp(); |
|
650 | - } elseif ( 'years_before' == $calendar_begins ) { |
|
651 | - $this->start = Carbon::today( $this->timezone )->subYears( $nth )->startOfYear()->getTimeStamp(); |
|
652 | - } elseif ( 'years_after' == $calendar_begins ) { |
|
653 | - $this->start = Carbon::today( $this->timezone )->addYears( $nth )->startOfYear()->getTimeStamp(); |
|
654 | - } elseif ( 'custom_date' == $calendar_begins ) { |
|
655 | - if ( $date = get_post_meta( $this->id, '_calendar_begins_custom_date', true ) ) { |
|
656 | - $this->start = Carbon::createFromFormat( 'Y-m-d', esc_attr( $date ), $this->timezone )->setTimezone( $this->timezone )->startOfDay()->getTimestamp(); |
|
634 | + } elseif ('weeks_before' == $calendar_begins) { |
|
635 | + $week = new Carbon('now', $this->timezone); |
|
636 | + $week->setWeekStartsAt($this->week_starts); |
|
637 | + $this->start = $week->startOfWeek()->subWeeks($nth)->getTimestamp(); |
|
638 | + } elseif ('weeks_after' == $calendar_begins) { |
|
639 | + $week = new Carbon('now', $this->timezone); |
|
640 | + $week->setWeekStartsAt($this->week_starts); |
|
641 | + $this->start = $week->startOfWeek()->addWeeks($nth)->getTimestamp(); |
|
642 | + } elseif ('this_month' == $calendar_begins) { |
|
643 | + $this->start = Carbon::today($this->timezone)->startOfMonth()->getTimeStamp(); |
|
644 | + } elseif ('months_before' == $calendar_begins) { |
|
645 | + $this->start = Carbon::today($this->timezone)->subMonths($nth)->startOfMonth()->getTimeStamp(); |
|
646 | + } elseif ('months_after' == $calendar_begins) { |
|
647 | + $this->start = Carbon::today($this->timezone)->addMonths($nth)->startOfMonth()->getTimeStamp(); |
|
648 | + } elseif ('this_year' == $calendar_begins) { |
|
649 | + $this->start = Carbon::today($this->timezone)->startOfYear()->getTimestamp(); |
|
650 | + } elseif ('years_before' == $calendar_begins) { |
|
651 | + $this->start = Carbon::today($this->timezone)->subYears($nth)->startOfYear()->getTimeStamp(); |
|
652 | + } elseif ('years_after' == $calendar_begins) { |
|
653 | + $this->start = Carbon::today($this->timezone)->addYears($nth)->startOfYear()->getTimeStamp(); |
|
654 | + } elseif ('custom_date' == $calendar_begins) { |
|
655 | + if ($date = get_post_meta($this->id, '_calendar_begins_custom_date', true)) { |
|
656 | + $this->start = Carbon::createFromFormat('Y-m-d', esc_attr($date), $this->timezone)->setTimezone($this->timezone)->startOfDay()->getTimestamp(); |
|
657 | 657 | } |
658 | 658 | } |
659 | 659 | } |
@@ -665,8 +665,8 @@ discard block |
||
665 | 665 | * |
666 | 666 | * @param int $timestamp |
667 | 667 | */ |
668 | - public function set_end( $timestamp = 0 ) { |
|
669 | - $latest = is_int( $timestamp ) && $timestamp !== 0 ? $timestamp : $this->latest_event; |
|
668 | + public function set_end($timestamp = 0) { |
|
669 | + $latest = is_int($timestamp) && $timestamp !== 0 ? $timestamp : $this->latest_event; |
|
670 | 670 | $this->end = $latest > $this->start ? $latest : $this->start; |
671 | 671 | } |
672 | 672 | |
@@ -677,14 +677,14 @@ discard block |
||
677 | 677 | * |
678 | 678 | * @param string|bool $static |
679 | 679 | */ |
680 | - public function set_static( $static = '' ) { |
|
680 | + public function set_static($static = '') { |
|
681 | 681 | |
682 | - if ( ! empty( $static ) && is_bool( $static ) ) { |
|
682 | + if ( ! empty($static) && is_bool($static)) { |
|
683 | 683 | $this->static = $static; |
684 | 684 | return; |
685 | 685 | } |
686 | 686 | |
687 | - if ( 'yes' == get_post_meta( $this->id, '_calendar_is_static', true ) ) { |
|
687 | + if ('yes' == get_post_meta($this->id, '_calendar_is_static', true)) { |
|
688 | 688 | $this->static = true; |
689 | 689 | return; |
690 | 690 | } |
@@ -712,7 +712,7 @@ discard block |
||
712 | 712 | * |
713 | 713 | * @return Calendar_View |
714 | 714 | */ |
715 | - abstract public function get_view( $view = '' ); |
|
715 | + abstract public function get_view($view = ''); |
|
716 | 716 | |
717 | 717 | /** |
718 | 718 | * Get event HTML parsed by template. |
@@ -724,11 +724,11 @@ discard block |
||
724 | 724 | * |
725 | 725 | * @return string |
726 | 726 | */ |
727 | - public function get_event_html( Event $event, $template = '' ) { |
|
728 | - $event_builder = new Event_Builder( $event, $this ); |
|
727 | + public function get_event_html(Event $event, $template = '') { |
|
728 | + $event_builder = new Event_Builder($event, $this); |
|
729 | 729 | // Use the event template to parse tags; if empty, fallback to calendar post content. |
730 | - $template = empty( $template ) ? ( empty( $event->template ) ? $this->events_template : $event->template ) : $template; |
|
731 | - return $event_builder->parse_event_template_tags( $template ); |
|
730 | + $template = empty($template) ? (empty($event->template) ? $this->events_template : $event->template) : $template; |
|
731 | + return $event_builder->parse_event_template_tags($template); |
|
732 | 732 | } |
733 | 733 | |
734 | 734 | /** |
@@ -738,58 +738,58 @@ discard block |
||
738 | 738 | * |
739 | 739 | * @param string $view The calendar view to display. |
740 | 740 | */ |
741 | - public function html( $view = '' ) { |
|
741 | + public function html($view = '') { |
|
742 | 742 | |
743 | - $view = empty( $view ) ? $this->view : $this->get_view( $view ); |
|
743 | + $view = empty($view) ? $this->view : $this->get_view($view); |
|
744 | 744 | |
745 | - if ( $view instanceof Calendar_View ) { |
|
745 | + if ($view instanceof Calendar_View) { |
|
746 | 746 | |
747 | - if ( ! empty( $this->errors ) ) { |
|
747 | + if ( ! empty($this->errors)) { |
|
748 | 748 | |
749 | - if ( current_user_can( 'manage_options' ) ) { |
|
749 | + if (current_user_can('manage_options')) { |
|
750 | 750 | echo '<pre><code>'; |
751 | - foreach ( $this->errors as $error ) { echo $error; } |
|
751 | + foreach ($this->errors as $error) { echo $error; } |
|
752 | 752 | echo '</code></pre>'; |
753 | 753 | } |
754 | 754 | |
755 | 755 | } else { |
756 | 756 | |
757 | 757 | // Get a CSS class from the class name of the calendar view (minus namespace part). |
758 | - $view_name = implode( '-', array_map( 'lcfirst', explode( '_', strtolower( get_class( $view ) ) ) ) ); |
|
759 | - $view_class = substr( $view_name, strrpos( $view_name, '\\' ) + 1 ); |
|
758 | + $view_name = implode('-', array_map('lcfirst', explode('_', strtolower(get_class($view))))); |
|
759 | + $view_class = substr($view_name, strrpos($view_name, '\\') + 1); |
|
760 | 760 | |
761 | - $calendar_class = trim( implode( ' simcal-', apply_filters( 'simcal_calendar_class', array( |
|
761 | + $calendar_class = trim(implode(' simcal-', apply_filters('simcal_calendar_class', array( |
|
762 | 762 | 'simcal-calendar', |
763 | 763 | $this->type, |
764 | 764 | $view_class, |
765 | - ), $this->id ) ) ); |
|
766 | - |
|
767 | - echo '<div class="' . $calendar_class . '" ' |
|
768 | - . 'data-calendar-id="' . $this->id . '" ' |
|
769 | - . 'data-timezone="' . $this->timezone . '" ' |
|
770 | - . 'data-offset="' . $this->offset . '" ' |
|
771 | - . 'data-week-start="' . $this->week_starts . '" ' |
|
772 | - . 'data-calendar-start="' . $this->start .'" ' |
|
773 | - . 'data-calendar-end="' . $this->end . '" ' |
|
774 | - . 'data-events-first="' . $this->earliest_event .'" ' |
|
775 | - . 'data-events-last="' . $this->latest_event . '"' |
|
765 | + ), $this->id))); |
|
766 | + |
|
767 | + echo '<div class="'.$calendar_class.'" ' |
|
768 | + . 'data-calendar-id="'.$this->id.'" ' |
|
769 | + . 'data-timezone="'.$this->timezone.'" ' |
|
770 | + . 'data-offset="'.$this->offset.'" ' |
|
771 | + . 'data-week-start="'.$this->week_starts.'" ' |
|
772 | + . 'data-calendar-start="'.$this->start.'" ' |
|
773 | + . 'data-calendar-end="'.$this->end.'" ' |
|
774 | + . 'data-events-first="'.$this->earliest_event.'" ' |
|
775 | + . 'data-events-last="'.$this->latest_event.'"' |
|
776 | 776 | . '>'; |
777 | 777 | |
778 | - date_default_timezone_set( $this->timezone ); |
|
779 | - do_action( 'simcal_calendar_html_before', $this->id ); |
|
778 | + date_default_timezone_set($this->timezone); |
|
779 | + do_action('simcal_calendar_html_before', $this->id); |
|
780 | 780 | |
781 | 781 | $view->html(); |
782 | 782 | |
783 | - do_action( 'simcal_calendar_html_after', $this->id ); |
|
784 | - date_default_timezone_set( $this->site_timezone ); |
|
783 | + do_action('simcal_calendar_html_after', $this->id); |
|
784 | + date_default_timezone_set($this->site_timezone); |
|
785 | 785 | |
786 | - $settings = get_option( 'simple-calendar_settings_calendars' ); |
|
787 | - $poweredby = isset( $settings['poweredby']['opt_in'] ) ? $settings['poweredby']['opt_in'] : ''; |
|
786 | + $settings = get_option('simple-calendar_settings_calendars'); |
|
787 | + $poweredby = isset($settings['poweredby']['opt_in']) ? $settings['poweredby']['opt_in'] : ''; |
|
788 | 788 | |
789 | - if ( 'yes' == $poweredby ) { |
|
789 | + if ('yes' == $poweredby) { |
|
790 | 790 | $align = is_rtl() ? 'left' : 'right'; |
791 | - echo '<small class="simcal-powered simcal-align-' . $align .'">' . |
|
792 | - sprintf( __( 'Powered by <a href="%s" target="_blank">Simple Calendar</a>', 'google-calendar-events' ), simcal_get_url( 'home' ) ) . |
|
791 | + echo '<small class="simcal-powered simcal-align-'.$align.'">'. |
|
792 | + sprintf(__('Powered by <a href="%s" target="_blank">Simple Calendar</a>', 'google-calendar-events'), simcal_get_url('home')). |
|
793 | 793 | '</small>'; |
794 | 794 | } |
795 | 795 |
@@ -7,7 +7,7 @@ discard block |
||
7 | 7 | * @package SimpleCalendar/Admin/Functions |
8 | 8 | */ |
9 | 9 | |
10 | -if ( ! defined( 'ABSPATH' ) ) { |
|
10 | +if ( ! defined('ABSPATH')) { |
|
11 | 11 | exit; |
12 | 12 | } |
13 | 13 | |
@@ -32,9 +32,9 @@ discard block |
||
32 | 32 | * |
33 | 33 | * @return null|\SimpleCalendar\Abstracts\Admin_Page |
34 | 34 | */ |
35 | -function simcal_get_admin_page( $page ) { |
|
35 | +function simcal_get_admin_page($page) { |
|
36 | 36 | $objects = \SimpleCalendar\plugin()->objects; |
37 | - return $objects instanceof \SimpleCalendar\Objects ? $objects->get_admin_page( $page ) : null; |
|
37 | + return $objects instanceof \SimpleCalendar\Objects ? $objects->get_admin_page($page) : null; |
|
38 | 38 | } |
39 | 39 | |
40 | 40 | /** |
@@ -47,9 +47,9 @@ discard block |
||
47 | 47 | * |
48 | 48 | * @return null|\SimpleCalendar\Abstracts\Field |
49 | 49 | */ |
50 | -function simcal_get_field( $args, $name = '' ) { |
|
50 | +function simcal_get_field($args, $name = '') { |
|
51 | 51 | $objects = \SimpleCalendar\plugin()->objects; |
52 | - return $objects instanceof \SimpleCalendar\Objects ? $objects->get_field( $args, $name ) : null; |
|
52 | + return $objects instanceof \SimpleCalendar\Objects ? $objects->get_field($args, $name) : null; |
|
53 | 53 | } |
54 | 54 | |
55 | 55 | /** |
@@ -62,11 +62,11 @@ discard block |
||
62 | 62 | * |
63 | 63 | * @return void |
64 | 64 | */ |
65 | -function simcal_print_field( $args, $name = '' ) { |
|
65 | +function simcal_print_field($args, $name = '') { |
|
66 | 66 | |
67 | - $field = simcal_get_field( $args, $name ); |
|
67 | + $field = simcal_get_field($args, $name); |
|
68 | 68 | |
69 | - if ( $field instanceof \SimpleCalendar\Abstracts\Field ) { |
|
69 | + if ($field instanceof \SimpleCalendar\Abstracts\Field) { |
|
70 | 70 | $field->html(); |
71 | 71 | } |
72 | 72 | } |
@@ -84,33 +84,33 @@ discard block |
||
84 | 84 | * |
85 | 85 | * @return array|string Sanitized variable |
86 | 86 | */ |
87 | -function simcal_sanitize_input( $var, $func = 'sanitize_text_field' ) { |
|
87 | +function simcal_sanitize_input($var, $func = 'sanitize_text_field') { |
|
88 | 88 | |
89 | - if ( is_null( $var ) ) { |
|
89 | + if (is_null($var)) { |
|
90 | 90 | return ''; |
91 | 91 | } |
92 | 92 | |
93 | - if ( is_bool( $var ) ) { |
|
94 | - if ( $var === true ) { |
|
93 | + if (is_bool($var)) { |
|
94 | + if ($var === true) { |
|
95 | 95 | return 'yes'; |
96 | 96 | } else { |
97 | 97 | return 'no'; |
98 | 98 | } |
99 | 99 | } |
100 | 100 | |
101 | - if ( is_string( $var ) || is_numeric( $var ) ) { |
|
102 | - $func = is_string( $func ) && function_exists( $func ) ? $func : 'sanitize_text_field'; |
|
103 | - return call_user_func( $func, trim( strval( $var ) ) ); |
|
101 | + if (is_string($var) || is_numeric($var)) { |
|
102 | + $func = is_string($func) && function_exists($func) ? $func : 'sanitize_text_field'; |
|
103 | + return call_user_func($func, trim(strval($var))); |
|
104 | 104 | } |
105 | 105 | |
106 | - if ( is_object( $var ) ) { |
|
106 | + if (is_object($var)) { |
|
107 | 107 | $var = (array) $var; |
108 | 108 | } |
109 | 109 | |
110 | - if ( is_array( $var ) ) { |
|
110 | + if (is_array($var)) { |
|
111 | 111 | $array = array(); |
112 | - foreach ( $var as $k => $v ) { |
|
113 | - $array[ $k ] = simcal_sanitize_input( $v ); |
|
112 | + foreach ($var as $k => $v) { |
|
113 | + $array[$k] = simcal_sanitize_input($v); |
|
114 | 114 | } |
115 | 115 | return $array; |
116 | 116 | } |
@@ -128,9 +128,9 @@ discard block |
||
128 | 128 | */ |
129 | 129 | function simcal_is_admin_screen() { |
130 | 130 | |
131 | - $view = function_exists( 'get_current_screen' ) ? get_current_screen() : false; |
|
131 | + $view = function_exists('get_current_screen') ? get_current_screen() : false; |
|
132 | 132 | |
133 | - if ( $view instanceof WP_Screen ) { |
|
133 | + if ($view instanceof WP_Screen) { |
|
134 | 134 | |
135 | 135 | // Screens used by this plugin. |
136 | 136 | $screens = array( |
@@ -145,7 +145,7 @@ discard block |
||
145 | 145 | 'dashboard_page_simple-calendar_credits', |
146 | 146 | 'dashboard_page_simple-calendar_translators', |
147 | 147 | ); |
148 | - if ( in_array( $view->id, $screens ) ) { |
|
148 | + if (in_array($view->id, $screens)) { |
|
149 | 149 | return $view->id; |
150 | 150 | } |
151 | 151 | } |
@@ -164,8 +164,8 @@ discard block |
||
164 | 164 | * |
165 | 165 | * @return \SimpleCalendar\Admin\Updater |
166 | 166 | */ |
167 | -function simcal_addon_updater( $_api_url, $_plugin_file, $_api_data = null ) { |
|
168 | - return new \SimpleCalendar\Admin\Updater( $_api_url, $_plugin_file, $_api_data ); |
|
167 | +function simcal_addon_updater($_api_url, $_plugin_file, $_api_data = null) { |
|
168 | + return new \SimpleCalendar\Admin\Updater($_api_url, $_plugin_file, $_api_data); |
|
169 | 169 | } |
170 | 170 | |
171 | 171 | /** |
@@ -177,10 +177,10 @@ discard block |
||
177 | 177 | * |
178 | 178 | * @return null|string |
179 | 179 | */ |
180 | -function simcal_get_license_key( $addon ) { |
|
181 | - $licenses = get_option( 'simple-calendar_settings_licenses', array() ); |
|
182 | - if ( isset( $licenses['keys'][ $addon ] ) ) { |
|
183 | - return empty( $licenses['keys'][ $addon ] ) ? null : $licenses['keys'][ $addon ]; |
|
180 | +function simcal_get_license_key($addon) { |
|
181 | + $licenses = get_option('simple-calendar_settings_licenses', array()); |
|
182 | + if (isset($licenses['keys'][$addon])) { |
|
183 | + return empty($licenses['keys'][$addon]) ? null : $licenses['keys'][$addon]; |
|
184 | 184 | } |
185 | 185 | return null; |
186 | 186 | } |
@@ -196,9 +196,9 @@ discard block |
||
196 | 196 | * |
197 | 197 | * @return array|string |
198 | 198 | */ |
199 | -function simcal_get_license_status( $addon = null ) { |
|
200 | - $licenses = get_option( 'simple-calendar_licenses_status', array() ); |
|
201 | - return isset( $licenses[ $addon ] ) ? $licenses[ $addon ] : $licenses; |
|
199 | +function simcal_get_license_status($addon = null) { |
|
200 | + $licenses = get_option('simple-calendar_licenses_status', array()); |
|
201 | + return isset($licenses[$addon]) ? $licenses[$addon] : $licenses; |
|
202 | 202 | } |
203 | 203 | |
204 | 204 | /** |
@@ -219,7 +219,7 @@ discard block |
||
219 | 219 | * @since 3.0.0 |
220 | 220 | */ |
221 | 221 | function simcal_delete_admin_notices() { |
222 | - delete_option( 'simple-calendar_admin_notices' ); |
|
222 | + delete_option('simple-calendar_admin_notices'); |
|
223 | 223 | } |
224 | 224 | |
225 | 225 | /** |
@@ -231,22 +231,22 @@ discard block |
||
231 | 231 | * |
232 | 232 | * @return void |
233 | 233 | */ |
234 | -function simcal_print_shortcode_tip( $post_id ) { |
|
234 | +function simcal_print_shortcode_tip($post_id) { |
|
235 | 235 | |
236 | 236 | $browser = new \SimpleCalendar\Browser(); |
237 | - if ( $browser::PLATFORM_APPLE == $browser->getPlatform() ) { |
|
237 | + if ($browser::PLATFORM_APPLE == $browser->getPlatform()) { |
|
238 | 238 | $cmd = '⌘+C'; |
239 | 239 | } else { |
240 | 240 | $cmd = 'Ctrl+C'; |
241 | 241 | } |
242 | 242 | |
243 | - $shortcut = sprintf( __( 'Press %s to copy.', 'google-calendar-events' ), $cmd ); |
|
244 | - $shortcode = sprintf( '[calendar id="%s"]', $post_id ); |
|
243 | + $shortcut = sprintf(__('Press %s to copy.', 'google-calendar-events'), $cmd); |
|
244 | + $shortcode = sprintf('[calendar id="%s"]', $post_id); |
|
245 | 245 | |
246 | - echo "<input readonly='readonly' " . |
|
247 | - "class='simcal-shortcode simcal-calendar-shortcode simcal-shortcode-tip' " . |
|
248 | - "title='" . $shortcut . "' " . |
|
249 | - "onclick='this.select();' value='" . $shortcode . "' />"; |
|
246 | + echo "<input readonly='readonly' ". |
|
247 | + "class='simcal-shortcode simcal-calendar-shortcode simcal-shortcode-tip' ". |
|
248 | + "title='".$shortcut."' ". |
|
249 | + "onclick='this.select();' value='".$shortcode."' />"; |
|
250 | 250 | } |
251 | 251 | |
252 | 252 | /** |
@@ -261,20 +261,20 @@ discard block |
||
261 | 261 | * |
262 | 262 | * @return string $url Full Google Analytics campaign URL |
263 | 263 | */ |
264 | -function simcal_ga_campaign_url( $base_url, $campaign, $content, $raw = false ) { |
|
264 | +function simcal_ga_campaign_url($base_url, $campaign, $content, $raw = false) { |
|
265 | 265 | |
266 | - $url = add_query_arg( array( |
|
266 | + $url = add_query_arg(array( |
|
267 | 267 | 'utm_source' => 'inside-plugin', |
268 | 268 | 'utm_medium' => 'link', |
269 | 269 | 'utm_campaign' => $campaign, // i.e. 'core-plugin', 'gcal-pro' |
270 | 270 | 'utm_content' => $content // i.e. 'sidebar-link', 'settings-link' |
271 | - ), $base_url ); |
|
271 | + ), $base_url); |
|
272 | 272 | |
273 | - if ( $raw ) { |
|
274 | - return esc_url_raw( $url ); |
|
273 | + if ($raw) { |
|
274 | + return esc_url_raw($url); |
|
275 | 275 | } |
276 | 276 | |
277 | - return esc_url( $url ); |
|
277 | + return esc_url($url); |
|
278 | 278 | } |
279 | 279 | |
280 | 280 | /** |
@@ -286,7 +286,7 @@ discard block |
||
286 | 286 | */ |
287 | 287 | function simcal_newsletter_signup() { |
288 | 288 | |
289 | - if ( $screen = simcal_is_admin_screen() ) { |
|
289 | + if ($screen = simcal_is_admin_screen()) { |
|
290 | 290 | |
291 | 291 | global $current_user; |
292 | 292 | wp_get_current_user(); |
@@ -297,11 +297,11 @@ discard block |
||
297 | 297 | <div id="simcal-drip" class="<?php echo $screen; ?>"> |
298 | 298 | <div class="signup"> |
299 | 299 | <p> |
300 | - <?php _e( "Enter your name and email and we'll send you a coupon code for 20% off our Google Calendar Pro add-on.", 'google-calendar-events' ); ?> |
|
300 | + <?php _e("Enter your name and email and we'll send you a coupon code for 20% off our Google Calendar Pro add-on.", 'google-calendar-events'); ?> |
|
301 | 301 | </p> |
302 | 302 | |
303 | 303 | <p> |
304 | - <label for="simcal-drip-field-email"><?php _e( 'Your Email', 'google-calendar-events' ); ?></label><br /> |
|
304 | + <label for="simcal-drip-field-email"><?php _e('Your Email', 'google-calendar-events'); ?></label><br /> |
|
305 | 305 | <input type="email" |
306 | 306 | id="simcal-drip-field-email" |
307 | 307 | name="fields[email]" |
@@ -309,7 +309,7 @@ discard block |
||
309 | 309 | </p> |
310 | 310 | |
311 | 311 | <p> |
312 | - <label for="simcal-drip-field-first_name"><?php _e( 'First Name', 'google-calendar-events' ); ?></label><br /> |
|
312 | + <label for="simcal-drip-field-first_name"><?php _e('First Name', 'google-calendar-events'); ?></label><br /> |
|
313 | 313 | <input type="text" |
314 | 314 | id="simcal-drip-field-first_name" |
315 | 315 | name="fields[first_name]" |
@@ -318,15 +318,15 @@ discard block |
||
318 | 318 | <p class="textright"> |
319 | 319 | <a href="#" |
320 | 320 | id="simcal-drip-signup" |
321 | - class="button button-primary"><?php _e( 'Send me the coupon', 'google-calendar-events' ); ?></a> |
|
321 | + class="button button-primary"><?php _e('Send me the coupon', 'google-calendar-events'); ?></a> |
|
322 | 322 | </p> |
323 | 323 | <div class="textright"> |
324 | - <a href="<?php echo simcal_ga_campaign_url( simcal_get_url( 'gcal-pro' ), 'core-plugin', 'sidebar-link' ); ?>" |
|
325 | - target="_blank"><?php _e( 'Just take me to GCal Pro', 'google-calendar-events' ); ?></a> |
|
324 | + <a href="<?php echo simcal_ga_campaign_url(simcal_get_url('gcal-pro'), 'core-plugin', 'sidebar-link'); ?>" |
|
325 | + target="_blank"><?php _e('Just take me to GCal Pro', 'google-calendar-events'); ?></a> |
|
326 | 326 | </div> |
327 | 327 | </div> |
328 | 328 | <div class="thank-you" style="display: none;"> |
329 | - <?php _e( 'Thank you!', 'google-calendar-events' ); ?> |
|
329 | + <?php _e('Thank you!', 'google-calendar-events'); ?> |
|
330 | 330 | </div> |
331 | 331 | <div class="clear"> |
332 | 332 | </div> |
@@ -9,7 +9,7 @@ discard block |
||
9 | 9 | use Carbon\Carbon; |
10 | 10 | use SimpleCalendar\Abstracts\Calendar; |
11 | 11 | |
12 | -if ( ! defined( 'ABSPATH' ) ) { |
|
12 | +if ( ! defined('ABSPATH')) { |
|
13 | 13 | exit; |
14 | 14 | } |
15 | 15 | |
@@ -54,7 +54,7 @@ discard block |
||
54 | 54 | * @param Event $event |
55 | 55 | * @param Calendar $calendar |
56 | 56 | */ |
57 | - public function __construct( Event $event, Calendar $calendar ) { |
|
57 | + public function __construct(Event $event, Calendar $calendar) { |
|
58 | 58 | $this->event = $event; |
59 | 59 | $this->calendar = $calendar; |
60 | 60 | $this->tags = $this->get_content_tags(); |
@@ -74,84 +74,84 @@ discard block |
||
74 | 74 | * Content Tags * |
75 | 75 | * ============ */ |
76 | 76 | |
77 | - 'title', // The event title. |
|
78 | - 'event-title', // @deprecated An alias for 'title' tag. |
|
79 | - 'description', // The event description. |
|
80 | - |
|
81 | - 'when', // Date and time of the event. |
|
82 | - 'start-time', // Start time of the event. |
|
83 | - 'start-date', // Start date of the event. |
|
84 | - 'start-custom', // @deprecated Start time in a user defined format (set by tag 'format' attribute). |
|
85 | - 'start-human', // Start time in a human friendly format. |
|
86 | - 'end-time', // End time of the event. |
|
87 | - 'end-date', // End date of the event. |
|
88 | - 'end-custom', // @deprecated End date-time in a user defined format (set by tag 'format' attribute). |
|
89 | - 'end-human', // End date-time in a human friendly format. |
|
90 | - |
|
91 | - 'duration', // How long the events lasts, in a human-readable format. |
|
92 | - 'length', // @deprecated An alias of 'duration' tag. |
|
93 | - |
|
94 | - 'location', // Alias of start-location. |
|
95 | - 'start-location', // Location name where the event starts. |
|
96 | - 'maps-link', // @deprecated An alias for 'start-location-link' tag. |
|
97 | - 'start-location-link', // Link to Google Maps querying the event start location address. |
|
98 | - 'end-location', // Location name where the event ends. |
|
99 | - 'end-location-link', // Link to Google Maps querying the event end location address. |
|
100 | - |
|
101 | - 'link', // An HTML link to the event URL. |
|
102 | - 'url', // A string with the raw event link URL. |
|
103 | - |
|
104 | - 'calendar', // The title of the source calendar. |
|
105 | - 'feed-title', // @deprecated An alias of 'calendar'. |
|
106 | - |
|
107 | - 'id', // The event unique ID. |
|
108 | - 'uid', // An alias of ID. |
|
109 | - 'event-id', // @deprecated An alias for 'id' tag. |
|
110 | - 'calendar-id', // The calendar ID. |
|
111 | - 'feed-id', // @deprecated An alias for 'calendar-id' tag. |
|
112 | - 'cal-id', // @deprecated An alias for 'calendar-id' tag. |
|
77 | + 'title', // The event title. |
|
78 | + 'event-title', // @deprecated An alias for 'title' tag. |
|
79 | + 'description', // The event description. |
|
80 | + |
|
81 | + 'when', // Date and time of the event. |
|
82 | + 'start-time', // Start time of the event. |
|
83 | + 'start-date', // Start date of the event. |
|
84 | + 'start-custom', // @deprecated Start time in a user defined format (set by tag 'format' attribute). |
|
85 | + 'start-human', // Start time in a human friendly format. |
|
86 | + 'end-time', // End time of the event. |
|
87 | + 'end-date', // End date of the event. |
|
88 | + 'end-custom', // @deprecated End date-time in a user defined format (set by tag 'format' attribute). |
|
89 | + 'end-human', // End date-time in a human friendly format. |
|
90 | + |
|
91 | + 'duration', // How long the events lasts, in a human-readable format. |
|
92 | + 'length', // @deprecated An alias of 'duration' tag. |
|
93 | + |
|
94 | + 'location', // Alias of start-location. |
|
95 | + 'start-location', // Location name where the event starts. |
|
96 | + 'maps-link', // @deprecated An alias for 'start-location-link' tag. |
|
97 | + 'start-location-link', // Link to Google Maps querying the event start location address. |
|
98 | + 'end-location', // Location name where the event ends. |
|
99 | + 'end-location-link', // Link to Google Maps querying the event end location address. |
|
100 | + |
|
101 | + 'link', // An HTML link to the event URL. |
|
102 | + 'url', // A string with the raw event link URL. |
|
103 | + |
|
104 | + 'calendar', // The title of the source calendar. |
|
105 | + 'feed-title', // @deprecated An alias of 'calendar'. |
|
106 | + |
|
107 | + 'id', // The event unique ID. |
|
108 | + 'uid', // An alias of ID. |
|
109 | + 'event-id', // @deprecated An alias for 'id' tag. |
|
110 | + 'calendar-id', // The calendar ID. |
|
111 | + 'feed-id', // @deprecated An alias for 'calendar-id' tag. |
|
112 | + 'cal-id', // @deprecated An alias for 'calendar-id' tag. |
|
113 | 113 | |
114 | 114 | /* ========= * |
115 | 115 | * Meta Tags * |
116 | 116 | * ========= */ |
117 | 117 | |
118 | - 'attachments', // List of attachments. |
|
119 | - 'attendees', // List of attendees. |
|
120 | - 'organizer', // Creator info. |
|
118 | + 'attachments', // List of attachments. |
|
119 | + 'attendees', // List of attendees. |
|
120 | + 'organizer', // Creator info. |
|
121 | 121 | |
122 | 122 | /* ================ * |
123 | 123 | * Conditional Tags * |
124 | 124 | * ================ */ |
125 | 125 | |
126 | - 'if-title', // If the event has a title. |
|
127 | - 'if-description', // If the event has a description. |
|
128 | - |
|
129 | - 'if-now', // If the event is taking place now. |
|
130 | - 'if-not-now', // If the event is not taking place now (may have ended or just not started yet). |
|
131 | - 'if-started', // If the event has started (and may as well as ended). |
|
132 | - 'if-not-started', // If the event has NOT started yet (event could be any time in the future). |
|
133 | - 'if-ended', // If the event has ended (event could be any time in the past). |
|
134 | - 'if-not-ended', // If the event has NOT ended (may as well as not started yet). |
|
135 | - |
|
136 | - 'if-whole-day', // If the event lasts the whole day. |
|
137 | - 'if-all-day', // @deprecated Alias for 'if-whole-day'. |
|
138 | - 'if-not-whole-day', // If the event does NOT last the whole day. |
|
139 | - 'if-not-all-day', // @deprecated Alias for 'if-not-whole-day'. |
|
140 | - 'if-end-time', // If the event has a set end time. |
|
141 | - 'if-no-end-time', // If the event has NOT a set end time. |
|
142 | - |
|
143 | - 'if-multi-day', // If the event spans multiple days. |
|
144 | - 'if-single-day', // If the event does not span multiple days. |
|
145 | - |
|
146 | - 'if-recurring', // If the event is a recurring event. |
|
147 | - 'if-not-recurring', // If the event is NOT a recurring event. |
|
148 | - |
|
149 | - 'if-location', // @deprecated Alias for 'if-start-location'. |
|
150 | - 'if-start-location', // Does the event has a start location? |
|
151 | - 'if-end-location', // Does the event has an end location? |
|
152 | - 'if-not-location', // @deprecated Alias for 'if-not-start-location'. |
|
126 | + 'if-title', // If the event has a title. |
|
127 | + 'if-description', // If the event has a description. |
|
128 | + |
|
129 | + 'if-now', // If the event is taking place now. |
|
130 | + 'if-not-now', // If the event is not taking place now (may have ended or just not started yet). |
|
131 | + 'if-started', // If the event has started (and may as well as ended). |
|
132 | + 'if-not-started', // If the event has NOT started yet (event could be any time in the future). |
|
133 | + 'if-ended', // If the event has ended (event could be any time in the past). |
|
134 | + 'if-not-ended', // If the event has NOT ended (may as well as not started yet). |
|
135 | + |
|
136 | + 'if-whole-day', // If the event lasts the whole day. |
|
137 | + 'if-all-day', // @deprecated Alias for 'if-whole-day'. |
|
138 | + 'if-not-whole-day', // If the event does NOT last the whole day. |
|
139 | + 'if-not-all-day', // @deprecated Alias for 'if-not-whole-day'. |
|
140 | + 'if-end-time', // If the event has a set end time. |
|
141 | + 'if-no-end-time', // If the event has NOT a set end time. |
|
142 | + |
|
143 | + 'if-multi-day', // If the event spans multiple days. |
|
144 | + 'if-single-day', // If the event does not span multiple days. |
|
145 | + |
|
146 | + 'if-recurring', // If the event is a recurring event. |
|
147 | + 'if-not-recurring', // If the event is NOT a recurring event. |
|
148 | + |
|
149 | + 'if-location', // @deprecated Alias for 'if-start-location'. |
|
150 | + 'if-start-location', // Does the event has a start location? |
|
151 | + 'if-end-location', // Does the event has an end location? |
|
152 | + 'if-not-location', // @deprecated Alias for 'if-not-start-location'. |
|
153 | 153 | 'if-not-start-location', // Does the event has NOT a start location? |
154 | - 'if-not-end-location', // Does the event has NOT an end location? |
|
154 | + 'if-not-end-location', // Does the event has NOT an end location? |
|
155 | 155 | |
156 | 156 | ); |
157 | 157 | } |
@@ -165,19 +165,19 @@ discard block |
||
165 | 165 | * |
166 | 166 | * @return string |
167 | 167 | */ |
168 | - public function parse_event_template_tags( $template_tags = '' ) { |
|
168 | + public function parse_event_template_tags($template_tags = '') { |
|
169 | 169 | |
170 | 170 | // Process tags. |
171 | 171 | $result = preg_replace_callback( |
172 | 172 | $this->get_regex(), |
173 | - array( $this, 'process_event_content' ), |
|
173 | + array($this, 'process_event_content'), |
|
174 | 174 | $template_tags |
175 | 175 | ); |
176 | 176 | |
177 | 177 | // Removes extra consecutive <br> tags. |
178 | 178 | // TODO: Doesn't seem to work but going to remove it to allow multiple <br> tags in the editor |
179 | 179 | /*return preg_replace( '#(<br *//*?>\s*)+#i', '<br />', trim( $result ) );*/ |
180 | - return do_shortcode( trim( $result ) ); |
|
180 | + return do_shortcode(trim($result)); |
|
181 | 181 | } |
182 | 182 | |
183 | 183 | /** |
@@ -189,10 +189,10 @@ discard block |
||
189 | 189 | * |
190 | 190 | * @return string |
191 | 191 | */ |
192 | - public function process_event_content( $match ) { |
|
192 | + public function process_event_content($match) { |
|
193 | 193 | |
194 | - if ( $match[1] == '[' && $match[6] == ']' ) { |
|
195 | - return substr( $match[0], 1, - 1 ); |
|
194 | + if ($match[1] == '[' && $match[6] == ']') { |
|
195 | + return substr($match[0], 1, - 1); |
|
196 | 196 | } |
197 | 197 | |
198 | 198 | $tag = $match[2]; // Tag name without square brackets. |
@@ -204,9 +204,9 @@ discard block |
||
204 | 204 | $calendar = $this->calendar; |
205 | 205 | $event = $this->event; |
206 | 206 | |
207 | - if ( ( $calendar instanceof Calendar ) && ( $event instanceof Event ) ) { |
|
207 | + if (($calendar instanceof Calendar) && ($event instanceof Event)) { |
|
208 | 208 | |
209 | - switch ( $tag ) { |
|
209 | + switch ($tag) { |
|
210 | 210 | |
211 | 211 | /* ============ * |
212 | 212 | * Content Tags * |
@@ -214,13 +214,13 @@ discard block |
||
214 | 214 | |
215 | 215 | case 'title' : |
216 | 216 | case 'event-title' : |
217 | - return $this->get_title( $event->title, $attr ); |
|
217 | + return $this->get_title($event->title, $attr); |
|
218 | 218 | |
219 | 219 | case 'description' : |
220 | - return $this->get_description( $event->description, $attr ); |
|
220 | + return $this->get_description($event->description, $attr); |
|
221 | 221 | |
222 | 222 | case 'when' : |
223 | - return $this->get_when( $event ); |
|
223 | + return $this->get_when($event); |
|
224 | 224 | |
225 | 225 | case 'end-date' : |
226 | 226 | case 'end-custom' : |
@@ -230,40 +230,40 @@ discard block |
||
230 | 230 | case 'start-date' : |
231 | 231 | case 'start-human' : |
232 | 232 | case 'start-time' : |
233 | - return $this->get_dt( $tag, $event, $attr ); |
|
233 | + return $this->get_dt($tag, $event, $attr); |
|
234 | 234 | |
235 | 235 | case 'length' : |
236 | 236 | case 'duration' : |
237 | - if ( false !== $event->end ) { |
|
237 | + if (false !== $event->end) { |
|
238 | 238 | $duration = $event->start - $event->end; |
239 | - $value = human_time_diff( $event->start, $event->end ); |
|
239 | + $value = human_time_diff($event->start, $event->end); |
|
240 | 240 | } else { |
241 | 241 | $duration = '-1'; |
242 | - $value = __( 'No end time', 'google-calendar-events' ); |
|
242 | + $value = __('No end time', 'google-calendar-events'); |
|
243 | 243 | } |
244 | - return ' <span class="simcal-event-duration" data-event-duration="' . $duration . '">' . $value . '</span>'; |
|
244 | + return ' <span class="simcal-event-duration" data-event-duration="'.$duration.'">'.$value.'</span>'; |
|
245 | 245 | |
246 | 246 | case 'location' : |
247 | 247 | case 'start-location' : |
248 | 248 | case 'end-location' : |
249 | 249 | $location = $tag == 'end-location' ? $event->end_location['address'] : $event->start_location['address']; |
250 | 250 | $location_class = $tag == 'end-location' ? 'end' : 'start'; |
251 | - return ' <span class="simcal-event-address simcal-event-' . $location_class . '-location" itemprop="location" itemscope itemtype="http://schema.org/Place">' . wp_strip_all_tags( $location ) . '</span>'; |
|
251 | + return ' <span class="simcal-event-address simcal-event-'.$location_class.'-location" itemprop="location" itemscope itemtype="http://schema.org/Place">'.wp_strip_all_tags($location).'</span>'; |
|
252 | 252 | |
253 | 253 | case 'start-location-link': |
254 | 254 | case 'end-location-link' : |
255 | 255 | case 'maps-link' : |
256 | 256 | $location = $tag == 'end-location-link' ? $event->end_location['address'] : $event->start_location['address']; |
257 | - if ( ! empty( $location ) ) { |
|
258 | - $url = '//maps.google.com?q=' . urlencode( $location ); |
|
259 | - return $this->make_link( $tag, $url, $calendar->get_event_html( $event, $partial ), $attr ); |
|
257 | + if ( ! empty($location)) { |
|
258 | + $url = '//maps.google.com?q='.urlencode($location); |
|
259 | + return $this->make_link($tag, $url, $calendar->get_event_html($event, $partial), $attr); |
|
260 | 260 | } |
261 | 261 | break; |
262 | 262 | |
263 | 263 | case 'link' : |
264 | 264 | case 'url' : |
265 | - $content = 'link' == $tag ? $calendar->get_event_html( $event, $partial ) : ''; |
|
266 | - return $this->make_link( $tag, $event->link, $content , $attr ); |
|
265 | + $content = 'link' == $tag ? $calendar->get_event_html($event, $partial) : ''; |
|
266 | + return $this->make_link($tag, $event->link, $content, $attr); |
|
267 | 267 | |
268 | 268 | case 'calendar' : |
269 | 269 | case 'feed-title' : |
@@ -285,22 +285,22 @@ discard block |
||
285 | 285 | |
286 | 286 | case 'attachments' : |
287 | 287 | $attachments = $event->get_attachments(); |
288 | - if ( ! empty( $attachments ) ) { |
|
289 | - return $this->get_attachments( $attachments ); |
|
288 | + if ( ! empty($attachments)) { |
|
289 | + return $this->get_attachments($attachments); |
|
290 | 290 | } |
291 | 291 | break; |
292 | 292 | |
293 | 293 | case 'attendees' : |
294 | 294 | $attendees = $event->get_attendees(); |
295 | - if ( ! empty( $attendees ) ) { |
|
296 | - return $this->get_attendees( $attendees, $attr ); |
|
295 | + if ( ! empty($attendees)) { |
|
296 | + return $this->get_attendees($attendees, $attr); |
|
297 | 297 | } |
298 | 298 | break; |
299 | 299 | |
300 | 300 | case 'organizer' : |
301 | 301 | $organizer = $event->get_organizer(); |
302 | - if ( ! empty( $organizer ) ) { |
|
303 | - return $this->get_organizer( $organizer, $attr ); |
|
302 | + if ( ! empty($organizer)) { |
|
303 | + return $this->get_organizer($organizer, $attr); |
|
304 | 304 | } |
305 | 305 | break; |
306 | 306 | |
@@ -309,35 +309,35 @@ discard block |
||
309 | 309 | * ================ */ |
310 | 310 | |
311 | 311 | case 'if-title': |
312 | - if ( ! empty( $event->title ) ) { |
|
313 | - return $calendar->get_event_html( $event, $partial ); |
|
312 | + if ( ! empty($event->title)) { |
|
313 | + return $calendar->get_event_html($event, $partial); |
|
314 | 314 | } |
315 | 315 | break; |
316 | 316 | |
317 | 317 | case 'if-description': |
318 | - if ( ! empty( $event->description ) ) { |
|
319 | - return $calendar->get_event_html( $event, $partial ); |
|
318 | + if ( ! empty($event->description)) { |
|
319 | + return $calendar->get_event_html($event, $partial); |
|
320 | 320 | } |
321 | 321 | break; |
322 | 322 | |
323 | 323 | case 'if-now' : |
324 | 324 | case 'if-not-now' : |
325 | 325 | |
326 | - $start_dt = $event->start_dt->setTimezone( $calendar->timezone ); |
|
326 | + $start_dt = $event->start_dt->setTimezone($calendar->timezone); |
|
327 | 327 | $start = $start_dt->getTimestamp(); |
328 | 328 | |
329 | - if ( $event->end_dt instanceof Carbon ) { |
|
330 | - $end = $event->end_dt->setTimezone( $calendar->timezone )->getTimestamp(); |
|
329 | + if ($event->end_dt instanceof Carbon) { |
|
330 | + $end = $event->end_dt->setTimezone($calendar->timezone)->getTimestamp(); |
|
331 | 331 | } else { |
332 | 332 | return ''; |
333 | 333 | } |
334 | 334 | |
335 | - $now = ( $start <= $calendar->now ) && ( $end >= $calendar->now ); |
|
335 | + $now = ($start <= $calendar->now) && ($end >= $calendar->now); |
|
336 | 336 | |
337 | - if ( ( 'if-now' == $tag ) && $now ) { |
|
338 | - return $calendar->get_event_html( $event, $partial ); |
|
339 | - } elseif ( ( 'if-not-now' == $tag ) && ( false == $now ) ) { |
|
340 | - return $calendar->get_event_html( $event, $partial ); |
|
337 | + if (('if-now' == $tag) && $now) { |
|
338 | + return $calendar->get_event_html($event, $partial); |
|
339 | + } elseif (('if-not-now' == $tag) && (false == $now)) { |
|
340 | + return $calendar->get_event_html($event, $partial); |
|
341 | 341 | } |
342 | 342 | |
343 | 343 | break; |
@@ -345,15 +345,15 @@ discard block |
||
345 | 345 | case 'if-started' : |
346 | 346 | case 'if-not-started' : |
347 | 347 | |
348 | - $start = $event->start_dt->setTimezone( $calendar->timezone )->getTimestamp(); |
|
348 | + $start = $event->start_dt->setTimezone($calendar->timezone)->getTimestamp(); |
|
349 | 349 | |
350 | - if ( 'if-started' == $tag ) { |
|
351 | - if ( $start < $calendar->now ) { |
|
352 | - return $calendar->get_event_html( $event, $partial ); |
|
350 | + if ('if-started' == $tag) { |
|
351 | + if ($start < $calendar->now) { |
|
352 | + return $calendar->get_event_html($event, $partial); |
|
353 | 353 | } |
354 | - } elseif ( 'if-not-started' == $tag ) { |
|
355 | - if ( $start > $calendar->now ) { |
|
356 | - return $calendar->get_event_html( $event, $partial ); |
|
354 | + } elseif ('if-not-started' == $tag) { |
|
355 | + if ($start > $calendar->now) { |
|
356 | + return $calendar->get_event_html($event, $partial); |
|
357 | 357 | } |
358 | 358 | } |
359 | 359 | |
@@ -362,17 +362,17 @@ discard block |
||
362 | 362 | case 'if-ended' : |
363 | 363 | case 'if-not-ended' : |
364 | 364 | |
365 | - if ( false !== $event->end ) { |
|
365 | + if (false !== $event->end) { |
|
366 | 366 | |
367 | - $end = $event->end_dt->setTimezone( $calendar->timezone )->getTimestamp(); |
|
367 | + $end = $event->end_dt->setTimezone($calendar->timezone)->getTimestamp(); |
|
368 | 368 | |
369 | - if ( 'if-ended' == $tag ) { |
|
370 | - if ( $end < $calendar->now ) { |
|
371 | - return $calendar->get_event_html( $event, $partial ); |
|
369 | + if ('if-ended' == $tag) { |
|
370 | + if ($end < $calendar->now) { |
|
371 | + return $calendar->get_event_html($event, $partial); |
|
372 | 372 | } |
373 | - } elseif ( 'if-not-ended' == $tag ) { |
|
374 | - if ( $end > $calendar->now ) { |
|
375 | - return $calendar->get_event_html( $event, $partial ); |
|
373 | + } elseif ('if-not-ended' == $tag) { |
|
374 | + if ($end > $calendar->now) { |
|
375 | + return $calendar->get_event_html($event, $partial); |
|
376 | 376 | } |
377 | 377 | } |
378 | 378 | |
@@ -381,14 +381,14 @@ discard block |
||
381 | 381 | break; |
382 | 382 | |
383 | 383 | case 'if-end-time' : |
384 | - if ( false !== $event->end ) { |
|
385 | - return $calendar->get_event_html( $event, $partial ); |
|
384 | + if (false !== $event->end) { |
|
385 | + return $calendar->get_event_html($event, $partial); |
|
386 | 386 | } |
387 | 387 | break; |
388 | 388 | |
389 | 389 | case 'if-no-end-time' : |
390 | - if ( false === $event->end ) { |
|
391 | - return $calendar->get_event_html( $event, $partial ); |
|
390 | + if (false === $event->end) { |
|
391 | + return $calendar->get_event_html($event, $partial); |
|
392 | 392 | } |
393 | 393 | break; |
394 | 394 | |
@@ -396,59 +396,59 @@ discard block |
||
396 | 396 | case 'if-whole-day' : |
397 | 397 | case 'if-not-all-day' : |
398 | 398 | case 'if-not-whole-day' : |
399 | - $bool = strstr( $tag, 'not' ) ? false : true; |
|
400 | - if ( $bool === $event->whole_day ) { |
|
401 | - return $calendar->get_event_html( $event, $partial ); |
|
399 | + $bool = strstr($tag, 'not') ? false : true; |
|
400 | + if ($bool === $event->whole_day) { |
|
401 | + return $calendar->get_event_html($event, $partial); |
|
402 | 402 | } |
403 | 403 | break; |
404 | 404 | |
405 | 405 | case 'if-recurring' : |
406 | - if ( ! empty( $event->recurrence ) ) { |
|
407 | - return $calendar->get_event_html( $event, $partial ); |
|
406 | + if ( ! empty($event->recurrence)) { |
|
407 | + return $calendar->get_event_html($event, $partial); |
|
408 | 408 | } |
409 | 409 | break; |
410 | 410 | |
411 | 411 | case 'if-not-recurring' : |
412 | - if ( false === $event->recurrence ) { |
|
413 | - return $calendar->get_event_html( $event, $partial ); |
|
412 | + if (false === $event->recurrence) { |
|
413 | + return $calendar->get_event_html($event, $partial); |
|
414 | 414 | } |
415 | 415 | break; |
416 | 416 | |
417 | 417 | case 'if-multi-day' : |
418 | - if ( false !== $event->multiple_days ) { |
|
419 | - return $calendar->get_event_html( $event, $partial ); |
|
418 | + if (false !== $event->multiple_days) { |
|
419 | + return $calendar->get_event_html($event, $partial); |
|
420 | 420 | } |
421 | 421 | break; |
422 | 422 | |
423 | 423 | case 'if-single-day' : |
424 | - if ( false === $event->multiple_days ) { |
|
425 | - return $calendar->get_event_html( $event, $partial ); |
|
424 | + if (false === $event->multiple_days) { |
|
425 | + return $calendar->get_event_html($event, $partial); |
|
426 | 426 | } |
427 | 427 | break; |
428 | 428 | |
429 | 429 | case 'if-location' : |
430 | 430 | case 'if-start-location' : |
431 | - if ( ! empty( $event->start_location['address'] ) ) { |
|
432 | - return $calendar->get_event_html( $event, $partial ); |
|
431 | + if ( ! empty($event->start_location['address'])) { |
|
432 | + return $calendar->get_event_html($event, $partial); |
|
433 | 433 | } |
434 | 434 | return false; |
435 | 435 | |
436 | 436 | case 'if-not-location' : |
437 | 437 | case 'if-not-start-location' : |
438 | - if ( empty( $event->start_location['address'] ) ) { |
|
439 | - return $calendar->get_event_html( $event, $partial ); |
|
438 | + if (empty($event->start_location['address'])) { |
|
439 | + return $calendar->get_event_html($event, $partial); |
|
440 | 440 | } |
441 | 441 | return ''; |
442 | 442 | |
443 | 443 | case 'if-not-end-location' : |
444 | - if ( empty( $event->end_location['address'] ) ) { |
|
445 | - return $calendar->get_event_html( $event, $partial ); |
|
444 | + if (empty($event->end_location['address'])) { |
|
445 | + return $calendar->get_event_html($event, $partial); |
|
446 | 446 | } |
447 | 447 | return ''; |
448 | 448 | |
449 | 449 | case 'if-end-location' : |
450 | - if ( ! empty( $event->end_location['address'] ) ) { |
|
451 | - return $calendar->get_event_html( $event, $partial ); |
|
450 | + if ( ! empty($event->end_location['address'])) { |
|
451 | + return $calendar->get_event_html($event, $partial); |
|
452 | 452 | } |
453 | 453 | return ''; |
454 | 454 | |
@@ -457,7 +457,7 @@ discard block |
||
457 | 457 | * ======= */ |
458 | 458 | |
459 | 459 | default : |
460 | - return wp_kses_post( $before . $partial . $after ); |
|
460 | + return wp_kses_post($before.$partial.$after); |
|
461 | 461 | } |
462 | 462 | } |
463 | 463 | |
@@ -475,14 +475,14 @@ discard block |
||
475 | 475 | * |
476 | 476 | * @return string |
477 | 477 | */ |
478 | - private function limit_words( $text, $limit ) { |
|
478 | + private function limit_words($text, $limit) { |
|
479 | 479 | |
480 | - $limit = max( absint( $limit ), 0 ); |
|
480 | + $limit = max(absint($limit), 0); |
|
481 | 481 | |
482 | - if ( $limit > 0 && ( str_word_count( $text, 0 ) > $limit ) ) { |
|
483 | - $words = str_word_count( $text, 2 ); |
|
484 | - $pos = array_keys( $words ); |
|
485 | - $text = trim( substr( $text, 0, $pos[ $limit ] ) ) . '…'; |
|
482 | + if ($limit > 0 && (str_word_count($text, 0) > $limit)) { |
|
483 | + $words = str_word_count($text, 2); |
|
484 | + $pos = array_keys($words); |
|
485 | + $text = trim(substr($text, 0, $pos[$limit])).'…'; |
|
486 | 486 | } |
487 | 487 | |
488 | 488 | return $text; |
@@ -499,26 +499,26 @@ discard block |
||
499 | 499 | * |
500 | 500 | * @return string |
501 | 501 | */ |
502 | - private function get_title( $title, $attr ) { |
|
502 | + private function get_title($title, $attr) { |
|
503 | 503 | |
504 | - if ( empty( $title ) ) { |
|
504 | + if (empty($title)) { |
|
505 | 505 | return ''; |
506 | 506 | } |
507 | 507 | |
508 | - $attr = array_merge( array( |
|
509 | - 'html' => '', // Parse HTML |
|
510 | - 'limit' => 0, // Trim length to amount of words |
|
511 | - ), (array) shortcode_parse_atts( $attr ) ); |
|
508 | + $attr = array_merge(array( |
|
509 | + 'html' => '', // Parse HTML |
|
510 | + 'limit' => 0, // Trim length to amount of words |
|
511 | + ), (array) shortcode_parse_atts($attr)); |
|
512 | 512 | |
513 | - if ( ! empty( $attr['html'] ) ) { |
|
514 | - $title = wp_kses_post( $title ); |
|
513 | + if ( ! empty($attr['html'])) { |
|
514 | + $title = wp_kses_post($title); |
|
515 | 515 | $tag = 'div'; |
516 | 516 | } else { |
517 | - $title = $this->limit_words( $title, $attr['limit'] ); |
|
517 | + $title = $this->limit_words($title, $attr['limit']); |
|
518 | 518 | $tag = 'span'; |
519 | 519 | } |
520 | 520 | |
521 | - return '<' . $tag . ' class="simcal-event-title" itemprop="name">' . $title . '</' . $tag . '>'; |
|
521 | + return '<'.$tag.' class="simcal-event-title" itemprop="name">'.$title.'</'.$tag.'>'; |
|
522 | 522 | } |
523 | 523 | |
524 | 524 | /** |
@@ -532,42 +532,42 @@ discard block |
||
532 | 532 | * |
533 | 533 | * @return string |
534 | 534 | */ |
535 | - private function get_description( $description, $attr ) { |
|
535 | + private function get_description($description, $attr) { |
|
536 | 536 | |
537 | - if ( empty( $description ) ) { |
|
537 | + if (empty($description)) { |
|
538 | 538 | return ''; |
539 | 539 | } |
540 | 540 | |
541 | - $attr = array_merge( array( |
|
542 | - 'limit' => 0, // Trim length to number of words |
|
543 | - 'html' => 'no', // Parse HTML content |
|
544 | - 'markdown' => 'no', // Parse Markdown content |
|
545 | - 'autolink' => 'no', // Automatically convert plaintext URIs to anchors |
|
546 | - ), (array) shortcode_parse_atts( $attr ) ); |
|
541 | + $attr = array_merge(array( |
|
542 | + 'limit' => 0, // Trim length to number of words |
|
543 | + 'html' => 'no', // Parse HTML content |
|
544 | + 'markdown' => 'no', // Parse Markdown content |
|
545 | + 'autolink' => 'no', // Automatically convert plaintext URIs to anchors |
|
546 | + ), (array) shortcode_parse_atts($attr)); |
|
547 | 547 | |
548 | - $allow_html = 'no' != $attr['html'] ? true : false; |
|
548 | + $allow_html = 'no' != $attr['html'] ? true : false; |
|
549 | 549 | $allow_md = 'no' != $attr['markdown'] ? true : false; |
550 | 550 | |
551 | 551 | $html = '<div class="simcal-event-description" itemprop="description">'; |
552 | 552 | |
553 | 553 | // Markdown and HTML don't play well together, use one or the other in the same tag. |
554 | - if ( $allow_html || $allow_md ) { |
|
555 | - if ( $allow_html ) { |
|
556 | - $description = wp_kses_post( $description ); |
|
557 | - } elseif ( $allow_md ) { |
|
554 | + if ($allow_html || $allow_md) { |
|
555 | + if ($allow_html) { |
|
556 | + $description = wp_kses_post($description); |
|
557 | + } elseif ($allow_md) { |
|
558 | 558 | $markdown = new \Parsedown(); |
559 | - $description = $markdown->text( wp_strip_all_tags( $description ) ); |
|
559 | + $description = $markdown->text(wp_strip_all_tags($description)); |
|
560 | 560 | } |
561 | 561 | } else { |
562 | - $description = wpautop( $description ); |
|
562 | + $description = wpautop($description); |
|
563 | 563 | } |
564 | 564 | |
565 | - $description = $this->limit_words( $description, $attr['limit'] ); |
|
565 | + $description = $this->limit_words($description, $attr['limit']); |
|
566 | 566 | |
567 | - $html .= $description . '</div>'; |
|
567 | + $html .= $description.'</div>'; |
|
568 | 568 | |
569 | - if ( 'no' != $attr['autolink'] ) { |
|
570 | - $html = ' ' . make_clickable( $html ); |
|
569 | + if ('no' != $attr['autolink']) { |
|
570 | + $html = ' '.make_clickable($html); |
|
571 | 571 | } |
572 | 572 | |
573 | 573 | return $html; |
@@ -583,74 +583,74 @@ discard block |
||
583 | 583 | * |
584 | 584 | * @return string |
585 | 585 | */ |
586 | - private function get_when( Event $event ) { |
|
586 | + private function get_when(Event $event) { |
|
587 | 587 | |
588 | - $start = $event->start_dt->setTimezone( $event->timezone ); |
|
589 | - $end = ! is_null( $event->end_dt ) ? $event->end_dt->setTimezone( $event->timezone ) : null; |
|
588 | + $start = $event->start_dt->setTimezone($event->timezone); |
|
589 | + $end = ! is_null($event->end_dt) ? $event->end_dt->setTimezone($event->timezone) : null; |
|
590 | 590 | |
591 | 591 | $time_start = ''; |
592 | 592 | $time_end = ''; |
593 | 593 | |
594 | - if ( ! $event->whole_day ) { |
|
594 | + if ( ! $event->whole_day) { |
|
595 | 595 | |
596 | - $time_start = $this->calendar->datetime_separator . |
|
597 | - ' <span class="simcal-event-start simcal-event-start-time" ' . |
|
598 | - 'data-event-start="' . $start->getTimestamp() . '" ' . |
|
599 | - 'data-event-format="' . $this->calendar->time_format . '" ' . |
|
600 | - 'itemprop="startDate" data-content="' . $start->toIso8601String() . '">' . |
|
601 | - date_i18n( $this->calendar->time_format, $start->getTimestamp() ) . |
|
596 | + $time_start = $this->calendar->datetime_separator. |
|
597 | + ' <span class="simcal-event-start simcal-event-start-time" '. |
|
598 | + 'data-event-start="'.$start->getTimestamp().'" '. |
|
599 | + 'data-event-format="'.$this->calendar->time_format.'" '. |
|
600 | + 'itemprop="startDate" data-content="'.$start->toIso8601String().'">'. |
|
601 | + date_i18n($this->calendar->time_format, $start->getTimestamp()). |
|
602 | 602 | '</span> '; |
603 | 603 | |
604 | - if ( $end instanceof Carbon ) { |
|
604 | + if ($end instanceof Carbon) { |
|
605 | 605 | |
606 | - $time_end = ' <span class="simcal-event-end simcal-event-end-time" ' . |
|
607 | - 'data-event-end="' . $end->getTimestamp() . '" ' . |
|
608 | - 'data-event-format="' . $this->calendar->time_format . '" ' . |
|
609 | - 'itemprop="endDate" data-content="' . $end->toIso8601String() . '">' . |
|
610 | - date_i18n( $this->calendar->time_format, $end->getTimestamp() ) . |
|
606 | + $time_end = ' <span class="simcal-event-end simcal-event-end-time" '. |
|
607 | + 'data-event-end="'.$end->getTimestamp().'" '. |
|
608 | + 'data-event-format="'.$this->calendar->time_format.'" '. |
|
609 | + 'itemprop="endDate" data-content="'.$end->toIso8601String().'">'. |
|
610 | + date_i18n($this->calendar->time_format, $end->getTimestamp()). |
|
611 | 611 | '</span> '; |
612 | 612 | |
613 | 613 | } |
614 | 614 | |
615 | 615 | } |
616 | 616 | |
617 | - if ( $event->multiple_days ) { |
|
617 | + if ($event->multiple_days) { |
|
618 | 618 | |
619 | - $output = ' <span class="simcal-event-start simcal-event-start-date" ' . |
|
620 | - 'data-event-start="' . $start->getTimestamp() . '" ' . |
|
621 | - 'data-event-format="' . $this->calendar->date_format . '" ' . |
|
622 | - 'itemprop="startDate" data-content="' . $start->toIso8601String() . '">' . |
|
623 | - date_i18n( $this->calendar->date_format, $start->getTimestamp() ) . |
|
624 | - '</span> ' . |
|
619 | + $output = ' <span class="simcal-event-start simcal-event-start-date" '. |
|
620 | + 'data-event-start="'.$start->getTimestamp().'" '. |
|
621 | + 'data-event-format="'.$this->calendar->date_format.'" '. |
|
622 | + 'itemprop="startDate" data-content="'.$start->toIso8601String().'">'. |
|
623 | + date_i18n($this->calendar->date_format, $start->getTimestamp()). |
|
624 | + '</span> '. |
|
625 | 625 | $time_start; |
626 | 626 | |
627 | - if ( $end instanceof Carbon ) { |
|
627 | + if ($end instanceof Carbon) { |
|
628 | 628 | |
629 | - $output .= '-' . |
|
630 | - ' <span class="simcal-event-start simcal-event-end-date" ' . |
|
631 | - 'data-event-start="' . $end->getTimestamp() . '" ' . |
|
632 | - 'data-event-format="' . $this->calendar->date_format . '" ' . |
|
633 | - 'itemprop="endDate" data-content="' . $end->toIso8601String() . '">' . |
|
634 | - date_i18n( $this->calendar->date_format, $end->getTimestamp() ) . |
|
635 | - '</span> ' . |
|
629 | + $output .= '-'. |
|
630 | + ' <span class="simcal-event-start simcal-event-end-date" '. |
|
631 | + 'data-event-start="'.$end->getTimestamp().'" '. |
|
632 | + 'data-event-format="'.$this->calendar->date_format.'" '. |
|
633 | + 'itemprop="endDate" data-content="'.$end->toIso8601String().'">'. |
|
634 | + date_i18n($this->calendar->date_format, $end->getTimestamp()). |
|
635 | + '</span> '. |
|
636 | 636 | $time_end; |
637 | 637 | } |
638 | 638 | |
639 | 639 | } else { |
640 | 640 | |
641 | - $time_end = ! empty( $time_start ) && ! empty( $time_end ) ? ' - ' . $time_end : ''; |
|
641 | + $time_end = ! empty($time_start) && ! empty($time_end) ? ' - '.$time_end : ''; |
|
642 | 642 | |
643 | - $output = ' <span class="simcal-event-start simcal-event-start-date" ' . |
|
644 | - 'data-event-start="' . $start->getTimestamp() . '" ' . |
|
645 | - 'data-event-format="' . $this->calendar->date_format . '">' . |
|
646 | - date_i18n( $this->calendar->date_format, $start->getTimestamp() ) . |
|
647 | - '</span> ' . |
|
648 | - $time_start . |
|
643 | + $output = ' <span class="simcal-event-start simcal-event-start-date" '. |
|
644 | + 'data-event-start="'.$start->getTimestamp().'" '. |
|
645 | + 'data-event-format="'.$this->calendar->date_format.'">'. |
|
646 | + date_i18n($this->calendar->date_format, $start->getTimestamp()). |
|
647 | + '</span> '. |
|
648 | + $time_start. |
|
649 | 649 | $time_end; |
650 | 650 | |
651 | 651 | } |
652 | 652 | |
653 | - return trim( $output ); |
|
653 | + return trim($output); |
|
654 | 654 | } |
655 | 655 | |
656 | 656 | /** |
@@ -665,50 +665,50 @@ discard block |
||
665 | 665 | * |
666 | 666 | * @return string |
667 | 667 | */ |
668 | - private function get_dt( $tag, Event $event, $attr ) { |
|
668 | + private function get_dt($tag, Event $event, $attr) { |
|
669 | 669 | |
670 | - $bound = 0 === strpos( $tag, 'end' ) ? 'end' : 'start'; |
|
671 | - if ( ( 'end' == $bound ) && ( false === $event->end ) ) { |
|
670 | + $bound = 0 === strpos($tag, 'end') ? 'end' : 'start'; |
|
671 | + if (('end' == $bound) && (false === $event->end)) { |
|
672 | 672 | return ''; |
673 | 673 | } |
674 | 674 | |
675 | - $dt = $bound . '_dt'; |
|
676 | - if ( ! $event->$dt instanceof Carbon ) { |
|
675 | + $dt = $bound.'_dt'; |
|
676 | + if ( ! $event->$dt instanceof Carbon) { |
|
677 | 677 | return ''; |
678 | 678 | } |
679 | - $event_dt = $event->$dt->setTimezone( $event->timezone ); |
|
679 | + $event_dt = $event->$dt->setTimezone($event->timezone); |
|
680 | 680 | |
681 | - $attr = array_merge( array( |
|
681 | + $attr = array_merge(array( |
|
682 | 682 | 'format' => '', |
683 | - ), (array) shortcode_parse_atts( $attr ) ); |
|
683 | + ), (array) shortcode_parse_atts($attr)); |
|
684 | 684 | |
685 | - $format = ltrim( strstr( $tag, '-' ), '-' ); |
|
685 | + $format = ltrim(strstr($tag, '-'), '-'); |
|
686 | 686 | $dt_format = ''; |
687 | - if ( ! empty( $attr['format'] ) ) { |
|
688 | - $dt_format = esc_attr( wp_strip_all_tags( $attr['format'] ) ); |
|
689 | - } elseif ( 'date' == $format ) { |
|
687 | + if ( ! empty($attr['format'])) { |
|
688 | + $dt_format = esc_attr(wp_strip_all_tags($attr['format'])); |
|
689 | + } elseif ('date' == $format) { |
|
690 | 690 | $dt_format = $this->calendar->date_format; |
691 | - } elseif ( 'time' == $format ) { |
|
691 | + } elseif ('time' == $format) { |
|
692 | 692 | $dt_format = $this->calendar->time_format; |
693 | 693 | } |
694 | 694 | |
695 | - if ( 'human' == $format ) { |
|
696 | - $value = human_time_diff( $event_dt->getTimestamp(), Carbon::now( $event->timezone )->getTimestamp() ); |
|
695 | + if ('human' == $format) { |
|
696 | + $value = human_time_diff($event_dt->getTimestamp(), Carbon::now($event->timezone)->getTimestamp()); |
|
697 | 697 | |
698 | - if ( $event_dt->getTimestamp() < Carbon::now( $event->timezone )->getTimestamp() ) { |
|
699 | - $value .= ' ' . _x( 'ago', 'human date event builder code modifier', 'google-calendar-events' ); |
|
698 | + if ($event_dt->getTimestamp() < Carbon::now($event->timezone)->getTimestamp()) { |
|
699 | + $value .= ' '._x('ago', 'human date event builder code modifier', 'google-calendar-events'); |
|
700 | 700 | } else { |
701 | - $value .= ' ' . _x( 'from now', 'human date event builder code modifier', 'google-calendar-events' ); |
|
701 | + $value .= ' '._x('from now', 'human date event builder code modifier', 'google-calendar-events'); |
|
702 | 702 | } |
703 | 703 | } else { |
704 | - $value = date_i18n( $dt_format, $event_dt->getTimestamp() ); |
|
704 | + $value = date_i18n($dt_format, $event_dt->getTimestamp()); |
|
705 | 705 | } |
706 | 706 | |
707 | - return '<span class="simcal-event-' . $bound . ' ' . 'simcal-event-' . $bound . '-' . $format . '" ' . |
|
708 | - 'data-event-' . $bound . '="' . $event_dt->getTimestamp() . '" ' . |
|
709 | - 'data-event-format="' . $dt_format . '" ' . |
|
710 | - 'itemprop="' . $bound . 'Date" data-content="' . $event_dt->toIso8601String() . '">' . |
|
711 | - $value . |
|
707 | + return '<span class="simcal-event-'.$bound.' '.'simcal-event-'.$bound.'-'.$format.'" '. |
|
708 | + 'data-event-'.$bound.'="'.$event_dt->getTimestamp().'" '. |
|
709 | + 'data-event-format="'.$dt_format.'" '. |
|
710 | + 'itemprop="'.$bound.'Date" data-content="'.$event_dt->toIso8601String().'">'. |
|
711 | + $value. |
|
712 | 712 | '</span>'; |
713 | 713 | } |
714 | 714 | |
@@ -725,23 +725,23 @@ discard block |
||
725 | 725 | * |
726 | 726 | * @return string |
727 | 727 | */ |
728 | - private function make_link( $tag, $url, $content, $attr ) { |
|
728 | + private function make_link($tag, $url, $content, $attr) { |
|
729 | 729 | |
730 | - if ( empty( $url ) ) { |
|
730 | + if (empty($url)) { |
|
731 | 731 | return ''; |
732 | 732 | } |
733 | 733 | |
734 | - $text = empty( $content ) ? $url : $content; |
|
734 | + $text = empty($content) ? $url : $content; |
|
735 | 735 | |
736 | - $attr = array_merge( array( |
|
737 | - 'autolink' => false, // Convert url to link anchor |
|
738 | - 'newwindow' => false, // If autolink attribute is true, open link in new window |
|
739 | - ), (array) shortcode_parse_atts( $attr ) ); |
|
736 | + $attr = array_merge(array( |
|
737 | + 'autolink' => false, // Convert url to link anchor |
|
738 | + 'newwindow' => false, // If autolink attribute is true, open link in new window |
|
739 | + ), (array) shortcode_parse_atts($attr)); |
|
740 | 740 | |
741 | 741 | $anchor = $tag != 'url' ? 'yes' : $attr['autolink']; |
742 | 742 | $target = $attr['newwindow'] !== false ? 'target="_blank"' : ''; |
743 | 743 | |
744 | - return $anchor !== false ? ' <a href="' . esc_url( $url ) . '" ' . $target . '>' . $text . '</a>' : ' ' . $text; |
|
744 | + return $anchor !== false ? ' <a href="'.esc_url($url).'" '.$target.'>'.$text.'</a>' : ' '.$text; |
|
745 | 745 | } |
746 | 746 | |
747 | 747 | /** |
@@ -754,20 +754,20 @@ discard block |
||
754 | 754 | * |
755 | 755 | * @return string |
756 | 756 | */ |
757 | - private function get_attachments( $attachments ) { |
|
757 | + private function get_attachments($attachments) { |
|
758 | 758 | |
759 | - $html = '<ul class="simcal-attachments">' . "\n\t"; |
|
759 | + $html = '<ul class="simcal-attachments">'."\n\t"; |
|
760 | 760 | |
761 | - foreach ( $attachments as $attachment ) { |
|
761 | + foreach ($attachments as $attachment) { |
|
762 | 762 | $html .= '<li class="simcal-attachment">'; |
763 | - $html .= '<a href="' . $attachment['url'] . '" target="_blank">'; |
|
764 | - $html .= ! empty( $attachment['icon'] ) ? '<img src="' . $attachment['icon'] . '" />' : ''; |
|
765 | - $html .= '<span>' . $attachment['name'] . '</span>'; |
|
763 | + $html .= '<a href="'.$attachment['url'].'" target="_blank">'; |
|
764 | + $html .= ! empty($attachment['icon']) ? '<img src="'.$attachment['icon'].'" />' : ''; |
|
765 | + $html .= '<span>'.$attachment['name'].'</span>'; |
|
766 | 766 | $html .= '</a>'; |
767 | - $html .= '</li>' . "\n"; |
|
767 | + $html .= '</li>'."\n"; |
|
768 | 768 | } |
769 | 769 | |
770 | - $html .= '</ul>' . "\n"; |
|
770 | + $html .= '</ul>'."\n"; |
|
771 | 771 | |
772 | 772 | return $html; |
773 | 773 | } |
@@ -783,41 +783,41 @@ discard block |
||
783 | 783 | * |
784 | 784 | * @return string |
785 | 785 | */ |
786 | - private function get_attendees( $attendees, $attr ) { |
|
786 | + private function get_attendees($attendees, $attr) { |
|
787 | 787 | |
788 | - $attr = array_merge( array( |
|
789 | - 'photo' => 'show', // show/hide attendee photo |
|
790 | - 'email' => 'hide', // show/hide attendee email address |
|
791 | - 'rsvp' => 'hide', // show/hide rsvp response status |
|
792 | - 'response' => '', // filter attendees by rsvp response (yes/no/maybe) |
|
793 | - ), (array) shortcode_parse_atts( $attr ) ); |
|
788 | + $attr = array_merge(array( |
|
789 | + 'photo' => 'show', // show/hide attendee photo |
|
790 | + 'email' => 'hide', // show/hide attendee email address |
|
791 | + 'rsvp' => 'hide', // show/hide rsvp response status |
|
792 | + 'response' => '', // filter attendees by rsvp response (yes/no/maybe) |
|
793 | + ), (array) shortcode_parse_atts($attr)); |
|
794 | 794 | |
795 | - $html = '<ul class="simcal-attendees" itemprop="attendees">' . "\n\t"; |
|
795 | + $html = '<ul class="simcal-attendees" itemprop="attendees">'."\n\t"; |
|
796 | 796 | |
797 | 797 | $known = 0; |
798 | 798 | $unknown = 0; |
799 | 799 | |
800 | - foreach ( $attendees as $attendee ) { |
|
800 | + foreach ($attendees as $attendee) { |
|
801 | 801 | |
802 | - if ( 'yes' == $attr['response'] && 'yes' != $attendee['response'] ) { |
|
802 | + if ('yes' == $attr['response'] && 'yes' != $attendee['response']) { |
|
803 | 803 | continue; |
804 | - } elseif ( 'no' == $attr['response'] && 'no' != $attendee['response'] ) { |
|
804 | + } elseif ('no' == $attr['response'] && 'no' != $attendee['response']) { |
|
805 | 805 | continue; |
806 | - } elseif ( 'maybe' == $attr['response'] && ! in_array( $attendee['response'], array( 'yes', 'maybe' ) ) ) { |
|
806 | + } elseif ('maybe' == $attr['response'] && ! in_array($attendee['response'], array('yes', 'maybe'))) { |
|
807 | 807 | continue; |
808 | 808 | } |
809 | 809 | |
810 | - if ( ! empty( $attendee['name'] ) ) { |
|
810 | + if ( ! empty($attendee['name'])) { |
|
811 | 811 | |
812 | - $photo = 'hide' != $attr['photo'] ? '<img class="avatar avatar-128 photo" src="' . $attendee['photo'] . '" itemprop="image" />' : ''; |
|
813 | - $response = 'hide' != $attr['rsvp'] ? $this->get_rsvp_response( $attendee['response'] ) : ''; |
|
814 | - $guest = $photo . '<span itemprop="name">' . $attendee['name'] . $response . '</span>'; |
|
812 | + $photo = 'hide' != $attr['photo'] ? '<img class="avatar avatar-128 photo" src="'.$attendee['photo'].'" itemprop="image" />' : ''; |
|
813 | + $response = 'hide' != $attr['rsvp'] ? $this->get_rsvp_response($attendee['response']) : ''; |
|
814 | + $guest = $photo.'<span itemprop="name">'.$attendee['name'].$response.'</span>'; |
|
815 | 815 | |
816 | - if ( ! empty( $attendee['email'] ) && ( 'show' == $attr['email'] ) ) { |
|
817 | - $guest = sprintf( '<a href="mailto:' . $attendee['email'] . '" itemprop="email">%s</a>', $guest ); |
|
816 | + if ( ! empty($attendee['email']) && ('show' == $attr['email'])) { |
|
817 | + $guest = sprintf('<a href="mailto:'.$attendee['email'].'" itemprop="email">%s</a>', $guest); |
|
818 | 818 | } |
819 | 819 | |
820 | - $html .= '<li class="simcal-attendee" itemprop="attendee" itemscope itemtype="http://schema.org/Person">' . $guest . '</li>' . "\n"; |
|
820 | + $html .= '<li class="simcal-attendee" itemprop="attendee" itemscope itemtype="http://schema.org/Person">'.$guest.'</li>'."\n"; |
|
821 | 821 | |
822 | 822 | $known++; |
823 | 823 | |
@@ -828,21 +828,21 @@ discard block |
||
828 | 828 | } |
829 | 829 | } |
830 | 830 | |
831 | - if ( $unknown > 0 ) { |
|
832 | - if ( $known > 0 ) { |
|
831 | + if ($unknown > 0) { |
|
832 | + if ($known > 0) { |
|
833 | 833 | /* translators: One more person attending the event. */ |
834 | - $others = sprintf( _n( '1 more attendee', '%s more attendees', $unknown, 'google-calendar-events' ), $unknown ); |
|
834 | + $others = sprintf(_n('1 more attendee', '%s more attendees', $unknown, 'google-calendar-events'), $unknown); |
|
835 | 835 | } else { |
836 | 836 | /* translators: One or more persons attending the event whose name is unknown. */ |
837 | - $others = sprintf( _n( '1 anonymous attendee', '%s anonymous attendees', $unknown, 'google-calendar-events' ), $unknown ); |
|
837 | + $others = sprintf(_n('1 anonymous attendee', '%s anonymous attendees', $unknown, 'google-calendar-events'), $unknown); |
|
838 | 838 | } |
839 | - $photo = $attr['photo'] !== 'hide' ? get_avatar( '', 128 ) : ''; |
|
840 | - $html .= '<li class="simcal-attendee simcal-attendee-anonymous">' . $photo . '<span>' . $others . '</span></li>' . "\n"; |
|
841 | - } elseif ( $known === 0 ) { |
|
842 | - $html .= '<li class="simcal-attendee">' . _x( 'No one yet', 'No one yet rsvp to attend the event.', 'google-calendar-events' ) . '</li>' . "\n"; |
|
839 | + $photo = $attr['photo'] !== 'hide' ? get_avatar('', 128) : ''; |
|
840 | + $html .= '<li class="simcal-attendee simcal-attendee-anonymous">'.$photo.'<span>'.$others.'</span></li>'."\n"; |
|
841 | + } elseif ($known === 0) { |
|
842 | + $html .= '<li class="simcal-attendee">'._x('No one yet', 'No one yet rsvp to attend the event.', 'google-calendar-events').'</li>'."\n"; |
|
843 | 843 | } |
844 | 844 | |
845 | - $html .= '</ul>' . "\n"; |
|
845 | + $html .= '</ul>'."\n"; |
|
846 | 846 | |
847 | 847 | return $html; |
848 | 848 | } |
@@ -856,23 +856,23 @@ discard block |
||
856 | 856 | * |
857 | 857 | * @return string |
858 | 858 | */ |
859 | - private function get_rsvp_response( $response ) { |
|
859 | + private function get_rsvp_response($response) { |
|
860 | 860 | |
861 | - if ( 'yes' == $response ) { |
|
861 | + if ('yes' == $response) { |
|
862 | 862 | /* translators: Someone replied with 'yes' to a rsvp request. */ |
863 | - $rsvp = __( 'Attending', 'google-calendar-events' ); |
|
864 | - } elseif ( 'no' == $response ) { |
|
863 | + $rsvp = __('Attending', 'google-calendar-events'); |
|
864 | + } elseif ('no' == $response) { |
|
865 | 865 | /* translators: Someone replied with 'no' to a rsvp request. */ |
866 | - $rsvp = __( 'Not attending', 'google-calendar-events' ); |
|
867 | - } elseif ( 'maybe' == $response ) { |
|
866 | + $rsvp = __('Not attending', 'google-calendar-events'); |
|
867 | + } elseif ('maybe' == $response) { |
|
868 | 868 | /* translators: Someone replied with 'maybe' to a rsvp request. */ |
869 | - $rsvp = __( 'Maybe attending', 'google-calendar-events' ); |
|
869 | + $rsvp = __('Maybe attending', 'google-calendar-events'); |
|
870 | 870 | } else { |
871 | 871 | /* translators: Someone did not send yet a rsvp confirmation to join an event. */ |
872 | - $rsvp = __( 'Response pending', 'google-calendar-events' ); |
|
872 | + $rsvp = __('Response pending', 'google-calendar-events'); |
|
873 | 873 | } |
874 | 874 | |
875 | - return ' <small>(' . $rsvp . ')</small>'; |
|
875 | + return ' <small>('.$rsvp.')</small>'; |
|
876 | 876 | } |
877 | 877 | |
878 | 878 | /** |
@@ -886,21 +886,21 @@ discard block |
||
886 | 886 | * |
887 | 887 | * @return string |
888 | 888 | */ |
889 | - private function get_organizer( $organizer, $attr ) { |
|
889 | + private function get_organizer($organizer, $attr) { |
|
890 | 890 | |
891 | - $attr = array_merge( array( |
|
892 | - 'photo' => 'show', // show/hide attendee photo |
|
893 | - 'email' => 'hide', // show/hide attendee email address |
|
894 | - ), (array) shortcode_parse_atts( $attr ) ); |
|
891 | + $attr = array_merge(array( |
|
892 | + 'photo' => 'show', // show/hide attendee photo |
|
893 | + 'email' => 'hide', // show/hide attendee email address |
|
894 | + ), (array) shortcode_parse_atts($attr)); |
|
895 | 895 | |
896 | - $photo = 'hide' != $attr['photo'] ? '<img class="avatar avatar-128 photo" src="' . $organizer['photo'] . '" itemprop="image" />' : ''; |
|
897 | - $organizer_html = $photo . '<span itemprop="name">' . $organizer['name'] . '</span>'; |
|
896 | + $photo = 'hide' != $attr['photo'] ? '<img class="avatar avatar-128 photo" src="'.$organizer['photo'].'" itemprop="image" />' : ''; |
|
897 | + $organizer_html = $photo.'<span itemprop="name">'.$organizer['name'].'</span>'; |
|
898 | 898 | |
899 | - if ( ! empty( $organizer['email'] ) && ( 'show' == $attr['email'] ) ) { |
|
900 | - $organizer_html = sprintf( '<a href="mailto:' . $organizer['email'] . '" itemprop="email">%s</a>', $organizer_html ); |
|
899 | + if ( ! empty($organizer['email']) && ('show' == $attr['email'])) { |
|
900 | + $organizer_html = sprintf('<a href="mailto:'.$organizer['email'].'" itemprop="email">%s</a>', $organizer_html); |
|
901 | 901 | } |
902 | 902 | |
903 | - return '<div class="simcal-organizer" itemprop="organizer" itemscope itemtype="https://schema.org/Person">' . $organizer_html . '</div>'; |
|
903 | + return '<div class="simcal-organizer" itemprop="organizer" itemscope itemtype="https://schema.org/Person">'.$organizer_html.'</div>'; |
|
904 | 904 | } |
905 | 905 | |
906 | 906 | /** |
@@ -925,7 +925,7 @@ discard block |
||
925 | 925 | // This is largely borrowed on get_shortcode_regex() from WordPress Core. |
926 | 926 | // @see /wp-includes/shortcodes.php (with some modification) |
927 | 927 | |
928 | - $tagregexp = implode( '|', array_values( $this->tags ) ); |
|
928 | + $tagregexp = implode('|', array_values($this->tags)); |
|
929 | 929 | |
930 | 930 | return '/' |
931 | 931 | . '\\[' // Opening bracket |