diff options
Diffstat (limited to 'apps/dav/lib/CardDAV/AddressBookImpl.php')
-rw-r--r-- | apps/dav/lib/CardDAV/AddressBookImpl.php | 44 |
1 files changed, 34 insertions, 10 deletions
diff --git a/apps/dav/lib/CardDAV/AddressBookImpl.php b/apps/dav/lib/CardDAV/AddressBookImpl.php index 310be695185..b26f81766c6 100644 --- a/apps/dav/lib/CardDAV/AddressBookImpl.php +++ b/apps/dav/lib/CardDAV/AddressBookImpl.php @@ -24,6 +24,7 @@ namespace OCA\DAV\CardDAV; use OCP\Constants; use OCP\IAddressBook; +use OCP\IURLGenerator; use Sabre\VObject\Component\VCard; use Sabre\VObject\Property\Text; use Sabre\VObject\Reader; @@ -40,21 +41,27 @@ class AddressBookImpl implements IAddressBook { /** @var AddressBook */ private $addressBook; + /** @var IURLGenerator */ + private $urlGenerator; + /** * AddressBookImpl constructor. * * @param AddressBook $addressBook * @param array $addressBookInfo * @param CardDavBackend $backend + * @param IUrlGenerator $urlGenerator */ public function __construct( AddressBook $addressBook, array $addressBookInfo, - CardDavBackend $backend) { + CardDavBackend $backend, + IURLGenerator $urlGenerator) { $this->addressBook = $addressBook; $this->addressBookInfo = $addressBookInfo; $this->backend = $backend; + $this->urlGenerator = $urlGenerator; } /** @@ -83,11 +90,11 @@ class AddressBookImpl implements IAddressBook { * @since 5.0.0 */ public function search($pattern, $searchProperties, $options) { - $result = $this->backend->search($this->getKey(), $pattern, $searchProperties); + $results = $this->backend->search($this->getKey(), $pattern, $searchProperties); $vCards = []; - foreach ($result as $cardData) { - $vCards[] = $this->vCard2Array($this->readCard($cardData)); + foreach ($results as $result) { + $vCards[] = $this->vCard2Array($result['uri'], $this->readCard($result['carddata'])); } return $vCards; @@ -100,13 +107,12 @@ class AddressBookImpl implements IAddressBook { */ public function createOrUpdate($properties) { $update = false; - if (!isset($properties['UID'])) { // create a new contact + if (!isset($properties['URI'])) { // create a new contact $uid = $this->createUid(); $uri = $uid . '.vcf'; $vCard = $this->createEmptyVCard($uid); } else { // update existing contact - $uid = $properties['UID']; - $uri = $uid . '.vcf'; + $uri = $properties['URI']; $vCardData = $this->backend->getCard($this->getKey(), $uri); $vCard = $this->readCard($vCardData['carddata']); $update = true; @@ -122,7 +128,7 @@ class AddressBookImpl implements IAddressBook { $this->backend->createCard($this->getKey(), $uri, $vCard->serialize()); } - return $this->vCard2Array($vCard); + return $this->vCard2Array($uri, $vCard); } @@ -207,13 +213,31 @@ class AddressBookImpl implements IAddressBook { /** * create array with all vCard properties * + * @param string $uri * @param VCard $vCard * @return array */ - protected function vCard2Array(VCard $vCard) { - $result = []; + protected function vCard2Array($uri, VCard $vCard) { + $result = [ + 'URI' => $uri, + ]; + foreach ($vCard->children as $property) { $result[$property->name] = $property->getValue(); + if ($property->name === 'PHOTO' && $property->getValueType() === 'BINARY') { + $url = $this->urlGenerator->getAbsoluteURL( + $this->urlGenerator->linkTo('', 'remote.php') . '/dav/'); + $url .= implode('/', [ + 'addressbooks', + substr($this->addressBookInfo['principaluri'], 11), //cut off 'principals/' + $this->addressBookInfo['uri'], + $uri + ]) . '?photo'; + + $result['PHOTO'] = 'VALUE=uri:' . $url; + } else { + $result[$property->name] = $property->getValue(); + } } if ($this->addressBookInfo['principaluri'] === 'principals/system/system' && $this->addressBookInfo['uri'] === 'system') { |