196 lines
7.2 KiB
PHP
196 lines
7.2 KiB
PHP
<?php
|
|
|
|
|
|
namespace App\Controllers;
|
|
use App\Models;
|
|
use Core\Controller;
|
|
use Core\View;
|
|
use Parsedown;
|
|
use App\Config;
|
|
|
|
|
|
class NewUi extends Controller
|
|
{
|
|
function indexAction() {
|
|
$docModel = new Models\Doc();
|
|
$limit = 5;
|
|
$offset = 0;
|
|
$firstpagedocs = [];
|
|
$typedocs = $docModel->getAllTypeDocs();
|
|
$titles = $docModel->AllTitle();
|
|
$groups = $docModel->getGroups();
|
|
$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"=>"一个博客",
|
|
]);
|
|
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"=>"一个博客",
|
|
]);
|
|
}
|
|
}
|
|
function articleAction(){
|
|
$commentModel = new Models\DocComment();
|
|
$doccoment = $commentModel->DocComments((int)$this->params[0]);
|
|
if(sizeof($this->params) > 0){
|
|
|
|
}
|
|
$docModel = new Models\Doc();
|
|
$firstpagedocs = [];
|
|
$typedocs = $docModel->getAllTypeDocs();
|
|
$doc = $docModel->doc((int)$this->params[0]);
|
|
$titles = $docModel->AllTitle();
|
|
$groups = $docModel->getGroups();
|
|
$groupstype = $docModel->GetAllGroupType();
|
|
|
|
$fisrtpage = $docModel->pageDoc(5,0,55);
|
|
$markdown = new \ParsedownToC();
|
|
$doc[0]['content'] = $markdown->body($doc[0]['content']);
|
|
$doc[0]['toc'] = $markdown->contentsList();
|
|
$top5 = $docModel->top5Doc();
|
|
|
|
foreach ($fisrtpage as $key => $value) {
|
|
$obj['title'] = $value['title'];
|
|
$obj['id'] = $value['id'];
|
|
$obj['content'] = $value['content'];
|
|
$obj['type'] = $value['type'];
|
|
//数据加工
|
|
$content = $markdown->body($value['content']);
|
|
$obj['content'] = $content;
|
|
array_push($firstpagedocs,$obj);
|
|
}
|
|
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->params[1]),
|
|
"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,
|
|
]);
|
|
else{
|
|
View::renderTemplate("/blog/article.html",[
|
|
"url"=>\App\Config::ServerUrl(),
|
|
'route'=>'article',
|
|
'index'=>true,
|
|
'debug'=>false,
|
|
"typedocs" => $typedocs,
|
|
"alltitle" => $titles,
|
|
"groups" => $groups,
|
|
"group_types"=>$groupstype,
|
|
"title"=>urldecode ($this->params[1]),
|
|
"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,
|
|
]);
|
|
}
|
|
}
|
|
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,
|
|
]);
|
|
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,
|
|
]);
|
|
} else {
|
|
View::renderTemplate("/blog/article.html", ['title' => 'test', 'index' => false]);
|
|
}
|
|
}
|
|
} |