Newer
Older
Digital_Repository / Repositories / statistics / includes / inc.class.input_check.es.php
  1. <?php
  2. /**
  3. * Project: ePrints Statistics
  4. * File: inc.class.input_check.es.php
  5. * Description: Gross input checks for POST and GET via this object.
  6. * Sql object does it's own checking based on the schema.
  7. */
  8.  
  9. class checkit {
  10. var $_config = array();
  11. var $_response;
  12. var $_clean;
  13. function checkit()
  14. {
  15. }
  16. function doCheck($value)
  17. {
  18. if (method_exists($this, $this->_config["type"])) {
  19. checkit::$this->_config["type"]($value);
  20. } else {
  21. /* Could do something meaningful here. */
  22. }
  23. }
  24. function getResponse()
  25. {
  26. return $this->_response;
  27. }
  28. function setConfig($config)
  29. {
  30. $this->_config = $config;
  31. }
  32. function cookie($value)
  33. {
  34. if (strlen($value)>$this->_config["maxlength"]) {
  35. $this->_response = $this->_config["action"];
  36. }
  37. }
  38. function string($value)
  39. {
  40. /*
  41. More restrictive here than freetext
  42. Use could be for the form actions. If they don't match
  43. a certain type we have to reset the request otherwise we
  44. don't know what will happen.
  45. */
  46. if (strlen($value)>$this->_config["maxlength"]) {
  47. $this->_response = $this->_config["action"];
  48. }
  49. if (isset($this->_config["pattern"])) {
  50. $pattern = $this->_config["pattern"];
  51. if ( preg_match($pattern, $value) ) {
  52. $this->_response = $this->_config["action"];
  53. }
  54. }
  55. if (isset($this->_config["values"])) {
  56. if (!in_array($value, $this->_config["values"])) {
  57. $this->_response = $this->_config["action"];
  58. }
  59. }
  60. return;
  61. }
  62. function integer($value)
  63. {
  64. /*
  65. Check that value is numeric and does not exceed maxlength.
  66. */
  67. if (!is_numeric($value)) {
  68. $this->_response = $this->_config["action"];
  69. }
  70. $test = (int) $value;
  71. if ($test > $this->_config["maxlength"]) {
  72. $this->_response = $this->_config["action"];
  73. }
  74. }
  75. function ignore($value)
  76. {
  77. return;
  78. }
  79. function freetext($value)
  80. {
  81. if (strlen($value)>$this->_config["maxlength"]) {
  82. return 1;
  83. }
  84. if (isset($this->_config["pattern"])) {
  85. $pattern = $this->_config["pattern"];
  86. $replacement = $this->_config["replacement"];
  87. $this->_clean = preg_replace($pattern, $replacement, $value);
  88. return 2;
  89. }
  90. }
  91. }
  92.  
  93. ?>
  94.