MY_Input.php 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839
  1. <?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
  2. class MY_Input extends CI_Input{
  3. protected function _fetch_from_array(&$array, $index = NULL, $xss_clean = NULL){
  4. is_bool($xss_clean) OR $xss_clean = $this->_enable_xss;
  5. // If $index is NULL, it means that the whole $array is requested
  6. isset($index) OR $index = array_keys($array);
  7. // allow fetching multiple keys at once
  8. if (is_array($index)){
  9. $output = array();
  10. foreach ($index as $key){
  11. $output[$key] = $this->_fetch_from_array($array, $key, $xss_clean);
  12. }
  13. return $output;
  14. }
  15. if (isset($array[$index])){
  16. $value = $array[$index];
  17. }elseif (($count = preg_match_all('/(?:^[^\[]+)|\[[^]]*\]/', $index, $matches)) > 1){ // Does the index contain array notation
  18. $value = $array;
  19. for ($i = 0; $i < $count; $i++){
  20. $key = trim($matches[0][$i], '[]');
  21. if ($key === ''){ // Empty notation will return the value as array
  22. break;
  23. }
  24. if (isset($value[$key])){
  25. $value = $value[$key];
  26. }else{
  27. return NULL;
  28. }
  29. }
  30. }else{
  31. return NULL;
  32. }
  33. return ($xss_clean === TRUE)
  34. ? safe_replace($this->security->xss_clean($value))
  35. : $value;
  36. }
  37. } // END class MY_URI