2021-04-26 00:10:50 +08:00
|
|
|
<?php
|
|
|
|
|
2021-04-26 23:08:55 +08:00
|
|
|
|
2021-04-26 00:10:50 +08:00
|
|
|
require_once "./src/Data/SiteMeta.php";
|
|
|
|
require_once "./src/Data/PageMeta.php";
|
2021-05-05 14:57:15 +08:00
|
|
|
require_once "./src/Utils/PageParse.php";
|
|
|
|
require_once "./src/Utils/RequestNotExistException.php";
|
2021-04-26 23:08:55 +08:00
|
|
|
|
|
|
|
|
2021-04-26 00:10:50 +08:00
|
|
|
|
|
|
|
try {
|
|
|
|
|
|
|
|
SiteMeta::load();
|
2021-04-26 22:02:22 +08:00
|
|
|
|
|
|
|
// 格式化所给链接,并将链接转化为路径字符串数组
|
2021-05-05 14:57:15 +08:00
|
|
|
$req = $_GET['p'];
|
|
|
|
if (strlen($req) > 0 && $req[strlen($req) - 1] === '/')
|
|
|
|
$tmp = substr($req, 0, -1);
|
|
|
|
$uri = explode("/", $req, 2);
|
2021-04-26 22:02:22 +08:00
|
|
|
|
2021-05-05 14:57:15 +08:00
|
|
|
try {
|
|
|
|
|
|
|
|
// 寻找页面
|
|
|
|
|
|
|
|
if (sizeof($uri) > 0 && $uri[0] != null) {
|
|
|
|
// 非主页面,判定当前定义的 book
|
2021-11-25 03:36:59 +08:00
|
|
|
if ($uri[0] == "%root") {
|
|
|
|
PageMeta::$book = SiteMeta::getBookshelf()->getRootBook();
|
|
|
|
} else {
|
|
|
|
$tmp = SiteMeta::getBookshelf()->getBook($uri[0]);
|
|
|
|
if ($tmp == null)
|
|
|
|
throw new RequestNotExistException("Book required \"$uri[0]\" not found!");
|
|
|
|
PageMeta::$book = $tmp->getContentedNode();
|
|
|
|
}
|
|
|
|
|
2021-05-05 14:57:15 +08:00
|
|
|
// 判定当前页面
|
|
|
|
if (sizeof($uri) > 1 && $uri[1] != null) {
|
|
|
|
$tmp = PageMeta::$book->getPage($uri[1]);
|
|
|
|
if ($tmp == null) throw new RequestNotExistException("Page required \"$uri[1]\" not found on book \"$uri[0]\"!");
|
|
|
|
PageMeta::$page = $tmp;
|
|
|
|
} else {
|
|
|
|
PageMeta::$page = PageMeta::$book->getChilds()->getChilds()[0];
|
|
|
|
}
|
2021-04-26 22:02:22 +08:00
|
|
|
} else {
|
2021-05-05 14:57:15 +08:00
|
|
|
// 主页面
|
|
|
|
PageMeta::$book = SiteMeta::getBookshelf()->getRootBook();
|
2021-04-26 22:02:22 +08:00
|
|
|
PageMeta::$page = PageMeta::$book->getChilds()->getChilds()[0];
|
2021-05-05 14:57:15 +08:00
|
|
|
PageMeta::$isMainPage = true;
|
2021-04-26 22:02:22 +08:00
|
|
|
}
|
2021-05-05 14:57:15 +08:00
|
|
|
|
|
|
|
} catch (RequestNotExistException $e) {
|
|
|
|
|
|
|
|
// 页面寻找失败,寻找资源文件
|
|
|
|
|
|
|
|
if (!is_file($resLoc = "./data/%assets/$req")) { // 全局文件夹的资源文件
|
|
|
|
throw $e;
|
|
|
|
}
|
|
|
|
PageParse::outputBinaryFile($resLoc);
|
|
|
|
|
2021-04-26 22:02:22 +08:00
|
|
|
}
|
2021-04-26 00:10:50 +08:00
|
|
|
|
|
|
|
require "./template/header.php";
|
|
|
|
|
2021-11-22 22:53:02 +08:00
|
|
|
require "./template/nav.php";
|
|
|
|
|
|
|
|
require "./template/main.php";
|
2021-04-26 00:10:50 +08:00
|
|
|
|
|
|
|
require "./template/footer.php";
|
|
|
|
|
|
|
|
} catch (Exception $e) {
|
|
|
|
|
|
|
|
echo "<h1>ERROR</h1><p>" . $e->getMessage() . "</p>";
|
|
|
|
|
|
|
|
}
|