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
|
2012-04-17 19:31:29 +02:00
|
|
|
|
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() {
|
2012-06-05 10:32:12 +02:00
|
|
|
//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-11-22 00:29:37 +01:00
|
|
|
exit;
|
2012-02-17 19:04:12 +01:00
|
|
|
}
|
|
|
|
|
2012-04-22 20:38:17 +02:00
|
|
|
$id = isset($_GET['id']) ? $_GET['id'] : null;
|
2013-03-23 02:02:21 +01:00
|
|
|
$parent = isset($_GET['parent']) ? $_GET['parent'] : null;
|
|
|
|
$backend = isset($_GET['backend']) ? $_GET['backend'] : null;
|
2012-08-09 16:31:04 +02:00
|
|
|
$etag = null;
|
|
|
|
$caching = null;
|
2012-12-10 00:03:10 +01:00
|
|
|
$max_size = 170;
|
2012-04-22 20:38:17 +02:00
|
|
|
|
2012-11-22 00:29:37 +01:00
|
|
|
if(!$id || $id === 'new') {
|
2012-04-22 20:38:17 +02:00
|
|
|
getStandardImage();
|
|
|
|
}
|
2011-08-06 22:32:06 +02:00
|
|
|
|
2012-05-04 23:53:29 +02:00
|
|
|
if(!extension_loaded('gd') || !function_exists('gd_info')) {
|
2012-08-09 16:31:04 +02:00
|
|
|
OCP\Util::writeLog('contacts',
|
2012-07-20 17:09:03 +02:00
|
|
|
'photo.php. GD module not installed', OCP\Util::DEBUG);
|
2012-05-04 23:53:29 +02:00
|
|
|
getStandardImage();
|
|
|
|
}
|
|
|
|
|
2013-03-23 02:02:21 +01:00
|
|
|
$app = new OCA\Contacts\App();
|
|
|
|
$contact = $app->getContact($backend, $parent, $id);
|
2012-01-19 16:04:39 +01:00
|
|
|
$image = new OC_Image();
|
2013-04-12 13:49:55 +02:00
|
|
|
if (!$image || !$contact) {
|
2012-02-17 19:04:12 +01:00
|
|
|
getStandardImage();
|
|
|
|
}
|
2011-09-17 00:26:57 +02:00
|
|
|
// invalid vcard
|
2012-07-20 17:09:03 +02:00
|
|
|
if (is_null($contact)) {
|
2012-08-09 16:31:04 +02:00
|
|
|
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);
|
2012-01-19 16:04:39 +01:00
|
|
|
} else {
|
|
|
|
// Photo :-)
|
2012-11-22 00:14:03 +01:00
|
|
|
if (isset($contact->PHOTO) && $image->loadFromBase64((string)$contact->PHOTO)) {
|
2012-02-12 14:57:44 +01:00
|
|
|
// OK
|
2012-11-22 00:14:03 +01:00
|
|
|
$etag = md5($contact->PHOTO);
|
2011-08-06 22:32:06 +02:00
|
|
|
}
|
2012-02-12 14:57:44 +01:00
|
|
|
else
|
|
|
|
// Logo :-/
|
2012-11-22 00:14:03 +01:00
|
|
|
if (isset($contact->LOGO) && $image->loadFromBase64((string)$contact->LOGO)) {
|
2012-02-12 14:57:44 +01:00
|
|
|
// OK
|
2012-11-22 00:14:03 +01:00
|
|
|
$etag = md5($contact->LOGO);
|
2012-02-12 14:57:44 +01:00
|
|
|
}
|
|
|
|
if ($image->valid()) {
|
2013-03-23 02:02:21 +01:00
|
|
|
$modified = $contact->lastModified();
|
2012-08-09 16:31:04 +02:00
|
|
|
// Force refresh if modified within the last minute.
|
|
|
|
if(!is_null($modified)) {
|
2013-03-23 02:02:21 +01:00
|
|
|
$caching = (time() - $modified > 60) ? null : 0;
|
2012-08-09 16:31:04 +02:00
|
|
|
}
|
|
|
|
OCP\Response::enableCaching($caching);
|
|
|
|
if(!is_null($modified)) {
|
|
|
|
OCP\Response::setLastModifiedHeader($modified);
|
|
|
|
}
|
|
|
|
if($etag) {
|
|
|
|
OCP\Response::setETagHeader($etag);
|
|
|
|
}
|
2012-07-20 17:09:03 +02:00
|
|
|
if ($image->width() > $max_size || $image->height() > $max_size) {
|
2012-02-12 14:57:44 +01:00
|
|
|
$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();
|
2012-02-12 14:57:44 +01:00
|
|
|
}
|
|
|
|
header('Content-Type: '.$image->mimeType());
|
|
|
|
$image->show();
|