1 |
joko |
1.1 |
<? |
2 |
|
|
// ------------------------------------------------------------------------- |
3 |
joko |
1.4 |
// $Id: Request.php,v 1.3 2002/12/13 00:22:27 jonen Exp $ |
4 |
joko |
1.1 |
// ------------------------------------------------------------------------- |
5 |
joko |
1.2 |
// $Log: Request.php,v $ |
6 |
joko |
1.4 |
// Revision 1.3 2002/12/13 00:22:27 jonen |
7 |
|
|
// - removed $site_state vars at cachedRequest |
8 |
|
|
// changes related to new Session class |
9 |
|
|
// |
10 |
jonen |
1.3 |
// Revision 1.2 2002/12/12 21:39:24 joko |
11 |
|
|
// + fix to 'cacheThisRequest' - now uses the current one to cache if none is passed |
12 |
|
|
// |
13 |
joko |
1.2 |
// Revision 1.1 2002/11/12 05:42:31 joko |
14 |
|
|
// + initial checkin |
15 |
|
|
// |
16 |
joko |
1.1 |
// ------------------------------------------------------------------------- |
17 |
|
|
|
18 |
|
|
|
19 |
|
|
class Site_Request { |
20 |
|
|
|
21 |
joko |
1.4 |
// site's instance |
22 |
joko |
1.1 |
var $site; |
23 |
joko |
1.4 |
|
24 |
|
|
// to keep some status-information for reading/parsing |
25 |
|
|
var $meta; |
26 |
|
|
|
27 |
|
|
// to keep some lowlevel-information about the request |
28 |
|
|
var $raw; |
29 |
|
|
|
30 |
|
|
// the read and parsed request - ready for further processing with the Request - object |
31 |
jonen |
1.3 |
var $request; |
32 |
joko |
1.1 |
|
33 |
|
|
function getRequest() { |
34 |
joko |
1.4 |
$this->site->log( get_class($this) . "->getRequest()", LOG_DEBUG ); |
35 |
|
|
$this->_init(); |
36 |
|
|
return $this->request; |
37 |
|
|
} |
38 |
|
|
|
39 |
|
|
function _init() { |
40 |
|
|
if (!$this->meta[read]) { |
41 |
|
|
$this->_read(); |
42 |
|
|
} |
43 |
|
|
if (!$this->meta[parse]) { |
44 |
|
|
$this->_parse(); |
45 |
|
|
} |
46 |
|
|
} |
47 |
|
|
|
48 |
|
|
|
49 |
|
|
function _read() { |
50 |
|
|
|
51 |
|
|
//print "_read<br>"; |
52 |
|
|
|
53 |
|
|
// shift external arguments from url |
54 |
|
|
$identifier = $_GET[x]; |
55 |
|
|
$externalpage = $_GET[p]; |
56 |
|
|
// fallback to post |
57 |
|
|
if (!$identifier) { $identifier = $_POST[x]; } |
58 |
|
|
|
59 |
|
|
$this->site->log( get_class($this) . "->_read( identifier $identifier )", LOG_DEBUG ); |
60 |
|
|
|
61 |
|
|
// remember arguments in object |
62 |
|
|
$this->raw[identifier] = $identifier; |
63 |
|
|
$this->raw[externalpage] = $externalpage; |
64 |
|
|
|
65 |
|
|
$this->meta[read] = 1; |
66 |
|
|
|
67 |
|
|
} |
68 |
|
|
|
69 |
joko |
1.1 |
|
70 |
joko |
1.4 |
function _parse() { |
71 |
|
|
|
72 |
|
|
//print "_parse<br>"; |
73 |
joko |
1.1 |
|
74 |
|
|
// generic identifier |
75 |
joko |
1.4 |
$ident = $this->site->decodeIdentifier($this->raw[identifier]); |
76 |
|
|
|
77 |
|
|
//print "ident: $ident<br>"; |
78 |
joko |
1.1 |
|
79 |
|
|
// get handler for identifier |
80 |
|
|
//$handler = $this->getHandler($ident); |
81 |
joko |
1.4 |
$this->site->log( get_class($this) . "->_parse: getHandler( identifier $ident )", LOG_DEBUG ); |
82 |
joko |
1.1 |
$handler = $this->site->getHandler($ident); |
83 |
|
|
//print "handler: " . dumpvar($handler) . "<br>"; |
84 |
|
|
$handler[name] = $ident; |
85 |
|
|
|
86 |
|
|
// parse action from identifier |
87 |
|
|
if ($ident && substr($ident, -1) != '/') { |
88 |
|
|
$action = substr($ident, strrpos($ident, '/') + 1); |
89 |
|
|
} |
90 |
|
|
|
91 |
|
|
$result = array( |
92 |
joko |
1.4 |
'raw' => $this->raw, |
93 |
joko |
1.1 |
'ident' => $ident, |
94 |
|
|
'handler' => $handler, |
95 |
|
|
'action' => $action, |
96 |
|
|
); |
97 |
jonen |
1.3 |
|
98 |
|
|
$this->request = $result; |
99 |
joko |
1.1 |
|
100 |
joko |
1.4 |
$this->meta[parse] = 1; |
101 |
|
|
|
102 |
joko |
1.1 |
} |
103 |
|
|
|
104 |
joko |
1.4 |
function getCached() { |
105 |
jonen |
1.3 |
return $this->site->session->get('cachedRequest'); |
106 |
joko |
1.1 |
} |
107 |
|
|
|
108 |
joko |
1.4 |
function cacheRequest($request = array()) { |
109 |
joko |
1.2 |
if (!count($request)) { |
110 |
|
|
$request = $this->getRequest(); |
111 |
|
|
} |
112 |
joko |
1.4 |
//print Dumper($request); |
113 |
jonen |
1.3 |
$this->site->session->set('cachedRequest', $request); |
114 |
joko |
1.1 |
} |
115 |
|
|
|
116 |
|
|
function overrideRequestIdentifier($ident) { |
117 |
joko |
1.4 |
$this->overrideIdentifier($ident); |
118 |
jonen |
1.3 |
} |
119 |
joko |
1.4 |
|
120 |
|
|
function overrideIdentifier($ident) { |
121 |
|
|
$ident_encoded = $this->site->encodeIdentifier($ident); |
122 |
|
|
$this->raw[identifier] = $ident_encoded; |
123 |
|
|
$this->meta[parse] = 0; |
124 |
|
|
} |
125 |
|
|
|
126 |
jonen |
1.3 |
function getIdentifier() { |
127 |
joko |
1.4 |
$this->_init(); |
128 |
jonen |
1.3 |
return $this->request[ident]; |
129 |
joko |
1.1 |
} |
130 |
|
|
|
131 |
joko |
1.4 |
function isPage() { |
132 |
|
|
$this->_init(); |
133 |
|
|
return $this->request[handler][isPage]; |
134 |
|
|
} |
135 |
joko |
1.1 |
|
136 |
|
|
} |
137 |
joko |
1.4 |
|
138 |
joko |
1.1 |
?> |