From a37297a83f211b2776bf33307829de6cf8dc9a71 Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Mon, 6 Apr 2009 08:34:42 +0000 Subject: [PATCH] Qual: Reduce too much memory used on all pages for only 1 test is 5 files (move function into functions2.lib.php instead of functions.lib.php, functions.php is always loaded, functions2 is loaded on demand). Fix: Removed test on url to allow to input url with no http before --- htdocs/core/menubase.class.php | 422 +++++++++--------- .../menus/barre_top/auguria_backoffice.php | 2 +- .../menus/barre_top/auguria_frontoffice.php | 2 +- .../menus/barre_top/eldy_backoffice.php | 2 +- .../menus/barre_top/eldy_frontoffice.php | 2 +- htdocs/includes/menus/barre_top/rodolphe.php | 2 +- htdocs/lib/functions.lib.php | 91 +--- htdocs/lib/functions2.lib.php | 87 ++++ htdocs/societe.class.php | 15 +- 9 files changed, 312 insertions(+), 313 deletions(-) diff --git a/htdocs/core/menubase.class.php b/htdocs/core/menubase.class.php index ca72f327370..ef7fdfa8693 100644 --- a/htdocs/core/menubase.class.php +++ b/htdocs/core/menubase.class.php @@ -17,25 +17,25 @@ */ /** - \file htdocs/core/menubase.class.php - \ingroup core - \version $Id$ - \brief File of class to manage dynamic menu entries - \remarks Initialy built by build_class_from_table on 2008-01-12 14:19 -*/ + \file htdocs/core/menubase.class.php + \ingroup core + \version $Id$ + \brief File of class to manage dynamic menu entries + \remarks Initialy built by build_class_from_table on 2008-01-12 14:19 + */ /** - \class Menubase - \brief Class to manage menu entries -*/ + \class Menubase + \brief Class to manage menu entries + */ class Menubase { var $db; // To store db handler var $error; // To return error code (or message) var $errors=array(); // To return several error codes (or messages) - var $id; + var $id; var $menu_handler; var $module; @@ -54,27 +54,27 @@ class Menubase var $tms; - /** - * \brief Constructor - * \param DB Database handler - */ - function Menubase($DB,$menu_handler='',$type='') - { - $this->db = $DB; + /** + * \brief Constructor + * \param DB Database handler + */ + function Menubase($DB,$menu_handler='',$type='') + { + $this->db = $DB; $this->menu_handler = $menu_handler; $this->type = $type; - return 1; - } + return 1; + } - /** - * \brief Create in database - * \param user User that create - * \return int <0 si ko, >0 si ok - */ - function create($user) - { - global $conf, $langs; + /** + * \brief Create in database + * \param user User that create + * \return int <0 si ko, >0 si ok + */ + function create($user) + { + global $conf, $langs; // Clean parameters $this->menu_handler=trim($this->menu_handler); @@ -96,7 +96,7 @@ class Menubase // Check parameters // Put here code to add control on parameters values - // Insert request + // Insert request $sql = "INSERT INTO ".MAIN_DB_PREFIX."menu("; $sql.= "menu_handler,"; $sql.= "module,"; @@ -112,7 +112,7 @@ class Menubase $sql.= "leftmenu,"; $sql.= "perms,"; $sql.= "user"; - $sql.= ") VALUES ("; + $sql.= ") VALUES ("; $sql.= " '".$this->menu_handler."',"; $sql.= " '".$this->module."',"; $sql.= " '".$this->type."',"; @@ -129,31 +129,31 @@ class Menubase $sql.= " '".$this->user."'"; $sql.= ")"; - dol_syslog("Menubase::create sql=".$sql, LOG_DEBUG); - $resql=$this->db->query($sql); - if ($resql) - { - $this->id = $this->db->last_insert_id(MAIN_DB_PREFIX."menu"); + dol_syslog("Menubase::create sql=".$sql, LOG_DEBUG); + $resql=$this->db->query($sql); + if ($resql) + { + $this->id = $this->db->last_insert_id(MAIN_DB_PREFIX."menu"); - return $this->id; - } - else - { - $this->error="Error ".$this->db->lasterror(); - dol_syslog("Menubase::create ".$this->error, LOG_ERR); - return -1; - } - } + return $this->id; + } + else + { + $this->error="Error ".$this->db->lasterror(); + dol_syslog("Menubase::create ".$this->error, LOG_ERR); + return -1; + } + } - /* - * \brief Update database - * \param user User that modify - * \param notrigger 0=no, 1=yes (no update trigger) - * \return int <0 if KO, >0 if OK - */ - function update($user=0, $notrigger=0) - { - global $conf, $langs; + /* + * \brief Update database + * \param user User that modify + * \param notrigger 0=no, 1=yes (no update trigger) + * \return int <0 if KO, >0 if OK + */ + function update($user=0, $notrigger=0) + { + global $conf, $langs; // Clean parameters $this->rowid=trim($this->rowid); @@ -175,8 +175,8 @@ class Menubase // Check parameters // Put here code to add control on parameters values - // Update request - $sql = "UPDATE ".MAIN_DB_PREFIX."menu SET"; + // Update request + $sql = "UPDATE ".MAIN_DB_PREFIX."menu SET"; $sql.= " menu_handler='".addslashes($this->menu_handler)."',"; $sql.= " module='".addslashes($this->module)."',"; $sql.= " type='".$this->type."',"; @@ -191,95 +191,95 @@ class Menubase $sql.= " leftmenu='".addslashes($this->leftmenu)."',"; $sql.= " perms='".addslashes($this->perms)."',"; $sql.= " user='".$this->user."'"; - $sql.= " WHERE rowid=".$this->id; + $sql.= " WHERE rowid=".$this->id; - dol_syslog("Menubase::update sql=".$sql, LOG_DEBUG); - $resql = $this->db->query($sql); - if (! $resql) - { - $this->error="Error ".$this->db->lasterror(); - dol_syslog("Menubase::update ".$this->error, LOG_ERR); - return -1; - } + dol_syslog("Menubase::update sql=".$sql, LOG_DEBUG); + $resql = $this->db->query($sql); + if (! $resql) + { + $this->error="Error ".$this->db->lasterror(); + dol_syslog("Menubase::update ".$this->error, LOG_ERR); + return -1; + } - return 1; - } + return 1; + } - /* - * \brief Load object in memory from database - * \param id id object - * \param user User that load - * \return int <0 if KO, >0 if OK - */ - function fetch($id, $user=0) - { - global $langs; - - $sql = "SELECT"; - $sql.= " t.rowid,"; - $sql.= " t.menu_handler,"; - $sql.= " t.module,"; - $sql.= " t.type,"; - $sql.= " t.mainmenu,"; - $sql.= " t.fk_menu,"; - $sql.= " t.position,"; - $sql.= " t.url,"; - $sql.= " t.target,"; - $sql.= " t.titre,"; - $sql.= " t.langs,"; - $sql.= " t.level,"; - $sql.= " t.leftmenu,"; - $sql.= " t.perms,"; - $sql.= " t.user,"; - $sql.= " ".$this->db->pdate('t.tms').""; - $sql.= " FROM ".MAIN_DB_PREFIX."menu as t"; - $sql.= " WHERE t.rowid = ".$id; + /* + * \brief Load object in memory from database + * \param id id object + * \param user User that load + * \return int <0 if KO, >0 if OK + */ + function fetch($id, $user=0) + { + global $langs; + + $sql = "SELECT"; + $sql.= " t.rowid,"; + $sql.= " t.menu_handler,"; + $sql.= " t.module,"; + $sql.= " t.type,"; + $sql.= " t.mainmenu,"; + $sql.= " t.fk_menu,"; + $sql.= " t.position,"; + $sql.= " t.url,"; + $sql.= " t.target,"; + $sql.= " t.titre,"; + $sql.= " t.langs,"; + $sql.= " t.level,"; + $sql.= " t.leftmenu,"; + $sql.= " t.perms,"; + $sql.= " t.user,"; + $sql.= " ".$this->db->pdate('t.tms').""; + $sql.= " FROM ".MAIN_DB_PREFIX."menu as t"; + $sql.= " WHERE t.rowid = ".$id; - dol_syslog("Menubase::fetch sql=".$sql, LOG_DEBUG); - $resql=$this->db->query($sql); - if ($resql) - { - if ($this->db->num_rows($resql)) - { - $obj = $this->db->fetch_object($resql); + dol_syslog("Menubase::fetch sql=".$sql, LOG_DEBUG); + $resql=$this->db->query($sql); + if ($resql) + { + if ($this->db->num_rows($resql)) + { + $obj = $this->db->fetch_object($resql); - $this->id = $obj->rowid; - - $this->menu_handler = $obj->menu_handler; - $this->module = $obj->module; - $this->type = $obj->type; - $this->mainmenu = $obj->mainmenu; - $this->fk_menu = $obj->fk_menu; - $this->position = $obj->position; - $this->url = $obj->url; - $this->target = $obj->target; - $this->titre = $obj->titre; - $this->langs = $obj->langs; - $this->level = $obj->level; - $this->leftmenu = $obj->leftmenu; - $this->perms = $obj->perms; - $this->user = $obj->user; - $this->tms = $obj->tms; - } - $this->db->free($resql); - - return 1; - } - else - { - $this->error="Error ".$this->db->lasterror(); - dol_syslog("Menubase::fetch ".$this->error, LOG_ERR); - return -1; - } - } + $this->id = $obj->rowid; + + $this->menu_handler = $obj->menu_handler; + $this->module = $obj->module; + $this->type = $obj->type; + $this->mainmenu = $obj->mainmenu; + $this->fk_menu = $obj->fk_menu; + $this->position = $obj->position; + $this->url = $obj->url; + $this->target = $obj->target; + $this->titre = $obj->titre; + $this->langs = $obj->langs; + $this->level = $obj->level; + $this->leftmenu = $obj->leftmenu; + $this->perms = $obj->perms; + $this->user = $obj->user; + $this->tms = $obj->tms; + } + $this->db->free($resql); + + return 1; + } + else + { + $this->error="Error ".$this->db->lasterror(); + dol_syslog("Menubase::fetch ".$this->error, LOG_ERR); + return -1; + } + } - /* - * \brief Delete object in database - * \param user User that delete - * \return int <0 if KO, >0 if OK - */ + /* + * \brief Delete object in database + * \param user User that delete + * \return int <0 if KO, >0 if OK + */ function delete($user) { global $conf, $langs; @@ -287,12 +287,12 @@ class Menubase $sql = "DELETE FROM ".MAIN_DB_PREFIX."menu"; $sql.= " WHERE rowid=".$this->id; - dol_syslog("Menubase::delete sql=".$sql); + dol_syslog("Menubase::delete sql=".$sql); $resql = $this->db->query($sql); if (! $resql) { $this->error="Error ".$this->db->lasterror(); - dol_syslog("Menubase::delete ".$this->error, LOG_ERR); + dol_syslog("Menubase::delete ".$this->error, LOG_ERR); return -1; } @@ -372,47 +372,47 @@ class Menubase //$objm = $this->db->fetch_object($resql); $menu = $this->db->fetch_array($resql); - // Define $chaine - $chaine=""; + // Define $chaine + $chaine=""; $title = $langs->trans($menu['titre']); - if ($title == $menu['titre'] && ! empty($menu['langs'])) + if ($title == $menu['titre'] && ! empty($menu['langs'])) { $title = $langs->trans($menu['titre']); $langs->load($menu['langs']); } if (eregi("/",$title)) - { - $tab_titre = explode("/",$title); - $chaine = $langs->trans($tab_titre[0])."/".$langs->trans($tab_titre[1]); - } - else - { - $chaine = $langs->trans($title); - } - - // Define $right - $perms = true; - if ($menu['perms']) - { - $perms = $this->verifCond($menu['perms']); - //print "verifCond rowid=".$menu['rowid']." ".$menu['right'].":".$perms."
\n"; - } - - // Define $constraint - $constraint = true; - if ($menu['action']) { - $constraint = $this->verifCond($menu['action']); - //print "verifCond rowid=".$menu['rowid']." ".$menu['action'].":".$constraint."
\n"; + $tab_titre = explode("/",$title); + $chaine = $langs->trans($tab_titre[0])."/".$langs->trans($tab_titre[1]); + } + else + { + $chaine = $langs->trans($title); + } + + // Define $right + $perms = true; + if ($menu['perms']) + { + $perms = $this->verifCond($menu['perms']); + //print "verifCond rowid=".$menu['rowid']." ".$menu['right'].":".$perms."
\n"; } - if ($menu['rowid'] != $oldrowid && $oldrowid) $b++; // Break on new entry - $oldrowid=$menu['rowid']; + // Define $constraint + $constraint = true; + if ($menu['action']) + { + $constraint = $this->verifCond($menu['action']); + //print "verifCond rowid=".$menu['rowid']." ".$menu['action'].":".$constraint."
\n"; + } - $tabMenu[$b][0] = $menu['rowid']; + if ($menu['rowid'] != $oldrowid && $oldrowid) $b++; // Break on new entry + $oldrowid=$menu['rowid']; + + $tabMenu[$b][0] = $menu['rowid']; $tabMenu[$b][1] = $menu['fk_menu']; $tabMenu[$b][2] = $menu['url']; - if (!valid_url($tabMenu[$b][2],1)) + if (! eregi($tabMenu[$b][2],"^(http:\/\/|https:\/\/)")) { if (eregi('\?',$tabMenu[$b][2])) $tabMenu[$b][2].='&idmenu='.$menu['rowid']; else $tabMenu[$b][2].='?idmenu='.$menu['rowid']; @@ -420,10 +420,10 @@ class Menubase $tabMenu[$b][3] = $chaine; $tabMenu[$b][5] = $menu['target']; $tabMenu[$b][6] = $menu['leftmenu']; - if (! isset($tabMenu[$b][4])) $tabMenu[$b][4] = $perms; - else $tabMenu[$b][4] = ($tabMenu[$b][4] && $perms); - if (! isset($tabMenu[$b][7])) $tabMenu[$b][7] = $constraint; - else $tabMenu[$b][7] = ($tabMenu[$b][7] && $constraint); + if (! isset($tabMenu[$b][4])) $tabMenu[$b][4] = $perms; + else $tabMenu[$b][4] = ($tabMenu[$b][4] && $perms); + if (! isset($tabMenu[$b][7])) $tabMenu[$b][7] = $constraint; + else $tabMenu[$b][7] = ($tabMenu[$b][7] && $constraint); $a++; } @@ -483,9 +483,9 @@ class Menubase if ($leftmenuConstraint) { -// print "x".$pere." ".$tab[$x][6]; + // print "x".$pere." ".$tab[$x][6]; - $this->newmenu->add_submenu((!valid_url($tab[$x][2],1)) ? DOL_URL_ROOT . $tab[$x][2] : $tab[$x][2], $tab[$x][3], $rang -1, $tab[$x][4], $tab[$x][5]); + $this->newmenu->add_submenu((! eregi($tab[$x][2],"^(http:\/\/|https:\/\/)")) ? DOL_URL_ROOT . $tab[$x][2] : $tab[$x][2], $tab[$x][3], $rang -1, $tab[$x][4], $tab[$x][5]); $this->recur($tab, $tab[$x][0], $rang +1); } } @@ -557,12 +557,12 @@ class Menubase } /** - * \brief Load tabMenu array - * \param type_user 0=Internal,1=External,2=All - * \param mainmenu Value for mainmenu that defined top menu - * \param menu_handler Name of menu_handler used (auguria, eldy...) - * \return array Return array with menu entries for top menu - */ + * \brief Load tabMenu array + * \param type_user 0=Internal,1=External,2=All + * \param mainmenu Value for mainmenu that defined top menu + * \param menu_handler Name of menu_handler used (auguria, eldy...) + * \return array Return array with menu entries for top menu + */ function menuTopCharger($type_user, $mainmenu, $menu_handler) { global $langs, $user, $conf; @@ -595,10 +595,10 @@ class Menubase { $objm = $this->db->fetch_object($resql); - // Define $chaine - $chaine=""; - $title=$langs->trans($objm->titre); - if ($title == $objm->titre) // Translation not found + // Define $chaine + $chaine=""; + $title=$langs->trans($objm->titre); + if ($title == $objm->titre) // Translation not found { if (! empty($objm->langs)) { @@ -606,15 +606,15 @@ class Menubase $langs->load($objm->langs); } - if (eregi("/",$title)) - { - $tab_titre = explode("/",$title); - $chaine = $langs->trans($tab_titre[0])."/".$langs->trans($tab_titre[1]); - } - else - { - $chaine = $langs->trans($title); - } + if (eregi("/",$title)) + { + $tab_titre = explode("/",$title); + $chaine = $langs->trans($tab_titre[0])."/".$langs->trans($tab_titre[1]); + } + else + { + $chaine = $langs->trans($title); + } } else { @@ -622,34 +622,34 @@ class Menubase } //print "x".$objm->titre."-".$chaine; - // Define $right - $perms = true; - if ($objm->perms) - { + // Define $right + $perms = true; + if ($objm->perms) + { $perms = $this->verifCond($objm->perms); - } + } - // Define $constraint - $constraint = true; - if ($objm->action) + // Define $constraint + $constraint = true; + if ($objm->action) { $constraint = $this->verifCond($objm->action); } - if ($objm->rowid != $oldrowid && $oldrowid) $b++; // Break on new entry - $oldrowid=$objm->rowid; + if ($objm->rowid != $oldrowid && $oldrowid) $b++; // Break on new entry + $oldrowid=$objm->rowid; - $tabMenu[$b]['rowid'] = $objm->rowid; - $tabMenu[$b]['mainmenu'] = $objm->mainmenu; - $tabMenu[$b]['titre'] = $chaine; // Title - $tabMenu[$b]['url'] = $objm->url; - $tabMenu[$b]['atarget'] = $objm->target; - if (! isset($tabMenu[$b]['right'])) $tabMenu[$b]['right'] = $perms; - else $tabMenu[$b]['right'] = ($tabMenu[$b]['right'] && $perms); - if (! isset($tabMenu[$b]['enabled'])) $tabMenu[$b]['enabled'] = $constraint; - else $tabMenu[$b]['enabled'] = ($tabMenu[$b]['enabled'] && $constraint); + $tabMenu[$b]['rowid'] = $objm->rowid; + $tabMenu[$b]['mainmenu'] = $objm->mainmenu; + $tabMenu[$b]['titre'] = $chaine; // Title + $tabMenu[$b]['url'] = $objm->url; + $tabMenu[$b]['atarget'] = $objm->target; + if (! isset($tabMenu[$b]['right'])) $tabMenu[$b]['right'] = $perms; + else $tabMenu[$b]['right'] = ($tabMenu[$b]['right'] && $perms); + if (! isset($tabMenu[$b]['enabled'])) $tabMenu[$b]['enabled'] = $constraint; + else $tabMenu[$b]['enabled'] = ($tabMenu[$b]['enabled'] && $constraint); - //var_dump($tabMenu); + //var_dump($tabMenu); $a++; } } diff --git a/htdocs/includes/menus/barre_top/auguria_backoffice.php b/htdocs/includes/menus/barre_top/auguria_backoffice.php index 0bff54f926f..9b64b933ec9 100644 --- a/htdocs/includes/menus/barre_top/auguria_backoffice.php +++ b/htdocs/includes/menus/barre_top/auguria_backoffice.php @@ -77,7 +77,7 @@ class MenuTop { if ($tabMenu[$i]['right'] == true) { // Define url - if (valid_url($tabMenu[$i]['url'],1)) + if (eregi($tabMenu[$i]['url'],"^(http:\/\/|https:\/\/)")) { $url = $tabMenu[$i]['url']; } diff --git a/htdocs/includes/menus/barre_top/auguria_frontoffice.php b/htdocs/includes/menus/barre_top/auguria_frontoffice.php index b6b15b4e727..ecb14bbca82 100644 --- a/htdocs/includes/menus/barre_top/auguria_frontoffice.php +++ b/htdocs/includes/menus/barre_top/auguria_frontoffice.php @@ -76,7 +76,7 @@ class MenuTop { if ($tabMenu[$i]['right'] == true) { // Define url - if (valid_url($tabMenu[$i]['url'],1)) + if (eregi($tabMenu[$i]['url'],"^(http:\/\/|https:\/\/)")) { $url = $tabMenu[$i]['url']; } diff --git a/htdocs/includes/menus/barre_top/eldy_backoffice.php b/htdocs/includes/menus/barre_top/eldy_backoffice.php index 66b4368df27..96c0541494e 100644 --- a/htdocs/includes/menus/barre_top/eldy_backoffice.php +++ b/htdocs/includes/menus/barre_top/eldy_backoffice.php @@ -364,7 +364,7 @@ class MenuTop { $idsel=(empty($tabMenu[$i]['mainmenu'])?'id="none" ':'id="'.$tabMenu[$i]['mainmenu'].'" '); if ($tabMenu[$i]['right'] == true) { - if (valid_url($tabMenu[$i]['url'],1)) + if (eregi($tabMenu[$i]['url'],"^(http:\/\/|https:\/\/)")) { $url = $tabMenu[$i]['url']; } diff --git a/htdocs/includes/menus/barre_top/eldy_frontoffice.php b/htdocs/includes/menus/barre_top/eldy_frontoffice.php index d0530204186..9055c4eaefe 100644 --- a/htdocs/includes/menus/barre_top/eldy_frontoffice.php +++ b/htdocs/includes/menus/barre_top/eldy_frontoffice.php @@ -365,7 +365,7 @@ class MenuTop { if ($tabMenu[$i]['right'] == true) { // Define url - if (valid_url($tabMenu[$i]['url'],1)) + if (eregi($tabMenu[$i]['url'],"^(http:\/\/|https:\/\/)")) { $url = $tabMenu[$i]['url']; } diff --git a/htdocs/includes/menus/barre_top/rodolphe.php b/htdocs/includes/menus/barre_top/rodolphe.php index f0306ed8c30..7487ba14f81 100644 --- a/htdocs/includes/menus/barre_top/rodolphe.php +++ b/htdocs/includes/menus/barre_top/rodolphe.php @@ -365,7 +365,7 @@ class MenuTop { $idsel=(empty($tabMenu[$i]['mainmenu'])?'id="none" ':'id="'.$tabMenu[$i]['mainmenu'].'" '); if ($tabMenu[$i]['right'] == true) { - if (valid_url($tabMenu[$i]['url'],1)) + if (eregi($tabMenu[$i]['url'],"^(http:\/\/|https:\/\/)")) { $url = $tabMenu[$i]['url']; } diff --git a/htdocs/lib/functions.lib.php b/htdocs/lib/functions.lib.php index 3227dd967da..c22aa1cf4c8 100644 --- a/htdocs/lib/functions.lib.php +++ b/htdocs/lib/functions.lib.php @@ -2323,13 +2323,13 @@ function create_exdir($dir) else { dol_syslog("functions.lib::create_exdir: Directory '".$ccdir."' created",LOG_DEBUG); - $nberr=0; // On remet a zero car si on arrive ici, cela veut dire que les �checs pr�c�dents peuvent etre ignor�s + $nberr=0; // On remet a zero car si on arrive ici, cela veut dire que les echecs precedents peuvent etre ignore $nbcreated++; } } else { - $nberr=0; // On remet a zero car si on arrive ici, cela veut dire que les �checs pr�c�dents peuvent etre ignor�s + $nberr=0; // On remet a zero car si on arrive ici, cela veut dire que les echecs precedents peuvent etre ignores } } } @@ -2347,93 +2347,6 @@ function picto_required() } -/** - * \brief Clean an url string - * \param url Url - * \param http 1: keep http, 0: remove also http - * \return string CleanUrl - */ -function clean_url($url,$http=1) -{ - // Fixed by Matelli (see http://matelli.fr/showcases/patchs-dolibarr/fix-cleaning-url.html) - // To include the minus sign in a char class, we must not escape it but put it at the end of the class - // Also, there's no need of escape a dot sign in a class - if (eregi('^(https?:[\\\/]+)?([0-9A-Z.-]+\.[A-Z]{2,4})(:[0-9]+)?',$url,$regs)) - { - $proto=$regs[1]; - $domain=$regs[2]; - $port=$regs[3]; - //print $url." -> ".$proto." - ".$domain." - ".$port; - //$url = dol_string_nospecial(trim($url)); - $url = trim($url); - - // Si http: defini on supprime le http (Si https on ne supprime pas) - $newproto=$proto; - if ($http==0) - { - if (eregi('^http:[\\\/]+',$url)) - { - $url = eregi_replace('^http:[\\\/]+','',$url); - $newproto = ''; - } - } - - // On passe le nom de domaine en minuscule - $CleanUrl = eregi_replace('^'.$proto.$domain, $newproto.strtolower($domain), $url); - - return $CleanUrl; - } -} - - -/** - * \brief Url string validation - * \remarks :// [user[:pass]@] hostname [port] [/path] [?getquery] [anchor] - * \param url Url - * \param http 1: verify http, 0: not verify http - * \param pass 1: verify user and pass, 0: not verify user and pass - * \param port 1: verify port, 0: not verify port - * \param path 1: verify path, 0: not verify path - * \param query 1: verify query, 0: not verify query - * \param anchor 1: verify anchor, 0: not verify anchor - * \return string ValidUrl - */ -function valid_url($url,$http=0,$pass=0,$port=0,$path=0,$query=0,$anchor=0) -{ - $ValidUrl = 0; - $urlregex = ''; - - // SCHEME - if ($http) $urlregex .= "^(http:\/\/|https:\/\/)"; - - // USER AND PASS - if ($pass) $urlregex .= "([a-z0-9+!*(),;?&=\$_.-]+(\:[a-z0-9+!*(),;?&=\$_.-]+)?@)"; - - // HOSTNAME OR IP - //$urlregex .= "[a-z0-9+\$_-]+(\.[a-z0-9+\$_-]+)*"; // http://x = allowed (ex. http://localhost, http://routerlogin) - //$urlregex .= "[a-z0-9+\$_-]+(\.[a-z0-9+\$_-]+)+"; // http://x.x = minimum - $urlregex .= "([a-z0-9+\$_-]+\.)*[a-z0-9+\$_-]{2,3}"; // http://x.xx(x) = minimum - //use only one of the above - - // PORT - if ($port) $urlregex .= "(\:[0-9]{2,5})"; - // PATH - if ($path) $urlregex .= "(\/([a-z0-9+\$_-]\.?)+)*\/"; - // GET Query - if ($query) $urlregex .= "(\?[a-z+&\$_.-][a-z0-9;:@/&%=+\$_.-]*)"; - // ANCHOR - if($anchor) $urlregex .= "(#[a-z_.-][a-z0-9+\$_.-]*)\$"; - - // check - if (eregi($urlregex, $url)) - { - $ValidUrl = 1; - } - - return $ValidUrl; -} - - /** * \brief Clean a string from all HTML tags and entities * \param StringHtml String to clean diff --git a/htdocs/lib/functions2.lib.php b/htdocs/lib/functions2.lib.php index 12eafbe9659..395593e4c11 100644 --- a/htdocs/lib/functions2.lib.php +++ b/htdocs/lib/functions2.lib.php @@ -155,6 +155,93 @@ function isValidMailDomain($mail) } +/** + * \brief Url string validation + * \remarks :// [user[:pass]@] hostname [port] [/path] [?getquery] [anchor] + * \param url Url + * \param http 1: verify http, 0: not verify http + * \param pass 1: verify user and pass, 0: not verify user and pass + * \param port 1: verify port, 0: not verify port + * \param path 1: verify path, 0: not verify path + * \param query 1: verify query, 0: not verify query + * \param anchor 1: verify anchor, 0: not verify anchor + * \return int 1=Check is OK, 0=Check is KO + */ +function isValidUrl($url,$http=0,$pass=0,$port=0,$path=0,$query=0,$anchor=0) +{ + $ValidUrl = 0; + $urlregex = ''; + + // SCHEME + if ($http) $urlregex .= "^(http:\/\/|https:\/\/)"; + + // USER AND PASS + if ($pass) $urlregex .= "([a-z0-9+!*(),;?&=\$_.-]+(\:[a-z0-9+!*(),;?&=\$_.-]+)?@)"; + + // HOSTNAME OR IP + //$urlregex .= "[a-z0-9+\$_-]+(\.[a-z0-9+\$_-]+)*"; // http://x = allowed (ex. http://localhost, http://routerlogin) + //$urlregex .= "[a-z0-9+\$_-]+(\.[a-z0-9+\$_-]+)+"; // http://x.x = minimum + $urlregex .= "([a-z0-9+\$_-]+\.)*[a-z0-9+\$_-]{2,3}"; // http://x.xx(x) = minimum + //use only one of the above + + // PORT + if ($port) $urlregex .= "(\:[0-9]{2,5})"; + // PATH + if ($path) $urlregex .= "(\/([a-z0-9+\$_-]\.?)+)*\/"; + // GET Query + if ($query) $urlregex .= "(\?[a-z+&\$_.-][a-z0-9;:@/&%=+\$_.-]*)"; + // ANCHOR + if($anchor) $urlregex .= "(#[a-z_.-][a-z0-9+\$_.-]*)\$"; + + // check + if (eregi($urlregex, $url)) + { + $ValidUrl = 1; + } + + return $ValidUrl; +} + + +/** + * \brief Clean an url string + * \param url Url + * \param http 1: keep http://, 0: remove also http:// + * \return string Cleaned url + */ +function clean_url($url,$http=1) +{ + // Fixed by Matelli (see http://matelli.fr/showcases/patchs-dolibarr/fix-cleaning-url.html) + // To include the minus sign in a char class, we must not escape it but put it at the end of the class + // Also, there's no need of escape a dot sign in a class + if (eregi('^(https?:[\\\/]+)?([0-9A-Z.-]+\.[A-Z]{2,4})(:[0-9]+)?',$url,$regs)) + { + $proto=$regs[1]; + $domain=$regs[2]; + $port=$regs[3]; + //print $url." -> ".$proto." - ".$domain." - ".$port; + //$url = dol_string_nospecial(trim($url)); + $url = trim($url); + + // Si http: defini on supprime le http (Si https on ne supprime pas) + $newproto=$proto; + if ($http==0) + { + if (eregi('^http:[\\\/]+',$url)) + { + $url = eregi_replace('^http:[\\\/]+','',$url); + $newproto = ''; + } + } + + // On passe le nom de domaine en minuscule + $CleanUrl = eregi_replace('^'.$proto.$domain, $newproto.strtolower($domain), $url); + + return $CleanUrl; + } +} + + /** * \brief Return lines of an html table from an array * \remarks Used by array2table function only diff --git a/htdocs/societe.class.php b/htdocs/societe.class.php index b2745a4221f..5beca995205 100644 --- a/htdocs/societe.class.php +++ b/htdocs/societe.class.php @@ -227,8 +227,8 @@ class Societe extends CommonObject } /** - * \brief Verification lors de la modification - * \return int 0 si OK, <0 si KO + * \brief Check properties of third party are ok + * \return int 0 if OK, <0 if KO */ function verify() { @@ -242,6 +242,7 @@ class Societe extends CommonObject $this->errors[] = 'ErrorBadThirdPartyName'; $result = -2; } + if ($this->client && $this->codeclient_modifiable()) { // On ne verifie le code client que si la societe est un client / prospect et que le code est modifiable @@ -268,6 +269,7 @@ class Societe extends CommonObject $result = -3; } } + if ($this->fournisseur && $this->codefournisseur_modifiable()) { // On ne verifie le code fournisseur que si la societe est un fournisseur et que le code est modifiable @@ -294,12 +296,7 @@ class Societe extends CommonObject $result = -3; } } - if (valid_url($this->url) == 0) - { - $this->errors[] = 'ErrorUrlNotValid'; - $result = -4; - } - + return $result; } @@ -314,6 +311,8 @@ class Societe extends CommonObject */ function update($id, $user='', $call_trigger=1, $allowmodcodeclient=0, $allowmodcodefournisseur=0) { + require_once(DOL_DOCUMENT_ROOT."/lib/functions2.lib.php"); + global $langs,$conf; dol_syslog("Societe::Update id=".$id." call_trigger=".$call_triger." allowmodcodeclient=".$allowmodcodeclient." allowmodcodefournisseur=".$allowmodcodefournisseur);