| 1 |
<? |
| 2 |
// ------------------------------------------------------------------------- |
| 3 |
// $Id: Request.php,v 1.3 2002/12/13 00:22:27 jonen Exp $ |
| 4 |
// ------------------------------------------------------------------------- |
| 5 |
// $Log: Request.php,v $ |
| 6 |
// 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 |
// 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 |
// Revision 1.1 2002/11/12 05:42:31 joko |
| 14 |
// + initial checkin |
| 15 |
// |
| 16 |
// ------------------------------------------------------------------------- |
| 17 |
|
| 18 |
|
| 19 |
class Site_Request { |
| 20 |
|
| 21 |
// site's instance |
| 22 |
var $site; |
| 23 |
|
| 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 |
var $request; |
| 32 |
|
| 33 |
function getRequest() { |
| 34 |
$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 |
|
| 70 |
function _parse() { |
| 71 |
|
| 72 |
//print "_parse<br>"; |
| 73 |
|
| 74 |
// generic identifier |
| 75 |
$ident = $this->site->decodeIdentifier($this->raw[identifier]); |
| 76 |
|
| 77 |
//print "ident: $ident<br>"; |
| 78 |
|
| 79 |
// get handler for identifier |
| 80 |
//$handler = $this->getHandler($ident); |
| 81 |
$this->site->log( get_class($this) . "->_parse: getHandler( identifier $ident )", LOG_DEBUG ); |
| 82 |
$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 |
'raw' => $this->raw, |
| 93 |
'ident' => $ident, |
| 94 |
'handler' => $handler, |
| 95 |
'action' => $action, |
| 96 |
); |
| 97 |
|
| 98 |
$this->request = $result; |
| 99 |
|
| 100 |
$this->meta[parse] = 1; |
| 101 |
|
| 102 |
} |
| 103 |
|
| 104 |
function getCached() { |
| 105 |
return $this->site->session->get('cachedRequest'); |
| 106 |
} |
| 107 |
|
| 108 |
function cacheRequest($request = array()) { |
| 109 |
if (!count($request)) { |
| 110 |
$request = $this->getRequest(); |
| 111 |
} |
| 112 |
//print Dumper($request); |
| 113 |
$this->site->session->set('cachedRequest', $request); |
| 114 |
} |
| 115 |
|
| 116 |
function overrideRequestIdentifier($ident) { |
| 117 |
$this->overrideIdentifier($ident); |
| 118 |
} |
| 119 |
|
| 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 |
function getIdentifier() { |
| 127 |
$this->_init(); |
| 128 |
return $this->request[ident]; |
| 129 |
} |
| 130 |
|
| 131 |
function isPage() { |
| 132 |
$this->_init(); |
| 133 |
return $this->request[handler][isPage]; |
| 134 |
} |
| 135 |
|
| 136 |
} |
| 137 |
|
| 138 |
?> |