|
|
@@ -12,43 +12,56 @@ class Router
|
|
|
|
|
|
function __construct()
|
|
|
{
|
|
|
- $this->request = $_SERVER["REQUEST_URI"];
|
|
|
- $this->data = null;
|
|
|
+ $request = $_SERVER["REQUEST_URI"];
|
|
|
+ $this->data = $this->requestingDate = null;
|
|
|
|
|
|
- if ($this->request[0] == '/')
|
|
|
- $this->request = substr($this->request, 1);
|
|
|
+ if ($request[0] == '/')
|
|
|
+ $request = substr($request, 1);
|
|
|
+ $this->request = $request;
|
|
|
|
|
|
- if ($this->request == "")
|
|
|
+ if (substr($request, -4) == ".jpg")
|
|
|
+ $request = substr($request, 0, -4);
|
|
|
+
|
|
|
+ if ($request == "")
|
|
|
$this->requestingDate = $this->checkFileExists($this->LATEST);
|
|
|
- else if (strlen($this->request) == 6)
|
|
|
+ else if (strlen($request) == 6)
|
|
|
{
|
|
|
$isNumeric = true;
|
|
|
|
|
|
for ($i =0; $i < 6; $i++)
|
|
|
{
|
|
|
- if (!is_numeric($this->request[$i]))
|
|
|
+ if (!is_numeric($request[$i]))
|
|
|
{
|
|
|
$isNumeric = false;
|
|
|
break;
|
|
|
}
|
|
|
}
|
|
|
if ($isNumeric)
|
|
|
- $this->requestingDate = $this->checkFileExists($this->request);
|
|
|
+ $this->requestingDate = $this->checkFileExists($request);
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+ public function getImageForRequest()
|
|
|
+ {
|
|
|
+ if ($this->requestingDate === null)
|
|
|
+ return "";
|
|
|
+ return "/{$this->requestingDate}.jpg";
|
|
|
+ }
|
|
|
+
|
|
|
private function checkFileExists($yymmdd)
|
|
|
{
|
|
|
+ $now = (int) (new \Datetime())->format("ymd");
|
|
|
if ($yymmdd != $this->LATEST)
|
|
|
{
|
|
|
// TODO use index cache
|
|
|
+ if ((int) $yymmdd > $now) // Anti spoil
|
|
|
+ return null;
|
|
|
if (file_exists("../data/${yymmdd}.json"))
|
|
|
return $yymmdd;
|
|
|
return null;
|
|
|
}
|
|
|
else
|
|
|
{
|
|
|
- $now = (int) (new \Datetime())->format("ymd");
|
|
|
$min = 0;
|
|
|
|
|
|
// obvious today-is-the-day
|
|
|
@@ -76,6 +89,21 @@ class Router
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+ public function isRequestingImage()
|
|
|
+ {
|
|
|
+ return (substr($this->request, -4) === ".jpg");
|
|
|
+ }
|
|
|
+
|
|
|
+ public function isGetRequest()
|
|
|
+ {
|
|
|
+ return $_SERVER["REQUEST_METHOD"] === "GET";
|
|
|
+ }
|
|
|
+
|
|
|
+ public function isPostUri()
|
|
|
+ {
|
|
|
+ return $this->request == "post";
|
|
|
+ }
|
|
|
+
|
|
|
public function isLost()
|
|
|
{
|
|
|
if ($this->requestingDate === null)
|
|
|
@@ -96,7 +124,7 @@ class Router
|
|
|
{
|
|
|
$req = $this->requestingDate;
|
|
|
|
|
|
- return new Flammenkuchen(json_decode(file_get_contents("../data/${req}.json")));
|
|
|
+ return Flammenkuchen::fromJson(json_decode(file_get_contents("../data/${req}.json")));
|
|
|
}
|
|
|
}
|
|
|
|