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