Commit 13d238d3 authored by Robert Rollins's avatar Robert Rollins

Issue #2203085: Added support for importing GEO fields from iCal feeds.

parent 668fe934
......@@ -28,6 +28,7 @@ class ParserVcalendar {
public function __construct($calendar, $source, $fetcher_result, $config) {
$this->calendar = $calendar;
$this->source = $source;
$this->mapping_sources = feeds_importer($source->id)->parser->getMappingSources();
$this->fetcherResult = $fetcher_result;
$this->config = $config;
}
......@@ -42,8 +43,7 @@ class ParserVcalendar {
* Specifies how many components to parse on this run.
*
* @return array
* An array of parsed event data keyed by the same strings as the array
* returned by DateiCalFeedsParser::getiCalMappingSources().
* An array of parsed event data keyed by our mapping source property keys.
*/
public function parse($offset, $limit) {
// Sometimes, the feed will set a timezone for every event in the calendar
......@@ -95,14 +95,49 @@ class ParserVcalendar {
// Parse each raw component in the current batch into a Feeds-compatible
// event data array.
$events = array();
$sources = DateiCalFeedsParser::getiCalMappingSources();
$batch = array_slice($raw_components, $offset, $limit, TRUE);
foreach ($batch as $ndx => $raw_component) {
$parsed_component = array();
foreach ($sources as $property_key => $data) {
foreach ($this->mapping_sources as $property_key => $data) {
$handler = NULL;
if (isset($data['date_ical_parse_handler'])) {
$handler = $data['date_ical_parse_handler'];
}
else {
// This is not one of our sources, so if we don't recognize and
// support it, we'll have to pass a warning to the user.
if ($property_key == 'geofield') {
$handler = 'parseGeofield';
}
else {
// We can safely ignore certain sources.
$known_unknowns = array(
// "Black Source 1" is from Feeds Tamper.
'Blank source 1',
);
if (!in_array($property_key, $known_unknowns)) {
// Only warn the user if this mapping source is in use.
foreach ($this->source->importer->processor->config['mappings'] as $mapping) {
if ($mapping['source'] == $property_key) {
drupal_set_message(t('Date iCal does not recognize the "@name" Mapping Source, and must skip it.', array('@name' => $data['name'])), 'warning', FALSE);
break;
}
}
}
}
}
if ($handler) {
$parsed_component[$property_key] = $this->$handler($property_key, $raw_component);
}
if ($property_key == 'geofield' && !empty($parsed_component['geofield'])) {
// To make our data readable by geofield_feeds_combined_source(), we
// need to put it into the format output by Simplepie 1.3.
$parsed_component['location_latitude'] = array($parsed_component['geofield']['lat']);
$parsed_component['location_longitude'] = array($parsed_component['geofield']['lon']);
}
}
// Allow modules to alter the final parsed data before we send it to the
// Feeds processor.
drupal_alter('date_ical_import_post_parse', $parsed_component, $context2);
......@@ -152,6 +187,21 @@ class ParserVcalendar {
return $text;
}
/**
* Parses GEO fields.
*
* @return array
* The latitude and longitude values, keyed by 'lat' and 'lon'.
*/
public function parseGeofield($property_key, $vcalendar_component) {
if (!empty($vcalendar_component->geo['value'])) {
return array(
'lat' => $vcalendar_component->geo['value']['latitude'],
'lon' => $vcalendar_component->geo['value']['longitude'],
);
}
}
/**
* Parses field parameters.
*
......
......@@ -132,4 +132,13 @@ UID:date_ical_basic_test0D
DESCRIPTION:This event uses a fake TZID and should throw the "not a valid timezone" warning at import time, and be treated as UTC.
END:VEVENT
BEGIN:VEVENT
SUMMARY:Event w/ GEO
DTSTART;TZID=America/New_York:20131009T190000
DTEND;TZID=America/New_York:20131009T210000
UID:date_ical_basic_test0E
DESCRIPTION:This is a standard event that has a GEO field.
GEO:34.1378534;-118.1252851
END:VEVENT
END:VALENDAR
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