From 81464c0cf56e4b5aa8a60bce6df8326736b8d678 Mon Sep 17 00:00:00 2001 From: Regis Houssin <regis@dolibarr.fr> Date: Fri, 23 Oct 2009 15:26:45 +0000 Subject: [PATCH] Fix: useing "preg_quote" is more simpler --- htdocs/admin/agenda_xcal.php | 3 +-- htdocs/admin/paybox.php | 4 +--- htdocs/admin/webcalendar.php | 3 +-- htdocs/admin/webservices.php | 4 +--- htdocs/categories/categorie.class.php | 3 +-- htdocs/includes/menus/barre_top/eldy_backoffice.php | 8 ++++---- htdocs/includes/menus/barre_top/eldy_frontoffice.php | 8 ++++---- htdocs/includes/menus/barre_top/rodolphe.php | 8 ++++---- htdocs/lib/functions2.lib.php | 5 +---- htdocs/product.class.php | 3 +-- 10 files changed, 19 insertions(+), 30 deletions(-) diff --git a/htdocs/admin/agenda_xcal.php b/htdocs/admin/agenda_xcal.php index 2b5cdd0e824..2b5d2eab081 100644 --- a/htdocs/admin/agenda_xcal.php +++ b/htdocs/admin/agenda_xcal.php @@ -120,8 +120,7 @@ print "<br>"; // Show message $message=''; -$pattern = str_replace('/','\/',DOL_URL_ROOT); // Add backslashes for regular expression -$urlwithouturlroot=preg_replace('/'.$pattern.'$/i','',$dolibarr_main_url_root); +$urlwithouturlroot=preg_replace('/'.preg_quote(DOL_URL_ROOT,'/').'$/i','',$dolibarr_main_url_root); $urlvcal='<a href="'.DOL_URL_ROOT.'/comm/action/agendaexport.php?format=vcal&exportkey='.($conf->global->MAIN_AGENDA_XCAL_EXPORTKEY?urlencode($conf->global->MAIN_AGENDA_XCAL_EXPORTKEY):'...').'" target="_blank">'.$urlwithouturlroot.DOL_URL_ROOT.'/comm/action/agendaexport.php?format=vcal&exportkey='.($conf->global->MAIN_AGENDA_XCAL_EXPORTKEY?urlencode($conf->global->MAIN_AGENDA_XCAL_EXPORTKEY):'KEYNOTDEFINED').'</a>'; $message.=$langs->trans("WebCalUrlForVCalExport",'vcal',$urlvcal); $message.='<br>'; diff --git a/htdocs/admin/paybox.php b/htdocs/admin/paybox.php index 5d69bde5fc8..f89c85f1146 100644 --- a/htdocs/admin/paybox.php +++ b/htdocs/admin/paybox.php @@ -160,9 +160,7 @@ print '<br><br>'; print '<u>'.$langs->trans("FollowingUrlAreAvailableToMakePayments").':</u><br>'; // Should work with DOL_URL_ROOT='' or DOL_URL_ROOT='/dolibarr' $firstpart=$dolibarr_main_url_root; -$pattern = str_replace('/','\/',DOL_URL_ROOT); // Add backslashes for regular expression -$regex='/'.$pattern.'$/i'; -$firstpart=preg_replace($regex,'',$firstpart); +$firstpart=preg_replace('/'.preg_quote(DOL_URL_ROOT,'/').'$/i','',$firstpart); print '<br>'; print img_picto('','puce.png').' '.$langs->trans("ToOfferALinkForOnlinePaymentOnFreeAmount",$servicename).':<br>'; print '<b>'.$firstpart.DOL_URL_ROOT.'/public/paybox/newpayment.php?amount=<i>9.99</i>&tag=<i>your_free_tag</i></b>'."<br>\n"; diff --git a/htdocs/admin/webcalendar.php b/htdocs/admin/webcalendar.php index e1790a6b50e..dba39f15403 100644 --- a/htdocs/admin/webcalendar.php +++ b/htdocs/admin/webcalendar.php @@ -313,8 +313,7 @@ print "<br>"; // Show message $message=''; -$pattern = str_replace('/','\/',DOL_URL_ROOT); // Add backslashes for regular expression -$urlwithouturlroot=preg_replace('/'.$pattern.'$/i','',$dolibarr_main_url_root); +$urlwithouturlroot=preg_replace('/'.preg_quote(DOL_URL_ROOT,'/').'$/i','',$dolibarr_main_url_root); $urlvcal='<a href="'.DOL_URL_ROOT.'/webcal/webcalexport.php?format=vcal&exportkey='.$conf->global->PHPWEBCALENDAR_PASSWORD_VCALEXPORT.'" target="_blank">'.$urlwithouturlroot.DOL_URL_ROOT.'/webcal/webcalexport.php?format=vcal&exportkey='.$conf->global->PHPWEBCALENDAR_PASSWORD_VCALEXPORT.'</a>'; $message.=$langs->trans("WebCalUrlForVCalExport",'vcal',$urlvcal); $message.='<br>'; diff --git a/htdocs/admin/webservices.php b/htdocs/admin/webservices.php index 75734829918..6381349df9d 100644 --- a/htdocs/admin/webservices.php +++ b/htdocs/admin/webservices.php @@ -92,9 +92,7 @@ print '<br><br>'; // Should work with DOL_URL_ROOT='' or DOL_URL_ROOT='/dolibarr' $firstpart=$dolibarr_main_url_root; -$pattern = str_replace('/','\/',DOL_URL_ROOT); // Add backslashes for regular expression -$regex='/'.$pattern.'$/i'; -$firstpart=preg_replace($regex,'',$firstpart); +$firstpart=preg_replace('/'.preg_quote(DOL_URL_ROOT,'/').'$/i','',$firstpart); print '<u>'.$langs->trans("WSDLCanBeDownloadedHere").':</u><br>'; $url=$firstpart.DOL_URL_ROOT.'/webservices/server.php?wsdl'; diff --git a/htdocs/categories/categorie.class.php b/htdocs/categories/categorie.class.php index a9fd66fa19a..02e9339b867 100644 --- a/htdocs/categories/categorie.class.php +++ b/htdocs/categories/categorie.class.php @@ -1091,8 +1091,7 @@ class Categorie { $dir = dirname($file).'/'; // Chemin du dossier contenant l'image d'origine $dirthumb = $dir.'/thumbs/'; // Chemin du dossier contenant la vignette - $dir = str_replace('/','\/',$dir); // Add backslashes for regular expression - $filename = preg_replace('/'.$dir.'/i','',$file); // Nom du fichier + $filename = preg_replace('/'.preg_quote($dir,'/').'/i','',$file); // Nom du fichier // On efface l'image d'origine dol_delete_file($file,1); diff --git a/htdocs/includes/menus/barre_top/eldy_backoffice.php b/htdocs/includes/menus/barre_top/eldy_backoffice.php index 07dfed3d796..e119e82fa79 100644 --- a/htdocs/includes/menus/barre_top/eldy_backoffice.php +++ b/htdocs/includes/menus/barre_top/eldy_backoffice.php @@ -292,8 +292,8 @@ class MenuTop { if (! empty($conf->telephonie->enabled) && $user->rights->telephonie->lire) { $class=""; - $pattern = str_replace('/','\/',DOL_URL_ROOT); // Add backslashes for regular expression - if (preg_match("/^".$pattern."\/telephonie\//",$_SERVER["PHP_SELF"])) + $path = DOL_URL_ROOT.'/telephonie/'; + if (preg_match("/^".preg_quote($path,'/')."/i",$_SERVER["PHP_SELF"])) { $class='class="tmenusel"'; $_SESSION['idmenu']=''; } @@ -313,8 +313,8 @@ class MenuTop { { $langs->load("energy"); $class=""; - $pattern = str_replace('/','\/',DOL_URL_ROOT); // Add backslashes for regular expression - if (preg_match("/^".$pattern."\/energie\//",$_SERVER["PHP_SELF"])) + $path = DOL_URL_ROOT.'/energie/'; + if (preg_match('/^'.preg_quote($path,'/').'/i',$_SERVER["PHP_SELF"])) { $class='class="tmenusel"'; $_SESSION['idmenu']=''; } diff --git a/htdocs/includes/menus/barre_top/eldy_frontoffice.php b/htdocs/includes/menus/barre_top/eldy_frontoffice.php index 0d14b9d9a08..f8b8d620e02 100644 --- a/htdocs/includes/menus/barre_top/eldy_frontoffice.php +++ b/htdocs/includes/menus/barre_top/eldy_frontoffice.php @@ -292,8 +292,8 @@ class MenuTop { if (! empty($conf->telephonie->enabled) && $user->rights->telephonie->lire) { $class=""; - $pattern = str_replace('/','\/',DOL_URL_ROOT); // Add backslashes for regular expression - if (preg_match("/^".$pattern."\/telephonie\//",$_SERVER["PHP_SELF"])) + $path = DOL_URL_ROOT.'/telephonie/'; + if (preg_match('/^'.preg_quote($path,'/').'/i',$_SERVER["PHP_SELF"])) { $class='class="tmenusel"'; $_SESSION['idmenu']=''; } @@ -313,8 +313,8 @@ class MenuTop { { $langs->load("energy"); $class=""; - $pattern = str_replace('/','\/',DOL_URL_ROOT); // Add backslashes for regular expression - if (preg_match("/^".$pattern."\/energie\//",$_SERVER["PHP_SELF"])) + $path = DOL_URL_ROOT.'/energie/'; + if (preg_match('/^'.preg_quote($path,'/').'/i',$_SERVER["PHP_SELF"])) { $class='class="tmenusel"'; $_SESSION['idmenu']=''; } diff --git a/htdocs/includes/menus/barre_top/rodolphe.php b/htdocs/includes/menus/barre_top/rodolphe.php index e37d362211d..d3929848230 100644 --- a/htdocs/includes/menus/barre_top/rodolphe.php +++ b/htdocs/includes/menus/barre_top/rodolphe.php @@ -249,8 +249,8 @@ class MenuTop { if ($conf->telephonie->enabled && $user->rights->telephonie->lire) { $class=""; - $pattern = str_replace('/','\/',DOL_URL_ROOT); // Add backslashes for regular expression - if (preg_match("/^".$pattern."\/telephonie\//",$_SERVER["PHP_SELF"])) + $path = DOL_URL_ROOT.'/telephonie/'; + if (preg_match('/^'.preg_quote($path,'/').'/i',$_SERVER["PHP_SELF"])) { $class='class="tmenusel"'; $_SESSION['idmenu']=''; } @@ -268,8 +268,8 @@ class MenuTop { { $langs->load("energy"); $class=""; - $pattern = str_replace('/','\/',DOL_URL_ROOT); // Add backslashes for regular expression - if (preg_match("/^".$pattern."\/energie\//",$_SERVER["PHP_SELF"])) + $path = DOL_URL_ROOT.'/energie/'; + if (preg_match('/^'.preg_quote($path,'/').'/i',$_SERVER["PHP_SELF"])) { $class='class="tmenusel"'; $_SESSION['idmenu']=''; } diff --git a/htdocs/lib/functions2.lib.php b/htdocs/lib/functions2.lib.php index fe5b5951d5a..70862e6237d 100644 --- a/htdocs/lib/functions2.lib.php +++ b/htdocs/lib/functions2.lib.php @@ -300,12 +300,9 @@ function clean_url($url,$http=1) $newproto = ''; } } - - // Add backslashes for regular expression - $proto = str_replace('/','\/',$proto); // On passe le nom de domaine en minuscule - $CleanUrl = preg_replace('/^'.$proto.$domain.'/i', $newproto.strtolower($domain), $url); + $CleanUrl = preg_replace('/^'.preg_quote($proto.$domain,'/').'/i', $newproto.strtolower($domain), $url); return $CleanUrl; } diff --git a/htdocs/product.class.php b/htdocs/product.class.php index 5c42c755401..1f73c8df6b5 100644 --- a/htdocs/product.class.php +++ b/htdocs/product.class.php @@ -2546,8 +2546,7 @@ class Product extends CommonObject { $dir = dirname($file).'/'; // Chemin du dossier contenant l'image d'origine $dirthumb = $dir.'/thumbs/'; // Chemin du dossier contenant la vignette - $pattern = str_replace('/','\/',$dir); // Add backslashes for regular expression - $filename = preg_replace('/'.$pattern.'/i','',$file); // Nom du fichier + $filename = preg_replace('/'.preg_quote($dir,'/').'/i','',$file); // Nom du fichier // On efface l'image d'origine dol_delete_file($file); -- GitLab