Example #1
0
 /**
  * Export Event in iCal Format
  *
  * @return [type] [description]
  */
 public function export()
 {
     // get event timezone setting
     // use this in "DTSTART;TZID="
     $tzInfo = \plgGroupsCalendarHelper::getTimezoneNameAndAbbreviation($this->get('time_zone'));
     $tzName = timezone_name_from_abbr($tzInfo['abbreviation']);
     // get publish up/down dates in UTC
     $publishUp = new DateTime($this->get('publish_up'), new DateTimezone('UTC'));
     $publishDown = new DateTime($this->get('publish_down'), new DateTimezone('UTC'));
     // Set eastern timezone as publish up/down date timezones
     // since all event date/times are stores relative to eastern
     // ----------------------------------------------------------------------------------
     // The timezone param "DTSTART;TZID=" defined above will allow a users calendar app to
     // adjust date/time display according to that timezone and their systems timezone setting
     $publishUp->setTimezone(new DateTimezone(timezone_name_from_abbr('EST')));
     $publishDown->setTimezone(new DateTimezone(timezone_name_from_abbr('EST')));
     //event vars
     $id = $this->get('id');
     $title = $this->get('title');
     $desc = str_replace("\n", '\\n', $this->get('content'));
     $url = $this->get('extra_info');
     $location = $this->get('adresse_info');
     $now = gmdate('Ymd') . 'T' . gmdate('His') . 'Z';
     $created = gmdate('Ymd', strtotime($this->get('created'))) . 'T' . gmdate('His', strtotime($this->get('created'))) . 'Z';
     $modified = gmdate('Ymd', strtotime($this->get('modified'))) . 'T' . gmdate('His', strtotime($this->get('modified'))) . 'Z';
     //create ouput
     $output = "BEGIN:VCALENDAR\r\n";
     $output .= "VERSION:2.0\r\n";
     $output .= "PRODID:PHP\r\n";
     $output .= "METHOD:PUBLISH\r\n";
     // get daylight start and end
     $ttz = new DateTimezone(timezone_name_from_abbr('EST'));
     $first = Date::of(date('Y') . '-01-02 00:00:00')->toUnix();
     $last = Date::of(date('Y') . '-12-30 00:00:00')->toUnix();
     $transitions = $ttz->getTransitions($first, $last);
     $daylightStart = Date::of($transitions[1]['ts']);
     $daylightEnd = Date::of($transitions[2]['ts']);
     // output timezone block
     $output .= "BEGIN:VTIMEZONE\r\n";
     $output .= "TZID:{$tzName}\r\n";
     $output .= "X-LIC-LOCATION:{$tzName}\r\n";
     $output .= "BEGIN:DAYLIGHT\r\n";
     $output .= "TZNAME:Daylight\r\n";
     $output .= "RRULE:FREQ=YEARLY;INTERVAL=1;BYDAY=2SU;BYMONTH=3\r\n";
     $output .= "TZOFFSETFROM:-0500\r\n";
     $output .= "TZOFFSETTO:-0400\r\n";
     $output .= "DTSTART:" . $daylightStart->format('Ymd\\THis') . "\r\n";
     $output .= "END:DAYLIGHT\r\n";
     $output .= "BEGIN:STANDARD\r\n";
     $output .= "TZNAME:Standard\r\n";
     $output .= "RRULE:FREQ=YEARLY;INTERVAL=1;BYDAY=1SU;BYMONTH=11\r\n";
     $output .= "TZOFFSETFROM:-0400\r\n";
     $output .= "TZOFFSETTO:-0500\r\n";
     $output .= "DTSTART:" . $daylightEnd->format('Ymd\\THis') . "\r\n";
     $output .= "END:STANDARD\r\n";
     $output .= "END:VTIMEZONE\r\n";
     // ouput event info
     $output .= "BEGIN:VEVENT\r\n";
     $output .= "UID:{$id}\r\n";
     $output .= "DTSTAMP:{$now}\r\n";
     $output .= "DTSTART;TZID={$tzName}:" . $publishUp->format('Ymd\\THis') . "\r\n";
     if ($this->get('publish_down') != '' && $this->get('publish_down') != '0000-00-00 00:00:00') {
         $output .= "DTEND;TZID={$tzName}:" . $publishDown->format('Ymd\\THis') . "\r\n";
     } else {
         $output .= "DTEND;TZID={$tzName}:" . $publishUp->format('Ymd\\THis') . "\r\n";
     }
     // repeating rule
     if ($this->get('repeating_rule') != '') {
         $output .= "RRULE:" . $this->get('repeating_rule') . "\r\n";
     }
     $output .= "CREATED:{$created}\r\n";
     $output .= "LAST-MODIFIED:{$modified}\r\n";
     $output .= "SUMMARY:{$title}\r\n";
     $output .= "DESCRIPTION:{$desc}\r\n";
     if ($url != '' && filter_var($url, FILTER_VALIDATE_URL)) {
         $output .= "URL;VALUE=URI:{$url}\r\n";
     }
     if ($location != '') {
         $output .= "LOCATION:{$location}\r\n";
     }
     $output .= "END:VEVENT\r\n";
     $output .= "END:VCALENDAR\r\n";
     //set the headers for output
     header('Content-type: text/calendar; charset=utf-8');
     header('Content-Disposition: attachment; filename=' . str_replace(' ', '_', strtolower($title)) . '_export.ics');
     echo $output;
     exit;
 }
