Work on multilang
This commit is contained in:
parent
45860b2494
commit
ac143b28ae
@ -607,7 +607,7 @@ function dolSavePageContent($filetpl, $object, $objectpage)
|
|||||||
|
|
||||||
$tplcontent ='';
|
$tplcontent ='';
|
||||||
$tplcontent.= "<?php // BEGIN PHP\n";
|
$tplcontent.= "<?php // BEGIN PHP\n";
|
||||||
$tplcontent.= '$websitekey=basename(dirname(__FILE__)); $websitepagefile=__FILE__;'."\n";
|
$tplcontent.= '$websitekey=basename(dirname(__FILE__)); if (empty($websitepagefile)) $websitepagefile=__FILE__;'."\n";
|
||||||
$tplcontent.= "if (! defined('USEDOLIBARRSERVER') && ! defined('USEDOLIBARREDITOR')) { require_once './master.inc.php'; } // Not already loaded"."\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/lib/website.lib.php';\n";
|
||||||
$tplcontent.= "require_once DOL_DOCUMENT_ROOT.'/core/website.inc.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);
|
dol_delete_file($fileindex);
|
||||||
$indexcontent = '<?php'."\n";
|
$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.= "// 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__)); $websitepagefile=__FILE__;'."\n";
|
$indexcontent.= '$websitekey=basename(dirname(__FILE__)); if (empty($websitepagefile)) $websitepagefile=__FILE__;'."\n";
|
||||||
$indexcontent.= "if (! defined('USEDOLIBARRSERVER') && ! defined('USEDOLIBARREDITOR')) { require_once './master.inc.php'; } // Load master if not already loaded\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.= 'if (! empty($_GET[\'pageref\']) || ! empty($_GET[\'pagealiasalt\']) || ! empty($_GET[\'pageid\'])) {'."\n";
|
||||||
$indexcontent.= " require_once DOL_DOCUMENT_ROOT.'/core/lib/website.lib.php';\n";
|
$indexcontent.= " require_once DOL_DOCUMENT_ROOT.'/core/lib/website.lib.php';\n";
|
||||||
|
|||||||
@ -1079,31 +1079,67 @@ class Website extends CommonObject
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Component to select language (Full CSS Only)
|
* Component to select language inside a container (Full CSS Only)
|
||||||
*
|
*
|
||||||
* @param array $languagecodes Language codes array. Example: array('en_US','fr_FR','de_DE','es_ES')
|
* @param array|string $languagecodes 'auto' to show all languages available for page or language codes array like array('en_US','fr_FR','de_DE','es_ES')
|
||||||
* @param Translate $weblangs Language Object
|
* @param Translate $weblangs Language Object
|
||||||
* @param string $morecss More CSS class on component
|
* @param string $morecss More CSS class on component
|
||||||
* @param string $htmlname Suffix for HTML name
|
* @param string $htmlname Suffix for HTML name
|
||||||
* @return string HTML select component
|
* @return string HTML select component
|
||||||
*/
|
*/
|
||||||
public function componentSelectLang($languagecodes, $weblangs, $morecss='', $htmlname='')
|
public function componentSelectLang($languagecodes, $weblangs, $morecss='', $htmlname='')
|
||||||
{
|
{
|
||||||
global $websitepagefile;
|
global $websitepagefile, $website;
|
||||||
|
|
||||||
if (! is_object($weblangs)) return 'ERROR componentSelectLang called with parameter $weblangs not defined';
|
if (! is_object($weblangs)) return 'ERROR componentSelectLang called with parameter $weblangs not defined';
|
||||||
|
|
||||||
$languagecodeselected= $weblangs->defaultlang; // Becasue we must init with a value, but real value is the lang of main parent container
|
// Load tmppage if we have $websitepagefile defined
|
||||||
|
$tmppage=new WebsitePage($this->db);
|
||||||
|
|
||||||
|
$pageid = 0;
|
||||||
if (! empty($websitepagefile))
|
if (! empty($websitepagefile))
|
||||||
{
|
{
|
||||||
$pageid = str_replace(array('.tpl.php', 'page'), array('', ''), basename($websitepagefile));
|
$pageid = str_replace(array('.tpl.php', 'page'), array('', ''), basename($websitepagefile));
|
||||||
if ($pageid > 0)
|
if ($pageid > 0)
|
||||||
{
|
{
|
||||||
$tmppage=new WebsitePage($this->db);
|
|
||||||
$tmppage->fetch($pageid);
|
$tmppage->fetch($pageid);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Fill with existing translation, nothing if none
|
||||||
|
if (! is_array($languagecodes) && $pageid > 0)
|
||||||
|
{
|
||||||
|
$languagecodes = array();
|
||||||
|
|
||||||
|
$sql ="SELECT wp.rowid, wp.lang, wp.pageurl, wp.fk_page";
|
||||||
|
$sql.=" FROM ".MAIN_DB_PREFIX."website_page as wp";
|
||||||
|
$sql.=" WHERE wp.fk_website = ".$website->id;
|
||||||
|
$sql.=" AND (wp.fk_page = ".$pageid." OR wp.rowid = ".$pageid;
|
||||||
|
if ($tmppage->fk_page > 0) $sql.=" OR wp.fk_page = ".$tmppage->fk_page." OR wp.rowid = ".$tmppage->fk_page;
|
||||||
|
$sql.=")";
|
||||||
|
|
||||||
|
$resql = $this->db->query($sql);
|
||||||
|
if ($resql)
|
||||||
|
{
|
||||||
|
while ($obj = $this->db->fetch_object($resql))
|
||||||
|
{
|
||||||
|
$newlang = $obj->lang;
|
||||||
|
if ($obj->rowid == $pageid) $newlang = $obj->lang;
|
||||||
|
if (! in_array($newlang, $languagecodes)) $languagecodes[]=$newlang;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
// Now $languagecodes is always an array
|
||||||
|
|
||||||
|
$languagecodeselected= $weblangs->defaultlang; // Because 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)
|
||||||
|
{
|
||||||
|
|
||||||
$languagecodeselected=$tmppage->lang;
|
$languagecodeselected=$tmppage->lang;
|
||||||
$languagecodes[]=$tmppage->lang; // We add language code of page into combo list
|
if (! in_array($tmppage->lang, $languagecodes)) $languagecodes[]=$tmppage->lang; // We add language code of page into combo list
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user