second try
[squirrelmail.git] / functions / i18n.php
1 <?php
2
3 /**
4 * i18n.php
5 *
6 * Copyright (c) 1999-2002 The SquirrelMail Project Team
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
18 /* Decodes a string to the internal encoding from the given charset */
19 function charset_decode ($charset, $string) {
20 global $languages, $squirrelmail_language;
21
22 if (isset($languages[$squirrelmail_language]['XTRA_CODE']) &&
23 function_exists($languages[$squirrelmail_language]['XTRA_CODE'])) {
24 $string = $languages[$squirrelmail_language]['XTRA_CODE']('decode', $string);
25 }
26
27 /* All HTML special characters are 7 bit and can be replaced first */
28 $string = htmlspecialchars ($string);
29
30 $charset = strtolower($charset);
31
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);
37 } else if ($res[1] == '4') {
38 $ret = charset_decode_iso_8859_4 ($string);
39 } else if ($res[1] == '7') {
40 $ret = charset_decode_iso_8859_7 ($string);
41 } else if ($res[1] == '13') {
42 $ret = charset_decode_iso_8859_13 ($string);
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') {
53 $ret = charset_decode_koi8r ($string);
54 } else {
55 $ret = $string;
56 }
57 return( $ret );
58 }
59
60 /*
61 iso-8859-1 is the same as Latin 1 and is normally used
62 in western europe.
63 */
64 function charset_decode_iso_8859_1 ($string) {
65 global $default_charset;
66
67 if (strtolower($default_charset) <> 'iso-8859-1') {
68 /* Only do the slow convert if there are 8-bit characters */
69 if (ereg("[\200-\377]", $string)) {
70 $string = str_replace("\201", '&#129;', $string);
71 $string = str_replace("\202", '&#130;', $string);
72 $string = str_replace("\203", '&#131;', $string);
73 $string = str_replace("\204", '&#132;', $string);
74 $string = str_replace("\205", '&#133;', $string);
75 $string = str_replace("\206", '&#134;', $string);
76 $string = str_replace("\207", '&#135;', $string);
77 $string = str_replace("\210", '&#136;', $string);
78 $string = str_replace("\211", '&#137;', $string);
79 $string = str_replace("\212", '&#138;', $string);
80 $string = str_replace("\213", '&#139;', $string);
81 $string = str_replace("\214", '&#140;', $string);
82 $string = str_replace("\215", '&#141;', $string);
83 $string = str_replace("\216", '&#142;', $string);
84 $string = str_replace("\217", '&#143;', $string);
85 $string = str_replace("\220", '&#144;', $string);
86 $string = str_replace("\221", '&#145;', $string);
87 $string = str_replace("\222", '&#146;', $string);
88 $string = str_replace("\223", '&#147;', $string);
89 $string = str_replace("\224", '&#148;', $string);
90 $string = str_replace("\225", '&#149;', $string);
91 $string = str_replace("\226", '&#150;', $string);
92 $string = str_replace("\227", '&#151;', $string);
93 $string = str_replace("\230", '&#152;', $string);
94 $string = str_replace("\231", '&#153;', $string);
95 $string = str_replace("\232", '&#154;', $string);
96 $string = str_replace("\233", '&#155;', $string);
97 $string = str_replace("\234", '&#156;', $string);
98 $string = str_replace("\235", '&#157;', $string);
99 $string = str_replace("\236", '&#158;', $string);
100 $string = str_replace("\237", '&#159;', $string);
101 $string = str_replace("\240", '&#160;', $string);
102 $string = str_replace("\241", '&#161;', $string);
103 $string = str_replace("\242", '&#162;', $string);
104 $string = str_replace("\243", '&#163;', $string);
105 $string = str_replace("\244", '&#164;', $string);
106 $string = str_replace("\245", '&#165;', $string);
107 $string = str_replace("\246", '&#166;', $string);
108 $string = str_replace("\247", '&#167;', $string);
109 $string = str_replace("\250", '&#168;', $string);
110 $string = str_replace("\251", '&#169;', $string);
111 $string = str_replace("\252", '&#170;', $string);
112 $string = str_replace("\253", '&#171;', $string);
113 $string = str_replace("\254", '&#172;', $string);
114 $string = str_replace("\255", '&#173;', $string);
115 $string = str_replace("\256", '&#174;', $string);
116 $string = str_replace("\257", '&#175;', $string);
117 $string = str_replace("\260", '&#176;', $string);
118 $string = str_replace("\261", '&#177;', $string);
119 $string = str_replace("\262", '&#178;', $string);
120 $string = str_replace("\263", '&#179;', $string);
121 $string = str_replace("\264", '&#180;', $string);
122 $string = str_replace("\265", '&#181;', $string);
123 $string = str_replace("\266", '&#182;', $string);
124 $string = str_replace("\267", '&#183;', $string);
125 $string = str_replace("\270", '&#184;', $string);
126 $string = str_replace("\271", '&#185;', $string);
127 $string = str_replace("\272", '&#186;', $string);
128 $string = str_replace("\273", '&#187;', $string);
129 $string = str_replace("\274", '&#188;', $string);
130 $string = str_replace("\275", '&#189;', $string);
131 $string = str_replace("\276", '&#190;', $string);
132 $string = str_replace("\277", '&#191;', $string);
133 $string = str_replace("\300", '&#192;', $string);
134 $string = str_replace("\301", '&#193;', $string);
135 $string = str_replace("\302", '&#194;', $string);
136 $string = str_replace("\303", '&#195;', $string);
137 $string = str_replace("\304", '&#196;', $string);
138 $string = str_replace("\305", '&#197;', $string);
139 $string = str_replace("\306", '&#198;', $string);
140 $string = str_replace("\307", '&#199;', $string);
141 $string = str_replace("\310", '&#200;', $string);
142 $string = str_replace("\311", '&#201;', $string);
143 $string = str_replace("\312", '&#202;', $string);
144 $string = str_replace("\313", '&#203;', $string);
145 $string = str_replace("\314", '&#204;', $string);
146 $string = str_replace("\315", '&#205;', $string);
147 $string = str_replace("\316", '&#206;', $string);
148 $string = str_replace("\317", '&#207;', $string);
149 $string = str_replace("\320", '&#208;', $string);
150 $string = str_replace("\321", '&#209;', $string);
151 $string = str_replace("\322", '&#210;', $string);
152 $string = str_replace("\323", '&#211;', $string);
153 $string = str_replace("\324", '&#212;', $string);
154 $string = str_replace("\325", '&#213;', $string);
155 $string = str_replace("\326", '&#214;', $string);
156 $string = str_replace("\327", '&#215;', $string);
157 $string = str_replace("\330", '&#216;', $string);
158 $string = str_replace("\331", '&#217;', $string);
159 $string = str_replace("\332", '&#218;', $string);
160 $string = str_replace("\333", '&#219;', $string);
161 $string = str_replace("\334", '&#220;', $string);
162 $string = str_replace("\335", '&#221;', $string);
163 $string = str_replace("\336", '&#222;', $string);
164 $string = str_replace("\337", '&#223;', $string);
165 $string = str_replace("\340", '&#224;', $string);
166 $string = str_replace("\341", '&#225;', $string);
167 $string = str_replace("\342", '&#226;', $string);
168 $string = str_replace("\343", '&#227;', $string);
169 $string = str_replace("\344", '&#228;', $string);
170 $string = str_replace("\345", '&#229;', $string);
171 $string = str_replace("\346", '&#230;', $string);
172 $string = str_replace("\347", '&#231;', $string);
173 $string = str_replace("\350", '&#232;', $string);
174 $string = str_replace("\351", '&#233;', $string);
175 $string = str_replace("\352", '&#234;', $string);
176 $string = str_replace("\353", '&#235;', $string);
177 $string = str_replace("\354", '&#236;', $string);
178 $string = str_replace("\355", '&#237;', $string);
179 $string = str_replace("\356", '&#238;', $string);
180 $string = str_replace("\357", '&#239;', $string);
181 $string = str_replace("\360", '&#240;', $string);
182 $string = str_replace("\361", '&#241;', $string);
183 $string = str_replace("\362", '&#242;', $string);
184 $string = str_replace("\363", '&#243;', $string);
185 $string = str_replace("\364", '&#244;', $string);
186 $string = str_replace("\365", '&#245;', $string);
187 $string = str_replace("\366", '&#246;', $string);
188 $string = str_replace("\367", '&#247;', $string);
189 $string = str_replace("\370", '&#248;', $string);
190 $string = str_replace("\371", '&#249;', $string);
191 $string = str_replace("\372", '&#250;', $string);
192 $string = str_replace("\373", '&#251;', $string);
193 $string = str_replace("\374", '&#252;', $string);
194 $string = str_replace("\375", '&#253;', $string);
195 $string = str_replace("\376", '&#254;', $string);
196 $string = str_replace("\377", '&#255;', $string);
197 }
198 }
199
200 return ($string);
201 }
202
203 /* iso-8859-2 is used for some eastern European languages */
204 function charset_decode_iso_8859_2 ($string) {
205 global $default_charset;
206
207 if (strtolower($default_charset) == 'iso-8859-2')
208 return $string;
209
210 /* Only do the slow convert if there are 8-bit characters */
211 if (! ereg("[\200-\377]", $string))
212 return $string;
213
214 /* NO-BREAK SPACE */
215 $string = str_replace("\240", '&#160;', $string);
216 /* LATIN CAPITAL LETTER A WITH OGONEK */
217 $string = str_replace("\241", '&#260;', $string);
218 /* BREVE */
219 $string = str_replace("\242", '&#728;', $string);
220 // LATIN CAPITAL LETTER L WITH STROKE
221 $string = str_replace("\243", '&#321;', $string);
222 // CURRENCY SIGN
223 $string = str_replace("\244", '&#164;', $string);
224 // LATIN CAPITAL LETTER L WITH CARON
225 $string = str_replace("\245", '&#317;', $string);
226 // LATIN CAPITAL LETTER S WITH ACUTE
227 $string = str_replace("\246", '&#346;', $string);
228 // SECTION SIGN
229 $string = str_replace("\247", '&#167;', $string);
230 // DIAERESIS
231 $string = str_replace("\250", '&#168;', $string);
232 // LATIN CAPITAL LETTER S WITH CARON
233 $string = str_replace("\251", '&#352;', $string);
234 // LATIN CAPITAL LETTER S WITH CEDILLA
235 $string = str_replace("\252", '&#350;', $string);
236 // LATIN CAPITAL LETTER T WITH CARON
237 $string = str_replace("\253", '&#356;', $string);
238 // LATIN CAPITAL LETTER Z WITH ACUTE
239 $string = str_replace("\254", '&#377;', $string);
240 // SOFT HYPHEN
241 $string = str_replace("\255", '&#173;', $string);
242 // LATIN CAPITAL LETTER Z WITH CARON
243 $string = str_replace("\256", '&#381;', $string);
244 // LATIN CAPITAL LETTER Z WITH DOT ABOVE
245 $string = str_replace("\257", '&#379;', $string);
246 // DEGREE SIGN
247 $string = str_replace("\260", '&#176;', $string);
248 // LATIN SMALL LETTER A WITH OGONEK
249 $string = str_replace("\261", '&#261;', $string);
250 // OGONEK
251 $string = str_replace("\262", '&#731;', $string);
252 // LATIN SMALL LETTER L WITH STROKE
253 $string = str_replace("\263", '&#322;', $string);
254 // ACUTE ACCENT
255 $string = str_replace("\264", '&#180;', $string);
256 // LATIN SMALL LETTER L WITH CARON
257 $string = str_replace("\265", '&#318;', $string);
258 // LATIN SMALL LETTER S WITH ACUTE
259 $string = str_replace("\266", '&#347;', $string);
260 // CARON
261 $string = str_replace("\267", '&#711;', $string);
262 // CEDILLA
263 $string = str_replace("\270", '&#184;', $string);
264 // LATIN SMALL LETTER S WITH CARON
265 $string = str_replace("\271", '&#353;', $string);
266 // LATIN SMALL LETTER S WITH CEDILLA
267 $string = str_replace("\272", '&#351;', $string);
268 // LATIN SMALL LETTER T WITH CARON
269 $string = str_replace("\273", '&#357;', $string);
270 // LATIN SMALL LETTER Z WITH ACUTE
271 $string = str_replace("\274", '&#378;', $string);
272 // DOUBLE ACUTE ACCENT
273 $string = str_replace("\275", '&#733;', $string);
274 // LATIN SMALL LETTER Z WITH CARON
275 $string = str_replace("\276", '&#382;', $string);
276 // LATIN SMALL LETTER Z WITH DOT ABOVE
277 $string = str_replace("\277", '&#380;', $string);
278 // LATIN CAPITAL LETTER R WITH ACUTE
279 $string = str_replace("\300", '&#340;', $string);
280 // LATIN CAPITAL LETTER A WITH ACUTE
281 $string = str_replace("\301", '&#193;', $string);
282 // LATIN CAPITAL LETTER A WITH CIRCUMFLEX
283 $string = str_replace("\302", '&#194;', $string);
284 // LATIN CAPITAL LETTER A WITH BREVE
285 $string = str_replace("\303", '&#258;', $string);
286 // LATIN CAPITAL LETTER A WITH DIAERESIS
287 $string = str_replace("\304", '&#196;', $string);
288 // LATIN CAPITAL LETTER L WITH ACUTE
289 $string = str_replace("\305", '&#313;', $string);
290 // LATIN CAPITAL LETTER C WITH ACUTE
291 $string = str_replace("\306", '&#262;', $string);
292 // LATIN CAPITAL LETTER C WITH CEDILLA
293 $string = str_replace("\307", '&#199;', $string);
294 // LATIN CAPITAL LETTER C WITH CARON
295 $string = str_replace("\310", '&#268;', $string);
296 // LATIN CAPITAL LETTER E WITH ACUTE
297 $string = str_replace("\311", '&#201;', $string);
298 // LATIN CAPITAL LETTER E WITH OGONEK
299 $string = str_replace("\312", '&#280;', $string);
300 // LATIN CAPITAL LETTER E WITH DIAERESIS
301 $string = str_replace("\313", '&#203;', $string);
302 // LATIN CAPITAL LETTER E WITH CARON
303 $string = str_replace("\314", '&#282;', $string);
304 // LATIN CAPITAL LETTER I WITH ACUTE
305 $string = str_replace("\315", '&#205;', $string);
306 // LATIN CAPITAL LETTER I WITH CIRCUMFLEX
307 $string = str_replace("\316", '&#206;', $string);
308 // LATIN CAPITAL LETTER D WITH CARON
309 $string = str_replace("\317", '&#270;', $string);
310 // LATIN CAPITAL LETTER D WITH STROKE
311 $string = str_replace("\320", '&#272;', $string);
312 // LATIN CAPITAL LETTER N WITH ACUTE
313 $string = str_replace("\321", '&#323;', $string);
314 // LATIN CAPITAL LETTER N WITH CARON
315 $string = str_replace("\322", '&#327;', $string);
316 // LATIN CAPITAL LETTER O WITH ACUTE
317 $string = str_replace("\323", '&#211;', $string);
318 // LATIN CAPITAL LETTER O WITH CIRCUMFLEX
319 $string = str_replace("\324", '&#212;', $string);
320 // LATIN CAPITAL LETTER O WITH DOUBLE ACUTE
321 $string = str_replace("\325", '&#336;', $string);
322 // LATIN CAPITAL LETTER O WITH DIAERESIS
323 $string = str_replace("\326", '&#214;', $string);
324 // MULTIPLICATION SIGN
325 $string = str_replace("\327", '&#215;', $string);
326 // LATIN CAPITAL LETTER R WITH CARON
327 $string = str_replace("\330", '&#344;', $string);
328 // LATIN CAPITAL LETTER U WITH RING ABOVE
329 $string = str_replace("\331", '&#366;', $string);
330 // LATIN CAPITAL LETTER U WITH ACUTE
331 $string = str_replace("\332", '&#218;', $string);
332 // LATIN CAPITAL LETTER U WITH DOUBLE ACUTE
333 $string = str_replace("\333", '&#368;', $string);
334 // LATIN CAPITAL LETTER U WITH DIAERESIS
335 $string = str_replace("\334", '&#220;', $string);
336 // LATIN CAPITAL LETTER Y WITH ACUTE
337 $string = str_replace("\335", '&#221;', $string);
338 // LATIN CAPITAL LETTER T WITH CEDILLA
339 $string = str_replace("\336", '&#354;', $string);
340 // LATIN SMALL LETTER SHARP S
341 $string = str_replace("\337", '&#223;', $string);
342 // LATIN SMALL LETTER R WITH ACUTE
343 $string = str_replace("\340", '&#341;', $string);
344 // LATIN SMALL LETTER A WITH ACUTE
345 $string = str_replace("\341", '&#225;', $string);
346 // LATIN SMALL LETTER A WITH CIRCUMFLEX
347 $string = str_replace("\342", '&#226;', $string);
348 // LATIN SMALL LETTER A WITH BREVE
349 $string = str_replace("\343", '&#259;', $string);
350 // LATIN SMALL LETTER A WITH DIAERESIS
351 $string = str_replace("\344", '&#228;', $string);
352 // LATIN SMALL LETTER L WITH ACUTE
353 $string = str_replace("\345", '&#314;', $string);
354 // LATIN SMALL LETTER C WITH ACUTE
355 $string = str_replace("\346", '&#263;', $string);
356 // LATIN SMALL LETTER C WITH CEDILLA
357 $string = str_replace("\347", '&#231;', $string);
358 // LATIN SMALL LETTER C WITH CARON
359 $string = str_replace("\350", '&#269;', $string);
360 // LATIN SMALL LETTER E WITH ACUTE
361 $string = str_replace("\351", '&#233;', $string);
362 // LATIN SMALL LETTER E WITH OGONEK
363 $string = str_replace("\352", '&#281;', $string);
364 // LATIN SMALL LETTER E WITH DIAERESIS
365 $string = str_replace("\353", '&#235;', $string);
366 // LATIN SMALL LETTER E WITH CARON
367 $string = str_replace("\354", '&#283;', $string);
368 // LATIN SMALL LETTER I WITH ACUTE
369 $string = str_replace("\355", '&#237;', $string);
370 // LATIN SMALL LETTER I WITH CIRCUMFLEX
371 $string = str_replace("\356", '&#238;', $string);
372 // LATIN SMALL LETTER D WITH CARON
373 $string = str_replace("\357", '&#271;', $string);
374 // LATIN SMALL LETTER D WITH STROKE
375 $string = str_replace("\360", '&#273;', $string);
376 // LATIN SMALL LETTER N WITH ACUTE
377 $string = str_replace("\361", '&#324;', $string);
378 // LATIN SMALL LETTER N WITH CARON
379 $string = str_replace("\362", '&#328;', $string);
380 // LATIN SMALL LETTER O WITH ACUTE
381 $string = str_replace("\363", '&#243;', $string);
382 // LATIN SMALL LETTER O WITH CIRCUMFLEX
383 $string = str_replace("\364", '&#244;', $string);
384 // LATIN SMALL LETTER O WITH DOUBLE ACUTE
385 $string = str_replace("\365", '&#337;', $string);
386 // LATIN SMALL LETTER O WITH DIAERESIS
387 $string = str_replace("\366", '&#246;', $string);
388 // DIVISION SIGN
389 $string = str_replace("\367", '&#247;', $string);
390 // LATIN SMALL LETTER R WITH CARON
391 $string = str_replace("\370", '&#345;', $string);
392 // LATIN SMALL LETTER U WITH RING ABOVE
393 $string = str_replace("\371", '&#367;', $string);
394 // LATIN SMALL LETTER U WITH ACUTE
395 $string = str_replace("\372", '&#250;', $string);
396 // LATIN SMALL LETTER U WITH DOUBLE ACUTE
397 $string = str_replace("\373", '&#369;', $string);
398 // LATIN SMALL LETTER U WITH DIAERESIS
399 $string = str_replace("\374", '&#252;', $string);
400 // LATIN SMALL LETTER Y WITH ACUTE
401 $string = str_replace("\375", '&#253;', $string);
402 // LATIN SMALL LETTER T WITH CEDILLA
403 $string = str_replace("\376", '&#355;', $string);
404 // DOT ABOVE
405 $string = str_replace("\377", '&#729;', $string);
406
407 return $string;
408 }
409
410 /*
411 iso-8859-4 is Baltic codeset used in some email clients
412 instead of iso-8859-13 in Lithuania
413 only Lithuanian charactes are added.
414 */
415
416 function charset_decode_iso_8859_4 ($string) {
417 // latin capital a with ogonek
418 $string = str_replace ("\241", '&#0260;', $string);
419 // latin capital c with caron
420 $string = str_replace ("\310", '&#0268;', $string);
421 // latin capital e with ogonek
422 $string = str_replace ("\312", '&#0280;', $string);
423 // latin capital e with dot above
424 $string = str_replace ("\314", '&#0278;', $string);
425 // latin capital i with ogonek
426 $string = str_replace ("\307", '&#0302;', $string);
427 // latin capital s with caron
428 $string = str_replace ("\251", '&#0352;', $string);
429 // latin capital u with ogonek
430 $string = str_replace ("\331", '&#0370;', $string);
431 // latin capital u with macron
432 $string = str_replace ("\336", '&#0362;', $string);
433 // latin capital z with caron
434 $string = str_replace ("\256", '&#0381;', $string);
435 // latin small a with ogonek
436 $string = str_replace ("\261", '&#0261;', $string);
437 // latin small c with caron
438 $string = str_replace ("\350", '&#0269;', $string);
439 // latin small e with ogonek
440 $string = str_replace ("\352", '&#0281;', $string);
441 // latin small e with dot above
442 $string = str_replace ("\354", '&#0279;', $string);
443 // latin small i with ogonek
444 $string = str_replace ("\347", '&#0303;', $string);
445 // latin small s with caron
446 $string = str_replace ("\271", '&#0353;', $string);
447 // latin small u with ogonek
448 $string = str_replace ("\371", '&#0371;', $string);
449 // latin small u with macron
450 $string = str_replace ("\376", '&#0363;', $string);
451 // latin small z with caron
452 $string = str_replace ("\276", '&#0382;', $string);
453
454 return (charset_decode_iso_8859_1($string));
455 }
456
457 /* iso-8859-7 is Greek. */
458 function charset_decode_iso_8859_7 ($string) {
459 global $default_charset;
460
461 if (strtolower($default_charset) == 'iso-8859-7') {
462 return $string;
463 }
464
465 /* Only do the slow convert if there are 8-bit characters */
466 if (!ereg("[\200-\377]", $string)) {
467 return $string;
468 }
469
470 /* Some diverse characters in the beginning */
471 $string = str_replace("\240", '&#160;', $string);
472 $string = str_replace("\241", '&#8216;', $string);
473 $string = str_replace("\242", '&#8217;', $string);
474 $string = str_replace("\243", '&#163;', $string);
475 $string = str_replace("\246", '&#166;', $string);
476 $string = str_replace("\247", '&#167;', $string);
477 $string = str_replace("\250", '&#168;', $string);
478 $string = str_replace("\251", '&#169;', $string);
479 $string = str_replace("\253", '&#171;', $string);
480 $string = str_replace("\254", '&#172;', $string);
481 $string = str_replace("\255", '&#173;', $string);
482 $string = str_replace("\257", '&#8213;', $string);
483 $string = str_replace("\260", '&#176;', $string);
484 $string = str_replace("\261", '&#177;', $string);
485 $string = str_replace("\262", '&#178;', $string);
486 $string = str_replace("\263", '&#179;', $string);
487
488 /* Horizontal bar (parentheki pavla) */
489 $string = str_replace ("\257", '&#8213;', $string);
490
491 /*
492 * ISO-8859-7 characters from 11/04 (0xB4) to 11/06 (0xB6)
493 * These are Unicode 900-902
494 */
495 $string = preg_replace("/([\264-\266])/e","'&#' . (ord(\\1)+720)",$string);
496
497 /* 11/07 (0xB7) Middle dot is the same in iso-8859-1 */
498 $string = str_replace("\267", '&#183;', $string);
499
500 /*
501 * ISO-8859-7 characters from 11/08 (0xB8) to 11/10 (0xBA)
502 * These are Unicode 900-902
503 */
504 $string = preg_replace("/([\270-\272])/e","'&#' . (ord(\\1)+720)",$string);
505
506 /*
507 * 11/11 (0xBB) Right angle quotation mark is the same as in
508 * iso-8859-1
509 */
510 $string = str_replace("\273", '&#187;', $string);
511
512 /* And now the rest of the charset */
513 $string = preg_replace("/([\274-\376])/e","'&#' . (ord(\\1)+720)",$string);
514
515 return $string;
516 }
517
518 /*
519 iso-8859-13 codeset used in Lithuania
520 only Lithuanian charactes are added.
521 */
522
523 function charset_decode_iso_8859_13 ($string) {
524 // latin capital a with ogonek
525 $string = str_replace ("\300", '&#0260;', $string);
526 // latin capital c with caron
527 $string = str_replace ("\310", '&#0268;', $string);
528 // latin capital e with ogonek
529 $string = str_replace ("\306", '&#0280;', $string);
530 // latin capital e with dot above
531 $string = str_replace ("\313", '&#0278;', $string);
532 // latin capital i with ogonek
533 $string = str_replace ("\301", '&#0302;', $string);
534 // latin capital s with caron
535 $string = str_replace ("\320", '&#0352;', $string);
536 // latin capital u with ogonek
537 $string = str_replace ("\330", '&#0370;', $string);
538 // latin capital u with macron
539 $string = str_replace ("\333", '&#0362;', $string);
540 // latin capital z with caron
541 $string = str_replace ("\336", '&#0381;', $string);
542 // latin small a with ogonek
543 $string = str_replace ("\340", '&#0261;', $string);
544 // latin small c with caron
545 $string = str_replace ("\350", '&#0269;', $string);
546 // latin small e with ogonek
547 $string = str_replace ("\346", '&#0281;', $string);
548 // latin small e with dot above
549 $string = str_replace ("\353", '&#0279;', $string);
550 // latin small i with ogonek
551 $string = str_replace ("\341", '&#0303;', $string);
552 // latin small s with caron
553 $string = str_replace ("\360", '&#0353;', $string);
554 // latin small u with ogonek
555 $string = str_replace ("\370", '&#0371;', $string);
556 // latin small u with macron
557 $string = str_replace ("\373", '&#0363;', $string);
558 // latin small z with caron
559 $string = str_replace ("\376", '&#0382;', $string);
560
561 return (charset_decode_iso_8859_1($string));
562 }
563
564 /*
565 * iso-8859-15 is Latin 9 and has very much the same use as Latin 1
566 * but has the Euro symbol and some characters needed for French.
567 */
568 function charset_decode_iso_8859_15 ($string) {
569 // Euro sign
570 $string = str_replace ("\244", '&#8364;', $string);
571 // Latin capital letter S with caron
572 $string = str_replace ("\246", '&#352;', $string);
573 // Latin small letter s with caron
574 $string = str_replace ("\250", '&#353;', $string);
575 // Latin capital letter Z with caron
576 $string = str_replace ("\264", '&#381;', $string);
577 // Latin small letter z with caron
578 $string = str_replace ("\270", '&#382;', $string);
579 // Latin capital ligature OE
580 $string = str_replace ("\274", '&#338;', $string);
581 // Latin small ligature oe
582 $string = str_replace ("\275", '&#339;', $string);
583 // Latin capital letter Y with diaeresis
584 $string = str_replace ("\276", '&#376;', $string);
585
586 return (charset_decode_iso_8859_1($string));
587 }
588
589 /* ISO-8859-5 is Cyrillic */
590 function charset_decode_iso_8859_5 ($string) {
591 // Convert to KOI8-R, then return this decoded.
592 $string = convert_cyr_string($string, 'i', 'k');
593 return charset_decode_koi8r($string);
594 }
595
596 /* Remove all 8 bit characters from all other ISO-8859 character sets */
597 function charset_decode_iso_8859_default ($string) {
598 return (strtr($string, "\240\241\242\243\244\245\246\247".
599 "\250\251\252\253\254\255\256\257".
600 "\260\261\262\263\264\265\266\267".
601 "\270\271\272\273\274\275\276\277".
602 "\300\301\302\303\304\305\306\307".
603 "\310\311\312\313\314\315\316\317".
604 "\320\321\322\323\324\325\326\327".
605 "\330\331\332\333\334\335\336\337".
606 "\340\341\342\343\344\345\346\347".
607 "\350\351\352\353\354\355\356\357".
608 "\360\361\362\363\364\365\366\367".
609 "\370\371\372\373\374\375\376\377",
610 "????????????????????????????????????????".
611 "????????????????????????????????????????".
612 "????????????????????????????????????????".
613 "????????"));
614
615 }
616
617 /*
618 * This is the same as ISO-646-NO and is used by some
619 * Microsoft programs when sending Norwegian characters
620 */
621 function charset_decode_ns_4551_1 ($string) {
622 /*
623 * These characters are:
624 * Latin capital letter AE
625 * Latin capital letter O with stroke
626 * Latin capital letter A with ring above
627 * and the same as small letters
628 */
629 return strtr ($string, "[\\]{|}", "ÆØÅæøå");
630 }
631
632 /*
633 * KOI8-R is used to encode Russian mail (Cyrrilic). Defined in RFC
634 * 1489.
635 */
636 function charset_decode_koi8r ($string) {
637 global $default_charset;
638
639 if ($default_charset == 'koi8-r') {
640 return $string;
641 }
642
643 /*
644 * Convert to Unicode HTML entities.
645 * This code is rather ineffective.
646 */
647 $string = str_replace("\200", '&#9472;', $string);
648 $string = str_replace("\201", '&#9474;', $string);
649 $string = str_replace("\202", '&#9484;', $string);
650 $string = str_replace("\203", '&#9488;', $string);
651 $string = str_replace("\204", '&#9492;', $string);
652 $string = str_replace("\205", '&#9496;', $string);
653 $string = str_replace("\206", '&#9500;', $string);
654 $string = str_replace("\207", '&#9508;', $string);
655 $string = str_replace("\210", '&#9516;', $string);
656 $string = str_replace("\211", '&#9524;', $string);
657 $string = str_replace("\212", '&#9532;', $string);
658 $string = str_replace("\213", '&#9600;', $string);
659 $string = str_replace("\214", '&#9604;', $string);
660 $string = str_replace("\215", '&#9608;', $string);
661 $string = str_replace("\216", '&#9612;', $string);
662 $string = str_replace("\217", '&#9616;', $string);
663 $string = str_replace("\220", '&#9617;', $string);
664 $string = str_replace("\221", '&#9618;', $string);
665 $string = str_replace("\222", '&#9619;', $string);
666 $string = str_replace("\223", '&#8992;', $string);
667 $string = str_replace("\224", '&#9632;', $string);
668 $string = str_replace("\225", '&#8729;', $string);
669 $string = str_replace("\226", '&#8730;', $string);
670 $string = str_replace("\227", '&#8776;', $string);
671 $string = str_replace("\230", '&#8804;', $string);
672 $string = str_replace("\231", '&#8805;', $string);
673 $string = str_replace("\232", '&#160;', $string);
674 $string = str_replace("\233", '&#8993;', $string);
675 $string = str_replace("\234", '&#176;', $string);
676 $string = str_replace("\235", '&#178;', $string);
677 $string = str_replace("\236", '&#183;', $string);
678 $string = str_replace("\237", '&#247;', $string);
679 $string = str_replace("\240", '&#9552;', $string);
680 $string = str_replace("\241", '&#9553;', $string);
681 $string = str_replace("\242", '&#9554;', $string);
682 $string = str_replace("\243", '&#1105;', $string);
683 $string = str_replace("\244", '&#9555;', $string);
684 $string = str_replace("\245", '&#9556;', $string);
685 $string = str_replace("\246", '&#9557;', $string);
686 $string = str_replace("\247", '&#9558;', $string);
687 $string = str_replace("\250", '&#9559;', $string);
688 $string = str_replace("\251", '&#9560;', $string);
689 $string = str_replace("\252", '&#9561;', $string);
690 $string = str_replace("\253", '&#9562;', $string);
691 $string = str_replace("\254", '&#9563;', $string);
692 $string = str_replace("\255", '&#9564;', $string);
693 $string = str_replace("\256", '&#9565;', $string);
694 $string = str_replace("\257", '&#9566;', $string);
695 $string = str_replace("\260", '&#9567;', $string);
696 $string = str_replace("\261", '&#9568;', $string);
697 $string = str_replace("\262", '&#9569;', $string);
698 $string = str_replace("\263", '&#1025;', $string);
699 $string = str_replace("\264", '&#9570;', $string);
700 $string = str_replace("\265", '&#9571;', $string);
701 $string = str_replace("\266", '&#9572;', $string);
702 $string = str_replace("\267", '&#9573;', $string);
703 $string = str_replace("\270", '&#9574;', $string);
704 $string = str_replace("\271", '&#9575;', $string);
705 $string = str_replace("\272", '&#9576;', $string);
706 $string = str_replace("\273", '&#9577;', $string);
707 $string = str_replace("\274", '&#9578;', $string);
708 $string = str_replace("\275", '&#9579;', $string);
709 $string = str_replace("\276", '&#9580;', $string);
710 $string = str_replace("\277", '&#169;', $string);
711 $string = str_replace("\300", '&#1102;', $string);
712 $string = str_replace("\301", '&#1072;', $string);
713 $string = str_replace("\302", '&#1073;', $string);
714 $string = str_replace("\303", '&#1094;', $string);
715 $string = str_replace("\304", '&#1076;', $string);
716 $string = str_replace("\305", '&#1077;', $string);
717 $string = str_replace("\306", '&#1092;', $string);
718 $string = str_replace("\307", '&#1075;', $string);
719 $string = str_replace("\310", '&#1093;', $string);
720 $string = str_replace("\311", '&#1080;', $string);
721 $string = str_replace("\312", '&#1081;', $string);
722 $string = str_replace("\313", '&#1082;', $string);
723 $string = str_replace("\314", '&#1083;', $string);
724 $string = str_replace("\315", '&#1084;', $string);
725 $string = str_replace("\316", '&#1085;', $string);
726 $string = str_replace("\317", '&#1086;', $string);
727 $string = str_replace("\320", '&#1087;', $string);
728 $string = str_replace("\321", '&#1103;', $string);
729 $string = str_replace("\322", '&#1088;', $string);
730 $string = str_replace("\323", '&#1089;', $string);
731 $string = str_replace("\324", '&#1090;', $string);
732 $string = str_replace("\325", '&#1091;', $string);
733 $string = str_replace("\326", '&#1078;', $string);
734 $string = str_replace("\327", '&#1074;', $string);
735 $string = str_replace("\330", '&#1100;', $string);
736 $string = str_replace("\331", '&#1099;', $string);
737 $string = str_replace("\332", '&#1079;', $string);
738 $string = str_replace("\333", '&#1096;', $string);
739 $string = str_replace("\334", '&#1101;', $string);
740 $string = str_replace("\335", '&#1097;', $string);
741 $string = str_replace("\336", '&#1095;', $string);
742 $string = str_replace("\337", '&#1098;', $string);
743 $string = str_replace("\340", '&#1070;', $string);
744 $string = str_replace("\341", '&#1040;', $string);
745 $string = str_replace("\342", '&#1041;', $string);
746 $string = str_replace("\343", '&#1062;', $string);
747 $string = str_replace("\344", '&#1044;', $string);
748 $string = str_replace("\345", '&#1045;', $string);
749 $string = str_replace("\346", '&#1060;', $string);
750 $string = str_replace("\347", '&#1043;', $string);
751 $string = str_replace("\350", '&#1061;', $string);
752 $string = str_replace("\351", '&#1048;', $string);
753 $string = str_replace("\352", '&#1049;', $string);
754 $string = str_replace("\353", '&#1050;', $string);
755 $string = str_replace("\354", '&#1051;', $string);
756 $string = str_replace("\355", '&#1052;', $string);
757 $string = str_replace("\356", '&#1053;', $string);
758 $string = str_replace("\357", '&#1054;', $string);
759 $string = str_replace("\360", '&#1055;', $string);
760 $string = str_replace("\361", '&#1071;', $string);
761 $string = str_replace("\362", '&#1056;', $string);
762 $string = str_replace("\363", '&#1057;', $string);
763 $string = str_replace("\364", '&#1058;', $string);
764 $string = str_replace("\365", '&#1059;', $string);
765 $string = str_replace("\366", '&#1046;', $string);
766 $string = str_replace("\367", '&#1042;', $string);
767 $string = str_replace("\370", '&#1068;', $string);
768 $string = str_replace("\371", '&#1067;', $string);
769 $string = str_replace("\372", '&#1047;', $string);
770 $string = str_replace("\373", '&#1064;', $string);
771 $string = str_replace("\374", '&#1069;', $string);
772 $string = str_replace("\375", '&#1065;', $string);
773 $string = str_replace("\376", '&#1063;', $string);
774 $string = str_replace("\377", '&#1066;', $string);
775
776 return $string;
777 }
778
779
780 /*
781 * Set up the language to be output
782 * if $do_search is true, then scan the browser information
783 * for a possible language that we know
784 */
785 function set_up_language($sm_language, $do_search = false) {
786
787 static $SetupAlready = 0;
788 global $use_gettext, $languages,
789 $squirrelmail_language, $squirrelmail_default_language,
790 $sm_notAlias;
791
792 if ($SetupAlready) {
793 return;
794 }
795 $SetupAlready = TRUE;
796
797 if ($do_search && ! $sm_language && isset($_SERVER['HTTP_ACCEPT_LANGUAGE'])) {
798 $sm_language = substr($_SERVER['HTTP_ACCEPT_LANGUAGE'], 0, 2);
799 }
800
801 if (!$sm_language && isset($squirrelmail_default_language)) {
802 $squirrelmail_language = $squirrelmail_default_language;
803 $sm_language = $squirrelmail_default_language;
804 }
805 $sm_notAlias = $sm_language;
806 while (isset($languages[$sm_notAlias]['ALIAS'])) {
807 $sm_notAlias = $languages[$sm_notAlias]['ALIAS'];
808 }
809
810 if ( isset($sm_language) &&
811 $use_gettext &&
812 $sm_language != '' &&
813 isset($languages[$sm_notAlias]['CHARSET']) ) {
814 bindtextdomain( 'squirrelmail', '../locale/' );
815 textdomain( 'squirrelmail' );
816 if ( !ini_get('safe_mode') &&
817 getenv( 'LC_ALL' ) != $sm_notAlias ) {
818 putenv( "LC_ALL=$sm_notAlias" );
819 putenv( "LANG=$sm_notAlias" );
820 putenv( "LANGUAGE=$sm_notAlias" );
821 }
822 setlocale(LC_ALL, $sm_notAlias);
823 $squirrelmail_language = $sm_notAlias;
824 if ($squirrelmail_language == 'ja_JP' && function_exists('mb_detect_encoding') ) {
825 header ('Content-Type: text/html; charset=EUC-JP');
826 if (!function_exists('mb_internal_encoding')) {
827 echo _("You need to have php4 installed with the multibyte string function enabled (using configure option --with-mbstring).");
828 }
829 mb_internal_encoding('EUC-JP');
830 mb_http_output('pass');
831 } else {
832 header( 'Content-Type: text/html; charset=' . $languages[$sm_notAlias]['CHARSET'] );
833 }
834 }
835 }
836
837 function set_my_charset(){
838
839 /*
840 * There can be a $default_charset setting in the
841 * config.php file, but the user may have a different language
842 * selected for a user interface. This function checks the
843 * language selected by the user and tags the outgoing messages
844 * with the appropriate charset corresponding to the language
845 * selection. This is "more right" (tm), than just stamping the
846 * message blindly with the system-wide $default_charset.
847 */
848 global $data_dir, $username, $default_charset, $languages;
849
850 $my_language = getPref($data_dir, $username, 'language');
851 if (!$my_language) {
852 return;
853 }
854 while (isset($languages[$my_language]['ALIAS'])) {
855 $my_language = $languages[$my_language]['ALIAS'];
856 }
857 $my_charset = $languages[$my_language]['CHARSET'];
858 if ($my_charset) {
859 $default_charset = $my_charset;
860 }
861 }
862
863 /* ------------------------------ main --------------------------- */
864
865 global $squirrelmail_language, $languages, $use_gettext;
866
867 if (! isset($squirrelmail_language)) {
868 $squirrelmail_language = '';
869 }
870
871 /* This array specifies the available languages. */
872
873 // The glibc locale is ca_ES.
874
875 $languages['ca_ES']['NAME'] = 'Catalan';
876 $languages['ca_ES']['CHARSET'] = 'iso-8859-1';
877 $languages['ca']['ALIAS'] = 'ca_ES';
878
879 $languages['cs_CZ']['NAME'] = 'Czech';
880 $languages['cs_CZ']['CHARSET'] = 'iso-8859-2';
881 $languages['cs']['ALIAS'] = 'cs_CZ';
882
883 // Danish locale is da_DK.
884
885 $languages['da_DK']['NAME'] = 'Danish';
886 $languages['da_DK']['CHARSET'] = 'iso-8859-1';
887 $languages['da']['ALIAS'] = 'da_DK';
888
889 $languages['de_DE']['NAME'] = 'Deutsch';
890 $languages['de_DE']['CHARSET'] = 'iso-8859-1';
891 $languages['de']['ALIAS'] = 'de_DE';
892
893 // There is no en_EN! There is en_US, en_BR, en_AU, and so forth,
894 // but who cares about !US, right? Right? :)
895
896 $languages['en_US']['NAME'] = 'English';
897 $languages['en_US']['CHARSET'] = 'iso-8859-1';
898 $languages['en']['ALIAS'] = 'en_US';
899
900 $languages['es_ES']['NAME'] = 'Spanish';
901 $languages['es_ES']['CHARSET'] = 'iso-8859-1';
902 $languages['es']['ALIAS'] = 'es_ES';
903
904 $languages['et_EE']['NAME'] = 'Estonian';
905 $languages['et_EE']['CHARSET'] = 'iso-8859-15';
906 $languages['et']['ALIAS'] = 'et_EE';
907
908 $languages['fi_FI']['NAME'] = 'Finnish';
909 $languages['fi_FI']['CHARSET'] = 'iso-8859-1';
910 $languages['fi']['ALIAS'] = 'fi_FI';
911
912 $languages['fr_FR']['NAME'] = 'French';
913 $languages['fr_FR']['CHARSET'] = 'iso-8859-1';
914 $languages['fr']['ALIAS'] = 'fr_FR';
915
916 $languages['hr_HR']['NAME'] = 'Croatian';
917 $languages['hr_HR']['CHARSET'] = 'iso-8859-2';
918 $languages['hr']['ALIAS'] = 'hr_HR';
919
920 $languages['hu_HU']['NAME'] = 'Hungarian';
921 $languages['hu_HU']['CHARSET'] = 'iso-8859-2';
922 $languages['hu']['ALIAS'] = 'hu_HU';
923
924 $languages['id_ID']['NAME'] = 'Indonesian';
925 $languages['id_ID']['CHARSET'] = 'iso-8859-1';
926 $languages['id']['ALIAS'] = 'id_ID';
927
928 $languages['is_IS']['NAME'] = 'Icelandic';
929 $languages['is_IS']['CHARSET'] = 'iso-8859-1';
930 $languages['is']['ALIAS'] = 'is_IS';
931
932 $languages['it_IT']['NAME'] = 'Italian';
933 $languages['it_IT']['CHARSET'] = 'iso-8859-1';
934 $languages['it']['ALIAS'] = 'it_IT';
935
936 $languages['ja_JP']['NAME'] = 'Japanese';
937 $languages['ja_JP']['CHARSET'] = 'iso-2022-jp';
938 $languages['ja_JP']['XTRA_CODE'] = 'japanese_charset_xtra';
939 $languages['ja']['ALIAS'] = 'ja_JP';
940
941 $languages['ko_KR']['NAME'] = 'Korean';
942 $languages['ko_KR']['CHARSET'] = 'euc-KR';
943 $languages['ko_KR']['XTRA_CODE'] = 'korean_charset_xtra';
944 $languages['ko']['ALIAS'] = 'ko_KR';
945
946 $languages['nl_NL']['NAME'] = 'Dutch';
947 $languages['nl_NL']['CHARSET'] = 'iso-8859-1';
948 $languages['nl']['ALIAS'] = 'nl_NL';
949
950 $languages['no_NO']['NAME'] = 'Norwegian (Bokm&aring;l)';
951 $languages['no_NO']['CHARSET'] = 'iso-8859-1';
952 $languages['no']['ALIAS'] = 'no_NO';
953 $languages['nn_NO']['NAME'] = 'Norwegian (Nynorsk)';
954 $languages['nn_NO']['CHARSET'] = 'iso-8859-1';
955
956 $languages['pl_PL']['NAME'] = 'Polish';
957 $languages['pl_PL']['CHARSET'] = 'iso-8859-2';
958 $languages['pl']['ALIAS'] = 'pl_PL';
959
960 $languages['pt_PT']['NAME'] = 'Portuguese (Portugal)';
961 $languages['pt_PT']['CHARSET'] = 'iso-8859-1';
962 $languages['pt_BR']['NAME'] = 'Portuguese (Brazil)';
963 $languages['pt_BR']['CHARSET'] = 'iso-8859-1';
964 $languages['pt']['ALIAS'] = 'pt_PT';
965
966 $languages['ru_RU']['NAME'] = 'Russian';
967 $languages['ru_RU']['CHARSET'] = 'koi8-r';
968 $languages['ru']['ALIAS'] = 'ru_RU';
969
970 $languages['sr_YU']['NAME'] = 'Serbian';
971 $languages['sr_YU']['CHARSET'] = 'iso-8859-2';
972 $languages['sr']['ALIAS'] = 'sr_YU';
973
974 $languages['sv_SE']['NAME'] = 'Swedish';
975 $languages['sv_SE']['CHARSET'] = 'iso-8859-1';
976 $languages['sv']['ALIAS'] = 'sv_SE';
977
978 $languages['tr_TR']['NAME'] = 'Turkish';
979 $languages['tr_TR']['CHARSET'] = 'iso-8859-9';
980 $languages['tr']['ALIAS'] = 'tr_TR';
981
982 $languages['zh_TW']['NAME'] = 'Taiwan';
983 $languages['zh_TW']['CHARSET'] = 'big5';
984 $languages['tw']['ALIAS'] = 'zh_TW';
985
986 $languages['zh_TW']['NAME'] = 'Chinese';
987 $languages['zh_TW']['CHARSET'] = 'gb2312';
988 $languages['tw']['ALIAS'] = 'zh_CN';
989
990 $languages['sk_SK']['NAME'] = 'Slovak';
991 $languages['sk_SK']['CHARSET'] = 'iso-8859-2';
992 $languages['sk']['ALIAS'] = 'sk_SK';
993
994 $languages['ro_RO']['NAME'] = 'Romanian';
995 $languages['ro_RO']['CHARSET'] = 'iso-8859-2';
996 $languages['ro']['ALIAS'] = 'ro_RO';
997
998 $languages['th_TH']['NAME'] = 'Thai';
999 $languages['th_TH']['CHARSET'] = 'tis-620';
1000 $languages['th']['ALIAS'] = 'th_TH';
1001
1002 $languages['lt_LT']['NAME'] = 'Lithuanian';
1003 $languages['lt_LT']['CHARSET'] = 'iso-8859-13';
1004 $languages['lt']['ALIAS'] = 'lt_LT';
1005
1006 $languages['sl_SI']['NAME'] = 'Slovenian';
1007 $languages['sl_SI']['CHARSET'] = 'iso-8859-2';
1008 $languages['sl']['ALIAS'] = 'sl_SI';
1009
1010 $languages['bg_BG']['NAME'] = 'Bulgarian';
1011 $languages['bg_BG']['CHARSET'] = 'windows-1251';
1012 $languages['bg']['ALIAS'] = 'bg_BG';
1013
1014 // Right to left languages
1015
1016 $languages['he_HE']['NAME'] = 'Hebrew';
1017 $languages['he_HE']['CHARSET'] = 'windows-1255';
1018 $languages['he_HE']['DIR'] = 'rtl';
1019 $languages['he']['ALIAS'] = 'he_HE';
1020
1021
1022 /* Detect whether gettext is installed. */
1023 $gettext_flags = 0;
1024 if (function_exists('_')) {
1025 $gettext_flags += 1;
1026 }
1027 if (function_exists('bindtextdomain')) {
1028 $gettext_flags += 2;
1029 }
1030 if (function_exists('textdomain')) {
1031 $gettext_flags += 4;
1032 }
1033
1034 /* If gettext is fully loaded, cool */
1035 if ($gettext_flags == 7) {
1036 $use_gettext = true;
1037 }
1038 /* If we can fake gettext, try that */
1039 elseif ($gettext_flags == 0) {
1040 $use_gettext = true;
1041 include_once(SM_PATH . 'functions/gettext.php');
1042 } else {
1043 /* Uh-ho. A weird install */
1044 if (! $gettext_flags & 1) {
1045 function _($str) {
1046 return $str;
1047 }
1048 }
1049 if (! $gettext_flags & 2) {
1050 function bindtextdomain() {
1051 return;
1052 }
1053 }
1054 if (! $gettext_flags & 4) {
1055 function textdomain() {
1056 return;
1057 }
1058 }
1059 }
1060
1061
1062 /*
1063 * Japanese charset extra function
1064 *
1065 */
1066 function japanese_charset_xtra() {
1067 $ret = func_get_arg(1); /* default return value */
1068 if (function_exists('mb_detect_encoding')) {
1069 switch (func_get_arg(0)) { /* action */
1070 case 'decode':
1071 $detect_encoding = mb_detect_encoding($ret);
1072 if ($detect_encoding == 'JIS' ||
1073 $detect_encoding == 'EUC-JP' ||
1074 $detect_encoding == 'SJIS') {
1075
1076 $ret = mb_convert_encoding($ret, 'EUC-JP', 'AUTO');
1077 }
1078 break;
1079 case 'encode':
1080 $detect_encoding = mb_detect_encoding($ret);
1081 if ($detect_encoding == 'JIS' ||
1082 $detect_encoding == 'EUC-JP' ||
1083 $detect_encoding == 'SJIS') {
1084
1085 $ret = mb_convert_encoding($ret, 'JIS', 'AUTO');
1086 }
1087 break;
1088 case 'strimwidth':
1089 $width = func_get_arg(2);
1090 $ret = mb_strimwidth($ret, 0, $width, '...');
1091 break;
1092 case 'encodeheader':
1093 $result = '';
1094 if (strlen($ret) > 0) {
1095 $tmpstr = mb_substr($ret, 0, 1);
1096 $prevcsize = strlen($tmpstr);
1097 for ($i = 1; $i < mb_strlen($ret); $i++) {
1098 $tmp = mb_substr($ret, $i, 1);
1099 if (strlen($tmp) == $prevcsize) {
1100 $tmpstr .= $tmp;
1101 } else {
1102 if ($prevcsize == 1) {
1103 $result .= $tmpstr;
1104 } else {
1105 $result .= mb_encode_mimeheader($tmpstr);
1106 }
1107 $tmpstr = $tmp;
1108 $prevcsize = strlen($tmp);
1109 }
1110 }
1111 if (strlen($tmpstr)) {
1112 if (strlen(mb_substr($tmpstr, 0, 1)) == 1)
1113 $result .= $tmpstr;
1114 else
1115 $result .= mb_encode_mimeheader($tmpstr);
1116 }
1117 }
1118 $ret = $result;
1119 //$ret = mb_encode_mimeheader($ret);
1120 break;
1121 case 'decodeheader':
1122 $ret = str_replace("\t", "", $ret);
1123 if (eregi('=\\?([^?]+)\\?(q|b)\\?([^?]+)\\?=', $ret))
1124 $ret = mb_decode_mimeheader($ret);
1125 $ret = mb_convert_encoding($ret, 'EUC-JP', 'AUTO');
1126 break;
1127 case 'downloadfilename':
1128 $useragent = func_get_arg(2);
1129 if (strstr($useragent, 'Windows') !== false ||
1130 strstr($useragent, 'Mac_') !== false) {
1131 $ret = mb_convert_encoding($ret, 'SJIS', 'AUTO');
1132 } else {
1133 $ret = mb_convert_encoding($ret, 'EUC-JP', 'AUTO');
1134 }
1135 break;
1136 }
1137 }
1138 return $ret;
1139 }
1140
1141
1142 /*
1143 * Korean charset extra function
1144 * Hangul(Korean Character) Attached File Name Fix.
1145 */
1146 function korean_charset_xtra() {
1147
1148 $ret = func_get_arg(1); /* default return value */
1149 if (func_get_arg(0) == 'downloadfilename') { /* action */
1150 $ret = str_replace("\x0D\x0A", '', $ret); /* Hanmail's CR/LF Clear */
1151 for ($i=0;$i<strlen($ret);$i++) {
1152 if ($ret[$i] >= "\xA1" && $ret[$i] <= "\xFE") { /* 0xA1 - 0XFE are Valid */
1153 $i++;
1154 continue;
1155 } else if (($ret[$i] >= 'a' && $ret[$i] <= 'z') || /* From Original ereg_replace in download.php */
1156 ($ret[$i] >= 'A' && $ret[$i] <= 'Z') ||
1157 ($ret[$i] == '.') || ($ret[$i] == '-')) {
1158 continue;
1159 } else {
1160 $ret[$i] = '_';
1161 }
1162 }
1163
1164 }
1165
1166 return $ret;
1167 }
1168
1169 ?>