1
0
mirror of https://github.com/owncloudarchive/contacts.git synced 2024-11-29 11:24:11 +01:00
OwncloudContactsOfficial/photo.php

68 lines
1.7 KiB
PHP
Executable File

<?php
/**
* 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
OC_Util::checkLoggedIn();
OC_Util::checkAppEnabled('contacts');
function getStandardImage(){
OC_Response::setExpiresHeader('P10D');
OC_Response::enableCaching();
OC_Response::redirect(OC_Helper::imagePath('contacts', 'person_large.png'));
}
$id = isset($_GET['id']) ? $_GET['id'] : null;
$caching = isset($_GET['refresh']) ? 0 : null;
if(is_null($id)) {
getStandardImage();
}
$contact = OC_Contacts_App::getContactVCard($id);
$image = new OC_Image();
if(!$image) {
getStandardImage();
}
// invalid vcard
if( is_null($contact)) {
OCP\Util::writeLog('contacts','photo.php. The VCard for ID '.$id.' is not RFC compatible',OCP\Util::ERROR);
} else {
OC_Response::enableCaching($caching);
OC_Contacts_App::setLastModifiedHeader($contact);
// Photo :-)
if($image->loadFromBase64($contact->getAsString('PHOTO'))) {
// OK
OC_Response::setETagHeader(md5($contact->getAsString('PHOTO')));
}
else
// Logo :-/
if($image->loadFromBase64($contact->getAsString('LOGO'))) {
// OK
OC_Response::setETagHeader(md5($contact->getAsString('LOGO')));
}
if ($image->valid()) {
$max_size = 200;
if($image->width() > $max_size ||
$image->height() > $max_size) {
$image->resize($max_size);
}
}
}
if (!$image->valid()) {
// Not found :-(
getStandardImage();
//$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.');