comparison program/steps/addressbook/photo.inc @ 0:4681f974d28b

vanilla 1.3.3 distro, I hope
author Charlie Root
date Thu, 04 Jan 2018 15:52:31 -0500
parents
children
comparison
equal deleted inserted replaced
-1:000000000000 0:4681f974d28b
1 <?php
2
3 /**
4 +-----------------------------------------------------------------------+
5 | program/steps/addressbook/photo.inc |
6 | |
7 | This file is part of the Roundcube Webmail client |
8 | Copyright (C) 2005-2013, The Roundcube Dev Team |
9 | |
10 | Licensed under the GNU General Public License version 3 or |
11 | any later version with exceptions for skins & plugins. |
12 | See the README file for a full license statement. |
13 | |
14 | PURPOSE: |
15 | Show contact photo |
16 | |
17 +-----------------------------------------------------------------------+
18 | Author: Thomas Bruederli <roundcube@gmail.com> |
19 | Author: Aleksander Machniak <alec@alec.pl> |
20 +-----------------------------------------------------------------------+
21 */
22
23 // Get contact ID and source ID from request
24 $cids = rcmail_get_cids();
25 $source = key($cids);
26 $cid = $cids ? array_shift($cids[$source]) : null;
27
28 // read the referenced file
29 if (($file_id = rcube_utils::get_input_value('_photo', rcube_utils::INPUT_GPC)) && ($tempfile = $_SESSION['contacts']['files'][$file_id])) {
30 $tempfile = $RCMAIL->plugins->exec_hook('attachment_display', $tempfile);
31 if ($tempfile['status']) {
32 if ($tempfile['data'])
33 $data = $tempfile['data'];
34 else if ($tempfile['path'])
35 $data = file_get_contents($tempfile['path']);
36 }
37 }
38 else {
39 // by email, search for contact first
40 if ($email = rcube_utils::get_input_value('_email', rcube_utils::INPUT_GPC)) {
41 foreach ($RCMAIL->get_address_sources() as $s) {
42 $abook = $RCMAIL->get_address_book($s['id']);
43 $result = $abook->search(array('email'), $email, 1, true, true, 'photo');
44 while ($result && ($record = $result->iterate())) {
45 if ($record['photo'])
46 break 2;
47 }
48 }
49 }
50
51 // by contact id
52 if (!$record && $cid) {
53 // Initialize addressbook source
54 $CONTACTS = rcmail_contact_source($source, true);
55 $SOURCE_ID = $source;
56 // read contact record
57 $record = $CONTACTS->get_record($cid, true);
58 }
59
60 if ($record['photo']) {
61 $data = is_array($record['photo']) ? $record['photo'][0] : $record['photo'];
62 if (!preg_match('![^a-z0-9/=+-]!i', $data))
63 $data = base64_decode($data, true);
64 }
65 }
66
67 // let plugins do fancy things with contact photos
68 $plugin = $RCMAIL->plugins->exec_hook('contact_photo',
69 array('record' => $record, 'email' => $email, 'data' => $data));
70
71 // redirect to url provided by a plugin
72 if ($plugin['url']) {
73 $RCMAIL->output->redirect($plugin['url']);
74 }
75
76 $data = $plugin['data'];
77
78 // detect if photo data is an URL
79 if (strlen($data) < 1024 && filter_var($data, FILTER_VALIDATE_URL)) {
80 $RCMAIL->output->redirect($data);
81 }
82
83 // cache for one day if requested by email
84 if (!$cid && $email) {
85 $RCMAIL->output->future_expire_header(86400);
86 }
87
88 if ($data) {
89 header('Content-Type: ' . rcube_mime::image_content_type($data));
90 echo $data;
91 }
92 else if (!empty($_GET['_error'])) {
93 header('HTTP/1.0 404 Photo not found');
94 }
95 else {
96 header('Content-Type: image/gif');
97 echo base64_decode(rcmail_output::BLANK_GIF);
98 }
99 exit;