OSDN Git Service

Functions to functions
[pukiwiki/pukiwiki_sandbox.git] / spam / checker.php
1 <?php
2 // $Id: checker.php,v 1.9 2011/01/25 13:16:35 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
6
7 error_reporting(E_ALL); // Debug purpose
8
9 if (! defined('CONTENT_CHARSET')) define('CONTENT_CHARSET', 'ISO-8859-1');
10 require('spam.php');
11
12 // Recursive array_map()
13 // e.g. Sanitilze ALL values (Debug purpose): var_dump(recursive_map('htmlsc', $array));
14 function recursive_map($func, $array)
15 {
16         if (is_array($array)) {
17                 if (! empty($array)) {
18                         $array = array_map('recursive_map',
19                                  array_fill(0, count($array), $func), $array);
20                 }
21         } else {
22                 $array = $func($array);
23         }
24         return $array;
25 }
26
27 function show_form($string, $asap = FALSE, $progress = TRUE, $pickup = TRUE)
28 {
29         $string   = htmlsc($string);
30         $asap     = $asap     ? ' checked' : '';
31         $progress = $progress ? ' checked' : '';
32         $pickup   = $pickup   ? ' checked' : '';
33         $base     = basename(__FILE__);
34
35         return <<< EOF
36 <form action="$base" method="post">
37
38         <textarea name="msg" rows="8" cols="80">$string</textarea><br />
39
40         <input type="checkbox" name="asap"   id="asap"   value="on"$asap>
41         <label for="asap">asap</label><br />
42
43         <input type="checkbox" name="progress" id="progress" value="on"$progress>
44         <label for="progress">Show \$progress</label><br />
45
46         <input type="checkbox" name="pickup" id="pickup" value="on"$pickup>
47         <label for="pickup">Show pickuped URIs</label><br />
48
49         <input type="submit" name="write" value="Submit" />
50
51 </form>
52 EOF;
53
54 }
55
56
57 // ---- Show form and result
58 echo basename(__FILE__) . '<br />';
59
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;
64
65 echo show_form(stripslashes($msg), $asap, $prog, $pickup);
66 echo '<br/>';
67
68
69 // -----------------------------------------------------
70         $spam = array();
71
72         // Threshold and rules for insertion (default)
73         $spam['method']['_default'] = array(
74                 '_comment'     => '_default',
75                 'quantity'     =>  8,
76                 //'non_uniquri'  =>  3,
77                 'non_uniqhost' =>  3,
78                 'area_anchor'  =>  0,
79                 'area_bbcode'  =>  0,
80                 'uniqhost'     => TRUE,
81                 'badhost'      => TRUE,
82                 //'asap'         => TRUE, // Stop as soon as possible (quick but less-info)
83         );
84         
85         // For editing
86         // NOTE:
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)
92                 '_comment'       => 'edit',
93                 'quantity'       => 150 * 1.5,
94                 'non_uniq'       =>   5 * 1.5,
95                 //'non_uniquri'  =>   5 * 1.5,
96                 //'non_uniqhost' =>  50 * 1.5,
97                 'area_anchor'    =>   3 * 1.5,
98                 'area_bbcode'    =>   1 * 1.5,
99                 'uniqhost'       => TRUE,
100                 'badhost'        => TRUE,
101                 //'asap'         => TRUE,
102         );
103         
104         
105 $method = & $spam['method']['_default'];
106 //$method = & $spam['method']['edit'];
107 //$method = check_uri_spam_method();
108 //var_dump($method);
109 // -----------------------------------------------------
110
111 if ($asap) $method['asap'] = TRUE;
112
113 $progress = check_uri_spam(
114         array(
115                 'a http://foobaA.example.com',
116                 $msg,
117                 'b http://foobarB.example.com'
118         ), $method);
119
120 if (! empty($progress)) {
121
122
123         if (empty($progress['is_spam'])) {
124                 echo 'ACTION: Seems not a spam';
125                 echo '<br />';
126         } else {
127                 echo 'ACTION: Blocked by ' . summarize_spam_progress($progress, TRUE);
128                 echo '<br />';
129
130                 if (! $asap) {
131                         echo 'METRICS: ' . summarize_spam_progress($progress) . '<br />' . "\n";
132                 }
133
134                 $action = 'Blocked by: ' . summarize_spam_progress($progress, TRUE);
135
136                 $tmp = summarize_detail_badhost($progress);
137                 if ($tmp != '') {
138                         echo 'DETAIL_BADHOST: ' . 
139                                 str_replace('  ', '&nbsp; ', nl2br(htmlsc($tmp). "\n"));
140                 }
141         }
142
143         $tmp = summarize_detail_newtral($progress);
144         if (! $asap && $tmp != '') {
145                 echo 'DETAIL_NEUTRAL_HOST: ' . 
146                                 str_replace('  ', '&nbsp; ', nl2br(htmlsc($tmp). "\n"));
147         }
148         
149         if ($prog) {
150                 echo '<pre>';
151                 echo '$progress:' . "\n";
152                 echo htmlsc(var_export($progress, TRUE));
153                 echo '</pre>';
154         }
155 }
156
157 if ($pickup) {
158         echo '<pre>';
159         $results = spam_uri_pickup($msg);
160         $results = uri_pickup_normalize($results);
161         $results = uri_pickup_normalize_pathfile($results);
162         echo '$results:' . "\n";
163         echo htmlsc(var_export($results, TRUE));
164         echo '</pre>';
165 }
166 ?>