Skip to content

Instantly share code, notes, and snippets.

@vtedesco
Forked from jakebellacera/ICS.php
Created May 29, 2013 15:24
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 2 You must be signed in to fork a gist
  • Save vtedesco/5671155 to your computer and use it in GitHub Desktop.
Save vtedesco/5671155 to your computer and use it in GitHub Desktop.
<?php
// Fetch vars
$event = array(
'id' => $_GET['id'],
'title' => $_GET['title'],
'address' => $_GET['address'],
'description' => $_GET['description'],
'datestart' => $_GET['datestart'],
'dateend' => $_GET['dateend'],
'address' => $_GET['stage']
);
// iCal date format: yyyymmddThhiissZ
// PHP equiv format: Ymd\This
// The Function
function dateToCal($time) {
return date('Ymd\This', $time) . 'Z';
}
// Build the ics file
$ical = 'BEGIN:VCALENDAR
VERSION:2.0
PRODID:-//hacksw/handcal//NONSGML v1.0//EN
CALSCALE:GREGORIAN
BEGIN:VEVENT
DTEND:' . dateToCal($event['dateend']) . '
UID:' . md5($event['title']) . '
DTSTAMP:' . time() . '
LOCATION:' . addslashes($event['address']) . '
DESCRIPTION:' . addslashes($event['description']) . '
URL;VALUE=URI:http://mohawkaustin.com/events/' . $event['id'] . '
SUMMARY:' . addslashes($event['title']) . '
DTSTART:' . dateToCal($event['datestart']) . '
END:VEVENT
END:VCALENDAR';
//set correct content-type-header
if($event['id']){
header('Content-type: text/calendar; charset=utf-8');
header('Content-Disposition: attachment; filename=mohawk-event.ics');
echo $ical;
} else {
// If $id isn't set, then kick the user back to home. Do not pass go, and do not collect $200.
header('Location: /');
}
?>
@gert186
Copy link

gert186 commented Aug 6, 2013

what is the $id ?

@vtedesco
Copy link
Author

copy/pasta error, $id mean $event['id']

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment