Rename function to make code cleaner
This commit is contained in:
parent
dbae510665
commit
59faec9b4e
@ -84,7 +84,7 @@ if ($_POST["action"] == 'update' && ! $_POST["cancel"])
|
|||||||
$account = new Account($db, $_POST["id"]);
|
$account = new Account($db, $_POST["id"]);
|
||||||
$account->fetch($_POST["id"]);
|
$account->fetch($_POST["id"]);
|
||||||
|
|
||||||
$account->ref = sanitize_string(trim($_POST["ref"]));
|
$account->ref = dol_string_nospecial(trim($_POST["ref"]));
|
||||||
$account->label = trim($_POST["label"]);
|
$account->label = trim($_POST["label"]);
|
||||||
$account->courant = $_POST["type"];
|
$account->courant = $_POST["type"];
|
||||||
$account->clos = $_POST["clos"];
|
$account->clos = $_POST["clos"];
|
||||||
|
|||||||
@ -37,9 +37,9 @@ if (! defined('ADODB_DATE_VERSION')) include_once(DOL_DOCUMENT_ROOT."/includes/a
|
|||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
\brief Renvoi vrai si l'email est syntaxiquement valide
|
* \brief Renvoi vrai si l'email est syntaxiquement valide
|
||||||
\param address adresse email (Ex: "toto@titi.com", "John Do <johndo@titi.com>")
|
* \param address adresse email (Ex: "toto@titi.com", "John Do <johndo@titi.com>")
|
||||||
\return boolean true si email valide, false sinon
|
* \return boolean true si email valide, false sinon
|
||||||
*/
|
*/
|
||||||
function ValidEmail($address)
|
function ValidEmail($address)
|
||||||
{
|
{
|
||||||
@ -57,11 +57,11 @@ function ValidEmail($address)
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
\brief Renvoi vrai si l'email a un nom de domaine qui r<EFBFBD>soud via dns
|
* \brief Renvoi vrai si l'email a un nom de domaine qui r<EFBFBD>soud via dns
|
||||||
\param mail adresse email (Ex: "toto@titi.com", "John Do <johndo@titi.com>")
|
* \param mail adresse email (Ex: "toto@titi.com", "John Do <johndo@titi.com>")
|
||||||
\return boolean true si email valide, false sinon
|
* \return boolean true si email valide, false sinon
|
||||||
*/
|
*/
|
||||||
function check_mail ($mail)
|
function check_mail($mail)
|
||||||
{
|
{
|
||||||
list($user, $domain) = split("@", $mail, 2);
|
list($user, $domain) = split("@", $mail, 2);
|
||||||
if (checkdnsrr($domain, "MX"))
|
if (checkdnsrr($domain, "MX"))
|
||||||
@ -75,15 +75,25 @@ function check_mail ($mail)
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
\brief Nettoie chaine de caractere des accents
|
* \brief Clean a string to use it as a file name.
|
||||||
\param str Chaine a nettoyer
|
* \param str String to clean
|
||||||
\return string Chaine nettoyee
|
* \param newstr String to replace bad chars by
|
||||||
|
* \return string String cleaned (a-zA-Z_)
|
||||||
*/
|
*/
|
||||||
function unaccent_isostring($str)
|
function sanitizeFileName($str,$newstr='_')
|
||||||
|
{
|
||||||
|
return dol_string_nospecial(dol_string_unaccent($str),$newstr);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* \brief Clean a string from all accent characters
|
||||||
|
* \param str String to clean
|
||||||
|
* \return string Cleaned string
|
||||||
|
*/
|
||||||
|
function dol_string_unaccent($str)
|
||||||
{
|
{
|
||||||
if (utf8_check($str))
|
if (utf8_check($str))
|
||||||
{
|
{
|
||||||
// TODO add utf8 convertion
|
|
||||||
$translationutf=array( );
|
$translationutf=array( );
|
||||||
return str_replace(array_keys($translationutf), array_values($translationutf), $str);
|
return str_replace(array_keys($translationutf), array_values($translationutf), $str);
|
||||||
}
|
}
|
||||||
@ -98,13 +108,12 @@ function unaccent_isostring($str)
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* \brief Nettoie chaine de caractere de ces caracteres speciaux
|
* \brief Clean a string from all punctuation characters
|
||||||
* \remarks Fonction appelee par exemple pour definir un nom de fichier depuis un identifiant chaine libre
|
|
||||||
* \param str String to clean
|
* \param str String to clean
|
||||||
* \param newstr String to replace bad chars by
|
* \param newstr String to replace bad chars by
|
||||||
* \return string String cleaned (a-zA-Z_)
|
* \return string Cleaned string
|
||||||
*/
|
*/
|
||||||
function sanitize_string($str,$newstr='_')
|
function dol_string_nospecial($str,$newstr='_')
|
||||||
{
|
{
|
||||||
$forbidden_chars_to_underscore=array(" ","'","/","\\",":","*","?","\"","<",">","|","[","]",",",";","=");
|
$forbidden_chars_to_underscore=array(" ","'","/","\\",":","*","?","\"","<",">","|","[","]",",",";","=");
|
||||||
//$forbidden_chars_to_remove=array("(",")");
|
//$forbidden_chars_to_remove=array("(",")");
|
||||||
@ -113,18 +122,6 @@ function sanitize_string($str,$newstr='_')
|
|||||||
return str_replace($forbidden_chars_to_underscore,$newstr,str_replace($forbidden_chars_to_remove,"",$str));
|
return str_replace($forbidden_chars_to_underscore,$newstr,str_replace($forbidden_chars_to_remove,"",$str));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* \brief Nettoie chaine de caractere de ces caracteres speciaux
|
|
||||||
* \remarks Fonction appelee par exemple pour definir un nom de fichier depuis un identifiant chaine libre
|
|
||||||
* \param str String to clean
|
|
||||||
* \param newstr String to replace bad chars by
|
|
||||||
* \return string String cleaned (a-zA-Z_)
|
|
||||||
*/
|
|
||||||
function sanitizeFileName($str,$newstr='_')
|
|
||||||
{
|
|
||||||
return sanitize_string(unaccent_isostring($str,$newstr));
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* \brief Returns text escaped for inclusion in javascript code
|
* \brief Returns text escaped for inclusion in javascript code
|
||||||
* \param $stringtoescape String to escape
|
* \param $stringtoescape String to escape
|
||||||
|
|||||||
@ -61,7 +61,7 @@ function get_next_value($db,$mask,$table,$field,$where='',$valueforccc='',$date=
|
|||||||
$maskrefclient_maskoffset=0; //default value of maskrefclient_counter offset
|
$maskrefclient_maskoffset=0; //default value of maskrefclient_counter offset
|
||||||
$maskrefclient_clientcode=substr($valueforccc,0,strlen($maskrefclient_maskclientcode));//get n first characters of client code to form maskrefclient_clientcode
|
$maskrefclient_clientcode=substr($valueforccc,0,strlen($maskrefclient_maskclientcode));//get n first characters of client code to form maskrefclient_clientcode
|
||||||
$maskrefclient_clientcode=str_pad($maskrefclient_clientcode,strlen($maskrefclient_maskclientcode),"#",STR_PAD_RIGHT);//padding maskrefclient_clientcode for having exactly n characters in maskrefclient_clientcode
|
$maskrefclient_clientcode=str_pad($maskrefclient_clientcode,strlen($maskrefclient_maskclientcode),"#",STR_PAD_RIGHT);//padding maskrefclient_clientcode for having exactly n characters in maskrefclient_clientcode
|
||||||
$maskrefclient_clientcode=sanitize_string($maskrefclient_clientcode);//sanitize maskrefclient_clientcode for sql insert and sql select like
|
$maskrefclient_clientcode=dol_string_nospecial($maskrefclient_clientcode);//sanitize maskrefclient_clientcode for sql insert and sql select like
|
||||||
if (strlen($maskrefclient_maskcounter) > 0 && strlen($maskrefclient_maskcounter) < 3) return 'CounterMustHaveMoreThan3Digits';
|
if (strlen($maskrefclient_maskcounter) > 0 && strlen($maskrefclient_maskcounter) < 3) return 'CounterMustHaveMoreThan3Digits';
|
||||||
}
|
}
|
||||||
else $maskrefclient='';
|
else $maskrefclient='';
|
||||||
@ -121,16 +121,16 @@ function get_next_value($db,$mask,$table,$field,$where='',$valueforccc='',$date=
|
|||||||
//print "x".$sqlstring;
|
//print "x".$sqlstring;
|
||||||
|
|
||||||
// Define $maskLike
|
// Define $maskLike
|
||||||
$maskLike = sanitize_string($mask);
|
$maskLike = dol_string_nospecial($mask);
|
||||||
$maskLike = str_replace("%","_",$maskLike);
|
$maskLike = str_replace("%","_",$maskLike);
|
||||||
// Replace protected special codes with matching number of _ as wild card caracter
|
// Replace protected special codes with matching number of _ as wild card caracter
|
||||||
$maskLike = str_replace(sanitize_string('{yyyy}'),'____',$maskLike);
|
$maskLike = str_replace(dol_string_nospecial('{yyyy}'),'____',$maskLike);
|
||||||
$maskLike = str_replace(sanitize_string('{yy}'),'__',$maskLike);
|
$maskLike = str_replace(dol_string_nospecial('{yy}'),'__',$maskLike);
|
||||||
$maskLike = str_replace(sanitize_string('{y}'),'_',$maskLike);
|
$maskLike = str_replace(dol_string_nospecial('{y}'),'_',$maskLike);
|
||||||
$maskLike = str_replace(sanitize_string('{mm}'),'__',$maskLike);
|
$maskLike = str_replace(dol_string_nospecial('{mm}'),'__',$maskLike);
|
||||||
$maskLike = str_replace(sanitize_string('{dd}'),'__',$maskLike);
|
$maskLike = str_replace(dol_string_nospecial('{dd}'),'__',$maskLike);
|
||||||
$maskLike = str_replace(sanitize_string('{'.$masktri.'}'),str_pad("",strlen($maskcounter),"_"),$maskLike);
|
$maskLike = str_replace(dol_string_nospecial('{'.$masktri.'}'),str_pad("",strlen($maskcounter),"_"),$maskLike);
|
||||||
if ($maskrefclient) $maskLike = str_replace(sanitize_string('{'.$maskrefclient.'}'),str_pad("",strlen($maskrefclient),"_"),$maskLike);
|
if ($maskrefclient) $maskLike = str_replace(dol_string_nospecial('{'.$maskrefclient.'}'),str_pad("",strlen($maskrefclient),"_"),$maskLike);
|
||||||
|
|
||||||
// Get counter in database
|
// Get counter in database
|
||||||
$counter=0;
|
$counter=0;
|
||||||
@ -163,16 +163,16 @@ function get_next_value($db,$mask,$table,$field,$where='',$valueforccc='',$date=
|
|||||||
//print "x".$sqlstring;
|
//print "x".$sqlstring;
|
||||||
|
|
||||||
// Define $maskrefclient_maskLike
|
// Define $maskrefclient_maskLike
|
||||||
$maskrefclient_maskLike = sanitize_string($mask);
|
$maskrefclient_maskLike = dol_string_nospecial($mask);
|
||||||
$maskrefclient_maskLike = str_replace("%","_",$maskrefclient_maskLike);
|
$maskrefclient_maskLike = str_replace("%","_",$maskrefclient_maskLike);
|
||||||
// Replace protected special codes with matching number of _ as wild card caracter
|
// Replace protected special codes with matching number of _ as wild card caracter
|
||||||
$maskrefclient_maskLike = str_replace(sanitize_string('{yyyy}'),'____',$maskrefclient_maskLike);
|
$maskrefclient_maskLike = str_replace(dol_string_nospecial('{yyyy}'),'____',$maskrefclient_maskLike);
|
||||||
$maskrefclient_maskLike = str_replace(sanitize_string('{yy}'),'__',$maskrefclient_maskLike);
|
$maskrefclient_maskLike = str_replace(dol_string_nospecial('{yy}'),'__',$maskrefclient_maskLike);
|
||||||
$maskrefclient_maskLike = str_replace(sanitize_string('{y}'),'_',$maskrefclient_maskLike);
|
$maskrefclient_maskLike = str_replace(dol_string_nospecial('{y}'),'_',$maskrefclient_maskLike);
|
||||||
$maskrefclient_maskLike = str_replace(sanitize_string('{mm}'),'__',$maskrefclient_maskLike);
|
$maskrefclient_maskLike = str_replace(dol_string_nospecial('{mm}'),'__',$maskrefclient_maskLike);
|
||||||
$maskrefclient_maskLike = str_replace(sanitize_string('{dd}'),'__',$maskrefclient_maskLike);
|
$maskrefclient_maskLike = str_replace(dol_string_nospecial('{dd}'),'__',$maskrefclient_maskLike);
|
||||||
$maskrefclient_maskLike = str_replace(sanitize_string('{'.$masktri.'}'),str_pad("",strlen($maskcounter),"_"),$maskrefclient_maskLike);
|
$maskrefclient_maskLike = str_replace(dol_string_nospecial('{'.$masktri.'}'),str_pad("",strlen($maskcounter),"_"),$maskrefclient_maskLike);
|
||||||
$maskrefclient_maskLike = str_replace(sanitize_string('{'.$maskrefclient.'}'),$maskrefclient_clientcode.str_pad("",strlen($maskrefclient_maskcounter),"_"),$maskrefclient_maskLike);
|
$maskrefclient_maskLike = str_replace(dol_string_nospecial('{'.$maskrefclient.'}'),$maskrefclient_clientcode.str_pad("",strlen($maskrefclient_maskcounter),"_"),$maskrefclient_maskLike);
|
||||||
|
|
||||||
// Get counter in database
|
// Get counter in database
|
||||||
$maskrefclient_counter=0;
|
$maskrefclient_counter=0;
|
||||||
|
|||||||
@ -161,7 +161,7 @@ class Product extends CommonObject
|
|||||||
$this->errno = 0;
|
$this->errno = 0;
|
||||||
|
|
||||||
// Clean parameters
|
// Clean parameters
|
||||||
$this->ref = trim(sanitize_string($this->ref));
|
$this->ref = dol_string_nospecial(trim($this->ref));
|
||||||
$this->libelle = trim($this->libelle);
|
$this->libelle = trim($this->libelle);
|
||||||
if ($this->tva_tx=='') $this->tva_tx = 0;
|
if ($this->tva_tx=='') $this->tva_tx = 0;
|
||||||
if ($this->price=='') $this->price = 0;
|
if ($this->price=='') $this->price = 0;
|
||||||
@ -357,7 +357,7 @@ class Product extends CommonObject
|
|||||||
if (! $this->libelle) $this->libelle = 'LIBELLE MANQUANT';
|
if (! $this->libelle) $this->libelle = 'LIBELLE MANQUANT';
|
||||||
|
|
||||||
// Nettoyage parametres
|
// Nettoyage parametres
|
||||||
$this->ref = trim(sanitize_string($this->ref));
|
$this->ref = dol_string_nospecial(trim($this->ref));
|
||||||
$this->libelle = trim($this->libelle);
|
$this->libelle = trim($this->libelle);
|
||||||
$this->description = trim($this->description);
|
$this->description = trim($this->description);
|
||||||
$this->note = trim($this->note);
|
$this->note = trim($this->note);
|
||||||
|
|||||||
@ -119,7 +119,7 @@ class LoginAnakin
|
|||||||
// 8 premieres lettre desaccentuees du nom en minuscule
|
// 8 premieres lettre desaccentuees du nom en minuscule
|
||||||
function generate_login_1()
|
function generate_login_1()
|
||||||
{
|
{
|
||||||
$nom = strtolower(unaccent_isostring(sanitize_string($this->user->nom)));
|
$nom = strtolower(dol_string_unaccent(dol_string_nospecial($this->user->nom)));
|
||||||
|
|
||||||
$this->login = substr($nom, 0, 8);
|
$this->login = substr($nom, 0, 8);
|
||||||
}
|
}
|
||||||
@ -128,7 +128,7 @@ class LoginAnakin
|
|||||||
// Regle de defaut
|
// Regle de defaut
|
||||||
function generate_login_else()
|
function generate_login_else()
|
||||||
{
|
{
|
||||||
$login = strtolower(unaccent_isostring(sanitize_string($this->user->nom)));
|
$login = strtolower(dol_string_unaccent(dol_string_nospecial($this->user->nom)));
|
||||||
|
|
||||||
$le = strlen($this->else_step);
|
$le = strlen($this->else_step);
|
||||||
|
|
||||||
@ -140,8 +140,8 @@ class LoginAnakin
|
|||||||
// premiere lettre du prenom + 7 premieres lettres du nom, desaccentuees en minuscule
|
// premiere lettre du prenom + 7 premieres lettres du nom, desaccentuees en minuscule
|
||||||
function generate_login_2()
|
function generate_login_2()
|
||||||
{
|
{
|
||||||
$nom = strtolower(unaccent_isostring(sanitize_string($this->user->nom)));
|
$nom = strtolower(dol_string_unaccent(dol_string_nospecial($this->user->nom)));
|
||||||
$prenom = strtolower(unaccent_isostring(sanitize_string($this->user->prenom)));
|
$prenom = strtolower(dol_string_unaccent(dol_string_nospecial($this->user->prenom)));
|
||||||
|
|
||||||
$this->login = substr($prenom, 0, 1) . substr($nom, 0, 7);
|
$this->login = substr($prenom, 0, 1) . substr($nom, 0, 7);
|
||||||
}
|
}
|
||||||
@ -150,8 +150,8 @@ class LoginAnakin
|
|||||||
// 2 premieres lettres du prenom + 6 premieres lettres du nom, desaccentuees en minuscule
|
// 2 premieres lettres du prenom + 6 premieres lettres du nom, desaccentuees en minuscule
|
||||||
function generate_login_3()
|
function generate_login_3()
|
||||||
{
|
{
|
||||||
$nom = strtolower(unaccent_isostring(sanitize_string($this->user->nom)));
|
$nom = strtolower(dol_string_unaccent(dol_string_nospecial($this->user->nom)));
|
||||||
$prenom = strtolower(unaccent_isostring(sanitize_string($this->user->prenom)));
|
$prenom = strtolower(dol_string_unaccent(dol_string_nospecial($this->user->prenom)));
|
||||||
|
|
||||||
$this->login = substr($prenom, 0, 2) . substr($nom, 0, 6);
|
$this->login = substr($prenom, 0, 2) . substr($nom, 0, 6);
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user