xref: /plugin/davcal/ics.php (revision 21d04f73144f4e2a45c7cc034725e3811f822e04)
1f69bb449SAndreas Boehler<?php
2f69bb449SAndreas Boehler
3cb71a62aSAndreas Boehler/**
4cb71a62aSAndreas Boehler * DoukWiki DAVCal PlugIn - ICS support server
5cb71a62aSAndreas Boehler */
6cb71a62aSAndreas Boehler
7f69bb449SAndreas Boehlerif(!defined('DOKU_INC')) define('DOKU_INC', dirname(__FILE__).'/../../../');
8f69bb449SAndreas Boehlerif (!defined('DOKU_DISABLE_GZIP_OUTPUT')) define('DOKU_DISABLE_GZIP_OUTPUT', 1);
9f69bb449SAndreas Boehlerrequire_once(DOKU_INC.'inc/init.php');
10f69bb449SAndreas Boehlersession_write_close(); //close session
11f69bb449SAndreas Boehler
12*21d04f73SAndreas Boehlerglobal $conf;
13*21d04f73SAndreas Boehlerif($conf['allowdebug'])
14*21d04f73SAndreas Boehler    dbglog('---- DAVCAL ics.php init');
15*21d04f73SAndreas Boehler
16f69bb449SAndreas Boehler$path = explode('/', $_SERVER['REQUEST_URI']);
17f69bb449SAndreas Boehler$icsFile = end($path);
18f69bb449SAndreas Boehler
19cb71a62aSAndreas Boehler// Load the helper plugin
207c7c6b0bSAndreas Boehler$hlp = null;
217c7c6b0bSAndreas Boehler$hlp =& plugin_load('helper', 'davcal');
227c7c6b0bSAndreas Boehler
237c7c6b0bSAndreas Boehlerif(is_null($hlp))
247c7c6b0bSAndreas Boehler{
25*21d04f73SAndreas Boehler    if($conf['allowdebug'])
26*21d04f73SAndreas Boehler        dbglog('Error loading helper plugin');
277c7c6b0bSAndreas Boehler    die('Error loading helper plugin');
287c7c6b0bSAndreas Boehler}
297c7c6b0bSAndreas Boehler
307c7c6b0bSAndreas Boehlerif($hlp->getConfig('disable_ics') === 1)
317c7c6b0bSAndreas Boehler{
32*21d04f73SAndreas Boehler    if($conf['allowdebug'])
33*21d04f73SAndreas Boehler        dbglog('ICS synchronisation is disabled');
347c7c6b0bSAndreas Boehler    die("ICS synchronisation is disabled");
357c7c6b0bSAndreas Boehler}
36f69bb449SAndreas Boehler
37cb71a62aSAndreas Boehler// Retrieve calendar ID based on private URI
38f69bb449SAndreas Boehler$calid = $hlp->getCalendarForPrivateURL($icsFile);
39f69bb449SAndreas Boehler
40f69bb449SAndreas Boehlerif($calid === false)
41*21d04f73SAndreas Boehler{
42*21d04f73SAndreas Boehler    if($conf['allowdebug'])
43*21d04f73SAndreas Boehler        dbglog('No calendar with this name known: '.$icsFile);
44f69bb449SAndreas Boehler    die("No calendar with this name known.");
45*21d04f73SAndreas Boehler}
46f69bb449SAndreas Boehler
47cb71a62aSAndreas Boehler// Retrieve calendar contents and serve
48f69bb449SAndreas Boehler$stream = $hlp->getCalendarAsICSFeed($calid);
49f69bb449SAndreas Boehlerheader("Content-Type: text/calendar");
50f69bb449SAndreas Boehlerheader("Content-Transfer-Encoding: Binary");
51f69bb449SAndreas Boehlerheader("Content-disposition: attachment; filename=\"calendar.ics\"");
52f69bb449SAndreas Boehlerecho $stream;