1
0
mirror of https://github.com/owncloudarchive/contacts.git synced 2025-01-18 07:52:21 +01:00

Merge pull request #1030 from gvde/fix-thumbnail-cache

Parse data: photo data uris.
This commit is contained in:
LEDfan 2015-09-09 16:16:57 +02:00
commit 3fc77e00aa
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

@ -333,8 +333,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;
}
}