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