添加版本页

doctree
zcy 2022-12-25 14:27:46 +08:00
parent 9f4948d778
commit 9e2dab5a37
4 changed files with 272 additions and 12 deletions

View File

@ -0,0 +1,256 @@
<?php
namespace App\Controllers;
use App\Models;
use Core\Controller;
use Core\View;
use Parsedown;
use App\Config;
class ArticleTree extends Controller
{
function indexAction() {
$docModel = new Models\Doc();
$limit = 5;
$offset = 0;
$firstpagedocs = [];
$typedocs = $docModel->getAllTypeDocs();
$titles = $docModel->AllTitle();
$doc_all = $docModel->getArticlesTree(-1);
var_dump($doc_all);
$mapforbuildtree = [];
$articletree = [];
foreach ($doc_all as $key => $value){
$tmp = array(
'name' => $value['title'],
'id' =>$value['id'],
'isParent'=> false,
'url' => \App\Config::Url() . "ArticleTree/article/" . $value['id'],
'level' => $value['level']
);
$mapforbuildtree[$value['id']] = $tmp;
}
foreach ($doc_all as $key => $value){
if($value['father'] != 0){
if(!isset($mapforbuildtree[$value['father']]['children'])){
$mapforbuildtree[$value['father']]['children'] = array();
}
array_push($mapforbuildtree[$value['father']]['children'],
$mapforbuildtree[$value['id']]);
$mapforbuildtree[$value['father']]["isParent"] = true;
}
}
foreach ($doc_all as $key => $value){
if($value['level'] == 0){
array_push($articletree,$mapforbuildtree[$value['id']]);
}
}
$dat = json_encode ( $articletree ,JSON_UNESCAPED_SLASHES|JSON_UNESCAPED_UNICODE );
$groupstype = $docModel->GetAllGroupType();
if(sizeof($this->params) == 2){
$limit = $this->params[0];
$offset = $this->params[1];
}
$fisrtpage = $docModel->pageDoc($limit,$offset,55);
$top5 = $docModel->top5Doc();
foreach ($fisrtpage as $key => $value) {
$obj['title'] = $value['title'];
$obj['id'] = $value['id'];
$obj['content'] = $value['content'];
$obj['type'] = $value['type'];
//数据加工
$markdown = new Parsedown;
$content = $markdown->text($value['content']);
$obj['content'] = $content;
array_push($firstpagedocs,$obj);
}
if(\App\Config::$DEBUG)
View::renderTemplate("/blog/index.html",[
"url"=>\App\Config::Url(),
'route'=>'article',
'docs'=>$firstpagedocs,
'index'=>true,
'debug'=>true,
"typedocs" => $typedocs,
"alltitle" => $titles,
"groups" => $groups,
"group_types"=>$groupstype,
"topdoc"=>$top5,
"title"=>"博客",
"openapi"=>\App\Config::OpenApiUrl(),
"treedoc"=>$dat,
]);
else{
View::renderTemplate("/blog/index.html",[
"url"=>\App\Config::Url(),
'route'=>'article',
'docs'=>$firstpagedocs,
'index'=>true,
'debug'=>false,
"typedocs" => $typedocs,
"alltitle" => $titles,
"groups" => $groups,
"group_types"=>$groupstype,
"topdoc"=>$top5,
"title"=>"博客",
"openapi"=>\App\Config::OpenApiUrl(),
"treedoc"=>$dat,
]);
}
}
function articleAction(){
$redis = new \Redis();
$redis->connect('127.0.0.1', 6379);
//查看服务是否运行
$commentModel = new Models\DocComment();
$doccoment = $commentModel->DocComments((int)$this->params[0]);
if(sizeof($this->params) > 0){
}
$docModel = new Models\Doc();
$doc_all = $docModel->getArticlesTree((int)$this->params[0]);
var_dump($this->querys);
$doc_vers = $docModel->DocVersTime((int)$this->params[0]);
$firstpagedocs = [];
$child_docs = $docModel->getChildrenDocs($this->params[0]);
$doc = $docModel->docTree((int)$this->params[0]);
$doc = array_merge($doc,$child_docs);
$top5 = $docModel->top5Doc();
$doc_history = $docModel->doc_history((int)$this->params[0]);
$markdowntoc = new \ParsedownToC();
$doc[0]['content'] = $markdowntoc->body($doc[0]['content']);
$doc[0]['toc'] = $markdowntoc->contentsList();
$markdown = new Parsedown;
foreach ($doc as $key => $value) {
$content = $markdown->text($value['content']);
$doc[$key]['content'] = $content;
}
$titles = $docModel->AllTitle();
$groups = $docModel->getGroups();
$groupstype = $docModel->GetAllGroupType();
if(\App\Config::$DEBUG){
View::renderTemplate("/blog/article.html",[
"url"=>\App\Config::ServerUrl(),
'route'=>'article',
'index'=>false,
'debug'=>true,
"alltitle" => $titles,
"groups" => $groups,
"group_types"=>$groupstype,
"title"=>urldecode ($doc[0]['title']),
"doc"=>$doc[0],
"docs"=>$doc,
"comments" => $doccoment,
"comment_count" => count($doccoment),
"doc_type"=>$doc[0]["type"],
"openapi"=>\App\Config::OpenApiUrl(),
"treedoc"=>$doc_all,
"topdoc"=>$top5,
"doc_toc" => $doc[0]['toc'],
"id"=>$doc[0]['id'],
"vestimes" => $doc_vers,
]);
}
else{
View::renderTemplate("/blog/article.html",[
"url"=>\App\Config::ServerUrl(),
'route'=>'article',
'index'=>true,
'debug'=>false,
"alltitle" => $titles,
"groups" => $groups,
"group_types"=>$groupstype,
"title"=>urldecode ($this->params[1]),
"doc"=>$doc[0],
"docs"=>$doc,
"comments" => $doccoment,
"comment_count" => count($doccoment),
"doc_type"=>$doc[0]["type"],
"openapi"=>\App\Config::OpenApiUrl(),
"treedoc"=>$doc_all,
"topdoc"=>$top5,
"doc_toc" => $doc[0]['toc'],
"id"=>$doc[0]['id'],
"vestimes" => $doc_vers,
]);
}
}
function searchAction()
{
if (sizeof($this->querys) != 0) {
$docModel = new Models\Doc();
$commentModel = new Models\DocComment();
$doc = $docModel->titleDoc(rawurldecode($this->querys['title']));
$id = $doc[0]["id"];
$markdown = new \ParsedownToC();
$doc[0]['content'] = $markdown->body($doc[0]['content']);
$typedocs = $docModel->getAllTypeDocs();
$doccoment = $commentModel->DocComments($id);
$titles = $docModel->AllTitle();
$top5 = $docModel->top5Doc();
$groups = $docModel->getGroups();
$groupstype = $docModel->GetAllGroupType();
if (\App\Config::$DEBUG)
View::renderTemplate("/blog/article.html",
[
"url"=>\App\Config::ServerUrl(),
'route'=>'article',
'index'=>true,
'debug'=>true,
"typedocs" => $typedocs,
"alltitle" => $titles,
"groups" => $groups,
"group_types"=>$groupstype,
"title"=>urldecode ($this->querys['title']),
"doc"=>$doc[0],
"comments" => $doccoment,
"comment_count" => count($doccoment),
"doc_type"=>$doc[0]["type"],
"group_type"=>$docModel->TypeGroup($doc[0]["type"])[0][0],
"topdoc"=>$top5,
"openapi"=>\App\Config::OpenApiUrl(),
"vestimes" => $doc_vers,
]);
else
View::renderTemplate("/blog/article.html", [
"url"=>\App\Config::ServerUrl(),
'route'=>'article',
'index'=>true,
'debug'=>true,
"typedocs" => $typedocs,
"alltitle" => $titles,
"groups" => $groups,
"group_types"=>$groupstype,
"title"=>urldecode ($this->querys['title']),
"doc"=>$doc[0],
"comments" => $doccoment,
"comment_count" => count($doccoment),
"doc_type"=>$doc[0]["type"],
"group_type"=>$docModel->TypeGroup($doc[0]["type"])[0][0],
"topdoc"=>$top5,
"openapi"=>\App\Config::OpenApiUrl(),
"vestimes" => $doc_vers,
]);
} else {
View::renderTemplate("/blog/article.html", ['title' => 'test', 'index' => false]);
}
}
}

