1: | <?php |
2: | |
3: | namespace Zippy; |
4: | |
5: | |
6: | |
7: | |
8: | class HttpRequest |
9: | { |
10: | public const QUERY_HOME = 0; |
11: | public const QUERY_EVENT = 1; |
12: | public const QUERY_PAGE = 2; |
13: | public const QUERY_SEF = 3; |
14: | public const QUERY_INVALID = 4; |
15: | |
16: | |
17: | |
18: | private $request; |
19: | public $request_c; |
20: | public $request_params; |
21: | public $request_page; |
22: | public $request_page_arg = array(); |
23: | public $uri; |
24: | |
25: | public $querytype = self::QUERY_INVALID; |
26: | private $pageindex = 0; |
27: | |
28: | |
29: | |
30: | |
31: | |
32: | public function __construct() { |
33: | $uri = $_SERVER["REQUEST_URI"]; |
34: | |
35: | |
36: | |
37: | if (isset($_REQUEST["q"])) { |
38: | |
39: | $this->querytype = self::QUERY_EVENT; |
40: | $this->request = explode("::", $_REQUEST["q"]); |
41: | if (count($this->request) < 1) { |
42: | throw new \Zippy\Exception(ERROR_INVALID_VERSION); |
43: | } |
44: | |
45: | $arr = explode(':', $this->request[0]); |
46: | |
47: | $this->pageindex = $arr[1]; |
48: | $this->request_page = "\\" . ltrim(str_replace("/", "\\", $arr[0]), "\\"); |
49: | |
50: | $this->request_params = array(); |
51: | $this->request_c = array("page"); |
52: | foreach (array_slice($this->request, 1) as $cid) { |
53: | $arr = explode(':', $cid); |
54: | $this->request_params[$arr[0]] = array_slice($arr, 1); |
55: | $this->request_c[] = $arr[0]; |
56: | } |
57: | |
58: | |
59: | return; |
60: | } |
61: | |
62: | |
63: | if (isset($_REQUEST["r"])) { |
64: | $this->querytype = self::QUERY_PAGE; |
65: | $p = unserialize(trim(base64_decode($_REQUEST["r"]))); |
66: | |
67: | $this->request_page = $p[0]; |
68: | $this->request_page_arg = $p[1]; |
69: | return; |
70: | } |
71: | |
72: | |
73: | |
74: | if (isset($_REQUEST["p"])) { |
75: | $this->querytype = self::QUERY_PAGE; |
76: | $this->request_page = "\\" . ltrim(str_replace("/", "\\", $_REQUEST["p"]), "\\"); |
77: | $this->request_page_arg = isset($_REQUEST["arg"]) ? explode('/', trim($_REQUEST["arg"], '/')) : array(); |
78: | return; |
79: | } |
80: | |
81: | |
82: | if (strlen($uri) > 1 && strpos($uri, '/?') === false && strpos($uri, '/index.php') === false) { |
83: | $p = strpos($uri, '?'); |
84: | if ($p > 0) { |
85: | $uri = substr($uri, 0, $p); |
86: | } |
87: | if (preg_match('/^[-#a-zA-Z0-9\/_]+$/', $uri)) { |
88: | $this->querytype = self::QUERY_SEF; |
89: | $this->uri = ltrim($uri, '/'); |
90: | } |
91: | } |
92: | if (strpos($uri, 'index.php') > 0) { |
93: | $this->querytype = self::QUERY_HOME; |
94: | } |
95: | $uri = ltrim($uri, '/'); |
96: | if ($uri == "") { |
97: | $this->querytype = self::QUERY_HOME; |
98: | } |
99: | |
100: | } |
101: | |
102: | |
103: | |
104: | |
105: | |
106: | public function getRequestIndex() { |
107: | return str_replace("/", "\\", $this->pageindex); |
108: | } |
109: | |
110: | |
111: | |
112: | |
113: | |
114: | public function isAjaxRequest() { |
115: | return isset($_REQUEST["ajax"]); |
116: | } |
117: | |
118: | |
119: | |
120: | |
121: | |
122: | public function isBinaryRequest() { |
123: | return isset($_REQUEST["binary"]); |
124: | } |
125: | |
126: | |
127: | |
128: | } |
129: | |