Work on multilang
This commit is contained in:
parent
b0569de166
commit
45860b2494
@ -307,7 +307,7 @@ function includeContainer($containerref)
|
||||
{
|
||||
global $conf, $db, $hookmanager, $langs, $mysoc, $user, $website, $weblangs; // Very important. Required to have var available when running inluded containers.
|
||||
global $includehtmlcontentopened;
|
||||
global $websitekey;
|
||||
global $websitekey, $websitepagefile;
|
||||
|
||||
$MAXLEVEL=20;
|
||||
|
||||
@ -607,7 +607,7 @@ function dolSavePageContent($filetpl, $object, $objectpage)
|
||||
|
||||
$tplcontent ='';
|
||||
$tplcontent.= "<?php // BEGIN PHP\n";
|
||||
$tplcontent.= '$websitekey=basename(dirname(__FILE__));'."\n";
|
||||
$tplcontent.= '$websitekey=basename(dirname(__FILE__)); $websitepagefile=__FILE__;'."\n";
|
||||
$tplcontent.= "if (! defined('USEDOLIBARRSERVER') && ! defined('USEDOLIBARREDITOR')) { require_once './master.inc.php'; } // Not already loaded"."\n";
|
||||
$tplcontent.= "require_once DOL_DOCUMENT_ROOT.'/core/lib/website.lib.php';\n";
|
||||
$tplcontent.= "require_once DOL_DOCUMENT_ROOT.'/core/website.inc.php';\n";
|
||||
@ -672,7 +672,7 @@ function dolSaveIndexPage($pathofwebsite, $fileindex, $filetpl, $filewrapper)
|
||||
dol_delete_file($fileindex);
|
||||
$indexcontent = '<?php'."\n";
|
||||
$indexcontent.= "// BEGIN PHP File generated to provide an index.php as Home Page or alias redirector - DO NOT MODIFY - It is just a generated wrapper.\n";
|
||||
$indexcontent.= '$websitekey=basename(dirname(__FILE__));'."\n";
|
||||
$indexcontent.= '$websitekey=basename(dirname(__FILE__)); $websitepagefile=__FILE__;'."\n";
|
||||
$indexcontent.= "if (! defined('USEDOLIBARRSERVER') && ! defined('USEDOLIBARREDITOR')) { require_once './master.inc.php'; } // Load master if not already loaded\n";
|
||||
$indexcontent.= 'if (! empty($_GET[\'pageref\']) || ! empty($_GET[\'pagealiasalt\']) || ! empty($_GET[\'pageid\'])) {'."\n";
|
||||
$indexcontent.= " require_once DOL_DOCUMENT_ROOT.'/core/lib/website.lib.php';\n";
|
||||
|
||||
@ -33,33 +33,48 @@ if (! is_object($website))
|
||||
}
|
||||
if (! is_object($weblangs))
|
||||
{
|
||||
$weblangs = dol_clone($langs);
|
||||
$weblangs = dol_clone($langs); // TODO Use an object lang from a language set into $website object instead of backoffice
|
||||
}
|
||||
|
||||
// A lang was forced, so we change weblangs init
|
||||
if (GETPOST('l','aZ09')) $weblangs->setDefaultLang(GETPOST('l','aZ09'));
|
||||
// A lang was forced, so we check to find if we must make a redirect on translation page
|
||||
if (! defined('USEDOLIBARREDITOR'))
|
||||
if ($_SERVER['PHP_SELF'] != DOL_URL_ROOT.'/website/index.php') // If we browsing page using Dolibarr server or a Native web server
|
||||
{
|
||||
//print_r(get_defined_constants(true));exit;
|
||||
if (GETPOST('l','aZ09'))
|
||||
{
|
||||
$sql ="SELECT wp.rowid, wp.lang, wp.pageurl, wp.fk_page";
|
||||
$sql.=" FROM ".MAIN_DB_PREFIX."website_page as wp, ".MAIN_DB_PREFIX."website as w";
|
||||
$sql.=" WHERE w.rowid = wp.fk_website AND w.ref = '".$db->escape($websitekey)."' AND fk_page = '".$db->escape($pageid)."' AND lang = '".$db->escape(GETPOST('l','aZ09'))."'";
|
||||
$resql = $db->query($sql);
|
||||
if ($resql)
|
||||
if (! $pageid && ! empty($websitepagefile))
|
||||
{
|
||||
$obj = $db->fetch_object($resql);
|
||||
if ($obj)
|
||||
$pageid = str_replace(array('.tpl.php', 'page'), array('', ''), basename($websitepagefile));
|
||||
}
|
||||
if ($pageid > 0)
|
||||
{
|
||||
$sql ="SELECT wp.rowid, wp.lang, wp.pageurl, wp.fk_page";
|
||||
$sql.=" FROM ".MAIN_DB_PREFIX."website_page as wp, ".MAIN_DB_PREFIX."website as w";
|
||||
$sql.=" WHERE w.rowid = wp.fk_website AND w.ref = '".$db->escape($websitekey)."' AND wp.lang = '".$db->escape(GETPOST('l','aZ09'))."'";
|
||||
$sql.=" AND wp.fk_page = ".$db->escape($pageid);
|
||||
//var_dump($sql);exit;
|
||||
$resql = $db->query($sql);
|
||||
if ($resql)
|
||||
{
|
||||
//$pageid = $obj->rowid;
|
||||
//$pageref = $obj->pageurl;
|
||||
if (! defined('USEDOLIBARRSERVER')) {
|
||||
// TODO Redirect
|
||||
}
|
||||
else
|
||||
$obj = $db->fetch_object($resql);
|
||||
if ($obj)
|
||||
{
|
||||
// TODO Redirect
|
||||
$newpageid = $obj->rowid;
|
||||
if ($newpageid != $pageid) // To avoid to make a redirect on same page (infinite loop)
|
||||
{
|
||||
if (defined('USEDOLIBARRSERVER')) {
|
||||
header("Location: ".DOL_URL_ROOT.'/public/website/index.php?website='.$websitekey.'&pageid='.$newpageid.'.php&l='.GETPOST('l','aZ09'));
|
||||
exit;
|
||||
}
|
||||
else
|
||||
{
|
||||
$newpageref = $obj->pageurl;
|
||||
header("Location: ".$newpageref.'.php?l='.GETPOST('l','aZ09'));
|
||||
exit;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -1089,10 +1089,26 @@ class Website extends CommonObject
|
||||
*/
|
||||
public function componentSelectLang($languagecodes, $weblangs, $morecss='', $htmlname='')
|
||||
{
|
||||
global $websitepagefile;
|
||||
|
||||
if (! is_object($weblangs)) return 'ERROR componentSelectLang called with parameter $weblangs not defined';
|
||||
|
||||
$languagecodeselected = $weblangs->defaultlang;
|
||||
$languagecodeselected= $weblangs->defaultlang; // Becasue we must init with a value, but real value is the lang of main parent container
|
||||
if (! empty($websitepagefile))
|
||||
{
|
||||
$pageid = str_replace(array('.tpl.php', 'page'), array('', ''), basename($websitepagefile));
|
||||
if ($pageid > 0)
|
||||
{
|
||||
$tmppage=new WebsitePage($this->db);
|
||||
$tmppage->fetch($pageid);
|
||||
|
||||
$languagecodeselected=$tmppage->lang;
|
||||
$languagecodes[]=$tmppage->lang; // We add language code of page into combo list
|
||||
}
|
||||
}
|
||||
|
||||
$weblangs->load('languages');
|
||||
//var_dump($weblangs->defaultlang);
|
||||
|
||||
$url = $_SERVER["REQUEST_URI"];
|
||||
$url = preg_replace('/(\?|&)l=([a-zA-Z_]*)/', '', $url); // We remove param l from url
|
||||
|
||||
Loading…
Reference in New Issue
Block a user