59177427 |
1 | <?php |
1fd97780 |
2 | |
35586184 |
3 | /** |
4 | * i18n.php |
5 | * |
76911253 |
6 | * Copyright (c) 1999-2003 The SquirrelMail Project Team |
35586184 |
7 | * Licensed under the GNU GPL. For full terms see the file COPYING. |
8 | * |
9 | * This file contains variuos functions that are needed to do |
10 | * internationalization of SquirrelMail. |
11 | * |
12 | * Internally the output character set is used. Other characters are |
13 | * encoded using Unicode entities according to HTML 4.0. |
14 | * |
15 | * $Id$ |
16 | */ |
17 | |
961ca3d8 |
18 | require_once(SM_PATH . 'functions/global.php'); |
19 | |
a2a7852b |
20 | /* Decodes a string to the internal encoding from the given charset */ |
21 | function charset_decode ($charset, $string) { |
6fbd125b |
22 | global $languages, $squirrelmail_language; |
a2a7852b |
23 | |
3714db45 |
24 | if (isset($languages[$squirrelmail_language]['XTRA_CODE']) && |
25 | function_exists($languages[$squirrelmail_language]['XTRA_CODE'])) { |
6fbd125b |
26 | $string = $languages[$squirrelmail_language]['XTRA_CODE']('decode', $string); |
27 | } |
b05c8961 |
28 | |
a2a7852b |
29 | /* All HTML special characters are 7 bit and can be replaced first */ |
cef054e4 |
30 | |
098ea084 |
31 | $string = htmlspecialchars ($string); |
a2a7852b |
32 | |
33 | $charset = strtolower($charset); |
34 | |
94965562 |
35 | set_my_charset() ; |
36 | |
a2a7852b |
37 | if (ereg('iso-8859-([[:digit:]]+)', $charset, $res)) { |
38 | if ($res[1] == '1') { |
39 | $ret = charset_decode_iso_8859_1 ($string); |
40 | } else if ($res[1] == '2') { |
41 | $ret = charset_decode_iso_8859_2 ($string); |
9be313d5 |
42 | } else if ($res[1] == '4') { |
43 | $ret = charset_decode_iso_8859_4 ($string); |
94965562 |
44 | } else if ($res[1] == '5') { |
45 | $ret = charset_decode_iso_8859_5 ($string); |
a2a7852b |
46 | } else if ($res[1] == '7') { |
47 | $ret = charset_decode_iso_8859_7 ($string); |
3ab35042 |
48 | } else if ($res[1] == '9') { |
49 | $ret = charset_decode_iso_8859_9 ($string); |
9be313d5 |
50 | } else if ($res[1] == '13') { |
51 | $ret = charset_decode_iso_8859_13 ($string); |
a2a7852b |
52 | } else if ($res[1] == '15') { |
53 | $ret = charset_decode_iso_8859_15 ($string); |
54 | } else { |
55 | $ret = charset_decode_iso_8859_default ($string); |
56 | } |
57 | } else if ($charset == 'ns_4551-1') { |
58 | $ret = charset_decode_ns_4551_1 ($string); |
59 | } else if ($charset == 'koi8-r') { |
60 | $ret = charset_decode_koi8r ($string); |
61 | } else if ($charset == 'windows-1251') { |
ecd877a8 |
62 | $ret = charset_decode_windows_1251 ($string); |
3ab35042 |
63 | } else if ($charset == 'windows-1253') { |
64 | $ret = charset_decode_windows_1253 ($string); |
65 | } else if ($charset == 'windows-1254') { |
66 | $ret = charset_decode_windows_1254 ($string); |
c37a12f8 |
67 | } else if ($charset == 'windows-1257') { |
68 | $ret = charset_decode_windows_1257 ($string); |
3ab35042 |
69 | } else if ($charset == 'utf-8') { |
70 | $ret = charset_decode_utf8 ($string); |
a2a7852b |
71 | } else { |
72 | $ret = $string; |
73 | } |
74 | return( $ret ); |
75 | } |
76 | |
77 | /* |
78 | iso-8859-1 is the same as Latin 1 and is normally used |
79 | in western europe. |
80 | */ |
81 | function charset_decode_iso_8859_1 ($string) { |
82 | global $default_charset; |
13e0c649 |
83 | |
a2a7852b |
84 | if (strtolower($default_charset) <> 'iso-8859-1') { |
85 | /* Only do the slow convert if there are 8-bit characters */ |
86 | if (ereg("[\200-\377]", $string)) { |
066c374f |
87 | $string = str_replace("\201", '', $string); |
88 | $string = str_replace("\202", '‚', $string); |
89 | $string = str_replace("\203", 'ƒ', $string); |
90 | $string = str_replace("\204", '„', $string); |
91 | $string = str_replace("\205", '…', $string); |
92 | $string = str_replace("\206", '†', $string); |
93 | $string = str_replace("\207", '‡', $string); |
94 | $string = str_replace("\210", 'ˆ', $string); |
95 | $string = str_replace("\211", '‰', $string); |
96 | $string = str_replace("\212", 'Š', $string); |
97 | $string = str_replace("\213", '‹', $string); |
98 | $string = str_replace("\214", 'Œ', $string); |
99 | $string = str_replace("\215", '', $string); |
100 | $string = str_replace("\216", 'Ž', $string); |
101 | $string = str_replace("\217", '', $string); |
102 | $string = str_replace("\220", '', $string); |
103 | $string = str_replace("\221", '‘', $string); |
104 | $string = str_replace("\222", '’', $string); |
105 | $string = str_replace("\223", '“', $string); |
106 | $string = str_replace("\224", '”', $string); |
107 | $string = str_replace("\225", '•', $string); |
108 | $string = str_replace("\226", '–', $string); |
109 | $string = str_replace("\227", '—', $string); |
110 | $string = str_replace("\230", '˜', $string); |
111 | $string = str_replace("\231", '™', $string); |
112 | $string = str_replace("\232", 'š', $string); |
113 | $string = str_replace("\233", '›', $string); |
114 | $string = str_replace("\234", 'œ', $string); |
115 | $string = str_replace("\235", '', $string); |
116 | $string = str_replace("\236", 'ž', $string); |
117 | $string = str_replace("\237", 'Ÿ', $string); |
118 | $string = str_replace("\240", ' ', $string); |
119 | $string = str_replace("\241", '¡', $string); |
120 | $string = str_replace("\242", '¢', $string); |
121 | $string = str_replace("\243", '£', $string); |
122 | $string = str_replace("\244", '¤', $string); |
123 | $string = str_replace("\245", '¥', $string); |
124 | $string = str_replace("\246", '¦', $string); |
125 | $string = str_replace("\247", '§', $string); |
126 | $string = str_replace("\250", '¨', $string); |
127 | $string = str_replace("\251", '©', $string); |
128 | $string = str_replace("\252", 'ª', $string); |
129 | $string = str_replace("\253", '«', $string); |
130 | $string = str_replace("\254", '¬', $string); |
131 | $string = str_replace("\255", '­', $string); |
132 | $string = str_replace("\256", '®', $string); |
133 | $string = str_replace("\257", '¯', $string); |
134 | $string = str_replace("\260", '°', $string); |
135 | $string = str_replace("\261", '±', $string); |
136 | $string = str_replace("\262", '²', $string); |
137 | $string = str_replace("\263", '³', $string); |
138 | $string = str_replace("\264", '´', $string); |
139 | $string = str_replace("\265", 'µ', $string); |
140 | $string = str_replace("\266", '¶', $string); |
141 | $string = str_replace("\267", '·', $string); |
142 | $string = str_replace("\270", '¸', $string); |
143 | $string = str_replace("\271", '¹', $string); |
144 | $string = str_replace("\272", 'º', $string); |
145 | $string = str_replace("\273", '»', $string); |
146 | $string = str_replace("\274", '¼', $string); |
147 | $string = str_replace("\275", '½', $string); |
148 | $string = str_replace("\276", '¾', $string); |
149 | $string = str_replace("\277", '¿', $string); |
150 | $string = str_replace("\300", 'À', $string); |
151 | $string = str_replace("\301", 'Á', $string); |
152 | $string = str_replace("\302", 'Â', $string); |
153 | $string = str_replace("\303", 'Ã', $string); |
154 | $string = str_replace("\304", 'Ä', $string); |
155 | $string = str_replace("\305", 'Å', $string); |
156 | $string = str_replace("\306", 'Æ', $string); |
157 | $string = str_replace("\307", 'Ç', $string); |
158 | $string = str_replace("\310", 'È', $string); |
159 | $string = str_replace("\311", 'É', $string); |
160 | $string = str_replace("\312", 'Ê', $string); |
161 | $string = str_replace("\313", 'Ë', $string); |
162 | $string = str_replace("\314", 'Ì', $string); |
163 | $string = str_replace("\315", 'Í', $string); |
164 | $string = str_replace("\316", 'Î', $string); |
165 | $string = str_replace("\317", 'Ï', $string); |
166 | $string = str_replace("\320", 'Ð', $string); |
167 | $string = str_replace("\321", 'Ñ', $string); |
168 | $string = str_replace("\322", 'Ò', $string); |
169 | $string = str_replace("\323", 'Ó', $string); |
170 | $string = str_replace("\324", 'Ô', $string); |
171 | $string = str_replace("\325", 'Õ', $string); |
172 | $string = str_replace("\326", 'Ö', $string); |
173 | $string = str_replace("\327", '×', $string); |
174 | $string = str_replace("\330", 'Ø', $string); |
175 | $string = str_replace("\331", 'Ù', $string); |
176 | $string = str_replace("\332", 'Ú', $string); |
177 | $string = str_replace("\333", 'Û', $string); |
178 | $string = str_replace("\334", 'Ü', $string); |
179 | $string = str_replace("\335", 'Ý', $string); |
180 | $string = str_replace("\336", 'Þ', $string); |
181 | $string = str_replace("\337", 'ß', $string); |
182 | $string = str_replace("\340", 'à', $string); |
183 | $string = str_replace("\341", 'á', $string); |
184 | $string = str_replace("\342", 'â', $string); |
185 | $string = str_replace("\343", 'ã', $string); |
186 | $string = str_replace("\344", 'ä', $string); |
187 | $string = str_replace("\345", 'å', $string); |
188 | $string = str_replace("\346", 'æ', $string); |
189 | $string = str_replace("\347", 'ç', $string); |
190 | $string = str_replace("\350", 'è', $string); |
191 | $string = str_replace("\351", 'é', $string); |
192 | $string = str_replace("\352", 'ê', $string); |
193 | $string = str_replace("\353", 'ë', $string); |
194 | $string = str_replace("\354", 'ì', $string); |
195 | $string = str_replace("\355", 'í', $string); |
196 | $string = str_replace("\356", 'î', $string); |
197 | $string = str_replace("\357", 'ï', $string); |
198 | $string = str_replace("\360", 'ð', $string); |
199 | $string = str_replace("\361", 'ñ', $string); |
200 | $string = str_replace("\362", 'ò', $string); |
201 | $string = str_replace("\363", 'ó', $string); |
202 | $string = str_replace("\364", 'ô', $string); |
203 | $string = str_replace("\365", 'õ', $string); |
204 | $string = str_replace("\366", 'ö', $string); |
205 | $string = str_replace("\367", '÷', $string); |
206 | $string = str_replace("\370", 'ø', $string); |
207 | $string = str_replace("\371", 'ù', $string); |
208 | $string = str_replace("\372", 'ú', $string); |
209 | $string = str_replace("\373", 'û', $string); |
210 | $string = str_replace("\374", 'ü', $string); |
211 | $string = str_replace("\375", 'ý', $string); |
212 | $string = str_replace("\376", 'þ', $string); |
213 | $string = str_replace("\377", 'ÿ', $string); |
a2a7852b |
214 | } |
215 | } |
216 | |
217 | return ($string); |
218 | } |
219 | |
220 | /* iso-8859-2 is used for some eastern European languages */ |
221 | function charset_decode_iso_8859_2 ($string) { |
222 | global $default_charset; |
223 | |
224 | if (strtolower($default_charset) == 'iso-8859-2') |
225 | return $string; |
226 | |
227 | /* Only do the slow convert if there are 8-bit characters */ |
228 | if (! ereg("[\200-\377]", $string)) |
229 | return $string; |
230 | |
231 | /* NO-BREAK SPACE */ |
232 | $string = str_replace("\240", ' ', $string); |
233 | /* LATIN CAPITAL LETTER A WITH OGONEK */ |
234 | $string = str_replace("\241", 'Ą', $string); |
235 | /* BREVE */ |
236 | $string = str_replace("\242", '˘', $string); |
237 | // LATIN CAPITAL LETTER L WITH STROKE |
238 | $string = str_replace("\243", 'Ł', $string); |
239 | // CURRENCY SIGN |
240 | $string = str_replace("\244", '¤', $string); |
241 | // LATIN CAPITAL LETTER L WITH CARON |
242 | $string = str_replace("\245", 'Ľ', $string); |
243 | // LATIN CAPITAL LETTER S WITH ACUTE |
244 | $string = str_replace("\246", 'Ś', $string); |
245 | // SECTION SIGN |
246 | $string = str_replace("\247", '§', $string); |
247 | // DIAERESIS |
248 | $string = str_replace("\250", '¨', $string); |
249 | // LATIN CAPITAL LETTER S WITH CARON |
250 | $string = str_replace("\251", 'Š', $string); |
251 | // LATIN CAPITAL LETTER S WITH CEDILLA |
252 | $string = str_replace("\252", 'Ş', $string); |
253 | // LATIN CAPITAL LETTER T WITH CARON |
254 | $string = str_replace("\253", 'Ť', $string); |
255 | // LATIN CAPITAL LETTER Z WITH ACUTE |
256 | $string = str_replace("\254", 'Ź', $string); |
257 | // SOFT HYPHEN |
258 | $string = str_replace("\255", '­', $string); |
259 | // LATIN CAPITAL LETTER Z WITH CARON |
260 | $string = str_replace("\256", 'Ž', $string); |
261 | // LATIN CAPITAL LETTER Z WITH DOT ABOVE |
262 | $string = str_replace("\257", 'Ż', $string); |
263 | // DEGREE SIGN |
264 | $string = str_replace("\260", '°', $string); |
265 | // LATIN SMALL LETTER A WITH OGONEK |
266 | $string = str_replace("\261", 'ą', $string); |
267 | // OGONEK |
268 | $string = str_replace("\262", '˛', $string); |
269 | // LATIN SMALL LETTER L WITH STROKE |
270 | $string = str_replace("\263", 'ł', $string); |
271 | // ACUTE ACCENT |
272 | $string = str_replace("\264", '´', $string); |
273 | // LATIN SMALL LETTER L WITH CARON |
274 | $string = str_replace("\265", 'ľ', $string); |
275 | // LATIN SMALL LETTER S WITH ACUTE |
276 | $string = str_replace("\266", 'ś', $string); |
277 | // CARON |
278 | $string = str_replace("\267", 'ˇ', $string); |
279 | // CEDILLA |
280 | $string = str_replace("\270", '¸', $string); |
281 | // LATIN SMALL LETTER S WITH CARON |
282 | $string = str_replace("\271", 'š', $string); |
283 | // LATIN SMALL LETTER S WITH CEDILLA |
284 | $string = str_replace("\272", 'ş', $string); |
285 | // LATIN SMALL LETTER T WITH CARON |
286 | $string = str_replace("\273", 'ť', $string); |
287 | // LATIN SMALL LETTER Z WITH ACUTE |
288 | $string = str_replace("\274", 'ź', $string); |
289 | // DOUBLE ACUTE ACCENT |
290 | $string = str_replace("\275", '˝', $string); |
291 | // LATIN SMALL LETTER Z WITH CARON |
292 | $string = str_replace("\276", 'ž', $string); |
293 | // LATIN SMALL LETTER Z WITH DOT ABOVE |
294 | $string = str_replace("\277", 'ż', $string); |
295 | // LATIN CAPITAL LETTER R WITH ACUTE |
296 | $string = str_replace("\300", 'Ŕ', $string); |
297 | // LATIN CAPITAL LETTER A WITH ACUTE |
298 | $string = str_replace("\301", 'Á', $string); |
299 | // LATIN CAPITAL LETTER A WITH CIRCUMFLEX |
300 | $string = str_replace("\302", 'Â', $string); |
301 | // LATIN CAPITAL LETTER A WITH BREVE |
302 | $string = str_replace("\303", 'Ă', $string); |
303 | // LATIN CAPITAL LETTER A WITH DIAERESIS |
304 | $string = str_replace("\304", 'Ä', $string); |
305 | // LATIN CAPITAL LETTER L WITH ACUTE |
306 | $string = str_replace("\305", 'Ĺ', $string); |
307 | // LATIN CAPITAL LETTER C WITH ACUTE |
308 | $string = str_replace("\306", 'Ć', $string); |
309 | // LATIN CAPITAL LETTER C WITH CEDILLA |
310 | $string = str_replace("\307", 'Ç', $string); |
311 | // LATIN CAPITAL LETTER C WITH CARON |
312 | $string = str_replace("\310", 'Č', $string); |
313 | // LATIN CAPITAL LETTER E WITH ACUTE |
314 | $string = str_replace("\311", 'É', $string); |
315 | // LATIN CAPITAL LETTER E WITH OGONEK |
316 | $string = str_replace("\312", 'Ę', $string); |
317 | // LATIN CAPITAL LETTER E WITH DIAERESIS |
318 | $string = str_replace("\313", 'Ë', $string); |
319 | // LATIN CAPITAL LETTER E WITH CARON |
320 | $string = str_replace("\314", 'Ě', $string); |
321 | // LATIN CAPITAL LETTER I WITH ACUTE |
322 | $string = str_replace("\315", 'Í', $string); |
323 | // LATIN CAPITAL LETTER I WITH CIRCUMFLEX |
324 | $string = str_replace("\316", 'Î', $string); |
325 | // LATIN CAPITAL LETTER D WITH CARON |
326 | $string = str_replace("\317", 'Ď', $string); |
327 | // LATIN CAPITAL LETTER D WITH STROKE |
328 | $string = str_replace("\320", 'Đ', $string); |
329 | // LATIN CAPITAL LETTER N WITH ACUTE |
330 | $string = str_replace("\321", 'Ń', $string); |
331 | // LATIN CAPITAL LETTER N WITH CARON |
332 | $string = str_replace("\322", 'Ň', $string); |
333 | // LATIN CAPITAL LETTER O WITH ACUTE |
334 | $string = str_replace("\323", 'Ó', $string); |
335 | // LATIN CAPITAL LETTER O WITH CIRCUMFLEX |
336 | $string = str_replace("\324", 'Ô', $string); |
337 | // LATIN CAPITAL LETTER O WITH DOUBLE ACUTE |
338 | $string = str_replace("\325", 'Ő', $string); |
339 | // LATIN CAPITAL LETTER O WITH DIAERESIS |
340 | $string = str_replace("\326", 'Ö', $string); |
341 | // MULTIPLICATION SIGN |
342 | $string = str_replace("\327", '×', $string); |
343 | // LATIN CAPITAL LETTER R WITH CARON |
344 | $string = str_replace("\330", 'Ř', $string); |
345 | // LATIN CAPITAL LETTER U WITH RING ABOVE |
346 | $string = str_replace("\331", 'Ů', $string); |
347 | // LATIN CAPITAL LETTER U WITH ACUTE |
348 | $string = str_replace("\332", 'Ú', $string); |
349 | // LATIN CAPITAL LETTER U WITH DOUBLE ACUTE |
350 | $string = str_replace("\333", 'Ű', $string); |
351 | // LATIN CAPITAL LETTER U WITH DIAERESIS |
352 | $string = str_replace("\334", 'Ü', $string); |
353 | // LATIN CAPITAL LETTER Y WITH ACUTE |
354 | $string = str_replace("\335", 'Ý', $string); |
355 | // LATIN CAPITAL LETTER T WITH CEDILLA |
356 | $string = str_replace("\336", 'Ţ', $string); |
357 | // LATIN SMALL LETTER SHARP S |
358 | $string = str_replace("\337", 'ß', $string); |
359 | // LATIN SMALL LETTER R WITH ACUTE |
360 | $string = str_replace("\340", 'ŕ', $string); |
361 | // LATIN SMALL LETTER A WITH ACUTE |
362 | $string = str_replace("\341", 'á', $string); |
363 | // LATIN SMALL LETTER A WITH CIRCUMFLEX |
364 | $string = str_replace("\342", 'â', $string); |
365 | // LATIN SMALL LETTER A WITH BREVE |
366 | $string = str_replace("\343", 'ă', $string); |
367 | // LATIN SMALL LETTER A WITH DIAERESIS |
368 | $string = str_replace("\344", 'ä', $string); |
369 | // LATIN SMALL LETTER L WITH ACUTE |
370 | $string = str_replace("\345", 'ĺ', $string); |
371 | // LATIN SMALL LETTER C WITH ACUTE |
372 | $string = str_replace("\346", 'ć', $string); |
373 | // LATIN SMALL LETTER C WITH CEDILLA |
374 | $string = str_replace("\347", 'ç', $string); |
375 | // LATIN SMALL LETTER C WITH CARON |
376 | $string = str_replace("\350", 'č', $string); |
377 | // LATIN SMALL LETTER E WITH ACUTE |
378 | $string = str_replace("\351", 'é', $string); |
379 | // LATIN SMALL LETTER E WITH OGONEK |
380 | $string = str_replace("\352", 'ę', $string); |
381 | // LATIN SMALL LETTER E WITH DIAERESIS |
382 | $string = str_replace("\353", 'ë', $string); |
383 | // LATIN SMALL LETTER E WITH CARON |
384 | $string = str_replace("\354", 'ě', $string); |
385 | // LATIN SMALL LETTER I WITH ACUTE |
386 | $string = str_replace("\355", 'í', $string); |
387 | // LATIN SMALL LETTER I WITH CIRCUMFLEX |
388 | $string = str_replace("\356", 'î', $string); |
389 | // LATIN SMALL LETTER D WITH CARON |
390 | $string = str_replace("\357", 'ď', $string); |
391 | // LATIN SMALL LETTER D WITH STROKE |
392 | $string = str_replace("\360", 'đ', $string); |
393 | // LATIN SMALL LETTER N WITH ACUTE |
394 | $string = str_replace("\361", 'ń', $string); |
395 | // LATIN SMALL LETTER N WITH CARON |
396 | $string = str_replace("\362", 'ň', $string); |
397 | // LATIN SMALL LETTER O WITH ACUTE |
398 | $string = str_replace("\363", 'ó', $string); |
399 | // LATIN SMALL LETTER O WITH CIRCUMFLEX |
400 | $string = str_replace("\364", 'ô', $string); |
401 | // LATIN SMALL LETTER O WITH DOUBLE ACUTE |
402 | $string = str_replace("\365", 'ő', $string); |
403 | // LATIN SMALL LETTER O WITH DIAERESIS |
404 | $string = str_replace("\366", 'ö', $string); |
405 | // DIVISION SIGN |
406 | $string = str_replace("\367", '÷', $string); |
407 | // LATIN SMALL LETTER R WITH CARON |
408 | $string = str_replace("\370", 'ř', $string); |
409 | // LATIN SMALL LETTER U WITH RING ABOVE |
410 | $string = str_replace("\371", 'ů', $string); |
411 | // LATIN SMALL LETTER U WITH ACUTE |
412 | $string = str_replace("\372", 'ú', $string); |
413 | // LATIN SMALL LETTER U WITH DOUBLE ACUTE |
414 | $string = str_replace("\373", 'ű', $string); |
415 | // LATIN SMALL LETTER U WITH DIAERESIS |
416 | $string = str_replace("\374", 'ü', $string); |
417 | // LATIN SMALL LETTER Y WITH ACUTE |
418 | $string = str_replace("\375", 'ý', $string); |
419 | // LATIN SMALL LETTER T WITH CEDILLA |
420 | $string = str_replace("\376", 'ţ', $string); |
421 | // DOT ABOVE |
422 | $string = str_replace("\377", '˙', $string); |
423 | |
424 | return $string; |
425 | } |
426 | |
9be313d5 |
427 | /* |
c37a12f8 |
428 | ISO/IEC 8859-4:1998 Latin Alphabet No. 4 |
9be313d5 |
429 | */ |
430 | |
431 | function charset_decode_iso_8859_4 ($string) { |
94965562 |
432 | global $default_charset; |
9be313d5 |
433 | |
c37a12f8 |
434 | if (strtolower($default_charset) == 'iso-8859-4') |
435 | return $string; |
c37a12f8 |
436 | |
437 | /* Only do the slow convert if there are 8-bit characters */ |
438 | if (! ereg("[\200-\377]", $string)) |
439 | return $string; |
440 | |
c37a12f8 |
441 | $string = str_replace ("\241", 'Ą', $string); |
c37a12f8 |
442 | $string = str_replace ("\242", 'ĸ', $string); |
c37a12f8 |
443 | $string = str_replace ("\243", 'Ŗ', $string); |
c37a12f8 |
444 | $string = str_replace ("\245", 'Ĩ', $string); |
c37a12f8 |
445 | $string = str_replace ("\246", 'Ļ', $string); |
c37a12f8 |
446 | $string = str_replace ("\251", 'Š', $string); |
c37a12f8 |
447 | $string = str_replace ("\252", 'Ē', $string); |
c37a12f8 |
448 | $string = str_replace ("\253", 'Ģ', $string); |
c37a12f8 |
449 | $string = str_replace ("\254", 'Ŧ', $string); |
c37a12f8 |
450 | $string = str_replace ("\256", 'Ž', $string); |
c37a12f8 |
451 | $string = str_replace ("\261", 'ą', $string); |
c37a12f8 |
452 | $string = str_replace ("\262", '˛', $string); |
c37a12f8 |
453 | $string = str_replace ("\263", 'ŗ', $string); |
c37a12f8 |
454 | $string = str_replace ("\265", 'ĩ', $string); |
c37a12f8 |
455 | $string = str_replace ("\266", 'ļ', $string); |
c37a12f8 |
456 | $string = str_replace ("\267", 'ˇ', $string); |
c37a12f8 |
457 | $string = str_replace ("\271", 'š', $string); |
c37a12f8 |
458 | $string = str_replace ("\272", 'ē', $string); |
c37a12f8 |
459 | $string = str_replace ("\273", 'ģ', $string); |
c37a12f8 |
460 | $string = str_replace ("\274", 'ŧ', $string); |
c37a12f8 |
461 | $string = str_replace ("\275", 'Ŋ', $string); |
c37a12f8 |
462 | $string = str_replace ("\276", 'ž', $string); |
c37a12f8 |
463 | $string = str_replace ("\277", 'ŋ', $string); |
c37a12f8 |
464 | $string = str_replace ("\300", 'Ā', $string); |
c37a12f8 |
465 | $string = str_replace ("\307", 'Į', $string); |
c37a12f8 |
466 | $string = str_replace ("\310", 'Č', $string); |
c37a12f8 |
467 | $string = str_replace ("\312", 'Ę', $string); |
c37a12f8 |
468 | $string = str_replace ("\314", 'Ė', $string); |
c37a12f8 |
469 | $string = str_replace ("\317", 'Ī', $string); |
c37a12f8 |
470 | $string = str_replace ("\320", 'Đ', $string); |
c37a12f8 |
471 | $string = str_replace ("\321", 'Ņ', $string); |
c37a12f8 |
472 | $string = str_replace ("\322", 'Ō', $string); |
c37a12f8 |
473 | $string = str_replace ("\323", 'Ķ', $string); |
c37a12f8 |
474 | $string = str_replace ("\331", 'Ų', $string); |
c37a12f8 |
475 | $string = str_replace ("\335", 'Ũ', $string); |
c37a12f8 |
476 | $string = str_replace ("\336", 'Ū', $string); |
c37a12f8 |
477 | $string = str_replace ("\340", 'ā', $string); |
c37a12f8 |
478 | $string = str_replace ("\347", 'į', $string); |
c37a12f8 |
479 | $string = str_replace ("\350", 'č', $string); |
c37a12f8 |
480 | $string = str_replace ("\352", 'ę', $string); |
c37a12f8 |
481 | $string = str_replace ("\354", 'ė', $string); |
c37a12f8 |
482 | $string = str_replace ("\357", 'ī', $string); |
c37a12f8 |
483 | $string = str_replace ("\360", 'đ', $string); |
c37a12f8 |
484 | $string = str_replace ("\361", 'ņ', $string); |
c37a12f8 |
485 | $string = str_replace ("\362", 'ō', $string); |
c37a12f8 |
486 | $string = str_replace ("\363", 'ķ', $string); |
c37a12f8 |
487 | $string = str_replace ("\371", 'ų', $string); |
c37a12f8 |
488 | $string = str_replace ("\375", 'ũ', $string); |
c37a12f8 |
489 | $string = str_replace ("\376", 'ū', $string); |
c37a12f8 |
490 | $string = str_replace ("\377", '˙', $string); |
491 | |
492 | // rest of charset is the same as ISO-8859-1 |
9be313d5 |
493 | return (charset_decode_iso_8859_1($string)); |
494 | } |
495 | |
a2a7852b |
496 | /* iso-8859-7 is Greek. */ |
497 | function charset_decode_iso_8859_7 ($string) { |
498 | global $default_charset; |
499 | |
500 | if (strtolower($default_charset) == 'iso-8859-7') { |
501 | return $string; |
502 | } |
503 | |
504 | /* Only do the slow convert if there are 8-bit characters */ |
505 | if (!ereg("[\200-\377]", $string)) { |
506 | return $string; |
507 | } |
508 | |
509 | /* Some diverse characters in the beginning */ |
510 | $string = str_replace("\240", ' ', $string); |
511 | $string = str_replace("\241", '‘', $string); |
512 | $string = str_replace("\242", '’', $string); |
513 | $string = str_replace("\243", '£', $string); |
514 | $string = str_replace("\246", '¦', $string); |
515 | $string = str_replace("\247", '§', $string); |
516 | $string = str_replace("\250", '¨', $string); |
517 | $string = str_replace("\251", '©', $string); |
518 | $string = str_replace("\253", '«', $string); |
519 | $string = str_replace("\254", '¬', $string); |
520 | $string = str_replace("\255", '­', $string); |
521 | $string = str_replace("\257", '―', $string); |
522 | $string = str_replace("\260", '°', $string); |
523 | $string = str_replace("\261", '±', $string); |
524 | $string = str_replace("\262", '²', $string); |
525 | $string = str_replace("\263", '³', $string); |
526 | |
527 | /* Horizontal bar (parentheki pavla) */ |
528 | $string = str_replace ("\257", '―', $string); |
529 | |
530 | /* |
531 | * ISO-8859-7 characters from 11/04 (0xB4) to 11/06 (0xB6) |
532 | * These are Unicode 900-902 |
533 | */ |
b85a4575 |
534 | $string = preg_replace("/([\264-\266])/e","'&#' . (ord('\\1')+720);",$string); |
49c17806 |
535 | |
a2a7852b |
536 | /* 11/07 (0xB7) Middle dot is the same in iso-8859-1 */ |
537 | $string = str_replace("\267", '·', $string); |
538 | |
539 | /* |
540 | * ISO-8859-7 characters from 11/08 (0xB8) to 11/10 (0xBA) |
541 | * These are Unicode 900-902 |
542 | */ |
b85a4575 |
543 | $string = preg_replace("/([\270-\272])/e","'&#' . (ord('\\1')+720);",$string); |
a2a7852b |
544 | |
545 | /* |
546 | * 11/11 (0xBB) Right angle quotation mark is the same as in |
547 | * iso-8859-1 |
548 | */ |
549 | $string = str_replace("\273", '»', $string); |
550 | |
551 | /* And now the rest of the charset */ |
b85a4575 |
552 | $string = preg_replace("/([\274-\376])/e","'&#'.(ord('\\1')+720);",$string); |
a2a7852b |
553 | |
554 | return $string; |
555 | } |
556 | |
557 | /* |
cd21d1aa |
558 | ISOIEC 8859-9:1999 Latin Alphabet No. 5 |
961ca3d8 |
559 | |
3ab35042 |
560 | */ |
561 | function charset_decode_iso_8859_9 ($string) { |
94965562 |
562 | global $default_charset; |
3ab35042 |
563 | |
564 | if (strtolower($default_charset) == 'iso-8859-9') |
565 | return $string; |
3ab35042 |
566 | |
567 | /* Only do the slow convert if there are 8-bit characters */ |
568 | if (! ereg("[\200-\377]", $string)) |
569 | return $string; |
570 | |
571 | // latin capital letter g with breve 208->286 |
572 | $string = str_replace("\320", 'Ğ', $string); |
573 | // latin capital letter i with dot above 221->304 |
574 | $string = str_replace("\335", 'İ', $string); |
575 | // latin capital letter s with cedilla 222->350 |
576 | $string = str_replace("\336", 'Ş', $string); |
577 | // latin small letter g with breve 240->287 |
578 | $string = str_replace("\360", 'ğ', $string); |
579 | // latin small letter dotless i 253->305 |
580 | $string = str_replace("\375", 'ı', $string); |
581 | // latin small letter s with cedilla 254->351 |
582 | $string = str_replace("\376", 'ş', $string); |
583 | |
584 | // rest of charset is the same as ISO-8859-1 |
585 | return (charset_decode_iso_8859_1($string)); |
586 | } |
587 | |
588 | |
589 | /* |
c37a12f8 |
590 | ISO/IEC 8859-13:1998 Latin Alphabet No. 7 (Baltic Rim) |
9be313d5 |
591 | */ |
9be313d5 |
592 | function charset_decode_iso_8859_13 ($string) { |
94965562 |
593 | global $default_charset; |
c37a12f8 |
594 | |
595 | if (strtolower($default_charset) == 'iso-8859-13') |
596 | return $string; |
c37a12f8 |
597 | |
598 | /* Only do the slow convert if there are 8-bit characters */ |
599 | if (! ereg("[\200-\377]", $string)) |
600 | return $string; |
9be313d5 |
601 | |
c37a12f8 |
602 | $string = str_replace ("\241", '”', $string); |
c37a12f8 |
603 | $string = str_replace ("\245", '„', $string); |
c37a12f8 |
604 | $string = str_replace ("\250", 'Ø', $string); |
c37a12f8 |
605 | $string = str_replace ("\252", 'Ŗ', $string); |
c37a12f8 |
606 | $string = str_replace ("\257", 'Æ', $string); |
c37a12f8 |
607 | $string = str_replace ("\264", '“', $string); |
c37a12f8 |
608 | $string = str_replace ("\270", 'ø', $string); |
c37a12f8 |
609 | $string = str_replace ("\272", 'ŗ', $string); |
c37a12f8 |
610 | $string = str_replace ("\277", 'æ', $string); |
c37a12f8 |
611 | $string = str_replace ("\300", 'Ą', $string); |
c37a12f8 |
612 | $string = str_replace ("\301", 'Į', $string); |
c37a12f8 |
613 | $string = str_replace ("\302", 'Ā', $string); |
c37a12f8 |
614 | $string = str_replace ("\303", 'Ć', $string); |
c37a12f8 |
615 | $string = str_replace ("\306", 'Ę', $string); |
c37a12f8 |
616 | $string = str_replace ("\307", 'Ē', $string); |
c37a12f8 |
617 | $string = str_replace ("\310", 'Č', $string); |
c37a12f8 |
618 | $string = str_replace ("\312", 'Ź', $string); |
c37a12f8 |
619 | $string = str_replace ("\313", 'Ė', $string); |
c37a12f8 |
620 | $string = str_replace ("\314", 'Ģ', $string); |
c37a12f8 |
621 | $string = str_replace ("\315", 'Ķ', $string); |
c37a12f8 |
622 | $string = str_replace ("\316", 'Ī', $string); |
c37a12f8 |
623 | $string = str_replace ("\317", 'Ļ', $string); |
c37a12f8 |
624 | $string = str_replace ("\320", 'Š', $string); |
c37a12f8 |
625 | $string = str_replace ("\321", 'Ń', $string); |
c37a12f8 |
626 | $string = str_replace ("\322", 'Ņ', $string); |
c37a12f8 |
627 | $string = str_replace ("\324", 'Ō', $string); |
c37a12f8 |
628 | $string = str_replace ("\330", 'Ų', $string); |
c37a12f8 |
629 | $string = str_replace ("\331", 'Ł', $string); |
c37a12f8 |
630 | $string = str_replace ("\332", 'Ś', $string); |
c37a12f8 |
631 | $string = str_replace ("\333", 'Ū', $string); |
c37a12f8 |
632 | $string = str_replace ("\335", 'Ż', $string); |
c37a12f8 |
633 | $string = str_replace ("\336", 'Ž', $string); |
c37a12f8 |
634 | $string = str_replace ("\340", 'ą', $string); |
c37a12f8 |
635 | $string = str_replace ("\341", 'į', $string); |
c37a12f8 |
636 | $string = str_replace ("\342", 'ā', $string); |
c37a12f8 |
637 | $string = str_replace ("\343", 'ć', $string); |
c37a12f8 |
638 | $string = str_replace ("\346", 'ę', $string); |
c37a12f8 |
639 | $string = str_replace ("\347", 'ē', $string); |
c37a12f8 |
640 | $string = str_replace ("\350", 'č', $string); |
c37a12f8 |
641 | $string = str_replace ("\352", 'ź', $string); |
c37a12f8 |
642 | $string = str_replace ("\353", 'ė', $string); |
c37a12f8 |
643 | $string = str_replace ("\354", 'ģ', $string); |
c37a12f8 |
644 | $string = str_replace ("\355", 'ķ', $string); |
c37a12f8 |
645 | $string = str_replace ("\356", 'ī', $string); |
c37a12f8 |
646 | $string = str_replace ("\357", 'ļ', $string); |
c37a12f8 |
647 | $string = str_replace ("\360", 'š', $string); |
c37a12f8 |
648 | $string = str_replace ("\361", 'ń', $string); |
c37a12f8 |
649 | $string = str_replace ("\362", 'ņ', $string); |
c37a12f8 |
650 | $string = str_replace ("\364", 'ō', $string); |
c37a12f8 |
651 | $string = str_replace ("\370", 'ų', $string); |
c37a12f8 |
652 | $string = str_replace ("\371", 'ł', $string); |
c37a12f8 |
653 | $string = str_replace ("\372", 'ś', $string); |
c37a12f8 |
654 | $string = str_replace ("\373", 'ū', $string); |
c37a12f8 |
655 | $string = str_replace ("\375", 'ż', $string); |
c37a12f8 |
656 | $string = str_replace ("\376", 'ž', $string); |
c37a12f8 |
657 | $string = str_replace ("\377", '’', $string); |
658 | |
659 | // rest of charset is the same as ISO-8859-1 |
9be313d5 |
660 | return (charset_decode_iso_8859_1($string)); |
661 | } |
662 | |
663 | /* |
a2a7852b |
664 | * iso-8859-15 is Latin 9 and has very much the same use as Latin 1 |
665 | * but has the Euro symbol and some characters needed for French. |
666 | */ |
667 | function charset_decode_iso_8859_15 ($string) { |
668 | // Euro sign |
669 | $string = str_replace ("\244", '€', $string); |
670 | // Latin capital letter S with caron |
84556805 |
671 | $string = str_replace ("\246", 'Š', $string); |
a2a7852b |
672 | // Latin small letter s with caron |
673 | $string = str_replace ("\250", 'š', $string); |
674 | // Latin capital letter Z with caron |
675 | $string = str_replace ("\264", 'Ž', $string); |
676 | // Latin small letter z with caron |
677 | $string = str_replace ("\270", 'ž', $string); |
678 | // Latin capital ligature OE |
679 | $string = str_replace ("\274", 'Œ', $string); |
680 | // Latin small ligature oe |
681 | $string = str_replace ("\275", 'œ', $string); |
682 | // Latin capital letter Y with diaeresis |
683 | $string = str_replace ("\276", 'Ÿ', $string); |
684 | |
685 | return (charset_decode_iso_8859_1($string)); |
686 | } |
687 | |
84556805 |
688 | /* ISO-8859-5 is Cyrillic */ |
a2a7852b |
689 | function charset_decode_iso_8859_5 ($string) { |
690 | // Convert to KOI8-R, then return this decoded. |
691 | $string = convert_cyr_string($string, 'i', 'k'); |
692 | return charset_decode_koi8r($string); |
693 | } |
694 | |
695 | /* Remove all 8 bit characters from all other ISO-8859 character sets */ |
696 | function charset_decode_iso_8859_default ($string) { |
697 | return (strtr($string, "\240\241\242\243\244\245\246\247". |
1fd97780 |
698 | "\250\251\252\253\254\255\256\257". |
699 | "\260\261\262\263\264\265\266\267". |
700 | "\270\271\272\273\274\275\276\277". |
701 | "\300\301\302\303\304\305\306\307". |
702 | "\310\311\312\313\314\315\316\317". |
703 | "\320\321\322\323\324\325\326\327". |
704 | "\330\331\332\333\334\335\336\337". |
705 | "\340\341\342\343\344\345\346\347". |
706 | "\350\351\352\353\354\355\356\357". |
707 | "\360\361\362\363\364\365\366\367". |
a2a7852b |
708 | "\370\371\372\373\374\375\376\377", |
1fd97780 |
709 | "????????????????????????????????????????". |
710 | "????????????????????????????????????????". |
711 | "????????????????????????????????????????". |
712 | "????????")); |
a2a7852b |
713 | |
714 | } |
715 | |
716 | /* |
717 | * This is the same as ISO-646-NO and is used by some |
718 | * Microsoft programs when sending Norwegian characters |
719 | */ |
720 | function charset_decode_ns_4551_1 ($string) { |
721 | /* |
722 | * These characters are: |
723 | * Latin capital letter AE |
724 | * Latin capital letter O with stroke |
725 | * Latin capital letter A with ring above |
726 | * and the same as small letters |
727 | */ |
728 | return strtr ($string, "[\\]{|}", "ÆØÅæøå"); |
729 | } |
730 | |
731 | /* |
732 | * KOI8-R is used to encode Russian mail (Cyrrilic). Defined in RFC |
733 | * 1489. |
734 | */ |
735 | function charset_decode_koi8r ($string) { |
736 | global $default_charset; |
737 | |
738 | if ($default_charset == 'koi8-r') { |
739 | return $string; |
740 | } |
741 | |
742 | /* |
743 | * Convert to Unicode HTML entities. |
744 | * This code is rather ineffective. |
745 | */ |
746 | $string = str_replace("\200", '─', $string); |
747 | $string = str_replace("\201", '│', $string); |
748 | $string = str_replace("\202", '┌', $string); |
749 | $string = str_replace("\203", '┐', $string); |
750 | $string = str_replace("\204", '└', $string); |
751 | $string = str_replace("\205", '┘', $string); |
752 | $string = str_replace("\206", '├', $string); |
753 | $string = str_replace("\207", '┤', $string); |
754 | $string = str_replace("\210", '┬', $string); |
755 | $string = str_replace("\211", '┴', $string); |
756 | $string = str_replace("\212", '┼', $string); |
757 | $string = str_replace("\213", '▀', $string); |
758 | $string = str_replace("\214", '▄', $string); |
759 | $string = str_replace("\215", '█', $string); |
760 | $string = str_replace("\216", '▌', $string); |
761 | $string = str_replace("\217", '▐', $string); |
762 | $string = str_replace("\220", '░', $string); |
763 | $string = str_replace("\221", '▒', $string); |
764 | $string = str_replace("\222", '▓', $string); |
765 | $string = str_replace("\223", '⌠', $string); |
766 | $string = str_replace("\224", '■', $string); |
767 | $string = str_replace("\225", '∙', $string); |
768 | $string = str_replace("\226", '√', $string); |
769 | $string = str_replace("\227", '≈', $string); |
770 | $string = str_replace("\230", '≤', $string); |
771 | $string = str_replace("\231", '≥', $string); |
772 | $string = str_replace("\232", ' ', $string); |
773 | $string = str_replace("\233", '⌡', $string); |
774 | $string = str_replace("\234", '°', $string); |
775 | $string = str_replace("\235", '²', $string); |
776 | $string = str_replace("\236", '·', $string); |
777 | $string = str_replace("\237", '÷', $string); |
778 | $string = str_replace("\240", '═', $string); |
779 | $string = str_replace("\241", '║', $string); |
780 | $string = str_replace("\242", '╒', $string); |
781 | $string = str_replace("\243", 'ё', $string); |
782 | $string = str_replace("\244", '╓', $string); |
783 | $string = str_replace("\245", '╔', $string); |
784 | $string = str_replace("\246", '╕', $string); |
785 | $string = str_replace("\247", '╖', $string); |
786 | $string = str_replace("\250", '╗', $string); |
787 | $string = str_replace("\251", '╘', $string); |
788 | $string = str_replace("\252", '╙', $string); |
789 | $string = str_replace("\253", '╚', $string); |
790 | $string = str_replace("\254", '╛', $string); |
791 | $string = str_replace("\255", '╜', $string); |
792 | $string = str_replace("\256", '╝', $string); |
793 | $string = str_replace("\257", '╞', $string); |
794 | $string = str_replace("\260", '╟', $string); |
795 | $string = str_replace("\261", '╠', $string); |
796 | $string = str_replace("\262", '╡', $string); |
797 | $string = str_replace("\263", 'Ё', $string); |
798 | $string = str_replace("\264", '╢', $string); |
799 | $string = str_replace("\265", '╣', $string); |
800 | $string = str_replace("\266", '╤', $string); |
801 | $string = str_replace("\267", '╥', $string); |
802 | $string = str_replace("\270", '╦', $string); |
803 | $string = str_replace("\271", '╧', $string); |
804 | $string = str_replace("\272", '╨', $string); |
805 | $string = str_replace("\273", '╩', $string); |
806 | $string = str_replace("\274", '╪', $string); |
807 | $string = str_replace("\275", '╫', $string); |
808 | $string = str_replace("\276", '╬', $string); |
809 | $string = str_replace("\277", '©', $string); |
810 | $string = str_replace("\300", 'ю', $string); |
811 | $string = str_replace("\301", 'а', $string); |
812 | $string = str_replace("\302", 'б', $string); |
813 | $string = str_replace("\303", 'ц', $string); |
814 | $string = str_replace("\304", 'д', $string); |
815 | $string = str_replace("\305", 'е', $string); |
816 | $string = str_replace("\306", 'ф', $string); |
817 | $string = str_replace("\307", 'г', $string); |
818 | $string = str_replace("\310", 'х', $string); |
819 | $string = str_replace("\311", 'и', $string); |
820 | $string = str_replace("\312", 'й', $string); |
821 | $string = str_replace("\313", 'к', $string); |
822 | $string = str_replace("\314", 'л', $string); |
823 | $string = str_replace("\315", 'м', $string); |
824 | $string = str_replace("\316", 'н', $string); |
825 | $string = str_replace("\317", 'о', $string); |
826 | $string = str_replace("\320", 'п', $string); |
827 | $string = str_replace("\321", 'я', $string); |
828 | $string = str_replace("\322", 'р', $string); |
829 | $string = str_replace("\323", 'с', $string); |
830 | $string = str_replace("\324", 'т', $string); |
831 | $string = str_replace("\325", 'у', $string); |
832 | $string = str_replace("\326", 'ж', $string); |
833 | $string = str_replace("\327", 'в', $string); |
834 | $string = str_replace("\330", 'ь', $string); |
835 | $string = str_replace("\331", 'ы', $string); |
836 | $string = str_replace("\332", 'з', $string); |
837 | $string = str_replace("\333", 'ш', $string); |
838 | $string = str_replace("\334", 'э', $string); |
839 | $string = str_replace("\335", 'щ', $string); |
840 | $string = str_replace("\336", 'ч', $string); |
841 | $string = str_replace("\337", 'ъ', $string); |
842 | $string = str_replace("\340", 'Ю', $string); |
843 | $string = str_replace("\341", 'А', $string); |
844 | $string = str_replace("\342", 'Б', $string); |
845 | $string = str_replace("\343", 'Ц', $string); |
846 | $string = str_replace("\344", 'Д', $string); |
847 | $string = str_replace("\345", 'Е', $string); |
848 | $string = str_replace("\346", 'Ф', $string); |
849 | $string = str_replace("\347", 'Г', $string); |
850 | $string = str_replace("\350", 'Х', $string); |
851 | $string = str_replace("\351", 'И', $string); |
852 | $string = str_replace("\352", 'Й', $string); |
853 | $string = str_replace("\353", 'К', $string); |
854 | $string = str_replace("\354", 'Л', $string); |
855 | $string = str_replace("\355", 'М', $string); |
856 | $string = str_replace("\356", 'Н', $string); |
857 | $string = str_replace("\357", 'О', $string); |
858 | $string = str_replace("\360", 'П', $string); |
859 | $string = str_replace("\361", 'Я', $string); |
860 | $string = str_replace("\362", 'Р', $string); |
861 | $string = str_replace("\363", 'С', $string); |
862 | $string = str_replace("\364", 'Т', $string); |
863 | $string = str_replace("\365", 'У', $string); |
864 | $string = str_replace("\366", 'Ж', $string); |
865 | $string = str_replace("\367", 'В', $string); |
866 | $string = str_replace("\370", 'Ь', $string); |
867 | $string = str_replace("\371", 'Ы', $string); |
868 | $string = str_replace("\372", 'З', $string); |
869 | $string = str_replace("\373", 'Ш', $string); |
870 | $string = str_replace("\374", 'Э', $string); |
871 | $string = str_replace("\375", 'Щ', $string); |
872 | $string = str_replace("\376", 'Ч', $string); |
873 | $string = str_replace("\377", 'Ъ', $string); |
874 | |
875 | return $string; |
876 | } |
877 | |
c37a12f8 |
878 | /* |
3ab35042 |
879 | windows-1254 (Turks) |
c37a12f8 |
880 | */ |
3ab35042 |
881 | function charset_decode_windows_1254 ($string) { |
94965562 |
882 | global $default_charset; |
c37a12f8 |
883 | |
3ab35042 |
884 | if (strtolower($default_charset) == 'windows-1254') |
c37a12f8 |
885 | return $string; |
c37a12f8 |
886 | |
887 | /* Only do the slow convert if there are 8-bit characters */ |
888 | if (! ereg("[\200-\377]", $string)) |
889 | return $string; |
890 | |
891 | // Euro sign 128 -> 8364 |
892 | $string = str_replace("\200", '€', $string); |
893 | // Single low-9 quotation mark 130 -> 8218 |
894 | $string = str_replace("\202", '‚', $string); |
3ab35042 |
895 | // latin small letter f with hook 131 -> 402 |
896 | $string = str_replace("\203", 'ƒ', $string); |
c37a12f8 |
897 | // Double low-9 quotation mark 132 -> 8222 |
898 | $string = str_replace("\204", '„', $string); |
899 | // horizontal ellipsis 133 -> 8230 |
900 | $string = str_replace("\205", '…', $string); |
901 | // dagger 134 -> 8224 |
902 | $string = str_replace("\206", '†', $string); |
903 | // double dagger 135 -> 8225 |
904 | $string = str_replace("\207", '‡', $string); |
3ab35042 |
905 | // modifier letter circumflex accent 136->710 |
906 | $string = str_replace("\210", 'ˆ', $string); |
c37a12f8 |
907 | // per mille sign 137 -> 8240 |
908 | $string = str_replace("\211", '‰', $string); |
3ab35042 |
909 | // latin capital letter s with caron 138 -> 352 |
910 | $string = str_replace("\212", 'Š', $string); |
c37a12f8 |
911 | // single left-pointing angle quotation mark 139 -> 8249 |
912 | $string = str_replace("\213", '‹', $string); |
3ab35042 |
913 | // latin capital ligature oe 140 -> 338 |
914 | $string = str_replace("\214", 'Œ', $string); |
c37a12f8 |
915 | // left single quotation mark 145 -> 8216 |
916 | $string = str_replace("\221", '‘', $string); |
917 | // right single quotation mark 146 -> 8217 |
918 | $string = str_replace("\222", '’', $string); |
919 | // left double quotation mark 147 -> 8220 |
920 | $string = str_replace("\223", '“', $string); |
921 | // right double quotation mark 148 -> 8221 |
922 | $string = str_replace("\224", '”', $string); |
923 | // bullet 149 -> 8226 |
924 | $string = str_replace("\225", '•', $string); |
925 | // en dash 150 -> 8211 |
926 | $string = str_replace("\226", '–', $string); |
927 | // em dash 151 -> 8212 |
928 | $string = str_replace("\227", '—', $string); |
3ab35042 |
929 | // small tilde 152 -> 732 |
930 | $string = str_replace("\230", '˜', $string); |
c37a12f8 |
931 | // trade mark sign 153 -> 8482 |
932 | $string = str_replace("\231", '™', $string); |
3ab35042 |
933 | // latin small letter s with caron 154 -> 353 |
934 | $string = str_replace("\232", 'š', $string); |
c37a12f8 |
935 | // single right-pointing angle quotation mark 155 -> 8250 |
936 | $string = str_replace("\233", '›', $string); |
3ab35042 |
937 | // latin small ligature oe 156 -> 339 |
938 | $string = str_replace("\234", 'œ', $string); |
939 | // latin capital letter y with diaresis 159->376 |
940 | $string = str_replace("\237", 'Ÿ', $string); |
941 | // latin capital letter g with breve 208->286 |
942 | $string = str_replace("\320", 'Ğ', $string); |
943 | // latin capital letter i with dot above 221->304 |
944 | $string = str_replace("\335", 'İ', $string); |
945 | // latin capital letter s with cedilla 222->350 |
946 | $string = str_replace("\336", 'Ş', $string); |
947 | // latin small letter g with breve 240->287 |
948 | $string = str_replace("\360", 'ğ', $string); |
949 | // latin small letter dotless i 253->305 |
950 | $string = str_replace("\375", 'ı', $string); |
951 | // latin small letter s with cedilla 254->351 |
952 | $string = str_replace("\376", 'ş', $string); |
953 | |
954 | // Rest of charset is like iso-8859-1 |
955 | return (charset_decode_iso_8859_1($string)); |
956 | } |
957 | |
958 | /* |
959 | windows-1253 (Greek) |
960 | */ |
961 | function charset_decode_windows_1253 ($string) { |
94965562 |
962 | global $default_charset; |
3ab35042 |
963 | |
94965562 |
964 | if (strtolower($default_charset) == 'windows-1253') |
3ab35042 |
965 | return $string; |
966 | |
967 | /* Only do the slow convert if there are 8-bit characters */ |
968 | if (! ereg("[\200-\377]", $string)) |
969 | return $string; |
970 | |
971 | $string = str_replace("\200", '€', $string); |
972 | $string = str_replace("\202", '‚', $string); |
973 | $string = str_replace("\203", 'ƒ', $string); |
974 | $string = str_replace("\204", '„', $string); |
975 | $string = str_replace("\205", '…', $string); |
976 | $string = str_replace("\206", '†', $string); |
977 | $string = str_replace("\207", '‡', $string); |
978 | $string = str_replace("\211", '‰', $string); |
979 | $string = str_replace("\213", '‹', $string); |
980 | $string = str_replace("\221", '‘', $string); |
981 | $string = str_replace("\222", '’', $string); |
982 | $string = str_replace("\223", '“', $string); |
983 | $string = str_replace("\224", '”', $string); |
984 | $string = str_replace("\225", '•', $string); |
985 | $string = str_replace("\226", '–', $string); |
986 | $string = str_replace("\227", '—', $string); |
987 | $string = str_replace("\231", '™', $string); |
988 | $string = str_replace("\233", '›', $string); |
989 | $string = str_replace("\241", '΅', $string); |
990 | $string = str_replace("\242", 'Ά', $string); |
991 | $string = str_replace ("\257", '―', $string); |
992 | $string = str_replace("\264", '΄', $string); |
993 | $string = str_replace("\270", 'Έ', $string); |
994 | $string = str_replace ("\271", 'Ή', $string); |
995 | $string = str_replace ("\272", 'Ί', $string); |
996 | $string = str_replace ("\274", 'Ό', $string); |
997 | // cycle for 190-254 symbols |
998 | $string = preg_replace("/([\274-\376])/e","'&#' . (ord('\\1')+720);",$string); |
999 | |
1000 | // Rest of charset is like iso-8859-1 |
1001 | return (charset_decode_iso_8859_1($string)); |
1002 | } |
1003 | |
1004 | |
1005 | /* |
1006 | windows-1257 (BaltRim) |
1007 | */ |
1008 | function charset_decode_windows_1257 ($string) { |
94965562 |
1009 | global $default_charset; |
3ab35042 |
1010 | |
1011 | if (strtolower($default_charset) == 'windows-1257') |
1012 | return $string; |
3ab35042 |
1013 | |
1014 | /* Only do the slow convert if there are 8-bit characters */ |
1015 | if (! ereg("[\200-\377]", $string)) |
1016 | return $string; |
1017 | |
1018 | $string = str_replace("\200", '€', $string); |
1019 | $string = str_replace("\202", '‚', $string); |
1020 | $string = str_replace("\204", '„', $string); |
1021 | $string = str_replace("\205", '…', $string); |
1022 | $string = str_replace("\206", '†', $string); |
1023 | $string = str_replace("\207", '‡', $string); |
1024 | $string = str_replace("\211", '‰', $string); |
1025 | $string = str_replace("\213", '‹', $string); |
1026 | $string = str_replace("\215", '¨', $string); |
1027 | $string = str_replace("\216", 'ˇ', $string); |
1028 | $string = str_replace("\217", '¸', $string); |
1029 | $string = str_replace("\221", '‘', $string); |
1030 | $string = str_replace("\222", '’', $string); |
1031 | $string = str_replace("\223", '“', $string); |
1032 | $string = str_replace("\224", '”', $string); |
1033 | $string = str_replace("\225", '•', $string); |
1034 | $string = str_replace("\226", '–', $string); |
1035 | $string = str_replace("\227", '—', $string); |
1036 | $string = str_replace("\231", '™', $string); |
1037 | $string = str_replace("\233", '›', $string); |
c37a12f8 |
1038 | $string = str_replace("\235", '¯', $string); |
c37a12f8 |
1039 | $string = str_replace("\236", '˛', $string); |
c37a12f8 |
1040 | $string = str_replace ("\250", 'Ø', $string); |
c37a12f8 |
1041 | $string = str_replace ("\252", 'Ŗ', $string); |
c37a12f8 |
1042 | $string = str_replace ("\257", 'Æ', $string); |
c37a12f8 |
1043 | $string = str_replace ("\270", 'ø', $string); |
c37a12f8 |
1044 | $string = str_replace ("\272", 'ŗ', $string); |
c37a12f8 |
1045 | $string = str_replace ("\277", 'æ', $string); |
c37a12f8 |
1046 | $string = str_replace ("\300", 'Ą', $string); |
c37a12f8 |
1047 | $string = str_replace ("\301", 'Į', $string); |
c37a12f8 |
1048 | $string = str_replace ("\302", 'Ā', $string); |
c37a12f8 |
1049 | $string = str_replace ("\303", 'Ć', $string); |
c37a12f8 |
1050 | $string = str_replace ("\306", 'Ę', $string); |
c37a12f8 |
1051 | $string = str_replace ("\307", 'Ē', $string); |
c37a12f8 |
1052 | $string = str_replace ("\310", 'Č', $string); |
c37a12f8 |
1053 | $string = str_replace ("\312", 'Ź', $string); |
c37a12f8 |
1054 | $string = str_replace ("\313", 'Ė', $string); |
c37a12f8 |
1055 | $string = str_replace ("\314", 'Ģ', $string); |
c37a12f8 |
1056 | $string = str_replace ("\315", 'Ķ', $string); |
c37a12f8 |
1057 | $string = str_replace ("\316", 'Ī', $string); |
c37a12f8 |
1058 | $string = str_replace ("\317", 'Ļ', $string); |
c37a12f8 |
1059 | $string = str_replace ("\320", 'Š', $string); |
c37a12f8 |
1060 | $string = str_replace ("\321", 'Ń', $string); |
c37a12f8 |
1061 | $string = str_replace ("\322", 'Ņ', $string); |
c37a12f8 |
1062 | $string = str_replace ("\324", 'Ō', $string); |
c37a12f8 |
1063 | $string = str_replace ("\330", 'Ų', $string); |
c37a12f8 |
1064 | $string = str_replace ("\331", 'Ł', $string); |
c37a12f8 |
1065 | $string = str_replace ("\332", 'Ŕ', $string); |
c37a12f8 |
1066 | $string = str_replace ("\333", 'Ū', $string); |
c37a12f8 |
1067 | $string = str_replace ("\335", 'Ż', $string); |
c37a12f8 |
1068 | $string = str_replace ("\336", 'Ž', $string); |
c37a12f8 |
1069 | $string = str_replace ("\340", 'ą', $string); |
c37a12f8 |
1070 | $string = str_replace ("\341", 'į', $string); |
c37a12f8 |
1071 | $string = str_replace ("\342", 'ā', $string); |
c37a12f8 |
1072 | $string = str_replace ("\343", 'ć', $string); |
c37a12f8 |
1073 | $string = str_replace ("\346", 'ę', $string); |
c37a12f8 |
1074 | $string = str_replace ("\347", 'ē', $string); |
c37a12f8 |
1075 | $string = str_replace ("\350", 'č', $string); |
c37a12f8 |
1076 | $string = str_replace ("\352", 'ź', $string); |
c37a12f8 |
1077 | $string = str_replace ("\353", 'ė', $string); |
c37a12f8 |
1078 | $string = str_replace ("\354", 'ģ', $string); |
c37a12f8 |
1079 | $string = str_replace ("\355", 'ķ', $string); |
c37a12f8 |
1080 | $string = str_replace ("\356", 'ī', $string); |
c37a12f8 |
1081 | $string = str_replace ("\357", 'ļ', $string); |
c37a12f8 |
1082 | $string = str_replace ("\360", 'š', $string); |
c37a12f8 |
1083 | $string = str_replace ("\361", 'ń', $string); |
c37a12f8 |
1084 | $string = str_replace ("\362", 'ņ', $string); |
c37a12f8 |
1085 | $string = str_replace ("\364", 'ō', $string); |
c37a12f8 |
1086 | $string = str_replace ("\370", 'ų', $string); |
c37a12f8 |
1087 | $string = str_replace ("\371", 'ł', $string); |
c37a12f8 |
1088 | $string = str_replace ("\372", 'ś', $string); |
c37a12f8 |
1089 | $string = str_replace ("\373", 'ū', $string); |
c37a12f8 |
1090 | $string = str_replace ("\375", 'ż', $string); |
c37a12f8 |
1091 | $string = str_replace ("\376", 'ž', $string); |
c37a12f8 |
1092 | $string = str_replace ("\377", '˙', $string); |
1093 | |
1094 | // Rest of charset is like iso-8859-1 |
1095 | return (charset_decode_iso_8859_1($string)); |
1096 | } |
1097 | |
ecd877a8 |
1098 | /* windows-1251 is Microsoft Cyrillic encoding */ |
1099 | function charset_decode_windows_1251 ($string) { |
1100 | // Convert to KOI8-R, then return this decoded. |
1101 | $string = convert_cyr_string($string, 'w', 'k'); |
1102 | return charset_decode_koi8r($string); |
1103 | } |
1104 | |
1105 | |
6fbd125b |
1106 | |
a2a7852b |
1107 | /* |
1108 | * Set up the language to be output |
1109 | * if $do_search is true, then scan the browser information |
1110 | * for a possible language that we know |
1111 | */ |
1112 | function set_up_language($sm_language, $do_search = false) { |
1113 | |
1114 | static $SetupAlready = 0; |
9eb0fbd4 |
1115 | global $use_gettext, $languages, |
a2a7852b |
1116 | $squirrelmail_language, $squirrelmail_default_language, |
1117 | $sm_notAlias; |
1118 | |
1119 | if ($SetupAlready) { |
1120 | return; |
1121 | } |
a65846a7 |
1122 | |
5c920668 |
1123 | $SetupAlready = TRUE; |
961ca3d8 |
1124 | sqgetGlobalVar('HTTP_ACCEPT_LANGUAGE', $accept_lang, SQ_SERVER); |
a2a7852b |
1125 | |
961ca3d8 |
1126 | if ($do_search && ! $sm_language && isset($accept_lang)) { |
1127 | $sm_language = substr($accept_lang, 0, 2); |
a2a7852b |
1128 | } |
66d7950f |
1129 | |
a2a7852b |
1130 | if (!$sm_language && isset($squirrelmail_default_language)) { |
1131 | $squirrelmail_language = $squirrelmail_default_language; |
66d7950f |
1132 | $sm_language = $squirrelmail_default_language; |
a2a7852b |
1133 | } |
1134 | $sm_notAlias = $sm_language; |
1135 | while (isset($languages[$sm_notAlias]['ALIAS'])) { |
1136 | $sm_notAlias = $languages[$sm_notAlias]['ALIAS']; |
1137 | } |
1138 | |
88cb1b4d |
1139 | if ( isset($sm_language) && |
5c920668 |
1140 | $use_gettext && |
1141 | $sm_language != '' && |
1142 | isset($languages[$sm_notAlias]['CHARSET']) ) { |
a65846a7 |
1143 | bindtextdomain( 'squirrelmail', SM_PATH . 'locale/' ); |
88cb1b4d |
1144 | textdomain( 'squirrelmail' ); |
7928848f |
1145 | if (function_exists('bind_textdomain_codeset')) { |
1146 | bind_textdomain_codeset ("squirrelmail", $languages[$sm_notAlias]['CHARSET'] ); |
1147 | } |
88cb1b4d |
1148 | if ( !ini_get('safe_mode') && |
5c920668 |
1149 | getenv( 'LC_ALL' ) != $sm_notAlias ) { |
1150 | putenv( "LC_ALL=$sm_notAlias" ); |
1151 | putenv( "LANG=$sm_notAlias" ); |
1152 | putenv( "LANGUAGE=$sm_notAlias" ); |
a2a7852b |
1153 | } |
88cb1b4d |
1154 | setlocale(LC_ALL, $sm_notAlias); |
5c920668 |
1155 | $squirrelmail_language = $sm_notAlias; |
538f1ab7 |
1156 | if ($squirrelmail_language == 'ja_JP' && function_exists('mb_detect_encoding') ) { |
b05c8961 |
1157 | header ('Content-Type: text/html; charset=EUC-JP'); |
1158 | if (!function_exists('mb_internal_encoding')) { |
e842b215 |
1159 | echo _("You need to have php4 installed with the multibyte string function enabled (using configure option --enable-mbstring)."); |
1160 | } |
1161 | if (function_exists('mb_language')) { |
1162 | mb_language('Japanese'); |
b05c8961 |
1163 | } |
1164 | mb_internal_encoding('EUC-JP'); |
1165 | mb_http_output('pass'); |
1166 | } else { |
5c920668 |
1167 | header( 'Content-Type: text/html; charset=' . $languages[$sm_notAlias]['CHARSET'] ); |
a2a7852b |
1168 | } |
1169 | } |
b05c8961 |
1170 | } |
a2a7852b |
1171 | |
1172 | function set_my_charset(){ |
1173 | |
1174 | /* |
1175 | * There can be a $default_charset setting in the |
1176 | * config.php file, but the user may have a different language |
1177 | * selected for a user interface. This function checks the |
1178 | * language selected by the user and tags the outgoing messages |
1179 | * with the appropriate charset corresponding to the language |
1180 | * selection. This is "more right" (tm), than just stamping the |
1181 | * message blindly with the system-wide $default_charset. |
1182 | */ |
94965562 |
1183 | global $data_dir, $username, $default_charset, $languages, $squirrelmail_default_language; |
88cb1b4d |
1184 | |
a2a7852b |
1185 | $my_language = getPref($data_dir, $username, 'language'); |
5c920668 |
1186 | if (!$my_language) { |
94965562 |
1187 | $my_language = $squirrelmail_default_language ; |
5c920668 |
1188 | } |
a2a7852b |
1189 | while (isset($languages[$my_language]['ALIAS'])) { |
f7e8861e |
1190 | $my_language = $languages[$my_language]['ALIAS']; |
a2a7852b |
1191 | } |
5c920668 |
1192 | $my_charset = $languages[$my_language]['CHARSET']; |
a2a7852b |
1193 | if ($my_charset) { |
1194 | $default_charset = $my_charset; |
1195 | } |
1196 | } |
1197 | |
a2a7852b |
1198 | /* ------------------------------ main --------------------------- */ |
1199 | |
5c920668 |
1200 | global $squirrelmail_language, $languages, $use_gettext; |
1201 | |
a2a7852b |
1202 | if (! isset($squirrelmail_language)) { |
1203 | $squirrelmail_language = ''; |
1204 | } |
1205 | |
1206 | /* This array specifies the available languages. */ |
5c920668 |
1207 | |
1208 | // The glibc locale is ca_ES. |
1209 | |
1210 | $languages['ca_ES']['NAME'] = 'Catalan'; |
1211 | $languages['ca_ES']['CHARSET'] = 'iso-8859-1'; |
1212 | $languages['ca']['ALIAS'] = 'ca_ES'; |
1213 | |
a2a7852b |
1214 | $languages['cs_CZ']['NAME'] = 'Czech'; |
1215 | $languages['cs_CZ']['CHARSET'] = 'iso-8859-2'; |
1216 | $languages['cs']['ALIAS'] = 'cs_CZ'; |
a2a7852b |
1217 | |
5c920668 |
1218 | // Danish locale is da_DK. |
1219 | |
1220 | $languages['da_DK']['NAME'] = 'Danish'; |
1221 | $languages['da_DK']['CHARSET'] = 'iso-8859-1'; |
1222 | $languages['da']['ALIAS'] = 'da_DK'; |
1223 | |
1224 | $languages['de_DE']['NAME'] = 'Deutsch'; |
1225 | $languages['de_DE']['CHARSET'] = 'iso-8859-1'; |
1226 | $languages['de']['ALIAS'] = 'de_DE'; |
a2a7852b |
1227 | |
5c920668 |
1228 | // There is no en_EN! There is en_US, en_BR, en_AU, and so forth, |
1229 | // but who cares about !US, right? Right? :) |
a2a7852b |
1230 | |
3ab35042 |
1231 | $languages['el_GR']['NAME'] = 'Greek'; |
1232 | $languages['el_GR']['CHARSET'] = 'iso-8859-7'; |
1233 | $languages['el']['ALIAS'] = 'el_GR'; |
1234 | |
5c920668 |
1235 | $languages['en_US']['NAME'] = 'English'; |
1236 | $languages['en_US']['CHARSET'] = 'iso-8859-1'; |
1237 | $languages['en']['ALIAS'] = 'en_US'; |
a2a7852b |
1238 | |
5c920668 |
1239 | $languages['es_ES']['NAME'] = 'Spanish'; |
1240 | $languages['es_ES']['CHARSET'] = 'iso-8859-1'; |
1241 | $languages['es']['ALIAS'] = 'es_ES'; |
a2a7852b |
1242 | |
5c920668 |
1243 | $languages['et_EE']['NAME'] = 'Estonian'; |
1244 | $languages['et_EE']['CHARSET'] = 'iso-8859-15'; |
1245 | $languages['et']['ALIAS'] = 'et_EE'; |
a2a7852b |
1246 | |
1ad5ab3a |
1247 | $languages['fo_FO']['NAME'] = 'Faroese'; |
1248 | $languages['fo_FO']['CHARSET'] = 'iso-8859-1'; |
1249 | $languages['fo']['ALIAS'] = 'fo_FO'; |
1250 | |
5c920668 |
1251 | $languages['fi_FI']['NAME'] = 'Finnish'; |
1252 | $languages['fi_FI']['CHARSET'] = 'iso-8859-1'; |
1253 | $languages['fi']['ALIAS'] = 'fi_FI'; |
a2a7852b |
1254 | |
5c920668 |
1255 | $languages['fr_FR']['NAME'] = 'French'; |
1256 | $languages['fr_FR']['CHARSET'] = 'iso-8859-1'; |
1257 | $languages['fr']['ALIAS'] = 'fr_FR'; |
a2a7852b |
1258 | |
5c920668 |
1259 | $languages['hr_HR']['NAME'] = 'Croatian'; |
1260 | $languages['hr_HR']['CHARSET'] = 'iso-8859-2'; |
1261 | $languages['hr']['ALIAS'] = 'hr_HR'; |
a2a7852b |
1262 | |
5c920668 |
1263 | $languages['hu_HU']['NAME'] = 'Hungarian'; |
1264 | $languages['hu_HU']['CHARSET'] = 'iso-8859-2'; |
1265 | $languages['hu']['ALIAS'] = 'hu_HU'; |
a2a7852b |
1266 | |
d90198d0 |
1267 | $languages['id_ID']['NAME'] = 'Bahasa Indonesia'; |
5c920668 |
1268 | $languages['id_ID']['CHARSET'] = 'iso-8859-1'; |
1269 | $languages['id']['ALIAS'] = 'id_ID'; |
a2a7852b |
1270 | |
5c920668 |
1271 | $languages['is_IS']['NAME'] = 'Icelandic'; |
1272 | $languages['is_IS']['CHARSET'] = 'iso-8859-1'; |
1273 | $languages['is']['ALIAS'] = 'is_IS'; |
a2a7852b |
1274 | |
5c920668 |
1275 | $languages['it_IT']['NAME'] = 'Italian'; |
1276 | $languages['it_IT']['CHARSET'] = 'iso-8859-1'; |
1277 | $languages['it']['ALIAS'] = 'it_IT'; |
a2a7852b |
1278 | |
b05c8961 |
1279 | $languages['ja_JP']['NAME'] = 'Japanese'; |
1280 | $languages['ja_JP']['CHARSET'] = 'iso-2022-jp'; |
6fbd125b |
1281 | $languages['ja_JP']['XTRA_CODE'] = 'japanese_charset_xtra'; |
b05c8961 |
1282 | $languages['ja']['ALIAS'] = 'ja_JP'; |
1283 | |
5c920668 |
1284 | $languages['ko_KR']['NAME'] = 'Korean'; |
1285 | $languages['ko_KR']['CHARSET'] = 'euc-KR'; |
1d33e35e |
1286 | $languages['ko_KR']['XTRA_CODE'] = 'korean_charset_xtra'; |
5c920668 |
1287 | $languages['ko']['ALIAS'] = 'ko_KR'; |
a2a7852b |
1288 | |
5c920668 |
1289 | $languages['nl_NL']['NAME'] = 'Dutch'; |
1290 | $languages['nl_NL']['CHARSET'] = 'iso-8859-1'; |
1291 | $languages['nl']['ALIAS'] = 'nl_NL'; |
a2a7852b |
1292 | |
5c920668 |
1293 | $languages['no_NO']['NAME'] = 'Norwegian (Bokmål)'; |
1294 | $languages['no_NO']['CHARSET'] = 'iso-8859-1'; |
1295 | $languages['no']['ALIAS'] = 'no_NO'; |
b8b4ac4a |
1296 | $languages['nn_NO']['NAME'] = 'Norwegian (Nynorsk)'; |
1297 | $languages['nn_NO']['CHARSET'] = 'iso-8859-1'; |
a2a7852b |
1298 | |
5c920668 |
1299 | $languages['pl_PL']['NAME'] = 'Polish'; |
1300 | $languages['pl_PL']['CHARSET'] = 'iso-8859-2'; |
1301 | $languages['pl']['ALIAS'] = 'pl_PL'; |
a2a7852b |
1302 | |
5c920668 |
1303 | $languages['pt_PT']['NAME'] = 'Portuguese (Portugal)'; |
1304 | $languages['pt_PT']['CHARSET'] = 'iso-8859-1'; |
a2a7852b |
1305 | $languages['pt_BR']['NAME'] = 'Portuguese (Brazil)'; |
1306 | $languages['pt_BR']['CHARSET'] = 'iso-8859-1'; |
5c920668 |
1307 | $languages['pt']['ALIAS'] = 'pt_PT'; |
a2a7852b |
1308 | |
5c920668 |
1309 | $languages['ru_RU']['NAME'] = 'Russian'; |
1310 | $languages['ru_RU']['CHARSET'] = 'koi8-r'; |
1311 | $languages['ru']['ALIAS'] = 'ru_RU'; |
a2a7852b |
1312 | |
dbec0d67 |
1313 | $languages['sr_YU']['NAME'] = 'Serbian'; |
1314 | $languages['sr_YU']['CHARSET'] = 'iso-8859-2'; |
1315 | $languages['sr']['ALIAS'] = 'sr_YU'; |
a2a7852b |
1316 | |
5c920668 |
1317 | $languages['sv_SE']['NAME'] = 'Swedish'; |
1318 | $languages['sv_SE']['CHARSET'] = 'iso-8859-1'; |
1319 | $languages['sv']['ALIAS'] = 'sv_SE'; |
a2a7852b |
1320 | |
5c920668 |
1321 | $languages['tr_TR']['NAME'] = 'Turkish'; |
1322 | $languages['tr_TR']['CHARSET'] = 'iso-8859-9'; |
1323 | $languages['tr']['ALIAS'] = 'tr_TR'; |
a2a7852b |
1324 | |
b62c1863 |
1325 | $languages['zh_TW']['NAME'] = 'Chinese Trad'; |
5c920668 |
1326 | $languages['zh_TW']['CHARSET'] = 'big5'; |
1327 | $languages['tw']['ALIAS'] = 'zh_TW'; |
a2a7852b |
1328 | |
b62c1863 |
1329 | $languages['zh_CN']['NAME'] = 'Chinese Simp'; |
1330 | $languages['zh_CN']['CHARSET'] = 'gb2312'; |
1331 | $languages['cn']['ALIAS'] = 'zh_CN'; |
8ba79a3b |
1332 | |
a2a7852b |
1333 | $languages['sk_SK']['NAME'] = 'Slovak'; |
1334 | $languages['sk_SK']['CHARSET'] = 'iso-8859-2'; |
1335 | $languages['sk']['ALIAS'] = 'sk_SK'; |
1336 | |
5c920668 |
1337 | $languages['ro_RO']['NAME'] = 'Romanian'; |
1338 | $languages['ro_RO']['CHARSET'] = 'iso-8859-2'; |
1339 | $languages['ro']['ALIAS'] = 'ro_RO'; |
a2a7852b |
1340 | |
5c920668 |
1341 | $languages['th_TH']['NAME'] = 'Thai'; |
1342 | $languages['th_TH']['CHARSET'] = 'tis-620'; |
1343 | $languages['th']['ALIAS'] = 'th_TH'; |
a2a7852b |
1344 | |
5c920668 |
1345 | $languages['lt_LT']['NAME'] = 'Lithuanian'; |
923229f2 |
1346 | $languages['lt_LT']['CHARSET'] = 'windows-1257'; |
5c920668 |
1347 | $languages['lt']['ALIAS'] = 'lt_LT'; |
a2a7852b |
1348 | |
5c920668 |
1349 | $languages['sl_SI']['NAME'] = 'Slovenian'; |
1350 | $languages['sl_SI']['CHARSET'] = 'iso-8859-2'; |
1351 | $languages['sl']['ALIAS'] = 'sl_SI'; |
a2a7852b |
1352 | |
5c920668 |
1353 | $languages['bg_BG']['NAME'] = 'Bulgarian'; |
1354 | $languages['bg_BG']['CHARSET'] = 'windows-1251'; |
1355 | $languages['bg']['ALIAS'] = 'bg_BG'; |
a2a7852b |
1356 | |
93ea3e70 |
1357 | $languages['uk_UA']['NAME'] = 'Ukrainian'; |
1358 | $languages['uk_UA']['CHARSET'] = 'koi8-u'; |
1359 | $languages['uk']['ALIAS'] = 'uk_UA'; |
1360 | |
969a0af6 |
1361 | $languages['cy_GB']['NAME'] = 'Welsh'; |
1362 | $languages['cy_GB']['CHARSET'] = 'iso-8859-1'; |
1363 | $languages['cy']['ALIAS'] = 'cy_GB'; |
b7617386 |
1364 | |
d90198d0 |
1365 | $languages['vi_VN']['NAME'] = 'Vietnamese'; |
1366 | $languages['vi_VN']['CHARSET'] = 'utf-8'; |
1367 | $languages['vi']['ALIAS'] = 'vi_VN'; |
b7617386 |
1368 | |
d3b57948 |
1369 | // Right to left languages |
1370 | |
7e3f5be8 |
1371 | $languages['ar']['NAME'] = 'Arabic'; |
1372 | $languages['ar']['CHARSET'] = 'windows-1256'; |
1373 | $languages['ar']['DIR'] = 'rtl'; |
1374 | |
ace72c6a |
1375 | $languages['he_IL']['NAME'] = 'Hebrew'; |
1376 | $languages['he_IL']['CHARSET'] = 'windows-1255'; |
1377 | $languages['he_IL']['DIR'] = 'rtl'; |
1378 | $languages['he']['ALIAS'] = 'he_IL'; |
d3b57948 |
1379 | |
5c920668 |
1380 | /* Detect whether gettext is installed. */ |
a2a7852b |
1381 | $gettext_flags = 0; |
1382 | if (function_exists('_')) { |
1383 | $gettext_flags += 1; |
1384 | } |
1385 | if (function_exists('bindtextdomain')) { |
1386 | $gettext_flags += 2; |
1387 | } |
1388 | if (function_exists('textdomain')) { |
1389 | $gettext_flags += 4; |
1390 | } |
1391 | |
5c920668 |
1392 | /* If gettext is fully loaded, cool */ |
a2a7852b |
1393 | if ($gettext_flags == 7) { |
1394 | $use_gettext = true; |
1395 | } |
5c920668 |
1396 | /* If we can fake gettext, try that */ |
a2a7852b |
1397 | elseif ($gettext_flags == 0) { |
1398 | $use_gettext = true; |
e7ab8c9d |
1399 | include_once(SM_PATH . 'functions/gettext.php'); |
a2a7852b |
1400 | } else { |
5c920668 |
1401 | /* Uh-ho. A weird install */ |
a2a7852b |
1402 | if (! $gettext_flags & 1) { |
1403 | function _($str) { |
1404 | return $str; |
1405 | } |
1406 | } |
1407 | if (! $gettext_flags & 2) { |
1408 | function bindtextdomain() { |
1409 | return; |
1410 | } |
1411 | } |
1412 | if (! $gettext_flags & 4) { |
1413 | function textdomain() { |
1414 | return; |
1415 | } |
1416 | } |
1417 | } |
1418 | |
3ab35042 |
1419 | function charset_decode_utf8 ($string) { |
1420 | /* |
1421 | Every decoded character consists of n bytes. First byte is octal |
1422 | 300-375, other bytes - always octals 200-277. |
1423 | |
1424 | \a\b characters are decoded to html code octdec(a-300)*64 + octdec(b-200) |
1425 | \a\b\c characters are decoded to html code octdec(a-340)*64*64 + octdec(b-200)*64 + octdec(c-200) |
1426 | |
1427 | decoding cycle is unfinished. please test and report problems to tokul@users.sourceforge.net |
1428 | */ |
1429 | global $default_charset, $languages, $sm_notAlias; |
1430 | |
1431 | if (strtolower($default_charset) == 'utf-8') |
1432 | return $string; |
1433 | if (strtolower($languages[$sm_notAlias]['CHARSET']) == 'utf-8') |
1434 | return $string; |
1435 | |
1436 | /* Only do the slow convert if there are 8-bit characters */ |
1437 | if (! ereg("[\200-\377]", $string)) |
1438 | return $string; |
1439 | |
1440 | // decode three byte unicode characters |
1441 | $string = preg_replace("/([\340-\357])([\200-\277])([\200-\277])/e", |
1442 | "'&#'.((ord('\\1')-224)*4096+(ord('\\2')-128)*64+(ord('\\3')-128)).';'", |
1443 | $string); |
1444 | |
1445 | // decode two byte unicode characters |
1446 | $string = preg_replace("/([\300-\337])([\200-\277])/e", |
1447 | "'&#'.((ord('\\1')-192)*64+(ord('\\2')-128)).';'", |
1448 | $string); |
1449 | |
1450 | return $string; |
1451 | } |
1d33e35e |
1452 | |
1453 | /* |
1454 | * Japanese charset extra function |
1455 | * |
1456 | */ |
1457 | function japanese_charset_xtra() { |
1458 | $ret = func_get_arg(1); /* default return value */ |
1459 | if (function_exists('mb_detect_encoding')) { |
1460 | switch (func_get_arg(0)) { /* action */ |
1461 | case 'decode': |
e842b215 |
1462 | $detect_encoding = @mb_detect_encoding($ret); |
1d33e35e |
1463 | if ($detect_encoding == 'JIS' || |
1464 | $detect_encoding == 'EUC-JP' || |
e842b215 |
1465 | $detect_encoding == 'SJIS' || |
1466 | $detect_encoding == 'UTF-8') { |
1d33e35e |
1467 | |
e842b215 |
1468 | $ret = mb_convert_kana(mb_convert_encoding($ret, 'EUC-JP', 'AUTO'), "KV"); |
1d33e35e |
1469 | } |
1470 | break; |
1471 | case 'encode': |
e842b215 |
1472 | $detect_encoding = @mb_detect_encoding($ret); |
1d33e35e |
1473 | if ($detect_encoding == 'JIS' || |
1474 | $detect_encoding == 'EUC-JP' || |
e842b215 |
1475 | $detect_encoding == 'SJIS' || |
1476 | $detect_encoding == 'UTF-8') { |
1d33e35e |
1477 | |
e842b215 |
1478 | $ret = mb_convert_encoding(mb_convert_kana($ret, "KV"), 'JIS', 'AUTO'); |
1d33e35e |
1479 | } |
1480 | break; |
1481 | case 'strimwidth': |
1482 | $width = func_get_arg(2); |
1483 | $ret = mb_strimwidth($ret, 0, $width, '...'); |
1484 | break; |
1485 | case 'encodeheader': |
8ba05cbe |
1486 | $result = ''; |
1487 | if (strlen($ret) > 0) { |
1488 | $tmpstr = mb_substr($ret, 0, 1); |
1489 | $prevcsize = strlen($tmpstr); |
1490 | for ($i = 1; $i < mb_strlen($ret); $i++) { |
1491 | $tmp = mb_substr($ret, $i, 1); |
1492 | if (strlen($tmp) == $prevcsize) { |
1493 | $tmpstr .= $tmp; |
1494 | } else { |
1495 | if ($prevcsize == 1) { |
1496 | $result .= $tmpstr; |
1497 | } else { |
e842b215 |
1498 | $result .= str_replace(' ', '', |
1499 | mb_encode_mimeheader($tmpstr,'iso-2022-jp','B','')); |
8ba05cbe |
1500 | } |
1501 | $tmpstr = $tmp; |
1502 | $prevcsize = strlen($tmp); |
1503 | } |
1504 | } |
1505 | if (strlen($tmpstr)) { |
1506 | if (strlen(mb_substr($tmpstr, 0, 1)) == 1) |
1507 | $result .= $tmpstr; |
1508 | else |
e842b215 |
1509 | $result .= str_replace(' ', '', |
1510 | mb_encode_mimeheader($tmpstr,'iso-2022-jp','B','')); |
8ba05cbe |
1511 | } |
1512 | } |
1513 | $ret = $result; |
1d33e35e |
1514 | break; |
1515 | case 'decodeheader': |
1516 | $ret = str_replace("\t", "", $ret); |
1517 | if (eregi('=\\?([^?]+)\\?(q|b)\\?([^?]+)\\?=', $ret)) |
e842b215 |
1518 | $ret = @mb_decode_mimeheader($ret); |
1519 | $ret = @mb_convert_encoding($ret, 'EUC-JP', 'AUTO'); |
1d33e35e |
1520 | break; |
1521 | case 'downloadfilename': |
1522 | $useragent = func_get_arg(2); |
1523 | if (strstr($useragent, 'Windows') !== false || |
1524 | strstr($useragent, 'Mac_') !== false) { |
1525 | $ret = mb_convert_encoding($ret, 'SJIS', 'AUTO'); |
1526 | } else { |
1527 | $ret = mb_convert_encoding($ret, 'EUC-JP', 'AUTO'); |
1528 | } |
1529 | break; |
e842b215 |
1530 | case 'wordwrap': |
1531 | $no_begin = "\x21\x25\x29\x2c\x2e\x3a\x3b\x3f\x5d\x7d\xa1\xf1\xa1\xeb\xa1" . |
1532 | "\xc7\xa1\xc9\xa2\xf3\xa1\xec\xa1\xed\xa1\xee\xa1\xa2\xa1\xa3\xa1\xb9" . |
1533 | "\xa1\xd3\xa1\xd5\xa1\xd7\xa1\xd9\xa1\xdb\xa1\xcd\xa4\xa1\xa4\xa3\xa4" . |
1534 | "\xa5\xa4\xa7\xa4\xa9\xa4\xc3\xa4\xe3\xa4\xe5\xa4\xe7\xa4\xee\xa1\xab" . |
1535 | "\xa1\xac\xa1\xb5\xa1\xb6\xa5\xa1\xa5\xa3\xa5\xa5\xa5\xa7\xa5\xa9\xa5" . |
1536 | "\xc3\xa5\xe3\xa5\xe5\xa5\xe7\xa5\xee\xa5\xf5\xa5\xf6\xa1\xa6\xa1\xbc" . |
1537 | "\xa1\xb3\xa1\xb4\xa1\xaa\xa1\xf3\xa1\xcb\xa1\xa4\xa1\xa5\xa1\xa7\xa1" . |
1538 | "\xa8\xa1\xa9\xa1\xcf\xa1\xd1"; |
1539 | $no_end = "\x5c\x24\x28\x5b\x7b\xa1\xf2\x5c\xa1\xc6\xa1\xc8\xa1\xd2\xa1" . |
1540 | "\xd4\xa1\xd6\xa1\xd8\xa1\xda\xa1\xcc\xa1\xf0\xa1\xca\xa1\xce\xa1\xd0\xa1\xef"; |
1541 | $wrap = func_get_arg(2); |
1542 | |
1543 | if (strlen($ret) >= $wrap && |
1544 | substr($ret, 0, 1) != '>' && |
1545 | strpos($ret, 'http://') === FALSE && |
1546 | strpos($ret, 'https://') === FALSE && |
1547 | strpos($ret, 'ftp://') === FALSE) { |
1548 | |
1549 | $ret = mb_convert_kana($ret, "KV"); |
1550 | |
1551 | $line_new = ''; |
1552 | $ptr = 0; |
1553 | |
1554 | while ($ptr < strlen($ret) - 1) { |
1555 | $l = mb_strcut($ret, $ptr, $wrap); |
1556 | $ptr += strlen($l); |
1557 | $tmp = $l; |
1558 | |
1559 | $l = mb_strcut($ret, $ptr, 2); |
1560 | while (strlen($l) != 0 && mb_strpos($no_begin, $l) !== FALSE ) { |
1561 | $tmp .= $l; |
1562 | $ptr += strlen($l); |
1563 | $l = mb_strcut($ret, $ptr, 1); |
1564 | } |
1565 | $line_new .= $tmp; |
1566 | if ($ptr < strlen($ret) - 1) |
1567 | $line_new .= "\n"; |
1568 | } |
1569 | $ret = $line_new; |
1570 | } |
1571 | break; |
1572 | case 'utf7-imap_encode': |
1573 | $ret = mb_convert_encoding($ret, 'UTF7-IMAP', 'EUC-JP'); |
1574 | break; |
1575 | case 'utf7-imap_decode': |
1576 | $ret = mb_convert_encoding($ret, 'EUC-JP', 'UTF7-IMAP'); |
1577 | break; |
1d33e35e |
1578 | } |
1579 | } |
1580 | return $ret; |
1581 | } |
1582 | |
1583 | |
1584 | /* |
1585 | * Korean charset extra function |
1586 | * Hangul(Korean Character) Attached File Name Fix. |
1587 | */ |
1588 | function korean_charset_xtra() { |
1589 | |
1590 | $ret = func_get_arg(1); /* default return value */ |
1591 | if (func_get_arg(0) == 'downloadfilename') { /* action */ |
1592 | $ret = str_replace("\x0D\x0A", '', $ret); /* Hanmail's CR/LF Clear */ |
1593 | for ($i=0;$i<strlen($ret);$i++) { |
1594 | if ($ret[$i] >= "\xA1" && $ret[$i] <= "\xFE") { /* 0xA1 - 0XFE are Valid */ |
1595 | $i++; |
1596 | continue; |
1597 | } else if (($ret[$i] >= 'a' && $ret[$i] <= 'z') || /* From Original ereg_replace in download.php */ |
1598 | ($ret[$i] >= 'A' && $ret[$i] <= 'Z') || |
1599 | ($ret[$i] == '.') || ($ret[$i] == '-')) { |
1600 | continue; |
1601 | } else { |
1602 | $ret[$i] = '_'; |
1603 | } |
1604 | } |
1605 | |
1606 | } |
1607 | |
1608 | return $ret; |
1609 | } |
1610 | |
e842b215 |
1611 | ?> |