Remerged strings
[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
a2a7852b 18/* Decodes a string to the internal encoding from the given charset */
19function charset_decode ($charset, $string) {
6fbd125b 20 global $languages, $squirrelmail_language;
a2a7852b 21
3714db45 22 if (isset($languages[$squirrelmail_language]['XTRA_CODE']) &&
23 function_exists($languages[$squirrelmail_language]['XTRA_CODE'])) {
6fbd125b 24 $string = $languages[$squirrelmail_language]['XTRA_CODE']('decode', $string);
25 }
b05c8961 26
a2a7852b 27 /* All HTML special characters are 7 bit and can be replaced first */
28 $string = htmlspecialchars ($string);
29
30 $charset = strtolower($charset);
31
a2a7852b 32 if (ereg('iso-8859-([[:digit:]]+)', $charset, $res)) {
33 if ($res[1] == '1') {
34 $ret = charset_decode_iso_8859_1 ($string);
35 } else if ($res[1] == '2') {
36 $ret = charset_decode_iso_8859_2 ($string);
9be313d5 37 } else if ($res[1] == '4') {
38 $ret = charset_decode_iso_8859_4 ($string);
a2a7852b 39 } else if ($res[1] == '7') {
40 $ret = charset_decode_iso_8859_7 ($string);
9be313d5 41 } else if ($res[1] == '13') {
42 $ret = charset_decode_iso_8859_13 ($string);
a2a7852b 43 } else if ($res[1] == '15') {
44 $ret = charset_decode_iso_8859_15 ($string);
45 } else {
46 $ret = charset_decode_iso_8859_default ($string);
47 }
48 } else if ($charset == 'ns_4551-1') {
49 $ret = charset_decode_ns_4551_1 ($string);
50 } else if ($charset == 'koi8-r') {
51 $ret = charset_decode_koi8r ($string);
52 } else if ($charset == 'windows-1251') {
ecd877a8 53 $ret = charset_decode_windows_1251 ($string);
c37a12f8 54 } else if ($charset == 'windows-1257') {
55 $ret = charset_decode_windows_1257 ($string);
a2a7852b 56 } else {
57 $ret = $string;
58 }
59 return( $ret );
60}
61
62/*
63 iso-8859-1 is the same as Latin 1 and is normally used
64 in western europe.
65 */
66function charset_decode_iso_8859_1 ($string) {
67 global $default_charset;
13e0c649 68
a2a7852b 69 if (strtolower($default_charset) <> 'iso-8859-1') {
70 /* Only do the slow convert if there are 8-bit characters */
71 if (ereg("[\200-\377]", $string)) {
066c374f 72 $string = str_replace("\201", '&#129;', $string);
73 $string = str_replace("\202", '&#130;', $string);
74 $string = str_replace("\203", '&#131;', $string);
75 $string = str_replace("\204", '&#132;', $string);
76 $string = str_replace("\205", '&#133;', $string);
77 $string = str_replace("\206", '&#134;', $string);
78 $string = str_replace("\207", '&#135;', $string);
79 $string = str_replace("\210", '&#136;', $string);
80 $string = str_replace("\211", '&#137;', $string);
81 $string = str_replace("\212", '&#138;', $string);
82 $string = str_replace("\213", '&#139;', $string);
83 $string = str_replace("\214", '&#140;', $string);
84 $string = str_replace("\215", '&#141;', $string);
85 $string = str_replace("\216", '&#142;', $string);
86 $string = str_replace("\217", '&#143;', $string);
87 $string = str_replace("\220", '&#144;', $string);
88 $string = str_replace("\221", '&#145;', $string);
89 $string = str_replace("\222", '&#146;', $string);
90 $string = str_replace("\223", '&#147;', $string);
91 $string = str_replace("\224", '&#148;', $string);
92 $string = str_replace("\225", '&#149;', $string);
93 $string = str_replace("\226", '&#150;', $string);
94 $string = str_replace("\227", '&#151;', $string);
95 $string = str_replace("\230", '&#152;', $string);
96 $string = str_replace("\231", '&#153;', $string);
97 $string = str_replace("\232", '&#154;', $string);
98 $string = str_replace("\233", '&#155;', $string);
99 $string = str_replace("\234", '&#156;', $string);
100 $string = str_replace("\235", '&#157;', $string);
101 $string = str_replace("\236", '&#158;', $string);
102 $string = str_replace("\237", '&#159;', $string);
103 $string = str_replace("\240", '&#160;', $string);
104 $string = str_replace("\241", '&#161;', $string);
105 $string = str_replace("\242", '&#162;', $string);
106 $string = str_replace("\243", '&#163;', $string);
107 $string = str_replace("\244", '&#164;', $string);
108 $string = str_replace("\245", '&#165;', $string);
109 $string = str_replace("\246", '&#166;', $string);
110 $string = str_replace("\247", '&#167;', $string);
111 $string = str_replace("\250", '&#168;', $string);
112 $string = str_replace("\251", '&#169;', $string);
113 $string = str_replace("\252", '&#170;', $string);
114 $string = str_replace("\253", '&#171;', $string);
115 $string = str_replace("\254", '&#172;', $string);
116 $string = str_replace("\255", '&#173;', $string);
117 $string = str_replace("\256", '&#174;', $string);
118 $string = str_replace("\257", '&#175;', $string);
119 $string = str_replace("\260", '&#176;', $string);
120 $string = str_replace("\261", '&#177;', $string);
121 $string = str_replace("\262", '&#178;', $string);
122 $string = str_replace("\263", '&#179;', $string);
123 $string = str_replace("\264", '&#180;', $string);
124 $string = str_replace("\265", '&#181;', $string);
125 $string = str_replace("\266", '&#182;', $string);
126 $string = str_replace("\267", '&#183;', $string);
127 $string = str_replace("\270", '&#184;', $string);
128 $string = str_replace("\271", '&#185;', $string);
129 $string = str_replace("\272", '&#186;', $string);
130 $string = str_replace("\273", '&#187;', $string);
131 $string = str_replace("\274", '&#188;', $string);
132 $string = str_replace("\275", '&#189;', $string);
133 $string = str_replace("\276", '&#190;', $string);
134 $string = str_replace("\277", '&#191;', $string);
135 $string = str_replace("\300", '&#192;', $string);
136 $string = str_replace("\301", '&#193;', $string);
137 $string = str_replace("\302", '&#194;', $string);
138 $string = str_replace("\303", '&#195;', $string);
139 $string = str_replace("\304", '&#196;', $string);
140 $string = str_replace("\305", '&#197;', $string);
141 $string = str_replace("\306", '&#198;', $string);
142 $string = str_replace("\307", '&#199;', $string);
143 $string = str_replace("\310", '&#200;', $string);
144 $string = str_replace("\311", '&#201;', $string);
145 $string = str_replace("\312", '&#202;', $string);
146 $string = str_replace("\313", '&#203;', $string);
147 $string = str_replace("\314", '&#204;', $string);
148 $string = str_replace("\315", '&#205;', $string);
149 $string = str_replace("\316", '&#206;', $string);
150 $string = str_replace("\317", '&#207;', $string);
151 $string = str_replace("\320", '&#208;', $string);
152 $string = str_replace("\321", '&#209;', $string);
153 $string = str_replace("\322", '&#210;', $string);
154 $string = str_replace("\323", '&#211;', $string);
155 $string = str_replace("\324", '&#212;', $string);
156 $string = str_replace("\325", '&#213;', $string);
157 $string = str_replace("\326", '&#214;', $string);
158 $string = str_replace("\327", '&#215;', $string);
159 $string = str_replace("\330", '&#216;', $string);
160 $string = str_replace("\331", '&#217;', $string);
161 $string = str_replace("\332", '&#218;', $string);
162 $string = str_replace("\333", '&#219;', $string);
163 $string = str_replace("\334", '&#220;', $string);
164 $string = str_replace("\335", '&#221;', $string);
165 $string = str_replace("\336", '&#222;', $string);
166 $string = str_replace("\337", '&#223;', $string);
167 $string = str_replace("\340", '&#224;', $string);
168 $string = str_replace("\341", '&#225;', $string);
169 $string = str_replace("\342", '&#226;', $string);
170 $string = str_replace("\343", '&#227;', $string);
171 $string = str_replace("\344", '&#228;', $string);
172 $string = str_replace("\345", '&#229;', $string);
173 $string = str_replace("\346", '&#230;', $string);
174 $string = str_replace("\347", '&#231;', $string);
175 $string = str_replace("\350", '&#232;', $string);
176 $string = str_replace("\351", '&#233;', $string);
177 $string = str_replace("\352", '&#234;', $string);
178 $string = str_replace("\353", '&#235;', $string);
179 $string = str_replace("\354", '&#236;', $string);
180 $string = str_replace("\355", '&#237;', $string);
181 $string = str_replace("\356", '&#238;', $string);
182 $string = str_replace("\357", '&#239;', $string);
183 $string = str_replace("\360", '&#240;', $string);
184 $string = str_replace("\361", '&#241;', $string);
185 $string = str_replace("\362", '&#242;', $string);
186 $string = str_replace("\363", '&#243;', $string);
187 $string = str_replace("\364", '&#244;', $string);
188 $string = str_replace("\365", '&#245;', $string);
189 $string = str_replace("\366", '&#246;', $string);
190 $string = str_replace("\367", '&#247;', $string);
191 $string = str_replace("\370", '&#248;', $string);
192 $string = str_replace("\371", '&#249;', $string);
193 $string = str_replace("\372", '&#250;', $string);
194 $string = str_replace("\373", '&#251;', $string);
195 $string = str_replace("\374", '&#252;', $string);
196 $string = str_replace("\375", '&#253;', $string);
197 $string = str_replace("\376", '&#254;', $string);
198 $string = str_replace("\377", '&#255;', $string);
a2a7852b 199 }
200 }
201
202 return ($string);
203}
204
205/* iso-8859-2 is used for some eastern European languages */
206function charset_decode_iso_8859_2 ($string) {
207 global $default_charset;
208
209 if (strtolower($default_charset) == 'iso-8859-2')
210 return $string;
211
212 /* Only do the slow convert if there are 8-bit characters */
213 if (! ereg("[\200-\377]", $string))
214 return $string;
215
216 /* NO-BREAK SPACE */
217 $string = str_replace("\240", '&#160;', $string);
218 /* LATIN CAPITAL LETTER A WITH OGONEK */
219 $string = str_replace("\241", '&#260;', $string);
220 /* BREVE */
221 $string = str_replace("\242", '&#728;', $string);
222 // LATIN CAPITAL LETTER L WITH STROKE
223 $string = str_replace("\243", '&#321;', $string);
224 // CURRENCY SIGN
225 $string = str_replace("\244", '&#164;', $string);
226 // LATIN CAPITAL LETTER L WITH CARON
227 $string = str_replace("\245", '&#317;', $string);
228 // LATIN CAPITAL LETTER S WITH ACUTE
229 $string = str_replace("\246", '&#346;', $string);
230 // SECTION SIGN
231 $string = str_replace("\247", '&#167;', $string);
232 // DIAERESIS
233 $string = str_replace("\250", '&#168;', $string);
234 // LATIN CAPITAL LETTER S WITH CARON
235 $string = str_replace("\251", '&#352;', $string);
236 // LATIN CAPITAL LETTER S WITH CEDILLA
237 $string = str_replace("\252", '&#350;', $string);
238 // LATIN CAPITAL LETTER T WITH CARON
239 $string = str_replace("\253", '&#356;', $string);
240 // LATIN CAPITAL LETTER Z WITH ACUTE
241 $string = str_replace("\254", '&#377;', $string);
242 // SOFT HYPHEN
243 $string = str_replace("\255", '&#173;', $string);
244 // LATIN CAPITAL LETTER Z WITH CARON
245 $string = str_replace("\256", '&#381;', $string);
246 // LATIN CAPITAL LETTER Z WITH DOT ABOVE
247 $string = str_replace("\257", '&#379;', $string);
248 // DEGREE SIGN
249 $string = str_replace("\260", '&#176;', $string);
250 // LATIN SMALL LETTER A WITH OGONEK
251 $string = str_replace("\261", '&#261;', $string);
252 // OGONEK
253 $string = str_replace("\262", '&#731;', $string);
254 // LATIN SMALL LETTER L WITH STROKE
255 $string = str_replace("\263", '&#322;', $string);
256 // ACUTE ACCENT
257 $string = str_replace("\264", '&#180;', $string);
258 // LATIN SMALL LETTER L WITH CARON
259 $string = str_replace("\265", '&#318;', $string);
260 // LATIN SMALL LETTER S WITH ACUTE
261 $string = str_replace("\266", '&#347;', $string);
262 // CARON
263 $string = str_replace("\267", '&#711;', $string);
264 // CEDILLA
265 $string = str_replace("\270", '&#184;', $string);
266 // LATIN SMALL LETTER S WITH CARON
267 $string = str_replace("\271", '&#353;', $string);
268 // LATIN SMALL LETTER S WITH CEDILLA
269 $string = str_replace("\272", '&#351;', $string);
270 // LATIN SMALL LETTER T WITH CARON
271 $string = str_replace("\273", '&#357;', $string);
272 // LATIN SMALL LETTER Z WITH ACUTE
273 $string = str_replace("\274", '&#378;', $string);
274 // DOUBLE ACUTE ACCENT
275 $string = str_replace("\275", '&#733;', $string);
276 // LATIN SMALL LETTER Z WITH CARON
277 $string = str_replace("\276", '&#382;', $string);
278 // LATIN SMALL LETTER Z WITH DOT ABOVE
279 $string = str_replace("\277", '&#380;', $string);
280 // LATIN CAPITAL LETTER R WITH ACUTE
281 $string = str_replace("\300", '&#340;', $string);
282 // LATIN CAPITAL LETTER A WITH ACUTE
283 $string = str_replace("\301", '&#193;', $string);
284 // LATIN CAPITAL LETTER A WITH CIRCUMFLEX
285 $string = str_replace("\302", '&#194;', $string);
286 // LATIN CAPITAL LETTER A WITH BREVE
287 $string = str_replace("\303", '&#258;', $string);
288 // LATIN CAPITAL LETTER A WITH DIAERESIS
289 $string = str_replace("\304", '&#196;', $string);
290 // LATIN CAPITAL LETTER L WITH ACUTE
291 $string = str_replace("\305", '&#313;', $string);
292 // LATIN CAPITAL LETTER C WITH ACUTE
293 $string = str_replace("\306", '&#262;', $string);
294 // LATIN CAPITAL LETTER C WITH CEDILLA
295 $string = str_replace("\307", '&#199;', $string);
296 // LATIN CAPITAL LETTER C WITH CARON
297 $string = str_replace("\310", '&#268;', $string);
298 // LATIN CAPITAL LETTER E WITH ACUTE
299 $string = str_replace("\311", '&#201;', $string);
300 // LATIN CAPITAL LETTER E WITH OGONEK
301 $string = str_replace("\312", '&#280;', $string);
302 // LATIN CAPITAL LETTER E WITH DIAERESIS
303 $string = str_replace("\313", '&#203;', $string);
304 // LATIN CAPITAL LETTER E WITH CARON
305 $string = str_replace("\314", '&#282;', $string);
306 // LATIN CAPITAL LETTER I WITH ACUTE
307 $string = str_replace("\315", '&#205;', $string);
308 // LATIN CAPITAL LETTER I WITH CIRCUMFLEX
309 $string = str_replace("\316", '&#206;', $string);
310 // LATIN CAPITAL LETTER D WITH CARON
311 $string = str_replace("\317", '&#270;', $string);
312 // LATIN CAPITAL LETTER D WITH STROKE
313 $string = str_replace("\320", '&#272;', $string);
314 // LATIN CAPITAL LETTER N WITH ACUTE
315 $string = str_replace("\321", '&#323;', $string);
316 // LATIN CAPITAL LETTER N WITH CARON
317 $string = str_replace("\322", '&#327;', $string);
318 // LATIN CAPITAL LETTER O WITH ACUTE
319 $string = str_replace("\323", '&#211;', $string);
320 // LATIN CAPITAL LETTER O WITH CIRCUMFLEX
321 $string = str_replace("\324", '&#212;', $string);
322 // LATIN CAPITAL LETTER O WITH DOUBLE ACUTE
323 $string = str_replace("\325", '&#336;', $string);
324 // LATIN CAPITAL LETTER O WITH DIAERESIS
325 $string = str_replace("\326", '&#214;', $string);
326 // MULTIPLICATION SIGN
327 $string = str_replace("\327", '&#215;', $string);
328 // LATIN CAPITAL LETTER R WITH CARON
329 $string = str_replace("\330", '&#344;', $string);
330 // LATIN CAPITAL LETTER U WITH RING ABOVE
331 $string = str_replace("\331", '&#366;', $string);
332 // LATIN CAPITAL LETTER U WITH ACUTE
333 $string = str_replace("\332", '&#218;', $string);
334 // LATIN CAPITAL LETTER U WITH DOUBLE ACUTE
335 $string = str_replace("\333", '&#368;', $string);
336 // LATIN CAPITAL LETTER U WITH DIAERESIS
337 $string = str_replace("\334", '&#220;', $string);
338 // LATIN CAPITAL LETTER Y WITH ACUTE
339 $string = str_replace("\335", '&#221;', $string);
340 // LATIN CAPITAL LETTER T WITH CEDILLA
341 $string = str_replace("\336", '&#354;', $string);
342 // LATIN SMALL LETTER SHARP S
343 $string = str_replace("\337", '&#223;', $string);
344 // LATIN SMALL LETTER R WITH ACUTE
345 $string = str_replace("\340", '&#341;', $string);
346 // LATIN SMALL LETTER A WITH ACUTE
347 $string = str_replace("\341", '&#225;', $string);
348 // LATIN SMALL LETTER A WITH CIRCUMFLEX
349 $string = str_replace("\342", '&#226;', $string);
350 // LATIN SMALL LETTER A WITH BREVE
351 $string = str_replace("\343", '&#259;', $string);
352 // LATIN SMALL LETTER A WITH DIAERESIS
353 $string = str_replace("\344", '&#228;', $string);
354 // LATIN SMALL LETTER L WITH ACUTE
355 $string = str_replace("\345", '&#314;', $string);
356 // LATIN SMALL LETTER C WITH ACUTE
357 $string = str_replace("\346", '&#263;', $string);
358 // LATIN SMALL LETTER C WITH CEDILLA
359 $string = str_replace("\347", '&#231;', $string);
360 // LATIN SMALL LETTER C WITH CARON
361 $string = str_replace("\350", '&#269;', $string);
362 // LATIN SMALL LETTER E WITH ACUTE
363 $string = str_replace("\351", '&#233;', $string);
364 // LATIN SMALL LETTER E WITH OGONEK
365 $string = str_replace("\352", '&#281;', $string);
366 // LATIN SMALL LETTER E WITH DIAERESIS
367 $string = str_replace("\353", '&#235;', $string);
368 // LATIN SMALL LETTER E WITH CARON
369 $string = str_replace("\354", '&#283;', $string);
370 // LATIN SMALL LETTER I WITH ACUTE
371 $string = str_replace("\355", '&#237;', $string);
372 // LATIN SMALL LETTER I WITH CIRCUMFLEX
373 $string = str_replace("\356", '&#238;', $string);
374 // LATIN SMALL LETTER D WITH CARON
375 $string = str_replace("\357", '&#271;', $string);
376 // LATIN SMALL LETTER D WITH STROKE
377 $string = str_replace("\360", '&#273;', $string);
378 // LATIN SMALL LETTER N WITH ACUTE
379 $string = str_replace("\361", '&#324;', $string);
380 // LATIN SMALL LETTER N WITH CARON
381 $string = str_replace("\362", '&#328;', $string);
382 // LATIN SMALL LETTER O WITH ACUTE
383 $string = str_replace("\363", '&#243;', $string);
384 // LATIN SMALL LETTER O WITH CIRCUMFLEX
385 $string = str_replace("\364", '&#244;', $string);
386 // LATIN SMALL LETTER O WITH DOUBLE ACUTE
387 $string = str_replace("\365", '&#337;', $string);
388 // LATIN SMALL LETTER O WITH DIAERESIS
389 $string = str_replace("\366", '&#246;', $string);
390 // DIVISION SIGN
391 $string = str_replace("\367", '&#247;', $string);
392 // LATIN SMALL LETTER R WITH CARON
393 $string = str_replace("\370", '&#345;', $string);
394 // LATIN SMALL LETTER U WITH RING ABOVE
395 $string = str_replace("\371", '&#367;', $string);
396 // LATIN SMALL LETTER U WITH ACUTE
397 $string = str_replace("\372", '&#250;', $string);
398 // LATIN SMALL LETTER U WITH DOUBLE ACUTE
399 $string = str_replace("\373", '&#369;', $string);
400 // LATIN SMALL LETTER U WITH DIAERESIS
401 $string = str_replace("\374", '&#252;', $string);
402 // LATIN SMALL LETTER Y WITH ACUTE
403 $string = str_replace("\375", '&#253;', $string);
404 // LATIN SMALL LETTER T WITH CEDILLA
405 $string = str_replace("\376", '&#355;', $string);
406 // DOT ABOVE
407 $string = str_replace("\377", '&#729;', $string);
408
409 return $string;
410}
411
9be313d5 412/*
c37a12f8 413 ISO/IEC 8859-4:1998 Latin Alphabet No. 4
9be313d5 414*/
415
416function charset_decode_iso_8859_4 ($string) {
c37a12f8 417 global $default_charset, $languages, $sm_notAlias;
9be313d5 418
c37a12f8 419 if (strtolower($default_charset) == 'iso-8859-4')
420 return $string;
421 if (strtolower($languages[$sm_notAlias]['CHARSET']) == 'iso-8859-4')
422 return $string;
423
424 /* Only do the slow convert if there are 8-bit characters */
425 if (! ereg("[\200-\377]", $string))
426 return $string;
427
428 // latin capital letter a with ogonek 161 -> 260
429 $string = str_replace ("\241", '&#260;', $string);
430 // latin small letter kra 162 -> 312
431 $string = str_replace ("\242", '&#312;', $string);
432 // latin capital letter r with cedilla 163 -> 342
433 $string = str_replace ("\243", '&#342;', $string);
434 // latin capital letter i with tilde 165 -> 296
435 $string = str_replace ("\245", '&#296;', $string);
436 // latin capital letter l with cedilla 166 -> 315
437 $string = str_replace ("\246", '&#315;', $string);
438 // latin capital letter s with caron 169 -> 352
439 $string = str_replace ("\251", '&#352;', $string);
440 // latin capital letter e with macron 170 -> 274
441 $string = str_replace ("\252", '&#274;', $string);
442 // latin capital letter g with cedilla 171 -> 290
443 $string = str_replace ("\253", '&#290;', $string);
444 // latin capital letter t with stroke 172 -> 358
445 $string = str_replace ("\254", '&#358;', $string);
446 // latin capital letter z with caron 174 -> 381
447 $string = str_replace ("\256", '&#381;', $string);
448 // latin small letter a with ogonek 177 -> 261
449 $string = str_replace ("\261", '&#261;', $string);
450 // ogonek 178 -> 731
451 $string = str_replace ("\262", '&#731;', $string);
452 // latin small letter r with cedilla 179 -> 343
453 $string = str_replace ("\263", '&#343;', $string);
454 // latin small letter i with tilde 181 -> 297
455 $string = str_replace ("\265", '&#297;', $string);
456 // latin small letter l with cedilla 182 -> 316
457 $string = str_replace ("\266", '&#316;', $string);
458 // caron 183 -> 711
459 $string = str_replace ("\267", '&#711;', $string);
460 // latin small letter s with caron 185 -> 353
461 $string = str_replace ("\271", '&#353;', $string);
462 // latin small letter e with macron 186 -> 275
463 $string = str_replace ("\272", '&#275;', $string);
464 // latin small letter g with cedilla 187 -> 291
465 $string = str_replace ("\273", '&#291;', $string);
466 // latin small letter t with stroke 188 -> 359
467 $string = str_replace ("\274", '&#359;', $string);
468 // latin capital letter eng 189 -> 330
469 $string = str_replace ("\275", '&#330;', $string);
470 // latin small letter z with caron 190 -> 382
471 $string = str_replace ("\276", '&#382;', $string);
472 // latin small letter eng 191 -> 331
473 $string = str_replace ("\277", '&#331;', $string);
474 // latin capital letter a with macron 192 -> 256
475 $string = str_replace ("\300", '&#256;', $string);
476 // latin capital letter i with ogonek 199 -> 302
477 $string = str_replace ("\307", '&#302;', $string);
478 // latin capital letter c with caron 200 -> 268
479 $string = str_replace ("\310", '&#268;', $string);
480 // latin capital letter e with ogonek 202 -> 280
481 $string = str_replace ("\312", '&#280;', $string);
482 // latin capital letter e with dot above 204 -> 278
483 $string = str_replace ("\314", '&#278;', $string);
484 // latin capital letter i with macron 207 -> 298
485 $string = str_replace ("\317", '&#298;', $string);
486 // latin capital letter d with stroke 208 -> 272
487 $string = str_replace ("\320", '&#272;', $string);
488 // latin capital letter n with cedilla 209 -> 325
489 $string = str_replace ("\321", '&#325;', $string);
490 // latin capital letter o with macron 210 -> 332
491 $string = str_replace ("\322", '&#332;', $string);
492 // latin capital letter k with cedilla 211 -> 310
493 $string = str_replace ("\323", '&#310;', $string);
494 // latin capital letter u with ogonek 217 -> 370
495 $string = str_replace ("\331", '&#370;', $string);
496 // latin capital letter u with tilde 221 -> 360
497 $string = str_replace ("\335", '&#360;', $string);
498 // latin capital letter u with macron 222 -> 362
499 $string = str_replace ("\336", '&#362;', $string);
500 // latin small letter a with macron 224 -> 257
501 $string = str_replace ("\340", '&#257;', $string);
502 // latin small letter i with ogonek 231 -> 303
503 $string = str_replace ("\347", '&#303;', $string);
504 // latin small letter c with caron 232 -> 269
505 $string = str_replace ("\350", '&#269;', $string);
506 // latin small letter e with ogonek 234 -> 281
507 $string = str_replace ("\352", '&#281;', $string);
508 // latin small letter e with dot above 236 -> 279
509 $string = str_replace ("\354", '&#279;', $string);
510 // latin small letter i with macron 239 -> 299
511 $string = str_replace ("\357", '&#299;', $string);
512 // latin small letter d with stroke 240 -> 273
513 $string = str_replace ("\360", '&#273;', $string);
514 // latin small letter n with cedilla 241 -> 326
515 $string = str_replace ("\361", '&#326;', $string);
516 // latin small letter o with macron 242 -> 333
517 $string = str_replace ("\362", '&#333;', $string);
518 // latin small letter k with cedilla 243 -> 311
519 $string = str_replace ("\363", '&#311;', $string);
520 // latin small letter u with ogonek 249 -> 371
521 $string = str_replace ("\371", '&#371;', $string);
522 // latin small letter u with tilde 253 -> 361
523 $string = str_replace ("\375", '&#361;', $string);
524 // latin small letter u with macron 254 -> 363
525 $string = str_replace ("\376", '&#363;', $string);
526 // dot above 255 -> 729
527 $string = str_replace ("\377", '&#729;', $string);
528
529 // rest of charset is the same as ISO-8859-1
9be313d5 530 return (charset_decode_iso_8859_1($string));
531}
532
a2a7852b 533/* iso-8859-7 is Greek. */
534function charset_decode_iso_8859_7 ($string) {
535 global $default_charset;
536
537 if (strtolower($default_charset) == 'iso-8859-7') {
538 return $string;
539 }
540
541 /* Only do the slow convert if there are 8-bit characters */
542 if (!ereg("[\200-\377]", $string)) {
543 return $string;
544 }
545
546 /* Some diverse characters in the beginning */
547 $string = str_replace("\240", '&#160;', $string);
548 $string = str_replace("\241", '&#8216;', $string);
549 $string = str_replace("\242", '&#8217;', $string);
550 $string = str_replace("\243", '&#163;', $string);
551 $string = str_replace("\246", '&#166;', $string);
552 $string = str_replace("\247", '&#167;', $string);
553 $string = str_replace("\250", '&#168;', $string);
554 $string = str_replace("\251", '&#169;', $string);
555 $string = str_replace("\253", '&#171;', $string);
556 $string = str_replace("\254", '&#172;', $string);
557 $string = str_replace("\255", '&#173;', $string);
558 $string = str_replace("\257", '&#8213;', $string);
559 $string = str_replace("\260", '&#176;', $string);
560 $string = str_replace("\261", '&#177;', $string);
561 $string = str_replace("\262", '&#178;', $string);
562 $string = str_replace("\263", '&#179;', $string);
563
564 /* Horizontal bar (parentheki pavla) */
565 $string = str_replace ("\257", '&#8213;', $string);
566
567 /*
568 * ISO-8859-7 characters from 11/04 (0xB4) to 11/06 (0xB6)
569 * These are Unicode 900-902
570 */
b85a4575 571 $string = preg_replace("/([\264-\266])/e","'&#' . (ord('\\1')+720);",$string);
49c17806 572
a2a7852b 573 /* 11/07 (0xB7) Middle dot is the same in iso-8859-1 */
574 $string = str_replace("\267", '&#183;', $string);
575
576 /*
577 * ISO-8859-7 characters from 11/08 (0xB8) to 11/10 (0xBA)
578 * These are Unicode 900-902
579 */
b85a4575 580 $string = preg_replace("/([\270-\272])/e","'&#' . (ord('\\1')+720);",$string);
a2a7852b 581
582 /*
583 * 11/11 (0xBB) Right angle quotation mark is the same as in
584 * iso-8859-1
585 */
586 $string = str_replace("\273", '&#187;', $string);
587
588 /* And now the rest of the charset */
b85a4575 589 $string = preg_replace("/([\274-\376])/e","'&#'.(ord('\\1')+720);",$string);
a2a7852b 590
591 return $string;
592}
593
594/*
c37a12f8 595 ISO/IEC 8859-13:1998 Latin Alphabet No. 7 (Baltic Rim)
9be313d5 596*/
9be313d5 597function charset_decode_iso_8859_13 ($string) {
c37a12f8 598 global $default_charset, $languages, $sm_notAlias;
599
600 if (strtolower($default_charset) == 'iso-8859-13')
601 return $string;
602 if (strtolower($languages[$sm_notAlias]['CHARSET']) == 'iso-8859-13')
603 return $string;
604
605 /* Only do the slow convert if there are 8-bit characters */
606 if (! ereg("[\200-\377]", $string))
607 return $string;
9be313d5 608
c37a12f8 609 // right double quotation mark 161 -> 8221
610 $string = str_replace ("\241", '&#8221;', $string);
611 // double low-9 quotation mark 165 -> 8222
612 $string = str_replace ("\245", '&#8222;', $string);
613 // latin capital letter o with stroke 168 -> 216
614 $string = str_replace ("\250", '&#216;', $string);
615 // latin capital letter r with cedilla 170 -> 342
616 $string = str_replace ("\252", '&#342;', $string);
617 // latin capital letter ae 175 -> 198
618 $string = str_replace ("\257", '&#198;', $string);
619 // left double quotation mark 180 -> 8220
620 $string = str_replace ("\264", '&#8220;', $string);
621 // latin small letter o with stroke 184 -> 248
622 $string = str_replace ("\270", '&#248;', $string);
623 // latin small letter r with cedilla 186 -> 343
624 $string = str_replace ("\272", '&#343;', $string);
625 // latin small letter ae 191 -> 230
626 $string = str_replace ("\277", '&#230;', $string);
627 // latin capital letter a with ogonek 192 -> 260
628 $string = str_replace ("\300", '&#260;', $string);
629 // latin capital letter i with ogonek 193 -> 302
630 $string = str_replace ("\301", '&#302;', $string);
631 // latin capital letter a with macron 194 -> 256
632 $string = str_replace ("\302", '&#256;', $string);
633 // latin capital letter c with acute 195 -> 262
634 $string = str_replace ("\303", '&#262;', $string);
635 // latin capital letter e with ogonek 198 -> 280
636 $string = str_replace ("\306", '&#280;', $string);
637 // latin capital letter e with macron 199 -> 274
638 $string = str_replace ("\307", '&#274;', $string);
639 // latin capital letter c with caron 200 -> 268
640 $string = str_replace ("\310", '&#268;', $string);
641 // latin capital letter z with acute 202 -> 377
642 $string = str_replace ("\312", '&#377;', $string);
643 // latin capital letter e with dot above 203 -> 278
644 $string = str_replace ("\313", '&#278;', $string);
645 // latin capital letter g with cedilla 204 -> 290
646 $string = str_replace ("\314", '&#290;', $string);
647 // latin capital letter k with cedilla 205 -> 310
648 $string = str_replace ("\315", '&#310;', $string);
649 // latin capital letter i with macron 206 -> 298
650 $string = str_replace ("\316", '&#298;', $string);
651 // latin capital letter l with cedilla 207 -> 315
652 $string = str_replace ("\317", '&#315;', $string);
653 // latin capital letter s with caron 208 -> 352
654 $string = str_replace ("\320", '&#352;', $string);
655 // latin capital letter n with acute 209 -> 323
656 $string = str_replace ("\321", '&#323;', $string);
657 // latin capital letter n with cedilla 210 -> 325
658 $string = str_replace ("\322", '&#325;', $string);
659 // latin capital letter o with macron 212 -> 332
660 $string = str_replace ("\324", '&#332;', $string);
661 // latin capital letter u with ogonek 216 -> 370
662 $string = str_replace ("\330", '&#370;', $string);
663 // latin capital letter l with stroke 217 -> 321
664 $string = str_replace ("\331", '&#321;', $string);
665 // latin capital letter s with acute 218 -> 346
666 $string = str_replace ("\332", '&#346;', $string);
667 // latin capital letter u with macron 219 -> 362
668 $string = str_replace ("\333", '&#362;', $string);
669 // latin capital letter z with dot above 221 -> 379
670 $string = str_replace ("\335", '&#379;', $string);
671 // latin capital letter z with caron 222 -> 381
672 $string = str_replace ("\336", '&#381;', $string);
673 // latin small letter a with ogonek 224 -> 261
674 $string = str_replace ("\340", '&#261;', $string);
675 // latin small letter i with ogonek 225 -> 303
676 $string = str_replace ("\341", '&#303;', $string);
677 // latin small letter a with macron 226 -> 257
678 $string = str_replace ("\342", '&#257;', $string);
679 // latin small letter c with acute 227 -> 263
680 $string = str_replace ("\343", '&#263;', $string);
681 // latin small letter e with ogonek 230 -> 281
682 $string = str_replace ("\346", '&#281;', $string);
683 // latin small letter e with macron 231 -> 275
684 $string = str_replace ("\347", '&#275;', $string);
685 // latin small letter c with caron 232 -> 269
686 $string = str_replace ("\350", '&#269;', $string);
687 // latin small letter z with acute 234 -> 378
688 $string = str_replace ("\352", '&#378;', $string);
689 // latin small letter e with dot above 235 -> 279
690 $string = str_replace ("\353", '&#279;', $string);
691 // latin small letter g with cedilla 236 -> 291
692 $string = str_replace ("\354", '&#291;', $string);
693 // latin small letter k with cedilla 237 -> 311
694 $string = str_replace ("\355", '&#311;', $string);
695 // latin small letter i with macron 238 -> 299
696 $string = str_replace ("\356", '&#299;', $string);
697 // latin small letter l with cedilla 239 -> 316
698 $string = str_replace ("\357", '&#316;', $string);
699 // latin small letter s with caron 240 -> 253
700 $string = str_replace ("\360", '&#353;', $string);
701 // latin small letter n with acute 241 -> 324
702 $string = str_replace ("\361", '&#324;', $string);
703 // latin small letter n with cedilla 242 -> 326
704 $string = str_replace ("\362", '&#326;', $string);
705 // latin small letter o with macron 244 -> 333
706 $string = str_replace ("\364", '&#333;', $string);
707 // latin small letter u with ogonek 248 -> 371
708 $string = str_replace ("\370", '&#371;', $string);
709 // latin small letter l with stroke 249 -> 322
710 $string = str_replace ("\371", '&#322;', $string);
711 // latin small letter s with acute 250 -> 347
712 $string = str_replace ("\372", '&#347;', $string);
713 // latin small letter u with macron 251 -> 363
714 $string = str_replace ("\373", '&#363;', $string);
715 // latin small letter z with dot above 253 -> 380
716 $string = str_replace ("\375", '&#380;', $string);
717 // latin small letter z with caron 254 -> 382
718 $string = str_replace ("\376", '&#382;', $string);
719 // right single quotation mark 255 -> 8217
720 $string = str_replace ("\377", '&#8217;', $string);
721
722 // rest of charset is the same as ISO-8859-1
9be313d5 723 return (charset_decode_iso_8859_1($string));
724}
725
726/*
a2a7852b 727 * iso-8859-15 is Latin 9 and has very much the same use as Latin 1
728 * but has the Euro symbol and some characters needed for French.
729 */
730function charset_decode_iso_8859_15 ($string) {
731 // Euro sign
732 $string = str_replace ("\244", '&#8364;', $string);
733 // Latin capital letter S with caron
84556805 734 $string = str_replace ("\246", '&#352;', $string);
a2a7852b 735 // Latin small letter s with caron
736 $string = str_replace ("\250", '&#353;', $string);
737 // Latin capital letter Z with caron
738 $string = str_replace ("\264", '&#381;', $string);
739 // Latin small letter z with caron
740 $string = str_replace ("\270", '&#382;', $string);
741 // Latin capital ligature OE
742 $string = str_replace ("\274", '&#338;', $string);
743 // Latin small ligature oe
744 $string = str_replace ("\275", '&#339;', $string);
745 // Latin capital letter Y with diaeresis
746 $string = str_replace ("\276", '&#376;', $string);
747
748 return (charset_decode_iso_8859_1($string));
749}
750
84556805 751/* ISO-8859-5 is Cyrillic */
a2a7852b 752function charset_decode_iso_8859_5 ($string) {
753 // Convert to KOI8-R, then return this decoded.
754 $string = convert_cyr_string($string, 'i', 'k');
755 return charset_decode_koi8r($string);
756}
757
758/* Remove all 8 bit characters from all other ISO-8859 character sets */
759function charset_decode_iso_8859_default ($string) {
760 return (strtr($string, "\240\241\242\243\244\245\246\247".
1fd97780 761 "\250\251\252\253\254\255\256\257".
762 "\260\261\262\263\264\265\266\267".
763 "\270\271\272\273\274\275\276\277".
764 "\300\301\302\303\304\305\306\307".
765 "\310\311\312\313\314\315\316\317".
766 "\320\321\322\323\324\325\326\327".
767 "\330\331\332\333\334\335\336\337".
768 "\340\341\342\343\344\345\346\347".
769 "\350\351\352\353\354\355\356\357".
770 "\360\361\362\363\364\365\366\367".
a2a7852b 771 "\370\371\372\373\374\375\376\377",
1fd97780 772 "????????????????????????????????????????".
773 "????????????????????????????????????????".
774 "????????????????????????????????????????".
775 "????????"));
a2a7852b 776
777}
778
779/*
780 * This is the same as ISO-646-NO and is used by some
781 * Microsoft programs when sending Norwegian characters
782 */
783function charset_decode_ns_4551_1 ($string) {
784 /*
785 * These characters are:
786 * Latin capital letter AE
787 * Latin capital letter O with stroke
788 * Latin capital letter A with ring above
789 * and the same as small letters
790 */
791 return strtr ($string, "[\\]{|}", "");
792}
793
794/*
795 * KOI8-R is used to encode Russian mail (Cyrrilic). Defined in RFC
796 * 1489.
797 */
798function charset_decode_koi8r ($string) {
799 global $default_charset;
800
801 if ($default_charset == 'koi8-r') {
802 return $string;
803 }
804
805 /*
806 * Convert to Unicode HTML entities.
807 * This code is rather ineffective.
808 */
809 $string = str_replace("\200", '&#9472;', $string);
810 $string = str_replace("\201", '&#9474;', $string);
811 $string = str_replace("\202", '&#9484;', $string);
812 $string = str_replace("\203", '&#9488;', $string);
813 $string = str_replace("\204", '&#9492;', $string);
814 $string = str_replace("\205", '&#9496;', $string);
815 $string = str_replace("\206", '&#9500;', $string);
816 $string = str_replace("\207", '&#9508;', $string);
817 $string = str_replace("\210", '&#9516;', $string);
818 $string = str_replace("\211", '&#9524;', $string);
819 $string = str_replace("\212", '&#9532;', $string);
820 $string = str_replace("\213", '&#9600;', $string);
821 $string = str_replace("\214", '&#9604;', $string);
822 $string = str_replace("\215", '&#9608;', $string);
823 $string = str_replace("\216", '&#9612;', $string);
824 $string = str_replace("\217", '&#9616;', $string);
825 $string = str_replace("\220", '&#9617;', $string);
826 $string = str_replace("\221", '&#9618;', $string);
827 $string = str_replace("\222", '&#9619;', $string);
828 $string = str_replace("\223", '&#8992;', $string);
829 $string = str_replace("\224", '&#9632;', $string);
830 $string = str_replace("\225", '&#8729;', $string);
831 $string = str_replace("\226", '&#8730;', $string);
832 $string = str_replace("\227", '&#8776;', $string);
833 $string = str_replace("\230", '&#8804;', $string);
834 $string = str_replace("\231", '&#8805;', $string);
835 $string = str_replace("\232", '&#160;', $string);
836 $string = str_replace("\233", '&#8993;', $string);
837 $string = str_replace("\234", '&#176;', $string);
838 $string = str_replace("\235", '&#178;', $string);
839 $string = str_replace("\236", '&#183;', $string);
840 $string = str_replace("\237", '&#247;', $string);
841 $string = str_replace("\240", '&#9552;', $string);
842 $string = str_replace("\241", '&#9553;', $string);
843 $string = str_replace("\242", '&#9554;', $string);
844 $string = str_replace("\243", '&#1105;', $string);
845 $string = str_replace("\244", '&#9555;', $string);
846 $string = str_replace("\245", '&#9556;', $string);
847 $string = str_replace("\246", '&#9557;', $string);
848 $string = str_replace("\247", '&#9558;', $string);
849 $string = str_replace("\250", '&#9559;', $string);
850 $string = str_replace("\251", '&#9560;', $string);
851 $string = str_replace("\252", '&#9561;', $string);
852 $string = str_replace("\253", '&#9562;', $string);
853 $string = str_replace("\254", '&#9563;', $string);
854 $string = str_replace("\255", '&#9564;', $string);
855 $string = str_replace("\256", '&#9565;', $string);
856 $string = str_replace("\257", '&#9566;', $string);
857 $string = str_replace("\260", '&#9567;', $string);
858 $string = str_replace("\261", '&#9568;', $string);
859 $string = str_replace("\262", '&#9569;', $string);
860 $string = str_replace("\263", '&#1025;', $string);
861 $string = str_replace("\264", '&#9570;', $string);
862 $string = str_replace("\265", '&#9571;', $string);
863 $string = str_replace("\266", '&#9572;', $string);
864 $string = str_replace("\267", '&#9573;', $string);
865 $string = str_replace("\270", '&#9574;', $string);
866 $string = str_replace("\271", '&#9575;', $string);
867 $string = str_replace("\272", '&#9576;', $string);
868 $string = str_replace("\273", '&#9577;', $string);
869 $string = str_replace("\274", '&#9578;', $string);
870 $string = str_replace("\275", '&#9579;', $string);
871 $string = str_replace("\276", '&#9580;', $string);
872 $string = str_replace("\277", '&#169;', $string);
873 $string = str_replace("\300", '&#1102;', $string);
874 $string = str_replace("\301", '&#1072;', $string);
875 $string = str_replace("\302", '&#1073;', $string);
876 $string = str_replace("\303", '&#1094;', $string);
877 $string = str_replace("\304", '&#1076;', $string);
878 $string = str_replace("\305", '&#1077;', $string);
879 $string = str_replace("\306", '&#1092;', $string);
880 $string = str_replace("\307", '&#1075;', $string);
881 $string = str_replace("\310", '&#1093;', $string);
882 $string = str_replace("\311", '&#1080;', $string);
883 $string = str_replace("\312", '&#1081;', $string);
884 $string = str_replace("\313", '&#1082;', $string);
885 $string = str_replace("\314", '&#1083;', $string);
886 $string = str_replace("\315", '&#1084;', $string);
887 $string = str_replace("\316", '&#1085;', $string);
888 $string = str_replace("\317", '&#1086;', $string);
889 $string = str_replace("\320", '&#1087;', $string);
890 $string = str_replace("\321", '&#1103;', $string);
891 $string = str_replace("\322", '&#1088;', $string);
892 $string = str_replace("\323", '&#1089;', $string);
893 $string = str_replace("\324", '&#1090;', $string);
894 $string = str_replace("\325", '&#1091;', $string);
895 $string = str_replace("\326", '&#1078;', $string);
896 $string = str_replace("\327", '&#1074;', $string);
897 $string = str_replace("\330", '&#1100;', $string);
898 $string = str_replace("\331", '&#1099;', $string);
899 $string = str_replace("\332", '&#1079;', $string);
900 $string = str_replace("\333", '&#1096;', $string);
901 $string = str_replace("\334", '&#1101;', $string);
902 $string = str_replace("\335", '&#1097;', $string);
903 $string = str_replace("\336", '&#1095;', $string);
904 $string = str_replace("\337", '&#1098;', $string);
905 $string = str_replace("\340", '&#1070;', $string);
906 $string = str_replace("\341", '&#1040;', $string);
907 $string = str_replace("\342", '&#1041;', $string);
908 $string = str_replace("\343", '&#1062;', $string);
909 $string = str_replace("\344", '&#1044;', $string);
910 $string = str_replace("\345", '&#1045;', $string);
911 $string = str_replace("\346", '&#1060;', $string);
912 $string = str_replace("\347", '&#1043;', $string);
913 $string = str_replace("\350", '&#1061;', $string);
914 $string = str_replace("\351", '&#1048;', $string);
915 $string = str_replace("\352", '&#1049;', $string);
916 $string = str_replace("\353", '&#1050;', $string);
917 $string = str_replace("\354", '&#1051;', $string);
918 $string = str_replace("\355", '&#1052;', $string);
919 $string = str_replace("\356", '&#1053;', $string);
920 $string = str_replace("\357", '&#1054;', $string);
921 $string = str_replace("\360", '&#1055;', $string);
922 $string = str_replace("\361", '&#1071;', $string);
923 $string = str_replace("\362", '&#1056;', $string);
924 $string = str_replace("\363", '&#1057;', $string);
925 $string = str_replace("\364", '&#1058;', $string);
926 $string = str_replace("\365", '&#1059;', $string);
927 $string = str_replace("\366", '&#1046;', $string);
928 $string = str_replace("\367", '&#1042;', $string);
929 $string = str_replace("\370", '&#1068;', $string);
930 $string = str_replace("\371", '&#1067;', $string);
931 $string = str_replace("\372", '&#1047;', $string);
932 $string = str_replace("\373", '&#1064;', $string);
933 $string = str_replace("\374", '&#1069;', $string);
934 $string = str_replace("\375", '&#1065;', $string);
935 $string = str_replace("\376", '&#1063;', $string);
936 $string = str_replace("\377", '&#1066;', $string);
937
938 return $string;
939}
940
c37a12f8 941/*
942 windows-1257 (BaltRim)
943 */
944function charset_decode_windows_1257 ($string) {
945 global $default_charset, $languages, $sm_notAlias;
946
947 if (strtolower($default_charset) == 'windows-1257')
948 return $string;
949 if (strtolower($languages[$sm_notAlias]['CHARSET']) == 'windows-1257')
950 return $string;
951
952 /* Only do the slow convert if there are 8-bit characters */
953 if (! ereg("[\200-\377]", $string))
954 return $string;
955
956 // Euro sign 128 -> 8364
957 $string = str_replace("\200", '&#8364;', $string);
958 // Single low-9 quotation mark 130 -> 8218
959 $string = str_replace("\202", '&#8218;', $string);
960 // Double low-9 quotation mark 132 -> 8222
961 $string = str_replace("\204", '&#8222;', $string);
962 // horizontal ellipsis 133 -> 8230
963 $string = str_replace("\205", '&#8230;', $string);
964 // dagger 134 -> 8224
965 $string = str_replace("\206", '&#8224;', $string);
966 // double dagger 135 -> 8225
967 $string = str_replace("\207", '&#8225;', $string);
968 // per mille sign 137 -> 8240
969 $string = str_replace("\211", '&#8240;', $string);
970 // single left-pointing angle quotation mark 139 -> 8249
971 $string = str_replace("\213", '&#8249;', $string);
972 // diaeresis 141 -> 168
973 $string = str_replace("\215", '&#168;', $string);
974 // caron 142 -> 711
975 $string = str_replace("\216", '&#711;', $string);
976 // cedilla 143 -> 184
977 $string = str_replace("\217", '&#184;', $string);
978 // left single quotation mark 145 -> 8216
979 $string = str_replace("\221", '&#8216;', $string);
980 // right single quotation mark 146 -> 8217
981 $string = str_replace("\222", '&#8217;', $string);
982 // left double quotation mark 147 -> 8220
983 $string = str_replace("\223", '&#8220;', $string);
984 // right double quotation mark 148 -> 8221
985 $string = str_replace("\224", '&#8221;', $string);
986 // bullet 149 -> 8226
987 $string = str_replace("\225", '&#8226;', $string);
988 // en dash 150 -> 8211
989 $string = str_replace("\226", '&#8211;', $string);
990 // em dash 151 -> 8212
991 $string = str_replace("\227", '&#8212;', $string);
992 // trade mark sign 153 -> 8482
993 $string = str_replace("\231", '&#8482;', $string);
994 // single right-pointing angle quotation mark 155 -> 8250
995 $string = str_replace("\233", '&#8250;', $string);
996 // macron 157 -> 175
997 $string = str_replace("\235", '&#175;', $string);
998 // ogonek 158 -> 731
999 $string = str_replace("\236", '&#731;', $string);
1000 // latin capital letter o with stroke 168 -> 216
1001 $string = str_replace ("\250", '&#216;', $string);
1002 // latin capital letter r with cedilla 170 -> 342
1003 $string = str_replace ("\252", '&#342;', $string);
1004 // latin capital letter ae 175 -> 198
1005 $string = str_replace ("\257", '&#198;', $string);
1006 // latin small letter o with stroke 184 -> 248
1007 $string = str_replace ("\270", '&#248;', $string);
1008 // latin small letter r with cedilla 186 -> 343
1009 $string = str_replace ("\272", '&#343;', $string);
1010 // latin small letter ae 191 -> 230
1011 $string = str_replace ("\277", '&#230;', $string);
1012 // latin capital letter a with ogonek 192 -> 260
1013 $string = str_replace ("\300", '&#260;', $string);
1014 // latin capital letter i with ogonek 193 -> 302
1015 $string = str_replace ("\301", '&#302;', $string);
1016 // latin capital letter a with macron 194 -> 256
1017 $string = str_replace ("\302", '&#256;', $string);
1018 // latin capital letter c with acute 195 -> 262
1019 $string = str_replace ("\303", '&#262;', $string);
1020 // latin capital letter e with ogonek 198 -> 280
1021 $string = str_replace ("\306", '&#280;', $string);
1022 // latin capital letter e with macron 199 -> 274
1023 $string = str_replace ("\307", '&#274;', $string);
1024 // latin capital letter c with caron 200 -> 268
1025 $string = str_replace ("\310", '&#268;', $string);
1026 // latin capital letter z with acute 202 -> 377
1027 $string = str_replace ("\312", '&#377;', $string);
1028 // latin capital letter e with dot above 203 -> 278
1029 $string = str_replace ("\313", '&#278;', $string);
1030 // latin capital letter g with cedilla 204 -> 290
1031 $string = str_replace ("\314", '&#290;', $string);
1032 // latin capital letter k with cedilla 205 -> 310
1033 $string = str_replace ("\315", '&#310;', $string);
1034 // latin capital letter i with macron 206 -> 298
1035 $string = str_replace ("\316", '&#298;', $string);
1036 // latin capital letter l with cedilla 207 -> 315
1037 $string = str_replace ("\317", '&#315;', $string);
1038 // latin capital letter s with caron 208 -> 352
1039 $string = str_replace ("\320", '&#352;', $string);
1040 // latin capital letter n with acute 209 -> 323
1041 $string = str_replace ("\321", '&#323;', $string);
1042 // latin capital letter n with cedilla 210 -> 325
1043 $string = str_replace ("\322", '&#325;', $string);
1044 // latin capital letter o with macron 212 -> 332
1045 $string = str_replace ("\324", '&#332;', $string);
1046 // latin capital letter u with ogonek 216 -> 370
1047 $string = str_replace ("\330", '&#370;', $string);
1048 // latin capital letter l with stroke 217 -> 321
1049 $string = str_replace ("\331", '&#321;', $string);
1050 // latin capital letter r with acute 218 -> 340
1051 $string = str_replace ("\332", '&#340;', $string);
1052 // latin capital letter u with macron 219 -> 362
1053 $string = str_replace ("\333", '&#362;', $string);
1054 // latin capital letter z with dot above 221 -> 379
1055 $string = str_replace ("\335", '&#379;', $string);
1056 // latin capital letter z with caron 222 -> 381
1057 $string = str_replace ("\336", '&#381;', $string);
1058 // latin small letter a with ogonek 224 -> 261
1059 $string = str_replace ("\340", '&#261;', $string);
1060 // latin small letter i with ogonek 225 -> 303
1061 $string = str_replace ("\341", '&#303;', $string);
1062 // latin small letter a with macron 226 -> 257
1063 $string = str_replace ("\342", '&#257;', $string);
1064 // latin small letter c with acute 227 -> 263
1065 $string = str_replace ("\343", '&#263;', $string);
1066 // latin small letter e with ogonek 230 -> 281
1067 $string = str_replace ("\346", '&#281;', $string);
1068 // latin small letter e with macron 231 -> 275
1069 $string = str_replace ("\347", '&#275;', $string);
1070 // latin small letter c with caron 232 -> 269
1071 $string = str_replace ("\350", '&#269;', $string);
1072 // latin small letter z with acute 234 -> 378
1073 $string = str_replace ("\352", '&#378;', $string);
1074 // latin small letter e with dot above 235 -> 279
1075 $string = str_replace ("\353", '&#279;', $string);
1076 // latin small letter g with cedilla 236 -> 291
1077 $string = str_replace ("\354", '&#291;', $string);
1078 // latin small letter k with cedilla 237 -> 311
1079 $string = str_replace ("\355", '&#311;', $string);
1080 // latin small letter i with macron 238 -> 299
1081 $string = str_replace ("\356", '&#299;', $string);
1082 // latin small letter l with cedilla 239 -> 316
1083 $string = str_replace ("\357", '&#316;', $string);
1084 // latin small letter s with caron 240 -> 253
1085 $string = str_replace ("\360", '&#353;', $string);
1086 // latin small letter n with acute 241 -> 324
1087 $string = str_replace ("\361", '&#324;', $string);
1088 // latin small letter n with cedilla 242 -> 326
1089 $string = str_replace ("\362", '&#326;', $string);
1090 // latin small letter o with macron 244 -> 333
1091 $string = str_replace ("\364", '&#333;', $string);
1092 // latin small letter u with ogonek 248 -> 371
1093 $string = str_replace ("\370", '&#371;', $string);
1094 // latin small letter l with stroke 249 -> 322
1095 $string = str_replace ("\371", '&#322;', $string);
1096 // latin small letter s with acute 250 -> 347
1097 $string = str_replace ("\372", '&#347;', $string);
1098 // latin small letter u with macron 251 -> 363
1099 $string = str_replace ("\373", '&#363;', $string);
1100 // latin small letter z with dot above 253 -> 380
1101 $string = str_replace ("\375", '&#380;', $string);
1102 // latin small letter z with caron 254 -> 382
1103 $string = str_replace ("\376", '&#382;', $string);
1104 // dot above 255 -> 729
1105 $string = str_replace ("\377", '&#729;', $string);
1106
1107 // Rest of charset is like iso-8859-1
1108 return (charset_decode_iso_8859_1($string));
1109}
1110
ecd877a8 1111/* windows-1251 is Microsoft Cyrillic encoding */
1112function charset_decode_windows_1251 ($string) {
1113 // Convert to KOI8-R, then return this decoded.
1114 $string = convert_cyr_string($string, 'w', 'k');
1115 return charset_decode_koi8r($string);
1116}
1117
1118
6fbd125b 1119
a2a7852b 1120/*
1121 * Set up the language to be output
1122 * if $do_search is true, then scan the browser information
1123 * for a possible language that we know
1124 */
1125function set_up_language($sm_language, $do_search = false) {
1126
1127 static $SetupAlready = 0;
9eb0fbd4 1128 global $use_gettext, $languages,
a2a7852b 1129 $squirrelmail_language, $squirrelmail_default_language,
1130 $sm_notAlias;
1131
1132 if ($SetupAlready) {
1133 return;
1134 }
a65846a7 1135
5c920668 1136 $SetupAlready = TRUE;
a2a7852b 1137
9eb0fbd4 1138 if ($do_search && ! $sm_language && isset($_SERVER['HTTP_ACCEPT_LANGUAGE'])) {
1139 $sm_language = substr($_SERVER['HTTP_ACCEPT_LANGUAGE'], 0, 2);
a2a7852b 1140 }
66d7950f 1141
a2a7852b 1142 if (!$sm_language && isset($squirrelmail_default_language)) {
1143 $squirrelmail_language = $squirrelmail_default_language;
66d7950f 1144 $sm_language = $squirrelmail_default_language;
a2a7852b 1145 }
1146 $sm_notAlias = $sm_language;
1147 while (isset($languages[$sm_notAlias]['ALIAS'])) {
1148 $sm_notAlias = $languages[$sm_notAlias]['ALIAS'];
1149 }
1150
88cb1b4d 1151 if ( isset($sm_language) &&
5c920668 1152 $use_gettext &&
1153 $sm_language != '' &&
1154 isset($languages[$sm_notAlias]['CHARSET']) ) {
a65846a7 1155 bindtextdomain( 'squirrelmail', SM_PATH . 'locale/' );
88cb1b4d 1156 textdomain( 'squirrelmail' );
1157 if ( !ini_get('safe_mode') &&
5c920668 1158 getenv( 'LC_ALL' ) != $sm_notAlias ) {
1159 putenv( "LC_ALL=$sm_notAlias" );
1160 putenv( "LANG=$sm_notAlias" );
1161 putenv( "LANGUAGE=$sm_notAlias" );
a2a7852b 1162 }
88cb1b4d 1163 setlocale(LC_ALL, $sm_notAlias);
5c920668 1164 $squirrelmail_language = $sm_notAlias;
538f1ab7 1165 if ($squirrelmail_language == 'ja_JP' && function_exists('mb_detect_encoding') ) {
b05c8961 1166 header ('Content-Type: text/html; charset=EUC-JP');
1167 if (!function_exists('mb_internal_encoding')) {
1168 echo _("You need to have php4 installed with the multibyte string function enabled (using configure option --with-mbstring).");
1169 }
1170 mb_internal_encoding('EUC-JP');
1171 mb_http_output('pass');
1172 } else {
5c920668 1173 header( 'Content-Type: text/html; charset=' . $languages[$sm_notAlias]['CHARSET'] );
a2a7852b 1174 }
1175}
b05c8961 1176}
a2a7852b 1177
1178function set_my_charset(){
1179
1180 /*
1181 * There can be a $default_charset setting in the
1182 * config.php file, but the user may have a different language
1183 * selected for a user interface. This function checks the
1184 * language selected by the user and tags the outgoing messages
1185 * with the appropriate charset corresponding to the language
1186 * selection. This is "more right" (tm), than just stamping the
1187 * message blindly with the system-wide $default_charset.
1188 */
1189 global $data_dir, $username, $default_charset, $languages;
88cb1b4d 1190
a2a7852b 1191 $my_language = getPref($data_dir, $username, 'language');
5c920668 1192 if (!$my_language) {
1193 return;
1194 }
a2a7852b 1195 while (isset($languages[$my_language]['ALIAS'])) {
f7e8861e 1196 $my_language = $languages[$my_language]['ALIAS'];
a2a7852b 1197 }
5c920668 1198 $my_charset = $languages[$my_language]['CHARSET'];
a2a7852b 1199 if ($my_charset) {
1200 $default_charset = $my_charset;
1201 }
1202}
1203
a2a7852b 1204/* ------------------------------ main --------------------------- */
1205
5c920668 1206global $squirrelmail_language, $languages, $use_gettext;
1207
a2a7852b 1208if (! isset($squirrelmail_language)) {
1209 $squirrelmail_language = '';
1210}
1211
1212/* This array specifies the available languages. */
5c920668 1213
1214// The glibc locale is ca_ES.
1215
1216$languages['ca_ES']['NAME'] = 'Catalan';
1217$languages['ca_ES']['CHARSET'] = 'iso-8859-1';
1218$languages['ca']['ALIAS'] = 'ca_ES';
1219
a2a7852b 1220$languages['cs_CZ']['NAME'] = 'Czech';
1221$languages['cs_CZ']['CHARSET'] = 'iso-8859-2';
1222$languages['cs']['ALIAS'] = 'cs_CZ';
a2a7852b 1223
5c920668 1224// Danish locale is da_DK.
1225
1226$languages['da_DK']['NAME'] = 'Danish';
1227$languages['da_DK']['CHARSET'] = 'iso-8859-1';
1228$languages['da']['ALIAS'] = 'da_DK';
1229
1230$languages['de_DE']['NAME'] = 'Deutsch';
1231$languages['de_DE']['CHARSET'] = 'iso-8859-1';
1232$languages['de']['ALIAS'] = 'de_DE';
a2a7852b 1233
5c920668 1234// There is no en_EN! There is en_US, en_BR, en_AU, and so forth,
1235// but who cares about !US, right? Right? :)
a2a7852b 1236
5c920668 1237$languages['en_US']['NAME'] = 'English';
1238$languages['en_US']['CHARSET'] = 'iso-8859-1';
1239$languages['en']['ALIAS'] = 'en_US';
a2a7852b 1240
5c920668 1241$languages['es_ES']['NAME'] = 'Spanish';
1242$languages['es_ES']['CHARSET'] = 'iso-8859-1';
1243$languages['es']['ALIAS'] = 'es_ES';
a2a7852b 1244
5c920668 1245$languages['et_EE']['NAME'] = 'Estonian';
1246$languages['et_EE']['CHARSET'] = 'iso-8859-15';
1247$languages['et']['ALIAS'] = 'et_EE';
a2a7852b 1248
5c920668 1249$languages['fi_FI']['NAME'] = 'Finnish';
1250$languages['fi_FI']['CHARSET'] = 'iso-8859-1';
1251$languages['fi']['ALIAS'] = 'fi_FI';
a2a7852b 1252
5c920668 1253$languages['fr_FR']['NAME'] = 'French';
1254$languages['fr_FR']['CHARSET'] = 'iso-8859-1';
1255$languages['fr']['ALIAS'] = 'fr_FR';
a2a7852b 1256
5c920668 1257$languages['hr_HR']['NAME'] = 'Croatian';
1258$languages['hr_HR']['CHARSET'] = 'iso-8859-2';
1259$languages['hr']['ALIAS'] = 'hr_HR';
a2a7852b 1260
5c920668 1261$languages['hu_HU']['NAME'] = 'Hungarian';
1262$languages['hu_HU']['CHARSET'] = 'iso-8859-2';
1263$languages['hu']['ALIAS'] = 'hu_HU';
a2a7852b 1264
5c920668 1265$languages['id_ID']['NAME'] = 'Indonesian';
1266$languages['id_ID']['CHARSET'] = 'iso-8859-1';
1267$languages['id']['ALIAS'] = 'id_ID';
a2a7852b 1268
5c920668 1269$languages['is_IS']['NAME'] = 'Icelandic';
1270$languages['is_IS']['CHARSET'] = 'iso-8859-1';
1271$languages['is']['ALIAS'] = 'is_IS';
a2a7852b 1272
5c920668 1273$languages['it_IT']['NAME'] = 'Italian';
1274$languages['it_IT']['CHARSET'] = 'iso-8859-1';
1275$languages['it']['ALIAS'] = 'it_IT';
a2a7852b 1276
b05c8961 1277$languages['ja_JP']['NAME'] = 'Japanese';
1278$languages['ja_JP']['CHARSET'] = 'iso-2022-jp';
6fbd125b 1279$languages['ja_JP']['XTRA_CODE'] = 'japanese_charset_xtra';
b05c8961 1280$languages['ja']['ALIAS'] = 'ja_JP';
1281
5c920668 1282$languages['ko_KR']['NAME'] = 'Korean';
1283$languages['ko_KR']['CHARSET'] = 'euc-KR';
1d33e35e 1284$languages['ko_KR']['XTRA_CODE'] = 'korean_charset_xtra';
5c920668 1285$languages['ko']['ALIAS'] = 'ko_KR';
a2a7852b 1286
5c920668 1287$languages['nl_NL']['NAME'] = 'Dutch';
1288$languages['nl_NL']['CHARSET'] = 'iso-8859-1';
1289$languages['nl']['ALIAS'] = 'nl_NL';
a2a7852b 1290
5c920668 1291$languages['no_NO']['NAME'] = 'Norwegian (Bokm&aring;l)';
1292$languages['no_NO']['CHARSET'] = 'iso-8859-1';
1293$languages['no']['ALIAS'] = 'no_NO';
b8b4ac4a 1294$languages['nn_NO']['NAME'] = 'Norwegian (Nynorsk)';
1295$languages['nn_NO']['CHARSET'] = 'iso-8859-1';
a2a7852b 1296
5c920668 1297$languages['pl_PL']['NAME'] = 'Polish';
1298$languages['pl_PL']['CHARSET'] = 'iso-8859-2';
1299$languages['pl']['ALIAS'] = 'pl_PL';
a2a7852b 1300
5c920668 1301$languages['pt_PT']['NAME'] = 'Portuguese (Portugal)';
1302$languages['pt_PT']['CHARSET'] = 'iso-8859-1';
a2a7852b 1303$languages['pt_BR']['NAME'] = 'Portuguese (Brazil)';
1304$languages['pt_BR']['CHARSET'] = 'iso-8859-1';
5c920668 1305$languages['pt']['ALIAS'] = 'pt_PT';
a2a7852b 1306
5c920668 1307$languages['ru_RU']['NAME'] = 'Russian';
1308$languages['ru_RU']['CHARSET'] = 'koi8-r';
1309$languages['ru']['ALIAS'] = 'ru_RU';
a2a7852b 1310
dbec0d67 1311$languages['sr_YU']['NAME'] = 'Serbian';
1312$languages['sr_YU']['CHARSET'] = 'iso-8859-2';
1313$languages['sr']['ALIAS'] = 'sr_YU';
a2a7852b 1314
5c920668 1315$languages['sv_SE']['NAME'] = 'Swedish';
1316$languages['sv_SE']['CHARSET'] = 'iso-8859-1';
1317$languages['sv']['ALIAS'] = 'sv_SE';
a2a7852b 1318
5c920668 1319$languages['tr_TR']['NAME'] = 'Turkish';
1320$languages['tr_TR']['CHARSET'] = 'iso-8859-9';
1321$languages['tr']['ALIAS'] = 'tr_TR';
a2a7852b 1322
b62c1863 1323$languages['zh_TW']['NAME'] = 'Chinese Trad';
5c920668 1324$languages['zh_TW']['CHARSET'] = 'big5';
1325$languages['tw']['ALIAS'] = 'zh_TW';
a2a7852b 1326
b62c1863 1327$languages['zh_CN']['NAME'] = 'Chinese Simp';
1328$languages['zh_CN']['CHARSET'] = 'gb2312';
1329$languages['cn']['ALIAS'] = 'zh_CN';
8ba79a3b 1330
a2a7852b 1331$languages['sk_SK']['NAME'] = 'Slovak';
1332$languages['sk_SK']['CHARSET'] = 'iso-8859-2';
1333$languages['sk']['ALIAS'] = 'sk_SK';
1334
5c920668 1335$languages['ro_RO']['NAME'] = 'Romanian';
1336$languages['ro_RO']['CHARSET'] = 'iso-8859-2';
1337$languages['ro']['ALIAS'] = 'ro_RO';
a2a7852b 1338
5c920668 1339$languages['th_TH']['NAME'] = 'Thai';
1340$languages['th_TH']['CHARSET'] = 'tis-620';
1341$languages['th']['ALIAS'] = 'th_TH';
a2a7852b 1342
5c920668 1343$languages['lt_LT']['NAME'] = 'Lithuanian';
923229f2 1344$languages['lt_LT']['CHARSET'] = 'windows-1257';
5c920668 1345$languages['lt']['ALIAS'] = 'lt_LT';
a2a7852b 1346
5c920668 1347$languages['sl_SI']['NAME'] = 'Slovenian';
1348$languages['sl_SI']['CHARSET'] = 'iso-8859-2';
1349$languages['sl']['ALIAS'] = 'sl_SI';
a2a7852b 1350
5c920668 1351$languages['bg_BG']['NAME'] = 'Bulgarian';
1352$languages['bg_BG']['CHARSET'] = 'windows-1251';
1353$languages['bg']['ALIAS'] = 'bg_BG';
a2a7852b 1354
93ea3e70 1355$languages['uk_UA']['NAME'] = 'Ukrainian';
1356$languages['uk_UA']['CHARSET'] = 'koi8-u';
1357$languages['uk']['ALIAS'] = 'uk_UA';
1358
d3b57948 1359// Right to left languages
1360
1361$languages['he_HE']['NAME'] = 'Hebrew';
1362$languages['he_HE']['CHARSET'] = 'windows-1255';
1363$languages['he_HE']['DIR'] = 'rtl';
1364$languages['he']['ALIAS'] = 'he_HE';
1365
1366
5c920668 1367/* Detect whether gettext is installed. */
a2a7852b 1368$gettext_flags = 0;
1369if (function_exists('_')) {
1370 $gettext_flags += 1;
1371}
1372if (function_exists('bindtextdomain')) {
1373 $gettext_flags += 2;
1374}
1375if (function_exists('textdomain')) {
1376 $gettext_flags += 4;
1377}
1378
5c920668 1379/* If gettext is fully loaded, cool */
a2a7852b 1380if ($gettext_flags == 7) {
1381 $use_gettext = true;
1382}
5c920668 1383/* If we can fake gettext, try that */
a2a7852b 1384elseif ($gettext_flags == 0) {
1385 $use_gettext = true;
e7ab8c9d 1386 include_once(SM_PATH . 'functions/gettext.php');
a2a7852b 1387} else {
5c920668 1388 /* Uh-ho. A weird install */
a2a7852b 1389 if (! $gettext_flags & 1) {
1390 function _($str) {
1391 return $str;
1392 }
1393 }
1394 if (! $gettext_flags & 2) {
1395 function bindtextdomain() {
1396 return;
1397 }
1398 }
1399 if (! $gettext_flags & 4) {
1400 function textdomain() {
1401 return;
1402 }
1403 }
1404}
1405
1d33e35e 1406
1407/*
1408 * Japanese charset extra function
1409 *
1410 */
1411function japanese_charset_xtra() {
1412 $ret = func_get_arg(1); /* default return value */
1413 if (function_exists('mb_detect_encoding')) {
1414 switch (func_get_arg(0)) { /* action */
1415 case 'decode':
1416 $detect_encoding = mb_detect_encoding($ret);
1417 if ($detect_encoding == 'JIS' ||
1418 $detect_encoding == 'EUC-JP' ||
1419 $detect_encoding == 'SJIS') {
1420
1421 $ret = mb_convert_encoding($ret, 'EUC-JP', 'AUTO');
1422 }
1423 break;
1424 case 'encode':
1425 $detect_encoding = mb_detect_encoding($ret);
1426 if ($detect_encoding == 'JIS' ||
1427 $detect_encoding == 'EUC-JP' ||
1428 $detect_encoding == 'SJIS') {
1429
1430 $ret = mb_convert_encoding($ret, 'JIS', 'AUTO');
1431 }
1432 break;
1433 case 'strimwidth':
1434 $width = func_get_arg(2);
1435 $ret = mb_strimwidth($ret, 0, $width, '...');
1436 break;
1437 case 'encodeheader':
8ba05cbe 1438 $result = '';
1439 if (strlen($ret) > 0) {
1440 $tmpstr = mb_substr($ret, 0, 1);
1441 $prevcsize = strlen($tmpstr);
1442 for ($i = 1; $i < mb_strlen($ret); $i++) {
1443 $tmp = mb_substr($ret, $i, 1);
1444 if (strlen($tmp) == $prevcsize) {
1445 $tmpstr .= $tmp;
1446 } else {
1447 if ($prevcsize == 1) {
1448 $result .= $tmpstr;
1449 } else {
1450 $result .= mb_encode_mimeheader($tmpstr);
1451 }
1452 $tmpstr = $tmp;
1453 $prevcsize = strlen($tmp);
1454 }
1455 }
1456 if (strlen($tmpstr)) {
1457 if (strlen(mb_substr($tmpstr, 0, 1)) == 1)
1458 $result .= $tmpstr;
1459 else
1460 $result .= mb_encode_mimeheader($tmpstr);
1461 }
1462 }
1463 $ret = $result;
1464 //$ret = mb_encode_mimeheader($ret);
1d33e35e 1465 break;
1466 case 'decodeheader':
1467 $ret = str_replace("\t", "", $ret);
1468 if (eregi('=\\?([^?]+)\\?(q|b)\\?([^?]+)\\?=', $ret))
1469 $ret = mb_decode_mimeheader($ret);
1470 $ret = mb_convert_encoding($ret, 'EUC-JP', 'AUTO');
1471 break;
1472 case 'downloadfilename':
1473 $useragent = func_get_arg(2);
1474 if (strstr($useragent, 'Windows') !== false ||
1475 strstr($useragent, 'Mac_') !== false) {
1476 $ret = mb_convert_encoding($ret, 'SJIS', 'AUTO');
1477 } else {
1478 $ret = mb_convert_encoding($ret, 'EUC-JP', 'AUTO');
1479}
1480 break;
1481 }
1482 }
1483 return $ret;
1484}
1485
1486
1487/*
1488 * Korean charset extra function
1489 * Hangul(Korean Character) Attached File Name Fix.
1490 */
1491function korean_charset_xtra() {
1492
1493 $ret = func_get_arg(1); /* default return value */
1494 if (func_get_arg(0) == 'downloadfilename') { /* action */
1495 $ret = str_replace("\x0D\x0A", '', $ret); /* Hanmail's CR/LF Clear */
1496 for ($i=0;$i<strlen($ret);$i++) {
1497 if ($ret[$i] >= "\xA1" && $ret[$i] <= "\xFE") { /* 0xA1 - 0XFE are Valid */
1498 $i++;
1499 continue;
1500 } else if (($ret[$i] >= 'a' && $ret[$i] <= 'z') || /* From Original ereg_replace in download.php */
1501 ($ret[$i] >= 'A' && $ret[$i] <= 'Z') ||
1502 ($ret[$i] == '.') || ($ret[$i] == '-')) {
1503 continue;
1504 } else {
1505 $ret[$i] = '_';
1506 }
1507 }
1508
1509 }
1510
1511 return $ret;
1512}
1513
e7ab8c9d 1514?>