summaryrefslogtreecommitdiffstats
path: root/apps
diff options
context:
space:
mode:
authorJoas Schilling <coding@schilljs.com>2016-08-30 12:08:39 +0200
committerJoas Schilling <coding@schilljs.com>2016-08-30 12:08:39 +0200
commit0c4d471c18eaefc41453a5fad2bf9788f4e56ca2 (patch)
tree083a5c218a498ca54aa7d33d381fbba82aef20c0 /apps
parentdd2482e2c27c9e9e84675dc1fcfb7fa276070123 (diff)
downloadnextcloud-server-0c4d471c18eaefc41453a5fad2bf9788f4e56ca2.tar.gz
nextcloud-server-0c4d471c18eaefc41453a5fad2bf9788f4e56ca2.zip
Correctly handle multi-values when converting VCards to array
Diffstat (limited to 'apps')
-rw-r--r--apps/dav/lib/CardDAV/AddressBookImpl.php42
1 files changed, 41 insertions, 1 deletions
diff --git a/apps/dav/lib/CardDAV/AddressBookImpl.php b/apps/dav/lib/CardDAV/AddressBookImpl.php
index c83ee613d37..9de54eec33d 100644
--- a/apps/dav/lib/CardDAV/AddressBookImpl.php
+++ b/apps/dav/lib/CardDAV/AddressBookImpl.php
@@ -28,6 +28,7 @@ use OCP\Constants;
use OCP\IAddressBook;
use OCP\IURLGenerator;
use Sabre\VObject\Component\VCard;
+use Sabre\VObject\Property;
use Sabre\VObject\Property\Text;
use Sabre\VObject\Reader;
use Sabre\VObject\UUIDUtil;
@@ -225,7 +226,7 @@ class AddressBookImpl implements IAddressBook {
];
foreach ($vCard->children as $property) {
- $result[$property->name] = $property->getValue();
+ /** @var \Sabre\VObject\Property\Unknown $property */
if ($property->name === 'PHOTO' && $property->getValueType() === 'BINARY') {
$url = $this->urlGenerator->getAbsoluteURL(
$this->urlGenerator->linkTo('', 'remote.php') . '/dav/');
@@ -237,14 +238,53 @@ class AddressBookImpl implements IAddressBook {
]) . '?photo';
$result['PHOTO'] = 'VALUE=uri:' . $url;
+
+ } else if ($property->name === 'X-SOCIALPROFILE') {
+ $type = $this->getTypeFromProperty($property);
+
+ // Type is the social network, when it's empty we don't need this.
+ if ($type !== null) {
+ if (!isset($result[$property->name])) {
+ $result[$property->name] = [];
+ }
+ $result[$property->name][$type] = $property->getValue();
+ }
+
+ // The following properties can be set multiple times
+ } else if (in_array($property->name, ['CLOUD', 'EMAIL', 'IMPP', 'TEL', 'URL'])) {
+ if (!isset($result[$property->name])) {
+ $result[$property->name] = [];
+ }
+
+ $result[$property->name][] = $property->getValue();
+
} else {
$result[$property->name] = $property->getValue();
}
}
+
if ($this->addressBookInfo['principaluri'] === 'principals/system/system' &&
$this->addressBookInfo['uri'] === 'system') {
$result['isLocalSystemBook'] = true;
}
return $result;
}
+
+ /**
+ * Get the type of the current property
+ *
+ * @param Property $property
+ * @return null|string
+ */
+ protected function getTypeFromProperty(Property $property) {
+ $parameters = $property->parameters();
+ // Type is the social network, when it's empty we don't need this.
+ if (isset($parameters['TYPE'])) {
+ /** @var \Sabre\VObject\Parameter $type */
+ $type = $parameters['TYPE'];
+ return $type->getValue();
+ }
+
+ return null;
+ }
}