You are here

public function ParserIcalDateModule::parse in iCal feed parser 7.2

Load and run parser implementation of FeedsParser::parse().

@params - change these to generic required paramters.

File

includes/ParserIcalDate.inc, line 60
Classes for using date_api ical parsing.

Class

ParserIcalDateModule
@file Classes for using date_api ical parsing.

Code

public function parse(FeedsSource $source, FeedsFetcherResult $fetcher_result) {
  self::loadLibrary();
  $feed_output = $fetcher_result
    ->getRaw();
  $feed_folded = explode("\n", $feed_output);
  $parsed = date_ical_parse($feed_folded);
  $ical = $parsed[0];
  $result = new ParserIcalResult();
  $result->title = isset($ical['X-WR-CALNAME']) ? $ical['X-WR-CALNAME'] : '';
  $result->description = isset($ical['X-WR-CALDESC']) ? $ical['X-WR-CALDESC'] : '';
  $timezone = isset($ical['X-WR-TIMEZONE']) ? $ical['X-WR-TIMEZONE'] : '';
  if (!empty($timezone)) {
    try {
      $tz = new DateTimeZone($xprop[1]);
      $result->timezone = $tz;
    } catch (Exception $e) {
      $source
        ->log('parse', 'Invalid X-WR-TIMEZONE: %error', array(
        '%error' => $e
          ->getMessage(),
      ), WATCHDOG_NOTICE);
    }
  }
  $components = array();
  if (isset($ical['VEVENT'])) {
    foreach ($ical['VEVENT'] as $event) {
      $components[] = new ParserIcalDateModuleComponent('vevent', $event);
    }
  }
  $result->items = $components;
  return $result;
}