修訂 | 6b30a7efd3f4baa495cffad7f8fd0f6e56ac838d (tree) |
---|---|
時間 | 2007-07-29 22:05:15 |
作者 | henoheno <henoheno> |
Commiter | henoheno |
$Id: spam.php,v 1.200 2007/07/29 12:59:24 henoheno Exp $
* Ressurect array_merge_leaves() to preserve numeric keys
* isser($sum['uniqhost'])
@@ -1,5 +1,5 @@ | ||
1 | 1 | <?php |
2 | -// $Id: spam.php,v 1.30 2007/07/03 14:53:35 henoheno Exp $ | |
2 | +// $Id: spam.php,v 1.31 2007/07/29 13:05:15 henoheno Exp $ | |
3 | 3 | // Copyright (C) 2006-2007 PukiWiki Developers Team |
4 | 4 | // License: GPL v2 or (at your option) any later version |
5 | 5 | // |
@@ -161,6 +161,44 @@ function array_count_leaves($array = array(), $count_empty = FALSE) | ||
161 | 161 | return $count; |
162 | 162 | } |
163 | 163 | |
164 | +// Merge two leaves | |
165 | +// Similar to PHP array_merge_leaves(), except strictly preserving keys as string | |
166 | +function array_merge_leaves($array1, $array2, $sort_keys = TRUE) | |
167 | +{ | |
168 | + // Array(s) only | |
169 | + $is_array1 = is_array($array1); | |
170 | + $is_array2 = is_array($array2); | |
171 | + if ($is_array1) { | |
172 | + if ($is_array2) { | |
173 | + ; // Pass | |
174 | + } else { | |
175 | + return $array1; | |
176 | + } | |
177 | + } else if ($is_array2) { | |
178 | + return $array2; | |
179 | + } else { | |
180 | + return $array2; // Not array ($array1 is overwritten) | |
181 | + } | |
182 | + | |
183 | + $keys_all = array_merge(array_keys($array1), array_keys($array2)); | |
184 | + if ($sort_keys) sort($keys_all, SORT_STRING); | |
185 | + | |
186 | + $result = array(); | |
187 | + foreach($keys_all as $key) { | |
188 | + $isset1 = isset($array1[$key]); | |
189 | + $isset2 = isset($array2[$key]); | |
190 | + if ($isset1 && $isset2) { | |
191 | + // Recurse | |
192 | + $result[$key] = array_merge_leaves($array1[$key], $array2[$key], $sort_keys); | |
193 | + } else if ($isset1) { | |
194 | + $result[$key] = & $array1[$key]; | |
195 | + } else { | |
196 | + $result[$key] = & $array2[$key]; | |
197 | + } | |
198 | + } | |
199 | + return $result; | |
200 | +} | |
201 | + | |
164 | 202 | // An array-leaves to a flat array |
165 | 203 | function array_flat_leaves($array, $unique = TRUE) |
166 | 204 | { |
@@ -529,8 +567,8 @@ function check_uri_spam($target = '', $method = array()) | ||
529 | 567 | if ($asap && $is_spam) break; |
530 | 568 | |
531 | 569 | // Merge only |
532 | - $blocked = array_merge_recursive($blocked, $_progress['blocked']); | |
533 | - $hosts = array_merge_recursive($hosts, $_progress['hosts']); | |
570 | + $blocked = array_merge_leaves($blocked, $_progress['blocked'], FALSE); | |
571 | + $hosts = array_merge_leaves($hosts, $_progress['hosts'], FALSE); | |
534 | 572 | } |
535 | 573 | |
536 | 574 | // Unique values |
@@ -646,7 +684,7 @@ function check_uri_spam($target = '', $method = array()) | ||
646 | 684 | // Host: Uniqueness (uniq / non-uniq) |
647 | 685 | foreach ($pickups as $pickup) $hosts[] = & $pickup['host']; |
648 | 686 | $hosts = array_unique($hosts); |
649 | - $sum['uniqhost'] += count($hosts); | |
687 | + if (isset($sum['uniqhost'])) $sum['uniqhost'] += count($hosts); | |
650 | 688 | if ((! $asap || ! $is_spam) && isset($method['non_uniqhost'])) { |
651 | 689 | $sum['non_uniqhost'] = $sum['quantity'] - $sum['uniqhost']; |
652 | 690 | if ($sum['non_uniqhost'] > $method['non_uniqhost']) { |
@@ -746,7 +784,7 @@ function summarize_detail_newtral($progress = array()) | ||
746 | 784 | } else { |
747 | 785 | $rest = rtrim(substr($value, 0, - strlen($resp)), '.'); // 'A.foo.bar' |
748 | 786 | } |
749 | - $trie = array_merge_recursive($trie, array($resp => array($rest => NULL))); | |
787 | + $trie = array_merge_leaves($trie, array($resp => array($rest => NULL)), FALSE); | |
750 | 788 | } |
751 | 789 | |
752 | 790 | // Format: var_export_shrink() -like output |