merge -r 6355 from trunk

fix bug 1663 : wrong decoding of non Ascii iptc/exif (charset issue)

git-svn-id: http://piwigo.org/svn/branches/2.1@6356 68402e56-0260-453c-a942-63ccdbb3a9ee
This commit is contained in:
rvelices 2010-05-25 19:55:28 +00:00
parent 442005ff0a
commit 7ab2dd2fac
2 changed files with 21 additions and 18 deletions

View file

@ -165,7 +165,7 @@ UPDATE '.USER_INFOS_TABLE.'
{ {
list($language_name) = @file($path.'/iso.txt'); list($language_name) = @file($path.'/iso.txt');
$languages[$file] = convert_charset($language_name, $target_charset); $languages[$file] = convert_charset($language_name, 'utf-8', $target_charset);
} }
} }
closedir($dir); closedir($dir);

View file

@ -1266,18 +1266,18 @@ function load_language($filename, $dirname = '',
{ {
if ( is_array($v) ) if ( is_array($v) )
{ {
$func = create_function('$v', 'return convert_charset($v, "'.$target_charset.'");' ); $func = create_function('$v', 'return convert_charset($v, "utf-8", "'.$target_charset.'");' );
$lang[$k] = array_map($func, $v); $lang[$k] = array_map($func, $v);
} }
else else
$lang[$k] = convert_charset($v, $target_charset); $lang[$k] = convert_charset($v, 'utf-8', $target_charset);
} }
} }
if ( is_array($load_lang_info) ) if ( is_array($load_lang_info) )
{ {
foreach ($load_lang_info as $k => $v) foreach ($load_lang_info as $k => $v)
{ {
$lang_info[$k] = convert_charset($v, $target_charset); $lang_info[$k] = convert_charset($v, 'utf-8', $target_charset);
} }
} }
} }
@ -1291,7 +1291,7 @@ function load_language($filename, $dirname = '',
else else
{ {
$content = @file_get_contents($source_file); $content = @file_get_contents($source_file);
$content = convert_charset($content, $target_charset); $content = convert_charset($content, 'utf-8', $target_charset);
return $content; return $content;
} }
} }
@ -1299,27 +1299,30 @@ function load_language($filename, $dirname = '',
} }
/** /**
* converts a string from utf-8 character set to another character set * converts a string from a character set to another character set
* @param string str the string to be converted * @param string str the string to be converted
* @param string source_charset the character set in which the string is encoded
* @param string dest_charset the destination character set * @param string dest_charset the destination character set
*/ */
function convert_charset($str, $dest_charset) function convert_charset($str, $source_charset, $dest_charset)
{ {
if ($dest_charset=='utf-8') if ($source_charset==$dest_charset)
{
return $str; return $str;
if ($source_charset=='iso-8859-1' and $dest_charset=='utf-8')
{
return utf8_encode($str);
} }
if ($dest_charset=='iso-8859-1') if ($source_charset=='utf-8' and $dest_charset=='iso-8859-1')
{ {
return utf8_decode($str); return utf8_decode($str);
} }
if (function_exists('iconv')) if (function_exists('iconv'))
{ {
return iconv('utf-8', $dest_charset, $str); return iconv($source_charset, $dest_charset, $str);
} }
if (function_exists('mb_convert_encoding')) if (function_exists('mb_convert_encoding'))
{ {
return mb_convert_encoding( $str, $dest_charset, 'utf-8' ); return mb_convert_encoding( $str, $dest_charset, $source_charset );
} }
return $str; //??? return $str; //???
} }