@@ -13,7 +13,7 @@ discard block |
||
13 | 13 | use SimpleCalendar\Calendars\Views; |
14 | 14 | use SimpleCalendar\Events\Event; |
15 | 15 | |
16 | -if ( ! defined( 'ABSPATH' ) ) { |
|
16 | +if ( ! defined('ABSPATH')) { |
|
17 | 17 | exit; |
18 | 18 | } |
19 | 19 | |
@@ -105,35 +105,35 @@ discard block |
||
105 | 105 | * |
106 | 106 | * @param int|object|\WP_Post|Calendar $calendar |
107 | 107 | */ |
108 | - public function __construct( $calendar ) { |
|
108 | + public function __construct($calendar) { |
|
109 | 109 | |
110 | 110 | $this->type = 'default-calendar'; |
111 | - $this->name = __( 'Default', 'google-calendar-events' ); |
|
112 | - $this->views = apply_filters( 'simcal_default_calendar_views', array( |
|
113 | - 'grid' => __( 'Grid', 'google-calendar-events' ), |
|
114 | - 'list' => __( 'List', 'google-calendar-events' ), |
|
115 | - ) ); |
|
111 | + $this->name = __('Default', 'google-calendar-events'); |
|
112 | + $this->views = apply_filters('simcal_default_calendar_views', array( |
|
113 | + 'grid' => __('Grid', 'google-calendar-events'), |
|
114 | + 'list' => __('List', 'google-calendar-events'), |
|
115 | + )); |
|
116 | 116 | |
117 | - parent::__construct( $calendar ); |
|
117 | + parent::__construct($calendar); |
|
118 | 118 | |
119 | - if ( ! is_null( $this->post ) ) { |
|
119 | + if ( ! is_null($this->post)) { |
|
120 | 120 | |
121 | - $this->set_properties( $this->view->get_type() ); |
|
121 | + $this->set_properties($this->view->get_type()); |
|
122 | 122 | |
123 | 123 | $id = $this->id; |
124 | 124 | $theme = $this->theme; |
125 | 125 | |
126 | - add_filter( 'simcal_calendar_class', function( $class, $post_id ) use ( $theme, $id ) { |
|
127 | - if ( in_array( 'default-calendar', $class ) && $post_id === $id ) { |
|
128 | - array_push( $class, 'default-calendar-' . $theme ); |
|
126 | + add_filter('simcal_calendar_class', function($class, $post_id) use ($theme, $id) { |
|
127 | + if (in_array('default-calendar', $class) && $post_id === $id) { |
|
128 | + array_push($class, 'default-calendar-'.$theme); |
|
129 | 129 | } |
130 | 130 | return $class; |
131 | - }, 10, 2 ); |
|
131 | + }, 10, 2); |
|
132 | 132 | |
133 | 133 | } |
134 | 134 | |
135 | 135 | // Calendar settings handling. |
136 | - if ( is_admin() && ! defined( 'DOING_AJAX' ) ) { |
|
136 | + if (is_admin() && ! defined('DOING_AJAX')) { |
|
137 | 137 | $admin = new Default_Calendar_Admin(); |
138 | 138 | $this->settings = $admin->settings_fields(); |
139 | 139 | } |
@@ -147,49 +147,49 @@ discard block |
||
147 | 147 | * |
148 | 148 | * @param $view |
149 | 149 | */ |
150 | - private function set_properties( $view ) { |
|
150 | + private function set_properties($view) { |
|
151 | 151 | |
152 | 152 | // Set styles. |
153 | - if ( 'dark' == get_post_meta( $this->id, '_default_calendar_style_theme', true ) ) { |
|
153 | + if ('dark' == get_post_meta($this->id, '_default_calendar_style_theme', true)) { |
|
154 | 154 | $this->theme = 'dark'; |
155 | 155 | } |
156 | - if ( $today_color = get_post_meta( $this->id, '_default_calendar_style_today', true ) ) { |
|
157 | - $this->today_color = esc_attr( $today_color ); |
|
156 | + if ($today_color = get_post_meta($this->id, '_default_calendar_style_today', true)) { |
|
157 | + $this->today_color = esc_attr($today_color); |
|
158 | 158 | } |
159 | - if ( $day_events_color = get_post_meta( $this->id, '_default_calendar_style_days_events', true ) ) { |
|
160 | - $this->days_events_color = esc_attr( $day_events_color ); |
|
159 | + if ($day_events_color = get_post_meta($this->id, '_default_calendar_style_days_events', true)) { |
|
160 | + $this->days_events_color = esc_attr($day_events_color); |
|
161 | 161 | } |
162 | 162 | |
163 | 163 | // Hide too many events. |
164 | - if ( 'yes' == get_post_meta( $this->id, '_default_calendar_limit_visible_events', true ) ) { |
|
165 | - $this->events_limit = absint( get_post_meta( $this->id, '_default_calendar_visible_events', true ) ); |
|
164 | + if ('yes' == get_post_meta($this->id, '_default_calendar_limit_visible_events', true)) { |
|
165 | + $this->events_limit = absint(get_post_meta($this->id, '_default_calendar_visible_events', true)); |
|
166 | 166 | } |
167 | 167 | |
168 | 168 | // Expand multiple day events. |
169 | - if ( 'yes' == get_post_meta( $this->id, '_default_calendar_expand_multi_day_events', true ) ) { |
|
169 | + if ('yes' == get_post_meta($this->id, '_default_calendar_expand_multi_day_events', true)) { |
|
170 | 170 | $this->events = $this->expand_multiple_days_events(); |
171 | 171 | } |
172 | 172 | |
173 | - if ( 'grid' == $view ) { |
|
173 | + if ('grid' == $view) { |
|
174 | 174 | |
175 | 175 | // Use hover to open event bubbles. |
176 | - if ( 'hover' == get_post_meta( $this->id, '_default_calendar_event_bubble_trigger', true ) ) { |
|
176 | + if ('hover' == get_post_meta($this->id, '_default_calendar_event_bubble_trigger', true)) { |
|
177 | 177 | $this->event_bubble_trigger = 'hover'; |
178 | 178 | } |
179 | 179 | |
180 | 180 | // Trim long event titles. |
181 | - if ( 'yes' == get_post_meta( $this->id, '_default_calendar_trim_titles', true ) ) { |
|
182 | - $this->trim_titles = max( absint( get_post_meta( $this->id, '_default_calendar_trim_titles_chars', true ) ), 1 ); |
|
181 | + if ('yes' == get_post_meta($this->id, '_default_calendar_trim_titles', true)) { |
|
182 | + $this->trim_titles = max(absint(get_post_meta($this->id, '_default_calendar_trim_titles_chars', true)), 1); |
|
183 | 183 | } |
184 | 184 | |
185 | 185 | } else { |
186 | 186 | |
187 | 187 | // List range. |
188 | - $this->group_type = esc_attr( get_post_meta( $this->id, '_default_calendar_list_range_type', true ) ); |
|
189 | - $this->group_span = max( absint( get_post_meta( $this->id, '_default_calendar_list_range_span', true ) ), 1 ); |
|
188 | + $this->group_type = esc_attr(get_post_meta($this->id, '_default_calendar_list_range_type', true)); |
|
189 | + $this->group_span = max(absint(get_post_meta($this->id, '_default_calendar_list_range_span', true)), 1); |
|
190 | 190 | |
191 | 191 | // Make the list look more compact. |
192 | - if ( 'yes' == get_post_meta( $this->id, '_default_calendar_compact_list', true ) ) { |
|
192 | + if ('yes' == get_post_meta($this->id, '_default_calendar_compact_list', true)) { |
|
193 | 193 | $this->compact_list = true; |
194 | 194 | } |
195 | 195 | |
@@ -210,24 +210,24 @@ discard block |
||
210 | 210 | $old_events = $this->events; |
211 | 211 | $new_events = array(); |
212 | 212 | |
213 | - if ( ! empty( $old_events ) ) { |
|
213 | + if ( ! empty($old_events)) { |
|
214 | 214 | |
215 | - foreach ( $old_events as $events ) { |
|
216 | - foreach ( $events as $event ) { |
|
217 | - if ( $event instanceof Event ) { |
|
218 | - if ( false !== $event->multiple_days ) { |
|
215 | + foreach ($old_events as $events) { |
|
216 | + foreach ($events as $event) { |
|
217 | + if ($event instanceof Event) { |
|
218 | + if (false !== $event->multiple_days) { |
|
219 | 219 | $days = $event->multiple_days; |
220 | 220 | |
221 | - if ( $days == 1 ) { |
|
222 | - $new_events[ intval( $event->start + ( DAY_IN_SECONDS ) - 1 ) ][] = $event; |
|
221 | + if ($days == 1) { |
|
222 | + $new_events[intval($event->start + (DAY_IN_SECONDS) - 1)][] = $event; |
|
223 | 223 | } else { |
224 | 224 | |
225 | - if ( ! empty( $event->whole_day ) ) { |
|
225 | + if ( ! empty($event->whole_day)) { |
|
226 | 226 | $days--; |
227 | 227 | } |
228 | 228 | |
229 | - for ( $d = 1; $d <= $days; $d++ ) { |
|
230 | - $new_events[ intval( $event->start + ( $d * DAY_IN_SECONDS ) - 1 ) ][] = $event; |
|
229 | + for ($d = 1; $d <= $days; $d++) { |
|
230 | + $new_events[intval($event->start + ($d * DAY_IN_SECONDS) - 1)][] = $event; |
|
231 | 231 | } |
232 | 232 | } |
233 | 233 | } |
@@ -239,7 +239,7 @@ discard block |
||
239 | 239 | } |
240 | 240 | |
241 | 241 | $events = $old_events + $new_events; |
242 | - ksort( $events, SORT_NUMERIC ); |
|
242 | + ksort($events, SORT_NUMERIC); |
|
243 | 243 | return $events; |
244 | 244 | } |
245 | 245 | |
@@ -254,16 +254,16 @@ discard block |
||
254 | 254 | * |
255 | 255 | * @return null|Calendar_View |
256 | 256 | */ |
257 | - public function get_view( $view = '' ) { |
|
257 | + public function get_view($view = '') { |
|
258 | 258 | |
259 | - $view = ! empty( $view ) ? $view : 'grid'; |
|
259 | + $view = ! empty($view) ? $view : 'grid'; |
|
260 | 260 | |
261 | - do_action( 'simcal_calendar_get_view', $this->type, $view ); |
|
261 | + do_action('simcal_calendar_get_view', $this->type, $view); |
|
262 | 262 | |
263 | - if ( 'grid' == $view ) { |
|
264 | - return new Views\Default_Calendar_Grid( $this ); |
|
265 | - } elseif ( 'list' == $view ) { |
|
266 | - return new Views\Default_Calendar_List( $this ); |
|
263 | + if ('grid' == $view) { |
|
264 | + return new Views\Default_Calendar_Grid($this); |
|
265 | + } elseif ('list' == $view) { |
|
266 | + return new Views\Default_Calendar_List($this); |
|
267 | 267 | } |
268 | 268 | |
269 | 269 | return null; |
@@ -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,47 +182,47 @@ 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 | - echo '<div class="simcal-calendar-list ' . $compact_list_class . '">'; |
|
196 | + echo '<div class="simcal-calendar-list '.$compact_list_class.'">'; |
|
197 | 197 | |
198 | - if ( ! $hide_header && ! $static_calendar ) { |
|
199 | - echo '<nav class="simcal-calendar-head">' . "\n"; |
|
198 | + if ( ! $hide_header && ! $static_calendar) { |
|
199 | + echo '<nav class="simcal-calendar-head">'."\n"; |
|
200 | 200 | |
201 | - echo "\t" . '<div class="simcal-nav">' . "\n"; |
|
202 | - echo "\t\t" . '<button class="simcal-nav-button simcal-prev" title="' . __('Previous', 'google-calendar-events') . '"' . $disabled . '>' . "\n"; |
|
203 | - echo "\t\t\t" . '<i class="simcal-icon-left"></i>' . "\n"; |
|
204 | - echo "\t\t" . '</button>' . "\n"; |
|
205 | - echo "\t" . '</div>' . "\n"; |
|
201 | + echo "\t".'<div class="simcal-nav">'."\n"; |
|
202 | + echo "\t\t".'<button class="simcal-nav-button simcal-prev" title="'.__('Previous', 'google-calendar-events').'"'.$disabled.'>'."\n"; |
|
203 | + echo "\t\t\t".'<i class="simcal-icon-left"></i>'."\n"; |
|
204 | + echo "\t\t".'</button>'."\n"; |
|
205 | + echo "\t".'</div>'."\n"; |
|
206 | 206 | |
207 | - if ( $hide_header ) { |
|
207 | + if ($hide_header) { |
|
208 | 208 | $header_class = 'simcal-hide-header'; |
209 | 209 | } |
210 | 210 | |
211 | 211 | |
212 | - echo "\t" . '<div class="simcal-nav simcal-current ' . $header_class . '" data-calendar-current="' . $calendar->start . '">' . "\n"; |
|
213 | - echo "\t\t" . '<h3 class="simcal-current-label"> </h3>' . "\n"; |
|
214 | - echo "\t" . '</div>' . "\n"; |
|
212 | + echo "\t".'<div class="simcal-nav simcal-current '.$header_class.'" data-calendar-current="'.$calendar->start.'">'."\n"; |
|
213 | + echo "\t\t".'<h3 class="simcal-current-label"> </h3>'."\n"; |
|
214 | + echo "\t".'</div>'."\n"; |
|
215 | 215 | |
216 | - echo "\t" . '<div class="simcal-nav">'; |
|
217 | - echo "\t\t" . '<button class="simcal-nav-button simcal-next" title="' . __('Next', 'google-calendar-events') . '"' . $disabled . '>'; |
|
218 | - echo "\t\t\t" . '<i class="simcal-icon-right"></i>' . "\n"; |
|
219 | - echo "\t\t" . '</button>' . "\n"; |
|
220 | - echo "\t" . '</div>' . "\n"; |
|
216 | + echo "\t".'<div class="simcal-nav">'; |
|
217 | + echo "\t\t".'<button class="simcal-nav-button simcal-next" title="'.__('Next', 'google-calendar-events').'"'.$disabled.'>'; |
|
218 | + echo "\t\t\t".'<i class="simcal-icon-right"></i>'."\n"; |
|
219 | + echo "\t\t".'</button>'."\n"; |
|
220 | + echo "\t".'</div>'."\n"; |
|
221 | 221 | |
222 | - echo '</nav>' . "\n"; |
|
222 | + echo '</nav>'."\n"; |
|
223 | 223 | } |
224 | 224 | |
225 | - echo $this->draw_list( $calendar->start ); |
|
225 | + echo $this->draw_list($calendar->start); |
|
226 | 226 | |
227 | 227 | echo '<div class="simcal-ajax-loader simcal-spinner-top" style="display: none;"><i class="simcal-icon-spinner simcal-icon-spin"></i></div>'; |
228 | 228 | |
@@ -241,92 +241,92 @@ discard block |
||
241 | 241 | * |
242 | 242 | * @return array |
243 | 243 | */ |
244 | - private function get_events( $timestamp ) { |
|
244 | + private function get_events($timestamp) { |
|
245 | 245 | |
246 | 246 | $calendar = $this->calendar; |
247 | 247 | $timezone = $calendar->timezone; |
248 | 248 | |
249 | - if ( ! $calendar->group_type || ! $calendar->group_span ) { |
|
249 | + if ( ! $calendar->group_type || ! $calendar->group_span) { |
|
250 | 250 | return array(); |
251 | 251 | } |
252 | 252 | |
253 | - $current = Carbon::createFromTimestamp( $timestamp, $timezone ); |
|
253 | + $current = Carbon::createFromTimestamp($timestamp, $timezone); |
|
254 | 254 | $prev = clone $current; |
255 | 255 | $next = clone $current; |
256 | 256 | |
257 | 257 | $this->start = $current->getTimestamp(); |
258 | 258 | |
259 | - $interval = $span = max( absint( $calendar->group_span ), 1 ); |
|
260 | - |
|
261 | - if ( 'monthly' == $calendar->group_type ) { |
|
262 | - $this->prev = $prev->subMonths( $span )->getTimestamp(); |
|
263 | - $this->next = $next->addMonths( $span )->getTimestamp(); |
|
264 | - } elseif ( 'weekly' == $calendar->group_type ) { |
|
265 | - $week = new Carbon( $calendar->timezone ); |
|
266 | - $week->setTimestamp( $timestamp ); |
|
267 | - $week->setWeekStartsAt( $calendar->week_starts ); |
|
268 | - $this->prev = $prev->subWeeks( $span )->getTimestamp(); |
|
269 | - $this->next = $next->addWeeks( $span )->getTimestamp(); |
|
270 | - } elseif ( 'daily' == $calendar->group_type ) { |
|
271 | - $this->prev = $prev->subDays( $span )->getTimestamp(); |
|
272 | - $this->next = $next->addDays( $span )->getTimestamp(); |
|
259 | + $interval = $span = max(absint($calendar->group_span), 1); |
|
260 | + |
|
261 | + if ('monthly' == $calendar->group_type) { |
|
262 | + $this->prev = $prev->subMonths($span)->getTimestamp(); |
|
263 | + $this->next = $next->addMonths($span)->getTimestamp(); |
|
264 | + } elseif ('weekly' == $calendar->group_type) { |
|
265 | + $week = new Carbon($calendar->timezone); |
|
266 | + $week->setTimestamp($timestamp); |
|
267 | + $week->setWeekStartsAt($calendar->week_starts); |
|
268 | + $this->prev = $prev->subWeeks($span)->getTimestamp(); |
|
269 | + $this->next = $next->addWeeks($span)->getTimestamp(); |
|
270 | + } elseif ('daily' == $calendar->group_type) { |
|
271 | + $this->prev = $prev->subDays($span)->getTimestamp(); |
|
272 | + $this->next = $next->addDays($span)->getTimestamp(); |
|
273 | 273 | } |
274 | 274 | |
275 | 275 | $events = $calendar->events; |
276 | 276 | $daily_events = $paged_events = $flattened_events = array(); |
277 | 277 | |
278 | - if ( 'events' != $calendar->group_type ) { |
|
278 | + if ('events' != $calendar->group_type) { |
|
279 | 279 | |
280 | - $this->end = $this->next - 1; |
|
280 | + $this->end = $this->next - 1; |
|
281 | 281 | |
282 | - $timestamps = array_keys( $events ); |
|
283 | - $lower_bound = array_filter( $timestamps, array( $this, 'filter_events_before' ) ); |
|
284 | - $higher_bound = array_filter( $lower_bound, array( $this, 'filter_events_after' ) ); |
|
282 | + $timestamps = array_keys($events); |
|
283 | + $lower_bound = array_filter($timestamps, array($this, 'filter_events_before')); |
|
284 | + $higher_bound = array_filter($lower_bound, array($this, 'filter_events_after')); |
|
285 | 285 | |
286 | - if ( is_array( $higher_bound ) && !empty( $higher_bound ) ) { |
|
287 | - $filtered = array_intersect_key( $events, array_combine( $higher_bound, $higher_bound ) ); |
|
288 | - foreach ( $filtered as $timestamp => $events ) { |
|
289 | - $paged_events[ intval( $timestamp ) ] = $events; |
|
286 | + if (is_array($higher_bound) && ! empty($higher_bound)) { |
|
287 | + $filtered = array_intersect_key($events, array_combine($higher_bound, $higher_bound)); |
|
288 | + foreach ($filtered as $timestamp => $events) { |
|
289 | + $paged_events[intval($timestamp)] = $events; |
|
290 | 290 | } |
291 | 291 | } |
292 | 292 | |
293 | 293 | } else { |
294 | 294 | |
295 | - foreach ( $events as $timestamp => $e ) { |
|
295 | + foreach ($events as $timestamp => $e) { |
|
296 | 296 | $second = 0; |
297 | - foreach ( $e as $event ) { |
|
298 | - $flattened_events[ intval( $timestamp + $second ) ][] = $event; |
|
297 | + foreach ($e as $event) { |
|
298 | + $flattened_events[intval($timestamp + $second)][] = $event; |
|
299 | 299 | $second++; |
300 | 300 | } |
301 | 301 | } |
302 | - ksort( $flattened_events, SORT_NUMERIC ); |
|
302 | + ksort($flattened_events, SORT_NUMERIC); |
|
303 | 303 | |
304 | - $keys = array_keys( $flattened_events ); |
|
304 | + $keys = array_keys($flattened_events); |
|
305 | 305 | $current = 0; |
306 | - foreach ( $keys as $timestamp ) { |
|
307 | - if ( $timestamp <= $this->start ) { |
|
306 | + foreach ($keys as $timestamp) { |
|
307 | + if ($timestamp <= $this->start) { |
|
308 | 308 | $current++; |
309 | 309 | } |
310 | 310 | } |
311 | 311 | |
312 | - $paged_events = array_slice( $flattened_events, $current, $interval, true ); |
|
312 | + $paged_events = array_slice($flattened_events, $current, $interval, true); |
|
313 | 313 | |
314 | - $events_end = isset( $keys[ $current + $interval ] ) ? $keys[ $current + $interval ] : $calendar->end; |
|
314 | + $events_end = isset($keys[$current + $interval]) ? $keys[$current + $interval] : $calendar->end; |
|
315 | 315 | $this->end = $events_end > $calendar->end ? $calendar->end : $events_end; |
316 | 316 | // -1 adjusts the interval count to index count, which starts at 0. |
317 | - $this->prev = isset( $keys[ $current - $interval - 1 ] ) ? $keys[ $current - $interval - 1 ] : $calendar->earliest_event; |
|
318 | - $this->next = isset( $keys[ $current + $interval - 1 ] ) ? $keys[ $current + $interval - 1 ] : $this->end; |
|
317 | + $this->prev = isset($keys[$current - $interval - 1]) ? $keys[$current - $interval - 1] : $calendar->earliest_event; |
|
318 | + $this->next = isset($keys[$current + $interval - 1]) ? $keys[$current + $interval - 1] : $this->end; |
|
319 | 319 | |
320 | 320 | } |
321 | 321 | |
322 | 322 | // Put resulting events in an associative array, with Ymd date as key for easy retrieval in calendar days loop. |
323 | - foreach ( $paged_events as $timestamp => $events ) { |
|
324 | - if ( $timestamp <= $this->end ) { |
|
325 | - $date = Carbon::createFromTimestamp( $timestamp, $calendar->timezone )->endOfDay()->format( 'Ymd' ); |
|
326 | - $daily_events[ intval( $date ) ][] = $events; |
|
323 | + foreach ($paged_events as $timestamp => $events) { |
|
324 | + if ($timestamp <= $this->end) { |
|
325 | + $date = Carbon::createFromTimestamp($timestamp, $calendar->timezone)->endOfDay()->format('Ymd'); |
|
326 | + $daily_events[intval($date)][] = $events; |
|
327 | 327 | } |
328 | 328 | } |
329 | - ksort( $daily_events, SORT_NUMERIC ); |
|
329 | + ksort($daily_events, SORT_NUMERIC); |
|
330 | 330 | |
331 | 331 | return $daily_events; |
332 | 332 | } |
@@ -344,71 +344,71 @@ discard block |
||
344 | 344 | private function get_heading() { |
345 | 345 | |
346 | 346 | $calendar = $this->calendar; |
347 | - $start = Carbon::createFromTimestamp( $this->start, $calendar->timezone ); |
|
348 | - $end = Carbon::createFromTimestamp( $this->end, $calendar->timezone ); |
|
347 | + $start = Carbon::createFromTimestamp($this->start, $calendar->timezone); |
|
348 | + $end = Carbon::createFromTimestamp($this->end, $calendar->timezone); |
|
349 | 349 | $date_format = $this->calendar->date_format; |
350 | - $date_order = simcal_get_date_format_order( $date_format ); |
|
350 | + $date_order = simcal_get_date_format_order($date_format); |
|
351 | 351 | |
352 | - if ( ( $start->day == $end->day ) && ( $start->month == $end->month ) && ( $start->year == $end->year ) ) { |
|
352 | + if (($start->day == $end->day) && ($start->month == $end->month) && ($start->year == $end->year)) { |
|
353 | 353 | // Start and end on the same day. |
354 | 354 | // e.g. 1 February 2020 |
355 | - $large = $small = date_i18n( $calendar->date_format , $this->start ); |
|
356 | - if ( ( $date_order['d'] !== false ) && ( $date_order['m'] !== false ) ) { |
|
357 | - if ( $date_order['m'] > $date_order['d'] ) { |
|
358 | - if ( $date_order['y'] !== false && $date_order['y'] > $date_order['m'] ) { |
|
359 | - $small = date_i18n( 'Y, d M', $this->start ); |
|
355 | + $large = $small = date_i18n($calendar->date_format, $this->start); |
|
356 | + if (($date_order['d'] !== false) && ($date_order['m'] !== false)) { |
|
357 | + if ($date_order['m'] > $date_order['d']) { |
|
358 | + if ($date_order['y'] !== false && $date_order['y'] > $date_order['m']) { |
|
359 | + $small = date_i18n('Y, d M', $this->start); |
|
360 | 360 | } else { |
361 | - $small = date_i18n( 'd M Y', $this->start ); |
|
361 | + $small = date_i18n('d M Y', $this->start); |
|
362 | 362 | } |
363 | 363 | } else { |
364 | - if ( $date_order['y'] !== false && $date_order['y'] > $date_order['m'] ) { |
|
365 | - $small = date_i18n( 'Y, M d', $this->start ); |
|
364 | + if ($date_order['y'] !== false && $date_order['y'] > $date_order['m']) { |
|
365 | + $small = date_i18n('Y, M d', $this->start); |
|
366 | 366 | } else { |
367 | - $small = date_i18n( 'M d Y', $this->start ); |
|
367 | + $small = date_i18n('M d Y', $this->start); |
|
368 | 368 | } |
369 | 369 | } |
370 | 370 | } |
371 | - } elseif ( ( $start->month == $end->month ) && ( $start->year == $end->year ) ) { |
|
371 | + } elseif (($start->month == $end->month) && ($start->year == $end->year)) { |
|
372 | 372 | // Start and end days on the same month. |
373 | 373 | // e.g. August 2020 |
374 | - if ( $date_order['y'] === false ) { |
|
374 | + if ($date_order['y'] === false) { |
|
375 | 375 | // August. |
376 | - $large = $small = date_i18n( 'F', $this->start ); |
|
376 | + $large = $small = date_i18n('F', $this->start); |
|
377 | 377 | } else { |
378 | - if ( $date_order['y'] < $date_order['m'] ) { |
|
378 | + if ($date_order['y'] < $date_order['m']) { |
|
379 | 379 | // 2020 August. |
380 | - $large = date_i18n( 'Y F', $this->start ); |
|
381 | - $small = date_i18n( 'Y M', $this->start ); |
|
380 | + $large = date_i18n('Y F', $this->start); |
|
381 | + $small = date_i18n('Y M', $this->start); |
|
382 | 382 | } else { |
383 | 383 | // August 2020. |
384 | - $large = date_i18n( 'F Y', $this->start ); |
|
385 | - $small = date_i18n( 'M Y', $this->start ); |
|
384 | + $large = date_i18n('F Y', $this->start); |
|
385 | + $small = date_i18n('M Y', $this->start); |
|
386 | 386 | } |
387 | 387 | } |
388 | - } elseif ( $start->year == $end->year ) { |
|
388 | + } elseif ($start->year == $end->year) { |
|
389 | 389 | // Start and end days on months of the same year. |
390 | 390 | // e.g. August - September 2020 |
391 | - if ( $date_order['y'] === false ) { |
|
391 | + if ($date_order['y'] === false) { |
|
392 | 392 | // August - September. |
393 | - $large = date_i18n( 'F', $this->start ) . ' - ' . date_i18n( 'F', $this->end ); |
|
394 | - $small = date_i18n( 'M', $this->start ) . ' - ' . date_i18n( 'M', $this->end ); |
|
393 | + $large = date_i18n('F', $this->start).' - '.date_i18n('F', $this->end); |
|
394 | + $small = date_i18n('M', $this->start).' - '.date_i18n('M', $this->end); |
|
395 | 395 | } else { |
396 | - if ( $date_order['y'] < $date_order['m'] ) { |
|
396 | + if ($date_order['y'] < $date_order['m']) { |
|
397 | 397 | // 2020, August - September. |
398 | - $large = $small = date( 'Y', $this->start ) . ', '; |
|
399 | - $large .= date_i18n( 'F', $this->start ) . ' - ' . date_i18n( 'F', $this->end ); |
|
400 | - $small .= date_i18n( 'M', $this->start ) . ' - ' . date_i18n( 'M', $this->end ); |
|
398 | + $large = $small = date('Y', $this->start).', '; |
|
399 | + $large .= date_i18n('F', $this->start).' - '.date_i18n('F', $this->end); |
|
400 | + $small .= date_i18n('M', $this->start).' - '.date_i18n('M', $this->end); |
|
401 | 401 | } else { |
402 | 402 | // August - September, 2020. |
403 | - $large = date_i18n( 'F', $this->start ) . ' - ' . date_i18n( 'F', $this->end ) . ', '; |
|
404 | - $small = date_i18n( 'M', $this->start ) . ' - ' . date_i18n( 'M', $this->end ) . ' '; |
|
405 | - $year = date( 'Y', $this->start ); |
|
403 | + $large = date_i18n('F', $this->start).' - '.date_i18n('F', $this->end).', '; |
|
404 | + $small = date_i18n('M', $this->start).' - '.date_i18n('M', $this->end).' '; |
|
405 | + $year = date('Y', $this->start); |
|
406 | 406 | $large .= $year; |
407 | 407 | $small .= $year; |
408 | 408 | } |
409 | 409 | } |
410 | 410 | } else { |
411 | - $large = $small = date( 'Y', $this->start ) . ' - ' . date( 'Y', $this->end ); |
|
411 | + $large = $small = date('Y', $this->start).' - '.date('Y', $this->end); |
|
412 | 412 | } |
413 | 413 | |
414 | 414 | return array( |
@@ -430,105 +430,105 @@ discard block |
||
430 | 430 | * |
431 | 431 | * @return string |
432 | 432 | */ |
433 | - private function draw_list( $timestamp, $id = 0 ) { |
|
433 | + private function draw_list($timestamp, $id = 0) { |
|
434 | 434 | |
435 | 435 | $calendar = $this->calendar; |
436 | 436 | |
437 | - if ( empty( $calendar ) ) { |
|
438 | - $calendar = $this->calendar = simcal_get_calendar( intval( $id ) ); |
|
439 | - if ( ! $calendar instanceof Default_Calendar ) { |
|
437 | + if (empty($calendar)) { |
|
438 | + $calendar = $this->calendar = simcal_get_calendar(intval($id)); |
|
439 | + if ( ! $calendar instanceof Default_Calendar) { |
|
440 | 440 | return ''; |
441 | 441 | } |
442 | 442 | } |
443 | 443 | |
444 | - date_default_timezone_set( $calendar->timezone ); |
|
444 | + date_default_timezone_set($calendar->timezone); |
|
445 | 445 | |
446 | 446 | $now = $calendar->now; |
447 | - $current_events = $this->get_events( $timestamp ); |
|
448 | - $day_format = explode( ' ', $calendar->date_format ); |
|
447 | + $current_events = $this->get_events($timestamp); |
|
448 | + $day_format = explode(' ', $calendar->date_format); |
|
449 | 449 | |
450 | 450 | ob_start(); |
451 | 451 | |
452 | 452 | // Draw the events. |
453 | 453 | |
454 | - $block_tag = $calendar->compact_list && ! empty( $current_events ) ? 'div' : 'dl'; |
|
454 | + $block_tag = $calendar->compact_list && ! empty($current_events) ? 'div' : 'dl'; |
|
455 | 455 | |
456 | 456 | $data_heading = ''; |
457 | 457 | $heading = $this->get_heading(); |
458 | - foreach ( $heading as $k => $v ) { |
|
459 | - $data_heading .= ' data-heading-' . $k . '="' . $v . '"'; |
|
458 | + foreach ($heading as $k => $v) { |
|
459 | + $data_heading .= ' data-heading-'.$k.'="'.$v.'"'; |
|
460 | 460 | } |
461 | 461 | |
462 | - echo '<' . $block_tag . ' class="simcal-events-list-container"' . |
|
463 | - ' data-prev="' . $this->prev . '"' . |
|
464 | - ' data-next="' . $this->next . '"' . |
|
465 | - $data_heading . '>'; |
|
462 | + echo '<'.$block_tag.' class="simcal-events-list-container"'. |
|
463 | + ' data-prev="'.$this->prev.'"'. |
|
464 | + ' data-next="'.$this->next.'"'. |
|
465 | + $data_heading.'>'; |
|
466 | 466 | |
467 | - if ( ! empty( $current_events ) && is_array( $current_events ) ) : |
|
467 | + if ( ! empty($current_events) && is_array($current_events)) : |
|
468 | 468 | |
469 | - foreach ( $current_events as $ymd => $events ) : |
|
469 | + foreach ($current_events as $ymd => $events) : |
|
470 | 470 | |
471 | - $day_ts = Carbon::createFromFormat( 'Ymd', $ymd, $calendar->timezone )->getTimestamp(); |
|
471 | + $day_ts = Carbon::createFromFormat('Ymd', $ymd, $calendar->timezone)->getTimestamp(); |
|
472 | 472 | |
473 | - if ( ! $calendar->compact_list ) : |
|
473 | + if ( ! $calendar->compact_list) : |
|
474 | 474 | |
475 | - $date = new Carbon( 'now', $calendar->timezone ); |
|
476 | - $date->setLocale( substr( get_locale(), 0, 2 ) ); |
|
477 | - $date->setTimestamp( $day_ts ); |
|
475 | + $date = new Carbon('now', $calendar->timezone); |
|
476 | + $date->setLocale(substr(get_locale(), 0, 2)); |
|
477 | + $date->setTimestamp($day_ts); |
|
478 | 478 | |
479 | - if ( $date->isToday() ) { |
|
480 | - $the_color = new Color( $calendar->today_color ); |
|
479 | + if ($date->isToday()) { |
|
480 | + $the_color = new Color($calendar->today_color); |
|
481 | 481 | } else { |
482 | - $the_color = new Color( $calendar->days_events_color ); |
|
482 | + $the_color = new Color($calendar->days_events_color); |
|
483 | 483 | } |
484 | 484 | |
485 | - $bg_color = '#' . $the_color->getHex(); |
|
485 | + $bg_color = '#'.$the_color->getHex(); |
|
486 | 486 | $color = $the_color->isDark() ? '#ffffff' : '#000000'; |
487 | - $border_style = ' style="border-bottom: 1px solid ' . $bg_color . ';" '; |
|
488 | - $bg_style = ' style="background-color: ' . $bg_color . '; color: ' . $color . ';"'; |
|
487 | + $border_style = ' style="border-bottom: 1px solid '.$bg_color.';" '; |
|
488 | + $bg_style = ' style="background-color: '.$bg_color.'; color: '.$color.';"'; |
|
489 | 489 | |
490 | - echo "\t" . '<dt class="simcal-day-label"' . $border_style . '>'; |
|
491 | - echo '<span' . $bg_style .'>'; |
|
492 | - foreach ( $day_format as $format ) { |
|
493 | - echo $format ? '<span class="simcal-date-format" data-date-format="' . $format . '">' . date_i18n( $format, $day_ts ) . '</span> ' : ' '; |
|
490 | + echo "\t".'<dt class="simcal-day-label"'.$border_style.'>'; |
|
491 | + echo '<span'.$bg_style.'>'; |
|
492 | + foreach ($day_format as $format) { |
|
493 | + echo $format ? '<span class="simcal-date-format" data-date-format="'.$format.'">'.date_i18n($format, $day_ts).'</span> ' : ' '; |
|
494 | 494 | } |
495 | 495 | echo '</span>'; |
496 | - echo '</dt>' . "\n"; |
|
496 | + echo '</dt>'."\n"; |
|
497 | 497 | |
498 | 498 | endif; |
499 | 499 | |
500 | - $list_events = '<ul class="simcal-events">' . "\n"; |
|
500 | + $list_events = '<ul class="simcal-events">'."\n"; |
|
501 | 501 | |
502 | 502 | $calendar_classes = array(); |
503 | - $day_classes = 'simcal-weekday-' . date( 'w', $day_ts ); |
|
503 | + $day_classes = 'simcal-weekday-'.date('w', $day_ts); |
|
504 | 504 | |
505 | 505 | // Is this the present, the past or the future, Doc? |
506 | - if ( $timestamp <= $now && $timestamp >= $now ) { |
|
506 | + if ($timestamp <= $now && $timestamp >= $now) { |
|
507 | 507 | $day_classes .= ' simcal-today simcal-present simcal-day'; |
508 | - } elseif ( $timestamp < $now ) { |
|
508 | + } elseif ($timestamp < $now) { |
|
509 | 509 | $day_classes .= ' simcal-past simcal-day'; |
510 | - } elseif ( $this->end > $now ) { |
|
510 | + } elseif ($this->end > $now) { |
|
511 | 511 | $day_classes .= ' simcal-future simcal-day'; |
512 | 512 | } |
513 | 513 | |
514 | 514 | $count = 0; |
515 | 515 | |
516 | - foreach ( $events as $day_events ) : |
|
517 | - foreach ( $day_events as $event ) : |
|
518 | - if ( $event instanceof Event ) : |
|
516 | + foreach ($events as $day_events) : |
|
517 | + foreach ($day_events as $event) : |
|
518 | + if ($event instanceof Event) : |
|
519 | 519 | |
520 | 520 | $event_classes = $event_visibility = ''; |
521 | 521 | |
522 | - $calendar_class = 'simcal-events-calendar-' . strval( $event->calendar ); |
|
522 | + $calendar_class = 'simcal-events-calendar-'.strval($event->calendar); |
|
523 | 523 | $calendar_classes[] = $calendar_class; |
524 | 524 | |
525 | 525 | $recurring = $event->recurrence ? 'simcal-event-recurring ' : ''; |
526 | 526 | $has_location = $event->venue ? 'simcal-event-has-location ' : ''; |
527 | 527 | |
528 | - $event_classes .= 'simcal-event ' . $recurring . $has_location . $calendar_class; |
|
528 | + $event_classes .= 'simcal-event '.$recurring.$has_location.$calendar_class; |
|
529 | 529 | |
530 | 530 | // Toggle some events visibility if more than optional limit. |
531 | - if ( ( $calendar->events_limit > - 1 ) && ( $count >= $calendar->events_limit ) ) : |
|
531 | + if (($calendar->events_limit > - 1) && ($count >= $calendar->events_limit)) : |
|
532 | 532 | $event_classes .= ' simcal-event-toggled'; |
533 | 533 | $event_visibility = ' style="display: none"'; |
534 | 534 | endif; |
@@ -536,75 +536,75 @@ discard block |
||
536 | 536 | $event_color = ''; |
537 | 537 | $bullet = ''; |
538 | 538 | $event_color = $event->get_color(); |
539 | - if ( ! empty( $event_color ) ) { |
|
539 | + if ( ! empty($event_color)) { |
|
540 | 540 | $side = is_rtl() ? 'right' : 'left'; |
541 | - $event_color = ' style="border-' . $side . ': 4px solid ' . $event_color . '; padding-' . $side . ': 8px;"'; |
|
541 | + $event_color = ' style="border-'.$side.': 4px solid '.$event_color.'; padding-'.$side.': 8px;"'; |
|
542 | 542 | } |
543 | 543 | |
544 | - $list_events .= "\t" . '<li class="' . $event_classes . '"' . $event_visibility . $event_color . ' itemprop="event" itemscope itemtype="http://schema.org/Event">' . "\n"; |
|
545 | - $list_events .= "\t\t" . '<div class="simcal-event-details">' . $calendar->get_event_html( $event ) . '</div>' . "\n"; |
|
546 | - $list_events .= "\t" . '</li>' . "\n"; |
|
544 | + $list_events .= "\t".'<li class="'.$event_classes.'"'.$event_visibility.$event_color.' itemprop="event" itemscope itemtype="http://schema.org/Event">'."\n"; |
|
545 | + $list_events .= "\t\t".'<div class="simcal-event-details">'.$calendar->get_event_html($event).'</div>'."\n"; |
|
546 | + $list_events .= "\t".'</li>'."\n"; |
|
547 | 547 | |
548 | - $count ++; |
|
548 | + $count++; |
|
549 | 549 | |
550 | 550 | // Event falls within today. |
551 | - if ( ( $this->end <= $now ) && ( $this->start >= $now ) ) : |
|
551 | + if (($this->end <= $now) && ($this->start >= $now)) : |
|
552 | 552 | $day_classes .= ' simcal-today-has-events'; |
553 | 553 | endif; |
554 | - $day_classes .= ' simcal-day-has-events simcal-day-has-' . strval( $count ) . '-events'; |
|
554 | + $day_classes .= ' simcal-day-has-events simcal-day-has-'.strval($count).'-events'; |
|
555 | 555 | |
556 | - if ( $calendar_classes ) : |
|
557 | - $day_classes .= ' ' . trim( implode( ' ', array_unique( $calendar_classes ) ) ); |
|
556 | + if ($calendar_classes) : |
|
557 | + $day_classes .= ' '.trim(implode(' ', array_unique($calendar_classes))); |
|
558 | 558 | endif; |
559 | 559 | |
560 | 560 | endif; |
561 | 561 | endforeach; |
562 | 562 | endforeach; |
563 | 563 | |
564 | - $list_events .= '</ul>' . "\n"; |
|
564 | + $list_events .= '</ul>'."\n"; |
|
565 | 565 | |
566 | 566 | // If events visibility is limited, print the button toggle. |
567 | - if ( ( $calendar->events_limit > -1 ) && ( $count > $calendar->events_limit ) ) : |
|
567 | + if (($calendar->events_limit > -1) && ($count > $calendar->events_limit)) : |
|
568 | 568 | $list_events .= '<button class="simcal-events-toggle"><i class="simcal-icon-down simcal-icon-animate"></i></button>'; |
569 | 569 | endif; |
570 | 570 | |
571 | 571 | // Print final list of events for the current day. |
572 | 572 | $tag = $calendar->compact_list ? 'div' : 'dd'; |
573 | - echo '<' . $tag . ' class="' . $day_classes . '" data-events-count="' . strval( $count ) . '">' . "\n"; |
|
574 | - echo "\t" . $list_events . "\n"; |
|
575 | - echo '</' . $tag . '>' . "\n"; |
|
573 | + echo '<'.$tag.' class="'.$day_classes.'" data-events-count="'.strval($count).'">'."\n"; |
|
574 | + echo "\t".$list_events."\n"; |
|
575 | + echo '</'.$tag.'>'."\n"; |
|
576 | 576 | |
577 | 577 | endforeach; |
578 | 578 | |
579 | 579 | else : |
580 | 580 | |
581 | - echo "\t" . '<p>'; |
|
581 | + echo "\t".'<p>'; |
|
582 | 582 | |
583 | - $message = get_post_meta( $calendar->id, '_no_events_message', true ); |
|
583 | + $message = get_post_meta($calendar->id, '_no_events_message', true); |
|
584 | 584 | |
585 | - if ( 'events' == $calendar->group_type ) { |
|
586 | - echo ! empty( $message ) ? $message : __( 'Nothing to show.', 'google-calendar-events' ); |
|
585 | + if ('events' == $calendar->group_type) { |
|
586 | + echo ! empty($message) ? $message : __('Nothing to show.', 'google-calendar-events'); |
|
587 | 587 | } else { |
588 | - if ( ! empty( $message ) ) { |
|
588 | + if ( ! empty($message)) { |
|
589 | 589 | echo $message; |
590 | 590 | } else { |
591 | - $from = Carbon::createFromTimestamp( $this->start, $calendar->timezone )->getTimestamp(); |
|
592 | - $to = Carbon::createFromTimestamp( $this->end, $calendar->timezone )->getTimestamp(); |
|
593 | - echo apply_filters( 'simcal_no_events_message', sprintf( |
|
594 | - __( 'Nothing from %1$s to %2$s.', 'google-calendar-events' ), |
|
595 | - date_i18n( $calendar->date_format, $from ), |
|
596 | - date_i18n( $calendar->date_format, $to ) |
|
597 | - ), $calendar->id, $from, $to ); |
|
591 | + $from = Carbon::createFromTimestamp($this->start, $calendar->timezone)->getTimestamp(); |
|
592 | + $to = Carbon::createFromTimestamp($this->end, $calendar->timezone)->getTimestamp(); |
|
593 | + echo apply_filters('simcal_no_events_message', sprintf( |
|
594 | + __('Nothing from %1$s to %2$s.', 'google-calendar-events'), |
|
595 | + date_i18n($calendar->date_format, $from), |
|
596 | + date_i18n($calendar->date_format, $to) |
|
597 | + ), $calendar->id, $from, $to); |
|
598 | 598 | } |
599 | 599 | } |
600 | 600 | |
601 | - echo "\t" . '</p>' . "\n"; |
|
601 | + echo "\t".'</p>'."\n"; |
|
602 | 602 | |
603 | 603 | endif; |
604 | 604 | |
605 | - echo '</' . $block_tag . '>'; |
|
605 | + echo '</'.$block_tag.'>'; |
|
606 | 606 | |
607 | - date_default_timezone_set( $calendar->site_timezone ); |
|
607 | + date_default_timezone_set($calendar->site_timezone); |
|
608 | 608 | |
609 | 609 | return ob_get_clean(); |
610 | 610 | } |
@@ -616,16 +616,16 @@ discard block |
||
616 | 616 | */ |
617 | 617 | public function draw_list_ajax() { |
618 | 618 | |
619 | - if ( isset( $_POST['ts'] ) && isset( $_POST['id'] ) ) { |
|
619 | + if (isset($_POST['ts']) && isset($_POST['id'])) { |
|
620 | 620 | |
621 | - $ts = absint( $_POST['ts'] ); |
|
622 | - $id = absint( $_POST['id'] ); |
|
621 | + $ts = absint($_POST['ts']); |
|
622 | + $id = absint($_POST['id']); |
|
623 | 623 | |
624 | - wp_send_json_success( $this->draw_list( $ts, $id ) ); |
|
624 | + wp_send_json_success($this->draw_list($ts, $id)); |
|
625 | 625 | |
626 | 626 | } else { |
627 | 627 | |
628 | - wp_send_json_error( 'Missing arguments in default calendar list ajax request.' ); |
|
628 | + wp_send_json_error('Missing arguments in default calendar list ajax request.'); |
|
629 | 629 | |
630 | 630 | } |
631 | 631 | } |
@@ -640,8 +640,8 @@ discard block |
||
640 | 640 | * |
641 | 641 | * @return bool |
642 | 642 | */ |
643 | - private function filter_events_before( $event ) { |
|
644 | - return intval( $event ) > intval( $this->start ); |
|
643 | + private function filter_events_before($event) { |
|
644 | + return intval($event) > intval($this->start); |
|
645 | 645 | } |
646 | 646 | |
647 | 647 | /** |
@@ -654,8 +654,8 @@ discard block |
||
654 | 654 | * |
655 | 655 | * @return bool |
656 | 656 | */ |
657 | - private function filter_events_after( $event ) { |
|
658 | - return intval( $event ) < intval( $this->end ); |
|
657 | + private function filter_events_after($event) { |
|
658 | + return intval($event) < intval($this->end); |
|
659 | 659 | } |
660 | 660 | |
661 | 661 | } |
@@ -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 | |
@@ -234,30 +234,30 @@ discard block |
||
234 | 234 | * |
235 | 235 | * @param array $event |
236 | 236 | */ |
237 | - public function __construct( array $event ) { |
|
237 | + public function __construct(array $event) { |
|
238 | 238 | |
239 | 239 | /* ================= * |
240 | 240 | * Event Identifiers * |
241 | 241 | * ================= */ |
242 | 242 | |
243 | 243 | // Event unique id. |
244 | - if ( ! empty( $event['uid'] ) ) { |
|
245 | - $this->uid = esc_attr( $event['uid'] ); |
|
244 | + if ( ! empty($event['uid'])) { |
|
245 | + $this->uid = esc_attr($event['uid']); |
|
246 | 246 | } |
247 | 247 | |
248 | 248 | // Event source. |
249 | - if ( ! empty( $event['source'] ) ) { |
|
250 | - $this->source = esc_attr( $event['source'] ); |
|
249 | + if ( ! empty($event['source'])) { |
|
250 | + $this->source = esc_attr($event['source']); |
|
251 | 251 | } |
252 | 252 | |
253 | 253 | // Event parent calendar id. |
254 | - if ( ! empty( $event['calendar'] ) ) { |
|
255 | - $this->calendar = max( intval( $event['calendar'] ), 0 ); |
|
254 | + if ( ! empty($event['calendar'])) { |
|
255 | + $this->calendar = max(intval($event['calendar']), 0); |
|
256 | 256 | } |
257 | 257 | |
258 | 258 | // Event parent calendar timezone. |
259 | - if ( ! empty( $event['timezone'] ) ) { |
|
260 | - $this->timezone = esc_attr( $event['timezone'] ); |
|
259 | + if ( ! empty($event['timezone'])) { |
|
260 | + $this->timezone = esc_attr($event['timezone']); |
|
261 | 261 | } |
262 | 262 | |
263 | 263 | /* ============= * |
@@ -265,23 +265,23 @@ discard block |
||
265 | 265 | * ============= */ |
266 | 266 | |
267 | 267 | // Event title. |
268 | - if ( ! empty( $event['title'] ) ) { |
|
269 | - $this->title = esc_html( $event['title'] ); |
|
268 | + if ( ! empty($event['title'])) { |
|
269 | + $this->title = esc_html($event['title']); |
|
270 | 270 | } |
271 | 271 | |
272 | 272 | // Event description. |
273 | - if ( ! empty( $event['description'] ) ) { |
|
274 | - $this->description = wp_kses_post( $event['description'] ); |
|
273 | + if ( ! empty($event['description'])) { |
|
274 | + $this->description = wp_kses_post($event['description']); |
|
275 | 275 | } |
276 | 276 | |
277 | 277 | // Event link URL. |
278 | - if ( ! empty( $event['link'] ) ) { |
|
279 | - $this->link = esc_url_raw( $event['link'] ); |
|
278 | + if ( ! empty($event['link'])) { |
|
279 | + $this->link = esc_url_raw($event['link']); |
|
280 | 280 | } |
281 | 281 | |
282 | 282 | // Event visibility. |
283 | - if ( ! empty( $event['visibility'] ) ) { |
|
284 | - $this->visibility = esc_attr( $event['visibility'] ); |
|
283 | + if ( ! empty($event['visibility'])) { |
|
284 | + $this->visibility = esc_attr($event['visibility']); |
|
285 | 285 | $this->public = $this->visibility == 'public' ? true : false; |
286 | 286 | } |
287 | 287 | |
@@ -289,34 +289,34 @@ discard block |
||
289 | 289 | * Event Start * |
290 | 290 | * =========== */ |
291 | 291 | |
292 | - if ( ! empty( $event['start'] ) ) { |
|
293 | - $this->start = is_numeric( $event['start'] ) ? intval( $event['start'] ) : 0; |
|
294 | - if ( ! empty( $event['start_utc'] ) ) { |
|
295 | - $this->start_utc = is_numeric( $event['start_utc'] ) ? intval( $event['start_utc'] ) : 0; |
|
292 | + if ( ! empty($event['start'])) { |
|
293 | + $this->start = is_numeric($event['start']) ? intval($event['start']) : 0; |
|
294 | + if ( ! empty($event['start_utc'])) { |
|
295 | + $this->start_utc = is_numeric($event['start_utc']) ? intval($event['start_utc']) : 0; |
|
296 | 296 | } |
297 | - if ( ! empty( $event['start_timezone'] ) ) { |
|
298 | - $this->start_timezone = esc_attr( $event['start_timezone'] ); |
|
297 | + if ( ! empty($event['start_timezone'])) { |
|
298 | + $this->start_timezone = esc_attr($event['start_timezone']); |
|
299 | 299 | } |
300 | - $this->start_dt = Carbon::createFromTimestamp( $this->start, $this->start_timezone ); |
|
301 | - $start_location = isset( $event['start_location'] ) ? $event['start_location'] : ''; |
|
302 | - $this->start_location = $this->esc_location( $start_location ); |
|
300 | + $this->start_dt = Carbon::createFromTimestamp($this->start, $this->start_timezone); |
|
301 | + $start_location = isset($event['start_location']) ? $event['start_location'] : ''; |
|
302 | + $this->start_location = $this->esc_location($start_location); |
|
303 | 303 | } |
304 | 304 | |
305 | 305 | /* ========= * |
306 | 306 | * Event End * |
307 | 307 | * ========= */ |
308 | 308 | |
309 | - if ( ! empty( $event['end'] ) ) { |
|
310 | - $this->end = is_numeric( $event['end'] ) ? intval( $event['end'] ): false; |
|
311 | - if ( ! empty( $event['end_timezone'] ) ) { |
|
312 | - $this->end_timezone = esc_attr( $event['end_timezone'] ); |
|
309 | + if ( ! empty($event['end'])) { |
|
310 | + $this->end = is_numeric($event['end']) ? intval($event['end']) : false; |
|
311 | + if ( ! empty($event['end_timezone'])) { |
|
312 | + $this->end_timezone = esc_attr($event['end_timezone']); |
|
313 | 313 | } |
314 | - if ( ! empty( $event['end_utc'] ) ) { |
|
315 | - $this->end_utc = is_numeric( $event['end_utc'] ) ? intval( $event['end_utc'] ) : false; |
|
316 | - $this->end_dt = Carbon::createFromTimestamp( $this->end, $this->end_timezone ); |
|
314 | + if ( ! empty($event['end_utc'])) { |
|
315 | + $this->end_utc = is_numeric($event['end_utc']) ? intval($event['end_utc']) : false; |
|
316 | + $this->end_dt = Carbon::createFromTimestamp($this->end, $this->end_timezone); |
|
317 | 317 | } |
318 | - $end_location = isset( $event['end_location'] ) ? $event['end_location'] : ''; |
|
319 | - $this->end_location = $this->esc_location( $end_location ); |
|
318 | + $end_location = isset($event['end_location']) ? $event['end_location'] : ''; |
|
319 | + $this->end_location = $this->esc_location($end_location); |
|
320 | 320 | } |
321 | 321 | |
322 | 322 | /* ================== * |
@@ -324,18 +324,18 @@ discard block |
||
324 | 324 | * ================== */ |
325 | 325 | |
326 | 326 | // Whole day event. |
327 | - if ( ! empty( $event['whole_day'] ) ) { |
|
328 | - $this->whole_day = true === $event['whole_day'] ? true: false; |
|
327 | + if ( ! empty($event['whole_day'])) { |
|
328 | + $this->whole_day = true === $event['whole_day'] ? true : false; |
|
329 | 329 | } |
330 | 330 | |
331 | 331 | // Multi day event. |
332 | - if ( ! empty( $event['multiple_days'] ) ) { |
|
333 | - $this->multiple_days = max( absint( $event['multiple_days'] ), 1 ); |
|
332 | + if ( ! empty($event['multiple_days'])) { |
|
333 | + $this->multiple_days = max(absint($event['multiple_days']), 1); |
|
334 | 334 | } |
335 | 335 | |
336 | 336 | // Event recurrence. |
337 | - if ( isset( $event['recurrence'] ) ) { |
|
338 | - $this->recurrence = ! empty( $event['recurrence'] ) ? $event['recurrence'] : false; |
|
337 | + if (isset($event['recurrence'])) { |
|
338 | + $this->recurrence = ! empty($event['recurrence']) ? $event['recurrence'] : false; |
|
339 | 339 | } |
340 | 340 | |
341 | 341 | /* ========== * |
@@ -343,18 +343,18 @@ discard block |
||
343 | 343 | * ========== */ |
344 | 344 | |
345 | 345 | // Event has venue(s). |
346 | - if ( $this->start_location['venue'] || $this->end_location['venue'] ) { |
|
346 | + if ($this->start_location['venue'] || $this->end_location['venue']) { |
|
347 | 347 | $this->venue = true; |
348 | 348 | } |
349 | 349 | |
350 | 350 | // Event meta. |
351 | - if ( ! empty( $event['meta'] ) ) { |
|
352 | - $this->meta = is_array( $event['meta'] ) ? $event['meta'] : array(); |
|
351 | + if ( ! empty($event['meta'])) { |
|
352 | + $this->meta = is_array($event['meta']) ? $event['meta'] : array(); |
|
353 | 353 | } |
354 | 354 | |
355 | 355 | // Event template. |
356 | - if ( ! empty( $event['template'] ) ) { |
|
357 | - $this->template = wp_kses_post( $event['template'] ); |
|
356 | + if ( ! empty($event['template'])) { |
|
357 | + $this->template = wp_kses_post($event['template']); |
|
358 | 358 | } |
359 | 359 | |
360 | 360 | } |
@@ -369,27 +369,27 @@ discard block |
||
369 | 369 | * |
370 | 370 | * @return array |
371 | 371 | */ |
372 | - private function esc_location( $var = '' ) { |
|
372 | + private function esc_location($var = '') { |
|
373 | 373 | |
374 | 374 | $location = array(); |
375 | 375 | |
376 | - if ( is_string( $var ) ) { |
|
376 | + if (is_string($var)) { |
|
377 | 377 | $var = array( |
378 | 378 | 'name' => $var, |
379 | 379 | 'address' => $var, |
380 | 380 | ); |
381 | - } elseif ( is_bool( $var ) || is_null( $var ) ) { |
|
381 | + } elseif (is_bool($var) || is_null($var)) { |
|
382 | 382 | $var = array(); |
383 | 383 | } else { |
384 | 384 | $var = (array) $var; |
385 | 385 | } |
386 | 386 | |
387 | - $location['name'] = isset( $var['name'] ) ? esc_attr( strip_tags( $var['name'] ) ) : ''; |
|
388 | - $location['address'] = isset( $var['address'] ) ? esc_attr( strip_tags( $var['address'] ) ) : ''; |
|
389 | - $location['lat'] = isset( $var['lat'] ) ? $this->esc_coordinate( $var['lat'] ) : 0; |
|
390 | - $location['lng'] = isset( $var['lng'] ) ? $this->esc_coordinate( $var['lng'] ) : 0; |
|
387 | + $location['name'] = isset($var['name']) ? esc_attr(strip_tags($var['name'])) : ''; |
|
388 | + $location['address'] = isset($var['address']) ? esc_attr(strip_tags($var['address'])) : ''; |
|
389 | + $location['lat'] = isset($var['lat']) ? $this->esc_coordinate($var['lat']) : 0; |
|
390 | + $location['lng'] = isset($var['lng']) ? $this->esc_coordinate($var['lng']) : 0; |
|
391 | 391 | |
392 | - if ( ! empty( $location['name'] ) || ! empty( $location['address'] ) ) { |
|
392 | + if ( ! empty($location['name']) || ! empty($location['address'])) { |
|
393 | 393 | $location['venue'] = true; |
394 | 394 | } else { |
395 | 395 | $location['venue'] = false; |
@@ -408,8 +408,8 @@ discard block |
||
408 | 408 | * |
409 | 409 | * @return int|float |
410 | 410 | */ |
411 | - private function esc_coordinate( $latlng = 0 ) { |
|
412 | - return is_numeric( $latlng ) ? floatval( $latlng ) : 0; |
|
411 | + private function esc_coordinate($latlng = 0) { |
|
412 | + return is_numeric($latlng) ? floatval($latlng) : 0; |
|
413 | 413 | } |
414 | 414 | |
415 | 415 | /** |
@@ -422,8 +422,8 @@ discard block |
||
422 | 422 | * |
423 | 423 | * @return bool |
424 | 424 | */ |
425 | - public function set_timezone( $tz ) { |
|
426 | - if ( in_array( $tz, timezone_identifiers_list() ) ) { |
|
425 | + public function set_timezone($tz) { |
|
426 | + if (in_array($tz, timezone_identifiers_list())) { |
|
427 | 427 | $this->timezone = $tz; |
428 | 428 | return true; |
429 | 429 | } |
@@ -449,7 +449,7 @@ discard block |
||
449 | 449 | * @return bool |
450 | 450 | */ |
451 | 451 | public function starts_today() { |
452 | - return $this->start_dt->setTimezone( $this->timezone )->isToday(); |
|
452 | + return $this->start_dt->setTimezone($this->timezone)->isToday(); |
|
453 | 453 | } |
454 | 454 | |
455 | 455 | /** |
@@ -460,7 +460,7 @@ discard block |
||
460 | 460 | * @return bool |
461 | 461 | */ |
462 | 462 | public function ends_today() { |
463 | - return ! is_null( $this->end_dt ) ? $this->end_dt->setTimezone( $this->timezone )->isToday() : true; |
|
463 | + return ! is_null($this->end_dt) ? $this->end_dt->setTimezone($this->timezone)->isToday() : true; |
|
464 | 464 | } |
465 | 465 | |
466 | 466 | /** |
@@ -471,7 +471,7 @@ discard block |
||
471 | 471 | * @return bool |
472 | 472 | */ |
473 | 473 | public function starts_tomorrow() { |
474 | - return $this->start_dt->setTimezone( $this->timezone )->isTomorrow(); |
|
474 | + return $this->start_dt->setTimezone($this->timezone)->isTomorrow(); |
|
475 | 475 | } |
476 | 476 | |
477 | 477 | /** |
@@ -482,7 +482,7 @@ discard block |
||
482 | 482 | * @return bool |
483 | 483 | */ |
484 | 484 | public function ends_tomorrow() { |
485 | - return ! is_null( $this->end_dt ) ? $this->end_dt->setTimezone( $this->timezone )->isTomorrow() : false; |
|
485 | + return ! is_null($this->end_dt) ? $this->end_dt->setTimezone($this->timezone)->isTomorrow() : false; |
|
486 | 486 | } |
487 | 487 | |
488 | 488 | /** |
@@ -493,7 +493,7 @@ discard block |
||
493 | 493 | * @return bool |
494 | 494 | */ |
495 | 495 | public function started_yesterday() { |
496 | - return $this->start_dt->setTimezone( $this->timezone )->isYesterday(); |
|
496 | + return $this->start_dt->setTimezone($this->timezone)->isYesterday(); |
|
497 | 497 | } |
498 | 498 | |
499 | 499 | /** |
@@ -504,7 +504,7 @@ discard block |
||
504 | 504 | * @return bool |
505 | 505 | */ |
506 | 506 | public function ended_yesterday() { |
507 | - return ! is_null( $this->end_dt ) ? $this->end_dt->setTimezone( $this->timezone )->isYesterday() : false; |
|
507 | + return ! is_null($this->end_dt) ? $this->end_dt->setTimezone($this->timezone)->isYesterday() : false; |
|
508 | 508 | } |
509 | 509 | |
510 | 510 | /** |
@@ -515,7 +515,7 @@ discard block |
||
515 | 515 | * @return bool |
516 | 516 | */ |
517 | 517 | public function starts_future() { |
518 | - return $this->start_dt->setTimezone( $this->timezone )->isFuture(); |
|
518 | + return $this->start_dt->setTimezone($this->timezone)->isFuture(); |
|
519 | 519 | } |
520 | 520 | |
521 | 521 | /** |
@@ -526,7 +526,7 @@ discard block |
||
526 | 526 | * @return bool |
527 | 527 | */ |
528 | 528 | public function ends_future() { |
529 | - return ! is_null( $this->end_dt ) ? $this->end_dt->setTimezone( $this->timezone )->isFuture() : false; |
|
529 | + return ! is_null($this->end_dt) ? $this->end_dt->setTimezone($this->timezone)->isFuture() : false; |
|
530 | 530 | } |
531 | 531 | |
532 | 532 | /** |
@@ -537,7 +537,7 @@ discard block |
||
537 | 537 | * @return bool |
538 | 538 | */ |
539 | 539 | public function started_past() { |
540 | - return $this->start_dt->setTimezone( $this->timezone )->isPast(); |
|
540 | + return $this->start_dt->setTimezone($this->timezone)->isPast(); |
|
541 | 541 | } |
542 | 542 | |
543 | 543 | /** |
@@ -548,7 +548,7 @@ discard block |
||
548 | 548 | * @return bool |
549 | 549 | */ |
550 | 550 | public function ended_past() { |
551 | - return ! is_null( $this->end_dt ) ? $this->end_dt->setTimezone( $this->timezone )->isPast() : false; |
|
551 | + return ! is_null($this->end_dt) ? $this->end_dt->setTimezone($this->timezone)->isPast() : false; |
|
552 | 552 | } |
553 | 553 | |
554 | 554 | /** |
@@ -560,9 +560,9 @@ discard block |
||
560 | 560 | * |
561 | 561 | * @return string |
562 | 562 | */ |
563 | - public function get_color( $default = '' ) { |
|
564 | - if ( isset( $this->meta['color'] ) ) { |
|
565 | - return ! empty( $this->meta['color'] ) ? esc_attr( $this->meta['color'] ) : $default; |
|
563 | + public function get_color($default = '') { |
|
564 | + if (isset($this->meta['color'])) { |
|
565 | + return ! empty($this->meta['color']) ? esc_attr($this->meta['color']) : $default; |
|
566 | 566 | } |
567 | 567 | return $default; |
568 | 568 | } |
@@ -575,7 +575,7 @@ discard block |
||
575 | 575 | * @return array |
576 | 576 | */ |
577 | 577 | public function get_attachments() { |
578 | - return isset( $this->meta['attachments'] ) ? $this->meta['attachments'] : array(); |
|
578 | + return isset($this->meta['attachments']) ? $this->meta['attachments'] : array(); |
|
579 | 579 | } |
580 | 580 | |
581 | 581 | /** |
@@ -586,7 +586,7 @@ discard block |
||
586 | 586 | * @return array |
587 | 587 | */ |
588 | 588 | public function get_attendees() { |
589 | - return isset( $this->meta['attendees'] ) ? $this->meta['attendees'] : array(); |
|
589 | + return isset($this->meta['attendees']) ? $this->meta['attendees'] : array(); |
|
590 | 590 | } |
591 | 591 | |
592 | 592 | /** |
@@ -597,7 +597,7 @@ discard block |
||
597 | 597 | * @return array |
598 | 598 | */ |
599 | 599 | public function get_organizer() { |
600 | - return isset( $this->meta['organizer'] ) ? $this->meta['organizer'] : array(); |
|
600 | + return isset($this->meta['organizer']) ? $this->meta['organizer'] : array(); |
|
601 | 601 | } |
602 | 602 | |
603 | 603 | } |
@@ -12,7 +12,7 @@ discard block |
||
12 | 12 | use SimpleCalendar\Abstracts\Feed; |
13 | 13 | use SimpleCalendar\Feeds\Admin\Google_Admin as Admin; |
14 | 14 | |
15 | -if ( ! defined( 'ABSPATH' ) ) { |
|
15 | +if ( ! defined('ABSPATH')) { |
|
16 | 16 | exit; |
17 | 17 | } |
18 | 18 | |
@@ -90,34 +90,34 @@ discard block |
||
90 | 90 | * @param string|Calendar $calendar |
91 | 91 | * @param bool $load_admin |
92 | 92 | */ |
93 | - public function __construct( $calendar = '', $load_admin = true ) { |
|
93 | + public function __construct($calendar = '', $load_admin = true) { |
|
94 | 94 | |
95 | - parent::__construct( $calendar ); |
|
95 | + parent::__construct($calendar); |
|
96 | 96 | |
97 | 97 | $this->type = 'google'; |
98 | - $this->name = __( 'Google Calendar', 'google-calendar-events' ); |
|
98 | + $this->name = __('Google Calendar', 'google-calendar-events'); |
|
99 | 99 | |
100 | 100 | // Google client config. |
101 | - $settings = get_option( 'simple-calendar_settings_feeds' ); |
|
102 | - $this->google_api_key = isset( $settings['google']['api_key'] ) ? esc_attr( $settings['google']['api_key'] ) : ''; |
|
103 | - $this->google_client_scopes = array( \Google_Service_Calendar::CALENDAR_READONLY ); |
|
101 | + $settings = get_option('simple-calendar_settings_feeds'); |
|
102 | + $this->google_api_key = isset($settings['google']['api_key']) ? esc_attr($settings['google']['api_key']) : ''; |
|
103 | + $this->google_client_scopes = array(\Google_Service_Calendar::CALENDAR_READONLY); |
|
104 | 104 | $this->google_client = $this->get_client(); |
105 | 105 | |
106 | - if ( $this->post_id > 0 ) { |
|
106 | + if ($this->post_id > 0) { |
|
107 | 107 | |
108 | 108 | // Google query args. |
109 | - $this->google_calendar_id = $this->esc_google_calendar_id( get_post_meta( $this->post_id, '_google_calendar_id', true ) ); |
|
110 | - $this->google_events_recurring = esc_attr( get_post_meta( $this->post_id, '_google_events_recurring', true ) ); |
|
111 | - $this->google_search_query = esc_attr( get_post_meta( $this->post_id, '_google_events_search_query', true ) ); |
|
112 | - $this->google_max_results = max( absint( get_post_meta( $this->post_id, '_google_events_max_results', true ) ), 1 ); |
|
109 | + $this->google_calendar_id = $this->esc_google_calendar_id(get_post_meta($this->post_id, '_google_calendar_id', true)); |
|
110 | + $this->google_events_recurring = esc_attr(get_post_meta($this->post_id, '_google_events_recurring', true)); |
|
111 | + $this->google_search_query = esc_attr(get_post_meta($this->post_id, '_google_events_search_query', true)); |
|
112 | + $this->google_max_results = max(absint(get_post_meta($this->post_id, '_google_events_max_results', true)), 1); |
|
113 | 113 | |
114 | - if ( ! is_admin() || defined( 'DOING_AJAX' ) ) { |
|
115 | - $this->events = ! empty( $this->google_api_key ) ? $this->get_events() : array(); |
|
114 | + if ( ! is_admin() || defined('DOING_AJAX')) { |
|
115 | + $this->events = ! empty($this->google_api_key) ? $this->get_events() : array(); |
|
116 | 116 | } |
117 | 117 | } |
118 | 118 | |
119 | - if ( is_admin() && $load_admin ) { |
|
120 | - $admin = new Admin( $this, $this->google_api_key, $this->google_calendar_id ); |
|
119 | + if (is_admin() && $load_admin) { |
|
120 | + $admin = new Admin($this, $this->google_api_key, $this->google_calendar_id); |
|
121 | 121 | $this->settings = $admin->settings_fields(); |
122 | 122 | } |
123 | 123 | } |
@@ -131,8 +131,8 @@ discard block |
||
131 | 131 | * |
132 | 132 | * @return string |
133 | 133 | */ |
134 | - public function esc_google_calendar_id( $id ) { |
|
135 | - return base64_decode( $id ); |
|
134 | + public function esc_google_calendar_id($id) { |
|
135 | + return base64_decode($id); |
|
136 | 136 | } |
137 | 137 | |
138 | 138 | /** |
@@ -146,59 +146,59 @@ discard block |
||
146 | 146 | */ |
147 | 147 | public function get_events() { |
148 | 148 | |
149 | - $calendar = get_transient( '_simple-calendar_feed_id_' . strval( $this->post_id ) . '_' . $this->type ); |
|
149 | + $calendar = get_transient('_simple-calendar_feed_id_'.strval($this->post_id).'_'.$this->type); |
|
150 | 150 | |
151 | - if ( empty( $calendar ) && ! empty( $this->google_calendar_id ) ) { |
|
151 | + if (empty($calendar) && ! empty($this->google_calendar_id)) { |
|
152 | 152 | |
153 | 153 | $error = ''; |
154 | 154 | |
155 | 155 | try { |
156 | - $response = $this->make_request( $this->google_calendar_id ); |
|
157 | - } catch ( \Exception $e ) { |
|
156 | + $response = $this->make_request($this->google_calendar_id); |
|
157 | + } catch (\Exception $e) { |
|
158 | 158 | $error .= $e->getMessage(); |
159 | 159 | } |
160 | 160 | |
161 | - if ( empty( $error ) && isset( $response['events'] ) && isset( $response['timezone'] ) ) { |
|
161 | + if (empty($error) && isset($response['events']) && isset($response['timezone'])) { |
|
162 | 162 | |
163 | - $calendar = array_merge( $response, array( 'events' => array() ) ); |
|
163 | + $calendar = array_merge($response, array('events' => array())); |
|
164 | 164 | |
165 | 165 | // If no timezone has been set, use calendar feed. |
166 | - if ( 'use_calendar' == $this->timezone_setting ) { |
|
166 | + if ('use_calendar' == $this->timezone_setting) { |
|
167 | 167 | $this->timezone = $calendar['timezone']; |
168 | 168 | } |
169 | 169 | |
170 | - $source = isset( $response['title'] ) ? sanitize_text_field( $response['title'] ) : ''; |
|
170 | + $source = isset($response['title']) ? sanitize_text_field($response['title']) : ''; |
|
171 | 171 | |
172 | - if ( ! empty( $response['events'] ) && is_array( $response['events'] ) ) { |
|
173 | - foreach ( $response['events'] as $event ) { |
|
174 | - if ( $event instanceof \Google_Service_Calendar_Event ) { |
|
172 | + if ( ! empty($response['events']) && is_array($response['events'])) { |
|
173 | + foreach ($response['events'] as $event) { |
|
174 | + if ($event instanceof \Google_Service_Calendar_Event) { |
|
175 | 175 | |
176 | 176 | // Visibility. |
177 | 177 | $visibility = $event->getVisibility(); |
178 | 178 | // Public calendars may have private events which can't be properly accessed by simple api key method. |
179 | - if ( $this->type == 'google' && ( $visibility == 'private' || $visibility == 'confidential' ) ) { |
|
179 | + if ($this->type == 'google' && ($visibility == 'private' || $visibility == 'confidential')) { |
|
180 | 180 | continue; |
181 | 181 | } |
182 | 182 | |
183 | 183 | // Event title & description. |
184 | - $title = strip_tags( $event->getSummary() ); |
|
185 | - $title = sanitize_text_field( iconv( mb_detect_encoding( $title, mb_detect_order(), true ), 'UTF-8', $title ) ); |
|
186 | - $description = wp_kses_post( iconv( mb_detect_encoding( $event->getDescription(), mb_detect_order(), true ), 'UTF-8', $event->getDescription() ) ); |
|
184 | + $title = strip_tags($event->getSummary()); |
|
185 | + $title = sanitize_text_field(iconv(mb_detect_encoding($title, mb_detect_order(), true), 'UTF-8', $title)); |
|
186 | + $description = wp_kses_post(iconv(mb_detect_encoding($event->getDescription(), mb_detect_order(), true), 'UTF-8', $event->getDescription())); |
|
187 | 187 | |
188 | 188 | $whole_day = false; |
189 | 189 | |
190 | 190 | // Event start properties. |
191 | 191 | $start_timezone = ! $event->getStart()->timeZone ? $calendar['timezone'] : $event->getStart()->timeZone; |
192 | - if ( is_null( $event->getStart()->dateTime ) ) { |
|
192 | + if (is_null($event->getStart()->dateTime)) { |
|
193 | 193 | // Whole day event. |
194 | - $date = Carbon::parse( $event->getStart()->date ); |
|
195 | - $google_start = Carbon::createFromDate( $date->year, $date->month, $date->day, $start_timezone )->startOfDay()->addSeconds( 59 ); |
|
196 | - $google_start_utc = Carbon::createFromDate( $date->year, $date->month, $date->day, 'UTC' )->startOfDay()->addSeconds( 59 ); |
|
194 | + $date = Carbon::parse($event->getStart()->date); |
|
195 | + $google_start = Carbon::createFromDate($date->year, $date->month, $date->day, $start_timezone)->startOfDay()->addSeconds(59); |
|
196 | + $google_start_utc = Carbon::createFromDate($date->year, $date->month, $date->day, 'UTC')->startOfDay()->addSeconds(59); |
|
197 | 197 | $whole_day = true; |
198 | 198 | } else { |
199 | - $date = Carbon::parse( $event->getStart()->dateTime ); |
|
200 | - $google_start = Carbon::create( $date->year, $date->month, $date->day, $date->hour, $date->minute, $date->second, $start_timezone ); |
|
201 | - $google_start_utc = Carbon::create( $date->year, $date->month, $date->day, $date->hour, $date->minute, $date->second, 'UTC' ); |
|
199 | + $date = Carbon::parse($event->getStart()->dateTime); |
|
200 | + $google_start = Carbon::create($date->year, $date->month, $date->day, $date->hour, $date->minute, $date->second, $start_timezone); |
|
201 | + $google_start_utc = Carbon::create($date->year, $date->month, $date->day, $date->hour, $date->minute, $date->second, 'UTC'); |
|
202 | 202 | } |
203 | 203 | // Start. |
204 | 204 | $start = $google_start->getTimestamp(); |
@@ -207,19 +207,19 @@ discard block |
||
207 | 207 | |
208 | 208 | $end = $end_utc = $end_timezone = ''; |
209 | 209 | $span = 0; |
210 | - if ( false == $event->getEndTimeUnspecified() ) { |
|
210 | + if (false == $event->getEndTimeUnspecified()) { |
|
211 | 211 | |
212 | 212 | // Event end properties. |
213 | 213 | $end_timezone = ! $event->getEnd()->timeZone ? $calendar['timezone'] : $event->getEnd()->timeZone; |
214 | - if ( is_null( $event->getEnd()->dateTime ) ) { |
|
214 | + if (is_null($event->getEnd()->dateTime)) { |
|
215 | 215 | // Whole day event. |
216 | - $date = Carbon::parse( $event->getEnd()->date ); |
|
217 | - $google_end = Carbon::createFromDate( $date->year, $date->month, $date->day, $end_timezone )->endOfDay()->subSeconds( 59 ); |
|
218 | - $google_end_utc = Carbon::createFromDate( $date->year, $date->month, $date->day, 'UTC' )->endOfDay()->subSeconds( 59 ); |
|
216 | + $date = Carbon::parse($event->getEnd()->date); |
|
217 | + $google_end = Carbon::createFromDate($date->year, $date->month, $date->day, $end_timezone)->endOfDay()->subSeconds(59); |
|
218 | + $google_end_utc = Carbon::createFromDate($date->year, $date->month, $date->day, 'UTC')->endOfDay()->subSeconds(59); |
|
219 | 219 | } else { |
220 | - $date = Carbon::parse( $event->getEnd()->dateTime ); |
|
221 | - $google_end = Carbon::create( $date->year, $date->month, $date->day, $date->hour, $date->minute, $date->second, $end_timezone ); |
|
222 | - $google_end_utc = Carbon::create( $date->year, $date->month, $date->day, $date->hour, $date->minute, $date->second, 'UTC' ); |
|
220 | + $date = Carbon::parse($event->getEnd()->dateTime); |
|
221 | + $google_end = Carbon::create($date->year, $date->month, $date->day, $date->hour, $date->minute, $date->second, $end_timezone); |
|
222 | + $google_end_utc = Carbon::create($date->year, $date->month, $date->day, $date->hour, $date->minute, $date->second, 'UTC'); |
|
223 | 223 | } |
224 | 224 | // End. |
225 | 225 | $end = $google_end->getTimestamp(); |
@@ -227,10 +227,10 @@ discard block |
||
227 | 227 | $end_utc = $google_end_utc->getTimestamp(); |
228 | 228 | |
229 | 229 | // Count multiple days. |
230 | - $span = $google_start->setTimezone( $calendar['timezone'] )->diffInDays( $google_end->setTimezone( $calendar['timezone'] ) ); |
|
230 | + $span = $google_start->setTimezone($calendar['timezone'])->diffInDays($google_end->setTimezone($calendar['timezone'])); |
|
231 | 231 | |
232 | - if ( $span == 0 ) { |
|
233 | - if ( $google_start->toDateString() !== $google_end->toDateString() ) { |
|
232 | + if ($span == 0) { |
|
233 | + if ($google_start->toDateString() !== $google_end->toDateString()) { |
|
234 | 234 | $span = 1; |
235 | 235 | } |
236 | 236 | } |
@@ -245,19 +245,19 @@ discard block |
||
245 | 245 | // Recurring event. |
246 | 246 | $recurrence = $event->getRecurrence(); |
247 | 247 | $recurring_id = $event->getRecurringEventId(); |
248 | - if ( ! $recurrence && $recurring_id ) { |
|
248 | + if ( ! $recurrence && $recurring_id) { |
|
249 | 249 | $recurrence = true; |
250 | 250 | } |
251 | 251 | |
252 | 252 | // Event link. |
253 | - if ( 'use_calendar' == $this->timezone_setting ) { |
|
254 | - $link = add_query_arg( array( 'ctz' => $this->timezone ), $event->getHtmlLink() ); |
|
253 | + if ('use_calendar' == $this->timezone_setting) { |
|
254 | + $link = add_query_arg(array('ctz' => $this->timezone), $event->getHtmlLink()); |
|
255 | 255 | } else { |
256 | 256 | $link = $event->getHtmlLink(); |
257 | 257 | } |
258 | 258 | |
259 | 259 | // Build the event. |
260 | - $calendar['events'][ intval( $start ) ][] = array( |
|
260 | + $calendar['events'][intval($start)][] = array( |
|
261 | 261 | 'type' => 'google-calendar', |
262 | 262 | 'source' => $source, |
263 | 263 | 'title' => $title, |
@@ -284,24 +284,24 @@ discard block |
||
284 | 284 | } |
285 | 285 | } |
286 | 286 | |
287 | - if ( ! empty( $calendar['events'] ) ) { |
|
287 | + if ( ! empty($calendar['events'])) { |
|
288 | 288 | |
289 | - ksort( $calendar['events'], SORT_NUMERIC ); |
|
289 | + ksort($calendar['events'], SORT_NUMERIC); |
|
290 | 290 | |
291 | 291 | set_transient( |
292 | - '_simple-calendar_feed_id_' . strval( $this->post_id ) . '_' . $this->type, |
|
292 | + '_simple-calendar_feed_id_'.strval($this->post_id).'_'.$this->type, |
|
293 | 293 | $calendar, |
294 | - max( absint( $this->cache ), 60 ) |
|
294 | + max(absint($this->cache), 60) |
|
295 | 295 | ); |
296 | 296 | } |
297 | 297 | } |
298 | 298 | |
299 | 299 | } else { |
300 | 300 | |
301 | - $message = __( 'While trying to retrieve events, Google returned an error:', 'google-calendar-events' ); |
|
302 | - $message .= '<br><br>' . $error . '<br><br>'; |
|
303 | - $message .= __( 'Please ensure that both your Google Calendar ID and API Key are valid and that the Google Calendar you want to display is public.', 'google-calendar-events' ) . '<br><br>'; |
|
304 | - $message .= __( 'Only you can see this notice.', 'google-calendar-events' ); |
|
301 | + $message = __('While trying to retrieve events, Google returned an error:', 'google-calendar-events'); |
|
302 | + $message .= '<br><br>'.$error.'<br><br>'; |
|
303 | + $message .= __('Please ensure that both your Google Calendar ID and API Key are valid and that the Google Calendar you want to display is public.', 'google-calendar-events').'<br><br>'; |
|
304 | + $message .= __('Only you can see this notice.', 'google-calendar-events'); |
|
305 | 305 | |
306 | 306 | return $message; |
307 | 307 | } |
@@ -309,11 +309,11 @@ discard block |
||
309 | 309 | } |
310 | 310 | |
311 | 311 | // If no timezone has been set, use calendar feed. |
312 | - if ( 'use_calendar' == $this->timezone_setting && isset( $calendar['timezone'] ) ) { |
|
312 | + if ('use_calendar' == $this->timezone_setting && isset($calendar['timezone'])) { |
|
313 | 313 | $this->timezone = $calendar['timezone']; |
314 | 314 | } |
315 | 315 | |
316 | - return isset( $calendar['events'] ) ? $calendar['events'] : array(); |
|
316 | + return isset($calendar['events']) ? $calendar['events'] : array(); |
|
317 | 317 | } |
318 | 318 | |
319 | 319 | /** |
@@ -329,67 +329,67 @@ discard block |
||
329 | 329 | * |
330 | 330 | * @throws \Exception On request failure will throw an exception from Google. |
331 | 331 | */ |
332 | - public function make_request( $id = '', $time_min = 0, $time_max = 0 ) { |
|
332 | + public function make_request($id = '', $time_min = 0, $time_max = 0) { |
|
333 | 333 | |
334 | 334 | $calendar = array(); |
335 | 335 | $google = $this->get_service(); |
336 | 336 | |
337 | - if ( ! is_null( $google ) && ! empty( $id ) ) { |
|
337 | + if ( ! is_null($google) && ! empty($id)) { |
|
338 | 338 | |
339 | 339 | // Build the request args. |
340 | 340 | $args = array(); |
341 | 341 | |
342 | 342 | // Expand recurring events. |
343 | - if ( $this->google_events_recurring == 'show' ) { |
|
343 | + if ($this->google_events_recurring == 'show') { |
|
344 | 344 | $args['singleEvents'] = true; |
345 | 345 | } |
346 | 346 | |
347 | 347 | // Query events using search terms. |
348 | - if ( ! empty( $this->google_search_query ) ) { |
|
349 | - $args['q'] = rawurlencode( $this->google_search_query ); |
|
348 | + if ( ! empty($this->google_search_query)) { |
|
349 | + $args['q'] = rawurlencode($this->google_search_query); |
|
350 | 350 | } |
351 | 351 | |
352 | 352 | // Max results to query. |
353 | - $args['maxResults'] = strval( min( absint( $this->google_max_results ), 2500 ) ); |
|
353 | + $args['maxResults'] = strval(min(absint($this->google_max_results), 2500)); |
|
354 | 354 | |
355 | 355 | // Specify a timezone. |
356 | 356 | $timezone = ''; |
357 | - if ( 'use_calendar' != get_post_meta( $this->post_id, '_feed_timezone_setting', true ) ) { |
|
357 | + if ('use_calendar' != get_post_meta($this->post_id, '_feed_timezone_setting', true)) { |
|
358 | 358 | $args['timeZone'] = $timezone = $this->timezone; |
359 | 359 | } |
360 | 360 | |
361 | 361 | // Lower bound (inclusive) for an event's end time to filter by. |
362 | - $earliest_event = intval( $this->time_min ); |
|
363 | - if ( $earliest_event > 0 ) { |
|
362 | + $earliest_event = intval($this->time_min); |
|
363 | + if ($earliest_event > 0) { |
|
364 | 364 | $timeMin = Carbon::now(); |
365 | - if ( ! empty( $timezone ) ) { |
|
366 | - $timeMin->setTimezone( $timezone ); |
|
365 | + if ( ! empty($timezone)) { |
|
366 | + $timeMin->setTimezone($timezone); |
|
367 | 367 | } |
368 | - $timeMin->setTimestamp( $earliest_event ); |
|
368 | + $timeMin->setTimestamp($earliest_event); |
|
369 | 369 | $args['timeMin'] = $timeMin->toRfc3339String(); |
370 | 370 | } |
371 | 371 | |
372 | 372 | // Upper bound (exclusive) for an event's start time to filter by. |
373 | - $latest_event = intval( $this->time_max ); |
|
374 | - if ( $latest_event > 0 ) { |
|
373 | + $latest_event = intval($this->time_max); |
|
374 | + if ($latest_event > 0) { |
|
375 | 375 | $timeMax = Carbon::now(); |
376 | - if ( ! empty( $timezone ) ) { |
|
377 | - $timeMax->setTimezone( $timezone ); |
|
376 | + if ( ! empty($timezone)) { |
|
377 | + $timeMax->setTimezone($timezone); |
|
378 | 378 | } |
379 | - $timeMax->setTimestamp( $latest_event ); |
|
379 | + $timeMax->setTimestamp($latest_event); |
|
380 | 380 | $args['timeMax'] = $timeMax->toRfc3339String(); |
381 | 381 | } |
382 | 382 | |
383 | 383 | // Query events in calendar. |
384 | - $response = $google->events->listEvents( $id, $args ); |
|
384 | + $response = $google->events->listEvents($id, $args); |
|
385 | 385 | |
386 | - if ( $response instanceof \Google_Service_Calendar_Events ) { |
|
386 | + if ($response instanceof \Google_Service_Calendar_Events) { |
|
387 | 387 | $calendar = array( |
388 | 388 | 'id' => $id, |
389 | 389 | 'title' => $response->getSummary(), |
390 | 390 | 'description' => $response->getDescription(), |
391 | 391 | 'timezone' => $response->getTimeZone(), |
392 | - 'url' => esc_url( '//www.google.com/calendar/embed?src=' . $id ), |
|
392 | + 'url' => esc_url('//www.google.com/calendar/embed?src='.$id), |
|
393 | 393 | 'events' => $response->getItems(), |
394 | 394 | ); |
395 | 395 | } |
@@ -409,10 +409,10 @@ discard block |
||
409 | 409 | private function get_client() { |
410 | 410 | |
411 | 411 | $client = new \Google_Client(); |
412 | - $client->setApplicationName( 'Simple Calendar' ); |
|
413 | - $client->setScopes( $this->google_client_scopes ); |
|
414 | - $client->setDeveloperKey( $this->google_api_key ); |
|
415 | - $client->setAccessType( 'online' ); |
|
412 | + $client->setApplicationName('Simple Calendar'); |
|
413 | + $client->setScopes($this->google_client_scopes); |
|
414 | + $client->setDeveloperKey($this->google_api_key); |
|
415 | + $client->setAccessType('online'); |
|
416 | 416 | |
417 | 417 | return $client; |
418 | 418 | } |
@@ -426,7 +426,7 @@ discard block |
||
426 | 426 | * @return null|\Google_Service_Calendar |
427 | 427 | */ |
428 | 428 | protected function get_service() { |
429 | - return $this->google_client instanceof \Google_Client ? new \Google_Service_Calendar( $this->google_client ) : null; |
|
429 | + return $this->google_client instanceof \Google_Client ? new \Google_Service_Calendar($this->google_client) : null; |
|
430 | 430 | } |
431 | 431 | |
432 | 432 | } |
@@ -10,7 +10,7 @@ discard block |
||
10 | 10 | use SimpleCalendar\Abstracts\Feed; |
11 | 11 | use SimpleCalendar\Feeds\Admin\Grouped_Calendars_Admin; |
12 | 12 | |
13 | -if ( ! defined( 'ABSPATH' ) ) { |
|
13 | +if ( ! defined('ABSPATH')) { |
|
14 | 14 | exit; |
15 | 15 | } |
16 | 16 | |
@@ -38,22 +38,22 @@ discard block |
||
38 | 38 | * |
39 | 39 | * @param string|Calendar $calendar |
40 | 40 | */ |
41 | - public function __construct( $calendar = '' ) { |
|
41 | + public function __construct($calendar = '') { |
|
42 | 42 | |
43 | - parent::__construct( $calendar ); |
|
43 | + parent::__construct($calendar); |
|
44 | 44 | |
45 | 45 | $this->type = 'grouped-calendars'; |
46 | - $this->name = __( 'Grouped Calendar', 'google-calendar-events' ); |
|
46 | + $this->name = __('Grouped Calendar', 'google-calendar-events'); |
|
47 | 47 | |
48 | - if ( $this->post_id > 0 ) { |
|
48 | + if ($this->post_id > 0) { |
|
49 | 49 | $this->set_source(); |
50 | - if ( ! is_admin() || defined( 'DOING_AJAX' ) ) { |
|
50 | + if ( ! is_admin() || defined('DOING_AJAX')) { |
|
51 | 51 | $this->events = $this->get_events(); |
52 | 52 | } |
53 | 53 | } |
54 | 54 | |
55 | - if ( is_admin() && ! defined( 'DOING_AJAX' ) ) { |
|
56 | - new Grouped_Calendars_Admin( $this ); |
|
55 | + if (is_admin() && ! defined('DOING_AJAX')) { |
|
56 | + new Grouped_Calendars_Admin($this); |
|
57 | 57 | } |
58 | 58 | } |
59 | 59 | |
@@ -64,38 +64,38 @@ discard block |
||
64 | 64 | * |
65 | 65 | * @param array $ids Array of calendar ids. |
66 | 66 | */ |
67 | - public function set_source( $ids = array() ) { |
|
67 | + public function set_source($ids = array()) { |
|
68 | 68 | |
69 | - $source = get_post_meta( $this->post_id, '_grouped_calendars_source', true ); |
|
69 | + $source = get_post_meta($this->post_id, '_grouped_calendars_source', true); |
|
70 | 70 | |
71 | - if ( 'ids' == $source ) { |
|
71 | + if ('ids' == $source) { |
|
72 | 72 | |
73 | - if ( empty( $ids ) ) { |
|
74 | - $ids = get_post_meta( $this->post_id, '_grouped_calendars_ids', true ); |
|
73 | + if (empty($ids)) { |
|
74 | + $ids = get_post_meta($this->post_id, '_grouped_calendars_ids', true); |
|
75 | 75 | } |
76 | 76 | |
77 | - $this->calendars_ids = ! empty( $ids ) && is_array( $ids ) ? array_map( 'absint', $ids ) : array(); |
|
77 | + $this->calendars_ids = ! empty($ids) && is_array($ids) ? array_map('absint', $ids) : array(); |
|
78 | 78 | |
79 | - } elseif ( 'category' == $source ) { |
|
79 | + } elseif ('category' == $source) { |
|
80 | 80 | |
81 | - $categories = get_post_meta( $this->post_id, '_grouped_calendars_category', true ); |
|
81 | + $categories = get_post_meta($this->post_id, '_grouped_calendars_category', true); |
|
82 | 82 | |
83 | - if ( $categories && is_array( $categories ) ) { |
|
83 | + if ($categories && is_array($categories)) { |
|
84 | 84 | |
85 | 85 | $tax_query = array( |
86 | 86 | 'taxonomy' => 'calendar_category', |
87 | 87 | 'field' => 'term_id', |
88 | - 'terms' => array_map( 'absint', $categories ), |
|
88 | + 'terms' => array_map('absint', $categories), |
|
89 | 89 | ); |
90 | 90 | |
91 | - $calendars = get_posts( array( |
|
91 | + $calendars = get_posts(array( |
|
92 | 92 | 'post_type' => 'calendar', |
93 | - 'tax_query' => array( $tax_query ), |
|
93 | + 'tax_query' => array($tax_query), |
|
94 | 94 | 'nopaging' => true, |
95 | 95 | 'fields' => 'ids', |
96 | - ) ); |
|
96 | + )); |
|
97 | 97 | |
98 | - $this->calendars_ids = ! empty( $calendars ) && is_array( $calendars ) ? $calendars : array(); |
|
98 | + $this->calendars_ids = ! empty($calendars) && is_array($calendars) ? $calendars : array(); |
|
99 | 99 | } |
100 | 100 | |
101 | 101 | } |
@@ -111,40 +111,40 @@ discard block |
||
111 | 111 | public function get_events() { |
112 | 112 | |
113 | 113 | $ids = $this->calendars_ids; |
114 | - $events = get_transient( '_simple-calendar_feed_id_' . strval( $this->post_id ) . '_' . $this->type ); |
|
114 | + $events = get_transient('_simple-calendar_feed_id_'.strval($this->post_id).'_'.$this->type); |
|
115 | 115 | |
116 | - if ( empty( $events ) && ! empty( $ids ) && is_array( $ids ) ) { |
|
116 | + if (empty($events) && ! empty($ids) && is_array($ids)) { |
|
117 | 117 | |
118 | 118 | $events = array(); |
119 | 119 | |
120 | - foreach ( $ids as $cal_id ) { |
|
120 | + foreach ($ids as $cal_id) { |
|
121 | 121 | |
122 | - $calendar = simcal_get_calendar( intval( $cal_id ) ); |
|
122 | + $calendar = simcal_get_calendar(intval($cal_id)); |
|
123 | 123 | |
124 | - if ( $calendar instanceof Calendar ) { |
|
125 | - $events = is_array( $calendar->events ) ? $events + $calendar->events : $events; |
|
124 | + if ($calendar instanceof Calendar) { |
|
125 | + $events = is_array($calendar->events) ? $events + $calendar->events : $events; |
|
126 | 126 | } |
127 | 127 | |
128 | 128 | } |
129 | 129 | |
130 | - if ( ! empty( $events ) ) { |
|
130 | + if ( ! empty($events)) { |
|
131 | 131 | |
132 | 132 | // Trim events to set the earliest one as specified in feed settings. |
133 | - $earliest_event = intval( $this->time_min ); |
|
134 | - if ( $earliest_event > 0 ) { |
|
135 | - $events = $this->array_filter_key( $events, array( $this, 'filter_events_before' ) ); |
|
133 | + $earliest_event = intval($this->time_min); |
|
134 | + if ($earliest_event > 0) { |
|
135 | + $events = $this->array_filter_key($events, array($this, 'filter_events_before')); |
|
136 | 136 | } |
137 | 137 | |
138 | 138 | // Trim events to set the latest one as specified in feed settings. |
139 | - $latest_event = intval( $this->time_max ); |
|
140 | - if ( $latest_event > 0 ) { |
|
141 | - $events = $this->array_filter_key( $events, array( $this, 'filter_events_after' ) ); |
|
139 | + $latest_event = intval($this->time_max); |
|
140 | + if ($latest_event > 0) { |
|
141 | + $events = $this->array_filter_key($events, array($this, 'filter_events_after')); |
|
142 | 142 | } |
143 | 143 | |
144 | 144 | set_transient( |
145 | - '_simple-calendar_feed_id_' . strval( $this->post_id ) . '_' . $this->type, |
|
145 | + '_simple-calendar_feed_id_'.strval($this->post_id).'_'.$this->type, |
|
146 | 146 | $events, |
147 | - absint( $this->cache ) |
|
147 | + absint($this->cache) |
|
148 | 148 | ); |
149 | 149 | } |
150 | 150 | |
@@ -166,9 +166,9 @@ discard block |
||
166 | 166 | * |
167 | 167 | * @return array |
168 | 168 | */ |
169 | - private function array_filter_key( array $array, $callback ) { |
|
170 | - $matched_keys = array_filter( array_keys( $array ), $callback ); |
|
171 | - return array_intersect_key( $array, array_flip( $matched_keys ) ); |
|
169 | + private function array_filter_key(array $array, $callback) { |
|
170 | + $matched_keys = array_filter(array_keys($array), $callback); |
|
171 | + return array_intersect_key($array, array_flip($matched_keys)); |
|
172 | 172 | } |
173 | 173 | |
174 | 174 | /** |
@@ -181,9 +181,9 @@ discard block |
||
181 | 181 | * |
182 | 182 | * @return bool |
183 | 183 | */ |
184 | - private function filter_events_before( $event ) { |
|
185 | - if ( $this->time_min !== 0 ) { |
|
186 | - return intval( $event ) > intval( $this->time_min ); |
|
184 | + private function filter_events_before($event) { |
|
185 | + if ($this->time_min !== 0) { |
|
186 | + return intval($event) > intval($this->time_min); |
|
187 | 187 | } |
188 | 188 | return true; |
189 | 189 | } |
@@ -198,9 +198,9 @@ discard block |
||
198 | 198 | * |
199 | 199 | * @return bool |
200 | 200 | */ |
201 | - private function filter_events_after( $event ) { |
|
202 | - if ( $this->time_max !== 0 ) { |
|
203 | - return intval( $event ) < intval( $this->time_max ); |
|
201 | + private function filter_events_after($event) { |
|
202 | + if ($this->time_max !== 0) { |
|
203 | + return intval($event) < intval($this->time_max); |
|
204 | 204 | } |
205 | 205 | return true; |
206 | 206 | } |