aboutsummaryrefslogtreecommitdiffstats
path: root/apps/dav/lib/carddav/converter.php
diff options
context:
space:
mode:
authorThomas Müller <thomas.mueller@tmit.eu>2015-11-30 22:28:36 +0100
committerThomas Müller <thomas.mueller@tmit.eu>2015-12-02 09:14:41 +0100
commit599ba31edcfc3cd9ffa659257c1686d6d5a73af0 (patch)
treecbff398e9c628f014dc7b4829deb06f3e9a13ffb /apps/dav/lib/carddav/converter.php
parent906777dc9c8e0d9075e6a8d8c7f6eeb7c07e5256 (diff)
downloadnextcloud-server-599ba31edcfc3cd9ffa659257c1686d6d5a73af0.tar.gz
nextcloud-server-599ba31edcfc3cd9ffa659257c1686d6d5a73af0.zip
Specify the email type and set name properly
Diffstat (limited to 'apps/dav/lib/carddav/converter.php')
-rw-r--r--apps/dav/lib/carddav/converter.php39
1 files changed, 35 insertions, 4 deletions
diff --git a/apps/dav/lib/carddav/converter.php b/apps/dav/lib/carddav/converter.php
index 3aa3639ffa3..eb2ee1f0604 100644
--- a/apps/dav/lib/carddav/converter.php
+++ b/apps/dav/lib/carddav/converter.php
@@ -43,9 +43,10 @@ class Converter {
$vCard->add(new Text($vCard, 'UID', $uid));
if (!empty($displayName)) {
$vCard->add(new Text($vCard, 'FN', $displayName));
+ $vCard->add(new Text($vCard, 'N', $this->splitFullName($displayName)));
}
if (!empty($emailAddress)) {
- $vCard->add(new Text($vCard, 'EMAIL', $emailAddress));
+ $vCard->add(new Text($vCard, 'EMAIL', $emailAddress, ['TYPE' => 'OTHER']));
}
if (!empty($cloudId)) {
$vCard->add(new Text($vCard, 'CLOUD', $cloudId));
@@ -67,18 +68,24 @@ class Converter {
$image = $user->getAvatarImage(-1);
$updated = false;
- if(!is_null($vCard->FN) && $vCard->FN->getValue() !== $displayName) {
+ if((is_null($vCard->FN) && !empty($image)) || (!is_null($vCard->FN) && $vCard->FN->getValue() !== $displayName)) {
$vCard->FN = new Text($vCard, 'FN', $displayName);
+ unset($vCard->N);
+ $vCard->add(new Text($vCard, 'N', $this->splitFullName($displayName)));
$updated = true;
}
- if(!is_null($vCard->EMail) && $vCard->EMail->getValue() !== $emailAddress) {
+ if((is_null($vCard->EMail) && !empty($image)) || (!is_null($vCard->EMail) && $vCard->EMail->getValue() !== $emailAddress)) {
$vCard->EMAIL = new Text($vCard, 'EMAIL', $emailAddress);
$updated = true;
}
- if(!is_null($vCard->CLOUD) && $vCard->CLOUD->getValue() !== $cloudId) {
+ if((is_null($vCard->CLOUD) && !empty($image)) || (!is_null($vCard->CLOUD) && $vCard->CLOUD->getValue() !== $cloudId)) {
$vCard->CLOUD = new Text($vCard, 'CLOUD', $cloudId);
$updated = true;
}
+ if((is_null($vCard->PHOTO) && !empty($image)) || (!is_null($vCard->PHOTO) && $vCard->PHOTO->getValue() !== $image)) {
+ $vCard->add('PHOTO', $image->data(), ['ENCODING' => 'b', 'TYPE' => $image->mimeType()]);
+ $updated = true;
+ }
if (empty($emailAddress) && !is_null($vCard->EMAIL)) {
unset($vCard->EMAIL);
@@ -95,4 +102,28 @@ class Converter {
return $updated;
}
+
+ /**
+ * @param string $fullName
+ * @return string[]
+ */
+ public function splitFullName($fullName) {
+ // Very basic western style parsing. I'm not gonna implement
+ // https://github.com/android/platform_packages_providers_contactsprovider/blob/master/src/com/android/providers/contacts/NameSplitter.java ;)
+
+ $elements = explode(' ', $fullName);
+ $result = ['', '', '', '', ''];
+ if (count($elements) > 2) {
+ $result[0] = implode(' ', array_slice($elements, count($elements)-1));
+ $result[1] = $elements[0];
+ $result[2] = implode(' ', array_slice($elements, 1, count($elements)-2));
+ } elseif (count($elements) === 2) {
+ $result[0] = $elements[1];
+ $result[1] = $elements[0];
+ } else {
+ $result[0] = $elements[0];
+ }
+
+ return $result;
+ }
}