URI
By: fruffl | Date: Feb 17 2010 17:00 | Format: PHP | Expires: never | Size: 7.56 KB | Hits: 966
- <?php
- CLASS ILLI_SequenceBoot_LinkKernel_SegmentUri EXTENDS ILLI_SequenceBoot_LinkKernel_Segment
- {
- private $forwardToUri = '';
- public function init(){}
- public function run()
- {
- $REGISTRY = $this->_root->Boot->System->Registry;
- $SESSION = $this->_root->Boot->Kernel->Params->Session;
- $this->forwardTo = $this->repair
- (
- $REGISTRY->get()->URI->PATH,
- $REGISTRY->get()->URI->ROOT,
- $REGISTRY->get()->URI->BASE,
- $REGISTRY->get()->PARAMS->GET
- );
- $forward = FALSE;
- if($REGISTRY->get()->SERVER->REQUEST == 'POST')
- {
- $SESSION->add
- (
- 'POST',
- $REGISTRY->get()->PARAMS->POST
- );
- if($this->forwardTo === FALSE)
- {
- // url accepted: forward to self-uri
- $this->forwardTo = $REGISTRY->get()->URI->ROOT;
- $forward = TRUE;
- }
- else
- {
- // url contains wrong params; forward to repaired uri
- $forward = TRUE;
- }
- }
- if($REGISTRY->get()->SERVER->REQUEST == 'GET')
- {
- if($this->forwardTo === FALSE)
- {
- // url accepted
- ### PASSED
- // load POST-data from SESSION
- $REGISTRY->remove
- (
- 'PARAMS',
- 'POST'
- )->add
- (
- 'PARAMS',
- 'POST',
- $SESSION->get('POST')
- );
- $SESSION->remove('POST');
- }
- else
- {
- // url contains wrong params; forward to repaired uri
- $forward = TRUE;
- }
- }
- if($forward)
- $REGISTRY->add
- (
- 'HEADER',
- 'location',
- $this->forwardTo
- );
- }
- private function repair($env_path, $env_uri, $env_base, ILLI_ArrayObject $clean_query)
- {
- // repair broken uri-parts
- // global: url-part wich contains .php are forbidden; base ends alway with '/' to simulate directories
- // if mod_rewrite is disabled: first arg must be {curpage}.php
- // create new query-string from cleaned get-vars
- // kill query-string to cleanup
- $uri = $env_uri;
- $valide_uri = $uri;
- $qry = '';
- {
- foreach($clean_query as $k => $v)
- {
- {
- }
- {
- $str .= $k.'='.$v;
- }
- if($v === NULL)
- {
- $str .= $k;
- }
- }
- $qry = '?'.$qry.$str;
- }
- // environment-base ends never with '.php' if mod_rewrite is enabled: kill it
- // forward
- // http://localhost/ILLI/vc4000/public_html2/{curpage}.php
- // http://localhost/ILLI/vc4000/public_html2/{curpage}.php/
- // to
- // http://localhost/ILLI/vc4000/public_html2/
- // forward
- // http://localhost/ILLI/vc4000/public_html2/{curpage}.php?page=1
- // http://localhost/ILLI/vc4000/public_html2/{curpage}.php/?page=1
- // to
- // http://localhost/ILLI/vc4000/public_html2/?page=1
- // forward
- // http://localhost/ILLI/vc4000/public_html2/test
- // http://localhost/ILLI/vc4000/public_html2/{curpage}.php/test
- // to
- // http://localhost/ILLI/vc4000/public_html2/test/
- // forward
- // http://localhost/ILLI/vc4000/public_html2/{curpage}.php/test/foo.php?page=1
- // http://localhost/ILLI/vc4000/public_html2/{curpage}.php/test/foo.php/?page=1
- // http://localhost/ILLI/vc4000/public_html2/test?page=1
- // http://localhost/ILLI/vc4000/public_html2/{curpage}.php/test?page=1
- // http://localhost/ILLI/vc4000/public_html2/{curpage}.php/test/?page=1
- // to
- // http://localhost/ILLI/vc4000/public_html2/test/?page=1
- {
- // find and kill rootpage:
- // http://localhost/ILLI/vc4000/public_html/index.php/foo/bar
- // to
- // http://localhost/ILLI/vc4000/public_html/foo/bar
- // find and kill php-ending base-parts:
- // http://localhost/ILLI/vc4000/public_html/index.php/foo/bar.php
- // to
- // http://localhost/ILLI/vc4000/public_html/foo/
- {
- (
- (
- $uri,
- (
- (
- (
- (
- $uri,
- PATHINFO_FILENAME
- )
- ).'.php'
- ) * -1
- )
- ),
- NULL,
- $uri
- );
- }
- $valide_uri = $valide_uri.'/'.$qry;
- }
- // mod_rewrite is disabled: kill all *.php-named args (ignore the location '{install_dir}/{curpage}.php')
- // forward
- // http://localhost/ILLI/vc4000/public_html2/{curpage}.php/
- // to
- // http://localhost/ILLI/vc4000/public_html2/{curpage}.php
- // forward
- // http://localhost/ILLI/vc4000/public_html2/{curpage}.php/?page=1
- // to
- // http://localhost/ILLI/vc4000/public_html2/{curpage}.php?page=1
- // forward
- // http://localhost/ILLI/vc4000/public_html2/{curpage}.php/test
- // to
- // http://localhost/ILLI/vc4000/public_html2/{curpage}.php/test/
- // forward
- // http://localhost/ILLI/vc4000/public_html2/{curpage}.php/test/foo.php?page=1
- // http://localhost/ILLI/vc4000/public_html2/{curpage}.php/test/foo.php/?page=1
- // http://localhost/ILLI/vc4000/public_html2/{curpage}.php/test?page=1
- // to
- // http://localhost/ILLI/vc4000/public_html2/{curpage}.php/test/?page=1
- else
- {
- // if current loacation is "{install_dir}/" forward to {install_dir}/{curpage}.php[/?query-string]
- if($env_path == $uri)
- $valide_uri = $env_base;
- // if path = '/' your current location is {install_dir}/index.php
- if($env_path != '/')
- {
- // the last part in path can't be an php-file-name
- {
- // the base ({install_dir}/index.php)
- // + path without the last part
- //
- // {install_dir}/index.php/test.php, {install_dir}/index.php/site/test.php...
- // kill test.php and forward to the next parent
- if($uri != $env_base)
- {
- (
- (
- $uri,
- (
- (
- (
- (
- $uri,
- PATHINFO_FILENAME
- )
- ).'.php'
- ) * -1
- )
- ),
- NULL,
- $uri
- );
- }
- }
- }
- {
- $valide_uri = $valide_uri.$qry;
- }
- else
- {
- $valide_uri = $valide_uri.'/'.$qry;
- }
- }
- {
- }
- if($_SERVER['REQUEST_URI'] != $valide_uri)
- return $valide_uri;
- return false;
- }
- }
Latest pastes
50 minutes ago
10 hours ago
1 days ago
2 days ago
2 days ago