1
0
mirror of https://github.com/owncloudarchive/contacts.git synced 2024-12-01 13:24:10 +01:00

Parse data: photo uris.

This commit is contained in:
Gerald Vogt 2015-08-26 10:49:49 +02:00
parent 111873b948
commit 23a2078365
2 changed files with 37 additions and 4 deletions

View File

@ -407,9 +407,28 @@ class Contact extends VObject\VCard implements IPIMObject {
public function getPhoto() {
$image = new \OCP\Image();
if (isset($this->PHOTO) && $image->loadFromData($this->PHOTO->getValue())) {
return $image;
} elseif (isset($this->LOGO) && $image->loadFromData($this->LOGO->getValue())) {
if (isset($this->PHOTO)) {
$photo = $this->PHOTO;
} elseif (isset($this->LOGO)) {
$photo = $this->LOGO;
} else {
return null;
}
$photovalue = $photo->getValue();
if ( $photo instanceof \Sabre\VObject\Property\Uri && substr($photovalue, 0, 5) === 'data:' ) {
$mimeType = substr($photovalue, 5, strpos($photovalue, ',')-5);
if (strpos($mimeType, ';')) {
$mimeType = substr($mimeType,0,strpos($mimeType, ';'));
}
$photovalue = substr($photovalue, strpos($photovalue,',')+1);
if ($image->loadFromBase64($photovalue)) {
return $image;
}
} elseif ($image->loadFromData($photovalue)) {
return $image;
}

View File

@ -328,8 +328,22 @@ Class Properties {
$app = new App();
$vCard = $app->getContact($backendName, $addressBookId, $contactId);
}
if (!isset($vCard->PHOTO)) {
return false;
}
$image = new \OCP\Image();
if (!isset($vCard->PHOTO) || !$image->loadFromBase64((string)$vCard->PHOTO)) {
$photostring = (string) $vCard->PHOTO;
if ( $vCard->PHOTO instanceof \Sabre\VObject\Property\Uri && substr($photostring, 0, 5) === 'data:' ) {
$mimeType = substr($photostring, 5, strpos($photostring, ',')-5);
if (strpos($mimeType, ';')) {
$mimeType = substr($mimeType,0,strpos($mimeType, ';'));
}
$photostring = substr($photostring, strpos($photostring,',')+1);
}
if (!$image->loadFromBase64($photostring)) {
#\OCP\Util::writeLog('contacts', __METHOD__.', photo: ' . print_r($photostring, true), \OCP\Util::DEBUG);
return false;
}
}