From 857ee659ae8269d6a7f02207b9db0249500daf79 Mon Sep 17 00:00:00 2001 From: henoheno Date: Sun, 13 May 2007 13:50:09 +0900 Subject: [PATCH] * Disallow "hostname.", allow "hostname". * Added sort option * array_joinkey_leaf() --- spam/spam.php | 43 +++++++++++++++++++++++++++++++++++-------- 1 file changed, 35 insertions(+), 8 deletions(-) diff --git a/spam/spam.php b/spam/spam.php index dbe5fdb..8f6b899 100644 --- a/spam/spam.php +++ b/spam/spam.php @@ -1,5 +1,5 @@ "\'\[\]/\#]+)*/+)?' . // 5: Directory path or path-info @@ -1498,15 +1498,20 @@ function summarize_detail_newtral($progress = array()) array_leaf(explode('.', delimiter_reverse($value) . '.'), TRUE, $value) ); } - ksort($tmp); + ksort($tmp, SORT_STRING); + + $tmp = array_joinkey_leaf($tmp, '.', TRUE, TRUE); + $tmp = array_joinkey_leaf($tmp, '.', TRUE, FALSE); + $tmp = array_joinkey_leaf($tmp, '.', TRUE, FALSE); + //$tmp = array_joinkey_leaf($tmp, '.', TRUE, FALSE); + foreach($tmp as $key => $value) { - ksort($tmp[$key]); - foreach($value as $_key => $_value) { - ksort($tmp[$key][$_key]); - $tmp[$key][$_key] = implode(', ', array_flat_leaves($_value)); + if (is_array($value)) { + ksort($tmp[$key]); + $tmp[$key] = implode(', ', array_flat_leaves($value)); } } - + //$tmp = array_unique_recursive($tmp); // Buggy? $result = var_export_shrink($tmp, TRUE, TRUE); } @@ -1515,6 +1520,28 @@ function summarize_detail_newtral($progress = array()) } +function array_joinkey_leaf($array = array('A' => array('B' => 'C.D')), + $delim = '.', $reverse = FALSE, $allowmulti = FALSE) +{ + if (! is_array($array)) return $array; + + $result = array(); + foreach(array_keys($array) as $key) { + if (! is_array($array[$key]) || (! $allowmulti && count($array[$key]) > 1)) { + $result[$key] = & $array[$key]; // Do nothing + } else { + foreach(array_keys($array[$key]) as $_key) { + $joinkey = $reverse ? + $_key . $delim . $key : + $key . $delim . $_key; + $result[$joinkey] = & $array[$key][$_key]; + } + } + } + + return $result; // array('A.B' => 'C.D') +} + // --------------------- // Exit -- 2.11.0