Changeset 3849488 in github


Ignore:
Timestamp:
Jul 13, 2012 2:16:52 PM (10 months ago)
Author:
Thomas Bruederli <thomas@…>
Children:
7938312
Parents:
88fb563
Message:

Prepare to show contact photo of email sender in mail views

Location:
program/steps
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • program/steps/addressbook/func.inc

    r041c93c r3849488  
    710710    unset($attrib['placeholder']); 
    711711 
    712     if (preg_match('!^https?://!i', $record['photo'])) 
     712    $plugin = $RCMAIL->plugins->exec_hook('contact_photo', array('record' => $record, 'data' => $record['photo'])); 
     713 
     714    if ($plugin['url']) 
     715        $photo_img = $plugin['url']; 
     716    else if (preg_match('!^https?://!i', $record['photo'])) 
    713717        $photo_img = $record['photo']; 
    714718    else if ($record['photo']) 
  • program/steps/addressbook/show.inc

    r041c93c r3849488  
    2323$cids   = rcmail_get_cids(); 
    2424$source = key($cids); 
    25 $cid    = array_shift($cids[$source]); 
     25$cid    = $cids ? array_shift($cids[$source]) : null; 
    2626 
    2727// Initialize addressbook source 
     
    4040// return raw photo of the given contact 
    4141if ($RCMAIL->action == 'photo') { 
     42    // search for contact first 
     43    if (!$record && ($email = get_input_value('_email', RCUBE_INPUT_GPC))) { 
     44        foreach ($RCMAIL->get_address_sources() as $s) { 
     45            $abook = $RCMAIL->get_address_book($s['id']); 
     46            $result = $abook->search(array('email'), $email, 1, true, true, 'photo'); 
     47            while ($result && ($record = $result->iterate())) { 
     48                if ($record['photo']) 
     49                    break 2; 
     50            } 
     51        } 
     52    } 
     53 
     54    // read the referenced file 
    4255    if (($file_id = get_input_value('_photo', RCUBE_INPUT_GPC)) && ($tempfile = $_SESSION['contacts']['files'][$file_id])) { 
    4356        $tempfile = $RCMAIL->plugins->exec_hook('attachment_display', $tempfile); 
     
    5568    } 
    5669 
     70    // let plugins do fancy things with contact photos 
     71    $plugin = $RCMAIL->plugins->exec_hook('contact_photo', array('record' => $record, 'email' => $email, 'data' => $data)); 
     72 
     73    // redirect to url provided by a plugin 
     74    if ($plugin['url']) 
     75        $RCMAIL->output->redirect($plugin['url']); 
     76    else 
     77        $data = $plugin['data']; 
     78 
     79    // deliver alt image 
     80    if (!$data && ($alt_img = get_input_value('_alt', RCUBE_INPUT_GPC)) && is_file($alt_img)) 
     81        $data = file_get_contents($alt_img); 
     82 
     83    // cache for one day if requested by email 
     84    if (!$cid && $email) 
     85        $RCMAIL->output->future_expire_header(86400); 
     86 
    5787    header('Content-Type: ' . rc_image_content_type($data)); 
    5888    echo $data ? $data : file_get_contents('program/blank.gif'); 
  • program/steps/mail/show.inc

    r8749e94 r3849488  
    267267} 
    268268 
     269function rcmail_message_contactphoto($attrib) 
     270{ 
     271  global $RCMAIL, $MESSAGE; 
     272 
     273  $placeholder = $attrib['placeholder'] ? $RCMAIL->config->get('skin_path') . $attrib['placeholder'] : null; 
     274  if ($MESSAGE->sender) 
     275    $photo_img = $RCMAIL->url(array('_task' => 'addressbook', '_action' => 'photo', '_email' => $MESSAGE->sender['mailto'], '_alt' => $placeholder)); 
     276  else 
     277    $photo_img = $placeholder ? $placeholder : 'program/blank.gif'; 
     278 
     279  return html::img(array('src' => $photo_img) + $attrib); 
     280} 
     281 
    269282 
    270283$OUTPUT->add_handlers(array( 
     
    272285  'mailboxname' => 'rcmail_mailbox_name_display', 
    273286  'messageobjects' => 'rcmail_message_objects', 
     287  'contactphoto' => 'rcmail_message_contactphoto', 
    274288)); 
    275289 
Note: See TracChangeset for help on using the changeset viewer.