Commit 690df398 authored by Robert Rollins's avatar Robert Rollins

Renamed hook_date_ical_import_calendar_alter to...

Renamed hook_date_ical_import_calendar_alter to hook_date_ical_import_vcalendar_alter, to match the export hook.

Also did some minor refactoring and comment editing.

Date iCal 3.0 is nearing completion! The only major task remaining
is to write the migration code.
parent 73d42500
...@@ -49,8 +49,7 @@ function hook_date_ical_export_html_alter(&$text_fields, $view, $context) { ...@@ -49,8 +49,7 @@ function hook_date_ical_export_html_alter(&$text_fields, $view, $context) {
* Modify an event's raw data. * Modify an event's raw data.
* *
* This hook is invoked after Date iCal has gathered all the data it will use * This hook is invoked after Date iCal has gathered all the data it will use
* to build an event object. Use this hook to set values of iCal fields which * to build an event object.
* Date iCal doesn't directly support.
* *
* @param array $event * @param array $event
* A reference to an associative array containing the event's raw data. * A reference to an associative array containing the event's raw data.
...@@ -91,8 +90,8 @@ function hook_date_ical_export_raw_event_alter(&$event, $view, $context) { ...@@ -91,8 +90,8 @@ function hook_date_ical_export_raw_event_alter(&$event, $view, $context) {
* Alter an iCal representation of an event. * Alter an iCal representation of an event.
* *
* This hook allows you to modify an event as it is added to the iCal calendar. * This hook allows you to modify an event as it is added to the iCal calendar.
* If Date iCal doesn't support an iCal property that you need to use, then you * If Date iCal doesn't support an iCal property that you want your feed to
* can add it to the event here. * include, you can add it to the event using this hook.
* *
* @param object $vevent * @param object $vevent
* A reference to an iCalcreator vevent which will be exported in this feed. * A reference to an iCalcreator vevent which will be exported in this feed.
...@@ -149,7 +148,7 @@ function hook_date_ical_export_post_render_alter(&$rendered_calendar, $view) { ...@@ -149,7 +148,7 @@ function hook_date_ical_export_post_render_alter(&$rendered_calendar, $view) {
* - 'source' FeedsSource object for this Feed. * - 'source' FeedsSource object for this Feed.
* - 'fetcher_result': The FeedsFetcherResult object for this Feed. * - 'fetcher_result': The FeedsFetcherResult object for this Feed.
*/ */
function hook_date_ical_import_calendar_alter(&$calendar, $context) { function hook_date_ical_import_vcalendar_alter(&$calendar, $context) {
} }
......
...@@ -39,7 +39,7 @@ class DateiCalFeedsParser extends FeedsParser { ...@@ -39,7 +39,7 @@ class DateiCalFeedsParser extends FeedsParser {
'source' => $source, 'source' => $source,
'fetcher_result' => $fetcher_result, 'fetcher_result' => $fetcher_result,
); );
drupal_alter('date_ical_import_calendar', $calendar, $context); drupal_alter('date_ical_import_vcalendar', $calendar, $context);
// We've got a vcalendar object created from the feed data. Now we need to // We've got a vcalendar object created from the feed data. Now we need to
// convert that vcalendar into an array of Feeds-compatible data arrays. // convert that vcalendar into an array of Feeds-compatible data arrays.
...@@ -47,7 +47,7 @@ class DateiCalFeedsParser extends FeedsParser { ...@@ -47,7 +47,7 @@ class DateiCalFeedsParser extends FeedsParser {
require_once(DRUPAL_ROOT . '/' . drupal_get_path('module', 'date_ical') . '/libraries/ParserVcalendar.inc'); require_once(DRUPAL_ROOT . '/' . drupal_get_path('module', 'date_ical') . '/libraries/ParserVcalendar.inc');
$parser = new ParserVcalendar($calendar, $source, $fetcher_result, $source->getConfigFor($this)); $parser = new ParserVcalendar($calendar, $source, $fetcher_result, $source->getConfigFor($this));
// Using either the stored progress pointer (or 0 if it's not set), // Using the stored progress pointer (or 0 if it's not set),
// determine which section of the feed to parse, then parse it. // determine which section of the feed to parse, then parse it.
$offset = isset($state->pointer) ? $state->pointer : 0; $offset = isset($state->pointer) ? $state->pointer : 0;
$limit = $source->importer->getLimit(); $limit = $source->importer->getLimit();
...@@ -56,7 +56,7 @@ class DateiCalFeedsParser extends FeedsParser { ...@@ -56,7 +56,7 @@ class DateiCalFeedsParser extends FeedsParser {
// Report progress. // Report progress.
$state->total = $parser->getTotalComponents(); $state->total = $parser->getTotalComponents();
// We need to add 1 to the index of the last parsed componenent so that // We need to add 1 to the index of the last parsed componenent so that
// the subsequent batch starts on the *next* component. // the subsequent batch starts on the first unparsed component.
$state->pointer = $parser->getLastComponentParsed() + 1; $state->pointer = $parser->getLastComponentParsed() + 1;
$state->progress($state->total, $state->pointer); $state->progress($state->total, $state->pointer);
......
...@@ -333,7 +333,7 @@ class date_ical_plugin_row_ical_entity extends views_plugin_row { ...@@ -333,7 +333,7 @@ class date_ical_plugin_row_ical_entity extends views_plugin_row {
// According to the iCal standard, CREATED and LAST-MODIFIED must be UTC. // According to the iCal standard, CREATED and LAST-MODIFIED must be UTC.
// Fortunately, Drupal stores timestamps in the DB as UTC, so we just need // Fortunately, Drupal stores timestamps in the DB as UTC, so we just need
// to tell Date to treat the timestamp as UTC from the start. // to tell DateObject to treat the timestamp as UTC from the start.
if (isset($entity->created)) { if (isset($entity->created)) {
$event['created'] = new DateObject($entity->created, 'UTC'); $event['created'] = new DateObject($entity->created, 'UTC');
} }
......
...@@ -138,23 +138,20 @@ class date_ical_plugin_style_ical_feed extends views_plugin_style { ...@@ -138,23 +138,20 @@ class date_ical_plugin_style_ical_feed extends views_plugin_style {
$vcalendar = new vcalendar($config); $vcalendar = new vcalendar($config);
$vcalendar->setMethod('PUBLISH'); $vcalendar->setMethod('PUBLISH');
// If the iCal Calendar Name has been set in the Feed Style options, it's used as the // Only include the X-WR-CALNAME property if the user didn't enable
// title in the iCal feed. If not, the View Title is used. If that is also blank, then // the "Exclude Calendar Name" option.
// the Site Name is used. if (!$this->_get_option('no_calname')) {
$cal_name = $this->_get_option('cal_name'); $cal_name = $this->_get_option('cal_name');
if (empty($cal_name)) { if (empty($cal_name)) {
$view_title = $this->view->get_title(); $cal_name = $this->view->get_title();
if (!empty($view_title)) { if (empty($cal_name)) {
$cal_name = $view_title; $cal_name = variable_get('site_name', 'Drupal');
}
} }
else { if (!empty($cal_name)) {
$cal_name = variable_get('site_name', 'Drupal'); $vcalendar->setProperty('X-WR-CALNAME', $cal_name, array('VALUE' => 'TEXT'));
} }
} }
// Only include the X-WR-CALNAME property if the user didn't check "Exclude Calendar Name".
if (!$this->_get_option('no_calname')) {
$vcalendar->setProperty('x-wr-calname', $cal_name, array('VALUE' => 'TEXT'));
}
// Now add the VEVENTs. // Now add the VEVENTs.
$timezones = array(); $timezones = array();
...@@ -167,6 +164,9 @@ class date_ical_plugin_style_ical_feed extends views_plugin_style { ...@@ -167,6 +164,9 @@ class date_ical_plugin_style_ical_feed extends views_plugin_style {
} }
$vevent = $vcalendar->newComponent('vevent'); $vevent = $vcalendar->newComponent('vevent');
$vevent->setUid($event['uid']);
$vevent->setSummary($event['summary']);
// Get the start date as an array. // Get the start date as an array.
$start = $event['start']->toArray(); $start = $event['start']->toArray();
$start_timezone = $event['start']->getTimezone()->getName(); $start_timezone = $event['start']->getTimezone()->getName();
...@@ -215,8 +215,6 @@ class date_ical_plugin_style_ical_feed extends views_plugin_style { ...@@ -215,8 +215,6 @@ class date_ical_plugin_style_ical_feed extends views_plugin_style {
} }
$end['tz'] = $event['end']->getTimezone(); $end['tz'] = $event['end']->getTimezone();
} }
$vevent->setProperty('uid', $event['uid']);
$vevent->setProperty('summary', $event['summary']);
// Handle repeating dates from the date_repeat module. // Handle repeating dates from the date_repeat module.
if (!empty($event['rrule']) && module_exists('date_repeat')) { if (!empty($event['rrule']) && module_exists('date_repeat')) {
...@@ -311,10 +309,10 @@ class date_ical_plugin_style_ical_feed extends views_plugin_style { ...@@ -311,10 +309,10 @@ class date_ical_plugin_style_ical_feed extends views_plugin_style {
$vevent->setUrl($event['url'], array('type' => 'URI')); $vevent->setUrl($event['url'], array('type' => 'URI'));
} }
if (!empty($event['location'])) { if (!empty($event['location'])) {
$vevent->setProperty('location', $event['location']); $vevent->setLocation($event['location']);
} }
if (!empty($event['description'])) { if (!empty($event['description'])) {
$vevent->setProperty('description', $event['description']); $vevent->setDescription($event['description']);
} }
if (!empty($event['last-modified'])) { if (!empty($event['last-modified'])) {
$lm = $event['last-modified']->toArray(); $lm = $event['last-modified']->toArray();
...@@ -356,10 +354,10 @@ class date_ical_plugin_style_ical_feed extends views_plugin_style { ...@@ -356,10 +354,10 @@ class date_ical_plugin_style_ical_feed extends views_plugin_style {
drupal_alter('date_ical_export_vcalendar', $vcalendar, $this->view); drupal_alter('date_ical_export_vcalendar', $vcalendar, $this->view);
$output = $vcalendar->createCalendar(); $output = $vcalendar->createCalendar();
// iCalcreator escapes all commas and semicolons in the strings that it, // iCalcreator escapes all commas and semicolons in string values, as the
// as the spec demands. However, some calendar clients are buggy and // spec demands. However, some calendar clients are buggy and fail to
// don't unescape these characters. Users may choose to unescape them // unescape these characters. Users may choose to unescape them here to
// here to sidestep those clients' bugs. // sidestep those clients' bugs.
// NOTE: This results in a non-compliant iCal feed, but it seems like a // NOTE: This results in a non-compliant iCal feed, but it seems like a
// LOT of major clients are bugged this way. // LOT of major clients are bugged this way.
if ($this->_get_option('unescape_punctuation')) { if ($this->_get_option('unescape_punctuation')) {
...@@ -396,7 +394,7 @@ class date_ical_plugin_style_ical_feed extends views_plugin_style { ...@@ -396,7 +394,7 @@ class date_ical_plugin_style_ical_feed extends views_plugin_style {
// need to manually instruct browsers to download a .ics file. // need to manually instruct browsers to download a .ics file.
if (!variable_get('clean_url', FALSE)) { if (!variable_get('clean_url', FALSE)) {
$path_array = explode('/', $this->display->display_options['path']); $path_array = explode('/', $this->display->display_options['path']);
$filename = array_pop($path_array); $filename = end($path_array);
drupal_add_http_header('Content-Disposition', "attachment; filename=\"$filename\""); drupal_add_http_header('Content-Disposition', "attachment; filename=\"$filename\"");
} }
} }
...@@ -430,8 +428,7 @@ class date_ical_plugin_style_ical_feed extends views_plugin_style { ...@@ -430,8 +428,7 @@ class date_ical_plugin_style_ical_feed extends views_plugin_style {
if (strtoupper($key) == 'BYDAY') { if (strtoupper($key) == 'BYDAY') {
$new_byday = array(); $new_byday = array();
foreach ($value as $day) { foreach ($value as $day) {
// Fortunately, the weekday values are always 2 characters, so it's easy to // Fortunately, the weekday values are always 2 characters.
// split off the ordwk part, even though it could be 1 or 2 characters.
$weekday = substr($day, -2); $weekday = substr($day, -2);
$ordwk = substr($day, 0, -2); $ordwk = substr($day, 0, -2);
$new_byday[] = array($ordwk, 'DAY' => $weekday); $new_byday[] = array($ordwk, 'DAY' => $weekday);
......
...@@ -34,15 +34,13 @@ class ParserVcalendar { ...@@ -34,15 +34,13 @@ class ParserVcalendar {
* Parses the vcalendar object into an array of event data arrays. * Parses the vcalendar object into an array of event data arrays.
* *
* @param int $offset * @param int $offset
* This parameter, along with $limit, specfy which section of the feed * Specifies which section of the feed to start parsing at.
* to parse. Useful for batch operation.
* *
* @param int $limit * @param int $limit
* This parameter, along with $offset, specfy which section of the feed * Specifies how many components to parse on this run.
* to parse. Useful for batch operation.
* *
* @return array * @return array
* An array of parsed event data keyed by the same property keys as * An array of parsed event data keyed by the same strings as the array
* returned by DateiCalFeedsParser::getiCalMappingSources(). * returned by DateiCalFeedsParser::getiCalMappingSources().
*/ */
public function parse($offset, $limit) { public function parse($offset, $limit) {
...@@ -103,7 +101,7 @@ class ParserVcalendar { ...@@ -103,7 +101,7 @@ class ParserVcalendar {
$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
// through the full collection of commpenents. // through the full collection of components.
$this->lastComponentParsed = $ndx; $this->lastComponentParsed = $ndx;
} }
...@@ -166,7 +164,7 @@ class ParserVcalendar { ...@@ -166,7 +164,7 @@ class ParserVcalendar {
$dtend = $vcalendar_component->getProperty('DTEND', FALSE, TRUE); $dtend = $vcalendar_component->getProperty('DTEND', FALSE, TRUE);
$uid = $vcalendar_component->getProperty('UID'); $uid = $vcalendar_component->getProperty('UID');
// DATE-type values are treated as All Day events which can span over // DATE-type properties are treated as All Day events which can span over
// multiple days. // multiple days.
// The Date module's All Day event handling was never finalized // The Date module's All Day event handling was never finalized
// (http://drupal.org/node/874322), which requires us to do some some // (http://drupal.org/node/874322), which requires us to do some some
......
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