PMWI_Input

The WP All Import - WooCommerce Add-On PMWI Input class.

Defined (1)

The class is defined in the following location(s).

/classes/input.php  
  1. class PMWI_Input { 
  2. protected $filters = array('stripslashes'); 
  3.  
  4. public function read($inputArray, $paramName, $default = NULL) { 
  5. if (is_array($paramName) and ! is_null($default)) { 
  6. throw new Exception('Either array of parameter names with default values as the only argument or param name and default value as seperate arguments are expected.'); 
  7. if (is_array($paramName)) { 
  8. foreach ($paramName as $param => $def) { 
  9. if (isset($inputArray[$param])) { 
  10. $paramName[$param] = $this->applyFilters($inputArray[$param]); 
  11. return $paramName; 
  12. } else { 
  13. return isset($inputArray[$paramName]) ? $this->applyFilters($inputArray[$paramName]) : $default; 
  14.  
  15. public function get($paramName, $default = NULL) { 
  16. $this->addFilter('strip_tags'); 
  17. $this->addFilter('htmlspecialchars');  
  18. $this->addFilter('esc_sql');  
  19. $result = $this->read($_GET, $paramName, $default); 
  20. $this->removeFilter('strip_tags');  
  21. $this->removeFilter('htmlspecialchars');  
  22. $this->removeFilter('esc_sql'); 
  23. return $result; 
  24.  
  25. public function post($paramName, $default = NULL) { 
  26. return $this->read($_POST, $paramName, $default); 
  27.  
  28. public function cookie($paramName, $default = NULL) { 
  29. return $this->read($_COOKIE, $paramName, $default); 
  30.  
  31. public function request($paramName, $default = NULL) { 
  32. return $this->read($_GET + $_POST + $_COOKIE, $paramName, $default); 
  33.  
  34. public function getpost($paramName, $default = NULL) { 
  35. return $this->read($_GET + $_POST, $paramName, $default); 
  36.  
  37. public function server($paramName, $default = NULL) { 
  38. return $this->read($_SERVER, $paramName, $default); 
  39.  
  40. public function addFilter($callback) { 
  41. if ( ! is_callable($callback)) { 
  42. throw new Exception(get_class($this) . '::' . __METHOD__ . ' parameter must be a proper callback function reference.'); 
  43. if ( ! in_array($callback, $this->filters)) { 
  44. $this->filters[] = $callback; 
  45. return $this; 
  46.  
  47. public function removeFilter($callback) { 
  48. $this->filters = array_diff($this->filters, array($callback)); 
  49. return $this; 
  50.  
  51. protected function applyFilters($val) { 
  52. if (is_array($val)) { 
  53. foreach ($val as $k => $v) { 
  54. $val[$k] = $this->applyFilters($v); 
  55. } else { 
  56. foreach ($this->filters as $filter) { 
  57. $val = call_user_func($filter, $val); 
  58. return $val;