Commit 7afb1324 authored by Robert Rollins's avatar Robert Rollins

Added hook_date_ical_import_post_parse_alter().

This hook allows modules to alter the final data array for each event,
just before it gets sent through the rest of the Feeds processing steps to
be turned into a node. The context array is what separates this hook's
functionality from what users can do with Feeds Tamper.
parent 68c69ec1
...@@ -139,7 +139,7 @@ function hook_date_ical_export_post_render_alter(&$rendered_calendar, $view) { ...@@ -139,7 +139,7 @@ function hook_date_ical_export_post_render_alter(&$rendered_calendar, $view) {
*****************************************************************************/ *****************************************************************************/
/** /**
* Alter the vcalendar object created from an imported iCal feed. * Alter the vcalendar object imported from an iCal feed.
* *
* @param object $calendar * @param object $calendar
* An instance of the iCalcreator library's vcalendar class. * An instance of the iCalcreator library's vcalendar class.
...@@ -153,7 +153,7 @@ function hook_date_ical_import_vcalendar_alter(&$calendar, $context) { ...@@ -153,7 +153,7 @@ function hook_date_ical_import_vcalendar_alter(&$calendar, $context) {
} }
/** /**
* Alter a calendar component created from an imported iCal feed. * Alter a calendar component imported from an iCal feed.
* *
* @param object $component * @param object $component
* This will usually be an iCalcreator vevent object, but Date iCal also * This will usually be an iCalcreator vevent object, but Date iCal also
...@@ -174,6 +174,24 @@ function hook_date_ical_import_component_alter(&$component, $context) { ...@@ -174,6 +174,24 @@ function hook_date_ical_import_component_alter(&$component, $context) {
} }
} }
/**
* Alter the parsed data for an event imported from an iCal feed.
*
* @param array $data
* An associative array of field data that represents an imported event.
* @param array $context
* An associative array of context, with the following keys and values:
* - 'calendar': The iCalcreator vcalendar parent object of this component.
* - 'source': FeedsSource object for this Feed.
* - 'fetcher_result': The FeedsFetcherResult object for this Feed.
*/
function hook_date_ical_import_post_parse_alter(&$data, $context) {
// Example of what might be done with this alter hook.
if (!empty($context['calendar']->xprop['X-WR-CALNAME']['value'])) {
// Do something with the calendar name....
}
}
/** /**
* Alter the timezone string from an imported iCal Feed. * Alter the timezone string from an imported iCal Feed.
* *
......
...@@ -410,7 +410,9 @@ class date_ical_plugin_style_ical_feed extends views_plugin_style { ...@@ -410,7 +410,9 @@ class date_ical_plugin_style_ical_feed extends views_plugin_style {
// Prevent devel module from appending queries to ical export. // Prevent devel module from appending queries to ical export.
$GLOBALS['devel_shutdown'] = FALSE; $GLOBALS['devel_shutdown'] = FALSE;
drupal_add_http_header('Content-Type', 'text/calendar; charset=utf-8'); drupal_add_http_header('Content-Type', 'text/calendar; charset=UTF-8');
drupal_add_http_header('Cache-Control', 'no-cache, must-revalidate');
drupal_add_http_header('Expires', 'Sat, 26 Jul 1997 05:00:00 GMT');
// For sites with Clean URLs disabled, the Display's "path" value ends // For sites with Clean URLs disabled, the Display's "path" value ends
// up only in the query args, meaning the filename won't be set properly // up only in the query args, meaning the filename won't be set properly
......
...@@ -69,6 +69,14 @@ class ParserVcalendar { ...@@ -69,6 +69,14 @@ class ParserVcalendar {
$this->timezones[] = $component; $this->timezones[] = $component;
} }
// This content array is used by date_ical_import_component_alter() and
// date_ical_import_parsed_data_alter().
$context2 = array(
'calendar' => $this->calendar,
'source' => $this->source,
'fetcher_result' => $this->fetcherResult,
);
// Collect each component, so we can batch them properly in the next loop. // Collect each component, so we can batch them properly in the next loop.
$raw_components = array(); $raw_components = array();
$types = array('VEVENT', 'VTODO', 'VJOURNAL', 'VFREEBUSY', 'VALARM'); $types = array('VEVENT', 'VTODO', 'VJOURNAL', 'VFREEBUSY', 'VALARM');
...@@ -76,12 +84,7 @@ class ParserVcalendar { ...@@ -76,12 +84,7 @@ class ParserVcalendar {
while ($vcalendar_component = $this->calendar->getComponent($type)) { while ($vcalendar_component = $this->calendar->getComponent($type)) {
// Allow modules to alter the vcalendar component before we parse it // Allow modules to alter the vcalendar component before we parse it
// into a Feeds-compatible data array. // into a Feeds-compatible data array.
$context = array( drupal_alter('date_ical_import_component', $vcalendar_component, $context2);
'calendar' => $this->calendar,
'source' => $this->source,
'fetcher_result' => $this->fetcherResult,
);
drupal_alter('date_ical_import_component', $vcalendar_component, $context);
$raw_components[] = $vcalendar_component; $raw_components[] = $vcalendar_component;
} }
} }
...@@ -100,6 +103,10 @@ class ParserVcalendar { ...@@ -100,6 +103,10 @@ class ParserVcalendar {
$handler = $data['date_ical_parse_handler']; $handler = $data['date_ical_parse_handler'];
$parsed_component[$property_key] = $this->$handler($property_key, $raw_component); $parsed_component[$property_key] = $this->$handler($property_key, $raw_component);
} }
// 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);
$events[] = $parsed_component; $events[] = $parsed_component;
// The indices of the original $raw_components array are preserved in // The indices of the original $raw_components array are preserved in
// $batch, so using the $ndx value here lets us communicate our progress // $batch, so using the $ndx value here lets us communicate our progress
......
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