View File

@ -167,6 +167,7 @@ class NewUi extends Controller
$doc = $docModel->titleDoc(rawurldecode($this->querys['title']));
$id = $doc[0]["id"];
$doc_all = $docModel->getArticlesTree($doc[0]["id"]);
$doc_vers = $docModel->DocVersTime($id);
$markdown = new \ParsedownToC();
$doc[0]['content'] = $markdown->body($doc[0]['content']);
@ -199,6 +200,8 @@ class NewUi extends Controller
"topdoc"=>$top5,
"openapi"=>\App\Config::OpenApiUrl(),
"treedoc"=>$doc_all,
"vestimes" => $doc_vers,
]);
else
View::renderTemplate("/blog/article.html", [
@ -220,6 +223,8 @@ class NewUi extends Controller
"topdoc"=>$top5,
"openapi"=>\App\Config::OpenApiUrl(),
"treedoc"=>$doc_all,
"vestimes" => $doc_vers,
]);
} else {
View::renderTemplate("/blog/article.html", ['title' => 'test', 'index' => false]);

View File

@ -71,8 +71,14 @@ class Doc extends Model
}
public function topDoc(){
$result = [];
$db = static::getDB();
$stmt = $db->query('select * from doc where doc.is_public = 0 order by TIMESTAMP(update_time) desc LIMIT 5 ');
$recv = $stmt->fetchAll();
return $recv;
}
public function DocVersTime($id){
$db = static::getDB();
$stmt = $db->query('select * from doc where doc.is_public = 0 order by TIMESTAMP(update_time) desc LIMIT 5 ');
$stmt = $db->query('select edit_time from doc_history where doc_history.doc_id = ' .$id);
$recv = $stmt->fetchAll();
return $recv;
}

View File

@ -209,23 +209,16 @@ function expandNode(e) {
</div>
</div>
<div class="col-lg-7" style="padding: 0px;" id="docshow" >
<div class="col-lg-7" style="padding: 0px;" id="docshow">
{% for doc in docs %}
<div class="panel panel-default" id="doc_id_{{ doc.id }}" style="letter-spacing: 0.4px;">
<div class="panel-heading" style="font-size: 20px ; background: #1d5987;color: white">
{{ doc.title }} 历史版本:
<select NAME="TEMP" οnchange="" style="font-size: 20px ; background: #1d5987;color: white;margin-left: 15px; ">
<option value></option>
<option value="AAAAAA">AAAAAA</option>
<option value="BBBBBB">BBBBBB</option>
<option value="CCCCCC">CCCCCC</option>
<option value="DDDDDD">DDDDDD</option>
<option value="EEEEEE">EEEEEE</option>
<option value="FFFFFF">FFFFFF</option>
{% for vertime in vestimes %}
<option value="AAAAAA">{{vertime.edit_time}}</option>
{% endfor %}
</select>
<div style="float: right; margin-right: 30px;">
上次修改时间: {{ doc.update_time }}