forked from Wavyzz/dolibarr
Enhance multilangue support in website module
This commit is contained in:
@@ -170,6 +170,15 @@ class Website extends CommonObject
|
||||
if (empty($this->date_modification)) {
|
||||
$this->date_modification = $now;
|
||||
}
|
||||
// Remove spaces and be sure we have main language only
|
||||
$this->lang = preg_replace('/[_-].*$/', '', trim($this->lang)); // en_US or en-US -> en
|
||||
$tmparray = explode(',', $this->otherlang);
|
||||
if (is_array($tmparray)) {
|
||||
foreach($tmparray as $key => $val) {
|
||||
$tmparray[$key] = preg_replace('/[_-].*$/', '', trim($val)); // en_US or en-US -> en
|
||||
}
|
||||
$this->otherlang = join(',', $tmparray);
|
||||
}
|
||||
|
||||
// Check parameters
|
||||
if (empty($this->entity)) {
|
||||
@@ -456,6 +465,16 @@ class Website extends CommonObject
|
||||
$this->status = (int) $this->status;
|
||||
}
|
||||
|
||||
// Remove spaces and be sure we have main language only
|
||||
$this->lang = preg_replace('/[_-].*$/', '', trim($this->lang)); // en_US or en-US -> en
|
||||
$tmparray = explode(',', $this->otherlang);
|
||||
if (is_array($tmparray)) {
|
||||
foreach($tmparray as $key => $val) {
|
||||
$tmparray[$key] = preg_replace('/[_-].*$/', '', trim($val)); // en_US or en-US -> en
|
||||
}
|
||||
$this->otherlang = join(',', $tmparray);
|
||||
}
|
||||
|
||||
// Check parameters
|
||||
// Put here code to add a control on parameters values
|
||||
|
||||
@@ -837,7 +856,7 @@ class Website extends CommonObject
|
||||
$this->ref = 'myspecimenwebsite';
|
||||
$this->description = 'A specimen website';
|
||||
$this->lang = 'en';
|
||||
$this->otherlang = 'fr,es_MX';
|
||||
$this->otherlang = 'fr,es';
|
||||
$this->status = '';
|
||||
$this->fk_default_home = null;
|
||||
$this->virtualhost = 'http://myvirtualhost';
|
||||
@@ -1178,7 +1197,11 @@ class Website extends CommonObject
|
||||
|
||||
// The move is not enough, so we regenerate page
|
||||
$filetpl = $conf->website->dir_output.'/'.$object->ref.'/page'.$newid.'.tpl.php';
|
||||
dolSavePageContent($filetpl, $object, $objectpagestatic);
|
||||
$result = dolSavePageContent($filetpl, $object, $objectpagestatic);
|
||||
if (!$result) {
|
||||
$this->errors[] = 'Failed to write file '.basename($filetpl);
|
||||
$error++;
|
||||
}
|
||||
|
||||
// Regenerate alternative aliases pages
|
||||
if (is_array($aliasesarray))
|
||||
@@ -1188,7 +1211,11 @@ class Website extends CommonObject
|
||||
if (trim($aliasshortcuttocreate))
|
||||
{
|
||||
$filealias = $conf->website->dir_output.'/'.$object->ref.'/'.trim($aliasshortcuttocreate).'.php';
|
||||
dolSavePageAlias($filealias, $object, $objectpagestatic);
|
||||
$result = dolSavePageAlias($filealias, $object, $objectpagestatic);
|
||||
if (!$result) {
|
||||
$this->errors[] = 'Failed to write file '.basename($filealias);
|
||||
$error++;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -158,6 +158,9 @@ class WebsitePage extends CommonObject
|
||||
$this->keywords = dol_trunc($this->keywords, 255, 'right', 'utf-8', 1);
|
||||
if ($this->aliasalt) $this->aliasalt = ','.preg_replace('/,+$/', '', preg_replace('/^,+/', '', $this->aliasalt)).','; // content in database must be ',xxx,...,yyy,'
|
||||
|
||||
// Remove spaces and be sure we have main language only
|
||||
$this->lang = preg_replace('/[_-].*$/', '', trim($this->lang)); // en_US or en-US -> en
|
||||
|
||||
return $this->createCommon($user, $notrigger);
|
||||
}
|
||||
|
||||
@@ -377,6 +380,22 @@ class WebsitePage extends CommonObject
|
||||
$this->keywords = dol_trunc($this->keywords, 255, 'right', 'utf-8', 1);
|
||||
if ($this->aliasalt) $this->aliasalt = ','.preg_replace('/,+$/', '', preg_replace('/^,+/', '', $this->aliasalt)).','; // content in database must be ',xxx,...,yyy,'
|
||||
|
||||
// Remove spaces and be sure we have main language only
|
||||
$this->lang = preg_replace('/[_-].*$/', '', trim($this->lang)); // en_US or en-US -> en
|
||||
|
||||
if ($this->fk_page > 0) {
|
||||
if (empty($this->lang)) {
|
||||
$this->error = "ErrorLanguageMandatoryIfPageSetAsTranslationOfAnother";
|
||||
return -1;
|
||||
}
|
||||
$tmppage = new WebsitePage($this->db);
|
||||
$tmppage->fetch($this->fk_page);
|
||||
if ($tmppage->lang == $this->lang) {
|
||||
$this->error = "ErrorLanguageOfTranslatedPageIsSameThanThisPage";
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
|
||||
return $this->updateCommon($user, $notrigger);
|
||||
}
|
||||
|
||||
@@ -513,7 +532,8 @@ class WebsitePage extends CommonObject
|
||||
$label .= '<br>';
|
||||
$label .= '<b>'.$langs->trans('Ref').':</b> '.$this->ref.'<br>';
|
||||
$label .= '<b>'.$langs->trans('ID').':</b> '.$this->id.'<br>';
|
||||
$label .= '<b>'.$langs->trans('Title').':</b> '.$this->title;
|
||||
$label .= '<b>'.$langs->trans('Title').':</b> '.$this->title.'<br>';
|
||||
$label .= '<b>'.$langs->trans('Language').':</b> '.$this->lang;
|
||||
|
||||
$url = DOL_URL_ROOT.'/website/index.php?websiteid='.$this->fk_website.'&pageid='.$this->id;
|
||||
|
||||
|
||||
@@ -860,7 +860,7 @@ if ($action == 'addcontainer')
|
||||
$result = dolSavePageAlias($filealias, $object, $objectpage);
|
||||
if (!$result)
|
||||
{
|
||||
setEventMessages('Failed to write file '.$filealias, null, 'errors');
|
||||
setEventMessages('Failed to write file '.basename($filealias), null, 'errors');
|
||||
}
|
||||
|
||||
// Save page of content
|
||||
@@ -1499,8 +1499,9 @@ if ($action == 'updatemeta')
|
||||
{
|
||||
if (trim($tmpaliasalt))
|
||||
{
|
||||
$result = dolSavePageAlias($pathofwebsite.'/'.trim($tmpaliasalt).'.php', $object, $objectpage);
|
||||
if (!$result) setEventMessages('Failed to write file '.$pathofwebsite.'/'.trim($tmpaliasalt).'.php', null, 'errors');
|
||||
$filealias = $pathofwebsite.'/'.trim($tmpaliasalt).'.php';
|
||||
$result = dolSavePageAlias($filealias, $object, $objectpage);
|
||||
if (!$result) setEventMessages('Failed to write file '.basename($filealias), null, 'errors');
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1756,7 +1757,7 @@ if (($action == 'updatesource' || $action == 'updatecontent' || $action == 'conf
|
||||
|
||||
// Save page alias
|
||||
$result = dolSavePageAlias($filealias, $object, $objectpage);
|
||||
if (!$result) setEventMessages('Failed to write file '.$filealias, null, 'errors');
|
||||
if (!$result) setEventMessages('Failed to write file '.basename($filealias), null, 'errors');
|
||||
|
||||
// Save page content
|
||||
$result = dolSavePageContent($filetpl, $object, $objectpage);
|
||||
@@ -2702,7 +2703,7 @@ if ($action == 'editcss')
|
||||
$htmltext='';
|
||||
print $form->textwithpicto($langs->trans('MainLanguage'), $htmltext, 1, 'help', '', 0, 2, 'WEBSITE_LANG');
|
||||
print '</td><td>';
|
||||
print $formadmin->select_language((GETPOSTISSET('WEBSITE_LANG') ? GETPOST('WEBSITE_LANG', 'aZ09comma') : ($object->lang ? $object->lang : '0')), 'WEBSITE_LANG', 0, null, 1, 0, 0, 'minwidth300', 2);
|
||||
print $formadmin->select_language((GETPOSTISSET('WEBSITE_LANG') ? GETPOST('WEBSITE_LANG', 'aZ09comma') : ($object->lang ? $object->lang : '0')), 'WEBSITE_LANG', 0, null, 1, 0, 0, 'minwidth300', 2, 0, 0, array(), 1);
|
||||
print '</td>';
|
||||
print '</tr>';
|
||||
|
||||
@@ -2861,7 +2862,7 @@ if ($action == 'createsite')
|
||||
print '<tr><td>';
|
||||
print $langs->trans('MainLanguage');
|
||||
print '</td><td>';
|
||||
print $formadmin->select_language((GETPOSTISSET('WEBSITE_LANG') ? GETPOST('WEBSITE_LANG', 'aZ09comma') : '0'), 'WEBSITE_LANG', 0, null, 1, 0, 0, 'minwidth300', 2);
|
||||
print $formadmin->select_language((GETPOSTISSET('WEBSITE_LANG') ? GETPOST('WEBSITE_LANG', 'aZ09comma') : '0'), 'WEBSITE_LANG', 0, null, 1, 0, 0, 'minwidth300', 2, 0, 0, array(), 1);
|
||||
print '</td></tr>';
|
||||
|
||||
print '<tr><td>';
|
||||
@@ -3104,7 +3105,7 @@ if ($action == 'editmeta' || $action == 'createcontainer')
|
||||
foreach($tmparray as $key) {
|
||||
$tmpkey = trim($key);
|
||||
if (strlen($key) == 2) {
|
||||
$tmpkey = strtolower($key).'_'.strtoupper($tmpkey);
|
||||
$tmpkey = strtolower($key);
|
||||
}
|
||||
$onlykeys[$tmpkey] = $tmpkey;
|
||||
}
|
||||
@@ -3112,7 +3113,7 @@ if ($action == 'editmeta' || $action == 'createcontainer')
|
||||
if (empty($object->lang) && empty($object->otherlang)) {
|
||||
$onlykeys = null; // We keep full list of languages
|
||||
}
|
||||
print $formadmin->select_language($pagelang ? $pagelang : '', 'WEBSITE_LANG', 0, null, '1', 0, 0, 'minwidth200', 0, 0, 0, $onlykeys);
|
||||
print $formadmin->select_language($pagelang ? $pagelang : '', 'WEBSITE_LANG', 0, null, '1', 0, 0, 'minwidth200', 0, 0, 0, $onlykeys, 1);
|
||||
$htmltext = $langs->trans("AvailableLanguagesAreDefinedIntoWebsiteProperties");
|
||||
print $form->textwithpicto('', $htmltext);
|
||||
print '</td></tr>';
|
||||
|
||||
Reference in New Issue
Block a user