123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148 |
- <?php
- class EasyPeasyICS
- {
-
- protected $calendarName;
-
- protected $events = array();
-
- public function __construct($calendarName = "")
- {
- $this->calendarName = $calendarName;
- }
-
- public function addEvent($start, $end, $summary = '', $description = '', $url = '', $uid = '')
- {
- if (empty($uid)) {
- $uid = md5(uniqid(mt_rand(), true)) . '@EasyPeasyICS';
- }
- $event = array(
- 'start' => gmdate('Ymd', $start) . 'T' . gmdate('His', $start) . 'Z',
- 'end' => gmdate('Ymd', $end) . 'T' . gmdate('His', $end) . 'Z',
- 'summary' => $summary,
- 'description' => $description,
- 'url' => $url,
- 'uid' => $uid
- );
- $this->events[] = $event;
- return $event;
- }
-
- public function getEvents()
- {
- return $this->events;
- }
-
- public function clearEvents()
- {
- $this->events = array();
- }
-
- public function getName()
- {
- return $this->calendarName;
- }
-
- public function setName($name)
- {
- $this->calendarName = $name;
- }
-
- public function render($output = true)
- {
-
- $ics = 'BEGIN:VCALENDAR
- METHOD:PUBLISH
- VERSION:2.0
- X-WR-CALNAME:' . $this->calendarName . '
- PRODID:-//hacksw/handcal//NONSGML v1.0//EN';
-
- foreach ($this->events as $event) {
- $ics .= '
- BEGIN:VEVENT
- UID:' . $event['uid'] . '
- DTSTAMP:' . gmdate('Ymd') . 'T' . gmdate('His') . 'Z
- DTSTART:' . $event['start'] . '
- DTEND:' . $event['end'] . '
- SUMMARY:' . str_replace("\n", "\\n", $event['summary']) . '
- DESCRIPTION:' . str_replace("\n", "\\n", $event['description']) . '
- URL;VALUE=URI:' . $event['url'] . '
- END:VEVENT';
- }
-
- $ics .= '
- END:VCALENDAR';
- if ($output) {
-
- $filename = $this->calendarName;
-
- if (strpos($filename, ' ') !== false) {
- $filename = '"'.$filename.'"';
- }
- header('Content-type: text/calendar; charset=utf-8');
- header('Content-Disposition: inline; filename=' . $filename . '.ics');
- echo $ics;
- }
- return $ics;
- }
- }
|