api/App/Controllers/NewUi.php

144 lines
4.9 KiB
PHP
Raw Normal View History

2020-07-09 16:04:53 +00:00
<?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();
2020-07-12 07:59:34 +00:00
$limit = 5;
$offset = 0;
2020-07-09 16:04:53 +00:00
$firstpagedocs = [];
$typedocs = $docModel->getAllTypeDocs();
$titles = $docModel->AllTitle();
$groups = $docModel->getGroups();
$groupstype = $docModel->GetAllGroupType();
2020-07-12 07:59:34 +00:00
if(sizeof($this->params) == 2){
$limit = $this->params[0];
$offset = $this->params[1];
}
$fisrtpage = $docModel->pageDoc($limit,$offset,5);
2020-07-28 14:19:23 +00:00
$top5 = $docModel->top5Doc();
echo "<pre>";
echo "</pre>";
2020-07-09 16:04:53 +00:00
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",[
2020-07-19 16:54:28 +00:00
"url"=>\App\Config::ServerUrl(),
2020-07-09 16:04:53 +00:00
'route'=>'article',
'docs'=>$firstpagedocs,
'index'=>true,
'debug'=>true,
"typedocs" => $typedocs,
"alltitle" => $titles,
"groups" => $groups,
2020-07-28 14:19:23 +00:00
"group_types"=>$groupstype,
"topdoc"=>$top5,
2020-07-28 14:39:14 +00:00
"title"=>"一个博客",
2020-07-09 16:04:53 +00:00
]);
else{
View::renderTemplate("/blog/index.html",[
2020-07-19 16:54:28 +00:00
"url"=>\App\Config::ServerUrl(),
2020-07-09 16:04:53 +00:00
'route'=>'article',
'docs'=>$firstpagedocs,
'index'=>true,
'debug'=>false,
"typedocs" => $typedocs,
"alltitle" => $titles,
"groups" => $groups,
2020-07-28 14:19:23 +00:00
"group_types"=>$groupstype,
"topdoc"=>$top5,
2020-07-28 14:39:14 +00:00
"title"=>"一个博客",
2020-07-09 16:04:53 +00:00
]);
}
}
2020-07-11 18:16:35 +00:00
function articleAction(){
2020-07-16 16:30:40 +00:00
$commentModel = new Models\DocComment();
$doccoment = $commentModel->DocComments((int)$this->params[0]);
2020-07-14 16:27:25 +00:00
if(sizeof($this->params) > 0){
2020-07-28 14:19:23 +00:00
2020-07-14 16:27:25 +00:00
}
$docModel = new Models\Doc();
$limit = 5;
$offset = 0;
$firstpagedocs = [];
$typedocs = $docModel->getAllTypeDocs();
2020-07-15 15:01:22 +00:00
$doc = $docModel->doc((int)$this->params[0]);
2020-07-14 16:27:25 +00:00
$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(5,0,5);
2020-07-15 15:01:22 +00:00
$markdown = new Parsedown;
$doc[0]['content'] = $markdown->text($doc[0]['content']);
2020-07-28 14:19:23 +00:00
$top5 = $docModel->top5Doc();
2020-07-12 07:59:34 +00:00
2020-07-14 16:27:25 +00:00
foreach ($fisrtpage as $key => $value) {
$obj['title'] = $value['title'];
$obj['id'] = $value['id'];
$obj['content'] = $value['content'];
$obj['type'] = $value['type'];
//数据加工
$content = $markdown->text($value['content']);
$obj['content'] = $content;
array_push($firstpagedocs,$obj);
}
if(\App\Config::$DEBUG)
2020-07-15 15:01:22 +00:00
View::renderTemplate("/blog/article.html",[
2020-07-19 16:54:28 +00:00
"url"=>\App\Config::ServerUrl(),
2020-07-14 16:27:25 +00:00
'route'=>'article',
'index'=>true,
'debug'=>true,
"typedocs" => $typedocs,
"alltitle" => $titles,
"groups" => $groups,
"group_types"=>$groupstype,
"title"=>urldecode ($this->params[1]),
2020-07-15 15:01:22 +00:00
"doc"=>$doc[0],
2020-07-16 16:30:40 +00:00
"comments" => $doccoment,
"comment_count" => count($doccoment),
2020-07-19 16:54:28 +00:00
"doc_type"=>$doc[0]["type"],
2020-07-19 17:06:07 +00:00
"group_type"=>$docModel->TypeGroup($doc[0]["type"])[0][0],
2020-07-28 14:19:23 +00:00
"topdoc"=>$top5,
2020-07-14 16:27:25 +00:00
]);
else{
2020-07-15 15:01:22 +00:00
View::renderTemplate("/blog/article.html",[
2020-07-19 16:54:28 +00:00
"url"=>\App\Config::ServerUrl(),
2020-07-14 16:27:25 +00:00
'route'=>'article',
'index'=>true,
'debug'=>false,
"typedocs" => $typedocs,
"alltitle" => $titles,
"groups" => $groups,
"group_types"=>$groupstype,
"title"=>urldecode ($this->params[1]),
2020-07-15 15:01:22 +00:00
"doc"=>$doc[0],
2020-07-16 16:30:40 +00:00
"comments" => $doccoment,
"comment_count" => count($doccoment),
2020-07-19 16:54:28 +00:00
"doc_type"=>$doc[0]["type"],
2020-07-19 17:06:07 +00:00
"group_type"=>$docModel->TypeGroup($doc[0]["type"])[0][0],
2020-07-28 14:19:23 +00:00
"topdoc"=>$top5,
2020-07-14 16:27:25 +00:00
]);
2020-07-11 18:16:35 +00:00
}
}
2020-07-09 16:04:53 +00:00
}