Quick Search:

View

Revision:

Diff

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