calendars.php 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. <?php
  2. require_once(__DIR__.'/../../common.php');
  3. require_once(__DIR__.'/constant.php');
  4. require_once __ROOT__.'/lib/sabre/autoload.php';
  5. global $conf;
  6. $pdo = new PDO('sqlite:'.__ROOT__.'/'.DB_NAME);
  7. $pdo->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
  8. // Backends
  9. $authBackend = new Sabre\DAV\Auth\Backend\BasicCallBack(function($userName, $password) {
  10. $myUser = User::exist($userName, $password,false,false);
  11. if(!$myUser){
  12. $userManager = new User();
  13. $myUser = $userManager->load(array('token'=>$password));
  14. }
  15. return $myUser!=false;
  16. });
  17. $principalBackend = new Sabre\DAVACL\PrincipalBackend\PDO($pdo);
  18. $principalBackend->tableName = ENTITY_PREFIX.'plugin_caldav_principals';
  19. $principalBackend->groupMembersTableName = ENTITY_PREFIX.'plugin_caldav_groupmembers';
  20. $calendarBackend = new Sabre\CalDAV\Backend\PDO($pdo);
  21. $calendarBackend->calendarTableName = ENTITY_PREFIX.'plugin_caldav_calendars';
  22. $calendarBackend->calendarObjectTableName = ENTITY_PREFIX.'plugin_caldav_calendarobjects';
  23. $calendarBackend->calendarChangesTableName = ENTITY_PREFIX.'plugin_caldav_calendarchanges';
  24. $calendarBackend->schedulingObjectTableName = ENTITY_PREFIX.'plugin_caldav_schedulingobjects';
  25. $calendarBackend->calendarSubscriptionsTableName = ENTITY_PREFIX.'plugin_caldav_calendarsubscriptions';
  26. // Directory structure
  27. $tree = [
  28. new Sabre\CalDAV\Principal\Collection($principalBackend),
  29. new Sabre\CalDAV\CalendarRoot($principalBackend, $calendarBackend),
  30. ];
  31. // The object tree needs in turn to be passed to the server class
  32. $server = new Sabre\DAV\Server($tree);
  33. $server->setBaseUri($conf->get('WEBDAV_CALENDAR_URL'));
  34. // Plugins
  35. $server->addPlugin(new Sabre\DAV\Auth\Plugin($authBackend));
  36. $server->addPlugin(new Sabre\DAVACL\Plugin());
  37. /* CalDAV support */
  38. $caldavPlugin = new Sabre\CalDAV\Plugin();
  39. $server->addPlugin($caldavPlugin);
  40. /* Calendar subscription support */
  41. $server->addPlugin(new Sabre\CalDAV\Subscriptions\Plugin());
  42. /* Calendar scheduling support */
  43. $server->addPlugin(new Sabre\CalDAV\Schedule\Plugin());
  44. /* WebDAV-Sync plugin */
  45. $server->addPlugin(new Sabre\DAV\Sync\Plugin());
  46. // Support for html frontend
  47. $server->addPlugin( new Sabre\DAV\Browser\Plugin());
  48. $server->exec();
  49. ?>