diff options
Diffstat (limited to 'program/steps/addressbook')
-rw-r--r-- | program/steps/addressbook/edit.inc | 14 | ||||
-rw-r--r-- | program/steps/addressbook/func.inc | 21 | ||||
-rw-r--r-- | program/steps/addressbook/photo.inc | 91 | ||||
-rw-r--r-- | program/steps/addressbook/show.inc | 52 |
4 files changed, 115 insertions, 63 deletions
diff --git a/program/steps/addressbook/edit.inc b/program/steps/addressbook/edit.inc index d175c05d9..7ddd3e516 100644 --- a/program/steps/addressbook/edit.inc +++ b/program/steps/addressbook/edit.inc @@ -43,16 +43,14 @@ if ($RCMAIL->action == 'edit') { else { $source = get_input_value('_source', RCUBE_INPUT_GPC); - if (!strlen($source)) { - // Give priority to configured default - $source = $RCMAIL->config->get('default_addressbook'); + if (strlen($source)) { + $CONTACTS = $RCMAIL->get_address_book($source, true); } - $CONTACTS = $RCMAIL->get_address_book($source, true); - - // find writable addressbook - if (!$CONTACTS || $CONTACTS->readonly) - $source = $RCMAIL->get_address_book(-1, true); + if (!$CONTACTS || $CONTACTS->readonly) { + $CONTACTS = $RCMAIL->get_address_book(-1, true); + $source = $RCMAIL->get_address_book_id($CONTACTS); + } // Initialize addressbook $CONTACTS = rcmail_contact_source($source, true); diff --git a/program/steps/addressbook/func.inc b/program/steps/addressbook/func.inc index 8ec581f9a..f94d15338 100644 --- a/program/steps/addressbook/func.inc +++ b/program/steps/addressbook/func.inc @@ -751,12 +751,28 @@ function rcmail_contact_photo($attrib) $plugin = $RCMAIL->plugins->exec_hook('contact_photo', array('record' => $record, 'data' => $record['photo'])); + // check if we have photo data from contact form + if ($GLOBALS['EDIT_RECORD']) { + $rec = $GLOBALS['EDIT_RECORD']; + if ($rec['photo'] == '-del-') { + $record['photo'] = ''; + } + else if ($_SESSION['contacts']['files'][$rec['photo']]) { + $record['photo'] = $file_id = $rec['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)); + else if ($record['photo']) { + $url = array('_action' => 'photo', '_cid' => $record['ID'], '_source' => $SOURCE_ID); + if ($file_id) { + $url['_photo'] = $ff_value = $file_id; + } + $photo_img = $RCMAIL->url($url); + } else $ff_value = '-del-'; // will disable delete-photo action @@ -893,7 +909,6 @@ $OUTPUT->add_handlers(array( // register action aliases $RCMAIL->register_action_map(array( 'add' => 'edit.inc', - 'photo' => 'show.inc', 'group-create' => 'groups.inc', 'group-rename' => 'groups.inc', 'group-delete' => 'groups.inc', diff --git a/program/steps/addressbook/photo.inc b/program/steps/addressbook/photo.inc new file mode 100644 index 000000000..658027de4 --- /dev/null +++ b/program/steps/addressbook/photo.inc @@ -0,0 +1,91 @@ +<?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 = get_input_value('_photo', RCUBE_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 = 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; + } + } + } + + // 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']); +} +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/resources/blank.gif'); +exit; diff --git a/program/steps/addressbook/show.inc b/program/steps/addressbook/show.inc index 950764bb1..efab5e9e5 100644 --- a/program/steps/addressbook/show.inc +++ b/program/steps/addressbook/show.inc @@ -38,58 +38,6 @@ if ($cid && ($record = $CONTACTS->get_record($cid, true))) { // get address book name (for display) 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']) { - if ($tempfile['data']) - $data = $tempfile['data']; - else if ($tempfile['path']) - $data = file_get_contents($tempfile['path']); - } - } - else 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']); - 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/resources/blank.gif'); - exit; -} - function rcmail_contact_head($attrib) { |