From 8a7486e8de9e7be004f747a83e9a6c97874b4ddf Mon Sep 17 00:00:00 2001 From: Luca Date: Thu, 11 Jun 2015 12:47:33 +0200 Subject: [PATCH 1/4] Return directly lambda function instead to assign it to a variable --- catalog/includes/functions/general.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/catalog/includes/functions/general.php b/catalog/includes/functions/general.php index c245d0d4a..586819e57 100644 --- a/catalog/includes/functions/general.php +++ b/catalog/includes/functions/general.php @@ -1290,7 +1290,7 @@ function tep_currency_exists($code) { // Parse and secure the cPath parameter values function tep_parse_category_path($cPath) { // make sure the category IDs are integers - $cPath_array = array_map(function ($string) { + return array_map(function ($string) { return (int)$string; }, explode('_', $cPath)); From 350cd9c245735db2aa22f3adcae41c408a2b7689 Mon Sep 17 00:00:00 2001 From: Luca Date: Thu, 11 Jun 2015 20:58:39 +0200 Subject: [PATCH 2/4] Update check for duplicate category ID removal --- catalog/includes/functions/general.php | 11 ++--------- 1 file changed, 2 insertions(+), 9 deletions(-) diff --git a/catalog/includes/functions/general.php b/catalog/includes/functions/general.php index 586819e57..549b1e0a1 100644 --- a/catalog/includes/functions/general.php +++ b/catalog/includes/functions/general.php @@ -1290,19 +1290,12 @@ function tep_currency_exists($code) { // Parse and secure the cPath parameter values function tep_parse_category_path($cPath) { // make sure the category IDs are integers - return array_map(function ($string) { + $cPath_array = array_map(function ($string) { return (int)$string; }, explode('_', $cPath)); // make sure no duplicate category IDs exist which could lock the server in a loop - $tmp_array = array(); - $n = sizeof($cPath_array); - for ($i=0; $i<$n; $i++) { - if (!in_array($cPath_array[$i], $tmp_array)) { - $tmp_array[] = $cPath_array[$i]; - } - } - + $tmp_array = array_unique($cPath_array); return $tmp_array; } From 0e6c961fd3fe058362be3c876530ea8faf051424 Mon Sep 17 00:00:00 2001 From: Luca Date: Thu, 11 Jun 2015 21:02:36 +0200 Subject: [PATCH 3/4] Remove temp_array as it is unneded --- catalog/includes/functions/general.php | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/catalog/includes/functions/general.php b/catalog/includes/functions/general.php index 549b1e0a1..5fbcc52b3 100644 --- a/catalog/includes/functions/general.php +++ b/catalog/includes/functions/general.php @@ -1295,8 +1295,7 @@ function tep_parse_category_path($cPath) { }, explode('_', $cPath)); // make sure no duplicate category IDs exist which could lock the server in a loop - $tmp_array = array_unique($cPath_array); - return $tmp_array; + return array_unique($cPath_array); } //// From 0043ccd3390882d4d145bd293f0ba488e3749e24 Mon Sep 17 00:00:00 2001 From: Luca Date: Thu, 11 Jun 2015 21:18:38 +0200 Subject: [PATCH 4/4] Change with array_flip as it is faster --- catalog/includes/functions/general.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/catalog/includes/functions/general.php b/catalog/includes/functions/general.php index 5fbcc52b3..c83ed64f9 100644 --- a/catalog/includes/functions/general.php +++ b/catalog/includes/functions/general.php @@ -1295,7 +1295,7 @@ function tep_parse_category_path($cPath) { }, explode('_', $cPath)); // make sure no duplicate category IDs exist which could lock the server in a loop - return array_unique($cPath_array); + return array_keys(array_flip($cPath_array)); } ////