1<?php 2 3/** 4 * DokuWiki DAVCal PlugIn - DAV Calendar Server PlugIn. 5 * 6 * This is heavily based on SabreDAV and features a DokuWiki connector. 7 */ 8 9 // Initialize DokuWiki 10if(!defined('DOKU_INC')) define('DOKU_INC', dirname(__FILE__).'/../../../'); 11if (!defined('DOKU_DISABLE_GZIP_OUTPUT')) define('DOKU_DISABLE_GZIP_OUTPUT', 1); 12require_once(DOKU_INC.'inc/init.php'); 13session_write_close(); //close session 14 15global $conf; 16 17if($conf['allowdebug']) 18 dbglog('---- DAVCAL calendarserver.php init'); 19 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 30$baseUri = DOKU_BASE.'lib/plugins/davcal/'.basename(__FILE__).'/'; 31$sqlFile = $conf['metadir'].'/davcal.sqlite3'; 32 33if(!file_exists($sqlFile)) 34{ 35 if($conf['allowdebug']) 36 dbglog('SQL File doesn\'t exist: '.$sqlFile); 37 die('SQL File doesn\'t exist'); 38} 39 40if($hlp->getConfig('disable_sync') === 1) 41{ 42 if($conf['allowdebug']) 43 dbglog('Synchronisation is disabled'); 44 die('Synchronisation is disabled'); 45} 46 47/* Database */ 48$pdo = new PDO('sqlite:'.$sqlFile); 49$pdo->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION); 50 51//Mapping PHP errors to exceptions 52function exception_error_handler($errno, $errstr, $errfile, $errline) { 53 if($conf['allowdebug']) 54 dbglog('Exception occured: '.$errstr); 55 throw new ErrorException($errstr, 0, $errno, $errfile, $errline); 56} 57//set_error_handler("exception_error_handler"); 58 59// Files we need 60require_once(DOKU_PLUGIN.'davcal/vendor/autoload.php'); 61require_once(DOKU_PLUGIN.'davcal/authBackendDokuwiki.php'); 62require_once(DOKU_PLUGIN.'davcal/principalBackendDokuwiki.php'); 63require_once(DOKU_PLUGIN.'davcal/calendarBackendDokuwiki.php'); 64 65// Backends - our DokuWiki backends 66$authBackend = new DokuWikiSabreAuthBackend(); 67$calendarBackend = new DokuWikiSabreCalendarBackend($pdo); 68$principalBackend = new DokuWikiSabrePrincipalBackend(); 69 70// Directory structure 71$tree = [ 72 new Sabre\CalDAV\Principal\Collection($principalBackend), 73 new Sabre\CalDAV\CalendarRoot($principalBackend, $calendarBackend), 74]; 75 76$server = new Sabre\DAV\Server($tree); 77 78if (isset($baseUri)) 79 $server->setBaseUri($baseUri); 80 81/* Server Plugins */ 82$authPlugin = new Sabre\DAV\Auth\Plugin($authBackend); 83$server->addPlugin($authPlugin); 84 85$aclPlugin = new Sabre\DAVACL\Plugin(); 86$server->addPlugin($aclPlugin); 87 88/* CalDAV support */ 89$caldavPlugin = new Sabre\CalDAV\Plugin(); 90$server->addPlugin($caldavPlugin); 91 92/* Calendar subscription support */ 93//$server->addPlugin( 94// new Sabre\CalDAV\Subscriptions\Plugin() 95//); 96 97/* Calendar scheduling support */ 98//$server->addPlugin( 99// new Sabre\CalDAV\Schedule\Plugin() 100//); 101 102/* WebDAV-Sync plugin */ 103$server->addPlugin(new Sabre\DAV\Sync\Plugin()); 104 105// Support for html frontend 106$browser = new Sabre\DAV\Browser\Plugin(); 107$server->addPlugin($browser); 108 109if($conf['allowdebug']) 110 dbglog('$server->exec()'); 111// And off we go! 112$server->exec(); 113