Created
February 13, 2013 19:27
-
-
Save tomkrush/4947361 to your computer and use it in GitHub Desktop.
Calendar event class for outputting an ics event file.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class CalendarEvent | |
{ | |
public $description; | |
public $start; | |
public $end; | |
public function data() | |
{ | |
$format = 'Ymd\THis'; | |
$lines = array(); | |
$lines[] = 'BEGIN:VCALENDAR'; | |
$lines[] = 'VERSION:2.0'; | |
$lines[] = 'PRODID://Wordpress//EN'; | |
$lines[] = 'BEGIN:VEVENT'; | |
$lines[] = 'UID:'.md5($this->start . $this->end . $this->description . time()); | |
$lines[] = 'DTSTART:'.date($format, $this->start); | |
$lines[] = 'DTEND:'.date($format, $this->end); | |
$lines[] = 'SUMMARY:'.$this->description; | |
$lines[] = 'END:VEVENT'; | |
$lines[] = 'END:VCALENDAR'; | |
return implode("\r\n", $lines); | |
} | |
public function download() | |
{ | |
$data = $this->data(); | |
header('Content-Disposition: attachment; filename="event.ics"'); | |
header("Cache-Control: no-cache, must-revalidate"); | |
header("Content-type:text/calendar"); | |
header('Content-Length: '.strlen($data)); | |
header('Connection: close'); | |
echo $data; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment