新建一次合并、继续重构
This commit is contained in:
5
src/views/index.php
Executable file
5
src/views/index.php
Executable file
@@ -0,0 +1,5 @@
|
||||
<?php
|
||||
require './MD.php';
|
||||
|
||||
$md=new MD('114514.md');
|
||||
$md->output();
|
||||
35
src/views/post.php
Executable file
35
src/views/post.php
Executable file
@@ -0,0 +1,35 @@
|
||||
<center>
|
||||
<h1>
|
||||
全部文章
|
||||
</h1>
|
||||
</center>
|
||||
|
||||
<?php
|
||||
|
||||
$file = '../databases/no_db/post.text';
|
||||
|
||||
$content = file_get_contents($file);
|
||||
|
||||
//分割输出内容
|
||||
$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 "<br><br>";
|
||||
echo "文章顺序ID: " . $sequence_id . "<br>"; // 输出顺序ID
|
||||
echo "" . $data . "\n";
|
||||
echo "" . $title . "\n";
|
||||
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
|
||||
}
|
||||
}
|
||||
|
||||
//print_r ($lines);
|
||||
@@ -1 +1,36 @@
|
||||
edgvo,paogbp,eo,bg,o[]
|
||||
<?php
|
||||
// 在文件顶部启动 session
|
||||
session_start();
|
||||
|
||||
if (isset($post_id)) {
|
||||
$file_path = "../md/" . $post_id . ".md";
|
||||
|
||||
if (file_exists($file_path)) {
|
||||
// 检查是否是重定向后的请求
|
||||
if (isset($_SESSION['redirected_to_post']) && $_SESSION['redirected_to_post'] == $post_id) {
|
||||
// 是重定向后的请求,直接显示内容
|
||||
$content = file_get_contents($file_path);
|
||||
sleep(2);
|
||||
unset($_SESSION['redirected_to_post']); // 清除 session 标记,避免影响其他请求
|
||||
require_once '../md/MD.php';
|
||||
$md = new MD('../md/' . $post_id . '.md');
|
||||
|
||||
// 输出处理后的内容
|
||||
echo $md->output();
|
||||
|
||||
exit();
|
||||
} else {
|
||||
$random_string = substr(str_shuffle("a_bc-def_ghij-klmno_-pq-rs_tu-vwxyz-_$&_#12-34-567-8-0"), 0, 16);
|
||||
// 这是第一次请求,执行重定向
|
||||
echo "<h2>" . "找到id为" . $post_id . "的文章<br>正在为您跳转" . "</h2>";
|
||||
$delay = 0.5;
|
||||
$_SESSION['redirected_to_post'] = $post_id; // 设置 session 标记
|
||||
header("Refresh: $delay; url=/blog/md/post/s/$post_id#content&$random_string");
|
||||
exit();
|
||||
}
|
||||
} else {
|
||||
echo "<h2>没有id为" . $post_id . "的文章</h2>";
|
||||
}
|
||||
} else {
|
||||
echo "<h1>抱歉,没有找到对应id文章,请检查!</h1>";
|
||||
}
|
||||
Reference in New Issue
Block a user