separate router from index.php
This commit is contained in:
parent
3d5172e235
commit
21a1b176c6
3 changed files with 24 additions and 21 deletions
|
@ -1725,26 +1725,6 @@ function _get_query() {
|
|||
return @$_POST["q"]?:@$_GET["q"];
|
||||
}
|
||||
|
||||
function _router() {
|
||||
// custom routing for stand-alone mode
|
||||
if(php_sapi_name() == 'cli-server') {
|
||||
// warehouse files
|
||||
$matches = array();
|
||||
if(preg_match('/\/_(images|thumbs)\/([0-9a-f]{32}).*$/', $_SERVER["REQUEST_URI"], $matches)) {
|
||||
header('Content-Type: image/jpeg');
|
||||
print(file_get_contents(warehouse_path($matches[1], $matches[2])));
|
||||
exit;
|
||||
}
|
||||
|
||||
// static files
|
||||
if(preg_match('/\.(?:png|jpg|jpeg|gif|css|js)$/', $_SERVER["REQUEST_URI"])) {
|
||||
return true;
|
||||
}
|
||||
|
||||
$_SERVER["PHP_SELF"] = '/';
|
||||
$_GET['q'] = $_SERVER["REQUEST_URI"];
|
||||
}
|
||||
}
|
||||
|
||||
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *\
|
||||
* Code coverage *
|
||||
|
|
|
@ -53,7 +53,6 @@ require_once "core/util.inc.php";
|
|||
// set up and purify the environment
|
||||
_version_check();
|
||||
_sanitise_environment();
|
||||
if(_router()) return false;
|
||||
|
||||
try {
|
||||
// load base files
|
||||
|
|
24
tests/router.php
Normal file
24
tests/router.php
Normal file
|
@ -0,0 +1,24 @@
|
|||
<?php
|
||||
// custom routing for stand-alone mode
|
||||
|
||||
if(php_sapi_name() != 'cli-server') {
|
||||
die('local testing only');
|
||||
}
|
||||
|
||||
// warehouse files
|
||||
$matches = array();
|
||||
if(preg_match('/\/_(images|thumbs)\/([0-9a-f]{32}).*$/', $_SERVER["REQUEST_URI"], $matches)) {
|
||||
header('Content-Type: image/jpeg');
|
||||
print(file_get_contents(warehouse_path($matches[1], $matches[2])));
|
||||
return true;
|
||||
}
|
||||
|
||||
// static files
|
||||
if(preg_match('/\.(?:png|jpg|jpeg|gif|css|js)$/', $_SERVER["REQUEST_URI"])) {
|
||||
return false;
|
||||
}
|
||||
|
||||
// all other requests
|
||||
$_SERVER["PHP_SELF"] = '/';
|
||||
$_GET['q'] = $_SERVER["REQUEST_URI"];
|
||||
require_once "index.php";
|
Reference in a new issue