1a1a3b679SAndreas Boehler<?php 2a1a3b679SAndreas Boehler 3cb71a62aSAndreas Boehler/** 4cb71a62aSAndreas Boehler * DokuWiki DAVCal PlugIn - DAV Calendar Server PlugIn. 5cb71a62aSAndreas Boehler * 6cb71a62aSAndreas Boehler * This is heavily based on SabreDAV and features a DokuWiki connector. 7cb71a62aSAndreas Boehler */ 8cb71a62aSAndreas Boehler 9cb71a62aSAndreas Boehler // Initialize DokuWiki 10a1a3b679SAndreas Boehlerif(!defined('DOKU_INC')) define('DOKU_INC', dirname(__FILE__).'/../../../'); 11a1a3b679SAndreas Boehlerif (!defined('DOKU_DISABLE_GZIP_OUTPUT')) define('DOKU_DISABLE_GZIP_OUTPUT', 1); 12a1a3b679SAndreas Boehlerrequire_once(DOKU_INC.'inc/init.php'); 13a1a3b679SAndreas Boehlersession_write_close(); //close session 14a1a3b679SAndreas Boehler 15a1a3b679SAndreas Boehlerglobal $conf; 16a1a3b679SAndreas Boehler 17*c42afaebSscottleechua\dokuwiki\Logger::debug('DAVCAL', 'Calendar server initialized', __FILE__, __LINE__); 1821d04f73SAndreas Boehler 197c7c6b0bSAndreas Boehler$hlp = null; 207c7c6b0bSAndreas Boehler$hlp =& plugin_load('helper', 'davcal'); 217c7c6b0bSAndreas Boehler 227c7c6b0bSAndreas Boehlerif(is_null($hlp)) 237c7c6b0bSAndreas Boehler{ 24*c42afaebSscottleechua \dokuwiki\Logger::error('DAVCAL', 'Error loading helper plugin', __FILE__, __LINE__); 257c7c6b0bSAndreas Boehler die('Error loading helper plugin'); 267c7c6b0bSAndreas Boehler} 277c7c6b0bSAndreas Boehler 28a1a3b679SAndreas Boehler$baseUri = DOKU_BASE.'lib/plugins/davcal/'.basename(__FILE__).'/'; 29a1a3b679SAndreas Boehler 307c7c6b0bSAndreas Boehlerif($hlp->getConfig('disable_sync') === 1) 31185e2535SAndreas Boehler{ 32*c42afaebSscottleechua \dokuwiki\Logger::debug('DAVCAL', 'Synchronisation is disabled', __FILE__, __LINE__); 33185e2535SAndreas Boehler die('Synchronisation is disabled'); 34185e2535SAndreas Boehler} 35185e2535SAndreas Boehler 36a1a3b679SAndreas Boehler//Mapping PHP errors to exceptions 37a1a3b679SAndreas Boehlerfunction exception_error_handler($errno, $errstr, $errfile, $errline) { 38*c42afaebSscottleechua \dokuwiki\Logger::error('DAVCAL', 'Exception occurred: '.$errstr, __FILE__, __LINE__); 39a1a3b679SAndreas Boehler throw new ErrorException($errstr, 0, $errno, $errfile, $errline); 40a1a3b679SAndreas Boehler} 41a1a3b679SAndreas Boehler//set_error_handler("exception_error_handler"); 42a1a3b679SAndreas Boehler 43a1a3b679SAndreas Boehler// Files we need 449bef4ad8SAndreas Boehlerrequire_once(DOKU_PLUGIN.'davcal/vendor/autoload.php'); 459bef4ad8SAndreas Boehlerrequire_once(DOKU_PLUGIN.'davcal/authBackendDokuwiki.php'); 469bef4ad8SAndreas Boehlerrequire_once(DOKU_PLUGIN.'davcal/principalBackendDokuwiki.php'); 479bef4ad8SAndreas Boehlerrequire_once(DOKU_PLUGIN.'davcal/calendarBackendDokuwiki.php'); 48a1a3b679SAndreas Boehler 49cb71a62aSAndreas Boehler// Backends - our DokuWiki backends 50a1a3b679SAndreas Boehler$authBackend = new DokuWikiSabreAuthBackend(); 51d5703f5aSAndreas Boehler$calendarBackend = new DokuWikiSabreCalendarBackend($hlp); 52a1a3b679SAndreas Boehler$principalBackend = new DokuWikiSabrePrincipalBackend(); 53a1a3b679SAndreas Boehler 54a1a3b679SAndreas Boehler// Directory structure 55d5703f5aSAndreas Boehler$tree = array( 56a1a3b679SAndreas Boehler new Sabre\CalDAV\Principal\Collection($principalBackend), 57a1a3b679SAndreas Boehler new Sabre\CalDAV\CalendarRoot($principalBackend, $calendarBackend), 58d5703f5aSAndreas Boehler); 59a1a3b679SAndreas Boehler 60a1a3b679SAndreas Boehler$server = new Sabre\DAV\Server($tree); 61a1a3b679SAndreas Boehler 62a1a3b679SAndreas Boehlerif (isset($baseUri)) 63a1a3b679SAndreas Boehler $server->setBaseUri($baseUri); 64a1a3b679SAndreas Boehler 65a1a3b679SAndreas Boehler/* Server Plugins */ 66a1a3b679SAndreas Boehler$authPlugin = new Sabre\DAV\Auth\Plugin($authBackend); 67a1a3b679SAndreas Boehler$server->addPlugin($authPlugin); 68a1a3b679SAndreas Boehler 69a1a3b679SAndreas Boehler$aclPlugin = new Sabre\DAVACL\Plugin(); 70a1a3b679SAndreas Boehler$server->addPlugin($aclPlugin); 71a1a3b679SAndreas Boehler 72a1a3b679SAndreas Boehler/* CalDAV support */ 73a1a3b679SAndreas Boehler$caldavPlugin = new Sabre\CalDAV\Plugin(); 74a1a3b679SAndreas Boehler$server->addPlugin($caldavPlugin); 75a1a3b679SAndreas Boehler 76a1a3b679SAndreas Boehler/* Calendar subscription support */ 7755a741c0SAndreas Boehler//$server->addPlugin( 7855a741c0SAndreas Boehler// new Sabre\CalDAV\Subscriptions\Plugin() 7955a741c0SAndreas Boehler//); 80a1a3b679SAndreas Boehler 81a1a3b679SAndreas Boehler/* Calendar scheduling support */ 8255a741c0SAndreas Boehler//$server->addPlugin( 8355a741c0SAndreas Boehler// new Sabre\CalDAV\Schedule\Plugin() 8455a741c0SAndreas Boehler//); 85a1a3b679SAndreas Boehler 86a1a3b679SAndreas Boehler/* WebDAV-Sync plugin */ 8755a741c0SAndreas Boehler$server->addPlugin(new Sabre\DAV\Sync\Plugin()); 88a1a3b679SAndreas Boehler 89a1a3b679SAndreas Boehler// Support for html frontend 90a1a3b679SAndreas Boehler$browser = new Sabre\DAV\Browser\Plugin(); 91a1a3b679SAndreas Boehler$server->addPlugin($browser); 92a1a3b679SAndreas Boehler 93*c42afaebSscottleechua\dokuwiki\Logger::debug('DAVCAL', 'Server execution started', __FILE__, __LINE__); 94a1a3b679SAndreas Boehler// And off we go! 95a1a3b679SAndreas Boehler$server->exec(); 96