Commit cba726e2 authored by Robert Rollins's avatar Robert Rollins

Removed the dependency on Feeds, and the old Date Module-based Feeds parser

parent cf6e11e3
......@@ -37,8 +37,8 @@ function hook_date_ical_feed_event_render_alter(&$event, $view, &$context) {
/**
* Alter an iCal representation of an event.
*
* This hook allows you to modify the event that is actually being added to the
* iCal calendar. If the Date iCal doesn't support an iCal property that you
* This hook allows you to modify the event that is being added to the
* iCal calendar. If Date iCal doesn't support an iCal property that you
* need to use, then you can add it to the event in the iCal feed here.
*
* @param $vevent
......@@ -132,7 +132,3 @@ function hook_date_ical_feeds_object_alter(&$value, &$context) {
// ...
}
}
object for the start time.
// ...
}
}
......@@ -6,10 +6,12 @@ core = 7.x
dependencies[] = date_views
dependencies[] = entity
dependencies[] = libraries (>=7.x-2.0)
dependencies[] = feeds
dependencies[] = date
dependencies[] = date_api
; Date iCal doesn't actually depend on Feeds, but it's iCal import functionality won't work without it.
;dependencies[] = feeds
; Includes
files[] = includes/date_ical_plugin_row_ical_entity.inc
files[] = includes/date_ical_plugin_style_ical_feed.inc
......
......@@ -192,20 +192,6 @@ function date_ical_feeds_plugins() {
'path' => $path,
),
);
/*
// Disabled until when (if) it can be updated to provide the same functionality as the iCalcreator parser.
$info['DateIcalDateModuleParser'] = array(
'name' => 'Date API iCal parser',
'description' => 'Use the Date module\'s API to parse iCal feeds.',
'help' => 'Parse feeds in the iCal format using API provided by the Date module.',
'handler' => array(
'parent' => 'DateIcalFeedsParser',
'class' => 'DateIcalDateModuleParser',
'file' => 'DateIcalDateModuleParser.inc',
'path' => $path,
),
);
*/
return $info;
}
......@@ -303,6 +289,7 @@ function date_ical_build_repeating_dates($rrule = NULL, $rrule_values = NULL, $f
if (!empty($rrule_values['UNTIL']['datetime'])) {
$end = date_ical_date($rrule_values['UNTIL'], $timezone);
// TODO: BUG HERE. Read import.pdf, probably something to do with RRULEs and DTENDs together.
$end_datetime = date_format($end, DATE_FORMAT_DATETIME);
}
elseif (!empty($rrule_values['COUNT'])) {
......
<?php
/**
* @file
* Classes implementing Date iCal's date_api-based parser functionality.
*/
class DateIcalDateModuleParser extends DateIcalFeedsParser {
/**
* Output sources this parser offers.
*
* Includes additional field for the handler for output.
*
* @see DateIcalFeedsParser::getMappingSources().
* @see DateIcalFeedsParser::getSourceElement().
*/
static protected $sources = array(
'summary' => array(
'name' => 'Summary',
'description' => 'A short summary or subject for the calendar component.',
'date_ical_parse_handler' => 'formatText',
),
'description' => array(
'name' => 'Description',
'description' => 'A more complete description calendar component than that provided by the "summary" property.',
'date_ical_parse_handler' => 'formatText',
),
'dtstart' => array(
'name' => 'Date for feed item',
'description' => 'Start time for the feed item.',
'date_ical_parse_handler' => 'formatDateTime',
),
// TODO: Why is this commented out?
/* 'dtend' => array(
'name' => 'Date end',
'description' => 'End time for the feed item.',
'date_ical_parse_handler' => 'formatDateTime',
), */
'uid' => array(
'name' => 'UID',
'description' => 'UID of feed item',
'date_ical_parse_handler' => 'formatText',
),
'url' => array(
'name' => 'URL',
'description' => 'URL for the feed item.',
'date_ical_parse_handler' => 'formatText',
),
'location' => array(
'name' => 'Location text',
'description' => 'Text of location property of feed item.',
'date_ical_parse_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 DateIcalParserResult();
$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 DateIcalDateModuleComponent('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, DateIcalComponentInterface $item, FeedsParserResult $result, FeedsSource $source) {
return $property;
}
/**
* Format datetime fields.
*/
public function formatDateTime($property_key, $property, DateIcalComponentInterface $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 the Date API.
*/
static public function loadLibrary() {
include_once(drupal_get_path('module', 'date_api') . '/date_api_ical.inc');
}
}
/**
* A wrapper on iCalcreator component class.
*/
class DateIcalDateModuleComponent implements DateIcalComponentInterface {
protected $component;
protected $type;
public function __construct($type, $component) {
$this->type = strtoupper($type);
$this->component = $component;
}
public function getComponentType() {
return $this->type;
}
public function getProperty($name) {
$name = strtoupper($name);
return (isset($this->component[$name]) ? $this->component[$name] : NULL);
}
// This implementation of DateIcalComponentInterface->setProperty() accepts only a
// singluar parameter, rather than an array of them.
public function setProperty($name, $value) {
$name = strtoupper($name);
$this->component[$name] = $value;
}
}
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment