Merge pull request #15187 from frederic34/patch-6

Make MAIN_ALL_TO_UPPER utf8 compliant
This commit is contained in:
Laurent Destailleur 2020-10-28 17:17:18 +01:00 committed by GitHub
commit 4cf32824bf
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 66 additions and 25 deletions

View File

@ -589,8 +589,9 @@ class Adherent extends CommonObject
$this->town = ($this->town ? $this->town : $this->town);
$this->country_id = ($this->country_id > 0 ? $this->country_id : $this->country_id);
$this->state_id = ($this->state_id > 0 ? $this->state_id : $this->state_id);
if (!empty($conf->global->MAIN_FIRST_TO_UPPER)) $this->lastname = ucwords(trim($this->lastname));
if (!empty($conf->global->MAIN_FIRST_TO_UPPER)) $this->firstname = ucwords(trim($this->firstname));
if (!empty($conf->global->MAIN_FIRST_TO_UPPER)) $this->lastname = dol_ucwords(dol_strtolower($this->lastname));
if (!empty($conf->global->MAIN_ALL_TO_UPPER)) $this->lastname = dol_strtoupper($this->lastname);
if (!empty($conf->global->MAIN_FIRST_TO_UPPER)) $this->firstname = dol_ucwords(dol_strtolower($this->firstname));
$this->note_public = ($this->note_public ? $this->note_public : $this->note_public);
$this->note_private = ($this->note_private ? $this->note_private : $this->note_private);

View File

@ -353,9 +353,9 @@ class Contact extends CommonObject
// Clean parameters
$this->lastname = $this->lastname ?trim($this->lastname) : trim($this->name);
$this->firstname = trim($this->firstname);
if (!empty($conf->global->MAIN_FIRST_TO_UPPER)) $this->lastname = ucwords(strtolower($this->lastname));
if (!empty($conf->global->MAIN_ALL_TO_UPPER)) $this->lastname = strtoupper($this->lastname);
if (!empty($conf->global->MAIN_FIRST_TO_UPPER)) $this->firstname = ucwords(strtolower($this->firstname));
if (!empty($conf->global->MAIN_FIRST_TO_UPPER)) $this->lastname = dol_ucwords(dol_strtolower($this->lastname));
if (!empty($conf->global->MAIN_ALL_TO_UPPER)) $this->lastname = dol_strtoupper($this->lastname);
if (!empty($conf->global->MAIN_FIRST_TO_UPPER)) $this->firstname = dol_ucwords(dol_strtolower($this->firstname));
if (empty($this->socid)) $this->socid = 0;
if (empty($this->priv)) $this->priv = 0;
if (empty($this->statut)) $this->statut = 0; // This is to convert '' into '0' to avoid bad sql request
@ -464,9 +464,9 @@ class Contact extends CommonObject
$this->entity = ((isset($this->entity) && is_numeric($this->entity)) ? $this->entity : $conf->entity);
// Clean parameters
if (!empty($conf->global->MAIN_FIRST_TO_UPPER)) $this->lastname = ucwords(strtolower($this->lastname));
if (!empty($conf->global->MAIN_ALL_TO_UPPER)) $this->lastname = strtoupper($this->lastname);
if (!empty($conf->global->MAIN_FIRST_TO_UPPER)) $this->firstname = ucwords(strtolower($this->firstname));
if (!empty($conf->global->MAIN_FIRST_TO_UPPER)) $this->lastname = dol_ucwords(dol_strtolower($this->lastname));
if (!empty($conf->global->MAIN_ALL_TO_UPPER)) $this->lastname = dol_strtoupper($this->lastname);
if (!empty($conf->global->MAIN_FIRST_TO_UPPER)) $this->firstname = dol_ucwords(dol_strtolower($this->firstname));
$this->lastname = trim($this->lastname) ?trim($this->lastname) : trim($this->lastname);
$this->firstname = trim($this->firstname);

View File

