Rename function to make code cleaner

This commit is contained in:
Laurent Destailleur
2008-10-25 21:35:27 +00:00
parent dbae510665
commit 59faec9b4e
5 changed files with 51 additions and 54 deletions

View File

@@ -84,7 +84,7 @@ if ($_POST["action"] == 'update' && ! $_POST["cancel"])
$account = new Account($db, $_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->courant = $_POST["type"];
$account->clos = $_POST["clos"];

View File

@@ -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
\param address adresse email (Ex: "toto@titi.com", "John Do <johndo@titi.com>")
\return boolean true si email valide, false sinon
* \brief Renvoi vrai si l'email est syntaxiquement valide
* \param address adresse email (Ex: "toto@titi.com", "John Do <johndo@titi.com>")
* \return boolean true si email valide, false sinon
*/
function ValidEmail($address)
{
@@ -57,11 +57,11 @@ function ValidEmail($address)
}
/**
\brief Renvoi vrai si l'email a un nom de domaine qui r<>soud via dns
\param mail adresse email (Ex: "toto@titi.com", "John Do <johndo@titi.com>")
\return boolean true si email valide, false sinon
* \brief Renvoi vrai si l'email a un nom de domaine qui r<>soud via dns
* \param mail adresse email (Ex: "toto@titi.com", "John Do <johndo@titi.com>")
* \return boolean true si email valide, false sinon
*/
function check_mail ($mail)
function check_mail($mail)
{
list($user, $domain) = split("@", $mail, 2);
if (checkdnsrr($domain, "MX"))
@@ -75,15 +75,25 @@ function check_mail ($mail)
}
/**
\brief Nettoie chaine de caractere des accents
\param str Chaine a nettoyer
\return string Chaine nettoyee
* \brief Clean a string to use it as a file name.
* \param str String to clean
* \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))
{
// TODO add utf8 convertion
$translationutf=array( );
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
* \remarks Fonction appelee par exemple pour definir un nom de fichier depuis un identifiant chaine libre
* \brief Clean a string from all punctuation characters
* \param str String to clean
* \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_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));
}
/**
* \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
* \param $stringtoescape String to escape

View File

@@ -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_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=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';
}
else $maskrefclient='';
@@ -121,16 +121,16 @@ function get_next_value($db,$mask,$table,$field,$where='',$valueforccc='',$date=
//print "x".$sqlstring;
// Define $maskLike
$maskLike = sanitize_string($mask);
$maskLike = dol_string_nospecial($mask);
$maskLike = str_replace("%","_",$maskLike);
// Replace protected special codes with matching number of _ as wild card caracter
$maskLike = str_replace(sanitize_string('{yyyy}'),'____',$maskLike);
$maskLike = str_replace(sanitize_string('{yy}'),'__',$maskLike);
$maskLike = str_replace(sanitize_string('{y}'),'_',$maskLike);
$maskLike = str_replace(sanitize_string('{mm}'),'__',$maskLike);
$maskLike = str_replace(sanitize_string('{dd}'),'__',$maskLike);
$maskLike = str_replace(sanitize_string('{'.$masktri.'}'),str_pad("",strlen($maskcounter),"_"),$maskLike);
if ($maskrefclient) $maskLike = str_replace(sanitize_string('{'.$maskrefclient.'}'),str_pad("",strlen($maskrefclient),"_"),$maskLike);
$maskLike = str_replace(dol_string_nospecial('{yyyy}'),'____',$maskLike);
$maskLike = str_replace(dol_string_nospecial('{yy}'),'__',$maskLike);
$maskLike = str_replace(dol_string_nospecial('{y}'),'_',$maskLike);
$maskLike = str_replace(dol_string_nospecial('{mm}'),'__',$maskLike);
$maskLike = str_replace(dol_string_nospecial('{dd}'),'__',$maskLike);
$maskLike = str_replace(dol_string_nospecial('{'.$masktri.'}'),str_pad("",strlen($maskcounter),"_"),$maskLike);
if ($maskrefclient) $maskLike = str_replace(dol_string_nospecial('{'.$maskrefclient.'}'),str_pad("",strlen($maskrefclient),"_"),$maskLike);
// Get counter in database
$counter=0;
@@ -163,16 +163,16 @@ function get_next_value($db,$mask,$table,$field,$where='',$valueforccc='',$date=
//print "x".$sqlstring;
// Define $maskrefclient_maskLike
$maskrefclient_maskLike = sanitize_string($mask);
$maskrefclient_maskLike = dol_string_nospecial($mask);
$maskrefclient_maskLike = str_replace("%","_",$maskrefclient_maskLike);
// 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(sanitize_string('{yy}'),'__',$maskrefclient_maskLike);
$maskrefclient_maskLike = str_replace(sanitize_string('{y}'),'_',$maskrefclient_maskLike);
$maskrefclient_maskLike = str_replace(sanitize_string('{mm}'),'__',$maskrefclient_maskLike);
$maskrefclient_maskLike = str_replace(sanitize_string('{dd}'),'__',$maskrefclient_maskLike);
$maskrefclient_maskLike = str_replace(sanitize_string('{'.$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('{yyyy}'),'____',$maskrefclient_maskLike);
$maskrefclient_maskLike = str_replace(dol_string_nospecial('{yy}'),'__',$maskrefclient_maskLike);
$maskrefclient_maskLike = str_replace(dol_string_nospecial('{y}'),'_',$maskrefclient_maskLike);
$maskrefclient_maskLike = str_replace(dol_string_nospecial('{mm}'),'__',$maskrefclient_maskLike);
$maskrefclient_maskLike = str_replace(dol_string_nospecial('{dd}'),'__',$maskrefclient_maskLike);
$maskrefclient_maskLike = str_replace(dol_string_nospecial('{'.$masktri.'}'),str_pad("",strlen($maskcounter),"_"),$maskrefclient_maskLike);
$maskrefclient_maskLike = str_replace(dol_string_nospecial('{'.$maskrefclient.'}'),$maskrefclient_clientcode.str_pad("",strlen($maskrefclient_maskcounter),"_"),$maskrefclient_maskLike);
// Get counter in database
$maskrefclient_counter=0;

View File

@@ -161,7 +161,7 @@ class Product extends CommonObject
$this->errno = 0;
// Clean parameters
$this->ref = trim(sanitize_string($this->ref));
$this->ref = dol_string_nospecial(trim($this->ref));
$this->libelle = trim($this->libelle);
if ($this->tva_tx=='') $this->tva_tx = 0;
if ($this->price=='') $this->price = 0;
@@ -357,7 +357,7 @@ class Product extends CommonObject
if (! $this->libelle) $this->libelle = 'LIBELLE MANQUANT';
// Nettoyage parametres
$this->ref = trim(sanitize_string($this->ref));
$this->ref = dol_string_nospecial(trim($this->ref));
$this->libelle = trim($this->libelle);
$this->description = trim($this->description);
$this->note = trim($this->note);

View File

@@ -119,7 +119,7 @@ class LoginAnakin
// 8 premieres lettre desaccentuees du nom en minuscule
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);
}
@@ -128,7 +128,7 @@ class LoginAnakin
// Regle de defaut
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);
@@ -140,8 +140,8 @@ class LoginAnakin
// premiere lettre du prenom + 7 premieres lettres du nom, desaccentuees en minuscule
function generate_login_2()
{
$nom = strtolower(unaccent_isostring(sanitize_string($this->user->nom)));
$prenom = strtolower(unaccent_isostring(sanitize_string($this->user->prenom)));
$nom = strtolower(dol_string_unaccent(dol_string_nospecial($this->user->nom)));
$prenom = strtolower(dol_string_unaccent(dol_string_nospecial($this->user->prenom)));
$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
function generate_login_3()
{
$nom = strtolower(unaccent_isostring(sanitize_string($this->user->nom)));
$prenom = strtolower(unaccent_isostring(sanitize_string($this->user->prenom)));
$nom = strtolower(dol_string_unaccent(dol_string_nospecial($this->user->nom)));
$prenom = strtolower(dol_string_unaccent(dol_string_nospecial($this->user->prenom)));
$this->login = substr($prenom, 0, 2) . substr($nom, 0, 6);
}