2 // $Id: checker.php,v 1.5 2009/01/02 09:30:50 henoheno Exp $
3 // Concept-work of spam-uri metrics
4 // Copyright (C) 2006-2007 PukiWiki Developers Team
5 // License: GPL v2 or (at your option) any later version
7 error_reporting(E_ALL); // Debug purpose
10 require('spam_pickup.php');
12 // Recursive array_map()
13 // e.g. Sanitilze ALL values (Debug purpose): var_dump(recursive_map('htmlspecialchars', $array));
14 function recursive_map($func, $array)
16 if (is_array($array)) {
17 if (! empty($array)) {
18 $array = array_map('recursive_map',
19 array_fill(0, count($array), $func), $array);
22 $array = $func($array);
27 function show_form($string, $asap = FALSE, $progress = TRUE, $pickup = TRUE)
29 $string = htmlspecialchars($string);
30 $asap = $asap ? ' checked' : '';
31 $progress = $progress ? ' checked' : '';
32 $pickup = $pickup ? ' checked' : '';
33 $base = basename(__FILE__);
36 <form action="$base" method="post">
38 <textarea name="msg" rows="8" cols="80">$string</textarea><br />
40 <input type="checkbox" name="asap" id="asap" value="on"$asap>
41 <label for="asap">asap</label><br />
43 <input type="checkbox" name="progress" id="progress" value="on"$progress>
44 <label for="progress">Show \$progress</label><br />
46 <input type="checkbox" name="pickup" id="pickup" value="on"$pickup>
47 <label for="pickup">Show pickuped URIs</label><br />
49 <input type="submit" name="write" value="Submit" />
57 // ---- Show form and result
58 echo basename(__FILE__) . '<br />';
60 $msg = isset($_POST['msg']) ? $_POST['msg'] : '';
61 $asap = isset($_POST['asap']) ? TRUE : FALSE;
62 $prog = isset($_POST['progress']) ? TRUE : FALSE;
63 $pickup = isset($_POST['pickup']) ? TRUE : FALSE;
65 echo show_form(stripslashes($msg), $asap, $prog, $pickup);
69 // -----------------------------------------------------
72 // Threshold and rules for insertion (default)
73 $spam['method']['_default'] = array(
74 '_comment' => '_default',
82 //'asap' => TRUE, // Stop as soon as possible (quick but less-info)
87 // Any thresholds may LOCK your contents by
88 // "posting one URL" many times.
89 // Any rules will lock contents that have NG things already.
90 $spam['method']['edit'] = array(
91 // Supposed_by_you(n) * Edit_form_spec(2) * Margin(1.5)
93 //'quantity' => 60 * 3,
94 //'non_uniquri' => 5 * 3,
95 //'non_uniqhost' => 50 * 3,
96 //'area_anchor' => 30 * 3,
97 //'area_bbcode' => 15 * 3,
104 $method = & $spam['method']['_default'];
105 //$method = & $spam['method']['edit'];
106 //$method = check_uri_spam_method();
108 // -----------------------------------------------------
110 if ($asap) $method['asap'] = TRUE;
112 $progress = check_uri_spam(
114 'a http://foobaA.example.com',
116 'b http://foobarB.example.com'
119 if (! empty($progress)) {
122 if (empty($progress['is_spam'])) {
123 echo 'ACTION: Seems not a spam';
126 echo 'ACTION: Blocked by ' . summarize_spam_progress($progress, TRUE);
130 echo 'METRICS: ' . summarize_spam_progress($progress) . '<br />' . "\n";
133 $action = 'Blocked by: ' . summarize_spam_progress($progress, TRUE);
135 $tmp = summarize_detail_badhost($progress);
137 echo 'DETAIL_BADHOST: ' .
138 str_replace(' ', ' ', nl2br(htmlspecialchars($tmp). "\n"));
142 $tmp = summarize_detail_newtral($progress);
143 if (! $asap && $tmp != '') {
144 echo 'DETAIL_NEUTRAL_HOST: ' .
145 str_replace(' ', ' ', nl2br(htmlspecialchars($tmp). "\n"));
150 echo '$progress:' . "\n";
151 echo htmlspecialchars(var_export($progress, TRUE));
158 $results = spam_uri_pickup($msg);
159 $results = uri_pickup_normalize($results);
160 $results = uri_pickup_normalize_pathfile($results);
161 echo '$results:' . "\n";
162 echo htmlspecialchars(var_export($results, TRUE));