Quick Search:

View

Revision:

Diff

Diff from 1497 to:

Annotations

Annotate by Age | Author | Mixed | None
/fisheye/browse/osCommerce/branches/hpdl/oscommerce/includes/classes/language.php

Annotated File View

hpdl
1
1 <?php
2 /*
hpdl
120
3   $Id: language.php 1497 2007-03-29 13:40:05Z hpdl $
hpdl
1
4
5   osCommerce, Open Source E-Commerce Solutions
6   http://www.oscommerce.com
7
hpdl
377
8   Copyright (c) 2006 osCommerce
hpdl
1
9
hpdl
1497
10   This program is free software; you can redistribute it and/or modify
11   it under the terms of the GNU General Public License v2 (1991)
12   as published by the Free Software Foundation.
hpdl
1
13 */
14
15   class osC_Language {
16
17 /* Private variables */
hpdl
377
18     var $_code,
hpdl
387
19         $_languages = array(),
20         $_definitions = array();
hpdl
1
21
22 /* Class constructor */
23
24     function osC_Language() {
hpdl
199
25       global $osC_Database;
hpdl
1
26
27       $Qlanguages = $osC_Database->query('select * from :table_languages order by sort_order, name');
28       $Qlanguages->bindTable(':table_languages', TABLE_LANGUAGES);
29       $Qlanguages->setCache('languages');
30       $Qlanguages->execute();
31
32       while ($Qlanguages->next()) {
33         $this->_languages[$Qlanguages->value('code')] = array('id' => $Qlanguages->valueInt('languages_id'),
hpdl
447
34                                                               'code' => $Qlanguages->value('code'),
hpdl
1
35                                                               'name' => $Qlanguages->value('name'),
hpdl
386
36                                                               'locale' => $Qlanguages->value('locale'),
37                                                               'charset' => $Qlanguages->value('charset'),
38                                                               'date_format_short' => $Qlanguages->value('date_format_short'),
39                                                               'date_format_long' => $Qlanguages->value('date_format_long'),
40                                                               'time_format' => $Qlanguages->value('time_format'),
41                                                               'text_direction' => $Qlanguages->value('text_direction'),
42                                                               'currencies_id' => $Qlanguages->valueInt('currencies_id'),
43                                                               'numeric_separator_decimal' => $Qlanguages->value('numeric_separator_decimal'),
hpdl
1431
44                                                               'numeric_separator_thousands' => $Qlanguages->value('numeric_separator_thousands'));
hpdl
1
45       }
46
47       $Qlanguages->freeResult();
48
hpdl
377
49       $this->set();
hpdl
1
50     }
51
52 /* Public methods */
53
hpdl
387
54     function load($key) {
hpdl
394
55       global $osC_Database;
hpdl
387
56
hpdl
394
57       $Qdef = $osC_Database->query('select * from :table_languages_definitions where languages_id = :languages_id and content_group = :content_group');
58       $Qdef->bindTable(':table_languages_definitions', TABLE_LANGUAGES_DEFINITIONS);
59       $Qdef->bindInt(':languages_id', $this->getID());
60       $Qdef->bindValue(':content_group', $key);
61       $Qdef->setCache('languages-' . $this->_code . '-' . $key);
62       $Qdef->execute();
hpdl
387
63
hpdl
394
64       while ($Qdef->next()) {
65         $this->_definitions[$Qdef->value('definition_key')] = $Qdef->value('definition_value');
hpdl
387
66       }
hpdl
394
67
68       $Qdef->freeResult();
hpdl
387
69     }
70
71     function get($key) {
72       if (isset($this->_definitions[$key])) {
73         return $this->_definitions[$key];
74       }
75
76       return $key;
77     }
78
hpdl
377
79     function set($code = '') {
80       $this->_code = $code;
81
82       if (empty($this->_code)) {
83         if (isset($_SESSION['language'])) {
84           $this->_code = $_SESSION['language'];
85         } elseif (isset($_COOKIE['language'])) {
86           $this->_code = $_COOKIE['language'];
87         } else {
88           $this->_code = $this->getBrowserSetting();
hpdl
1
89         }
90       }
91
hpdl
377
92       if (empty($this->_code) || ($this->exists($this->_code) === false)) {
93         $this->_code = DEFAULT_LANGUAGE;
hpdl
1
94       }
95
hpdl
377
96       if (!isset($_COOKIE['language']) || (isset($_COOKIE['language']) && ($_COOKIE['language'] != $this->_code))) {
hpdl
733
97         osc_setcookie('language', $this->_code, time()+60*60*24*90);
hpdl
1
98       }
99
hpdl
377
100       if ((isset($_SESSION['language']) === false) || (isset($_SESSION['language']) && ($_SESSION['language'] != $this->_code))) {
101         $_SESSION['language'] = $this->_code;
hpdl
1
102       }
103     }
104
hpdl
377
105     function getBrowserSetting() {
106       if (isset($_SERVER['HTTP_ACCEPT_LANGUAGE']) && !empty($_SERVER['HTTP_ACCEPT_LANGUAGE'])) {
107         $browser_languages = explode(',', $_SERVER['HTTP_ACCEPT_LANGUAGE']);
hpdl
1
108
hpdl
377
109         $languages = array('ar' => 'ar([-_][[:alpha:]]{2})?|arabic',
110                            'bg' => 'bg|bulgarian',
111                            'br' => 'pt[-_]br|brazilian portuguese',
112                            'ca' => 'ca|catalan',
113                            'cs' => 'cs|czech',
114                            'da' => 'da|danish',
115                            'de' => 'de([-_][[:alpha:]]{2})?|german',
116                            'el' => 'el|greek',
117                            'en' => 'en([-_][[:alpha:]]{2})?|english',
118                            'es' => 'es([-_][[:alpha:]]{2})?|spanish',
119                            'et' => 'et|estonian',
120                            'fi' => 'fi|finnish',
121                            'fr' => 'fr([-_][[:alpha:]]{2})?|french',
122                            'gl' => 'gl|galician',
123                            'he' => 'he|hebrew',
124                            'hu' => 'hu|hungarian',
125                            'id' => 'id|indonesian',
126                            'it' => 'it|italian',
127                            'ja' => 'ja|japanese',
128                            'ko' => 'ko|korean',
129                            'ka' => 'ka|georgian',
130                            'lt' => 'lt|lithuanian',
131                            'lv' => 'lv|latvian',
132                            'nl' => 'nl([-_][[:alpha:]]{2})?|dutch',
133                            'no' => 'no|norwegian',
134                            'pl' => 'pl|polish',
135                            'pt' => 'pt([-_][[:alpha:]]{2})?|portuguese',
136                            'ro' => 'ro|romanian',
137                            'ru' => 'ru|russian',
138                            'sk' => 'sk|slovak',
139                            'sr' => 'sr|serbian',
140                            'sv' => 'sv|swedish',
141                            'th' => 'th|thai',
142                            'tr' => 'tr|turkish',
143                            'uk' => 'uk|ukrainian',
144                            'tw' => 'zh[-_]tw|chinese traditional',
145                            'zh' => 'zh|chinese simplified');
hpdl
1
146
hpdl
377
147         foreach ($browser_languages as $browser_language) {
148           foreach ($languages as $key => $value) {
149             if (eregi('^(' . $value . ')(;q=[0-9]\\.[0-9])?$', $browser_language) && $this->exists($key)) {
150               return $key;
151             }
hpdl
1
152           }
153         }
154       }
155
hpdl
377
156       return false;
hpdl
1
157     }
158
hpdl
377
159     function exists($code) {
160       return array_key_exists($code, $this->_languages);
hpdl
1
161     }
162
163     function getAll() {
164       return $this->_languages;
165     }
166
hpdl
387
167     function getData($key, $language = '') {
168       if (empty($language)) {
169         $language = $this->_code;
170       }
171
172       return $this->_languages[$language][$key];
173     }
174
hpdl
399
175     function getCodeFromID($id) {
176       foreach ($this->_languages as $code => $lang) {
177         if ($lang['id'] == $id) {
178           return $code;
179         }
180       }
181     }
182
hpdl
120
183     function getID() {
hpdl
377
184       return $this->_languages[$this->_code]['id'];
hpdl
1
185     }
hpdl
120
186
187     function getName() {
hpdl
377
188       return $this->_languages[$this->_code]['name'];
hpdl
120
189     }
190
191     function getCode() {
hpdl
377
192       return $this->_code;
hpdl
120
193     }
194
hpdl
386
195     function getLocale() {
196       return $this->_languages[$this->_code]['locale'];
197     }
198
199     function getCharacterSet() {
200       return $this->_languages[$this->_code]['charset'];
201     }
202
hpdl
735
203     function getDateFormatShort($with_time = false) {
204       if ($with_time === true) {
205         return $this->_languages[$this->_code]['date_format_short'] . ' ' . $this->getTimeFormat();
206       }
207
hpdl
386
208       return $this->_languages[$this->_code]['date_format_short'];
209     }
210
211     function getDateFormatLong() {
212       return $this->_languages[$this->_code]['date_format_long'];
213     }
214
215     function getTimeFormat() {
216       return $this->_languages[$this->_code]['time_format'];
217     }
218
219     function getTextDirection() {
220       return $this->_languages[$this->_code]['text_direction'];
221     }
222
223     function getCurrencyID() {
224       return $this->_languages[$this->_code]['currencies_id'];
225     }
226
227     function getNumericDecimalSeparator() {
228       return $this->_languages[$this->_code]['numeric_separator_decimal'];
229     }
230
231     function getNumericThousandsSeparator() {
232       return $this->_languages[$this->_code]['numeric_separator_thousands'];
233     }
hpdl
1431
234
235     function showImage($code = null, $width = '16', $height = '10', $parameters = null) {
236       if ( empty($code) ) {
237         $code = $this->_code;
238       }
239
240       $image_code = strtolower(substr($code, 3));
241
242       if ( !is_numeric($width) ) {
243         $width = 16;
244       }
245
246       if ( !is_numeric($height) ) {
247         $height = 10;
248       }
249
250       return osc_image('images/worldflags/' . $image_code . '.png', $this->_languages[$code]['name'], $width, $height, $parameters);
251     }
hpdl
1
252   }
253 ?>