OSDN Git Service

Just cleanups
authorhenoheno <henoheno>
Wed, 11 Apr 2007 13:13:33 +0000 (22:13 +0900)
committerhenoheno <henoheno>
Wed, 11 Apr 2007 13:13:33 +0000 (22:13 +0900)
spam.php
spam/spam.php

index b3a57d1..547a481 100644 (file)
--- a/spam.php
+++ b/spam.php
@@ -1,5 +1,5 @@
 <?php
-// $Id: spam.php,v 1.129 2007/03/25 16:37:26 henoheno Exp $
+// $Id: spam.php,v 1.130 2007/04/11 13:13:33 henoheno Exp $
 // Copyright (C) 2006-2007 PukiWiki Developers Team
 // License: GPL v2 or (at your option) any later version
 //
@@ -110,9 +110,9 @@ function uri_pickup_normalize(& $pickups, $destructive = TRUE)
        if ($destructive) {
                foreach (array_keys($pickups) as $key) {
                        $_key = & $pickups[$key];
-                       $_key['scheme'] = isset($_key['scheme']) ? scheme_normalize($_key['scheme']) : '';
+                       $_key['scheme']   = isset($_key['scheme']) ? scheme_normalize($_key['scheme']) : '';
                        $_key['host']     = isset($_key['host'])     ? host_normalize($_key['host']) : '';
-                       $_key['port']   = isset($_key['port'])       ? port_normalize($_key['port'], $_key['scheme'], FALSE) : '';
+                       $_key['port']     = isset($_key['port'])       ? port_normalize($_key['port'], $_key['scheme'], FALSE) : '';
                        $_key['path']     = isset($_key['path'])     ? strtolower(path_normalize($_key['path'])) : '';
                        $_key['file']     = isset($_key['file'])     ? file_normalize($_key['file']) : '';
                        $_key['query']    = isset($_key['query'])    ? query_normalize($_key['query']) : '';
@@ -121,14 +121,13 @@ function uri_pickup_normalize(& $pickups, $destructive = TRUE)
        } else {
                foreach (array_keys($pickups) as $key) {
                        $_key = & $pickups[$key];
-                       $_key['scheme'] = isset($_key['scheme']) ? scheme_normalize($_key['scheme']) : '';
-                       $_key['host']   = isset($_key['host'])   ? strtolower($_key['host']) : '';
-                       $_key['port']   = isset($_key['port'])   ? port_normalize($_key['port'], $_key['scheme'], FALSE) : '';
-                       $_key['path']   = isset($_key['path'])   ? path_normalize($_key['path']) : '';
+                       $_key['scheme']   = isset($_key['scheme']) ? scheme_normalize($_key['scheme']) : '';
+                       $_key['host']     = isset($_key['host'])   ? strtolower($_key['host']) : '';
+                       $_key['port']     = isset($_key['port'])   ? port_normalize($_key['port'], $_key['scheme'], FALSE) : '';
+                       $_key['path']     = isset($_key['path'])   ? path_normalize($_key['path']) : '';
                }
        }
 
-
        return $pickups;
 }
 
@@ -742,6 +741,7 @@ function file_normalize($file = 'index.html.en')
 // [OK] nothing==&eg=dummy&eg=padding&eg=foobar  =>  eg=foobar
 function query_normalize($string = '', $equal = TRUE, $equal_cutempty = TRUE, $stortolower = TRUE)
 {
+       if (! is_string($string)) return '';
        if ($stortolower) $string = strtolower($string);
 
        $array = explode('&', $string);
@@ -807,6 +807,8 @@ function generate_glob_regex($string = '', $divider = '/')
        //              23 => ']',
                );
 
+       if (! is_string($string)) return '';
+
        $string = str_replace($from, $mid, $string); // Hide
        $string = preg_quote($string, $divider);
        $string = str_replace($mid, $to, $string);   // Unhide
