| 1 | <?php |
| 2 | |
| 3 | /** |
| 4 | * SquirrelMail internationalization functions |
| 5 | * |
| 6 | * Copyright (c) 1999-2004 The SquirrelMail Project Team |
| 7 | * Licensed under the GNU GPL. For full terms see the file COPYING. |
| 8 | * |
| 9 | * This file contains variuos functions that are needed to do |
| 10 | * internationalization of SquirrelMail. |
| 11 | * |
| 12 | * Internally the output character set is used. Other characters are |
| 13 | * encoded using Unicode entities according to HTML 4.0. |
| 14 | * |
| 15 | * @version $Id$ |
| 16 | * @package squirrelmail |
| 17 | * @subpackage i18n |
| 18 | */ |
| 19 | |
| 20 | /** Everything uses global.php... */ |
| 21 | require_once(SM_PATH . 'functions/global.php'); |
| 22 | |
| 23 | /** |
| 24 | * Gettext bindtextdomain wrapper. |
| 25 | * |
| 26 | * Wrapper solves differences between php versions in order to provide |
| 27 | * ngettext support. Should be used if translation uses ngettext |
| 28 | * functions. |
| 29 | * @param string $domain gettext domain name |
| 30 | * @param string $dir directory that contains all translations |
| 31 | * @return string path to translation directory |
| 32 | */ |
| 33 | function sq_bindtextdomain($domain,$dir) { |
| 34 | global $l10n, $gettext_flags, $sm_notAlias; |
| 35 | |
| 36 | if ($gettext_flags==7) { |
| 37 | // gettext extension without ngettext |
| 38 | if (substr($dir, -1) != '/') $dir .= '/'; |
| 39 | $mofile=$dir . $sm_notAlias . '/LC_MESSAGES/' . $domain . '.mo'; |
| 40 | $input = new FileReader($mofile); |
| 41 | $l10n[$domain] = new gettext_reader($input); |
| 42 | } |
| 43 | |
| 44 | $dir=bindtextdomain($domain,$dir); |
| 45 | |
| 46 | return $dir; |
| 47 | } |
| 48 | |
| 49 | /** |
| 50 | * Gettext textdomain wrapper. |
| 51 | * Makes sure that gettext_domain global is modified. |
| 52 | * @param string $name gettext domain name |
| 53 | * @return string gettext domain name |
| 54 | */ |
| 55 | function sq_textdomain($domain) { |
| 56 | global $gettext_domain; |
| 57 | $gettext_domain=textdomain($domain); |
| 58 | return $gettext_domain; |
| 59 | } |
| 60 | |
| 61 | /** |
| 62 | * Converts string from given charset to charset, that can be displayed by user translation. |
| 63 | * |
| 64 | * Function by default returns html encoded strings, if translation uses different encoding. |
| 65 | * If Japanese translation is used - function returns string converted to euc-jp |
| 66 | * If iconv or recode functions are enabled and translation uses utf-8 - function returns utf-8 encoded string. |
| 67 | * If $charset is not supported - function returns unconverted string. |
| 68 | * |
| 69 | * sanitizing of html tags is also done by this function. |
| 70 | * |
| 71 | * @param string $charset |
| 72 | * @param string $string Text to be decoded |
| 73 | * @return string decoded string |
| 74 | */ |
| 75 | function charset_decode ($charset, $string) { |
| 76 | global $languages, $squirrelmail_language, $default_charset; |
| 77 | global $use_php_recode, $use_php_iconv, $aggressive_decoding; |
| 78 | |
| 79 | if (isset($languages[$squirrelmail_language]['XTRA_CODE']) && |
| 80 | function_exists($languages[$squirrelmail_language]['XTRA_CODE'] . '_decode')) { |
| 81 | $string = call_user_func($languages[$squirrelmail_language]['XTRA_CODE'] . '_decode', $string); |
| 82 | } |
| 83 | |
| 84 | $charset = strtolower($charset); |
| 85 | |
| 86 | set_my_charset(); |
| 87 | |
| 88 | // Variables that allow to use functions without function_exist() calls |
| 89 | if (! isset($use_php_recode) || $use_php_recode=="" ) { |
| 90 | $use_php_recode=false; } |
| 91 | if (! isset($use_php_iconv) || $use_php_iconv=="" ) { |
| 92 | $use_php_iconv=false; } |
| 93 | |
| 94 | // Don't do conversion if charset is the same. |
| 95 | if ( $charset == strtolower($default_charset) ) |
| 96 | return htmlspecialchars($string); |
| 97 | |
| 98 | // catch iso-8859-8-i thing |
| 99 | if ( $charset == "iso-8859-8-i" ) |
| 100 | $charset = "iso-8859-8"; |
| 101 | |
| 102 | /* |
| 103 | * Recode converts html special characters automatically if you use |
| 104 | * 'charset..html' decoding. There is no documented way to put -d option |
| 105 | * into php recode function call. |
| 106 | */ |
| 107 | if ( $use_php_recode ) { |
| 108 | if ( $default_charset == "utf-8" ) { |
| 109 | // other charsets can be converted to utf-8 without loss. |
| 110 | // and output string is smaller |
| 111 | $string = recode_string($charset . "..utf-8",$string); |
| 112 | return htmlspecialchars($string); |
| 113 | } else { |
| 114 | $string = recode_string($charset . "..html",$string); |
| 115 | // recode does not convert single quote, htmlspecialchars does. |
| 116 | $string = str_replace("'", ''', $string); |
| 117 | return $string; |
| 118 | } |
| 119 | } |
| 120 | |
| 121 | // iconv functions does not have html target and can be used only with utf-8 |
| 122 | if ( $use_php_iconv && $default_charset=='utf-8') { |
| 123 | $string = iconv($charset,$default_charset,$string); |
| 124 | return htmlspecialchars($string); |
| 125 | } |
| 126 | |
| 127 | // If we don't use recode and iconv, we'll do it old way. |
| 128 | |
| 129 | /* All HTML special characters are 7 bit and can be replaced first */ |
| 130 | |
| 131 | $string = htmlspecialchars ($string); |
| 132 | |
| 133 | /* controls cpu and memory intensive decoding cycles */ |
| 134 | if (! isset($aggressive_decoding) || $aggressive_decoding=="" ) { |
| 135 | $aggressive_decoding=false; } |
| 136 | |
| 137 | $decode=fixcharset($charset); |
| 138 | $decodefile=SM_PATH . 'functions/decode/' . $decode . '.php'; |
| 139 | if (file_exists($decodefile)) { |
| 140 | include_once($decodefile); |
| 141 | $ret = call_user_func('charset_decode_'.$decode, $string); |
| 142 | } else { |
| 143 | $ret = $string; |
| 144 | } |
| 145 | return( $ret ); |
| 146 | } |
| 147 | |
| 148 | /** |
| 149 | * Converts html string to given charset |
| 150 | * @param string $string |
| 151 | * @param string $charset |
| 152 | * @param boolean $htmlencode keep htmlspecialchars encoding |
| 153 | * @param string |
| 154 | */ |
| 155 | function charset_encode($string,$charset,$htmlencode=true) { |
| 156 | global $default_charset; |
| 157 | |
| 158 | // Undo html special chars |
| 159 | if (! $htmlencode ) { |
| 160 | $string = str_replace(array('&','>','<','"'),array('&','>','<','"'),$string); |
| 161 | } |
| 162 | |
| 163 | $encode=fixcharset($charset); |
| 164 | $encodefile=SM_PATH . 'functions/encode/' . $encode . '.php'; |
| 165 | if (file_exists($encodefile)) { |
| 166 | include_once($encodefile); |
| 167 | $ret = call_user_func('charset_encode_'.$encode, $string); |
| 168 | } else { |
| 169 | include_once(SM_PATH . 'functions/encode/us_ascii.php'); |
| 170 | $ret = charset_encode_us_ascii($string); |
| 171 | } |
| 172 | return( $ret ); |
| 173 | } |
| 174 | |
| 175 | /** |
| 176 | * Combined decoding and encoding functions |
| 177 | * |
| 178 | * If conversion is done to charset different that utf-8, unsupported symbols |
| 179 | * will be replaced with question marks. |
| 180 | * @param string $in_charset initial charset |
| 181 | * @param string $string string that has to be converted |
| 182 | * @param string $out_charset final charset |
| 183 | * @param boolean $htmlencode keep htmlspecialchars encoding |
| 184 | * @return string converted string |
| 185 | */ |
| 186 | function charset_convert($in_charset,$string,$out_charset,$htmlencode=true) { |
| 187 | $string=charset_decode($in_charset,$string); |
| 188 | $string=charset_encode($string,$out_charset,$htmlencode); |
| 189 | return $string; |
| 190 | } |
| 191 | |
| 192 | /** |
| 193 | * Makes charset name suitable for decoding cycles |
| 194 | * |
| 195 | * @param string $charset Name of charset |
| 196 | * @return string $charset Adjusted name of charset |
| 197 | */ |
| 198 | function fixcharset($charset) { |
| 199 | // minus removed from function names |
| 200 | $charset=str_replace('-','_',$charset); |
| 201 | |
| 202 | // windows-125x and cp125x charsets |
| 203 | $charset=str_replace('windows_','cp',$charset); |
| 204 | |
| 205 | // ibm > cp |
| 206 | $charset=str_replace('ibm','cp',$charset); |
| 207 | |
| 208 | // iso-8859-8-i -> iso-8859-8 |
| 209 | // use same cycle until I'll find differences |
| 210 | $charset=str_replace('iso_8859_8_i','iso_8859_8',$charset); |
| 211 | |
| 212 | return $charset; |
| 213 | } |
| 214 | |
| 215 | /** |
| 216 | * Set up the language to be output |
| 217 | * if $do_search is true, then scan the browser information |
| 218 | * for a possible language that we know |
| 219 | * |
| 220 | * Function sets system locale environment (LC_ALL, LANG, LANGUAGE), |
| 221 | * gettext translation bindings and html header information. |
| 222 | * |
| 223 | * Function returns error codes, if there is some fatal error. |
| 224 | * 0 = no error, |
| 225 | * 1 = mbstring support is not present, |
| 226 | * 2 = mbstring support is not present, user's translation reverted to en_US. |
| 227 | * |
| 228 | * @param string $sm_language translation used by user's interface |
| 229 | * @param bool $do_search use browser's preferred language detection functions. Defaults to false. |
| 230 | * @param bool $default set $sm_language to $squirrelmail_default_language if language detection fails or language is not set. Defaults to false. |
| 231 | * @return int function execution error codes. |
| 232 | */ |
| 233 | function set_up_language($sm_language, $do_search = false, $default = false) { |
| 234 | |
| 235 | static $SetupAlready = 0; |
| 236 | global $use_gettext, $languages, |
| 237 | $squirrelmail_language, $squirrelmail_default_language, $default_charset, |
| 238 | $sm_notAlias, $username, $data_dir; |
| 239 | |
| 240 | if ($SetupAlready) { |
| 241 | return; |
| 242 | } |
| 243 | |
| 244 | $SetupAlready = TRUE; |
| 245 | sqgetGlobalVar('HTTP_ACCEPT_LANGUAGE', $accept_lang, SQ_SERVER); |
| 246 | |
| 247 | if ($do_search && ! $sm_language && isset($accept_lang)) { |
| 248 | $sm_language = substr($accept_lang, 0, 2); |
| 249 | } |
| 250 | |
| 251 | if ((!$sm_language||$default) && isset($squirrelmail_default_language)) { |
| 252 | $squirrelmail_language = $squirrelmail_default_language; |
| 253 | $sm_language = $squirrelmail_default_language; |
| 254 | } |
| 255 | $sm_notAlias = $sm_language; |
| 256 | |
| 257 | // Catching removed translation |
| 258 | // System reverts to English translation if user prefs contain translation |
| 259 | // that is not available in $languages array |
| 260 | if (!isset($languages[$sm_notAlias])) { |
| 261 | $sm_notAlias="en_US"; |
| 262 | } |
| 263 | |
| 264 | while (isset($languages[$sm_notAlias]['ALIAS'])) { |
| 265 | $sm_notAlias = $languages[$sm_notAlias]['ALIAS']; |
| 266 | } |
| 267 | |
| 268 | if ( isset($sm_language) && |
| 269 | $use_gettext && |
| 270 | $sm_language != '' && |
| 271 | isset($languages[$sm_notAlias]['CHARSET']) ) { |
| 272 | sq_bindtextdomain( 'squirrelmail', SM_PATH . 'locale/' ); |
| 273 | sq_textdomain( 'squirrelmail' ); |
| 274 | if (function_exists('bind_textdomain_codeset')) { |
| 275 | if ($sm_notAlias == 'ja_JP') { |
| 276 | bind_textdomain_codeset ("squirrelmail", 'EUC-JP'); |
| 277 | } else { |
| 278 | bind_textdomain_codeset ("squirrelmail", $languages[$sm_notAlias]['CHARSET'] ); |
| 279 | } |
| 280 | } |
| 281 | if (isset($languages[$sm_notAlias]['LOCALE'])){ |
| 282 | $longlocale=$languages[$sm_notAlias]['LOCALE']; |
| 283 | } else { |
| 284 | $longlocale=$sm_notAlias; |
| 285 | } |
| 286 | if ( !ini_get('safe_mode') && |
| 287 | getenv( 'LC_ALL' ) != $longlocale ) { |
| 288 | putenv( "LC_ALL=$longlocale" ); |
| 289 | putenv( "LANG=$longlocale" ); |
| 290 | putenv( "LANGUAGE=$longlocale" ); |
| 291 | if ($sm_notAlias=='tr_TR') putenv( "LC_CTYPE=C" ); |
| 292 | } |
| 293 | setlocale(LC_ALL, $longlocale); |
| 294 | if ($sm_notAlias=='tr_TR') setlocale(LC_CTYPE,'C'); |
| 295 | |
| 296 | // Set text direction/alignment variables |
| 297 | if (isset($languages[$sm_notAlias]['DIR']) && |
| 298 | $languages[$sm_notAlias]['DIR'] == 'rtl') { |
| 299 | /** |
| 300 | * Text direction |
| 301 | * @global string $text_direction |
| 302 | */ |
| 303 | $text_direction='rtl'; |
| 304 | /** |
| 305 | * Left alignment |
| 306 | * @global string $left_align |
| 307 | */ |
| 308 | $left_align='right'; |
| 309 | /** |
| 310 | * Right alignment |
| 311 | * @global string $right_align |
| 312 | */ |
| 313 | $right_align='left'; |
| 314 | } else { |
| 315 | $text_direction='ltr'; |
| 316 | $left_align='left'; |
| 317 | $right_align='right'; |
| 318 | } |
| 319 | |
| 320 | $squirrelmail_language = $sm_notAlias; |
| 321 | if ($squirrelmail_language == 'ja_JP') { |
| 322 | header ('Content-Type: text/html; charset=EUC-JP'); |
| 323 | if (!function_exists('mb_internal_encoding')) { |
| 324 | // Error messages can't be displayed here |
| 325 | $error = 1; |
| 326 | // Revert to English if possible. |
| 327 | if (function_exists('setPref') && $username!='' && $data_dir!="") { |
| 328 | setPref($data_dir, $username, 'language', "en_US"); |
| 329 | $error = 2; |
| 330 | } |
| 331 | // stop further execution in order not to get php errors on mb_internal_encoding(). |
| 332 | return $error; |
| 333 | } |
| 334 | if (function_exists('mb_language')) { |
| 335 | mb_language('Japanese'); |
| 336 | } |
| 337 | mb_internal_encoding('EUC-JP'); |
| 338 | mb_http_output('pass'); |
| 339 | } elseif ($squirrelmail_language == 'en_US') { |
| 340 | header( 'Content-Type: text/html; charset=' . $default_charset ); |
| 341 | } else { |
| 342 | header( 'Content-Type: text/html; charset=' . $languages[$sm_notAlias]['CHARSET'] ); |
| 343 | } |
| 344 | } |
| 345 | return 0; |
| 346 | } |
| 347 | |
| 348 | /** |
| 349 | * Sets default_charset variable according to the one that is used by user's translations. |
| 350 | * |
| 351 | * Function changes global $default_charset variable in order to be sure, that it |
| 352 | * contains charset used by user's translation. Sanity of $squirrelmail_default_language |
| 353 | * and $default_charset combination provided in SquirrelMail config is also tested. |
| 354 | * |
| 355 | * There can be a $default_charset setting in the |
| 356 | * config.php file, but the user may have a different language |
| 357 | * selected for a user interface. This function checks the |
| 358 | * language selected by the user and tags the outgoing messages |
| 359 | * with the appropriate charset corresponding to the language |
| 360 | * selection. This is "more right" (tm), than just stamping the |
| 361 | * message blindly with the system-wide $default_charset. |
| 362 | */ |
| 363 | function set_my_charset(){ |
| 364 | global $data_dir, $username, $default_charset, $languages, $squirrelmail_default_language; |
| 365 | |
| 366 | $my_language = getPref($data_dir, $username, 'language'); |
| 367 | if (!$my_language) { |
| 368 | $my_language = $squirrelmail_default_language ; |
| 369 | } |
| 370 | // Catch removed translation |
| 371 | if (!isset($languages[$my_language])) { |
| 372 | $my_language="en_US"; |
| 373 | } |
| 374 | while (isset($languages[$my_language]['ALIAS'])) { |
| 375 | $my_language = $languages[$my_language]['ALIAS']; |
| 376 | } |
| 377 | $my_charset = $languages[$my_language]['CHARSET']; |
| 378 | if ($my_language!='en_US') { |
| 379 | $default_charset = $my_charset; |
| 380 | } |
| 381 | } |
| 382 | |
| 383 | /* ------------------------------ main --------------------------- */ |
| 384 | |
| 385 | global $squirrelmail_language, $languages, $use_gettext; |
| 386 | |
| 387 | if (! isset($squirrelmail_language)) { |
| 388 | $squirrelmail_language = ''; |
| 389 | } |
| 390 | |
| 391 | /** |
| 392 | * Array specifies the available translations. |
| 393 | * |
| 394 | * Structure of array: |
| 395 | * $languages['language']['variable'] = 'value' |
| 396 | * |
| 397 | * Possible 'variable' names: |
| 398 | * NAME - Translation name in English |
| 399 | * CHARSET - Encoding used by translation |
| 400 | * ALIAS - used when 'language' is only short name and 'value' should provide long language name |
| 401 | * ALTNAME - Native translation name. Any 8bit symbols must be html encoded. |
| 402 | * LOCALE - Full locale name (in xx_XX.charset format) |
| 403 | * DIR - Text direction. Used to define Right-to-Left languages. Possible values 'rtl' or 'ltr'. If undefined - defaults to 'ltr' |
| 404 | * XTRA_CODE - translation uses special functions. See doc/i18n.txt |
| 405 | * |
| 406 | * Each 'language' definition requires NAME+CHARSET or ALIAS variables. |
| 407 | * |
| 408 | * @name $languages |
| 409 | * @global array $languages |
| 410 | */ |
| 411 | $languages['bg_BG']['NAME'] = 'Bulgarian'; |
| 412 | $languages['bg_BG']['ALTNAME'] = 'Български'; |
| 413 | $languages['bg_BG']['CHARSET'] = 'windows-1251'; |
| 414 | $languages['bg_BG']['LOCALE'] = 'bg_BG.CP1251'; |
| 415 | $languages['bg']['ALIAS'] = 'bg_BG'; |
| 416 | |
| 417 | $languages['bn_IN']['NAME'] = 'Bengali'; |
| 418 | $languages['bn_IN']['CHARSET'] = 'utf-8'; |
| 419 | $languages['bn_IN']['LOCALE'] = 'bn_IN.UTF-8'; |
| 420 | $languages['bn']['ALIAS'] = 'bn_IN'; |
| 421 | |
| 422 | $languages['ca_ES']['NAME'] = 'Catalan'; |
| 423 | $languages['ca_ES']['CHARSET'] = 'iso-8859-1'; |
| 424 | $languages['ca_ES']['LOCALE'] = 'ca_ES.ISO8859-1'; |
| 425 | $languages['ca']['ALIAS'] = 'ca_ES'; |
| 426 | |
| 427 | $languages['cs_CZ']['NAME'] = 'Czech'; |
| 428 | $languages['cs_CZ']['ALTNAME'] = 'Čeština'; |
| 429 | $languages['cs_CZ']['CHARSET'] = 'iso-8859-2'; |
| 430 | $languages['cs_CZ']['LOCALE'] = 'cs_CZ.ISO8859-2'; |
| 431 | $languages['cs']['ALIAS'] = 'cs_CZ'; |
| 432 | |
| 433 | $languages['cy_GB']['NAME'] = 'Welsh'; |
| 434 | $languages['cy_GB']['ALTNAME'] = 'Cymraeg'; |
| 435 | $languages['cy_GB']['CHARSET'] = 'iso-8859-1'; |
| 436 | $languages['cy_GB']['LOCALE'] = 'cy_GB.ISO8859-1'; |
| 437 | $languages['cy']['ALIAS'] = 'cy_GB'; |
| 438 | |
| 439 | // Danish locale is da_DK. |
| 440 | $languages['da_DK']['NAME'] = 'Danish'; |
| 441 | $languages['da_DK']['ALTNAME'] = 'Dansk'; |
| 442 | $languages['da_DK']['CHARSET'] = 'iso-8859-1'; |
| 443 | $languages['da_DK']['LOCALE'] = 'da_DK.ISO8859-1'; |
| 444 | $languages['da']['ALIAS'] = 'da_DK'; |
| 445 | |
| 446 | $languages['de_DE']['NAME'] = 'German'; |
| 447 | $languages['de_DE']['ALTNAME'] = 'Deutsch'; |
| 448 | $languages['de_DE']['CHARSET'] = 'iso-8859-1'; |
| 449 | $languages['de_DE']['LOCALE'] = 'de_DE.ISO8859-1'; |
| 450 | $languages['de']['ALIAS'] = 'de_DE'; |
| 451 | |
| 452 | $languages['el_GR']['NAME'] = 'Greek'; |
| 453 | $languages['el_GR']['ALTNAME'] = 'Ελληνικά'; |
| 454 | $languages['el_GR']['CHARSET'] = 'iso-8859-7'; |
| 455 | $languages['el_GR']['LOCALE'] = 'el_GR.ISO8859-7'; |
| 456 | $languages['el']['ALIAS'] = 'el_GR'; |
| 457 | |
| 458 | $languages['en_GB']['NAME'] = 'British'; |
| 459 | $languages['en_GB']['CHARSET'] = 'iso-8859-15'; |
| 460 | $languages['en_GB']['LOCALE'] = 'en_GB.ISO8859-15'; |
| 461 | |
| 462 | $languages['en_US']['NAME'] = 'English'; |
| 463 | $languages['en_US']['CHARSET'] = 'iso-8859-1'; |
| 464 | $languages['en_US']['LOCALE'] = 'en_US.ISO8859-1'; |
| 465 | $languages['en']['ALIAS'] = 'en_US'; |
| 466 | |
| 467 | $languages['es_ES']['NAME'] = 'Spanish'; |
| 468 | $languages['es_ES']['ALTNAME'] = 'Español'; |
| 469 | $languages['es_ES']['CHARSET'] = 'iso-8859-1'; |
| 470 | $languages['es_ES']['LOCALE'] = 'es_ES.ISO8859-1'; |
| 471 | $languages['es']['ALIAS'] = 'es_ES'; |
| 472 | |
| 473 | $languages['et_EE']['NAME'] = 'Estonian'; |
| 474 | $languages['et_EE']['CHARSET'] = 'iso-8859-15'; |
| 475 | $languages['et_EE']['LOCALE'] = 'et_EE.ISO8859-15'; |
| 476 | $languages['et']['ALIAS'] = 'et_EE'; |
| 477 | |
| 478 | $languages['eu_ES']['NAME'] = 'Basque'; |
| 479 | $languages['eu_ES']['CHARSET'] = 'iso-8859-1'; |
| 480 | $languages['eu_ES']['LOCALE'] = 'eu_ES.ISO8859-1'; |
| 481 | $languages['eu']['ALIAS'] = 'eu_ES'; |
| 482 | |
| 483 | $languages['fo_FO']['NAME'] = 'Faroese'; |
| 484 | $languages['fo_FO']['CHARSET'] = 'iso-8859-1'; |
| 485 | $languages['fo_FO']['LOCALE'] = 'fo_FO.ISO8859-1'; |
| 486 | $languages['fo']['ALIAS'] = 'fo_FO'; |
| 487 | |
| 488 | $languages['fi_FI']['NAME'] = 'Finnish'; |
| 489 | $languages['fi_FI']['ALTNAME'] = 'Suomi'; |
| 490 | $languages['fi_FI']['CHARSET'] = 'iso-8859-1'; |
| 491 | $languages['fi_FI']['LOCALE'] = 'fi_FI.ISO8859-1'; |
| 492 | $languages['fi']['ALIAS'] = 'fi_FI'; |
| 493 | |
| 494 | $languages['fr_FR']['NAME'] = 'French'; |
| 495 | $languages['fr_FR']['ALTNAME'] = 'Français'; |
| 496 | $languages['fr_FR']['CHARSET'] = 'iso-8859-1'; |
| 497 | $languages['fr_FR']['LOCALE'] = 'fr_FR.ISO8859-1'; |
| 498 | $languages['fr']['ALIAS'] = 'fr_FR'; |
| 499 | |
| 500 | $languages['hr_HR']['NAME'] = 'Croatian'; |
| 501 | $languages['hr_HR']['CHARSET'] = 'iso-8859-2'; |
| 502 | $languages['hr_HR']['LOCALE'] = 'hr_HR.ISO8859-2'; |
| 503 | $languages['hr']['ALIAS'] = 'hr_HR'; |
| 504 | |
| 505 | $languages['hu_HU']['NAME'] = 'Hungarian'; |
| 506 | $languages['hu_HU']['ALTNAME'] = 'Magyar'; |
| 507 | $languages['hu_HU']['CHARSET'] = 'iso-8859-2'; |
| 508 | $languages['hu_HU']['LOCALE'] = 'hu_HU.ISO8859-2'; |
| 509 | $languages['hu']['ALIAS'] = 'hu_HU'; |
| 510 | |
| 511 | $languages['id_ID']['NAME'] = 'Indonesian'; |
| 512 | $languages['id_ID']['ALTNAME'] = 'Bahasa Indonesia'; |
| 513 | $languages['id_ID']['CHARSET'] = 'iso-8859-1'; |
| 514 | $languages['id_ID']['LOCALE'] = 'id_ID.ISO8859-1'; |
| 515 | $languages['id']['ALIAS'] = 'id_ID'; |
| 516 | |
| 517 | $languages['is_IS']['NAME'] = 'Icelandic'; |
| 518 | $languages['is_IS']['ALTNAME'] = 'Íslenska'; |
| 519 | $languages['is_IS']['CHARSET'] = 'iso-8859-1'; |
| 520 | $languages['is_IS']['LOCALE'] = 'is_IS.ISO8859-1'; |
| 521 | $languages['is']['ALIAS'] = 'is_IS'; |
| 522 | |
| 523 | $languages['it_IT']['NAME'] = 'Italian'; |
| 524 | $languages['it_IT']['CHARSET'] = 'iso-8859-1'; |
| 525 | $languages['it_IT']['LOCALE'] = 'it_IT.ISO8859-1'; |
| 526 | $languages['it']['ALIAS'] = 'it_IT'; |
| 527 | |
| 528 | $languages['ja_JP']['NAME'] = 'Japanese'; |
| 529 | $languages['ja_JP']['ALTNAME'] = '日本語'; |
| 530 | $languages['ja_JP']['CHARSET'] = 'iso-2022-jp'; |
| 531 | $languages['ja_JP']['LOCALE'] = 'ja_JP.EUC-JP'; |
| 532 | $languages['ja_JP']['XTRA_CODE'] = 'japanese_xtra'; |
| 533 | $languages['ja']['ALIAS'] = 'ja_JP'; |
| 534 | |
| 535 | $languages['ko_KR']['NAME'] = 'Korean'; |
| 536 | $languages['ko_KR']['CHARSET'] = 'euc-KR'; |
| 537 | $languages['ko_KR']['LOCALE'] = 'ko_KR.EUC-KR'; |
| 538 | $languages['ko_KR']['XTRA_CODE'] = 'korean_xtra'; |
| 539 | $languages['ko']['ALIAS'] = 'ko_KR'; |
| 540 | |
| 541 | $languages['lt_LT']['NAME'] = 'Lithuanian'; |
| 542 | $languages['lt_LT']['ALTNAME'] = 'Lietuvių'; |
| 543 | $languages['lt_LT']['CHARSET'] = 'utf-8'; |
| 544 | $languages['lt_LT']['LOCALE'] = 'lt_LT.UTF-8'; |
| 545 | $languages['lt']['ALIAS'] = 'lt_LT'; |
| 546 | |
| 547 | $languages['nl_NL']['NAME'] = 'Dutch'; |
| 548 | $languages['nl_NL']['ALTNAME'] = 'Nederlands'; |
| 549 | $languages['nl_NL']['CHARSET'] = 'iso-8859-1'; |
| 550 | $languages['nl_NL']['LOCALE'] = 'nl_NL.ISO8859-1'; |
| 551 | $languages['nl']['ALIAS'] = 'nl_NL'; |
| 552 | |
| 553 | $languages['ms_MY']['NAME'] = 'Malay'; |
| 554 | $languages['ms_MY']['ALTNAME'] = 'Bahasa Melayu'; |
| 555 | $languages['ms_MY']['CHARSET'] = 'iso-8859-1'; |
| 556 | $languages['ms_MY']['LOCALE'] = 'ms_MY.ISO8859-1'; |
| 557 | $languages['my']['ALIAS'] = 'ms_MY'; |
| 558 | |
| 559 | $languages['nb_NO']['NAME'] = 'Norwegian (Bokmål)'; |
| 560 | $languages['nb_NO']['ALTNAME'] = 'Norsk (Bokmål)'; |
| 561 | $languages['nb_NO']['CHARSET'] = 'iso-8859-1'; |
| 562 | $languages['nb_NO']['LOCALE'] = 'nb_NO.ISO8859-1'; |
| 563 | $languages['nb']['ALIAS'] = 'nb_NO'; |
| 564 | |
| 565 | $languages['nn_NO']['NAME'] = 'Norwegian (Nynorsk)'; |
| 566 | $languages['nn_NO']['ALTNAME'] = 'Norsk (Nynorsk)'; |
| 567 | $languages['nn_NO']['CHARSET'] = 'iso-8859-1'; |
| 568 | $languages['nn_NO']['LOCALE'] = 'nn_NO.ISO8859-1'; |
| 569 | |
| 570 | $languages['pl_PL']['NAME'] = 'Polish'; |
| 571 | $languages['pl_PL']['ALTNAME'] = 'Polski'; |
| 572 | $languages['pl_PL']['CHARSET'] = 'iso-8859-2'; |
| 573 | $languages['pl_PL']['LOCALE'] = 'pl_PL.ISO8859-2'; |
| 574 | $languages['pl']['ALIAS'] = 'pl_PL'; |
| 575 | |
| 576 | $languages['pt_PT']['NAME'] = 'Portuguese (Portugal)'; |
| 577 | $languages['pt_PT']['CHARSET'] = 'iso-8859-1'; |
| 578 | $languages['pt_PT']['LOCALE'] = 'pt_PT.ISO8859-1'; |
| 579 | $languages['pt']['ALIAS'] = 'pt_PT'; |
| 580 | |
| 581 | $languages['pt_BR']['NAME'] = 'Portuguese (Brazil)'; |
| 582 | $languages['pt_BR']['ALTNAME'] = 'Português do Brasil'; |
| 583 | $languages['pt_BR']['CHARSET'] = 'iso-8859-1'; |
| 584 | $languages['pt_BR']['LOCALE'] = 'pt_BR.ISO8859-1'; |
| 585 | |
| 586 | $languages['ro_RO']['NAME'] = 'Romanian'; |
| 587 | $languages['ro_RO']['ALTNAME'] = 'Română'; |
| 588 | $languages['ro_RO']['CHARSET'] = 'iso-8859-2'; |
| 589 | $languages['ro_RO']['LOCALE'] = 'ro_RO.ISO8859-2'; |
| 590 | $languages['ro']['ALIAS'] = 'ro_RO'; |
| 591 | |
| 592 | $languages['ru_RU']['NAME'] = 'Russian'; |
| 593 | $languages['ru_RU']['ALTNAME'] = 'Русский'; |
| 594 | $languages['ru_RU']['CHARSET'] = 'utf-8'; |
| 595 | $languages['ru_RU']['LOCALE'] = 'ru_RU.UTF-8'; |
| 596 | $languages['ru']['ALIAS'] = 'ru_RU'; |
| 597 | |
| 598 | $languages['sk_SK']['NAME'] = 'Slovak'; |
| 599 | $languages['sk_SK']['CHARSET'] = 'iso-8859-2'; |
| 600 | $languages['sk_SK']['LOCALE'] = 'sk_SK.ISO8859-2'; |
| 601 | $languages['sk']['ALIAS'] = 'sk_SK'; |
| 602 | |
| 603 | $languages['sl_SI']['NAME'] = 'Slovenian'; |
| 604 | $languages['sl_SI']['ALTNAME'] = 'Slovenščina'; |
| 605 | $languages['sl_SI']['CHARSET'] = 'iso-8859-2'; |
| 606 | $languages['sl_SI']['LOCALE'] = 'sl_SI.ISO8859-2'; |
| 607 | $languages['sl']['ALIAS'] = 'sl_SI'; |
| 608 | |
| 609 | $languages['sr_YU']['NAME'] = 'Serbian'; |
| 610 | $languages['sr_YU']['ALTNAME'] = 'Srpski'; |
| 611 | $languages['sr_YU']['CHARSET'] = 'iso-8859-2'; |
| 612 | $languages['sr_YU']['LOCALE'] = 'sr_YU.ISO8859-2'; |
| 613 | $languages['sr']['ALIAS'] = 'sr_YU'; |
| 614 | |
| 615 | $languages['sv_SE']['NAME'] = 'Swedish'; |
| 616 | $languages['sv_SE']['ALTNAME'] = 'Svenska'; |
| 617 | $languages['sv_SE']['CHARSET'] = 'iso-8859-1'; |
| 618 | $languages['sv_SE']['LOCALE'] = 'sv_SE.ISO8859-1'; |
| 619 | $languages['sv']['ALIAS'] = 'sv_SE'; |
| 620 | |
| 621 | $languages['th_TH']['NAME'] = 'Thai'; |
| 622 | $languages['th_TH']['CHARSET'] = 'tis-620'; |
| 623 | $languages['th_TH']['LOCALE'] = 'th_TH.TIS-620'; |
| 624 | $languages['th']['ALIAS'] = 'th_TH'; |
| 625 | |
| 626 | $languages['tl_PH']['NAME'] = 'Tagalog'; |
| 627 | $languages['tl_PH']['CHARSET'] = 'iso-8859-1'; |
| 628 | $languages['tl_PH']['LOCALE'] = 'tl_PH.ISO8859-1'; |
| 629 | $languages['tl']['ALIAS'] = 'tl_PH'; |
| 630 | |
| 631 | $languages['tr_TR']['NAME'] = 'Turkish'; |
| 632 | $languages['tr_TR']['CHARSET'] = 'iso-8859-9'; |
| 633 | $languages['tr_TR']['LOCALE'] = 'tr_TR.ISO8859-9'; |
| 634 | $languages['tr']['ALIAS'] = 'tr_TR'; |
| 635 | |
| 636 | $languages['zh_TW']['NAME'] = 'Chinese Trad'; |
| 637 | $languages['zh_TW']['CHARSET'] = 'big5'; |
| 638 | $languages['zh_TW']['LOCALE'] = 'zh_TW.BIG5'; |
| 639 | $languages['tw']['ALIAS'] = 'zh_TW'; |
| 640 | |
| 641 | $languages['zh_CN']['NAME'] = 'Chinese Simp'; |
| 642 | $languages['zh_CN']['CHARSET'] = 'gb2312'; |
| 643 | $languages['zh_CN']['LOCALE'] = 'zh_CN.GB2312'; |
| 644 | $languages['cn']['ALIAS'] = 'zh_CN'; |
| 645 | |
| 646 | $languages['uk_UA']['NAME'] = 'Ukrainian'; |
| 647 | $languages['uk_UA']['CHARSET'] = 'koi8-u'; |
| 648 | $languages['uk_UA']['LOCALE'] = 'uk_UA.KOI8-U'; |
| 649 | $languages['uk']['ALIAS'] = 'uk_UA'; |
| 650 | |
| 651 | $languages['ru_UA']['NAME'] = 'Russian (Ukrainian)'; |
| 652 | $languages['ru_UA']['CHARSET'] = 'koi8-r'; |
| 653 | $languages['ru_UA']['LOCALE'] = 'ru_UA.KOI8-R'; |
| 654 | |
| 655 | /* |
| 656 | $languages['vi_VN']['NAME'] = 'Vietnamese'; |
| 657 | $languages['vi_VN']['CHARSET'] = 'utf-8'; |
| 658 | $languages['vi']['ALIAS'] = 'vi_VN'; |
| 659 | */ |
| 660 | |
| 661 | // Right to left languages |
| 662 | $languages['ar']['NAME'] = 'Arabic'; |
| 663 | $languages['ar']['CHARSET'] = 'windows-1256'; |
| 664 | $languages['ar']['DIR'] = 'rtl'; |
| 665 | |
| 666 | $languages['fa_IR']['NAME'] = 'Farsi'; |
| 667 | $languages['fa_IR']['CHARSET'] = 'utf-8'; |
| 668 | $languages['fa_IR']['DIR'] = 'rtl'; |
| 669 | $languages['fa_IR']['LOCALE'] = 'fa_IR.UTF-8'; |
| 670 | $languages['fa']['ALIAS'] = 'fa_IR'; |
| 671 | |
| 672 | $languages['he_IL']['NAME'] = 'Hebrew'; |
| 673 | $languages['he_IL']['CHARSET'] = 'windows-1255'; |
| 674 | $languages['he_IL']['LOCALE'] = 'he_IL.CP1255'; |
| 675 | $languages['he_IL']['DIR'] = 'rtl'; |
| 676 | $languages['he']['ALIAS'] = 'he_IL'; |
| 677 | |
| 678 | $languages['ug']['NAME'] = 'Uighur'; |
| 679 | $languages['ug']['CHARSET'] = 'utf-8'; |
| 680 | $languages['ug']['DIR'] = 'rtl'; |
| 681 | |
| 682 | /* Detect whether gettext is installed. */ |
| 683 | $gettext_flags = 0; |
| 684 | if (function_exists('_')) { |
| 685 | $gettext_flags += 1; |
| 686 | } |
| 687 | if (function_exists('bindtextdomain')) { |
| 688 | $gettext_flags += 2; |
| 689 | } |
| 690 | if (function_exists('textdomain')) { |
| 691 | $gettext_flags += 4; |
| 692 | } |
| 693 | if (function_exists('ngettext')) { |
| 694 | $gettext_flags += 8; |
| 695 | } |
| 696 | |
| 697 | /* If gettext is fully loaded, cool */ |
| 698 | if ($gettext_flags == 15) { |
| 699 | $use_gettext = true; |
| 700 | } |
| 701 | |
| 702 | /* If ngettext support is missing, load it */ |
| 703 | elseif ($gettext_flags == 7) { |
| 704 | $use_gettext = true; |
| 705 | // load internal ngettext functions |
| 706 | include_once(SM_PATH . 'class/l10n.class.php'); |
| 707 | include_once(SM_PATH . 'functions/ngettext.php'); |
| 708 | } |
| 709 | |
| 710 | /* If we can fake gettext, try that */ |
| 711 | elseif ($gettext_flags == 0) { |
| 712 | $use_gettext = true; |
| 713 | include_once(SM_PATH . 'functions/gettext.php'); |
| 714 | } else { |
| 715 | /* Uh-ho. A weird install */ |
| 716 | if (! $gettext_flags & 1) { |
| 717 | /** |
| 718 | * Function is used as replacement in broken installs |
| 719 | * @ignore |
| 720 | */ |
| 721 | function _($str) { |
| 722 | return $str; |
| 723 | } |
| 724 | } |
| 725 | if (! $gettext_flags & 2) { |
| 726 | /** |
| 727 | * Function is used as replacement in broken installs |
| 728 | * @ignore |
| 729 | */ |
| 730 | function bindtextdomain() { |
| 731 | return; |
| 732 | } |
| 733 | } |
| 734 | if (! $gettext_flags & 4) { |
| 735 | /** |
| 736 | * Function is used as replacemet in broken installs |
| 737 | * @ignore |
| 738 | */ |
| 739 | function textdomain() { |
| 740 | return; |
| 741 | } |
| 742 | } |
| 743 | if (! $gettext_flags & 8) { |
| 744 | /** |
| 745 | * Function is used as replacemet in broken installs |
| 746 | * @ignore |
| 747 | */ |
| 748 | function ngettext($str,$str2,$number) { |
| 749 | if ($number>1) { |
| 750 | return $str2; |
| 751 | } else { |
| 752 | return $str; |
| 753 | } |
| 754 | } |
| 755 | } |
| 756 | } |
| 757 | |
| 758 | |
| 759 | /** |
| 760 | * Japanese charset extra function |
| 761 | * |
| 762 | * Action performed by function is defined by first argument. |
| 763 | * Default return value is defined by second argument. |
| 764 | * Use of third argument depends on action. |
| 765 | * |
| 766 | * @param string $action action performed by this function. |
| 767 | * possible values: |
| 768 | * decode - convert returned string to euc-jp. third argument unused |
| 769 | * encode - convert returned string to jis. third argument unused |
| 770 | * strimwidth - third argument=$width. trims string to $width symbols. |
| 771 | * encodeheader - create base64 encoded header in iso-2022-jp. third argument unused |
| 772 | * decodeheader - return human readable string from mime header. string is returned in euc-jp. third argument unused |
| 773 | * downloadfilename - third argument $useragent. Arguments provide browser info. Returns shift-jis or euc-jp encoded file name |
| 774 | * wordwrap - third argument=$wrap. wraps text at $wrap symbols |
| 775 | * utf7-imap_encode - returns string converted from euc-jp to utf7-imap. third argument unused |
| 776 | * utf7-imap_decode - returns string converted from utf7-imap to euc-jp. third argument unused |
| 777 | * @param string $ret default return value |
| 778 | */ |
| 779 | function japanese_xtra() { |
| 780 | $ret = func_get_arg(1); /* default return value */ |
| 781 | if (function_exists('mb_detect_encoding')) { |
| 782 | switch (func_get_arg(0)) { /* action */ |
| 783 | case 'decode': |
| 784 | $detect_encoding = @mb_detect_encoding($ret); |
| 785 | if ($detect_encoding == 'JIS' || |
| 786 | $detect_encoding == 'EUC-JP' || |
| 787 | $detect_encoding == 'SJIS' || |
| 788 | $detect_encoding == 'UTF-8') { |
| 789 | |
| 790 | $ret = mb_convert_kana(mb_convert_encoding($ret, 'EUC-JP', 'AUTO'), "KV"); |
| 791 | } |
| 792 | break; |
| 793 | case 'encode': |
| 794 | $detect_encoding = @mb_detect_encoding($ret); |
| 795 | if ($detect_encoding == 'JIS' || |
| 796 | $detect_encoding == 'EUC-JP' || |
| 797 | $detect_encoding == 'SJIS' || |
| 798 | $detect_encoding == 'UTF-8') { |
| 799 | |
| 800 | $ret = mb_convert_encoding(mb_convert_kana($ret, "KV"), 'JIS', 'AUTO'); |
| 801 | } |
| 802 | break; |
| 803 | case 'strimwidth': |
| 804 | $width = func_get_arg(2); |
| 805 | $ret = mb_strimwidth($ret, 0, $width, '...'); |
| 806 | break; |
| 807 | case 'encodeheader': |
| 808 | $result = ''; |
| 809 | if (strlen($ret) > 0) { |
| 810 | $tmpstr = mb_substr($ret, 0, 1); |
| 811 | $prevcsize = strlen($tmpstr); |
| 812 | for ($i = 1; $i < mb_strlen($ret); $i++) { |
| 813 | $tmp = mb_substr($ret, $i, 1); |
| 814 | if (strlen($tmp) == $prevcsize) { |
| 815 | $tmpstr .= $tmp; |
| 816 | } else { |
| 817 | if ($prevcsize == 1) { |
| 818 | $result .= $tmpstr; |
| 819 | } else { |
| 820 | $result .= str_replace(' ', '', |
| 821 | mb_encode_mimeheader($tmpstr,'iso-2022-jp','B','')); |
| 822 | } |
| 823 | $tmpstr = $tmp; |
| 824 | $prevcsize = strlen($tmp); |
| 825 | } |
| 826 | } |
| 827 | if (strlen($tmpstr)) { |
| 828 | if (strlen(mb_substr($tmpstr, 0, 1)) == 1) |
| 829 | $result .= $tmpstr; |
| 830 | else |
| 831 | $result .= str_replace(' ', '', |
| 832 | mb_encode_mimeheader($tmpstr,'iso-2022-jp','B','')); |
| 833 | } |
| 834 | } |
| 835 | $ret = $result; |
| 836 | break; |
| 837 | case 'decodeheader': |
| 838 | $ret = str_replace("\t", "", $ret); |
| 839 | if (eregi('=\\?([^?]+)\\?(q|b)\\?([^?]+)\\?=', $ret)) |
| 840 | $ret = @mb_decode_mimeheader($ret); |
| 841 | $ret = @mb_convert_encoding($ret, 'EUC-JP', 'AUTO'); |
| 842 | break; |
| 843 | case 'downloadfilename': |
| 844 | $useragent = func_get_arg(2); |
| 845 | if (strstr($useragent, 'Windows') !== false || |
| 846 | strstr($useragent, 'Mac_') !== false) { |
| 847 | $ret = mb_convert_encoding($ret, 'SJIS', 'AUTO'); |
| 848 | } else { |
| 849 | $ret = mb_convert_encoding($ret, 'EUC-JP', 'AUTO'); |
| 850 | } |
| 851 | break; |
| 852 | case 'wordwrap': |
| 853 | $no_begin = "\x21\x25\x29\x2c\x2e\x3a\x3b\x3f\x5d\x7d\xa1\xf1\xa1\xeb\xa1" . |
| 854 | "\xc7\xa1\xc9\xa2\xf3\xa1\xec\xa1\xed\xa1\xee\xa1\xa2\xa1\xa3\xa1\xb9" . |
| 855 | "\xa1\xd3\xa1\xd5\xa1\xd7\xa1\xd9\xa1\xdb\xa1\xcd\xa4\xa1\xa4\xa3\xa4" . |
| 856 | "\xa5\xa4\xa7\xa4\xa9\xa4\xc3\xa4\xe3\xa4\xe5\xa4\xe7\xa4\xee\xa1\xab" . |
| 857 | "\xa1\xac\xa1\xb5\xa1\xb6\xa5\xa1\xa5\xa3\xa5\xa5\xa5\xa7\xa5\xa9\xa5" . |
| 858 | "\xc3\xa5\xe3\xa5\xe5\xa5\xe7\xa5\xee\xa5\xf5\xa5\xf6\xa1\xa6\xa1\xbc" . |
| 859 | "\xa1\xb3\xa1\xb4\xa1\xaa\xa1\xf3\xa1\xcb\xa1\xa4\xa1\xa5\xa1\xa7\xa1" . |
| 860 | "\xa8\xa1\xa9\xa1\xcf\xa1\xd1"; |
| 861 | $no_end = "\x5c\x24\x28\x5b\x7b\xa1\xf2\x5c\xa1\xc6\xa1\xc8\xa1\xd2\xa1" . |
| 862 | "\xd4\xa1\xd6\xa1\xd8\xa1\xda\xa1\xcc\xa1\xf0\xa1\xca\xa1\xce\xa1\xd0\xa1\xef"; |
| 863 | $wrap = func_get_arg(2); |
| 864 | |
| 865 | if (strlen($ret) >= $wrap && |
| 866 | substr($ret, 0, 1) != '>' && |
| 867 | strpos($ret, 'http://') === FALSE && |
| 868 | strpos($ret, 'https://') === FALSE && |
| 869 | strpos($ret, 'ftp://') === FALSE) { |
| 870 | |
| 871 | $ret = mb_convert_kana($ret, "KV"); |
| 872 | |
| 873 | $line_new = ''; |
| 874 | $ptr = 0; |
| 875 | |
| 876 | while ($ptr < strlen($ret) - 1) { |
| 877 | $l = mb_strcut($ret, $ptr, $wrap); |
| 878 | $ptr += strlen($l); |
| 879 | $tmp = $l; |
| 880 | |
| 881 | $l = mb_strcut($ret, $ptr, 2); |
| 882 | while (strlen($l) != 0 && mb_strpos($no_begin, $l) !== FALSE ) { |
| 883 | $tmp .= $l; |
| 884 | $ptr += strlen($l); |
| 885 | $l = mb_strcut($ret, $ptr, 1); |
| 886 | } |
| 887 | $line_new .= $tmp; |
| 888 | if ($ptr < strlen($ret) - 1) |
| 889 | $line_new .= "\n"; |
| 890 | } |
| 891 | $ret = $line_new; |
| 892 | } |
| 893 | break; |
| 894 | case 'utf7-imap_encode': |
| 895 | $ret = mb_convert_encoding($ret, 'UTF7-IMAP', 'EUC-JP'); |
| 896 | break; |
| 897 | case 'utf7-imap_decode': |
| 898 | $ret = mb_convert_encoding($ret, 'EUC-JP', 'UTF7-IMAP'); |
| 899 | break; |
| 900 | } |
| 901 | } |
| 902 | return $ret; |
| 903 | } |
| 904 | |
| 905 | /************************** |
| 906 | * Japanese extra functions |
| 907 | **************************/ |
| 908 | |
| 909 | /** |
| 910 | * Japanese decoding function |
| 911 | * |
| 912 | * converts string to euc-jp, if string uses JIS, EUC-JP, ShiftJIS or UTF-8 |
| 913 | * charset. Needs mbstring support in php. |
| 914 | * @param string $ret text, that has to be converted |
| 915 | * @return string converted string |
| 916 | * @since 1.5.1 |
| 917 | */ |
| 918 | function japanese_xtra_decode($ret) { |
| 919 | if (function_exists('mb_detect_encoding')) { |
| 920 | $detect_encoding = @mb_detect_encoding($ret); |
| 921 | if ($detect_encoding == 'JIS' || |
| 922 | $detect_encoding == 'EUC-JP' || |
| 923 | $detect_encoding == 'SJIS' || |
| 924 | $detect_encoding == 'UTF-8') { |
| 925 | |
| 926 | $ret = mb_convert_kana(mb_convert_encoding($ret, 'EUC-JP', 'AUTO'), "KV"); |
| 927 | } |
| 928 | } |
| 929 | return $ret; |
| 930 | } |
| 931 | |
| 932 | /** |
| 933 | * Japanese encoding function |
| 934 | * |
| 935 | * converts string to jis, if string uses JIS, EUC-JP, ShiftJIS or UTF-8 |
| 936 | * charset. Needs mbstring support in php. |
| 937 | * @param string $ret text, that has to be converted |
| 938 | * @return string converted text |
| 939 | * @since 1.5.1 |
| 940 | */ |
| 941 | function japanese_xtra_encode($ret) { |
| 942 | if (function_exists('mb_detect_encoding')) { |
| 943 | $detect_encoding = @mb_detect_encoding($ret); |
| 944 | if ($detect_encoding == 'JIS' || |
| 945 | $detect_encoding == 'EUC-JP' || |
| 946 | $detect_encoding == 'SJIS' || |
| 947 | $detect_encoding == 'UTF-8') { |
| 948 | |
| 949 | $ret = mb_convert_encoding(mb_convert_kana($ret, "KV"), 'JIS', 'AUTO'); |
| 950 | } |
| 951 | } |
| 952 | return $ret; |
| 953 | } |
| 954 | |
| 955 | /** |
| 956 | * Japanese header encoding function |
| 957 | * |
| 958 | * creates base64 encoded header in iso-2022-jp charset |
| 959 | * @param string $ret text, that has to be converted |
| 960 | * @return string mime base64 encoded string |
| 961 | * @since 1.5.1 |
| 962 | */ |
| 963 | function japanese_xtra_encodeheader($ret) { |
| 964 | if (function_exists('mb_detect_encoding')) { |
| 965 | $result = ''; |
| 966 | if (strlen($ret) > 0) { |
| 967 | $tmpstr = mb_substr($ret, 0, 1); |
| 968 | $prevcsize = strlen($tmpstr); |
| 969 | for ($i = 1; $i < mb_strlen($ret); $i++) { |
| 970 | $tmp = mb_substr($ret, $i, 1); |
| 971 | if (strlen($tmp) == $prevcsize) { |
| 972 | $tmpstr .= $tmp; |
| 973 | } else { |
| 974 | if ($prevcsize == 1) { |
| 975 | $result .= $tmpstr; |
| 976 | } else { |
| 977 | $result .= str_replace(' ', '', |
| 978 | mb_encode_mimeheader($tmpstr,'iso-2022-jp','B','')); |
| 979 | } |
| 980 | $tmpstr = $tmp; |
| 981 | $prevcsize = strlen($tmp); |
| 982 | } |
| 983 | } |
| 984 | if (strlen($tmpstr)) { |
| 985 | if (strlen(mb_substr($tmpstr, 0, 1)) == 1) |
| 986 | $result .= $tmpstr; |
| 987 | else |
| 988 | $result .= str_replace(' ', '', |
| 989 | mb_encode_mimeheader($tmpstr,'iso-2022-jp','B','')); |
| 990 | } |
| 991 | } |
| 992 | $ret = $result; |
| 993 | } |
| 994 | return $ret; |
| 995 | } |
| 996 | |
| 997 | /** |
| 998 | * Japanese header decoding function |
| 999 | * |
| 1000 | * return human readable string from mime header. string is returned in euc-jp |
| 1001 | * charset. |
| 1002 | * @param string $ret header string |
| 1003 | * @return string decoded header string |
| 1004 | * @since 1.5.1 |
| 1005 | */ |
| 1006 | function japanese_xtra_decodeheader($ret) { |
| 1007 | if (function_exists('mb_detect_encoding')) { |
| 1008 | $ret = str_replace("\t", "", $ret); |
| 1009 | if (eregi('=\\?([^?]+)\\?(q|b)\\?([^?]+)\\?=', $ret)) |
| 1010 | $ret = @mb_decode_mimeheader($ret); |
| 1011 | $ret = @mb_convert_encoding($ret, 'EUC-JP', 'AUTO'); |
| 1012 | } |
| 1013 | return $ret; |
| 1014 | } |
| 1015 | |
| 1016 | /** |
| 1017 | * Japanese downloaded filename processing function |
| 1018 | * |
| 1019 | * Returns shift-jis or euc-jp encoded file name |
| 1020 | * @param string $ret string |
| 1021 | * @param string $useragent browser |
| 1022 | * @return string converted string |
| 1023 | * @since 1.5.1 |
| 1024 | */ |
| 1025 | function japanese_xtra_downloadfilename($ret,$useragent) { |
| 1026 | if (function_exists('mb_detect_encoding')) { |
| 1027 | if (strstr($useragent, 'Windows') !== false || |
| 1028 | strstr($useragent, 'Mac_') !== false) { |
| 1029 | $ret = mb_convert_encoding($ret, 'SJIS', 'AUTO'); |
| 1030 | } else { |
| 1031 | $ret = mb_convert_encoding($ret, 'EUC-JP', 'AUTO'); |
| 1032 | } |
| 1033 | } |
| 1034 | return $ret; |
| 1035 | } |
| 1036 | |
| 1037 | /** |
| 1038 | * Japanese wordwrap function |
| 1039 | * |
| 1040 | * wraps text at set number of symbols |
| 1041 | * @param string $ret text |
| 1042 | * @param integer $wrap number of symbols per line |
| 1043 | * @return string wrapped text |
| 1044 | * @since 1.5.1 |
| 1045 | */ |
| 1046 | function japanese_xtra_wordwrap($ret,$wrap) { |
| 1047 | if (function_exists('mb_detect_encoding')) { |
| 1048 | $no_begin = "\x21\x25\x29\x2c\x2e\x3a\x3b\x3f\x5d\x7d\xa1\xf1\xa1\xeb\xa1" . |
| 1049 | "\xc7\xa1\xc9\xa2\xf3\xa1\xec\xa1\xed\xa1\xee\xa1\xa2\xa1\xa3\xa1\xb9" . |
| 1050 | "\xa1\xd3\xa1\xd5\xa1\xd7\xa1\xd9\xa1\xdb\xa1\xcd\xa4\xa1\xa4\xa3\xa4" . |
| 1051 | "\xa5\xa4\xa7\xa4\xa9\xa4\xc3\xa4\xe3\xa4\xe5\xa4\xe7\xa4\xee\xa1\xab" . |
| 1052 | "\xa1\xac\xa1\xb5\xa1\xb6\xa5\xa1\xa5\xa3\xa5\xa5\xa5\xa7\xa5\xa9\xa5" . |
| 1053 | "\xc3\xa5\xe3\xa5\xe5\xa5\xe7\xa5\xee\xa5\xf5\xa5\xf6\xa1\xa6\xa1\xbc" . |
| 1054 | "\xa1\xb3\xa1\xb4\xa1\xaa\xa1\xf3\xa1\xcb\xa1\xa4\xa1\xa5\xa1\xa7\xa1" . |
| 1055 | "\xa8\xa1\xa9\xa1\xcf\xa1\xd1"; |
| 1056 | $no_end = "\x5c\x24\x28\x5b\x7b\xa1\xf2\x5c\xa1\xc6\xa1\xc8\xa1\xd2\xa1" . |
| 1057 | "\xd4\xa1\xd6\xa1\xd8\xa1\xda\xa1\xcc\xa1\xf0\xa1\xca\xa1\xce\xa1\xd0\xa1\xef"; |
| 1058 | |
| 1059 | if (strlen($ret) >= $wrap && |
| 1060 | substr($ret, 0, 1) != '>' && |
| 1061 | strpos($ret, 'http://') === FALSE && |
| 1062 | strpos($ret, 'https://') === FALSE && |
| 1063 | strpos($ret, 'ftp://') === FALSE) { |
| 1064 | |
| 1065 | $ret = mb_convert_kana($ret, "KV"); |
| 1066 | |
| 1067 | $line_new = ''; |
| 1068 | $ptr = 0; |
| 1069 | |
| 1070 | while ($ptr < strlen($ret) - 1) { |
| 1071 | $l = mb_strcut($ret, $ptr, $wrap); |
| 1072 | $ptr += strlen($l); |
| 1073 | $tmp = $l; |
| 1074 | |
| 1075 | $l = mb_strcut($ret, $ptr, 2); |
| 1076 | while (strlen($l) != 0 && mb_strpos($no_begin, $l) !== FALSE ) { |
| 1077 | $tmp .= $l; |
| 1078 | $ptr += strlen($l); |
| 1079 | $l = mb_strcut($ret, $ptr, 1); |
| 1080 | } |
| 1081 | $line_new .= $tmp; |
| 1082 | if ($ptr < strlen($ret) - 1) |
| 1083 | $line_new .= "\n"; |
| 1084 | } |
| 1085 | $ret = $line_new; |
| 1086 | } |
| 1087 | } |
| 1088 | return $ret; |
| 1089 | } |
| 1090 | |
| 1091 | /** |
| 1092 | * Japanese imap folder name encoding function |
| 1093 | * |
| 1094 | * converts folder name from euc-jp to utf7-imap |
| 1095 | * @param string $ret folder name |
| 1096 | * @return string converted folder name |
| 1097 | * @since 1.5.1 |
| 1098 | */ |
| 1099 | function japanese_xtra_utf7_imap_encode($ret){ |
| 1100 | if (function_exists('mb_detect_encoding')) { |
| 1101 | $ret = mb_convert_encoding($ret, 'UTF7-IMAP', 'EUC-JP'); |
| 1102 | } |
| 1103 | return $ret; |
| 1104 | } |
| 1105 | |
| 1106 | /** |
| 1107 | * Japanese imap folder name decoding function |
| 1108 | * |
| 1109 | * converts folder name from utf7-imap to euc-jp. |
| 1110 | * @param string $ret folder name in utf7-imap |
| 1111 | * @return string converted folder name |
| 1112 | * @since 1.5.1 |
| 1113 | */ |
| 1114 | function japanese_xtra_utf7_imap_decode($ret) { |
| 1115 | if (function_exists('mb_detect_encoding')) { |
| 1116 | $ret = mb_convert_encoding($ret, 'EUC-JP', 'UTF7-IMAP'); |
| 1117 | } |
| 1118 | return $ret; |
| 1119 | } |
| 1120 | |
| 1121 | /** |
| 1122 | * Japanese string trimming function |
| 1123 | * |
| 1124 | * trims string to defined number of symbols |
| 1125 | * @param string $ret string |
| 1126 | * @param integer $width number of symbols |
| 1127 | * @return string trimmed string |
| 1128 | * @since 1.5.1 |
| 1129 | */ |
| 1130 | function japanese_xtra_strimwidth($ret,$width) { |
| 1131 | if (function_exists('mb_detect_encoding')) { |
| 1132 | $ret = mb_strimwidth($ret, 0, $width, '...'); |
| 1133 | } |
| 1134 | return $ret; |
| 1135 | } |
| 1136 | |
| 1137 | /******************************** |
| 1138 | * Korean charset extra functions |
| 1139 | ********************************/ |
| 1140 | |
| 1141 | /** |
| 1142 | * Korean downloaded filename processing functions |
| 1143 | * |
| 1144 | * @param string default return value |
| 1145 | * @return string |
| 1146 | */ |
| 1147 | function korean_xtra_downloadfilename($ret) { |
| 1148 | $ret = str_replace("\x0D\x0A", '', $ret); /* Hanmail's CR/LF Clear */ |
| 1149 | for ($i=0;$i<strlen($ret);$i++) { |
| 1150 | if ($ret[$i] >= "\xA1" && $ret[$i] <= "\xFE") { /* 0xA1 - 0XFE are Valid */ |
| 1151 | $i++; |
| 1152 | continue; |
| 1153 | } else if (($ret[$i] >= 'a' && $ret[$i] <= 'z') || /* From Original ereg_replace in download.php */ |
| 1154 | ($ret[$i] >= 'A' && $ret[$i] <= 'Z') || |
| 1155 | ($ret[$i] == '.') || ($ret[$i] == '-')) { |
| 1156 | continue; |
| 1157 | } else { |
| 1158 | $ret[$i] = '_'; |
| 1159 | } |
| 1160 | } |
| 1161 | return $ret; |
| 1162 | } |
| 1163 | |
| 1164 | /** |
| 1165 | * Replaces non-braking spaces inserted by some browsers with regular space |
| 1166 | * |
| 1167 | * This function can be used to replace non-braking space symbols |
| 1168 | * that are inserted in forms by some browsers instead of normal |
| 1169 | * space symbol. |
| 1170 | * |
| 1171 | * @param string $string Text that needs to be cleaned |
| 1172 | * @param string $charset Charset used in text |
| 1173 | * @return string Cleaned text |
| 1174 | */ |
| 1175 | function cleanup_nbsp($string,$charset) { |
| 1176 | |
| 1177 | // reduce number of case statements |
| 1178 | if (stristr('iso-8859-',substr($charset,0,9))){ |
| 1179 | $output_charset="iso-8859-x"; |
| 1180 | } |
| 1181 | if (stristr('windows-125',substr($charset,0,11))){ |
| 1182 | $output_charset="cp125x"; |
| 1183 | } |
| 1184 | if (stristr('koi8',substr($charset,0,4))){ |
| 1185 | $output_charset="koi8-x"; |
| 1186 | } |
| 1187 | if (! isset($output_charset)){ |
| 1188 | $output_charset=strtolower($charset); |
| 1189 | } |
| 1190 | |
| 1191 | // where is non-braking space symbol |
| 1192 | switch($output_charset): |
| 1193 | case "iso-8859-x": |
| 1194 | case "cp125x": |
| 1195 | case "iso-2022-jp": |
| 1196 | $nbsp="\xA0"; |
| 1197 | break; |
| 1198 | case "koi8-x": |
| 1199 | $nbsp="\x9A"; |
| 1200 | break; |
| 1201 | case "utf-8": |
| 1202 | $nbsp="\xC2\xA0"; |
| 1203 | break; |
| 1204 | default: |
| 1205 | // don't change string if charset is unmatched |
| 1206 | return $string; |
| 1207 | endswitch; |
| 1208 | |
| 1209 | // return space instead of non-braking space. |
| 1210 | return str_replace($nbsp,' ',$string); |
| 1211 | } |
| 1212 | |
| 1213 | /** |
| 1214 | * Function informs if it is safe to convert given charset to the one that is used by user. |
| 1215 | * |
| 1216 | * It is safe to use conversion only if user uses utf-8 encoding and when |
| 1217 | * converted charset is similar to the one that is used by user. |
| 1218 | * |
| 1219 | * @param string $input_charset Charset of text that needs to be converted |
| 1220 | * @return bool is it possible to convert to user's charset |
| 1221 | */ |
| 1222 | function is_conversion_safe($input_charset) { |
| 1223 | global $languages, $sm_notAlias, $default_charset, $lossy_encoding; |
| 1224 | |
| 1225 | if (isset($lossy_encoding) && $lossy_encoding ) |
| 1226 | return true; |
| 1227 | |
| 1228 | // convert to lower case |
| 1229 | $input_charset = strtolower($input_charset); |
| 1230 | |
| 1231 | // Is user's locale Unicode based ? |
| 1232 | if ( $default_charset == "utf-8" ) { |
| 1233 | return true; |
| 1234 | } |
| 1235 | |
| 1236 | // Charsets that are similar |
| 1237 | switch ($default_charset): |
| 1238 | case "windows-1251": |
| 1239 | if ( $input_charset == "iso-8859-5" || |
| 1240 | $input_charset == "koi8-r" || |
| 1241 | $input_charset == "koi8-u" ) { |
| 1242 | return true; |
| 1243 | } else { |
| 1244 | return false; |
| 1245 | } |
| 1246 | case "windows-1257": |
| 1247 | if ( $input_charset == "iso-8859-13" || |
| 1248 | $input_charset == "iso-8859-4" ) { |
| 1249 | return true; |
| 1250 | } else { |
| 1251 | return false; |
| 1252 | } |
| 1253 | case "iso-8859-4": |
| 1254 | if ( $input_charset == "iso-8859-13" || |
| 1255 | $input_charset == "windows-1257" ) { |
| 1256 | return true; |
| 1257 | } else { |
| 1258 | return false; |
| 1259 | } |
| 1260 | case "iso-8859-5": |
| 1261 | if ( $input_charset == "windows-1251" || |
| 1262 | $input_charset == "koi8-r" || |
| 1263 | $input_charset == "koi8-u" ) { |
| 1264 | return true; |
| 1265 | } else { |
| 1266 | return false; |
| 1267 | } |
| 1268 | case "iso-8859-13": |
| 1269 | if ( $input_charset == "iso-8859-4" || |
| 1270 | $input_charset == "windows-1257" ) { |
| 1271 | return true; |
| 1272 | } else { |
| 1273 | return false; |
| 1274 | } |
| 1275 | case "koi8-r": |
| 1276 | if ( $input_charset == "windows-1251" || |
| 1277 | $input_charset == "iso-8859-5" || |
| 1278 | $input_charset == "koi8-u" ) { |
| 1279 | return true; |
| 1280 | } else { |
| 1281 | return false; |
| 1282 | } |
| 1283 | case "koi8-u": |
| 1284 | if ( $input_charset == "windows-1251" || |
| 1285 | $input_charset == "iso-8859-5" || |
| 1286 | $input_charset == "koi8-r" ) { |
| 1287 | return true; |
| 1288 | } else { |
| 1289 | return false; |
| 1290 | } |
| 1291 | default: |
| 1292 | return false; |
| 1293 | endswitch; |
| 1294 | } |
| 1295 | ?> |