@@ -62,17 +62,17 @@ discard block |
||
62 | 62 | * @param string $_plugin_file Path to the plugin file. |
63 | 63 | * @param array $_api_data Optional data to send with API calls. |
64 | 64 | */ |
65 | - public function __construct( $_api_url, $_plugin_file, $_api_data = null ) { |
|
65 | + public function __construct($_api_url, $_plugin_file, $_api_data = null) { |
|
66 | 66 | |
67 | - $this->api_url = trailingslashit( $_api_url ); |
|
67 | + $this->api_url = trailingslashit($_api_url); |
|
68 | 68 | $this->api_data = $_api_data; |
69 | - $this->name = plugin_basename( $_plugin_file ); |
|
70 | - $this->slug = basename( $_plugin_file, '.php' ); |
|
69 | + $this->name = plugin_basename($_plugin_file); |
|
70 | + $this->slug = basename($_plugin_file, '.php'); |
|
71 | 71 | $this->version = $_api_data['version']; |
72 | 72 | |
73 | 73 | // Set up hooks. |
74 | 74 | $this->init(); |
75 | - add_action( 'admin_init', array( $this, 'show_changelog' ) ); |
|
75 | + add_action('admin_init', array($this, 'show_changelog')); |
|
76 | 76 | } |
77 | 77 | |
78 | 78 | /** |
@@ -83,10 +83,10 @@ discard block |
||
83 | 83 | * @return void |
84 | 84 | */ |
85 | 85 | public function init() { |
86 | - add_filter( 'pre_set_site_transient_update_plugins', array( $this, 'check_update' ) ); |
|
87 | - add_filter( 'plugins_api', array( $this, 'plugins_api_filter' ), 10, 3 ); |
|
88 | - remove_action( 'after_plugin_row_' . $this->name, 'wp_plugin_update_row', 10 ); |
|
89 | - add_action( 'after_plugin_row_' . $this->name, array( $this, 'show_update_notification' ), 10, 2 ); |
|
86 | + add_filter('pre_set_site_transient_update_plugins', array($this, 'check_update')); |
|
87 | + add_filter('plugins_api', array($this, 'plugins_api_filter'), 10, 3); |
|
88 | + remove_action('after_plugin_row_'.$this->name, 'wp_plugin_update_row', 10); |
|
89 | + add_action('after_plugin_row_'.$this->name, array($this, 'show_update_notification'), 10, 2); |
|
90 | 90 | } |
91 | 91 | |
92 | 92 | /** |
@@ -103,30 +103,30 @@ discard block |
||
103 | 103 | * |
104 | 104 | * @return array|\stdClass Modified update array with custom plugin data. |
105 | 105 | */ |
106 | - public function check_update( $_transient_data ) { |
|
106 | + public function check_update($_transient_data) { |
|
107 | 107 | |
108 | 108 | global $pagenow; |
109 | 109 | |
110 | - if ( ! is_object( $_transient_data ) ) { |
|
110 | + if ( ! is_object($_transient_data)) { |
|
111 | 111 | $_transient_data = new \stdClass(); |
112 | 112 | } |
113 | 113 | |
114 | - if ( 'plugins.php' == $pagenow && is_multisite() ) { |
|
114 | + if ('plugins.php' == $pagenow && is_multisite()) { |
|
115 | 115 | return $_transient_data; |
116 | 116 | } |
117 | 117 | |
118 | - if ( empty( $_transient_data->response ) || empty( $_transient_data->response[ $this->name ] ) ) { |
|
118 | + if (empty($_transient_data->response) || empty($_transient_data->response[$this->name])) { |
|
119 | 119 | |
120 | - $version_info = $this->api_request( 'plugin_latest_version', array( 'slug' => $this->slug ) ); |
|
120 | + $version_info = $this->api_request('plugin_latest_version', array('slug' => $this->slug)); |
|
121 | 121 | |
122 | - if ( false !== $version_info && is_object( $version_info ) && isset( $version_info->new_version ) ) { |
|
122 | + if (false !== $version_info && is_object($version_info) && isset($version_info->new_version)) { |
|
123 | 123 | |
124 | - if ( version_compare( $this->version, $version_info->new_version, '<' ) ) { |
|
125 | - $_transient_data->response[ $this->name ] = $version_info; |
|
124 | + if (version_compare($this->version, $version_info->new_version, '<')) { |
|
125 | + $_transient_data->response[$this->name] = $version_info; |
|
126 | 126 | } |
127 | 127 | |
128 | 128 | $_transient_data->last_checked = time(); |
129 | - $_transient_data->checked[ $this->name ] = $this->version; |
|
129 | + $_transient_data->checked[$this->name] = $this->version; |
|
130 | 130 | } |
131 | 131 | |
132 | 132 | } |
@@ -144,81 +144,81 @@ discard block |
||
144 | 144 | * @param string $file |
145 | 145 | * @param array $plugin |
146 | 146 | */ |
147 | - public function show_update_notification( $file, $plugin ) { |
|
147 | + public function show_update_notification($file, $plugin) { |
|
148 | 148 | |
149 | - if ( ! current_user_can( 'update_plugins' ) ) { |
|
149 | + if ( ! current_user_can('update_plugins')) { |
|
150 | 150 | return; |
151 | 151 | } |
152 | 152 | |
153 | - if ( ! is_multisite() ) { |
|
153 | + if ( ! is_multisite()) { |
|
154 | 154 | return; |
155 | 155 | } |
156 | 156 | |
157 | - if ( $this->name != $file ) { |
|
157 | + if ($this->name != $file) { |
|
158 | 158 | return; |
159 | 159 | } |
160 | 160 | |
161 | 161 | // Remove our filter on the site transient |
162 | - remove_filter( 'pre_set_site_transient_update_plugins', array( $this, 'check_update' ), 10 ); |
|
162 | + remove_filter('pre_set_site_transient_update_plugins', array($this, 'check_update'), 10); |
|
163 | 163 | |
164 | - $update_cache = get_site_transient( 'update_plugins' ); |
|
164 | + $update_cache = get_site_transient('update_plugins'); |
|
165 | 165 | |
166 | - if ( ! is_object( $update_cache ) || empty( $update_cache->response ) || empty( $update_cache->response[ $this->name ] ) ) { |
|
166 | + if ( ! is_object($update_cache) || empty($update_cache->response) || empty($update_cache->response[$this->name])) { |
|
167 | 167 | |
168 | - $cache_key = md5( 'edd_plugin_' .sanitize_key( $this->name ) . '_version_info' ); |
|
169 | - $version_info = get_transient( $cache_key ); |
|
168 | + $cache_key = md5('edd_plugin_'.sanitize_key($this->name).'_version_info'); |
|
169 | + $version_info = get_transient($cache_key); |
|
170 | 170 | |
171 | - if ( false === $version_info ) { |
|
171 | + if (false === $version_info) { |
|
172 | 172 | |
173 | - $version_info = $this->api_request( 'plugin_latest_version', array( 'slug' => $this->slug ) ); |
|
173 | + $version_info = $this->api_request('plugin_latest_version', array('slug' => $this->slug)); |
|
174 | 174 | |
175 | - set_transient( $cache_key, $version_info, 3600 ); |
|
175 | + set_transient($cache_key, $version_info, 3600); |
|
176 | 176 | } |
177 | 177 | |
178 | - if ( ! is_object( $version_info ) ) { |
|
178 | + if ( ! is_object($version_info)) { |
|
179 | 179 | return; |
180 | 180 | } |
181 | 181 | |
182 | - if ( version_compare( $this->version, $version_info->new_version, '<' ) ) { |
|
183 | - $update_cache->response[ $this->name ] = $version_info; |
|
182 | + if (version_compare($this->version, $version_info->new_version, '<')) { |
|
183 | + $update_cache->response[$this->name] = $version_info; |
|
184 | 184 | } |
185 | 185 | |
186 | 186 | $update_cache->last_checked = time(); |
187 | - $update_cache->checked[ $this->name ] = $this->version; |
|
187 | + $update_cache->checked[$this->name] = $this->version; |
|
188 | 188 | |
189 | - set_site_transient( 'update_plugins', $update_cache ); |
|
189 | + set_site_transient('update_plugins', $update_cache); |
|
190 | 190 | |
191 | 191 | } else { |
192 | 192 | |
193 | - $version_info = $update_cache->response[ $this->name ]; |
|
193 | + $version_info = $update_cache->response[$this->name]; |
|
194 | 194 | |
195 | 195 | } |
196 | 196 | |
197 | 197 | // Restore our filter |
198 | - add_filter( 'pre_set_site_transient_update_plugins', array( $this, 'check_update' ) ); |
|
198 | + add_filter('pre_set_site_transient_update_plugins', array($this, 'check_update')); |
|
199 | 199 | |
200 | - if ( ! empty( $update_cache->response[ $this->name ] ) && version_compare( $this->version, $version_info->new_version, '<' ) ) { |
|
200 | + if ( ! empty($update_cache->response[$this->name]) && version_compare($this->version, $version_info->new_version, '<')) { |
|
201 | 201 | |
202 | 202 | // build a plugin list row, with update notification |
203 | - $wp_list_table = _get_list_table( 'WP_Plugins_List_Table' ); |
|
204 | - echo '<tr class="plugin-update-tr"><td colspan="' . $wp_list_table->get_column_count() . '" class="plugin-update colspanchange"><div class="update-message">'; |
|
203 | + $wp_list_table = _get_list_table('WP_Plugins_List_Table'); |
|
204 | + echo '<tr class="plugin-update-tr"><td colspan="'.$wp_list_table->get_column_count().'" class="plugin-update colspanchange"><div class="update-message">'; |
|
205 | 205 | |
206 | - $changelog_link = self_admin_url( 'index.php?edd_sl_action=view_plugin_changelog&plugin=' . $this->name . '&slug=' . $this->slug . '&TB_iframe=true&width=772&height=911' ); |
|
206 | + $changelog_link = self_admin_url('index.php?edd_sl_action=view_plugin_changelog&plugin='.$this->name.'&slug='.$this->slug.'&TB_iframe=true&width=772&height=911'); |
|
207 | 207 | |
208 | - if ( empty( $version_info->download_link ) ) { |
|
208 | + if (empty($version_info->download_link)) { |
|
209 | 209 | printf( |
210 | - __( 'There is a new version of %1$s available. <a target="_blank" class="thickbox" href="%2$s">View version %3$s details</a>.', 'google-calendar-events' ), |
|
211 | - esc_html( $version_info->name ), |
|
212 | - esc_url( $changelog_link ), |
|
213 | - esc_html( $version_info->new_version ) |
|
210 | + __('There is a new version of %1$s available. <a target="_blank" class="thickbox" href="%2$s">View version %3$s details</a>.', 'google-calendar-events'), |
|
211 | + esc_html($version_info->name), |
|
212 | + esc_url($changelog_link), |
|
213 | + esc_html($version_info->new_version) |
|
214 | 214 | ); |
215 | 215 | } else { |
216 | 216 | printf( |
217 | - __( 'There is a new version of %1$s available. <a target="_blank" class="thickbox" href="%2$s">View version %3$s details</a> or <a href="%4$s">update now</a>.', 'google-calendar-events' ), |
|
218 | - esc_html( $version_info->name ), |
|
219 | - esc_url( $changelog_link ), |
|
220 | - esc_html( $version_info->new_version ), |
|
221 | - esc_url( wp_nonce_url( self_admin_url( 'update.php?action=upgrade-plugin&plugin=' ) . $this->name, 'upgrade-plugin_' . $this->name ) ) |
|
217 | + __('There is a new version of %1$s available. <a target="_blank" class="thickbox" href="%2$s">View version %3$s details</a> or <a href="%4$s">update now</a>.', 'google-calendar-events'), |
|
218 | + esc_html($version_info->name), |
|
219 | + esc_url($changelog_link), |
|
220 | + esc_html($version_info->new_version), |
|
221 | + esc_url(wp_nonce_url(self_admin_url('update.php?action=upgrade-plugin&plugin=').$this->name, 'upgrade-plugin_'.$this->name)) |
|
222 | 222 | ); |
223 | 223 | } |
224 | 224 | |
@@ -238,13 +238,13 @@ discard block |
||
238 | 238 | * |
239 | 239 | * @return object |
240 | 240 | */ |
241 | - public function plugins_api_filter( $_data, $_action = '', $_args = null ) { |
|
241 | + public function plugins_api_filter($_data, $_action = '', $_args = null) { |
|
242 | 242 | |
243 | - if ( 'plugin_information' != $_action ) { |
|
243 | + if ('plugin_information' != $_action) { |
|
244 | 244 | return $_data; |
245 | 245 | } |
246 | 246 | |
247 | - if ( ! isset( $_args->slug ) || ( $_args->slug != $this->slug ) ) { |
|
247 | + if ( ! isset($_args->slug) || ($_args->slug != $this->slug)) { |
|
248 | 248 | return $_data; |
249 | 249 | } |
250 | 250 | |
@@ -257,9 +257,9 @@ discard block |
||
257 | 257 | ), |
258 | 258 | ); |
259 | 259 | |
260 | - $api_response = $this->api_request( 'plugin_information', $to_send ); |
|
260 | + $api_response = $this->api_request('plugin_information', $to_send); |
|
261 | 261 | |
262 | - if ( false !== $api_response ) { |
|
262 | + if (false !== $api_response) { |
|
263 | 263 | $_data = $api_response; |
264 | 264 | } |
265 | 265 | |
@@ -276,9 +276,9 @@ discard block |
||
276 | 276 | * @param string $url |
277 | 277 | * @return object|array $array |
278 | 278 | */ |
279 | - public function http_request_args( $args, $url ) { |
|
279 | + public function http_request_args($args, $url) { |
|
280 | 280 | // If it is an https request and we are performing a package download, disable ssl verification |
281 | - if ( strpos( $url, 'https://' ) !== false && strpos( $url, 'edd_action=package_download' ) ) { |
|
281 | + if (strpos($url, 'https://') !== false && strpos($url, 'edd_action=package_download')) { |
|
282 | 282 | $args['sslverify'] = false; |
283 | 283 | } |
284 | 284 | return $args; |
@@ -293,42 +293,42 @@ discard block |
||
293 | 293 | * @param array $_data Parameters for the API action. |
294 | 294 | * @return false|object |
295 | 295 | */ |
296 | - private function api_request( $_action, $_data ) { |
|
296 | + private function api_request($_action, $_data) { |
|
297 | 297 | |
298 | 298 | global $wp_version; |
299 | 299 | |
300 | - $data = array_merge( $this->api_data, $_data ); |
|
300 | + $data = array_merge($this->api_data, $_data); |
|
301 | 301 | |
302 | - if ( $data['slug'] != $this->slug ) { |
|
302 | + if ($data['slug'] != $this->slug) { |
|
303 | 303 | return; |
304 | 304 | } |
305 | 305 | |
306 | - if ( empty( $data['license'] ) ) { |
|
306 | + if (empty($data['license'])) { |
|
307 | 307 | return; |
308 | 308 | } |
309 | 309 | |
310 | - if ( $this->api_url == home_url() ) { |
|
310 | + if ($this->api_url == home_url()) { |
|
311 | 311 | return false; // Don't allow a plugin to ping itself |
312 | 312 | } |
313 | 313 | |
314 | 314 | $api_params = array( |
315 | 315 | 'edd_action' => 'get_version', |
316 | 316 | 'license' => $data['license'], |
317 | - 'item_name' => isset( $data['item_name'] ) ? $data['item_name'] : false, |
|
318 | - 'item_id' => isset( $data['item_id'] ) ? $data['item_id'] : false, |
|
317 | + 'item_name' => isset($data['item_name']) ? $data['item_name'] : false, |
|
318 | + 'item_id' => isset($data['item_id']) ? $data['item_id'] : false, |
|
319 | 319 | 'slug' => $data['slug'], |
320 | 320 | 'author' => $data['author'], |
321 | 321 | 'url' => home_url() |
322 | 322 | ); |
323 | 323 | |
324 | - $request = wp_remote_post( $this->api_url, array( 'timeout' => 15, 'sslverify' => false, 'body' => $api_params ) ); |
|
324 | + $request = wp_remote_post($this->api_url, array('timeout' => 15, 'sslverify' => false, 'body' => $api_params)); |
|
325 | 325 | |
326 | - if ( ! is_wp_error( $request ) ) { |
|
327 | - $request = json_decode( wp_remote_retrieve_body( $request ) ); |
|
326 | + if ( ! is_wp_error($request)) { |
|
327 | + $request = json_decode(wp_remote_retrieve_body($request)); |
|
328 | 328 | } |
329 | 329 | |
330 | - if ( $request && isset( $request->sections ) ) { |
|
331 | - $request->sections = maybe_unserialize( $request->sections ); |
|
330 | + if ($request && isset($request->sections)) { |
|
331 | + $request->sections = maybe_unserialize($request->sections); |
|
332 | 332 | } else { |
333 | 333 | $request = false; |
334 | 334 | } |
@@ -343,26 +343,26 @@ discard block |
||
343 | 343 | */ |
344 | 344 | public function show_changelog() { |
345 | 345 | |
346 | - if ( empty( $_REQUEST['edd_sl_action'] ) || 'view_plugin_changelog' != $_REQUEST['edd_sl_action'] ) { |
|
346 | + if (empty($_REQUEST['edd_sl_action']) || 'view_plugin_changelog' != $_REQUEST['edd_sl_action']) { |
|
347 | 347 | return; |
348 | 348 | } |
349 | 349 | |
350 | - if ( empty( $_REQUEST['plugin'] ) ) { |
|
350 | + if (empty($_REQUEST['plugin'])) { |
|
351 | 351 | return; |
352 | 352 | } |
353 | 353 | |
354 | - if ( empty( $_REQUEST['slug'] ) ) { |
|
354 | + if (empty($_REQUEST['slug'])) { |
|
355 | 355 | return; |
356 | 356 | } |
357 | 357 | |
358 | - if ( ! current_user_can( 'update_plugins' ) ) { |
|
359 | - wp_die( __( 'You do not have permission to install plugin updates', 'google-calendar-events' ), __( 'Error', 'google-calendar-events' ), array( 'response' => 403 ) ); |
|
358 | + if ( ! current_user_can('update_plugins')) { |
|
359 | + wp_die(__('You do not have permission to install plugin updates', 'google-calendar-events'), __('Error', 'google-calendar-events'), array('response' => 403)); |
|
360 | 360 | } |
361 | 361 | |
362 | - $response = $this->api_request( 'plugin_latest_version', array( 'slug' => $_REQUEST['slug'] ) ); |
|
362 | + $response = $this->api_request('plugin_latest_version', array('slug' => $_REQUEST['slug'])); |
|
363 | 363 | |
364 | - if ( $response && isset( $response->sections['changelog'] ) ) { |
|
365 | - echo '<div style="background:#fff;padding:10px;">' . $response->sections['changelog'] . '</div>'; |
|
364 | + if ($response && isset($response->sections['changelog'])) { |
|
365 | + echo '<div style="background:#fff;padding:10px;">'.$response->sections['changelog'].'</div>'; |
|
366 | 366 | } |
367 | 367 | |
368 | 368 | exit; |
@@ -8,7 +8,7 @@ discard block |
||
8 | 8 | |
9 | 9 | use SimpleCalendar\Abstracts\Calendar_View; |
10 | 10 | |
11 | -if ( ! defined( 'ABSPATH' ) ) { |
|
11 | +if ( ! defined('ABSPATH')) { |
|
12 | 12 | exit; |
13 | 13 | } |
14 | 14 | |
@@ -25,7 +25,7 @@ discard block |
||
25 | 25 | * @since 3.0.0 |
26 | 26 | */ |
27 | 27 | public function __construct() { |
28 | - add_action( 'init', array( $this, 'add_callbacks' ), 100 ); |
|
28 | + add_action('init', array($this, 'add_callbacks'), 100); |
|
29 | 29 | } |
30 | 30 | |
31 | 31 | /** |
@@ -37,19 +37,19 @@ discard block |
||
37 | 37 | |
38 | 38 | $calendars = simcal_get_calendar_types(); |
39 | 39 | |
40 | - foreach ( $calendars as $calendar => $views ) { |
|
40 | + foreach ($calendars as $calendar => $views) { |
|
41 | 41 | |
42 | - foreach ( $views as $view ) { |
|
42 | + foreach ($views as $view) { |
|
43 | 43 | |
44 | - $the_view = simcal_get_calendar_view( 0, $calendar . '-' . $view ); |
|
44 | + $the_view = simcal_get_calendar_view(0, $calendar.'-'.$view); |
|
45 | 45 | |
46 | - if ( $the_view instanceof Calendar_View ) { |
|
46 | + if ($the_view instanceof Calendar_View) { |
|
47 | 47 | $the_view->add_ajax_actions(); |
48 | 48 | } |
49 | 49 | } |
50 | 50 | } |
51 | 51 | |
52 | - do_action( 'simcal_add_ajax_callbacks' ); |
|
52 | + do_action('simcal_add_ajax_callbacks'); |
|
53 | 53 | } |
54 | 54 | |
55 | 55 | } |
@@ -5,11 +5,11 @@ discard block |
||
5 | 5 | * @package SimpleCalendar |
6 | 6 | */ |
7 | 7 | |
8 | -if ( ! defined( 'ABSPATH' ) ) { |
|
8 | +if ( ! defined('ABSPATH')) { |
|
9 | 9 | exit; |
10 | 10 | } |
11 | 11 | |
12 | -if ( ! function_exists( 'SimpleCalendar_Autoload' ) ) { |
|
12 | +if ( ! function_exists('SimpleCalendar_Autoload')) { |
|
13 | 13 | |
14 | 14 | /** |
15 | 15 | * Plugin autoloader. |
@@ -22,31 +22,31 @@ discard block |
||
22 | 22 | * |
23 | 23 | * @param $class |
24 | 24 | */ |
25 | - function SimpleCalendar_Autoload( $class ) { |
|
25 | + function SimpleCalendar_Autoload($class) { |
|
26 | 26 | |
27 | 27 | // Do not load unless in plugin domain. |
28 | 28 | $namespace = 'SimpleCalendar'; |
29 | - if ( strpos( $class, $namespace ) !== 0 ) { |
|
29 | + if (strpos($class, $namespace) !== 0) { |
|
30 | 30 | return; |
31 | 31 | } |
32 | 32 | |
33 | 33 | // Converts Class_Name (class convention) to class-name (file convention). |
34 | - $class_name = implode( '-', array_map( 'lcfirst', explode( '_', strtolower( $class ) ) ) ); |
|
34 | + $class_name = implode('-', array_map('lcfirst', explode('_', strtolower($class)))); |
|
35 | 35 | |
36 | 36 | // Remove the root namespace. |
37 | - $unprefixed = substr( $class_name, strlen( $namespace ) ); |
|
37 | + $unprefixed = substr($class_name, strlen($namespace)); |
|
38 | 38 | |
39 | 39 | // Build the file path. |
40 | - $file_path = str_replace( '\\', DIRECTORY_SEPARATOR, $unprefixed ); |
|
41 | - $file = dirname( __FILE__ ) . '/' . $file_path . '.php'; |
|
40 | + $file_path = str_replace('\\', DIRECTORY_SEPARATOR, $unprefixed); |
|
41 | + $file = dirname(__FILE__).'/'.$file_path.'.php'; |
|
42 | 42 | |
43 | - if ( file_exists( $file ) ) { |
|
43 | + if (file_exists($file)) { |
|
44 | 44 | require $file; |
45 | 45 | } |
46 | 46 | |
47 | 47 | } |
48 | 48 | |
49 | 49 | // Register the autoloader. |
50 | - spl_autoload_register( 'SimpleCalendar_Autoload' ); |
|
50 | + spl_autoload_register('SimpleCalendar_Autoload'); |
|
51 | 51 | |
52 | 52 | } |
@@ -453,10 +453,12 @@ |
||
453 | 453 | $list_events .= '<button class="simcal-events-toggle"><i class="simcal-icon-down simcal-icon-animate"></i></button>'; |
454 | 454 | endif; |
455 | 455 | |
456 | - else : |
|
456 | + else { |
|
457 | + : |
|
457 | 458 | |
458 | 459 | // Empty cell for day with no events. |
459 | 460 | $list_events = '<span class="simcal-no-events"></span>'; |
461 | + } |
|
460 | 462 | |
461 | 463 | endif; |
462 | 464 |
@@ -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,82 +284,82 @@ 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 | - date_default_timezone_set( $calendar->timezone ); |
|
296 | + date_default_timezone_set($calendar->timezone); |
|
297 | 297 | $events = $calendar->events; |
298 | 298 | |
299 | 299 | // Variables to cycle days in current month and find today in calendar. |
300 | 300 | $now = $calendar->now; |
301 | - $current = Carbon::create( $year, $month, 1, 0, 0, 0, $calendar->timezone ); |
|
301 | + $current = Carbon::create($year, $month, 1, 0, 0, 0, $calendar->timezone); |
|
302 | 302 | $current_min = $current->getTimestamp(); |
303 | 303 | $current_max = $current->endOfDay()->getTimestamp(); |
304 | 304 | |
305 | 305 | // Calendar grid variables. |
306 | 306 | $week_starts = $calendar->week_starts; |
307 | - $week_of_year = $current->weekOfYear; // Relative count of the week number of the year. |
|
308 | - $month_starts = $current->dayOfWeek; // Day upon which the month starts. |
|
309 | - $days_in_month = $current->daysInMonth; // Number of days in the given month. |
|
307 | + $week_of_year = $current->weekOfYear; // Relative count of the week number of the year. |
|
308 | + $month_starts = $current->dayOfWeek; // Day upon which the month starts. |
|
309 | + $days_in_month = $current->daysInMonth; // Number of days in the given month. |
|
310 | 310 | |
311 | 311 | // Set current month events timestamp boundaries. |
312 | 312 | $this->start = $current_min; |
313 | 313 | $this->end = $current->endOfMonth()->timestamp; |
314 | 314 | |
315 | 315 | // Get daily events for this month. |
316 | - if ( $events && is_array( $events ) ) { |
|
316 | + if ($events && is_array($events)) { |
|
317 | 317 | |
318 | 318 | // Filter events within the boundaries previously set above. |
319 | - $timestamps = array_keys( $events ); |
|
320 | - $lower_bound = array_filter( $timestamps, array( $this, 'filter_events_before' ) ); |
|
321 | - $higher_bound = array_filter( $lower_bound, array( $this, 'filter_events_after' ) ); |
|
322 | - $filtered = ( is_array( $events ) && is_array( $higher_bound) ) && ! empty( $events ) && ! empty( $higher_bound ) ? array_intersect_key( $events, array_combine( $higher_bound, $higher_bound ) ) : array(); |
|
319 | + $timestamps = array_keys($events); |
|
320 | + $lower_bound = array_filter($timestamps, array($this, 'filter_events_before')); |
|
321 | + $higher_bound = array_filter($lower_bound, array($this, 'filter_events_after')); |
|
322 | + $filtered = (is_array($events) && is_array($higher_bound)) && ! empty($events) && ! empty($higher_bound) ? array_intersect_key($events, array_combine($higher_bound, $higher_bound)) : array(); |
|
323 | 323 | |
324 | 324 | // Put resulting events in an associative array, with day of the month as key for easy retrieval in calendar days loop. |
325 | 325 | $day_events = array(); |
326 | - foreach ( $filtered as $timestamp => $events_in_day ) { |
|
327 | - foreach ( $events_in_day as $event ) { |
|
328 | - if ( $event instanceof Event ){ |
|
329 | - $day = intval( Carbon::createFromTimestamp( $timestamp, $event->timezone )->endOfDay()->day ); |
|
330 | - $day_events[ $day ][] = $event; |
|
326 | + foreach ($filtered as $timestamp => $events_in_day) { |
|
327 | + foreach ($events_in_day as $event) { |
|
328 | + if ($event instanceof Event) { |
|
329 | + $day = intval(Carbon::createFromTimestamp($timestamp, $event->timezone)->endOfDay()->day); |
|
330 | + $day_events[$day][] = $event; |
|
331 | 331 | } |
332 | 332 | } |
333 | 333 | } |
334 | 334 | |
335 | - ksort( $day_events, SORT_NUMERIC ); |
|
335 | + ksort($day_events, SORT_NUMERIC); |
|
336 | 336 | } |
337 | 337 | |
338 | 338 | ob_start(); |
339 | 339 | |
340 | - echo '<tbody class="simcal-month simcal-month-' . $month . '">' . "\n"; |
|
341 | - echo "\t" . '<tr class="simcal-week simcal-week-' . $week_of_year . '">'; |
|
340 | + echo '<tbody class="simcal-month simcal-month-'.$month.'">'."\n"; |
|
341 | + echo "\t".'<tr class="simcal-week simcal-week-'.$week_of_year.'">'; |
|
342 | 342 | |
343 | 343 | $days_in_row = 0; |
344 | 344 | // Week may start on an arbitrary day (sun, 0 - sat, 6). |
345 | 345 | $week_day = $week_starts; |
346 | 346 | |
347 | 347 | // This fixes a possible bug when a month starts by Sunday (0). |
348 | - if ( 0 !== $week_starts ) { |
|
348 | + if (0 !== $week_starts) { |
|
349 | 349 | $b = $month_starts === 0 ? 7 : $month_starts; |
350 | 350 | } else { |
351 | 351 | $b = $month_starts; |
352 | 352 | } |
353 | 353 | |
354 | 354 | // Void days in first week. |
355 | - for ( $a = $week_starts; $a < $b; $a++ ) : |
|
355 | + for ($a = $week_starts; $a < $b; $a++) : |
|
356 | 356 | |
357 | - $last_void_day_class = ( $a === ( $b - 1 ) ) ? 'simcal-day-void-last' : ''; |
|
357 | + $last_void_day_class = ($a === ($b - 1)) ? 'simcal-day-void-last' : ''; |
|
358 | 358 | |
359 | - echo '<td class="simcal-day simcal-day-void ' . $last_void_day_class . '"></td>' . "\n"; |
|
359 | + echo '<td class="simcal-day simcal-day-void '.$last_void_day_class.'"></td>'."\n"; |
|
360 | 360 | |
361 | 361 | // Reset day of the week count (sun, 0 - sat, 6). |
362 | - if ( $week_day === 6 ) { |
|
362 | + if ($week_day === 6) { |
|
363 | 363 | $week_day = -1; |
364 | 364 | } |
365 | 365 | $week_day++; |
@@ -369,91 +369,91 @@ discard block |
||
369 | 369 | endfor; |
370 | 370 | |
371 | 371 | // Actual days of the month. |
372 | - for ( $day = 1; $day <= $days_in_month; $day++ ) : |
|
372 | + for ($day = 1; $day <= $days_in_month; $day++) : |
|
373 | 373 | |
374 | 374 | $count = 0; |
375 | 375 | $calendar_classes = array(); |
376 | - $day_classes = 'simcal-day-' . $day . ' simcal-weekday-' . $week_day; |
|
376 | + $day_classes = 'simcal-day-'.$day.' simcal-weekday-'.$week_day; |
|
377 | 377 | |
378 | 378 | $border_style = $bg_color = $color = ''; |
379 | 379 | |
380 | 380 | // Is this the present, the past or the future, Doc? |
381 | - if ( $current_min <= $now && $current_max >= $now ) { |
|
381 | + if ($current_min <= $now && $current_max >= $now) { |
|
382 | 382 | $day_classes .= ' simcal-today simcal-present simcal-day'; |
383 | - $the_color = new Color( $calendar->today_color ); |
|
384 | - $bg_color = '#' . $the_color->getHex(); |
|
383 | + $the_color = new Color($calendar->today_color); |
|
384 | + $bg_color = '#'.$the_color->getHex(); |
|
385 | 385 | $color = $the_color->isDark() ? '#ffffff' : '#000000'; |
386 | - $border_style = ' style="border: 1px solid ' . $bg_color . ';"'; |
|
387 | - } elseif ( $current_max < $now ) { |
|
386 | + $border_style = ' style="border: 1px solid '.$bg_color.';"'; |
|
387 | + } elseif ($current_max < $now) { |
|
388 | 388 | $day_classes .= ' simcal-past simcal-day'; |
389 | - } elseif ( $current_min > $now ) { |
|
389 | + } elseif ($current_min > $now) { |
|
390 | 390 | $day_classes .= ' simcal-future simcal-day'; |
391 | 391 | } |
392 | 392 | |
393 | 393 | // Print events for the current day in loop, if found any. |
394 | - if ( isset( $day_events[ $day ] ) ) : |
|
394 | + if (isset($day_events[$day])) : |
|
395 | 395 | |
396 | 396 | $list_events = '<ul class="simcal-events">'; |
397 | 397 | |
398 | - foreach ( $day_events[ $day ] as $event ) : |
|
398 | + foreach ($day_events[$day] as $event) : |
|
399 | 399 | |
400 | 400 | $event_classes = $event_visibility = ''; |
401 | 401 | |
402 | - if ( $event instanceof Event ) : |
|
402 | + if ($event instanceof Event) : |
|
403 | 403 | |
404 | 404 | // Store the calendar id where the event belongs (useful in grouped calendar feeds) |
405 | - $calendar_class = 'simcal-events-calendar-' . strval( $event->calendar ); |
|
406 | - $calendar_classes[] = $calendar_class ; |
|
405 | + $calendar_class = 'simcal-events-calendar-'.strval($event->calendar); |
|
406 | + $calendar_classes[] = $calendar_class; |
|
407 | 407 | |
408 | 408 | $recurring = $event->recurrence ? 'simcal-event-recurring ' : ''; |
409 | 409 | $has_location = $event->venue ? 'simcal-event-has-location ' : ''; |
410 | 410 | |
411 | - $event_classes .= 'simcal-event ' . $recurring . $has_location . $calendar_class . ' simcal-tooltip'; |
|
411 | + $event_classes .= 'simcal-event '.$recurring.$has_location.$calendar_class.' simcal-tooltip'; |
|
412 | 412 | |
413 | 413 | // Toggle some events visibility if more than optional limit. |
414 | - if ( ( $calendar->events_limit > -1 ) && ( $count >= $calendar->events_limit ) ) : |
|
414 | + if (($calendar->events_limit > -1) && ($count >= $calendar->events_limit)) : |
|
415 | 415 | $event_classes .= ' simcal-event-toggled'; |
416 | 416 | $event_visibility = ' style="display: none"'; |
417 | 417 | endif; |
418 | 418 | |
419 | 419 | // Event title in list. |
420 | - $title = ! empty( $event->title ) ? trim( $event->title ) : __( 'Event', 'google-calendar-events' ); |
|
421 | - if ( $calendar->trim_titles >= 1 ) { |
|
422 | - $title = strlen( $title ) > $calendar->trim_titles ? mb_substr( $title, 0, $calendar->trim_titles ) . '…' : $title; |
|
420 | + $title = ! empty($event->title) ? trim($event->title) : __('Event', 'google-calendar-events'); |
|
421 | + if ($calendar->trim_titles >= 1) { |
|
422 | + $title = strlen($title) > $calendar->trim_titles ? mb_substr($title, 0, $calendar->trim_titles).'…' : $title; |
|
423 | 423 | } |
424 | 424 | |
425 | 425 | // Event color. |
426 | 426 | $bullet = ''; |
427 | 427 | $event_color = $event->get_color(); |
428 | - if ( ! empty( $event_color ) ) { |
|
429 | - $bullet = '<span style="color: ' . $event_color . ';">■</span> '; |
|
428 | + if ( ! empty($event_color)) { |
|
429 | + $bullet = '<span style="color: '.$event_color.';">■</span> '; |
|
430 | 430 | } |
431 | 431 | |
432 | 432 | // Event contents. |
433 | - $list_events .= "\t" . '<li class="' . $event_classes . '"' . $event_visibility . ' itemscope itemtype="http://schema.org/Event">' . "\n"; |
|
434 | - $list_events .= "\t\t" . '<span class="simcal-event-title">' . $bullet . $title . '</span>' . "\n"; |
|
435 | - $list_events .= "\t\t" . '<div class="simcal-event-details simcal-tooltip-content" style="display: none;">' . $calendar->get_event_html( $event ) . '</div>' . "\n"; |
|
436 | - $list_events .= "\t" . '</li>' . "\n"; |
|
433 | + $list_events .= "\t".'<li class="'.$event_classes.'"'.$event_visibility.' itemscope itemtype="http://schema.org/Event">'."\n"; |
|
434 | + $list_events .= "\t\t".'<span class="simcal-event-title">'.$bullet.$title.'</span>'."\n"; |
|
435 | + $list_events .= "\t\t".'<div class="simcal-event-details simcal-tooltip-content" style="display: none;">'.$calendar->get_event_html($event).'</div>'."\n"; |
|
436 | + $list_events .= "\t".'</li>'."\n"; |
|
437 | 437 | |
438 | - $count ++; |
|
438 | + $count++; |
|
439 | 439 | |
440 | 440 | endif; |
441 | 441 | |
442 | 442 | endforeach; |
443 | 443 | |
444 | - if ( ( $current_min <= $now ) && ( $current_max >= $now ) ) { |
|
444 | + if (($current_min <= $now) && ($current_max >= $now)) { |
|
445 | 445 | $day_classes .= ' simcal-today-has-events'; |
446 | 446 | } |
447 | - $day_classes .= ' simcal-day-has-events simcal-day-has-' . strval( $count ) . '-events'; |
|
447 | + $day_classes .= ' simcal-day-has-events simcal-day-has-'.strval($count).'-events'; |
|
448 | 448 | |
449 | - if ( $calendar_classes ) { |
|
450 | - $day_classes .= ' ' . trim( implode( ' ', array_unique( $calendar_classes ) ) ); |
|
449 | + if ($calendar_classes) { |
|
450 | + $day_classes .= ' '.trim(implode(' ', array_unique($calendar_classes))); |
|
451 | 451 | } |
452 | 452 | |
453 | - $list_events .= '</ul>' . "\n"; |
|
453 | + $list_events .= '</ul>'."\n"; |
|
454 | 454 | |
455 | 455 | // Optional button to toggle hidden events in list. |
456 | - if ( ( $calendar->events_limit > -1 ) && ( $count > $calendar->events_limit ) ) : |
|
456 | + if (($calendar->events_limit > -1) && ($count > $calendar->events_limit)) : |
|
457 | 457 | $list_events .= '<button class="simcal-events-toggle"><i class="simcal-icon-down simcal-icon-animate"></i></button>'; |
458 | 458 | endif; |
459 | 459 | |
@@ -465,49 +465,49 @@ discard block |
||
465 | 465 | endif; |
466 | 466 | |
467 | 467 | // The actual days with numbers and events in each row cell. |
468 | - echo '<td class="' . $day_classes . '" data-events-count="' . strval( $count ) . '">' . "\n"; |
|
469 | - |
|
470 | - if ( $color ) { |
|
471 | - $day_style = ' style="background-color: ' . $bg_color . '; color: ' . $color .'"'; |
|
472 | - } elseif ( $count > 0 ) { |
|
473 | - $the_color = new Color( $calendar->days_events_color ); |
|
474 | - $color = ! $color ? ( $the_color->isDark() ? '#ffffff' : '#000000' ) : $color; |
|
475 | - $bg_color = ! $bg_color ? '#' . $the_color->getHex() : $bg_color; |
|
476 | - $day_style = ' style="background-color: ' . $bg_color . '; color: ' . $color .'"'; |
|
468 | + echo '<td class="'.$day_classes.'" data-events-count="'.strval($count).'">'."\n"; |
|
469 | + |
|
470 | + if ($color) { |
|
471 | + $day_style = ' style="background-color: '.$bg_color.'; color: '.$color.'"'; |
|
472 | + } elseif ($count > 0) { |
|
473 | + $the_color = new Color($calendar->days_events_color); |
|
474 | + $color = ! $color ? ($the_color->isDark() ? '#ffffff' : '#000000') : $color; |
|
475 | + $bg_color = ! $bg_color ? '#'.$the_color->getHex() : $bg_color; |
|
476 | + $day_style = ' style="background-color: '.$bg_color.'; color: '.$color.'"'; |
|
477 | 477 | } else { |
478 | 478 | $day_style = ''; |
479 | 479 | } |
480 | 480 | |
481 | - echo "\t" . '<div' . $border_style . '>' . "\n"; |
|
482 | - echo "\t\t" . '<span class="simcal-day-label simcal-day-number"' . $day_style . '>' . $day . '</span>' . "\n"; |
|
483 | - echo "\t\t" . $list_events . "\n"; |
|
481 | + echo "\t".'<div'.$border_style.'>'."\n"; |
|
482 | + echo "\t\t".'<span class="simcal-day-label simcal-day-number"'.$day_style.'>'.$day.'</span>'."\n"; |
|
483 | + echo "\t\t".$list_events."\n"; |
|
484 | 484 | echo "\t\t"; |
485 | 485 | echo '<span class="simcal-events-dots" style="display: none;">'; |
486 | 486 | |
487 | 487 | // Event bullets for calendar mobile mode. |
488 | - for( $i = 0; $i < $count; $i++ ) { |
|
488 | + for ($i = 0; $i < $count; $i++) { |
|
489 | 489 | echo '<b> • </b>'; |
490 | 490 | } |
491 | 491 | |
492 | - echo '</span>' . "\n"; |
|
493 | - echo "\t" . '</div>' . "\n"; |
|
494 | - echo '</td>' . "\n"; |
|
492 | + echo '</span>'."\n"; |
|
493 | + echo "\t".'</div>'."\n"; |
|
494 | + echo '</td>'."\n"; |
|
495 | 495 | |
496 | 496 | // Reset day of the week count (sun, 0 - sat, 6). |
497 | - if ( $week_day === 6 ) { |
|
497 | + if ($week_day === 6) { |
|
498 | 498 | $week_day = - 1; |
499 | 499 | } |
500 | 500 | $week_day++; |
501 | 501 | |
502 | 502 | // Reset count of days for this row (0-6). |
503 | - if ( $days_in_row === 6 ) : |
|
503 | + if ($days_in_row === 6) : |
|
504 | 504 | |
505 | 505 | // Close the week row. |
506 | 506 | echo '</tr>'; |
507 | 507 | |
508 | 508 | // Open a new week row. |
509 | - if ( $day < $days_in_month ) { |
|
510 | - echo '<tr class="simcal-week simcal-week-' . $week_of_year++ . '">' . "\n"; |
|
509 | + if ($day < $days_in_month) { |
|
510 | + echo '<tr class="simcal-week simcal-week-'.$week_of_year++.'">'."\n"; |
|
511 | 511 | } |
512 | 512 | |
513 | 513 | $days_in_row = -1; |
@@ -516,27 +516,27 @@ discard block |
||
516 | 516 | |
517 | 517 | $days_in_row++; |
518 | 518 | |
519 | - $current_min = Carbon::createFromTimestamp( $current_min, $calendar->timezone )->addDay()->getTimestamp(); |
|
520 | - $current_max = Carbon::createFromTimestamp( $current_max, $calendar->timezone )->addDay()->getTimestamp(); |
|
519 | + $current_min = Carbon::createFromTimestamp($current_min, $calendar->timezone)->addDay()->getTimestamp(); |
|
520 | + $current_max = Carbon::createFromTimestamp($current_max, $calendar->timezone)->addDay()->getTimestamp(); |
|
521 | 521 | |
522 | 522 | endfor; |
523 | 523 | |
524 | 524 | // Void days at the end of the month. |
525 | - $remainder_days = ( 6 - $days_in_row ); |
|
525 | + $remainder_days = (6 - $days_in_row); |
|
526 | 526 | |
527 | - for ( $i = 0; $i <= $remainder_days; $i ++ ) { |
|
527 | + for ($i = 0; $i <= $remainder_days; $i++) { |
|
528 | 528 | |
529 | - $last_void_day_class = ( $i == $remainder_days ) ? 'simcal-day-void-last' : ''; |
|
529 | + $last_void_day_class = ($i == $remainder_days) ? 'simcal-day-void-last' : ''; |
|
530 | 530 | |
531 | - echo '<td class="simcal-day simcal-day-void ' . $last_void_day_class . '"></td>' . "\n"; |
|
531 | + echo '<td class="simcal-day simcal-day-void '.$last_void_day_class.'"></td>'."\n"; |
|
532 | 532 | |
533 | 533 | $week_day++; |
534 | 534 | } |
535 | 535 | |
536 | - echo "\t" . '</tr>' . "\n"; |
|
537 | - echo '</tbody>' . "\n"; |
|
536 | + echo "\t".'</tr>'."\n"; |
|
537 | + echo '</tbody>'."\n"; |
|
538 | 538 | |
539 | - date_default_timezone_set( $calendar->site_timezone ); |
|
539 | + date_default_timezone_set($calendar->site_timezone); |
|
540 | 540 | |
541 | 541 | return ob_get_clean(); |
542 | 542 | } |
@@ -548,17 +548,17 @@ discard block |
||
548 | 548 | */ |
549 | 549 | public function draw_grid_ajax() { |
550 | 550 | |
551 | - if ( isset( $_POST['month'] ) && isset( $_POST['year'] ) && isset( $_POST['id'] ) ) { |
|
551 | + if (isset($_POST['month']) && isset($_POST['year']) && isset($_POST['id'])) { |
|
552 | 552 | |
553 | - $month = absint( $_POST['month'] ); |
|
554 | - $year = absint( $_POST['year'] ); |
|
555 | - $id = absint( $_POST['id'] ); |
|
553 | + $month = absint($_POST['month']); |
|
554 | + $year = absint($_POST['year']); |
|
555 | + $id = absint($_POST['id']); |
|
556 | 556 | |
557 | - wp_send_json_success( $this->draw_month( $month, $year, $id ) ); |
|
557 | + wp_send_json_success($this->draw_month($month, $year, $id)); |
|
558 | 558 | |
559 | 559 | } else { |
560 | 560 | |
561 | - wp_send_json_error( 'Missing arguments in default calendar grid ajax request.' ); |
|
561 | + wp_send_json_error('Missing arguments in default calendar grid ajax request.'); |
|
562 | 562 | |
563 | 563 | } |
564 | 564 | |
@@ -574,8 +574,8 @@ discard block |
||
574 | 574 | * |
575 | 575 | * @return bool |
576 | 576 | */ |
577 | - private function filter_events_before( $event ) { |
|
578 | - return intval( $event ) >= intval( $this->start ); |
|
577 | + private function filter_events_before($event) { |
|
578 | + return intval($event) >= intval($this->start); |
|
579 | 579 | } |
580 | 580 | |
581 | 581 | /** |
@@ -588,8 +588,8 @@ discard block |
||
588 | 588 | * |
589 | 589 | * @return bool |
590 | 590 | */ |
591 | - private function filter_events_after( $event ) { |
|
592 | - return intval( $event ) < intval( $this->end ); |
|
591 | + private function filter_events_after($event) { |
|
592 | + return intval($event) < intval($this->end); |
|
593 | 593 | } |
594 | 594 | |
595 | 595 | } |
@@ -576,9 +576,11 @@ |
||
576 | 576 | |
577 | 577 | endforeach; |
578 | 578 | |
579 | - else : |
|
579 | + else { |
|
580 | + : |
|
580 | 581 | |
581 | 582 | echo "\t" . '<p>'; |
583 | + } |
|
582 | 584 | |
583 | 585 | $message = get_post_meta( $calendar->id, '_no_events_message', true ); |
584 | 586 |
@@ -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,123 +433,123 @@ 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 | - date_default_timezone_set( $calendar->timezone ); |
|
447 | + date_default_timezone_set($calendar->timezone); |
|
448 | 448 | |
449 | 449 | $now = $calendar->now; |
450 | - $current_events = $this->get_events( $timestamp ); |
|
451 | - $day_format = explode( ' ', $calendar->date_format ); |
|
450 | + $current_events = $this->get_events($timestamp); |
|
451 | + $day_format = explode(' ', $calendar->date_format); |
|
452 | 452 | |
453 | 453 | ob_start(); |
454 | 454 | |
455 | 455 | // Draw the events. |
456 | 456 | |
457 | - $block_tag = $calendar->compact_list && ! empty( $current_events ) ? 'div' : 'dl'; |
|
457 | + $block_tag = $calendar->compact_list && ! empty($current_events) ? 'div' : 'dl'; |
|
458 | 458 | |
459 | 459 | $data_heading = ''; |
460 | 460 | $heading = $this->get_heading(); |
461 | - foreach ( $heading as $k => $v ) { |
|
462 | - $data_heading .= ' data-heading-' . $k . '="' . $v . '"'; |
|
461 | + foreach ($heading as $k => $v) { |
|
462 | + $data_heading .= ' data-heading-'.$k.'="'.$v.'"'; |
|
463 | 463 | } |
464 | 464 | |
465 | - echo '<' . $block_tag . ' class="simcal-events-list-container"' . |
|
466 | - ' data-prev="' . $this->prev . '"' . |
|
467 | - ' data-next="' . $this->next . '"' . |
|
468 | - $data_heading . '>'; |
|
465 | + echo '<'.$block_tag.' class="simcal-events-list-container"'. |
|
466 | + ' data-prev="'.$this->prev.'"'. |
|
467 | + ' data-next="'.$this->next.'"'. |
|
468 | + $data_heading.'>'; |
|
469 | 469 | |
470 | - if ( ! empty( $current_events ) && is_array( $current_events ) ) : |
|
470 | + if ( ! empty($current_events) && is_array($current_events)) : |
|
471 | 471 | |
472 | - foreach ( $current_events as $ymd => $events ) : |
|
472 | + foreach ($current_events as $ymd => $events) : |
|
473 | 473 | |
474 | 474 | // This is where we can find out if an event is a multi-day event and if it needs to be shown. |
475 | 475 | // Since this is for list view we are showing the event on the day viewed if it is part of that day even when |
476 | 476 | // expand multi-day events are turned off. |
477 | - if ( isset( $events[0][0]->multiple_days ) && $events[0][0]->multiple_days > 0 ) { |
|
478 | - if ( 'current_day_only' == get_post_meta($calendar->id, '_default_calendar_expand_multi_day_events', true ) ) { |
|
477 | + if (isset($events[0][0]->multiple_days) && $events[0][0]->multiple_days > 0) { |
|
478 | + if ('current_day_only' == get_post_meta($calendar->id, '_default_calendar_expand_multi_day_events', true)) { |
|
479 | 479 | |
480 | - $year = substr( $ymd, 0, 4 ); |
|
481 | - $month = substr( $ymd, 4, 2 ); |
|
482 | - $day = substr( $ymd, 6, 2 ); |
|
480 | + $year = substr($ymd, 0, 4); |
|
481 | + $month = substr($ymd, 4, 2); |
|
482 | + $day = substr($ymd, 6, 2); |
|
483 | 483 | |
484 | - $temp_date = Carbon::createFromDate( $year, $month, $day ); |
|
484 | + $temp_date = Carbon::createFromDate($year, $month, $day); |
|
485 | 485 | |
486 | - if( ! ( $temp_date < Carbon::now()->endOfDay() ) ) { |
|
486 | + if ( ! ($temp_date < Carbon::now()->endOfDay())) { |
|
487 | 487 | continue; |
488 | 488 | } |
489 | 489 | } |
490 | 490 | } |
491 | 491 | |
492 | - $day_ts = Carbon::createFromFormat( 'Ymd', $ymd, $calendar->timezone )->getTimestamp(); |
|
492 | + $day_ts = Carbon::createFromFormat('Ymd', $ymd, $calendar->timezone)->getTimestamp(); |
|
493 | 493 | |
494 | - if ( ! $calendar->compact_list ) : |
|
494 | + if ( ! $calendar->compact_list) : |
|
495 | 495 | |
496 | - $date = new Carbon( 'now', $calendar->timezone ); |
|
497 | - $date->setLocale( substr( get_locale(), 0, 2 ) ); |
|
498 | - $date->setTimestamp( $day_ts ); |
|
496 | + $date = new Carbon('now', $calendar->timezone); |
|
497 | + $date->setLocale(substr(get_locale(), 0, 2)); |
|
498 | + $date->setTimestamp($day_ts); |
|
499 | 499 | |
500 | - if ( $date->isToday() ) { |
|
501 | - $the_color = new Color( $calendar->today_color ); |
|
500 | + if ($date->isToday()) { |
|
501 | + $the_color = new Color($calendar->today_color); |
|
502 | 502 | } else { |
503 | - $the_color = new Color( $calendar->days_events_color ); |
|
503 | + $the_color = new Color($calendar->days_events_color); |
|
504 | 504 | } |
505 | 505 | |
506 | - $bg_color = '#' . $the_color->getHex(); |
|
506 | + $bg_color = '#'.$the_color->getHex(); |
|
507 | 507 | $color = $the_color->isDark() ? '#ffffff' : '#000000'; |
508 | - $border_style = ' style="border-bottom: 1px solid ' . $bg_color . ';" '; |
|
509 | - $bg_style = ' style="background-color: ' . $bg_color . '; color: ' . $color . ';"'; |
|
508 | + $border_style = ' style="border-bottom: 1px solid '.$bg_color.';" '; |
|
509 | + $bg_style = ' style="background-color: '.$bg_color.'; color: '.$color.';"'; |
|
510 | 510 | |
511 | - echo "\t" . '<dt class="simcal-day-label"' . $border_style . '>'; |
|
512 | - echo '<span' . $bg_style .'>'; |
|
513 | - foreach ( $day_format as $format ) { |
|
514 | - echo $format ? '<span class="simcal-date-format" data-date-format="' . $format . '">' . date_i18n( $format, $day_ts ) . '</span> ' : ' '; |
|
511 | + echo "\t".'<dt class="simcal-day-label"'.$border_style.'>'; |
|
512 | + echo '<span'.$bg_style.'>'; |
|
513 | + foreach ($day_format as $format) { |
|
514 | + echo $format ? '<span class="simcal-date-format" data-date-format="'.$format.'">'.date_i18n($format, $day_ts).'</span> ' : ' '; |
|
515 | 515 | } |
516 | 516 | echo '</span>'; |
517 | - echo '</dt>' . "\n"; |
|
517 | + echo '</dt>'."\n"; |
|
518 | 518 | |
519 | 519 | endif; |
520 | 520 | |
521 | - $list_events = '<ul class="simcal-events">' . "\n"; |
|
521 | + $list_events = '<ul class="simcal-events">'."\n"; |
|
522 | 522 | |
523 | 523 | $calendar_classes = array(); |
524 | - $day_classes = 'simcal-weekday-' . date( 'w', $day_ts ); |
|
524 | + $day_classes = 'simcal-weekday-'.date('w', $day_ts); |
|
525 | 525 | |
526 | 526 | // Is this the present, the past or the future, Doc? |
527 | - if ( $timestamp <= $now && $timestamp >= $now ) { |
|
527 | + if ($timestamp <= $now && $timestamp >= $now) { |
|
528 | 528 | $day_classes .= ' simcal-today simcal-present simcal-day'; |
529 | - } elseif ( $timestamp < $now ) { |
|
529 | + } elseif ($timestamp < $now) { |
|
530 | 530 | $day_classes .= ' simcal-past simcal-day'; |
531 | - } elseif ( $this->end > $now ) { |
|
531 | + } elseif ($this->end > $now) { |
|
532 | 532 | $day_classes .= ' simcal-future simcal-day'; |
533 | 533 | } |
534 | 534 | |
535 | 535 | $count = 0; |
536 | 536 | |
537 | - foreach ( $events as $day_events ) : |
|
538 | - foreach ( $day_events as $event ) : |
|
539 | - if ( $event instanceof Event ) : |
|
537 | + foreach ($events as $day_events) : |
|
538 | + foreach ($day_events as $event) : |
|
539 | + if ($event instanceof Event) : |
|
540 | 540 | |
541 | 541 | $event_classes = $event_visibility = ''; |
542 | 542 | |
543 | - $calendar_class = 'simcal-events-calendar-' . strval( $event->calendar ); |
|
543 | + $calendar_class = 'simcal-events-calendar-'.strval($event->calendar); |
|
544 | 544 | $calendar_classes[] = $calendar_class; |
545 | 545 | |
546 | 546 | $recurring = $event->recurrence ? 'simcal-event-recurring ' : ''; |
547 | 547 | $has_location = $event->venue ? 'simcal-event-has-location ' : ''; |
548 | 548 | |
549 | - $event_classes .= 'simcal-event ' . $recurring . $has_location . $calendar_class; |
|
549 | + $event_classes .= 'simcal-event '.$recurring.$has_location.$calendar_class; |
|
550 | 550 | |
551 | 551 | // Toggle some events visibility if more than optional limit. |
552 | - if ( ( $calendar->events_limit > - 1 ) && ( $count >= $calendar->events_limit ) ) : |
|
552 | + if (($calendar->events_limit > - 1) && ($count >= $calendar->events_limit)) : |
|
553 | 553 | $event_classes .= ' simcal-event-toggled'; |
554 | 554 | $event_visibility = ' style="display: none"'; |
555 | 555 | endif; |
@@ -557,75 +557,75 @@ discard block |
||
557 | 557 | $event_color = ''; |
558 | 558 | $bullet = ''; |
559 | 559 | $event_color = $event->get_color(); |
560 | - if ( ! empty( $event_color ) ) { |
|
560 | + if ( ! empty($event_color)) { |
|
561 | 561 | $side = is_rtl() ? 'right' : 'left'; |
562 | - $event_color = ' style="border-' . $side . ': 4px solid ' . $event_color . '; padding-' . $side . ': 8px;"'; |
|
562 | + $event_color = ' style="border-'.$side.': 4px solid '.$event_color.'; padding-'.$side.': 8px;"'; |
|
563 | 563 | } |
564 | 564 | |
565 | - $list_events .= "\t" . '<li class="' . $event_classes . '"' . $event_visibility . $event_color . ' itemscope itemtype="http://schema.org/Event">' . "\n"; |
|
566 | - $list_events .= "\t\t" . '<div class="simcal-event-details">' . $calendar->get_event_html( $event ) . '</div>' . "\n"; |
|
567 | - $list_events .= "\t" . '</li>' . "\n"; |
|
565 | + $list_events .= "\t".'<li class="'.$event_classes.'"'.$event_visibility.$event_color.' itemscope itemtype="http://schema.org/Event">'."\n"; |
|
566 | + $list_events .= "\t\t".'<div class="simcal-event-details">'.$calendar->get_event_html($event).'</div>'."\n"; |
|
567 | + $list_events .= "\t".'</li>'."\n"; |
|
568 | 568 | |
569 | - $count ++; |
|
569 | + $count++; |
|
570 | 570 | |
571 | 571 | // Event falls within today. |
572 | - if ( ( $this->end <= $now ) && ( $this->start >= $now ) ) : |
|
572 | + if (($this->end <= $now) && ($this->start >= $now)) : |
|
573 | 573 | $day_classes .= ' simcal-today-has-events'; |
574 | 574 | endif; |
575 | - $day_classes .= ' simcal-day-has-events simcal-day-has-' . strval( $count ) . '-events'; |
|
575 | + $day_classes .= ' simcal-day-has-events simcal-day-has-'.strval($count).'-events'; |
|
576 | 576 | |
577 | - if ( $calendar_classes ) : |
|
578 | - $day_classes .= ' ' . trim( implode( ' ', array_unique( $calendar_classes ) ) ); |
|
577 | + if ($calendar_classes) : |
|
578 | + $day_classes .= ' '.trim(implode(' ', array_unique($calendar_classes))); |
|
579 | 579 | endif; |
580 | 580 | |
581 | 581 | endif; |
582 | 582 | endforeach; |
583 | 583 | endforeach; |
584 | 584 | |
585 | - $list_events .= '</ul>' . "\n"; |
|
585 | + $list_events .= '</ul>'."\n"; |
|
586 | 586 | |
587 | 587 | // If events visibility is limited, print the button toggle. |
588 | - if ( ( $calendar->events_limit > -1 ) && ( $count > $calendar->events_limit ) ) : |
|
588 | + if (($calendar->events_limit > -1) && ($count > $calendar->events_limit)) : |
|
589 | 589 | $list_events .= '<button class="simcal-events-toggle"><i class="simcal-icon-down simcal-icon-animate"></i></button>'; |
590 | 590 | endif; |
591 | 591 | |
592 | 592 | // Print final list of events for the current day. |
593 | 593 | $tag = $calendar->compact_list ? 'div' : 'dd'; |
594 | - echo '<' . $tag . ' class="' . $day_classes . '" data-events-count="' . strval( $count ) . '">' . "\n"; |
|
595 | - echo "\t" . $list_events . "\n"; |
|
596 | - echo '</' . $tag . '>' . "\n"; |
|
594 | + echo '<'.$tag.' class="'.$day_classes.'" data-events-count="'.strval($count).'">'."\n"; |
|
595 | + echo "\t".$list_events."\n"; |
|
596 | + echo '</'.$tag.'>'."\n"; |
|
597 | 597 | |
598 | 598 | endforeach; |
599 | 599 | |
600 | 600 | else : |
601 | 601 | |
602 | - echo "\t" . '<p>'; |
|
602 | + echo "\t".'<p>'; |
|
603 | 603 | |
604 | - $message = get_post_meta( $calendar->id, '_no_events_message', true ); |
|
604 | + $message = get_post_meta($calendar->id, '_no_events_message', true); |
|
605 | 605 | |
606 | - if ( 'events' == $calendar->group_type ) { |
|
607 | - echo ! empty( $message ) ? $message : __( 'Nothing to show.', 'google-calendar-events' ); |
|
606 | + if ('events' == $calendar->group_type) { |
|
607 | + echo ! empty($message) ? $message : __('Nothing to show.', 'google-calendar-events'); |
|
608 | 608 | } else { |
609 | - if ( ! empty( $message ) ) { |
|
609 | + if ( ! empty($message)) { |
|
610 | 610 | echo $message; |
611 | 611 | } else { |
612 | - $from = Carbon::createFromTimestamp( $this->start, $calendar->timezone )->getTimestamp(); |
|
613 | - $to = Carbon::createFromTimestamp( $this->end, $calendar->timezone )->getTimestamp(); |
|
614 | - echo apply_filters( 'simcal_no_events_message', sprintf( |
|
615 | - __( 'Nothing from %1$s to %2$s.', 'google-calendar-events' ), |
|
616 | - date_i18n( $calendar->date_format, $from ), |
|
617 | - date_i18n( $calendar->date_format, $to ) |
|
618 | - ), $calendar->id, $from, $to ); |
|
612 | + $from = Carbon::createFromTimestamp($this->start, $calendar->timezone)->getTimestamp(); |
|
613 | + $to = Carbon::createFromTimestamp($this->end, $calendar->timezone)->getTimestamp(); |
|
614 | + echo apply_filters('simcal_no_events_message', sprintf( |
|
615 | + __('Nothing from %1$s to %2$s.', 'google-calendar-events'), |
|
616 | + date_i18n($calendar->date_format, $from), |
|
617 | + date_i18n($calendar->date_format, $to) |
|
618 | + ), $calendar->id, $from, $to); |
|
619 | 619 | } |
620 | 620 | } |
621 | 621 | |
622 | - echo "\t" . '</p>' . "\n"; |
|
622 | + echo "\t".'</p>'."\n"; |
|
623 | 623 | |
624 | 624 | endif; |
625 | 625 | |
626 | - echo '</' . $block_tag . '>'; |
|
626 | + echo '</'.$block_tag.'>'; |
|
627 | 627 | |
628 | - date_default_timezone_set( $calendar->site_timezone ); |
|
628 | + date_default_timezone_set($calendar->site_timezone); |
|
629 | 629 | |
630 | 630 | return ob_get_clean(); |
631 | 631 | } |
@@ -637,16 +637,16 @@ discard block |
||
637 | 637 | */ |
638 | 638 | public function draw_list_ajax() { |
639 | 639 | |
640 | - if ( isset( $_POST['ts'] ) && isset( $_POST['id'] ) ) { |
|
640 | + if (isset($_POST['ts']) && isset($_POST['id'])) { |
|
641 | 641 | |
642 | - $ts = absint( $_POST['ts'] ); |
|
643 | - $id = absint( $_POST['id'] ); |
|
642 | + $ts = absint($_POST['ts']); |
|
643 | + $id = absint($_POST['id']); |
|
644 | 644 | |
645 | - wp_send_json_success( $this->draw_list( $ts, $id ) ); |
|
645 | + wp_send_json_success($this->draw_list($ts, $id)); |
|
646 | 646 | |
647 | 647 | } else { |
648 | 648 | |
649 | - wp_send_json_error( 'Missing arguments in default calendar list ajax request.' ); |
|
649 | + wp_send_json_error('Missing arguments in default calendar list ajax request.'); |
|
650 | 650 | |
651 | 651 | } |
652 | 652 | } |
@@ -661,8 +661,8 @@ discard block |
||
661 | 661 | * |
662 | 662 | * @return bool |
663 | 663 | */ |
664 | - private function filter_events_before( $event ) { |
|
665 | - return intval( $event ) >= intval( $this->start ); |
|
664 | + private function filter_events_before($event) { |
|
665 | + return intval($event) >= intval($this->start); |
|
666 | 666 | } |
667 | 667 | |
668 | 668 | /** |
@@ -675,8 +675,8 @@ discard block |
||
675 | 675 | * |
676 | 676 | * @return bool |
677 | 677 | */ |
678 | - private function filter_events_after( $event ) { |
|
679 | - return intval( $event ) < intval( $this->end ); |
|
678 | + private function filter_events_after($event) { |
|
679 | + return intval($event) < intval($this->end); |
|
680 | 680 | } |
681 | 681 | |
682 | 682 | } |
@@ -8,7 +8,7 @@ discard block |
||
8 | 8 | |
9 | 9 | use Carbon\Carbon; |
10 | 10 | |
11 | -if ( ! defined( 'ABSPATH' ) ) { |
|
11 | +if ( ! defined('ABSPATH')) { |
|
12 | 12 | exit; |
13 | 13 | } |
14 | 14 | |
@@ -45,9 +45,9 @@ discard block |
||
45 | 45 | * @param array $e Events. |
46 | 46 | * @param string|\DateTimeZone $tz Timezone. |
47 | 47 | */ |
48 | - public function __construct( $e = array(), $tz = 'UTC' ) { |
|
49 | - $this->set_events( $e ); |
|
50 | - $this->set_timezone( $tz ); |
|
48 | + public function __construct($e = array(), $tz = 'UTC') { |
|
49 | + $this->set_events($e); |
|
50 | + $this->set_timezone($tz); |
|
51 | 51 | } |
52 | 52 | |
53 | 53 | /** |
@@ -59,10 +59,10 @@ discard block |
||
59 | 59 | * |
60 | 60 | * @return array |
61 | 61 | */ |
62 | - public function get_events( $n = '' ) { |
|
63 | - if ( ! empty( $n ) && ! empty( $this->events ) ) { |
|
64 | - $length = absint( $n ); |
|
65 | - return array_slice( $this->events, 0, $length, true ); |
|
62 | + public function get_events($n = '') { |
|
63 | + if ( ! empty($n) && ! empty($this->events)) { |
|
64 | + $length = absint($n); |
|
65 | + return array_slice($this->events, 0, $length, true); |
|
66 | 66 | } |
67 | 67 | return $this->events; |
68 | 68 | } |
@@ -74,7 +74,7 @@ discard block |
||
74 | 74 | * |
75 | 75 | * @param array $ev Events. |
76 | 76 | */ |
77 | - public function set_events( array $ev ) { |
|
77 | + public function set_events(array $ev) { |
|
78 | 78 | $this->events = $ev; |
79 | 79 | } |
80 | 80 | |
@@ -87,11 +87,11 @@ discard block |
||
87 | 87 | * |
88 | 88 | * @return Events |
89 | 89 | */ |
90 | - public function set_timezone( $tz ) { |
|
91 | - if ( $tz instanceof \DateTimeZone ) { |
|
90 | + public function set_timezone($tz) { |
|
91 | + if ($tz instanceof \DateTimeZone) { |
|
92 | 92 | $tz = $tz->getName(); |
93 | 93 | } |
94 | - $this->timezone = simcal_esc_timezone( $tz, $this->timezone ); |
|
94 | + $this->timezone = simcal_esc_timezone($tz, $this->timezone); |
|
95 | 95 | return $this; |
96 | 96 | } |
97 | 97 | |
@@ -104,11 +104,11 @@ discard block |
||
104 | 104 | * |
105 | 105 | * @return Events |
106 | 106 | */ |
107 | - public function shift( $n ) { |
|
108 | - if ( ! empty( $this->events ) ) { |
|
109 | - $offset = intval( $n ); |
|
110 | - $length = count( $this->events ); |
|
111 | - $this->set_events( array_slice( $this->events, $offset, $length, true ) ); |
|
107 | + public function shift($n) { |
|
108 | + if ( ! empty($this->events)) { |
|
109 | + $offset = intval($n); |
|
110 | + $length = count($this->events); |
|
111 | + $this->set_events(array_slice($this->events, $offset, $length, true)); |
|
112 | 112 | } |
113 | 113 | return $this; |
114 | 114 | } |
@@ -121,7 +121,7 @@ discard block |
||
121 | 121 | * @return Events |
122 | 122 | */ |
123 | 123 | public function private_only() { |
124 | - $this->set_events( $this->filter_property( 'public', 'hide' ) ); |
|
124 | + $this->set_events($this->filter_property('public', 'hide')); |
|
125 | 125 | return $this; |
126 | 126 | } |
127 | 127 | |
@@ -133,7 +133,7 @@ discard block |
||
133 | 133 | * @return Events |
134 | 134 | */ |
135 | 135 | public function public_only() { |
136 | - $this->set_events( $this->filter_property( 'public', 'show' ) ); |
|
136 | + $this->set_events($this->filter_property('public', 'show')); |
|
137 | 137 | return $this; |
138 | 138 | } |
139 | 139 | |
@@ -145,7 +145,7 @@ discard block |
||
145 | 145 | * @return Events |
146 | 146 | */ |
147 | 147 | public function recurring() { |
148 | - $this->set_events( $this->filter_property( 'recurrence', 'show' ) ); |
|
148 | + $this->set_events($this->filter_property('recurrence', 'show')); |
|
149 | 149 | return $this; |
150 | 150 | } |
151 | 151 | |
@@ -157,7 +157,7 @@ discard block |
||
157 | 157 | * @return Events |
158 | 158 | */ |
159 | 159 | public function not_recurring() { |
160 | - $this->set_events( $this->filter_property( 'recurrence', 'hide' ) ); |
|
160 | + $this->set_events($this->filter_property('recurrence', 'hide')); |
|
161 | 161 | return $this; |
162 | 162 | } |
163 | 163 | |
@@ -169,7 +169,7 @@ discard block |
||
169 | 169 | * @return Events |
170 | 170 | */ |
171 | 171 | public function whole_day() { |
172 | - $this->set_events( $this->filter_property( 'whole_day', 'show' ) ); |
|
172 | + $this->set_events($this->filter_property('whole_day', 'show')); |
|
173 | 173 | return $this; |
174 | 174 | } |
175 | 175 | |
@@ -181,7 +181,7 @@ discard block |
||
181 | 181 | * @return Events |
182 | 182 | */ |
183 | 183 | public function not_whole_day() { |
184 | - $this->set_events( $this->filter_property( 'whole_day', 'hide' ) ); |
|
184 | + $this->set_events($this->filter_property('whole_day', 'hide')); |
|
185 | 185 | return $this; |
186 | 186 | } |
187 | 187 | |
@@ -193,7 +193,7 @@ discard block |
||
193 | 193 | * @return Events |
194 | 194 | */ |
195 | 195 | public function multi_day() { |
196 | - $this->set_events( $this->filter_property( 'multiple_days', 'show' ) ); |
|
196 | + $this->set_events($this->filter_property('multiple_days', 'show')); |
|
197 | 197 | return $this; |
198 | 198 | } |
199 | 199 | |
@@ -205,7 +205,7 @@ discard block |
||
205 | 205 | * @return Events |
206 | 206 | */ |
207 | 207 | public function single_day() { |
208 | - $this->set_events( $this->filter_property( 'multiple_days', 'hide' ) ); |
|
208 | + $this->set_events($this->filter_property('multiple_days', 'hide')); |
|
209 | 209 | return $this; |
210 | 210 | } |
211 | 211 | |
@@ -217,7 +217,7 @@ discard block |
||
217 | 217 | * @return Events |
218 | 218 | */ |
219 | 219 | public function with_location() { |
220 | - $this->set_events( $this->filter_property( 'venue', 'show' ) ); |
|
220 | + $this->set_events($this->filter_property('venue', 'show')); |
|
221 | 221 | return $this; |
222 | 222 | } |
223 | 223 | |
@@ -229,7 +229,7 @@ discard block |
||
229 | 229 | * @return Events |
230 | 230 | */ |
231 | 231 | public function without_location() { |
232 | - $this->set_events( $this->filter_property( 'venue', 'hide' ) ); |
|
232 | + $this->set_events($this->filter_property('venue', 'hide')); |
|
233 | 233 | return $this; |
234 | 234 | } |
235 | 235 | |
@@ -244,18 +244,18 @@ discard block |
||
244 | 244 | * |
245 | 245 | * @return array |
246 | 246 | */ |
247 | - private function filter_property( $property, $toggle ) { |
|
247 | + private function filter_property($property, $toggle) { |
|
248 | 248 | $filtered = array(); |
249 | - if ( ! empty( $this->events ) ) { |
|
250 | - foreach ( $this->events as $ts => $events ) { |
|
251 | - foreach ( $events as $event ) { |
|
252 | - if ( 'hide' == $toggle ) { |
|
253 | - if ( ! $event->$property ) { |
|
254 | - $filtered[ $ts ][] = $event; |
|
249 | + if ( ! empty($this->events)) { |
|
250 | + foreach ($this->events as $ts => $events) { |
|
251 | + foreach ($events as $event) { |
|
252 | + if ('hide' == $toggle) { |
|
253 | + if ( ! $event->$property) { |
|
254 | + $filtered[$ts][] = $event; |
|
255 | 255 | } |
256 | - } elseif ( 'show' == $toggle ) { |
|
257 | - if ( $event->$property ) { |
|
258 | - $filtered[ $ts ][] = $event; |
|
256 | + } elseif ('show' == $toggle) { |
|
257 | + if ($event->$property) { |
|
258 | + $filtered[$ts][] = $event; |
|
259 | 259 | } |
260 | 260 | } |
261 | 261 | } |
@@ -273,14 +273,14 @@ discard block |
||
273 | 273 | * |
274 | 274 | * @return Events |
275 | 275 | */ |
276 | - public function future( $present = '' ) { |
|
276 | + public function future($present = '') { |
|
277 | 277 | $last = $this->get_last(); |
278 | 278 | $to = $last instanceof Event ? $last->start_utc : false; |
279 | - if ( $to ) { |
|
280 | - if ( empty( $present ) ) { |
|
281 | - $present = Carbon::now( $this->timezone )->getTimestamp(); |
|
279 | + if ($to) { |
|
280 | + if (empty($present)) { |
|
281 | + $present = Carbon::now($this->timezone)->getTimestamp(); |
|
282 | 282 | } |
283 | - $this->set_events( $this->filter_events( intval( $present ), $to ) ); |
|
283 | + $this->set_events($this->filter_events(intval($present), $to)); |
|
284 | 284 | } |
285 | 285 | return $this; |
286 | 286 | } |
@@ -294,14 +294,14 @@ discard block |
||
294 | 294 | * |
295 | 295 | * @return Events |
296 | 296 | */ |
297 | - public function past( $present = '' ) { |
|
297 | + public function past($present = '') { |
|
298 | 298 | $first = $this->get_last(); |
299 | 299 | $from = $first instanceof Event ? $first->start_utc : false; |
300 | - if ( $from ) { |
|
301 | - if ( empty( $present ) ) { |
|
302 | - $present = Carbon::now( $this->timezone )->getTimestamp(); |
|
300 | + if ($from) { |
|
301 | + if (empty($present)) { |
|
302 | + $present = Carbon::now($this->timezone)->getTimestamp(); |
|
303 | 303 | } |
304 | - $this->set_events( $this->filter_events( $from, intval( $present ) ) ); |
|
304 | + $this->set_events($this->filter_events($from, intval($present))); |
|
305 | 305 | } |
306 | 306 | return $this; |
307 | 307 | } |
@@ -315,9 +315,9 @@ discard block |
||
315 | 315 | * |
316 | 316 | * @return Events |
317 | 317 | */ |
318 | - public function after( $time ) { |
|
319 | - $dt = $this->parse( $time ); |
|
320 | - return ! is_null( $dt ) ? $this->future( $dt->getTimestamp() ) : $this; |
|
318 | + public function after($time) { |
|
319 | + $dt = $this->parse($time); |
|
320 | + return ! is_null($dt) ? $this->future($dt->getTimestamp()) : $this; |
|
321 | 321 | } |
322 | 322 | |
323 | 323 | /** |
@@ -329,9 +329,9 @@ discard block |
||
329 | 329 | * |
330 | 330 | * @return Events |
331 | 331 | */ |
332 | - public function before( $time ) { |
|
333 | - $dt = $this->parse( $time ); |
|
334 | - return ! is_null( $dt ) ? $this->past( $dt->getTimestamp() ) : $this; |
|
332 | + public function before($time) { |
|
333 | + $dt = $this->parse($time); |
|
334 | + return ! is_null($dt) ? $this->past($dt->getTimestamp()) : $this; |
|
335 | 335 | } |
336 | 336 | |
337 | 337 | /** |
@@ -343,10 +343,10 @@ discard block |
||
343 | 343 | * |
344 | 344 | * @return Events |
345 | 345 | */ |
346 | - public function from( $time ) { |
|
347 | - $last = $this->parse( $time ); |
|
348 | - if ( ! is_null( $last ) ) { |
|
349 | - $this->set_events( $this->filter_events( $time, $last->getTimestamp() ) ); |
|
346 | + public function from($time) { |
|
347 | + $last = $this->parse($time); |
|
348 | + if ( ! is_null($last)) { |
|
349 | + $this->set_events($this->filter_events($time, $last->getTimestamp())); |
|
350 | 350 | } |
351 | 351 | return $this; |
352 | 352 | } |
@@ -360,10 +360,10 @@ discard block |
||
360 | 360 | * |
361 | 361 | * @return Events |
362 | 362 | */ |
363 | - public function to( $time ) { |
|
364 | - $first = $this->parse( $time ); |
|
365 | - if ( ! is_null( $first ) ) { |
|
366 | - $this->set_events( $this->filter_events( $first->getTimestamp(), $time ) ); |
|
363 | + public function to($time) { |
|
364 | + $first = $this->parse($time); |
|
365 | + if ( ! is_null($first)) { |
|
366 | + $this->set_events($this->filter_events($first->getTimestamp(), $time)); |
|
367 | 367 | } |
368 | 368 | return $this; |
369 | 369 | } |
@@ -377,15 +377,15 @@ discard block |
||
377 | 377 | * |
378 | 378 | * @return null|Carbon |
379 | 379 | */ |
380 | - private function parse( $time ) { |
|
381 | - if ( is_int( $time ) ) { |
|
382 | - return Carbon::createFromTimestamp( $time, $this->timezone ); |
|
383 | - } elseif ( is_string( $time ) && ! empty( $time ) ) { |
|
384 | - return Carbon::parse( $time, $this->timezone ); |
|
385 | - } elseif ( $time instanceof Carbon ) { |
|
386 | - return $time->setTimezone( $this->timezone ); |
|
387 | - } elseif ( $time instanceof \DateTime ) { |
|
388 | - return Carbon::instance( $time )->setTimezone( $this->timezone ); |
|
380 | + private function parse($time) { |
|
381 | + if (is_int($time)) { |
|
382 | + return Carbon::createFromTimestamp($time, $this->timezone); |
|
383 | + } elseif (is_string($time) && ! empty($time)) { |
|
384 | + return Carbon::parse($time, $this->timezone); |
|
385 | + } elseif ($time instanceof Carbon) { |
|
386 | + return $time->setTimezone($this->timezone); |
|
387 | + } elseif ($time instanceof \DateTime) { |
|
388 | + return Carbon::instance($time)->setTimezone($this->timezone); |
|
389 | 389 | } |
390 | 390 | return null; |
391 | 391 | } |
@@ -398,7 +398,7 @@ discard block |
||
398 | 398 | * @return null|Event |
399 | 399 | */ |
400 | 400 | public function get_first() { |
401 | - return array_shift( $this->events ); |
|
401 | + return array_shift($this->events); |
|
402 | 402 | } |
403 | 403 | |
404 | 404 | /** |
@@ -409,7 +409,7 @@ discard block |
||
409 | 409 | * @return null|Event |
410 | 410 | */ |
411 | 411 | public function get_last() { |
412 | - return array_pop( $this->events ); |
|
412 | + return array_pop($this->events); |
|
413 | 413 | } |
414 | 414 | |
415 | 415 | /** |
@@ -420,7 +420,7 @@ discard block |
||
420 | 420 | * @return null|Event |
421 | 421 | */ |
422 | 422 | public function get_upcoming() { |
423 | - return $this->get_closest( 'future' ); |
|
423 | + return $this->get_closest('future'); |
|
424 | 424 | } |
425 | 425 | |
426 | 426 | /** |
@@ -431,7 +431,7 @@ discard block |
||
431 | 431 | * @return null|Event |
432 | 432 | */ |
433 | 433 | public function get_latest() { |
434 | - return $this->get_closest( 'past' ); |
|
434 | + return $this->get_closest('past'); |
|
435 | 435 | } |
436 | 436 | |
437 | 437 | /** |
@@ -444,11 +444,11 @@ discard block |
||
444 | 444 | * |
445 | 445 | * @return null|Event |
446 | 446 | */ |
447 | - private function get_closest( $dir ) { |
|
448 | - if ( 'future' == $dir ) { |
|
449 | - return array_shift( $this->future()->get_events() ); |
|
450 | - } elseif ( 'past' == $dir ) { |
|
451 | - return array_shift( $this->past()->get_events() ); |
|
447 | + private function get_closest($dir) { |
|
448 | + if ('future' == $dir) { |
|
449 | + return array_shift($this->future()->get_events()); |
|
450 | + } elseif ('past' == $dir) { |
|
451 | + return array_shift($this->past()->get_events()); |
|
452 | 452 | } |
453 | 453 | return null; |
454 | 454 | } |
@@ -462,11 +462,11 @@ discard block |
||
462 | 462 | * |
463 | 463 | * @return array Multidimensional array with month number, week number and Event objects for each weekday. |
464 | 464 | */ |
465 | - public function get_year( $year ) { |
|
466 | - $y = intval( $year ); |
|
465 | + public function get_year($year) { |
|
466 | + $y = intval($year); |
|
467 | 467 | $months = array(); |
468 | - for ( $m = 1; $m <= 12; $m++ ) { |
|
469 | - $months[ strval( $m ) ] = $this->get_month( $y, $m ); |
|
468 | + for ($m = 1; $m <= 12; $m++) { |
|
469 | + $months[strval($m)] = $this->get_month($y, $m); |
|
470 | 470 | } |
471 | 471 | return $months; |
472 | 472 | } |
@@ -481,16 +481,16 @@ discard block |
||
481 | 481 | * |
482 | 482 | * @return array Multidimensional array with week number, day of the week and array of Event objects for each week day. |
483 | 483 | */ |
484 | - public function get_month( $year, $month ) { |
|
485 | - $y = intval( $year ); |
|
486 | - $m = min( max( 1, absint( $month ) ), 12 ); |
|
487 | - $days = Carbon::createFromDate( $y, $m, 2, $this->timezone )->startOfMonth()->daysInMonth; |
|
484 | + public function get_month($year, $month) { |
|
485 | + $y = intval($year); |
|
486 | + $m = min(max(1, absint($month)), 12); |
|
487 | + $days = Carbon::createFromDate($y, $m, 2, $this->timezone)->startOfMonth()->daysInMonth; |
|
488 | 488 | $weeks = array(); |
489 | - for ( $d = 1; $d < $days; $d++ ) { |
|
490 | - $current = Carbon::createFromDate( $y, $m, $d ); |
|
489 | + for ($d = 1; $d < $days; $d++) { |
|
490 | + $current = Carbon::createFromDate($y, $m, $d); |
|
491 | 491 | $week = $current->weekOfYear; |
492 | 492 | $day = $current->dayOfWeek; |
493 | - $weeks[ strval( $week ) ][ strval( $day ) ] = $this->get_day( $y, $m, $d ); |
|
493 | + $weeks[strval($week)][strval($day)] = $this->get_day($y, $m, $d); |
|
494 | 494 | } |
495 | 495 | return $weeks; |
496 | 496 | } |
@@ -505,16 +505,16 @@ discard block |
||
505 | 505 | * |
506 | 506 | * @return array Associative array with day of the week for key and array of Event objects for value. |
507 | 507 | */ |
508 | - public function get_week( $year, $week ) { |
|
509 | - $y = intval( $year ); |
|
510 | - $w = absint( $week ); |
|
511 | - $m = date( 'n', strtotime( strval( $y ) . '-W' . strval( $w ) ) ); |
|
512 | - $month_dt = Carbon::createFromDate( $y, $m, 2, $this->timezone ); |
|
508 | + public function get_week($year, $week) { |
|
509 | + $y = intval($year); |
|
510 | + $w = absint($week); |
|
511 | + $m = date('n', strtotime(strval($y).'-W'.strval($w))); |
|
512 | + $month_dt = Carbon::createFromDate($y, $m, 2, $this->timezone); |
|
513 | 513 | $days = array(); |
514 | - for ( $d = 1; $d < $month_dt->daysInMonth; $d++ ) { |
|
515 | - $current = Carbon::createFromDate( $y, $m, $d ); |
|
516 | - if ( $w == $current->weekOfYear ) { |
|
517 | - $days[ strval( $current->dayOfWeek ) ] = $this->get_day( $y, $m, $d ); |
|
514 | + for ($d = 1; $d < $month_dt->daysInMonth; $d++) { |
|
515 | + $current = Carbon::createFromDate($y, $m, $d); |
|
516 | + if ($w == $current->weekOfYear) { |
|
517 | + $days[strval($current->dayOfWeek)] = $this->get_day($y, $m, $d); |
|
518 | 518 | } |
519 | 519 | } |
520 | 520 | return $days; |
@@ -531,13 +531,13 @@ discard block |
||
531 | 531 | * |
532 | 532 | * @return array Event objects for the day. |
533 | 533 | */ |
534 | - public function get_day( $year, $month, $day ) { |
|
535 | - $y = intval( $year ); |
|
536 | - $m = min( max( 1, absint( $month ) ), 12 ); |
|
537 | - $d = min( absint( $day ), 31 ); |
|
538 | - $from = Carbon::createFromDate( $y, $m, $d, $this->timezone )->startOfDay()->getTimestamp(); |
|
539 | - $to = Carbon::createFromDate( $y, $m, $d, $this->timezone )->endOfDay()->getTimestamp(); |
|
540 | - return $this->filter_events( $from, $to ); |
|
534 | + public function get_day($year, $month, $day) { |
|
535 | + $y = intval($year); |
|
536 | + $m = min(max(1, absint($month)), 12); |
|
537 | + $d = min(absint($day), 31); |
|
538 | + $from = Carbon::createFromDate($y, $m, $d, $this->timezone)->startOfDay()->getTimestamp(); |
|
539 | + $to = Carbon::createFromDate($y, $m, $d, $this->timezone)->endOfDay()->getTimestamp(); |
|
540 | + return $this->filter_events($from, $to); |
|
541 | 541 | } |
542 | 542 | |
543 | 543 | /** |
@@ -548,9 +548,9 @@ discard block |
||
548 | 548 | * @return array Event objects for today. |
549 | 549 | */ |
550 | 550 | public function get_today() { |
551 | - $start = Carbon::today( $this->timezone )->startOfDay()->getTimestamp(); |
|
552 | - $end = Carbon::today( $this->timezone )->endOfDay()->getTimestamp(); |
|
553 | - return $this->filter_events( $start, $end ); |
|
551 | + $start = Carbon::today($this->timezone)->startOfDay()->getTimestamp(); |
|
552 | + $end = Carbon::today($this->timezone)->endOfDay()->getTimestamp(); |
|
553 | + return $this->filter_events($start, $end); |
|
554 | 554 | } |
555 | 555 | |
556 | 556 | /** |
@@ -561,9 +561,9 @@ discard block |
||
561 | 561 | * @return array Event objects for tomorrow. |
562 | 562 | */ |
563 | 563 | public function get_tomorrow() { |
564 | - $start = Carbon::tomorrow( $this->timezone )->startOfDay()->getTimestamp(); |
|
565 | - $end = Carbon::tomorrow( $this->timezone )->endOfDay()->getTimestamp(); |
|
566 | - return $this->filter_events( $start, $end ); |
|
564 | + $start = Carbon::tomorrow($this->timezone)->startOfDay()->getTimestamp(); |
|
565 | + $end = Carbon::tomorrow($this->timezone)->endOfDay()->getTimestamp(); |
|
566 | + return $this->filter_events($start, $end); |
|
567 | 567 | } |
568 | 568 | |
569 | 569 | /** |
@@ -574,9 +574,9 @@ discard block |
||
574 | 574 | * @return array Event objects for yesterday. |
575 | 575 | */ |
576 | 576 | public function get_yesterday() { |
577 | - $start = Carbon::yesterday( $this->timezone )->startOfDay()->getTimestamp(); |
|
578 | - $end = Carbon::yesterday( $this->timezone )->endOfDay()->getTimestamp(); |
|
579 | - return $this->filter_events( $start, $end ); |
|
577 | + $start = Carbon::yesterday($this->timezone)->startOfDay()->getTimestamp(); |
|
578 | + $end = Carbon::yesterday($this->timezone)->endOfDay()->getTimestamp(); |
|
579 | + return $this->filter_events($start, $end); |
|
580 | 580 | } |
581 | 581 | |
582 | 582 | /** |
@@ -590,16 +590,16 @@ discard block |
||
590 | 590 | * |
591 | 591 | * @return array Filtered array of Event objects. |
592 | 592 | */ |
593 | - private function filter_events( $from, $to ) { |
|
594 | - $timestamps = array_keys( $this->events ); |
|
595 | - $lower_bound = array_filter( $timestamps, function( $ts ) use( $from ) { |
|
596 | - return intval( $ts ) > intval( $from ); |
|
593 | + private function filter_events($from, $to) { |
|
594 | + $timestamps = array_keys($this->events); |
|
595 | + $lower_bound = array_filter($timestamps, function($ts) use($from) { |
|
596 | + return intval($ts) > intval($from); |
|
597 | 597 | } ); |
598 | - $higher_bound = array_filter( $lower_bound, function( $ts ) use( $to ) { |
|
599 | - return intval( $ts ) > intval( $to ); |
|
598 | + $higher_bound = array_filter($lower_bound, function($ts) use($to) { |
|
599 | + return intval($ts) > intval($to); |
|
600 | 600 | } ); |
601 | - $filtered = array_combine( $higher_bound, $higher_bound ); |
|
602 | - return array_intersect_key( $this->events, $filtered ); |
|
601 | + $filtered = array_combine($higher_bound, $higher_bound); |
|
602 | + return array_intersect_key($this->events, $filtered); |
|
603 | 603 | } |
604 | 604 | |
605 | 605 | } |
@@ -8,7 +8,7 @@ discard block |
||
8 | 8 | |
9 | 9 | use SimpleCalendar\Feeds\Grouped_Calendars; |
10 | 10 | |
11 | -if ( ! defined( 'ABSPATH' ) ) { |
|
11 | +if ( ! defined('ABSPATH')) { |
|
12 | 12 | exit; |
13 | 13 | } |
14 | 14 | |
@@ -34,15 +34,15 @@ discard block |
||
34 | 34 | * |
35 | 35 | * @param Grouped_Calendars $feed |
36 | 36 | */ |
37 | - public function __construct( Grouped_Calendars $feed ) { |
|
37 | + public function __construct(Grouped_Calendars $feed) { |
|
38 | 38 | |
39 | 39 | $this->feed = $feed; |
40 | 40 | |
41 | - if ( 'calendar' == simcal_is_admin_screen() ) { |
|
42 | - add_filter( 'simcal_settings_meta_tabs_li', array( $this, 'add_settings_meta_tab_li' ), 10, 1 ); |
|
43 | - add_action( 'simcal_settings_meta_panels', array( $this, 'add_settings_meta_panel' ), 10, 1 ); |
|
41 | + if ('calendar' == simcal_is_admin_screen()) { |
|
42 | + add_filter('simcal_settings_meta_tabs_li', array($this, 'add_settings_meta_tab_li'), 10, 1); |
|
43 | + add_action('simcal_settings_meta_panels', array($this, 'add_settings_meta_panel'), 10, 1); |
|
44 | 44 | } |
45 | - add_action( 'simcal_process_settings_meta', array( $this, 'process_meta' ), 10, 1 ); |
|
45 | + add_action('simcal_process_settings_meta', array($this, 'process_meta'), 10, 1); |
|
46 | 46 | } |
47 | 47 | |
48 | 48 | /** |
@@ -54,8 +54,8 @@ discard block |
||
54 | 54 | * |
55 | 55 | * @return array |
56 | 56 | */ |
57 | - public function add_settings_meta_tab_li( $tabs ) { |
|
58 | - return array_merge( $tabs, array( |
|
57 | + public function add_settings_meta_tab_li($tabs) { |
|
58 | + return array_merge($tabs, array( |
|
59 | 59 | 'grouped-calendars' => array( |
60 | 60 | 'label' => $this->feed->name, |
61 | 61 | 'target' => 'grouped-calendars-settings-panel', |
@@ -75,40 +75,40 @@ discard block |
||
75 | 75 | * |
76 | 76 | * @param int $post_id |
77 | 77 | */ |
78 | - public function add_settings_meta_panel( $post_id ) { |
|
78 | + public function add_settings_meta_panel($post_id) { |
|
79 | 79 | |
80 | 80 | ?> |
81 | 81 | <div id="grouped-calendars-settings-panel" class="simcal-panel"> |
82 | 82 | <table> |
83 | 83 | <thead> |
84 | - <tr><th colspan="2"><?php _e( 'Grouped Calendar settings', 'google-calendar-events' ); ?></th></tr> |
|
84 | + <tr><th colspan="2"><?php _e('Grouped Calendar settings', 'google-calendar-events'); ?></th></tr> |
|
85 | 85 | </thead> |
86 | 86 | <tbody class="simcal-panel-section"> |
87 | 87 | <tr class="simcal-panel-field"> |
88 | - <th><label for="_grouped_calendars_source"><?php _e( 'Get calendars from', 'google-calendar-events' ); ?></label></th> |
|
88 | + <th><label for="_grouped_calendars_source"><?php _e('Get calendars from', 'google-calendar-events'); ?></label></th> |
|
89 | 89 | <td> |
90 | 90 | <?php |
91 | 91 | |
92 | - $source = esc_attr( get_post_meta( $post_id, '_grouped_calendars_source', true ) ); |
|
93 | - $source = empty( $source ) ? 'ids' : $source; |
|
92 | + $source = esc_attr(get_post_meta($post_id, '_grouped_calendars_source', true)); |
|
93 | + $source = empty($source) ? 'ids' : $source; |
|
94 | 94 | |
95 | 95 | ?> |
96 | 96 | <select name="_grouped_calendars_source" |
97 | 97 | id="_grouped_calendars_source" |
98 | 98 | class="simcal-field simcal-field-select simcal-field-inline simcal-field-show-other" |
99 | 99 | data-show-field-on-choice="true"> |
100 | - <option value="ids" data-show-field="_grouped_calendars_ids" <?php selected( 'ids', $source, true ); ?>><?php _e( 'Manual selection', 'google-calendar-events' ); ?></option> |
|
101 | - <option value="category" data-show-field="_grouped_calendars_category" <?php selected( 'category', $source, true ); ?>><?php _e( 'Category', 'google-calendar-events' ); ?></option> |
|
100 | + <option value="ids" data-show-field="_grouped_calendars_ids" <?php selected('ids', $source, true); ?>><?php _e('Manual selection', 'google-calendar-events'); ?></option> |
|
101 | + <option value="category" data-show-field="_grouped_calendars_category" <?php selected('category', $source, true); ?>><?php _e('Category', 'google-calendar-events'); ?></option> |
|
102 | 102 | </select> |
103 | - <i class="simcal-icon-help simcal-help-tip" data-tip="<?php _e( 'Choose from which calendar feeds you want to get events from. Choose them individually or select all those belonging to calendar feed categories.', 'google-calendar-events' ); ?>"></i> |
|
103 | + <i class="simcal-icon-help simcal-help-tip" data-tip="<?php _e('Choose from which calendar feeds you want to get events from. Choose them individually or select all those belonging to calendar feed categories.', 'google-calendar-events'); ?>"></i> |
|
104 | 104 | <br><br> |
105 | 105 | <?php |
106 | 106 | |
107 | - $cals = simcal_get_calendars( $post_id ); |
|
108 | - $meta = get_post_meta( $post_id, '_grouped_calendars_ids', true ); |
|
109 | - $ids = $meta && is_array( $meta ) ? implode( ',', array_map( 'absint', $meta ) ) : absint( $meta ); |
|
107 | + $cals = simcal_get_calendars($post_id); |
|
108 | + $meta = get_post_meta($post_id, '_grouped_calendars_ids', true); |
|
109 | + $ids = $meta && is_array($meta) ? implode(',', array_map('absint', $meta)) : absint($meta); |
|
110 | 110 | |
111 | - simcal_print_field( array( |
|
111 | + simcal_print_field(array( |
|
112 | 112 | 'type' => 'select', |
113 | 113 | 'multiselect' => 'multiselect', |
114 | 114 | 'name' => '_grouped_calendars_ids', |
@@ -116,25 +116,25 @@ discard block |
||
116 | 116 | 'value' => $ids !== 0 ? $ids : '', |
117 | 117 | 'options' => $cals, |
118 | 118 | 'enhanced' => 'enhanced', |
119 | - 'style' => 'ids' == $source ? '' : array( 'display' => 'none' ), |
|
119 | + 'style' => 'ids' == $source ? '' : array('display' => 'none'), |
|
120 | 120 | 'attributes' => array( |
121 | - 'data-noresults' => __( 'No results found.', 'google-calendar-events' ), |
|
121 | + 'data-noresults' => __('No results found.', 'google-calendar-events'), |
|
122 | 122 | ), |
123 | 123 | )); |
124 | 124 | |
125 | - $meta = get_post_meta( $post_id, '_grouped_calendars_category', true ); |
|
126 | - $category = $meta && is_array( $meta ) ? implode( ',', array_map( 'absint', $meta ) ): ''; |
|
125 | + $meta = get_post_meta($post_id, '_grouped_calendars_category', true); |
|
126 | + $category = $meta && is_array($meta) ? implode(',', array_map('absint', $meta)) : ''; |
|
127 | 127 | |
128 | - $terms = get_terms( 'calendar_category' ); |
|
128 | + $terms = get_terms('calendar_category'); |
|
129 | 129 | |
130 | - if ( ! empty( $terms ) ) { |
|
130 | + if ( ! empty($terms)) { |
|
131 | 131 | |
132 | 132 | $categories = array(); |
133 | - foreach ( $terms as $term ) { |
|
134 | - $categories[ $term->term_id ] = $term->name; |
|
133 | + foreach ($terms as $term) { |
|
134 | + $categories[$term->term_id] = $term->name; |
|
135 | 135 | } |
136 | 136 | |
137 | - simcal_print_field( array( |
|
137 | + simcal_print_field(array( |
|
138 | 138 | 'type' => 'select', |
139 | 139 | 'multiselect' => 'multiselect', |
140 | 140 | 'name' => '_grouped_calendars_category', |
@@ -142,17 +142,17 @@ discard block |
||
142 | 142 | 'value' => $category, |
143 | 143 | 'options' => $categories, |
144 | 144 | 'enhanced' => 'enhanced', |
145 | - 'style' => 'category' == $source ? '' : array( 'display' => 'none' ), |
|
145 | + 'style' => 'category' == $source ? '' : array('display' => 'none'), |
|
146 | 146 | 'attributes' => array( |
147 | - 'data-noresults' => __( 'No results found.', 'google-calendar-events' ), |
|
147 | + 'data-noresults' => __('No results found.', 'google-calendar-events'), |
|
148 | 148 | ), |
149 | - ) ); |
|
149 | + )); |
|
150 | 150 | |
151 | 151 | } else { |
152 | 152 | |
153 | 153 | $style = 'category' == $source ? '' : 'display: none;'; |
154 | 154 | $style .= ' width: 100%; max-width: 500px'; |
155 | - echo '<input type="text" disabled="disabled" name="_grouped_calendars_category" id="_grouped_calendars_category" style="' . $style . '" placeholder="' . __( 'There are no calendar categories yet.', 'google-calendar-events' ) . '" />'; |
|
155 | + echo '<input type="text" disabled="disabled" name="_grouped_calendars_category" id="_grouped_calendars_category" style="'.$style.'" placeholder="'.__('There are no calendar categories yet.', 'google-calendar-events').'" />'; |
|
156 | 156 | |
157 | 157 | } |
158 | 158 | |
@@ -173,16 +173,16 @@ discard block |
||
173 | 173 | * |
174 | 174 | * @param int $post_id |
175 | 175 | */ |
176 | - public function process_meta( $post_id ) { |
|
176 | + public function process_meta($post_id) { |
|
177 | 177 | |
178 | - $source = isset( $_POST['_grouped_calendars_source'] ) ? sanitize_key( $_POST['_grouped_calendars_source'] ) : 'ids'; |
|
179 | - update_post_meta( $post_id, '_grouped_calendars_source', $source ); |
|
178 | + $source = isset($_POST['_grouped_calendars_source']) ? sanitize_key($_POST['_grouped_calendars_source']) : 'ids'; |
|
179 | + update_post_meta($post_id, '_grouped_calendars_source', $source); |
|
180 | 180 | |
181 | - $ids = isset( $_POST['_grouped_calendars_ids'] ) ? array_map( 'absint', $_POST['_grouped_calendars_ids'] ) : ''; |
|
182 | - update_post_meta( $post_id, '_grouped_calendars_ids', $ids ); |
|
181 | + $ids = isset($_POST['_grouped_calendars_ids']) ? array_map('absint', $_POST['_grouped_calendars_ids']) : ''; |
|
182 | + update_post_meta($post_id, '_grouped_calendars_ids', $ids); |
|
183 | 183 | |
184 | - $category = isset( $_POST['_grouped_calendars_category'] ) ? array_map( 'absint', $_POST['_grouped_calendars_category'] ) : ''; |
|
185 | - update_post_meta( $post_id, '_grouped_calendars_category', $category ); |
|
184 | + $category = isset($_POST['_grouped_calendars_category']) ? array_map('absint', $_POST['_grouped_calendars_category']) : ''; |
|
185 | + update_post_meta($post_id, '_grouped_calendars_category', $category); |
|
186 | 186 | |
187 | 187 | } |
188 | 188 |
@@ -8,7 +8,7 @@ discard block |
||
8 | 8 | * @deprecated |
9 | 9 | */ |
10 | 10 | |
11 | -if ( ! defined( 'ABSPATH' ) ) { |
|
11 | +if ( ! defined('ABSPATH')) { |
|
12 | 12 | exit; |
13 | 13 | } |
14 | 14 | |
@@ -16,18 +16,18 @@ discard block |
||
16 | 16 | * Print a calendar. |
17 | 17 | * @deprecated Use simcal_print_calendar() |
18 | 18 | */ |
19 | -function gce_print_calendar( $feed_ids, $display, $args ) { |
|
19 | +function gce_print_calendar($feed_ids, $display, $args) { |
|
20 | 20 | |
21 | 21 | $id = 0; |
22 | 22 | |
23 | - if ( is_numeric( $feed_ids ) ) { |
|
24 | - $id = intval( $feed_ids ); |
|
25 | - } elseif ( is_array( $feed_ids ) ) { |
|
26 | - $id = isset( $feed_ids[0] ) ? intval( $feed_ids[0] ) : ''; |
|
23 | + if (is_numeric($feed_ids)) { |
|
24 | + $id = intval($feed_ids); |
|
25 | + } elseif (is_array($feed_ids)) { |
|
26 | + $id = isset($feed_ids[0]) ? intval($feed_ids[0]) : ''; |
|
27 | 27 | } |
28 | 28 | |
29 | - if ( $id > 0 ) { |
|
30 | - simcal_print_calendar( $id ); |
|
29 | + if ($id > 0) { |
|
30 | + simcal_print_calendar($id); |
|
31 | 31 | } |
32 | 32 | } |
33 | 33 | |
@@ -35,16 +35,16 @@ discard block |
||
35 | 35 | * Convert date from mm/dd/yyyy to unix timestamp. |
36 | 36 | * @deprecated Assumes a US-only time format. |
37 | 37 | */ |
38 | -function gce_date_unix( $date = '' ) { |
|
39 | - if ( empty( $date ) ) { |
|
40 | - $current_time = current_time( 'timestamp' ); |
|
41 | - $timestamp = mktime( 0, 0, 0, date( 'm', $current_time ), date( 'd', $current_time ), date( 'Y', $current_time ) ); |
|
38 | +function gce_date_unix($date = '') { |
|
39 | + if (empty($date)) { |
|
40 | + $current_time = current_time('timestamp'); |
|
41 | + $timestamp = mktime(0, 0, 0, date('m', $current_time), date('d', $current_time), date('Y', $current_time)); |
|
42 | 42 | } else { |
43 | - $date = explode( '/', $date ); |
|
43 | + $date = explode('/', $date); |
|
44 | 44 | $month = $date[0]; |
45 | 45 | $day = $date[1]; |
46 | 46 | $year = $date[2]; |
47 | - $timestamp = mktime( 0, 0, 0, $month, $day, $year ); |
|
47 | + $timestamp = mktime(0, 0, 0, $month, $day, $year); |
|
48 | 48 | } |
49 | 49 | return $timestamp; |
50 | 50 | } |
@@ -1,11 +1,11 @@ |
||
1 | 1 | <?php |
2 | 2 | /** |
3 | - * Shared functions |
|
4 | - * |
|
5 | - * Functions shared by both back end and front end components. |
|
6 | - * |
|
7 | - * @package SimpleCalendar/Functions |
|
8 | - */ |
|
3 | + * Shared functions |
|
4 | + * |
|
5 | + * Functions shared by both back end and front end components. |
|
6 | + * |
|
7 | + * @package SimpleCalendar/Functions |
|
8 | + */ |
|
9 | 9 | |
10 | 10 | if ( ! defined( 'ABSPATH' ) ) { |
11 | 11 | exit; |
@@ -7,7 +7,7 @@ discard block |
||
7 | 7 | * @package SimpleCalendar/Functions |
8 | 8 | */ |
9 | 9 | |
10 | -if ( ! defined( 'ABSPATH' ) ) { |
|
10 | +if ( ! defined('ABSPATH')) { |
|
11 | 11 | exit; |
12 | 12 | } |
13 | 13 | |
@@ -20,17 +20,17 @@ discard block |
||
20 | 20 | */ |
21 | 21 | function is_simple_calendar() { |
22 | 22 | |
23 | - if ( is_singular() ) { |
|
23 | + if (is_singular()) { |
|
24 | 24 | |
25 | 25 | global $post, $post_type; |
26 | 26 | |
27 | - if ( 'calendar' == $post_type ) { |
|
27 | + if ('calendar' == $post_type) { |
|
28 | 28 | return true; |
29 | 29 | } else { |
30 | - if ( false !== get_post_meta( $post->ID, '_simcal_attach_calendar_id', true ) ) { |
|
30 | + if (false !== get_post_meta($post->ID, '_simcal_attach_calendar_id', true)) { |
|
31 | 31 | return true; |
32 | 32 | } |
33 | - if ( has_shortcode( $post->post_content, 'calendar' ) ) { |
|
33 | + if (has_shortcode($post->post_content, 'calendar')) { |
|
34 | 34 | return true; |
35 | 35 | } |
36 | 36 | } |
@@ -46,8 +46,8 @@ discard block |
||
46 | 46 | * |
47 | 47 | * @return string |
48 | 48 | */ |
49 | -function simcal_get_url( $url ) { |
|
50 | - return \SimpleCalendar\plugin()->get_url( $url ); |
|
49 | +function simcal_get_url($url) { |
|
50 | + return \SimpleCalendar\plugin()->get_url($url); |
|
51 | 51 | } |
52 | 52 | |
53 | 53 | /** |
@@ -71,9 +71,9 @@ discard block |
||
71 | 71 | * |
72 | 72 | * @return null|\SimpleCalendar\Abstracts\Feed |
73 | 73 | */ |
74 | -function simcal_get_feed( $object ) { |
|
74 | +function simcal_get_feed($object) { |
|
75 | 75 | $objects = \SimpleCalendar\plugin()->objects; |
76 | - return $objects instanceof \SimpleCalendar\Objects ? $objects->get_feed( $object ) : null; |
|
76 | + return $objects instanceof \SimpleCalendar\Objects ? $objects->get_feed($object) : null; |
|
77 | 77 | } |
78 | 78 | |
79 | 79 | /** |
@@ -97,9 +97,9 @@ discard block |
||
97 | 97 | * |
98 | 98 | * @return null|\SimpleCalendar\Abstracts\Calendar |
99 | 99 | */ |
100 | -function simcal_get_calendar( $object ) { |
|
100 | +function simcal_get_calendar($object) { |
|
101 | 101 | $objects = \SimpleCalendar\plugin()->objects; |
102 | - return $objects instanceof \SimpleCalendar\Objects ? $objects->get_calendar( $object ) : null; |
|
102 | + return $objects instanceof \SimpleCalendar\Objects ? $objects->get_calendar($object) : null; |
|
103 | 103 | } |
104 | 104 | |
105 | 105 | /** |
@@ -112,9 +112,9 @@ discard block |
||
112 | 112 | * |
113 | 113 | * @return mixed |
114 | 114 | */ |
115 | -function simcal_get_calendar_view( $id = 0, $name = '' ) { |
|
115 | +function simcal_get_calendar_view($id = 0, $name = '') { |
|
116 | 116 | $objects = \SimpleCalendar\plugin()->objects; |
117 | - return $objects instanceof \SimpleCalendar\Objects ? $objects->get_calendar_view( $id, $name ) : false; |
|
117 | + return $objects instanceof \SimpleCalendar\Objects ? $objects->get_calendar_view($id, $name) : false; |
|
118 | 118 | } |
119 | 119 | |
120 | 120 | /** |
@@ -126,11 +126,11 @@ discard block |
||
126 | 126 | * |
127 | 127 | * @return void |
128 | 128 | */ |
129 | -function simcal_print_calendar( $object ) { |
|
129 | +function simcal_print_calendar($object) { |
|
130 | 130 | |
131 | - $calendar = simcal_get_calendar( $object ); |
|
131 | + $calendar = simcal_get_calendar($object); |
|
132 | 132 | |
133 | - if ( $calendar instanceof \SimpleCalendar\Abstracts\Calendar ) { |
|
133 | + if ($calendar instanceof \SimpleCalendar\Abstracts\Calendar) { |
|
134 | 134 | $calendar->html(); |
135 | 135 | } |
136 | 136 | } |
@@ -148,21 +148,21 @@ discard block |
||
148 | 148 | |
149 | 149 | $vars = array( |
150 | 150 | 'ajax_url' => \SimpleCalendar\plugin()->ajax_url(), |
151 | - 'nonce' => wp_create_nonce( 'simcal' ), |
|
151 | + 'nonce' => wp_create_nonce('simcal'), |
|
152 | 152 | 'locale' => \SimpleCalendar\plugin()->locale, |
153 | 153 | 'text_dir' => is_rtl() ? 'rtl' : 'ltr', |
154 | 154 | 'months' => array( |
155 | - 'full' => simcal_get_calendar_names_i18n( 'month', 'full' ), |
|
156 | - 'short' => simcal_get_calendar_names_i18n( 'month', 'short' ), |
|
155 | + 'full' => simcal_get_calendar_names_i18n('month', 'full'), |
|
156 | + 'short' => simcal_get_calendar_names_i18n('month', 'short'), |
|
157 | 157 | ), |
158 | 158 | 'days' => array( |
159 | - 'full' => simcal_get_calendar_names_i18n( 'day', 'full' ), |
|
160 | - 'short' => simcal_get_calendar_names_i18n( 'day', 'short' ), |
|
159 | + 'full' => simcal_get_calendar_names_i18n('day', 'full'), |
|
160 | + 'short' => simcal_get_calendar_names_i18n('day', 'short'), |
|
161 | 161 | ), |
162 | - 'meridiem' => simcal_get_calendar_names_i18n( 'meridiem' ), |
|
162 | + 'meridiem' => simcal_get_calendar_names_i18n('meridiem'), |
|
163 | 163 | ); |
164 | 164 | |
165 | - return array_merge( $vars, apply_filters( 'simcal_common_scripts_variables', array() ) ); |
|
165 | + return array_merge($vars, apply_filters('simcal_common_scripts_variables', array())); |
|
166 | 166 | } |
167 | 167 | |
168 | 168 | /** |
@@ -175,31 +175,31 @@ discard block |
||
175 | 175 | * |
176 | 176 | * @return array Associative array with ids as keys and feed titles as values. |
177 | 177 | */ |
178 | -function simcal_get_calendars( $exclude = '', $cached = true ) { |
|
178 | +function simcal_get_calendars($exclude = '', $cached = true) { |
|
179 | 179 | |
180 | - $calendars = get_transient( '_simple-calendar_feed_ids' ); |
|
180 | + $calendars = get_transient('_simple-calendar_feed_ids'); |
|
181 | 181 | |
182 | - if ( ! $calendars || $cached === false ) { |
|
182 | + if ( ! $calendars || $cached === false) { |
|
183 | 183 | |
184 | - $posts = get_posts( array( |
|
184 | + $posts = get_posts(array( |
|
185 | 185 | 'post_type' => 'calendar', |
186 | 186 | 'nopaging' => true, |
187 | - ) ); |
|
187 | + )); |
|
188 | 188 | |
189 | 189 | $calendars = array(); |
190 | - foreach ( $posts as $post ) { |
|
191 | - $calendars[ $post->ID ] = $post->post_title; |
|
190 | + foreach ($posts as $post) { |
|
191 | + $calendars[$post->ID] = $post->post_title; |
|
192 | 192 | } |
193 | - asort( $calendars ); |
|
193 | + asort($calendars); |
|
194 | 194 | |
195 | - set_transient( '_simple-calendar_feed_ids', $calendars, 604800 ); |
|
195 | + set_transient('_simple-calendar_feed_ids', $calendars, 604800); |
|
196 | 196 | } |
197 | 197 | |
198 | - if ( ! empty( $exclude ) ) { |
|
199 | - if ( is_numeric( $exclude ) ) { |
|
200 | - unset( $calendars[ intval( $exclude ) ] ); |
|
201 | - } elseif ( is_array( $exclude ) ) { |
|
202 | - array_diff_key( $calendars, array_map( 'intval', array_keys( $exclude ) ) ); |
|
198 | + if ( ! empty($exclude)) { |
|
199 | + if (is_numeric($exclude)) { |
|
200 | + unset($calendars[intval($exclude)]); |
|
201 | + } elseif (is_array($exclude)) { |
|
202 | + array_diff_key($calendars, array_map('intval', array_keys($exclude))); |
|
203 | 203 | } |
204 | 204 | } |
205 | 205 | |
@@ -218,45 +218,45 @@ discard block |
||
218 | 218 | * |
219 | 219 | * @return array |
220 | 220 | */ |
221 | -function simcal_get_calendar_names_i18n( $group, $style = 'full' ) { |
|
221 | +function simcal_get_calendar_names_i18n($group, $style = 'full') { |
|
222 | 222 | |
223 | 223 | $names = array(); |
224 | 224 | |
225 | - if ( in_array( $group, array( 'month', 'day', 'meridiem' ) ) ) { |
|
225 | + if (in_array($group, array('month', 'day', 'meridiem'))) { |
|
226 | 226 | |
227 | 227 | $format = ''; |
228 | 228 | $length = 0; |
229 | 229 | |
230 | 230 | $date = Carbon\Carbon::now(); |
231 | 231 | |
232 | - if ( 'month' == $group ) { |
|
233 | - $date->month( 0 )->startOfMonth(); |
|
232 | + if ('month' == $group) { |
|
233 | + $date->month(0)->startOfMonth(); |
|
234 | 234 | $format = 'short' == $style ? 'M' : 'F'; |
235 | 235 | $length = 11; |
236 | - } elseif ( 'day' == $group ) { |
|
237 | - $date->next( 6 ); |
|
236 | + } elseif ('day' == $group) { |
|
237 | + $date->next(6); |
|
238 | 238 | $format = 'short' == $style ? 'D' : 'l'; |
239 | 239 | $length = 6; |
240 | - } elseif ( 'meridiem' == $group ) { |
|
240 | + } elseif ('meridiem' == $group) { |
|
241 | 241 | $date->startOfDay(); |
242 | - $am = $date->addHour( 1 )->getTimestamp(); |
|
243 | - $pm = $date->addHours( 13 )->getTimestamp(); |
|
242 | + $am = $date->addHour(1)->getTimestamp(); |
|
243 | + $pm = $date->addHours(13)->getTimestamp(); |
|
244 | 244 | return array( |
245 | - 'AM' => date_i18n( 'A', $am ), |
|
246 | - 'am' => date_i18n( 'a', $am ), |
|
247 | - 'PM' => date_i18n( 'A', $pm ), |
|
248 | - 'pm' => date_i18n( 'a', $pm ), |
|
245 | + 'AM' => date_i18n('A', $am), |
|
246 | + 'am' => date_i18n('a', $am), |
|
247 | + 'PM' => date_i18n('A', $pm), |
|
248 | + 'pm' => date_i18n('a', $pm), |
|
249 | 249 | ); |
250 | 250 | } |
251 | 251 | |
252 | 252 | $i = 0; |
253 | - while ( $i <= $length ) { |
|
254 | - if ( 'month' == $group ) { |
|
255 | - $date->addMonths( 1 ); |
|
253 | + while ($i <= $length) { |
|
254 | + if ('month' == $group) { |
|
255 | + $date->addMonths(1); |
|
256 | 256 | } else { |
257 | - $date->addDays( 1 ); |
|
257 | + $date->addDays(1); |
|
258 | 258 | } |
259 | - $names[ strval( $i ) ] = date_i18n( $format, $date->getTimestamp() ); |
|
259 | + $names[strval($i)] = date_i18n($format, $date->getTimestamp()); |
|
260 | 260 | $i++; |
261 | 261 | } |
262 | 262 | |
@@ -274,15 +274,15 @@ discard block |
||
274 | 274 | */ |
275 | 275 | function simcal_default_event_template() { |
276 | 276 | |
277 | - $content = '<strong>' . '[title]' . '</strong>'; |
|
277 | + $content = '<strong>'.'[title]'.'</strong>'; |
|
278 | 278 | $content .= "\n\n"; |
279 | - $content .= '[when]' . "\n"; |
|
279 | + $content .= '[when]'."\n"; |
|
280 | 280 | $content .= '[location]'; |
281 | 281 | $content .= "\n"; |
282 | - $content .= '<div>' . '[description]' . '</div>'; |
|
283 | - $content .= "\n" . '[link newwindow="yes"]' . __( 'See more details', 'google-calendar-events' ) . '[/link]'; |
|
282 | + $content .= '<div>'.'[description]'.'</div>'; |
|
283 | + $content .= "\n".'[link newwindow="yes"]'.__('See more details', 'google-calendar-events').'[/link]'; |
|
284 | 284 | |
285 | - return apply_filters( 'simcal_default_event_template', $content ); |
|
285 | + return apply_filters('simcal_default_event_template', $content); |
|
286 | 286 | } |
287 | 287 | |
288 | 288 | /** |
@@ -297,21 +297,21 @@ discard block |
||
297 | 297 | * |
298 | 298 | * @return array |
299 | 299 | */ |
300 | -function simcal_get_date_format_order( $date_format ) { |
|
300 | +function simcal_get_date_format_order($date_format) { |
|
301 | 301 | |
302 | 302 | $pos = array( |
303 | - 'd' => strpos( $date_format, strpbrk( $date_format, 'Dj' ) ), |
|
304 | - 'm' => strpos( $date_format, strpbrk( $date_format, 'FMmn' ) ), |
|
305 | - 'y' => strpos( $date_format, strpbrk( $date_format, 'Yy' ) ), |
|
303 | + 'd' => strpos($date_format, strpbrk($date_format, 'Dj')), |
|
304 | + 'm' => strpos($date_format, strpbrk($date_format, 'FMmn')), |
|
305 | + 'y' => strpos($date_format, strpbrk($date_format, 'Yy')), |
|
306 | 306 | ); |
307 | 307 | |
308 | 308 | // @TODO When one date piece is not found, perhaps fallback to ISO standard position. |
309 | 309 | |
310 | 310 | $order = array(); |
311 | - foreach ( $pos as $k => $v ) { |
|
312 | - $order[ $k ] = $v; |
|
311 | + foreach ($pos as $k => $v) { |
|
312 | + $order[$k] = $v; |
|
313 | 313 | } |
314 | - ksort( $order ); |
|
314 | + ksort($order); |
|
315 | 315 | |
316 | 316 | return $order; |
317 | 317 | } |
@@ -327,11 +327,11 @@ discard block |
||
327 | 327 | */ |
328 | 328 | function simcal_get_wp_timezone() { |
329 | 329 | |
330 | - $timezone = get_option( 'timezone_string' ); |
|
330 | + $timezone = get_option('timezone_string'); |
|
331 | 331 | |
332 | - if ( empty( $timezone ) ) { |
|
333 | - $gmt = get_option( 'gmt_offset' ); |
|
334 | - $timezone = simcal_get_timezone_from_gmt_offset( $gmt ); |
|
332 | + if (empty($timezone)) { |
|
333 | + $gmt = get_option('gmt_offset'); |
|
334 | + $timezone = simcal_get_timezone_from_gmt_offset($gmt); |
|
335 | 335 | } |
336 | 336 | |
337 | 337 | return $timezone; |
@@ -348,26 +348,26 @@ discard block |
||
348 | 348 | * |
349 | 349 | * @return null|string |
350 | 350 | */ |
351 | -function simcal_get_timezone_from_gmt_offset( $offset ) { |
|
351 | +function simcal_get_timezone_from_gmt_offset($offset) { |
|
352 | 352 | |
353 | - if ( is_numeric( $offset ) ) { |
|
353 | + if (is_numeric($offset)) { |
|
354 | 354 | |
355 | - if ( 0 === intval( $offset ) ) { |
|
355 | + if (0 === intval($offset)) { |
|
356 | 356 | return 'UTC'; |
357 | 357 | } else { |
358 | - $offset = floatval( $offset ) * 3600; |
|
358 | + $offset = floatval($offset) * 3600; |
|
359 | 359 | } |
360 | 360 | |
361 | - $timezone = timezone_name_from_abbr( null, $offset, false ); |
|
361 | + $timezone = timezone_name_from_abbr(null, $offset, false); |
|
362 | 362 | // This is buggy and might return false: |
363 | 363 | // @see http://php.net/manual/en/function.timezone-name-from-abbr.php#86928 |
364 | 364 | // Therefore: |
365 | - if ( false == $timezone ) { |
|
365 | + if (false == $timezone) { |
|
366 | 366 | |
367 | 367 | $list = timezone_abbreviations_list(); |
368 | - foreach ( $list as $abbr ) { |
|
369 | - foreach ( $abbr as $city ) { |
|
370 | - if ( $offset == $city['offset'] ) { |
|
368 | + foreach ($list as $abbr) { |
|
369 | + foreach ($abbr as $city) { |
|
370 | + if ($offset == $city['offset']) { |
|
371 | 371 | return $city['timezone_id']; |
372 | 372 | } |
373 | 373 | } |
@@ -390,8 +390,8 @@ discard block |
||
390 | 390 | * |
391 | 391 | * @return int Unix time offset |
392 | 392 | */ |
393 | -function simcal_get_timezone_offset( $timezone ) { |
|
394 | - return \Carbon\Carbon::now( $timezone )->offset; |
|
393 | +function simcal_get_timezone_offset($timezone) { |
|
394 | + return \Carbon\Carbon::now($timezone)->offset; |
|
395 | 395 | } |
396 | 396 | |
397 | 397 | /** |
@@ -404,8 +404,8 @@ discard block |
||
404 | 404 | * |
405 | 405 | * @return mixed|string |
406 | 406 | */ |
407 | -function simcal_esc_timezone( $tz, $default = 'UTC' ) { |
|
408 | - return in_array( $tz, timezone_identifiers_list() ) ? $tz : $default; |
|
407 | +function simcal_esc_timezone($tz, $default = 'UTC') { |
|
408 | + return in_array($tz, timezone_identifiers_list()) ? $tz : $default; |
|
409 | 409 | } |
410 | 410 | |
411 | 411 | /** |
@@ -417,57 +417,57 @@ discard block |
||
417 | 417 | * |
418 | 418 | * @return bool |
419 | 419 | */ |
420 | -function simcal_delete_feed_transients( $id = '' ) { |
|
420 | +function simcal_delete_feed_transients($id = '') { |
|
421 | 421 | |
422 | - $grouped_ids = get_post_meta( $id, '_grouped_calendars_ids', true ); |
|
422 | + $grouped_ids = get_post_meta($id, '_grouped_calendars_ids', true); |
|
423 | 423 | |
424 | 424 | // If there are group IDs we need to construct an array to pass along with the grouped IDs + the original $post_id |
425 | - if ( is_array( $grouped_ids ) ) { |
|
425 | + if (is_array($grouped_ids)) { |
|
426 | 426 | $temp_id = $id; |
427 | 427 | $id = $grouped_ids; |
428 | 428 | $id[] = $temp_id; |
429 | 429 | } |
430 | 430 | |
431 | - if ( is_numeric( $id ) ) { |
|
432 | - $id = intval( $id ) > 0 ? absint( $id ) : simcal_get_calendars(); |
|
433 | - } elseif ( $id instanceof WP_Post ) { |
|
431 | + if (is_numeric($id)) { |
|
432 | + $id = intval($id) > 0 ? absint($id) : simcal_get_calendars(); |
|
433 | + } elseif ($id instanceof WP_Post) { |
|
434 | 434 | $id = $id->ID; |
435 | - } elseif ( is_array( $id ) ) { |
|
436 | - $id = array_map( 'absint', $id ); |
|
435 | + } elseif (is_array($id)) { |
|
436 | + $id = array_map('absint', $id); |
|
437 | 437 | } else { |
438 | - $id = simcal_get_calendars( '', true ); |
|
438 | + $id = simcal_get_calendars('', true); |
|
439 | 439 | } |
440 | 440 | |
441 | 441 | $feed_types = simcal_get_feed_types(); |
442 | 442 | |
443 | - if ( is_array( $id ) ) { |
|
443 | + if (is_array($id)) { |
|
444 | 444 | |
445 | - $posts = get_posts( array( |
|
445 | + $posts = get_posts(array( |
|
446 | 446 | 'post_type' => 'calendar', |
447 | 447 | 'fields' => 'ids', |
448 | 448 | 'post__in' => $id, |
449 | 449 | 'nopaging' => true, |
450 | - ) ); |
|
450 | + )); |
|
451 | 451 | |
452 | - foreach ( $posts as $post ) { |
|
453 | - $calendar = simcal_get_calendar( $post ); |
|
454 | - if ( $calendar instanceof \SimpleCalendar\Abstracts\Calendar ) { |
|
455 | - foreach ( $feed_types as $feed_type ) { |
|
456 | - delete_transient( '_simple-calendar_feed_id_' . strval( $calendar->id ) . '_' . $feed_type ); |
|
452 | + foreach ($posts as $post) { |
|
453 | + $calendar = simcal_get_calendar($post); |
|
454 | + if ($calendar instanceof \SimpleCalendar\Abstracts\Calendar) { |
|
455 | + foreach ($feed_types as $feed_type) { |
|
456 | + delete_transient('_simple-calendar_feed_id_'.strval($calendar->id).'_'.$feed_type); |
|
457 | 457 | } |
458 | 458 | } |
459 | 459 | } |
460 | 460 | |
461 | 461 | } else { |
462 | 462 | |
463 | - $post = get_post( $id ); |
|
464 | - $calendar = simcal_get_calendar( $post ); |
|
465 | - if ( $calendar instanceof \SimpleCalendar\Abstracts\Calendar ) { |
|
466 | - foreach ( $feed_types as $feed_type ) { |
|
467 | - delete_transient( '_simple-calendar_feed_id_' . strval( $calendar->id ) . '_' . $feed_type ); |
|
463 | + $post = get_post($id); |
|
464 | + $calendar = simcal_get_calendar($post); |
|
465 | + if ($calendar instanceof \SimpleCalendar\Abstracts\Calendar) { |
|
466 | + foreach ($feed_types as $feed_type) { |
|
467 | + delete_transient('_simple-calendar_feed_id_'.strval($calendar->id).'_'.$feed_type); |
|
468 | 468 | } |
469 | 469 | } |
470 | 470 | } |
471 | 471 | |
472 | - return delete_transient( '_simple-calendar_feed_ids' ); |
|
472 | + return delete_transient('_simple-calendar_feed_ids'); |
|
473 | 473 | } |
474 | 474 | \ No newline at end of file |