[TEP-COMMIT] [CVS catalog] update the language class structure
hpdl-OfajU3CKLf1/[email protected] 24 Nov 2004 15:54:01 -0000
| Newsgroups | gmane.comp.web.oscommerce.cvs |
|---|---|
| Message-ID | <[email protected]> |
<html>
<head>
<style><!--
body {background-color:#ffffff;}
.file {border:1px solid #eeeeee;margin-top:1em;margin-bottom:1em;}
.pathname {font-family:monospace; float:right;}
.fileheader {margin-bottom:.5em;}
.diff {margin:0;}
.tasklist {padding:4px;border:1px dashed #000000;margin-top:1em;}
.tasklist ul {margin-top:0;margin-bottom:0;}
tr.alt {background-color:#eeeeee}
#added {background-color:#ddffdd;}
#addedchars {background-color:#99ff99;font-weight:bolder;}
tr.alt #added {background-color:#ccf7cc;}
#removed {background-color:#ffdddd;}
#removedchars {background-color:#ff9999;font-weight:bolder;}
tr.alt #removed {background-color:#f7cccc;}
#info {color:#888888;}
#context {background-color:#eeeeee;}
td {padding-left:.3em;padding-right:.3em;}
tr.head {border-bottom-width:1px;border-bottom-style:solid;}
tr.head td {padding:0;padding-top:.2em;}
.task {background-color:#ffff00;}
.comment {padding:4px;border:1px dashed #000000;background-color:#ffffdd}
.error {color:red;}
hr {border-width:0px;height:2px;background:black;}
--></style>
</head>
<body>
<table cellspacing="0" cellpadding="0" border="0" rules="cols">
<tr class="head"><td colspan="4">Commit in <b><tt>catalog/catalog/includes</tt></b><span id="info"> on MAIN</span></td></tr>
<tr><td><tt>boxes/<a href="#file1">languages.php</a></tt></td><td align="right" id="added">+4</td><td align="right" id="removed">-10</td><td nowrap="nowrap" align="center"><a href="http://cvs.oscommerce.com/viewcvs.cgi/catalog/catalog/includes/boxes/languages.php?rev=1.17&content-type=text/vnd.viewcvs-markup">1.17</a> <a href="http://cvs.oscommerce.com/viewcvs.cgi/catalog/catalog/includes/boxes/languages.php.diff?r1=1.17&r2=1.18">-></a> <a href="http://cvs.oscommerce.com/viewcvs.cgi/catalog/catalog/includes/boxes/languages.php?rev=1.18&content-type=text/vnd.viewcvs-markup">1.18</a></td></tr>
<tr class="alt"><td><tt>classes/<a href="#file2">language.php</a></tt></td><td align="right" id="added">+104</td><td align="right" id="removed">-71</td><td nowrap="nowrap" align="center"><a href="http://cvs.oscommerce.com/viewcvs.cgi/catalog/catalog/includes/classes/language.php?rev=1.8&content-type=text/vnd.viewcvs-markup">1.8</a> <a href="http://cvs.oscommerce.com/viewcvs.cgi/catalog/catalog/includes/classes/language.php.diff?r1=1.8&r2=1.9">-></a> <a href="http://cvs.oscommerce.com/viewcvs.cgi/catalog/catalog/includes/classes/language.php?rev=1.9&content-type=text/vnd.viewcvs-markup">1.9</a></td></tr>
<tr><td><tt>modules/services/<a href="#file3">language.php</a></tt></td><td align="right" id="added">+5</td><td align="right" id="removed">-12</td><td nowrap="nowrap" align="center"><a href="http://cvs.oscommerce.com/viewcvs.cgi/catalog/catalog/includes/modules/services/language.php?rev=1.2&content-type=text/vnd.viewcvs-markup">1.2</a> <a href="http://cvs.oscommerce.com/viewcvs.cgi/catalog/catalog/includes/modules/services/language.php.diff?r1=1.2&r2=1.3">-></a> <a href="http://cvs.oscommerce.com/viewcvs.cgi/catalog/catalog/includes/modules/services/language.php?rev=1.3&content-type=text/vnd.viewcvs-markup">1.3</a></td></tr>
<tr><td></td><td align="right" id="added">+113</td><td align="right" id="removed">-93</td><td></td></tr>
</table>
<small id="info">3 modified files</small><br />
<pre class="comment">
update the language class structure
store the selected language in a cookie for 90 days
</pre>
<hr /><a name="file1" /><div class="file">
<span class="pathname"><a href="http://cvs.oscommerce.com/viewcvs.cgi/catalog">catalog</a>/<a href="http://cvs.oscommerce.com/viewcvs.cgi/catalog/catalog">catalog</a>/<a href="http://cvs.oscommerce.com/viewcvs.cgi/catalog/catalog/includes">includes</a>/<a href="http://cvs.oscommerce.com/viewcvs.cgi/catalog/catalog/includes/boxes">boxes</a><br /></span>
<div class="fileheader"><big><b>languages.php</b></big> <small id="info"><a href="http://cvs.oscommerce.com/viewcvs.cgi/catalog/catalog/includes/boxes/languages.php?rev=1.17&content-type=text/vnd.viewcvs-markup">1.17</a> <a href="http://cvs.oscommerce.com/viewcvs.cgi/catalog/catalog/includes/boxes/languages.php.diff?r1=1.17&r2=1.18">-></a> <a href="http://cvs.oscommerce.com/viewcvs.cgi/catalog/catalog/includes/boxes/languages.php?rev=1.18&content-type=text/vnd.viewcvs-markup">1.18</a></small></div>
<pre class="diff"><small id="info">diff -u -r1.17 -r1.18
--- languages.php 2004/04/13 07:53:42 1.17
+++ languages.php 2004/11/24 15:53:50 1.18
@@ -5,17 +5,12 @@
</small></pre><pre class="diff" id="context"> osCommerce, Open Source E-Commerce Solutions
http://www.oscommerce.com
</pre><pre class="diff" id="removed">- Copyright (c) 200<span id="removedchars">3</span> osCommerce
</pre><pre class="diff" id="added">+ Copyright (c) 200<span id="addedchars">4</span> osCommerce
</pre><pre class="diff" id="context">
Released under the GNU General Public License
*/
</pre><pre class="diff" id="removed">- if (!isset($lng) || (isset($lng) && !is_object($lng))) {
- include(DIR_WS_CLASSES . 'language.php');
- $lng = new language;
- }
-
- if (sizeof($lng->catalog_languages) > 1){
</pre><pre class="diff" id="added">+ if (sizeof($osC_Language->getAll() > 1)) {
</pre><pre class="diff" id="context"> ?>
<!-- languages //-->
<tr>
</pre><pre class="diff"><small id="info">@@ -27,9 +22,8 @@
</small></pre><pre class="diff" id="context"> new infoBoxHeading($info_box_contents, false, false);
$languages_string = '';
</pre><pre class="diff" id="removed">- reset($lng->catalog_languages);
- while (list($key, $value) = each($lng->catalog_languages)) {
- $languages_string .= ' <a href="' . tep_href_link(basename($_SERVER['PHP_SELF']), tep_get_all_get_params(array('language', 'currency')) . 'language=' . $key, $request_type) . '">' . tep_image(DIR_WS_LANGUAGES . $value['directory'] . '/images/' . $value['image'], $value['name']) . '</a> ';
</pre><pre class="diff" id="added">+ foreach ($osC_Language->getAll() as $language) {
+ $languages_string .= ' <a href="' . tep_href_link(basename($_SERVER['PHP_SELF']), tep_get_all_get_params(array('language', 'currency')) . 'language=' . $language['code'], $request_type) . '">' . tep_image(DIR_WS_LANGUAGES . $language['directory'] . '/images/' . $language['image'], $language['name']) . '</a> ';
</pre><pre class="diff" id="context"> }
$info_box_contents = array();
</pre></div>
<hr /><a name="file2" /><div class="file">
<span class="pathname"><a href="http://cvs.oscommerce.com/viewcvs.cgi/catalog">catalog</a>/<a href="http://cvs.oscommerce.com/viewcvs.cgi/catalog/catalog">catalog</a>/<a href="http://cvs.oscommerce.com/viewcvs.cgi/catalog/catalog/includes">includes</a>/<a href="http://cvs.oscommerce.com/viewcvs.cgi/catalog/catalog/includes/classes">classes</a><br /></span>
<div class="fileheader"><big><b>language.php</b></big> <small id="info"><a href="http://cvs.oscommerce.com/viewcvs.cgi/catalog/catalog/includes/classes/language.php?rev=1.8&content-type=text/vnd.viewcvs-markup">1.8</a> <a href="http://cvs.oscommerce.com/viewcvs.cgi/catalog/catalog/includes/classes/language.php.diff?r1=1.8&r2=1.9">-></a> <a href="http://cvs.oscommerce.com/viewcvs.cgi/catalog/catalog/includes/classes/language.php?rev=1.9&content-type=text/vnd.viewcvs-markup">1.9</a></small></div>
<pre class="diff"><small id="info">diff -u -r1.8 -r1.9
--- language.php 2004/11/20 02:11:47 1.8
+++ language.php 2004/11/24 15:53:52 1.9
@@ -8,56 +8,21 @@
</small></pre><pre class="diff" id="context"> Copyright (c) 2004 osCommerce
Released under the GNU General Public License
</pre><pre class="diff" id="removed">-
- browser language detection logic Copyright phpMyAdmin (select_lang.lib.php3 v1.24 04/19/2002)
- Copyright Stephane Garin <[email protected]> (detect_language.php v0.1 04/02/2002)
</pre><pre class="diff" id="context"> */
</pre><pre class="diff" id="added">+
+ class osC_Language {
+
+/* Public variables */
</pre><pre class="diff" id="context">
</pre><pre class="diff" id="removed">- class language {
- var $languages, $catalog_languages, $browser_languages, $language;
</pre><pre class="diff" id="added">+ var $language;
</pre><pre class="diff" id="context">
</pre><pre class="diff" id="removed">- function language($lng = '') {
- global $osC_Database;
</pre><pre class="diff" id="added">+/* Private variables */
+ var $_languages = array();
</pre><pre class="diff" id="context">
</pre><pre class="diff" id="removed">- $this->languages = array('ar' => 'ar([-_][[:alpha:]]{2})?|arabic',
- 'bg' => 'bg|bulgarian',
- 'br' => 'pt[-_]br|brazilian portuguese',
- 'ca' => 'ca|catalan',
- 'cs' => 'cs|czech',
- 'da' => 'da|danish',
- 'de' => 'de([-_][[:alpha:]]{2})?|german',
- 'el' => 'el|greek',
- 'en' => 'en([-_][[:alpha:]]{2})?|english',
- 'es' => 'es([-_][[:alpha:]]{2})?|spanish',
- 'et' => 'et|estonian',
- 'fi' => 'fi|finnish',
- 'fr' => 'fr([-_][[:alpha:]]{2})?|french',
- 'gl' => 'gl|galician',
- 'he' => 'he|hebrew',
- 'hu' => 'hu|hungarian',
- 'id' => 'id|indonesian',
- 'it' => 'it|italian',
- 'ja' => 'ja|japanese',
- 'ko' => 'ko|korean',
- 'ka' => 'ka|georgian',
- 'lt' => 'lt|lithuanian',
- 'lv' => 'lv|latvian',
- 'nl' => 'nl([-_][[:alpha:]]{2})?|dutch',
- 'no' => 'no|norwegian',
- 'pl' => 'pl|polish',
- 'pt' => 'pt([-_][[:alpha:]]{2})?|portuguese',
- 'ro' => 'ro|romanian',
- 'ru' => 'ru|russian',
- 'sk' => 'sk|slovak',
- 'sr' => 'sr|serbian',
- 'sv' => 'sv|swedish',
- 'th' => 'th|thai',
- 'tr' => 'tr|turkish',
- 'uk' => 'uk|ukrainian',
- 'tw' => 'zh[-_]tw|chinese traditional',
- 'zh' => 'zh|chinese simplified');
</pre><pre class="diff" id="added">+/* Class constructor */
</pre><pre class="diff" id="context">
</pre><pre class="diff" id="removed">- $this->catalog_languages = array();
</pre><pre class="diff" id="added">+ function osC_Language() {
+ global $osC_Database, $osC_Session;
</pre><pre class="diff" id="context">
$Qlanguages = $osC_Database->query('select * from :table_languages order by sort_order, name');
$Qlanguages->bindTable(':table_languages', TABLE_LANGUAGES);
</pre><pre class="diff"><small id="info">@@ -65,26 +30,33 @@
</small></pre><pre class="diff" id="context"> $Qlanguages->execute();
while ($Qlanguages->next()) {
</pre><pre class="diff" id="removed">- $this->catalog_languages[$Qlanguages->value('code')] = array('id' => $Qlanguages->valueInt('languages_id'),
- 'name' => $Qlanguages->value('name'),
- 'code' => $Qlanguages->value('code'),
- 'image' => $Qlanguages->value('image'),
- 'directory' => $Qlanguages->value('directory'));
</pre><pre class="diff" id="added">+ $this->_languages[$Qlanguages->value('code')] = array('id' => $Qlanguages->valueInt('languages_id'),
+ 'name' => $Qlanguages->value('name'),
+ 'code' => $Qlanguages->value('code'),
+ 'image' => $Qlanguages->value('image'),
+ 'directory' => $Qlanguages->value('directory'));
</pre><pre class="diff" id="context"> }
$Qlanguages->freeResult();
</pre><pre class="diff" id="removed">- $this->browser_languages = '';
- $this->language = '';
-
- $this->set_language($lng);
</pre><pre class="diff" id="added">+ if ($osC_Session->exists('language')) {
+ $this->set();
+ } else {
+ $this->setToBrowser();
+ }
</pre><pre class="diff" id="context"> }
</pre><pre class="diff" id="removed">- function set_language($language) {
</pre><pre class="diff" id="added">+/* Public methods */
+
+ function set($language = '') {
+ if (PHP_VERSION < 4.1) {
+ global $_COOKIE;
+ }
+
</pre><pre class="diff" id="context"> global $osC_Session;
if (empty($language) && $osC_Session->exists('language')) {
</pre><pre class="diff" id="removed">- foreach ($this-><span id="removedchars">catalog</span>_languages as $l) {
</pre><pre class="diff" id="added">+ foreach ($this->_languages as $l) {
</pre><pre class="diff" id="context"> if ($l['directory'] == $osC_Session->value('language')) {
$language = $l['code'];
break;
</pre><pre class="diff"><small id="info">@@ -92,37 +64,98 @@
</small></pre><pre class="diff" id="context"> }
}
</pre><pre class="diff" id="removed">- if (!empty($language) && $this->exists($language)) {
- $this->language = $this->get($language);
- } else {
- $this->language = $this->get(DEFAULT_LANGUAGE);
</pre><pre class="diff" id="added">+ if (empty($language) || ($this->exists($language) === false)) {
+ $language = DEFAULT_LANGUAGE;
</pre><pre class="diff" id="context"> }
</pre><pre class="diff" id="added">+
+ $this->language = $this->get($language);
+
+ if (!isset($_COOKIE['language']) || (isset($_COOKIE['language']) && ($_COOKIE['language'] != $this->language['code']))) {
+ tep_setcookie('language', $this->language['code'], time()+60*60*24*90);
+ }
+
+ if (($osC_Session->exists('language') === false) || ($osC_Session->exists('language') && ($osC_Session->value('language') != $this->language['directory']))) {
+ $osC_Session->set('language', $this->language['directory']);
+ $osC_Session->set('languages_id', $this->language['id']);
+ }
</pre><pre class="diff" id="context"> }
</pre><pre class="diff" id="removed">- function get_browser_language() {
- $this->browser_languages = explode(',', getenv('HTTP_ACCEPT_LANGUAGE'));
</pre><pre class="diff" id="added">+ function setToBrowser() {
+ if (PHP_VERSION < 4.1) {
+ global $_COOKIE, $_SERVER;
+ }
+
+ if (isset($_COOKIE['language'])) {
+ if ($this->exists($_COOKIE['language'])) {
+ $this->set($_COOKIE['language']);
</pre><pre class="diff" id="context">
</pre><pre class="diff" id="removed">- for ($i=0, $n=sizeof($this->browser_languages); $i<$n; $i++) {
- reset($this->languages);
- while (list($key, $value) = each($this->languages)) {
- if (eregi('^(' . $value . ')(;q=[0-9]\\.[0-9])?$', $this->browser_languages[$i]) && isset($this->catalog_languages[$key])) {
- $this->language = $this->catalog_languages[$key];
- break 2;
</pre><pre class="diff" id="added">+ return true;
+ }
+ }
+
+ $http_accept_language = explode(',', $_SERVER['HTTP_ACCEPT_LANGUAGE']);
+
+ $browser_languages = array('ar' => 'ar([-_][[:alpha:]]{2})?|arabic',
+ 'bg' => 'bg|bulgarian',
+ 'br' => 'pt[-_]br|brazilian portuguese',
+ 'ca' => 'ca|catalan',
+ 'cs' => 'cs|czech',
+ 'da' => 'da|danish',
+ 'de' => 'de([-_][[:alpha:]]{2})?|german',
+ 'el' => 'el|greek',
+ 'en' => 'en([-_][[:alpha:]]{2})?|english',
+ 'es' => 'es([-_][[:alpha:]]{2})?|spanish',
+ 'et' => 'et|estonian',
+ 'fi' => 'fi|finnish',
+ 'fr' => 'fr([-_][[:alpha:]]{2})?|french',
+ 'gl' => 'gl|galician',
+ 'he' => 'he|hebrew',
+ 'hu' => 'hu|hungarian',
+ 'id' => 'id|indonesian',
+ 'it' => 'it|italian',
+ 'ja' => 'ja|japanese',
+ 'ko' => 'ko|korean',
+ 'ka' => 'ka|georgian',
+ 'lt' => 'lt|lithuanian',
+ 'lv' => 'lv|latvian',
+ 'nl' => 'nl([-_][[:alpha:]]{2})?|dutch',
+ 'no' => 'no|norwegian',
+ 'pl' => 'pl|polish',
+ 'pt' => 'pt([-_][[:alpha:]]{2})?|portuguese',
+ 'ro' => 'ro|romanian',
+ 'ru' => 'ru|russian',
+ 'sk' => 'sk|slovak',
+ 'sr' => 'sr|serbian',
+ 'sv' => 'sv|swedish',
+ 'th' => 'th|thai',
+ 'tr' => 'tr|turkish',
+ 'uk' => 'uk|ukrainian',
+ 'tw' => 'zh[-_]tw|chinese traditional',
+ 'zh' => 'zh|chinese simplified');
+
+ foreach ($http_accept_language as $browser_language) {
+ foreach ($browser_languages as $key => $value) {
+ if (eregi('^(' . $value . ')(;q=[0-9]\\.[0-9])?$', $browser_language) && $this->exists($key)) {
+ $this->set($this->_languages[$key]);
+
+ return true;
</pre><pre class="diff" id="context"> }
}
}
</pre><pre class="diff" id="added">+
+ $this->set(DEFAULT_LANGUAGE);
</pre><pre class="diff" id="context"> }
function get($language) {
</pre><pre class="diff" id="removed">- return $this-><span id="removedchars">catalog</span>_languages[$language];
</pre><pre class="diff" id="added">+ return $this->_languages[$language];
</pre><pre class="diff" id="context"> }
function getAll() {
</pre><pre class="diff" id="removed">- return $this-><span id="removedchars">catalog</span>_languages;
</pre><pre class="diff" id="added">+ return $this->_languages;
</pre><pre class="diff" id="context"> }
function exists($language) {
</pre><pre class="diff" id="removed">- if (isset($this-><span id="removedchars">catalog</span>_languages[$language])) {
</pre><pre class="diff" id="added">+ if (isset($this->_languages[$language])) {
</pre><pre class="diff" id="context"> return true;
}
</pre></div>
<hr /><a name="file3" /><div class="file">
<span class="pathname"><a href="http://cvs.oscommerce.com/viewcvs.cgi/catalog">catalog</a>/<a href="http://cvs.oscommerce.com/viewcvs.cgi/catalog/catalog">catalog</a>/<a href="http://cvs.oscommerce.com/viewcvs.cgi/catalog/catalog/includes">includes</a>/<a href="http://cvs.oscommerce.com/viewcvs.cgi/catalog/catalog/includes/modules">modules</a>/<a href="http://cvs.oscommerce.com/viewcvs.cgi/catalog/catalog/includes/modules/services">services</a><br /></span>
<div class="fileheader"><big><b>language.php</b></big> <small id="info"><a href="http://cvs.oscommerce.com/viewcvs.cgi/catalog/catalog/includes/modules/services/language.php?rev=1.2&content-type=text/vnd.viewcvs-markup">1.2</a> <a href="http://cvs.oscommerce.com/viewcvs.cgi/catalog/catalog/includes/modules/services/language.php.diff?r1=1.2&r2=1.3">-></a> <a href="http://cvs.oscommerce.com/viewcvs.cgi/catalog/catalog/includes/modules/services/language.php?rev=1.3&content-type=text/vnd.viewcvs-markup">1.3</a></small></div>
<pre class="diff"><small id="info">diff -u -r1.2 -r1.3
--- language.php 2004/04/14 23:22:56 1.2
+++ language.php 2004/11/24 15:53:54 1.3
@@ -22,20 +22,13 @@
</small></pre><pre class="diff" id="context"> global $_GET;
}
</pre><pre class="diff" id="removed">- global $osC_Session, $<span id="removedchars">lng</span>;
</pre><pre class="diff" id="added">+ global $osC_Session, $<span id="addedchars">osC_Language</span>;
</pre><pre class="diff" id="context">
</pre><pre class="diff" id="removed">- if (($osC_Session->exists('language') == false) || isset($_GET['language'])) {
- include('includes/classes/language.php');
- $lng = new language;
</pre><pre class="diff" id="added">+ require('includes/classes/language.php');
+ $osC_Language = new osC_Language();
</pre><pre class="diff" id="context">
</pre><pre class="diff" id="removed">- if (isset($_GET['language']) && tep_not_null($_GET['language'])) {
- $lng->set_language($_GET['language']);
- } else {
- $lng->get_browser_language();
- }
-
- $osC_Session->set('language', $lng->language['directory']);
- $osC_Session->set('languages_id', $lng->language['id']);
</pre><pre class="diff" id="added">+ if (isset($_GET['language']) && !empty($_GET['language'])) {
+ $osC_Language->set($_GET['language']);
</pre><pre class="diff" id="context"> }
require('includes/languages/' . $osC_Session->value('language') . '.php');
</pre></div>
<center><small><a href="http://www.badgers-in-foil.co.uk/projects/cvsspam/" title="commit -> email">CVSspam</a> 0.2.9</small></center>
</body></html>
-------------------------------------------------------
SF email is sponsored by - The IT Product Guide
Read honest & candid reviews on hundreds of IT Products from real users.
Discover which products truly live up to the hype. Start reading now.
http://productguide.itmanagersjournal.com/