update
This commit is contained in:
@@ -0,0 +1,167 @@
|
||||
<?php
|
||||
init();
|
||||
?>
|
||||
|
||||
<!doctype html>
|
||||
<html>
|
||||
<head>
|
||||
<meta charset="utf-8">
|
||||
<meta http-equiv="X-UA-Compatible" content="IE=edge">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1">
|
||||
<link rel="shortcut icon" href="/favicon.ico"/>
|
||||
<title><?php echo get_page_title(); ?></title>
|
||||
<link rel="stylesheet" href="/css/style.css">
|
||||
</head>
|
||||
<body>
|
||||
|
||||
<div class="flex h-12 bg-black w-full p-3">
|
||||
<div class="flex text-xl text-light-200">
|
||||
Logo
|
||||
</div>
|
||||
|
||||
<div class="flex space-x-5 text-light-200 text-xl px-5">
|
||||
<div>
|
||||
<a href="/">Hello</a>
|
||||
</div>
|
||||
<div>
|
||||
<a href="/about">About</a>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="flex justify-center">
|
||||
|
||||
<div class="md:w-2/3 w-full p-2 md:p-3">
|
||||
<?php show_page(); ?>
|
||||
</div>
|
||||
</div>
|
||||
</body>
|
||||
</html>
|
||||
|
||||
<!--page func-->
|
||||
<?php function show_index()
|
||||
{
|
||||
ob_start(); ?>
|
||||
|
||||
<div class="">
|
||||
|
||||
</div>
|
||||
|
||||
|
||||
<?php
|
||||
$html = ob_get_contents();
|
||||
ob_clean();
|
||||
echo $html;
|
||||
}
|
||||
|
||||
?>
|
||||
|
||||
<?php function show_about()
|
||||
{
|
||||
ob_start(); ?>
|
||||
|
||||
<div class="">
|
||||
about
|
||||
</div>
|
||||
|
||||
|
||||
<?php
|
||||
$html = ob_get_contents();
|
||||
ob_clean();
|
||||
echo $html;
|
||||
}
|
||||
|
||||
?>
|
||||
|
||||
<?php function show_404()
|
||||
{
|
||||
ob_start(); ?>
|
||||
|
||||
<div class="">
|
||||
404 NOT FOUND
|
||||
</div>
|
||||
|
||||
|
||||
<?php
|
||||
$html = ob_get_contents();
|
||||
ob_clean();
|
||||
echo $html;
|
||||
}
|
||||
|
||||
?>
|
||||
<!--page func end-->
|
||||
|
||||
<!--api-->
|
||||
<?php
|
||||
|
||||
function check_api()
|
||||
{
|
||||
$uri = $_SERVER["REQUEST_URI"];
|
||||
$func = ltrim(implode("_", explode("/", $uri)), "_");
|
||||
if (str_starts_with($uri, "/api")) {
|
||||
if (!function_exists($func)) echo_json([
|
||||
"code" => 1,
|
||||
"msg" => "uri错误",
|
||||
"data" => []
|
||||
]);
|
||||
|
||||
call_user_func($func);
|
||||
}
|
||||
}
|
||||
|
||||
function echo_json($data)
|
||||
{
|
||||
header('Content-Type: application/json; charset=utf-8');
|
||||
echo json_encode($data, JSON_UNESCAPED_UNICODE);
|
||||
die;
|
||||
}
|
||||
|
||||
function api_test()
|
||||
{
|
||||
echo_json([
|
||||
"code" => 0,
|
||||
"msg" => "test",
|
||||
"data" => []
|
||||
]);
|
||||
}
|
||||
|
||||
?>
|
||||
<!--api end-->
|
||||
|
||||
|
||||
<!--common func-->
|
||||
|
||||
<?php
|
||||
function init()
|
||||
{
|
||||
define("BASE_PATH", __DIR__ . "/../");
|
||||
define("CONFIG_PATH", BASE_PATH . "/./config/");
|
||||
empty($_SERVER['REQUEST_URI']) || $_SERVER['REQUEST_URI'] == "/" && $_SERVER['REQUEST_URI'] = "/index";
|
||||
|
||||
check_api();
|
||||
}
|
||||
|
||||
function get_page_title()
|
||||
{
|
||||
$uri = $_SERVER['REQUEST_URI'];
|
||||
$pages = json_decode(file_get_contents(CONFIG_PATH . "page.json"), true);
|
||||
return $pages[$uri]["title"] ?? "404 NOT FOUND";
|
||||
}
|
||||
|
||||
function show_page()
|
||||
{
|
||||
$uri = $_SERVER["REQUEST_URI"];
|
||||
$func = ltrim(implode("_", explode("/", $uri)), "_");
|
||||
|
||||
if (function_exists("show_{$func}")) {
|
||||
call_user_func("show_{$func}");
|
||||
} else {
|
||||
call_user_func("show_404");
|
||||
}
|
||||
}
|
||||
|
||||
?>
|
||||
<!--common func end-->
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user