Plugin.php 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. <?php
  2. /**
  3. * SPDX-FileCopyrightText: 2016-2024 Nextcloud GmbH and Nextcloud contributors
  4. * SPDX-FileCopyrightText: 2016 ownCloud, Inc.
  5. * SPDX-License-Identifier: AGPL-3.0-only
  6. */
  7. namespace OCA\DAV\CardDAV;
  8. use OCA\DAV\CardDAV\Xml\Groups;
  9. use Sabre\DAV\INode;
  10. use Sabre\DAV\PropFind;
  11. use Sabre\DAV\Server;
  12. class Plugin extends \Sabre\CardDAV\Plugin {
  13. public function initialize(Server $server) {
  14. $server->on('propFind', [$this, 'propFind']);
  15. parent::initialize($server);
  16. }
  17. /**
  18. * Returns the addressbook home for a given principal
  19. *
  20. * @param string $principal
  21. * @return string|null
  22. */
  23. protected function getAddressbookHomeForPrincipal($principal) {
  24. if (strrpos($principal, 'principals/users', -strlen($principal)) !== false) {
  25. [, $principalId] = \Sabre\Uri\split($principal);
  26. return self::ADDRESSBOOK_ROOT . '/users/' . $principalId;
  27. }
  28. if (strrpos($principal, 'principals/groups', -strlen($principal)) !== false) {
  29. [, $principalId] = \Sabre\Uri\split($principal);
  30. return self::ADDRESSBOOK_ROOT . '/groups/' . $principalId;
  31. }
  32. if (strrpos($principal, 'principals/system', -strlen($principal)) !== false) {
  33. [, $principalId] = \Sabre\Uri\split($principal);
  34. return self::ADDRESSBOOK_ROOT . '/system/' . $principalId;
  35. }
  36. }
  37. /**
  38. * Adds all CardDAV-specific properties
  39. *
  40. * @param PropFind $propFind
  41. * @param INode $node
  42. * @return void
  43. */
  44. public function propFind(PropFind $propFind, INode $node) {
  45. $ns = '{http://owncloud.org/ns}';
  46. if ($node instanceof AddressBook) {
  47. $propFind->handle($ns . 'groups', function () use ($node) {
  48. return new Groups($node->getContactsGroups());
  49. });
  50. }
  51. }
  52. }