|
@@ -1,5 +1,6 @@
|
|
<?php
|
|
<?php
|
|
-declare (strict_types = 1);
|
|
|
|
|
|
+
|
|
|
|
+declare(strict_types=1);
|
|
/**
|
|
/**
|
|
* +----------------------------------------------------------------------
|
|
* +----------------------------------------------------------------------
|
|
* 文章控制制器
|
|
* 文章控制制器
|
|
@@ -26,12 +27,18 @@ class Article extends Base
|
|
protected $modelName = "Article";
|
|
protected $modelName = "Article";
|
|
|
|
|
|
public function index()
|
|
public function index()
|
|
- {
|
|
|
|
|
|
+ {
|
|
$params = $this->app->request->param();
|
|
$params = $this->app->request->param();
|
|
|
|
|
|
$list = ArticleModel::queryPage($params);
|
|
$list = ArticleModel::queryPage($params);
|
|
-
|
|
|
|
- $baseUrl = $this->request->baseUrl();
|
|
|
|
|
|
+
|
|
|
|
+ $category = CategoryModel::find($params['cid']);
|
|
|
|
+
|
|
|
|
+ if ($category) {
|
|
|
|
+ $baseUrl = $category->url;
|
|
|
|
+ } else {
|
|
|
|
+ $baseUrl = '/index/all';
|
|
|
|
+ }
|
|
|
|
|
|
View::assign([
|
|
View::assign([
|
|
'baseUrl' => $baseUrl,
|
|
'baseUrl' => $baseUrl,
|
|
@@ -41,16 +48,21 @@ class Article extends Base
|
|
'page' => $list->currentPage(),
|
|
'page' => $list->currentPage(),
|
|
'lastPage' => $list->lastPage(),
|
|
'lastPage' => $list->lastPage(),
|
|
'pagelist' => $list->render(),
|
|
'pagelist' => $list->render(),
|
|
- 'cid' => $params['cid']
|
|
|
|
|
|
+ 'cid' => $params['cid'],
|
|
]);
|
|
]);
|
|
|
|
|
|
- return View::fetch();
|
|
|
|
|
|
+ $html = View::fetch();
|
|
|
|
+ // if ($this->html) {
|
|
|
|
+ // $this->makeHtmlFile($html);
|
|
|
|
+ // }
|
|
|
|
+
|
|
|
|
+ return $html;
|
|
}
|
|
}
|
|
|
|
|
|
/**
|
|
/**
|
|
* 阅读文章
|
|
* 阅读文章
|
|
*/
|
|
*/
|
|
- public function read($id=null)
|
|
|
|
|
|
+ public function read($id = null)
|
|
{
|
|
{
|
|
$data = ArticleModel::getOne($id);
|
|
$data = ArticleModel::getOne($id);
|
|
|
|
|
|
@@ -64,7 +76,7 @@ class Article extends Base
|
|
|
|
|
|
$prev_next = ArticleModel::getNextPrev($id, $data->cid);
|
|
$prev_next = ArticleModel::getNextPrev($id, $data->cid);
|
|
|
|
|
|
- if ($data->content_type==1) {
|
|
|
|
|
|
+ if ($data->content_type == 1) {
|
|
$parsedownExtension = new \ParsedownExtension();
|
|
$parsedownExtension = new \ParsedownExtension();
|
|
// $parsedownExtension->setTocEnabled(true);
|
|
// $parsedownExtension->setTocEnabled(true);
|
|
$res = $parsedownExtension->text($data->content);
|
|
$res = $parsedownExtension->text($data->content);
|
|
@@ -81,7 +93,12 @@ class Article extends Base
|
|
$this->seo['des'] = $data->summary;
|
|
$this->seo['des'] = $data->summary;
|
|
View::assign('seo', $this->seo);
|
|
View::assign('seo', $this->seo);
|
|
|
|
|
|
- return View::fetch();
|
|
|
|
|
|
+ $html = View::fetch();
|
|
|
|
+ if ($this->html) {
|
|
|
|
+ $this->makeHtmlFile($html);
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ return $html;
|
|
}
|
|
}
|
|
|
|
|
|
/**
|
|
/**
|
|
@@ -96,7 +113,7 @@ class Article extends Base
|
|
$log = ArticleDolikeLog::where('aid', $id)->where('ip', $ip)->find();
|
|
$log = ArticleDolikeLog::where('aid', $id)->where('ip', $ip)->find();
|
|
|
|
|
|
if ($log) {
|
|
if ($log) {
|
|
- return ['code' => 1, 'msg'=>'多谢喜欢, 已经点过赞了'];
|
|
|
|
|
|
+ return ['code' => 1, 'msg' => '多谢喜欢, 已经点过赞了'];
|
|
}
|
|
}
|
|
|
|
|
|
$res = ArticleModel::where('id', $id)->inc('likes')->update();
|
|
$res = ArticleModel::where('id', $id)->inc('likes')->update();
|
|
@@ -107,8 +124,8 @@ class Article extends Base
|
|
'ip' => $this->request->ip()
|
|
'ip' => $this->request->ip()
|
|
]);
|
|
]);
|
|
|
|
|
|
- if ($res===false) {
|
|
|
|
- return ['code' => 2, 'msg'=>'未知错误'];
|
|
|
|
|
|
+ if ($res === false) {
|
|
|
|
+ return ['code' => 2, 'msg' => '未知错误'];
|
|
} else {
|
|
} else {
|
|
return ['code' => 0];
|
|
return ['code' => 0];
|
|
}
|
|
}
|
|
@@ -117,7 +134,7 @@ class Article extends Base
|
|
/**
|
|
/**
|
|
* 标签列表
|
|
* 标签列表
|
|
*/
|
|
*/
|
|
- public function tags($name=null)
|
|
|
|
|
|
+ public function tags($name = null)
|
|
{
|
|
{
|
|
if (!$name) {
|
|
if (!$name) {
|
|
throw new HttpException(404, '标签不可为空');
|
|
throw new HttpException(404, '标签不可为空');
|
|
@@ -136,22 +153,32 @@ class Article extends Base
|
|
/**
|
|
/**
|
|
* 归档页面(时间)
|
|
* 归档页面(时间)
|
|
*/
|
|
*/
|
|
- public function archive($year=0, $month=0)
|
|
|
|
|
|
+ public function archive($year = 0, $month = 0)
|
|
{
|
|
{
|
|
$yearMonth = $year . '-' . $month;
|
|
$yearMonth = $year . '-' . $month;
|
|
|
|
|
|
- if ($year==0 || $month==0) {
|
|
|
|
|
|
+ if ($year == 0 || $month == 0) {
|
|
throw new HttpException(404, '日期格式不正确');
|
|
throw new HttpException(404, '日期格式不正确');
|
|
}
|
|
}
|
|
|
|
|
|
- $list = ArticleModel::queryPage(['yearMonth'=>$yearMonth]);
|
|
|
|
|
|
+ $list = ArticleModel::queryPage(['yearMonth' => $yearMonth]);
|
|
|
|
|
|
View::assign([
|
|
View::assign([
|
|
- 'list' => $list,
|
|
|
|
|
|
+ 'list' => $list->all(),
|
|
|
|
+ 'total' => $list->total(),
|
|
|
|
+ 'limit' => $list->listRows(),
|
|
|
|
+ 'page' => $list->currentPage(),
|
|
|
|
+ 'lastPage' => $list->lastPage(),
|
|
|
|
+ 'pagelist' => $list->render(),
|
|
'yearMonth' => $yearMonth
|
|
'yearMonth' => $yearMonth
|
|
]);
|
|
]);
|
|
|
|
|
|
- return View::fetch();
|
|
|
|
|
|
+ $html = View::fetch();
|
|
|
|
+ // if ($this->html) {
|
|
|
|
+ // $this->makeHtmlFile($html);
|
|
|
|
+ // }
|
|
|
|
+
|
|
|
|
+ return $html;
|
|
}
|
|
}
|
|
|
|
|
|
/**
|
|
/**
|
|
@@ -159,11 +186,23 @@ class Article extends Base
|
|
*/
|
|
*/
|
|
public function time()
|
|
public function time()
|
|
{
|
|
{
|
|
- $list =ArticleModel::field('id,cid,title,titlepic,username,summary,hits,sort,status,create_time')->with(['category'])->order('update_time desc')->paginate();
|
|
|
|
|
|
+ $params = ['order' => 'update_time desc'];
|
|
|
|
+ $list = ArticleModel::queryPage($params);
|
|
|
|
+
|
|
|
|
+ View::assign([
|
|
|
|
+ 'list' => $list->all(),
|
|
|
|
+ 'total' => $list->total(),
|
|
|
|
+ 'limit' => $list->listRows(),
|
|
|
|
+ 'page' => $list->currentPage(),
|
|
|
|
+ 'lastPage' => $list->lastPage(),
|
|
|
|
+ 'pagelist' => $list->render(),
|
|
|
|
+ ]);
|
|
|
|
|
|
- View::assign('list', $list);
|
|
|
|
|
|
+ $html = View::fetch();
|
|
|
|
+ if ($this->html) {
|
|
|
|
+ $this->makeHtmlFile($html);
|
|
|
|
+ }
|
|
|
|
|
|
- return View::fetch();
|
|
|
|
|
|
+ return $html;
|
|
}
|
|
}
|
|
-
|
|
|
|
}
|
|
}
|