Changeset 4298 in subversion


Ignore:
Timestamp:
Dec 1, 2010 2:39:36 PM (2 years ago)
Author:
thomasb
Message:

Handle both binary and base64 encoded photo values

Location:
branches/devel-addressbook/program
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • branches/devel-addressbook/program/include/rcube_vcard.php

    r4297 r4298  
    234234        break; 
    235235         
     236      case 'photo': 
     237        $encoded = base64_decode($value, true) ? true : false; 
     238        $this->raw['PHOTO'][] = array(0 => $encoded ? $value : base64_encode($value), array('BASE64')); 
     239        break; 
     240         
    236241      case 'email': 
    237242        $this->raw['EMAIL'][] = array(0 => $value, 'type' => array_filter(array('INTERNET', $type))); 
  • branches/devel-addressbook/program/steps/addressbook/func.inc

    r4297 r4298  
    325325            if ($coltypes['photo']) { 
    326326                if ($record['photo']) 
    327                     $pic_img = $browser->imgdata ? 'data:image/jpeg;base64,' . $data : $RCMAIL->url(array('_action' => 'photo', '_cid' => $record['ID'], '_source' => $_REQUEST['_source'])); 
     327                    $pic_img = $RCMAIL->url(array('_action' => 'photo', '_cid' => $record['ID'], '_source' => $_REQUEST['_source'])); 
    328328                $img = html::img(array('src' => $pic_img, 'border' => 1, 'alt' => '')); 
    329329                if ($edit_mode) { 
  • branches/devel-addressbook/program/steps/addressbook/show.inc

    r4297 r4298  
    2929if ($RCMAIL->action == 'photo') { 
    3030    if ($record['photo']) { 
    31         // assume image/jpg base64 encoded 
    32         $data = base64_decode(is_array($record['photo']) ? $record['photo'][0] : $record['photo'], true); 
     31        $data = is_array($record['photo']) ? $record['photo'][0] : $record['photo']; 
     32        if (!preg_match('![^a-z0-9/+-]!i', $data)) 
     33            $data = base64_decode($data, true); 
    3334    } 
    3435     
    35     header('Content-Type: image/jpeg'); 
     36    // check some magic numbers to detect image type 
     37    $type = 'jpeg'; 
     38    if (preg_match('/^\x89\x50\x4E\x47/', $data)) 
     39        $type = 'png'; 
     40    else if (preg_match('/^\x47\x49\x46\x38/', $data)) 
     41        $type = 'png'; 
     42    //else if (preg_match('/^\xFF\xD8\xFF\xE0/', $data)) 
     43    //    $type = 'jpeg'; 
     44     
     45    header('Content-Type: image/' . $type); 
    3646    echo $data ? $data : file_get_contents('program/blank.gif'); 
    3747    exit; 
Note: See TracChangeset for help on using the changeset viewer.