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