mirror of
https://github.com/e107inc/e107.git
synced 2025-08-03 21:27:25 +02:00
Fix for failing multi-language methods.
This commit is contained in:
@@ -1451,14 +1451,12 @@ class e_db_mysql
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Check for the existence of a matching language table when multi-language tables are active.
|
* Check for the existence of a matching language table when multi-language tables are active.
|
||||||
* @param string $table Name of table, without the prefix.
|
* @param string $table Name of table, without the prefix. or an array of table names.
|
||||||
* @access private
|
* @access private
|
||||||
* @return name of the language table (eg. lan_french_news)
|
* @return mixed the name of the language table (eg. lan_french_news) or an array of all matching language tables. (with mprefix)
|
||||||
*/
|
*/
|
||||||
function db_IsLang($table,$multiple=FALSE)
|
function db_IsLang($table, $multiple=false)
|
||||||
{
|
{
|
||||||
global $pref;
|
|
||||||
|
|
||||||
//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
|
||||||
@@ -1487,23 +1485,41 @@ class e_db_mysql
|
|||||||
$table = array($table);
|
$table = array($table);
|
||||||
}
|
}
|
||||||
|
|
||||||
foreach($this->mySQLtablelist as $tab)
|
if(!$this->mySQLtableList)
|
||||||
{
|
{
|
||||||
if(stristr($tab, $this->mySQLPrefix."lan_") !== FALSE)
|
$this->mySQLtableList = $this->db_mySQLtableList();
|
||||||
|
}
|
||||||
|
|
||||||
|
$lanlist = array();
|
||||||
|
|
||||||
|
foreach($this->mySQLtableList as $tab)
|
||||||
|
{
|
||||||
|
|
||||||
|
if(substr($tab,0,4) == "lan_")
|
||||||
{
|
{
|
||||||
$tmp = explode("_",str_replace($this->mySQLPrefix."lan_","",$tab));
|
list($tmp,$lng,$tableName) = explode("_",$tab,3);
|
||||||
$lng = $tmp[0];
|
|
||||||
foreach($table as $t)
|
foreach($table as $t)
|
||||||
{
|
{
|
||||||
if(preg_match('/'.$t.'$/i', $tab)) // some str*() check instead?
|
if($tableName == $t)
|
||||||
{
|
{
|
||||||
$lanlist[$lng][$this->mySQLPrefix.$t] = $tab;
|
$lanlist[$lng][$this->mySQLPrefix.$t] = $this->mySQLPrefix.$tab; // prefix needed.
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return (varset($lanlist)) ? $lanlist : FALSE;
|
if(empty($lanlist))
|
||||||
|
{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
return $lanlist;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
// -------------------------
|
// -------------------------
|
||||||
|
|
||||||
@@ -1597,53 +1613,67 @@ class e_db_mysql
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/*
|
/**
|
||||||
Multi-language Query Function.
|
* Multi-language Query Function. Run a query on the same table across all languages.
|
||||||
*/
|
* @param $query
|
||||||
function db_Query_all($query,$debug="")
|
* @param bool $debug
|
||||||
|
* @return bool
|
||||||
|
*/
|
||||||
|
function db_Query_all($query, $debug=false)
|
||||||
{
|
{
|
||||||
$error = "";
|
$error = "";
|
||||||
|
|
||||||
$query = str_replace("#",$this->mySQLPrefix,$query);
|
$query = str_replace("#", $this->mySQLPrefix, $query);
|
||||||
|
|
||||||
if(!$this->db_Query($query))
|
if(!$this->db_Query($query))
|
||||||
{ // run query on the default language first.
|
{ // run query on the default language first.
|
||||||
$error .= $query. " failed";
|
$error .= $query. " failed";
|
||||||
}
|
}
|
||||||
|
|
||||||
$tmp = explode(" ",$query);
|
$table = array();
|
||||||
|
$search = array();
|
||||||
|
|
||||||
|
$tmp = explode(" ",$query); // split the query
|
||||||
|
|
||||||
foreach($tmp as $val)
|
foreach($tmp as $val)
|
||||||
{
|
{
|
||||||
if(strpos($val,$this->mySQLPrefix) !== FALSE)
|
if(strpos($val,$this->mySQLPrefix) !== false) // search for table names references using the mprefix
|
||||||
{
|
{
|
||||||
$table[] = str_replace($this->mySQLPrefix,"",$val);
|
$table[] = str_replace(array($this->mySQLPrefix,"`"),"", $val);
|
||||||
$search[] = $val;
|
$search[] = str_replace("`","",$val);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if(empty($table) || empty($search))
|
||||||
|
{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
// Loop thru relevant language tables and replace each tablename within the query.
|
// Loop thru relevant language tables and replace each tablename within the query.
|
||||||
if($tablist = $this->db_IsLang($table,TRUE))
|
|
||||||
|
if($tablist = $this->db_IsLang($table, true))
|
||||||
{
|
{
|
||||||
foreach($tablist as $key=>$tab)
|
foreach($tablist as $key=>$tab)
|
||||||
{
|
{
|
||||||
$querylan = $query;
|
$querylan = $query;
|
||||||
|
|
||||||
foreach($search as $find)
|
foreach($search as $find)
|
||||||
{
|
{
|
||||||
$lang = $key;
|
|
||||||
$replace = ($tab[$find] !="") ? $tab[$find] : $find;
|
$replace = ($tab[$find] !="") ? $tab[$find] : $find;
|
||||||
$querylan = str_replace($find,$replace,$querylan);
|
$querylan = str_replace($find,$replace,$querylan);
|
||||||
}
|
}
|
||||||
|
|
||||||
if(!$this->db_Query($querylan))
|
if(!$this->db_Query($querylan)) // run query on other language tables.
|
||||||
{ // run query on other language tables.
|
{
|
||||||
$error .= $querylan." failed for language";
|
$error .= $querylan." failed for language";
|
||||||
}
|
}
|
||||||
|
|
||||||
if($debug){ echo "<br />** lang= ".$querylan; }
|
if($debug){ echo "<br />** lang= ".$querylan; }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
return ($error)? FALSE : TRUE;
|
return ($error) ? false : true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -1892,17 +1922,28 @@ class e_db_mysql
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Return a filtered list of DB tables.
|
* Legacy Alias of tables
|
||||||
* @param object $mode [optional] all|lan|nolan
|
* @deprecated
|
||||||
|
* @param string $mode
|
||||||
* @return array
|
* @return array
|
||||||
*/
|
*/
|
||||||
public function db_TableList($mode='all')
|
public function db_TableList($mode='all')
|
||||||
|
{
|
||||||
|
return $this->tables($mode);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Return a filtered list of DB tables.
|
||||||
|
* @param object $mode [optional] all|lan|nolan|nologs
|
||||||
|
* @return array
|
||||||
|
*/
|
||||||
|
public function tables($mode='all')
|
||||||
{
|
{
|
||||||
|
|
||||||
if(!$this->mySQLtableList)
|
if(!$this->mySQLtableList)
|
||||||
{
|
{
|
||||||
$this->mySQLtableList = $this->db_mySQLtableList();
|
$this->mySQLtableList = $this->db_mySQLtableList();
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if($mode == 'nologs')
|
if($mode == 'nologs')
|
||||||
@@ -1947,7 +1988,8 @@ class e_db_mysql
|
|||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Duplicate a Table Row in a table.
|
* Duplicate a Table Row in a table.
|
||||||
*/
|
*/
|
||||||
@@ -2037,7 +2079,7 @@ class e_db_mysql
|
|||||||
if($table=='*')
|
if($table=='*')
|
||||||
{
|
{
|
||||||
$nolog = vartrue($options['nologs']) ? 'nologs' : 'all';
|
$nolog = vartrue($options['nologs']) ? 'nologs' : 'all';
|
||||||
$tableList = $this->db_TableList($nolog);
|
$tableList = $this->tables($nolog);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
Reference in New Issue
Block a user