2015-08-01 15:27:07 +00:00
|
|
|
<?php
|
2021-12-14 18:32:47 +00:00
|
|
|
|
2023-01-10 21:21:26 +00:00
|
|
|
declare(strict_types=1);
|
|
|
|
|
2023-01-10 22:44:09 +00:00
|
|
|
namespace Shimmie2;
|
|
|
|
|
2020-04-02 21:31:57 +00:00
|
|
|
// custom routing for stand-alone mode, basically
|
|
|
|
// .htaccess for the built-in php web server
|
2019-05-28 16:59:38 +00:00
|
|
|
if (PHP_SAPI !== 'cli-server') {
|
|
|
|
die('cli only');
|
|
|
|
}
|
2015-08-01 15:27:07 +00:00
|
|
|
|
|
|
|
// warehouse files
|
2019-05-28 16:59:38 +00:00
|
|
|
$matches = [];
|
2020-04-02 21:31:57 +00:00
|
|
|
if (preg_match('/\/_(images|thumbs)\/([0-9a-f]{2})([0-9a-f]{30}).*$/', $_SERVER["REQUEST_URI"], $matches)) {
|
2019-05-28 16:59:38 +00:00
|
|
|
header('Content-Type: image/jpeg');
|
2020-03-25 19:57:39 +00:00
|
|
|
header("Cache-control: public, max-age=86400");
|
2020-04-02 21:31:57 +00:00
|
|
|
print(file_get_contents("data/$matches[1]/$matches[2]/$matches[2]$matches[3]"));
|
2019-05-28 16:59:38 +00:00
|
|
|
return true;
|
2015-08-01 15:27:07 +00:00
|
|
|
}
|
|
|
|
|
2020-04-02 21:31:57 +00:00
|
|
|
// if file exists, serve it as normal
|
|
|
|
elseif (is_file("." . explode("?", $_SERVER["REQUEST_URI"])[0])) {
|
|
|
|
return false;
|
2015-08-01 15:27:07 +00:00
|
|
|
}
|
|
|
|
|
2015-08-01 13:25:53 +00:00
|
|
|
// all other requests (use shimmie routing based on URL)
|
2020-04-02 21:31:57 +00:00
|
|
|
else {
|
|
|
|
unset($matches);
|
|
|
|
// PHP_SELF is very unreliable, but there's no(?) better way to know what
|
|
|
|
// website subdirectory we're installed in - if we're using router.php, then
|
|
|
|
// let's blindly assume that we're in the root directory.
|
|
|
|
$_SERVER["PHP_SELF"] = "/index.php";
|
|
|
|
$_GET['q'] = explode("?", $_SERVER["REQUEST_URI"])[0];
|
|
|
|
// if we use a custom handler, we need to do our own access log
|
|
|
|
error_log("{$_SERVER['REMOTE_ADDR']}:{$_SERVER['REMOTE_PORT']} [???]: {$_GET['q']}");
|
|
|
|
require_once "index.php";
|
|
|
|
}
|