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