<?php
-// $Id: spam_pickup.php,v 1.24 2006/12/16 01:55:15 henoheno Exp $
+// $Id: spam_pickup.php,v 1.42 2007/03/04 10:43:46 henoheno Exp $
// Concept-work of spam-uri metrics
-// Copyright (C) 2006 PukiWiki Developers Team
+// Copyright (C) 2006-2007 PukiWiki Developers Team
// License: GPL v2 or (at your option) any later version
error_reporting(E_ALL); // Debug purpose
return $array;
}
-// $array[0] => $array['name']
-function array_rename_key(& $array, $from, $to, $force = FALSE, $default = '')
+function show_form($string, $asap = FALSE, $progress = TRUE, $pickup = TRUE)
{
- if (isset($array[$from])) {
- $array[$to] = & $array[$from];
- unset($array[$from]);
- } else if ($force) {
- $array[$to] = $default;
- } else {
- return FALSE;
- }
- return TRUE;
-}
+ $string = htmlspecialchars($string);
+ $asap = $asap ? ' checked' : '';
+ $progress = $progress ? ' checked' : '';
+ $pickup = $pickup ? ' checked' : '';
+ $base = basename(__FILE__);
-function show_form($string)
-{
- $base = basename(__FILE__);
- $string = htmlspecialchars($string);
- print <<< EOF
+ return <<< EOF
<form action="$base" method="post">
+
<textarea name="msg" rows="8" cols="80">$string</textarea><br />
+
+ <input type="checkbox" name="asap" id="asap" value="on"$asap>
+ <label for="asap">asap</label><br />
+
+ <input type="checkbox" name="progress" id="progress" value="on"$progress>
+ <label for="progress">Show \$progress</label><br />
+
+ <input type="checkbox" name="pickup" id="pickup" value="on"$pickup>
+ <label for="pickup">Show pickuped URIs</label><br />
+
<input type="submit" name="write" value="Submit" />
+
</form>
-<br/>
EOF;
+
}
// ---- Show form and result
echo basename(__FILE__) . '<br />';
-$msg = isset($_POST['msg']) ? $_POST['msg'] : '';
-show_form($msg);
-echo '<pre>';
-$pickup = TRUE;
-$progress = array();
-$progress = check_uri_spam(array('a', $msg, 'b'), array(), FALSE);
+$msg = isset($_POST['msg']) ? $_POST['msg'] : '';
+$asap = isset($_POST['asap']) ? TRUE : FALSE;
+$prog = isset($_POST['progress']) ? TRUE : FALSE;
+$pickup = isset($_POST['pickup']) ? TRUE : FALSE;
+
+echo show_form($msg, $asap, $prog, $pickup);
+echo '<br/>';
+
+
+// -----------------------------------------------------
+ $spam = array();
+
+ // Threshold and rules for insertion (default)
+ $spam['method']['_default'] = array(
+ '_comment' => '_default',
+ 'quantity' => 8,
+ //'non_uniquri' => 3,
+ 'non_uniqhost' => 3,
+ 'area_anchor' => 0,
+ 'area_bbcode' => 0,
+ 'uniqhost' => TRUE,
+ 'badhost' => TRUE,
+ //'asap' => TRUE, // Stop as soon as possible (quick but less-info)
+ );
+
+ // For editing
+ // NOTE:
+ // Any thresholds may LOCK your contents by
+ // "posting one URL" many times.
+ // Any rules will lock contents that have NG things already.
+ $spam['method']['edit'] = array(
+ // Supposed_by_you(n) * Edit_form_spec(2) * Margin(1.5)
+ '_comment' => 'edit',
+ //'quantity' => 60 * 3,
+ //'non_uniquri' => 5 * 3,
+ //'non_uniqhost' => 50 * 3,
+ //'area_anchor' => 30 * 3,
+ //'area_bbcode' => 15 * 3,
+ 'uniqhost' => TRUE,
+ 'badhost' => TRUE,
+ //'asap' => TRUE,
+ );
+
+
+$method = & $spam['method']['_default'];
+//$method = & $spam['method']['edit'];
+//$method = check_uri_spam_method();
+//var_dump($method);
+// -----------------------------------------------------
+
+if ($asap) $method['asap'] = TRUE;
+
+$progress = check_uri_spam(
+ array(
+ 'a http://foobaA.example.com',
+ $msg,
+ 'b http://foobarB.example.com'
+ ), $method);
if (! empty($progress)) {
- $action = 'Metrics: ' . summarize_spam_progress($progress, FALSE);
- var_dump($action);
- if (! empty($progress['is_spam'])) {
+
+
+ if (empty($progress['is_spam'])) {
+ echo 'ACTION: Seems not a spam';
+ echo '<br />';
+ } else {
+ echo 'ACTION: Blocked by ' . summarize_spam_progress($progress, TRUE);
+ echo '<br />';
+
+ if (! $asap) {
+ echo 'METRICS: ' . summarize_spam_progress($progress);
+ echo '<br />';
+ }
+
$action = 'Blocked by: ' . summarize_spam_progress($progress, TRUE);
- var_dump($action);
+ if (isset($progress['is_spam']['badhost'])) {
+ $badhost = array();
+ foreach($progress['is_spam']['badhost'] as $glob=>$number) {
+ $badhost[] = $glob . '(' . $number . ')';
+ }
+ echo 'DETAIL_BADHOST: ' . htmlspecialchars(implode(', ', $badhost));
+ echo '<br />';
+ }
+ }
+
+ if (isset($progress['remains']['badhost'])) {
+ $count = count($progress['remains']['badhost']);
+ echo 'DETAIL_NEUTRAL_HOST: ' . $count .
+ ' (' .
+ htmlspecialchars(
+ preg_replace(
+ '/[^, a-z0-9.-]/i',
+ '',
+ implode(', ', array_keys($progress['remains']['badhost']))
+ )
+ ) .
+ ')';
+ echo '<br />';
+ }
+
+ if ($prog) {
+ echo '<pre>';
+ htmlspecialchars(var_dump($progress));
+ echo '</pre>';
}
}
if ($pickup) {
+ echo '<pre>';
$results = spam_uri_pickup($msg);
$results = uri_array_normalize($results, TRUE);
- var_dump('$results', $results);
+ htmlspecialchars(var_dump('$results', $results));
+ echo '</pre>';
}
-echo '</pre>';
+
?>