OSDN Git Service

Added preg_grep_invert(), get_blocklist()
authorhenoheno <henoheno>
Wed, 3 Jan 2007 08:00:58 +0000 (17:00 +0900)
committerhenoheno <henoheno>
Wed, 3 Jan 2007 08:00:58 +0000 (17:00 +0900)
spam.php
spam/spam.php

index be6566f..acb58fd 100644 (file)
--- a/spam.php
+++ b/spam.php
@@ -1,5 +1,5 @@
 <?php
-// $Id: spam.php,v 1.91 2007/01/03 07:35:54 henoheno Exp $
+// $Id: spam.php,v 1.92 2007/01/03 08:00:58 henoheno Exp $
 // Copyright (C) 2006-2007 PukiWiki Developers Team
 // License: GPL v2 or (at your option) any later version
 
@@ -18,6 +18,19 @@ if (! function_exists('var_export')) {
        }
 }
 
+// (PHP 4 >= 4.2.0): preg_grep() enabels invert option
+function preg_grep_invert($pattern = '//', $input = array())
+{
+       static $invert;
+       if (! isset($invert)) $invert = defined('PREG_GREP_INVERT');
+
+       if ($invert) {
+               return preg_grep($pattern, $input, PREG_GREP_INVERT);
+       } else {
+               return array_diff($input, preg_grep($pattern, $input));
+       }
+}
+
 // ---------------------
 // URI pickup
 
@@ -636,9 +649,7 @@ function generate_glob_regex($string = '', $divider = '/')
        }
 }
 
-// TODO: preg_grep() ?
-// TODO: Multi list
-function is_badhost($hosts = '', $asap = TRUE)
+function get_blocklist($listname = '')
 {
        static $regex;
 
@@ -673,6 +684,21 @@ function is_badhost($hosts = '', $asap = TRUE)
                }
        }
 
+       if ($listname == '') {
+               return $regex;
+       } else if (isset($regex[$listname])) {
+               return $regex[$listname];
+       } else {        
+               return array();
+       }
+}
+
+
+// TODO: preg_grep() ?
+function is_badhost($hosts = '', $asap = TRUE)
+{
+       $regex = get_blocklist();
+
        $result = array();
        if (! is_array($hosts)) $hosts = array($hosts);
 
index be6566f..acb58fd 100644 (file)
@@ -1,5 +1,5 @@
 <?php
-// $Id: spam.php,v 1.91 2007/01/03 07:35:54 henoheno Exp $
+// $Id: spam.php,v 1.92 2007/01/03 08:00:58 henoheno Exp $
 // Copyright (C) 2006-2007 PukiWiki Developers Team
 // License: GPL v2 or (at your option) any later version
 
@@ -18,6 +18,19 @@ if (! function_exists('var_export')) {
        }
 }
 
+// (PHP 4 >= 4.2.0): preg_grep() enabels invert option
+function preg_grep_invert($pattern = '//', $input = array())
+{
+       static $invert;
+       if (! isset($invert)) $invert = defined('PREG_GREP_INVERT');
+
+       if ($invert) {
+               return preg_grep($pattern, $input, PREG_GREP_INVERT);
+       } else {
+               return array_diff($input, preg_grep($pattern, $input));
+       }
+}
+
 // ---------------------
 // URI pickup
 
@@ -636,9 +649,7 @@ function generate_glob_regex($string = '', $divider = '/')
        }
 }
 
-// TODO: preg_grep() ?
-// TODO: Multi list
-function is_badhost($hosts = '', $asap = TRUE)
+function get_blocklist($listname = '')
 {
        static $regex;
 
@@ -673,6 +684,21 @@ function is_badhost($hosts = '', $asap = TRUE)
                }
        }
 
+       if ($listname == '') {
+               return $regex;
+       } else if (isset($regex[$listname])) {
+               return $regex[$listname];
+       } else {        
+               return array();
+       }
+}
+
+
+// TODO: preg_grep() ?
+function is_badhost($hosts = '', $asap = TRUE)
+{
+       $regex = get_blocklist();
+
        $result = array();
        if (! is_array($hosts)) $hosts = array($hosts);