CdataStrategy.php
8 years ago
CdataStrategyAlways.php
8 years ago
CdataStrategyFactory.php
9 years ago
CdataStrategyIllegalCharacters.php
8 years ago
CdataStrategyIllegalCharactersHtmlEntities.php
8 years ago
CdataStrategyNever.php
8 years ago
XMLWriter.php
8 years ago
chunk.php
5 years ago
config.php
7 years ago
download.php
6 years ago
handler.php
10 years ago
helper.php
12 years ago
input.php
7 years ago
installer.php
9 years ago
session.php
10 years ago
wpallimport.php
4 years ago
zip.php
10 years ago
input.php
81 lines
| 1 | <?php |
| 2 | class PMXE_Input { |
| 3 | protected $filters = array('stripslashes'); |
| 4 | |
| 5 | public function read($inputArray, $paramName, $default = NULL) { |
| 6 | if (is_array($paramName) and ! is_null($default)) { |
| 7 | 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.'); |
| 8 | } |
| 9 | if (is_array($paramName)) { |
| 10 | foreach ($paramName as $param => $def) { |
| 11 | if (isset($inputArray[$param])) { |
| 12 | $paramName[$param] = $this->applyFilters($inputArray[$param]); |
| 13 | } |
| 14 | } |
| 15 | return $paramName; |
| 16 | } else { |
| 17 | return isset($inputArray[$paramName]) ? $this->applyFilters($inputArray[$paramName]) : $default; |
| 18 | } |
| 19 | } |
| 20 | |
| 21 | public function get($paramName, $default = NULL) { |
| 22 | $this->addFilter('htmlspecialchars'); |
| 23 | $this->addFilter('strip_tags'); |
| 24 | $this->addFilter('esc_sql'); |
| 25 | $this->addFilter('esc_js'); |
| 26 | $result = $this->read($_GET, $paramName, $default); |
| 27 | $this->removeFilter('htmlspecialchars'); |
| 28 | $this->removeFilter('strip_tags'); |
| 29 | $this->removeFilter('esc_sql'); |
| 30 | $this->removeFilter('esc_js'); |
| 31 | return $result; |
| 32 | } |
| 33 | |
| 34 | public function post($paramName, $default = NULL) { |
| 35 | return $this->read($_POST, $paramName, $default); |
| 36 | } |
| 37 | |
| 38 | public function cookie($paramName, $default = NULL) { |
| 39 | return $this->read($_COOKIE, $paramName, $default); |
| 40 | } |
| 41 | |
| 42 | public function request($paramName, $default = NULL) { |
| 43 | return $this->read($_GET + $_POST + $_COOKIE, $paramName, $default); |
| 44 | } |
| 45 | |
| 46 | public function getpost($paramName, $default = NULL) { |
| 47 | return $this->read($_GET + $_POST, $paramName, $default); |
| 48 | } |
| 49 | |
| 50 | public function server($paramName, $default = NULL) { |
| 51 | return $this->read($_SERVER, $paramName, $default); |
| 52 | } |
| 53 | |
| 54 | public function addFilter($callback) { |
| 55 | if ( ! is_callable($callback)) { |
| 56 | throw new Exception(get_class($this) . '::' . __METHOD__ . ' parameter must be a proper callback function reference.'); |
| 57 | } |
| 58 | if ( ! in_array($callback, $this->filters)) { |
| 59 | $this->filters[] = $callback; |
| 60 | } |
| 61 | return $this; |
| 62 | } |
| 63 | |
| 64 | public function removeFilter($callback) { |
| 65 | $this->filters = array_diff($this->filters, array($callback)); |
| 66 | return $this; |
| 67 | } |
| 68 | |
| 69 | protected function applyFilters($val) { |
| 70 | if (is_array($val)) { |
| 71 | foreach ($val as $k => $v) { |
| 72 | $val[$k] = $this->applyFilters($v); |
| 73 | } |
| 74 | } else { |
| 75 | foreach ($this->filters as $filter) { |
| 76 | $val = call_user_func($filter, $val); |
| 77 | } |
| 78 | } |
| 79 | return $val; |
| 80 | } |
| 81 | } |