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