Ignore:
Timestamp:
Aug 23, 2006 5:52:13 PM (7 years ago)
Author:
thomasb
Message:

Fixed wrong usage of mbstring (Bug #1462439)

File:
1 edited

Legend:

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

    r321 r324  
    378378function rcmail_set_locale($lang) 
    379379  { 
    380   global $OUTPUT, $MBSTRING, $MBSTRING_ENCODING; 
     380  global $OUTPUT, $MBSTRING; 
    381381  static $s_mbstring_loaded = NULL; 
    382382   
    383383  // settings for mbstring module (by Tadashi Jokagi) 
    384   if ($s_mbstring_loaded===NULL) 
    385     { 
    386     if ($s_mbstring_loaded = extension_loaded("mbstring")) 
    387       { 
    388       $MBSTRING = TRUE; 
    389       if (function_exists("mb_mbstring_encodings")) 
    390         $MBSTRING_ENCODING = mb_mbstring_encodings(); 
    391       else 
    392         $MBSTRING_ENCODING = array("ISO-8859-1", "UTF-7", "UTF7-IMAP", "UTF-8", 
    393                                    "ISO-2022-JP", "EUC-JP", "EUCJP-WIN", 
    394                                    "SJIS", "SJIS-WIN"); 
    395  
    396        $MBSTRING_ENCODING = array_map("strtoupper", $MBSTRING_ENCODING); 
    397        if (in_array("SJIS", $MBSTRING_ENCODING)) 
    398          $MBSTRING_ENCODING[] = "SHIFT_JIS"; 
    399        } 
    400      else 
    401       { 
    402       $MBSTRING = FALSE; 
    403       $MBSTRING_ENCODING = array(); 
    404       } 
    405     } 
    406  
    407   if ($MBSTRING && function_exists("mb_language")) 
    408     { 
    409     if (!@mb_language(strtok($lang, "_"))) 
    410       $MBSTRING = FALSE;   //  unsupport language 
    411     } 
     384  if (is_null($s_mbstring_loaded)) 
     385    $MBSTRING = $s_mbstring_loaded = extension_loaded("mbstring"); 
     386  else 
     387    $MBSTRING = $s_mbstring_loaded = FALSE; 
    412388 
    413389  $OUTPUT->set_charset(rcube_language_prop($lang, 'charset')); 
     
    869845function rcube_charset_convert($str, $from, $to=NULL) 
    870846  { 
    871   global $MBSTRING, $MBSTRING_ENCODING; 
     847  global $MBSTRING; 
    872848 
    873849  $from = strtoupper($from); 
    874850  $to = $to==NULL ? strtoupper($GLOBALS['CHARSET']) : strtoupper($to); 
    875851 
    876   if ($from==$to) 
     852  if ($from==$to || $str=='') 
    877853    return $str; 
    878      
     854 
    879855  // convert charset using mbstring module   
    880856  if ($MBSTRING) 
     
    882858    $to = $to=="UTF-7" ? "UTF7-IMAP" : $to; 
    883859    $from = $from=="UTF-7" ? "UTF7-IMAP": $from; 
    884      
    885     if (in_array($to, $MBSTRING_ENCODING) && in_array($from, $MBSTRING_ENCODING)) 
    886       return mb_convert_encoding($str, $to, $from); 
     860 
     861    // return if convert succeeded 
     862    if (($out = mb_convert_encoding($str, $to, $from)) != '') 
     863      return $out; 
    887864    } 
    888865 
Note: See TracChangeset for help on using the changeset viewer.