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 1221d04f73SAndreas Boehlerglobal $conf; 1321d04f73SAndreas Boehlerif($conf['allowdebug']) 14*c42afaebSscottleechua \dokuwiki\Logger::debug('DAVCAL', 'ICS server initialized', __FILE__, __LINE__); 1521d04f73SAndreas 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{ 2521d04f73SAndreas Boehler if($conf['allowdebug']) 26*c42afaebSscottleechua \dokuwiki\Logger::error('DAVCAL', 'Error loading helper plugin', __FILE__, __LINE__); 277c7c6b0bSAndreas Boehler die('Error loading helper plugin'); 287c7c6b0bSAndreas Boehler} 297c7c6b0bSAndreas Boehler 307c7c6b0bSAndreas Boehlerif($hlp->getConfig('disable_ics') === 1) 317c7c6b0bSAndreas Boehler{ 3221d04f73SAndreas Boehler if($conf['allowdebug']) 33*c42afaebSscottleechua \dokuwiki\Logger::debug('DAVCAL', 'ICS synchronisation is disabled', __FILE__, __LINE__); 347c7c6b0bSAndreas Boehler die("ICS synchronisation is disabled"); 357c7c6b0bSAndreas Boehler} 36f69bb449SAndreas Boehler 37a8a4aa52Sscottleechua// Check if this is an aggregated calendar URL 38a8a4aa52Sscottleechuaif(strpos($icsFile, 'dokuwiki-aggregated-') === 0) 39a8a4aa52Sscottleechua{ 40a8a4aa52Sscottleechua // This is an aggregated calendar - handle it specially 41a8a4aa52Sscottleechua $stream = $hlp->getAggregatedCalendarAsICSFeed($icsFile); 42a8a4aa52Sscottleechua if($stream === false) 43a8a4aa52Sscottleechua { 44a8a4aa52Sscottleechua if($conf['allowdebug']) 45*c42afaebSscottleechua \dokuwiki\Logger::error('DAVCAL', 'No aggregated calendar with this name known: '.$icsFile, __FILE__, __LINE__); 46a8a4aa52Sscottleechua die("No aggregated calendar with this name known."); 47a8a4aa52Sscottleechua } 48a8a4aa52Sscottleechua} 49a8a4aa52Sscottleechuaelse 50a8a4aa52Sscottleechua{ 51a8a4aa52Sscottleechua // Regular single calendar 52cb71a62aSAndreas Boehler // Retrieve calendar ID based on private URI 53f69bb449SAndreas Boehler $calid = $hlp->getCalendarForPrivateURL($icsFile); 54f69bb449SAndreas Boehler 55f69bb449SAndreas Boehler if($calid === false) 5621d04f73SAndreas Boehler { 5721d04f73SAndreas Boehler if($conf['allowdebug']) 58*c42afaebSscottleechua \dokuwiki\Logger::error('DAVCAL', 'No calendar with this name known: '.$icsFile, __FILE__, __LINE__); 59f69bb449SAndreas Boehler die("No calendar with this name known."); 6021d04f73SAndreas Boehler } 61f69bb449SAndreas Boehler 62cb71a62aSAndreas Boehler // Retrieve calendar contents and serve 63f69bb449SAndreas Boehler $stream = $hlp->getCalendarAsICSFeed($calid); 64a8a4aa52Sscottleechua} 65a8a4aa52Sscottleechua 66f69bb449SAndreas Boehlerheader("Content-Type: text/calendar"); 67f69bb449SAndreas Boehlerheader("Content-Transfer-Encoding: Binary"); 68f69bb449SAndreas Boehlerheader("Content-disposition: attachment; filename=\"calendar.ics\""); 69f69bb449SAndreas Boehlerecho $stream;