summaryrefslogtreecommitdiffstats
path: root/apps/contacts/photo.php
blob: 298f1215e3c467685b629cdd37d832093ba28a57 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
<?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
require_once('../../lib/base.php');
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 = $_GET['id'];

$contact = OC_Contacts_App::getContactVCard($id);
$image = new OC_Image();
if(!$image) {
	getStandardImage();
}
// invalid vcard
if( is_null($contact)) {
	OC_Log::write('contacts','photo.php. The VCard for ID '.$id.' is not RFC compatible',OC_Log::ERROR);
} else {
	OC_Response::enableCaching();
	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.');