OSDN Git Service

* Simplify $method['area'] => $method, 'anchor' => 'area_anchor', 'bbcode' => 'area_b...
[pukiwiki/pukiwiki_sandbox.git] / spam / spam_pickup.php
1 <?php
2 // $Id: spam_pickup.php,v 1.24 2006/12/16 01:55:15 henoheno Exp $
3 // Concept-work of spam-uri metrics
4 // Copyright (C) 2006 PukiWiki Developers Team
5 // License: GPL v2 or (at your option) any later version
6
7 error_reporting(E_ALL); // Debug purpose
8
9 require('spam.php');
10
11 // Recursive array_map()
12 // e.g. Sanitilze ALL values (Debug purpose): var_dump(recursive_map('htmlspecialchars', $array));
13 function recursive_map($func, $array)
14 {
15         if (is_array($array)) {
16                 if (! empty($array)) {
17                         $array = array_map('recursive_map',
18                                  array_fill(0, count($array), $func), $array);
19                 }
20         } else {
21                 $array = $func($array);
22         }
23         return $array;
24 }
25
26 // $array[0] => $array['name']
27 function array_rename_key(& $array, $from, $to, $force = FALSE, $default = '')
28 {
29         if (isset($array[$from])) {
30                 $array[$to] = & $array[$from];
31                 unset($array[$from]);
32         } else if ($force) {
33                 $array[$to] = $default;
34         } else {
35                 return FALSE;
36         }
37         return TRUE;
38 }
39
40 function show_form($string)
41 {
42         $base = basename(__FILE__);
43         $string = htmlspecialchars($string);
44         print <<< EOF
45 <form action="$base" method="post">
46         <textarea name="msg" rows="8" cols="80">$string</textarea><br />
47         <input type="submit" name="write" value="Submit" />
48 </form>
49 <br/>
50 EOF;
51 }
52
53
54 // ---- Show form and result
55 echo basename(__FILE__) . '<br />';
56 $msg = isset($_POST['msg']) ? $_POST['msg'] : '';
57 show_form($msg);
58 echo '<pre>';
59
60 $pickup = TRUE;
61 $progress = array();
62 $progress = check_uri_spam(array('a', $msg, 'b'), array(), FALSE);
63
64 if (! empty($progress)) {
65         $action = 'Metrics: ' . summarize_spam_progress($progress, FALSE);
66         var_dump($action);
67         if (! empty($progress['is_spam'])) {
68                 $action = 'Blocked by: ' . summarize_spam_progress($progress, TRUE);
69                 var_dump($action);
70         }
71 }
72
73 if ($pickup) {
74         $results = spam_uri_pickup($msg);
75         $results = uri_array_normalize($results, TRUE);
76         var_dump('$results', $results);
77 }
78 echo '</pre>';
79
80 ?>