Changeset 2156 in subversion


Ignore:
Timestamp:
Dec 16, 2008 8:40:13 AM (4 years ago)
Author:
alec
Message:

#1485549: fix mb_convert_encoding() issue

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/roundcubemail/program/include/main.inc

    r2117 r2156  
    179179function rcube_charset_convert($str, $from, $to=NULL) 
    180180  { 
    181   static $mbstring_loaded = null, $convert_warning = false; 
     181  static $mbstring_loaded = null; 
     182  static $mbstring_list = null; 
     183  static $convert_warning = false; 
    182184 
    183185  $from = strtoupper($from); 
     
    220222    $aliases['WINDOWS-1257'] = 'ISO-8859-13'; 
    221223     
    222     // return if convert succeeded 
    223     if (($out = mb_convert_encoding($str, ($aliases[$to] ? $aliases[$to] : $to), ($aliases[$from] ? $aliases[$from] : $from))) != '') 
    224       return $out; 
     224    if (is_null($mbstring_list)) { 
     225      $mbstring_list = mb_list_encodings(); 
     226      $mbstring_list = array_map('strtoupper', $mbstring_list); 
     227    } 
     228     
     229    $mb_from = $aliases[$from] ? $aliases[$from] : $from; 
     230    $mb_to = $aliases[$to] ? $aliases[$to] : $to; 
     231     
     232    // return if encoding found, string matches encoding and convert succeeded 
     233    if (in_array($mb_from, $mbstring_list) && in_array($mb_to, $mbstring_list)) 
     234      if (mb_check_encoding($str, $mb_from)) 
     235        if ($out = mb_convert_encoding($str, $mb_to, $mb_from)) 
     236          return $out; 
    225237    } 
    226238     
Note: See TracChangeset for help on using the changeset viewer.