diff options
author | Thomas Bruederli <thomas@roundcube.net> | 2012-07-13 20:16:52 +0200 |
---|---|---|
committer | Thomas Bruederli <thomas@roundcube.net> | 2012-07-13 20:16:52 +0200 |
commit | 384948886c4a1bedb17318af63c944c33ae0b3b6 (patch) | |
tree | 66f7a0fb29be3070dda9434c68097b22ec8be905 /program | |
parent | 88fb5635109ff5ed994aa5624c0bc1a95c814176 (diff) |
Prepare to show contact photo of email sender in mail views
Diffstat (limited to 'program')
-rw-r--r-- | program/steps/addressbook/func.inc | 6 | ||||
-rw-r--r-- | program/steps/addressbook/show.inc | 32 | ||||
-rw-r--r-- | program/steps/mail/show.inc | 14 |
3 files changed, 50 insertions, 2 deletions
diff --git a/program/steps/addressbook/func.inc b/program/steps/addressbook/func.inc index 80d89b001..a612d7c11 100644 --- a/program/steps/addressbook/func.inc +++ b/program/steps/addressbook/func.inc @@ -709,7 +709,11 @@ function rcmail_contact_photo($attrib) $RCMAIL->output->set_env('photo_placeholder', $photo_img); unset($attrib['placeholder']); - if (preg_match('!^https?://!i', $record['photo'])) + $plugin = $RCMAIL->plugins->exec_hook('contact_photo', array('record' => $record, 'data' => $record['photo'])); + + if ($plugin['url']) + $photo_img = $plugin['url']; + else if (preg_match('!^https?://!i', $record['photo'])) $photo_img = $record['photo']; else if ($record['photo']) $photo_img = $RCMAIL->url(array('_action' => 'photo', '_cid' => $record['ID'], '_source' => $SOURCE_ID)); diff --git a/program/steps/addressbook/show.inc b/program/steps/addressbook/show.inc index e5ff0d73e..d7f6f8f1d 100644 --- a/program/steps/addressbook/show.inc +++ b/program/steps/addressbook/show.inc @@ -22,7 +22,7 @@ // Get contact ID and source ID from request $cids = rcmail_get_cids(); $source = key($cids); -$cid = array_shift($cids[$source]); +$cid = $cids ? array_shift($cids[$source]) : null; // Initialize addressbook source $CONTACTS = rcmail_contact_source($source, true); @@ -39,6 +39,19 @@ rcmail_set_sourcename($CONTACTS); // return raw photo of the given contact if ($RCMAIL->action == 'photo') { + // search for contact first + if (!$record && ($email = get_input_value('_email', RCUBE_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; + } + } + } + + // read the referenced file if (($file_id = get_input_value('_photo', RCUBE_INPUT_GPC)) && ($tempfile = $_SESSION['contacts']['files'][$file_id])) { $tempfile = $RCMAIL->plugins->exec_hook('attachment_display', $tempfile); if ($tempfile['status']) { @@ -54,6 +67,23 @@ if ($RCMAIL->action == 'photo') { $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']); + else + $data = $plugin['data']; + + // deliver alt image + if (!$data && ($alt_img = get_input_value('_alt', RCUBE_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: ' . rc_image_content_type($data)); echo $data ? $data : file_get_contents('program/blank.gif'); exit; diff --git a/program/steps/mail/show.inc b/program/steps/mail/show.inc index 5fa72d77f..70c083353 100644 --- a/program/steps/mail/show.inc +++ b/program/steps/mail/show.inc @@ -266,11 +266,25 @@ function rcmail_contact_exists($email) return false; } +function rcmail_message_contactphoto($attrib) +{ + global $RCMAIL, $MESSAGE; + + $placeholder = $attrib['placeholder'] ? $RCMAIL->config->get('skin_path') . $attrib['placeholder'] : null; + if ($MESSAGE->sender) + $photo_img = $RCMAIL->url(array('_task' => 'addressbook', '_action' => 'photo', '_email' => $MESSAGE->sender['mailto'], '_alt' => $placeholder)); + else + $photo_img = $placeholder ? $placeholder : 'program/blank.gif'; + + return html::img(array('src' => $photo_img) + $attrib); +} + $OUTPUT->add_handlers(array( 'messageattachments' => 'rcmail_message_attachments', 'mailboxname' => 'rcmail_mailbox_name_display', 'messageobjects' => 'rcmail_message_objects', + 'contactphoto' => 'rcmail_message_contactphoto', )); |