From facd4cbe17df60af015fc31692aa46225fa59951 Mon Sep 17 00:00:00 2001 From: Bart Visscher Date: Sun, 12 Feb 2012 14:57:44 +0100 Subject: Contacts: Cleanup photo and thumbnail code --- apps/contacts/photo.php | 103 ++++++++++++++---------------------------------- 1 file changed, 30 insertions(+), 73 deletions(-) (limited to 'apps/contacts/photo.php') diff --git a/apps/contacts/photo.php b/apps/contacts/photo.php index 9566764e70a..0b7769ebe07 100644 --- a/apps/contacts/photo.php +++ b/apps/contacts/photo.php @@ -1,23 +1,11 @@ . - * + * Copyright (c) 2012 Thomas Tanghus + * Copyright (c) 2011, 2012 Bart Visscher + * Copyright (c) 2011 Jakob Sack mail@jakobsack.de + * This file is licensed under the Affero General Public License version 3 or + * later. + * See the COPYING-README file. */ // Init owncloud @@ -29,67 +17,36 @@ $id = $_GET['id']; if(isset($GET['refresh'])) { header("Cache-Control: no-cache, no-store, must-revalidate"); } -$l10n = new OC_L10N('contacts'); -$content = OC_Contacts_App::getContactVCard($id); +$contact = OC_Contacts_App::getContactVCard($id); $image = new OC_Image(); // invalid vcard -if( is_null($content)){ - $image->loadFromFile('img/person_large.png'); - header('Content-Type: '.$image->mimeType()); - $image(); - //echo $l10n->t('This card is not RFC compatible.'); - exit(); +if( is_null($contact)) { + OC_Log::write('contacts','photo.php. The VCard for ID '.$id.' is not RFC compatible',OC_Log::ERROR); } else { // Photo :-) - foreach($content->children as $child){ - if($child->name == 'PHOTO'){ - $mime = 'image/jpeg'; - foreach($child->parameters as $parameter){ - if( $parameter->name == 'TYPE' ){ - $mime = $parameter->value; - } - } - if($image->loadFromBase64($child->value)) { - if($image->width() > 200 || $image->height() > 200) { - $image->resize(200); - } - header('Content-Type: '.$mime); - $image(); - exit(); - } else { - $image->loadFromFile('img/person_large.png'); - header('Content-Type: '.$image->mimeType()); - $image(); - } - //$photo = base64_decode($child->value); - //header('Content-Type: '.$mime); - //header('Content-Length: ' . strlen($photo)); - //echo $photo; - //exit(); - } + if($image->loadFromBase64($contact->getAsString('PHOTO'))) { + // OK + header('ETag: '.md5($contact->getAsString('PHOTO'))); } -} -$image->loadFromFile('img/person_large.png'); -header('Content-Type: '.$image->mimeType()); -$image(); -/* -// Logo :-/ -foreach($content->children as $child){ - if($child->name == 'PHOTO'){ - $mime = 'image/jpeg'; - foreach($child->parameters as $parameter){ - if($parameter->name == 'TYPE'){ - $mime = $parameter->value; - } + else + // Logo :-/ + if($image->loadFromBase64($contact->getAsString('LOGO'))) { + // OK + header('ETag: '.md5($contact->getAsString('LOGO'))); + } + if ($image->valid()) { + $max_size = 200; + if($image->width() > $max_size || + $image->height() > $max_size) { + $image->resize($max_size); } - $photo = base64_decode($child->value()); - header('Content-Type: '.$mime); - header('Content-Length: ' . strlen($photo)); - echo $photo; - exit(); } } -*/ -// Not found :-( -//echo $l10n->t('This card does not contain a photo.'); +if (!$image->valid()) { + // Not found :-( + $image->loadFromFile('img/person_large.png'); +} +header('Content-Type: '.$image->mimeType()); +$image->show(); +//echo OC_Contacts_App::$l10n->t('This card does not contain a photo.'); -- cgit v1.2.3