Merge pull request #17148 from indelog/fix_empty_website_otherlang

Fix empty string WEBSITE_OTHERLANG (better fix)
This commit is contained in:
Laurent Destailleur 2021-04-09 12:49:01 +02:00 committed by GitHub
commit 592800555f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 25 additions and 0 deletions

View File

@ -108,6 +108,8 @@ function dolSavePageAlias($filealias, $object, $objectpage)
$dirname = dirname($filealias);
$filename = basename($filealias);
foreach (explode(',', $object->otherlang) as $sublang) {
// Avoid to erase main alias file if $sublang is empty string
if (empty(trim($sublang))) continue;
$filealiassub = $dirname.'/'.$sublang.'/'.$filename;
$aliascontent = '<?php'."\n";

View File

@ -184,6 +184,11 @@ class Website extends CommonObject
$tmparray = explode(',', $this->otherlang);
if (is_array($tmparray)) {
foreach ($tmparray as $key => $val) {
// It possible we have empty val here if postparam WEBSITE_OTHERLANG is empty or set like this : 'en,,sv' or 'en,sv,'
if (empty(trim($val))) {
unset($tmparray[$key]);
continue;
}
$tmparray[$key] = preg_replace('/[_-].*$/', '', trim($val)); // en_US or en-US -> en
}
$this->otherlang = join(',', $tmparray);
@ -494,6 +499,11 @@ class Website extends CommonObject
$tmparray = explode(',', $this->otherlang);
if (is_array($tmparray)) {
foreach ($tmparray as $key => $val) {
// It possible we have empty val here if postparam WEBSITE_OTHERLANG is empty or set like this : 'en,,sv' or 'en,sv,'
if (empty(trim($val))) {
unset($tmparray[$key]);
continue;
}
$tmparray[$key] = preg_replace('/[_-].*$/', '', trim($val)); // en_US or en-US -> en
}
$this->otherlang = join(',', $tmparray);

View File

@ -551,6 +551,8 @@ if ($action == 'addsite')
{
$arrayotherlang = explode(',', GETPOST('WEBSITE_OTHERLANG', 'alphanohtml'));
foreach ($arrayotherlang as $key => $val) {
// It possible we have empty val here if postparam WEBSITE_OTHERLANG is empty or set like this : 'en,,sv' or 'en,sv,'
if (empty(trim($val))) continue;
$arrayotherlang[$key] = substr(trim($val), 0, 2); // Kept short language code only
}
@ -1327,6 +1329,8 @@ if ($action == 'updatecss')
{
$arrayotherlang = explode(',', GETPOST('WEBSITE_OTHERLANG', 'alphanohtml'));
foreach ($arrayotherlang as $key => $val) {
// It possible we have empty val here if postparam WEBSITE_OTHERLANG is empty or set like this : 'en,,sv' or 'en,sv,'
if (empty(trim($val))) continue;
$arrayotherlang[$key] = substr(trim($val), 0, 2); // Kept short language code only
}
@ -1768,6 +1772,10 @@ if ($action == 'updatemeta')
$filename = basename($fileoldalias);
$sublangs = explode(',', $object->otherlang);
foreach ($sublangs as $sublang) {
// Under certain conditions $sublang can be an empty string
// ($object->otherlang with empty string or with string like this 'en,,sv')
// if is the case we try to re-delete the main alias file. Avoid it.
if (empty(trim($sublang))) continue;
$fileoldaliassub = $dirname.'/'.$sublang.'/'.$filename;
dol_delete_file($fileoldaliassub);
}
@ -1790,6 +1798,10 @@ if ($action == 'updatemeta')
$filename = basename($pathofwebsite.'/'.trim($tmpaliasalt).'.php');
$sublangs = explode(',', $object->otherlang);
foreach ($sublangs as $sublang) {
// Under certain conditions $ sublang can be an empty string
// ($object->otherlang with empty string or with string like this 'en,,sv')
// if is the case we try to re-delete the main alias file. Avoid it.
if (empty(trim($sublang))) continue;
$fileoldaliassub = $dirname.'/'.$sublang.'/'.$filename;
dol_delete_file($fileoldaliassub);
}
@ -2710,6 +2722,7 @@ if (!GETPOST('hide_websitemenu'))
$onlylang[$website->lang] = $website->lang.' ('.$langs->trans("Default").')';
}
foreach (explode(',', $website->otherlang) as $langkey) {
if (empty(trim($langkey))) continue;
$onlylang[$langkey] = $langkey;
}
$textifempty = $langs->trans("Default");