@ -1086,29 +1086,69 @@ function dol_escape_htmltag($stringtoescape, $keepb = 0, $keepn = 0, $keepmoreta
}
}
/**
* Convert a string to lower. Never use strtolower because it does not works with UTF8 strings.
*
* @param string $utf8_string String to encode
* @param string $string String to encode
* @param string $encoding Character set encoding
* @return string String converted
*/
function dol_strtolower($utf8_string)
function dol_strtolower($string, $encoding = "UTF-8")
{
return mb_strtolower($utf8_string, "UTF-8");
if (function_exists('mb_strtolower')) {
return mb_strtolower($string, $encoding);
} else {
return strtolower($string);
}
}
/**
* Convert a string to upper. Never use strtolower because it does not works with UTF8 strings.
*
* @param string $utf8_string String to encode
* @param string $string String to encode
* @param string $encoding Character set encoding
* @return string String converted
*/
function dol_strtoupper($utf8_string)
function dol_strtoupper($string, $encoding = "UTF-8")
{
return mb_strtoupper($utf8_string, "UTF-8");
if (function_exists('mb_strtoupper')) {
return mb_strtoupper($string, $encoding);
} else {
return strtoupper($string);
}
}
/**
* Convert first character of the first word of a string to upper. Never use ucfirst because it does not works with UTF8 strings.
*
* @param string $string String to encode
* @param string $encoding Character set encodign
* @return string String converted
*/
function dol_ucfirst($string, $encoding = "UTF-8")
{
if (function_exists('mb_substr')) {
return mb_strtoupper(mb_substr($string, 0, 1, $encoding), $encoding) . mb_substr($string, 1, null, $encoding);
} else {
return ucfirst($string);
}
}
/**
* Convert first character of all the words of a string to upper. Never use ucfirst because it does not works with UTF8 strings.
*
* @param string $string String to encode
* @param string $encoding Character set encodign
* @return string String converted
*/
function dol_ucwords($string, $encoding = "UTF-8")
{
if (function_exists('mb_convert_case')) {
return mb_convert_case($string, MB_CASE_TITLE, $encoding);
} else {
return ucwords($string);
}
}
/**
* Write log message into outputs. Possible outputs can be:

View File

@ -789,8 +789,8 @@ class Societe extends CommonObject
// Clean parameters
if (empty($this->status)) $this->status = 0;
$this->name = $this->name ?trim($this->name) : trim($this->nom);
if (!empty($conf->global->MAIN_FIRST_TO_UPPER)) $this->name = ucwords($this->name);
if (!empty($conf->global->MAIN_ALL_TO_UPPER)) $this->name = strtoupper($this->name);
if (!empty($conf->global->MAIN_FIRST_TO_UPPER)) $this->name = dol_ucwords(dol_strtolower($this->name));
if (!empty($conf->global->MAIN_ALL_TO_UPPER)) $this->name = dol_strtoupper($this->name);
$this->nom = $this->name; // For backward compatibility
if (empty($this->client)) $this->client = 0;
if (empty($this->fournisseur)) $this->fournisseur = 0;
@ -1094,8 +1094,8 @@ class Societe extends CommonObject
$now = dol_now();
if (!empty($conf->global->MAIN_FIRST_TO_UPPER)) $this->name = ucwords($this->name);
if (!empty($conf->global->MAIN_ALL_TO_UPPER)) $this->name = strtoupper($this->name);
if (!empty($conf->global->MAIN_FIRST_TO_UPPER)) $this->name = dol_ucwords(dol_strtolower($this->name));
if (!empty($conf->global->MAIN_ALL_TO_UPPER)) $this->name = dol_strtoupper($this->name);
// Clean parameters
$this->id = $id;
$this->entity = ((isset($this->entity) && is_numeric($this->entity)) ? $this->entity : $conf->entity);

View File

@ -1123,9 +1123,9 @@ class User extends CommonObject
// Clean parameters
if (!empty($conf->global->MAIN_FIRST_TO_UPPER)) $this->lastname = ucwords($this->lastname);
if (!empty($conf->global->MAIN_ALL_TO_UPPER)) $this->lastname = strtoupper($this->lastname);
if (!empty($conf->global->MAIN_FIRST_TO_UPPER)) $this->firstname = ucwords($this->firstname);
if (!empty($conf->global->MAIN_FIRST_TO_UPPER)) $this->lastname = dol_ucwords(dol_strtolower($this->lastname));
if (!empty($conf->global->MAIN_ALL_TO_UPPER)) $this->lastname = dol_strtoupper($this->lastname);
if (!empty($conf->global->MAIN_FIRST_TO_UPPER)) $this->firstname = dol_ucwords(dol_strtolower($this->firstname));
$this->login = trim($this->login);
if (!isset($this->entity)) $this->entity = $conf->entity; // If not defined, we use default value
@ -1468,9 +1468,9 @@ class User extends CommonObject
// Clean parameters
if (!empty($conf->global->MAIN_FIRST_TO_UPPER)) $this->lastname = ucwords($this->lastname);
if (!empty($conf->global->MAIN_ALL_TO_UPPER)) $this->lastname = strtoupper($this->lastname);
if (!empty($conf->global->MAIN_FIRST_TO_UPPER)) $this->firstname = ucwords($this->firstname);
if (!empty($conf->global->MAIN_FIRST_TO_UPPER)) $this->lastname = dol_ucwords(dol_strtolower($this->lastname));
if (!empty($conf->global->MAIN_ALL_TO_UPPER)) $this->lastname = dol_strtoupper($this->lastname);
if (!empty($conf->global->MAIN_FIRST_TO_UPPER)) $this->firstname = dol_ucwords(dol_strtolower($this->firstname));
$this->lastname = trim($this->lastname);
$this->firstname = trim($this->firstname);