1
0
mirror of https://github.com/e107inc/e107.git synced 2025-08-06 14:46:56 +02:00

multi-language problems

This commit is contained in:
secretr
2011-05-01 16:35:57 +00:00
parent 644c287ee0
commit 820da43f63

View File

@@ -2,16 +2,14 @@
/* /*
* e107 website system * e107 website system
* *
* Copyright (C) 2008-2009 e107 Inc (e107.org) * Copyright (C) 2008-2011 e107 Inc (e107.org)
* Released under the terms and conditions of the * Released under the terms and conditions of the
* GNU General Public License (http://www.gnu.org/licenses/gpl.txt) * GNU General Public License (http://www.gnu.org/licenses/gpl.txt)
* *
* mySQL Handler * mySQL Handler
* *
* $Source: /cvs_backup/e107_0.8/e107_handlers/mysql_class.php,v $ * $URL$
* $Revision$ * $Id$
* $Date$
* $Author$
*/ */
@@ -24,8 +22,8 @@
* @todo separate cache for db type tables * @todo separate cache for db type tables
* *
* WARNING!!! System config should be DIRECTLY called inside db handler like this: * WARNING!!! System config should be DIRECTLY called inside db handler like this:
* e107::getConfig('core', false); * e107::getConfig('core', false);
* FALSE (don't load) is critical important - if missed, expect dead loop (preference handler is calling db handler as well * FALSE (don't load) is critical important - if missed, expect dead loop (preference handler is calling db handler as well
* when data is initally loaded) * when data is initally loaded)
* Always use $this->getConfig() method to avoid issues pointed above * Always use $this->getConfig() method to avoid issues pointed above
*/ */
@@ -117,7 +115,7 @@ class e_db_mysql
$this->mySQLPrefix = MPREFIX; // Set the default prefix - may be overridden $this->mySQLPrefix = MPREFIX; // Set the default prefix - may be overridden
$langid = (isset($pref['cookie_name'])) ? 'e107language_'.$pref['cookie_name'] : 'e107language_temp'; /*$langid = (isset($pref['cookie_name'])) ? 'e107language_'.$pref['cookie_name'] : 'e107language_temp';
if (isset($pref['user_tracking']) && ($pref['user_tracking'] == 'session')) if (isset($pref['user_tracking']) && ($pref['user_tracking'] == 'session'))
{ {
if (!isset($_SESSION[$langid])) { return; } if (!isset($_SESSION[$langid])) { return; }
@@ -127,7 +125,9 @@ class e_db_mysql
{ {
if (!isset($_COOKIE[$langid])) { return; } if (!isset($_COOKIE[$langid])) { return; }
$this->mySQLlanguage = $_COOKIE[$langid]; $this->mySQLlanguage = $_COOKIE[$langid];
} }*/
// Detect is already done in language handler, use it if not too early
if(defined('e_LANGUAGE')) $this->mySQLlanguage = e107::getLanguage()->e_language;
} }
/** /**
@@ -929,8 +929,9 @@ class e_db_mysql
if(strpos($query,'`#') !== FALSE) if(strpos($query,'`#') !== FALSE)
{ {
$query = str_replace('`#','`'.$this->mySQLPrefix,$query); // This simple substitution should be OK when backticks used //$query = str_replace('`#','`'.$this->mySQLPrefix,$query); // This simple substitution should be OK when backticks used
//$query = preg_replace_callback("/\s`#([\w]*?)`\W/", array($this, 'ml_check'), $query); // SecretR - reverted back - breaks multi-language
$query = preg_replace_callback("/\s`#([\w]*?)`\W/", array($this, 'ml_check'), $query);
} }
elseif(strpos($query,'#') !== FALSE) elseif(strpos($query,'#') !== FALSE)
{ // Deprecated scenario - caused problems when '#' appeared in data - hence use of backticks { // Deprecated scenario - caused problems when '#' appeared in data - hence use of backticks
@@ -1031,7 +1032,7 @@ class e_db_mysql
//When running a multi-language site with english included. English must be the main site language. //When running a multi-language site with english included. English must be the main site language.
// WARNING!!! FALSE is critical important - if missed, expect dead loop (prefs are calling db handler as well when loading) // WARNING!!! FALSE is critical important - if missed, expect dead loop (prefs are calling db handler as well when loading)
// Temporary solution, better one is needed // Temporary solution, better one is needed
$core_pref = $this->getConfig(); $core_pref = $this->getConfig();
//if ((!$this->mySQLlanguage || !$pref['multilanguage'] || $this->mySQLlanguage=='English') && $multiple==FALSE) //if ((!$this->mySQLlanguage || !$pref['multilanguage'] || $this->mySQLlanguage=='English') && $multiple==FALSE)
if ((!$this->mySQLlanguage || !$core_pref->get('multilanguage') || !$core_pref->get('sitelanguage') /*|| $this->mySQLlanguage==$core_pref->get('sitelanguage')*/) && $multiple==FALSE) if ((!$this->mySQLlanguage || !$core_pref->get('multilanguage') || !$core_pref->get('sitelanguage') /*|| $this->mySQLlanguage==$core_pref->get('sitelanguage')*/) && $multiple==FALSE)
{ {
@@ -1047,7 +1048,7 @@ class e_db_mysql
if($multiple == FALSE) if($multiple == FALSE)
{ {
$mltable = "lan_".strtolower($this->mySQLlanguage.'_'.$table); $mltable = "lan_".strtolower($this->mySQLlanguage.'_'.$table);
return ($this->db_Table_exists($table,$this->mySQLlanguage)) ? $mltable : $table; return ($this->db_Table_exists($table,$this->mySQLlanguage) ? $mltable : $table);
} }
else // return an array of all matching language tables. eg [french]->e107_lan_news else // return an array of all matching language tables. eg [french]->e107_lan_news
{ {
@@ -1319,9 +1320,11 @@ class e_db_mysql
{ {
global $pref; global $pref;
$table = strtolower($table); // precaution for multilanguage $table = strtolower($table); // precaution for multilanguage
// it's lan table check
if($language && ($language != $pref['sitelanguage'])) if($language)
{ {
// TODO - discuss this!!! Smells like mislogic - we ignore e.g. bulgarian_news when default language is Bulgarian!
if($language == $pref['sitelanguage']) return false;
if(!isset($this->mySQLtableListLanguage[$language])) if(!isset($this->mySQLtableListLanguage[$language]))
{ {
$this->mySQLtableListLanguage = $this->db_mySQLtableList($language); $this->mySQLtableListLanguage = $this->db_mySQLtableList($language);
@@ -1341,7 +1344,8 @@ class e_db_mysql
/** /**
* Populate $this->mySQLtableList; * Populate mySQLtableList and mySQLtableListLanguage
* TODO - better runtime cache - use e107::getRegistry() && e107::setRegistry()
* @return array * @return array
*/ */
private function db_mySQLtableList($language='') private function db_mySQLtableList($language='')
@@ -1507,7 +1511,7 @@ class e_db_mysql
{ {
return $this->mySQLlastErrText; // Text of last error (empty string if no error) return $this->mySQLlastErrText; // Text of last error (empty string if no error)
} }
function resetLastError() function resetLastError()
{ {
$this->mySQLlastErrNum = 0; $this->mySQLlastErrNum = 0;