Daan is sweet to Kelley and delegates himself TestCMS code reflection
[ssproject1617.git] / testcms-final-anon / system / classes / input.php
1 <?php defined('IN_CMS') or die('No direct access allowed.');
2
3 class Input {
4
5 public static function clean($str) {
6 // handle magic quotes for people who cant turn it off
7 if(function_exists('get_magic_quotes_gpc')) {
8 if(get_magic_quotes_gpc()) {
9 return is_array($str) ? array_map(array('Input', 'clean'), $str) : stripslashes($str);
10 }
11 }
12
13 return $str;
14 }
15
16 private static function fetch_array($array, $key, $default = false) {
17 if(is_array($key)) {
18 $data = array();
19
20 foreach($key as $k) {
21 $data[$k] = static::fetch_array($array, $k, $default);
22 }
23
24 return $data;
25 }
26
27 if(array_key_exists($key, $array)) {
28 return static::clean($array[$key]);
29 }
30
31 return ($default instanceof \Closure) ? call_user_func($default) : $default;
32 }
33
34 public static function post($key, $default = false) {
35 return static::fetch_array($_POST, $key, $default);
36 }
37
38 public static function get($key, $default = false) {
39 return static::fetch_array($_GET, $key, $default);
40 }
41
42 public static function put($key, $default = false) {
43 return static::fetch_array(parse_str(file_get_contents('php://input')), $key, $default);
44 }
45
46 public static function delete($key, $default = false) {
47 return static::fetch_array(parse_str(file_get_contents('php://input')), $key, $default);
48 }
49
50 public static function cookie($key, $default = false) {
51 return static::fetch_array($_COOKIE, $key, $default);
52 }
53
54 public static function server($key, $default = false) {
55 return static::fetch_array($_SERVER, strtoupper($key), $default);
56 }
57
58 public static function file($key, $default = false) {
59 return static::fetch_array($_FILES, $key, $default);
60 }
61
62 public static function method() {
63 return static::server('REQUEST_METHOD');
64 }
65
66 public static function ip_address() {
67 // IP from share internet
68 if (static::server('REMOTE_ADDR') and static::server('HTTP_CLIENT_IP')) {
69 return static::server('HTTP_CLIENT_IP');
70 }
71
72 if(static::server('REMOTE_ADDR')) {
73 return static::server('REMOTE_ADDR');
74 }
75
76 if(static::server('HTTP_CLIENT_IP')) {
77 return static::server('HTTP_CLIENT_IP');
78 }
79
80 // Proxy detection
81 if(static::server('HTTP_X_FORWARDED_FOR')) {
82 return static::server('HTTP_X_FORWARDED_FOR');
83 }
84
85 return '0.0.0.0';
86 }
87
88 public static function user_agent() {
89 return static::server('HTTP_USER_AGENT');
90 }
91
92 }