function date_ical_export in Date 5
Same name in this branch
- 5 date_api_ical.inc \date_ical_export()
- 5 date_ical.inc \date_ical_export()
Same name and namespace in other branches
- 5.2 date_api_ical.inc \date_ical_export()
- 6 date_api_ical.inc \date_ical_export()
Turn an array of events into a valid iCalendar file
Parameters
$events: An array of associative arrays where 'start' => Unix timestamp (GMT) of start time (Required, if no allday_start) 'end' => Unix timestamp (GMT) of end time (Optional) 'allday_start' => Start date of all-day event in YYYYMMDD format (Required, if no start) 'allday_end' => End date of all-day event in YYYYMMDD format (Optional) 'summary' => Title of event (Text) 'description' => Description of event (Text) 'location' => Location of event (Text) 'uid' => ID of the event for use by calendaring program. Recommend the url of the node 'url' => URL of event information
$calname: Name of the calendar. Will use site name if none is specified.
Return value
Text of a date_icalendar file
File
- ./
date_ical.inc, line 24
Code
function date_ical_export($events, $calname = NULL) {
$output .= "BEGIN:VCALENDAR\nVERSION:2.0\n";
$output .= "METHOD:PUBLISH\n";
$output .= 'X-WR-CALNAME:' . date_ical_escape_text($calname ? $calname : variable_get('site_name', '')) . "\n";
$output .= "PRODID:-//strange bird labs//Drupal iCal API//EN\n";
foreach ($events as $uid => $event) {
$output .= "BEGIN:VEVENT\n";
$output .= "DTSTAMP;VALUE=DATE-TIME:" . gmdate("Ymd\\THis\\Z", time()) . "\n";
if ($event['allday_start'] && $event['allday_end']) {
$output .= "DTSTART;VALUE=DATE-TIME:" . $event['allday_start'] . "\n";
$output .= "DTEND;VALUE=DATE-TIME:" . $event['allday_end'] . "\n";
}
else {
if ($event['allday_start'] && empty($event['allday_end'])) {
$output .= "DTSTART;VALUE=DATE-TIME:" . $event['allday_start'] . "\n";
$output .= "DTEND;VALUE=DATE-TIME:" . date('Ymd', strtotime($event['allday_start']) + 86400) . "\n";
//If no allday end date, set to day after allday start
}
else {
if ($event['start'] && $event['end']) {
$output .= "DTSTART;VALUE=DATE-TIME:" . gmdate("Ymd\\THis\\Z", $event['start']) . "\n";
$output .= "DTEND;VALUE=DATE-TIME:" . gmdate("Ymd\\THis\\Z", $event['end']) . "\n";
}
else {
if ($event['start']) {
$output .= "DTSTART;VALUE=DATE-TIME:" . gmdate("Ymd\\THis\\Z", $event['start']) . "\n";
}
}
}
}
$output .= "UID:" . ($event['uid'] ? $event['uid'] : $uid) . "\n";
if ($event['url']) {
$output .= "URL;VALUE=URI:" . $event['url'] . "\n";
}
if ($event['location']) {
$output .= "LOCATION:" . date_ical_escape_text($event['location']) . "\n";
}
$output .= "SUMMARY:" . date_ical_escape_text($event['summary']) . "\n";
if ($event['description']) {
$output .= "DESCRIPTION:" . date_ical_escape_text($event['description']) . "\n";
}
$output .= "END:VEVENT\n";
}
$output .= "END:VCALENDAR\n";
return $output;
}