summaryrefslogtreecommitdiffstats
path: root/apps
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
parent3eff161bbf242b48764f92dbabe157b2e9ed4947 (diff)
downloadnextcloud-server-facd4cbe17df60af015fc31692aa46225fa59951.tar.gz
nextcloud-server-facd4cbe17df60af015fc31692aa46225fa59951.zip
Contacts: Cleanup photo and thumbnail code
Diffstat (limited to 'apps')
-rw-r--r--apps/contacts/photo.php103
-rw-r--r--apps/contacts/thumbnail.php71
2 files changed, 69 insertions, 105 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.');
diff --git a/apps/contacts/thumbnail.php b/apps/contacts/thumbnail.php
index b981fdbe1e7..b44db95b390 100644
--- a/apps/contacts/thumbnail.php
+++ b/apps/contacts/thumbnail.php
@@ -29,15 +29,11 @@ OC_Util::checkAppEnabled('contacts');
function getStandardImage(){
$date = new DateTime('now');
$date->add(new DateInterval('P10D'));
- header('Expires: '.$date->format(DateTime::RFC850));
+ header('Expires: '.$date->format(DateTime::RFC2822));
header('Cache-Control: cache');
header('Pragma: cache');
+ header("HTTP/1.1 307 Temporary Redirect");
header('Location: '.OC_Helper::imagePath('contacts', 'person.png'));
- exit();
-// $src_img = imagecreatefrompng('img/person.png');
-// header('Content-Type: image/png');
-// imagepng($src_img);
-// imagedestroy($src_img);
}
if(!function_exists('imagecreatefromjpeg')) {
@@ -50,10 +46,10 @@ $id = $_GET['id'];
$l10n = new OC_L10N('contacts');
-$content = OC_Contacts_App::getContactVCard($id);
+$contact = OC_Contacts_App::getContactVCard($id);
// invalid vcard
-if( is_null($content)){
+if( is_null($contact)){
OC_Log::write('contacts','thumbnail.php. The VCard for ID '.$id.' is not RFC compatible',OC_Log::ERROR);
getStandardImage();
exit();
@@ -62,34 +58,45 @@ if( is_null($content)){
$thumbnail_size = 23;
// Find the photo from VCard.
-foreach($content->children as $child){
- if($child->name == 'PHOTO'){
- $image = new OC_Image();
- if($image->loadFromBase64($child->value)) {
- if($image->centerCrop()) {
- if($image->resize($thumbnail_size)) {
- header('ETag: '.md5($child->value));
- if(!$image()) {
- OC_Log::write('contacts','thumbnail.php. Couldn\'t display thumbnail for ID '.$id,OC_Log::ERROR);
- getStandardImage();
- exit();
- }
- } else {
- OC_Log::write('contacts','thumbnail.php. Couldn\'t resize thumbnail for ID '.$id,OC_Log::ERROR);
- getStandardImage();
- exit();
- }
- }else{
- OC_Log::write('contacts','thumbnail.php. Couldn\'t crop thumbnail for ID '.$id,OC_Log::ERROR);
- getStandardImage();
+$image = new OC_Image();
+$photo = $contact->getAsString('PHOTO');
+$etag = md5($photo);
+$rev_string = $contact->getAsString('REV');
+if ($rev_string) {
+ $rev = DateTime::createFromFormat(DateTime::W3C, $rev_string);
+ $last_modified_time = $rev->format(DateTime::RFC2822);
+} else {
+ $last_modified_time = null;
+}
+
+header('Cache-Control: cache');
+header('Pragma: cache');
+if ($rev_string) {
+ header('Last-Modified: '.$last_modified_time);
+}
+header('ETag: '.$etag);
+
+if (@trim($_SERVER['HTTP_IF_MODIFIED_SINCE']) == $last_modified_time ||
+ @trim($_SERVER['HTTP_IF_NONE_MATCH']) == $etag) {
+ header('HTTP/1.1 304 Not Modified');
+ exit;
+}
+
+if($image->loadFromBase64($photo)) {
+ if($image->centerCrop()) {
+ if($image->resize($thumbnail_size)) {
+ if($image->show()) {
exit();
+ } else {
+ OC_Log::write('contacts','thumbnail.php. Couldn\'t display thumbnail for ID '.$id,OC_Log::ERROR);
}
} else {
- OC_Log::write('contacts','thumbnail.php. Couldn\'t load image string for ID '.$id,OC_Log::ERROR);
- getStandardImage();
- exit();
+ OC_Log::write('contacts','thumbnail.php. Couldn\'t resize thumbnail for ID '.$id,OC_Log::ERROR);
}
- exit();
+ }else{
+ OC_Log::write('contacts','thumbnail.php. Couldn\'t crop thumbnail for ID '.$id,OC_Log::ERROR);
}
+} else {
+ OC_Log::write('contacts','thumbnail.php. Couldn\'t load image string for ID '.$id,OC_Log::ERROR);
}
getStandardImage();