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