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
17dbglog('---- DAVCAL calendarserver.php init');
18
19$hlp = null;
20$hlp =& plugin_load('helper', 'davcal');
21
22if(is_null($hlp))
23{
24    dbglog('Error loading helper plugin');
25    die('Error loading helper plugin');
26}
27
28$baseUri = DOKU_BASE.'lib/plugins/davcal/'.basename(__FILE__).'/';
29
30if($hlp->getConfig('disable_sync') === 1)
31{
32    dbglog('Synchronisation is disabled');
33    die('Synchronisation is disabled');
34}
35
36//Mapping PHP errors to exceptions
37function exception_error_handler($errno, $errstr, $errfile, $errline) {
38    dbglog('Exception occured: '.$errstr);
39    throw new ErrorException($errstr, 0, $errno, $errfile, $errline);
40}
41//set_error_handler("exception_error_handler");
42
43// Files we need
44require_once(DOKU_PLUGIN.'davcal/vendor/autoload.php');
45require_once(DOKU_PLUGIN.'davcal/authBackendDokuwiki.php');
46require_once(DOKU_PLUGIN.'davcal/principalBackendDokuwiki.php');
47require_once(DOKU_PLUGIN.'davcal/calendarBackendDokuwiki.php');
48
49// Backends - our DokuWiki backends
50$authBackend = new DokuWikiSabreAuthBackend();
51$calendarBackend = new DokuWikiSabreCalendarBackend($hlp);
52$principalBackend = new DokuWikiSabrePrincipalBackend();
53
54// Directory structure
55$tree = array(
56    new Sabre\CalDAV\Principal\Collection($principalBackend),
57    new Sabre\CalDAV\CalendarRoot($principalBackend, $calendarBackend),
58);
59
60$server = new Sabre\DAV\Server($tree);
61
62if (isset($baseUri))
63    $server->setBaseUri($baseUri);
64
65/* Server Plugins */
66$authPlugin = new Sabre\DAV\Auth\Plugin($authBackend);
67$server->addPlugin($authPlugin);
68
69$aclPlugin = new Sabre\DAVACL\Plugin();
70$server->addPlugin($aclPlugin);
71
72/* CalDAV support */
73$caldavPlugin = new Sabre\CalDAV\Plugin();
74$server->addPlugin($caldavPlugin);
75
76/* Calendar subscription support */
77//$server->addPlugin(
78//    new Sabre\CalDAV\Subscriptions\Plugin()
79//);
80
81/* Calendar scheduling support */
82//$server->addPlugin(
83//    new Sabre\CalDAV\Schedule\Plugin()
84//);
85
86/* WebDAV-Sync plugin */
87$server->addPlugin(new Sabre\DAV\Sync\Plugin());
88
89// Support for html frontend
90$browser = new Sabre\DAV\Browser\Plugin();
91$server->addPlugin($browser);
92
93dbglog('$server->exec()');
94// And off we go!
95$server->exec();
96