1<?php
2
3/**
4 * DoukWiki DAVCal PlugIn - ICS support server
5 */
6
7if(!defined('DOKU_INC')) define('DOKU_INC', dirname(__FILE__).'/../../../');
8if (!defined('DOKU_DISABLE_GZIP_OUTPUT')) define('DOKU_DISABLE_GZIP_OUTPUT', 1);
9require_once(DOKU_INC.'inc/init.php');
10session_write_close(); //close session
11
12global $conf;
13if($conf['allowdebug'])
14    dbglog('---- DAVCAL ics.php init');
15
16$path = explode('/', $_SERVER['REQUEST_URI']);
17$icsFile = end($path);
18
19// Load the helper plugin
20$hlp = null;
21$hlp =& plugin_load('helper', 'davcal');
22
23if(is_null($hlp))
24{
25    if($conf['allowdebug'])
26        dbglog('Error loading helper plugin');
27    die('Error loading helper plugin');
28}
29
30if($hlp->getConfig('disable_ics') === 1)
31{
32    if($conf['allowdebug'])
33        dbglog('ICS synchronisation is disabled');
34    die("ICS synchronisation is disabled");
35}
36
37// Retrieve calendar ID based on private URI
38$calid = $hlp->getCalendarForPrivateURL($icsFile);
39
40if($calid === false)
41{
42    if($conf['allowdebug'])
43        dbglog('No calendar with this name known: '.$icsFile);
44    die("No calendar with this name known.");
45}
46
47// Retrieve calendar contents and serve
48$stream = $hlp->getCalendarAsICSFeed($calid);
49header("Content-Type: text/calendar");
50header("Content-Transfer-Encoding: Binary");
51header("Content-disposition: attachment; filename=\"calendar.ics\"");
52echo $stream;