Fixed dates in copyright. added koi8-r and koi8-u decoding. fixed ereg in
[squirrelmail.git] / functions / i18n.php
CommitLineData
59177427 1<?php
1fd97780 2
35586184 3/**
4 * i18n.php
5 *
76911253 6 * Copyright (c) 1999-2003 The SquirrelMail Project Team
35586184 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 * $Id$
16 */
17
961ca3d8 18require_once(SM_PATH . 'functions/global.php');
19
a2a7852b 20/* Decodes a string to the internal encoding from the given charset */
21function charset_decode ($charset, $string) {
6fbd125b 22 global $languages, $squirrelmail_language;
a2a7852b 23
3714db45 24 if (isset($languages[$squirrelmail_language]['XTRA_CODE']) &&
25 function_exists($languages[$squirrelmail_language]['XTRA_CODE'])) {
6fbd125b 26 $string = $languages[$squirrelmail_language]['XTRA_CODE']('decode', $string);
27 }
b05c8961 28
a2a7852b 29 /* All HTML special characters are 7 bit and can be replaced first */
cef054e4 30
098ea084 31 $string = htmlspecialchars ($string);
a2a7852b 32
33 $charset = strtolower($charset);
34
94965562 35 set_my_charset() ;
36
a2a7852b 37 if (ereg('iso-8859-([[:digit:]]+)', $charset, $res)) {
38 if ($res[1] == '1') {
39 $ret = charset_decode_iso_8859_1 ($string);
40 } else if ($res[1] == '2') {
41 $ret = charset_decode_iso_8859_2 ($string);
3a66bed2 42 } else if ($res[1] == '3') {
43 include_once(SM_PATH . 'functions/decode/iso8859-3.php');
44 $ret = charset_decode_iso8859_3 ($string);
9be313d5 45 } else if ($res[1] == '4') {
3a66bed2 46 include_once(SM_PATH . 'functions/decode/iso8859-4.php');
47 $ret = charset_decode_iso8859_4 ($string);
94965562 48 } else if ($res[1] == '5') {
3a66bed2 49 include_once(SM_PATH . 'functions/decode/iso8859-5.php');
50 $ret = charset_decode_iso8859_5 ($string);
ef82d2d5 51 } else if ($res[1] == '6') {
52 $ret = charset_decode_iso_8859_6 ($string);
a2a7852b 53 } else if ($res[1] == '7') {
54 $ret = charset_decode_iso_8859_7 ($string);
3a66bed2 55 } else if ($res[1] == '8') {
56 include_once(SM_PATH . 'functions/decode/iso8859-8.php');
57 $ret = charset_decode_iso8859_8 ($string);
3ab35042 58 } else if ($res[1] == '9') {
59 $ret = charset_decode_iso_8859_9 ($string);
3a66bed2 60 } else if ($res[1] == '10') {
61 include_once(SM_PATH . 'functions/decode/iso8859-10.php');
62 $ret = charset_decode_iso8859_10 ($string);
63 } else if ($res[1] == '11') {
64 include_once(SM_PATH . 'functions/decode/iso8859-11.php');
65 $ret = charset_decode_iso8859_11 ($string);
9be313d5 66 } else if ($res[1] == '13') {
3a66bed2 67 include_once(SM_PATH . 'functions/decode/iso8859-13.php');
68 $ret = charset_decode_iso8859_13 ($string);
69 } else if ($res[1] == '14') {
70 include_once(SM_PATH . 'functions/decode/iso8859-14.php');
71 $ret = charset_decode_iso8859_14 ($string);
a2a7852b 72 } else if ($res[1] == '15') {
73 $ret = charset_decode_iso_8859_15 ($string);
3a66bed2 74 } else if ($res[1] == '16') {
75 include_once(SM_PATH . 'functions/decode/iso8859-16.php');
76 $ret = charset_decode_iso8859_16 ($string);
a2a7852b 77 } else {
78 $ret = charset_decode_iso_8859_default ($string);
79 }
80 } else if ($charset == 'ns_4551-1') {
81 $ret = charset_decode_ns_4551_1 ($string);
82 } else if ($charset == 'koi8-r') {
83 $ret = charset_decode_koi8r ($string);
1c0e847f 84 } else if ($charset == 'koi8-u') {
85 $ret = charset_decode_koi8u ($string);
a2a7852b 86 } else if ($charset == 'windows-1251') {
ecd877a8 87 $ret = charset_decode_windows_1251 ($string);
3ab35042 88 } else if ($charset == 'windows-1253') {
89 $ret = charset_decode_windows_1253 ($string);
90 } else if ($charset == 'windows-1254') {
91 $ret = charset_decode_windows_1254 ($string);
c48a8ca7 92 } else if ($charset == 'windows-1255') {
93 $ret = charset_decode_windows_1255 ($string);
94 } else if ($charset == 'windows-1256') {
95 $ret = charset_decode_windows_1256 ($string);
c37a12f8 96 } else if ($charset == 'windows-1257') {
3a66bed2 97 include_once(SM_PATH . 'functions/decode/cp1257.php');
98 $ret = charset_decode_cp1257 ($string);
3ab35042 99 } else if ($charset == 'utf-8') {
100 $ret = charset_decode_utf8 ($string);
a2a7852b 101 } else {
102 $ret = $string;
103 }
104 return( $ret );
105}
106
107/*
108 iso-8859-1 is the same as Latin 1 and is normally used
109 in western europe.
110 */
111function charset_decode_iso_8859_1 ($string) {
112 global $default_charset;
13e0c649 113
a2a7852b 114 if (strtolower($default_charset) <> 'iso-8859-1') {
115 /* Only do the slow convert if there are 8-bit characters */
116 if (ereg("[\200-\377]", $string)) {
066c374f 117 $string = str_replace("\201", '&#129;', $string);
118 $string = str_replace("\202", '&#130;', $string);
119 $string = str_replace("\203", '&#131;', $string);
120 $string = str_replace("\204", '&#132;', $string);
121 $string = str_replace("\205", '&#133;', $string);
122 $string = str_replace("\206", '&#134;', $string);
123 $string = str_replace("\207", '&#135;', $string);
124 $string = str_replace("\210", '&#136;', $string);
125 $string = str_replace("\211", '&#137;', $string);
126 $string = str_replace("\212", '&#138;', $string);
127 $string = str_replace("\213", '&#139;', $string);
128 $string = str_replace("\214", '&#140;', $string);
129 $string = str_replace("\215", '&#141;', $string);
130 $string = str_replace("\216", '&#142;', $string);
131 $string = str_replace("\217", '&#143;', $string);
132 $string = str_replace("\220", '&#144;', $string);
133 $string = str_replace("\221", '&#145;', $string);
134 $string = str_replace("\222", '&#146;', $string);
135 $string = str_replace("\223", '&#147;', $string);
136 $string = str_replace("\224", '&#148;', $string);
137 $string = str_replace("\225", '&#149;', $string);
138 $string = str_replace("\226", '&#150;', $string);
139 $string = str_replace("\227", '&#151;', $string);
140 $string = str_replace("\230", '&#152;', $string);
141 $string = str_replace("\231", '&#153;', $string);
142 $string = str_replace("\232", '&#154;', $string);
143 $string = str_replace("\233", '&#155;', $string);
144 $string = str_replace("\234", '&#156;', $string);
145 $string = str_replace("\235", '&#157;', $string);
146 $string = str_replace("\236", '&#158;', $string);
147 $string = str_replace("\237", '&#159;', $string);
148 $string = str_replace("\240", '&#160;', $string);
149 $string = str_replace("\241", '&#161;', $string);
150 $string = str_replace("\242", '&#162;', $string);
151 $string = str_replace("\243", '&#163;', $string);
152 $string = str_replace("\244", '&#164;', $string);
153 $string = str_replace("\245", '&#165;', $string);
154 $string = str_replace("\246", '&#166;', $string);
155 $string = str_replace("\247", '&#167;', $string);
156 $string = str_replace("\250", '&#168;', $string);
157 $string = str_replace("\251", '&#169;', $string);
158 $string = str_replace("\252", '&#170;', $string);
159 $string = str_replace("\253", '&#171;', $string);
160 $string = str_replace("\254", '&#172;', $string);
161 $string = str_replace("\255", '&#173;', $string);
162 $string = str_replace("\256", '&#174;', $string);
163 $string = str_replace("\257", '&#175;', $string);
164 $string = str_replace("\260", '&#176;', $string);
165 $string = str_replace("\261", '&#177;', $string);
166 $string = str_replace("\262", '&#178;', $string);
167 $string = str_replace("\263", '&#179;', $string);
168 $string = str_replace("\264", '&#180;', $string);
169 $string = str_replace("\265", '&#181;', $string);
170 $string = str_replace("\266", '&#182;', $string);
171 $string = str_replace("\267", '&#183;', $string);
172 $string = str_replace("\270", '&#184;', $string);
173 $string = str_replace("\271", '&#185;', $string);
174 $string = str_replace("\272", '&#186;', $string);
175 $string = str_replace("\273", '&#187;', $string);
176 $string = str_replace("\274", '&#188;', $string);
177 $string = str_replace("\275", '&#189;', $string);
178 $string = str_replace("\276", '&#190;', $string);
179 $string = str_replace("\277", '&#191;', $string);
180 $string = str_replace("\300", '&#192;', $string);
181 $string = str_replace("\301", '&#193;', $string);
182 $string = str_replace("\302", '&#194;', $string);
183 $string = str_replace("\303", '&#195;', $string);
184 $string = str_replace("\304", '&#196;', $string);
185 $string = str_replace("\305", '&#197;', $string);
186 $string = str_replace("\306", '&#198;', $string);
187 $string = str_replace("\307", '&#199;', $string);
188 $string = str_replace("\310", '&#200;', $string);
189 $string = str_replace("\311", '&#201;', $string);
190 $string = str_replace("\312", '&#202;', $string);
191 $string = str_replace("\313", '&#203;', $string);
192 $string = str_replace("\314", '&#204;', $string);
193 $string = str_replace("\315", '&#205;', $string);
194 $string = str_replace("\316", '&#206;', $string);
195 $string = str_replace("\317", '&#207;', $string);
196 $string = str_replace("\320", '&#208;', $string);
197 $string = str_replace("\321", '&#209;', $string);
198 $string = str_replace("\322", '&#210;', $string);
199 $string = str_replace("\323", '&#211;', $string);
200 $string = str_replace("\324", '&#212;', $string);
201 $string = str_replace("\325", '&#213;', $string);
202 $string = str_replace("\326", '&#214;', $string);
203 $string = str_replace("\327", '&#215;', $string);
204 $string = str_replace("\330", '&#216;', $string);
205 $string = str_replace("\331", '&#217;', $string);
206 $string = str_replace("\332", '&#218;', $string);
207 $string = str_replace("\333", '&#219;', $string);
208 $string = str_replace("\334", '&#220;', $string);
209 $string = str_replace("\335", '&#221;', $string);
210 $string = str_replace("\336", '&#222;', $string);
211 $string = str_replace("\337", '&#223;', $string);
212 $string = str_replace("\340", '&#224;', $string);
213 $string = str_replace("\341", '&#225;', $string);
214 $string = str_replace("\342", '&#226;', $string);
215 $string = str_replace("\343", '&#227;', $string);
216 $string = str_replace("\344", '&#228;', $string);
217 $string = str_replace("\345", '&#229;', $string);
218 $string = str_replace("\346", '&#230;', $string);
219 $string = str_replace("\347", '&#231;', $string);
220 $string = str_replace("\350", '&#232;', $string);
221 $string = str_replace("\351", '&#233;', $string);
222 $string = str_replace("\352", '&#234;', $string);
223 $string = str_replace("\353", '&#235;', $string);
224 $string = str_replace("\354", '&#236;', $string);
225 $string = str_replace("\355", '&#237;', $string);
226 $string = str_replace("\356", '&#238;', $string);
227 $string = str_replace("\357", '&#239;', $string);
228 $string = str_replace("\360", '&#240;', $string);
229 $string = str_replace("\361", '&#241;', $string);
230 $string = str_replace("\362", '&#242;', $string);
231 $string = str_replace("\363", '&#243;', $string);
232 $string = str_replace("\364", '&#244;', $string);
233 $string = str_replace("\365", '&#245;', $string);
234 $string = str_replace("\366", '&#246;', $string);
235 $string = str_replace("\367", '&#247;', $string);
236 $string = str_replace("\370", '&#248;', $string);
237 $string = str_replace("\371", '&#249;', $string);
238 $string = str_replace("\372", '&#250;', $string);
239 $string = str_replace("\373", '&#251;', $string);
240 $string = str_replace("\374", '&#252;', $string);
241 $string = str_replace("\375", '&#253;', $string);
242 $string = str_replace("\376", '&#254;', $string);
243 $string = str_replace("\377", '&#255;', $string);
a2a7852b 244 }
245 }
246
247 return ($string);
248}
249
250/* iso-8859-2 is used for some eastern European languages */
251function charset_decode_iso_8859_2 ($string) {
252 global $default_charset;
253
254 if (strtolower($default_charset) == 'iso-8859-2')
255 return $string;
256
257 /* Only do the slow convert if there are 8-bit characters */
258 if (! ereg("[\200-\377]", $string))
259 return $string;
260
261 /* NO-BREAK SPACE */
262 $string = str_replace("\240", '&#160;', $string);
263 /* LATIN CAPITAL LETTER A WITH OGONEK */
264 $string = str_replace("\241", '&#260;', $string);
265 /* BREVE */
266 $string = str_replace("\242", '&#728;', $string);
267 // LATIN CAPITAL LETTER L WITH STROKE
268 $string = str_replace("\243", '&#321;', $string);
269 // CURRENCY SIGN
270 $string = str_replace("\244", '&#164;', $string);
271 // LATIN CAPITAL LETTER L WITH CARON
272 $string = str_replace("\245", '&#317;', $string);
273 // LATIN CAPITAL LETTER S WITH ACUTE
274 $string = str_replace("\246", '&#346;', $string);
275 // SECTION SIGN
276 $string = str_replace("\247", '&#167;', $string);
277 // DIAERESIS
278 $string = str_replace("\250", '&#168;', $string);
279 // LATIN CAPITAL LETTER S WITH CARON
280 $string = str_replace("\251", '&#352;', $string);
281 // LATIN CAPITAL LETTER S WITH CEDILLA
282 $string = str_replace("\252", '&#350;', $string);
283 // LATIN CAPITAL LETTER T WITH CARON
284 $string = str_replace("\253", '&#356;', $string);
285 // LATIN CAPITAL LETTER Z WITH ACUTE
286 $string = str_replace("\254", '&#377;', $string);
287 // SOFT HYPHEN
288 $string = str_replace("\255", '&#173;', $string);
289 // LATIN CAPITAL LETTER Z WITH CARON
290 $string = str_replace("\256", '&#381;', $string);
291 // LATIN CAPITAL LETTER Z WITH DOT ABOVE
292 $string = str_replace("\257", '&#379;', $string);
293 // DEGREE SIGN
294 $string = str_replace("\260", '&#176;', $string);
295 // LATIN SMALL LETTER A WITH OGONEK
296 $string = str_replace("\261", '&#261;', $string);
297 // OGONEK
298 $string = str_replace("\262", '&#731;', $string);
299 // LATIN SMALL LETTER L WITH STROKE
300 $string = str_replace("\263", '&#322;', $string);
301 // ACUTE ACCENT
302 $string = str_replace("\264", '&#180;', $string);
303 // LATIN SMALL LETTER L WITH CARON
304 $string = str_replace("\265", '&#318;', $string);
305 // LATIN SMALL LETTER S WITH ACUTE
306 $string = str_replace("\266", '&#347;', $string);
307 // CARON
308 $string = str_replace("\267", '&#711;', $string);
309 // CEDILLA
310 $string = str_replace("\270", '&#184;', $string);
311 // LATIN SMALL LETTER S WITH CARON
312 $string = str_replace("\271", '&#353;', $string);
313 // LATIN SMALL LETTER S WITH CEDILLA
314 $string = str_replace("\272", '&#351;', $string);
315 // LATIN SMALL LETTER T WITH CARON
316 $string = str_replace("\273", '&#357;', $string);
317 // LATIN SMALL LETTER Z WITH ACUTE
318 $string = str_replace("\274", '&#378;', $string);
319 // DOUBLE ACUTE ACCENT
320 $string = str_replace("\275", '&#733;', $string);
321 // LATIN SMALL LETTER Z WITH CARON
322 $string = str_replace("\276", '&#382;', $string);
323 // LATIN SMALL LETTER Z WITH DOT ABOVE
324 $string = str_replace("\277", '&#380;', $string);
325 // LATIN CAPITAL LETTER R WITH ACUTE
326 $string = str_replace("\300", '&#340;', $string);
327 // LATIN CAPITAL LETTER A WITH ACUTE
328 $string = str_replace("\301", '&#193;', $string);
329 // LATIN CAPITAL LETTER A WITH CIRCUMFLEX
330 $string = str_replace("\302", '&#194;', $string);
331 // LATIN CAPITAL LETTER A WITH BREVE
332 $string = str_replace("\303", '&#258;', $string);
333 // LATIN CAPITAL LETTER A WITH DIAERESIS
334 $string = str_replace("\304", '&#196;', $string);
335 // LATIN CAPITAL LETTER L WITH ACUTE
336 $string = str_replace("\305", '&#313;', $string);
337 // LATIN CAPITAL LETTER C WITH ACUTE
338 $string = str_replace("\306", '&#262;', $string);
339 // LATIN CAPITAL LETTER C WITH CEDILLA
340 $string = str_replace("\307", '&#199;', $string);
341 // LATIN CAPITAL LETTER C WITH CARON
342 $string = str_replace("\310", '&#268;', $string);
343 // LATIN CAPITAL LETTER E WITH ACUTE
344 $string = str_replace("\311", '&#201;', $string);
345 // LATIN CAPITAL LETTER E WITH OGONEK
346 $string = str_replace("\312", '&#280;', $string);
347 // LATIN CAPITAL LETTER E WITH DIAERESIS
348 $string = str_replace("\313", '&#203;', $string);
349 // LATIN CAPITAL LETTER E WITH CARON
350 $string = str_replace("\314", '&#282;', $string);
351 // LATIN CAPITAL LETTER I WITH ACUTE
352 $string = str_replace("\315", '&#205;', $string);
353 // LATIN CAPITAL LETTER I WITH CIRCUMFLEX
354 $string = str_replace("\316", '&#206;', $string);
355 // LATIN CAPITAL LETTER D WITH CARON
356 $string = str_replace("\317", '&#270;', $string);
357 // LATIN CAPITAL LETTER D WITH STROKE
358 $string = str_replace("\320", '&#272;', $string);
359 // LATIN CAPITAL LETTER N WITH ACUTE
360 $string = str_replace("\321", '&#323;', $string);
361 // LATIN CAPITAL LETTER N WITH CARON
362 $string = str_replace("\322", '&#327;', $string);
363 // LATIN CAPITAL LETTER O WITH ACUTE
364 $string = str_replace("\323", '&#211;', $string);
365 // LATIN CAPITAL LETTER O WITH CIRCUMFLEX
366 $string = str_replace("\324", '&#212;', $string);
367 // LATIN CAPITAL LETTER O WITH DOUBLE ACUTE
368 $string = str_replace("\325", '&#336;', $string);
369 // LATIN CAPITAL LETTER O WITH DIAERESIS
370 $string = str_replace("\326", '&#214;', $string);
371 // MULTIPLICATION SIGN
372 $string = str_replace("\327", '&#215;', $string);
373 // LATIN CAPITAL LETTER R WITH CARON
374 $string = str_replace("\330", '&#344;', $string);
375 // LATIN CAPITAL LETTER U WITH RING ABOVE
376 $string = str_replace("\331", '&#366;', $string);
377 // LATIN CAPITAL LETTER U WITH ACUTE
378 $string = str_replace("\332", '&#218;', $string);
379 // LATIN CAPITAL LETTER U WITH DOUBLE ACUTE
380 $string = str_replace("\333", '&#368;', $string);
381 // LATIN CAPITAL LETTER U WITH DIAERESIS
382 $string = str_replace("\334", '&#220;', $string);
383 // LATIN CAPITAL LETTER Y WITH ACUTE
384 $string = str_replace("\335", '&#221;', $string);
385 // LATIN CAPITAL LETTER T WITH CEDILLA
386 $string = str_replace("\336", '&#354;', $string);
387 // LATIN SMALL LETTER SHARP S
388 $string = str_replace("\337", '&#223;', $string);
389 // LATIN SMALL LETTER R WITH ACUTE
390 $string = str_replace("\340", '&#341;', $string);
391 // LATIN SMALL LETTER A WITH ACUTE
392 $string = str_replace("\341", '&#225;', $string);
393 // LATIN SMALL LETTER A WITH CIRCUMFLEX
394 $string = str_replace("\342", '&#226;', $string);
395 // LATIN SMALL LETTER A WITH BREVE
396 $string = str_replace("\343", '&#259;', $string);
397 // LATIN SMALL LETTER A WITH DIAERESIS
398 $string = str_replace("\344", '&#228;', $string);
399 // LATIN SMALL LETTER L WITH ACUTE
400 $string = str_replace("\345", '&#314;', $string);
401 // LATIN SMALL LETTER C WITH ACUTE
402 $string = str_replace("\346", '&#263;', $string);
403 // LATIN SMALL LETTER C WITH CEDILLA
404 $string = str_replace("\347", '&#231;', $string);
405 // LATIN SMALL LETTER C WITH CARON
406 $string = str_replace("\350", '&#269;', $string);
407 // LATIN SMALL LETTER E WITH ACUTE
408 $string = str_replace("\351", '&#233;', $string);
409 // LATIN SMALL LETTER E WITH OGONEK
410 $string = str_replace("\352", '&#281;', $string);
411 // LATIN SMALL LETTER E WITH DIAERESIS
412 $string = str_replace("\353", '&#235;', $string);
413 // LATIN SMALL LETTER E WITH CARON
414 $string = str_replace("\354", '&#283;', $string);
415 // LATIN SMALL LETTER I WITH ACUTE
416 $string = str_replace("\355", '&#237;', $string);
417 // LATIN SMALL LETTER I WITH CIRCUMFLEX
418 $string = str_replace("\356", '&#238;', $string);
419 // LATIN SMALL LETTER D WITH CARON
420 $string = str_replace("\357", '&#271;', $string);
421 // LATIN SMALL LETTER D WITH STROKE
422 $string = str_replace("\360", '&#273;', $string);
423 // LATIN SMALL LETTER N WITH ACUTE
424 $string = str_replace("\361", '&#324;', $string);
425 // LATIN SMALL LETTER N WITH CARON
426 $string = str_replace("\362", '&#328;', $string);
427 // LATIN SMALL LETTER O WITH ACUTE
428 $string = str_replace("\363", '&#243;', $string);
429 // LATIN SMALL LETTER O WITH CIRCUMFLEX
430 $string = str_replace("\364", '&#244;', $string);
431 // LATIN SMALL LETTER O WITH DOUBLE ACUTE
432 $string = str_replace("\365", '&#337;', $string);
433 // LATIN SMALL LETTER O WITH DIAERESIS
434 $string = str_replace("\366", '&#246;', $string);
435 // DIVISION SIGN
436 $string = str_replace("\367", '&#247;', $string);
437 // LATIN SMALL LETTER R WITH CARON
438 $string = str_replace("\370", '&#345;', $string);
439 // LATIN SMALL LETTER U WITH RING ABOVE
440 $string = str_replace("\371", '&#367;', $string);
441 // LATIN SMALL LETTER U WITH ACUTE
442 $string = str_replace("\372", '&#250;', $string);
443 // LATIN SMALL LETTER U WITH DOUBLE ACUTE
444 $string = str_replace("\373", '&#369;', $string);
445 // LATIN SMALL LETTER U WITH DIAERESIS
446 $string = str_replace("\374", '&#252;', $string);
447 // LATIN SMALL LETTER Y WITH ACUTE
448 $string = str_replace("\375", '&#253;', $string);
449 // LATIN SMALL LETTER T WITH CEDILLA
450 $string = str_replace("\376", '&#355;', $string);
451 // DOT ABOVE
452 $string = str_replace("\377", '&#729;', $string);
453
454 return $string;
455}
456
9be313d5 457/*
c37a12f8 458 ISO/IEC 8859-4:1998 Latin Alphabet No. 4
9be313d5 459*/
460
461function charset_decode_iso_8859_4 ($string) {
94965562 462 global $default_charset;
9be313d5 463
c37a12f8 464 if (strtolower($default_charset) == 'iso-8859-4')
465 return $string;
c37a12f8 466
467 /* Only do the slow convert if there are 8-bit characters */
468 if (! ereg("[\200-\377]", $string))
469 return $string;
470
c37a12f8 471 $string = str_replace ("\241", '&#260;', $string);
c37a12f8 472 $string = str_replace ("\242", '&#312;', $string);
c37a12f8 473 $string = str_replace ("\243", '&#342;', $string);
c37a12f8 474 $string = str_replace ("\245", '&#296;', $string);
c37a12f8 475 $string = str_replace ("\246", '&#315;', $string);
c37a12f8 476 $string = str_replace ("\251", '&#352;', $string);
c37a12f8 477 $string = str_replace ("\252", '&#274;', $string);
c37a12f8 478 $string = str_replace ("\253", '&#290;', $string);
c37a12f8 479 $string = str_replace ("\254", '&#358;', $string);
c37a12f8 480 $string = str_replace ("\256", '&#381;', $string);
c37a12f8 481 $string = str_replace ("\261", '&#261;', $string);
c37a12f8 482 $string = str_replace ("\262", '&#731;', $string);
c37a12f8 483 $string = str_replace ("\263", '&#343;', $string);
c37a12f8 484 $string = str_replace ("\265", '&#297;', $string);
c37a12f8 485 $string = str_replace ("\266", '&#316;', $string);
c37a12f8 486 $string = str_replace ("\267", '&#711;', $string);
c37a12f8 487 $string = str_replace ("\271", '&#353;', $string);
c37a12f8 488 $string = str_replace ("\272", '&#275;', $string);
c37a12f8 489 $string = str_replace ("\273", '&#291;', $string);
c37a12f8 490 $string = str_replace ("\274", '&#359;', $string);
c37a12f8 491 $string = str_replace ("\275", '&#330;', $string);
c37a12f8 492 $string = str_replace ("\276", '&#382;', $string);
c37a12f8 493 $string = str_replace ("\277", '&#331;', $string);
c37a12f8 494 $string = str_replace ("\300", '&#256;', $string);
c37a12f8 495 $string = str_replace ("\307", '&#302;', $string);
c37a12f8 496 $string = str_replace ("\310", '&#268;', $string);
c37a12f8 497 $string = str_replace ("\312", '&#280;', $string);
c37a12f8 498 $string = str_replace ("\314", '&#278;', $string);
c37a12f8 499 $string = str_replace ("\317", '&#298;', $string);
c37a12f8 500 $string = str_replace ("\320", '&#272;', $string);
c37a12f8 501 $string = str_replace ("\321", '&#325;', $string);
c37a12f8 502 $string = str_replace ("\322", '&#332;', $string);
c37a12f8 503 $string = str_replace ("\323", '&#310;', $string);
c37a12f8 504 $string = str_replace ("\331", '&#370;', $string);
c37a12f8 505 $string = str_replace ("\335", '&#360;', $string);
c37a12f8 506 $string = str_replace ("\336", '&#362;', $string);
c37a12f8 507 $string = str_replace ("\340", '&#257;', $string);
c37a12f8 508 $string = str_replace ("\347", '&#303;', $string);
c37a12f8 509 $string = str_replace ("\350", '&#269;', $string);
c37a12f8 510 $string = str_replace ("\352", '&#281;', $string);
c37a12f8 511 $string = str_replace ("\354", '&#279;', $string);
c37a12f8 512 $string = str_replace ("\357", '&#299;', $string);
c37a12f8 513 $string = str_replace ("\360", '&#273;', $string);
c37a12f8 514 $string = str_replace ("\361", '&#326;', $string);
c37a12f8 515 $string = str_replace ("\362", '&#333;', $string);
c37a12f8 516 $string = str_replace ("\363", '&#311;', $string);
c37a12f8 517 $string = str_replace ("\371", '&#371;', $string);
c37a12f8 518 $string = str_replace ("\375", '&#361;', $string);
c37a12f8 519 $string = str_replace ("\376", '&#363;', $string);
c37a12f8 520 $string = str_replace ("\377", '&#729;', $string);
521
522 // rest of charset is the same as ISO-8859-1
9be313d5 523 return (charset_decode_iso_8859_1($string));
524}
525
1c0e847f 526/* ISO-8859-5 is Cyrillic */
527function charset_decode_iso_8859_5 ($string) {
528 global $default_charset;
529
530 if (strtolower($default_charset) == 'iso-8859-5') {
531 return $string;
532 }
533
534 /* Only do the slow convert if there are 8-bit characters */
535 if (! ereg("[\200-\377]", $string))
536 return $string;
537
538 // NO-BREAK SPACE
539 $string = str_replace("\240", '&#160;', $string);
540 // 161-172 -> 1025-1036 (+864)
541 $string = preg_replace("/([\241-\254])/e","'&#' . (ord('\\1')+864) . ';'",$string);
542 // SOFT HYPHEN
543 $string = str_replace("\255", '&#173;', $string);
544 // 174-239 -> 1038-1103 (+864)
545 $string = preg_replace("/([\256-\357])/e","'&#' . (ord('\\1')+864) . ';'",$string);
546 // NUMERO SIGN
547 $string = str_replace("\360", '&#8470;', $string);
548 // 241-252 -> 1105-1116 (+864)
549 $string = preg_replace("/([\361-\374])/e","'&#' . (ord('\\1')+864) . ';'",$string);
550 // SECTION SIGN
551 $string = str_replace("\375", '&#167;', $string);
552 // CYRILLIC SMALL LETTER SHORT U (Byelorussian)
553 $string = str_replace("\376", '&#1118;', $string);
554 // CYRILLIC SMALL LETTER DZHE
555 $string = str_replace("\377", '&#1119;', $string);
556
557 return $string;
558}
559
ef82d2d5 560/*
561 ISO/IEC 8859-6:1999 Latin/Arabic Alphabet
562*/
563function charset_decode_iso_8859_6 ($string) {
564 global $default_charset;
565
566 if (strtolower($default_charset) == 'iso-8859-6')
567 return $string;
568
569 /* Only do the slow convert if there are 8-bit characters */
570 if (! ereg("[\200-\377]", $string))
571 return $string;
572
573 $string = str_replace ("\240", '&#160;', $string);
574 $string = str_replace ("\244", '&#164;', $string);
575 $string = str_replace ("\254", '&#1548;', $string);
576 $string = str_replace ("\255", '&#173;', $string);
577 $string = str_replace ("\273", '&#1563;', $string);
578 $string = str_replace ("\277", '&#1567;', $string);
579 // 193-218 -> 1569-1594 (+1376)
580 $string = preg_replace("/([\301-\332])/e","'&#' . (ord('\\1')+1376).';'",$string);
581 // 224-242 -> 1600-1618 (+1376)
582 $string = preg_replace("/([\340-\362])/e","'&#' . (ord('\\1')+1376).';'",$string);
583
584 return ($string);
585}
586
a2a7852b 587/* iso-8859-7 is Greek. */
588function charset_decode_iso_8859_7 ($string) {
589 global $default_charset;
590
591 if (strtolower($default_charset) == 'iso-8859-7') {
592 return $string;
593 }
594
595 /* Only do the slow convert if there are 8-bit characters */
596 if (!ereg("[\200-\377]", $string)) {
597 return $string;
598 }
599
600 /* Some diverse characters in the beginning */
601 $string = str_replace("\240", '&#160;', $string);
602 $string = str_replace("\241", '&#8216;', $string);
603 $string = str_replace("\242", '&#8217;', $string);
604 $string = str_replace("\243", '&#163;', $string);
605 $string = str_replace("\246", '&#166;', $string);
606 $string = str_replace("\247", '&#167;', $string);
607 $string = str_replace("\250", '&#168;', $string);
608 $string = str_replace("\251", '&#169;', $string);
609 $string = str_replace("\253", '&#171;', $string);
610 $string = str_replace("\254", '&#172;', $string);
611 $string = str_replace("\255", '&#173;', $string);
612 $string = str_replace("\257", '&#8213;', $string);
613 $string = str_replace("\260", '&#176;', $string);
614 $string = str_replace("\261", '&#177;', $string);
615 $string = str_replace("\262", '&#178;', $string);
616 $string = str_replace("\263", '&#179;', $string);
617
618 /* Horizontal bar (parentheki pavla) */
619 $string = str_replace ("\257", '&#8213;', $string);
620
621 /*
622 * ISO-8859-7 characters from 11/04 (0xB4) to 11/06 (0xB6)
623 * These are Unicode 900-902
624 */
b85a4575 625 $string = preg_replace("/([\264-\266])/e","'&#' . (ord('\\1')+720);",$string);
49c17806 626
a2a7852b 627 /* 11/07 (0xB7) Middle dot is the same in iso-8859-1 */
628 $string = str_replace("\267", '&#183;', $string);
629
630 /*
631 * ISO-8859-7 characters from 11/08 (0xB8) to 11/10 (0xBA)
632 * These are Unicode 900-902
633 */
b85a4575 634 $string = preg_replace("/([\270-\272])/e","'&#' . (ord('\\1')+720);",$string);
a2a7852b 635
636 /*
637 * 11/11 (0xBB) Right angle quotation mark is the same as in
638 * iso-8859-1
639 */
640 $string = str_replace("\273", '&#187;', $string);
641
642 /* And now the rest of the charset */
b85a4575 643 $string = preg_replace("/([\274-\376])/e","'&#'.(ord('\\1')+720);",$string);
a2a7852b 644
645 return $string;
646}
647
648/*
cd21d1aa 649 ISOIEC 8859-9:1999 Latin Alphabet No. 5
961ca3d8 650
3ab35042 651*/
652function charset_decode_iso_8859_9 ($string) {
94965562 653 global $default_charset;
3ab35042 654
655 if (strtolower($default_charset) == 'iso-8859-9')
656 return $string;
3ab35042 657
658 /* Only do the slow convert if there are 8-bit characters */
659 if (! ereg("[\200-\377]", $string))
660 return $string;
661
662 // latin capital letter g with breve 208->286
663 $string = str_replace("\320", '&#286;', $string);
664 // latin capital letter i with dot above 221->304
665 $string = str_replace("\335", '&#304;', $string);
666 // latin capital letter s with cedilla 222->350
667 $string = str_replace("\336", '&#350;', $string);
668 // latin small letter g with breve 240->287
669 $string = str_replace("\360", '&#287;', $string);
670 // latin small letter dotless i 253->305
671 $string = str_replace("\375", '&#305;', $string);
672 // latin small letter s with cedilla 254->351
673 $string = str_replace("\376", '&#351;', $string);
674
675 // rest of charset is the same as ISO-8859-1
676 return (charset_decode_iso_8859_1($string));
677}
678
679
680/*
c37a12f8 681 ISO/IEC 8859-13:1998 Latin Alphabet No. 7 (Baltic Rim)
9be313d5 682*/
9be313d5 683function charset_decode_iso_8859_13 ($string) {
94965562 684 global $default_charset;
c37a12f8 685
686 if (strtolower($default_charset) == 'iso-8859-13')
687 return $string;
c37a12f8 688
689 /* Only do the slow convert if there are 8-bit characters */
690 if (! ereg("[\200-\377]", $string))
691 return $string;
9be313d5 692
c37a12f8 693 $string = str_replace ("\241", '&#8221;', $string);
c37a12f8 694 $string = str_replace ("\245", '&#8222;', $string);
c37a12f8 695 $string = str_replace ("\250", '&#216;', $string);
c37a12f8 696 $string = str_replace ("\252", '&#342;', $string);
c37a12f8 697 $string = str_replace ("\257", '&#198;', $string);
c37a12f8 698 $string = str_replace ("\264", '&#8220;', $string);
c37a12f8 699 $string = str_replace ("\270", '&#248;', $string);
c37a12f8 700 $string = str_replace ("\272", '&#343;', $string);
c37a12f8 701 $string = str_replace ("\277", '&#230;', $string);
c37a12f8 702 $string = str_replace ("\300", '&#260;', $string);
c37a12f8 703 $string = str_replace ("\301", '&#302;', $string);
c37a12f8 704 $string = str_replace ("\302", '&#256;', $string);
c37a12f8 705 $string = str_replace ("\303", '&#262;', $string);
c37a12f8 706 $string = str_replace ("\306", '&#280;', $string);
c37a12f8 707 $string = str_replace ("\307", '&#274;', $string);
c37a12f8 708 $string = str_replace ("\310", '&#268;', $string);
c37a12f8 709 $string = str_replace ("\312", '&#377;', $string);
c37a12f8 710 $string = str_replace ("\313", '&#278;', $string);
c37a12f8 711 $string = str_replace ("\314", '&#290;', $string);
c37a12f8 712 $string = str_replace ("\315", '&#310;', $string);
c37a12f8 713 $string = str_replace ("\316", '&#298;', $string);
c37a12f8 714 $string = str_replace ("\317", '&#315;', $string);
c37a12f8 715 $string = str_replace ("\320", '&#352;', $string);
c37a12f8 716 $string = str_replace ("\321", '&#323;', $string);
c37a12f8 717 $string = str_replace ("\322", '&#325;', $string);
c37a12f8 718 $string = str_replace ("\324", '&#332;', $string);
c37a12f8 719 $string = str_replace ("\330", '&#370;', $string);
c37a12f8 720 $string = str_replace ("\331", '&#321;', $string);
c37a12f8 721 $string = str_replace ("\332", '&#346;', $string);
c37a12f8 722 $string = str_replace ("\333", '&#362;', $string);
c37a12f8 723 $string = str_replace ("\335", '&#379;', $string);
c37a12f8 724 $string = str_replace ("\336", '&#381;', $string);
c37a12f8 725 $string = str_replace ("\340", '&#261;', $string);
c37a12f8 726 $string = str_replace ("\341", '&#303;', $string);
c37a12f8 727 $string = str_replace ("\342", '&#257;', $string);
c37a12f8 728 $string = str_replace ("\343", '&#263;', $string);
c37a12f8 729 $string = str_replace ("\346", '&#281;', $string);
c37a12f8 730 $string = str_replace ("\347", '&#275;', $string);
c37a12f8 731 $string = str_replace ("\350", '&#269;', $string);
c37a12f8 732 $string = str_replace ("\352", '&#378;', $string);
c37a12f8 733 $string = str_replace ("\353", '&#279;', $string);
c37a12f8 734 $string = str_replace ("\354", '&#291;', $string);
c37a12f8 735 $string = str_replace ("\355", '&#311;', $string);
c37a12f8 736 $string = str_replace ("\356", '&#299;', $string);
c37a12f8 737 $string = str_replace ("\357", '&#316;', $string);
c37a12f8 738 $string = str_replace ("\360", '&#353;', $string);
c37a12f8 739 $string = str_replace ("\361", '&#324;', $string);
c37a12f8 740 $string = str_replace ("\362", '&#326;', $string);
c37a12f8 741 $string = str_replace ("\364", '&#333;', $string);
c37a12f8 742 $string = str_replace ("\370", '&#371;', $string);
c37a12f8 743 $string = str_replace ("\371", '&#322;', $string);
c37a12f8 744 $string = str_replace ("\372", '&#347;', $string);
c37a12f8 745 $string = str_replace ("\373", '&#363;', $string);
c37a12f8 746 $string = str_replace ("\375", '&#380;', $string);
c37a12f8 747 $string = str_replace ("\376", '&#382;', $string);
c37a12f8 748 $string = str_replace ("\377", '&#8217;', $string);
749
750 // rest of charset is the same as ISO-8859-1
9be313d5 751 return (charset_decode_iso_8859_1($string));
752}
753
754/*
a2a7852b 755 * iso-8859-15 is Latin 9 and has very much the same use as Latin 1
756 * but has the Euro symbol and some characters needed for French.
757 */
758function charset_decode_iso_8859_15 ($string) {
759 // Euro sign
760 $string = str_replace ("\244", '&#8364;', $string);
761 // Latin capital letter S with caron
84556805 762 $string = str_replace ("\246", '&#352;', $string);
a2a7852b 763 // Latin small letter s with caron
764 $string = str_replace ("\250", '&#353;', $string);
765 // Latin capital letter Z with caron
766 $string = str_replace ("\264", '&#381;', $string);
767 // Latin small letter z with caron
768 $string = str_replace ("\270", '&#382;', $string);
769 // Latin capital ligature OE
770 $string = str_replace ("\274", '&#338;', $string);
771 // Latin small ligature oe
772 $string = str_replace ("\275", '&#339;', $string);
773 // Latin capital letter Y with diaeresis
774 $string = str_replace ("\276", '&#376;', $string);
775
776 return (charset_decode_iso_8859_1($string));
777}
778
a2a7852b 779
780/* Remove all 8 bit characters from all other ISO-8859 character sets */
781function charset_decode_iso_8859_default ($string) {
782 return (strtr($string, "\240\241\242\243\244\245\246\247".
1fd97780 783 "\250\251\252\253\254\255\256\257".
784 "\260\261\262\263\264\265\266\267".
785 "\270\271\272\273\274\275\276\277".
786 "\300\301\302\303\304\305\306\307".
787 "\310\311\312\313\314\315\316\317".
788 "\320\321\322\323\324\325\326\327".
789 "\330\331\332\333\334\335\336\337".
790 "\340\341\342\343\344\345\346\347".
791 "\350\351\352\353\354\355\356\357".
792 "\360\361\362\363\364\365\366\367".
a2a7852b 793 "\370\371\372\373\374\375\376\377",
1fd97780 794 "????????????????????????????????????????".
795 "????????????????????????????????????????".
796 "????????????????????????????????????????".
797 "????????"));
a2a7852b 798
799}
800
801/*
802 * This is the same as ISO-646-NO and is used by some
803 * Microsoft programs when sending Norwegian characters
804 */
805function charset_decode_ns_4551_1 ($string) {
806 /*
807 * These characters are:
808 * Latin capital letter AE
809 * Latin capital letter O with stroke
810 * Latin capital letter A with ring above
811 * and the same as small letters
812 */
813 return strtr ($string, "[\\]{|}", "");
814}
815
816/*
817 * KOI8-R is used to encode Russian mail (Cyrrilic). Defined in RFC
818 * 1489.
819 */
820function charset_decode_koi8r ($string) {
821 global $default_charset;
822
823 if ($default_charset == 'koi8-r') {
824 return $string;
825 }
826
827 /*
828 * Convert to Unicode HTML entities.
829 * This code is rather ineffective.
830 */
831 $string = str_replace("\200", '&#9472;', $string);
832 $string = str_replace("\201", '&#9474;', $string);
833 $string = str_replace("\202", '&#9484;', $string);
834 $string = str_replace("\203", '&#9488;', $string);
835 $string = str_replace("\204", '&#9492;', $string);
836 $string = str_replace("\205", '&#9496;', $string);
837 $string = str_replace("\206", '&#9500;', $string);
838 $string = str_replace("\207", '&#9508;', $string);
839 $string = str_replace("\210", '&#9516;', $string);
840 $string = str_replace("\211", '&#9524;', $string);
841 $string = str_replace("\212", '&#9532;', $string);
842 $string = str_replace("\213", '&#9600;', $string);
843 $string = str_replace("\214", '&#9604;', $string);
844 $string = str_replace("\215", '&#9608;', $string);
845 $string = str_replace("\216", '&#9612;', $string);
846 $string = str_replace("\217", '&#9616;', $string);
847 $string = str_replace("\220", '&#9617;', $string);
848 $string = str_replace("\221", '&#9618;', $string);
849 $string = str_replace("\222", '&#9619;', $string);
850 $string = str_replace("\223", '&#8992;', $string);
851 $string = str_replace("\224", '&#9632;', $string);
852 $string = str_replace("\225", '&#8729;', $string);
853 $string = str_replace("\226", '&#8730;', $string);
854 $string = str_replace("\227", '&#8776;', $string);
855 $string = str_replace("\230", '&#8804;', $string);
856 $string = str_replace("\231", '&#8805;', $string);
857 $string = str_replace("\232", '&#160;', $string);
858 $string = str_replace("\233", '&#8993;', $string);
859 $string = str_replace("\234", '&#176;', $string);
860 $string = str_replace("\235", '&#178;', $string);
861 $string = str_replace("\236", '&#183;', $string);
862 $string = str_replace("\237", '&#247;', $string);
863 $string = str_replace("\240", '&#9552;', $string);
864 $string = str_replace("\241", '&#9553;', $string);
865 $string = str_replace("\242", '&#9554;', $string);
866 $string = str_replace("\243", '&#1105;', $string);
867 $string = str_replace("\244", '&#9555;', $string);
868 $string = str_replace("\245", '&#9556;', $string);
869 $string = str_replace("\246", '&#9557;', $string);
870 $string = str_replace("\247", '&#9558;', $string);
871 $string = str_replace("\250", '&#9559;', $string);
872 $string = str_replace("\251", '&#9560;', $string);
873 $string = str_replace("\252", '&#9561;', $string);
874 $string = str_replace("\253", '&#9562;', $string);
875 $string = str_replace("\254", '&#9563;', $string);
876 $string = str_replace("\255", '&#9564;', $string);
877 $string = str_replace("\256", '&#9565;', $string);
878 $string = str_replace("\257", '&#9566;', $string);
879 $string = str_replace("\260", '&#9567;', $string);
880 $string = str_replace("\261", '&#9568;', $string);
881 $string = str_replace("\262", '&#9569;', $string);
882 $string = str_replace("\263", '&#1025;', $string);
883 $string = str_replace("\264", '&#9570;', $string);
884 $string = str_replace("\265", '&#9571;', $string);
885 $string = str_replace("\266", '&#9572;', $string);
886 $string = str_replace("\267", '&#9573;', $string);
887 $string = str_replace("\270", '&#9574;', $string);
888 $string = str_replace("\271", '&#9575;', $string);
889 $string = str_replace("\272", '&#9576;', $string);
890 $string = str_replace("\273", '&#9577;', $string);
891 $string = str_replace("\274", '&#9578;', $string);
892 $string = str_replace("\275", '&#9579;', $string);
893 $string = str_replace("\276", '&#9580;', $string);
894 $string = str_replace("\277", '&#169;', $string);
895 $string = str_replace("\300", '&#1102;', $string);
896 $string = str_replace("\301", '&#1072;', $string);
897 $string = str_replace("\302", '&#1073;', $string);
898 $string = str_replace("\303", '&#1094;', $string);
899 $string = str_replace("\304", '&#1076;', $string);
900 $string = str_replace("\305", '&#1077;', $string);
901 $string = str_replace("\306", '&#1092;', $string);
902 $string = str_replace("\307", '&#1075;', $string);
903 $string = str_replace("\310", '&#1093;', $string);
904 $string = str_replace("\311", '&#1080;', $string);
905 $string = str_replace("\312", '&#1081;', $string);
906 $string = str_replace("\313", '&#1082;', $string);
907 $string = str_replace("\314", '&#1083;', $string);
908 $string = str_replace("\315", '&#1084;', $string);
909 $string = str_replace("\316", '&#1085;', $string);
910 $string = str_replace("\317", '&#1086;', $string);
911 $string = str_replace("\320", '&#1087;', $string);
912 $string = str_replace("\321", '&#1103;', $string);
913 $string = str_replace("\322", '&#1088;', $string);
914 $string = str_replace("\323", '&#1089;', $string);
915 $string = str_replace("\324", '&#1090;', $string);
916 $string = str_replace("\325", '&#1091;', $string);
917 $string = str_replace("\326", '&#1078;', $string);
918 $string = str_replace("\327", '&#1074;', $string);
919 $string = str_replace("\330", '&#1100;', $string);
920 $string = str_replace("\331", '&#1099;', $string);
921 $string = str_replace("\332", '&#1079;', $string);
922 $string = str_replace("\333", '&#1096;', $string);
923 $string = str_replace("\334", '&#1101;', $string);
924 $string = str_replace("\335", '&#1097;', $string);
925 $string = str_replace("\336", '&#1095;', $string);
926 $string = str_replace("\337", '&#1098;', $string);
927 $string = str_replace("\340", '&#1070;', $string);
928 $string = str_replace("\341", '&#1040;', $string);
929 $string = str_replace("\342", '&#1041;', $string);
930 $string = str_replace("\343", '&#1062;', $string);
931 $string = str_replace("\344", '&#1044;', $string);
932 $string = str_replace("\345", '&#1045;', $string);
933 $string = str_replace("\346", '&#1060;', $string);
934 $string = str_replace("\347", '&#1043;', $string);
935 $string = str_replace("\350", '&#1061;', $string);
936 $string = str_replace("\351", '&#1048;', $string);
937 $string = str_replace("\352", '&#1049;', $string);
938 $string = str_replace("\353", '&#1050;', $string);
939 $string = str_replace("\354", '&#1051;', $string);
940 $string = str_replace("\355", '&#1052;', $string);
941 $string = str_replace("\356", '&#1053;', $string);
942 $string = str_replace("\357", '&#1054;', $string);
943 $string = str_replace("\360", '&#1055;', $string);
944 $string = str_replace("\361", '&#1071;', $string);
945 $string = str_replace("\362", '&#1056;', $string);
946 $string = str_replace("\363", '&#1057;', $string);
947 $string = str_replace("\364", '&#1058;', $string);
948 $string = str_replace("\365", '&#1059;', $string);
949 $string = str_replace("\366", '&#1046;', $string);
950 $string = str_replace("\367", '&#1042;', $string);
951 $string = str_replace("\370", '&#1068;', $string);
952 $string = str_replace("\371", '&#1067;', $string);
953 $string = str_replace("\372", '&#1047;', $string);
954 $string = str_replace("\373", '&#1064;', $string);
955 $string = str_replace("\374", '&#1069;', $string);
956 $string = str_replace("\375", '&#1065;', $string);
957 $string = str_replace("\376", '&#1063;', $string);
958 $string = str_replace("\377", '&#1066;', $string);
959
960 return $string;
961}
962
c37a12f8 963/*
1c0e847f 964 * KOI8-U is used to encode Ukrainian mail (Cyrrilic). Defined in RFC
965 * 2319.
966 */
967function charset_decode_koi8u ($string) {
968 global $default_charset;
969
970 if (strtolower($default_charset) == 'koi8-u') {
971 return $string;
972 }
973
974 /* Only do the slow convert if there are 8-bit characters */
975 if (! ereg("[\200-\377]", $string))
976 return $string;
977
978 // BOX DRAWINGS LIGHT HORIZONTAL
979 $string = str_replace("\200", '&#9472;', $string);
980 // BOX DRAWINGS LIGHT VERTICAL
981 $string = str_replace("\201", '&#9474;', $string);
982 // BOX DRAWINGS LIGHT DOWN AND RIGHT
983 $string = str_replace("\202", '&#9484;', $string);
984 // BOX DRAWINGS LIGHT DOWN AND LEFT
985 $string = str_replace("\203", '&#9488;', $string);
986 // BOX DRAWINGS LIGHT UP AND RIGHT
987 $string = str_replace("\204", '&#9492;', $string);
988 // BOX DRAWINGS LIGHT UP AND LEFT
989 $string = str_replace("\205", '&#9496;', $string);
990 // BOX DRAWINGS LIGHT VERTICAL AND RIGHT
991 $string = str_replace("\206", '&#9500;', $string);
992 // BOX DRAWINGS LIGHT VERTICAL AND LEFT
993 $string = str_replace("\207", '&#9508;', $string);
994 // BOX DRAWINGS LIGHT DOWN AND HORIZONTAL
995 $string = str_replace("\210", '&#9516;', $string);
996 // BOX DRAWINGS LIGHT UP AND HORIZONTAL
997 $string = str_replace("\211", '&#9524;', $string);
998 // BOX DRAWINGS LIGHT VERTICAL AND HORIZONTAL
999 $string = str_replace("\212", '&#9532;', $string);
1000 // UPPER HALF BLOCK
1001 $string = str_replace("\213", '&#9600;', $string);
1002 // LOWER HALF BLOCK
1003 $string = str_replace("\214", '&#9604;', $string);
1004 // FULL BLOCK
1005 $string = str_replace("\215", '&#9608;', $string);
1006 // LEFT HALF BLOCK
1007 $string = str_replace("\216", '&#9612;', $string);
1008 // RIGHT HALF BLOCK
1009 $string = str_replace("\217", '&#9616;', $string);
1010 // LIGHT SHADE
1011 $string = str_replace("\220", '&#9617;', $string);
1012 // MEDIUM SHADE
1013 $string = str_replace("\221", '&#9618;', $string);
1014 // DARK SHADE
1015 $string = str_replace("\222", '&#9619;', $string);
1016 // TOP HALF INTEGRAL
1017 $string = str_replace("\223", '&#8992;', $string);
1018 // BLACK SQUARE
1019 $string = str_replace("\224", '&#9632;', $string);
1020 // BULLET OPERATOR
1021 $string = str_replace("\225", '&#8729;', $string);
1022 // SQUARE ROOT
1023 $string = str_replace("\226", '&#8730;', $string);
1024 // ALMOST EQUAL TO
1025 $string = str_replace("\227", '&#8776;', $string);
1026 // LESS THAN OR EQUAL TO
1027 $string = str_replace("\230", '&#8804;', $string);
1028 // GREATER THAN OR EQUAL TO
1029 $string = str_replace("\231", '&#8805;', $string);
1030 // NO-BREAK SPACE
1031 $string = str_replace("\232", '&#160;', $string);
1032 // BOTTOM HALF INTEGRAL
1033 $string = str_replace("\233", '&#8993;', $string);
1034 // DEGREE SIGN
1035 $string = str_replace("\234", '&#176;', $string);
1036 // SUPERSCRIPT DIGIT TWO
1037 $string = str_replace("\235", '&#178;', $string);
1038 // MIDDLE DOT
1039 $string = str_replace("\236", '&#183;', $string);
1040 // DIVISION SIGN
1041 $string = str_replace("\237", '&#247;', $string);
1042 // BOX DRAWINGS DOUBLE HORIZONTAL
1043 $string = str_replace("\240", '&#9552;', $string);
1044 // BOX DRAWINGS DOUBLE VERTICAL
1045 $string = str_replace("\241", '&#9553;', $string);
1046 // BOX DRAWINGS DOWN SINGLE AND RIGHT DOUBLE
1047 $string = str_replace("\242", '&#9554;', $string);
1048 // CYRILLIC SMALL LETTER IO
1049 $string = str_replace("\243", '&#1105;', $string);
1050 // CYRILLIC SMALL LETTER UKRAINIAN IE
1051 $string = str_replace("\244", '&#1108;', $string);
1052 // BOX DRAWINGS DOUBLE DOWN AND RIGHT
1053 $string = str_replace("\245", '&#9556;', $string);
1054 // CYRILLIC SMALL LETTER BYELORUSSIAN-UKRAINIAN I
1055 $string = str_replace("\246", '&#1110;', $string);
1056 // CYRILLIC SMALL LETTER YI (Ukrainian)
1057 $string = str_replace("\247", '&#1111;', $string);
1058 // BOX DRAWINGS DOUBLE DOWN AND LEFT
1059 $string = str_replace("\250", '&#9559;', $string);
1060 // BOX DRAWINGS UP SINGLE AND RIGHT DOUBLE
1061 $string = str_replace("\251", '&#9560;', $string);
1062 // BOX DRAWINGS UP DOUBLE AND RIGHT SINGLE
1063 $string = str_replace("\252", '&#9561;', $string);
1064 // BOX DRAWINGS DOUBLE UP AND RIGHT
1065 $string = str_replace("\253", '&#9562;', $string);
1066 // BOX DRAWINGS UP SINGLE AND LEFT DOUBLE
1067 $string = str_replace("\254", '&#9563;', $string);
1068 // CYRILLIC SMALL LETTER GHE WITH UPTURN
1069 $string = str_replace("\255", '&#1169;', $string);
1070 // BOX DRAWINGS DOUBLE UP AND LEFT
1071 $string = str_replace("\256", '&#9565;', $string);
1072 // BOX DRAWINGS VERTICAL SINGLE AND RIGHT DOUBLE
1073 $string = str_replace("\257", '&#9566;', $string);
1074 // BOX DRAWINGS VERTICAL DOUBLE AND RIGHT SINGLE
1075 $string = str_replace("\260", '&#9567;', $string);
1076 // BOX DRAWINGS DOUBLE VERTICAL AND RIGHT
1077 $string = str_replace("\261", '&#9568;', $string);
1078 // BOX DRAWINGS VERTICAL SINGLE AND LEFT DOUBLE
1079 $string = str_replace("\262", '&#9569;', $string);
1080 // CYRILLIC CAPITAL LETTER IO
1081 $string = str_replace("\263", '&#1025;', $string);
1082 // CYRILLIC CAPITAL LETTER UKRAINIAN IE
1083 $string = str_replace("\264", '&#1028;', $string);
1084 // DOUBLE VERTICAL AND LEFT
1085 $string = str_replace("\265", '&#9571;', $string);
1086 // CYRILLIC CAPITAL LETTER BYELORUSSIAN-UKRAINIAN I
1087 $string = str_replace("\266", '&#1030;', $string);
1088 // CYRILLIC CAPITAL LETTER YI (Ukrainian)
1089 $string = str_replace("\267", '&#1031;', $string);
1090 // BOX DRAWINGS DOUBLE DOWN AND HORIZONTAL
1091 $string = str_replace("\270", '&#9574;', $string);
1092 // BOX DRAWINGS UP SINGLE AND HORIZONTAL DOUBLE
1093 $string = str_replace("\271", '&#9575;', $string);
1094 // BOX DRAWINGS UP DOUBLE AND HORIZONTAL SINGLE
1095 $string = str_replace("\272", '&#9576;', $string);
1096 // BOX DRAWINGS DOUBLE UP AND HORIZONTAL
1097 $string = str_replace("\273", '&#9577;', $string);
1098 // BOX DRAWINGS VERTICAL SINGLE AND HORIZONTAL DOUBLE
1099 $string = str_replace("\274", '&#9578;', $string);
1100 // CYRILLIC CAPITAL LETTER GHE WITH UPTURN
1101 $string = str_replace("\275", '&#1168;', $string);
1102 // BOX DRAWINGS DOUBLE VERTICAL AND HORIZONTAL
1103 $string = str_replace("\276", '&#9580;', $string);
1104 // COPYRIGHT SIGN
1105 $string = str_replace("\277", '&#169;', $string);
1106 // CYRILLIC SMALL LETTER YU
1107 $string = str_replace("\300", '&#1102;', $string);
1108 // CYRILLIC SMALL LETTER A
1109 $string = str_replace("\301", '&#1072;', $string);
1110 // CYRILLIC SMALL LETTER BE
1111 $string = str_replace("\302", '&#1073;', $string);
1112 // CYRILLIC SMALL LETTER TSE
1113 $string = str_replace("\303", '&#1094;', $string);
1114 // CYRILLIC SMALL LETTER DE
1115 $string = str_replace("\304", '&#1076;', $string);
1116 // CYRILLIC SMALL LETTER IE
1117 $string = str_replace("\305", '&#1077;', $string);
1118 // CYRILLIC SMALL LETTER EF
1119 $string = str_replace("\306", '&#1092;', $string);
1120 // CYRILLIC SMALL LETTER GHE
1121 $string = str_replace("\307", '&#1075;', $string);
1122 // CYRILLIC SMALL LETTER HA
1123 $string = str_replace("\310", '&#1093;', $string);
1124 // CYRILLIC SMALL LETTER I
1125 $string = str_replace("\311", '&#1080;', $string);
1126 // CYRILLIC SMALL LETTER SHORT I
1127 $string = str_replace("\312", '&#1081;', $string);
1128 // CYRILLIC SMALL LETTER KA
1129 $string = str_replace("\313", '&#1082;', $string);
1130 // CYRILLIC SMALL LETTER EL
1131 $string = str_replace("\314", '&#1083;', $string);
1132 // CYRILLIC SMALL LETTER EM
1133 $string = str_replace("\315", '&#1084;', $string);
1134 // CYRILLIC SMALL LETTER EN
1135 $string = str_replace("\316", '&#1085;', $string);
1136 // CYRILLIC SMALL LETTER O
1137 $string = str_replace("\317", '&#1086;', $string);
1138 // CYRILLIC SMALL LETTER PE
1139 $string = str_replace("\320", '&#1087;', $string);
1140 // CYRILLIC SMALL LETTER YA
1141 $string = str_replace("\321", '&#1103;', $string);
1142 // CYRILLIC SMALL LETTER ER
1143 $string = str_replace("\322", '&#1088;', $string);
1144 // CYRILLIC SMALL LETTER ES
1145 $string = str_replace("\323", '&#1089;', $string);
1146 // CYRILLIC SMALL LETTER TE
1147 $string = str_replace("\324", '&#1090;', $string);
1148 // CYRILLIC SMALL LETTER U
1149 $string = str_replace("\325", '&#1091;', $string);
1150 // CYRILLIC SMALL LETTER ZHE
1151 $string = str_replace("\326", '&#1078;', $string);
1152 // CYRILLIC SMALL LETTER VE
1153 $string = str_replace("\327", '&#1074;', $string);
1154 // CYRILLIC SMALL LETTER SOFT SIGN
1155 $string = str_replace("\330", '&#1100;', $string);
1156 // CYRILLIC SMALL LETTER YERU
1157 $string = str_replace("\331", '&#1099;', $string);
1158 // CYRILLIC SMALL LETTER ZE
1159 $string = str_replace("\332", '&#1079;', $string);
1160 // CYRILLIC SMALL LETTER SHA
1161 $string = str_replace("\333", '&#1096;', $string);
1162 // CYRILLIC SMALL LETTER E
1163 $string = str_replace("\334", '&#1101;', $string);
1164 // CYRILLIC SMALL LETTER SHCHA
1165 $string = str_replace("\335", '&#1097;', $string);
1166 // CYRILLIC SMALL LETTER CHE
1167 $string = str_replace("\336", '&#1095;', $string);
1168 // CYRILLIC SMALL LETTER HARD SIGN
1169 $string = str_replace("\337", '&#1098;', $string);
1170 // CYRILLIC CAPITAL LETTER YU
1171 $string = str_replace("\340", '&#1070;', $string);
1172 // CYRILLIC CAPITAL LETTER A
1173 $string = str_replace("\341", '&#1040;', $string);
1174 // CYRILLIC CAPITAL LETTER BE
1175 $string = str_replace("\342", '&#1041;', $string);
1176 // CYRILLIC CAPITAL LETTER TSE
1177 $string = str_replace("\343", '&#1062;', $string);
1178 // CYRILLIC CAPITAL LETTER DE
1179 $string = str_replace("\344", '&#1044;', $string);
1180 // CYRILLIC CAPITAL LETTER IE
1181 $string = str_replace("\345", '&#1045;', $string);
1182 // CYRILLIC CAPITAL LETTER EF
1183 $string = str_replace("\346", '&#1060;', $string);
1184 // CYRILLIC CAPITAL LETTER GHE
1185 $string = str_replace("\347", '&#1043;', $string);
1186 // CYRILLIC CAPITAL LETTER HA
1187 $string = str_replace("\350", '&#1061;', $string);
1188 // CYRILLIC CAPITAL LETTER I
1189 $string = str_replace("\351", '&#1048;', $string);
1190 // CYRILLIC CAPITAL LETTER SHORT I
1191 $string = str_replace("\352", '&#1049;', $string);
1192 // CYRILLIC CAPITAL LETTER KA
1193 $string = str_replace("\353", '&#1050;', $string);
1194 // CYRILLIC CAPITAL LETTER EL
1195 $string = str_replace("\354", '&#1051;', $string);
1196 // CYRILLIC CAPITAL LETTER EM
1197 $string = str_replace("\355", '&#1052;', $string);
1198 // CYRILLIC CAPITAL LETTER EN
1199 $string = str_replace("\356", '&#1053;', $string);
1200 // CYRILLIC CAPITAL LETTER O
1201 $string = str_replace("\357", '&#1054;', $string);
1202 // CYRILLIC CAPITAL LETTER PE
1203 $string = str_replace("\360", '&#1055;', $string);
1204 // CYRILLIC CAPITAL LETTER YA
1205 $string = str_replace("\361", '&#1071;', $string);
1206 // CYRILLIC CAPITAL LETTER ER
1207 $string = str_replace("\362", '&#1056;', $string);
1208 // CYRILLIC CAPITAL LETTER ES
1209 $string = str_replace("\363", '&#1057;', $string);
1210 // CYRILLIC CAPITAL LETTER TE
1211 $string = str_replace("\364", '&#1058;', $string);
1212 // CYRILLIC CAPITAL LETTER U
1213 $string = str_replace("\365", '&#1059;', $string);
1214 // CYRILLIC CAPITAL LETTER ZHE
1215 $string = str_replace("\366", '&#1046;', $string);
1216 // CYRILLIC CAPITAL LETTER VE
1217 $string = str_replace("\367", '&#1042;', $string);
1218 // CYRILLIC CAPITAL LETTER SOFT SIGN
1219 $string = str_replace("\370", '&#1068;', $string);
1220 // CYRILLIC CAPITAL LETTER YERU
1221 $string = str_replace("\371", '&#1067;', $string);
1222 // CYRILLIC CAPITAL LETTER ZE
1223 $string = str_replace("\372", '&#1047;', $string);
1224 // CYRILLIC CAPITAL LETTER SHA
1225 $string = str_replace("\373", '&#1064;', $string);
1226 // CYRILLIC CAPITAL LETTER E
1227 $string = str_replace("\374", '&#1069;', $string);
1228 // CYRILLIC CAPITAL LETTER SHCHA
1229 $string = str_replace("\375", '&#1065;', $string);
1230 // CYRILLIC CAPITAL LETTER CHE
1231 $string = str_replace("\376", '&#1063;', $string);
1232 // CYRILLIC CAPITAL LETTER HARD SIGN
1233 $string = str_replace("\377", '&#1066;', $string);
1234
1235 return $string;
1236}
1237
1238/*
1239 * windows-1251 is used to encode Bulgarian mail (Cyrrilic).
1240 */
1241function charset_decode_windows_1251 ($string) {
1242 global $default_charset;
1243
1244 if (strtolower($default_charset) == 'windows-1251') {
1245 return $string;
1246 }
1247
1248 /* Only do the slow convert if there are 8-bit characters */
1249 if (! ereg("[\200-\377]", $string))
1250 return $string;
1251
1252 // CYRILLIC CAPITAL LETTER DJE (Serbocroatian)
1253 $string = str_replace("\200", '&#1026;', $string);
1254 // CYRILLIC CAPITAL LETTER GJE
1255 $string = str_replace("\201", '&#1027;', $string);
1256 // SINGLE LOW-9 QUOTATION MARK
1257 $string = str_replace("\202", '&#8218;', $string);
1258 // CYRILLIC SMALL LETTER GJE
1259 $string = str_replace("\203", '&#1107;', $string);
1260 // DOUBLE LOW-9 QUOTATION MARK
1261 $string = str_replace("\204", '&#8222;', $string);
1262 // HORIZONTAL ELLIPSIS
1263 $string = str_replace("\205", '&#8230;', $string);
1264 // DAGGER
1265 $string = str_replace("\206", '&#8224;', $string);
1266 // DOUBLE DAGGER
1267 $string = str_replace("\207", '&#8225;', $string);
1268 // EURO SIGN
1269 $string = str_replace("\210", '&#8364;', $string);
1270 // PER MILLE SIGN
1271 $string = str_replace("\211", '&#8240;', $string);
1272 // CYRILLIC CAPITAL LETTER LJE
1273 $string = str_replace("\212", '&#1033;', $string);
1274 // SINGLE LEFT-POINTING ANGLE QUOTATION MARK
1275 $string = str_replace("\213", '&#8249;', $string);
1276 // CYRILLIC CAPITAL LETTER NJE
1277 $string = str_replace("\214", '&#1034;', $string);
1278 // CYRILLIC CAPITAL LETTER KJE
1279 $string = str_replace("\215", '&#1036;', $string);
1280 // CYRILLIC CAPITAL LETTER TSHE (Serbocroatian)
1281 $string = str_replace("\216", '&#1035;', $string);
1282 // CYRILLIC CAPITAL LETTER DZHE
1283 $string = str_replace("\217", '&#1039;', $string);
1284 // CYRILLIC SMALL LETTER DJE (Serbocroatian)
1285 $string = str_replace("\220", '&#1106;', $string);
1286 // LEFT SINGLE QUOTATION MARK
1287 $string = str_replace("\221", '&#8216;', $string);
1288 // RIGHT SINGLE QUOTATION MARK
1289 $string = str_replace("\222", '&#8217;', $string);
1290 // LEFT DOUBLE QUOTATION MARK
1291 $string = str_replace("\223", '&#8220;', $string);
1292 // RIGHT DOUBLE QUOTATION MARK
1293 $string = str_replace("\224", '&#8221;', $string);
1294 // BULLET
1295 $string = str_replace("\225", '&#8226;', $string);
1296 // EN DASH
1297 $string = str_replace("\226", '&#8211;', $string);
1298 // EM DASH
1299 $string = str_replace("\227", '&#8212;', $string);
1300 // TRADE MARK SIGN
1301 $string = str_replace("\231", '&#8482;', $string);
1302 // CYRILLIC SMALL LETTER LJE
1303 $string = str_replace("\232", '&#1113;', $string);
1304 // SINGLE RIGHT-POINTING ANGLE QUOTATION MARK
1305 $string = str_replace("\233", '&#8250;', $string);
1306 // CYRILLIC SMALL LETTER NJE
1307 $string = str_replace("\234", '&#1114;', $string);
1308 // CYRILLIC SMALL LETTER KJE
1309 $string = str_replace("\235", '&#1116;', $string);
1310 // CYRILLIC SMALL LETTER TSHE (Serbocroatian)
1311 $string = str_replace("\236", '&#1115;', $string);
1312 // CYRILLIC SMALL LETTER DZHE
1313 $string = str_replace("\237", '&#1119;', $string);
1314 // NO-BREAK SPACE
1315 $string = str_replace("\240", '&#160;', $string);
1316 // CYRILLIC CAPITAL LETTER SHORT U (Byelorussian)
1317 $string = str_replace("\241", '&#1038;', $string);
1318 // CYRILLIC SMALL LETTER SHORT U (Byelorussian)
1319 $string = str_replace("\242", '&#1118;', $string);
1320 // CYRILLIC CAPITAL LETTER JE
1321 $string = str_replace("\243", '&#1032;', $string);
1322 // CURRENCY SIGN
1323 $string = str_replace("\244", '&#164;', $string);
1324 // CYRILLIC CAPITAL LETTER GHE WITH UPTURN
1325 $string = str_replace("\245", '&#1168;', $string);
1326 // BROKEN BAR
1327 $string = str_replace("\246", '&#166;', $string);
1328 // SECTION SIGN
1329 $string = str_replace("\247", '&#167;', $string);
1330 // CYRILLIC CAPITAL LETTER IO
1331 $string = str_replace("\250", '&#1025;', $string);
1332 // COPYRIGHT SIGN
1333 $string = str_replace("\251", '&#169;', $string);
1334 // CYRILLIC CAPITAL LETTER UKRAINIAN IE
1335 $string = str_replace("\252", '&#1028;', $string);
1336 // LEFT-POINTING DOUBLE ANGLE QUOTATION MARK
1337 $string = str_replace("\253", '&#171;', $string);
1338 // NOT SIGN
1339 $string = str_replace("\254", '&#172;', $string);
1340 // SOFT HYPHEN
1341 $string = str_replace("\255", '&#173;', $string);
1342 // REGISTERED SIGN
1343 $string = str_replace("\256", '&#174;', $string);
1344 // CYRILLIC CAPITAL LETTER YI (Ukrainian)
1345 $string = str_replace("\257", '&#1031;', $string);
1346 // DEGREE SIGN
1347 $string = str_replace("\260", '&#176;', $string);
1348 // PLUS-MINUS SIGN
1349 $string = str_replace("\261", '&#177;', $string);
1350 // CYRILLIC CAPITAL LETTER BYELORUSSIAN-UKRAINIAN I
1351 $string = str_replace("\262", '&#1030;', $string);
1352 // CYRILLIC SMALL LETTER BYELORUSSIAN-UKRAINIAN I
1353 $string = str_replace("\263", '&#1110;', $string);
1354 // CYRILLIC SMALL LETTER GHE WITH UPTURN
1355 $string = str_replace("\264", '&#1169;', $string);
1356 // MICRO SIGN
1357 $string = str_replace("\265", '&#181;', $string);
1358 // PILCROW SIGN
1359 $string = str_replace("\266", '&#182;', $string);
1360 // MIDDLE DOT
1361 $string = str_replace("\267", '&#183;', $string);
1362 // CYRILLIC SMALL LETTER IO
1363 $string = str_replace("\270", '&#1105;', $string);
1364 // NUMERO SIGN
1365 $string = str_replace("\271", '&#8470;', $string);
1366 // CYRILLIC SMALL LETTER UKRAINIAN IE
1367 $string = str_replace("\272", '&#1108;', $string);
1368 // RIGHT-POINTING DOUBLE ANGLE QUOTATION MARK
1369 $string = str_replace("\273", '&#187;', $string);
1370 // CYRILLIC SMALL LETTER JE
1371 $string = str_replace("\274", '&#1112;', $string);
1372 // CYRILLIC CAPITAL LETTER DZE
1373 $string = str_replace("\275", '&#1029;', $string);
1374 // CYRILLIC SMALL LETTER DZE
1375 $string = str_replace("\276", '&#1109;', $string);
1376 // CYRILLIC SMALL LETTER YI (Ukrainian)
1377 $string = str_replace("\277", '&#1111;', $string);
1378
1379 // 192-255 > 1040-1103 (+848)
1380 $string = preg_replace("/([\300-\377])/e","'&#' . (ord('\\1')+848) . ';'",$string);
1381
1382 return $string;
1383}
1384
1385/*
1386 windows-1253 (Greek)
1387 */
1388function charset_decode_windows_1253 ($string) {
1389 global $default_charset;
1390
1391 if (strtolower($default_charset) == 'windows-1253')
1392 return $string;
1393
1394 /* Only do the slow convert if there are 8-bit characters */
1395 if (! ereg("[\200-\377]", $string))
1396 return $string;
1397
1398 $string = str_replace("\200", '&#8364;', $string);
1399 $string = str_replace("\202", '&#8218;', $string);
1400 $string = str_replace("\203", '&#402;', $string);
1401 $string = str_replace("\204", '&#8222;', $string);
1402 $string = str_replace("\205", '&#8230;', $string);
1403 $string = str_replace("\206", '&#8224;', $string);
1404 $string = str_replace("\207", '&#8225;', $string);
1405 $string = str_replace("\211", '&#8240;', $string);
1406 $string = str_replace("\213", '&#8249;', $string);
1407 $string = str_replace("\221", '&#8216;', $string);
1408 $string = str_replace("\222", '&#8217;', $string);
1409 $string = str_replace("\223", '&#8220;', $string);
1410 $string = str_replace("\224", '&#8221;', $string);
1411 $string = str_replace("\225", '&#8226;', $string);
1412 $string = str_replace("\226", '&#8211;', $string);
1413 $string = str_replace("\227", '&#8212;', $string);
1414 $string = str_replace("\231", '&#8482;', $string);
1415 $string = str_replace("\233", '&#8250;', $string);
1416 $string = str_replace("\241", '&#901;', $string);
1417 $string = str_replace("\242", '&#902;', $string);
1418 $string = str_replace ("\257", '&#8213;', $string);
1419 $string = str_replace("\264", '&#900;', $string);
1420 $string = str_replace("\270", '&#904;', $string);
1421 $string = str_replace ("\271", '&#905;', $string);
1422 $string = str_replace ("\272", '&#906;', $string);
1423 $string = str_replace ("\274", '&#908;', $string);
1424 // cycle for 190-254 symbols
1425 $string = preg_replace("/([\274-\376])/e","'&#' . (ord('\\1')+720);",$string);
1426
1427 // Rest of charset is like iso-8859-1
1428 return (charset_decode_iso_8859_1($string));
1429}
1430
1431/*
3ab35042 1432 windows-1254 (Turks)
c37a12f8 1433 */
3ab35042 1434function charset_decode_windows_1254 ($string) {
94965562 1435 global $default_charset;
c37a12f8 1436
3ab35042 1437 if (strtolower($default_charset) == 'windows-1254')
c37a12f8 1438 return $string;
c37a12f8 1439
1440 /* Only do the slow convert if there are 8-bit characters */
1441 if (! ereg("[\200-\377]", $string))
1442 return $string;
1443
1444 // Euro sign 128 -> 8364
1445 $string = str_replace("\200", '&#8364;', $string);
1446 // Single low-9 quotation mark 130 -> 8218
1447 $string = str_replace("\202", '&#8218;', $string);
3ab35042 1448 // latin small letter f with hook 131 -> 402
1449 $string = str_replace("\203", '&#402;', $string);
c37a12f8 1450 // Double low-9 quotation mark 132 -> 8222
1451 $string = str_replace("\204", '&#8222;', $string);
1452 // horizontal ellipsis 133 -> 8230
1453 $string = str_replace("\205", '&#8230;', $string);
1454 // dagger 134 -> 8224
1455 $string = str_replace("\206", '&#8224;', $string);
1456 // double dagger 135 -> 8225
1457 $string = str_replace("\207", '&#8225;', $string);
3ab35042 1458 // modifier letter circumflex accent 136->710
1459 $string = str_replace("\210", '&#710;', $string);
c37a12f8 1460 // per mille sign 137 -> 8240
1461 $string = str_replace("\211", '&#8240;', $string);
3ab35042 1462 // latin capital letter s with caron 138 -> 352
1463 $string = str_replace("\212", '&#352;', $string);
c37a12f8 1464 // single left-pointing angle quotation mark 139 -> 8249
1465 $string = str_replace("\213", '&#8249;', $string);
3ab35042 1466 // latin capital ligature oe 140 -> 338
1467 $string = str_replace("\214", '&#338;', $string);
c37a12f8 1468 // left single quotation mark 145 -> 8216
1469 $string = str_replace("\221", '&#8216;', $string);
1470 // right single quotation mark 146 -> 8217
1471 $string = str_replace("\222", '&#8217;', $string);
1472 // left double quotation mark 147 -> 8220
1473 $string = str_replace("\223", '&#8220;', $string);
1474 // right double quotation mark 148 -> 8221
1475 $string = str_replace("\224", '&#8221;', $string);
1476 // bullet 149 -> 8226
1477 $string = str_replace("\225", '&#8226;', $string);
1478 // en dash 150 -> 8211
1479 $string = str_replace("\226", '&#8211;', $string);
1480 // em dash 151 -> 8212
1481 $string = str_replace("\227", '&#8212;', $string);
3ab35042 1482 // small tilde 152 -> 732
1483 $string = str_replace("\230", '&#732;', $string);
c37a12f8 1484 // trade mark sign 153 -> 8482
1485 $string = str_replace("\231", '&#8482;', $string);
3ab35042 1486 // latin small letter s with caron 154 -> 353
1487 $string = str_replace("\232", '&#353;', $string);
c37a12f8 1488 // single right-pointing angle quotation mark 155 -> 8250
1489 $string = str_replace("\233", '&#8250;', $string);
3ab35042 1490 // latin small ligature oe 156 -> 339
1491 $string = str_replace("\234", '&#339;', $string);
1492 // latin capital letter y with diaresis 159->376
1493 $string = str_replace("\237", '&#376;', $string);
1494 // latin capital letter g with breve 208->286
1495 $string = str_replace("\320", '&#286;', $string);
1496 // latin capital letter i with dot above 221->304
1497 $string = str_replace("\335", '&#304;', $string);
1498 // latin capital letter s with cedilla 222->350
1499 $string = str_replace("\336", '&#350;', $string);
1500 // latin small letter g with breve 240->287
1501 $string = str_replace("\360", '&#287;', $string);
1502 // latin small letter dotless i 253->305
1503 $string = str_replace("\375", '&#305;', $string);
1504 // latin small letter s with cedilla 254->351
1505 $string = str_replace("\376", '&#351;', $string);
1506
1507 // Rest of charset is like iso-8859-1
1508 return (charset_decode_iso_8859_1($string));
1509}
1510
1511/*
c48a8ca7 1512 windows-1255 (Hebr)
1513 */
1514function charset_decode_windows_1255 ($string) {
1515 global $default_charset;
1516
1517 if (strtolower($default_charset) == 'windows-1255')
1518 return $string;
1519
1520 /* Only do the slow convert if there are 8-bit characters */
1521 if (! ereg("[\200-\377]", $string))
1522 return $string;
1523
1524 $string = str_replace("\200", '&#8364;', $string);
1525 $string = str_replace("\202", '&#8218;', $string);
1526 $string = str_replace("\203", '&#402;', $string);
1527 $string = str_replace("\204", '&#8222;', $string);
1528 $string = str_replace("\205", '&#8230;', $string);
1529 $string = str_replace("\206", '&#8224;', $string);
1530 $string = str_replace("\207", '&#8225;', $string);
1531 $string = str_replace("\211", '&#8240;', $string);
1532 $string = str_replace("\213", '&#8249;', $string);
1533 $string = str_replace("\221", '&#8216;', $string);
1534 $string = str_replace("\222", '&#8217;', $string);
1535 $string = str_replace("\223", '&#8220;', $string);
1536 $string = str_replace("\224", '&#8221;', $string);
1537 $string = str_replace("\225", '&#8226;', $string);
1538 $string = str_replace("\226", '&#8211;', $string);
1539 $string = str_replace("\227", '&#8212;', $string);
1540 $string = str_replace("\231", '&#8482;', $string);
1541 $string = str_replace("\233", '&#8250;', $string);
1542 $string = str_replace("\240", '&#160;', $string);
1543 // 162-169
1544 $string = preg_replace("/([\242-\251])/e","'&#' . ord('\\1') . ';'",$string);
1545 $string = str_replace("\252", '&#215;', $string);
1546 // 171-174
1547 $string = preg_replace("/([\253-\256])/e","'&#' . ord('\\1') . ';'",$string);
1548 $string = str_replace ("\257", '&#781;', $string);
1549 // 176-185
1550 $string = preg_replace("/([\260-\271])/e","'&#' . ord('\\1') . ';'",$string);
1551 $string = str_replace ("\272", '&#247;', $string);
1552 // 187-190
1553 $string = preg_replace("/([\273-\276])/e","'&#' . ord('\\1') . ';'",$string);
1554 $string = str_replace ("\337", '&#8215;', $string);
1555 // 224-250 1488-1514 (+1264)
1556 $string = preg_replace("/([\340-\372])/e","'&#' . (ord('\\1')+1264) . ';'",$string);
1557
1558 return ($string);
1559}
1560
1561/*
1562 windows-1256 (Arab)
1563 */
1564function charset_decode_windows_1256 ($string) {
1565 global $default_charset;
1566
1567 if (strtolower($default_charset) == 'windows-1256')
1568 return $string;
1569
1570 /* Only do the slow convert if there are 8-bit characters */
1571 if (! ereg("[\200-\377]", $string))
1572 return $string;
1573
1574 $string = str_replace("\200", '&#1548;', $string);
1575 $string = str_replace("\202", '&#8218;', $string);
1576 $string = str_replace("\204", '&#8222;', $string);
1577 $string = str_replace("\205", '&#8230;', $string);
1578 $string = str_replace("\206", '&#8224;', $string);
1579 $string = str_replace("\207", '&#8225;', $string);
1580 $string = str_replace("\211", '&#8240;', $string);
1581 $string = str_replace("\213", '&#8249;', $string);
1582 $string = str_replace("\221", '&#8216;', $string);
1583 $string = str_replace("\222", '&#8217;', $string);
1584 $string = str_replace("\223", '&#8220;', $string);
1585 $string = str_replace("\224", '&#8221;', $string);
1586 $string = str_replace("\225", '&#8226;', $string);
1587 $string = str_replace("\226", '&#8211;', $string);
1588 $string = str_replace("\227", '&#8212;', $string);
1589 $string = str_replace("\230", '&#1564;', $string);
1590 $string = str_replace("\231", '&#8482;', $string);
1591 $string = str_replace("\232", '&#1567;', $string);
1592 $string = str_replace("\233", '&#8250;', $string);
1593 $string = str_replace("\234", '&#1569;', $string);
1594 $string = str_replace("\235", '&#1570;', $string);
1595 $string = str_replace("\236", '&#1571;', $string);
1596 $string = str_replace("\237", '&#376;', $string);
1597 $string = str_replace("\241", '&#1572;', $string);
1598 $string = str_replace("\242", '&#1573;', $string);
1599 $string = str_replace("\245", '&#1574;', $string);
1600 $string = str_replace ("\250", '&#1575;', $string);
1601 $string = str_replace ("\252", '&#1576;', $string);
1602 $string = str_replace ("\262", '&#1577;', $string);
1603 $string = str_replace ("\263", '&#1578;', $string);
1604 $string = str_replace ("\264", '&#1579;', $string);
1605 $string = str_replace ("\270", '&#1580;', $string);
1606 $string = str_replace ("\272", '&#1581;', $string);
1607 $string = str_replace ("\274", '&#1582;', $string);
1608 $string = str_replace ("\275", '&#1583;', $string);
1609 $string = str_replace ("\276", '&#1584;', $string);
1610 $string = str_replace ("\277", '&#1585;', $string);
1611 $string = str_replace ("\301", '&#1586;', $string);
1612 $string = str_replace ("\304", '&#1587;', $string);
1613 $string = str_replace ("\305", '&#1588;', $string);
1614 $string = str_replace ("\306", '&#1589;', $string);
1615 $string = str_replace ("\314", '&#1590;', $string);
1616 $string = str_replace ("\315", '&#1591;', $string);
1617 $string = str_replace ("\320", '&#1592;', $string);
1618 $string = str_replace ("\321", '&#1593;', $string);
1619 $string = str_replace ("\322", '&#1594;', $string);
1620 $string = str_replace ("\323", '&#1600;', $string);
1621 $string = str_replace ("\325", '&#1601;', $string);
1622 $string = str_replace ("\326", '&#1602;', $string);
1623 $string = str_replace ("\330", '&#1603;', $string);
1624 $string = str_replace ("\332", '&#1711;', $string);
1625 $string = str_replace ("\335", '&#1604;', $string);
1626 $string = str_replace ("\336", '&#1605;', $string);
1627 $string = str_replace ("\337", '&#1606;', $string);
1628 $string = str_replace ("\341", '&#1607;', $string);
1629 $string = str_replace ("\344", '&#1608;', $string);
1630 $string = str_replace ("\345", '&#1609;', $string);
1631 $string = str_replace ("\346", '&#1610;', $string);
1632 $string = str_replace ("\354", '&#1611;', $string);
1633 $string = str_replace ("\355", '&#1612;', $string);
1634 $string = str_replace ("\360", '&#1613;', $string);
1635 $string = str_replace ("\361", '&#1614;', $string);
1636 $string = str_replace ("\362", '&#1615;', $string);
1637 $string = str_replace ("\363", '&#1616;', $string);
1638 $string = str_replace ("\365", '&#1617;', $string);
1639 $string = str_replace ("\366", '&#1618;', $string);
1640
1641 // Rest of charset is like iso-8859-1
1642 return (charset_decode_iso_8859_1($string));
1643}
1644
1645/*
3ab35042 1646 windows-1257 (BaltRim)
1647 */
1648function charset_decode_windows_1257 ($string) {
94965562 1649 global $default_charset;
3ab35042 1650
1651 if (strtolower($default_charset) == 'windows-1257')
1652 return $string;
3ab35042 1653
1654 /* Only do the slow convert if there are 8-bit characters */
1655 if (! ereg("[\200-\377]", $string))
1656 return $string;
1657
1658 $string = str_replace("\200", '&#8364;', $string);
1659 $string = str_replace("\202", '&#8218;', $string);
1660 $string = str_replace("\204", '&#8222;', $string);
1661 $string = str_replace("\205", '&#8230;', $string);
1662 $string = str_replace("\206", '&#8224;', $string);
1663 $string = str_replace("\207", '&#8225;', $string);
1664 $string = str_replace("\211", '&#8240;', $string);
1665 $string = str_replace("\213", '&#8249;', $string);
1666 $string = str_replace("\215", '&#168;', $string);
1667 $string = str_replace("\216", '&#711;', $string);
1668 $string = str_replace("\217", '&#184;', $string);
1669 $string = str_replace("\221", '&#8216;', $string);
1670 $string = str_replace("\222", '&#8217;', $string);
1671 $string = str_replace("\223", '&#8220;', $string);
1672 $string = str_replace("\224", '&#8221;', $string);
1673 $string = str_replace("\225", '&#8226;', $string);
1674 $string = str_replace("\226", '&#8211;', $string);
1675 $string = str_replace("\227", '&#8212;', $string);
1676 $string = str_replace("\231", '&#8482;', $string);
1677 $string = str_replace("\233", '&#8250;', $string);
c37a12f8 1678 $string = str_replace("\235", '&#175;', $string);
c37a12f8 1679 $string = str_replace("\236", '&#731;', $string);
c37a12f8 1680 $string = str_replace ("\250", '&#216;', $string);
c37a12f8 1681 $string = str_replace ("\252", '&#342;', $string);
c37a12f8 1682 $string = str_replace ("\257", '&#198;', $string);
c37a12f8 1683 $string = str_replace ("\270", '&#248;', $string);
c37a12f8 1684 $string = str_replace ("\272", '&#343;', $string);
c37a12f8 1685 $string = str_replace ("\277", '&#230;', $string);
c37a12f8 1686 $string = str_replace ("\300", '&#260;', $string);
c37a12f8 1687 $string = str_replace ("\301", '&#302;', $string);
c37a12f8 1688 $string = str_replace ("\302", '&#256;', $string);
c37a12f8 1689 $string = str_replace ("\303", '&#262;', $string);
c37a12f8 1690 $string = str_replace ("\306", '&#280;', $string);
c37a12f8 1691 $string = str_replace ("\307", '&#274;', $string);
c37a12f8 1692 $string = str_replace ("\310", '&#268;', $string);
c37a12f8 1693 $string = str_replace ("\312", '&#377;', $string);
c37a12f8 1694 $string = str_replace ("\313", '&#278;', $string);
c37a12f8 1695 $string = str_replace ("\314", '&#290;', $string);
c37a12f8 1696 $string = str_replace ("\315", '&#310;', $string);
c37a12f8 1697 $string = str_replace ("\316", '&#298;', $string);
c37a12f8 1698 $string = str_replace ("\317", '&#315;', $string);
c37a12f8 1699 $string = str_replace ("\320", '&#352;', $string);
c37a12f8 1700 $string = str_replace ("\321", '&#323;', $string);
c37a12f8 1701 $string = str_replace ("\322", '&#325;', $string);
c37a12f8 1702 $string = str_replace ("\324", '&#332;', $string);
c37a12f8 1703 $string = str_replace ("\330", '&#370;', $string);
c37a12f8 1704 $string = str_replace ("\331", '&#321;', $string);
c37a12f8 1705 $string = str_replace ("\332", '&#340;', $string);
c37a12f8 1706 $string = str_replace ("\333", '&#362;', $string);
c37a12f8 1707 $string = str_replace ("\335", '&#379;', $string);
c37a12f8 1708 $string = str_replace ("\336", '&#381;', $string);
c37a12f8 1709 $string = str_replace ("\340", '&#261;', $string);
c37a12f8 1710 $string = str_replace ("\341", '&#303;', $string);
c37a12f8 1711 $string = str_replace ("\342", '&#257;', $string);
c37a12f8 1712 $string = str_replace ("\343", '&#263;', $string);
c37a12f8 1713 $string = str_replace ("\346", '&#281;', $string);
c37a12f8 1714 $string = str_replace ("\347", '&#275;', $string);
c37a12f8 1715 $string = str_replace ("\350", '&#269;', $string);
c37a12f8 1716 $string = str_replace ("\352", '&#378;', $string);
c37a12f8 1717 $string = str_replace ("\353", '&#279;', $string);
c37a12f8 1718 $string = str_replace ("\354", '&#291;', $string);
c37a12f8 1719 $string = str_replace ("\355", '&#311;', $string);
c37a12f8 1720 $string = str_replace ("\356", '&#299;', $string);
c37a12f8 1721 $string = str_replace ("\357", '&#316;', $string);
c37a12f8 1722 $string = str_replace ("\360", '&#353;', $string);
c37a12f8 1723 $string = str_replace ("\361", '&#324;', $string);
c37a12f8 1724 $string = str_replace ("\362", '&#326;', $string);
c37a12f8 1725 $string = str_replace ("\364", '&#333;', $string);
c37a12f8 1726 $string = str_replace ("\370", '&#371;', $string);
c37a12f8 1727 $string = str_replace ("\371", '&#322;', $string);
c37a12f8 1728 $string = str_replace ("\372", '&#347;', $string);
c37a12f8 1729 $string = str_replace ("\373", '&#363;', $string);
c37a12f8 1730 $string = str_replace ("\375", '&#380;', $string);
c37a12f8 1731 $string = str_replace ("\376", '&#382;', $string);
c37a12f8 1732 $string = str_replace ("\377", '&#729;', $string);
1733
1734 // Rest of charset is like iso-8859-1
1735 return (charset_decode_iso_8859_1($string));
1736}
1737
6fbd125b 1738
a2a7852b 1739/*
1740 * Set up the language to be output
1741 * if $do_search is true, then scan the browser information
1742 * for a possible language that we know
1743 */
1744function set_up_language($sm_language, $do_search = false) {
1745
1746 static $SetupAlready = 0;
9eb0fbd4 1747 global $use_gettext, $languages,
a2a7852b 1748 $squirrelmail_language, $squirrelmail_default_language,
1749 $sm_notAlias;
1750
1751 if ($SetupAlready) {
1752 return;
1753 }
a65846a7 1754
5c920668 1755 $SetupAlready = TRUE;
961ca3d8 1756 sqgetGlobalVar('HTTP_ACCEPT_LANGUAGE', $accept_lang, SQ_SERVER);
a2a7852b 1757
961ca3d8 1758 if ($do_search && ! $sm_language && isset($accept_lang)) {
1759 $sm_language = substr($accept_lang, 0, 2);
a2a7852b 1760 }
66d7950f 1761
a2a7852b 1762 if (!$sm_language && isset($squirrelmail_default_language)) {
1763 $squirrelmail_language = $squirrelmail_default_language;
66d7950f 1764 $sm_language = $squirrelmail_default_language;
a2a7852b 1765 }
1766 $sm_notAlias = $sm_language;
1767 while (isset($languages[$sm_notAlias]['ALIAS'])) {
1768 $sm_notAlias = $languages[$sm_notAlias]['ALIAS'];
1769 }
1770
88cb1b4d 1771 if ( isset($sm_language) &&
5c920668 1772 $use_gettext &&
1773 $sm_language != '' &&
1774 isset($languages[$sm_notAlias]['CHARSET']) ) {
a65846a7 1775 bindtextdomain( 'squirrelmail', SM_PATH . 'locale/' );
88cb1b4d 1776 textdomain( 'squirrelmail' );
7928848f 1777 if (function_exists('bind_textdomain_codeset')) {
1778 bind_textdomain_codeset ("squirrelmail", $languages[$sm_notAlias]['CHARSET'] );
1779 }
88cb1b4d 1780 if ( !ini_get('safe_mode') &&
5c920668 1781 getenv( 'LC_ALL' ) != $sm_notAlias ) {
1782 putenv( "LC_ALL=$sm_notAlias" );
1783 putenv( "LANG=$sm_notAlias" );
1784 putenv( "LANGUAGE=$sm_notAlias" );
a2a7852b 1785 }
88cb1b4d 1786 setlocale(LC_ALL, $sm_notAlias);
5c920668 1787 $squirrelmail_language = $sm_notAlias;
538f1ab7 1788 if ($squirrelmail_language == 'ja_JP' && function_exists('mb_detect_encoding') ) {
b05c8961 1789 header ('Content-Type: text/html; charset=EUC-JP');
1790 if (!function_exists('mb_internal_encoding')) {
e842b215 1791 echo _("You need to have php4 installed with the multibyte string function enabled (using configure option --enable-mbstring).");
1792 }
1793 if (function_exists('mb_language')) {
1794 mb_language('Japanese');
b05c8961 1795 }
1796 mb_internal_encoding('EUC-JP');
1797 mb_http_output('pass');
1798 } else {
5c920668 1799 header( 'Content-Type: text/html; charset=' . $languages[$sm_notAlias]['CHARSET'] );
a2a7852b 1800 }
1801}
b05c8961 1802}
a2a7852b 1803
1804function set_my_charset(){
1805
1806 /*
1807 * There can be a $default_charset setting in the
1808 * config.php file, but the user may have a different language
1809 * selected for a user interface. This function checks the
1810 * language selected by the user and tags the outgoing messages
1811 * with the appropriate charset corresponding to the language
1812 * selection. This is "more right" (tm), than just stamping the
1813 * message blindly with the system-wide $default_charset.
1814 */
94965562 1815 global $data_dir, $username, $default_charset, $languages, $squirrelmail_default_language;
88cb1b4d 1816
a2a7852b 1817 $my_language = getPref($data_dir, $username, 'language');
5c920668 1818 if (!$my_language) {
94965562 1819 $my_language = $squirrelmail_default_language ;
5c920668 1820 }
a2a7852b 1821 while (isset($languages[$my_language]['ALIAS'])) {
f7e8861e 1822 $my_language = $languages[$my_language]['ALIAS'];
a2a7852b 1823 }
5c920668 1824 $my_charset = $languages[$my_language]['CHARSET'];
a2a7852b 1825 if ($my_charset) {
1826 $default_charset = $my_charset;
1827 }
1828}
1829
a2a7852b 1830/* ------------------------------ main --------------------------- */
1831
5c920668 1832global $squirrelmail_language, $languages, $use_gettext;
1833
a2a7852b 1834if (! isset($squirrelmail_language)) {
1835 $squirrelmail_language = '';
1836}
1837
1838/* This array specifies the available languages. */
5c920668 1839
1840// The glibc locale is ca_ES.
1841
1842$languages['ca_ES']['NAME'] = 'Catalan';
1843$languages['ca_ES']['CHARSET'] = 'iso-8859-1';
1844$languages['ca']['ALIAS'] = 'ca_ES';
1845
a2a7852b 1846$languages['cs_CZ']['NAME'] = 'Czech';
1847$languages['cs_CZ']['CHARSET'] = 'iso-8859-2';
1848$languages['cs']['ALIAS'] = 'cs_CZ';
a2a7852b 1849
5c920668 1850// Danish locale is da_DK.
1851
1852$languages['da_DK']['NAME'] = 'Danish';
1853$languages['da_DK']['CHARSET'] = 'iso-8859-1';
1854$languages['da']['ALIAS'] = 'da_DK';
1855
1856$languages['de_DE']['NAME'] = 'Deutsch';
1857$languages['de_DE']['CHARSET'] = 'iso-8859-1';
1858$languages['de']['ALIAS'] = 'de_DE';
a2a7852b 1859
5c920668 1860// There is no en_EN! There is en_US, en_BR, en_AU, and so forth,
1861// but who cares about !US, right? Right? :)
a2a7852b 1862
3ab35042 1863$languages['el_GR']['NAME'] = 'Greek';
1864$languages['el_GR']['CHARSET'] = 'iso-8859-7';
1865$languages['el']['ALIAS'] = 'el_GR';
1866
5c920668 1867$languages['en_US']['NAME'] = 'English';
1868$languages['en_US']['CHARSET'] = 'iso-8859-1';
1869$languages['en']['ALIAS'] = 'en_US';
a2a7852b 1870
5c920668 1871$languages['es_ES']['NAME'] = 'Spanish';
1872$languages['es_ES']['CHARSET'] = 'iso-8859-1';
1873$languages['es']['ALIAS'] = 'es_ES';
a2a7852b 1874
5c920668 1875$languages['et_EE']['NAME'] = 'Estonian';
1876$languages['et_EE']['CHARSET'] = 'iso-8859-15';
1877$languages['et']['ALIAS'] = 'et_EE';
a2a7852b 1878
1ad5ab3a 1879$languages['fo_FO']['NAME'] = 'Faroese';
1880$languages['fo_FO']['CHARSET'] = 'iso-8859-1';
1881$languages['fo']['ALIAS'] = 'fo_FO';
1882
5c920668 1883$languages['fi_FI']['NAME'] = 'Finnish';
1884$languages['fi_FI']['CHARSET'] = 'iso-8859-1';
1885$languages['fi']['ALIAS'] = 'fi_FI';
a2a7852b 1886
5c920668 1887$languages['fr_FR']['NAME'] = 'French';
1888$languages['fr_FR']['CHARSET'] = 'iso-8859-1';
1889$languages['fr']['ALIAS'] = 'fr_FR';
a2a7852b 1890
5c920668 1891$languages['hr_HR']['NAME'] = 'Croatian';
1892$languages['hr_HR']['CHARSET'] = 'iso-8859-2';
1893$languages['hr']['ALIAS'] = 'hr_HR';
a2a7852b 1894
5c920668 1895$languages['hu_HU']['NAME'] = 'Hungarian';
1896$languages['hu_HU']['CHARSET'] = 'iso-8859-2';
1897$languages['hu']['ALIAS'] = 'hu_HU';
a2a7852b 1898
d90198d0 1899$languages['id_ID']['NAME'] = 'Bahasa Indonesia';
5c920668 1900$languages['id_ID']['CHARSET'] = 'iso-8859-1';
1901$languages['id']['ALIAS'] = 'id_ID';
a2a7852b 1902
5c920668 1903$languages['is_IS']['NAME'] = 'Icelandic';
1904$languages['is_IS']['CHARSET'] = 'iso-8859-1';
1905$languages['is']['ALIAS'] = 'is_IS';
a2a7852b 1906
5c920668 1907$languages['it_IT']['NAME'] = 'Italian';
1908$languages['it_IT']['CHARSET'] = 'iso-8859-1';
1909$languages['it']['ALIAS'] = 'it_IT';
a2a7852b 1910
b05c8961 1911$languages['ja_JP']['NAME'] = 'Japanese';
1912$languages['ja_JP']['CHARSET'] = 'iso-2022-jp';
6fbd125b 1913$languages['ja_JP']['XTRA_CODE'] = 'japanese_charset_xtra';
b05c8961 1914$languages['ja']['ALIAS'] = 'ja_JP';
1915
5c920668 1916$languages['ko_KR']['NAME'] = 'Korean';
1917$languages['ko_KR']['CHARSET'] = 'euc-KR';
1d33e35e 1918$languages['ko_KR']['XTRA_CODE'] = 'korean_charset_xtra';
5c920668 1919$languages['ko']['ALIAS'] = 'ko_KR';
a2a7852b 1920
5c920668 1921$languages['nl_NL']['NAME'] = 'Dutch';
1922$languages['nl_NL']['CHARSET'] = 'iso-8859-1';
1923$languages['nl']['ALIAS'] = 'nl_NL';
a2a7852b 1924
5c920668 1925$languages['no_NO']['NAME'] = 'Norwegian (Bokm&aring;l)';
1926$languages['no_NO']['CHARSET'] = 'iso-8859-1';
1927$languages['no']['ALIAS'] = 'no_NO';
b8b4ac4a 1928$languages['nn_NO']['NAME'] = 'Norwegian (Nynorsk)';
1929$languages['nn_NO']['CHARSET'] = 'iso-8859-1';
a2a7852b 1930
5c920668 1931$languages['pl_PL']['NAME'] = 'Polish';
1932$languages['pl_PL']['CHARSET'] = 'iso-8859-2';
1933$languages['pl']['ALIAS'] = 'pl_PL';
a2a7852b 1934
5c920668 1935$languages['pt_PT']['NAME'] = 'Portuguese (Portugal)';
1936$languages['pt_PT']['CHARSET'] = 'iso-8859-1';
a2a7852b 1937$languages['pt_BR']['NAME'] = 'Portuguese (Brazil)';
1938$languages['pt_BR']['CHARSET'] = 'iso-8859-1';
5c920668 1939$languages['pt']['ALIAS'] = 'pt_PT';
a2a7852b 1940
5c920668 1941$languages['ru_RU']['NAME'] = 'Russian';
1942$languages['ru_RU']['CHARSET'] = 'koi8-r';
1943$languages['ru']['ALIAS'] = 'ru_RU';
a2a7852b 1944
dbec0d67 1945$languages['sr_YU']['NAME'] = 'Serbian';
1946$languages['sr_YU']['CHARSET'] = 'iso-8859-2';
1947$languages['sr']['ALIAS'] = 'sr_YU';
a2a7852b 1948
5c920668 1949$languages['sv_SE']['NAME'] = 'Swedish';
1950$languages['sv_SE']['CHARSET'] = 'iso-8859-1';
1951$languages['sv']['ALIAS'] = 'sv_SE';
a2a7852b 1952
5c920668 1953$languages['tr_TR']['NAME'] = 'Turkish';
1954$languages['tr_TR']['CHARSET'] = 'iso-8859-9';
1955$languages['tr']['ALIAS'] = 'tr_TR';
a2a7852b 1956
b62c1863 1957$languages['zh_TW']['NAME'] = 'Chinese Trad';
5c920668 1958$languages['zh_TW']['CHARSET'] = 'big5';
1959$languages['tw']['ALIAS'] = 'zh_TW';
a2a7852b 1960
b62c1863 1961$languages['zh_CN']['NAME'] = 'Chinese Simp';
1962$languages['zh_CN']['CHARSET'] = 'gb2312';
1963$languages['cn']['ALIAS'] = 'zh_CN';
8ba79a3b 1964
a2a7852b 1965$languages['sk_SK']['NAME'] = 'Slovak';
1966$languages['sk_SK']['CHARSET'] = 'iso-8859-2';
1967$languages['sk']['ALIAS'] = 'sk_SK';
1968
5c920668 1969$languages['ro_RO']['NAME'] = 'Romanian';
1970$languages['ro_RO']['CHARSET'] = 'iso-8859-2';
1971$languages['ro']['ALIAS'] = 'ro_RO';
a2a7852b 1972
5c920668 1973$languages['th_TH']['NAME'] = 'Thai';
1974$languages['th_TH']['CHARSET'] = 'tis-620';
1975$languages['th']['ALIAS'] = 'th_TH';
a2a7852b 1976
5c920668 1977$languages['lt_LT']['NAME'] = 'Lithuanian';
923229f2 1978$languages['lt_LT']['CHARSET'] = 'windows-1257';
5c920668 1979$languages['lt']['ALIAS'] = 'lt_LT';
a2a7852b 1980
5c920668 1981$languages['sl_SI']['NAME'] = 'Slovenian';
1982$languages['sl_SI']['CHARSET'] = 'iso-8859-2';
1983$languages['sl']['ALIAS'] = 'sl_SI';
a2a7852b 1984
5c920668 1985$languages['bg_BG']['NAME'] = 'Bulgarian';
1986$languages['bg_BG']['CHARSET'] = 'windows-1251';
1987$languages['bg']['ALIAS'] = 'bg_BG';
a2a7852b 1988
93ea3e70 1989$languages['uk_UA']['NAME'] = 'Ukrainian';
1990$languages['uk_UA']['CHARSET'] = 'koi8-u';
1991$languages['uk']['ALIAS'] = 'uk_UA';
1992
969a0af6 1993$languages['cy_GB']['NAME'] = 'Welsh';
1994$languages['cy_GB']['CHARSET'] = 'iso-8859-1';
1995$languages['cy']['ALIAS'] = 'cy_GB';
b7617386 1996
d90198d0 1997$languages['vi_VN']['NAME'] = 'Vietnamese';
1998$languages['vi_VN']['CHARSET'] = 'utf-8';
1999$languages['vi']['ALIAS'] = 'vi_VN';
b7617386 2000
d3b57948 2001// Right to left languages
2002
7e3f5be8 2003$languages['ar']['NAME'] = 'Arabic';
2004$languages['ar']['CHARSET'] = 'windows-1256';
2005$languages['ar']['DIR'] = 'rtl';
2006
ace72c6a 2007$languages['he_IL']['NAME'] = 'Hebrew';
2008$languages['he_IL']['CHARSET'] = 'windows-1255';
2009$languages['he_IL']['DIR'] = 'rtl';
2010$languages['he']['ALIAS'] = 'he_IL';
d3b57948 2011
5c920668 2012/* Detect whether gettext is installed. */
a2a7852b 2013$gettext_flags = 0;
2014if (function_exists('_')) {
2015 $gettext_flags += 1;
2016}
2017if (function_exists('bindtextdomain')) {
2018 $gettext_flags += 2;
2019}
2020if (function_exists('textdomain')) {
2021 $gettext_flags += 4;
2022}
2023
5c920668 2024/* If gettext is fully loaded, cool */
a2a7852b 2025if ($gettext_flags == 7) {
2026 $use_gettext = true;
2027}
5c920668 2028/* If we can fake gettext, try that */
a2a7852b 2029elseif ($gettext_flags == 0) {
2030 $use_gettext = true;
e7ab8c9d 2031 include_once(SM_PATH . 'functions/gettext.php');
a2a7852b 2032} else {
5c920668 2033 /* Uh-ho. A weird install */
a2a7852b 2034 if (! $gettext_flags & 1) {
2035 function _($str) {
2036 return $str;
2037 }
2038 }
2039 if (! $gettext_flags & 2) {
2040 function bindtextdomain() {
2041 return;
2042 }
2043 }
2044 if (! $gettext_flags & 4) {
2045 function textdomain() {
2046 return;
2047 }
2048 }
2049}
2050
3ab35042 2051function charset_decode_utf8 ($string) {
2052/*
2053 Every decoded character consists of n bytes. First byte is octal
2054 300-375, other bytes - always octals 200-277.
2055
2056 \a\b characters are decoded to html code octdec(a-300)*64 + octdec(b-200)
2057 \a\b\c characters are decoded to html code octdec(a-340)*64*64 + octdec(b-200)*64 + octdec(c-200)
2058
2059 decoding cycle is unfinished. please test and report problems to tokul@users.sourceforge.net
2060*/
2061 global $default_charset, $languages, $sm_notAlias;
2062
2063 if (strtolower($default_charset) == 'utf-8')
2064 return $string;
2065 if (strtolower($languages[$sm_notAlias]['CHARSET']) == 'utf-8')
2066 return $string;
2067
2068 /* Only do the slow convert if there are 8-bit characters */
2069 if (! ereg("[\200-\377]", $string))
2070 return $string;
2071
2072 // decode three byte unicode characters
2073 $string = preg_replace("/([\340-\357])([\200-\277])([\200-\277])/e",
2074 "'&#'.((ord('\\1')-224)*4096+(ord('\\2')-128)*64+(ord('\\3')-128)).';'",
2075 $string);
2076
2077 // decode two byte unicode characters
2078 $string = preg_replace("/([\300-\337])([\200-\277])/e",
2079 "'&#'.((ord('\\1')-192)*64+(ord('\\2')-128)).';'",
2080 $string);
2081
2082 return $string;
2083}
1d33e35e 2084
2085/*
2086 * Japanese charset extra function
2087 *
2088 */
2089function japanese_charset_xtra() {
2090 $ret = func_get_arg(1); /* default return value */
2091 if (function_exists('mb_detect_encoding')) {
2092 switch (func_get_arg(0)) { /* action */
2093 case 'decode':
e842b215 2094 $detect_encoding = @mb_detect_encoding($ret);
1d33e35e 2095 if ($detect_encoding == 'JIS' ||
2096 $detect_encoding == 'EUC-JP' ||
e842b215 2097 $detect_encoding == 'SJIS' ||
2098 $detect_encoding == 'UTF-8') {
1d33e35e 2099
e842b215 2100 $ret = mb_convert_kana(mb_convert_encoding($ret, 'EUC-JP', 'AUTO'), "KV");
1d33e35e 2101 }
2102 break;
2103 case 'encode':
e842b215 2104 $detect_encoding = @mb_detect_encoding($ret);
1d33e35e 2105 if ($detect_encoding == 'JIS' ||
2106 $detect_encoding == 'EUC-JP' ||
e842b215 2107 $detect_encoding == 'SJIS' ||
2108 $detect_encoding == 'UTF-8') {
1d33e35e 2109
e842b215 2110 $ret = mb_convert_encoding(mb_convert_kana($ret, "KV"), 'JIS', 'AUTO');
1d33e35e 2111 }
2112 break;
2113 case 'strimwidth':
2114 $width = func_get_arg(2);
2115 $ret = mb_strimwidth($ret, 0, $width, '...');
2116 break;
2117 case 'encodeheader':
8ba05cbe 2118 $result = '';
2119 if (strlen($ret) > 0) {
2120 $tmpstr = mb_substr($ret, 0, 1);
2121 $prevcsize = strlen($tmpstr);
2122 for ($i = 1; $i < mb_strlen($ret); $i++) {
2123 $tmp = mb_substr($ret, $i, 1);
2124 if (strlen($tmp) == $prevcsize) {
2125 $tmpstr .= $tmp;
2126 } else {
2127 if ($prevcsize == 1) {
2128 $result .= $tmpstr;
2129 } else {
e842b215 2130 $result .= str_replace(' ', '',
2131 mb_encode_mimeheader($tmpstr,'iso-2022-jp','B',''));
8ba05cbe 2132 }
2133 $tmpstr = $tmp;
2134 $prevcsize = strlen($tmp);
2135 }
2136 }
2137 if (strlen($tmpstr)) {
2138 if (strlen(mb_substr($tmpstr, 0, 1)) == 1)
2139 $result .= $tmpstr;
2140 else
e842b215 2141 $result .= str_replace(' ', '',
2142 mb_encode_mimeheader($tmpstr,'iso-2022-jp','B',''));
8ba05cbe 2143 }
2144 }
2145 $ret = $result;
1d33e35e 2146 break;
2147 case 'decodeheader':
2148 $ret = str_replace("\t", "", $ret);
2149 if (eregi('=\\?([^?]+)\\?(q|b)\\?([^?]+)\\?=', $ret))
e842b215 2150 $ret = @mb_decode_mimeheader($ret);
2151 $ret = @mb_convert_encoding($ret, 'EUC-JP', 'AUTO');
1d33e35e 2152 break;
2153 case 'downloadfilename':
2154 $useragent = func_get_arg(2);
2155 if (strstr($useragent, 'Windows') !== false ||
2156 strstr($useragent, 'Mac_') !== false) {
2157 $ret = mb_convert_encoding($ret, 'SJIS', 'AUTO');
2158 } else {
2159 $ret = mb_convert_encoding($ret, 'EUC-JP', 'AUTO');
2160}
2161 break;
e842b215 2162 case 'wordwrap':
2163 $no_begin = "\x21\x25\x29\x2c\x2e\x3a\x3b\x3f\x5d\x7d\xa1\xf1\xa1\xeb\xa1" .
2164 "\xc7\xa1\xc9\xa2\xf3\xa1\xec\xa1\xed\xa1\xee\xa1\xa2\xa1\xa3\xa1\xb9" .
2165 "\xa1\xd3\xa1\xd5\xa1\xd7\xa1\xd9\xa1\xdb\xa1\xcd\xa4\xa1\xa4\xa3\xa4" .
2166 "\xa5\xa4\xa7\xa4\xa9\xa4\xc3\xa4\xe3\xa4\xe5\xa4\xe7\xa4\xee\xa1\xab" .
2167 "\xa1\xac\xa1\xb5\xa1\xb6\xa5\xa1\xa5\xa3\xa5\xa5\xa5\xa7\xa5\xa9\xa5" .
2168 "\xc3\xa5\xe3\xa5\xe5\xa5\xe7\xa5\xee\xa5\xf5\xa5\xf6\xa1\xa6\xa1\xbc" .
2169 "\xa1\xb3\xa1\xb4\xa1\xaa\xa1\xf3\xa1\xcb\xa1\xa4\xa1\xa5\xa1\xa7\xa1" .
2170 "\xa8\xa1\xa9\xa1\xcf\xa1\xd1";
2171 $no_end = "\x5c\x24\x28\x5b\x7b\xa1\xf2\x5c\xa1\xc6\xa1\xc8\xa1\xd2\xa1" .
2172 "\xd4\xa1\xd6\xa1\xd8\xa1\xda\xa1\xcc\xa1\xf0\xa1\xca\xa1\xce\xa1\xd0\xa1\xef";
2173 $wrap = func_get_arg(2);
2174
2175 if (strlen($ret) >= $wrap &&
2176 substr($ret, 0, 1) != '>' &&
2177 strpos($ret, 'http://') === FALSE &&
2178 strpos($ret, 'https://') === FALSE &&
2179 strpos($ret, 'ftp://') === FALSE) {
2180
2181 $ret = mb_convert_kana($ret, "KV");
2182
2183 $line_new = '';
2184 $ptr = 0;
2185
2186 while ($ptr < strlen($ret) - 1) {
2187 $l = mb_strcut($ret, $ptr, $wrap);
2188 $ptr += strlen($l);
2189 $tmp = $l;
2190
2191 $l = mb_strcut($ret, $ptr, 2);
2192 while (strlen($l) != 0 && mb_strpos($no_begin, $l) !== FALSE ) {
2193 $tmp .= $l;
2194 $ptr += strlen($l);
2195 $l = mb_strcut($ret, $ptr, 1);
2196 }
2197 $line_new .= $tmp;
2198 if ($ptr < strlen($ret) - 1)
2199 $line_new .= "\n";
2200 }
2201 $ret = $line_new;
2202 }
2203 break;
2204 case 'utf7-imap_encode':
2205 $ret = mb_convert_encoding($ret, 'UTF7-IMAP', 'EUC-JP');
2206 break;
2207 case 'utf7-imap_decode':
2208 $ret = mb_convert_encoding($ret, 'EUC-JP', 'UTF7-IMAP');
2209 break;
1d33e35e 2210 }
2211 }
2212 return $ret;
2213}
2214
2215
2216/*
2217 * Korean charset extra function
2218 * Hangul(Korean Character) Attached File Name Fix.
2219 */
2220function korean_charset_xtra() {
2221
2222 $ret = func_get_arg(1); /* default return value */
2223 if (func_get_arg(0) == 'downloadfilename') { /* action */
2224 $ret = str_replace("\x0D\x0A", '', $ret); /* Hanmail's CR/LF Clear */
2225 for ($i=0;$i<strlen($ret);$i++) {
2226 if ($ret[$i] >= "\xA1" && $ret[$i] <= "\xFE") { /* 0xA1 - 0XFE are Valid */
2227 $i++;
2228 continue;
2229 } else if (($ret[$i] >= 'a' && $ret[$i] <= 'z') || /* From Original ereg_replace in download.php */
2230 ($ret[$i] >= 'A' && $ret[$i] <= 'Z') ||
2231 ($ret[$i] == '.') || ($ret[$i] == '-')) {
2232 continue;
2233 } else {
2234 $ret[$i] = '_';
2235 }
2236 }
2237
2238 }
2239
2240 return $ret;
2241}
2242
e842b215 2243?>