You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

Plugin.php 2.3KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  1. <?php
  2. /**
  3. * @copyright Copyright (c) 2016, ownCloud, Inc.
  4. *
  5. * @author Georg Ehrke <oc.list@georgehrke.com>
  6. * @author Roeland Jago Douma <roeland@famdouma.nl>
  7. * @author Thomas Müller <thomas.mueller@tmit.eu>
  8. *
  9. * @license AGPL-3.0
  10. *
  11. * This code is free software: you can redistribute it and/or modify
  12. * it under the terms of the GNU Affero General Public License, version 3,
  13. * as published by the Free Software Foundation.
  14. *
  15. * This program is distributed in the hope that it will be useful,
  16. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  17. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  18. * GNU Affero General Public License for more details.
  19. *
  20. * You should have received a copy of the GNU Affero General Public License, version 3,
  21. * along with this program. If not, see <http://www.gnu.org/licenses/>
  22. *
  23. */
  24. namespace OCA\DAV\CardDAV;
  25. use OCA\DAV\CardDAV\Xml\Groups;
  26. use Sabre\DAV\INode;
  27. use Sabre\DAV\PropFind;
  28. use Sabre\DAV\Server;
  29. class Plugin extends \Sabre\CardDAV\Plugin {
  30. function initialize(Server $server) {
  31. $server->on('propFind', [$this, 'propFind']);
  32. parent::initialize($server);
  33. }
  34. /**
  35. * Returns the addressbook home for a given principal
  36. *
  37. * @param string $principal
  38. * @return string|null
  39. */
  40. protected function getAddressbookHomeForPrincipal($principal) {
  41. if (strrpos($principal, 'principals/users', -strlen($principal)) !== false) {
  42. list(, $principalId) = \Sabre\Uri\split($principal);
  43. return self::ADDRESSBOOK_ROOT . '/users/' . $principalId;
  44. }
  45. if (strrpos($principal, 'principals/groups', -strlen($principal)) !== false) {
  46. list(, $principalId) = \Sabre\Uri\split($principal);
  47. return self::ADDRESSBOOK_ROOT . '/groups/' . $principalId;
  48. }
  49. if (strrpos($principal, 'principals/system', -strlen($principal)) !== false) {
  50. list(, $principalId) = \Sabre\Uri\split($principal);
  51. return self::ADDRESSBOOK_ROOT . '/system/' . $principalId;
  52. }
  53. }
  54. /**
  55. * Adds all CardDAV-specific properties
  56. *
  57. * @param PropFind $propFind
  58. * @param INode $node
  59. * @return void
  60. */
  61. function propFind(PropFind $propFind, INode $node) {
  62. $ns = '{http://owncloud.org/ns}';
  63. if ($node instanceof AddressBook) {
  64. $propFind->handle($ns . 'groups', function () use ($node) {
  65. return new Groups($node->getContactsGroups());
  66. });
  67. }
  68. }
  69. }