/** * Action: favorites in iCalendar format */ public function action_favorites_ical() { $this->auto_render = false; $this->history = false; $user = $this->_get_user(); // Proper headers $this->response->headers(array('Content-Type' => 'text/calendar; charset=utf-8', 'Content-Disposition' => 'inline; filename=favorites.ics')); // Create iCalendar $icalendar = new View_iCalendar(); // Load favorites $upcoming = Model_Event::factory()->find_favorites_upcoming($user, 0, 'DESC'); $past = Model_Event::factory()->find_favorites_past($user, 0); $favorites = array(); foreach ($upcoming as $event) { $favorites[] = new View_Event_vEvent($event); } foreach ($past as $event) { $favorites[] = new View_Event_vEvent($event); } $icalendar->events = $favorites; $icalendar->calname = Kohana::$config->load('site.site_name'); $this->response->body($icalendar->render()); }
/** * Create new vEvent. * * @param Model_Event $event */ public function __construct(Model_Event $event) { parent::__construct(); $this->uid = 'event-' . $event->id . '@' . $_SERVER['HTTP_HOST']; $this->summary = $event->name; $this->dtstamp = View_iCalendar::stamp($event->created); $this->dtstart = View_iCalendar::stamp($event->stamp_begin); $this->dtend = View_iCalendar::stamp($event->stamp_end); $this->url = URL::site(Route::model($event), true); $this->description = $this->url; if ($venue = $event->venue()) { $this->location = $venue->name . ', ' . ($venue->address ? $venue->address . ', ' : '') . $venue->city_name; } else { if ($event->venue_name) { $this->location = $event->venue_name . ', ' . $event->city_name; } else { $this->location = ($event->venue_hidden ? __('Underground') . ', ' : '') . $event->city_name; } } if ($event->modified) { $this->last_modified = View_iCalendar::stamp($event->modified); } }
/** * Render section. * * @return string */ public function render() { ob_start(); echo "BEGIN:VEVENT\r\n"; echo "UID:" . $this->uid . "\r\n"; echo "DTSTAMP:" . $this->dtstamp . "\r\n"; echo "DTSTART:" . $this->dtstart . "\r\n"; echo "DTEND:" . $this->dtend . "\r\n"; if ($this->last_modified) { echo "LAST-MODIFIED:" . $this->last_modified . "\r\n"; } echo "SUMMARY:" . View_iCalendar::escape($this->summary) . "\r\n"; if ($this->description) { echo "DESCRIPTION:" . View_iCalendar::escape($this->description) . "\r\n"; } if ($this->url) { echo "URL:" . $this->url . "\r\n"; } if ($this->location) { echo "LOCATION:" . View_iCalendar::escape($this->location) . "\r\n"; } echo "END:VEVENT\r\n"; return ob_get_clean(); }