summaryrefslogtreecommitdiffstats
path: root/apps/contacts/photo.php
diff options
context:
space:
mode:
authorBart Visscher <bartv@thisnet.nl>2012-02-12 14:57:44 +0100
committerBart Visscher <bartv@thisnet.nl>2012-02-12 15:14:24 +0100
commitfacd4cbe17df60af015fc31692aa46225fa59951 (patch)
tree2280583d0a87a5e1fa1ff6fc85c3fa49081db72e /apps/contacts/photo.php
parent3eff161bbf242b48764f92dbabe157b2e9ed4947 (diff)
downloadnextcloud-server-facd4cbe17df60af015fc31692aa46225fa59951.tar.gz
nextcloud-server-facd4cbe17df60af015fc31692aa46225fa59951.zip
Contacts: Cleanup photo and thumbnail code
Diffstat (limited to 'apps/contacts/photo.php')
-rw-r--r--apps/contacts/photo.php103
1 files changed, 30 insertions, 73 deletions
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 @@
<?php
/**
- * ownCloud - Addressbook
- *
- * @author Jakob Sack
- * @copyright 2011 Jakob Sack mail@jakobsack.de
- *
- * This library is free software; you can redistribute it and/or
- * modify it under the terms of the GNU AFFERO GENERAL PUBLIC LICENSE
- * License as published by the Free Software Foundation; either
- * version 3 of the License, or any later version.
- *
- * This library is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU AFFERO GENERAL PUBLIC LICENSE for more details.
- *
- * You should have received a copy of the GNU Affero General Public
- * License along with this library. If not, see <http://www.gnu.org/licenses/>.
- *
+ * Copyright (c) 2012 Thomas Tanghus <thomas@tanghus.net>
+ * Copyright (c) 2011, 2012 Bart Visscher <bartv@thisnet.nl>
+ * 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.');