Changeset 2659

Show
Ignore:
Timestamp:
05/07/08 15:25:32 (2 months ago)
Author:
Shadowhand
Message:

Major change to Input! All get(), post(), cookie(), server() calls are now defined as:

method($key, $default = NULL, $xss_clean = FALSE)

You can no longer get multiple params from these methods by using multiple $key arguments!

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trunk/system/libraries/Input.php

    r2627 r2659  
    133133        { 
    134134                // Array to be searched, assigned by reference 
    135                 $array = array(); 
    136135                switch (strtolower($global)) 
    137136                { 
     
    144143                } 
    145144 
    146                 if (count($args) === 0
     145                if ($args === array()
    147146                        return $array; 
    148147 
    149                 // If the last argument is a boolean, it's the XSS clean flag 
    150                 $xss_clean = (is_bool(end($args))) ? array_pop($args) : FALSE; 
    151  
    152                 // Reset the array pointer 
    153                 reset($args); 
    154  
    155                 // Multiple inputs require us to return an array 
    156                 $return_array = (count($args) > 1); 
    157  
    158                 $data = array(); 
    159                 while ($key = array_shift($args)) 
    160                 { 
    161                         if (isset($array[$key])) 
    162                         { 
    163                                 // XSS clean if the data has not already been cleaned 
    164                                 $data[$key] = ($this->use_xss_clean == FALSE AND $xss_clean == TRUE) ? $this->xss_clean($array[$key]) : $array[$key]; 
    165                         } 
    166                         else 
    167                         { 
    168                                 $data[$key] = NULL; 
    169                         } 
    170                 } 
    171  
    172                 // Return the global value 
    173                 return ($return_array) ? $data : current($data); 
     148                if (count($args) < 3) 
     149                { 
     150                        // Add $default and $xss_clean params 
     151                        $args += array(1 => NULL, 2 => FALSE); 
     152                } 
     153 
     154                // Extract the arguments 
     155                list ($key, $default, $xss_clean) = $args; 
     156 
     157                // Get the value from the array 
     158                $value = isset($array[$key]) ? $array[$key] : $default; 
     159 
     160                if ($xss_clean === TRUE AND $this->use_xss_clean === FALSE) 
     161                { 
     162                        // XSS clean the value 
     163                        $value = $this->xss_clean($value); 
     164                } 
     165 
     166                return $value; 
    174167        } 
    175168