1
0
mirror of https://github.com/owncloudarchive/contacts.git synced 2024-12-10 21:24:33 +01:00
OwncloudContactsOfficial/photo.php

83 lines
2.0 KiB
PHP
Raw Normal View History

2011-08-06 22:32:06 +02:00
<?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.
2011-08-06 22:32:06 +02:00
*/
// Init owncloud
2012-05-01 22:59:38 +02:00
OCP\User::checkLoggedIn();
2012-05-02 19:08:37 +02:00
OCP\App::checkAppEnabled('contacts');
2011-08-06 22:32:06 +02:00
2012-07-20 17:09:03 +02:00
function getStandardImage() {
//OCP\Response::setExpiresHeader('P10D');
2012-05-03 10:46:27 +02:00
OCP\Response::enableCaching();
OCP\Response::redirect(OCP\Util::imagePath('contacts', 'person_large.png'));
2012-02-17 19:04:12 +01:00
}
$id = isset($_GET['id']) ? $_GET['id'] : null;
$etag = null;
$caching = null;
if(!$id) {
getStandardImage();
}
2011-08-06 22:32:06 +02:00
if(!extension_loaded('gd') || !function_exists('gd_info')) {
OCP\Util::writeLog('contacts',
2012-07-20 17:09:03 +02:00
'photo.php. GD module not installed', OCP\Util::DEBUG);
getStandardImage();
}
$contact = OC_Contacts_App::getContactVCard($id);
$image = new OC_Image();
2012-07-20 17:09:03 +02:00
if (!$image) {
2012-02-17 19:04:12 +01:00
getStandardImage();
}
// invalid vcard
2012-07-20 17:09:03 +02:00
if (is_null($contact)) {
OCP\Util::writeLog('contacts',
'photo.php. The VCard for ID ' . $id . ' is not RFC compatible',
2012-07-20 17:09:03 +02:00
OCP\Util::ERROR);
} else {
// Photo :-)
2012-07-20 17:09:03 +02:00
if ($image->loadFromBase64($contact->getAsString('PHOTO'))) {
// OK
$etag = md5($contact->getAsString('PHOTO'));
2011-08-06 22:32:06 +02:00
}
else
// Logo :-/
2012-07-20 17:09:03 +02:00
if ($image->loadFromBase64($contact->getAsString('LOGO'))) {
// OK
$etag = md5($contact->getAsString('LOGO'));
}
if ($image->valid()) {
$modified = OC_Contacts_App::lastModified($contact);
// Force refresh if modified within the last minute.
if(!is_null($modified)) {
$caching = (time() - $modified->format('U') > 60) ? null : 0;
}
OCP\Response::enableCaching($caching);
if(!is_null($modified)) {
OCP\Response::setLastModifiedHeader($modified);
}
if($etag) {
OCP\Response::setETagHeader($etag);
}
$max_size = 200;
2012-07-20 17:09:03 +02:00
if ($image->width() > $max_size || $image->height() > $max_size) {
$image->resize($max_size);
2011-08-06 22:32:06 +02:00
}
}
}
if (!$image->valid()) {
// Not found :-(
2012-02-17 19:04:12 +01:00
getStandardImage();
}
header('Content-Type: '.$image->mimeType());
$image->show();