@@ -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 | 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 )->startOfDay()->subSeconds( 59 ); |
|
| 218 | - $google_end_utc = Carbon::createFromDate( $date->year, $date->month, $date->day, 'UTC' )->startOfDay()->subSeconds( 59 ); |
|
| 216 | + $date = Carbon::parse($event->getEnd()->date); |
|
| 217 | + $google_end = Carbon::createFromDate($date->year, $date->month, $date->day, $end_timezone)->startOfDay()->subSeconds(59); |
|
| 218 | + $google_end_utc = Carbon::createFromDate($date->year, $date->month, $date->day, 'UTC')->startOfDay()->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 ), 1 ) // Since a value of 0 means forever we set the minimum here to 1 if the user has set it to be 0 |
|
| 294 | + max(absint($this->cache), 1) // Since a value of 0 means forever we set the minimum here to 1 if the user has set it to be 0 |
|
| 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. |
@@ -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 | } |
@@ -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 | |
@@ -28,7 +28,7 @@ discard block |
||
| 28 | 28 | * |
| 29 | 29 | * @return void |
| 30 | 30 | */ |
| 31 | - public static function html( $post ); |
|
| 31 | + public static function html($post); |
|
| 32 | 32 | |
| 33 | 33 | /** |
| 34 | 34 | * Validate and save the meta box fields. |
@@ -40,6 +40,6 @@ discard block |
||
| 40 | 40 | * |
| 41 | 41 | * @return void |
| 42 | 42 | */ |
| 43 | - public static function save( $post_id, $post ); |
|
| 43 | + public static function save($post_id, $post); |
|
| 44 | 44 | |
| 45 | 45 | } |
@@ -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 | |
@@ -36,7 +36,7 @@ discard block |
||
| 36 | 36 | * |
| 37 | 37 | * @return void |
| 38 | 38 | */ |
| 39 | - public function widget( $args, $instance ); |
|
| 39 | + public function widget($args, $instance); |
|
| 40 | 40 | |
| 41 | 41 | /** |
| 42 | 42 | * Update a particular instance of the widget. |
@@ -52,7 +52,7 @@ discard block |
||
| 52 | 52 | * |
| 53 | 53 | * @return array Settings to save or bool false to cancel saving. |
| 54 | 54 | */ |
| 55 | - public function update( $new_instance, $old_instance ); |
|
| 55 | + public function update($new_instance, $old_instance); |
|
| 56 | 56 | |
| 57 | 57 | /** |
| 58 | 58 | * Print the settings update form. |
@@ -63,6 +63,6 @@ discard block |
||
| 63 | 63 | * |
| 64 | 64 | * @return string |
| 65 | 65 | */ |
| 66 | - public function form( $instance ); |
|
| 66 | + public function form($instance); |
|
| 67 | 67 | |
| 68 | 68 | } |