2011-08-06 22:32:06 +02:00
|
|
|
<?php
|
|
|
|
/**
|
2012-02-12 14:57:44 +01:00
|
|
|
* 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.
|
2011-08-06 22:32:06 +02:00
|
|
|
*/
|
|
|
|
|
|
|
|
// Init owncloud
|
|
|
|
require_once('../../lib/base.php');
|
2011-09-30 23:10:08 +02:00
|
|
|
OC_Util::checkLoggedIn();
|
2011-09-30 23:05:10 +02:00
|
|
|
OC_Util::checkAppEnabled('contacts');
|
2011-08-06 22:32:06 +02:00
|
|
|
|
2012-02-17 19:04:12 +01:00
|
|
|
function getStandardImage(){
|
|
|
|
OC_Response::setExpiresHeader('P10D');
|
|
|
|
OC_Response::enableCaching();
|
|
|
|
OC_Response::redirect(OC_Helper::imagePath('contacts', 'person_large.png'));
|
|
|
|
}
|
|
|
|
|
2011-08-06 22:32:06 +02:00
|
|
|
$id = $_GET['id'];
|
|
|
|
|
2012-02-12 14:57:44 +01:00
|
|
|
$contact = OC_Contacts_App::getContactVCard($id);
|
2012-01-19 16:04:39 +01:00
|
|
|
$image = new OC_Image();
|
2012-02-17 19:04:12 +01:00
|
|
|
if(!$image) {
|
|
|
|
getStandardImage();
|
|
|
|
}
|
2011-09-17 00:26:57 +02:00
|
|
|
// invalid vcard
|
2012-02-12 14:57:44 +01:00
|
|
|
if( is_null($contact)) {
|
|
|
|
OC_Log::write('contacts','photo.php. The VCard for ID '.$id.' is not RFC compatible',OC_Log::ERROR);
|
2012-01-19 16:04:39 +01:00
|
|
|
} else {
|
2012-02-13 22:47:31 +01:00
|
|
|
OC_Response::enableCaching();
|
2012-02-12 17:20:30 +01:00
|
|
|
OC_Contacts_App::setLastModifiedHeader($contact);
|
|
|
|
|
2012-01-19 16:04:39 +01:00
|
|
|
// Photo :-)
|
2012-02-12 14:57:44 +01:00
|
|
|
if($image->loadFromBase64($contact->getAsString('PHOTO'))) {
|
|
|
|
// OK
|
2012-02-12 17:20:30 +01:00
|
|
|
OC_Response::setETagHeader(md5($contact->getAsString('PHOTO')));
|
2011-08-06 22:32:06 +02:00
|
|
|
}
|
2012-02-12 14:57:44 +01:00
|
|
|
else
|
|
|
|
// Logo :-/
|
|
|
|
if($image->loadFromBase64($contact->getAsString('LOGO'))) {
|
|
|
|
// OK
|
2012-02-12 17:20:30 +01:00
|
|
|
OC_Response::setETagHeader(md5($contact->getAsString('LOGO')));
|
2012-02-12 14:57:44 +01:00
|
|
|
}
|
|
|
|
if ($image->valid()) {
|
|
|
|
$max_size = 200;
|
|
|
|
if($image->width() > $max_size ||
|
|
|
|
$image->height() > $max_size) {
|
|
|
|
$image->resize($max_size);
|
2011-08-06 22:32:06 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2012-02-12 14:57:44 +01:00
|
|
|
if (!$image->valid()) {
|
|
|
|
// Not found :-(
|
2012-02-17 19:04:12 +01:00
|
|
|
getStandardImage();
|
|
|
|
//$image->loadFromFile('img/person_large.png');
|
2012-02-12 14:57:44 +01:00
|
|
|
}
|
|
|
|
header('Content-Type: '.$image->mimeType());
|
|
|
|
$image->show();
|
|
|
|
//echo OC_Contacts_App::$l10n->t('This card does not contain a photo.');
|