Example #2
0
    echo $this->event->get('extra_info');
    ?>
					</a>
				</td>
			</tr>
		<?php 
}
?>

		<?php 
if ($this->event->get('content') != '') {
    ?>
			<tr>
				<th class="details"></th>
				<td colspan="3"><?php 
    echo plgGroupsCalendarHelper::autoLinkText(nl2br($this->event->get('content')));
    ?>
</td>
			</tr>
		<?php 
}
?>

		<tr>
			<td colspan="4"></td>
		</tr>
		<tr>
			<th class="download"></th>
			<td colspan="4">
				<a class="btn" href="<?php 
echo Route::url('index.php?option=' . $this->option . '&cn=' . $this->group->get('cn') . '&active=calendar&action=export&event_id=' . $this->event->get('id'));
Example #3
0
 /**
  * Subscribe to group calendars
  *
  * @return void
  */
 public function subscribe($name = 'Calendar Subscription', $scope = 'event', $scope_id = null)
 {
     // get request varse
     $calendarIds = Request::getVar('calendar_id', '', 'get');
     $calendarIds = array_map("intval", explode(',', $calendarIds));
     // array to hold events
     $events = new ItemList();
     // loop through and get each calendar
     foreach ($calendarIds as $k => $calendarId) {
         // load calendar model
         $eventsCalendar = new Calendar($calendarId);
         // make sure calendar is published
         if (!$eventsCalendar->get('published') && $calendarId != 0) {
             continue;
         }
         // get calendar events
         $rawEvents = $eventsCalendar->events('list', array('scope' => $scope, 'scope_id' => $scope_id, 'calendar_id' => $calendarId, 'state' => array(1)));
         // merge with full events list
         $events = $events->merge($rawEvents);
     }
     //create output
     $output = "BEGIN:VCALENDAR\r\n";
     $output .= "VERSION:2.0\r\n";
     $output .= "PRODID:PHP\r\n";
     $output .= "METHOD:PUBLISH\r\n";
     $output .= "X-WR-CALNAME;VALUE=TEXT:" . $name . "\r\n";
     $output .= "X-PUBLISHED-TTL:PT15M\r\n";
     $output .= "X-ORIGINAL-URL:https://" . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI'] . "\r\n";
     $output .= "CALSCALE:GREGORIAN\r\n";
     // get daylight start and end
     $ttz = new DateTimezone(timezone_name_from_abbr('EST'));
     $first = Date::of(date('Y') . '-01-02 00:00:00')->toUnix();
     $last = Date::of(date('Y') . '-12-30 00:00:00')->toUnix();
     $transitions = $ttz->getTransitions($first, $last);
     $daylightStart = Date::of($transitions[1]['ts']);
     $daylightEnd = Date::of($transitions[2]['ts']);
     // output timezone block
     $output .= "BEGIN:VTIMEZONE\r\n";
     $output .= "TZID:America/New_York\r\n";
     $output .= "X-LIC-LOCATION:America/New_York\r\n";
     $output .= "BEGIN:DAYLIGHT\r\n";
     $output .= "TZNAME:Daylight\r\n";
     $output .= "RRULE:FREQ=YEARLY;INTERVAL=1;BYDAY=2SU;BYMONTH=3\r\n";
     $output .= "TZOFFSETFROM:-0500\r\n";
     $output .= "TZOFFSETTO:-0400\r\n";
     $output .= "DTSTART:" . $daylightStart->format('Ymd\\THis') . "\r\n";
     $output .= "END:DAYLIGHT\r\n";
     $output .= "BEGIN:STANDARD\r\n";
     $output .= "TZNAME:Standard\r\n";
     $output .= "RRULE:FREQ=YEARLY;INTERVAL=1;BYDAY=1SU;BYMONTH=11\r\n";
     $output .= "TZOFFSETFROM:-0400\r\n";
     $output .= "TZOFFSETTO:-0500\r\n";
     $output .= "DTSTART:" . $daylightEnd->format('Ymd\\THis') . "\r\n";
     $output .= "END:STANDARD\r\n";
     $output .= "END:VTIMEZONE\r\n";
     // loop through events
     foreach ($events as $event) {
         $sequence = 0;
         $uid = $event->get('id') . '@' . $_SERVER['HTTP_HOST'];
         $title = $event->get('title');
         $content = str_replace("\r\n", '\\n', $event->get('content'));
         $location = $event->get('adresse_info');
         $url = $event->get('extra_info');
         // get event timezone setting
         // use this in "DTSTART;TZID="
         $tzInfo = \plgGroupsCalendarHelper::getTimezoneNameAndAbbreviation($event->get('time_zone'));
         $tzName = timezone_name_from_abbr($tzInfo['abbreviation']);
         // get publish up/down dates in UTC
         $publishUp = new DateTime($event->get('publish_up'), new DateTimezone('UTC'));
         $publishDown = new DateTime($event->get('publish_down'), new DateTimezone('UTC'));
         // Set eastern timezone as publish up/down date timezones
         // since all event date/times are stores relative to eastern
         // ----------------------------------------------------------------------------------
         // The timezone param "DTSTART;TZID=" defined above will allow a users calendar app to
         // adjust date/time display according to that timezone and their systems timezone setting
         $publishUp->setTimezone(new DateTimezone(timezone_name_from_abbr('EST')));
         $publishDown->setTimezone(new DateTimezone(timezone_name_from_abbr('EST')));
         // create now, created, and modified vars
         $now = gmdate('Ymd') . 'T' . gmdate('His') . 'Z';
         $created = gmdate('Ymd', strtotime($event->get('created'))) . 'T' . gmdate('His', strtotime($event->get('created'))) . 'Z';
         $modified = gmdate('Ymd', strtotime($event->get('modified'))) . 'T' . gmdate('His', strtotime($event->get('modified'))) . 'Z';
         // start output
         $output .= "BEGIN:VEVENT\r\n";
         $output .= "UID:{$uid}\r\n";
         $output .= "SEQUENCE:{$sequence}\r\n";
         $output .= "DTSTAMP:{$now}\r\n";
         $output .= "DTSTART;TZID={$tzName}:" . $publishUp->format('Ymd\\THis') . "\r\n";
         if ($event->get('publish_down') != '' && $event->get('publish_down') != '0000-00-00 00:00:00') {
             $output .= "DTEND;TZID={$tzName}:" . $publishDown->format('Ymd\\THis') . "\r\n";
         } else {
             $output .= "DTEND;TZID={$tzName}:" . $publishUp->format('Ymd\\THis') . "\r\n";
         }
         // repeating rule
         if ($event->get('repeating_rule') != '') {
             $output .= "RRULE:" . $event->get('repeating_rule') . "\r\n";
         }
         $output .= "CREATED:{$created}\r\n";
         $output .= "LAST-MODIFIED:{$modified}\r\n";
         $output .= "SUMMARY:{$title}\r\n";
         $output .= "DESCRIPTION:{$content}\r\n";
         // do we have extra info
         if ($url != '' && filter_var($url, FILTER_VALIDATE_URL)) {
             $output .= "URL;VALUE=URI:{$url}\r\n";
         }
         // do we have a location
         if ($location != '') {
             $output .= "LOCATION:{$location}\r\n";
         }
         $output .= "END:VEVENT\r\n";
     }
     // close calendar
     $output .= "END:VCALENDAR";
     // set headers and output
     header('Content-type: text/calendar; charset=utf-8');
     header('Content-Disposition: attachment; filename="' . $name . '.ics"');
     header('Last-Modified: ' . gmdate('D, d M Y H:i:s') . ' GMT');
     echo $output;
     exit;
 }