1a1a3b679SAndreas Boehler<?php 2a1a3b679SAndreas Boehler 3a1a3b679SAndreas Boehlerif(!defined('DOKU_INC')) define('DOKU_INC', dirname(__FILE__).'/../../../'); 4a1a3b679SAndreas Boehlerif (!defined('DOKU_DISABLE_GZIP_OUTPUT')) define('DOKU_DISABLE_GZIP_OUTPUT', 1); 5a1a3b679SAndreas Boehlerrequire_once(DOKU_INC.'inc/init.php'); 6a1a3b679SAndreas Boehlersession_write_close(); //close session 7a1a3b679SAndreas Boehler 8a1a3b679SAndreas Boehlerrequire_once (DOKU_INC.'inc/fetch.functions.php'); 9a1a3b679SAndreas Boehler 10a1a3b679SAndreas Boehlerglobal $conf; 11a1a3b679SAndreas Boehler 12a1a3b679SAndreas Boehler$baseUri = DOKU_BASE.'lib/plugins/davcal/'.basename(__FILE__).'/'; 13a1a3b679SAndreas Boehler$sqlFile = $conf['metadir'].'/davcal.sqlite3'; 14a1a3b679SAndreas Boehler 15a1a3b679SAndreas Boehlerif(!file_exists($sqlFile)) 16a1a3b679SAndreas Boehler{ 17a1a3b679SAndreas Boehler die('SQL File doesn\'t exist'); 18a1a3b679SAndreas Boehler} 19a1a3b679SAndreas Boehler 20a1a3b679SAndreas Boehler/* 21a1a3b679SAndreas Boehler 22a1a3b679SAndreas BoehlerCalendarServer example 23a1a3b679SAndreas Boehler 24a1a3b679SAndreas BoehlerThis server features CalDAV support 25a1a3b679SAndreas Boehler 26a1a3b679SAndreas Boehler*/ 27a1a3b679SAndreas Boehler 28a1a3b679SAndreas Boehler// settings 29a1a3b679SAndreas Boehler// date_default_timezone_set('Canada/Eastern'); 30a1a3b679SAndreas Boehler 31a1a3b679SAndreas Boehler// If you want to run the SabreDAV server in a custom location (using mod_rewrite for instance) 32a1a3b679SAndreas Boehler// You can override the baseUri here. 33a1a3b679SAndreas Boehler// $baseUri = '/'; 34a1a3b679SAndreas Boehler 35a1a3b679SAndreas Boehler/* Database */ 36a1a3b679SAndreas Boehler$pdo = new PDO('sqlite:'.$sqlFile); 37a1a3b679SAndreas Boehler$pdo->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION); 38a1a3b679SAndreas Boehler 39a1a3b679SAndreas Boehler//Mapping PHP errors to exceptions 40a1a3b679SAndreas Boehlerfunction exception_error_handler($errno, $errstr, $errfile, $errline) { 41a1a3b679SAndreas Boehler throw new ErrorException($errstr, 0, $errno, $errfile, $errline); 42a1a3b679SAndreas Boehler} 43a1a3b679SAndreas Boehler//set_error_handler("exception_error_handler"); 44a1a3b679SAndreas Boehler 45a1a3b679SAndreas Boehler// Files we need 46a1a3b679SAndreas Boehlerrequire_once 'vendor/autoload.php'; 47a1a3b679SAndreas Boehlerrequire_once('authBackendDokuwiki.php'); 48a1a3b679SAndreas Boehlerrequire_once('principalBackendDokuwiki.php'); 49a1a3b679SAndreas Boehlerrequire_once('calendarBackendDokuwiki.php'); 50a1a3b679SAndreas Boehler 51a1a3b679SAndreas Boehler// Backends 52a1a3b679SAndreas Boehler$authBackend = new DokuWikiSabreAuthBackend(); 53a1a3b679SAndreas Boehler$calendarBackend = new DokuWikiSabreCalendarBackend($pdo); //Sabre\CalDAV\Backend\PDO($pdo); 54a1a3b679SAndreas Boehler$principalBackend = new DokuWikiSabrePrincipalBackend(); 55a1a3b679SAndreas Boehler 56a1a3b679SAndreas Boehler// Directory structure 57a1a3b679SAndreas Boehler$tree = [ 58a1a3b679SAndreas Boehler new Sabre\CalDAV\Principal\Collection($principalBackend), 59a1a3b679SAndreas Boehler new Sabre\CalDAV\CalendarRoot($principalBackend, $calendarBackend), 60a1a3b679SAndreas Boehler]; 61a1a3b679SAndreas Boehler 62a1a3b679SAndreas Boehler$server = new Sabre\DAV\Server($tree); 63a1a3b679SAndreas Boehler 64a1a3b679SAndreas Boehlerif (isset($baseUri)) 65a1a3b679SAndreas Boehler $server->setBaseUri($baseUri); 66a1a3b679SAndreas Boehler 67a1a3b679SAndreas Boehler/* Server Plugins */ 68a1a3b679SAndreas Boehler$authPlugin = new Sabre\DAV\Auth\Plugin($authBackend); 69a1a3b679SAndreas Boehler$server->addPlugin($authPlugin); 70a1a3b679SAndreas Boehler 71a1a3b679SAndreas Boehler$aclPlugin = new Sabre\DAVACL\Plugin(); 72a1a3b679SAndreas Boehler$server->addPlugin($aclPlugin); 73a1a3b679SAndreas Boehler 74a1a3b679SAndreas Boehler/* CalDAV support */ 75a1a3b679SAndreas Boehler$caldavPlugin = new Sabre\CalDAV\Plugin(); 76a1a3b679SAndreas Boehler$server->addPlugin($caldavPlugin); 77a1a3b679SAndreas Boehler 78a1a3b679SAndreas Boehler/* Calendar subscription support */ 79*55a741c0SAndreas Boehler//$server->addPlugin( 80*55a741c0SAndreas Boehler// new Sabre\CalDAV\Subscriptions\Plugin() 81*55a741c0SAndreas Boehler//); 82a1a3b679SAndreas Boehler 83a1a3b679SAndreas Boehler/* Calendar scheduling support */ 84*55a741c0SAndreas Boehler//$server->addPlugin( 85*55a741c0SAndreas Boehler// new Sabre\CalDAV\Schedule\Plugin() 86*55a741c0SAndreas Boehler//); 87a1a3b679SAndreas Boehler 88a1a3b679SAndreas Boehler/* WebDAV-Sync plugin */ 89*55a741c0SAndreas Boehler$server->addPlugin(new Sabre\DAV\Sync\Plugin()); 90a1a3b679SAndreas Boehler 91a1a3b679SAndreas Boehler// Support for html frontend 92a1a3b679SAndreas Boehler$browser = new Sabre\DAV\Browser\Plugin(); 93a1a3b679SAndreas Boehler$server->addPlugin($browser); 94a1a3b679SAndreas Boehler 95a1a3b679SAndreas Boehler// And off we go! 96a1a3b679SAndreas Boehler$server->exec(); 97