新建一次合并、继续重构
This commit is contained in:
24
.gitignore
vendored
24
.gitignore
vendored
@@ -1,6 +1,22 @@
|
|||||||
|
#### 忽略目录
|
||||||
|
# 数据库
|
||||||
databases/*
|
databases/*
|
||||||
|
public/*.sql
|
||||||
|
public/*.db
|
||||||
|
|
||||||
|
# 博客文档
|
||||||
|
|
||||||
|
|
||||||
|
# 管理员面板
|
||||||
|
public/blog/master/passwd
|
||||||
|
|
||||||
|
|
||||||
|
# 可能未知
|
||||||
public/message/static/src/video/*
|
public/message/static/src/video/*
|
||||||
public/blog/md/post/*
|
|
||||||
public/blog/md/image/*
|
|
||||||
public/blog/md0/post/*
|
# 临时区
|
||||||
public/blog/md0/image/*
|
public/blog/md/*
|
||||||
|
public/blog/md0/*
|
||||||
|
|
||||||
|
# 临时区
|
||||||
11
md/1.md
Executable file
11
md/1.md
Executable file
@@ -0,0 +1,11 @@
|
|||||||
|
# 今天、2025.7.30
|
||||||
|
----
|
||||||
|
|
||||||
|
blog 正式 完工
|
||||||
|
|
||||||
|
测试
|
||||||
|
|
||||||
|
**署名**
|
||||||
|
|
||||||
|
<br>
|
||||||
|
SkimrMe_
|
||||||
479
md/MD.php
Executable file
479
md/MD.php
Executable file
@@ -0,0 +1,479 @@
|
|||||||
|
|
||||||
|
<?php
|
||||||
|
Header('Content:text/html;charset=utf-8');
|
||||||
|
?>
|
||||||
|
<meta name="viewport" content="width=device-width,initial-scale=1" />
|
||||||
|
<style>
|
||||||
|
body,ol,ul,li,img,p{
|
||||||
|
padding:0;
|
||||||
|
margin:0;
|
||||||
|
border:none;
|
||||||
|
}
|
||||||
|
|
||||||
|
li{
|
||||||
|
list-style-type: square;
|
||||||
|
padding:2px;
|
||||||
|
}
|
||||||
|
|
||||||
|
h1,h2,h3,h4,h5,h6{
|
||||||
|
margin:10px 0 0 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
h1,h2,h3{
|
||||||
|
border-bottom:solid 1px #ddd;
|
||||||
|
}
|
||||||
|
|
||||||
|
h1{
|
||||||
|
padding-bottom:12px;
|
||||||
|
}
|
||||||
|
|
||||||
|
h2{
|
||||||
|
padding-bottom: 6px;
|
||||||
|
}
|
||||||
|
|
||||||
|
h3{
|
||||||
|
padding-bottom: 2px;
|
||||||
|
}
|
||||||
|
|
||||||
|
body,ul{
|
||||||
|
padding:10px 20px;
|
||||||
|
}
|
||||||
|
|
||||||
|
body{
|
||||||
|
max-width:1024px;
|
||||||
|
margin:0 auto;
|
||||||
|
}
|
||||||
|
|
||||||
|
blockquote{
|
||||||
|
border-left:solid 4px #bbb;
|
||||||
|
background-color:#eee;
|
||||||
|
min-height:24px;
|
||||||
|
line-height:24px;
|
||||||
|
padding:0px 10px;
|
||||||
|
margin:0;
|
||||||
|
color:#333;
|
||||||
|
font-size:12px;
|
||||||
|
font-style: italic;
|
||||||
|
font-family: consolas,楷体;
|
||||||
|
}
|
||||||
|
|
||||||
|
table{
|
||||||
|
width:100%;
|
||||||
|
}
|
||||||
|
|
||||||
|
table,td,th{
|
||||||
|
border:solid 1px #ddd;
|
||||||
|
border-collapse: collapse;
|
||||||
|
padding:10px;
|
||||||
|
font-family: consolas;
|
||||||
|
font-size:14px;
|
||||||
|
}
|
||||||
|
|
||||||
|
table{
|
||||||
|
margin:10px 0;
|
||||||
|
text-align:center;
|
||||||
|
}
|
||||||
|
|
||||||
|
.table-left{
|
||||||
|
text-align:left;
|
||||||
|
}
|
||||||
|
|
||||||
|
.table-center{
|
||||||
|
text-align: center;
|
||||||
|
}
|
||||||
|
|
||||||
|
.table-right{
|
||||||
|
text-align: right;
|
||||||
|
}
|
||||||
|
|
||||||
|
tr:nth-child(even){
|
||||||
|
background-color:#eee;
|
||||||
|
}
|
||||||
|
|
||||||
|
code,pre{
|
||||||
|
border-radius:5px;
|
||||||
|
border:solid 1px #eee;
|
||||||
|
background-color:#f9f9f9;
|
||||||
|
font-family: consolas;
|
||||||
|
font-size:14px;
|
||||||
|
box-shadow: 1px 2px 3px #ddd;
|
||||||
|
}
|
||||||
|
|
||||||
|
code{
|
||||||
|
padding:2px 12px;
|
||||||
|
display: inline-block;
|
||||||
|
margin:10px 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
pre{
|
||||||
|
padding:10px 12px;
|
||||||
|
overflow-x:auto;
|
||||||
|
}
|
||||||
|
</style>
|
||||||
|
<?php
|
||||||
|
/*
|
||||||
|
* flag规则:
|
||||||
|
* h1-h6 标题
|
||||||
|
* u1,u2 无序列表
|
||||||
|
* ol 有序列表
|
||||||
|
* p 普通文本
|
||||||
|
* code 代码
|
||||||
|
* table 文本
|
||||||
|
* check 选择
|
||||||
|
* uncheck 未选择
|
||||||
|
* quote 引用
|
||||||
|
* img 图片
|
||||||
|
* url 网址
|
||||||
|
* bold 加粗
|
||||||
|
* italia 斜体
|
||||||
|
* el 空行
|
||||||
|
*
|
||||||
|
* idel 闲置
|
||||||
|
*/
|
||||||
|
class MD{
|
||||||
|
|
||||||
|
private $file; //当前文件
|
||||||
|
private $mdGen; //生成器
|
||||||
|
private $flag; //当前标志
|
||||||
|
private $flag_pre; //上一次的flag
|
||||||
|
private $flag_like; //假定类型
|
||||||
|
|
||||||
|
private $line_count; //总行数
|
||||||
|
private $lines; //所有行
|
||||||
|
private $buf; //缓存行
|
||||||
|
|
||||||
|
public function __construct($filename){
|
||||||
|
$this->file = $filename; //设置当前文件
|
||||||
|
$this->mdGen = $this->content($filename); //获取生成器
|
||||||
|
$this->flag = 'idel'; //闲置
|
||||||
|
$this->lines = array(); //所有行状态
|
||||||
|
$this->line_count = 0; //行数归0
|
||||||
|
}
|
||||||
|
|
||||||
|
private function content($file){ //获取生成器
|
||||||
|
if(file_exists($file)){
|
||||||
|
$fh = fopen($file,"r");
|
||||||
|
while(!feof($fh)){
|
||||||
|
yield fgets($fh);
|
||||||
|
}
|
||||||
|
fclose($fh);
|
||||||
|
}else{
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
//遍历每一个字符
|
||||||
|
private function every($str){
|
||||||
|
$l = strlen($str);
|
||||||
|
for($i=0;$i<$l;$i++)
|
||||||
|
if(ord($str[$i])<0x80)
|
||||||
|
yield $str[$i];
|
||||||
|
else{
|
||||||
|
yield $str[$i].$str[$i+1].$str[$i+2]; //三个字节
|
||||||
|
$i+=2;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
//解析
|
||||||
|
private function parse(){
|
||||||
|
$ctnt = $this->mdGen; //生成器
|
||||||
|
$ret=array();
|
||||||
|
if($ctnt != null){
|
||||||
|
$ret = array();
|
||||||
|
foreach($ctnt as $line){
|
||||||
|
if($this->flag != 'code')
|
||||||
|
$line=ltrim($line); //删除左边
|
||||||
|
if(strlen($line)){
|
||||||
|
$ch = $line[0]; //判断第一个字符
|
||||||
|
$type=ctype_punct($ch);//标点符号
|
||||||
|
if($this->flag !== 'code') $line=preg_replace('/\s{2,}$/','<br>',$line); //非代码模式
|
||||||
|
$ret[] = $this->parseLine($line,$type); //解析行
|
||||||
|
}else{ //空行
|
||||||
|
switch($this->flag){
|
||||||
|
case 'ul':
|
||||||
|
case 'ol':
|
||||||
|
$ret[]="</$this->flag>";
|
||||||
|
$this->flag_pre = $this->flag;
|
||||||
|
$this->flag = 'idel';
|
||||||
|
break;
|
||||||
|
case 'table':
|
||||||
|
$this->flag = 'idel';
|
||||||
|
$ret[]='</table>';
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
if($this->flag != 'el') $ret[] = '<br>';
|
||||||
|
$this->flag = 'el'; //空行
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
$this->lines = $ret;
|
||||||
|
return $ret;
|
||||||
|
}
|
||||||
|
|
||||||
|
//生成blockquote
|
||||||
|
private function genQuote($level,$content){
|
||||||
|
if($level<=0) return "";
|
||||||
|
return str_repeat('<blockquote>',$level).$content.str_repeat('</blockquote>',$level);
|
||||||
|
}
|
||||||
|
|
||||||
|
//检查是否处于某个状态,默认检查是否处于代码状态
|
||||||
|
private function check($value='code'){
|
||||||
|
return ($this->flag == $value);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 生成一行新的表格列
|
||||||
|
* $data:需要输入的数据
|
||||||
|
* $type:生成类型
|
||||||
|
* $wrap:最快层包裹
|
||||||
|
* $sep:分隔符
|
||||||
|
*/
|
||||||
|
private function genRow($data,$type='td',$wrap='tr',$sep='|'){
|
||||||
|
$ret='';
|
||||||
|
$mat = explode($sep,$data);
|
||||||
|
foreach($mat as $elem)
|
||||||
|
$ret.="<$type>".$elem."</$type>";
|
||||||
|
return "<$wrap>".$ret."</$wrap>";
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 解析行内元素
|
||||||
|
* bold,italic,code,link,pic
|
||||||
|
*/
|
||||||
|
private function parseInner($str){
|
||||||
|
$str=preg_replace('/\*\*\*([^\*\n\r]+)\*\*\*/','<b><i>\1</i></b>',$str); //加粗并加斜字体
|
||||||
|
$str=preg_replace('/\*\*([^\*\n\r]+)\*\*/','<b>\1</b>',$str); //加粗字体
|
||||||
|
$str=preg_replace('/\*([^\*\n\r]+)\*/','<i>\1</i>',$str); //斜体
|
||||||
|
$str=preg_replace('/```([^`\n\r]+)```/','<code>\1</code>',$str); //代码
|
||||||
|
$str=preg_replace('/`([^`\n\r]+)`/','<code>\1</code>',$str); //代码
|
||||||
|
$str=preg_replace('/!\[([^\]\r\n]+)\]\(([^\)\r\n]+)\)/','<img src="\2" alt="\1" title="\1">',$str); //图片
|
||||||
|
$str=preg_replace('/\[([^\]\r\n]+)\]\(([^\)\r\n]+)\)/','<a href="\2">\1</a>',$str); //图片
|
||||||
|
return $str;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 按照给定规则解析字符串:
|
||||||
|
* type:
|
||||||
|
* true 符号
|
||||||
|
* false 文字
|
||||||
|
* 返回:
|
||||||
|
* array('type'=>类型,'parts'=>array(...))
|
||||||
|
*/
|
||||||
|
private function parseLine($str,$type){
|
||||||
|
if(strlen($str) == 0){
|
||||||
|
return array('type'=>'p','parts'=>[]); //返回空段
|
||||||
|
}
|
||||||
|
|
||||||
|
$valid_str = rtrim($str); //去除右边的空格
|
||||||
|
|
||||||
|
$str = $valid_str;
|
||||||
|
$output = ''; //需要输出的字符串
|
||||||
|
|
||||||
|
if($type == true){ //标点
|
||||||
|
$type_str = ''; //类型字符串
|
||||||
|
$data_str = '';
|
||||||
|
$flag = 0;
|
||||||
|
|
||||||
|
foreach($this->every($str) as $ch){
|
||||||
|
if(!ctype_punct($ch)){
|
||||||
|
$flag = 1;
|
||||||
|
}
|
||||||
|
if($flag == 0)
|
||||||
|
$type_str .= $ch;
|
||||||
|
else
|
||||||
|
$data_str .= $ch;
|
||||||
|
}
|
||||||
|
|
||||||
|
switch($type_str){
|
||||||
|
case '#':
|
||||||
|
$wrap = 'h1';
|
||||||
|
$this->flag_like = 'h1';
|
||||||
|
break;
|
||||||
|
case '##':
|
||||||
|
$wrap = 'h2';
|
||||||
|
$this->flag_like = 'h2';
|
||||||
|
break;
|
||||||
|
case '###':
|
||||||
|
$wrap = 'h3';
|
||||||
|
$this->flag_like = 'h3';
|
||||||
|
break;
|
||||||
|
case '####':
|
||||||
|
$wrap = 'h4';
|
||||||
|
$this->flag_like = 'h4';
|
||||||
|
break;
|
||||||
|
case '#####':
|
||||||
|
$wrap = 'h5';
|
||||||
|
$this->flag_like = 'h5';
|
||||||
|
break;
|
||||||
|
case '######':
|
||||||
|
$wrap = 'h6';
|
||||||
|
$this->flag_like = 'h6';
|
||||||
|
break;
|
||||||
|
case '+':
|
||||||
|
case '-':
|
||||||
|
$wrap = 'li';
|
||||||
|
$this->flag_like = 'ul';
|
||||||
|
if($this->flag != 'code'){
|
||||||
|
if($this->flag != 'ul'){
|
||||||
|
$this->flag_pre = $this->flag;
|
||||||
|
$this->flag = 'ul';
|
||||||
|
$output.='<ul>';
|
||||||
|
}
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
case '```': //代码模式,不进行干扰
|
||||||
|
if($this->flag != 'code'){ //不为code,判断是否为单行代码
|
||||||
|
$output.='<pre>';
|
||||||
|
if(preg_match('/^\s*```([^`]+)```([^\s]+)\s*$/',$str,$mat)){ //单行代码
|
||||||
|
$output.="$mat[1]</pre>$mat[2]";
|
||||||
|
$str = '';
|
||||||
|
$data_str = '';
|
||||||
|
}else{
|
||||||
|
$this->flag_pre = $this->flag;
|
||||||
|
$this->flag = 'code'; //代码
|
||||||
|
}
|
||||||
|
}else{
|
||||||
|
$output.='</pre>';
|
||||||
|
$this->flag_pre = $this->flag;
|
||||||
|
$this->flag = 'idel'; //闲置
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
case '[':
|
||||||
|
if(preg_match('/^\[\s\]\s*(.+)$/',$str,$mat)){ //选择
|
||||||
|
$output.="<label><input type='checkbox' disabled> $mat[1]</label><br>";
|
||||||
|
$this->flag_like = 'check';
|
||||||
|
}else if(preg_match('/^\[([^\]]+)\]\(([^\)]+)\)([^\s]+)\s*$/',$str,$mat)){ //未选择
|
||||||
|
$output.="<a href='$mat[2]'>$mat[1]</a>".$this->parseInner($mat[3]);
|
||||||
|
$this->flag_like = 'a'; //网址
|
||||||
|
}else if(preg_match('/^\s*(\[\d+\]\:)\s+([^\s]+)\s+([^\r\n]+)\s*$/',$str,$mat)){ //外部资料
|
||||||
|
$output.="$mat[1] <a href='$mat[2]'>$mat[3]</a>";
|
||||||
|
}else{
|
||||||
|
$output.=$str;
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
case '[-]':
|
||||||
|
$output.="<label><input type='checkbox' checked disabled>$data_str</label><br>";
|
||||||
|
$this->flag_like = 'check';
|
||||||
|
break;
|
||||||
|
case '![':
|
||||||
|
if(preg_match('/^!\[([^\]]+)\]\(([^\)]+)\)([^\s]+)\s*$/',$str,$mat)){
|
||||||
|
$output.="<img src='$mat[2]' alt='$mat[1]'>".$this->parseInner($mat[3]);
|
||||||
|
$this->flag_like = 'img';
|
||||||
|
}else{
|
||||||
|
$this->flag_like = 'p'; //没有模式
|
||||||
|
$output.="$str";
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
case '*': //斜体
|
||||||
|
if(preg_match('/^\*(.*)\*([^\s]+)\s*$/',$str,$mat)){
|
||||||
|
$output.=$this->parseInner($str);
|
||||||
|
$this->flag_like = 'i';
|
||||||
|
}else if(preg_match('/^\s*\*\s+(.+)\s*$/',$str,$mat)){
|
||||||
|
$str=$mat[1];
|
||||||
|
$wrap = 'li';
|
||||||
|
$this->flag_like = 'ul';
|
||||||
|
if($this->flag != 'code'){
|
||||||
|
if($this->flag != 'ul'){
|
||||||
|
$this->flag_pre = $this->flag;
|
||||||
|
$this->flag = 'ul';
|
||||||
|
$output.='<ul>';
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
case '**': //粗体
|
||||||
|
if(preg_match('/^\*\*(.*)\*\*/',$str,$mat)){
|
||||||
|
$output.=$this->parseInner($str);
|
||||||
|
$this->flag_like = 'b';
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
case '<':
|
||||||
|
$output.=$str;
|
||||||
|
$this->flag_like = 'html';
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
if(!$this->check()){ //非代码模式
|
||||||
|
if(preg_match('/^>+$/',$type_str)){ //引用
|
||||||
|
$level = strlen($type_str);
|
||||||
|
$this->flag_like = 'quote';
|
||||||
|
$output.=$this->genQuote($level,$data_str); //引用
|
||||||
|
}else if(preg_match('/^([^\|\n\r]+)(?:\|[^\|\n\r]+)+$/',$str)){ //表格确定格式---|---|....
|
||||||
|
if($this->flag == 'table'){
|
||||||
|
$this->flag_like = 'table';
|
||||||
|
$output.='<table><thead>'.$this->genRow($this->buf,'th').'</thead><tbody>';
|
||||||
|
}else{ //非表格格式,上一行没有标题
|
||||||
|
$this->flag_like = 'p'; //没有格式
|
||||||
|
$output.=$this->buf;
|
||||||
|
$this->buf = '';
|
||||||
|
}
|
||||||
|
}else if(preg_match('/^\s*(\-{3,})|(\={3,})$/',$type_str)){ //hr
|
||||||
|
$output.='<hr>';
|
||||||
|
$this->flag_like = 'hr';
|
||||||
|
break;
|
||||||
|
}else{
|
||||||
|
$this->flag_like = 'p';
|
||||||
|
$output.=$str.'<br>';
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
$br = '';
|
||||||
|
preg_match('/^(.*)(<br\s*\/?>)?$/',$data_str,$mat);
|
||||||
|
$data_str = htmlspecialchars($mat[1]);
|
||||||
|
if(!$this->check()){ //代码
|
||||||
|
if(!empty($wrap)) $output.="<$wrap>$mat[1]</$wrap>".(isset($mat[2])?'<br>':'');
|
||||||
|
}else if($type_str!='```'){
|
||||||
|
$output.=htmlspecialchars($str).'<br>';
|
||||||
|
}
|
||||||
|
}else{ //首个非空字符不为符号
|
||||||
|
if($this->flag == 'code'){ //代码,直接输出
|
||||||
|
$str=str_replace("\t",' ',$str);
|
||||||
|
$output.=htmlspecialchars($str).'<br>';
|
||||||
|
}else if(is_numeric($str[0])){ //可能为有序列表,也可能是表格
|
||||||
|
if(preg_match('/^\s*\d+\.\s+([^\r\n]+)\s*$/',$str)){ //有序列表
|
||||||
|
$this->flag_like = 'ol';
|
||||||
|
$output.=$str;
|
||||||
|
}else{
|
||||||
|
$this->flag_like = 'idel';
|
||||||
|
foreach($this->every($str) as $ch){
|
||||||
|
$output.=$ch;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
$output.='<br>';
|
||||||
|
}else if(preg_match('/^([^\|\n\r]+)(?:\|[^\|\n\r]+)+$/',$str)){ //表格
|
||||||
|
$mat = explode('|',$str);
|
||||||
|
|
||||||
|
if($this->flag!='table'){ //进入表格
|
||||||
|
$this->buf = $str;
|
||||||
|
$this->flag_like = 'table';
|
||||||
|
$wrap = '';
|
||||||
|
}else{
|
||||||
|
$output.=$this->genRow($str);
|
||||||
|
}
|
||||||
|
//echo $mat[0].'<br>';
|
||||||
|
//var_dump($mat);
|
||||||
|
}else{ //其他
|
||||||
|
$this->flag = 'p';
|
||||||
|
$output.=$str;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if(!$this->check()){ //不为代码,设置flag
|
||||||
|
$this->flag_pre = $this->flag;
|
||||||
|
$this->flag = $this->flag_like;
|
||||||
|
if($this->flag_pre == 'table' && $this->flag != 'table')
|
||||||
|
$output='</table>'.$output;
|
||||||
|
else if($this->flag_pre == 'ul' && $this->flag != 'ul'){
|
||||||
|
$output='</ul>'.$output;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return $this->parseInner($output); //输出需要输出的内容
|
||||||
|
}
|
||||||
|
|
||||||
|
//获取输出内容
|
||||||
|
public function output(){
|
||||||
|
$this->parse();
|
||||||
|
echo implode('',$this->lines);
|
||||||
|
}
|
||||||
|
}
|
||||||
6
md/inite.php
Executable file
6
md/inite.php
Executable file
@@ -0,0 +1,6 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
require '/var/www/owp/open-ww3-project-ww3-tw/md/MD.php';
|
||||||
|
|
||||||
|
$md=new MD('/var/www/owp/open-ww3-project-ww3-tw/md/inte.md');
|
||||||
|
$md->output();
|
||||||
10
md/inte.md
Executable file
10
md/inte.md
Executable file
@@ -0,0 +1,10 @@
|
|||||||
|
## MD介绍页面
|
||||||
|
|
||||||
|
顾名思义、本文件夹下使用的基本都是markdown
|
||||||
|
|
||||||
|
最后感谢提供php的md插件的开源制作者
|
||||||
|
|
||||||
|
[点击跳转](https://ww3.tw/blog/md/src/php-markdown/)
|
||||||
|
|
||||||
|
日期 2025.07.30
|
||||||
|
|
||||||
@@ -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';
|
|
||||||
}
|
|
||||||
@@ -31,6 +31,11 @@
|
|||||||
<font size="3.2">
|
<font size="3.2">
|
||||||
<table border="0">
|
<table border="0">
|
||||||
<tbody>
|
<tbody>
|
||||||
|
<tr>
|
||||||
|
<td id="td_logs">2025.08.20</td>
|
||||||
|
<td id="td_logs_content">路由模式修改完善、现在开始重写文章系统</td>
|
||||||
|
|
||||||
|
</tr>
|
||||||
<tr>
|
<tr>
|
||||||
<td id="td_logs">2025.08.19</td>
|
<td id="td_logs">2025.08.19</td>
|
||||||
<td id="td_logs_content">修改php_web的路由方式</td>
|
<td id="td_logs_content">修改php_web的路由方式</td>
|
||||||
|
|||||||
9
public/blog/master/index.html
Executable file
9
public/blog/master/index.html
Executable 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>
|
||||||
@@ -1 +0,0 @@
|
|||||||
{2025/07/30};{"第一篇文章"}
|
|
||||||
@@ -1,27 +1,27 @@
|
|||||||
<?php
|
<?php
|
||||||
|
|
||||||
// 1. 定义要写入的文件路径
|
// 1. 定义要写入的文件路径
|
||||||
$file = './index.txt';
|
$file = '../../../databases/no_db/post.text';
|
||||||
|
|
||||||
// 2. 检查是否通过 POST 请求接收到了数据
|
// 2. 检查是否通过 POST 请求接收到了数据
|
||||||
// 'data' 是表单中 <textarea> 标签的 name 属性
|
|
||||||
if (isset($_POST['data']) && !empty($_POST['data'])) {
|
if (isset($_POST['data']) && !empty($_POST['data'])) {
|
||||||
|
|
||||||
// 自动获取当前日期和时间
|
// 自动获取当前日期
|
||||||
$date = date('Y/m/d');
|
$date = date('Y/m/d');
|
||||||
|
|
||||||
// 获取你在网页输入框中写的数据
|
// 获取你在网页输入框中写的数据
|
||||||
$data = $_POST['data'];
|
$data = $_POST['data'];
|
||||||
|
|
||||||
// 3. 构建完整的单行内容,格式为 {日期};{数据},并以换行符 \n 结尾
|
// 3. 构建完整的单行内容
|
||||||
$content = "{" . $date . "};" . "{" . '"' . $data . '"' . "}" . "\n";
|
// 使用 PHP_EOL 常量确保正确的换行符
|
||||||
|
$content = "{" . $date . "};" . "{" . '"' . $data . '"' . "}" . ";" . PHP_EOL;
|
||||||
|
|
||||||
// 4. 将内容追加到文件末尾
|
// 4. 将内容追加到文件末尾
|
||||||
$result = file_put_contents($file, $content, FILE_APPEND | LOCK_EX);
|
$result = file_put_contents($file, $content, FILE_APPEND | LOCK_EX);
|
||||||
|
|
||||||
// 5. 检查是否写入成功并给出反馈
|
// 5. 检查是否写入成功并给出反馈
|
||||||
if ($result !== false) {
|
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 {
|
} else {
|
||||||
echo "写入文件失败,请检查文件权限。";
|
echo "写入文件失败,请检查文件权限。";
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,9 +1,8 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
?>
|
||||||
<title>master</title>
|
<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">
|
<form action="post_data.php" method="POST">
|
||||||
<textarea name="data" placeholder="在这里输入数据..."></textarea>
|
<textarea name="data" placeholder="在这里输入数据..."></textarea>
|
||||||
@@ -1,33 +1,30 @@
|
|||||||
<?php
|
<?php
|
||||||
$file = './master/index.txt'; //定义文件的位置
|
$file = '../../databases/no_db/post.text'; //定义文件的位置
|
||||||
if (file_exists($file)) {
|
|
||||||
|
|
||||||
$content = file_get_contents($file);
|
$content = file_get_contents($file);
|
||||||
|
|
||||||
|
|
||||||
//分割输出内容
|
//分割输出内容
|
||||||
$lines = explode("\n",$content);
|
$lines = explode("\n",$content);
|
||||||
|
|
||||||
|
$sequence_id = 1; // 设定id起始数字
|
||||||
|
|
||||||
|
echo "文章如下: ";
|
||||||
|
|
||||||
//逐行解析
|
|
||||||
foreach ($lines as $line) {
|
foreach ($lines as $line) {
|
||||||
if (preg_match('/\{([^}]+)\};\{"([^"]+)\"}/', $line, $matches)) {
|
if (preg_match('/\{([^}]+)\};\{"([^"]+)\"};/', $line, $matches)) {
|
||||||
$data = $matches[1]; // 提取出数据
|
$data = $matches[1]; // 提取出数据
|
||||||
$title = $matches[2]; // 提取出标题
|
$title = $matches[2]; // 提取出标题
|
||||||
|
|
||||||
echo "文章如下: ";
|
|
||||||
// 输出提取到的内容
|
|
||||||
echo "<br><br>";
|
echo "<br><br>";
|
||||||
|
echo "文章顺序ID: " . $sequence_id . "<br>"; // 输出顺序ID
|
||||||
echo "" . $data . "\n";
|
echo "" . $data . "\n";
|
||||||
echo "" . $title . "\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>';
|
//echo '链接 (URL): <a herf="">链接</a>';
|
||||||
|
$sequence_id++; // 每次循环后,顺序ID加1
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
//输出内容
|
|
||||||
//echo "文件 '{$file}' 的内容是: <br><br>\n\n";
|
|
||||||
//echo $content;
|
|
||||||
} else {
|
|
||||||
echo "错误: 文件 '$file' 不存在 ";
|
|
||||||
}
|
|
||||||
?>
|
|
||||||
@@ -8,6 +8,7 @@
|
|||||||
switch($request_uri){
|
switch($request_uri){
|
||||||
case '/':
|
case '/':
|
||||||
include './re_blog.php';
|
include './re_blog.php';
|
||||||
|
exit(); // 执行成功立即结束
|
||||||
break;
|
break;
|
||||||
|
|
||||||
}
|
}
|
||||||
@@ -21,7 +22,7 @@ if (!$found_route) {
|
|||||||
// 设置 HTTP 状态码为 404
|
// 设置 HTTP 状态码为 404
|
||||||
header("HTTP/1.0 404 Not Found");
|
header("HTTP/1.0 404 Not Found");
|
||||||
// 包含 404 页面文件
|
// 包含 404 页面文件
|
||||||
exit();
|
//exit();
|
||||||
include "../src/views/error/404.html";
|
include "../src/views/error/404.html";
|
||||||
|
exit(); // 执行成功立即结束
|
||||||
}
|
}
|
||||||
@@ -1,6 +1,32 @@
|
|||||||
<?php
|
<?php
|
||||||
switch($request_uri){
|
switch($request_uri){
|
||||||
|
case '/blog/md/';
|
||||||
|
include '/var/www/owp/open-ww3-project-ww3-tw/md/inite.php';
|
||||||
|
exit(); // 执行成功立即结束
|
||||||
|
|
||||||
case '/blog/md/post/';
|
case '/blog/md/post/';
|
||||||
include '../src/views/posts.php';
|
include '../src/views/post.php';
|
||||||
|
exit(); // 执行成功立即结束
|
||||||
break;
|
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;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
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