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) {
|
|
|
|
|
|
|
|
// 页面寻找失败,寻找资源文件
|
|
|
|
|
2023-01-25 13:03:58 +08:00
|
|
|
if ( // 搜索全局资源文件夹的指定文件
|
|
|
|
file_exists($resLoc = "./data/%assets/$req")
|
|
|
|
) {} else if ( // 搜索原始路径上的文件
|
|
|
|
file_exists($resLoc = "./data/$req")
|
|
|
|
) {} else if ( // 搜索可能存在的书籍资源文件夹中的指定文件
|
|
|
|
sizeof($uri) > 1 && ($resBook = (SiteMeta::getBookshelf()->getBook($uri[0]))) != null &&
|
|
|
|
file_exists($resLoc = "./data/{$resBook->getId()}/%assets/$uri[1]")
|
|
|
|
) {} else if ( // 上面的 %root 兼容
|
|
|
|
sizeof($uri) > 1 && ($resBook = $uri[0]) == "%root" &&
|
|
|
|
file_exists($resLoc = "./data/$resBook/%assets/$uri[1]")
|
|
|
|
) {} else if ( // 搜索以root书为根目录的原始路径上的文件
|
|
|
|
file_exists($resLoc = "./data/%root/$req")
|
|
|
|
) {} else if ( // 搜索root书中的书籍资源文件夹中的文件
|
|
|
|
file_exists($resLoc = "./data/%root/%assets/$req")
|
|
|
|
) {} else {
|
|
|
|
throw $e; // 找不到资源文件
|
2021-05-05 14:57:15 +08:00
|
|
|
}
|
|
|
|
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>";
|
|
|
|
|
|
|
|
}
|