Example PHP and Zap
//import Zap
require_once("zap/zapcallib.php");
// Create Zap
$icalobj = new ZCiCal();
// Load all events from database somehow
$events = ...
// Loop through all vents
foreach($events as $event) {
// Create a Zap event object
$eventobj = new ZCiCalNode("VEVENT", $icalobj->curnode);
// Every event needs a unique ID
$uid = $event->id . "@yourdomainname.com";
$eventobj->addNode(new ZCiCalDataNode("UID:" . $uid));
// Add event using current time as timestamp
$eventobj->addNode(new ZCiCalDataNode("DTSTAMP:" . ZCiCal::fromSqlDateTime()));
// in this case we don't have the exact time, so we want to make 'whole day' events that are displayed on top in your calendar.
// You do that by having the event be exactly 24h, from 12:00 to 12:00
$eventobj->addNode(new ZCiCalDataNode("DTSTART;VALUE=DATE:" . date('Ymd', $event->startdate) ));
$start = date('Y-m-d', $event->startdate);
// Add exactly one day
$nextDay = strtotime($start . ' +1 day');
$eventobj->addNode(new ZCiCalDataNode("DTEND;VALUE=DATE:" . date('Ymd', $nextDay) ));
// Construct a link back to your website so you can go straight to the event page
$eventobj->addNode(new ZCiCalDataNode("URL:" . 'https://yourdomainname.com/event/' . $event->parent->name . '/event/' . $event->name));
// Could add an image, would be nice!
$eventobj->addNode(new ZCiCalDataNode("ATTACH;FMTTYPE=image/jpeg:" . $event->image->url));
// A title for the event
$eventobj->addNode(new ZCiCalDataNode("SUMMARY: " . $event->parent->title . ', ' . $event->title));
// And maybe a lead text
$eventobj->addNode(new ZCiCalDataNode("Description:" . ZCiCal::formatContent($event->leadtext)));
}
// Use the right header
header("Content-type:text/calendar");
//...Aaand export!
echo $icalobj->export();