@@ -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' == $date_format_option ) { |
|
| 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' == $date_format_option) { |
|
| 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' == $time_format_option ) { |
|
| 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' == $time_format_option) { |
|
| 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', true ) ), 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', true)), 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 SimpleCalendar\Abstracts\Calendar_View; |
| 10 | 10 | |
| 11 | -if ( ! defined( 'ABSPATH' ) ) { |
|
| 11 | +if ( ! defined('ABSPATH')) { |
|
| 12 | 12 | exit; |
| 13 | 13 | } |
| 14 | 14 | |
@@ -76,23 +76,23 @@ discard block |
||
| 76 | 76 | */ |
| 77 | 77 | public function __construct() { |
| 78 | 78 | |
| 79 | - $this->min = ( defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG == true ) ? '' : '.min'; |
|
| 79 | + $this->min = (defined('SCRIPT_DEBUG') && SCRIPT_DEBUG == true) ? '' : '.min'; |
|
| 80 | 80 | |
| 81 | - $settings = get_option( 'simple-calendar_settings_advanced' ); |
|
| 82 | - if ( isset( $settings['assets']['disable_js'] ) ) { |
|
| 81 | + $settings = get_option('simple-calendar_settings_advanced'); |
|
| 82 | + if (isset($settings['assets']['disable_js'])) { |
|
| 83 | 83 | $this->disable_scripts = 'yes' == $settings['assets']['disable_js'] ? true : false; |
| 84 | 84 | } |
| 85 | 85 | |
| 86 | - if ( isset( $settings['assets']['disable_css'] ) ) { |
|
| 86 | + if (isset($settings['assets']['disable_css'])) { |
|
| 87 | 87 | $this->disable_styles = 'yes' == $settings['assets']['disable_css'] ? true : false; |
| 88 | 88 | } |
| 89 | 89 | |
| 90 | - if ( isset( $settings['assets']['always_enqueue'] ) ) { |
|
| 90 | + if (isset($settings['assets']['always_enqueue'])) { |
|
| 91 | 91 | $this->always_enqueue = 'yes' == $settings['assets']['always_enqueue'] ? true : false; |
| 92 | 92 | } |
| 93 | 93 | |
| 94 | - add_action( 'init', array( $this, 'register' ), 20 ); |
|
| 95 | - add_action( 'init', array( $this, 'enqueue' ), 40 ); |
|
| 94 | + add_action('init', array($this, 'register'), 20); |
|
| 95 | + add_action('init', array($this, 'enqueue'), 40); |
|
| 96 | 96 | } |
| 97 | 97 | |
| 98 | 98 | /** |
@@ -101,7 +101,7 @@ discard block |
||
| 101 | 101 | * @since 3.0.0 |
| 102 | 102 | */ |
| 103 | 103 | public function register() { |
| 104 | - do_action( 'simcal_register_assets', $this->min ); |
|
| 104 | + do_action('simcal_register_assets', $this->min); |
|
| 105 | 105 | } |
| 106 | 106 | |
| 107 | 107 | /** |
@@ -111,25 +111,25 @@ discard block |
||
| 111 | 111 | */ |
| 112 | 112 | public function enqueue() { |
| 113 | 113 | |
| 114 | - add_action( 'wp_enqueue_scripts', array( $this, 'load' ), 10 ); |
|
| 114 | + add_action('wp_enqueue_scripts', array($this, 'load'), 10); |
|
| 115 | 115 | |
| 116 | - do_action( 'simcal_enqueue_assets', $this->min ); |
|
| 116 | + do_action('simcal_enqueue_assets', $this->min); |
|
| 117 | 117 | |
| 118 | - if ( false === $this->disable_scripts ) { |
|
| 118 | + if (false === $this->disable_scripts) { |
|
| 119 | 119 | $min = $this->min; |
| 120 | 120 | // Improves compatibility with themes and plugins using Isotope and Masonry. |
| 121 | - add_action( 'wp_enqueue_scripts', |
|
| 122 | - function () use ( $min ) { |
|
| 123 | - if ( wp_script_is( 'simcal-qtip', 'enqueued' ) ) { |
|
| 121 | + add_action('wp_enqueue_scripts', |
|
| 122 | + function() use ($min) { |
|
| 123 | + if (wp_script_is('simcal-qtip', 'enqueued')) { |
|
| 124 | 124 | wp_enqueue_script( |
| 125 | 125 | 'simplecalendar-imagesloaded', |
| 126 | - SIMPLE_CALENDAR_ASSETS . 'js/vendor/imagesloaded' . $min . '.js', |
|
| 127 | - array( 'simcal-qtip' ), |
|
| 126 | + SIMPLE_CALENDAR_ASSETS.'js/vendor/imagesloaded'.$min.'.js', |
|
| 127 | + array('simcal-qtip'), |
|
| 128 | 128 | '3.1.8', |
| 129 | 129 | true |
| 130 | 130 | ); |
| 131 | 131 | } |
| 132 | - }, 1000 ); |
|
| 132 | + }, 1000); |
|
| 133 | 133 | } |
| 134 | 134 | } |
| 135 | 135 | |
@@ -140,15 +140,15 @@ discard block |
||
| 140 | 140 | */ |
| 141 | 141 | public function load() { |
| 142 | 142 | |
| 143 | - if ( $this->always_enqueue ) { |
|
| 143 | + if ($this->always_enqueue) { |
|
| 144 | 144 | $scripts = $this->get_default_scripts(); |
| 145 | 145 | $styles = $this->get_default_styles(); |
| 146 | 146 | |
| 147 | - $this->scripts = apply_filters( 'simcal_front_end_scripts', $scripts, $this->min ); |
|
| 148 | - $this->styles = apply_filters( 'simcal_front_end_styles', $styles, $this->min ); |
|
| 147 | + $this->scripts = apply_filters('simcal_front_end_scripts', $scripts, $this->min); |
|
| 148 | + $this->styles = apply_filters('simcal_front_end_styles', $styles, $this->min); |
|
| 149 | 149 | |
| 150 | - $this->load_scripts( $this->scripts ); |
|
| 151 | - $this->load_styles( $this->styles ); |
|
| 150 | + $this->load_scripts($this->scripts); |
|
| 151 | + $this->load_styles($this->styles); |
|
| 152 | 152 | |
| 153 | 153 | return; |
| 154 | 154 | } |
@@ -157,33 +157,33 @@ discard block |
||
| 157 | 157 | $cal_id = array(); |
| 158 | 158 | $scripts = $styles = array(); |
| 159 | 159 | |
| 160 | - if ( is_singular() ) { |
|
| 160 | + if (is_singular()) { |
|
| 161 | 161 | |
| 162 | 162 | global $post, $post_type; |
| 163 | 163 | |
| 164 | - if ( 'calendar' == $post_type ) { |
|
| 164 | + if ('calendar' == $post_type) { |
|
| 165 | 165 | |
| 166 | 166 | $id = get_queried_object_id(); |
| 167 | 167 | |
| 168 | - $view = simcal_get_calendar_view( $id ); |
|
| 169 | - if ( $view instanceof Calendar_View ) { |
|
| 170 | - $scripts[] = $view->scripts( $this->min ); |
|
| 171 | - $styles[] = $view->styles( $this->min ); |
|
| 168 | + $view = simcal_get_calendar_view($id); |
|
| 169 | + if ($view instanceof Calendar_View) { |
|
| 170 | + $scripts[] = $view->scripts($this->min); |
|
| 171 | + $styles[] = $view->styles($this->min); |
|
| 172 | 172 | } |
| 173 | 173 | |
| 174 | 174 | } else { |
| 175 | 175 | |
| 176 | - $id = absint( get_post_meta( $post->ID, '_simcal_attach_calendar_id', true ) ); |
|
| 176 | + $id = absint(get_post_meta($post->ID, '_simcal_attach_calendar_id', true)); |
|
| 177 | 177 | |
| 178 | - if ( $id === 0 ) { |
|
| 178 | + if ($id === 0) { |
|
| 179 | 179 | |
| 180 | - preg_match_all( '/' . get_shortcode_regex() . '/s', $post->post_content, $matches, PREG_SET_ORDER ); |
|
| 180 | + preg_match_all('/'.get_shortcode_regex().'/s', $post->post_content, $matches, PREG_SET_ORDER); |
|
| 181 | 181 | |
| 182 | - if ( ! empty( $matches ) && is_array( $matches ) ) { |
|
| 183 | - foreach ( $matches as $shortcode ) { |
|
| 184 | - if ( 'calendar' === $shortcode[2] || 'gcal' === $shortcode[2] ) { |
|
| 185 | - $atts = shortcode_parse_atts( $shortcode[3] ); |
|
| 186 | - $cal_id[] = isset( $atts['id'] ) ? intval( $atts['id'] ) : 0; |
|
| 182 | + if ( ! empty($matches) && is_array($matches)) { |
|
| 183 | + foreach ($matches as $shortcode) { |
|
| 184 | + if ('calendar' === $shortcode[2] || 'gcal' === $shortcode[2]) { |
|
| 185 | + $atts = shortcode_parse_atts($shortcode[3]); |
|
| 186 | + $cal_id[] = isset($atts['id']) ? intval($atts['id']) : 0; |
|
| 187 | 187 | } |
| 188 | 188 | } |
| 189 | 189 | } |
@@ -191,41 +191,41 @@ discard block |
||
| 191 | 191 | } |
| 192 | 192 | } |
| 193 | 193 | |
| 194 | - foreach( $cal_id as $i ) { |
|
| 194 | + foreach ($cal_id as $i) { |
|
| 195 | 195 | |
| 196 | - if ( $i > 0 ) { |
|
| 196 | + if ($i > 0) { |
|
| 197 | 197 | |
| 198 | - $view = simcal_get_calendar_view( $i ); |
|
| 198 | + $view = simcal_get_calendar_view($i); |
|
| 199 | 199 | |
| 200 | - if ( $view instanceof Calendar_View ) { |
|
| 201 | - $scripts[] = $view->scripts( $this->min ); |
|
| 202 | - $styles[] = $view->styles( $this->min ); |
|
| 200 | + if ($view instanceof Calendar_View) { |
|
| 201 | + $scripts[] = $view->scripts($this->min); |
|
| 202 | + $styles[] = $view->styles($this->min); |
|
| 203 | 203 | } |
| 204 | 204 | } |
| 205 | 205 | } |
| 206 | 206 | |
| 207 | 207 | $this->get_widgets_assets(); |
| 208 | 208 | |
| 209 | - $this->scripts = apply_filters( 'simcal_front_end_scripts', $scripts, $this->min ); |
|
| 209 | + $this->scripts = apply_filters('simcal_front_end_scripts', $scripts, $this->min); |
|
| 210 | 210 | |
| 211 | 211 | // First check if there is a multi-dimensional array of scripts |
| 212 | - if ( isset( $this->scripts[0] ) ) { |
|
| 213 | - foreach ( $this->scripts as $script ) { |
|
| 214 | - $this->load_scripts ( $script ); |
|
| 212 | + if (isset($this->scripts[0])) { |
|
| 213 | + foreach ($this->scripts as $script) { |
|
| 214 | + $this->load_scripts($script); |
|
| 215 | 215 | } |
| 216 | 216 | } else { |
| 217 | - $this->load_scripts( $this->scripts ); |
|
| 217 | + $this->load_scripts($this->scripts); |
|
| 218 | 218 | } |
| 219 | 219 | |
| 220 | - $this->styles = apply_filters( 'simcal_front_end_styles', $styles, $this->min ); |
|
| 220 | + $this->styles = apply_filters('simcal_front_end_styles', $styles, $this->min); |
|
| 221 | 221 | |
| 222 | 222 | // First check if there is a multi-dimensional array of styles |
| 223 | - if ( isset( $this->styles[0] ) ) { |
|
| 224 | - foreach( $this->styles as $style ) { |
|
| 225 | - $this->load_styles( $style ); |
|
| 223 | + if (isset($this->styles[0])) { |
|
| 224 | + foreach ($this->styles as $style) { |
|
| 225 | + $this->load_styles($style); |
|
| 226 | 226 | } |
| 227 | 227 | } else { |
| 228 | - $this->load_styles( $this->styles ); |
|
| 228 | + $this->load_styles($this->styles); |
|
| 229 | 229 | } |
| 230 | 230 | } |
| 231 | 231 | |
@@ -236,25 +236,25 @@ discard block |
||
| 236 | 236 | */ |
| 237 | 237 | public function get_widgets_assets() { |
| 238 | 238 | |
| 239 | - $widgets = get_option( 'widget_gce_widget' ); |
|
| 239 | + $widgets = get_option('widget_gce_widget'); |
|
| 240 | 240 | |
| 241 | - if ( ! empty( $widgets ) && is_array( $widgets ) ) { |
|
| 241 | + if ( ! empty($widgets) && is_array($widgets)) { |
|
| 242 | 242 | |
| 243 | - foreach ( $widgets as $settings ) { |
|
| 243 | + foreach ($widgets as $settings) { |
|
| 244 | 244 | |
| 245 | - if ( ! empty( $settings ) && is_array( $settings ) ) { |
|
| 245 | + if ( ! empty($settings) && is_array($settings)) { |
|
| 246 | 246 | |
| 247 | - if ( isset( $settings['calendar_id'] ) ) { |
|
| 247 | + if (isset($settings['calendar_id'])) { |
|
| 248 | 248 | |
| 249 | - $view = simcal_get_calendar_view( absint( $settings['calendar_id'] ) ); |
|
| 249 | + $view = simcal_get_calendar_view(absint($settings['calendar_id'])); |
|
| 250 | 250 | |
| 251 | - if ( $view instanceof Calendar_View ) { |
|
| 252 | - add_filter( 'simcal_front_end_scripts', function ( $scripts, $min ) use ( $view ) { |
|
| 253 | - return array_merge( $scripts, $view->scripts( $min ) ); |
|
| 254 | - }, 100, 2 ); |
|
| 255 | - add_filter( 'simcal_front_end_styles', function ( $styles, $min ) use ( $view ) { |
|
| 256 | - return array_merge( $styles, $view->styles( $min ) ); |
|
| 257 | - }, 100, 2 ); |
|
| 251 | + if ($view instanceof Calendar_View) { |
|
| 252 | + add_filter('simcal_front_end_scripts', function($scripts, $min) use ($view) { |
|
| 253 | + return array_merge($scripts, $view->scripts($min)); |
|
| 254 | + }, 100, 2); |
|
| 255 | + add_filter('simcal_front_end_styles', function($styles, $min) use ($view) { |
|
| 256 | + return array_merge($styles, $view->styles($min)); |
|
| 257 | + }, 100, 2); |
|
| 258 | 258 | } |
| 259 | 259 | |
| 260 | 260 | } |
@@ -272,31 +272,31 @@ discard block |
||
| 272 | 272 | * |
| 273 | 273 | * @param array $scripts |
| 274 | 274 | */ |
| 275 | - public function load_scripts( $scripts ) { |
|
| 275 | + public function load_scripts($scripts) { |
|
| 276 | 276 | |
| 277 | 277 | // Only load if not disabled in the settings |
| 278 | - if ( ! empty( $scripts ) && is_array( $scripts ) && false === $this->disable_scripts ) { |
|
| 278 | + if ( ! empty($scripts) && is_array($scripts) && false === $this->disable_scripts) { |
|
| 279 | 279 | |
| 280 | - foreach ( $scripts as $script => $v ) { |
|
| 280 | + foreach ($scripts as $script => $v) { |
|
| 281 | 281 | |
| 282 | - if ( ! empty( $v['src'] ) ) { |
|
| 282 | + if ( ! empty($v['src'])) { |
|
| 283 | 283 | |
| 284 | - $src = esc_url( $v['src'] ); |
|
| 285 | - $deps = isset( $v['deps'] ) ? $v['deps'] : array(); |
|
| 286 | - $ver = isset( $v['ver'] ) ? $v['ver'] : SIMPLE_CALENDAR_VERSION; |
|
| 287 | - $in_footer = isset( $v['in_footer'] ) ? $v['in_footer'] : false; |
|
| 284 | + $src = esc_url($v['src']); |
|
| 285 | + $deps = isset($v['deps']) ? $v['deps'] : array(); |
|
| 286 | + $ver = isset($v['ver']) ? $v['ver'] : SIMPLE_CALENDAR_VERSION; |
|
| 287 | + $in_footer = isset($v['in_footer']) ? $v['in_footer'] : false; |
|
| 288 | 288 | |
| 289 | - wp_enqueue_script( $script, $src, $deps, $ver, $in_footer ); |
|
| 289 | + wp_enqueue_script($script, $src, $deps, $ver, $in_footer); |
|
| 290 | 290 | |
| 291 | - if ( ! empty( $v['localize'] ) && is_array( $v['localize'] ) ) { |
|
| 292 | - foreach ( $v['localize'] as $object => $l10n ) { |
|
| 293 | - wp_localize_script( $script, $object, $l10n ); |
|
| 291 | + if ( ! empty($v['localize']) && is_array($v['localize'])) { |
|
| 292 | + foreach ($v['localize'] as $object => $l10n) { |
|
| 293 | + wp_localize_script($script, $object, $l10n); |
|
| 294 | 294 | } |
| 295 | 295 | } |
| 296 | 296 | |
| 297 | - } elseif ( is_string( $v ) && ! empty( $v ) ) { |
|
| 297 | + } elseif (is_string($v) && ! empty($v)) { |
|
| 298 | 298 | |
| 299 | - wp_enqueue_script( $v ); |
|
| 299 | + wp_enqueue_script($v); |
|
| 300 | 300 | } |
| 301 | 301 | } |
| 302 | 302 | |
@@ -310,25 +310,25 @@ discard block |
||
| 310 | 310 | * |
| 311 | 311 | * @param array $styles |
| 312 | 312 | */ |
| 313 | - public function load_styles( $styles ) { |
|
| 313 | + public function load_styles($styles) { |
|
| 314 | 314 | |
| 315 | 315 | // Only load if not disabled in the settings |
| 316 | - if ( ! empty( $styles ) && is_array( $styles ) && false === $this->disable_styles ) { |
|
| 316 | + if ( ! empty($styles) && is_array($styles) && false === $this->disable_styles) { |
|
| 317 | 317 | |
| 318 | - foreach ( $styles as $style => $v ) { |
|
| 318 | + foreach ($styles as $style => $v) { |
|
| 319 | 319 | |
| 320 | - if ( ! empty( $v['src'] ) ) { |
|
| 320 | + if ( ! empty($v['src'])) { |
|
| 321 | 321 | |
| 322 | - $src = esc_url( $v['src'] ); |
|
| 323 | - $deps = isset( $v['deps'] ) ? $v['deps'] : array(); |
|
| 324 | - $ver = isset( $v['ver'] ) ? $v['ver'] : SIMPLE_CALENDAR_VERSION; |
|
| 325 | - $media = isset( $v['media'] ) ? $v['media'] : 'all'; |
|
| 322 | + $src = esc_url($v['src']); |
|
| 323 | + $deps = isset($v['deps']) ? $v['deps'] : array(); |
|
| 324 | + $ver = isset($v['ver']) ? $v['ver'] : SIMPLE_CALENDAR_VERSION; |
|
| 325 | + $media = isset($v['media']) ? $v['media'] : 'all'; |
|
| 326 | 326 | |
| 327 | - wp_enqueue_style( $style, $src, $deps, $ver, $media ); |
|
| 327 | + wp_enqueue_style($style, $src, $deps, $ver, $media); |
|
| 328 | 328 | |
| 329 | - } elseif ( is_string( $v ) && ! empty( $v ) ) { |
|
| 329 | + } elseif (is_string($v) && ! empty($v)) { |
|
| 330 | 330 | |
| 331 | - wp_enqueue_style( $v ); |
|
| 331 | + wp_enqueue_style($v); |
|
| 332 | 332 | } |
| 333 | 333 | |
| 334 | 334 | } |
@@ -344,13 +344,13 @@ discard block |
||
| 344 | 344 | public function get_default_scripts() { |
| 345 | 345 | return array( |
| 346 | 346 | 'simcal-qtip' => array( |
| 347 | - 'src' => SIMPLE_CALENDAR_ASSETS . 'js/vendor/qtip' . $this->min . '.js', |
|
| 348 | - 'deps' => array( 'jquery' ), |
|
| 347 | + 'src' => SIMPLE_CALENDAR_ASSETS.'js/vendor/qtip'.$this->min.'.js', |
|
| 348 | + 'deps' => array('jquery'), |
|
| 349 | 349 | 'ver' => '2.2.1', |
| 350 | 350 | 'in_footer' => true, |
| 351 | 351 | ), |
| 352 | 352 | 'simcal-default-calendar' => array( |
| 353 | - 'src' => SIMPLE_CALENDAR_ASSETS . 'js/default-calendar' . $this->min . '.js', |
|
| 353 | + 'src' => SIMPLE_CALENDAR_ASSETS.'js/default-calendar'.$this->min.'.js', |
|
| 354 | 354 | 'deps' => array( |
| 355 | 355 | 'jquery', |
| 356 | 356 | 'simcal-qtip', |
@@ -372,12 +372,12 @@ discard block |
||
| 372 | 372 | public function get_default_styles() { |
| 373 | 373 | return array( |
| 374 | 374 | 'simcal-qtip' => array( |
| 375 | - 'src' => SIMPLE_CALENDAR_ASSETS . 'css/vendor/qtip' . $this->min . '.css', |
|
| 375 | + 'src' => SIMPLE_CALENDAR_ASSETS.'css/vendor/qtip'.$this->min.'.css', |
|
| 376 | 376 | 'ver' => '2.2.1', |
| 377 | 377 | 'media' => 'all', |
| 378 | 378 | ), |
| 379 | 379 | 'simcal-default-calendar-grid' => array( |
| 380 | - 'src' => SIMPLE_CALENDAR_ASSETS . 'css/default-calendar-grid' . $this->min . '.css', |
|
| 380 | + 'src' => SIMPLE_CALENDAR_ASSETS.'css/default-calendar-grid'.$this->min.'.css', |
|
| 381 | 381 | 'deps' => array( |
| 382 | 382 | 'simcal-qtip', |
| 383 | 383 | ), |
@@ -385,7 +385,7 @@ discard block |
||
| 385 | 385 | 'media' => 'all', |
| 386 | 386 | ), |
| 387 | 387 | 'simcal-default-calendar-list' => array( |
| 388 | - 'src' => SIMPLE_CALENDAR_ASSETS . 'css/default-calendar-list' . $this->min . '.css', |
|
| 388 | + 'src' => SIMPLE_CALENDAR_ASSETS.'css/default-calendar-list'.$this->min.'.css', |
|
| 389 | 389 | 'deps' => array( |
| 390 | 390 | 'simcal-qtip', |
| 391 | 391 | ), |
@@ -13,7 +13,7 @@ discard block |
||
| 13 | 13 | use SimpleCalendar\Events\Event; |
| 14 | 14 | use SimpleCalendar\Calendars\Default_Calendar; |
| 15 | 15 | |
| 16 | -if ( ! defined( 'ABSPATH' ) ) { |
|
| 16 | +if ( ! defined('ABSPATH')) { |
|
| 17 | 17 | exit; |
| 18 | 18 | } |
| 19 | 19 | |
@@ -55,7 +55,7 @@ discard block |
||
| 55 | 55 | * |
| 56 | 56 | * @param string|Calendar $calendar |
| 57 | 57 | */ |
| 58 | - public function __construct( $calendar = '' ) { |
|
| 58 | + public function __construct($calendar = '') { |
|
| 59 | 59 | $this->calendar = $calendar; |
| 60 | 60 | } |
| 61 | 61 | |
@@ -89,7 +89,7 @@ discard block |
||
| 89 | 89 | * @return string |
| 90 | 90 | */ |
| 91 | 91 | public function get_name() { |
| 92 | - return __( 'Grid', 'google-calendar-events' ); |
|
| 92 | + return __('Grid', 'google-calendar-events'); |
|
| 93 | 93 | } |
| 94 | 94 | |
| 95 | 95 | /** |
@@ -98,8 +98,8 @@ discard block |
||
| 98 | 98 | * @since 3.0.0 |
| 99 | 99 | */ |
| 100 | 100 | public function add_ajax_actions() { |
| 101 | - add_action( 'wp_ajax_simcal_default_calendar_draw_grid', array( $this, 'draw_grid_ajax' ) ); |
|
| 102 | - add_action( 'wp_ajax_nopriv_simcal_default_calendar_draw_grid', array( $this, 'draw_grid_ajax' ) ); |
|
| 101 | + add_action('wp_ajax_simcal_default_calendar_draw_grid', array($this, 'draw_grid_ajax')); |
|
| 102 | + add_action('wp_ajax_nopriv_simcal_default_calendar_draw_grid', array($this, 'draw_grid_ajax')); |
|
| 103 | 103 | } |
| 104 | 104 | |
| 105 | 105 | /** |
@@ -113,16 +113,16 @@ discard block |
||
| 113 | 113 | * |
| 114 | 114 | * @return array |
| 115 | 115 | */ |
| 116 | - public function scripts( $min = '' ) { |
|
| 116 | + public function scripts($min = '') { |
|
| 117 | 117 | return array( |
| 118 | 118 | 'simcal-qtip' => array( |
| 119 | - 'src' => SIMPLE_CALENDAR_ASSETS . 'js/vendor/qtip' . $min . '.js', |
|
| 120 | - 'deps' => array( 'jquery' ), |
|
| 119 | + 'src' => SIMPLE_CALENDAR_ASSETS.'js/vendor/qtip'.$min.'.js', |
|
| 120 | + 'deps' => array('jquery'), |
|
| 121 | 121 | 'ver' => '2.2.1', |
| 122 | 122 | 'in_footer' => true, |
| 123 | 123 | ), |
| 124 | 124 | 'simcal-default-calendar' => array( |
| 125 | - 'src' => SIMPLE_CALENDAR_ASSETS . 'js/default-calendar' . $min . '.js', |
|
| 125 | + 'src' => SIMPLE_CALENDAR_ASSETS.'js/default-calendar'.$min.'.js', |
|
| 126 | 126 | 'deps' => array( |
| 127 | 127 | 'jquery', |
| 128 | 128 | 'simcal-qtip', |
@@ -147,15 +147,15 @@ discard block |
||
| 147 | 147 | * |
| 148 | 148 | * @return array |
| 149 | 149 | */ |
| 150 | - public function styles( $min = '' ) { |
|
| 150 | + public function styles($min = '') { |
|
| 151 | 151 | return array( |
| 152 | 152 | 'simcal-qtip' => array( |
| 153 | - 'src' => SIMPLE_CALENDAR_ASSETS . 'css/vendor/qtip' . $min . '.css', |
|
| 153 | + 'src' => SIMPLE_CALENDAR_ASSETS.'css/vendor/qtip'.$min.'.css', |
|
| 154 | 154 | 'ver' => '2.2.1', |
| 155 | 155 | 'media' => 'all', |
| 156 | 156 | ), |
| 157 | 157 | 'simcal-default-calendar-grid' => array( |
| 158 | - 'src' => SIMPLE_CALENDAR_ASSETS . 'css/default-calendar-grid' . $min . '.css', |
|
| 158 | + 'src' => SIMPLE_CALENDAR_ASSETS.'css/default-calendar-grid'.$min.'.css', |
|
| 159 | 159 | 'deps' => array( |
| 160 | 160 | 'simcal-qtip', |
| 161 | 161 | ), |
@@ -174,16 +174,16 @@ discard block |
||
| 174 | 174 | |
| 175 | 175 | $calendar = $this->calendar; |
| 176 | 176 | |
| 177 | - if ( $calendar instanceof Default_Calendar ) { |
|
| 177 | + if ($calendar instanceof Default_Calendar) { |
|
| 178 | 178 | |
| 179 | 179 | ?> |
| 180 | 180 | <table class="simcal-calendar-grid" |
| 181 | 181 | data-event-bubble-trigger="<?php echo $calendar->event_bubble_trigger; ?>"> |
| 182 | 182 | <thead class="simcal-calendar-head"> |
| 183 | 183 | <tr> |
| 184 | - <?php if ( ! $calendar->static ) { ?> |
|
| 184 | + <?php if ( ! $calendar->static) { ?> |
|
| 185 | 185 | <th class="simcal-nav simcal-prev-wrapper" colspan="1"> |
| 186 | - <button class="simcal-nav-button simcal-month-nav simcal-prev" title="<?php _e( 'Previous Month', 'google-calendar-events' ); ?>"><i class="simcal-icon-left"></i></button> |
|
| 186 | + <button class="simcal-nav-button simcal-month-nav simcal-prev" title="<?php _e('Previous Month', 'google-calendar-events'); ?>"><i class="simcal-icon-left"></i></button> |
|
| 187 | 187 | </th> |
| 188 | 188 | <?php } ?> |
| 189 | 189 | <th colspan="<?php echo $calendar->static ? '7' : '5'; ?>" |
@@ -195,26 +195,26 @@ discard block |
||
| 195 | 195 | |
| 196 | 196 | // Display month and year according to user date format preference. |
| 197 | 197 | |
| 198 | - $year_pos = strcspn( $calendar->date_format, 'Y y' ); |
|
| 199 | - $month_pos = strcspn( $calendar->date_format, 'F M m n' ); |
|
| 198 | + $year_pos = strcspn($calendar->date_format, 'Y y'); |
|
| 199 | + $month_pos = strcspn($calendar->date_format, 'F M m n'); |
|
| 200 | 200 | |
| 201 | - $current = array( 'month' => 'F', 'year' => 'Y' ); |
|
| 201 | + $current = array('month' => 'F', 'year' => 'Y'); |
|
| 202 | 202 | |
| 203 | - if ( $year_pos < $month_pos ) { |
|
| 204 | - $current = array_reverse( $current ); |
|
| 203 | + if ($year_pos < $month_pos) { |
|
| 204 | + $current = array_reverse($current); |
|
| 205 | 205 | } |
| 206 | 206 | |
| 207 | - foreach ( $current as $k => $v ) { |
|
| 208 | - echo ' <span class="simcal-current-' . $k , '">' . date_i18n( $v, $calendar->start ) . '</span> '; |
|
| 207 | + foreach ($current as $k => $v) { |
|
| 208 | + echo ' <span class="simcal-current-'.$k, '">'.date_i18n($v, $calendar->start).'</span> '; |
|
| 209 | 209 | } |
| 210 | 210 | |
| 211 | 211 | echo '</h3>'; |
| 212 | 212 | |
| 213 | 213 | ?> |
| 214 | 214 | </th> |
| 215 | - <?php if ( ! $calendar->static ) { ?> |
|
| 215 | + <?php if ( ! $calendar->static) { ?> |
|
| 216 | 216 | <th class="simcal-nav simcal-next-wrapper" colspan="1"> |
| 217 | - <button class="simcal-nav-button simcal-month-nav simcal-next" title="<?php _e( 'Next Month', 'google-calendar-events' ); ?>"><i class="simcal-icon-right"></i></button> |
|
| 217 | + <button class="simcal-nav-button simcal-month-nav simcal-next" title="<?php _e('Next Month', 'google-calendar-events'); ?>"><i class="simcal-icon-right"></i></button> |
|
| 218 | 218 | </th> |
| 219 | 219 | <?php } ?> |
| 220 | 220 | </tr> |
@@ -224,28 +224,28 @@ discard block |
||
| 224 | 224 | // Print day names in short or long form for different viewport sizes. |
| 225 | 225 | |
| 226 | 226 | $week_starts = $calendar->week_starts; |
| 227 | - $week_days_short = simcal_get_calendar_names_i18n( 'day', 'short' ); |
|
| 228 | - $week_days_full = simcal_get_calendar_names_i18n( 'day', 'full' ); |
|
| 227 | + $week_days_short = simcal_get_calendar_names_i18n('day', 'short'); |
|
| 228 | + $week_days_full = simcal_get_calendar_names_i18n('day', 'full'); |
|
| 229 | 229 | |
| 230 | - for ( $i = $week_starts; $i <= 6; $i ++ ) : |
|
| 230 | + for ($i = $week_starts; $i <= 6; $i++) : |
|
| 231 | 231 | |
| 232 | 232 | ?> |
| 233 | 233 | <th class="simcal-week-day simcal-week-day-<?php echo $i ?>" |
| 234 | - data-screen-small="<?php echo mb_substr( $week_days_short[ $i ], 0, 1, 'UTF-8' ); ?>" |
|
| 235 | - data-screen-medium="<?php echo $week_days_short[ $i ]; ?>" |
|
| 236 | - data-screen-large="<?php echo $week_days_full[ $i ]; ?>"><?php echo $week_days_short[ $i ]; ?></th> |
|
| 234 | + data-screen-small="<?php echo mb_substr($week_days_short[$i], 0, 1, 'UTF-8'); ?>" |
|
| 235 | + data-screen-medium="<?php echo $week_days_short[$i]; ?>" |
|
| 236 | + data-screen-large="<?php echo $week_days_full[$i]; ?>"><?php echo $week_days_short[$i]; ?></th> |
|
| 237 | 237 | <?php |
| 238 | 238 | |
| 239 | 239 | endfor; |
| 240 | 240 | |
| 241 | - if ( $week_starts !== 0 ) : |
|
| 242 | - for ( $i = 0; $i < $week_starts; $i ++ ) : |
|
| 241 | + if ($week_starts !== 0) : |
|
| 242 | + for ($i = 0; $i < $week_starts; $i++) : |
|
| 243 | 243 | |
| 244 | 244 | ?> |
| 245 | 245 | <th class="simcal-week-day simcal-week-day-<?php echo $i ?>" |
| 246 | - data-screen-small="<?php echo substr( $week_days_short[ $i ], 0, 1 ); ?>" |
|
| 247 | - data-screen-medium="<?php echo $week_days_short[ $i ]; ?>" |
|
| 248 | - data-screen-large="<?php echo $week_days_full[ $i ]; ?>"><?php echo $week_days_short[ $i ]; ?></th> |
|
| 246 | + data-screen-small="<?php echo substr($week_days_short[$i], 0, 1); ?>" |
|
| 247 | + data-screen-medium="<?php echo $week_days_short[$i]; ?>" |
|
| 248 | + data-screen-large="<?php echo $week_days_full[$i]; ?>"><?php echo $week_days_short[$i]; ?></th> |
|
| 249 | 249 | <?php |
| 250 | 250 | |
| 251 | 251 | endfor; |
@@ -255,7 +255,7 @@ discard block |
||
| 255 | 255 | </tr> |
| 256 | 256 | </thead> |
| 257 | 257 | |
| 258 | - <?php echo $this->draw_month( date( 'n', $calendar->start ), date( 'Y', $calendar->start ) ); ?> |
|
| 258 | + <?php echo $this->draw_month(date('n', $calendar->start), date('Y', $calendar->start)); ?> |
|
| 259 | 259 | |
| 260 | 260 | </table> |
| 261 | 261 | <?php |
@@ -280,82 +280,82 @@ discard block |
||
| 280 | 280 | * |
| 281 | 281 | * @return string |
| 282 | 282 | */ |
| 283 | - private function draw_month( $month, $year, $id = 0 ) { |
|
| 283 | + private function draw_month($month, $year, $id = 0) { |
|
| 284 | 284 | |
| 285 | 285 | $calendar = $this->calendar; |
| 286 | - if ( empty( $calendar ) ) { |
|
| 287 | - $calendar = simcal_get_calendar( intval( $id ) ); |
|
| 288 | - if ( ! $calendar ) { |
|
| 286 | + if (empty($calendar)) { |
|
| 287 | + $calendar = simcal_get_calendar(intval($id)); |
|
| 288 | + if ( ! $calendar) { |
|
| 289 | 289 | return ''; |
| 290 | 290 | } |
| 291 | 291 | } |
| 292 | - date_default_timezone_set( $calendar->timezone ); |
|
| 292 | + date_default_timezone_set($calendar->timezone); |
|
| 293 | 293 | $events = $calendar->events; |
| 294 | 294 | |
| 295 | 295 | // Variables to cycle days in current month and find today in calendar. |
| 296 | 296 | $now = $calendar->now; |
| 297 | - $current = Carbon::create( $year, $month, 1, 0, 0, 59, $calendar->timezone ); |
|
| 297 | + $current = Carbon::create($year, $month, 1, 0, 0, 59, $calendar->timezone); |
|
| 298 | 298 | $current_min = $current->getTimestamp(); |
| 299 | 299 | $current_max = $current->endOfDay()->getTimestamp(); |
| 300 | 300 | |
| 301 | 301 | // Calendar grid variables. |
| 302 | 302 | $week_starts = $calendar->week_starts; |
| 303 | - $week_of_year = $current->weekOfYear; // Relative count of the week number of the year. |
|
| 304 | - $month_starts = $current->dayOfWeek; // Day upon which the month starts. |
|
| 305 | - $days_in_month = $current->daysInMonth; // Number of days in the given month. |
|
| 303 | + $week_of_year = $current->weekOfYear; // Relative count of the week number of the year. |
|
| 304 | + $month_starts = $current->dayOfWeek; // Day upon which the month starts. |
|
| 305 | + $days_in_month = $current->daysInMonth; // Number of days in the given month. |
|
| 306 | 306 | |
| 307 | 307 | // Set current month events timestamp boundaries. |
| 308 | 308 | $this->start = $current_min; |
| 309 | 309 | $this->end = $current->endOfMonth()->timestamp; |
| 310 | 310 | |
| 311 | 311 | // Get daily events for this month. |
| 312 | - if ( $events && is_array( $events ) ) { |
|
| 312 | + if ($events && is_array($events)) { |
|
| 313 | 313 | |
| 314 | 314 | // Filter events within the boundaries previously set above. |
| 315 | - $timestamps = array_keys( $events ); |
|
| 316 | - $lower_bound = array_filter( $timestamps, array( $this, 'filter_events_before' ) ); |
|
| 317 | - $higher_bound = array_filter( $lower_bound, array( $this, 'filter_events_after' ) ); |
|
| 318 | - $filtered = ( is_array( $events ) && is_array( $higher_bound) ) && ! empty( $events ) && ! empty( $higher_bound ) ? array_intersect_key( $events, array_combine( $higher_bound, $higher_bound ) ) : array(); |
|
| 315 | + $timestamps = array_keys($events); |
|
| 316 | + $lower_bound = array_filter($timestamps, array($this, 'filter_events_before')); |
|
| 317 | + $higher_bound = array_filter($lower_bound, array($this, 'filter_events_after')); |
|
| 318 | + $filtered = (is_array($events) && is_array($higher_bound)) && ! empty($events) && ! empty($higher_bound) ? array_intersect_key($events, array_combine($higher_bound, $higher_bound)) : array(); |
|
| 319 | 319 | |
| 320 | 320 | // Put resulting events in an associative array, with day of the month as key for easy retrieval in calendar days loop. |
| 321 | 321 | $day_events = array(); |
| 322 | - foreach ( $filtered as $timestamp => $events_in_day ) { |
|
| 323 | - foreach ( $events_in_day as $event ) { |
|
| 324 | - if ( $event instanceof Event ){ |
|
| 325 | - $day = intval( Carbon::createFromTimestamp( $timestamp, $event->timezone )->endOfDay()->day ); |
|
| 326 | - $day_events[ $day ][] = $event; |
|
| 322 | + foreach ($filtered as $timestamp => $events_in_day) { |
|
| 323 | + foreach ($events_in_day as $event) { |
|
| 324 | + if ($event instanceof Event) { |
|
| 325 | + $day = intval(Carbon::createFromTimestamp($timestamp, $event->timezone)->endOfDay()->day); |
|
| 326 | + $day_events[$day][] = $event; |
|
| 327 | 327 | } |
| 328 | 328 | } |
| 329 | 329 | } |
| 330 | 330 | |
| 331 | - ksort( $day_events, SORT_NUMERIC ); |
|
| 331 | + ksort($day_events, SORT_NUMERIC); |
|
| 332 | 332 | } |
| 333 | 333 | |
| 334 | 334 | ob_start(); |
| 335 | 335 | |
| 336 | - echo '<tbody class="simcal-month simcal-month-' . $month . '">' . "\n"; |
|
| 337 | - echo "\t" . '<tr class="simcal-week simcal-week-' . $week_of_year . '">'; |
|
| 336 | + echo '<tbody class="simcal-month simcal-month-'.$month.'">'."\n"; |
|
| 337 | + echo "\t".'<tr class="simcal-week simcal-week-'.$week_of_year.'">'; |
|
| 338 | 338 | |
| 339 | 339 | $days_in_row = 0; |
| 340 | 340 | // Week may start on an arbitrary day (sun, 0 - sat, 6). |
| 341 | 341 | $week_day = $week_starts; |
| 342 | 342 | |
| 343 | 343 | // This fixes a possible bug when a month starts by Sunday (0). |
| 344 | - if ( 0 !== $week_starts ) { |
|
| 344 | + if (0 !== $week_starts) { |
|
| 345 | 345 | $b = $month_starts === 0 ? 7 : $month_starts; |
| 346 | 346 | } else { |
| 347 | 347 | $b = $month_starts; |
| 348 | 348 | } |
| 349 | 349 | |
| 350 | 350 | // Void days in first week. |
| 351 | - for ( $a = $week_starts; $a < $b; $a++ ) : |
|
| 351 | + for ($a = $week_starts; $a < $b; $a++) : |
|
| 352 | 352 | |
| 353 | - $last_void_day_class = ( $a === ( $b - 1 ) ) ? 'simcal-day-void-last' : ''; |
|
| 353 | + $last_void_day_class = ($a === ($b - 1)) ? 'simcal-day-void-last' : ''; |
|
| 354 | 354 | |
| 355 | - echo '<td class="simcal-day simcal-day-void ' . $last_void_day_class . '"></td>' . "\n"; |
|
| 355 | + echo '<td class="simcal-day simcal-day-void '.$last_void_day_class.'"></td>'."\n"; |
|
| 356 | 356 | |
| 357 | 357 | // Reset day of the week count (sun, 0 - sat, 6). |
| 358 | - if ( $week_day === 6 ) { |
|
| 358 | + if ($week_day === 6) { |
|
| 359 | 359 | $week_day = -1; |
| 360 | 360 | } |
| 361 | 361 | $week_day++; |
@@ -365,91 +365,91 @@ discard block |
||
| 365 | 365 | endfor; |
| 366 | 366 | |
| 367 | 367 | // Actual days of the month. |
| 368 | - for ( $day = 1; $day <= $days_in_month; $day++ ) : |
|
| 368 | + for ($day = 1; $day <= $days_in_month; $day++) : |
|
| 369 | 369 | |
| 370 | 370 | $count = 0; |
| 371 | 371 | $calendar_classes = array(); |
| 372 | - $day_classes = 'simcal-day-' . $day . ' simcal-weekday-' . $week_day; |
|
| 372 | + $day_classes = 'simcal-day-'.$day.' simcal-weekday-'.$week_day; |
|
| 373 | 373 | |
| 374 | 374 | $border_style = $bg_color = $color = ''; |
| 375 | 375 | |
| 376 | 376 | // Is this the present, the past or the future, Doc? |
| 377 | - if ( $current_min <= $now && $current_max >= $now ) { |
|
| 377 | + if ($current_min <= $now && $current_max >= $now) { |
|
| 378 | 378 | $day_classes .= ' simcal-today simcal-present simcal-day'; |
| 379 | - $the_color = new Color( $calendar->today_color ); |
|
| 380 | - $bg_color = '#' . $the_color->getHex(); |
|
| 379 | + $the_color = new Color($calendar->today_color); |
|
| 380 | + $bg_color = '#'.$the_color->getHex(); |
|
| 381 | 381 | $color = $the_color->isDark() ? '#ffffff' : '#000000'; |
| 382 | - $border_style = ' style="border: 1px solid ' . $bg_color . ';"'; |
|
| 383 | - } elseif ( $current_max < $now ) { |
|
| 382 | + $border_style = ' style="border: 1px solid '.$bg_color.';"'; |
|
| 383 | + } elseif ($current_max < $now) { |
|
| 384 | 384 | $day_classes .= ' simcal-past simcal-day'; |
| 385 | - } elseif ( $current_min > $now ) { |
|
| 385 | + } elseif ($current_min > $now) { |
|
| 386 | 386 | $day_classes .= ' simcal-future simcal-day'; |
| 387 | 387 | } |
| 388 | 388 | |
| 389 | 389 | // Print events for the current day in loop, if found any. |
| 390 | - if ( isset( $day_events[ $day ] ) ) : |
|
| 390 | + if (isset($day_events[$day])) : |
|
| 391 | 391 | |
| 392 | 392 | $list_events = '<ul class="simcal-events">'; |
| 393 | 393 | |
| 394 | - foreach ( $day_events[ $day ] as $event ) : |
|
| 394 | + foreach ($day_events[$day] as $event) : |
|
| 395 | 395 | |
| 396 | 396 | $event_classes = $event_visibility = ''; |
| 397 | 397 | |
| 398 | - if ( $event instanceof Event ) : |
|
| 398 | + if ($event instanceof Event) : |
|
| 399 | 399 | |
| 400 | 400 | // Store the calendar id where the event belongs (useful in grouped calendar feeds) |
| 401 | - $calendar_class = 'simcal-events-calendar-' . strval( $event->calendar ); |
|
| 402 | - $calendar_classes[] = $calendar_class ; |
|
| 401 | + $calendar_class = 'simcal-events-calendar-'.strval($event->calendar); |
|
| 402 | + $calendar_classes[] = $calendar_class; |
|
| 403 | 403 | |
| 404 | 404 | $recurring = $event->recurrence ? 'simcal-event-recurring ' : ''; |
| 405 | 405 | $has_location = $event->venue ? 'simcal-event-has-location ' : ''; |
| 406 | 406 | |
| 407 | - $event_classes .= 'simcal-event ' . $recurring . $has_location . $calendar_class . ' simcal-tooltip'; |
|
| 407 | + $event_classes .= 'simcal-event '.$recurring.$has_location.$calendar_class.' simcal-tooltip'; |
|
| 408 | 408 | |
| 409 | 409 | // Toggle some events visibility if more than optional limit. |
| 410 | - if ( ( $calendar->events_limit > -1 ) && ( $count >= $calendar->events_limit ) ) : |
|
| 410 | + if (($calendar->events_limit > -1) && ($count >= $calendar->events_limit)) : |
|
| 411 | 411 | $event_classes .= ' simcal-event-toggled'; |
| 412 | 412 | $event_visibility = ' style="display: none"'; |
| 413 | 413 | endif; |
| 414 | 414 | |
| 415 | 415 | // Event title in list. |
| 416 | - $title = ! empty( $event->title ) ? trim( $event->title ) : __( 'Event', 'google-calendar-events' ); |
|
| 417 | - if ( $calendar->trim_titles >= 1 ) { |
|
| 418 | - $title = strlen( $title ) > $calendar->trim_titles ? mb_substr( $title, 0, $calendar->trim_titles ) . '…' : $title; |
|
| 416 | + $title = ! empty($event->title) ? trim($event->title) : __('Event', 'google-calendar-events'); |
|
| 417 | + if ($calendar->trim_titles >= 1) { |
|
| 418 | + $title = strlen($title) > $calendar->trim_titles ? mb_substr($title, 0, $calendar->trim_titles).'…' : $title; |
|
| 419 | 419 | } |
| 420 | 420 | |
| 421 | 421 | // Event color. |
| 422 | 422 | $bullet = ''; |
| 423 | 423 | $event_color = $event->get_color(); |
| 424 | - if ( ! empty( $event_color ) ) { |
|
| 425 | - $bullet = '<span style="color: ' . $event_color . ';">■</span> '; |
|
| 424 | + if ( ! empty($event_color)) { |
|
| 425 | + $bullet = '<span style="color: '.$event_color.';">■</span> '; |
|
| 426 | 426 | } |
| 427 | 427 | |
| 428 | 428 | // Event contents. |
| 429 | - $list_events .= "\t" . '<li class="' . $event_classes . '"' . $event_visibility . ' itemprop="event" itemscope itemtype="http://schema.org/Event">' . "\n"; |
|
| 430 | - $list_events .= "\t\t" . '<span class="simcal-event-title">' . $bullet . $title . '</span>' . "\n"; |
|
| 431 | - $list_events .= "\t\t" . '<div class="simcal-event-details simcal-tooltip-content" style="display: none;">' . $calendar->get_event_html( $event ) . '</div>' . "\n"; |
|
| 432 | - $list_events .= "\t" . '</li>' . "\n"; |
|
| 429 | + $list_events .= "\t".'<li class="'.$event_classes.'"'.$event_visibility.' itemprop="event" itemscope itemtype="http://schema.org/Event">'."\n"; |
|
| 430 | + $list_events .= "\t\t".'<span class="simcal-event-title">'.$bullet.$title.'</span>'."\n"; |
|
| 431 | + $list_events .= "\t\t".'<div class="simcal-event-details simcal-tooltip-content" style="display: none;">'.$calendar->get_event_html($event).'</div>'."\n"; |
|
| 432 | + $list_events .= "\t".'</li>'."\n"; |
|
| 433 | 433 | |
| 434 | - $count ++; |
|
| 434 | + $count++; |
|
| 435 | 435 | |
| 436 | 436 | endif; |
| 437 | 437 | |
| 438 | 438 | endforeach; |
| 439 | 439 | |
| 440 | - if ( ( $current_min <= $now ) && ( $current_max >= $now ) ) { |
|
| 440 | + if (($current_min <= $now) && ($current_max >= $now)) { |
|
| 441 | 441 | $day_classes .= ' simcal-today-has-events'; |
| 442 | 442 | } |
| 443 | - $day_classes .= ' simcal-day-has-events simcal-day-has-' . strval( $count ) . '-events'; |
|
| 443 | + $day_classes .= ' simcal-day-has-events simcal-day-has-'.strval($count).'-events'; |
|
| 444 | 444 | |
| 445 | - if ( $calendar_classes ) { |
|
| 446 | - $day_classes .= ' ' . trim( implode( ' ', array_unique( $calendar_classes ) ) ); |
|
| 445 | + if ($calendar_classes) { |
|
| 446 | + $day_classes .= ' '.trim(implode(' ', array_unique($calendar_classes))); |
|
| 447 | 447 | } |
| 448 | 448 | |
| 449 | - $list_events .= '</ul>' . "\n"; |
|
| 449 | + $list_events .= '</ul>'."\n"; |
|
| 450 | 450 | |
| 451 | 451 | // Optional button to toggle hidden events in list. |
| 452 | - if ( ( $calendar->events_limit > -1 ) && ( $count > $calendar->events_limit ) ) : |
|
| 452 | + if (($calendar->events_limit > -1) && ($count > $calendar->events_limit)) : |
|
| 453 | 453 | $list_events .= '<button class="simcal-events-toggle"><i class="simcal-icon-down simcal-icon-animate"></i></button>'; |
| 454 | 454 | endif; |
| 455 | 455 | |
@@ -461,49 +461,49 @@ discard block |
||
| 461 | 461 | endif; |
| 462 | 462 | |
| 463 | 463 | // The actual days with numbers and events in each row cell. |
| 464 | - echo '<td class="' . $day_classes . '" data-events-count="' . strval( $count ) . '">' . "\n"; |
|
| 465 | - |
|
| 466 | - if ( $color ) { |
|
| 467 | - $day_style = ' style="background-color: ' . $bg_color . '; color: ' . $color .'"'; |
|
| 468 | - } elseif ( $count > 0 ) { |
|
| 469 | - $the_color = new Color( $calendar->days_events_color ); |
|
| 470 | - $color = ! $color ? ( $the_color->isDark() ? '#ffffff' : '#000000' ) : $color; |
|
| 471 | - $bg_color = ! $bg_color ? '#' . $the_color->getHex() : $bg_color; |
|
| 472 | - $day_style = ' style="background-color: ' . $bg_color . '; color: ' . $color .'"'; |
|
| 464 | + echo '<td class="'.$day_classes.'" data-events-count="'.strval($count).'">'."\n"; |
|
| 465 | + |
|
| 466 | + if ($color) { |
|
| 467 | + $day_style = ' style="background-color: '.$bg_color.'; color: '.$color.'"'; |
|
| 468 | + } elseif ($count > 0) { |
|
| 469 | + $the_color = new Color($calendar->days_events_color); |
|
| 470 | + $color = ! $color ? ($the_color->isDark() ? '#ffffff' : '#000000') : $color; |
|
| 471 | + $bg_color = ! $bg_color ? '#'.$the_color->getHex() : $bg_color; |
|
| 472 | + $day_style = ' style="background-color: '.$bg_color.'; color: '.$color.'"'; |
|
| 473 | 473 | } else { |
| 474 | 474 | $day_style = ''; |
| 475 | 475 | } |
| 476 | 476 | |
| 477 | - echo "\t" . '<div' . $border_style . '>' . "\n"; |
|
| 478 | - echo "\t\t" . '<span class="simcal-day-label simcal-day-number"' . $day_style . '>' . $day . '</span>' . "\n"; |
|
| 479 | - echo "\t\t" . $list_events . "\n"; |
|
| 477 | + echo "\t".'<div'.$border_style.'>'."\n"; |
|
| 478 | + echo "\t\t".'<span class="simcal-day-label simcal-day-number"'.$day_style.'>'.$day.'</span>'."\n"; |
|
| 479 | + echo "\t\t".$list_events."\n"; |
|
| 480 | 480 | echo "\t\t"; |
| 481 | 481 | echo '<span class="simcal-events-dots" style="display: none;">'; |
| 482 | 482 | |
| 483 | 483 | // Event bullets for calendar mobile mode. |
| 484 | - for( $i = 0; $i < $count; $i++ ) { |
|
| 484 | + for ($i = 0; $i < $count; $i++) { |
|
| 485 | 485 | echo '<b> • </b>'; |
| 486 | 486 | } |
| 487 | 487 | |
| 488 | - echo '</span>' . "\n"; |
|
| 489 | - echo "\t" . '</div>' . "\n"; |
|
| 490 | - echo '</td>' . "\n"; |
|
| 488 | + echo '</span>'."\n"; |
|
| 489 | + echo "\t".'</div>'."\n"; |
|
| 490 | + echo '</td>'."\n"; |
|
| 491 | 491 | |
| 492 | 492 | // Reset day of the week count (sun, 0 - sat, 6). |
| 493 | - if ( $week_day === 6 ) { |
|
| 493 | + if ($week_day === 6) { |
|
| 494 | 494 | $week_day = - 1; |
| 495 | 495 | } |
| 496 | 496 | $week_day++; |
| 497 | 497 | |
| 498 | 498 | // Reset count of days for this row (0-6). |
| 499 | - if ( $days_in_row === 6 ) : |
|
| 499 | + if ($days_in_row === 6) : |
|
| 500 | 500 | |
| 501 | 501 | // Close the week row. |
| 502 | 502 | echo '</tr>'; |
| 503 | 503 | |
| 504 | 504 | // Open a new week row. |
| 505 | - if ( $day < $days_in_month ) { |
|
| 506 | - echo '<tr class="simcal-week simcal-week-' . $week_of_year++ . '">' . "\n"; |
|
| 505 | + if ($day < $days_in_month) { |
|
| 506 | + echo '<tr class="simcal-week simcal-week-'.$week_of_year++.'">'."\n"; |
|
| 507 | 507 | } |
| 508 | 508 | |
| 509 | 509 | $days_in_row = -1; |
@@ -512,27 +512,27 @@ discard block |
||
| 512 | 512 | |
| 513 | 513 | $days_in_row++; |
| 514 | 514 | |
| 515 | - $current_min = Carbon::createFromTimestamp( $current_min, $calendar->timezone )->addDay()->getTimestamp(); |
|
| 516 | - $current_max = Carbon::createFromTimestamp( $current_max, $calendar->timezone )->addDay()->getTimestamp(); |
|
| 515 | + $current_min = Carbon::createFromTimestamp($current_min, $calendar->timezone)->addDay()->getTimestamp(); |
|
| 516 | + $current_max = Carbon::createFromTimestamp($current_max, $calendar->timezone)->addDay()->getTimestamp(); |
|
| 517 | 517 | |
| 518 | 518 | endfor; |
| 519 | 519 | |
| 520 | 520 | // Void days at the end of the month. |
| 521 | - $remainder_days = ( 6 - $days_in_row ); |
|
| 521 | + $remainder_days = (6 - $days_in_row); |
|
| 522 | 522 | |
| 523 | - for ( $i = 0; $i <= $remainder_days; $i ++ ) { |
|
| 523 | + for ($i = 0; $i <= $remainder_days; $i++) { |
|
| 524 | 524 | |
| 525 | - $last_void_day_class = ( $i == $remainder_days ) ? 'simcal-day-void-last' : ''; |
|
| 525 | + $last_void_day_class = ($i == $remainder_days) ? 'simcal-day-void-last' : ''; |
|
| 526 | 526 | |
| 527 | - echo '<td class="simcal-day simcal-day-void ' . $last_void_day_class . '"></td>' . "\n"; |
|
| 527 | + echo '<td class="simcal-day simcal-day-void '.$last_void_day_class.'"></td>'."\n"; |
|
| 528 | 528 | |
| 529 | 529 | $week_day++; |
| 530 | 530 | } |
| 531 | 531 | |
| 532 | - echo "\t" . '</tr>' . "\n"; |
|
| 533 | - echo '</tbody>' . "\n"; |
|
| 532 | + echo "\t".'</tr>'."\n"; |
|
| 533 | + echo '</tbody>'."\n"; |
|
| 534 | 534 | |
| 535 | - date_default_timezone_set( $calendar->site_timezone ); |
|
| 535 | + date_default_timezone_set($calendar->site_timezone); |
|
| 536 | 536 | |
| 537 | 537 | return ob_get_clean(); |
| 538 | 538 | } |
@@ -544,17 +544,17 @@ discard block |
||
| 544 | 544 | */ |
| 545 | 545 | public function draw_grid_ajax() { |
| 546 | 546 | |
| 547 | - if ( isset( $_POST['month'] ) && isset( $_POST['year'] ) && isset( $_POST['id'] ) ) { |
|
| 547 | + if (isset($_POST['month']) && isset($_POST['year']) && isset($_POST['id'])) { |
|
| 548 | 548 | |
| 549 | - $month = absint( $_POST['month'] ); |
|
| 550 | - $year = absint( $_POST['year'] ); |
|
| 551 | - $id = absint( $_POST['id'] ); |
|
| 549 | + $month = absint($_POST['month']); |
|
| 550 | + $year = absint($_POST['year']); |
|
| 551 | + $id = absint($_POST['id']); |
|
| 552 | 552 | |
| 553 | - wp_send_json_success( $this->draw_month( $month, $year, $id ) ); |
|
| 553 | + wp_send_json_success($this->draw_month($month, $year, $id)); |
|
| 554 | 554 | |
| 555 | 555 | } else { |
| 556 | 556 | |
| 557 | - wp_send_json_error( 'Missing arguments in default calendar grid ajax request.' ); |
|
| 557 | + wp_send_json_error('Missing arguments in default calendar grid ajax request.'); |
|
| 558 | 558 | |
| 559 | 559 | } |
| 560 | 560 | |
@@ -570,8 +570,8 @@ discard block |
||
| 570 | 570 | * |
| 571 | 571 | * @return bool |
| 572 | 572 | */ |
| 573 | - private function filter_events_before( $event ) { |
|
| 574 | - return intval( $event ) >= intval( $this->start ); |
|
| 573 | + private function filter_events_before($event) { |
|
| 574 | + return intval($event) >= intval($this->start); |
|
| 575 | 575 | } |
| 576 | 576 | |
| 577 | 577 | /** |
@@ -584,8 +584,8 @@ discard block |
||
| 584 | 584 | * |
| 585 | 585 | * @return bool |
| 586 | 586 | */ |
| 587 | - private function filter_events_after( $event ) { |
|
| 588 | - return intval( $event ) < intval( $this->end ); |
|
| 587 | + private function filter_events_after($event) { |
|
| 588 | + return intval($event) < intval($this->end); |
|
| 589 | 589 | } |
| 590 | 590 | |
| 591 | 591 | } |
@@ -9,7 +9,7 @@ discard block |
||
| 9 | 9 | use Carbon\Carbon; |
| 10 | 10 | use SimpleCalendar\Abstracts\Calendar; |
| 11 | 11 | |
| 12 | -if ( ! defined( 'ABSPATH' ) ) { |
|
| 12 | +if ( ! defined('ABSPATH')) { |
|
| 13 | 13 | exit; |
| 14 | 14 | } |
| 15 | 15 | |
@@ -54,7 +54,7 @@ discard block |
||
| 54 | 54 | * @param Event $event |
| 55 | 55 | * @param Calendar $calendar |
| 56 | 56 | */ |
| 57 | - public function __construct( Event $event, Calendar $calendar ) { |
|
| 57 | + public function __construct(Event $event, Calendar $calendar) { |
|
| 58 | 58 | $this->event = $event; |
| 59 | 59 | $this->calendar = $calendar; |
| 60 | 60 | $this->tags = $this->get_content_tags(); |
@@ -74,84 +74,84 @@ discard block |
||
| 74 | 74 | * Content Tags * |
| 75 | 75 | * ============ */ |
| 76 | 76 | |
| 77 | - 'title', // The event title. |
|
| 78 | - 'event-title', // @deprecated An alias for 'title' tag. |
|
| 79 | - 'description', // The event description. |
|
| 80 | - |
|
| 81 | - 'when', // Date and time of the event. |
|
| 82 | - 'start-time', // Start time of the event. |
|
| 83 | - 'start-date', // Start date of the event. |
|
| 84 | - 'start-custom', // @deprecated Start time in a user defined format (set by tag 'format' attribute). |
|
| 85 | - 'start-human', // Start time in a human friendly format. |
|
| 86 | - 'end-time', // End time of the event. |
|
| 87 | - 'end-date', // End date of the event. |
|
| 88 | - 'end-custom', // @deprecated End date-time in a user defined format (set by tag 'format' attribute). |
|
| 89 | - 'end-human', // End date-time in a human friendly format. |
|
| 90 | - |
|
| 91 | - 'duration', // How long the events lasts, in a human-readable format. |
|
| 92 | - 'length', // @deprecated An alias of 'duration' tag. |
|
| 93 | - |
|
| 94 | - 'location', // Alias of start-location. |
|
| 95 | - 'start-location', // Location name where the event starts. |
|
| 96 | - 'maps-link', // @deprecated An alias for 'start-location-link' tag. |
|
| 97 | - 'start-location-link', // Link to Google Maps querying the event start location address. |
|
| 98 | - 'end-location', // Location name where the event ends. |
|
| 99 | - 'end-location-link', // Link to Google Maps querying the event end location address. |
|
| 100 | - |
|
| 101 | - 'link', // An HTML link to the event URL. |
|
| 102 | - 'url', // A string with the raw event link URL. |
|
| 103 | - |
|
| 104 | - 'calendar', // The title of the source calendar. |
|
| 105 | - 'feed-title', // @deprecated An alias of 'calendar'. |
|
| 106 | - |
|
| 107 | - 'id', // The event unique ID. |
|
| 108 | - 'uid', // An alias of ID. |
|
| 109 | - 'event-id', // @deprecated An alias for 'id' tag. |
|
| 110 | - 'calendar-id', // The calendar ID. |
|
| 111 | - 'feed-id', // @deprecated An alias for 'calendar-id' tag. |
|
| 112 | - 'cal-id', // @deprecated An alias for 'calendar-id' tag. |
|
| 77 | + 'title', // The event title. |
|
| 78 | + 'event-title', // @deprecated An alias for 'title' tag. |
|
| 79 | + 'description', // The event description. |
|
| 80 | + |
|
| 81 | + 'when', // Date and time of the event. |
|
| 82 | + 'start-time', // Start time of the event. |
|
| 83 | + 'start-date', // Start date of the event. |
|
| 84 | + 'start-custom', // @deprecated Start time in a user defined format (set by tag 'format' attribute). |
|
| 85 | + 'start-human', // Start time in a human friendly format. |
|
| 86 | + 'end-time', // End time of the event. |
|
| 87 | + 'end-date', // End date of the event. |
|
| 88 | + 'end-custom', // @deprecated End date-time in a user defined format (set by tag 'format' attribute). |
|
| 89 | + 'end-human', // End date-time in a human friendly format. |
|
| 90 | + |
|
| 91 | + 'duration', // How long the events lasts, in a human-readable format. |
|
| 92 | + 'length', // @deprecated An alias of 'duration' tag. |
|
| 93 | + |
|
| 94 | + 'location', // Alias of start-location. |
|
| 95 | + 'start-location', // Location name where the event starts. |
|
| 96 | + 'maps-link', // @deprecated An alias for 'start-location-link' tag. |
|
| 97 | + 'start-location-link', // Link to Google Maps querying the event start location address. |
|
| 98 | + 'end-location', // Location name where the event ends. |
|
| 99 | + 'end-location-link', // Link to Google Maps querying the event end location address. |
|
| 100 | + |
|
| 101 | + 'link', // An HTML link to the event URL. |
|
| 102 | + 'url', // A string with the raw event link URL. |
|
| 103 | + |
|
| 104 | + 'calendar', // The title of the source calendar. |
|
| 105 | + 'feed-title', // @deprecated An alias of 'calendar'. |
|
| 106 | + |
|
| 107 | + 'id', // The event unique ID. |
|
| 108 | + 'uid', // An alias of ID. |
|
| 109 | + 'event-id', // @deprecated An alias for 'id' tag. |
|
| 110 | + 'calendar-id', // The calendar ID. |
|
| 111 | + 'feed-id', // @deprecated An alias for 'calendar-id' tag. |
|
| 112 | + 'cal-id', // @deprecated An alias for 'calendar-id' tag. |
|
| 113 | 113 | |
| 114 | 114 | /* ========= * |
| 115 | 115 | * Meta Tags * |
| 116 | 116 | * ========= */ |
| 117 | 117 | |
| 118 | - 'attachments', // List of attachments. |
|
| 119 | - 'attendees', // List of attendees. |
|
| 120 | - 'organizer', // Creator info. |
|
| 118 | + 'attachments', // List of attachments. |
|
| 119 | + 'attendees', // List of attendees. |
|
| 120 | + 'organizer', // Creator info. |
|
| 121 | 121 | |
| 122 | 122 | /* ================ * |
| 123 | 123 | * Conditional Tags * |
| 124 | 124 | * ================ */ |
| 125 | 125 | |
| 126 | - 'if-title', // If the event has a title. |
|
| 127 | - 'if-description', // If the event has a description. |
|
| 128 | - |
|
| 129 | - 'if-now', // If the event is taking place now. |
|
| 130 | - 'if-not-now', // If the event is not taking place now (may have ended or just not started yet). |
|
| 131 | - 'if-started', // If the event has started (and may as well as ended). |
|
| 132 | - 'if-not-started', // If the event has NOT started yet (event could be any time in the future). |
|
| 133 | - 'if-ended', // If the event has ended (event could be any time in the past). |
|
| 134 | - 'if-not-ended', // If the event has NOT ended (may as well as not started yet). |
|
| 135 | - |
|
| 136 | - 'if-whole-day', // If the event lasts the whole day. |
|
| 137 | - 'if-all-day', // @deprecated Alias for 'if-whole-day'. |
|
| 138 | - 'if-not-whole-day', // If the event does NOT last the whole day. |
|
| 139 | - 'if-not-all-day', // @deprecated Alias for 'if-not-whole-day'. |
|
| 140 | - 'if-end-time', // If the event has a set end time. |
|
| 141 | - 'if-no-end-time', // If the event has NOT a set end time. |
|
| 142 | - |
|
| 143 | - 'if-multi-day', // If the event spans multiple days. |
|
| 144 | - 'if-single-day', // If the event does not span multiple days. |
|
| 145 | - |
|
| 146 | - 'if-recurring', // If the event is a recurring event. |
|
| 147 | - 'if-not-recurring', // If the event is NOT a recurring event. |
|
| 148 | - |
|
| 149 | - 'if-location', // @deprecated Alias for 'if-start-location'. |
|
| 150 | - 'if-start-location', // Does the event has a start location? |
|
| 151 | - 'if-end-location', // Does the event has an end location? |
|
| 152 | - 'if-not-location', // @deprecated Alias for 'if-not-start-location'. |
|
| 126 | + 'if-title', // If the event has a title. |
|
| 127 | + 'if-description', // If the event has a description. |
|
| 128 | + |
|
| 129 | + 'if-now', // If the event is taking place now. |
|
| 130 | + 'if-not-now', // If the event is not taking place now (may have ended or just not started yet). |
|
| 131 | + 'if-started', // If the event has started (and may as well as ended). |
|
| 132 | + 'if-not-started', // If the event has NOT started yet (event could be any time in the future). |
|
| 133 | + 'if-ended', // If the event has ended (event could be any time in the past). |
|
| 134 | + 'if-not-ended', // If the event has NOT ended (may as well as not started yet). |
|
| 135 | + |
|
| 136 | + 'if-whole-day', // If the event lasts the whole day. |
|
| 137 | + 'if-all-day', // @deprecated Alias for 'if-whole-day'. |
|
| 138 | + 'if-not-whole-day', // If the event does NOT last the whole day. |
|
| 139 | + 'if-not-all-day', // @deprecated Alias for 'if-not-whole-day'. |
|
| 140 | + 'if-end-time', // If the event has a set end time. |
|
| 141 | + 'if-no-end-time', // If the event has NOT a set end time. |
|
| 142 | + |
|
| 143 | + 'if-multi-day', // If the event spans multiple days. |
|
| 144 | + 'if-single-day', // If the event does not span multiple days. |
|
| 145 | + |
|
| 146 | + 'if-recurring', // If the event is a recurring event. |
|
| 147 | + 'if-not-recurring', // If the event is NOT a recurring event. |
|
| 148 | + |
|
| 149 | + 'if-location', // @deprecated Alias for 'if-start-location'. |
|
| 150 | + 'if-start-location', // Does the event has a start location? |
|
| 151 | + 'if-end-location', // Does the event has an end location? |
|
| 152 | + 'if-not-location', // @deprecated Alias for 'if-not-start-location'. |
|
| 153 | 153 | 'if-not-start-location', // Does the event has NOT a start location? |
| 154 | - 'if-not-end-location', // Does the event has NOT an end location? |
|
| 154 | + 'if-not-end-location', // Does the event has NOT an end location? |
|
| 155 | 155 | |
| 156 | 156 | ); |
| 157 | 157 | } |
@@ -165,17 +165,17 @@ discard block |
||
| 165 | 165 | * |
| 166 | 166 | * @return string |
| 167 | 167 | */ |
| 168 | - public function parse_event_template_tags( $template_tags = '' ) { |
|
| 168 | + public function parse_event_template_tags($template_tags = '') { |
|
| 169 | 169 | |
| 170 | 170 | // Process tags. |
| 171 | 171 | $result = preg_replace_callback( |
| 172 | 172 | $this->get_regex(), |
| 173 | - array( $this, 'process_event_content' ), |
|
| 173 | + array($this, 'process_event_content'), |
|
| 174 | 174 | $template_tags |
| 175 | 175 | ); |
| 176 | 176 | |
| 177 | 177 | // Removes extra consecutive <br> tags. |
| 178 | - return preg_replace( '#(<br */?>\s*)+#i', '<br />', trim( $result ) ); |
|
| 178 | + return preg_replace('#(<br */?>\s*)+#i', '<br />', trim($result)); |
|
| 179 | 179 | } |
| 180 | 180 | |
| 181 | 181 | /** |
@@ -187,10 +187,10 @@ discard block |
||
| 187 | 187 | * |
| 188 | 188 | * @return string |
| 189 | 189 | */ |
| 190 | - public function process_event_content( $match ) { |
|
| 190 | + public function process_event_content($match) { |
|
| 191 | 191 | |
| 192 | - if ( $match[1] == '[' && $match[6] == ']' ) { |
|
| 193 | - return substr( $match[0], 1, - 1 ); |
|
| 192 | + if ($match[1] == '[' && $match[6] == ']') { |
|
| 193 | + return substr($match[0], 1, - 1); |
|
| 194 | 194 | } |
| 195 | 195 | |
| 196 | 196 | $tag = $match[2]; // Tag name without square brackets. |
@@ -202,9 +202,9 @@ discard block |
||
| 202 | 202 | $calendar = $this->calendar; |
| 203 | 203 | $event = $this->event; |
| 204 | 204 | |
| 205 | - if ( ( $calendar instanceof Calendar ) && ( $event instanceof Event ) ) { |
|
| 205 | + if (($calendar instanceof Calendar) && ($event instanceof Event)) { |
|
| 206 | 206 | |
| 207 | - switch ( $tag ) { |
|
| 207 | + switch ($tag) { |
|
| 208 | 208 | |
| 209 | 209 | /* ============ * |
| 210 | 210 | * Content Tags * |
@@ -212,13 +212,13 @@ discard block |
||
| 212 | 212 | |
| 213 | 213 | case 'title' : |
| 214 | 214 | case 'event-title' : |
| 215 | - return $this->get_title( $event->title, $attr ); |
|
| 215 | + return $this->get_title($event->title, $attr); |
|
| 216 | 216 | |
| 217 | 217 | case 'description' : |
| 218 | - return $this->get_description( $event->description, $attr ); |
|
| 218 | + return $this->get_description($event->description, $attr); |
|
| 219 | 219 | |
| 220 | 220 | case 'when' : |
| 221 | - return $this->get_when( $event ); |
|
| 221 | + return $this->get_when($event); |
|
| 222 | 222 | |
| 223 | 223 | case 'end-date' : |
| 224 | 224 | case 'end-custom' : |
@@ -228,40 +228,40 @@ discard block |
||
| 228 | 228 | case 'start-date' : |
| 229 | 229 | case 'start-human' : |
| 230 | 230 | case 'start-time' : |
| 231 | - return $this->get_dt( $tag, $event, $attr ); |
|
| 231 | + return $this->get_dt($tag, $event, $attr); |
|
| 232 | 232 | |
| 233 | 233 | case 'length' : |
| 234 | 234 | case 'duration' : |
| 235 | - if ( false !== $event->end ) { |
|
| 235 | + if (false !== $event->end) { |
|
| 236 | 236 | $duration = $event->start - $event->end; |
| 237 | - $value = human_time_diff( $event->start, $event->end ); |
|
| 237 | + $value = human_time_diff($event->start, $event->end); |
|
| 238 | 238 | } else { |
| 239 | 239 | $duration = '-1'; |
| 240 | - $value = __( 'No end time', 'google-calendar-events' ); |
|
| 240 | + $value = __('No end time', 'google-calendar-events'); |
|
| 241 | 241 | } |
| 242 | - return ' <span class="simcal-event-duration" data-event-duration="' . $duration . '">' . $value . '</span>'; |
|
| 242 | + return ' <span class="simcal-event-duration" data-event-duration="'.$duration.'">'.$value.'</span>'; |
|
| 243 | 243 | |
| 244 | 244 | case 'location' : |
| 245 | 245 | case 'start-location' : |
| 246 | 246 | case 'end-location' : |
| 247 | 247 | $location = $tag == 'end-location' ? $event->end_location['address'] : $event->start_location['address']; |
| 248 | 248 | $location_class = $tag == 'end-location' ? 'end' : 'start'; |
| 249 | - return ' <span class="simcal-event-address simcal-event-' . $location_class . '-location" itemprop="location" itemscope itemtype="http://schema.org/Place">' . wp_strip_all_tags( $location ) . '</span>'; |
|
| 249 | + return ' <span class="simcal-event-address simcal-event-'.$location_class.'-location" itemprop="location" itemscope itemtype="http://schema.org/Place">'.wp_strip_all_tags($location).'</span>'; |
|
| 250 | 250 | |
| 251 | 251 | case 'start-location-link': |
| 252 | 252 | case 'end-location-link' : |
| 253 | 253 | case 'maps-link' : |
| 254 | 254 | $location = $tag == 'end-location-link' ? $event->end_location['address'] : $event->start_location['address']; |
| 255 | - if ( ! empty( $location ) ) { |
|
| 256 | - $url = '//maps.google.com?q=' . urlencode( $location ); |
|
| 257 | - return $this->make_link( $tag, $url, $calendar->get_event_html( $event, $partial ), $attr ); |
|
| 255 | + if ( ! empty($location)) { |
|
| 256 | + $url = '//maps.google.com?q='.urlencode($location); |
|
| 257 | + return $this->make_link($tag, $url, $calendar->get_event_html($event, $partial), $attr); |
|
| 258 | 258 | } |
| 259 | 259 | break; |
| 260 | 260 | |
| 261 | 261 | case 'link' : |
| 262 | 262 | case 'url' : |
| 263 | - $content = 'link' == $tag ? $calendar->get_event_html( $event, $partial ) : ''; |
|
| 264 | - return $this->make_link( $tag, $event->link, $content , $attr ); |
|
| 263 | + $content = 'link' == $tag ? $calendar->get_event_html($event, $partial) : ''; |
|
| 264 | + return $this->make_link($tag, $event->link, $content, $attr); |
|
| 265 | 265 | |
| 266 | 266 | case 'calendar' : |
| 267 | 267 | case 'feed-title' : |
@@ -283,22 +283,22 @@ discard block |
||
| 283 | 283 | |
| 284 | 284 | case 'attachments' : |
| 285 | 285 | $attachments = $event->get_attachments(); |
| 286 | - if ( ! empty( $attachments ) ) { |
|
| 287 | - return $this->get_attachments( $attachments ); |
|
| 286 | + if ( ! empty($attachments)) { |
|
| 287 | + return $this->get_attachments($attachments); |
|
| 288 | 288 | } |
| 289 | 289 | break; |
| 290 | 290 | |
| 291 | 291 | case 'attendees' : |
| 292 | 292 | $attendees = $event->get_attendees(); |
| 293 | - if ( ! empty( $attendees ) ) { |
|
| 294 | - return $this->get_attendees( $attendees, $attr ); |
|
| 293 | + if ( ! empty($attendees)) { |
|
| 294 | + return $this->get_attendees($attendees, $attr); |
|
| 295 | 295 | } |
| 296 | 296 | break; |
| 297 | 297 | |
| 298 | 298 | case 'organizer' : |
| 299 | 299 | $organizer = $event->get_organizer(); |
| 300 | - if ( ! empty( $organizer ) ) { |
|
| 301 | - return $this->get_organizer( $organizer, $attr ); |
|
| 300 | + if ( ! empty($organizer)) { |
|
| 301 | + return $this->get_organizer($organizer, $attr); |
|
| 302 | 302 | } |
| 303 | 303 | break; |
| 304 | 304 | |
@@ -307,35 +307,35 @@ discard block |
||
| 307 | 307 | * ================ */ |
| 308 | 308 | |
| 309 | 309 | case 'if-title': |
| 310 | - if ( ! empty( $event->title ) ) { |
|
| 311 | - return $calendar->get_event_html( $event, $partial ); |
|
| 310 | + if ( ! empty($event->title)) { |
|
| 311 | + return $calendar->get_event_html($event, $partial); |
|
| 312 | 312 | } |
| 313 | 313 | break; |
| 314 | 314 | |
| 315 | 315 | case 'if-description': |
| 316 | - if ( ! empty( $event->description ) ) { |
|
| 317 | - return $calendar->get_event_html( $event, $partial ); |
|
| 316 | + if ( ! empty($event->description)) { |
|
| 317 | + return $calendar->get_event_html($event, $partial); |
|
| 318 | 318 | } |
| 319 | 319 | break; |
| 320 | 320 | |
| 321 | 321 | case 'if-now' : |
| 322 | 322 | case 'if-not-now' : |
| 323 | 323 | |
| 324 | - $start_dt = $event->start_dt->setTimezone( $calendar->timezone ); |
|
| 324 | + $start_dt = $event->start_dt->setTimezone($calendar->timezone); |
|
| 325 | 325 | $start = $start_dt->getTimestamp(); |
| 326 | 326 | |
| 327 | - if ( $event->end_dt instanceof Carbon ) { |
|
| 328 | - $end = $event->end_dt->setTimezone( $calendar->timezone )->getTimestamp(); |
|
| 327 | + if ($event->end_dt instanceof Carbon) { |
|
| 328 | + $end = $event->end_dt->setTimezone($calendar->timezone)->getTimestamp(); |
|
| 329 | 329 | } else { |
| 330 | 330 | return ''; |
| 331 | 331 | } |
| 332 | 332 | |
| 333 | - $now = ( $start <= $calendar->now ) && ( $end >= $calendar->now ); |
|
| 333 | + $now = ($start <= $calendar->now) && ($end >= $calendar->now); |
|
| 334 | 334 | |
| 335 | - if ( ( 'if-now' == $tag ) && $now ) { |
|
| 336 | - return $calendar->get_event_html( $event, $partial ); |
|
| 337 | - } elseif ( ( 'if-not-now' == $tag ) && ( false == $now ) ) { |
|
| 338 | - return $calendar->get_event_html( $event, $partial ); |
|
| 335 | + if (('if-now' == $tag) && $now) { |
|
| 336 | + return $calendar->get_event_html($event, $partial); |
|
| 337 | + } elseif (('if-not-now' == $tag) && (false == $now)) { |
|
| 338 | + return $calendar->get_event_html($event, $partial); |
|
| 339 | 339 | } |
| 340 | 340 | |
| 341 | 341 | break; |
@@ -343,15 +343,15 @@ discard block |
||
| 343 | 343 | case 'if-started' : |
| 344 | 344 | case 'if-not-started' : |
| 345 | 345 | |
| 346 | - $start = $event->start_dt->setTimezone( $calendar->timezone )->getTimestamp(); |
|
| 346 | + $start = $event->start_dt->setTimezone($calendar->timezone)->getTimestamp(); |
|
| 347 | 347 | |
| 348 | - if ( 'if-started' == $tag ) { |
|
| 349 | - if ( $start < $calendar->now ) { |
|
| 350 | - return $calendar->get_event_html( $event, $partial ); |
|
| 348 | + if ('if-started' == $tag) { |
|
| 349 | + if ($start < $calendar->now) { |
|
| 350 | + return $calendar->get_event_html($event, $partial); |
|
| 351 | 351 | } |
| 352 | - } elseif ( 'if-not-started' == $tag ) { |
|
| 353 | - if ( $start > $calendar->now ) { |
|
| 354 | - return $calendar->get_event_html( $event, $partial ); |
|
| 352 | + } elseif ('if-not-started' == $tag) { |
|
| 353 | + if ($start > $calendar->now) { |
|
| 354 | + return $calendar->get_event_html($event, $partial); |
|
| 355 | 355 | } |
| 356 | 356 | } |
| 357 | 357 | |
@@ -360,17 +360,17 @@ discard block |
||
| 360 | 360 | case 'if-ended' : |
| 361 | 361 | case 'if-not-ended' : |
| 362 | 362 | |
| 363 | - if ( false !== $event->end ) { |
|
| 363 | + if (false !== $event->end) { |
|
| 364 | 364 | |
| 365 | - $end = $event->end_dt->setTimezone( $calendar->timezone )->getTimestamp(); |
|
| 365 | + $end = $event->end_dt->setTimezone($calendar->timezone)->getTimestamp(); |
|
| 366 | 366 | |
| 367 | - if ( 'if-ended' == $tag ) { |
|
| 368 | - if ( $end < $calendar->now ) { |
|
| 369 | - return $calendar->get_event_html( $event, $partial ); |
|
| 367 | + if ('if-ended' == $tag) { |
|
| 368 | + if ($end < $calendar->now) { |
|
| 369 | + return $calendar->get_event_html($event, $partial); |
|
| 370 | 370 | } |
| 371 | - } elseif ( 'if-not-ended' == $tag ) { |
|
| 372 | - if ( $end > $calendar->now ) { |
|
| 373 | - return $calendar->get_event_html( $event, $partial ); |
|
| 371 | + } elseif ('if-not-ended' == $tag) { |
|
| 372 | + if ($end > $calendar->now) { |
|
| 373 | + return $calendar->get_event_html($event, $partial); |
|
| 374 | 374 | } |
| 375 | 375 | } |
| 376 | 376 | |
@@ -379,14 +379,14 @@ discard block |
||
| 379 | 379 | break; |
| 380 | 380 | |
| 381 | 381 | case 'if-end-time' : |
| 382 | - if ( false !== $event->end ) { |
|
| 383 | - return $calendar->get_event_html( $event, $partial ); |
|
| 382 | + if (false !== $event->end) { |
|
| 383 | + return $calendar->get_event_html($event, $partial); |
|
| 384 | 384 | } |
| 385 | 385 | break; |
| 386 | 386 | |
| 387 | 387 | case 'if-no-end-time' : |
| 388 | - if ( false === $event->end ) { |
|
| 389 | - return $calendar->get_event_html( $event, $partial ); |
|
| 388 | + if (false === $event->end) { |
|
| 389 | + return $calendar->get_event_html($event, $partial); |
|
| 390 | 390 | } |
| 391 | 391 | break; |
| 392 | 392 | |
@@ -394,59 +394,59 @@ discard block |
||
| 394 | 394 | case 'if-whole-day' : |
| 395 | 395 | case 'if-not-all-day' : |
| 396 | 396 | case 'if-not-whole-day' : |
| 397 | - $bool = strstr( $tag, 'not' ) ? false : true; |
|
| 398 | - if ( $bool === $event->whole_day ) { |
|
| 399 | - return $calendar->get_event_html( $event, $partial ); |
|
| 397 | + $bool = strstr($tag, 'not') ? false : true; |
|
| 398 | + if ($bool === $event->whole_day) { |
|
| 399 | + return $calendar->get_event_html($event, $partial); |
|
| 400 | 400 | } |
| 401 | 401 | break; |
| 402 | 402 | |
| 403 | 403 | case 'if-recurring' : |
| 404 | - if ( ! empty( $event->recurrence ) ) { |
|
| 405 | - return $calendar->get_event_html( $event, $partial ); |
|
| 404 | + if ( ! empty($event->recurrence)) { |
|
| 405 | + return $calendar->get_event_html($event, $partial); |
|
| 406 | 406 | } |
| 407 | 407 | break; |
| 408 | 408 | |
| 409 | 409 | case 'if-not-recurring' : |
| 410 | - if ( false === $event->recurrence ) { |
|
| 411 | - return $calendar->get_event_html( $event, $partial ); |
|
| 410 | + if (false === $event->recurrence) { |
|
| 411 | + return $calendar->get_event_html($event, $partial); |
|
| 412 | 412 | } |
| 413 | 413 | break; |
| 414 | 414 | |
| 415 | 415 | case 'if-multi-day' : |
| 416 | - if ( false !== $event->multiple_days ) { |
|
| 417 | - return $calendar->get_event_html( $event, $partial ); |
|
| 416 | + if (false !== $event->multiple_days) { |
|
| 417 | + return $calendar->get_event_html($event, $partial); |
|
| 418 | 418 | } |
| 419 | 419 | break; |
| 420 | 420 | |
| 421 | 421 | case 'if-single-day' : |
| 422 | - if ( false === $event->multiple_days ) { |
|
| 423 | - return $calendar->get_event_html( $event, $partial ); |
|
| 422 | + if (false === $event->multiple_days) { |
|
| 423 | + return $calendar->get_event_html($event, $partial); |
|
| 424 | 424 | } |
| 425 | 425 | break; |
| 426 | 426 | |
| 427 | 427 | case 'if-location' : |
| 428 | 428 | case 'if-start-location' : |
| 429 | - if ( ! empty( $event->start_location['address'] ) ) { |
|
| 430 | - return $calendar->get_event_html( $event, $partial ); |
|
| 429 | + if ( ! empty($event->start_location['address'])) { |
|
| 430 | + return $calendar->get_event_html($event, $partial); |
|
| 431 | 431 | } |
| 432 | 432 | return false; |
| 433 | 433 | |
| 434 | 434 | case 'if-not-location' : |
| 435 | 435 | case 'if-not-start-location' : |
| 436 | - if ( empty( $event->start_location['address'] ) ) { |
|
| 437 | - return $calendar->get_event_html( $event, $partial ); |
|
| 436 | + if (empty($event->start_location['address'])) { |
|
| 437 | + return $calendar->get_event_html($event, $partial); |
|
| 438 | 438 | } |
| 439 | 439 | return ''; |
| 440 | 440 | |
| 441 | 441 | case 'if-not-end-location' : |
| 442 | - if ( empty( $event->end_location['address'] ) ) { |
|
| 443 | - return $calendar->get_event_html( $event, $partial ); |
|
| 442 | + if (empty($event->end_location['address'])) { |
|
| 443 | + return $calendar->get_event_html($event, $partial); |
|
| 444 | 444 | } |
| 445 | 445 | return ''; |
| 446 | 446 | |
| 447 | 447 | case 'if-end-location' : |
| 448 | - if ( ! empty( $event->end_location['address'] ) ) { |
|
| 449 | - return $calendar->get_event_html( $event, $partial ); |
|
| 448 | + if ( ! empty($event->end_location['address'])) { |
|
| 449 | + return $calendar->get_event_html($event, $partial); |
|
| 450 | 450 | } |
| 451 | 451 | return ''; |
| 452 | 452 | |
@@ -455,7 +455,7 @@ discard block |
||
| 455 | 455 | * ======= */ |
| 456 | 456 | |
| 457 | 457 | default : |
| 458 | - return wp_kses_post( $before . $partial . $after ); |
|
| 458 | + return wp_kses_post($before.$partial.$after); |
|
| 459 | 459 | } |
| 460 | 460 | } |
| 461 | 461 | |
@@ -473,14 +473,14 @@ discard block |
||
| 473 | 473 | * |
| 474 | 474 | * @return string |
| 475 | 475 | */ |
| 476 | - private function limit_words( $text, $limit ) { |
|
| 476 | + private function limit_words($text, $limit) { |
|
| 477 | 477 | |
| 478 | - $limit = max( absint( $limit ), 0 ); |
|
| 478 | + $limit = max(absint($limit), 0); |
|
| 479 | 479 | |
| 480 | - if ( $limit > 0 && ( str_word_count( $text, 0 ) > $limit ) ) { |
|
| 481 | - $words = str_word_count( $text, 2 ); |
|
| 482 | - $pos = array_keys( $words ); |
|
| 483 | - $text = trim( substr( $text, 0, $pos[ $limit ] ) ) . '…'; |
|
| 480 | + if ($limit > 0 && (str_word_count($text, 0) > $limit)) { |
|
| 481 | + $words = str_word_count($text, 2); |
|
| 482 | + $pos = array_keys($words); |
|
| 483 | + $text = trim(substr($text, 0, $pos[$limit])).'…'; |
|
| 484 | 484 | } |
| 485 | 485 | |
| 486 | 486 | return $text; |
@@ -497,26 +497,26 @@ discard block |
||
| 497 | 497 | * |
| 498 | 498 | * @return string |
| 499 | 499 | */ |
| 500 | - private function get_title( $title, $attr ) { |
|
| 500 | + private function get_title($title, $attr) { |
|
| 501 | 501 | |
| 502 | - if ( empty( $title ) ) { |
|
| 502 | + if (empty($title)) { |
|
| 503 | 503 | return ''; |
| 504 | 504 | } |
| 505 | 505 | |
| 506 | - $attr = array_merge( array( |
|
| 507 | - 'html' => '', // Parse HTML |
|
| 508 | - 'limit' => 0, // Trim length to amount of words |
|
| 509 | - ), (array) shortcode_parse_atts( $attr ) ); |
|
| 506 | + $attr = array_merge(array( |
|
| 507 | + 'html' => '', // Parse HTML |
|
| 508 | + 'limit' => 0, // Trim length to amount of words |
|
| 509 | + ), (array) shortcode_parse_atts($attr)); |
|
| 510 | 510 | |
| 511 | - if ( ! empty( $attr['html'] ) ) { |
|
| 512 | - $title = wp_kses_post( $title ); |
|
| 511 | + if ( ! empty($attr['html'])) { |
|
| 512 | + $title = wp_kses_post($title); |
|
| 513 | 513 | $tag = 'div'; |
| 514 | 514 | } else { |
| 515 | - $title = $this->limit_words( $title, $attr['limit'] ); |
|
| 515 | + $title = $this->limit_words($title, $attr['limit']); |
|
| 516 | 516 | $tag = 'span'; |
| 517 | 517 | } |
| 518 | 518 | |
| 519 | - return '<' . $tag . ' class="simcal-event-title" itemprop="name">' . $title . '</' . $tag . '>'; |
|
| 519 | + return '<'.$tag.' class="simcal-event-title" itemprop="name">'.$title.'</'.$tag.'>'; |
|
| 520 | 520 | } |
| 521 | 521 | |
| 522 | 522 | /** |
@@ -530,40 +530,40 @@ discard block |
||
| 530 | 530 | * |
| 531 | 531 | * @return string |
| 532 | 532 | */ |
| 533 | - private function get_description( $description, $attr ) { |
|
| 533 | + private function get_description($description, $attr) { |
|
| 534 | 534 | |
| 535 | - if ( empty( $description ) ) { |
|
| 535 | + if (empty($description)) { |
|
| 536 | 536 | return ''; |
| 537 | 537 | } |
| 538 | 538 | |
| 539 | - $attr = array_merge( array( |
|
| 540 | - 'limit' => 0, // Trim length to number of words |
|
| 541 | - 'html' => 'no', // Parse HTML content |
|
| 542 | - 'markdown' => 'no', // Parse Markdown content |
|
| 543 | - 'autolink' => 'no', // Automatically convert plaintext URIs to anchors |
|
| 544 | - ), (array) shortcode_parse_atts( $attr ) ); |
|
| 539 | + $attr = array_merge(array( |
|
| 540 | + 'limit' => 0, // Trim length to number of words |
|
| 541 | + 'html' => 'no', // Parse HTML content |
|
| 542 | + 'markdown' => 'no', // Parse Markdown content |
|
| 543 | + 'autolink' => 'no', // Automatically convert plaintext URIs to anchors |
|
| 544 | + ), (array) shortcode_parse_atts($attr)); |
|
| 545 | 545 | |
| 546 | - $allow_html = 'no' != $attr['html'] ? true : false; |
|
| 546 | + $allow_html = 'no' != $attr['html'] ? true : false; |
|
| 547 | 547 | $allow_md = 'no' != $attr['markdown'] ? true : false; |
| 548 | 548 | |
| 549 | 549 | $html = '<div class="simcal-event-description" itemprop="description">'; |
| 550 | 550 | |
| 551 | 551 | // Markdown and HTML don't play well together, use one or the other in the same tag. |
| 552 | - if ( $allow_html || $allow_md ) { |
|
| 553 | - if ( $allow_html ) { |
|
| 554 | - $description = wp_kses_post( $description ); |
|
| 555 | - } elseif ( $allow_md ) { |
|
| 552 | + if ($allow_html || $allow_md) { |
|
| 553 | + if ($allow_html) { |
|
| 554 | + $description = wp_kses_post($description); |
|
| 555 | + } elseif ($allow_md) { |
|
| 556 | 556 | $markdown = new \Parsedown(); |
| 557 | - $description = $markdown->text( wp_strip_all_tags( $description ) ); |
|
| 557 | + $description = $markdown->text(wp_strip_all_tags($description)); |
|
| 558 | 558 | } |
| 559 | 559 | } |
| 560 | 560 | |
| 561 | - $description = $this->limit_words( $description, $attr['limit'] ); |
|
| 561 | + $description = $this->limit_words($description, $attr['limit']); |
|
| 562 | 562 | |
| 563 | - $html .= $description . '</div>'; |
|
| 563 | + $html .= $description.'</div>'; |
|
| 564 | 564 | |
| 565 | - if ( 'no' != $attr['autolink'] ) { |
|
| 566 | - $html = ' ' . make_clickable( $html ); |
|
| 565 | + if ('no' != $attr['autolink']) { |
|
| 566 | + $html = ' '.make_clickable($html); |
|
| 567 | 567 | } |
| 568 | 568 | |
| 569 | 569 | return $html; |
@@ -579,74 +579,74 @@ discard block |
||
| 579 | 579 | * |
| 580 | 580 | * @return string |
| 581 | 581 | */ |
| 582 | - private function get_when( Event $event ) { |
|
| 582 | + private function get_when(Event $event) { |
|
| 583 | 583 | |
| 584 | - $start = $event->start_dt->setTimezone( $event->timezone ); |
|
| 585 | - $end = ! is_null( $event->end_dt ) ? $event->end_dt->setTimezone( $event->timezone ) : null; |
|
| 584 | + $start = $event->start_dt->setTimezone($event->timezone); |
|
| 585 | + $end = ! is_null($event->end_dt) ? $event->end_dt->setTimezone($event->timezone) : null; |
|
| 586 | 586 | |
| 587 | 587 | $time_start = ''; |
| 588 | 588 | $time_end = ''; |
| 589 | 589 | |
| 590 | - if ( ! $event->whole_day ) { |
|
| 590 | + if ( ! $event->whole_day) { |
|
| 591 | 591 | |
| 592 | - $time_start = $this->calendar->datetime_separator . |
|
| 593 | - ' <span class="simcal-event-start simcal-event-start-time" ' . |
|
| 594 | - 'data-event-start="' . $start->getTimestamp() . '" ' . |
|
| 595 | - 'data-event-format="' . $this->calendar->time_format . '" ' . |
|
| 596 | - 'itemprop="startDate" content="' . $start->toIso8601String() . '">' . |
|
| 597 | - date_i18n( $this->calendar->time_format, $start->getTimestamp() ) . |
|
| 592 | + $time_start = $this->calendar->datetime_separator. |
|
| 593 | + ' <span class="simcal-event-start simcal-event-start-time" '. |
|
| 594 | + 'data-event-start="'.$start->getTimestamp().'" '. |
|
| 595 | + 'data-event-format="'.$this->calendar->time_format.'" '. |
|
| 596 | + 'itemprop="startDate" content="'.$start->toIso8601String().'">'. |
|
| 597 | + date_i18n($this->calendar->time_format, $start->getTimestamp()). |
|
| 598 | 598 | '</span> '; |
| 599 | 599 | |
| 600 | - if ( $end instanceof Carbon ) { |
|
| 600 | + if ($end instanceof Carbon) { |
|
| 601 | 601 | |
| 602 | - $time_end = ' <span class="simcal-event-end simcal-event-end-time" ' . |
|
| 603 | - 'data-event-end="' . $end->getTimestamp() . '" ' . |
|
| 604 | - 'data-event-format="' . $this->calendar->time_format . '" ' . |
|
| 605 | - 'itemprop="endDate" content="' . $end->toIso8601String() . '">' . |
|
| 606 | - date_i18n( $this->calendar->time_format, $end->getTimestamp() ) . |
|
| 602 | + $time_end = ' <span class="simcal-event-end simcal-event-end-time" '. |
|
| 603 | + 'data-event-end="'.$end->getTimestamp().'" '. |
|
| 604 | + 'data-event-format="'.$this->calendar->time_format.'" '. |
|
| 605 | + 'itemprop="endDate" content="'.$end->toIso8601String().'">'. |
|
| 606 | + date_i18n($this->calendar->time_format, $end->getTimestamp()). |
|
| 607 | 607 | '</span> '; |
| 608 | 608 | |
| 609 | 609 | } |
| 610 | 610 | |
| 611 | 611 | } |
| 612 | 612 | |
| 613 | - if ( $event->multiple_days ) { |
|
| 613 | + if ($event->multiple_days) { |
|
| 614 | 614 | |
| 615 | - $output = ' <span class="simcal-event-start simcal-event-start-date" ' . |
|
| 616 | - 'data-event-start="' . $start->getTimestamp() . '" ' . |
|
| 617 | - 'data-event-format="' . $this->calendar->date_format . '" ' . |
|
| 618 | - 'itemprop="startDate" content="' . $start->toIso8601String() . '">' . |
|
| 619 | - date_i18n( $this->calendar->date_format, $start->getTimestamp() ) . |
|
| 620 | - '</span> ' . |
|
| 615 | + $output = ' <span class="simcal-event-start simcal-event-start-date" '. |
|
| 616 | + 'data-event-start="'.$start->getTimestamp().'" '. |
|
| 617 | + 'data-event-format="'.$this->calendar->date_format.'" '. |
|
| 618 | + 'itemprop="startDate" content="'.$start->toIso8601String().'">'. |
|
| 619 | + date_i18n($this->calendar->date_format, $start->getTimestamp()). |
|
| 620 | + '</span> '. |
|
| 621 | 621 | $time_start; |
| 622 | 622 | |
| 623 | - if ( $end instanceof Carbon ) { |
|
| 623 | + if ($end instanceof Carbon) { |
|
| 624 | 624 | |
| 625 | - $output .= '-' . |
|
| 626 | - ' <span class="simcal-event-start simcal-event-end-date" ' . |
|
| 627 | - 'data-event-start="' . $end->getTimestamp() . '" ' . |
|
| 628 | - 'data-event-format="' . $this->calendar->date_format . '" ' . |
|
| 629 | - 'itemprop="endDate" content="' . $end->toIso8601String() . '">' . |
|
| 630 | - date_i18n( $this->calendar->date_format, $end->getTimestamp() ) . |
|
| 631 | - '</span> ' . |
|
| 625 | + $output .= '-'. |
|
| 626 | + ' <span class="simcal-event-start simcal-event-end-date" '. |
|
| 627 | + 'data-event-start="'.$end->getTimestamp().'" '. |
|
| 628 | + 'data-event-format="'.$this->calendar->date_format.'" '. |
|
| 629 | + 'itemprop="endDate" content="'.$end->toIso8601String().'">'. |
|
| 630 | + date_i18n($this->calendar->date_format, $end->getTimestamp()). |
|
| 631 | + '</span> '. |
|
| 632 | 632 | $time_end; |
| 633 | 633 | } |
| 634 | 634 | |
| 635 | 635 | } else { |
| 636 | 636 | |
| 637 | - $time_end = ! empty( $time_start ) && ! empty( $time_end ) ? ' - ' . $time_end : ''; |
|
| 637 | + $time_end = ! empty($time_start) && ! empty($time_end) ? ' - '.$time_end : ''; |
|
| 638 | 638 | |
| 639 | - $output = ' <span class="simcal-event-start simcal-event-start-date" ' . |
|
| 640 | - 'data-event-start="' . $start->getTimestamp() . '" ' . |
|
| 641 | - 'data-event-format="' . $this->calendar->date_format . '">' . |
|
| 642 | - date_i18n( $this->calendar->date_format, $start->getTimestamp() ) . |
|
| 643 | - '</span> ' . |
|
| 644 | - $time_start . |
|
| 639 | + $output = ' <span class="simcal-event-start simcal-event-start-date" '. |
|
| 640 | + 'data-event-start="'.$start->getTimestamp().'" '. |
|
| 641 | + 'data-event-format="'.$this->calendar->date_format.'">'. |
|
| 642 | + date_i18n($this->calendar->date_format, $start->getTimestamp()). |
|
| 643 | + '</span> '. |
|
| 644 | + $time_start. |
|
| 645 | 645 | $time_end; |
| 646 | 646 | |
| 647 | 647 | } |
| 648 | 648 | |
| 649 | - return trim( $output ); |
|
| 649 | + return trim($output); |
|
| 650 | 650 | } |
| 651 | 651 | |
| 652 | 652 | /** |
@@ -661,50 +661,50 @@ discard block |
||
| 661 | 661 | * |
| 662 | 662 | * @return string |
| 663 | 663 | */ |
| 664 | - private function get_dt( $tag, Event $event, $attr ) { |
|
| 664 | + private function get_dt($tag, Event $event, $attr) { |
|
| 665 | 665 | |
| 666 | - $bound = 0 === strpos( $tag, 'end' ) ? 'end' : 'start'; |
|
| 667 | - if ( ( 'end' == $bound ) && ( false === $event->end ) ) { |
|
| 666 | + $bound = 0 === strpos($tag, 'end') ? 'end' : 'start'; |
|
| 667 | + if (('end' == $bound) && (false === $event->end)) { |
|
| 668 | 668 | return ''; |
| 669 | 669 | } |
| 670 | 670 | |
| 671 | - $dt = $bound . '_dt'; |
|
| 672 | - if ( ! $event->$dt instanceof Carbon ) { |
|
| 671 | + $dt = $bound.'_dt'; |
|
| 672 | + if ( ! $event->$dt instanceof Carbon) { |
|
| 673 | 673 | return ''; |
| 674 | 674 | } |
| 675 | - $event_dt = $event->$dt->setTimezone( $event->timezone ); |
|
| 675 | + $event_dt = $event->$dt->setTimezone($event->timezone); |
|
| 676 | 676 | |
| 677 | - $attr = array_merge( array( |
|
| 677 | + $attr = array_merge(array( |
|
| 678 | 678 | 'format' => '', |
| 679 | - ), (array) shortcode_parse_atts( $attr ) ); |
|
| 679 | + ), (array) shortcode_parse_atts($attr)); |
|
| 680 | 680 | |
| 681 | - $format = ltrim( strstr( $tag, '-' ), '-' ); |
|
| 681 | + $format = ltrim(strstr($tag, '-'), '-'); |
|
| 682 | 682 | $dt_format = ''; |
| 683 | - if ( ! empty( $attr['format'] ) ) { |
|
| 684 | - $dt_format = esc_attr( wp_strip_all_tags( $attr['format'] ) ); |
|
| 685 | - } elseif ( 'date' == $format ) { |
|
| 683 | + if ( ! empty($attr['format'])) { |
|
| 684 | + $dt_format = esc_attr(wp_strip_all_tags($attr['format'])); |
|
| 685 | + } elseif ('date' == $format) { |
|
| 686 | 686 | $dt_format = $this->calendar->date_format; |
| 687 | - } elseif ( 'time' == $format ) { |
|
| 687 | + } elseif ('time' == $format) { |
|
| 688 | 688 | $dt_format = $this->calendar->time_format; |
| 689 | 689 | } |
| 690 | 690 | |
| 691 | - if ( 'human' == $format ) { |
|
| 692 | - $value = human_time_diff( $event_dt->getTimestamp(), Carbon::now( $event->timezone )->getTimestamp() ); |
|
| 691 | + if ('human' == $format) { |
|
| 692 | + $value = human_time_diff($event_dt->getTimestamp(), Carbon::now($event->timezone)->getTimestamp()); |
|
| 693 | 693 | |
| 694 | - if ( $event_dt->getTimestamp() < Carbon::now( $event->timezone )->getTimestamp() ) { |
|
| 695 | - $value .= ' ' . _x( 'before', 'human date event builder code modifier', 'google-calendar-events' ); |
|
| 694 | + if ($event_dt->getTimestamp() < Carbon::now($event->timezone)->getTimestamp()) { |
|
| 695 | + $value .= ' '._x('before', 'human date event builder code modifier', 'google-calendar-events'); |
|
| 696 | 696 | } else { |
| 697 | - $value .= ' ' . _x( 'after', 'human date event builder code modifier', 'google-calendar-events' ); |
|
| 697 | + $value .= ' '._x('after', 'human date event builder code modifier', 'google-calendar-events'); |
|
| 698 | 698 | } |
| 699 | 699 | } else { |
| 700 | - $value = date_i18n( $dt_format, $event_dt->getTimestamp() ); |
|
| 700 | + $value = date_i18n($dt_format, $event_dt->getTimestamp()); |
|
| 701 | 701 | } |
| 702 | 702 | |
| 703 | - return '<span class="simcal-event-' . $bound . ' ' . 'simcal-event-' . $bound . '-' . $format . '"' . |
|
| 704 | - 'data-event-' . $bound . '="' . $event_dt->getTimestamp() . '"' . |
|
| 705 | - 'data-event-format="' . $dt_format . '"' . |
|
| 706 | - 'itemprop="' . $bound . 'Date" content="' . $event_dt->toIso8601String() . '">' . |
|
| 707 | - $value . |
|
| 703 | + return '<span class="simcal-event-'.$bound.' '.'simcal-event-'.$bound.'-'.$format.'"'. |
|
| 704 | + 'data-event-'.$bound.'="'.$event_dt->getTimestamp().'"'. |
|
| 705 | + 'data-event-format="'.$dt_format.'"'. |
|
| 706 | + 'itemprop="'.$bound.'Date" content="'.$event_dt->toIso8601String().'">'. |
|
| 707 | + $value. |
|
| 708 | 708 | '</span>'; |
| 709 | 709 | } |
| 710 | 710 | |
@@ -721,23 +721,23 @@ discard block |
||
| 721 | 721 | * |
| 722 | 722 | * @return string |
| 723 | 723 | */ |
| 724 | - private function make_link( $tag, $url, $content, $attr ) { |
|
| 724 | + private function make_link($tag, $url, $content, $attr) { |
|
| 725 | 725 | |
| 726 | - if ( empty( $url ) ) { |
|
| 726 | + if (empty($url)) { |
|
| 727 | 727 | return ''; |
| 728 | 728 | } |
| 729 | 729 | |
| 730 | - $text = empty( $content ) ? $url : $content; |
|
| 730 | + $text = empty($content) ? $url : $content; |
|
| 731 | 731 | |
| 732 | - $attr = array_merge( array( |
|
| 733 | - 'autolink' => false, // Convert url to link anchor |
|
| 734 | - 'newwindow' => false, // If autolink attribute is true, open link in new window |
|
| 735 | - ), (array) shortcode_parse_atts( $attr ) ); |
|
| 732 | + $attr = array_merge(array( |
|
| 733 | + 'autolink' => false, // Convert url to link anchor |
|
| 734 | + 'newwindow' => false, // If autolink attribute is true, open link in new window |
|
| 735 | + ), (array) shortcode_parse_atts($attr)); |
|
| 736 | 736 | |
| 737 | 737 | $anchor = $tag != 'url' ? 'yes' : $attr['autolink']; |
| 738 | 738 | $target = $attr['newwindow'] !== false ? 'target="_blank"' : ''; |
| 739 | 739 | |
| 740 | - return $anchor !== false ? ' <a href="' . esc_url( $url ) . '" ' . $target . '>' . $text . '</a>' : ' ' . $text; |
|
| 740 | + return $anchor !== false ? ' <a href="'.esc_url($url).'" '.$target.'>'.$text.'</a>' : ' '.$text; |
|
| 741 | 741 | } |
| 742 | 742 | |
| 743 | 743 | /** |
@@ -750,20 +750,20 @@ discard block |
||
| 750 | 750 | * |
| 751 | 751 | * @return string |
| 752 | 752 | */ |
| 753 | - private function get_attachments( $attachments ) { |
|
| 753 | + private function get_attachments($attachments) { |
|
| 754 | 754 | |
| 755 | - $html = '<ul class="simcal-attachments">' . "\n\t"; |
|
| 755 | + $html = '<ul class="simcal-attachments">'."\n\t"; |
|
| 756 | 756 | |
| 757 | - foreach ( $attachments as $attachment ) { |
|
| 757 | + foreach ($attachments as $attachment) { |
|
| 758 | 758 | $html .= '<li class="simcal-attachment">'; |
| 759 | - $html .= '<a href="' . $attachment['url'] . '" target="_blank">'; |
|
| 760 | - $html .= ! empty( $attachment['icon'] ) ? '<img src="' . $attachment['icon'] . '" />' : ''; |
|
| 761 | - $html .= '<span>' . $attachment['name'] . '</span>'; |
|
| 759 | + $html .= '<a href="'.$attachment['url'].'" target="_blank">'; |
|
| 760 | + $html .= ! empty($attachment['icon']) ? '<img src="'.$attachment['icon'].'" />' : ''; |
|
| 761 | + $html .= '<span>'.$attachment['name'].'</span>'; |
|
| 762 | 762 | $html .= '</a>'; |
| 763 | - $html .= '</li>' . "\n"; |
|
| 763 | + $html .= '</li>'."\n"; |
|
| 764 | 764 | } |
| 765 | 765 | |
| 766 | - $html .= '</ul>' . "\n"; |
|
| 766 | + $html .= '</ul>'."\n"; |
|
| 767 | 767 | |
| 768 | 768 | return $html; |
| 769 | 769 | } |
@@ -779,41 +779,41 @@ discard block |
||
| 779 | 779 | * |
| 780 | 780 | * @return string |
| 781 | 781 | */ |
| 782 | - private function get_attendees( $attendees, $attr ) { |
|
| 782 | + private function get_attendees($attendees, $attr) { |
|
| 783 | 783 | |
| 784 | - $attr = array_merge( array( |
|
| 785 | - 'photo' => 'show', // show/hide attendee photo |
|
| 786 | - 'email' => 'hide', // show/hide attendee email address |
|
| 787 | - 'rsvp' => 'hide', // show/hide rsvp response status |
|
| 788 | - 'response' => '', // filter attendees by rsvp response (yes/no/maybe) |
|
| 789 | - ), (array) shortcode_parse_atts( $attr ) ); |
|
| 784 | + $attr = array_merge(array( |
|
| 785 | + 'photo' => 'show', // show/hide attendee photo |
|
| 786 | + 'email' => 'hide', // show/hide attendee email address |
|
| 787 | + 'rsvp' => 'hide', // show/hide rsvp response status |
|
| 788 | + 'response' => '', // filter attendees by rsvp response (yes/no/maybe) |
|
| 789 | + ), (array) shortcode_parse_atts($attr)); |
|
| 790 | 790 | |
| 791 | - $html = '<ul class="simcal-attendees" itemprop="attendees">' . "\n\t"; |
|
| 791 | + $html = '<ul class="simcal-attendees" itemprop="attendees">'."\n\t"; |
|
| 792 | 792 | |
| 793 | 793 | $known = 0; |
| 794 | 794 | $unknown = 0; |
| 795 | 795 | |
| 796 | - foreach ( $attendees as $attendee ) { |
|
| 796 | + foreach ($attendees as $attendee) { |
|
| 797 | 797 | |
| 798 | - if ( 'yes' == $attr['response'] && 'yes' != $attendee['response'] ) { |
|
| 798 | + if ('yes' == $attr['response'] && 'yes' != $attendee['response']) { |
|
| 799 | 799 | continue; |
| 800 | - } elseif ( 'no' == $attr['response'] && 'no' != $attendee['response'] ) { |
|
| 800 | + } elseif ('no' == $attr['response'] && 'no' != $attendee['response']) { |
|
| 801 | 801 | continue; |
| 802 | - } elseif ( 'maybe' == $attr['response'] && ! in_array( $attendee['response'], array( 'yes', 'maybe' ) ) ) { |
|
| 802 | + } elseif ('maybe' == $attr['response'] && ! in_array($attendee['response'], array('yes', 'maybe'))) { |
|
| 803 | 803 | continue; |
| 804 | 804 | } |
| 805 | 805 | |
| 806 | - if ( ! empty( $attendee['name'] ) ) { |
|
| 806 | + if ( ! empty($attendee['name'])) { |
|
| 807 | 807 | |
| 808 | - $photo = 'hide' != $attr['photo'] ? '<img class="avatar avatar-128 photo" src="' . $attendee['photo'] . '" itemprop="image" />' : ''; |
|
| 809 | - $response = 'hide' != $attr['rsvp'] ? $this->get_rsvp_response( $attendee['response'] ) : ''; |
|
| 810 | - $guest = $photo . '<span itemprop="name">' . $attendee['name'] . $response . '</span>'; |
|
| 808 | + $photo = 'hide' != $attr['photo'] ? '<img class="avatar avatar-128 photo" src="'.$attendee['photo'].'" itemprop="image" />' : ''; |
|
| 809 | + $response = 'hide' != $attr['rsvp'] ? $this->get_rsvp_response($attendee['response']) : ''; |
|
| 810 | + $guest = $photo.'<span itemprop="name">'.$attendee['name'].$response.'</span>'; |
|
| 811 | 811 | |
| 812 | - if ( ! empty( $attendee['email'] ) && ( 'show' == $attr['email'] ) ) { |
|
| 813 | - $guest = sprintf( '<a href="mailto:' . $attendee['email'] . '" itemprop="email">%s</a>', $guest ); |
|
| 812 | + if ( ! empty($attendee['email']) && ('show' == $attr['email'])) { |
|
| 813 | + $guest = sprintf('<a href="mailto:'.$attendee['email'].'" itemprop="email">%s</a>', $guest); |
|
| 814 | 814 | } |
| 815 | 815 | |
| 816 | - $html .= '<li class="simcal-attendee" itemprop="attendee" itemscope itemtype="http://schema.org/Person">' . $guest . '</li>' . "\n"; |
|
| 816 | + $html .= '<li class="simcal-attendee" itemprop="attendee" itemscope itemtype="http://schema.org/Person">'.$guest.'</li>'."\n"; |
|
| 817 | 817 | |
| 818 | 818 | $known++; |
| 819 | 819 | |
@@ -824,21 +824,21 @@ discard block |
||
| 824 | 824 | } |
| 825 | 825 | } |
| 826 | 826 | |
| 827 | - if ( $unknown > 0 ) { |
|
| 828 | - if ( $known > 0 ) { |
|
| 827 | + if ($unknown > 0) { |
|
| 828 | + if ($known > 0) { |
|
| 829 | 829 | /* translators: One more person attending the event. */ |
| 830 | - $others = sprintf( _n( '1 more attendee', '%s more attendees', $unknown, 'google-calendar-events' ), $unknown ); |
|
| 830 | + $others = sprintf(_n('1 more attendee', '%s more attendees', $unknown, 'google-calendar-events'), $unknown); |
|
| 831 | 831 | } else { |
| 832 | 832 | /* translators: One or more persons attending the event whose name is unknown. */ |
| 833 | - $others = sprintf( _n( '1 anonymous attendee', '%s anonymous attendees', $unknown, 'google-calendar-events' ), $unknown ); |
|
| 833 | + $others = sprintf(_n('1 anonymous attendee', '%s anonymous attendees', $unknown, 'google-calendar-events'), $unknown); |
|
| 834 | 834 | } |
| 835 | - $photo = $attr['photo'] !== 'hide' ? get_avatar( '', 128 ) : ''; |
|
| 836 | - $html .= '<li class="simcal-attendee simcal-attendee-anonymous">' . $photo . '<span>' . $others . '</span></li>' . "\n"; |
|
| 837 | - } elseif ( $known === 0 ) { |
|
| 838 | - $html .= '<li class="simcal-attendee">' . _x( 'No one yet', 'No one yet rsvp to attend the event.', 'google-calendar-events' ) . '</li>' . "\n"; |
|
| 835 | + $photo = $attr['photo'] !== 'hide' ? get_avatar('', 128) : ''; |
|
| 836 | + $html .= '<li class="simcal-attendee simcal-attendee-anonymous">'.$photo.'<span>'.$others.'</span></li>'."\n"; |
|
| 837 | + } elseif ($known === 0) { |
|
| 838 | + $html .= '<li class="simcal-attendee">'._x('No one yet', 'No one yet rsvp to attend the event.', 'google-calendar-events').'</li>'."\n"; |
|
| 839 | 839 | } |
| 840 | 840 | |
| 841 | - $html .= '</ul>' . "\n"; |
|
| 841 | + $html .= '</ul>'."\n"; |
|
| 842 | 842 | |
| 843 | 843 | return $html; |
| 844 | 844 | } |
@@ -852,23 +852,23 @@ discard block |
||
| 852 | 852 | * |
| 853 | 853 | * @return string |
| 854 | 854 | */ |
| 855 | - private function get_rsvp_response( $response ) { |
|
| 855 | + private function get_rsvp_response($response) { |
|
| 856 | 856 | |
| 857 | - if ( 'yes' == $response ) { |
|
| 857 | + if ('yes' == $response) { |
|
| 858 | 858 | /* translators: Someone replied with 'yes' to a rsvp request. */ |
| 859 | - $rsvp = __( 'Attending', 'google-calendar-events' ); |
|
| 860 | - } elseif ( 'no' == $response ) { |
|
| 859 | + $rsvp = __('Attending', 'google-calendar-events'); |
|
| 860 | + } elseif ('no' == $response) { |
|
| 861 | 861 | /* translators: Someone replied with 'no' to a rsvp request. */ |
| 862 | - $rsvp = __( 'Not attending', 'google-calendar-events' ); |
|
| 863 | - } elseif ( 'maybe' == $response ) { |
|
| 862 | + $rsvp = __('Not attending', 'google-calendar-events'); |
|
| 863 | + } elseif ('maybe' == $response) { |
|
| 864 | 864 | /* translators: Someone replied with 'maybe' to a rsvp request. */ |
| 865 | - $rsvp = __( 'Maybe attending', 'google-calendar-events' ); |
|
| 865 | + $rsvp = __('Maybe attending', 'google-calendar-events'); |
|
| 866 | 866 | } else { |
| 867 | 867 | /* translators: Someone did not send yet a rsvp confirmation to join an event. */ |
| 868 | - $rsvp = __( 'Response pending', 'google-calendar-events' ); |
|
| 868 | + $rsvp = __('Response pending', 'google-calendar-events'); |
|
| 869 | 869 | } |
| 870 | 870 | |
| 871 | - return ' <small>(' . $rsvp . ')</small>'; |
|
| 871 | + return ' <small>('.$rsvp.')</small>'; |
|
| 872 | 872 | } |
| 873 | 873 | |
| 874 | 874 | /** |
@@ -882,21 +882,21 @@ discard block |
||
| 882 | 882 | * |
| 883 | 883 | * @return string |
| 884 | 884 | */ |
| 885 | - private function get_organizer( $organizer, $attr ) { |
|
| 885 | + private function get_organizer($organizer, $attr) { |
|
| 886 | 886 | |
| 887 | - $attr = array_merge( array( |
|
| 888 | - 'photo' => 'show', // show/hide attendee photo |
|
| 889 | - 'email' => 'hide', // show/hide attendee email address |
|
| 890 | - ), (array) shortcode_parse_atts( $attr ) ); |
|
| 887 | + $attr = array_merge(array( |
|
| 888 | + 'photo' => 'show', // show/hide attendee photo |
|
| 889 | + 'email' => 'hide', // show/hide attendee email address |
|
| 890 | + ), (array) shortcode_parse_atts($attr)); |
|
| 891 | 891 | |
| 892 | - $photo = 'hide' != $attr['photo'] ? '<img class="avatar avatar-128 photo" src="' . $organizer['photo'] . '" itemprop="image" />' : ''; |
|
| 893 | - $organizer_html = $photo . '<span itemprop="name">' . $organizer['name'] . '</span>'; |
|
| 892 | + $photo = 'hide' != $attr['photo'] ? '<img class="avatar avatar-128 photo" src="'.$organizer['photo'].'" itemprop="image" />' : ''; |
|
| 893 | + $organizer_html = $photo.'<span itemprop="name">'.$organizer['name'].'</span>'; |
|
| 894 | 894 | |
| 895 | - if ( ! empty( $organizer['email'] ) && ( 'show' == $attr['email'] ) ) { |
|
| 896 | - $organizer_html = sprintf( '<a href="mailto:' . $organizer['email'] . '" itemprop="email">%s</a>', $organizer_html ); |
|
| 895 | + if ( ! empty($organizer['email']) && ('show' == $attr['email'])) { |
|
| 896 | + $organizer_html = sprintf('<a href="mailto:'.$organizer['email'].'" itemprop="email">%s</a>', $organizer_html); |
|
| 897 | 897 | } |
| 898 | 898 | |
| 899 | - return '<div class="simcal-organizer" itemprop="organizer" itemscope itemtype="https://schema.org/Person">' . $organizer_html . '</div>'; |
|
| 899 | + return '<div class="simcal-organizer" itemprop="organizer" itemscope itemtype="https://schema.org/Person">'.$organizer_html.'</div>'; |
|
| 900 | 900 | } |
| 901 | 901 | |
| 902 | 902 | /** |
@@ -921,7 +921,7 @@ discard block |
||
| 921 | 921 | // This is largely borrowed on get_shortcode_regex() from WordPress Core. |
| 922 | 922 | // @see /wp-includes/shortcodes.php (with some modification) |
| 923 | 923 | |
| 924 | - $tagregexp = implode( '|', array_values( $this->tags ) ); |
|
| 924 | + $tagregexp = implode('|', array_values($this->tags)); |
|
| 925 | 925 | |
| 926 | 926 | return '/' |
| 927 | 927 | . '\\[' // Opening bracket |