| @@ -45,8 +45,15 @@ | ||
| 45 | 45 | */ |
| 46 | 46 | public $timezone = null; |
| 47 | 47 | |
| 48 | 48 | /** |
| 49 | + * Last iCalendar keyword parsed. | |
| 50 | + * | |
| 51 | + * @var string | |
| 52 | + */ | |
| 53 | + public $last_keyword; | |
| 54 | + | |
| 55 | + /** | |
| 49 | 56 | * Class constructor |
| 50 | 57 | * |
| 51 | 58 | * @return void |
| 52 | 59 | */ |
| @@ -64,9 +71,8 @@ | ||
| 64 | 71 | $count = (int) $count; |
| 65 | 72 | $transient_id = 'icalendar_vcal_' . md5( $url ) . '_' . $count; |
| 66 | 73 | |
| 67 | 74 | $vcal = get_transient( $transient_id ); |
| 68 | - $vcal = false; | |
| 69 | 75 | if ( ! empty( $vcal ) ) { |
| 70 | 76 | if ( isset( $vcal['TIMEZONE'] ) ) { |
| 71 | 77 | $this->timezone = $this->timezone_from_string( $vcal['TIMEZONE'] ); |
| 72 | 78 | } |
| @@ -146,15 +152,15 @@ | ||
| 146 | 152 | if ( 8 < strlen( $event['DTSTART'] ) ) { |
| 147 | 153 | $start_time = preg_replace( '/Z$/', '', $event['DTSTART'] ); |
| 148 | 154 | $start_time = new DateTime( $start_time, $this->timezone ); |
| 149 | 155 | $start_time->setTimeZone( $timezone ); |
| 150 | - | |
| 151 | - $end_time = preg_replace( '/Z$/', '', $event['DTEND'] ); | |
| 152 | - $end_time = new DateTime( $end_time, $this->timezone ); | |
| 153 | - $end_time->setTimeZone( $timezone ); | |
| 154 | - | |
| 155 | 156 | $event['DTSTART'] = $start_time->format( 'YmdHis\Z' ); |
| 156 | - $event['DTEND'] = $end_time->format( 'YmdHis\Z' ); | |
| 157 | + if ( isset( $event['DTEND'] ) ) { | |
| 158 | + $end_time = preg_replace( '/Z$/', '', $event['DTEND'] ); | |
| 159 | + $end_time = new DateTime( $end_time, $this->timezone ); | |
| 160 | + $end_time->setTimeZone( $timezone ); | |
| 161 | + $event['DTEND'] = $end_time->format( 'YmdHis\Z' ); | |
| 162 | + } | |
| 157 | 163 | } |
| 158 | 164 | |
| 159 | 165 | $offsetted_events[] = $event; |
| 160 | 166 | } |
| @@ -229,12 +235,12 @@ | ||
| 229 | 235 | continue; |
| 230 | 236 | } |
| 231 | 237 | |
| 232 | 238 | // Process events with RRULE before other events. |
| 233 | - $rrule = isset( $event['RRULE'] ) ? $event['RRULE'] : false; | |
| 234 | - $uid = $event['UID']; | |
| 239 | + $rrule = $event['RRULE'] ?? false; | |
| 240 | + $uid = $event['UID'] ?? false; | |
| 235 | 241 | |
| 236 | - if ( $rrule && ! in_array( $uid, $set_recurring_events, true ) ) { | |
| 242 | + if ( $rrule && $uid && ! in_array( $uid, $set_recurring_events, true ) ) { | |
| 237 | 243 | |
| 238 | 244 | // Break down the RRULE into digestible chunks. |
| 239 | 245 | $rrule_array = array(); |
| 240 | 246 | |
| @@ -242,10 +248,10 @@ | ||
| 242 | 248 | list( $rkey, $rvalue ) = explode( '=', $rline, 2 ); |
| 243 | 249 | $rrule_array[ $rkey ] = $rvalue; |
| 244 | 250 | } |
| 245 | 251 | |
| 246 | - $interval = ( isset( $rrule_array['INTERVAL'] ) ) ? $rrule_array['INTERVAL'] : 1; | |
| 247 | - $rrule_count = ( isset( $rrule_array['COUNT'] ) ) ? $rrule_array['COUNT'] : 0; | |
| 252 | + $interval = $rrule_array['INTERVAL'] ?? 1; | |
| 253 | + $rrule_count = $rrule_array['COUNT'] ?? 0; | |
| 248 | 254 | $until = ( isset( $rrule_array['UNTIL'] ) ) ? strtotime( $rrule_array['UNTIL'] ) : strtotime( '+1 year', $current ); |
| 249 | 255 | |
| 250 | 256 | // Used to bound event checks. |
| 251 | 257 | $echo_limit = 10; |
| @@ -268,9 +274,9 @@ | ||
| 268 | 274 | // Interval and count. |
| 269 | 275 | $catchup = floor( ( $current - strtotime( $event['DTSTART'] ) ) / ( $interval * DAY_IN_SECONDS ) ); |
| 270 | 276 | if ( $rrule_count && $catchup > 0 ) { |
| 271 | 277 | if ( $catchup < $rrule_count ) { |
| 272 | - $rrule_count = $rrule_count - $catchup; | |
| 278 | + $rrule_count -= $catchup; | |
| 273 | 279 | $recurring_event_date_start = date( |
| 274 | 280 | 'Ymd', |
| 275 | 281 | strtotime( |
| 276 | 282 | '+ ' . ( $interval * $catchup ) . ' days', |
| @@ -316,9 +322,9 @@ | ||
| 316 | 322 | // Interval and count. |
| 317 | 323 | $catchup = floor( ( $current - strtotime( $event['DTSTART'] ) ) / ( $interval * WEEK_IN_SECONDS ) ); |
| 318 | 324 | if ( $rrule_count && $catchup > 0 ) { |
| 319 | 325 | if ( ( $catchup * count( $bydays ) ) < $rrule_count ) { |
| 320 | - $rrule_count = $rrule_count - ( $catchup * count( $bydays ) ); // Estimate current event count. | |
| 326 | + $rrule_count -= $catchup * count( $bydays ); // Estimate current event count. | |
| 321 | 327 | $recurring_event_date_start = date( 'Ymd', strtotime( '+ ' . ( $interval * $catchup ) . ' weeks', strtotime( $event['DTSTART'] ) ) ) . date( '\THis', strtotime( $event['DTSTART'] ) ); |
| 322 | 328 | } else { |
| 323 | 329 | $noop = true; |
| 324 | 330 | } |
| @@ -436,9 +442,9 @@ | ||
| 436 | 442 | $rrule_count = 10; |
| 437 | 443 | } |
| 438 | 444 | |
| 439 | 445 | // Set up EXDATE handling for the event. |
| 440 | - $exdates = ( isset( $event['EXDATE'] ) ) ? $event['EXDATE'] : array(); | |
| 446 | + $exdates = $event['EXDATE'] ?? array(); | |
| 441 | 447 | |
| 442 | 448 | for ( $i = 1; $i <= $echo_limit; $i++ ) { |
| 443 | 449 | |
| 444 | 450 | // Weeks need a daily loop and must check for inclusion in BYDAYS. |
| @@ -551,9 +557,9 @@ | ||
| 551 | 557 | } |
| 552 | 558 | $set_recurring_events[] = $uid; |
| 553 | 559 | |
| 554 | 560 | } |
| 555 | - } elseif ( strtotime( isset( $event['DTEND'] ) ? $event['DTEND'] : $event['DTSTART'] ) >= $current ) { // Process normal events. | |
| 561 | + } elseif ( strtotime( $event['DTEND'] ?? $event['DTSTART'] ) >= $current ) { // Process normal events. | |
| 556 | 562 | $upcoming[] = $event; |
| 557 | 563 | } |
| 558 | 564 | } |
| 559 | 565 | return $upcoming; |