Plugin.php 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637
  1. <?php
  2. /**
  3. * SPDX-FileCopyrightText: 2017-2024 Nextcloud GmbH and Nextcloud contributors
  4. * SPDX-FileCopyrightText: 2016 ownCloud GmbH.
  5. * SPDX-License-Identifier: AGPL-3.0-only
  6. */
  7. namespace OCA\DAV\CalDAV;
  8. class Plugin extends \Sabre\CalDAV\Plugin {
  9. public const SYSTEM_CALENDAR_ROOT = 'system-calendars';
  10. /**
  11. * Returns the path to a principal's calendar home.
  12. *
  13. * The return url must not end with a slash.
  14. * This function should return null in case a principal did not have
  15. * a calendar home.
  16. *
  17. * @param string $principalUrl
  18. * @return string|null
  19. */
  20. public function getCalendarHomeForPrincipal($principalUrl) {
  21. if (strrpos($principalUrl, 'principals/users', -strlen($principalUrl)) !== false) {
  22. [, $principalId] = \Sabre\Uri\split($principalUrl);
  23. return self::CALENDAR_ROOT . '/' . $principalId;
  24. }
  25. if (strrpos($principalUrl, 'principals/calendar-resources', -strlen($principalUrl)) !== false) {
  26. [, $principalId] = \Sabre\Uri\split($principalUrl);
  27. return self::SYSTEM_CALENDAR_ROOT . '/calendar-resources/' . $principalId;
  28. }
  29. if (strrpos($principalUrl, 'principals/calendar-rooms', -strlen($principalUrl)) !== false) {
  30. [, $principalId] = \Sabre\Uri\split($principalUrl);
  31. return self::SYSTEM_CALENDAR_ROOT . '/calendar-rooms/' . $principalId;
  32. }
  33. }
  34. }