I install a Zenphoto on my server. And I saw that in themes don't have a encoding declaration:
`
`
(my server send all pages in `ISO-8859-2`). Polish chars are broken.
And I saw that Ajax script to add a titles and description save a polish chars (`?, ?, ?, ?, ?, ó, ?, ?...`) bad.
Example:
?a?ó?? ?ó?t? ja??
changing to:
Za%u017Có%u0142%u0107 %u017Có%u0142t%u0105 ja%u017A%u0144
Comments
`
/**
* Function converts an Javascript escaped string back into a string with specified charset (default is UTF-8).
* Modified function from http://pure-essence.net/stuff/code/utf8RawUrlDecode.phps
*
* @param string $source escaped with Javascript's escape() function
* @param string $iconv_to destination character set will be used as second paramether in the iconv function. Default is UTF-8.
* @return string
*/
function unescape($source, $iconv_to = 'UTF-8') {
$decodedStr = '';
$pos = 0;
$len = strlen ($source);
while ($pos < $len) {
$charAt = substr ($source, $pos, 1);
if ($charAt == '%') {
$pos++;
$charAt = substr ($source, $pos, 1);
if ($charAt == 'u') {
// we got a unicode character
$pos++;
$unicodeHexVal = substr ($source, $pos, 4);
$unicode = hexdec ($unicodeHexVal);
$decodedStr .= code2utf($unicode);
$pos += 4;
}
else {
// we have an escaped ascii character
$hexVal = substr ($source, $pos, 2);
$decodedStr .= chr (hexdec ($hexVal));
$pos += 2;
}
}
else {
$decodedStr .= $charAt;
$pos++;
}
}
if ($iconv_to != "UTF-8") {
$decodedStr = iconv("UTF-8", $iconv_to, $decodedStr);
}
return $decodedStr;
}
/**
* Function coverts number of utf char into that character.
* Function taken from: http://sk2.php.net/manual/en/function.utf8-encode.php#49336
*
* @param int $num
* @return utf8char
*/
function code2utf($num){
if($num<128)return chr($num);<br />
if($num<2048)return chr(($num>>6)+192).chr(($num&63)+128);
if($num<65536)return chr(($num>>12)+224).chr((($num>>6)&63)+128).chr(($num&63)+128);
if($num<2097152)return chr(($num>>18)+240).chr((($num>>12)&63)+128).chr((($num>>6)&63)+128) .chr(($num&63)+128);
return '';
}
`
then change stripslashes($newtitle) to stripslashes(unescape($newtitle))
and stripslashes($newdesc) to stripslashes(unescape($newdesc)).
and don't forget to add meta content-type = utf-8
Thanks for the report.
It probably is fine. You're welcome to hack ZP to use it if need be.
but I think that these encoding problems are quite critical for non-english users. and why to search for something more if solution is available
add
header("Content-type: text/html; charset=utf-8");
into zp/index.php in the first line to override the default charset.
in Sajax.php, replace "escape" with "encodeURIComponent".
It works very well for Chinese characters.
http://blog.dukechina.org/gallery/
header("Content-type: text/html; charset=utf-8");
is good thing to adding into admin.php
Perhaps this change should be added in the next version?
However, if the image has Finnish letters, it won't display properly.
And of course your MySQL-Database must have the right encoding too.
It's not because of my server provider, and it's propably not because of mysql either, though I don't understand how I could change mysql to utf-8 (or to anything).
The idea of changing all question marks in admin is not an option, because in Finnish language ä:s and ö:s are almoust as common as i or e in English, and there is usually a lot of text in fileinfos.
Anyway, thanks for one of the greatest software ever!
1. set utf-8 to false.
2. refresh the zenphoto-database & metadata
3. set utf-8 to true again.
This works for me.