diff --git a/e107_admin/language.php b/e107_admin/language.php
index b56e3fdb8..2606989db 100644
--- a/e107_admin/language.php
+++ b/e107_admin/language.php
@@ -9,78 +9,66 @@
* Administration Area - Languages
*
* $Source: /cvs_backup/e107_0.8/e107_admin/language.php,v $
- * $Revision: 1.18 $
- * $Date: 2009-08-28 16:11:01 $
- * $Author: marj_nl_fr $
+ * $Revision: 1.19 $
+ * $Date: 2009-09-05 18:58:56 $
+ * $Author: e107coders $
*
-*/
-
-require_once("../class2.php");
+ */
+require_once ("../class2.php");
if (!getperms('0'))
{
header("location:".e_BASE."index.php");
exit;
}
-
include_lan(e_LANGUAGEDIR.e_LANGUAGE.'/admin/lan_'.e_PAGE);
-
$e_sub_cat = 'language';
-
-require_once("auth.php");
-require_once(e_HANDLER."form_handler.php");
-require_once(e_HANDLER."message_handler.php");
-
+require_once ("auth.php");
+require_once (e_HANDLER."form_handler.php");
+require_once (e_HANDLER."message_handler.php");
$frm = new e_form();
$emessage = &eMessage::getInstance();
-
$tabs = table_list(); // array("news","content","links");
-$lanlist = explode(",",e_LANLIST);
+$lanlist = explode(",", e_LANLIST);
$message = '';
-
if (e_QUERY)
{
$tmp = explode('.', e_QUERY);
- $action = $tmp[0];
- $sub_action = $tmp[1];
- $id = $tmp[2];
+ $action = varset($tmp[0]);
+ $sub_action = varset($tmp[1]);
+ $id = varset($tmp[2]);
unset($tmp);
}
-
if (isset($_POST['submit_prefs']) && isset($_POST['mainsitelanguage']))
{
unset($temp);
$changes = array();
-
- $temp['multilanguage'] = $_POST['multilanguage'];
- $temp['multilanguage_subdomain'] = $_POST['multilanguage_subdomain'];
+ $temp['multilanguage'] = $_POST['multilanguage'];
+ $temp['multilanguage_subdomain'] = $_POST['multilanguage_subdomain'];
$temp['sitelanguage'] = $_POST['mainsitelanguage'];
$temp['noLanguageSubs'] = $_POST['noLanguageSubs'];
-
if ($admin_log->logArrayDiffs($temp, $pref, 'LANG_01'))
{
- save_prefs(); // Only save if changes
+ save_prefs(); // Only save if changes
$emessage->add(LAN_SETSAVED, E_MESSAGE_SUCCESS);
-
}
else
{
$emessage->add(LAN_NO_CHANGE);
}
}
-
-
// ----------------- delete tables ---------------------------------------------
if (isset($_POST['del_existing']) && $_POST['lang_choices'])
{
$lang = strtolower($_POST['lang_choices']);
foreach ($tabs as $del_table)
{
- if (db_Table_exists($lang."_".$del_table))
+ if ($sql->db_Table_exists($lang."_".$del_table,TRUE))
{
+ echo $del_table." exists
";
$qry = "DROP TABLE ".$mySQLprefix."lan_".$lang."_".$del_table;
if (mysql_query($qry))
{
- $message .= sprintf(LANG_LAN_28, $_POST['lang_choices'].' '.$del_table).'[!br!]' ;
+ $message .= sprintf(LANG_LAN_28, $_POST['lang_choices'].' '.$del_table).'[!br!]';
$emessage->add(sprintf(LANG_LAN_28, $_POST['lang_choices'].' '.$del_table), E_MESSAGE_SUCCESS);
}
else
@@ -91,32 +79,30 @@ if (isset($_POST['del_existing']) && $_POST['lang_choices'])
}
}
$admin_log->log_event('LANG_02', $message, E_LOG_INFORMATIVE, '');
- global $cachevar;
- unset($cachevar['table_list']);
- if($action == 'modify') $action = 'db';//FIX - force db action when deleting all lan tables
+ $sql->db_ResetTableList();
+
+ if ($action == 'modify')
+ $action = 'db';//FIX - force db action when deleting all lan tables
}
-
// ----------create tables -----------------------------------------------------
-
if (isset($_POST['create_tables']) && $_POST['language'])
{
$table_to_copy = array();
$lang_to_create = array();
-
foreach ($tabs as $value)
{
$lang = strtolower($_POST['language']);
if (isset($_POST[$value]))
{
- $copdata = ($_POST['copydata_'.$value]) ? 1 : 0;
- if (copy_table($value, "lan_".$lang."_".$value, $_POST['drop'],$copdata))
+ $copdata = ($_POST['copydata_'.$value]) ? 1 : 0;
+ if ($sql->db_CopyTable($value, "lan_".$lang."_".$value, $_POST['drop'], $copdata))
{
$message .= sprintf(LANG_LAN_30, $_POST['language'].' '.$value).'[!br!]';
$emessage->add(sprintf(LANG_LAN_30, $_POST['language'].' '.$value), E_MESSAGE_SUCCESS);
}
else
{
- if(!$_POST['drop'])
+ if (!$_POST['drop'])
{
$message .= sprintf(LANG_LAN_00, $_POST['language'].' '.$value).'[!br!]';
$emessage->add(sprintf(LANG_LAN_00, $_POST['language'].' '.$value), E_MESSAGE_WARNING);
@@ -128,12 +114,12 @@ if (isset($_POST['create_tables']) && $_POST['language'])
}
}
}
- elseif (db_Table_exists($lang."_".$value))
+ elseif ($sql->db_Table_exists($value,$_POST['language']))
{
if ($_POST['remove'])
{
// Remove table.
- if(mysql_query("DROP TABLE ".$mySQLprefix."lan_".$lang."_".$value))
+ if (mysql_query("DROP TABLE ".$mySQLprefix."lan_".$lang."_".$value))
{
$message .= $_POST['language'].' '.$value.' '.LAN_DELETED.'[!br!]';
$emessage->add($_POST['language'].' '.$value.' '.LAN_DELETED, E_MESSAGE_SUCCESS);
@@ -153,52 +139,39 @@ if (isset($_POST['create_tables']) && $_POST['language'])
}
}
$admin_log->log_event('LANG_03', $message, E_LOG_INFORMATIVE, '');
- global $cachevar;
- unset($cachevar['table_list']);
+ $sql->db_ResetTableList();
}
-
-
/*
- if(isset($message) && $message)
- {
- $ns->tablerender(LAN_OK, $message);
- }
-*/
-
-
+ if(isset($message) && $message)
+ {
+ $ns->tablerender(LAN_OK, $message);
+ }
+ */
+
+
unset($text);
-
-
-
if (!e_QUERY || $action == 'main' && !$_POST['language'] && !$_POST['edit_existing'])
{
multilang_prefs();
}
-
-if ($action == 'db')
+if (varset($action) == 'db')
{
multilang_db();
}
-
-if($_POST['ziplang'] && $_POST['language'])
+if (varset($_POST['ziplang']) && varset($_POST['language']))
{
- $text = zip_up_lang($_POST['language']);
+ $text = zip_up_lang($_POST['language']);
$admin_log->log_event('LANG_04', $_POST['language'], E_LOG_INFORMATIVE, '');
- //$ns -> tablerender(LANG_LAN_25, $text);
- $emessage->add(LANG_LAN_25.': '.$text);
+ //$ns -> tablerender(LANG_LAN_25, $text);
+ $emessage->add(LANG_LAN_25.': '.$text);
}
-
-if($action == "tools")
+if (varset($action) == "tools")
{
show_tools();
}
-
-
-
-
//FIX - create or edit check
-if(isset($_POST['create_edit_existing'])) $_POST['edit_existing'] = true;
-
+if (isset($_POST['create_edit_existing']))
+ $_POST['edit_existing'] = true;
// Grab Language configuration. ---
if (isset($_POST['edit_existing']))
{
@@ -214,10 +187,9 @@ if (isset($_POST['edit_existing']))
";
-
foreach ($tabs as $table_name)
{
- $installed = strtolower($_POST['lang_choices'])."_".$table_name;
+ $installed = 'lan_'.strtolower($_POST['lang_choices'])."_".$table_name;
if (stristr($_POST['lang_choices'], $installed) === FALSE)
{
$text .= "
@@ -226,7 +198,7 @@ if (isset($_POST['edit_existing']))
";
- $selected = (db_Table_exists($installed)) ? " checked='checked'" : "";
+ $selected = ($sql->db_Table_exists($table_name,$_POST['lang_choices'])) ? " checked='checked'" : "";
$text .= "
@@ -242,11 +214,9 @@ if (isset($_POST['edit_existing']))
";
}
}
-
// ===========================================================================
-
// Drop tables ? isset()
- if(varset($_POST['create_edit_existing']))
+ if (varset($_POST['create_edit_existing']))
{
$baction = 'create';
$bcaption = LANG_LAN_06;
@@ -256,7 +226,6 @@ if (isset($_POST['edit_existing']))
$baction = 'update';
$bcaption = LAN_UPDATE;
}
-
$text .= "
|
".LANG_LAN_07." |
@@ -281,17 +250,15 @@ if (isset($_POST['edit_existing']))
";
-
$ns->tablerender($_POST['lang_choices'], $emessage->render().$text);
}
-
-require_once(e_ADMIN."footer.php");
-
+require_once (e_ADMIN."footer.php");
// ---------------------------------------------------------------------------
+
+
function multilang_prefs()
{
- global $e107, $pref, $lanlist, $emessage;
-
+ global $pref,$lanlist,$emessage;
$text = "
-
- ";
-
- $text .= "
+ ";
+
+ $text .= "
";
-
- $e107->ns->tablerender(LANG_LAN_PAGE_TITLE.' - '.LANG_LAN_21, $emessage->render().$text);
+ e107::getRender()->tablerender(LANG_LAN_PAGE_TITLE.' - '.LANG_LAN_21, $emessage->render().$text);
}
-
-
// ----------------------------------------------------------------------------
+
function language_adminmenu()
{
global $action,$pref;
@@ -645,114 +545,103 @@ function language_adminmenu()
{
$action = "main";
}
-
- if($action == "modify")
+ if ($action == "modify")
{
- $action = "db";
+ $action = "db";
}
$var['main']['text'] = LAN_PREFS;
$var['main']['link'] = e_SELF;
-
- if(isset($pref['multilanguage']) && $pref['multilanguage'])
+ if (isset($pref['multilanguage']) && $pref['multilanguage'])
{
$var['db']['text'] = LANG_LAN_03;
$var['db']['link'] = e_SELF."?db";
}
-
- $lcnt = explode(",",e_LANLIST);
- if(count($lcnt) > 1)
+ $lcnt = explode(",", e_LANLIST);
+ if (count($lcnt) > 1)
{
$var['tools']['text'] = ADLAN_CL_6;
$var['tools']['link'] = e_SELF."?tools";
- }
-
+ }
e_admin_menu(ADLAN_132, $action, $var);
}
-
-
-
// Zip up the language pack.
-
// ===================================================
+
+
function zip_up_lang($language)
{
- if (is_readable(e_ADMIN."ver.php"))
+ if (is_readable(e_ADMIN."ver.php"))
{
- include(e_ADMIN."ver.php");
+ include (e_ADMIN."ver.php");
}
-/*
- $core_plugins = array(
- "alt_auth","banner_menu","blogcalendar_menu","calendar_menu","chatbox_menu",
- "clock_menu","comment_menu","content","featurebox","forum","gsitemap",
- "links_page","linkwords","list_new","log","login_menu",
- "newforumposts_main","newsfeed","newsletter","online",
- "other_news_menu","pdf","pm","poll","rss_menu",
- "search_menu","siteinfo_menu","trackback","tree_menu","user_menu","userlanguage_menu",
- "usertheme_menu"
- );
-
- $core_themes = array("crahan","e107v4a","human_condition","interfectus","jayya",
- "khatru","kubrick","lamb","leaf","newsroom","reline","sebes","vekna_blue");
-*/
-
- require_once(e_HANDLER.'pclzip.lib.php');
-
- list($ver,$tmp) = explode(" ",$e107info['e107_version']);
-
+ /*
+ $core_plugins = array(
+ "alt_auth","banner_menu","blogcalendar_menu","calendar_menu","chatbox_menu",
+ "clock_menu","comment_menu","content","featurebox","forum","gsitemap",
+ "links_page","linkwords","list_new","log","login_menu",
+ "newforumposts_main","newsfeed","newsletter","online",
+ "other_news_menu","pdf","pm","poll","rss_menu",
+ "search_menu","siteinfo_menu","trackback","tree_menu","user_menu","userlanguage_menu",
+ "usertheme_menu"
+ );
+ $core_themes = array("crahan","e107v4a","human_condition","interfectus","jayya",
+ "khatru","kubrick","lamb","leaf","newsroom","reline","sebes","vekna_blue");
+ */
+ require_once (e_HANDLER.'pclzip.lib.php');
+ list($ver, $tmp) = explode(" ", $e107info['e107_version']);
$newfile = e_UPLOAD."e107_".$ver."_".$language."_utf8.zip";
- $archive = new PclZip($newfile);
-
- $core = grab_lans(e_LANGUAGEDIR.$language."/",$language);
- $plugs = grab_lans(e_PLUGIN,$language);
- $theme = grab_lans(e_THEME,$language);
-
- $file = array_merge($core,$plugs,$theme);
- $data = implode(",",$file);
-
- if ($archive->create($data) == 0)
+ $archive = new PclZip($newfile);
+ $core = grab_lans(e_LANGUAGEDIR.$language."/", $language);
+ $plugs = grab_lans(e_PLUGIN, $language);
+ $theme = grab_lans(e_THEME, $language);
+ $file = array_merge($core, $plugs, $theme);
+ $data = implode(",", $file);
+ if ($archive->create($data) == 0)
{
- return $archive->errorInfo(true);
- }
+ return $archive->errorInfo(true);
+ }
else
{
- return LANG_LAN_22." (".str_replace("../","",e_UPLOAD)."".basename($newfile).").";
+ return LANG_LAN_22." (".str_replace("../", "", e_UPLOAD)."".basename($newfile).").";
}
-
-
}
-function grab_lans($path,$language,$filter = "")
+
+function grab_lans($path, $language, $filter = "")
{
- require_once(e_HANDLER."file_class.php");
- $fl = new e_file;
-
- if($lanlist = $fl->get_files($path,"", "standard",4)){
- sort($lanlist);
- }else{
- return;
+ $fl = e107::getFile();
+
+ if ($lanlist = $fl->get_files($path, "", "standard", 4))
+ {
+ sort($lanlist);
}
-
- $pzip = array();
- foreach($lanlist as $p)
+ else
+ {
+ return;
+ }
+ $pzip = array();
+ foreach ($lanlist as $p)
{
$fullpath = $p['path'].$p['fname'];
- if(strpos($fullpath,$language)!== FALSE)
- {
+ if (strpos($fullpath, $language) !== FALSE)
+ {
$pzip[] = $fullpath;
}
}
- return $pzip;
-
+ return $pzip;
}
-
/**
* Handle page DOM within the page header
*
* @return string JS source
*/
+
+
function headerjs()
{
- require_once(e_HANDLER.'js_helper.php');
+ //FIXME breaking functionality.
+ return;
+ require_once (e_HANDLER.'js_helper.php');
$ret = "
";
-
return $ret;
}
-?>
\ No newline at end of file
+?>
diff --git a/e107_handlers/mysql_class.php b/e107_handlers/mysql_class.php
index 0f6d8bd90..0e6cc374c 100644
--- a/e107_handlers/mysql_class.php
+++ b/e107_handlers/mysql_class.php
@@ -9,8 +9,8 @@
* mySQL Handler
*
* $Source: /cvs_backup/e107_0.8/e107_handlers/mysql_class.php,v $
- * $Revision: 1.45 $
- * $Date: 2009-09-05 12:48:28 $
+ * $Revision: 1.46 $
+ * $Date: 2009-09-05 18:58:56 $
* $Author: e107coders $
*/
@@ -61,7 +61,7 @@ $db_ConnectionID = NULL; // Stores ID for the first DB connection used - which s
* MySQL Abstraction class
*
* @package e107
-* @version $Revision: 1.45 $
+* @version $Revision: 1.46 $
* @author $Author: e107coders $
*/
class db {
@@ -81,7 +81,8 @@ class db {
var $mySQLlanguage;
var $mySQLinfo;
var $tabset;
- private $mySQLtableList = array();
+ private $mySQLtableList = array(); // list of all Db tables.
+ var $mySQLtableListLanguage = array(); // Db table list for the currently selected language
/**
* @public MySQL Charset
@@ -912,14 +913,15 @@ class db {
}
/**
- * @return unknown
- * @param unknown $table
- * @desc Enter description here...
+ * Check for the existence of a matching language table when multi-language tables are active.
+ * @param string $table Name of table, without the prefix.
* @access private
+ * @return name of the language table (eg. lan_french_news)
*/
function db_IsLang($table,$multiple=FALSE)
{
- global $pref, $mySQLtablelist;
+ global $pref;
+
if ((!$this->mySQLlanguage || !$pref['multilanguage']) && $multiple==FALSE)
{
return $table;
@@ -930,28 +932,20 @@ class db {
global $db_ConnectionID;
$this->mySQLaccess = $db_ConnectionID;
}
-
- if (!$mySQLtablelist)
- {
- $tablist = mysql_list_tables($this->mySQLdefaultdb,$this->mySQLaccess);
- while (list($temp) = mysql_fetch_array($tablist))
- {
- $mySQLtablelist[] = $temp;
- }
+
+ if($multiple == FALSE)
+ {
+ $mltable = "lan_".strtolower($this->mySQLlanguage.'_'.$table);
+ return ($this->db_Table_exists($table,$this->mySQLlanguage)) ? $mltable : $table;
}
-
- $mltable = "lan_".strtolower($this->mySQLlanguage.'_'.$table);
-
- // ---- Find all multi-language tables.
-
- if($multiple == TRUE)
- { // 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
+ {
if(!is_array($table))
{
$table = array($table);
}
- foreach($mySQLtablelist as $tab)
+ foreach($this->mySQLtablelist as $tab)
{
if(stristr($tab, $this->mySQLPrefix."lan_") !== FALSE)
{
@@ -966,15 +960,12 @@ class db {
}
}
}
+
return ($lanlist) ? $lanlist : FALSE;
}
// -------------------------
- if (in_array($this->mySQLPrefix.$mltable, $mySQLtablelist))
- {
- return $mltable;
- }
- return $table;
+
}
/**
@@ -1151,33 +1142,170 @@ class db {
* Verify whether a table exists, without causing an error
*
* @param string $table Table name without the prefix
- * @return boolean TRUE if exists, FALSE if it doesn't
+ * @param string $lanMode [optional] When set to TRUE, searches for multilanguage tables
+ * @return boolean TRUE if exists
*
* NOTES: Slower (28ms) than "SELECT 1 FROM" (4-5ms), but doesn't produce MySQL errors.
* Multiple checks on a single page will only use 1 query. ie. faster on multiple calls.
*/
- function db_Table_exists($table)
+ public function db_Table_exists($table,$language='')
{
- if(!$this->mySQLtableList)
+ global $pref;
+ $table = strtolower($table); // precaution for multilanguage
+
+ if($language && ($language != $pref['sitelanguage']))
{
- $res = $this->db_Query("SHOW TABLES LIKE '".$this->mySQLPrefix."%' "); // error if not there
- while($rows = $this->db_Fetch(MYSQL_BOTH))
+ if(!isset($this->mySQLtableListLanguage[$language]))
{
- $this->mySQLtableList[] = $rows[0];
- }
- }
-
- if(!in_array($this->mySQLPrefix.$table,$this->mySQLtableList))
- {
- return FALSE;
+ $this->mySQLtableListLanguage = $this->db_mySQLtableList($language);
+ }
+ return in_array('lan_'.strtolower($language)."_".$table,$this->mySQLtableListLanguage[$language]);
}
else
{
- return TRUE;
- }
+ if(!$this->mySQLtableList)
+ {
+ $this->mySQLtableList = $this->db_mySQLtableList();
+ }
+ return in_array($table,$this->mySQLtableList);
+ }
+
}
+ /**
+ * Populate $this->mySQLtableList;
+ * @return array
+ */
+ private function db_mySQLtableList($language='')
+ {
+ if($language)
+ {
+ if(!isset($this->mySQLtableListLanguage[$language]))
+ {
+ $table = array();
+ if($res = $this->db_Query("SHOW TABLES LIKE '".$this->mySQLPrefix."lan_".strtolower($language)."%' "))
+ {
+ while($rows = $this->db_Fetch(MYSQL_NUM))
+ {
+ $table[] = str_replace($this->mySQLPrefix,"",$rows[0]);
+ }
+ }
+ $ret = array($language=>$table);
+ return $ret;
+ }
+ else
+ {
+ return $this->mySQLtableListLanguage[$language];
+ }
+ }
+
+ if(!$this->mySQLtableList)
+ {
+ $table = array();
+ if($res = $this->db_Query("SHOW TABLES LIKE '".$this->mySQLPrefix."%' "))
+ {
+ while($rows = $this->db_Fetch(MYSQL_NUM))
+ {
+ $table[] = str_replace($this->mySQLPrefix,"",$rows[0]);
+ }
+ }
+ return $table;
+ }
+ else
+ {
+ return $this->mySQLtableList;
+ }
+ }
+
+ public function db_ResetTableList()
+ {
+ $this->mySQLtableList = array();
+ $this->mySQLtableListLanguage = array();
+ }
+
+ /**
+ * Return a filtered list of DB tables.
+ * @param object $mode [optional] all|lan|nolan
+ * @return array
+ */
+ public function db_TableList($mode='all')
+ {
+
+ if(!$this->mySQLtableList)
+ {
+ $this->mySQLtableList = $this->db_mySQLtableList();
+
+ }
+
+ if($mode == 'all')
+ {
+ return $this->mySQLtableList;
+ }
+
+ if($mode == 'lan' || $mode=='nolan')
+ {
+ $nolan = array();
+ $lan = array();
+
+ foreach($this->mySQLtableList as $tab)
+ {
+ if(substr($tab,0,4)!='lan_')
+ {
+ $nolan[] = $tab;
+ }
+ else
+ {
+ $lan[] = $tab;
+ }
+ }
+
+ return ($mode == 'lan') ? $lan : $nolan;
+ }
+
+ }
+
+ function db_CopyTable($oldtable, $newtable, $drop = FALSE, $data = FALSE)
+ {
+ $old = $this->mySQLPrefix.strtolower($oldtable);
+ $new = $this->mySQLPrefix.strtolower($newtable);
+
+ if ($drop)
+ {
+ $this->db_Select_gen("DROP TABLE IF EXISTS {$new}");
+ }
+
+ //Get $old table structure
+ $this->db_Select_gen('SET SQL_QUOTE_SHOW_CREATE = 1');
+
+ $qry = "SHOW CREATE TABLE {$old}";
+ if ($this->db_Select_gen($qry))
+ {
+ $row = $this->db_Fetch(MYSQL_NUM);
+ $qry = $row[1];
+ // $qry = str_replace($old, $new, $qry);
+ $qry = preg_replace("#CREATE\sTABLE\s`{0,1}".$old."`{0,1}\s#", "CREATE TABLE `{$new}` ", $qry, 1); // More selective search
+ }
+ else
+ {
+ return FALSE;
+ }
+
+ if(!$this->db_Table_exists($newtable))
+ {
+ $result = $this->db_Query($qry);
+ }
+
+ if ($data) //We need to copy the data too
+ {
+ $qry = "INSERT INTO {$new} SELECT * FROM {$old}";
+ $result = $this->db_Select_gen($qry);
+ }
+ return $result;
+ }
+
+
+
/**
* @return text string relating to error (empty string if no error)
* @param unknown $from