Nick Freear avatar Nick Freear committed cf3234a

Bug #207, Make the iCal events view cope with Cloud-type events..

* ie. Cloudscape->summary/description v. Cloud->body, optional end-date,
* Plus fix for Bug #206, DB schema bug - Cloud->created is a Unix timestamp, not an SQL datetime
* Plus, use the 'debug' parameter from Events controller - Bug #208.

Comments (0)

Files changed (1)

system/application/views/events/ical.php

-<?php 
-  header("Content-Type: text/Calendar; charset=".config_item("charset"));
-  header("Content-Disposition: inline; filename=calendar.ics");  
+<?php
+  $site_name = $this->config->item('site_name');
+  if ($debug) {
+    header("Content-Type: text/plain; charset=".config_item("charset"));
+  } else {
+    header("Content-Type: text/calendar; charset=".config_item("charset"));
+  }
+  @header("Content-Disposition: inline; filename=".
+    str_replace(' ','-', strtolower($site_name)) ."-$view-calendar.ics");
 ?>
 BEGIN:VCALENDAR
 VERSION:2.0
-PRODID:-//CloudEngine/<?= $this->config->item('site_name') ?>//EN
+PRODID:-//CloudEngine/<?= $site_name ?>//EN
+X-WRCALNAME:<?= ical_escape_text(t('!site-name! events')) ?>
+
 <?php foreach($events as $event): ?>
+
 BEGIN:VEVENT
-DTSTAMP:<?= date('Ymd\THi00', strtotime($event->created)) ?>
+<?php //Bug #206, Clouds use a Unix epoch, Cloudscapes use SQL datetime :(. ?>
+DTSTAMP:<?= date('Ymd\THi00',
+  /*isset($event->cloudscape_id) ?*/
+  preg_match('/^\d{4}-\d{2}/', $event->created) ? strtotime($event->created) : $event->created) ?>
 
-DTSTART:<?= date('Ymd\THi00', $event->start_date) ?>
+DTSTART:<?= date('Ymd\THi00',
+  isset($event->event_date) ? $event->event_date : $event->start_date) ?>
+<?php if (isset($event->end_date) && $event->end_date): ?>
 
 DTEND:<?= date('Ymd\THi00', $event->end_date) ?>
+<?php endif; ?>
 
 SUMMARY:<?= ical_escape_text($event->title) ?>
 
-<?php if ($event->summary) {?>
-DESCRIPTION:<?= ical_escape_text($event->summary) ?>
+<?php if (isset($event->cloudscape_id)): ?>
+DESCRIPTION:<?php if ($event->summary): ?><?=
+  ical_escape_text($event->summary) ?>\n\n<?php endif; ?><?=ical_escape_text(t('View on !site-name!')) ?>: <?=
+  site_url('cloudscape/view/'. $event->cloudscape_id) ?>
+<?php else: ?>
+DESCRIPTION:<?=ical_escape_text($event->body) ?>\n\n<?=
+  ical_escape_text(t('View on !site-name!')) ?>: <?= site_url('cloud/view/'. $event->cloud_id) ?>
+<?php endif; ?>
+<?php if ($event->location): ?> 
+LOCATION: <?= ical_escape_text($event->location) ?>
+<?php endif; ?>
 
-<?php } ?>
-<?php if ($event->location) {?> 
-LOCATION: <?= ical_escape_text($event->location) ?>
+URL;VALUE=URI:<?= isset($event->cloud_id) ? site_url('cloud/view/'.$event->cloud_id) 
+  : site_url('cloudscape/view/'. $event->cloudscape_id) ?>
 
-<?php } ?>
-URL;VALUE=URI:<?= base_url(); ?>cloudscape/view/<?= $event->cloudscape_id ?>
+<?php /*X-ORGANIZER:<NAME user=<?= $event->user_id ?> > (author):MAILTO:<?=str_replace('@', '-noreply@', config_item('site_email'))*/ ?>
+END:VEVENT
 
-END:VEVENT
 <?php endforeach; ?>
 END:VCALENDAR
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.