• R/O
  • HTTP
  • SSH
  • HTTPS

Commit

Tags
No Tags

Frequently used words (click to add to your profile)

javac++androidlinuxc#windowsobjective-ccocoa誰得qtpythonphprubygameguibathyscaphec計画中(planning stage)翻訳omegatframeworktwitterdomtestvb.netdirectxゲームエンジンbtronarduinopreviewer

Commit MetaInfo

Revisión6b30a7efd3f4baa495cffad7f8fd0f6e56ac838d (tree)
Tiempo2007-07-29 22:05:15
Autorhenoheno <henoheno>
Commiterhenoheno

Log Message

$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'])

Cambiar Resumen

Diferencia incremental

--- a/lib/spam.php
+++ b/lib/spam.php
@@ -1,5 +1,5 @@
11 <?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 $
33 // Copyright (C) 2006-2007 PukiWiki Developers Team
44 // License: GPL v2 or (at your option) any later version
55 //
@@ -161,6 +161,44 @@ function array_count_leaves($array = array(), $count_empty = FALSE)
161161 return $count;
162162 }
163163
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+
164202 // An array-leaves to a flat array
165203 function array_flat_leaves($array, $unique = TRUE)
166204 {
@@ -529,8 +567,8 @@ function check_uri_spam($target = '', $method = array())
529567 if ($asap && $is_spam) break;
530568
531569 // 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);
534572 }
535573
536574 // Unique values
@@ -646,7 +684,7 @@ function check_uri_spam($target = '', $method = array())
646684 // Host: Uniqueness (uniq / non-uniq)
647685 foreach ($pickups as $pickup) $hosts[] = & $pickup['host'];
648686 $hosts = array_unique($hosts);
649- $sum['uniqhost'] += count($hosts);
687+ if (isset($sum['uniqhost'])) $sum['uniqhost'] += count($hosts);
650688 if ((! $asap || ! $is_spam) && isset($method['non_uniqhost'])) {
651689 $sum['non_uniqhost'] = $sum['quantity'] - $sum['uniqhost'];
652690 if ($sum['non_uniqhost'] > $method['non_uniqhost']) {
@@ -746,7 +784,7 @@ function summarize_detail_newtral($progress = array())
746784 } else {
747785 $rest = rtrim(substr($value, 0, - strlen($resp)), '.'); // 'A.foo.bar'
748786 }
749- $trie = array_merge_recursive($trie, array($resp => array($rest => NULL)));
787+ $trie = array_merge_leaves($trie, array($resp => array($rest => NULL)), FALSE);
750788 }
751789
752790 // Format: var_export_shrink() -like output