10fe4e8e689d4792ceeb5710272379c3b10eea56
6 * Copyright (c) 1999-2003 The SquirrelMail Project Team
7 * Licensed under the GNU GPL. For full terms see the file COPYING.
9 * This file contains variuos functions that are needed to do
10 * internationalization of SquirrelMail.
12 * Internally the output character set is used. Other characters are
13 * encoded using Unicode entities according to HTML 4.0.
18 require_once(SM_PATH
. 'functions/global.php');
20 /* Decodes a string to the internal encoding from the given charset */
21 function charset_decode ($charset, $string) {
22 global $languages, $squirrelmail_language, $default_charset;
23 global $use_php_recode, $use_php_iconv, $agresive_decoding;
25 if (isset($languages[$squirrelmail_language]['XTRA_CODE']) &&
26 function_exists($languages[$squirrelmail_language]['XTRA_CODE'])) {
27 $string = $languages[$squirrelmail_language]['XTRA_CODE']('decode', $string);
30 $charset = strtolower($charset);
34 // Variables that allow to use functions without function_exist() calls
35 if (! isset($use_php_recode) ||
$use_php_recode=="" ) {
36 $use_php_recode=false; }
37 if (! isset($use_php_iconv) ||
$use_php_iconv=="" ) {
38 $use_php_iconv=false; }
40 // Don't do conversion if charset is the same.
41 if ( $charset == strtolower($default_charset) )
42 return htmlspecialchars($string);
44 // catch iso-8859-8-i thing
45 if ( $charset == "iso-8859-8-i" )
46 $charset = "iso-8859-8";
49 * Recode converts html special characters automatically if you use
50 * 'charset..html' decoding. There is no documented way to put -d option
51 * into php recode function call.
53 if ( $use_php_recode ) {
54 if ( $default_charset == "utf-8" ) {
55 // other charsets can be converted to utf-8 without loss.
56 // and output string is smaller
57 $string = recode_string($charset . "..utf-8",$string);
58 return htmlspecialchars($string);
60 $string = recode_string($charset . "..html",$string);
61 // recode does not convert single quote, htmlspecialchars does.
62 $string = str_replace("'", ''', $string);
67 // iconv functions does not have html target and can be used only with utf-8
68 if ( $use_php_iconv && $default_charset=='utf-8') {
69 $string = iconv($charset,$default_charset,$string);
70 return htmlspecialchars($string);
73 // If we don't use recode and iconv, we'll do it old way.
75 /* All HTML special characters are 7 bit and can be replaced first */
77 $string = htmlspecialchars ($string);
79 /* controls cpu and memory intensive decoding cycles */
80 if (! isset($agresive_decoding) ||
$agresive_decoding=="" ) {
81 $agresive_decoding=false; }
83 if (ereg('iso-8859-([[:digit:]]+)', $charset, $res)) {
85 include_once(SM_PATH
. 'functions/decode/iso8859-1.php');
86 $ret = charset_decode_iso8859_1 ($string);
87 } else if ($res[1] == '2') {
88 include_once(SM_PATH
. 'functions/decode/iso8859-2.php');
89 $ret = charset_decode_iso8859_2 ($string);
90 } else if ($res[1] == '3') {
91 include_once(SM_PATH
. 'functions/decode/iso8859-3.php');
92 $ret = charset_decode_iso8859_3 ($string);
93 } else if ($res[1] == '4') {
94 include_once(SM_PATH
. 'functions/decode/iso8859-4.php');
95 $ret = charset_decode_iso8859_4 ($string);
96 } else if ($res[1] == '5') {
97 include_once(SM_PATH
. 'functions/decode/iso8859-5.php');
98 $ret = charset_decode_iso8859_5 ($string);
99 } else if ($res[1] == '6') {
100 include_once(SM_PATH
. 'functions/decode/iso8859-6.php');
101 $ret = charset_decode_iso8859_6 ($string);
102 } else if ($res[1] == '7') {
103 include_once(SM_PATH
. 'functions/decode/iso8859-7.php');
104 $ret = charset_decode_iso8859_7 ($string);
105 } else if ($res[1] == '8') {
106 include_once(SM_PATH
. 'functions/decode/iso8859-8.php');
107 $ret = charset_decode_iso8859_8 ($string);
108 } else if ($res[1] == '9') {
109 include_once(SM_PATH
. 'functions/decode/iso8859-9.php');
110 $ret = charset_decode_iso8859_9 ($string);
111 } else if ($res[1] == '10') {
112 include_once(SM_PATH
. 'functions/decode/iso8859-10.php');
113 $ret = charset_decode_iso8859_10 ($string);
114 } else if ($res[1] == '11') {
115 include_once(SM_PATH
. 'functions/decode/iso8859-11.php');
116 $ret = charset_decode_iso8859_11 ($string);
117 } else if ($res[1] == '13') {
118 include_once(SM_PATH
. 'functions/decode/iso8859-13.php');
119 $ret = charset_decode_iso8859_13 ($string);
120 } else if ($res[1] == '14') {
121 include_once(SM_PATH
. 'functions/decode/iso8859-14.php');
122 $ret = charset_decode_iso8859_14 ($string);
123 } else if ($res[1] == '15') {
124 include_once(SM_PATH
. 'functions/decode/iso8859-15.php');
125 $ret = charset_decode_iso8859_15 ($string);
126 } else if ($res[1] == '16') {
127 include_once(SM_PATH
. 'functions/decode/iso8859-16.php');
128 $ret = charset_decode_iso8859_16 ($string);
130 $ret = charset_decode_iso_8859_default ($string);
132 } else if ($charset == 'ns_4551-1') {
133 $ret = charset_decode_ns_4551_1 ($string);
134 } else if ($charset == 'koi8-r') {
135 include_once(SM_PATH
. 'functions/decode/koi8-r.php');
136 $ret = charset_decode_koi8r ($string);
137 } else if ($charset == 'koi8-u') {
138 include_once(SM_PATH
. 'functions/decode/koi8-u.php');
139 $ret = charset_decode_koi8u ($string);
140 } else if ($charset == 'windows-1250') {
141 include_once(SM_PATH
. 'functions/decode/cp1250.php');
142 $ret = charset_decode_cp1250 ($string);
143 } else if ($charset == 'windows-1251') {
144 include_once(SM_PATH
. 'functions/decode/cp1251.php');
145 $ret = charset_decode_cp1251 ($string);
146 } else if ($charset == 'windows-1252') {
147 include_once(SM_PATH
. 'functions/decode/cp1252.php');
148 $ret = charset_decode_cp1252 ($string);
149 } else if ($charset == 'windows-1253') {
150 include_once(SM_PATH
. 'functions/decode/cp1253.php');
151 $ret = charset_decode_cp1253 ($string);
152 } else if ($charset == 'windows-1254') {
153 include_once(SM_PATH
. 'functions/decode/cp1254.php');
154 $ret = charset_decode_cp1254 ($string);
155 } else if ($charset == 'windows-1255') {
156 include_once(SM_PATH
. 'functions/decode/cp1255.php');
157 $ret = charset_decode_cp1255 ($string);
158 } else if ($charset == 'windows-1256') {
159 include_once(SM_PATH
. 'functions/decode/cp1256.php');
160 $ret = charset_decode_cp1256 ($string);
161 } else if ($charset == 'windows-1257') {
162 include_once(SM_PATH
. 'functions/decode/cp1257.php');
163 $ret = charset_decode_cp1257 ($string);
164 } else if ($charset == 'windows-1258') {
165 include_once(SM_PATH
. 'functions/decode/cp1258.php');
166 $ret = charset_decode_cp1258 ($string);
167 } else if ($charset == 'x-mac-roman') {
168 include_once(SM_PATH
. 'functions/decode/cp10000.php');
169 $ret = charset_decode_cp10000 ($string);
170 } else if ($charset == 'x-mac-greek') {
171 include_once(SM_PATH
. 'functions/decode/cp10006.php');
172 $ret = charset_decode_cp10006 ($string);
173 } else if ($charset == 'x-mac-cyrillic') {
174 include_once(SM_PATH
. 'functions/decode/cp10007.php');
175 $ret = charset_decode_cp10007 ($string);
176 } else if ($charset == 'x-mac-ukrainian') {
177 include_once(SM_PATH
. 'functions/decode/cp10017.php');
178 $ret = charset_decode_cp10017 ($string);
179 } else if ($charset == 'x-mac-centraleurroman') {
180 include_once(SM_PATH
. 'functions/decode/cp10029.php');
181 $ret = charset_decode_cp10029 ($string);
182 } else if ($charset == 'x-mac-icelandic') {
183 include_once(SM_PATH
. 'functions/decode/cp10079.php');
184 $ret = charset_decode_cp10079 ($string);
185 } else if ($charset == 'x-mac-turkish') {
186 include_once(SM_PATH
. 'functions/decode/cp10081.php');
187 $ret = charset_decode_cp10081 ($string);
188 } else if ($charset == 'ibm855') {
189 include_once(SM_PATH
. 'functions/decode/cp855.php');
190 $ret = charset_decode_cp855 ($string);
191 } else if ($charset == 'ibm866') {
192 include_once(SM_PATH
. 'functions/decode/cp866.php');
193 $ret = charset_decode_cp866 ($string);
194 } else if ($charset == 'iso-ir-111') {
195 include_once(SM_PATH
. 'functions/decode/iso-ir-111.php');
196 $ret = charset_decode_iso_ir_111 ($string);
197 } else if ($charset == 'tis-620') {
198 include_once(SM_PATH
. 'functions/decode/tis620.php');
199 $ret = charset_decode_tis620 ($string);
200 } else if ($charset == 'big5' and $agresive_decoding ) {
201 include_once(SM_PATH
. 'functions/decode/big5.php');
202 $ret = charset_decode_big5 ($string);
203 } else if ($charset == 'gb2312' and $agresive_decoding ) {
204 include_once(SM_PATH
. 'functions/decode/gb2312.php');
205 $ret = charset_decode_gb2312 ($string);
206 } else if ($charset == 'utf-8') {
207 include_once(SM_PATH
. 'functions/decode/utf-8.php');
208 $ret = charset_decode_utf8 ($string);
216 /* Remove all 8 bit characters from all other ISO-8859 character sets */
217 function charset_decode_iso_8859_default ($string) {
218 return (strtr($string, "\240\241\242\243\244\245\246\247".
219 "\250\251\252\253\254\255\256\257".
220 "\260\261\262\263\264\265\266\267".
221 "\270\271\272\273\274\275\276\277".
222 "\300\301\302\303\304\305\306\307".
223 "\310\311\312\313\314\315\316\317".
224 "\320\321\322\323\324\325\326\327".
225 "\330\331\332\333\334\335\336\337".
226 "\340\341\342\343\344\345\346\347".
227 "\350\351\352\353\354\355\356\357".
228 "\360\361\362\363\364\365\366\367".
229 "\370\371\372\373\374\375\376\377",
230 "????????????????????????????????????????".
231 "????????????????????????????????????????".
232 "????????????????????????????????????????".
238 * This is the same as ISO-646-NO and is used by some
239 * Microsoft programs when sending Norwegian characters
241 function charset_decode_ns_4551_1 ($string) {
243 * These characters are:
244 * Latin capital letter AE
245 * Latin capital letter O with stroke
246 * Latin capital letter A with ring above
247 * and the same as small letters
249 return strtr ($string, "[\\]{|}", "ÆØÅæøå");
254 * Set up the language to be output
255 * if $do_search is true, then scan the browser information
256 * for a possible language that we know
258 function set_up_language($sm_language, $do_search = false, $default = false) {
260 static $SetupAlready = 0;
261 global $use_gettext, $languages,
262 $squirrelmail_language, $squirrelmail_default_language,
269 $SetupAlready = TRUE;
270 sqgetGlobalVar('HTTP_ACCEPT_LANGUAGE', $accept_lang, SQ_SERVER
);
272 if ($do_search && ! $sm_language && isset($accept_lang)) {
273 $sm_language = substr($accept_lang, 0, 2);
276 if ((!$sm_language||
$default) && isset($squirrelmail_default_language)) {
277 $squirrelmail_language = $squirrelmail_default_language;
278 $sm_language = $squirrelmail_default_language;
280 $sm_notAlias = $sm_language;
282 // Catching removed translation
283 // System reverts to English translation if user prefs contain translation
284 // that is not available in $languages array (admin removed directory
285 // with that translation)
286 if (!isset($languages[$sm_notAlias])) {
287 $sm_notAlias="en_US";
290 while (isset($languages[$sm_notAlias]['ALIAS'])) {
291 $sm_notAlias = $languages[$sm_notAlias]['ALIAS'];
294 if ( isset($sm_language) &&
296 $sm_language != '' &&
297 isset($languages[$sm_notAlias]['CHARSET']) ) {
298 bindtextdomain( 'squirrelmail', SM_PATH
. 'locale/' );
299 textdomain( 'squirrelmail' );
300 if (function_exists('bind_textdomain_codeset')) {
301 bind_textdomain_codeset ("squirrelmail", $languages[$sm_notAlias]['CHARSET'] );
303 if (isset($languages[$sm_notAlias]['LOCALE'])){
304 $longlocale=$languages[$sm_notAlias]['LOCALE'];
306 $longlocale=$sm_notAlias;
308 if ( !ini_get('safe_mode') &&
309 getenv( 'LC_ALL' ) != $longlocale ) {
310 putenv( "LC_ALL=$longlocale" );
311 putenv( "LANG=$longlocale" );
312 putenv( "LANGUAGE=$longlocale" );
314 setlocale(LC_ALL
, $longlocale);
315 $squirrelmail_language = $sm_notAlias;
316 if ($squirrelmail_language == 'ja_JP' && function_exists('mb_detect_encoding') ) {
317 header ('Content-Type: text/html; charset=EUC-JP');
318 if (!function_exists('mb_internal_encoding')) {
319 echo _("You need to have php4 installed with the multibyte string function enabled (using configure option --enable-mbstring).");
321 if (function_exists('mb_language')) {
322 mb_language('Japanese');
324 mb_internal_encoding('EUC-JP');
325 mb_http_output('pass');
327 header( 'Content-Type: text/html; charset=' . $languages[$sm_notAlias]['CHARSET'] );
332 function set_my_charset(){
335 * There can be a $default_charset setting in the
336 * config.php file, but the user may have a different language
337 * selected for a user interface. This function checks the
338 * language selected by the user and tags the outgoing messages
339 * with the appropriate charset corresponding to the language
340 * selection. This is "more right" (tm), than just stamping the
341 * message blindly with the system-wide $default_charset.
343 global $data_dir, $username, $default_charset, $languages, $squirrelmail_default_language;
345 $my_language = getPref($data_dir, $username, 'language');
347 $my_language = $squirrelmail_default_language ;
349 // Catch removed translation
350 if (!isset($languages[$my_language])) {
351 $my_language="en_US";
353 while (isset($languages[$my_language]['ALIAS'])) {
354 $my_language = $languages[$my_language]['ALIAS'];
356 $my_charset = $languages[$my_language]['CHARSET'];
358 $default_charset = $my_charset;
362 /* ------------------------------ main --------------------------- */
364 global $squirrelmail_language, $languages, $use_gettext;
366 if (! isset($squirrelmail_language)) {
367 $squirrelmail_language = '';
370 /* This array specifies the available languages. */
371 $languages['bg_BG']['NAME'] = 'Bulgarian';
372 $languages['bg_BG']['ALTNAME'] = 'Български';
373 $languages['bg_BG']['CHARSET'] = 'windows-1251';
374 $languages['bg']['ALIAS'] = 'bg_BG';
376 $languages['ca_ES']['NAME'] = 'Catalan';
377 $languages['ca_ES']['CHARSET'] = 'iso-8859-1';
378 $languages['ca']['ALIAS'] = 'ca_ES';
380 $languages['cs_CZ']['NAME'] = 'Czech';
381 $languages['cs_CZ']['ALTNAME'] = 'Čeština';
382 $languages['cs_CZ']['CHARSET'] = 'iso-8859-2';
383 $languages['cs']['ALIAS'] = 'cs_CZ';
385 $languages['cy_GB']['NAME'] = 'Welsh';
386 $languages['cy_GB']['ALTNAME'] = 'Cymraeg';
387 $languages['cy_GB']['CHARSET'] = 'iso-8859-1';
388 $languages['cy']['ALIAS'] = 'cy_GB';
390 // Danish locale is da_DK.
391 $languages['da_DK']['NAME'] = 'Danish';
392 $languages['da_DK']['ALTNAME'] = 'Dansk';
393 $languages['da_DK']['CHARSET'] = 'iso-8859-1';
394 $languages['da']['ALIAS'] = 'da_DK';
396 $languages['de_DE']['NAME'] = 'German';
397 $languages['de_DE']['ALTNAME'] = 'Deutsch';
398 $languages['de_DE']['CHARSET'] = 'iso-8859-1';
399 $languages['de']['ALIAS'] = 'de_DE';
401 $languages['el_GR']['NAME'] = 'Greek';
402 $languages['el_GR']['ALTNAME'] = 'Ελληνικά';
403 $languages['el_GR']['CHARSET'] = 'iso-8859-7';
404 $languages['el']['ALIAS'] = 'el_GR';
406 // There is no en_EN! There is en_US, en_BR, en_AU, and so forth,
407 // but who cares about !US, right? Right? :)
408 $languages['en_US']['NAME'] = 'English';
409 $languages['en_US']['CHARSET'] = 'iso-8859-1';
410 $languages['en']['ALIAS'] = 'en_US';
412 $languages['es_ES']['NAME'] = 'Spanish';
413 $languages['es_ES']['ALTNAME'] = 'Español';
414 $languages['es_ES']['CHARSET'] = 'iso-8859-1';
415 $languages['es']['ALIAS'] = 'es_ES';
417 $languages['et_EE']['NAME'] = 'Estonian';
418 $languages['et_EE']['CHARSET'] = 'iso-8859-15';
419 $languages['et']['ALIAS'] = 'et_EE';
421 $languages['fo_FO']['NAME'] = 'Faroese';
422 $languages['fo_FO']['CHARSET'] = 'iso-8859-1';
423 $languages['fo']['ALIAS'] = 'fo_FO';
425 $languages['fi_FI']['NAME'] = 'Finnish';
426 $languages['fi_FI']['ALTNAME'] = 'Suomi';
427 $languages['fi_FI']['CHARSET'] = 'iso-8859-1';
428 $languages['fi']['ALIAS'] = 'fi_FI';
430 $languages['fr_FR']['NAME'] = 'French';
431 $languages['fr_FR']['ALTNAME'] = 'Français';
432 $languages['fr_FR']['CHARSET'] = 'iso-8859-1';
433 $languages['fr']['ALIAS'] = 'fr_FR';
435 $languages['hr_HR']['NAME'] = 'Croatian';
436 $languages['hr_HR']['CHARSET'] = 'iso-8859-2';
437 $languages['hr']['ALIAS'] = 'hr_HR';
439 $languages['hu_HU']['NAME'] = 'Hungarian';
440 $languages['hu_HU']['ALTNAME'] = 'Magyar';
441 $languages['hu_HU']['CHARSET'] = 'iso-8859-2';
442 $languages['hu']['ALIAS'] = 'hu_HU';
444 $languages['id_ID']['NAME'] = 'Indonesian';
445 $languages['id_ID']['ALTNAME'] = 'Bahasa Indonesia';
446 $languages['id_ID']['CHARSET'] = 'iso-8859-1';
447 $languages['id']['ALIAS'] = 'id_ID';
449 $languages['is_IS']['NAME'] = 'Icelandic';
450 $languages['is_IS']['ALTNAME'] = 'Íslenska';
451 $languages['is_IS']['CHARSET'] = 'iso-8859-1';
452 $languages['is']['ALIAS'] = 'is_IS';
454 $languages['it_IT']['NAME'] = 'Italian';
455 $languages['it_IT']['CHARSET'] = 'iso-8859-1';
456 $languages['it']['ALIAS'] = 'it_IT';
458 $languages['ja_JP']['NAME'] = 'Japanese';
459 $languages['ja_JP']['ALTNAME'] = '日本語';
460 $languages['ja_JP']['CHARSET'] = 'iso-2022-jp';
461 $languages['ja_JP']['XTRA_CODE'] = 'japanese_charset_xtra';
462 $languages['ja']['ALIAS'] = 'ja_JP';
464 $languages['ko_KR']['NAME'] = 'Korean';
465 $languages['ko_KR']['CHARSET'] = 'euc-KR';
466 $languages['ko_KR']['XTRA_CODE'] = 'korean_charset_xtra';
467 $languages['ko']['ALIAS'] = 'ko_KR';
469 $languages['lt_LT']['NAME'] = 'Lithuanian';
470 $languages['lt_LT']['ALTNAME'] = 'Lietuvių';
471 $languages['lt_LT']['CHARSET'] = 'utf-8';
472 $languages['lt_LT']['LOCALE'] = 'lt_LT.UTF-8';
473 $languages['lt']['ALIAS'] = 'lt_LT';
475 $languages['nl_NL']['NAME'] = 'Dutch';
476 $languages['nl_NL']['ALTNAME'] = 'Nederlands';
477 $languages['nl_NL']['CHARSET'] = 'iso-8859-1';
478 $languages['nl']['ALIAS'] = 'nl_NL';
480 $languages['ms_MY']['NAME'] = 'Malay';
481 $languages['ms_MY']['ALTNAME'] = 'Bahasa Melayu';
482 $languages['ms_MY']['CHARSET'] = 'iso-8859-1';
483 $languages['my']['ALIAS'] = 'ms_MY';
485 $languages['no_NO']['NAME'] = 'Norwegian (Bokmål)';
486 $languages['no_NO']['ALTNAME'] = 'Norsk (Bokmål)';
487 $languages['no_NO']['CHARSET'] = 'iso-8859-1';
488 $languages['no']['ALIAS'] = 'no_NO';
490 $languages['nn_NO']['NAME'] = 'Norwegian (Nynorsk)';
491 $languages['nn_NO']['ALTNAME'] = 'Norsk (Nynorsk)';
492 $languages['nn_NO']['CHARSET'] = 'iso-8859-1';
494 $languages['pl_PL']['NAME'] = 'Polish';
495 $languages['pl_PL']['ALTNAME'] = 'Polski';
496 $languages['pl_PL']['CHARSET'] = 'iso-8859-2';
497 $languages['pl']['ALIAS'] = 'pl_PL';
499 $languages['pt_PT']['NAME'] = 'Portuguese (Portugal)';
500 $languages['pt_PT']['CHARSET'] = 'iso-8859-1';
501 $languages['pt']['ALIAS'] = 'pt_PT';
503 $languages['pt_BR']['NAME'] = 'Portuguese (Brazil)';
504 $languages['pt_BR']['ALTNAME'] = 'Português do Brasil';
505 $languages['pt_BR']['CHARSET'] = 'iso-8859-1';
507 $languages['ro_RO']['NAME'] = 'Romanian';
508 $languages['ro_RO']['ALTNAME'] = 'Română';
509 $languages['ro_RO']['CHARSET'] = 'iso-8859-2';
510 $languages['ro']['ALIAS'] = 'ro_RO';
512 $languages['ru_RU']['NAME'] = 'Russian';
513 $languages['ru_RU']['ALTNAME'] = 'Русский';
514 $languages['ru_RU']['CHARSET'] = 'utf-8';
515 $languages['ru_RU']['LOCALE'] = 'ru_RU.UTF-8';
516 $languages['ru']['ALIAS'] = 'ru_RU';
518 $languages['sk_SK']['NAME'] = 'Slovak';
519 $languages['sk_SK']['CHARSET'] = 'iso-8859-2';
520 $languages['sk']['ALIAS'] = 'sk_SK';
522 $languages['sl_SI']['NAME'] = 'Slovenian';
523 $languages['sl_SI']['ALTNAME'] = 'Slovenščina';
524 $languages['sl_SI']['CHARSET'] = 'iso-8859-2';
525 $languages['sl']['ALIAS'] = 'sl_SI';
527 $languages['sr_YU']['NAME'] = 'Serbian';
528 $languages['sr_YU']['ALTNAME'] = 'Srpski';
529 $languages['sr_YU']['CHARSET'] = 'iso-8859-2';
530 $languages['sr']['ALIAS'] = 'sr_YU';
532 $languages['sv_SE']['NAME'] = 'Swedish';
533 $languages['sv_SE']['ALTNAME'] = 'Svenska';
534 $languages['sv_SE']['CHARSET'] = 'iso-8859-1';
535 $languages['sv']['ALIAS'] = 'sv_SE';
537 $languages['th_TH']['NAME'] = 'Thai';
538 $languages['th_TH']['CHARSET'] = 'tis-620';
539 $languages['th']['ALIAS'] = 'th_TH';
541 $languages['tr_TR']['NAME'] = 'Turkish';
542 $languages['tr_TR']['CHARSET'] = 'iso-8859-9';
543 $languages['tr']['ALIAS'] = 'tr_TR';
545 $languages['zh_TW']['NAME'] = 'Chinese Trad';
546 $languages['zh_TW']['CHARSET'] = 'big5';
547 $languages['tw']['ALIAS'] = 'zh_TW';
549 $languages['zh_CN']['NAME'] = 'Chinese Simp';
550 $languages['zh_CN']['CHARSET'] = 'gb2312';
551 $languages['cn']['ALIAS'] = 'zh_CN';
554 $languages['uk_UA']['NAME'] = 'Ukrainian';
555 $languages['uk_UA']['CHARSET'] = 'koi8-u';
556 $languages['uk']['ALIAS'] = 'uk_UA';
559 if ( file_exists( SM_PATH . 'locale/vi_VN') ) {
560 $languages['vi_VN']['NAME'] = 'Vietnamese';
561 $languages['vi_VN']['CHARSET'] = 'utf-8';
562 $languages['vi']['ALIAS'] = 'vi_VN';
566 // Right to left languages
567 $languages['ar']['NAME'] = 'Arabic';
568 $languages['ar']['CHARSET'] = 'windows-1256';
569 $languages['ar']['DIR'] = 'rtl';
571 $languages['he_IL']['NAME'] = 'Hebrew';
572 $languages['he_IL']['CHARSET'] = 'windows-1255';
573 $languages['he_IL']['DIR'] = 'rtl';
574 $languages['he']['ALIAS'] = 'he_IL';
576 /* Detect whether gettext is installed. */
578 if (function_exists('_')) {
581 if (function_exists('bindtextdomain')) {
584 if (function_exists('textdomain')) {
588 /* If gettext is fully loaded, cool */
589 if ($gettext_flags == 7) {
592 /* If we can fake gettext, try that */
593 elseif ($gettext_flags == 0) {
595 include_once(SM_PATH
. 'functions/gettext.php');
597 /* Uh-ho. A weird install */
598 if (! $gettext_flags & 1) {
603 if (! $gettext_flags & 2) {
604 function bindtextdomain() {
608 if (! $gettext_flags & 4) {
609 function textdomain() {
617 * Japanese charset extra function
620 function japanese_charset_xtra() {
621 $ret = func_get_arg(1); /* default return value */
622 if (function_exists('mb_detect_encoding')) {
623 switch (func_get_arg(0)) { /* action */
625 $detect_encoding = @mb_detect_encoding
($ret);
626 if ($detect_encoding == 'JIS' ||
627 $detect_encoding == 'EUC-JP' ||
628 $detect_encoding == 'SJIS' ||
629 $detect_encoding == 'UTF-8') {
631 $ret = mb_convert_kana(mb_convert_encoding($ret, 'EUC-JP', 'AUTO'), "KV");
635 $detect_encoding = @mb_detect_encoding
($ret);
636 if ($detect_encoding == 'JIS' ||
637 $detect_encoding == 'EUC-JP' ||
638 $detect_encoding == 'SJIS' ||
639 $detect_encoding == 'UTF-8') {
641 $ret = mb_convert_encoding(mb_convert_kana($ret, "KV"), 'JIS', 'AUTO');
645 $width = func_get_arg(2);
646 $ret = mb_strimwidth($ret, 0, $width, '...');
650 if (strlen($ret) > 0) {
651 $tmpstr = mb_substr($ret, 0, 1);
652 $prevcsize = strlen($tmpstr);
653 for ($i = 1; $i < mb_strlen($ret); $i++
) {
654 $tmp = mb_substr($ret, $i, 1);
655 if (strlen($tmp) == $prevcsize) {
658 if ($prevcsize == 1) {
661 $result .= str_replace(' ', '',
662 mb_encode_mimeheader($tmpstr,'iso-2022-jp','B',''));
665 $prevcsize = strlen($tmp);
668 if (strlen($tmpstr)) {
669 if (strlen(mb_substr($tmpstr, 0, 1)) == 1)
672 $result .= str_replace(' ', '',
673 mb_encode_mimeheader($tmpstr,'iso-2022-jp','B',''));
679 $ret = str_replace("\t", "", $ret);
680 if (eregi('=\\?([^?]+)\\?(q|b)\\?([^?]+)\\?=', $ret))
681 $ret = @mb_decode_mimeheader
($ret);
682 $ret = @mb_convert_encoding
($ret, 'EUC-JP', 'AUTO');
684 case 'downloadfilename':
685 $useragent = func_get_arg(2);
686 if (strstr($useragent, 'Windows') !== false ||
687 strstr($useragent, 'Mac_') !== false) {
688 $ret = mb_convert_encoding($ret, 'SJIS', 'AUTO');
690 $ret = mb_convert_encoding($ret, 'EUC-JP', 'AUTO');
694 $no_begin = "\x21\x25\x29\x2c\x2e\x3a\x3b\x3f\x5d\x7d\xa1\xf1\xa1\xeb\xa1" .
695 "\xc7\xa1\xc9\xa2\xf3\xa1\xec\xa1\xed\xa1\xee\xa1\xa2\xa1\xa3\xa1\xb9" .
696 "\xa1\xd3\xa1\xd5\xa1\xd7\xa1\xd9\xa1\xdb\xa1\xcd\xa4\xa1\xa4\xa3\xa4" .
697 "\xa5\xa4\xa7\xa4\xa9\xa4\xc3\xa4\xe3\xa4\xe5\xa4\xe7\xa4\xee\xa1\xab" .
698 "\xa1\xac\xa1\xb5\xa1\xb6\xa5\xa1\xa5\xa3\xa5\xa5\xa5\xa7\xa5\xa9\xa5" .
699 "\xc3\xa5\xe3\xa5\xe5\xa5\xe7\xa5\xee\xa5\xf5\xa5\xf6\xa1\xa6\xa1\xbc" .
700 "\xa1\xb3\xa1\xb4\xa1\xaa\xa1\xf3\xa1\xcb\xa1\xa4\xa1\xa5\xa1\xa7\xa1" .
701 "\xa8\xa1\xa9\xa1\xcf\xa1\xd1";
702 $no_end = "\x5c\x24\x28\x5b\x7b\xa1\xf2\x5c\xa1\xc6\xa1\xc8\xa1\xd2\xa1" .
703 "\xd4\xa1\xd6\xa1\xd8\xa1\xda\xa1\xcc\xa1\xf0\xa1\xca\xa1\xce\xa1\xd0\xa1\xef";
704 $wrap = func_get_arg(2);
706 if (strlen($ret) >= $wrap &&
707 substr($ret, 0, 1) != '>' &&
708 strpos($ret, 'http://') === FALSE &&
709 strpos($ret, 'https://') === FALSE &&
710 strpos($ret, 'ftp://') === FALSE) {
712 $ret = mb_convert_kana($ret, "KV");
717 while ($ptr < strlen($ret) - 1) {
718 $l = mb_strcut($ret, $ptr, $wrap);
722 $l = mb_strcut($ret, $ptr, 2);
723 while (strlen($l) != 0 && mb_strpos($no_begin, $l) !== FALSE ) {
726 $l = mb_strcut($ret, $ptr, 1);
729 if ($ptr < strlen($ret) - 1)
735 case 'utf7-imap_encode':
736 $ret = mb_convert_encoding($ret, 'UTF7-IMAP', 'EUC-JP');
738 case 'utf7-imap_decode':
739 $ret = mb_convert_encoding($ret, 'EUC-JP', 'UTF7-IMAP');
748 * Korean charset extra function
749 * Hangul(Korean Character) Attached File Name Fix.
751 function korean_charset_xtra() {
753 $ret = func_get_arg(1); /* default return value */
754 if (func_get_arg(0) == 'downloadfilename') { /* action */
755 $ret = str_replace("\x0D\x0A", '', $ret); /* Hanmail's CR/LF Clear */
756 for ($i=0;$i<strlen($ret);$i++
) {
757 if ($ret[$i] >= "\xA1" && $ret[$i] <= "\xFE") { /* 0xA1 - 0XFE are Valid */
760 } else if (($ret[$i] >= 'a' && $ret[$i] <= 'z') ||
/* From Original ereg_replace in download.php */
761 ($ret[$i] >= 'A' && $ret[$i] <= 'Z') ||
762 ($ret[$i] == '.') ||
($ret[$i] == '-')) {
775 * This function can be used to replace non-braking space symbols
776 * that are inserted in forms by some browsers instead of normal
779 function cleanup_nbsp($string,$charset) {
781 // reduce number of case statements
782 if (stristr('iso-8859-',substr($charset,0,9))){
783 $output_charset="iso-8859-x";
785 if (stristr('windows-125',substr($charset,0,11))){
786 $output_charset="cp125x";
788 if (stristr('koi8',substr($charset,0,4))){
789 $output_charset="koi8-x";
791 if (! isset($output_charset)){
792 $output_charset=strtolower($charset);
795 // where is non-braking space symbol
796 switch($output_charset):
809 // don't change string if charset is unmatched
813 // return space instead of non-braking space.
814 return str_replace($nbsp,' ',$string);
817 function is_conversion_safe($input_charset) {
818 global $languages, $sm_notAlias, $default_charset;
820 // convert to lower case
821 $input_charset = strtolower($input_charset);
823 // Is user's locale Unicode based ?
824 if ( $default_charset == "utf-8" ) {
828 // Charsets that are similar
829 switch ($default_charset):
831 if ( $input_charset == "iso-8859-5" ||
832 $input_charset == "koi8-r" ||
833 $input_charset == "koi8-u" ) {
839 if ( $input_charset == "iso-8859-13" ||
840 $input_charset == "iso-8859-4" ) {
846 if ( $input_charset == "iso-8859-13" ||
847 $input_charset == "windows-1257" ) {
853 if ( $input_charset == "windows-1251" ||
854 $input_charset == "koi8-r" ||
855 $input_charset == "koi8-u" ) {
861 if ( $input_charset == "iso-8859-4" ||
862 $input_charset == "windows-1257" ) {
868 if ( $input_charset == "windows-1251" ||
869 $input_charset == "iso-8859-5" ||
870 $input_charset == "koi8-u" ) {
876 if ( $input_charset == "windows-1251" ||
877 $input_charset == "iso-8859-5" ||
878 $input_charset == "koi8-r" ) {