OK, I’ll post it here (if it should go somewhere else on the site, let me know and I’ll move it).
1. Add a template to your theme which looks like this:
<?php
/**
* Template Name: iCal
*
* Custom page template to send iCal vcs content for an event.
*
* pw - Summer 2011
*
* Notes
* 1. This template does not output any html at all, but just sends a vcs file.
* 2. The template reads the event id from the url which calls it: ".../page?id=n" and
* must be strict in validating the id because it is used in an sql statement.
* 3. Uses iCal not vCal format - should be compatible with most Calendars, and can
* have 'floating' times instead of UTC only.
*/
global $wpdb;
$_id = mysql_real_escape_string($_GET['id']);
if (is_numeric($_id)) {
$_event = $wpdb->get_row("SELECT * FROM <code>".$wpdb->prefix."events</code> WHERE <code>id</code> = $_id");
}
if ($_event->title) {
$dateStart = date('Ymd\THis', $_event->thetime);
$dateEnd = date('Ymd\THis', $_event->theend);
$title = $_event->title;
$location = $_event->location;
} else {
$dateStart = '';
$dateEnd = '';
$title = 'No event found';
$location = '';
}
header('Content-type: text/calendar; charset=ISO-8859-1');
header('Content-Disposition: inline; filename="outlook.vcs"');
$_feed ="BEGIN:VCALENDAR\n";
$_feed.="VERSION:2.0\n";
$_feed.="BEGIN:VEVENT\n";
$_feed.="DTStart:$dateStart\n";
$_feed.="DTEnd:$dateEnd\n";
$_feed.="SUMMARY:$title\n";
$_feed.="Location:$location\n";
$_feed.="UID:".$_id."@example.com\n";
$_feed.="End:VEVENT\n";
$_feed.="End:VCALENDAR";
echo $_feed;
?>
Note – you may want to change the UID to include the time or something to make it more unique.
2. Create a new page in your site – it needn’t have any content. Make it Private, and under Attributes / Template, choose the iCal template in 1 above.
3. Create a link in the page which displays the event (I don’t use widgets) which looks like this:
<a href="yoursite/page?id=nn">ICAL</a>
where ‘yoursite/page’ is a full link to the page you created in 2,
and ‘nn’ is the id which identifies the event. I modified the ‘events_build_output’ function to put this in.
That’s it – but note this will likely make your version of WP-Events incompatible and will break if you use the plug-in update system!