You are here

protected function AvailabilityCalendarICalFeedsParser::parseVcalendar in Availability Calendars 7.5

Parses a VCALENDAR feed into VEVENTS.

Parameters

string $feed: The full iCal feed.

Return value

\stdClass[] A list of VEVENT objects.

Throws

\Exception

1 call to AvailabilityCalendarICalFeedsParser::parseVcalendar()
AvailabilityCalendarICalFeedsParser::parse in ./AvailabilityCalendarICalFeedsParser.inc
Implements FeedsParser::parse().

File

./AvailabilityCalendarICalFeedsParser.inc, line 46

Class

AvailabilityCalendarICalFeedsParser
@class ICalendar parser for availability calendars.

Code

protected function parseVcalendar($feed) {
  $vevents = array();

  // https://icalendar.org/iCalendar-RFC-5545/3-1-content-lines.html:
  // - Content lines are delimited by a line break, which is a CRLF sequence.
  // - Long content lines SHOULD be split into a multiple line representations
  //   {...} by inserting a CRLF immediately followed by a {...} SPACE or
  //   HTAB. Any {such} sequence {...} is {to be} ignored.
  // We accept all line endings:
  $feed = str_replace("\r\n", "\n", $feed);
  $feed = str_replace("\r", "\n", $feed);

  // Join lines that were split.
  $feed = str_replace(array(
    "\n ",
    "\n\t",
  ), '', $feed);
  $lines = explode("\n", $feed);
  $i = 0;
  $c = count($lines);
  while ($i < $c) {
    if (strtoupper(trim($lines[$i++])) === 'BEGIN:VEVENT') {
      $vevent = $this
        ->parseVevent($lines, $i);
      if (is_object($vevent)) {
        $vevents[] = $vevent;
      }
    }
  }
  return $vevents;
}