From 2ce3cc1da9b3ab31d44e82646fdc73a2a68abc55 Mon Sep 17 00:00:00 2001 From: Sebastian Mendel Date: Wed, 12 Apr 2006 16:41:27 +0000 Subject: [PATCH] - added option to PMA_arrayWalkRecursive() to use function also on keys - un-magic_quotes_gpc also keys in GPC arrays --- ChangeLog | 3 +++ libraries/common.lib.php | 20 ++++++++++++++------ 2 files changed, 17 insertions(+), 6 deletions(-) diff --git a/ChangeLog b/ChangeLog index 8d20e0e62..e963ac234 100755 --- a/ChangeLog +++ b/ChangeLog @@ -6,6 +6,9 @@ $Id$ $Source$ 2006-04-12 Sebastian Mendel + * libraries/common.lib.php: + - added option to PMA_arrayWalkRecursive() to use function also on keys + - un-magic_quotes_gpc also keys in GPC arrays * libraries/db_table_exists.lib.php: cleanup - what a mess; fixed several undefined variables * tbl_printview.php: diff --git a/libraries/common.lib.php b/libraries/common.lib.php index c00946196..15a344344 100644 --- a/libraries/common.lib.php +++ b/libraries/common.lib.php @@ -501,14 +501,22 @@ function PMA_array_merge_recursive() * @param array $array array to walk * @param string $function function to call for every array element */ -function PMA_arrayWalkRecursive(&$array, $function) +function PMA_arrayWalkRecursive(&$array, $function, $apply_to_keys_also = false) { foreach ($array as $key => $value) { if (is_array($value)) { - PMA_arrayWalkRecursive($array[$key], $function); + PMA_arrayWalkRecursive($array[$key], $function, $apply_to_keys_also); } else { $array[$key] = $function($value); } + + if ($apply_to_keys_also && is_string($key)) { + $new_key = $function($key); + if ($new_key != $key) { + $array[$new_key] = $array[$key]; + unset($array[$key]); + } + } } } @@ -2635,10 +2643,10 @@ if (isset($_POST['usesubform'])) { // end check if a subform is submitted if (get_magic_quotes_gpc()) { - PMA_arrayWalkRecursive($_GET, 'stripslashes'); - PMA_arrayWalkRecursive($_POST, 'stripslashes'); - PMA_arrayWalkRecursive($_COOKIE, 'stripslashes'); - PMA_arrayWalkRecursive($_REQUEST, 'stripslashes'); + PMA_arrayWalkRecursive($_GET, 'stripslashes', true); + PMA_arrayWalkRecursive($_POST, 'stripslashes', true); + PMA_arrayWalkRecursive($_COOKIE, 'stripslashes', true); + PMA_arrayWalkRecursive($_REQUEST, 'stripslashes', true); } require_once './libraries/session.inc.php';