ZenphotoCMS Forum
Encoding in AJAX - Printable Version

+- ZenphotoCMS Forum (https://forum.zenphoto.org)
+-- Forum: Support (https://forum.zenphoto.org/forum-1.html)
+--- Forum: General support (https://forum.zenphoto.org/forum-4.html)
+--- Thread: Encoding in AJAX (/thread-222.html)

Pages: 1 2


Encoding in AJAX - adas - 2006-01-13

I install a Zenphoto on my server. And I saw that in themes don't have a encoding declaration:
` (my server send all pages inISO-8859-2`). Polish chars are broken.

And I saw that Ajax script to add a titles and description save a polish chars (?, ?, ?, ?, ?, ó, ?, ?...) bad.
Example:

Quote:?a?ó?? ?ó?t? ja??
changing to:

Quote:Za%u017Có%u0142%u0107 %u017Có%u0142t%u0105 ja%u017A%u0144




Encoding in AJAX - pronvit - 2006-01-14

i've sent patches to fix this to tristan some time ago but still no reply..




Encoding in AJAX - adas - 2006-01-19

pronvit: write it in comment.




Encoding in AJAX - pronvit - 2006-01-19

add to beginning of template-functions.php
`

/**

  • 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 (&#36;pos < &#36;len) {

   &#36;charAt = substr (&#36;source, &#36;pos, 1);

   if (&#36;charAt == '%') {

       &#36;pos++;

       &#36;charAt = substr (&#36;source, &#36;pos, 1);

       if (&#36;charAt == 'u') {

           // we got a unicode character

           &#36;pos++;

           &#36;unicodeHexVal = substr (&#36;source, &#36;pos, 4);

           &#36;unicode = hexdec (&#36;unicodeHexVal);

           &#36;decodedStr .= code2utf(&#36;unicode);

           &#36;pos += 4;

       }

       else {

           // we have an escaped ascii character

           &#36;hexVal = substr (&#36;source, &#36;pos, 2);

           &#36;decodedStr .= chr (hexdec (&#36;hexVal));

           &#36;pos += 2;

       }

   }

   else {

       &#36;decodedStr .= &#36;charAt;

       &#36;pos++;

   }

}

if (&#36;iconv_to != "UTF-8") {

   &#36;decodedStr = iconv("UTF-8", &#36;iconv_to, &#36;decodedStr);

}

return &#36;decodedStr;

}

/**

*/

function code2utf(&#36;num){

if(&#36;num6)+192).chr((&#36;num&63)+128);

if(&#36;num>12)+224).chr(((&#36;num>>6)&63)+128).chr((&#36;num&63)+128);

if(&#36;num>18)+240).chr(((&#36;num>>12)&63)+128).chr(((&#36;num>>6)&63)+128) .chr((&#36;num&63)+128);

return '';

}

`

then change stripslashes(&#36;newtitle) to stripslashes(unescape(&#36;newtitle))
and stripslashes(&#36;newdesc) to stripslashes(unescape(&#36;newdesc)).

and don't forget to add meta content-type = utf-8




Encoding in AJAX - adas - 2006-01-20

Thanks. But one polish letter (ó) doesn't work now fine.




Encoding in AJAX - trisweb - 2006-01-22

I'm sure there are better ways to do this. I have pronvit's mods, but I'll look into better encoding options.

Thanks for the report.




Encoding in AJAX - pronvit - 2006-01-22

why this way isn't good enough?




Encoding in AJAX - trisweb - 2006-01-22

It might be, I just always look for the best way... is there something wrong with that? ;-)

It probably is fine. You're welcome to hack ZP to use it if need be.




Encoding in AJAX - pronvit - 2006-01-25

nothing wrong.
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




Encoding in AJAX - adas - 2006-01-26

Quote:encoding problems are quite critical for non-english users
It's a very big problem.




Encoding in AJAX - WeiChen - 2006-01-31

Easy solution for non-english users.

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/




Encoding in AJAX - adas - 2006-01-31

WeiChen: thanks




Encoding in AJAX - adas - 2006-01-31

I think, that this line:
header("Content-type: text/html; charset=utf-8");
is good thing to adding into admin.php




Encoding in AJAX - spacemonkey - 2006-02-21

Shouldn't a simple htmlentities() PHP function change any special character to a valid html entity? I mean it converts all applicable characters to HTML entities. http://fi.php.net/htmlentities . I just don't know where to put this so that it would convert the text to html entities BEFORE it's saved to the database. I need Finnish/Scandinavian characters and they're coming out as just blocks or question marks. Help, please. Where could I put this?




Encoding in AJAX - hdort - 2006-03-08

WeiChen: seems to work ok for German, too! Many thanks!

Perhaps this change should be added in the next version?




Encoding in AJAX - Guest - 2006-04-20

Oh, but this doesn't work for Russian language... shit =)




Encoding in AJAX - Mania - 2006-04-21

Spacemonkey: I used WeiChen method but with a charset ISO-8859-15 to make Finnish letters work.

However, if the image has Finnish letters, it won't display properly.




Encoding in AJAX - adas - 2006-05-31

In latest version this bug is not resolved...




Encoding in AJAX - trisweb - 2006-05-31

It is now! Version to be released today with support for any desired character-set, including UTF-8 by default.




Encoding in AJAX - JohnieRoger - 2007-12-02

It still shows all scandinavian letters (ä,å,ö) as question marks in File Info and Tags. Does anyone know what to do for this?