Plugin.php 2.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  1. <?php
  2. /**
  3. * @copyright Copyright (c) 2016, ownCloud, Inc.
  4. *
  5. * @author Christoph Wurst <christoph@winzerhof-wurst.at>
  6. * @author Georg Ehrke <oc.list@georgehrke.com>
  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. public 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. [, $principalId] = \Sabre\Uri\split($principal);
  43. return self::ADDRESSBOOK_ROOT . '/users/' . $principalId;
  44. }
  45. if (strrpos($principal, 'principals/groups', -strlen($principal)) !== false) {
  46. [, $principalId] = \Sabre\Uri\split($principal);
  47. return self::ADDRESSBOOK_ROOT . '/groups/' . $principalId;
  48. }
  49. if (strrpos($principal, 'principals/system', -strlen($principal)) !== false) {
  50. [, $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. public 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. }