@@ -839,6 +841,8 @@ function is_ip($string = '')
 // TODO: IPv4, CIDR?, IPv6
 function generate_host_regex($string = '', $divider = '/')
 {
+       if (! is_string($string)) return '';
+
        if (mb_strpos($string, '.') === FALSE)
                return generate_glob_regex($string, $divider);
 
@@ -875,7 +879,7 @@ function get_blocklist($list = '')
                        //              'IANA-examples' => '#^(?:.*\.)?example\.(?:com|net|org)$#',
                        //      );
                        foreach(array('goodhost', 'badhost') as $_list) {
-                               if (! isset($blocklist[$list])) continue;
+                               if (! isset($blocklist[$_list])) continue;
                                foreach ($blocklist[$_list] as $key => $value) {
                                        if (is_array($value)) {
                                                $regexs[$_list][$key] = array();
@@ -914,7 +918,9 @@ function is_badhost($hosts = array(), $asap = TRUE, & $remains)
        $result = array();
        if (! is_array($hosts)) $hosts = array($hosts);
        foreach(array_keys($hosts) as $key) {
-               if (! is_string($hosts[$key])) unset($hosts[$key]);
+               if (! is_string($hosts[$key])) {
+                       unset($hosts[$key]);
+               }
        }
        if (empty($hosts)) return $result;
 
@@ -923,16 +929,19 @@ function is_badhost($hosts = array(), $asap = TRUE, & $remains)
        }
        if (empty($hosts)) return $result;
 
-       $tmp = array();
        foreach (get_blocklist('badhost') as $label => $regex) {
                if (is_array($regex)) {
                        $result[$label] = array();
                        foreach($regex as $_label => $_regex) {
-                               if (is_badhost_avail($_label, $_regex, $hosts, $result[$label]) && $asap) break;
+                               if (is_badhost_avail($_label, $_regex, $hosts, $result[$label]) && $asap) {
+                                       break;
+                               }
                        }
                        if (empty($result[$label])) unset($result[$label]);
                } else {
-                       if (is_badhost_avail($label, $regex, $hosts, $result) && $asap) break;
+                       if (is_badhost_avail($label, $regex, $hosts, $result) && $asap) {
+                               break;
+                       }
                }
        }
 
index b3a57d1..547a481 100644 (file)
@@ -1,5 +1,5 @@
 <?php
-// $Id: spam.php,v 1.129 2007/03/25 16:37:26 henoheno Exp $
+// $Id: spam.php,v 1.130 2007/04/11 13:13:33 henoheno Exp $
 // Copyright (C) 2006-2007 PukiWiki Developers Team
 // License: GPL v2 or (at your option) any later version
 //
@@ -110,9 +110,9 @@ function uri_pickup_normalize(& $pickups, $destructive = TRUE)
        if ($destructive) {
                foreach (array_keys($pickups) as $key) {
                        $_key = & $pickups[$key];
-                       $_key['scheme'] = isset($_key['scheme']) ? scheme_normalize($_key['scheme']) : '';
+                       $_key['scheme']   = isset($_key['scheme']) ? scheme_normalize($_key['scheme']) : '';
                        $_key['host']     = isset($_key['host'])     ? host_normalize($_key['host']) : '';
-                       $_key['port']   = isset($_key['port'])       ? port_normalize($_key['port'], $_key['scheme'], FALSE) : '';
+                       $_key['port']     = isset($_key['port'])       ? port_normalize($_key['port'], $_key['scheme'], FALSE) : '';
                        $_key['path']     = isset($_key['path'])     ? strtolower(path_normalize($_key['path'])) : '';
                        $_key['file']     = isset($_key['file'])     ? file_normalize($_key['file']) : '';
                        $_key['query']    = isset($_key['query'])    ? query_normalize($_key['query']) : '';
@@ -121,14 +121,13 @@ function uri_pickup_normalize(& $pickups, $destructive = TRUE)
        } else {
                foreach (array_keys($pickups) as $key) {
                        $_key = & $pickups[$key];
-                       $_key['scheme'] = isset($_key['scheme']) ? scheme_normalize($_key['scheme']) : '';
-                       $_key['host']   = isset($_key['host'])   ? strtolower($_key['host']) : '';
-                       $_key['port']   = isset($_key['port'])   ? port_normalize($_key['port'], $_key['scheme'], FALSE) : '';
-                       $_key['path']   = isset($_key['path'])   ? path_normalize($_key['path']) : '';
+                       $_key['scheme']   = isset($_key['scheme']) ? scheme_normalize($_key['scheme']) : '';
+                       $_key['host']     = isset($_key['host'])   ? strtolower($_key['host']) : '';
+                       $_key['port']     = isset($_key['port'])   ? port_normalize($_key['port'], $_key['scheme'], FALSE) : '';
+                       $_key['path']     = isset($_key['path'])   ? path_normalize($_key['path']) : '';
                }
        }
 
-
        return $pickups;
 }
 
@@ -742,6 +741,7 @@ function file_normalize($file = 'index.html.en')
 // [OK] nothing==&eg=dummy&eg=padding&eg=foobar  =>  eg=foobar
 function query_normalize($string = '', $equal = TRUE, $equal_cutempty = TRUE, $stortolower = TRUE)
 {
+       if (! is_string($string)) return '';
        if ($stortolower) $string = strtolower($string);
 
        $array = explode('&', $string);
@@ -807,6 +807,8 @@ function generate_glob_regex($string = '', $divider = '/')
        //              23 => ']',
                );
 
+       if (! is_string($string)) return '';
+
        $string = str_replace($from, $mid, $string); // Hide
        $string = preg_quote($string, $divider);
        $string = str_replace($mid, $to, $string);   // Unhide
@@ -839,6 +841,8 @@ function is_ip($string = '')
 // TODO: IPv4, CIDR?, IPv6
 function generate_host_regex($string = '', $divider = '/')
 {
+       if (! is_string($string)) return '';
+
        if (mb_strpos($string, '.') === FALSE)
                return generate_glob_regex($string, $divider);
 
@@ -875,7 +879,7 @@ function get_blocklist($list = '')
                        //              'IANA-examples' => '#^(?:.*\.)?example\.(?:com|net|org)$#',
                        //      );
                        foreach(array('goodhost', 'badhost') as $_list) {
-                               if (! isset($blocklist[$list])) continue;
+                               if (! isset($blocklist[$_list])) continue;
                                foreach ($blocklist[$_list] as $key => $value) {
                                        if (is_array($value)) {
                                                $regexs[$_list][$key] = array();
@@ -914,7 +918,9 @@ function is_badhost($hosts = array(), $asap = TRUE, & $remains)
        $result = array();
        if (! is_array($hosts)) $hosts = array($hosts);
        foreach(array_keys($hosts) as $key) {
-               if (! is_string($hosts[$key])) unset($hosts[$key]);
+               if (! is_string($hosts[$key])) {
+                       unset($hosts[$key]);
+               }
        }
        if (empty($hosts)) return $result;
 
@@ -923,16 +929,19 @@ function is_badhost($hosts = array(), $asap = TRUE, & $remains)
        }
        if (empty($hosts)) return $result;
 
-       $tmp = array();
        foreach (get_blocklist('badhost') as $label => $regex) {
                if (is_array($regex)) {
                        $result[$label] = array();
                        foreach($regex as $_label => $_regex) {
-                               if (is_badhost_avail($_label, $_regex, $hosts, $result[$label]) && $asap) break;
+                               if (is_badhost_avail($_label, $_regex, $hosts, $result[$label]) && $asap) {
+                                       break;
+                               }
                        }
                        if (empty($result[$label])) unset($result[$label]);
                } else {
-                       if (is_badhost_avail($label, $regex, $hosts, $result) && $asap) break;
+                       if (is_badhost_avail($label, $regex, $hosts, $result) && $asap) {
+                               break;
+                       }
                }
        }