2021-04-26 00:10:50 +08:00
|
|
|
<?php
|
|
|
|
|
2023-01-24 20:30:27 +08:00
|
|
|
require "./constant.php";
|
|
|
|
require "./vendor/autoload.php";
|
2021-04-26 23:08:55 +08:00
|
|
|
|
2023-01-24 20:30:27 +08:00
|
|
|
use SukWs\Bookshelf\Data\PageMeta;
|
|
|
|
use SukWs\Bookshelf\Data\SiteMeta;
|
|
|
|
use SukWs\Bookshelf\Utils\PageParse;
|
|
|
|
use SukWs\Bookshelf\Utils\RequestNotExistException;
|
2021-04-26 00:10:50 +08:00
|
|
|
|
|
|
|
try {
|
|
|
|
|
|
|
|
SiteMeta::load();
|
2021-04-26 22:02:22 +08:00
|
|
|
|
|
|
|
// 格式化所给链接,并将链接转化为路径字符串数组
|
2023-01-24 19:08:15 +08:00
|
|
|
$req = array_key_exists('p', $_GET) ? $_GET['p'] : "";
|
2021-05-05 14:57:15 +08:00
|
|
|
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 {
|
2023-01-24 20:30:27 +08:00
|
|
|
PageMeta::$page = PageMeta::$book->getChilds()->getChildren()[0];
|
2021-05-05 14:57:15 +08:00
|
|
|
}
|
2021-04-26 22:02:22 +08:00
|
|
|
} else {
|
2021-05-05 14:57:15 +08:00
|
|
|
// 主页面
|
|
|
|
PageMeta::$book = SiteMeta::getBookshelf()->getRootBook();
|
2023-01-24 20:30:27 +08:00
|
|
|
PageMeta::$page = PageMeta::$book->getChilds()->getChildren()[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>";
|
|
|
|
|
|
|
|
}
|