You are here

class ParserIcalDateModule in iCal feed parser 7.2

@file Classes for using date_api ical parsing.

Hierarchy

Expanded class hierarchy of ParserIcalDateModule

4 string references to 'ParserIcalDateModule'
ParserIcalDateModuleLinkCase::configureParser in tests/parser_ical_link.test
Set and configure the parser plugin.
ParserIcalDateModuleLocationCase::configureParser in tests/parser_ical_location.test
Set and configure the parser plugin.
ParserIcalDateModuleTextCase::configureParser in tests/parser_ical_text.test
Set and configure the parser plugin.
parser_ical_feeds_plugins in ./parser_ical.module
Implementation of ctools plugin for feeds hook_feeds_plugins().

File

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

View source
class ParserIcalDateModule extends ParserIcalFeeds {

  /**
   * Output sources this parser offers.
   *
   * Includes additional field for the handler for output.
   *
   * @see ParserIcalCreator::getMappingSources().
   * @see ParserIcalCreator::getSourceElement().
   */
  protected static $sources = array(
    'summary' => array(
      'name' => 'Summary',
      'description' => 'A short summary or subject for the calendar component.',
      'parser_ical_handler' => 'formatText',
    ),
    'description' => array(
      'name' => 'Description',
      'description' => 'A more complete description calendar component than that provided by the "summary" property.',
      'parser_ical_handler' => 'formatText',
    ),
    'dtstart' => array(
      'name' => 'Date for feed item',
      'description' => 'Start time for the feed item.',
      'parser_ical_handler' => 'formatDateTime',
    ),
    /*    'dtend' => array(
          'name' => 'Date end',
          'description' => 'End time for the feed item.',
          'parser_ical_handler' => 'formatDateTime',
          ), */
    'uid' => array(
      'name' => 'UID',
      'description' => 'UID of feed item',
      'parser_ical_handler' => 'formatText',
    ),
    'url' => array(
      'name' => 'URL',
      'description' => 'URL for the feed item.',
      'parser_ical_handler' => 'formatText',
    ),
    'location' => array(
      'name' => 'Location text',
      'description' => 'Text of location property of feed item.',
      'parser_ical_handler' => 'formatText',
    ),
  );

  /**
   * Load and run parser implementation of FeedsParser::parse().
   *
   * @params - change these to generic required paramters.
   */
  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;
  }

  /******
   * Source output formatters.
   *
   * Could be in a class of their own?
   **/

  /**
   * Format text fields.
   */
  public function formatText($property_key, $property, ParserIcalComponentInterface $item, FeedsParserResult $result, FeedsSource $source) {
    return $property;
  }

  /**
   * Format datetime fields.
   */
  public function formatDateTime($property_key, $property, ParserIcalComponentInterface $item, FeedsParserResult $result, FeedsSource $source) {
    $dtstart = $item
      ->getProperty("dtstart");
    $dtend = $item
      ->getProperty("dtend");

    # drupal_set_message(print_r($dtstart, TRUE));
    $dstart = new FeedsDateTime($dtstart["datetime"]);
    $dend = new FeedsDateTime($dtend["datetime"]);
    $dt = new FeedsDateTimeElement($dstart, $dend, $dtstart["tz"]);

    # drupal_set_message(print_r($property_key, TRUE));

    # drupal_set_message(print_r($dt, TRUE));

    # drupal_set_message("<pre>" . print_r($item, TRUE) . "</pre>");
    return $dt;
  }

  /**
   * Load external iCalcreator class from libary.
   */
  public static function loadLibrary() {
    include_once drupal_get_path('module', 'date_api') . '/date_api_ical.inc';
  }

}

Members

Namesort descending Modifiers Type Description Overrides
ParserIcalDateModule::$sources protected static property Output sources this parser offers. Overrides ParserIcalFeeds::$sources
ParserIcalDateModule::formatDateTime public function Format datetime fields.
ParserIcalDateModule::formatText public function Format text fields.
ParserIcalDateModule::loadLibrary public static function Load external iCalcreator class from libary.
ParserIcalDateModule::parse public function Load and run parser implementation of FeedsParser::parse().
ParserIcalFeeds::getMappingSources public function Implementation of FeedsParser::getMappingSources().
ParserIcalFeeds::getSourceElement public function Override FeedsParser::getSourceElement().