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;
|
2023-01-25 13:48:03 +08:00
|
|
|
use SukWs\Bookshelf\Data\SiteConfig\RobotsPolicy;
|
2023-01-24 20:30:27 +08:00
|
|
|
use SukWs\Bookshelf\Data\SiteMeta;
|
2023-04-04 21:08:08 +08:00
|
|
|
use SukWs\Bookshelf\Resource\Assets;
|
|
|
|
use SukWs\Bookshelf\Resource\Data;
|
2023-01-24 20:30:27 +08:00
|
|
|
use SukWs\Bookshelf\Utils\PageParse;
|
2023-03-25 20:11:10 +08:00
|
|
|
use SukWs\Bookshelf\Web\Main;
|
|
|
|
|
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
|
|
|
|
2023-01-25 13:48:03 +08:00
|
|
|
// 为 robots.txt 进行特别支持
|
|
|
|
if (sizeof($uri) == 1 && $uri[0] == "robots.txt") {
|
|
|
|
|
|
|
|
$policy = SiteMeta::getRobotsPolicy();
|
|
|
|
|
|
|
|
switch ($policy) {
|
|
|
|
case RobotsPolicy::allow:
|
2023-04-04 21:08:08 +08:00
|
|
|
exit(Assets::get("robots.allow")->get_content());
|
2023-01-25 13:48:03 +08:00
|
|
|
case RobotsPolicy::deny:
|
2023-04-04 21:08:08 +08:00
|
|
|
exit(Assets::get("robots.deny")->get_content());
|
2023-01-25 13:48:03 +08:00
|
|
|
case RobotsPolicy::file:
|
2023-04-04 21:08:08 +08:00
|
|
|
exit(Data::get("./data/robots.txt")->get_content());
|
2023-01-25 13:48:03 +08:00
|
|
|
case RobotsPolicy::raw:
|
|
|
|
exit(SiteMeta::getConfigurationLevelShelf("site.robots"));
|
|
|
|
}
|
|
|
|
|
2023-03-25 20:11:10 +08:00
|
|
|
} else if (PageMeta::init($uri)) {
|
2021-05-05 14:57:15 +08:00
|
|
|
|
2023-03-25 20:11:10 +08:00
|
|
|
require "./template/header.php";
|
2021-05-05 14:57:15 +08:00
|
|
|
|
2023-03-25 20:11:10 +08:00
|
|
|
require "./template/nav.php";
|
|
|
|
|
|
|
|
Main::main(PageMeta::$page_data);
|
2021-05-05 14:57:15 +08:00
|
|
|
|
2023-03-25 20:11:10 +08:00
|
|
|
require "./template/footer.php";
|
|
|
|
|
|
|
|
} else {
|
2021-05-05 14:57:15 +08:00
|
|
|
|
|
|
|
// 页面寻找失败,寻找资源文件
|
|
|
|
|
2023-01-25 13:03:58 +08:00
|
|
|
if ( // 搜索全局资源文件夹的指定文件
|
2023-03-27 16:26:35 +08:00
|
|
|
is_file($resLoc = "./data/%assets/$req")
|
2023-01-25 13:03:58 +08:00
|
|
|
) {} else if ( // 搜索原始路径上的文件
|
2023-03-27 16:26:35 +08:00
|
|
|
is_file($resLoc = "./data/$req")
|
2023-01-25 13:03:58 +08:00
|
|
|
) {} else if ( // 搜索可能存在的书籍资源文件夹中的指定文件
|
|
|
|
sizeof($uri) > 1 && ($resBook = (SiteMeta::getBookshelf()->getBook($uri[0]))) != null &&
|
2023-03-27 16:26:35 +08:00
|
|
|
is_file($resLoc = "./data/{$resBook->getId()}/%assets/$uri[1]")
|
2023-01-25 13:03:58 +08:00
|
|
|
) {} else if ( // 上面的 %root 兼容
|
|
|
|
sizeof($uri) > 1 && ($resBook = $uri[0]) == "%root" &&
|
2023-03-27 16:26:35 +08:00
|
|
|
is_file($resLoc = "./data/$resBook/%assets/$uri[1]")
|
2023-01-25 13:03:58 +08:00
|
|
|
) {} else if ( // 搜索以root书为根目录的原始路径上的文件
|
2023-03-27 16:26:35 +08:00
|
|
|
is_file($resLoc = "./data/%root/$req")
|
2023-01-25 13:03:58 +08:00
|
|
|
) {} else if ( // 搜索root书中的书籍资源文件夹中的文件
|
2023-03-27 16:26:35 +08:00
|
|
|
is_file($resLoc = "./data/%root/%assets/$req")
|
2023-01-25 13:03:58 +08:00
|
|
|
) {} else {
|
2023-03-25 20:11:10 +08:00
|
|
|
throw new Exception("cannot find file " . $req); // 找不到资源文件
|
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
|
|
|
|
|
|
|
} catch (Exception $e) {
|
|
|
|
|
|
|
|
echo "<h1>ERROR</h1><p>" . $e->getMessage() . "</p>";
|
|
|
|
|
|
|
|
}
|