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