This project does not seem to handle request data directly as such no vulnerable execution paths were found.
include
, or for example
via PHP's auto-loading mechanism.
These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more
1 | <?php |
||
2 | |||
3 | //------------------------------------------------------------------------------ |
||
4 | // |
||
5 | // eTraxis - Records tracking web-based system |
||
6 | // Copyright (C) 2004-2011 Artem Rodygin |
||
7 | // |
||
8 | // This program is free software: you can redistribute it and/or modify |
||
9 | // it under the terms of the GNU General Public License as published by |
||
10 | // the Free Software Foundation, either version 3 of the License, or |
||
11 | // (at your option) any later version. |
||
12 | // |
||
13 | // This program is distributed in the hope that it will be useful, |
||
14 | // but WITHOUT ANY WARRANTY; without even the implied warranty of |
||
15 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
||
16 | // GNU General Public License for more details. |
||
17 | // |
||
18 | // You should have received a copy of the GNU General Public License |
||
19 | // along with this program. If not, see <http://www.gnu.org/licenses/>. |
||
20 | // |
||
21 | //------------------------------------------------------------------------------ |
||
22 | |||
23 | /** |
||
24 | * Localization |
||
25 | * |
||
26 | * This module implements multilingual support of eTraxis UI. |
||
27 | * |
||
28 | * @package Engine |
||
29 | * @subpackage Localization |
||
30 | */ |
||
31 | |||
32 | /**#@+ |
||
33 | * Dependency. |
||
34 | */ |
||
35 | require_once('../config.php'); |
||
36 | require_once('../engine/resource.php'); |
||
37 | require_once('../engine/debug.php'); |
||
38 | require_once('../engine/utility.php'); |
||
39 | /**#@-*/ |
||
40 | |||
41 | /**#@+ |
||
42 | * Resource file with translated UI prompts. |
||
43 | */ |
||
44 | require_once('../engine/res/english.php'); |
||
45 | require_once('../engine/res/french.php'); |
||
46 | require_once('../engine/res/german.php'); |
||
47 | require_once('../engine/res/italian.php'); |
||
48 | require_once('../engine/res/spanish.php'); |
||
49 | require_once('../engine/res/portuguese.php'); |
||
50 | require_once('../engine/res/dutch.php'); |
||
51 | require_once('../engine/res/swedish.php'); |
||
52 | require_once('../engine/res/latvian.php'); |
||
53 | require_once('../engine/res/russian.php'); |
||
54 | require_once('../engine/res/polish.php'); |
||
55 | require_once('../engine/res/czech.php'); |
||
56 | require_once('../engine/res/hungarian.php'); |
||
57 | require_once('../engine/res/bulgarian.php'); |
||
58 | require_once('../engine/res/romanian.php'); |
||
59 | require_once('../engine/res/japanese.php'); |
||
60 | require_once('../engine/res/turkish.php'); |
||
61 | require_once('../engine/res/indonesian.php'); |
||
62 | /**#@-*/ |
||
63 | |||
64 | //------------------------------------------------------------------------------ |
||
65 | // Definitions. |
||
66 | //------------------------------------------------------------------------------ |
||
67 | |||
68 | /**#@+ |
||
69 | * Supported language ID. |
||
70 | */ |
||
71 | define('LANG_ENGLISH_US', 1000); |
||
72 | define('LANG_ENGLISH_UK', 1001); |
||
73 | define('LANG_ENGLISH_CAN', 1002); |
||
74 | define('LANG_ENGLISH_AUS', 1003); |
||
75 | define('LANG_ENGLISH_NZ', 1004); |
||
76 | define('LANG_FRENCH', 1010); |
||
77 | define('LANG_GERMAN', 1020); |
||
78 | define('LANG_ITALIAN', 1030); |
||
79 | define('LANG_SPANISH', 1040); |
||
80 | define('LANG_CATALAN', 1050); |
||
81 | define('LANG_GALICIAN', 1060); |
||
82 | define('LANG_BASQUE', 1070); |
||
83 | define('LANG_PORTUGUESE', 1080); |
||
84 | define('LANG_DUTCH', 1090); |
||
85 | define('LANG_GREEK', 1100); |
||
86 | define('LANG_IRISH', 1110); |
||
87 | define('LANG_MALTESE', 1120); |
||
88 | define('LANG_DANISH', 2000); |
||
89 | define('LANG_NORWEGIAN', 2010); |
||
90 | define('LANG_SWEDISH', 2020); |
||
91 | define('LANG_FINNISH', 2030); |
||
92 | define('LANG_ESTONIAN', 2040); |
||
93 | define('LANG_LATVIAN', 2050); |
||
94 | define('LANG_LITHUANIAN', 2060); |
||
95 | define('LANG_ICELANDIC', 2070); |
||
96 | define('LANG_RUSSIAN', 3000); |
||
97 | define('LANG_UKRAINIAN', 3010); |
||
98 | define('LANG_BELARUSIAN', 3020); |
||
99 | define('LANG_POLISH', 3030); |
||
100 | define('LANG_CZECH', 3040); |
||
101 | define('LANG_SLOVAK', 3050); |
||
102 | define('LANG_HUNGARIAN', 3060); |
||
103 | define('LANG_SLOVENIAN', 3070); |
||
104 | define('LANG_CROATIAN', 3080); |
||
105 | define('LANG_BOSNIAN', 3090); |
||
106 | define('LANG_SERBIAN', 3100); |
||
107 | define('LANG_ALBANIAN', 3110); |
||
108 | define('LANG_MACEDONIAN', 3120); |
||
109 | define('LANG_BULGARIAN', 3130); |
||
110 | define('LANG_ROMANIAN', 3140); |
||
111 | define('LANG_MOLDAVIAN', 3150); |
||
112 | define('LANG_GEORGIAN', 4000); |
||
113 | define('LANG_ARMENIAN', 4010); |
||
114 | define('LANG_AZERBAIJANI', 4020); |
||
115 | define('LANG_KAZAKH', 4030); |
||
116 | define('LANG_TURKMEN', 4040); |
||
117 | define('LANG_UZBEK', 4050); |
||
118 | define('LANG_TAJIK', 4060); |
||
119 | define('LANG_KYRGYZ', 4070); |
||
120 | define('LANG_JAPANESE', 5000); |
||
121 | define('LANG_CHINESE_SIMP', 5010); |
||
122 | define('LANG_CHINESE_TRAD', 5020); |
||
123 | define('LANG_KOREAN', 5030); |
||
124 | define('LANG_MONGOLIAN', 5040); |
||
125 | define('LANG_TURKISH', 6000); |
||
126 | define('LANG_HEBREW', 6010); |
||
127 | define('LANG_YIDDISH', 6020); |
||
128 | define('LANG_ARABIC', 6030); |
||
129 | define('LANG_KURDISH', 6040); |
||
130 | define('LANG_ASSYRIAN', 6050); |
||
131 | define('LANG_PERSIAN', 6060); |
||
132 | define('LANG_PUSHTU', 6070); |
||
133 | define('LANG_TURKIC', 6080); |
||
134 | define('LANG_URDU', 6090); |
||
135 | define('LANG_PUNJABI', 6100); |
||
136 | define('LANG_SINDHI', 6110); |
||
137 | define('LANG_HINDI', 7000); |
||
138 | define('LANG_TELUGU', 7010); |
||
139 | define('LANG_MARATHI', 7020); |
||
140 | define('LANG_KANNADA', 7030); |
||
141 | define('LANG_GUJARATI', 7040); |
||
142 | define('LANG_MALAYALAM', 7050); |
||
143 | define('LANG_ORIYA', 7060); |
||
144 | define('LANG_ASSAMESE', 7070); |
||
145 | define('LANG_KASHMIRI', 7080); |
||
146 | define('LANG_NEPALI', 7090); |
||
147 | define('LANG_TIBETAN', 7100); |
||
148 | define('LANG_BENGALI', 7110); |
||
149 | define('LANG_BURMESE', 7120); |
||
150 | define('LANG_THAI', 7130); |
||
151 | define('LANG_LAOTHIAN', 7140); |
||
152 | define('LANG_VIETNAMESE', 7150); |
||
153 | define('LANG_INDONESIAN', 7160); |
||
154 | define('LANG_MALAY', 7170); |
||
155 | define('LANG_TAGALOG', 7180); |
||
156 | define('LANG_SINHALESE', 7190); |
||
157 | define('LANG_TAMIL', 7200); |
||
158 | define('LANG_AFRIKAANS', 8000); |
||
159 | define('LANG_SWAHILI', 8010); |
||
160 | define('LANG_HAUSA', 8020); |
||
161 | define('LANG_AMHARIC', 8030); |
||
162 | define('LANG_YORUBA', 8040); |
||
163 | define('LANG_IGBO', 8050); |
||
164 | define('LANG_MALAGASY', 8060); |
||
165 | define('LANG_SOMALI', 8070); |
||
166 | define('LANG_FULAH', 8080); |
||
167 | define('LANG_SHONA', 8090); |
||
168 | define('LANG_ZULU', 8100); |
||
169 | define('LANG_XHOSA', 8110); |
||
170 | define('LANG_KIRUNDI', 8120); |
||
171 | define('LANG_BEMBA', 8130); |
||
172 | define('LANG_WOLOF', 8140); |
||
173 | define('LANG_TSWANA', 8150); |
||
174 | define('LANG_TSONGA', 8160); |
||
175 | define('LANG_LUGANDA', 8170); |
||
176 | define('LANG_LINGALA', 8180); |
||
177 | /**#@-*/ |
||
178 | |||
179 | /**#@+ |
||
180 | * Localization parameter. |
||
181 | */ |
||
182 | define('LOCALE_RES_TABLE', 1); |
||
183 | define('LOCALE_SUFFIX', 2); |
||
184 | define('LOCALE_CODE', 3); |
||
185 | define('LOCALE_DIRECTION', 4); |
||
186 | define('LOCALE_DATE_FORMAT', 5); |
||
187 | define('LOCALE_TIME_FORMAT', 6); |
||
188 | /**#@-*/ |
||
189 | |||
190 | // Prompts tables. |
||
191 | global $resource_english; |
||
192 | global $resource_french; |
||
193 | global $resource_german; |
||
194 | global $resource_italian; |
||
195 | global $resource_spanish; |
||
196 | global $resource_portuguese; |
||
197 | global $resource_dutch; |
||
198 | global $resource_swedish; |
||
199 | global $resource_latvian; |
||
200 | global $resource_russian; |
||
201 | global $resource_polish; |
||
202 | global $resource_czech; |
||
203 | global $resource_hungarian; |
||
204 | global $resource_bulgarian; |
||
205 | global $resource_romanian; |
||
206 | global $resource_japanese; |
||
207 | global $resource_turkish; |
||
208 | global $resource_indonesian; |
||
209 | |||
210 | // Locales. |
||
211 | $locale_info = array |
||
212 | ( |
||
213 | // English (US) |
||
214 | LANG_ENGLISH_US => array |
||
215 | ( |
||
216 | LOCALE_RES_TABLE => $resource_english, |
||
217 | LOCALE_SUFFIX => 'US', |
||
218 | LOCALE_CODE => 'en-us', |
||
219 | LOCALE_DIRECTION => 'ltr', |
||
220 | LOCALE_DATE_FORMAT => 'n/j/Y', |
||
221 | LOCALE_TIME_FORMAT => 'g:i A', |
||
222 | ), |
||
223 | |||
224 | // English (UK) |
||
225 | LANG_ENGLISH_UK => array |
||
226 | ( |
||
227 | LOCALE_RES_TABLE => $resource_english, |
||
228 | LOCALE_SUFFIX => 'UK', |
||
229 | LOCALE_CODE => 'en-gb', |
||
230 | LOCALE_DIRECTION => 'ltr', |
||
231 | LOCALE_DATE_FORMAT => 'd/m/Y', |
||
232 | LOCALE_TIME_FORMAT => 'H:i', |
||
233 | ), |
||
234 | |||
235 | // English (Canada) |
||
236 | LANG_ENGLISH_CAN => array |
||
237 | ( |
||
238 | LOCALE_RES_TABLE => $resource_english, |
||
239 | LOCALE_SUFFIX => 'Canada', |
||
240 | LOCALE_CODE => 'en-ca', |
||
241 | LOCALE_DIRECTION => 'ltr', |
||
242 | LOCALE_DATE_FORMAT => 'd/m/Y', |
||
243 | LOCALE_TIME_FORMAT => 'g:i A', |
||
244 | ), |
||
245 | |||
246 | // English (Australia) |
||
247 | LANG_ENGLISH_AUS => array |
||
248 | ( |
||
249 | LOCALE_RES_TABLE => $resource_english, |
||
250 | LOCALE_SUFFIX => 'Australia', |
||
251 | LOCALE_CODE => 'en-au', |
||
252 | LOCALE_DIRECTION => 'ltr', |
||
253 | LOCALE_DATE_FORMAT => 'j/m/Y', |
||
254 | LOCALE_TIME_FORMAT => 'g:i A', |
||
255 | ), |
||
256 | |||
257 | // English (New Zealand) |
||
258 | LANG_ENGLISH_NZ => array |
||
259 | ( |
||
260 | LOCALE_RES_TABLE => $resource_english, |
||
261 | LOCALE_SUFFIX => 'New Zealand', |
||
262 | LOCALE_CODE => 'en-nz', |
||
263 | LOCALE_DIRECTION => 'ltr', |
||
264 | LOCALE_DATE_FORMAT => 'j/m/Y', |
||
265 | LOCALE_TIME_FORMAT => 'g:i a', |
||
266 | ), |
||
267 | |||
268 | // French |
||
269 | LANG_FRENCH => array |
||
270 | ( |
||
271 | LOCALE_RES_TABLE => $resource_french, |
||
272 | LOCALE_SUFFIX => NULL, |
||
273 | LOCALE_CODE => 'fr', |
||
274 | LOCALE_DIRECTION => 'ltr', |
||
275 | LOCALE_DATE_FORMAT => 'd/m/Y', |
||
276 | LOCALE_TIME_FORMAT => 'H:i', |
||
277 | ), |
||
278 | |||
279 | // German |
||
280 | LANG_GERMAN => array |
||
281 | ( |
||
282 | LOCALE_RES_TABLE => $resource_german, |
||
283 | LOCALE_SUFFIX => NULL, |
||
284 | LOCALE_CODE => 'de', |
||
285 | LOCALE_DIRECTION => 'ltr', |
||
286 | LOCALE_DATE_FORMAT => 'd.m.Y', |
||
287 | LOCALE_TIME_FORMAT => 'H:i', |
||
288 | ), |
||
289 | |||
290 | // Italian |
||
291 | LANG_ITALIAN => array |
||
292 | ( |
||
293 | LOCALE_RES_TABLE => $resource_italian, |
||
294 | LOCALE_SUFFIX => NULL, |
||
295 | LOCALE_CODE => 'it', |
||
296 | LOCALE_DIRECTION => 'ltr', |
||
297 | LOCALE_DATE_FORMAT => 'd/m/Y', |
||
298 | LOCALE_TIME_FORMAT => 'G.i', |
||
299 | ), |
||
300 | |||
301 | // Spanish |
||
302 | LANG_SPANISH => array |
||
303 | ( |
||
304 | LOCALE_RES_TABLE => $resource_spanish, |
||
305 | LOCALE_SUFFIX => NULL, |
||
306 | LOCALE_CODE => 'es', |
||
307 | LOCALE_DIRECTION => 'ltr', |
||
308 | LOCALE_DATE_FORMAT => 'd/m/Y', |
||
309 | LOCALE_TIME_FORMAT => 'G:i', |
||
310 | ), |
||
311 | |||
312 | // Portuguese (Brazil) |
||
313 | LANG_PORTUGUESE => array |
||
314 | ( |
||
315 | LOCALE_RES_TABLE => $resource_portuguese, |
||
316 | LOCALE_SUFFIX => 'Brasil', |
||
317 | LOCALE_CODE => 'pt-br', |
||
318 | LOCALE_DIRECTION => 'ltr', |
||
319 | LOCALE_DATE_FORMAT => 'j/n/Y', |
||
320 | LOCALE_TIME_FORMAT => 'H:i', |
||
321 | ), |
||
322 | |||
323 | // Dutch |
||
324 | LANG_DUTCH => array |
||
325 | ( |
||
326 | LOCALE_RES_TABLE => $resource_dutch, |
||
327 | LOCALE_SUFFIX => NULL, |
||
328 | LOCALE_CODE => 'nl', |
||
329 | LOCALE_DIRECTION => 'ltr', |
||
330 | LOCALE_DATE_FORMAT => 'j-n-Y', |
||
331 | LOCALE_TIME_FORMAT => 'G:i', |
||
332 | ), |
||
333 | |||
334 | // Swedish |
||
335 | LANG_SWEDISH => array |
||
336 | ( |
||
337 | LOCALE_RES_TABLE => $resource_swedish, |
||
338 | LOCALE_SUFFIX => NULL, |
||
339 | LOCALE_CODE => 'sv', |
||
340 | LOCALE_DIRECTION => 'ltr', |
||
341 | LOCALE_DATE_FORMAT => 'Y-m-d', |
||
342 | LOCALE_TIME_FORMAT => 'H:i', |
||
343 | ), |
||
344 | |||
345 | // Latvian |
||
346 | LANG_LATVIAN => array |
||
347 | ( |
||
348 | LOCALE_RES_TABLE => $resource_latvian, |
||
349 | LOCALE_SUFFIX => NULL, |
||
350 | LOCALE_CODE => 'lv', |
||
351 | LOCALE_DIRECTION => 'ltr', |
||
352 | LOCALE_DATE_FORMAT => 'Y.m.d.', |
||
353 | LOCALE_TIME_FORMAT => 'G:i', |
||
354 | ), |
||
355 | |||
356 | // Russian |
||
357 | LANG_RUSSIAN => array |
||
358 | ( |
||
359 | LOCALE_RES_TABLE => $resource_russian, |
||
360 | LOCALE_SUFFIX => NULL, |
||
361 | LOCALE_CODE => 'ru', |
||
362 | LOCALE_DIRECTION => 'ltr', |
||
363 | LOCALE_DATE_FORMAT => 'd.m.Y', |
||
364 | LOCALE_TIME_FORMAT => 'G:i', |
||
365 | ), |
||
366 | |||
367 | // Polish |
||
368 | LANG_POLISH => array |
||
369 | ( |
||
370 | LOCALE_RES_TABLE => $resource_polish, |
||
371 | LOCALE_SUFFIX => NULL, |
||
372 | LOCALE_CODE => 'pl', |
||
373 | LOCALE_DIRECTION => 'ltr', |
||
374 | LOCALE_DATE_FORMAT => 'Y-m-d', |
||
375 | LOCALE_TIME_FORMAT => 'H:i', |
||
376 | ), |
||
377 | |||
378 | // Czech |
||
379 | LANG_CZECH => array |
||
380 | ( |
||
381 | LOCALE_RES_TABLE => $resource_czech, |
||
382 | LOCALE_SUFFIX => NULL, |
||
383 | LOCALE_CODE => 'cs', |
||
384 | LOCALE_DIRECTION => 'ltr', |
||
385 | LOCALE_DATE_FORMAT => 'j.n.Y', |
||
386 | LOCALE_TIME_FORMAT => 'G:i', |
||
387 | ), |
||
388 | |||
389 | // Hungarian |
||
390 | LANG_HUNGARIAN => array |
||
391 | ( |
||
392 | LOCALE_RES_TABLE => $resource_hungarian, |
||
393 | LOCALE_SUFFIX => NULL, |
||
394 | LOCALE_CODE => 'hu', |
||
395 | LOCALE_DIRECTION => 'ltr', |
||
396 | LOCALE_DATE_FORMAT => 'Y.m.d', |
||
397 | LOCALE_TIME_FORMAT => 'G:i', |
||
398 | ), |
||
399 | |||
400 | // Bulgarian |
||
401 | LANG_BULGARIAN => array |
||
402 | ( |
||
403 | LOCALE_RES_TABLE => $resource_bulgarian, |
||
404 | LOCALE_SUFFIX => NULL, |
||
405 | LOCALE_CODE => 'bg', |
||
406 | LOCALE_DIRECTION => 'ltr', |
||
407 | LOCALE_DATE_FORMAT => 'd.n.Y', |
||
408 | LOCALE_TIME_FORMAT => 'H:i', |
||
409 | ), |
||
410 | |||
411 | // Romanian |
||
412 | LANG_ROMANIAN => array |
||
413 | ( |
||
414 | LOCALE_RES_TABLE => $resource_romanian, |
||
415 | LOCALE_SUFFIX => NULL, |
||
416 | LOCALE_CODE => 'ro', |
||
417 | LOCALE_DIRECTION => 'ltr', |
||
418 | LOCALE_DATE_FORMAT => 'd.m.Y', |
||
419 | LOCALE_TIME_FORMAT => 'H:i', |
||
420 | ), |
||
421 | |||
422 | // Japanese |
||
423 | LANG_JAPANESE => array |
||
424 | ( |
||
425 | LOCALE_RES_TABLE => $resource_japanese, |
||
426 | LOCALE_SUFFIX => NULL, |
||
427 | LOCALE_CODE => 'ja', |
||
428 | LOCALE_DIRECTION => 'ltr', |
||
429 | LOCALE_DATE_FORMAT => 'Y/m/d', |
||
430 | LOCALE_TIME_FORMAT => 'G:i', |
||
431 | ), |
||
432 | |||
433 | // Turkish |
||
434 | LANG_TURKISH => array |
||
435 | ( |
||
436 | LOCALE_RES_TABLE => $resource_turkish, |
||
437 | LOCALE_SUFFIX => NULL, |
||
438 | LOCALE_CODE => 'tr', |
||
439 | LOCALE_DIRECTION => 'ltr', |
||
440 | LOCALE_DATE_FORMAT => 'd.m.Y', |
||
441 | LOCALE_TIME_FORMAT => 'H:i', |
||
442 | ), |
||
443 | |||
444 | // Indonesian |
||
445 | LANG_INDONESIAN => array |
||
446 | ( |
||
447 | LOCALE_RES_TABLE => $resource_indonesian, |
||
448 | LOCALE_SUFFIX => NULL, |
||
449 | LOCALE_CODE => 'id', |
||
450 | LOCALE_DIRECTION => 'ltr', |
||
451 | LOCALE_DATE_FORMAT => 'd/m/Y', |
||
452 | LOCALE_TIME_FORMAT => 'G:i', |
||
453 | ), |
||
454 | ); |
||
455 | |||
456 | /** |
||
457 | * Session variable to store current UI language. |
||
458 | */ |
||
459 | define('VAR_LOCALE', 'eTraxis_Locale'); |
||
460 | |||
461 | //------------------------------------------------------------------------------ |
||
462 | // Functions. |
||
463 | //------------------------------------------------------------------------------ |
||
464 | |||
465 | /** |
||
466 | * Returns requested prompt. |
||
467 | * |
||
468 | * @param int $res_id ID of prompt (see {@link resource.php}) |
||
469 | * @param int $lang ID of language. If omitted, then language of current user, or (when user is |
||
470 | * not logged in) default language will be used (see {@link LANG_DEFAULT}). |
||
471 | * @return string Text of prompt, converted to UTF-8. |
||
472 | */ |
||
473 | function get_resource ($res_id, $lang = NULL) |
||
474 | { |
||
475 | global $locale_info; |
||
476 | |||
477 | if (is_null($lang)) |
||
478 | { |
||
479 | $lang = (isset($_SESSION[VAR_LOCALE]) ? $_SESSION[VAR_LOCALE] : LANG_DEFAULT); |
||
480 | } |
||
481 | |||
482 | $res = (isset($locale_info[$lang][LOCALE_RES_TABLE][$res_id]) |
||
483 | ? $locale_info[$lang][LOCALE_RES_TABLE][$res_id] |
||
484 | : $locale_info[LANG_ENGLISH_US][LOCALE_RES_TABLE][$res_id]); |
||
485 | |||
486 | if ($res_id == RES_LOCALE_ID && !is_null($locale_info[$lang][LOCALE_SUFFIX])) |
||
487 | { |
||
488 | $res .= " ({$locale_info[$lang][LOCALE_SUFFIX]})"; |
||
489 | } |
||
490 | |||
491 | return $res; |
||
492 | } |
||
493 | |||
494 | /** |
||
495 | * Returns requested prompt, updated to be displayed in HTML. |
||
496 | * |
||
497 | * @param int $res_id ID of prompt (see {@link resource.php}) |
||
498 | * @param int $lang ID of language. If omitted, then language of current user, or (when user is |
||
499 | * not logged in) default language will be used (see {@link LANG_DEFAULT}). |
||
500 | * @return string Text of prompt, converted to UTF-8. The value is HTML-safe (tags are stripped). |
||
501 | */ |
||
502 | function get_html_resource ($res_id, $lang = NULL) |
||
503 | { |
||
504 | return ustr2html(get_resource($res_id, $lang)); |
||
505 | } |
||
506 | |||
507 | /** |
||
508 | * Returns requested prompt, updated to be displayed in JavaScript. |
||
509 | * |
||
510 | * @param int $res_id ID of prompt (see {@link resource.php}) |
||
511 | * @param int $lang ID of language. If omitted, then language of current user, or (when user is |
||
512 | * not logged in) default language will be used (see {@link LANG_DEFAULT}). |
||
513 | * @return string Text of prompt, converted to UTF-8. The value is JavaScript-safe (quotes are stripped). |
||
514 | */ |
||
515 | function get_js_resource ($res_id, $lang = NULL) |
||
516 | { |
||
517 | return ustr2js(get_resource($res_id, $lang)); |
||
518 | } |
||
519 | |||
520 | /** |
||
521 | * Returns direction of specified language. |
||
522 | * |
||
523 | * @param int $lang ID of language. If omitted, then language of current user, or (when user is |
||
524 | * not logged in) default language will be used (see {@link LANG_DEFAULT}). |
||
525 | * @return string Either "LTR", or "RTL". |
||
526 | */ |
||
527 | function get_direction ($lang = NULL) |
||
528 | { |
||
529 | global $locale_info; |
||
530 | |||
531 | if (is_null($lang)) |
||
532 | { |
||
533 | $lang = (isset($_SESSION[VAR_LOCALE]) ? $_SESSION[VAR_LOCALE] : LANG_DEFAULT); |
||
534 | } |
||
535 | |||
536 | return $locale_info[$lang][LOCALE_DIRECTION]; |
||
537 | } |
||
538 | |||
539 | /** |
||
540 | * Returns string with date, formatted according to specified language. |
||
541 | * |
||
542 | * @param int $timestamp Unix timestamp (see {@link http://en.wikipedia.org/wiki/Unix_time}) |
||
543 | * @param int $lang ID of language. If omitted, then language of current user, or (when user is |
||
544 | * not logged in) default language will be used (see {@link LANG_DEFAULT}). |
||
545 | * @return string String with date. |
||
546 | */ |
||
547 | View Code Duplication | function get_date ($timestamp, $lang = NULL) |
|
548 | { |
||
549 | global $locale_info; |
||
550 | |||
551 | if (is_null($lang)) |
||
552 | { |
||
553 | $lang = (isset($_SESSION[VAR_LOCALE]) ? $_SESSION[VAR_LOCALE] : LANG_DEFAULT); |
||
554 | } |
||
555 | |||
556 | $format = $locale_info[$lang][LOCALE_DATE_FORMAT]; |
||
557 | $offset = $_SESSION[VAR_TIMEZONE] - intval(date('Z')); |
||
558 | |||
559 | return date($format, $timestamp + $offset); |
||
560 | } |
||
561 | |||
562 | /** |
||
563 | * Returns string with time, formatted according to specified language. |
||
564 | * |
||
565 | * @param int $timestamp Unix timestamp (see {@link http://en.wikipedia.org/wiki/Unix_time}) |
||
566 | * @param int $lang ID of language. If omitted, then language of current user, or (when user is |
||
567 | * not logged in) default language will be used (see {@link LANG_DEFAULT}). |
||
568 | * @return string String with time. |
||
569 | */ |
||
570 | View Code Duplication | function get_time ($timestamp, $lang = NULL) |
|
571 | { |
||
572 | global $locale_info; |
||
573 | |||
574 | if (is_null($lang)) |
||
575 | { |
||
576 | $lang = (isset($_SESSION[VAR_LOCALE]) ? $_SESSION[VAR_LOCALE] : LANG_DEFAULT); |
||
577 | } |
||
578 | |||
579 | $format = $locale_info[$lang][LOCALE_TIME_FORMAT]; |
||
580 | $offset = $_SESSION[VAR_TIMEZONE] - intval(date('Z')); |
||
581 | |||
582 | return date($format, $timestamp + $offset); |
||
583 | } |
||
584 | |||
585 | /** |
||
586 | * Returns string with date and time, formatted according to specified language. |
||
587 | * |
||
588 | * @param int $timestamp Unix timestamp (see {@link http://en.wikipedia.org/wiki/Unix_time}) |
||
589 | * @param int $lang ID of language. If omitted, then language of current user, or (when user is |
||
590 | * not logged in) default language will be used (see {@link LANG_DEFAULT}). |
||
591 | * @return string String with date and time, space separated. |
||
592 | */ |
||
593 | function get_datetime ($timestamp, $lang = NULL) |
||
594 | { |
||
595 | global $locale_info; |
||
596 | |||
597 | if (is_null($lang)) |
||
598 | { |
||
599 | $lang = (isset($_SESSION[VAR_LOCALE]) ? $_SESSION[VAR_LOCALE] : LANG_DEFAULT); |
||
600 | } |
||
601 | |||
602 | $format = $locale_info[$lang][LOCALE_DATE_FORMAT] . ' ' . $locale_info[$lang][LOCALE_TIME_FORMAT]; |
||
603 | $offset = $_SESSION[VAR_TIMEZONE] - intval(date('Z')); |
||
604 | |||
605 | return date($format, $timestamp + $offset); |
||
606 | } |
||
607 | |||
608 | /** |
||
609 | * Returns string with human-readable presentation of date format for specified language. |
||
610 | * |
||
611 | * @param int $lang ID of language. If omitted, then language of current user, or (when user is |
||
612 | * not logged in) default language will be used (see {@link LANG_DEFAULT}). |
||
613 | * @return string Human-readable date format string. |
||
614 | */ |
||
615 | function get_date_format_str ($lang = NULL) |
||
616 | { |
||
617 | debug_write_log(DEBUG_TRACE, '[get_date_format_str]'); |
||
618 | debug_write_log(DEBUG_DUMP, '[get_date_format_str] $lang = ' . $lang); |
||
619 | |||
620 | global $locale_info; |
||
621 | |||
622 | if (is_null($lang)) |
||
623 | { |
||
624 | $lang = (isset($_SESSION[VAR_LOCALE]) ? $_SESSION[VAR_LOCALE] : LANG_DEFAULT); |
||
625 | } |
||
626 | |||
627 | $format = $locale_info[$lang][LOCALE_DATE_FORMAT]; |
||
628 | |||
629 | $format_chars = array |
||
630 | ( |
||
631 | 'Y' => 'YYYY', |
||
632 | 'y' => 'YY', |
||
633 | 'm' => 'MM', |
||
634 | 'n' => 'M', |
||
635 | 'd' => 'DD', |
||
636 | 'j' => 'D', |
||
637 | ); |
||
638 | |||
639 | foreach ($format_chars as $from => $to) |
||
640 | { |
||
641 | $format = str_replace($from, $to, $format); |
||
642 | } |
||
643 | |||
644 | return $format; |
||
645 | } |
||
646 | |||
647 | /** |
||
648 | * Converts string presentation of date to Unix timestamp (see {@link http://en.wikipedia.org/wiki/Unix_time}). |
||
649 | * |
||
650 | * @param string $str String presentation of date. It must consist to date format of specified language. |
||
651 | * @param int $lang ID of language. If omitted, then language of current user, or (when user is |
||
652 | * not logged in) default language will be used (see {@link LANG_DEFAULT}). |
||
653 | * @return int Valid Unix timestamp on success, or -1 if specified date is not formatted in consistancy |
||
654 | * with date format of specified language. |
||
655 | */ |
||
656 | function ustr2date ($str, $lang = NULL) |
||
657 | { |
||
658 | debug_write_log(DEBUG_TRACE, '[ustr2date]'); |
||
659 | debug_write_log(DEBUG_DUMP, '[ustr2date] $str = ' . $str); |
||
660 | debug_write_log(DEBUG_DUMP, '[ustr2date] $lang = ' . $lang); |
||
661 | |||
662 | global $locale_info; |
||
663 | |||
664 | if (is_null($lang)) |
||
665 | { |
||
666 | $lang = (isset($_SESSION[VAR_LOCALE]) ? $_SESSION[VAR_LOCALE] : LANG_DEFAULT); |
||
667 | } |
||
668 | |||
669 | $format = $locale_info[$lang][LOCALE_DATE_FORMAT]; |
||
670 | |||
671 | $date = array(0, 0, 0); |
||
672 | |||
673 | $regexp = array |
||
674 | ( |
||
675 | 'd' => array('([0-9]{1,2})', 1), |
||
676 | 'j' => array('([0-9]{1,2})', 1), |
||
677 | 'm' => array('([0-9]{1,2})', 0), |
||
678 | 'n' => array('([0-9]{1,2})', 0), |
||
679 | 'Y' => array('([0-9]{4})', 2), |
||
680 | 'y' => array('([0-9]{2})', 2), |
||
681 | ); |
||
682 | |||
683 | $count = 0; |
||
684 | |||
685 | for ($i = 0; $i < ustrlen($format); $i++) |
||
686 | { |
||
687 | $key = usubstr($format, $i, 1); |
||
688 | |||
689 | if (array_key_exists($key, $regexp)) |
||
690 | { |
||
691 | $format = ustr_replace($key, $regexp[$key][0], $format); |
||
692 | $i += ustrlen($regexp[$key][0]); |
||
693 | $date[$regexp[$key][1]] = ++$count; |
||
694 | } |
||
695 | } |
||
696 | |||
697 | mb_regex_encoding('UTF-8'); |
||
698 | |||
699 | $regs = NULL; |
||
700 | |||
701 | if (mb_eregi($format, @iconv('UTF-8', 'ISO-8859-1', $str), $regs)) |
||
702 | { |
||
703 | debug_write_log(DEBUG_DUMP, '[ustr2date] $regs[$date[0]] = ' . $regs[$date[0]]); |
||
704 | debug_write_log(DEBUG_DUMP, '[ustr2date] $regs[$date[1]] = ' . $regs[$date[1]]); |
||
705 | debug_write_log(DEBUG_DUMP, '[ustr2date] $regs[$date[2]] = ' . $regs[$date[2]]); |
||
706 | |||
707 | if (checkdate($regs[$date[0]], $regs[$date[1]], $regs[$date[2]])) |
||
708 | { |
||
709 | $offset = $_SESSION[VAR_TIMEZONE] - intval(date('Z')); |
||
710 | return @mktime(0, 0, 0, $regs[$date[0]], $regs[$date[1]], $regs[$date[2]]) - $offset; |
||
711 | } |
||
712 | else |
||
713 | { |
||
714 | debug_write_log(DEBUG_NOTICE, '[ustr2date] \'checkdate\' has returned FALSE value.'); |
||
715 | return -1; |
||
716 | } |
||
717 | } |
||
718 | else |
||
719 | { |
||
720 | debug_write_log(DEBUG_NOTICE, '[ustr2date] \'mb_eregi\' has returned FALSE value.'); |
||
721 | return -1; |
||
722 | } |
||
723 | } |
||
724 | |||
725 | /** |
||
726 | * Converts string presentation of time duration to amount of minutes. |
||
727 | * Time duration is a string like "hh:mm", where "hh" can be from "0" to "999999" and "mm" can be from "0" to "59". |
||
728 | * |
||
729 | * @param string $str String presentation of time duration. |
||
730 | * @return int Valid amount of minutes on success, or -1 if specified duration is not in consistancy |
||
731 | * with described format. |
||
732 | */ |
||
733 | function ustr2time ($str) |
||
734 | { |
||
735 | debug_write_log(DEBUG_TRACE, '[ustr2time]'); |
||
736 | debug_write_log(DEBUG_DUMP, '[ustr2time] $str = ' . $str); |
||
737 | |||
738 | mb_regex_encoding('UTF-8'); |
||
739 | |||
740 | $regs = NULL; |
||
741 | |||
742 | if (mb_eregi('([0-9]{1,6}):([0-9]{1,2})', $str, $regs)) |
||
743 | { |
||
744 | debug_write_log(DEBUG_DUMP, '[ustr2time] $regs[1] = ' . $regs[1]); |
||
745 | debug_write_log(DEBUG_DUMP, '[ustr2time] $regs[2] = ' . $regs[2]); |
||
746 | |||
747 | return ($regs[2] < 60 ? ($regs[1] * 60 + $regs[2]) : -1); |
||
748 | } |
||
749 | else |
||
750 | { |
||
751 | debug_write_log(DEBUG_NOTICE, '[ustr2time] \'mb_eregi\' has returned FALSE value.'); |
||
752 | return -1; |
||
753 | } |
||
754 | } |
||
755 | |||
756 | /** |
||
757 | * Returns array of supported locales sorted alphabetically. |
||
758 | * |
||
759 | * @return array Array with supported locales. |
||
760 | */ |
||
761 | function get_supported_locales_sorted () |
||
762 | { |
||
763 | debug_write_log(DEBUG_TRACE, '[get_supported_locales_sorted]'); |
||
764 | |||
765 | global $locale_info; |
||
766 | |||
767 | $supported_locales = array_keys($locale_info); |
||
768 | $supported_locales_names = array(); |
||
769 | |||
770 | foreach ($supported_locales as $item) |
||
771 | { |
||
772 | debug_write_log(DEBUG_DUMP, '[get_supported_locales_sorted] $item = ' . $item); |
||
773 | $supported_locales_names[$item] = get_html_resource(RES_LOCALE_ID, $item); |
||
774 | } |
||
775 | |||
776 | asort($supported_locales_names); |
||
777 | |||
778 | return $supported_locales_names; |
||
779 | } |
||
780 | |||
781 | /** |
||
782 | * Returns language of user's browser. |
||
783 | * |
||
784 | * @return int ID of language. |
||
785 | */ |
||
786 | function get_browser_locale () |
||
787 | { |
||
788 | debug_write_log(DEBUG_TRACE, '[get_browser_locale]'); |
||
789 | |||
790 | global $locale_info; |
||
791 | |||
792 | if (isset($_SERVER['HTTP_ACCEPT_LANGUAGE'])) |
||
793 | { |
||
794 | $langs = preg_split("/[;,]+/", strtolower($_SERVER['HTTP_ACCEPT_LANGUAGE'])); |
||
795 | |||
796 | foreach ($langs as $lang) |
||
797 | { |
||
798 | if (substr($lang, 0, 2) != 'q=') |
||
799 | { |
||
800 | foreach ($locale_info as $locale => $info) |
||
801 | { |
||
802 | if (strpos($lang, $info[LOCALE_CODE]) !== FALSE) |
||
803 | { |
||
804 | return $locale; |
||
805 | } |
||
806 | } |
||
807 | } |
||
808 | } |
||
809 | } |
||
810 | |||
811 | return LANG_DEFAULT; |
||
812 | } |
||
813 | |||
814 | ?> |
||
0 ignored issues
–
show
|
|||
815 |
Using a closing tag in PHP files that only contain PHP code is not recommended as you might accidentally add whitespace after the closing tag which would then be output by PHP. This can cause severe problems, for example headers cannot be sent anymore.
A simple precaution is to leave off the closing tag as it is not required, and it also has no negative effects whatsoever.