Plugin.php 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. <?php
  2. /**
  3. * @copyright Copyright (c) 2016, ownCloud GmbH.
  4. *
  5. * @author Christoph Wurst <christoph@winzerhof-wurst.at>
  6. * @author Georg Ehrke <oc.list@georgehrke.com>
  7. * @author Roeland Jago Douma <roeland@famdouma.nl>
  8. * @author Thomas Müller <thomas.mueller@tmit.eu>
  9. *
  10. * @license AGPL-3.0
  11. *
  12. * This code is free software: you can redistribute it and/or modify
  13. * it under the terms of the GNU Affero General Public License, version 3,
  14. * as published by the Free Software Foundation.
  15. *
  16. * This program is distributed in the hope that it will be useful,
  17. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  18. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  19. * GNU Affero General Public License for more details.
  20. *
  21. * You should have received a copy of the GNU Affero General Public License, version 3,
  22. * along with this program. If not, see <http://www.gnu.org/licenses/>
  23. *
  24. */
  25. namespace OCA\DAV\CalDAV;
  26. class Plugin extends \Sabre\CalDAV\Plugin {
  27. public const SYSTEM_CALENDAR_ROOT = 'system-calendars';
  28. /**
  29. * Returns the path to a principal's calendar home.
  30. *
  31. * The return url must not end with a slash.
  32. * This function should return null in case a principal did not have
  33. * a calendar home.
  34. *
  35. * @param string $principalUrl
  36. * @return string|null
  37. */
  38. public function getCalendarHomeForPrincipal($principalUrl) {
  39. if (strrpos($principalUrl, 'principals/users', -strlen($principalUrl)) !== false) {
  40. [, $principalId] = \Sabre\Uri\split($principalUrl);
  41. return self::CALENDAR_ROOT . '/' . $principalId;
  42. }
  43. if (strrpos($principalUrl, 'principals/calendar-resources', -strlen($principalUrl)) !== false) {
  44. [, $principalId] = \Sabre\Uri\split($principalUrl);
  45. return self::SYSTEM_CALENDAR_ROOT . '/calendar-resources/' . $principalId;
  46. }
  47. if (strrpos($principalUrl, 'principals/calendar-rooms', -strlen($principalUrl)) !== false) {
  48. [, $principalId] = \Sabre\Uri\split($principalUrl);
  49. return self::SYSTEM_CALENDAR_ROOT . '/calendar-rooms/' . $principalId;
  50. }
  51. }
  52. }