1a1a3b679SAndreas Boehler<?php 2a1a3b679SAndreas Boehler 3*cb71a62aSAndreas Boehler/** 4*cb71a62aSAndreas Boehler * DokuWiki DAVCal PlugIn - DAV Calendar Server PlugIn. 5*cb71a62aSAndreas Boehler * 6*cb71a62aSAndreas Boehler * This is heavily based on SabreDAV and features a DokuWiki connector. 7*cb71a62aSAndreas Boehler */ 8*cb71a62aSAndreas Boehler 9*cb71a62aSAndreas 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 17a1a3b679SAndreas Boehler$baseUri = DOKU_BASE.'lib/plugins/davcal/'.basename(__FILE__).'/'; 18a1a3b679SAndreas Boehler$sqlFile = $conf['metadir'].'/davcal.sqlite3'; 19a1a3b679SAndreas Boehler 20a1a3b679SAndreas Boehlerif(!file_exists($sqlFile)) 21a1a3b679SAndreas Boehler{ 22a1a3b679SAndreas Boehler die('SQL File doesn\'t exist'); 23a1a3b679SAndreas Boehler} 24a1a3b679SAndreas Boehler 25a1a3b679SAndreas Boehler/* Database */ 26a1a3b679SAndreas Boehler$pdo = new PDO('sqlite:'.$sqlFile); 27a1a3b679SAndreas Boehler$pdo->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION); 28a1a3b679SAndreas Boehler 29a1a3b679SAndreas Boehler//Mapping PHP errors to exceptions 30a1a3b679SAndreas Boehlerfunction exception_error_handler($errno, $errstr, $errfile, $errline) { 31a1a3b679SAndreas Boehler throw new ErrorException($errstr, 0, $errno, $errfile, $errline); 32a1a3b679SAndreas Boehler} 33a1a3b679SAndreas Boehler//set_error_handler("exception_error_handler"); 34a1a3b679SAndreas Boehler 35a1a3b679SAndreas Boehler// Files we need 36a1a3b679SAndreas Boehlerrequire_once 'vendor/autoload.php'; 37a1a3b679SAndreas Boehlerrequire_once('authBackendDokuwiki.php'); 38a1a3b679SAndreas Boehlerrequire_once('principalBackendDokuwiki.php'); 39a1a3b679SAndreas Boehlerrequire_once('calendarBackendDokuwiki.php'); 40a1a3b679SAndreas Boehler 41*cb71a62aSAndreas Boehler// Backends - our DokuWiki backends 42a1a3b679SAndreas Boehler$authBackend = new DokuWikiSabreAuthBackend(); 43*cb71a62aSAndreas Boehler$calendarBackend = new DokuWikiSabreCalendarBackend($pdo); 44a1a3b679SAndreas Boehler$principalBackend = new DokuWikiSabrePrincipalBackend(); 45a1a3b679SAndreas Boehler 46a1a3b679SAndreas Boehler// Directory structure 47a1a3b679SAndreas Boehler$tree = [ 48a1a3b679SAndreas Boehler new Sabre\CalDAV\Principal\Collection($principalBackend), 49a1a3b679SAndreas Boehler new Sabre\CalDAV\CalendarRoot($principalBackend, $calendarBackend), 50a1a3b679SAndreas Boehler]; 51a1a3b679SAndreas Boehler 52a1a3b679SAndreas Boehler$server = new Sabre\DAV\Server($tree); 53a1a3b679SAndreas Boehler 54a1a3b679SAndreas Boehlerif (isset($baseUri)) 55a1a3b679SAndreas Boehler $server->setBaseUri($baseUri); 56a1a3b679SAndreas Boehler 57a1a3b679SAndreas Boehler/* Server Plugins */ 58a1a3b679SAndreas Boehler$authPlugin = new Sabre\DAV\Auth\Plugin($authBackend); 59a1a3b679SAndreas Boehler$server->addPlugin($authPlugin); 60a1a3b679SAndreas Boehler 61a1a3b679SAndreas Boehler$aclPlugin = new Sabre\DAVACL\Plugin(); 62a1a3b679SAndreas Boehler$server->addPlugin($aclPlugin); 63a1a3b679SAndreas Boehler 64a1a3b679SAndreas Boehler/* CalDAV support */ 65a1a3b679SAndreas Boehler$caldavPlugin = new Sabre\CalDAV\Plugin(); 66a1a3b679SAndreas Boehler$server->addPlugin($caldavPlugin); 67a1a3b679SAndreas Boehler 68a1a3b679SAndreas Boehler/* Calendar subscription support */ 6955a741c0SAndreas Boehler//$server->addPlugin( 7055a741c0SAndreas Boehler// new Sabre\CalDAV\Subscriptions\Plugin() 7155a741c0SAndreas Boehler//); 72a1a3b679SAndreas Boehler 73a1a3b679SAndreas Boehler/* Calendar scheduling support */ 7455a741c0SAndreas Boehler//$server->addPlugin( 7555a741c0SAndreas Boehler// new Sabre\CalDAV\Schedule\Plugin() 7655a741c0SAndreas Boehler//); 77a1a3b679SAndreas Boehler 78a1a3b679SAndreas Boehler/* WebDAV-Sync plugin */ 7955a741c0SAndreas Boehler$server->addPlugin(new Sabre\DAV\Sync\Plugin()); 80a1a3b679SAndreas Boehler 81a1a3b679SAndreas Boehler// Support for html frontend 82a1a3b679SAndreas Boehler$browser = new Sabre\DAV\Browser\Plugin(); 83a1a3b679SAndreas Boehler$server->addPlugin($browser); 84a1a3b679SAndreas Boehler 85a1a3b679SAndreas Boehler// And off we go! 86a1a3b679SAndreas Boehler$server->exec(); 87