diff --git a/calendar_ical/calendar-view-ical.tpl.php b/calendar_ical/calendar-view-ical.tpl.php index f7cf350..a8e3994 100644 --- a/calendar_ical/calendar-view-ical.tpl.php +++ b/calendar_ical/calendar-view-ical.tpl.php @@ -33,14 +33,47 @@ if (!empty($calname)): endif; print "PRODID:-//Drupal iCal API//EN\r\n"; foreach($events as $event): - print "BEGIN:VEVENT\r\n"; - print "UID:" . $event['uid'] . "\r\n"; - print "SUMMARY:" . $event['summary'] . "\r\n"; - print "DTSTAMP:" . $current_date . "Z\r\n"; - print "DTSTART:" . $event['start'] . "Z\r\n"; - if (!empty($event['end'])): - print "DTEND:" . $event['end'] . "Z\r\n"; - endif; + // TODO - This date code is really ugly. If we can break backwards compatibility this should be moved to preprocess. + $end_conditionals = $start_conditionals = ''; + // Timezone should not have anything at the end but date puts something there... + $event['timezone'] = rtrim($event['timezone'], ';'); + // If the timezone is not UTC, endcode the timezone into the conditional fields. + if ($event['timezone'] != 'TZID=UTC') { + $start_conditionals .= ';' . $event['timezone']; + $end_conditionals .= ';' . $event['timezone']; + } + else { + // This timezone is UTC. + // If there is a T inside the string this is a DATE-TIME. + if (strpos($event['start'], 'T')) { + // Adjust the string to specify UTC times. + $event['start'] .= 'Z'; + } + else { + // Otherwise, this is a DATE value so specify that in the conditionals. + $start_conditionals .= ';VALUE=DATE'; + } + if ($event['end']) { + // If there is a T inside the string this is a DATE-TIME. + if (strpos($event['end'], 'T')) { + // Adjust the string to specify UTC times. + $event['end'] .= 'Z'; + } + else { + // Otherwise, this is a DATE value so specify that in the conditionals. + $end_conditionals .= ';VALUE=DATE'; + } + } + } + + print "BEGIN:VEVENT\r\n"; + print "UID:" . $event['uid'] . "\r\n"; + print "SUMMARY:" . $event['summary'] . "\r\n"; + print "DTSTAMP:" . $current_date . "Z\r\n"; + print "DTSTART$start_conditionals:" . $event['start'] . "\r\n"; + if ($event['end']) { + print "DTEND$end_conditionals:" . $event['end'] . "\r\n"; + } if (!empty($event['rrule'])): print $event['rrule'] . "\r\n"; endif;