新建一次合并、继续重构

This commit is contained in:
2025-08-22 11:00:35 +08:00
parent e62ae0968d
commit 6e79e2ee40
18 changed files with 677 additions and 64 deletions

View File

@@ -1,20 +0,0 @@
<?php
// 获取请求的 URL 路径
$requestUri = $_SERVER['REQUEST_URI'];
$path = strtok($requestUri, '?');
// 定义路由规则
$routes = [
'/' => 're_blog.php',
'/blog/md/post/s/' => '../src/views/posts.php',
];
// 根据 URL 找到对应的文件
if (array_key_exists($path, $routes)) {
require $routes[$path];
} else {
// 如果找不到对应的 URL返回 404 错误
http_response_code(404);
require '../src/views/error/404.html';
}

View File

@@ -31,6 +31,11 @@
<font size="3.2">
<table border="0">
<tbody>
<tr>
<td id="td_logs">2025.08.20</td>
<td id="td_logs_content">路由模式修改完善、现在开始重写文章系统</td>
</tr>
<tr>
<td id="td_logs">2025.08.19</td>
<td id="td_logs_content">修改php_web的路由方式</td>

9
public/blog/master/index.html Executable file
View File

@@ -0,0 +1,9 @@
<html>
<head>
<meta charset="utf-8" lang="zh-CN">
<title>master 页面</title>
</head>
<body>
<a href="./push.php">跳转建立索引</a>
</body>
</html>

View File

@@ -1 +0,0 @@
{2025/07/30};{"第一篇文章"}

View File

@@ -1,27 +1,27 @@
<?php
// 1. 定义要写入的文件路径
$file = './index.txt';
$file = '../../../databases/no_db/post.text';
// 2. 检查是否通过 POST 请求接收到了数据
// 'data' 是表单中 <textarea> 标签的 name 属性
if (isset($_POST['data']) && !empty($_POST['data'])) {
// 自动获取当前日期和时间
// 自动获取当前日期
$date = date('Y/m/d');
// 获取你在网页输入框中写的数据
$data = $_POST['data'];
// 3. 构建完整的单行内容,格式为 {日期};{数据},并以换行符 \n 结尾
$content = "{" . $date . "};" . "{" . '"' . $data . '"' . "}" . "\n";
// 3. 构建完整的单行内容
// 使用 PHP_EOL 常量确保正确的换行符
$content = "{" . $date . "};" . "{" . '"' . $data . '"' . "}" . ";" . PHP_EOL;
// 4. 将内容追加到文件末尾
$result = file_put_contents($file, $content, FILE_APPEND | LOCK_EX);
// 5. 检查是否写入成功并给出反馈
if ($result !== false) {
echo "数据已成功写入到 " . $file . " 文件。你可以 <a href='https://open-ww3-project.ww3.tw/blog/master/'>返回</a>。";
echo "数据已成功写入到 " . $file . " 文件。你可以 <a href='https://open-ww3-project.ww3.tw/blog/master/push.php'>返回</a>。";
} else {
echo "写入文件失败,请检查文件权限。";
}

View File

@@ -1,9 +1,8 @@
<?php
?>
<title>master</title>
<style>
body { font-family: Arial, sans-serif; padding: 20px; }
textarea { width: 400px; height: 150px; }
input[type="submit"] { padding: 10px 20px; font-size: 16px; cursor: pointer; }
</style>
<form action="post_data.php" method="POST">
<textarea name="data" placeholder="在这里输入数据..."></textarea>

View File

@@ -2,4 +2,4 @@
require './MD.php';
$md=new MD('114514.md');
$md->output();
$md->output();

View File

@@ -1,33 +1,30 @@
<?php
$file = './master/index.txt'; //定义文件的位置
if (file_exists($file)) {
$content = file_get_contents($file);
$file = '../../databases/no_db/post.text'; //定义文件的位置
//分割输出内容
$lines = explode("\n",$content);
$content = file_get_contents($file);
//逐行解析
foreach ($lines as $line) {
if (preg_match('/\{([^}]+)\};\{"([^"]+)\"}/', $line, $matches)) {
//分割输出内容
$lines = explode("\n",$content);
$sequence_id = 1; // 设定id起始数字
echo "文章如下: ";
foreach ($lines as $line) {
if (preg_match('/\{([^}]+)\};\{"([^"]+)\"};/', $line, $matches)) {
$data = $matches[1]; // 提取出数据
$title = $matches[2]; // 提取出标题
echo "文章如下: ";
// 输出提取到的内容
echo "<br><br>";
echo "文章顺序ID: " . $sequence_id . "<br>"; // 输出顺序ID
echo "" . $data . "\n";
echo "" . $title . "\n";
echo "<a href='https://ww3.tw/blog/md/post/s/$data' style='color: black;'> 跳转页面</a>";
echo "<a href='https://ww3.tw/blog/md/post/s/$sequence_id' style='color: black;'> 跳转页面</a>";
//echo '链接 (URL): <a herf="">链接</a>';
$sequence_id++; // 每次循环后顺序ID加1
}
}
//输出内容
//echo "文件 '{$file}' 的内容是: <br><br>\n\n";
//echo $content;
} else {
echo "错误: 文件 '$file' 不存在 ";
}
?>

View File

@@ -8,6 +8,7 @@
switch($request_uri){
case '/':
include './re_blog.php';
exit(); // 执行成功立即结束
break;
}
@@ -15,13 +16,13 @@
// posts 路由
include "./request/posts.php";
// 所有路由匹配结束后,检查是否找到路由
if (!$found_route) {
if (!$found_route) {
// 设置 HTTP 状态码为 404
header("HTTP/1.0 404 Not Found");
// 包含 404 页面文件
exit();
//exit();
include "../src/views/error/404.html";
}
exit(); // 执行成功立即结束
}

View File

@@ -1,6 +1,32 @@
<?php
switch($request_uri){
case '/blog/md/';
include '/var/www/owp/open-ww3-project-ww3-tw/md/inite.php';
exit(); // 执行成功立即结束
case '/blog/md/post/';
include '../src/views/posts.php';
include '../src/views/post.php';
exit(); // 执行成功立即结束
break;
case '/blog/md/post/s/2025/07/30/';
header("Location: https://ww3.tw/blog/md/post/s/1");
exit(); // 执行成功立即结束
break;
case '/blog/md/post/s/2025/07/30';
header("Location: https://ww3.tw/blog/md/post/s/1");
exit(); // 执行成功立即结束
break;
}
$post_id = null; // 初始化 post_id 变量
switch(true){
case preg_match('/^\/blog\/md\/post\/s\/(\d+)$/', $request_uri, $matches):
$post_id = (int)$matches[1];
include "../src/views/posts.php";
exit(); // 执行成功立即结束
break;
}