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) { |
3ec81e63 |
22 | global $languages, $squirrelmail_language, $default_charset; |
edf2c0ba |
23 | global $use_php_recode, $use_php_iconv, $agresive_decoding; |
a2a7852b |
24 | |
3714db45 |
25 | if (isset($languages[$squirrelmail_language]['XTRA_CODE']) && |
26 | function_exists($languages[$squirrelmail_language]['XTRA_CODE'])) { |
6fbd125b |
27 | $string = $languages[$squirrelmail_language]['XTRA_CODE']('decode', $string); |
28 | } |
b05c8961 |
29 | |
3ec81e63 |
30 | $charset = strtolower($charset); |
31 | |
32 | set_my_charset(); |
33 | |
34 | // Variables that allow to use functions without function_exist() calls |
edf2c0ba |
35 | if (! isset($use_php_recode) || $use_php_recode=="" ) { |
36 | $use_php_recode=false; } |
37 | if (! isset($use_php_iconv) || $use_php_iconv=="" ) { |
38 | $use_php_iconv=false; } |
3ec81e63 |
39 | |
40 | // Don't do conversion if charset is the same. |
41 | if ( $charset == strtolower($default_charset) ) |
42 | return htmlspecialchars($string); |
43 | |
44 | // catch iso-8859-8-i thing |
45 | if ( $charset == "iso-8859-8-i" ) |
46 | $charset = "iso-8859-8"; |
47 | |
48 | /* |
49 | * Recode converts html special characters automatically if you use |
50 | * 'charset..html' decoding. There is no documented way to put -d option |
51 | * into php recode function call. |
52 | */ |
53 | if ( $use_php_recode ) { |
54 | if ( $default_charset == "utf-8" ) { |
55 | // other charsets can be converted to utf-8 without loss. |
56 | // and output string is smaller |
57 | $string = recode_string($charset . "..utf-8",$string); |
58 | return htmlspecialchars($string); |
59 | } else { |
60 | $string = recode_string($charset . "..html",$string); |
61 | // recode does not convert single quote, htmlspecialchars does. |
62 | $string = str_replace("'", ''', $string); |
63 | return $string; |
64 | } |
65 | } |
66 | |
67 | // iconv functions does not have html target and can be used only with utf-8 |
68 | if ( $use_php_iconv && $default_charset=='utf-8') { |
69 | $string = iconv($charset,$default_charset,$string); |
70 | return htmlspecialchars($string); |
71 | } |
72 | |
73 | // If we don't use recode and iconv, we'll do it old way. |
74 | |
a2a7852b |
75 | /* All HTML special characters are 7 bit and can be replaced first */ |
cef054e4 |
76 | |
098ea084 |
77 | $string = htmlspecialchars ($string); |
a2a7852b |
78 | |
5dd23dac |
79 | /* controls cpu and memory intensive decoding cycles */ |
edf2c0ba |
80 | if (! isset($agresive_decoding) || $agresive_decoding=="" ) { |
81 | $agresive_decoding=false; } |
5dd23dac |
82 | |
a2a7852b |
83 | if (ereg('iso-8859-([[:digit:]]+)', $charset, $res)) { |
84 | if ($res[1] == '1') { |
5dd23dac |
85 | include_once(SM_PATH . 'functions/decode/iso8859-1.php'); |
86 | $ret = charset_decode_iso8859_1 ($string); |
a2a7852b |
87 | } else if ($res[1] == '2') { |
5dd23dac |
88 | include_once(SM_PATH . 'functions/decode/iso8859-2.php'); |
89 | $ret = charset_decode_iso8859_2 ($string); |
3a66bed2 |
90 | } else if ($res[1] == '3') { |
91 | include_once(SM_PATH . 'functions/decode/iso8859-3.php'); |
92 | $ret = charset_decode_iso8859_3 ($string); |
9be313d5 |
93 | } else if ($res[1] == '4') { |
3a66bed2 |
94 | include_once(SM_PATH . 'functions/decode/iso8859-4.php'); |
95 | $ret = charset_decode_iso8859_4 ($string); |
94965562 |
96 | } else if ($res[1] == '5') { |
3a66bed2 |
97 | include_once(SM_PATH . 'functions/decode/iso8859-5.php'); |
98 | $ret = charset_decode_iso8859_5 ($string); |
ef82d2d5 |
99 | } else if ($res[1] == '6') { |
5dd23dac |
100 | include_once(SM_PATH . 'functions/decode/iso8859-6.php'); |
101 | $ret = charset_decode_iso8859_6 ($string); |
a2a7852b |
102 | } else if ($res[1] == '7') { |
5dd23dac |
103 | include_once(SM_PATH . 'functions/decode/iso8859-7.php'); |
104 | $ret = charset_decode_iso8859_7 ($string); |
3a66bed2 |
105 | } else if ($res[1] == '8') { |
106 | include_once(SM_PATH . 'functions/decode/iso8859-8.php'); |
107 | $ret = charset_decode_iso8859_8 ($string); |
3ab35042 |
108 | } else if ($res[1] == '9') { |
5dd23dac |
109 | include_once(SM_PATH . 'functions/decode/iso8859-9.php'); |
110 | $ret = charset_decode_iso8859_9 ($string); |
3a66bed2 |
111 | } else if ($res[1] == '10') { |
112 | include_once(SM_PATH . 'functions/decode/iso8859-10.php'); |
113 | $ret = charset_decode_iso8859_10 ($string); |
114 | } else if ($res[1] == '11') { |
115 | include_once(SM_PATH . 'functions/decode/iso8859-11.php'); |
116 | $ret = charset_decode_iso8859_11 ($string); |
9be313d5 |
117 | } else if ($res[1] == '13') { |
3a66bed2 |
118 | include_once(SM_PATH . 'functions/decode/iso8859-13.php'); |
119 | $ret = charset_decode_iso8859_13 ($string); |
120 | } else if ($res[1] == '14') { |
121 | include_once(SM_PATH . 'functions/decode/iso8859-14.php'); |
122 | $ret = charset_decode_iso8859_14 ($string); |
a2a7852b |
123 | } else if ($res[1] == '15') { |
5dd23dac |
124 | include_once(SM_PATH . 'functions/decode/iso8859-15.php'); |
125 | $ret = charset_decode_iso8859_15 ($string); |
3a66bed2 |
126 | } else if ($res[1] == '16') { |
127 | include_once(SM_PATH . 'functions/decode/iso8859-16.php'); |
128 | $ret = charset_decode_iso8859_16 ($string); |
a2a7852b |
129 | } else { |
130 | $ret = charset_decode_iso_8859_default ($string); |
131 | } |
132 | } else if ($charset == 'ns_4551-1') { |
133 | $ret = charset_decode_ns_4551_1 ($string); |
134 | } else if ($charset == 'koi8-r') { |
5dd23dac |
135 | include_once(SM_PATH . 'functions/decode/koi8-r.php'); |
a2a7852b |
136 | $ret = charset_decode_koi8r ($string); |
1c0e847f |
137 | } else if ($charset == 'koi8-u') { |
5dd23dac |
138 | include_once(SM_PATH . 'functions/decode/koi8-u.php'); |
1c0e847f |
139 | $ret = charset_decode_koi8u ($string); |
5dd23dac |
140 | } else if ($charset == 'windows-1250') { |
141 | include_once(SM_PATH . 'functions/decode/cp1250.php'); |
142 | $ret = charset_decode_cp1250 ($string); |
a2a7852b |
143 | } else if ($charset == 'windows-1251') { |
5dd23dac |
144 | include_once(SM_PATH . 'functions/decode/cp1251.php'); |
145 | $ret = charset_decode_cp1251 ($string); |
146 | } else if ($charset == 'windows-1252') { |
147 | include_once(SM_PATH . 'functions/decode/cp1252.php'); |
148 | $ret = charset_decode_cp1252 ($string); |
3ab35042 |
149 | } else if ($charset == 'windows-1253') { |
5dd23dac |
150 | include_once(SM_PATH . 'functions/decode/cp1253.php'); |
151 | $ret = charset_decode_cp1253 ($string); |
3ab35042 |
152 | } else if ($charset == 'windows-1254') { |
5dd23dac |
153 | include_once(SM_PATH . 'functions/decode/cp1254.php'); |
154 | $ret = charset_decode_cp1254 ($string); |
c48a8ca7 |
155 | } else if ($charset == 'windows-1255') { |
5dd23dac |
156 | include_once(SM_PATH . 'functions/decode/cp1255.php'); |
157 | $ret = charset_decode_cp1255 ($string); |
c48a8ca7 |
158 | } else if ($charset == 'windows-1256') { |
5dd23dac |
159 | include_once(SM_PATH . 'functions/decode/cp1256.php'); |
160 | $ret = charset_decode_cp1256 ($string); |
c37a12f8 |
161 | } else if ($charset == 'windows-1257') { |
3a66bed2 |
162 | include_once(SM_PATH . 'functions/decode/cp1257.php'); |
163 | $ret = charset_decode_cp1257 ($string); |
5dd23dac |
164 | } else if ($charset == 'windows-1258') { |
165 | include_once(SM_PATH . 'functions/decode/cp1258.php'); |
166 | $ret = charset_decode_cp1258 ($string); |
e9a71964 |
167 | } else if ($charset == 'x-mac-roman') { |
168 | include_once(SM_PATH . 'functions/decode/cp10000.php'); |
169 | $ret = charset_decode_cp10000 ($string); |
170 | } else if ($charset == 'x-mac-greek') { |
171 | include_once(SM_PATH . 'functions/decode/cp10006.php'); |
172 | $ret = charset_decode_cp10006 ($string); |
173 | } else if ($charset == 'x-mac-cyrillic') { |
174 | include_once(SM_PATH . 'functions/decode/cp10007.php'); |
175 | $ret = charset_decode_cp10007 ($string); |
176 | } else if ($charset == 'x-mac-ukrainian') { |
177 | include_once(SM_PATH . 'functions/decode/cp10017.php'); |
178 | $ret = charset_decode_cp10017 ($string); |
179 | } else if ($charset == 'x-mac-centraleurroman') { |
180 | include_once(SM_PATH . 'functions/decode/cp10029.php'); |
181 | $ret = charset_decode_cp10029 ($string); |
182 | } else if ($charset == 'x-mac-icelandic') { |
183 | include_once(SM_PATH . 'functions/decode/cp10079.php'); |
184 | $ret = charset_decode_cp10079 ($string); |
185 | } else if ($charset == 'x-mac-turkish') { |
186 | include_once(SM_PATH . 'functions/decode/cp10081.php'); |
187 | $ret = charset_decode_cp10081 ($string); |
188 | } else if ($charset == 'ibm855') { |
189 | include_once(SM_PATH . 'functions/decode/cp855.php'); |
190 | $ret = charset_decode_cp855 ($string); |
191 | } else if ($charset == 'ibm866') { |
192 | include_once(SM_PATH . 'functions/decode/cp866.php'); |
193 | $ret = charset_decode_cp866 ($string); |
0e4337e7 |
194 | } else if ($charset == 'iso-ir-111') { |
195 | include_once(SM_PATH . 'functions/decode/iso-ir-111.php'); |
196 | $ret = charset_decode_iso_ir_111 ($string); |
7af26ef8 |
197 | } else if ($charset == 'tis-620') { |
198 | include_once(SM_PATH . 'functions/decode/tis620.php'); |
199 | $ret = charset_decode_tis620 ($string); |
5dd23dac |
200 | } else if ($charset == 'big5' and $agresive_decoding ) { |
201 | include_once(SM_PATH . 'functions/decode/big5.php'); |
202 | $ret = charset_decode_big5 ($string); |
203 | } else if ($charset == 'gb2312' and $agresive_decoding ) { |
204 | include_once(SM_PATH . 'functions/decode/gb2312.php'); |
205 | $ret = charset_decode_gb2312 ($string); |
3ab35042 |
206 | } else if ($charset == 'utf-8') { |
5dd23dac |
207 | include_once(SM_PATH . 'functions/decode/utf-8.php'); |
3ab35042 |
208 | $ret = charset_decode_utf8 ($string); |
a2a7852b |
209 | } else { |
210 | $ret = $string; |
211 | } |
212 | return( $ret ); |
213 | } |
214 | |
a2a7852b |
215 | |
216 | /* Remove all 8 bit characters from all other ISO-8859 character sets */ |
217 | function charset_decode_iso_8859_default ($string) { |
218 | return (strtr($string, "\240\241\242\243\244\245\246\247". |
1fd97780 |
219 | "\250\251\252\253\254\255\256\257". |
220 | "\260\261\262\263\264\265\266\267". |
221 | "\270\271\272\273\274\275\276\277". |
222 | "\300\301\302\303\304\305\306\307". |
223 | "\310\311\312\313\314\315\316\317". |
224 | "\320\321\322\323\324\325\326\327". |
225 | "\330\331\332\333\334\335\336\337". |
226 | "\340\341\342\343\344\345\346\347". |
227 | "\350\351\352\353\354\355\356\357". |
228 | "\360\361\362\363\364\365\366\367". |
a2a7852b |
229 | "\370\371\372\373\374\375\376\377", |
1fd97780 |
230 | "????????????????????????????????????????". |
231 | "????????????????????????????????????????". |
232 | "????????????????????????????????????????". |
233 | "????????")); |
a2a7852b |
234 | |
235 | } |
236 | |
237 | /* |
238 | * This is the same as ISO-646-NO and is used by some |
239 | * Microsoft programs when sending Norwegian characters |
240 | */ |
241 | function charset_decode_ns_4551_1 ($string) { |
242 | /* |
243 | * These characters are: |
244 | * Latin capital letter AE |
245 | * Latin capital letter O with stroke |
246 | * Latin capital letter A with ring above |
247 | * and the same as small letters |
248 | */ |
249 |