@@ -6,7 +6,6 @@ |
||
| 6 | 6 | */ |
| 7 | 7 | namespace SimpleCalendar\Calendars; |
| 8 | 8 | |
| 9 | -use Carbon\Carbon; |
|
| 10 | 9 | use SimpleCalendar\Abstracts\Calendar; |
| 11 | 10 | use SimpleCalendar\Abstracts\Calendar_View; |
| 12 | 11 | use SimpleCalendar\Calendars\Admin\Default_Calendar_Admin; |
@@ -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; |
@@ -7,7 +7,6 @@ |
||
| 7 | 7 | namespace SimpleCalendar\Feeds; |
| 8 | 8 | |
| 9 | 9 | use Carbon\Carbon; |
| 10 | -use Carbon\CarbonInterval; |
|
| 11 | 10 | use SimpleCalendar\Abstracts\Calendar; |
| 12 | 11 | use SimpleCalendar\Abstracts\Feed; |
| 13 | 12 | use SimpleCalendar\Feeds\Admin\Google_Admin as Admin; |
@@ -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 | } |
@@ -6,8 +6,6 @@ |
||
| 6 | 6 | */ |
| 7 | 7 | namespace SimpleCalendar; |
| 8 | 8 | |
| 9 | -use SimpleCalendar\Admin\License_Manager; |
|
| 10 | - |
|
| 11 | 9 | if ( ! defined( 'ABSPATH' ) ) { |
| 12 | 10 | exit; |
| 13 | 11 | } |
@@ -8,7 +8,7 @@ discard block |
||
| 8 | 8 | |
| 9 | 9 | use SimpleCalendar\Admin\License_Manager; |
| 10 | 10 | |
| 11 | -if ( ! defined( 'ABSPATH' ) ) { |
|
| 11 | +if ( ! defined('ABSPATH')) { |
|
| 12 | 12 | exit; |
| 13 | 13 | } |
| 14 | 14 | |
@@ -71,7 +71,7 @@ discard block |
||
| 71 | 71 | * @return Plugin |
| 72 | 72 | */ |
| 73 | 73 | public static function get_instance() { |
| 74 | - if ( is_null( self::$_instance ) ) { |
|
| 74 | + if (is_null(self::$_instance)) { |
|
| 75 | 75 | self::$_instance = new self(); |
| 76 | 76 | } |
| 77 | 77 | return self::$_instance; |
@@ -81,14 +81,14 @@ discard block |
||
| 81 | 81 | * Cloning is forbidden. |
| 82 | 82 | */ |
| 83 | 83 | public function __clone() { |
| 84 | - _doing_it_wrong( __FUNCTION__, 'Cloning the main instance of this plugin is forbidden.', '1.0.0' ); |
|
| 84 | + _doing_it_wrong(__FUNCTION__, 'Cloning the main instance of this plugin is forbidden.', '1.0.0'); |
|
| 85 | 85 | } |
| 86 | 86 | |
| 87 | 87 | /** |
| 88 | 88 | * Unserializing instances of this class is forbidden. |
| 89 | 89 | */ |
| 90 | 90 | public function __wakeup() { |
| 91 | - _doing_it_wrong( __FUNCTION__, 'Unserializing instances of this plugin is forbidden.', '1.0.0' ); |
|
| 91 | + _doing_it_wrong(__FUNCTION__, 'Unserializing instances of this plugin is forbidden.', '1.0.0'); |
|
| 92 | 92 | } |
| 93 | 93 | |
| 94 | 94 | /** |
@@ -100,22 +100,22 @@ discard block |
||
| 100 | 100 | |
| 101 | 101 | // Load plugin. |
| 102 | 102 | require_once 'autoload.php'; |
| 103 | - $this->locale = apply_filters( 'plugin_locale', get_locale(), 'google-calendar-events' ); |
|
| 103 | + $this->locale = apply_filters('plugin_locale', get_locale(), 'google-calendar-events'); |
|
| 104 | 104 | $this->load(); |
| 105 | 105 | |
| 106 | 106 | // Installation hooks. |
| 107 | - register_activation_hook( SIMPLE_CALENDAR_MAIN_FILE, array( 'SimpleCalendar\Installation', 'activate' ) ); |
|
| 108 | - register_deactivation_hook( SIMPLE_CALENDAR_MAIN_FILE, array( 'SimpleCalendar\Installation', 'deactivate' ) ); |
|
| 107 | + register_activation_hook(SIMPLE_CALENDAR_MAIN_FILE, array('SimpleCalendar\Installation', 'activate')); |
|
| 108 | + register_deactivation_hook(SIMPLE_CALENDAR_MAIN_FILE, array('SimpleCalendar\Installation', 'deactivate')); |
|
| 109 | 109 | |
| 110 | 110 | // Do update call here. |
| 111 | - add_action( 'admin_init', array( $this, 'update' ), 999 ); |
|
| 111 | + add_action('admin_init', array($this, 'update'), 999); |
|
| 112 | 112 | |
| 113 | 113 | // Init hooks. |
| 114 | - add_action( 'init', array( $this, 'init' ), 5 ); |
|
| 115 | - add_action( 'admin_init', array( $this, 'register_settings' ), 5 ); |
|
| 114 | + add_action('init', array($this, 'init'), 5); |
|
| 115 | + add_action('admin_init', array($this, 'register_settings'), 5); |
|
| 116 | 116 | |
| 117 | 117 | // Upon plugin loaded action hook. |
| 118 | - do_action( 'simcal_loaded' ); |
|
| 118 | + do_action('simcal_loaded'); |
|
| 119 | 119 | } |
| 120 | 120 | |
| 121 | 121 | /** |
@@ -132,7 +132,7 @@ discard block |
||
| 132 | 132 | new Post_Types(); |
| 133 | 133 | |
| 134 | 134 | // Load back end. |
| 135 | - if ( is_admin() ) { |
|
| 135 | + if (is_admin()) { |
|
| 136 | 136 | $this->load_admin(); |
| 137 | 137 | } else { |
| 138 | 138 | // Load front end scripts and styles. |
@@ -174,7 +174,7 @@ discard block |
||
| 174 | 174 | // Init menus and settings. |
| 175 | 175 | new Admin\Menus(); |
| 176 | 176 | |
| 177 | - if ( defined( 'DOING_AJAX' ) ) { |
|
| 177 | + if (defined('DOING_AJAX')) { |
|
| 178 | 178 | // Admin ajax callbacks. |
| 179 | 179 | new Admin\Ajax(); |
| 180 | 180 | } |
@@ -188,16 +188,16 @@ discard block |
||
| 188 | 188 | public function init() { |
| 189 | 189 | |
| 190 | 190 | // Before init action hook. |
| 191 | - do_action( 'before_simcal_init' ); |
|
| 191 | + do_action('before_simcal_init'); |
|
| 192 | 192 | |
| 193 | 193 | // Set up localization. |
| 194 | - load_plugin_textdomain( 'google-calendar-events', false, dirname( plugin_basename( SIMPLE_CALENDAR_MAIN_FILE ) ) . '/languages/' ); |
|
| 194 | + load_plugin_textdomain('google-calendar-events', false, dirname(plugin_basename(SIMPLE_CALENDAR_MAIN_FILE)).'/languages/'); |
|
| 195 | 195 | |
| 196 | 196 | // Init objects factory. |
| 197 | 197 | $this->objects = new Objects(); |
| 198 | 198 | |
| 199 | 199 | // Upon init action hook. |
| 200 | - do_action( 'simcal_init' ); |
|
| 200 | + do_action('simcal_init'); |
|
| 201 | 201 | } |
| 202 | 202 | |
| 203 | 203 | /** |
@@ -206,9 +206,9 @@ discard block |
||
| 206 | 206 | * @since 3.0.0 |
| 207 | 207 | */ |
| 208 | 208 | public function register_settings() { |
| 209 | - if ( is_admin() && ! defined( 'DOING_AJAX' ) ) { |
|
| 209 | + if (is_admin() && ! defined('DOING_AJAX')) { |
|
| 210 | 210 | $settings = new Admin\Pages(); |
| 211 | - $settings->register_settings( $settings->get_settings() ); |
|
| 211 | + $settings->register_settings($settings->get_settings()); |
|
| 212 | 212 | } |
| 213 | 213 | } |
| 214 | 214 | |
@@ -220,7 +220,7 @@ discard block |
||
| 220 | 220 | * @return string |
| 221 | 221 | */ |
| 222 | 222 | public function ajax_url() { |
| 223 | - return admin_url( 'admin-ajax.php', 'relative' ); |
|
| 223 | + return admin_url('admin-ajax.php', 'relative'); |
|
| 224 | 224 | } |
| 225 | 225 | |
| 226 | 226 | /** |
@@ -232,15 +232,15 @@ discard block |
||
| 232 | 232 | * |
| 233 | 233 | * @return string |
| 234 | 234 | */ |
| 235 | - public function get_url( $case ) { |
|
| 236 | - switch ( $case ) { |
|
| 235 | + public function get_url($case) { |
|
| 236 | + switch ($case) { |
|
| 237 | 237 | case 'codex' : |
| 238 | 238 | case 'apidocs' : |
| 239 | 239 | return 'http://codex.simplecalendar.io'; |
| 240 | 240 | case 'add-ons' : |
| 241 | - return self::$homepage . '/addons/'; |
|
| 241 | + return self::$homepage.'/addons/'; |
|
| 242 | 242 | case 'gcal-pro' : |
| 243 | - return self::$homepage . '/addons/google-calendar-pro/'; |
|
| 243 | + return self::$homepage.'/addons/google-calendar-pro/'; |
|
| 244 | 244 | case 'docs' : |
| 245 | 245 | return 'http://docs.simplecalendar.io'; |
| 246 | 246 | case 'github' : |
@@ -260,7 +260,7 @@ discard block |
||
| 260 | 260 | * @since 3.0.0 |
| 261 | 261 | */ |
| 262 | 262 | public static function update() { |
| 263 | - $update = new Update( SIMPLE_CALENDAR_VERSION ); |
|
| 263 | + $update = new Update(SIMPLE_CALENDAR_VERSION); |
|
| 264 | 264 | } |
| 265 | 265 | |
| 266 | 266 | } |
@@ -14,38 +14,38 @@ discard block |
||
| 14 | 14 | */ |
| 15 | 15 | |
| 16 | 16 | // Exit if accessed directly. |
| 17 | -if ( ! defined( 'ABSPATH' ) ) { |
|
| 17 | +if ( ! defined('ABSPATH')) { |
|
| 18 | 18 | exit; |
| 19 | 19 | } |
| 20 | 20 | |
| 21 | 21 | // Composer fallback for PHP < 5.3.0. |
| 22 | -if ( version_compare( PHP_VERSION, '5.3.0' ) === -1 ) { |
|
| 22 | +if (version_compare(PHP_VERSION, '5.3.0') === -1) { |
|
| 23 | 23 | include_once 'vendor/autoload_52.php'; |
| 24 | 24 | } else { |
| 25 | 25 | include_once 'vendor/autoload.php'; |
| 26 | 26 | } |
| 27 | 27 | |
| 28 | 28 | // Plugin constants. |
| 29 | -$this_plugin_path = trailingslashit( dirname( __FILE__ ) ); |
|
| 30 | -$this_plugin_dir = plugin_dir_url( __FILE__ ); |
|
| 29 | +$this_plugin_path = trailingslashit(dirname(__FILE__)); |
|
| 30 | +$this_plugin_dir = plugin_dir_url(__FILE__); |
|
| 31 | 31 | $this_plugin_constants = array( |
| 32 | 32 | 'SIMPLE_CALENDAR_VERSION' => '3.0.6', |
| 33 | 33 | 'SIMPLE_CALENDAR_MAIN_FILE' => __FILE__, |
| 34 | 34 | 'SIMPLE_CALENDAR_URL' => $this_plugin_dir, |
| 35 | - 'SIMPLE_CALENDAR_ASSETS' => $this_plugin_dir . 'assets/', |
|
| 35 | + 'SIMPLE_CALENDAR_ASSETS' => $this_plugin_dir.'assets/', |
|
| 36 | 36 | 'SIMPLE_CALENDAR_PATH' => $this_plugin_path, |
| 37 | - 'SIMPLE_CALENDAR_INC' => $this_plugin_path . 'includes/', |
|
| 37 | + 'SIMPLE_CALENDAR_INC' => $this_plugin_path.'includes/', |
|
| 38 | 38 | ); |
| 39 | -foreach ( $this_plugin_constants as $constant => $value ) { |
|
| 40 | - if ( ! defined( $constant ) ) { |
|
| 41 | - define( $constant, $value ); |
|
| 39 | +foreach ($this_plugin_constants as $constant => $value) { |
|
| 40 | + if ( ! defined($constant)) { |
|
| 41 | + define($constant, $value); |
|
| 42 | 42 | } |
| 43 | 43 | } |
| 44 | 44 | |
| 45 | 45 | // Check plugin requirements before loading plugin. |
| 46 | 46 | $this_plugin_checks = new WP_Requirements( |
| 47 | 47 | 'Simple Calendar', |
| 48 | - plugin_basename( __FILE__ ), |
|
| 48 | + plugin_basename(__FILE__), |
|
| 49 | 49 | array( |
| 50 | 50 | 'PHP' => '5.3.0', |
| 51 | 51 | 'WordPress' => '4.0.0', |
@@ -55,7 +55,7 @@ discard block |
||
| 55 | 55 | ) |
| 56 | 56 | ) |
| 57 | 57 | ); |
| 58 | -if ( $this_plugin_checks->pass() === false ) { |
|
| 58 | +if ($this_plugin_checks->pass() === false) { |
|
| 59 | 59 | $this_plugin_checks->halt(); |
| 60 | 60 | return; |
| 61 | 61 | } |
@@ -6,7 +6,7 @@ discard block |
||
| 6 | 6 | */ |
| 7 | 7 | namespace SimpleCalendar\Abstracts; |
| 8 | 8 | |
| 9 | -if ( ! defined( 'ABSPATH' ) ) { |
|
| 9 | +if ( ! defined('ABSPATH')) { |
|
| 10 | 10 | exit; |
| 11 | 11 | } |
| 12 | 12 | |
@@ -84,27 +84,27 @@ discard block |
||
| 84 | 84 | |
| 85 | 85 | $settings = array(); |
| 86 | 86 | |
| 87 | - $settings[ $this->id ] = array( |
|
| 87 | + $settings[$this->id] = array( |
|
| 88 | 88 | 'label' => $this->label, |
| 89 | 89 | 'description' => $this->description, |
| 90 | 90 | ); |
| 91 | 91 | |
| 92 | - if ( ! empty( $this->sections ) && is_array( $this->sections ) ) { |
|
| 92 | + if ( ! empty($this->sections) && is_array($this->sections)) { |
|
| 93 | 93 | |
| 94 | - foreach ( $this->sections as $section => $content ) { |
|
| 94 | + foreach ($this->sections as $section => $content) { |
|
| 95 | 95 | |
| 96 | - $settings[ $this->id ]['sections'][ $section ] = array( |
|
| 97 | - 'title' => isset( $content['title'] ) ? $content['title'] : '', |
|
| 98 | - 'description' => isset( $content['description'] ) ? $content['description'] : '', |
|
| 99 | - 'callback' => array( $this, 'add_settings_section_callback' ), |
|
| 100 | - 'fields' => isset( $this->fields[ $section ] ) ? $this->fields[ $section ] : '', |
|
| 96 | + $settings[$this->id]['sections'][$section] = array( |
|
| 97 | + 'title' => isset($content['title']) ? $content['title'] : '', |
|
| 98 | + 'description' => isset($content['description']) ? $content['description'] : '', |
|
| 99 | + 'callback' => array($this, 'add_settings_section_callback'), |
|
| 100 | + 'fields' => isset($this->fields[$section]) ? $this->fields[$section] : '', |
|
| 101 | 101 | ); |
| 102 | 102 | |
| 103 | 103 | } |
| 104 | 104 | |
| 105 | 105 | } |
| 106 | 106 | |
| 107 | - return apply_filters( 'simcal_get_' . $this->option_group . '_' . $this->id , $settings ); |
|
| 107 | + return apply_filters('simcal_get_'.$this->option_group.'_'.$this->id, $settings); |
|
| 108 | 108 | } |
| 109 | 109 | |
| 110 | 110 | /** |
@@ -118,12 +118,12 @@ discard block |
||
| 118 | 118 | * |
| 119 | 119 | * @return string |
| 120 | 120 | */ |
| 121 | - protected function get_option_value( $section, $setting ) { |
|
| 121 | + protected function get_option_value($section, $setting) { |
|
| 122 | 122 | |
| 123 | 123 | $option = $this->values; |
| 124 | 124 | |
| 125 | - if ( ! empty( $option ) && is_array( $option ) ) { |
|
| 126 | - return isset( $option[ $section ][ $setting ] ) ? $option[ $section ][ $setting ] : ''; |
|
| 125 | + if ( ! empty($option) && is_array($option)) { |
|
| 126 | + return isset($option[$section][$setting]) ? $option[$section][$setting] : ''; |
|
| 127 | 127 | } |
| 128 | 128 | |
| 129 | 129 | return ''; |
@@ -156,14 +156,14 @@ discard block |
||
| 156 | 156 | * |
| 157 | 157 | * @return string |
| 158 | 158 | */ |
| 159 | - public function add_settings_section_callback( $section ) { |
|
| 159 | + public function add_settings_section_callback($section) { |
|
| 160 | 160 | |
| 161 | - $callback = isset( $section['callback'][0] ) ? $section['callback'][0] : ''; |
|
| 162 | - $sections = isset( $callback->sections ) ? $callback->sections : ''; |
|
| 163 | - $description = isset( $sections[ $section['id'] ]['description'] ) ? $sections[ $section['id'] ]['description'] : ''; |
|
| 164 | - $default = $description ? '<p>' . $description . '</p>' : ''; |
|
| 161 | + $callback = isset($section['callback'][0]) ? $section['callback'][0] : ''; |
|
| 162 | + $sections = isset($callback->sections) ? $callback->sections : ''; |
|
| 163 | + $description = isset($sections[$section['id']]['description']) ? $sections[$section['id']]['description'] : ''; |
|
| 164 | + $default = $description ? '<p>'.$description.'</p>' : ''; |
|
| 165 | 165 | |
| 166 | - echo apply_filters( 'simcal_' . $this->option_group . '_' . $this->id . '_sections_callback', $default ); |
|
| 166 | + echo apply_filters('simcal_'.$this->option_group.'_'.$this->id.'_sections_callback', $default); |
|
| 167 | 167 | } |
| 168 | 168 | |
| 169 | 169 | /** |
@@ -177,16 +177,16 @@ discard block |
||
| 177 | 177 | * |
| 178 | 178 | * @return array Sanitized settings. |
| 179 | 179 | */ |
| 180 | - public function validate( $settings ) { |
|
| 180 | + public function validate($settings) { |
|
| 181 | 181 | |
| 182 | 182 | $sanitized = ''; |
| 183 | 183 | |
| 184 | - if ( is_array( $settings ) ) { |
|
| 185 | - foreach ( $settings as $k => $v ) { |
|
| 186 | - $sanitized[ $k ] = simcal_sanitize_input( $v ); |
|
| 184 | + if (is_array($settings)) { |
|
| 185 | + foreach ($settings as $k => $v) { |
|
| 186 | + $sanitized[$k] = simcal_sanitize_input($v); |
|
| 187 | 187 | } |
| 188 | 188 | } else { |
| 189 | - $sanitized = simcal_sanitize_input( $settings ); |
|
| 189 | + $sanitized = simcal_sanitize_input($settings); |
|
| 190 | 190 | } |
| 191 | 191 | |
| 192 | 192 | return $sanitized; |
@@ -6,7 +6,7 @@ discard block |
||
| 6 | 6 | */ |
| 7 | 7 | namespace SimpleCalendar\Abstracts; |
| 8 | 8 | |
| 9 | -if ( ! defined( 'ABSPATH' ) ) { |
|
| 9 | +if ( ! defined('ABSPATH')) { |
|
| 10 | 10 | exit; |
| 11 | 11 | } |
| 12 | 12 | |
@@ -26,7 +26,7 @@ discard block |
||
| 26 | 26 | * |
| 27 | 27 | * @param mixed $args |
| 28 | 28 | */ |
| 29 | - public function __construct( $args = '' ); |
|
| 29 | + public function __construct($args = ''); |
|
| 30 | 30 | |
| 31 | 31 | /** |
| 32 | 32 | * Return the parent calendar type. |
@@ -75,7 +75,7 @@ discard block |
||
| 75 | 75 | * |
| 76 | 76 | * @return array |
| 77 | 77 | */ |
| 78 | - public function scripts( $min = '' ); |
|
| 78 | + public function scripts($min = ''); |
|
| 79 | 79 | |
| 80 | 80 | /** |
| 81 | 81 | * Styles. |
@@ -88,7 +88,7 @@ discard block |
||
| 88 | 88 | * |
| 89 | 89 | * @return array |
| 90 | 90 | */ |
| 91 | - public function styles( $min = '' ); |
|
| 91 | + public function styles($min = ''); |
|
| 92 | 92 | |
| 93 | 93 | /** |
| 94 | 94 | * Print HTML. |
@@ -11,7 +11,7 @@ discard block |
||
| 11 | 11 | use SimpleCalendar\Events\Event_Builder; |
| 12 | 12 | use SimpleCalendar\Events\Events; |
| 13 | 13 | |
| 14 | -if ( ! defined( 'ABSPATH' ) ) { |
|
| 14 | +if ( ! defined('ABSPATH')) { |
|
| 15 | 15 | exit; |
| 16 | 16 | } |
| 17 | 17 | |
@@ -234,12 +234,12 @@ discard block |
||
| 234 | 234 | * @param int|object|\WP_Post|Calendar $calendar |
| 235 | 235 | * @param string $view |
| 236 | 236 | */ |
| 237 | - public function __construct( $calendar, $view = '' ) { |
|
| 237 | + public function __construct($calendar, $view = '') { |
|
| 238 | 238 | |
| 239 | 239 | // Set the post object. |
| 240 | - $this->set_post_object( $calendar ); |
|
| 240 | + $this->set_post_object($calendar); |
|
| 241 | 241 | |
| 242 | - if ( ! is_null( $this->post ) ) { |
|
| 242 | + if ( ! is_null($this->post)) { |
|
| 243 | 243 | |
| 244 | 244 | // Set calendar type and events source. |
| 245 | 245 | $this->set_taxonomies(); |
@@ -256,23 +256,23 @@ discard block |
||
| 256 | 256 | $this->set_events_template(); |
| 257 | 257 | |
| 258 | 258 | // Get events source data. |
| 259 | - $feed = simcal_get_feed( $this ); |
|
| 260 | - if ( $feed instanceof Feed ) { |
|
| 261 | - if ( ! empty( $feed->events ) ) { |
|
| 262 | - if ( is_array( $feed->events ) ) { |
|
| 263 | - $this->set_events( $feed->events ); |
|
| 264 | - if ( 'use_calendar' == get_post_meta( $this->id, '_feed_timezone_setting', true ) ) { |
|
| 259 | + $feed = simcal_get_feed($this); |
|
| 260 | + if ($feed instanceof Feed) { |
|
| 261 | + if ( ! empty($feed->events)) { |
|
| 262 | + if (is_array($feed->events)) { |
|
| 263 | + $this->set_events($feed->events); |
|
| 264 | + if ('use_calendar' == get_post_meta($this->id, '_feed_timezone_setting', true)) { |
|
| 265 | 265 | $this->timezone = $feed->timezone; |
| 266 | - $this->set_start( $feed->timezone ); |
|
| 266 | + $this->set_start($feed->timezone); |
|
| 267 | 267 | } |
| 268 | - } elseif ( is_string( $feed->events ) ) { |
|
| 268 | + } elseif (is_string($feed->events)) { |
|
| 269 | 269 | $this->errors[] = $feed->events; |
| 270 | 270 | } |
| 271 | 271 | } |
| 272 | 272 | } |
| 273 | 273 | |
| 274 | 274 | // Set general purpose timestamps. |
| 275 | - $now = Carbon::now( $this->timezone ); |
|
| 275 | + $now = Carbon::now($this->timezone); |
|
| 276 | 276 | $this->now = $now->getTimestamp(); |
| 277 | 277 | $this->today = $now->startOfDay()->getTimestamp(); |
| 278 | 278 | $this->offset = $now->getOffset(); |
@@ -283,26 +283,26 @@ discard block |
||
| 283 | 283 | $this->set_datetime_separator(); |
| 284 | 284 | |
| 285 | 285 | // Set earliest and latest event timestamps. |
| 286 | - if ( $this->events && is_array( $this->events ) ) { |
|
| 287 | - $this->earliest_event = intval( current( array_keys( $this->events ) ) ); |
|
| 288 | - $this->latest_event = intval( key( array_slice( $this->events, -1, 1, true ) ) ); |
|
| 286 | + if ($this->events && is_array($this->events)) { |
|
| 287 | + $this->earliest_event = intval(current(array_keys($this->events))); |
|
| 288 | + $this->latest_event = intval(key(array_slice($this->events, -1, 1, true))); |
|
| 289 | 289 | } |
| 290 | 290 | |
| 291 | 291 | // Set calendar end. |
| 292 | 292 | $this->set_end(); |
| 293 | 293 | |
| 294 | 294 | // Set view. |
| 295 | - if ( ! $view ) { |
|
| 295 | + if ( ! $view) { |
|
| 296 | 296 | |
| 297 | - $calendar_view = get_post_meta( $this->id, '_calendar_view', true ); |
|
| 298 | - $calendar_view = isset( $calendar_view[ $this->type ] ) ? $calendar_view[ $this->type ] : ''; |
|
| 297 | + $calendar_view = get_post_meta($this->id, '_calendar_view', true); |
|
| 298 | + $calendar_view = isset($calendar_view[$this->type]) ? $calendar_view[$this->type] : ''; |
|
| 299 | 299 | |
| 300 | - $view = esc_attr( $calendar_view ); |
|
| 300 | + $view = esc_attr($calendar_view); |
|
| 301 | 301 | } |
| 302 | 302 | } |
| 303 | 303 | |
| 304 | 304 | // Get view. |
| 305 | - $this->view = $this->get_view( $view ); |
|
| 305 | + $this->view = $this->get_view($view); |
|
| 306 | 306 | } |
| 307 | 307 | |
| 308 | 308 | /** |
@@ -314,8 +314,8 @@ discard block |
||
| 314 | 314 | * |
| 315 | 315 | * @return bool |
| 316 | 316 | */ |
| 317 | - public function __isset( $key ) { |
|
| 318 | - return metadata_exists( 'post', $this->id, '_' . $key ); |
|
| 317 | + public function __isset($key) { |
|
| 318 | + return metadata_exists('post', $this->id, '_'.$key); |
|
| 319 | 319 | } |
| 320 | 320 | |
| 321 | 321 | /** |
@@ -327,9 +327,9 @@ discard block |
||
| 327 | 327 | * |
| 328 | 328 | * @return mixed |
| 329 | 329 | */ |
| 330 | - public function __get( $key ) { |
|
| 331 | - $value = get_post_meta( $this->id, '_' . $key, true ); |
|
| 332 | - if ( ! empty( $value ) ) { |
|
| 330 | + public function __get($key) { |
|
| 331 | + $value = get_post_meta($this->id, '_'.$key, true); |
|
| 332 | + if ( ! empty($value)) { |
|
| 333 | 333 | $this->$key = $value; |
| 334 | 334 | } |
| 335 | 335 | return $value; |
@@ -342,17 +342,17 @@ discard block |
||
| 342 | 342 | * |
| 343 | 343 | * @param int|object|\WP_Post|Calendar $calendar |
| 344 | 344 | */ |
| 345 | - public function set_post_object( $calendar ) { |
|
| 346 | - if ( is_numeric( $calendar ) ) { |
|
| 347 | - $this->id = absint( $calendar ); |
|
| 348 | - $this->post = get_post( $this->id ); |
|
| 349 | - } elseif ( $calendar instanceof Calendar ) { |
|
| 350 | - $this->id = absint( $calendar->id ); |
|
| 345 | + public function set_post_object($calendar) { |
|
| 346 | + if (is_numeric($calendar)) { |
|
| 347 | + $this->id = absint($calendar); |
|
| 348 | + $this->post = get_post($this->id); |
|
| 349 | + } elseif ($calendar instanceof Calendar) { |
|
| 350 | + $this->id = absint($calendar->id); |
|
| 351 | 351 | $this->post = $calendar->post; |
| 352 | - } elseif ( $calendar instanceof \WP_Post ) { |
|
| 353 | - $this->id = absint( $calendar->ID ); |
|
| 352 | + } elseif ($calendar instanceof \WP_Post) { |
|
| 353 | + $this->id = absint($calendar->ID); |
|
| 354 | 354 | $this->post = $calendar; |
| 355 | - } elseif ( isset( $calendar->id ) && isset( $calendar->post ) ) { |
|
| 355 | + } elseif (isset($calendar->id) && isset($calendar->post)) { |
|
| 356 | 356 | $this->id = $calendar->id; |
| 357 | 357 | $this->post = $calendar->post; |
| 358 | 358 | } |
@@ -366,8 +366,8 @@ discard block |
||
| 366 | 366 | * @return string |
| 367 | 367 | */ |
| 368 | 368 | public function get_title() { |
| 369 | - $title = isset( $this->post->post_title ) ? $this->post->post_title : ''; |
|
| 370 | - return apply_filters( 'simcal_calendar_title', $title ); |
|
| 369 | + $title = isset($this->post->post_title) ? $this->post->post_title : ''; |
|
| 370 | + return apply_filters('simcal_calendar_title', $title); |
|
| 371 | 371 | } |
| 372 | 372 | |
| 373 | 373 | /** |
@@ -389,16 +389,16 @@ discard block |
||
| 389 | 389 | */ |
| 390 | 390 | protected function set_taxonomies() { |
| 391 | 391 | // Set calendar type. |
| 392 | - if ( $type = wp_get_object_terms( $this->id, 'calendar_type' ) ) { |
|
| 393 | - $this->type = sanitize_title( current( $type )->name ); |
|
| 392 | + if ($type = wp_get_object_terms($this->id, 'calendar_type')) { |
|
| 393 | + $this->type = sanitize_title(current($type)->name); |
|
| 394 | 394 | } else { |
| 395 | - $this->type = apply_filters( 'simcal_calendar_default_type', 'default-calendar' ); |
|
| 395 | + $this->type = apply_filters('simcal_calendar_default_type', 'default-calendar'); |
|
| 396 | 396 | } |
| 397 | 397 | // Set feed type. |
| 398 | - if ( $feed_type = wp_get_object_terms( $this->id, 'calendar_feed' ) ) { |
|
| 399 | - $this->feed = sanitize_title( current( $feed_type )->name ); |
|
| 398 | + if ($feed_type = wp_get_object_terms($this->id, 'calendar_feed')) { |
|
| 399 | + $this->feed = sanitize_title(current($feed_type)->name); |
|
| 400 | 400 | } else { |
| 401 | - $this->feed = apply_filters( 'simcal_calendar_default_feed', 'google' ); |
|
| 401 | + $this->feed = apply_filters('simcal_calendar_default_feed', 'google'); |
|
| 402 | 402 | } |
| 403 | 403 | } |
| 404 | 404 | |
@@ -410,7 +410,7 @@ discard block |
||
| 410 | 410 | * @return Events |
| 411 | 411 | */ |
| 412 | 412 | public function get_events() { |
| 413 | - return new Events( $this->events, $this->timezone ); |
|
| 413 | + return new Events($this->events, $this->timezone); |
|
| 414 | 414 | } |
| 415 | 415 | |
| 416 | 416 | /** |
@@ -420,14 +420,14 @@ discard block |
||
| 420 | 420 | * |
| 421 | 421 | * @param array $array |
| 422 | 422 | */ |
| 423 | - public function set_events( array $array ) { |
|
| 423 | + public function set_events(array $array) { |
|
| 424 | 424 | |
| 425 | 425 | $events = array(); |
| 426 | 426 | |
| 427 | - if ( ! empty( $array ) ) { |
|
| 428 | - foreach ( $array as $tz => $e ) { |
|
| 429 | - foreach ( $e as $event ) { |
|
| 430 | - $events[ $tz ][] = $event instanceof Event ? $event : new Event( $event ); |
|
| 427 | + if ( ! empty($array)) { |
|
| 428 | + foreach ($array as $tz => $e) { |
|
| 429 | + foreach ($e as $event) { |
|
| 430 | + $events[$tz][] = $event instanceof Event ? $event : new Event($event); |
|
| 431 | 431 | } |
| 432 | 432 | } |
| 433 | 433 | } |
@@ -444,11 +444,11 @@ discard block |
||
| 444 | 444 | * |
| 445 | 445 | * @return string |
| 446 | 446 | */ |
| 447 | - public function set_events_template( $template = '' ) { |
|
| 448 | - if ( empty( $template ) ) { |
|
| 449 | - $template = isset( $this->post->post_content ) ? $this->post->post_content : ''; |
|
| 447 | + public function set_events_template($template = '') { |
|
| 448 | + if (empty($template)) { |
|
| 449 | + $template = isset($this->post->post_content) ? $this->post->post_content : ''; |
|
| 450 | 450 | } |
| 451 | - $this->events_template = wpautop( wp_kses_post( trim( $template ) ) ); |
|
| 451 | + $this->events_template = wpautop(wp_kses_post(trim($template))); |
|
| 452 | 452 | } |
| 453 | 453 | |
| 454 | 454 | /** |
@@ -458,32 +458,32 @@ discard block |
||
| 458 | 458 | * |
| 459 | 459 | * @param string $tz Timezone. |
| 460 | 460 | */ |
| 461 | - public function set_timezone( $tz = '' ) { |
|
| 461 | + public function set_timezone($tz = '') { |
|
| 462 | 462 | |
| 463 | - $site_tz = esc_attr( simcal_get_wp_timezone() ); |
|
| 463 | + $site_tz = esc_attr(simcal_get_wp_timezone()); |
|
| 464 | 464 | |
| 465 | - if ( empty( $tz ) ) { |
|
| 465 | + if (empty($tz)) { |
|
| 466 | 466 | |
| 467 | - $timezone_setting = get_post_meta( $this->id, '_feed_timezone_setting', true ); |
|
| 467 | + $timezone_setting = get_post_meta($this->id, '_feed_timezone_setting', true); |
|
| 468 | 468 | |
| 469 | - if ( 'use_site' == $timezone_setting ) { |
|
| 469 | + if ('use_site' == $timezone_setting) { |
|
| 470 | 470 | $tz = $site_tz; |
| 471 | - } elseif ( 'use_custom' == $timezone_setting ) { |
|
| 472 | - $custom_timezone = esc_attr( get_post_meta( $this->id, '_feed_timezone', true ) ); |
|
| 471 | + } elseif ('use_custom' == $timezone_setting) { |
|
| 472 | + $custom_timezone = esc_attr(get_post_meta($this->id, '_feed_timezone', true)); |
|
| 473 | 473 | // One may be using a non standard timezone in GMT (UTC) offset format. |
| 474 | - if ( ( strpos( $custom_timezone, 'UTC+' ) === 0 ) || ( strpos( $custom_timezone, 'UTC-' ) === 0 ) ) { |
|
| 475 | - $tz = simcal_get_timezone_from_gmt_offset( substr( $custom_timezone, 3 ) ); |
|
| 474 | + if ((strpos($custom_timezone, 'UTC+') === 0) || (strpos($custom_timezone, 'UTC-') === 0)) { |
|
| 475 | + $tz = simcal_get_timezone_from_gmt_offset(substr($custom_timezone, 3)); |
|
| 476 | 476 | } else { |
| 477 | - $tz = ! empty( $custom_timezone ) ? $custom_timezone : 'UTC'; |
|
| 477 | + $tz = ! empty($custom_timezone) ? $custom_timezone : 'UTC'; |
|
| 478 | 478 | } |
| 479 | 479 | } |
| 480 | 480 | |
| 481 | - $this->timezone = empty( $tz ) ? 'UTC' : $tz; |
|
| 481 | + $this->timezone = empty($tz) ? 'UTC' : $tz; |
|
| 482 | 482 | return; |
| 483 | 483 | } |
| 484 | 484 | |
| 485 | 485 | $this->site_timezone = $site_tz; |
| 486 | - $this->timezone = simcal_esc_timezone( $tz, $this->timezone ); |
|
| 486 | + $this->timezone = simcal_esc_timezone($tz, $this->timezone); |
|
| 487 | 487 | } |
| 488 | 488 | |
| 489 | 489 | /** |
@@ -493,20 +493,20 @@ discard block |
||
| 493 | 493 | * |
| 494 | 494 | * @param string $format PHP datetime format. |
| 495 | 495 | */ |
| 496 | - public function set_date_format( $format = '' ) { |
|
| 496 | + public function set_date_format($format = '') { |
|
| 497 | 497 | |
| 498 | 498 | $date_format_custom = $date_format_default = $format; |
| 499 | 499 | |
| 500 | - if ( empty( $date_format_custom ) ) { |
|
| 500 | + if (empty($date_format_custom)) { |
|
| 501 | 501 | |
| 502 | - $date_format_option = esc_attr( get_post_meta( $this->id, '_calendar_date_format_setting', true ) ); |
|
| 503 | - $date_format_default = esc_attr( get_option( 'date_format' ) ); |
|
| 502 | + $date_format_option = esc_attr(get_post_meta($this->id, '_calendar_date_format_setting', true)); |
|
| 503 | + $date_format_default = esc_attr(get_option('date_format')); |
|
| 504 | 504 | $date_format_custom = ''; |
| 505 | 505 | |
| 506 | - if ( 'use_custom' == $date_format_option ) { |
|
| 507 | - $date_format_custom = esc_attr( get_post_meta( $this->id, '_calendar_date_format', true ) ); |
|
| 508 | - } elseif ( 'use_custom_php' ) { |
|
| 509 | - $date_format_custom = esc_attr( get_post_meta( $this->id, '_calendar_date_format_php', true ) ); |
|
| 506 | + if ('use_custom' == $date_format_option) { |
|
| 507 | + $date_format_custom = esc_attr(get_post_meta($this->id, '_calendar_date_format', true)); |
|
| 508 | + } elseif ('use_custom_php') { |
|
| 509 | + $date_format_custom = esc_attr(get_post_meta($this->id, '_calendar_date_format_php', true)); |
|
| 510 | 510 | } |
| 511 | 511 | } |
| 512 | 512 | |
@@ -520,20 +520,20 @@ discard block |
||
| 520 | 520 | * |
| 521 | 521 | * @param string $format PHP datetime format. |
| 522 | 522 | */ |
| 523 | - public function set_time_format( $format = '' ) { |
|
| 523 | + public function set_time_format($format = '') { |
|
| 524 | 524 | |
| 525 | 525 | $time_format_custom = $time_format_default = $format; |
| 526 | 526 | |
| 527 | - if ( empty( $time_format_custom ) ) { |
|
| 527 | + if (empty($time_format_custom)) { |
|
| 528 | 528 | |
| 529 | - $time_format_option = esc_attr( get_post_meta( $this->id, '_calendar_time_format_setting', true ) ); |
|
| 530 | - $time_format_default = esc_attr( get_option( 'time_format' ) ); |
|
| 529 | + $time_format_option = esc_attr(get_post_meta($this->id, '_calendar_time_format_setting', true)); |
|
| 530 | + $time_format_default = esc_attr(get_option('time_format')); |
|
| 531 | 531 | $time_format_custom = ''; |
| 532 | 532 | |
| 533 | - if ( 'use_custom' == $time_format_option ) { |
|
| 534 | - $time_format_custom = esc_attr( get_post_meta( $this->id, '_calendar_time_format', true ) ); |
|
| 535 | - } elseif ( 'use_custom_php' ) { |
|
| 536 | - $time_format_custom = esc_attr( get_post_meta( $this->id, '_calendar_time_format_php', true ) ); |
|
| 533 | + if ('use_custom' == $time_format_option) { |
|
| 534 | + $time_format_custom = esc_attr(get_post_meta($this->id, '_calendar_time_format', true)); |
|
| 535 | + } elseif ('use_custom_php') { |
|
| 536 | + $time_format_custom = esc_attr(get_post_meta($this->id, '_calendar_time_format_php', true)); |
|
| 537 | 537 | } |
| 538 | 538 | } |
| 539 | 539 | |
@@ -547,13 +547,13 @@ discard block |
||
| 547 | 547 | * |
| 548 | 548 | * @param string $separator A UTF8 character used as separator. |
| 549 | 549 | */ |
| 550 | - public function set_datetime_separator( $separator = '' ) { |
|
| 550 | + public function set_datetime_separator($separator = '') { |
|
| 551 | 551 | |
| 552 | - if ( empty( $separator ) ) { |
|
| 553 | - $separator = get_post_meta( $this->id, '_calendar_datetime_separator', true ); |
|
| 552 | + if (empty($separator)) { |
|
| 553 | + $separator = get_post_meta($this->id, '_calendar_datetime_separator', true); |
|
| 554 | 554 | } |
| 555 | 555 | |
| 556 | - $this->datetime_separator = esc_attr( $separator ); |
|
| 556 | + $this->datetime_separator = esc_attr($separator); |
|
| 557 | 557 | } |
| 558 | 558 | |
| 559 | 559 | /** |
@@ -563,18 +563,18 @@ discard block |
||
| 563 | 563 | * |
| 564 | 564 | * @param int $weekday From 0 (Sunday) to 6 (Friday). |
| 565 | 565 | */ |
| 566 | - public function set_start_of_week( $weekday = -1 ) { |
|
| 566 | + public function set_start_of_week($weekday = -1) { |
|
| 567 | 567 | |
| 568 | - $week_starts = is_int( $weekday ) ? $weekday : -1; |
|
| 568 | + $week_starts = is_int($weekday) ? $weekday : -1; |
|
| 569 | 569 | |
| 570 | - if ( $week_starts < 0 || $week_starts > 6 ) { |
|
| 570 | + if ($week_starts < 0 || $week_starts > 6) { |
|
| 571 | 571 | |
| 572 | - $week_starts_setting = get_post_meta( $this->id, '_calendar_week_starts_on_setting', true ); |
|
| 573 | - $week_starts = intval( get_option( 'start_of_week' ) ); |
|
| 572 | + $week_starts_setting = get_post_meta($this->id, '_calendar_week_starts_on_setting', true); |
|
| 573 | + $week_starts = intval(get_option('start_of_week')); |
|
| 574 | 574 | |
| 575 | - if ( 'use_custom' == $week_starts_setting ) { |
|
| 576 | - $week_starts_on = get_post_meta( $this->id, '_calendar_week_starts_on', true ); |
|
| 577 | - $week_starts = is_numeric( $week_starts_on ) ? intval( $week_starts_on ) : $week_starts; |
|
| 575 | + if ('use_custom' == $week_starts_setting) { |
|
| 576 | + $week_starts_on = get_post_meta($this->id, '_calendar_week_starts_on', true); |
|
| 577 | + $week_starts = is_numeric($week_starts_on) ? intval($week_starts_on) : $week_starts; |
|
| 578 | 578 | } |
| 579 | 579 | } |
| 580 | 580 | |
@@ -588,51 +588,51 @@ discard block |
||
| 588 | 588 | * |
| 589 | 589 | * @param int $timestamp |
| 590 | 590 | */ |
| 591 | - public function set_start( $timestamp = 0 ) { |
|
| 591 | + public function set_start($timestamp = 0) { |
|
| 592 | 592 | |
| 593 | - if ( is_int( $timestamp ) && $timestamp !== 0 ) { |
|
| 593 | + if (is_int($timestamp) && $timestamp !== 0) { |
|
| 594 | 594 | $this->start = $timestamp; |
| 595 | 595 | return; |
| 596 | 596 | } |
| 597 | 597 | |
| 598 | - $this->start = Carbon::now( $this->timezone )->getTimestamp(); |
|
| 598 | + $this->start = Carbon::now($this->timezone)->getTimestamp(); |
|
| 599 | 599 | |
| 600 | - $calendar_begins = esc_attr( get_post_meta( $this->id, '_calendar_begins', true ) ); |
|
| 601 | - $nth = max( absint( get_post_meta( $this->id, '_calendar_begins_nth' ) ), 1 ); |
|
| 600 | + $calendar_begins = esc_attr(get_post_meta($this->id, '_calendar_begins', true)); |
|
| 601 | + $nth = max(absint(get_post_meta($this->id, '_calendar_begins_nth')), 1); |
|
| 602 | 602 | |
| 603 | - if ( 'today' == $calendar_begins ) { |
|
| 604 | - $this->start = Carbon::today( $this->timezone )->getTimestamp(); |
|
| 605 | - } elseif ( 'days_before' == $calendar_begins ) { |
|
| 606 | - $this->start = Carbon::today( $this->timezone )->subDays( $nth )->getTimestamp(); |
|
| 607 | - } elseif ( 'days_after' == $calendar_begins ) { |
|
| 608 | - $this->start = Carbon::today( $this->timezone )->addDays( $nth )->getTimestamp(); |
|
| 609 | - } elseif ( 'this_week' == $calendar_begins ) { |
|
| 610 | - $week = new Carbon( 'now', $this->timezone ); |
|
| 611 | - $week->setWeekStartsAt( $this->week_starts ); |
|
| 603 | + if ('today' == $calendar_begins) { |
|
| 604 | + $this->start = Carbon::today($this->timezone)->getTimestamp(); |
|
| 605 | + } elseif ('days_before' == $calendar_begins) { |
|
| 606 | + $this->start = Carbon::today($this->timezone)->subDays($nth)->getTimestamp(); |
|
| 607 | + } elseif ('days_after' == $calendar_begins) { |
|
| 608 | + $this->start = Carbon::today($this->timezone)->addDays($nth)->getTimestamp(); |
|
| 609 | + } elseif ('this_week' == $calendar_begins) { |
|
| 610 | + $week = new Carbon('now', $this->timezone); |
|
| 611 | + $week->setWeekStartsAt($this->week_starts); |
|
| 612 | 612 | $this->start = $week->startOfWeek()->getTimestamp(); |
| 613 | - } elseif ( 'weeks_before' == $calendar_begins ) { |
|
| 614 | - $week = new Carbon( 'now', $this->timezone ); |
|
| 615 | - $week->setWeekStartsAt( $this->week_starts ); |
|
| 616 | - $this->start = $week->startOfWeek()->subWeeks( $nth )->getTimestamp(); |
|
| 617 | - } elseif ( 'weeks_after' == $calendar_begins ) { |
|
| 618 | - $week = new Carbon( 'now', $this->timezone ); |
|
| 619 | - $week->setWeekStartsAt( $this->week_starts ); |
|
| 620 | - $this->start = $week->startOfWeek()->addWeeks( $nth )->getTimestamp(); |
|
| 621 | - } elseif ( 'this_month' == $calendar_begins ) { |
|
| 622 | - $this->start = Carbon::today( $this->timezone )->startOfMonth()->getTimeStamp(); |
|
| 623 | - } elseif ( 'months_before' == $calendar_begins ) { |
|
| 624 | - $this->start = Carbon::today( $this->timezone )->subMonths( $nth )->startOfMonth()->getTimeStamp(); |
|
| 625 | - } elseif ( 'months_after' == $calendar_begins ) { |
|
| 626 | - $this->start = Carbon::today( $this->timezone )->addMonths( $nth )->startOfMonth()->getTimeStamp(); |
|
| 627 | - } elseif ( 'this_year' == $calendar_begins ) { |
|
| 628 | - $this->start = Carbon::today( $this->timezone )->startOfYear()->getTimestamp(); |
|
| 629 | - } elseif ( 'years_before' == $calendar_begins ) { |
|
| 630 | - $this->start = Carbon::today( $this->timezone )->subYears( $nth )->startOfYear()->getTimeStamp(); |
|
| 631 | - } elseif ( 'years_after' == $calendar_begins ) { |
|
| 632 | - $this->start = Carbon::today( $this->timezone )->addYears( $nth )->startOfYear()->getTimeStamp(); |
|
| 633 | - } elseif ( 'custom_date' == $calendar_begins ) { |
|
| 634 | - if ( $date = get_post_meta( $this->id, '_calendar_begins_custom_date', true ) ) { |
|
| 635 | - $this->start = Carbon::createFromFormat( 'Y-m-d', esc_attr( $date ) )->setTimezone( $this->timezone )->getTimestamp(); |
|
| 613 | + } elseif ('weeks_before' == $calendar_begins) { |
|
| 614 | + $week = new Carbon('now', $this->timezone); |
|
| 615 | + $week->setWeekStartsAt($this->week_starts); |
|
| 616 | + $this->start = $week->startOfWeek()->subWeeks($nth)->getTimestamp(); |
|
| 617 | + } elseif ('weeks_after' == $calendar_begins) { |
|
| 618 | + $week = new Carbon('now', $this->timezone); |
|
| 619 | + $week->setWeekStartsAt($this->week_starts); |
|
| 620 | + $this->start = $week->startOfWeek()->addWeeks($nth)->getTimestamp(); |
|
| 621 | + } elseif ('this_month' == $calendar_begins) { |
|
| 622 | + $this->start = Carbon::today($this->timezone)->startOfMonth()->getTimeStamp(); |
|
| 623 | + } elseif ('months_before' == $calendar_begins) { |
|
| 624 | + $this->start = Carbon::today($this->timezone)->subMonths($nth)->startOfMonth()->getTimeStamp(); |
|
| 625 | + } elseif ('months_after' == $calendar_begins) { |
|
| 626 | + $this->start = Carbon::today($this->timezone)->addMonths($nth)->startOfMonth()->getTimeStamp(); |
|
| 627 | + } elseif ('this_year' == $calendar_begins) { |
|
| 628 | + $this->start = Carbon::today($this->timezone)->startOfYear()->getTimestamp(); |
|
| 629 | + } elseif ('years_before' == $calendar_begins) { |
|
| 630 | + $this->start = Carbon::today($this->timezone)->subYears($nth)->startOfYear()->getTimeStamp(); |
|
| 631 | + } elseif ('years_after' == $calendar_begins) { |
|
| 632 | + $this->start = Carbon::today($this->timezone)->addYears($nth)->startOfYear()->getTimeStamp(); |
|
| 633 | + } elseif ('custom_date' == $calendar_begins) { |
|
| 634 | + if ($date = get_post_meta($this->id, '_calendar_begins_custom_date', true)) { |
|
| 635 | + $this->start = Carbon::createFromFormat('Y-m-d', esc_attr($date))->setTimezone($this->timezone)->getTimestamp(); |
|
| 636 | 636 | } |
| 637 | 637 | } |
| 638 | 638 | } |
@@ -644,8 +644,8 @@ discard block |
||
| 644 | 644 | * |
| 645 | 645 | * @param int $timestamp |
| 646 | 646 | */ |
| 647 | - public function set_end( $timestamp = 0 ) { |
|
| 648 | - $latest = is_int( $timestamp ) && $timestamp !== 0 ? $timestamp : $this->latest_event; |
|
| 647 | + public function set_end($timestamp = 0) { |
|
| 648 | + $latest = is_int($timestamp) && $timestamp !== 0 ? $timestamp : $this->latest_event; |
|
| 649 | 649 | $this->end = $latest > $this->start ? $latest : $this->start; |
| 650 | 650 | } |
| 651 | 651 | |
@@ -656,14 +656,14 @@ discard block |
||
| 656 | 656 | * |
| 657 | 657 | * @param string|bool $static |
| 658 | 658 | */ |
| 659 | - public function set_static( $static = '' ) { |
|
| 659 | + public function set_static($static = '') { |
|
| 660 | 660 | |
| 661 | - if ( ! empty( $static ) && is_bool( $static ) ) { |
|
| 661 | + if ( ! empty($static) && is_bool($static)) { |
|
| 662 | 662 | $this->static = $static; |
| 663 | 663 | return; |
| 664 | 664 | } |
| 665 | 665 | |
| 666 | - if ( 'yes' == get_post_meta( $this->id, '_calendar_is_static', true ) ) { |
|
| 666 | + if ('yes' == get_post_meta($this->id, '_calendar_is_static', true)) { |
|
| 667 | 667 | $this->static = true; |
| 668 | 668 | return; |
| 669 | 669 | } |
@@ -691,7 +691,7 @@ discard block |
||
| 691 | 691 | * |
| 692 | 692 | * @return Calendar_View |
| 693 | 693 | */ |
| 694 | - abstract public function get_view( $view = '' ); |
|
| 694 | + abstract public function get_view($view = ''); |
|
| 695 | 695 | |
| 696 | 696 | /** |
| 697 | 697 | * Get event HTML parsed by template. |
@@ -703,11 +703,11 @@ discard block |
||
| 703 | 703 | * |
| 704 | 704 | * @return string |
| 705 | 705 | */ |
| 706 | - public function get_event_html( Event $event, $template = '' ) { |
|
| 707 | - $event_builder = new Event_Builder( $event, $this ); |
|
| 706 | + public function get_event_html(Event $event, $template = '') { |
|
| 707 | + $event_builder = new Event_Builder($event, $this); |
|
| 708 | 708 | // Use the event template to parse tags; if empty, fallback to calendar post content. |
| 709 | - $template = empty( $template ) ? ( empty( $event->template ) ? $this->events_template : $event->template ) : $template; |
|
| 710 | - return $event_builder->parse_event_template_tags( $template ); |
|
| 709 | + $template = empty($template) ? (empty($event->template) ? $this->events_template : $event->template) : $template; |
|
| 710 | + return $event_builder->parse_event_template_tags($template); |
|
| 711 | 711 | } |
| 712 | 712 | |
| 713 | 713 | /** |
@@ -717,57 +717,57 @@ discard block |
||
| 717 | 717 | * |
| 718 | 718 | * @param string $view The calendar view to display. |
| 719 | 719 | */ |
| 720 | - public function html( $view = '' ) { |
|
| 720 | + public function html($view = '') { |
|
| 721 | 721 | |
| 722 | - $view = empty( $view ) ? $this->view : $this->get_view( $view ); |
|
| 722 | + $view = empty($view) ? $this->view : $this->get_view($view); |
|
| 723 | 723 | |
| 724 | - if ( $view instanceof Calendar_View ) { |
|
| 724 | + if ($view instanceof Calendar_View) { |
|
| 725 | 725 | |
| 726 | - if ( ! empty( $this->errors ) ) { |
|
| 726 | + if ( ! empty($this->errors)) { |
|
| 727 | 727 | |
| 728 | - if ( current_user_can( 'manage_options' ) ) { |
|
| 728 | + if (current_user_can('manage_options')) { |
|
| 729 | 729 | echo '<pre><code>'; |
| 730 | - foreach ( $this->errors as $error ) { echo $error; } |
|
| 730 | + foreach ($this->errors as $error) { echo $error; } |
|
| 731 | 731 | echo '</code></pre>'; |
| 732 | 732 | } |
| 733 | 733 | |
| 734 | 734 | } else { |
| 735 | 735 | |
| 736 | 736 | // Get a CSS class from the class name of the calendar view (minus namespace part). |
| 737 | - $view_name = implode( '-', array_map( 'lcfirst', explode( '_', strtolower( get_class( $view ) ) ) ) ); |
|
| 738 | - $view_class = substr( $view_name, strrpos( $view_name, '\\' ) + 1 ); |
|
| 737 | + $view_name = implode('-', array_map('lcfirst', explode('_', strtolower(get_class($view))))); |
|
| 738 | + $view_class = substr($view_name, strrpos($view_name, '\\') + 1); |
|
| 739 | 739 | |
| 740 | - $calendar_class = trim( implode( ' simcal-', apply_filters( 'simcal_calendar_class', array( |
|
| 740 | + $calendar_class = trim(implode(' simcal-', apply_filters('simcal_calendar_class', array( |
|
| 741 | 741 | 'simcal-calendar', |
| 742 | 742 | $this->type, |
| 743 | 743 | $view_class, |
| 744 | - ), $this->id ) ) ); |
|
| 745 | - |
|
| 746 | - echo '<div class="' . $calendar_class . '" ' |
|
| 747 | - . 'data-calendar-id="' . $this->id . '" ' |
|
| 748 | - . 'data-timezone="' . $this->timezone . '" ' |
|
| 749 | - . 'data-offset="' . $this->offset . '" ' |
|
| 750 | - . 'data-week-start="' . $this->week_starts . '" ' |
|
| 751 | - . 'data-calendar-start="' . $this->start .'" ' |
|
| 752 | - . 'data-calendar-end="' . $this->end . '" ' |
|
| 753 | - . 'data-events-first="' . $this->earliest_event .'" ' |
|
| 754 | - . 'data-events-last="' . $this->latest_event . '"' |
|
| 744 | + ), $this->id))); |
|
| 745 | + |
|
| 746 | + echo '<div class="'.$calendar_class.'" ' |
|
| 747 | + . 'data-calendar-id="'.$this->id.'" ' |
|
| 748 | + . 'data-timezone="'.$this->timezone.'" ' |
|
| 749 | + . 'data-offset="'.$this->offset.'" ' |
|
| 750 | + . 'data-week-start="'.$this->week_starts.'" ' |
|
| 751 | + . 'data-calendar-start="'.$this->start.'" ' |
|
| 752 | + . 'data-calendar-end="'.$this->end.'" ' |
|
| 753 | + . 'data-events-first="'.$this->earliest_event.'" ' |
|
| 754 | + . 'data-events-last="'.$this->latest_event.'"' |
|
| 755 | 755 | . '>'; |
| 756 | 756 | |
| 757 | - date_default_timezone_set( $this->timezone ); |
|
| 758 | - do_action( 'simcal_calendar_html_before', $this->id ); |
|
| 757 | + date_default_timezone_set($this->timezone); |
|
| 758 | + do_action('simcal_calendar_html_before', $this->id); |
|
| 759 | 759 | |
| 760 | 760 | $view->html(); |
| 761 | 761 | |
| 762 | - do_action( 'simcal_calendar_html_after', $this->id ); |
|
| 763 | - date_default_timezone_set( $this->site_timezone ); |
|
| 762 | + do_action('simcal_calendar_html_after', $this->id); |
|
| 763 | + date_default_timezone_set($this->site_timezone); |
|
| 764 | 764 | |
| 765 | - $settings = get_option( 'simple-calendar_settings_calendars' ); |
|
| 766 | - $poweredby = isset( $settings['poweredby']['opt_in'] ) ? $settings['poweredby']['opt_in'] : ''; |
|
| 765 | + $settings = get_option('simple-calendar_settings_calendars'); |
|
| 766 | + $poweredby = isset($settings['poweredby']['opt_in']) ? $settings['poweredby']['opt_in'] : ''; |
|
| 767 | 767 | |
| 768 | - if ( 'yes' == $poweredby ) { |
|
| 768 | + if ('yes' == $poweredby) { |
|
| 769 | 769 | $align = is_rtl() ? 'left' : 'right'; |
| 770 | - echo '<small class="simcal-powered simcal-align-' . $align .'">Powered by <a href="https://simplecalendar.io" target="_blank">Simple Calendar</a></small>'; |
|
| 770 | + echo '<small class="simcal-powered simcal-align-'.$align.'">Powered by <a href="https://simplecalendar.io" target="_blank">Simple Calendar</a></small>'; |
|
| 771 | 771 | } |
| 772 | 772 | |
| 773 | 773 | echo '</div>'; |
@@ -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 | |
@@ -132,22 +132,22 @@ discard block |
||
| 132 | 132 | * |
| 133 | 133 | * @param string|Calendar $calendar |
| 134 | 134 | */ |
| 135 | - public function __construct( $calendar = '' ) { |
|
| 135 | + public function __construct($calendar = '') { |
|
| 136 | 136 | |
| 137 | - if ( $calendar instanceof Calendar ) { |
|
| 137 | + if ($calendar instanceof Calendar) { |
|
| 138 | 138 | |
| 139 | - if ( isset( $calendar->id ) ) { |
|
| 139 | + if (isset($calendar->id)) { |
|
| 140 | 140 | $this->post_id = $calendar->id; |
| 141 | 141 | } |
| 142 | - if ( isset( $calendar->start ) ) { |
|
| 142 | + if (isset($calendar->start)) { |
|
| 143 | 143 | $this->calendar_start = $calendar->start; |
| 144 | 144 | } |
| 145 | - $this->week_starts = isset( $calendar->week_starts ) ? $calendar->week_starts : get_option( 'start_of_week' ); |
|
| 146 | - $this->events_template = ! empty( $calendar->events_template ) ? $calendar->events_template : simcal_default_event_template(); |
|
| 145 | + $this->week_starts = isset($calendar->week_starts) ? $calendar->week_starts : get_option('start_of_week'); |
|
| 146 | + $this->events_template = ! empty($calendar->events_template) ? $calendar->events_template : simcal_default_event_template(); |
|
| 147 | 147 | |
| 148 | - if ( $this->post_id > 0 ) { |
|
| 148 | + if ($this->post_id > 0) { |
|
| 149 | 149 | $this->set_cache(); |
| 150 | - $this->timezone_setting = get_post_meta( $this->post_id, '_feed_timezone_setting', true ); |
|
| 150 | + $this->timezone_setting = get_post_meta($this->post_id, '_feed_timezone_setting', true); |
|
| 151 | 151 | $this->timezone = $calendar->timezone; |
| 152 | 152 | $this->set_earliest_event(); |
| 153 | 153 | $this->set_latest_event(); |
@@ -173,25 +173,25 @@ discard block |
||
| 173 | 173 | * |
| 174 | 174 | * @param int $timestamp |
| 175 | 175 | */ |
| 176 | - public function set_earliest_event( $timestamp = 0 ) { |
|
| 176 | + public function set_earliest_event($timestamp = 0) { |
|
| 177 | 177 | |
| 178 | - $earliest = intval( $timestamp ); |
|
| 178 | + $earliest = intval($timestamp); |
|
| 179 | 179 | |
| 180 | - if ( $earliest === 0 ) { |
|
| 180 | + if ($earliest === 0) { |
|
| 181 | 181 | |
| 182 | - $start = Carbon::createFromTimestamp( $this->calendar_start, $this->timezone ); |
|
| 182 | + $start = Carbon::createFromTimestamp($this->calendar_start, $this->timezone); |
|
| 183 | 183 | |
| 184 | - $earliest_date = esc_attr( get_post_meta( $this->post_id, '_feed_earliest_event_date', true ) ); |
|
| 185 | - $earliest_range = max( absint( get_post_meta( $this->post_id, '_feed_earliest_event_date_range', true ) ), 1 ); |
|
| 184 | + $earliest_date = esc_attr(get_post_meta($this->post_id, '_feed_earliest_event_date', true)); |
|
| 185 | + $earliest_range = max(absint(get_post_meta($this->post_id, '_feed_earliest_event_date_range', true)), 1); |
|
| 186 | 186 | |
| 187 | - if ( 'days_before' == $earliest_date ) { |
|
| 188 | - $earliest = $start->subDays( $earliest_range )->getTimestamp(); |
|
| 189 | - } elseif ( 'weeks_before' == $earliest_date ) { |
|
| 190 | - $earliest = $start->subWeeks( $earliest_range )->addDay()->getTimestamp(); |
|
| 191 | - } elseif ( 'months_before' == $earliest_date ) { |
|
| 192 | - $earliest = $start->subMonths( $earliest_range )->addDay()->getTimestamp(); |
|
| 193 | - } elseif ( 'years_before' == $earliest_date ) { |
|
| 194 | - $earliest = $start->subYears( $earliest_range )->addDay()->getTimestamp(); |
|
| 187 | + if ('days_before' == $earliest_date) { |
|
| 188 | + $earliest = $start->subDays($earliest_range)->getTimestamp(); |
|
| 189 | + } elseif ('weeks_before' == $earliest_date) { |
|
| 190 | + $earliest = $start->subWeeks($earliest_range)->addDay()->getTimestamp(); |
|
| 191 | + } elseif ('months_before' == $earliest_date) { |
|
| 192 | + $earliest = $start->subMonths($earliest_range)->addDay()->getTimestamp(); |
|
| 193 | + } elseif ('years_before' == $earliest_date) { |
|
| 194 | + $earliest = $start->subYears($earliest_range)->addDay()->getTimestamp(); |
|
| 195 | 195 | } else { |
| 196 | 196 | $earliest = $start->getTimestamp(); |
| 197 | 197 | } |
@@ -207,25 +207,25 @@ discard block |
||
| 207 | 207 | * |
| 208 | 208 | * @param int $timestamp |
| 209 | 209 | */ |
| 210 | - public function set_latest_event( $timestamp = 0 ) { |
|
| 210 | + public function set_latest_event($timestamp = 0) { |
|
| 211 | 211 | |
| 212 | - $latest = intval( $timestamp ); |
|
| 212 | + $latest = intval($timestamp); |
|
| 213 | 213 | |
| 214 | - if ( $latest === 0 ) { |
|
| 214 | + if ($latest === 0) { |
|
| 215 | 215 | |
| 216 | - $start = Carbon::createFromTimestamp( $this->calendar_start, $this->timezone )->endOfDay(); |
|
| 216 | + $start = Carbon::createFromTimestamp($this->calendar_start, $this->timezone)->endOfDay(); |
|
| 217 | 217 | |
| 218 | - $latest_date = esc_attr( get_post_meta( $this->post_id, '_feed_latest_event_date', true ) ); |
|
| 219 | - $latest_range = max( absint( get_post_meta( $this->post_id, '_feed_latest_event_date_range', true ) ), 1 ); |
|
| 218 | + $latest_date = esc_attr(get_post_meta($this->post_id, '_feed_latest_event_date', true)); |
|
| 219 | + $latest_range = max(absint(get_post_meta($this->post_id, '_feed_latest_event_date_range', true)), 1); |
|
| 220 | 220 | |
| 221 | - if ( 'days_after' == $latest_date ) { |
|
| 222 | - $latest = $start->addDays( $latest_range )->getTimestamp(); |
|
| 223 | - } elseif ( 'weeks_after' == $latest_date ) { |
|
| 224 | - $latest = $start->addWeeks( $latest_range )->subDay()->getTimestamp(); |
|
| 225 | - } elseif ( 'months_after' == $latest_date ) { |
|
| 226 | - $latest = $start->addMonths( $latest_range )->subDay()->getTimestamp(); |
|
| 227 | - } elseif ( 'years_after' == $latest_date ) { |
|
| 228 | - $latest = $start->addYears( $latest_range )->subDay()->getTimestamp(); |
|
| 221 | + if ('days_after' == $latest_date) { |
|
| 222 | + $latest = $start->addDays($latest_range)->getTimestamp(); |
|
| 223 | + } elseif ('weeks_after' == $latest_date) { |
|
| 224 | + $latest = $start->addWeeks($latest_range)->subDay()->getTimestamp(); |
|
| 225 | + } elseif ('months_after' == $latest_date) { |
|
| 226 | + $latest = $start->addMonths($latest_range)->subDay()->getTimestamp(); |
|
| 227 | + } elseif ('years_after' == $latest_date) { |
|
| 228 | + $latest = $start->addYears($latest_range)->subDay()->getTimestamp(); |
|
| 229 | 229 | } else { |
| 230 | 230 | $latest = $start->getTimestamp(); |
| 231 | 231 | } |
@@ -242,12 +242,12 @@ discard block |
||
| 242 | 242 | * |
| 243 | 243 | * @param int $time |
| 244 | 244 | */ |
| 245 | - public function set_cache( $time = 0 ) { |
|
| 246 | - if ( $time === 0 || ! is_numeric( $time ) ) { |
|
| 247 | - $cache = get_post_meta( $this->post_id, '_feed_cache', true ); |
|
| 248 | - $time = is_numeric( $cache ) && $cache > 0 ? absint( $cache ) : $this->cache; |
|
| 245 | + public function set_cache($time = 0) { |
|
| 246 | + if ($time === 0 || ! is_numeric($time)) { |
|
| 247 | + $cache = get_post_meta($this->post_id, '_feed_cache', true); |
|
| 248 | + $time = is_numeric($cache) && $cache > 0 ? absint($cache) : $this->cache; |
|
| 249 | 249 | } |
| 250 | - $this->cache = absint( $time ); |
|
| 250 | + $this->cache = absint($time); |
|
| 251 | 251 | } |
| 252 | 252 | |
| 253 | 253 | /** |
@@ -6,7 +6,7 @@ discard block |
||
| 6 | 6 | */ |
| 7 | 7 | namespace SimpleCalendar\Abstracts; |
| 8 | 8 | |
| 9 | -if ( ! defined( 'ABSPATH' ) ) { |
|
| 9 | +if ( ! defined('ABSPATH')) { |
|
| 10 | 10 | exit; |
| 11 | 11 | } |
| 12 | 12 | |
@@ -148,68 +148,68 @@ discard block |
||
| 148 | 148 | * |
| 149 | 149 | * @param array $field Field data. |
| 150 | 150 | */ |
| 151 | - public function __construct( $field ) { |
|
| 151 | + public function __construct($field) { |
|
| 152 | 152 | |
| 153 | 153 | // Field properties. |
| 154 | - if ( isset( $field['title'] ) ) { |
|
| 155 | - $this->title = esc_attr( $field['title'] ); |
|
| 154 | + if (isset($field['title'])) { |
|
| 155 | + $this->title = esc_attr($field['title']); |
|
| 156 | 156 | } |
| 157 | - if ( isset( $field['description'] ) ) { |
|
| 158 | - $this->description = wp_kses_post( $field['description'] ); |
|
| 157 | + if (isset($field['description'])) { |
|
| 158 | + $this->description = wp_kses_post($field['description']); |
|
| 159 | 159 | } |
| 160 | - if ( isset( $field['type'] ) ) { |
|
| 161 | - $this->type = esc_attr( $field['type'] ); |
|
| 160 | + if (isset($field['type'])) { |
|
| 161 | + $this->type = esc_attr($field['type']); |
|
| 162 | 162 | } |
| 163 | - if ( isset( $field['name'] ) ) { |
|
| 164 | - $this->name = esc_attr( $field['name'] ); |
|
| 163 | + if (isset($field['name'])) { |
|
| 164 | + $this->name = esc_attr($field['name']); |
|
| 165 | 165 | } |
| 166 | - if ( isset( $field['id'] ) ) { |
|
| 167 | - $this->id = esc_attr( $field['id'] ); |
|
| 166 | + if (isset($field['id'])) { |
|
| 167 | + $this->id = esc_attr($field['id']); |
|
| 168 | 168 | } |
| 169 | - if ( isset( $field['placeholder'] ) ) { |
|
| 170 | - $this->placeholder = esc_attr( $field['placeholder'] ); |
|
| 169 | + if (isset($field['placeholder'])) { |
|
| 170 | + $this->placeholder = esc_attr($field['placeholder']); |
|
| 171 | 171 | } |
| 172 | - if ( isset( $field['options'] ) && is_array( $field['options'] ) ) { |
|
| 173 | - $this->options = array_map( 'esc_attr', $field['options'] ); |
|
| 172 | + if (isset($field['options']) && is_array($field['options'])) { |
|
| 173 | + $this->options = array_map('esc_attr', $field['options']); |
|
| 174 | 174 | } |
| 175 | 175 | |
| 176 | 176 | // Escaping. |
| 177 | - if ( ! empty( $field['escaping'] ) && ( is_string( $field['escaping'] ) || is_array( $field['escaping'] ) ) ) { |
|
| 178 | - if ( isset( $field['default'] ) ) { |
|
| 179 | - $this->default = $this->escape_callback( $field['escaping'], $field['default'] ); |
|
| 177 | + if ( ! empty($field['escaping']) && (is_string($field['escaping']) || is_array($field['escaping']))) { |
|
| 178 | + if (isset($field['default'])) { |
|
| 179 | + $this->default = $this->escape_callback($field['escaping'], $field['default']); |
|
| 180 | 180 | } |
| 181 | - if ( isset( $field['value'] ) ) { |
|
| 182 | - $this->value = $this->escape_callback( $field['escaping'], $field['value'] ); |
|
| 181 | + if (isset($field['value'])) { |
|
| 182 | + $this->value = $this->escape_callback($field['escaping'], $field['value']); |
|
| 183 | 183 | } |
| 184 | 184 | } else { |
| 185 | - if ( isset( $field['default'] ) ) { |
|
| 186 | - $this->default = $this->escape( $field['default'] ); |
|
| 185 | + if (isset($field['default'])) { |
|
| 186 | + $this->default = $this->escape($field['default']); |
|
| 187 | 187 | } |
| 188 | - if ( isset( $field['value'] ) ) { |
|
| 189 | - $this->value = $this->escape( $field['value'] ); |
|
| 188 | + if (isset($field['value'])) { |
|
| 189 | + $this->value = $this->escape($field['value']); |
|
| 190 | 190 | } |
| 191 | 191 | } |
| 192 | 192 | |
| 193 | 193 | // Validation. |
| 194 | - if ( ! empty( $field['validation'] ) ) { |
|
| 195 | - $this->validation = $this->validate( $field['validation'], $this->value ); |
|
| 194 | + if ( ! empty($field['validation'])) { |
|
| 195 | + $this->validation = $this->validate($field['validation'], $this->value); |
|
| 196 | 196 | } |
| 197 | 197 | |
| 198 | 198 | // CSS classes and styles. |
| 199 | - $classes = isset( $field['class'] ) ? $field['class'] : ''; |
|
| 200 | - $this->set_class( $classes ); |
|
| 201 | - if ( isset( $field['style'] ) ) { |
|
| 202 | - $this->set_style( $field['style'] ); |
|
| 199 | + $classes = isset($field['class']) ? $field['class'] : ''; |
|
| 200 | + $this->set_class($classes); |
|
| 201 | + if (isset($field['style'])) { |
|
| 202 | + $this->set_style($field['style']); |
|
| 203 | 203 | } |
| 204 | 204 | |
| 205 | 205 | // Custom attributes. |
| 206 | - if ( isset( $field['attributes'] ) ) { |
|
| 207 | - $this->set_attributes( $field['attributes'] ); |
|
| 206 | + if (isset($field['attributes'])) { |
|
| 207 | + $this->set_attributes($field['attributes']); |
|
| 208 | 208 | } |
| 209 | 209 | |
| 210 | 210 | // Tooltip markup. |
| 211 | - if ( isset( $field['tooltip'] ) ) { |
|
| 212 | - $this->tooltip = ' <i class="simcal-icon-help simcal-help-tip" data-tip="' . esc_attr( $field['tooltip'] ) . '"></i> ' ; |
|
| 211 | + if (isset($field['tooltip'])) { |
|
| 212 | + $this->tooltip = ' <i class="simcal-icon-help simcal-help-tip" data-tip="'.esc_attr($field['tooltip']).'"></i> '; |
|
| 213 | 213 | } |
| 214 | 214 | } |
| 215 | 215 | |
@@ -222,13 +222,13 @@ discard block |
||
| 222 | 222 | * |
| 223 | 223 | * @return void |
| 224 | 224 | */ |
| 225 | - public function set_attributes( $attributes ) { |
|
| 225 | + public function set_attributes($attributes) { |
|
| 226 | 226 | |
| 227 | 227 | $attr = ''; |
| 228 | 228 | |
| 229 | - if ( ! empty( $attributes ) && is_array( $attributes ) ) { |
|
| 230 | - foreach ( $attributes as $k => $v ) { |
|
| 231 | - $attr .= esc_attr( $k ) . '="' . esc_attr( $v ) . '" '; |
|
| 229 | + if ( ! empty($attributes) && is_array($attributes)) { |
|
| 230 | + foreach ($attributes as $k => $v) { |
|
| 231 | + $attr .= esc_attr($k).'="'.esc_attr($v).'" '; |
|
| 232 | 232 | } |
| 233 | 233 | } |
| 234 | 234 | |
@@ -244,13 +244,13 @@ discard block |
||
| 244 | 244 | * |
| 245 | 245 | * @return void |
| 246 | 246 | */ |
| 247 | - public function set_style( $css ) { |
|
| 247 | + public function set_style($css) { |
|
| 248 | 248 | |
| 249 | 249 | $styles = ''; |
| 250 | 250 | |
| 251 | - if ( ! empty( $css ) && is_array( $css ) ) { |
|
| 252 | - foreach ( $css as $k => $v ) { |
|
| 253 | - $styles .= esc_attr( $k ) . ': ' . esc_attr( $v ) . '; '; |
|
| 251 | + if ( ! empty($css) && is_array($css)) { |
|
| 252 | + foreach ($css as $k => $v) { |
|
| 253 | + $styles .= esc_attr($k).': '.esc_attr($v).'; '; |
|
| 254 | 254 | } |
| 255 | 255 | } |
| 256 | 256 | |
@@ -266,23 +266,23 @@ discard block |
||
| 266 | 266 | * |
| 267 | 267 | * @return void |
| 268 | 268 | */ |
| 269 | - public function set_class( $class ) { |
|
| 269 | + public function set_class($class) { |
|
| 270 | 270 | |
| 271 | 271 | $classes = ''; |
| 272 | 272 | $type_class = ''; |
| 273 | 273 | $error = ''; |
| 274 | 274 | |
| 275 | - if ( ! empty( $class ) && is_array( $class ) ) { |
|
| 276 | - $classes = implode( ' ', array_map( 'esc_attr', $class ) ); |
|
| 275 | + if ( ! empty($class) && is_array($class)) { |
|
| 276 | + $classes = implode(' ', array_map('esc_attr', $class)); |
|
| 277 | 277 | } |
| 278 | - if ( ! empty( $this->type_class ) ) { |
|
| 279 | - $type_class = esc_attr( $this->type_class ); |
|
| 278 | + if ( ! empty($this->type_class)) { |
|
| 279 | + $type_class = esc_attr($this->type_class); |
|
| 280 | 280 | } |
| 281 | - if ( true !== $this->validation && ! empty( $this->validation ) ) { |
|
| 281 | + if (true !== $this->validation && ! empty($this->validation)) { |
|
| 282 | 282 | $error = 'simcal-field-error '; |
| 283 | 283 | } |
| 284 | 284 | |
| 285 | - $this->class = trim( $error . 'simcal-field ' . $type_class . ' ' . $classes ); |
|
| 285 | + $this->class = trim($error.'simcal-field '.$type_class.' '.$classes); |
|
| 286 | 286 | } |
| 287 | 287 | |
| 288 | 288 | /** |
@@ -297,8 +297,8 @@ discard block |
||
| 297 | 297 | * |
| 298 | 298 | * @return array|string |
| 299 | 299 | */ |
| 300 | - protected function escape( $value ) { |
|
| 301 | - return ! empty( $value ) ? ( is_array( $value ) ? array_map( 'esc_attr', $value ) : esc_attr( $value ) ) : ''; |
|
| 300 | + protected function escape($value) { |
|
| 301 | + return ! empty($value) ? (is_array($value) ? array_map('esc_attr', $value) : esc_attr($value)) : ''; |
|
| 302 | 302 | } |
| 303 | 303 | |
| 304 | 304 | /** |
@@ -314,11 +314,11 @@ discard block |
||
| 314 | 314 | * |
| 315 | 315 | * @return mixed |
| 316 | 316 | */ |
| 317 | - protected function escape_callback( $callback, $value ) { |
|
| 318 | - if ( $callback && ( is_string( $callback ) || is_array( $callback ) ) ) { |
|
| 319 | - return call_user_func( $callback, $value ); |
|
| 317 | + protected function escape_callback($callback, $value) { |
|
| 318 | + if ($callback && (is_string($callback) || is_array($callback))) { |
|
| 319 | + return call_user_func($callback, $value); |
|
| 320 | 320 | } |
| 321 | - return esc_attr( $value ); |
|
| 321 | + return esc_attr($value); |
|
| 322 | 322 | } |
| 323 | 323 | |
| 324 | 324 | /** |
@@ -334,10 +334,10 @@ discard block |
||
| 334 | 334 | * |
| 335 | 335 | * @return true|string Expected to return bool (true) if passes, message string if not. |
| 336 | 336 | */ |
| 337 | - protected function validate( $callback, $value ) { |
|
| 338 | - if ( $callback && ( is_string( $callback ) || is_array( $callback ) ) ) { |
|
| 339 | - $screen = function_exists( 'get_current_screen' ) ? get_current_screen() : ''; |
|
| 340 | - return call_user_func( $callback, $value, $screen ); |
|
| 337 | + protected function validate($callback, $value) { |
|
| 338 | + if ($callback && (is_string($callback) || is_array($callback))) { |
|
| 339 | + $screen = function_exists('get_current_screen') ? get_current_screen() : ''; |
|
| 340 | + return call_user_func($callback, $value, $screen); |
|
| 341 | 341 | } |
| 342 | 342 | return true; |
| 343 | 343 | } |