function eme_ical_single_event($event, $title_format, $description_format) {
global $eme_timezone;
$title = eme_sanitize_ical (eme_replace_placeholders ( $title_format, $event, "text" ));
$description = eme_sanitize_ical (eme_replace_placeholders ( $description_format, $event, "text" ));
$html_description = eme_sanitize_ical (eme_replace_placeholders ( $description_format, $event, "html" ),1);
$event_link = eme_event_url($event);
$startstring=new ExpressiveDate($event['event_start_date']." ".$event['event_start_time'],$eme_timezone);
$dtstartdate=$startstring->format("Ymd");
$dtstarthour=$startstring->format("His");
//$dtstart=$dtstartdate."T".$dtstarthour."Z";
// we'll use localtime, so no "Z"
$dtstart=$dtstartdate."T".$dtstarthour;
if ($event['event_end_date'] == "")
$event['event_end_date'] = $event['event_start_date'];
if ($event['event_end_time'] == "")
$event['event_end_time'] = $event['event_start_time'];
$endstring=$event['event_end_date']." ".$event['event_end_time'];
$endstring=new ExpressiveDate($event['event_end_date']." ".$event['event_end_time'],$eme_timezone);
$dtenddate=$endstring->format("Ymd");
$dtendhour=$endstring->format("His");
//$dtend=$dtenddate."T".$dtendhour."Z";
// we'll use localtime, so no "Z"
$dtend=$dtenddate."T".$dtendhour;
$tzstring = get_option('timezone_string');
$res = "";
$res .= "BEGIN:VEVENT\r\n";
//DTSTAMP must be in UTC format, so adding "Z" as well
$res .= "DTSTAMP:" . gmdate('Ymd').'T'. gmdate('His') . "Z\r\n";
if ($event['event_properties']['all_day']) {
// ical standard for an all day event: specify only the day, meaning
// an 'all day' event is flagged as starting at the beginning of one day and lasting until the beginning of the next
// so it is the same as adding "T000000" as time spec to the start/end datestring
// But since it "ends" at the beginning of the next day, we should add 24 hours, otherwise the event ends one day too soon
$dtenddate=$endstring->addOneDay()->format('Ymd');
$res .= "DTSTART;VALUE=DATE:$dtstartdate\r\n";
$res .= "DTEND;VALUE=DATE:$dtenddate\r\n";
} else {
$res .= "DTSTART;TZID=$tzstring:$dtstart\r\n";
$res .= "DTEND;TZID=$tzstring:$dtend\r\n";
}
$res .= "UID:$dtstart-$dtend-".$event['event_id']."@".$_SERVER['SERVER_NAME']."\r\n";
$res .= "SUMMARY:$title\r\n";
$res .= "DESCRIPTION:$description\r\n";
$res .= "X-ALT-DESC;FMTTYPE=text/html:$html_description\r\n";
$res .= "URL:$event_link\r\n";
$res .= "ATTACH:$event_link\r\n";
if ($event['event_image_id']) {
$thumb_array = image_downsize( $event['event_image_id'], get_option('eme_thumbnail_size') );
$thumb_url = $thumb_array[0];
$res .= "ATTACH:$thumb_url\r\n";
}
if (isset($event['location_id']) && $event['location_id']) {
$location = eme_sanitize_ical (eme_replace_placeholders ( "#_LOCATION, #_ADDRESS, #_TOWN", $event, "text" ));
$res .= "LOCATION:$location\r\n";
}
$res .= "END:VEVENT\r\n";
return $res;
}