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.4KB

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