1
0

Plugin.php 2.2 KB

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