]> git.mxchange.org Git - friendica-addons.git/blob - dav/SabreDAV/examples/groupwareserver.php
Merge branch 'master' of git://github.com/friendica/friendica-addons
[friendica-addons.git] / dav / SabreDAV / examples / groupwareserver.php
1 <?php
2
3 /**
4  * This server combines both CardDAV and CalDAV functionality into a single
5  * server. It is assumed that the server runs at the root of a HTTP domain (be
6  * that a domainname-based vhost or a specific TCP port.
7  *
8  * This example also assumes that you're using SQLite and the database has
9  * already been setup (along with the database tables).
10  *
11  * You may choose to use MySQL instead, just change the PDO connection
12  * statement.
13  */
14
15 /**
16  * UTC or GMT is easy to work with, and usually recommended for any
17  * application.
18  */
19 date_default_timezone_set('UTC');
20
21 /**
22  * Make sure this setting is turned on and reflect the root url for your WebDAV
23  * server.
24  *
25  * This can be for example the root / or a complete path to your server script.
26  */
27 $baseUri = '/';
28
29 /**
30  * Database
31  *
32  * Feel free to switch this to MySQL, it will definitely be better for higher
33  * concurrency.
34  */
35 $pdo = new PDO('sqlite:data/db.sqlite');
36 $pdo->setAttribute(PDO::ATTR_ERRMODE,PDO::ERRMODE_EXCEPTION);
37
38 /**
39  * Mapping PHP errors to exceptions.
40  *
41  * While this is not strictly needed, it makes a lot of sense to do so. If an
42  * E_NOTICE or anything appears in your code, this allows SabreDAV to intercept
43  * the issue and send a proper response back to the client (HTTP/1.1 500).
44  */
45 function exception_error_handler($errno, $errstr, $errfile, $errline ) {
46     throw new ErrorException($errstr, 0, $errno, $errfile, $errline);
47 }
48 set_error_handler("exception_error_handler");
49
50 // Autoloader
51 require_once 'lib/Sabre/autoload.php';
52
53 /**
54  * The backends. Yes we do really need all of them.
55  *
56  * This allows any developer to subclass just any of them and hook into their
57  * own backend systems.
58  */
59 $authBackend      = new Sabre_DAV_Auth_Backend_PDO($pdo);
60 $principalBackend = new Sabre_DAVACL_PrincipalBackend_PDO($pdo);
61 $carddavBackend   = new Sabre_CardDAV_Backend_PDO($pdo);
62 $caldavBackend    = new Sabre_CalDAV_Backend_PDO($pdo);
63
64 /**
65  * The directory tree
66  *
67  * Basically this is an array which contains the 'top-level' directories in the
68  * WebDAV server.
69  */
70 $nodes = array(
71     // /principals
72     new Sabre_CalDAV_Principal_Collection($principalBackend),
73     // /calendars
74     new Sabre_CalDAV_CalendarRootNode($principalBackend, $caldavBackend),
75     // /addressbook
76     new Sabre_CardDAV_AddressBookRoot($principalBackend, $carddavBackend),
77 );
78
79 // The object tree needs in turn to be passed to the server class
80 $server = new Sabre_DAV_Server($nodes);
81 $server->setBaseUri($baseUri);
82
83 // Plugins
84 $server->addPlugin(new Sabre_DAV_Auth_Plugin($authBackend,'SabreDAV'));
85 $server->addPlugin(new Sabre_DAV_Browser_Plugin());
86 $server->addPlugin(new Sabre_CalDAV_Plugin());
87 $server->addPlugin(new Sabre_CardDAV_Plugin());
88 $server->addPlugin(new Sabre_DAVACL_Plugin());
89
90 // And off we go!
91 $server->exec();