Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/nextcloud/server.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJoas Schilling <coding@schilljs.com>2016-08-31 13:19:16 +0300
committerJoas Schilling <coding@schilljs.com>2016-08-31 13:19:16 +0300
commitd8adb48147ecd5e2a34a51ebad63f35d438d2edc (patch)
treedf66a14ec53fb49b6a70c76e238a69c9e3b9018c
parentd2a96a69a466f08be9ac1836937d621a1f3a8f71 (diff)
Correctly handle multi-values when converting VCards to array
-rw-r--r--apps/dav/lib/carddav/addressbookimpl.php44
1 files changed, 43 insertions, 1 deletions
diff --git a/apps/dav/lib/carddav/addressbookimpl.php b/apps/dav/lib/carddav/addressbookimpl.php
index ccbafd5ba96..009f0d62ae3 100644
--- a/apps/dav/lib/carddav/addressbookimpl.php
+++ b/apps/dav/lib/carddav/addressbookimpl.php
@@ -26,6 +26,7 @@ namespace OCA\DAV\CardDAV;
use OCP\Constants;
use OCP\IAddressBook;
use Sabre\VObject\Component\VCard;
+use Sabre\VObject\Property;
use Sabre\VObject\Property\Text;
use Sabre\VObject\Reader;
use Sabre\VObject\UUIDUtil;
@@ -214,12 +215,53 @@ class AddressBookImpl implements IAddressBook {
protected function vCard2Array(VCard $vCard) {
$result = [];
foreach ($vCard->children as $property) {
- $result[$property->name] = $property->getValue();
+ /** @var \Sabre\VObject\Property\Unknown $property */
+ 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;
+ }
}