plugin.php 2.1 KB

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