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 \dokuwiki\Logger::debug('DAVCAL', 'ICS server initialized', __FILE__, __LINE__); 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 \dokuwiki\Logger::error('DAVCAL', 'Error loading helper plugin', __FILE__, __LINE__); 27 die('Error loading helper plugin'); 28} 29 30if($hlp->getConfig('disable_ics') === 1) 31{ 32 if($conf['allowdebug']) 33 \dokuwiki\Logger::debug('DAVCAL', 'ICS synchronisation is disabled', __FILE__, __LINE__); 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 \dokuwiki\Logger::error('DAVCAL', 'No aggregated calendar with this name known: '.$icsFile, __FILE__, __LINE__); 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 \dokuwiki\Logger::error('DAVCAL', 'No calendar with this name known: '.$icsFile, __FILE__, __LINE__); 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;