<?php  if ( ! defined('BASEPATH')) exit('No direct script access allowed');
class MY_Input extends CI_Input
{
	function _clean_input_keys($str)
	{
		if(preg_match("/^,_[a-z0-9:_\/-]+$/",$str)){
			$str = preg_replace("/,_/","",$str);
		}
                
    	if ( ! preg_match("/^[a-z0-9:_\/-]+$/i", $str))
     	{
     		exit('Disallowed Key Characters.'.$str);
  	 	}
		// Clean UTF-8 if supported
		if (UTF8_ENABLED === TRUE)
		{
			$str = $this->uni->clean_string($str);
		}

		return $str;
	}

	function _fetch_from_array(&$array, $index = '', $xss_clean = FALSE)
	{
		if ( ! isset($array[$index]))
		{
			return FALSE;
		}
		if ($xss_clean === TRUE)
		{
            return $this->security->xss_clean($this->Safe($array[$index]));
		}
		return $this->Safe_swf($array[$index]);
	}

	function Safe_swf($string) { 
        		if(is_array($string)) { //如果其为一个数组则循环执行此函数 
            			foreach($string as $key => $val) { 
                			$string[$key] = $this->Safe_swf($val); 
            			} 
        		} else { 
	                   $string = str_replace("allowfullscreen='true'","",$string);
	                   $string = str_replace('allowfullscreen="true"',"",$string);
	                   $string = str_replace("allownetworking='all'","",$string);
	                   $string = str_replace('allownetworking="all"',"",$string);
	                   $string = str_replace("allowscriptaccess='always'","",$string);
	                   $string = str_replace('allowscriptaccess="always"',"",$string);
        		} 
		        return $string;
	}

	function Safe($array){
         @set_magic_quotes_runtime(0);   // 判断 magic_quotes_gpc 状态   
         if(get_magic_quotes_gpc()) { 
              $array=$this->stripslashes_array($array);
		 }
		 return $array;
	}

    function stripslashes_array($array) {
        if (is_array($array)) {
            foreach ($array as $k => $v) {
                $array[$k] = $this->stripslashes_array($v);
            }
        } 
        else if (is_string($array)) {
            $array = str_replace('%20','',$array);
            $array = str_replace('%27','',$array);
            $array = str_replace('%2527','',$array);
            $array = str_replace("'",'&#039;',$array);
            $array = str_replace('"','&quot;',$array);
            $array = str_replace(';','',$array);
            $array = str_replace('<','&lt;',$array);
            $array = str_replace('>','&gt;',$array);
            $array = str_replace('\\','',$array);
            $array = str_replace("%","\%",$array);
            $array = str_replace("_","\_",$array);
            $array = preg_replace("/ /","", $array);
            $array = preg_replace("/　/","", $array);
            $array = stripslashes($array);  
        }
		return $array;  
	} 

} // END class MY_Input
