From edb1b47a48be97fdfb5373e9dfe16e89d3abd2e7 Mon Sep 17 00:00:00 2001 From: thinkphp Date: Wed, 27 Mar 2013 12:03:43 +0800 Subject: [PATCH] =?UTF-8?q?=E5=8F=96=E6=B6=88base=E6=96=87=E4=BB=B6?= =?UTF-8?q?=E4=B8=AD=E7=9A=84filter=5Fexp=E5=87=BD=E6=95=B0=E5=B9=B6?= =?UTF-8?q?=E5=85=A5Input=E7=B1=BB?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Think/Input.php | 17 +++++++++++++++++ base.php | 7 ------- 2 files changed, 17 insertions(+), 7 deletions(-) diff --git a/Think/Input.php b/Think/Input.php index 6badc897..64de2f9d 100644 --- a/Think/Input.php +++ b/Think/Input.php @@ -11,6 +11,8 @@ // $Id$ namespace Think; class Input { + // 全局过滤规则 + static $filter = NULL; /** * 获取系统变量 支持过滤和默认值 @@ -43,6 +45,15 @@ class Input { case 'globals': $input =& $GLOBALS;break; default:return NULL; } + // 变量全局过滤 + array_walk_recursive($input,'self::filter_exp'); + if(self::$filter) { + $_filters = explode(',',self::$filter); + foreach($_filters as $_filter){ + // 全局参数过滤 + array_walk_recursive($input,$_filter); + } + } if(''== $args[0]) { // 返回全部数据 return $input; @@ -67,4 +78,10 @@ class Input { return $data; } + // 过滤表单中的表达式 + static private filter_exp(&$value){ + if (in_array(strtolower($value),array('exp','or'))){ + $value .= ' '; + } + } } \ No newline at end of file diff --git a/base.php b/base.php index 9774af89..8224f1ab 100644 --- a/base.php +++ b/base.php @@ -283,11 +283,4 @@ function S($name,$value='',$options=null) { $expire = is_numeric($options)?$options:NULL; return Think\Cache::set($name, $value, $expire); } -} - -// 过滤表单中的表达式 -function filter_exp(&$value){ - if (in_array(strtolower($value),array('exp','or'))){ - $value .= ' '; - } } \ No newline at end of file