OSDN Git Service

spam_uri_removing_hocus_pocus(): Remove/Replace quoted-spaces within tags
authorhenoheno <henoheno>
Sat, 15 Sep 2007 15:55:29 +0000 (00:55 +0900)
committerhenoheno <henoheno>
Sat, 15 Sep 2007 15:55:29 +0000 (00:55 +0900)
spam/spam_pickup.php

index 82c387e..bc53b56 100644 (file)
@@ -1,5 +1,5 @@
 <?php
-// $Id: spam_pickup.php,v 1.59 2007/09/13 13:02:53 henoheno Exp $
+// $Id: spam_pickup.php,v 1.60 2007/09/15 15:55:29 henoheno Exp $
 // Copyright (C) 2006-2007 PukiWiki Developers Team
 // License: GPL v2 or (at your option) any later version
 //
@@ -605,9 +605,12 @@ function area_measure($areas, & $array, $belief = -1, $a_key = 'area', $o_key =
 // ---------------------
 // Spam-uri pickup
 
-// Preprocess: Removing uninterest part for URI detection
+// Preprocess: Removing/Modifying uninterest part for URI detection
 function spam_uri_removing_hocus_pocus($binary = '', $method = array())
 {
+       $from = $to = array();
+
+       // Remove sequential spaces and too short lines
        $length = 4 ; // 'http'(1) and '://'(2) and 'fqdn'(1)
        if (is_array($method)) {
                // '<a'(2) or 'href='(5) or '>'(1) or '</a>'(4)
@@ -616,14 +619,17 @@ function spam_uri_removing_hocus_pocus($binary = '', $method = array())
                    isset($method['area_bbcode']) || isset($method['uri_bbcode']))
                                $length = 1;    // Seems not effective
        }
-
-       // Removing sequential spaces and too short lines
        $binary = strings($binary, $length, TRUE, FALSE); // Multibyte NOT needed
 
+       // Remove/Replace quoted-spaces within tags
+       $from[] = '#(<\w+ [^<>]*?\w ?= ?")([^"<>]*? [^"<>]*)("[^<>]*?>)#ie';
+       $to[]   = "'$1' . str_replace(' ' , '%20' , trim('$2')) . '$3'";
+
        // Remove words (has no '<>[]:') between spaces
-       $binary = preg_replace('/[ \t][\w.,()\ \t]+[ \t]/', ' ', $binary);
+       $from[] = '/[ \t][\w.,()\ \t]+[ \t]/';
+       $to[]   = ' ';
 
-       return $binary;
+       return preg_replace($from, $to, $binary);
 }
 
 // Preprocess: Domain exposure callback (See spam_uri_pickup_preprocess())
@@ -680,7 +686,6 @@ function spam_uri_pickup_preprocess($string = '', $method = array())
        );
 
        $string = spam_uri_removing_hocus_pocus($string, $method);
-       //var_dump(htmlspecialchars($string));
 
        // Domain exposure (simple)
        // http://victim.example.org/nasty.example.org/path#frag