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