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
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
|
<?php
/*
+-----------------------------------------------------------------------+
| program/steps/addressbook/photo.inc |
| |
| This file is part of the Roundcube Webmail client |
| Copyright (C) 2005-2013, The Roundcube Dev Team |
| |
| Licensed under the GNU General Public License version 3 or |
| any later version with exceptions for skins & plugins. |
| See the README file for a full license statement. |
| |
| PURPOSE: |
| Show contact photo |
| |
+-----------------------------------------------------------------------+
| Author: Thomas Bruederli <roundcube@gmail.com> |
| Author: Aleksander Machniak <alec@alec.pl> |
+-----------------------------------------------------------------------+
*/
// Get contact ID and source ID from request
$cids = rcmail_get_cids();
$source = key($cids);
$cid = $cids ? array_shift($cids[$source]) : null;
// read the referenced file
if (($file_id = rcube_utils::get_input_value('_photo', rcube_utils::INPUT_GPC)) && ($tempfile = $_SESSION['contacts']['files'][$file_id])) {
$tempfile = $RCMAIL->plugins->exec_hook('attachment_display', $tempfile);
if ($tempfile['status']) {
if ($tempfile['data'])
$data = $tempfile['data'];
else if ($tempfile['path'])
$data = file_get_contents($tempfile['path']);
}
}
else {
// by email, search for contact first
if ($email = rcube_utils::get_input_value('_email', rcube_utils::INPUT_GPC)) {
foreach ($RCMAIL->get_address_sources() as $s) {
$abook = $RCMAIL->get_address_book($s['id']);
$result = $abook->search(array('email'), $email, 1, true, true, 'photo');
while ($result && ($record = $result->iterate())) {
if ($record['photo'])
break 2;
}
}
}
// by contact id
if (!$record && $cid) {
// Initialize addressbook source
$CONTACTS = rcmail_contact_source($source, true);
$SOURCE_ID = $source;
// read contact record
$record = $CONTACTS->get_record($cid, true);
}
if ($record['photo']) {
$data = is_array($record['photo']) ? $record['photo'][0] : $record['photo'];
if (!preg_match('![^a-z0-9/=+-]!i', $data))
$data = base64_decode($data, true);
}
}
// let plugins do fancy things with contact photos
$plugin = $RCMAIL->plugins->exec_hook('contact_photo',
array('record' => $record, 'email' => $email, 'data' => $data));
// redirect to url provided by a plugin
if ($plugin['url']) {
$RCMAIL->output->redirect($plugin['url']);
}
$data = $plugin['data'];
// detect if photo data is an URL
if (strlen($data) < 1024 && filter_var($data, FILTER_VALIDATE_URL)) {
$RCMAIL->output->redirect($data);
}
// deliver alt image
if (!$data && ($alt_img = rcube_utils::get_input_value('_alt', rcube_utils::INPUT_GPC)) && is_file($alt_img)) {
$data = file_get_contents($alt_img);
}
// cache for one day if requested by email
if (!$cid && $email) {
$RCMAIL->output->future_expire_header(86400);
}
header('Content-Type: ' . rcube_mime::image_content_type($data));
echo $data ? $data : file_get_contents('program/resources/blank.gif');
exit;
|