xref: /plugin/davcal/ics.php (revision a8a4aa529bc469c0c73929a1c39caef9affcecd7)
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// Check if this is an aggregated calendar URL
38if(strpos($icsFile, 'dokuwiki-aggregated-') === 0)
39{
40    // This is an aggregated calendar - handle it specially
41    $stream = $hlp->getAggregatedCalendarAsICSFeed($icsFile);
42    if($stream === false)
43    {
44        if($conf['allowdebug'])
45            dbglog('No aggregated calendar with this name known: '.$icsFile);
46        die("No aggregated calendar with this name known.");
47    }
48}
49else
50{
51    // Regular single calendar
52    // Retrieve calendar ID based on private URI
53    $calid = $hlp->getCalendarForPrivateURL($icsFile);
54
55    if($calid === false)
56    {
57        if($conf['allowdebug'])
58            dbglog('No calendar with this name known: '.$icsFile);
59        die("No calendar with this name known.");
60    }
61
62    // Retrieve calendar contents and serve
63    $stream = $hlp->getCalendarAsICSFeed($calid);
64}
65
66header("Content-Type: text/calendar");
67header("Content-Transfer-Encoding: Binary");
68header("Content-disposition: attachment; filename=\"calendar.ics\"");
69echo $stream;