i18n.php 41 KB

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