xref: /plugin/davcal/calendarserver.php (revision 21d04f73144f4e2a45c7cc034725e3811f822e04)
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*21d04f73SAndreas Boehlerif($conf['allowdebug'])
18*21d04f73SAndreas Boehler    dbglog('---- DAVCAL calendarserver.php init');
19*21d04f73SAndreas Boehler
207c7c6b0bSAndreas Boehler$hlp = null;
217c7c6b0bSAndreas Boehler$hlp =& plugin_load('helper', 'davcal');
227c7c6b0bSAndreas Boehler
237c7c6b0bSAndreas Boehlerif(is_null($hlp))
247c7c6b0bSAndreas Boehler{
25*21d04f73SAndreas Boehler    if($conf['allowdebug'])
26*21d04f73SAndreas Boehler        dbglog('Error loading helper plugin');
277c7c6b0bSAndreas Boehler    die('Error loading helper plugin');
287c7c6b0bSAndreas Boehler}
297c7c6b0bSAndreas Boehler
30a1a3b679SAndreas Boehler$baseUri = DOKU_BASE.'lib/plugins/davcal/'.basename(__FILE__).'/';
31a1a3b679SAndreas Boehler$sqlFile = $conf['metadir'].'/davcal.sqlite3';
32a1a3b679SAndreas Boehler
33a1a3b679SAndreas Boehlerif(!file_exists($sqlFile))
34a1a3b679SAndreas Boehler{
35*21d04f73SAndreas Boehler    if($conf['allowdebug'])
36*21d04f73SAndreas Boehler        dbglog('SQL File doesn\'t exist: '.$sqlFile);
37a1a3b679SAndreas Boehler    die('SQL File doesn\'t exist');
38a1a3b679SAndreas Boehler}
39a1a3b679SAndreas Boehler
407c7c6b0bSAndreas Boehlerif($hlp->getConfig('disable_sync') === 1)
41185e2535SAndreas Boehler{
42*21d04f73SAndreas Boehler    if($conf['allowdebug'])
43*21d04f73SAndreas Boehler        dbglog('Synchronisation is disabled');
44185e2535SAndreas Boehler    die('Synchronisation is disabled');
45185e2535SAndreas Boehler}
46185e2535SAndreas Boehler
47a1a3b679SAndreas Boehler/* Database */
48a1a3b679SAndreas Boehler$pdo = new PDO('sqlite:'.$sqlFile);
49a1a3b679SAndreas Boehler$pdo->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
50a1a3b679SAndreas Boehler
51a1a3b679SAndreas Boehler//Mapping PHP errors to exceptions
52a1a3b679SAndreas Boehlerfunction exception_error_handler($errno, $errstr, $errfile, $errline) {
53*21d04f73SAndreas Boehler    if($conf['allowdebug'])
54*21d04f73SAndreas Boehler        dbglog('Exception occured: '.$errstr);
55a1a3b679SAndreas Boehler    throw new ErrorException($errstr, 0, $errno, $errfile, $errline);
56a1a3b679SAndreas Boehler}
57a1a3b679SAndreas Boehler//set_error_handler("exception_error_handler");
58a1a3b679SAndreas Boehler
59a1a3b679SAndreas Boehler// Files we need
609bef4ad8SAndreas Boehlerrequire_once(DOKU_PLUGIN.'davcal/vendor/autoload.php');
619bef4ad8SAndreas Boehlerrequire_once(DOKU_PLUGIN.'davcal/authBackendDokuwiki.php');
629bef4ad8SAndreas Boehlerrequire_once(DOKU_PLUGIN.'davcal/principalBackendDokuwiki.php');
639bef4ad8SAndreas Boehlerrequire_once(DOKU_PLUGIN.'davcal/calendarBackendDokuwiki.php');
64a1a3b679SAndreas Boehler
65cb71a62aSAndreas Boehler// Backends - our DokuWiki backends
66a1a3b679SAndreas Boehler$authBackend = new DokuWikiSabreAuthBackend();
67cb71a62aSAndreas Boehler$calendarBackend = new DokuWikiSabreCalendarBackend($pdo);
68a1a3b679SAndreas Boehler$principalBackend = new DokuWikiSabrePrincipalBackend();
69a1a3b679SAndreas Boehler
70a1a3b679SAndreas Boehler// Directory structure
71a1a3b679SAndreas Boehler$tree = [
72a1a3b679SAndreas Boehler    new Sabre\CalDAV\Principal\Collection($principalBackend),
73a1a3b679SAndreas Boehler    new Sabre\CalDAV\CalendarRoot($principalBackend, $calendarBackend),
74a1a3b679SAndreas Boehler];
75a1a3b679SAndreas Boehler
76a1a3b679SAndreas Boehler$server = new Sabre\DAV\Server($tree);
77a1a3b679SAndreas Boehler
78a1a3b679SAndreas Boehlerif (isset($baseUri))
79a1a3b679SAndreas Boehler    $server->setBaseUri($baseUri);
80a1a3b679SAndreas Boehler
81a1a3b679SAndreas Boehler/* Server Plugins */
82a1a3b679SAndreas Boehler$authPlugin = new Sabre\DAV\Auth\Plugin($authBackend);
83a1a3b679SAndreas Boehler$server->addPlugin($authPlugin);
84a1a3b679SAndreas Boehler
85a1a3b679SAndreas Boehler$aclPlugin = new Sabre\DAVACL\Plugin();
86a1a3b679SAndreas Boehler$server->addPlugin($aclPlugin);
87a1a3b679SAndreas Boehler
88a1a3b679SAndreas Boehler/* CalDAV support */
89a1a3b679SAndreas Boehler$caldavPlugin = new Sabre\CalDAV\Plugin();
90a1a3b679SAndreas Boehler$server->addPlugin($caldavPlugin);
91a1a3b679SAndreas Boehler
92a1a3b679SAndreas Boehler/* Calendar subscription support */
9355a741c0SAndreas Boehler//$server->addPlugin(
9455a741c0SAndreas Boehler//    new Sabre\CalDAV\Subscriptions\Plugin()
9555a741c0SAndreas Boehler//);
96a1a3b679SAndreas Boehler
97a1a3b679SAndreas Boehler/* Calendar scheduling support */
9855a741c0SAndreas Boehler//$server->addPlugin(
9955a741c0SAndreas Boehler//    new Sabre\CalDAV\Schedule\Plugin()
10055a741c0SAndreas Boehler//);
101a1a3b679SAndreas Boehler
102a1a3b679SAndreas Boehler/* WebDAV-Sync plugin */
10355a741c0SAndreas Boehler$server->addPlugin(new Sabre\DAV\Sync\Plugin());
104a1a3b679SAndreas Boehler
105a1a3b679SAndreas Boehler// Support for html frontend
106a1a3b679SAndreas Boehler$browser = new Sabre\DAV\Browser\Plugin();
107a1a3b679SAndreas Boehler$server->addPlugin($browser);
108a1a3b679SAndreas Boehler
109*21d04f73SAndreas Boehlerif($conf['allowdebug'])
110*21d04f73SAndreas Boehler    dbglog('$server->exec()');
111a1a3b679SAndreas Boehler// And off we go!
112a1a3b679SAndreas Boehler$server->exec();
113