mirror of https://github.com/1099438829/apeblog
修正评论,评论增加验证码验证判断
修正文章获取评论数问题 修正标签获取文章列表偶发的报错问题 文章详情增加评论数 文章列表页数据获取和详情页数据获取问题修正
This commit is contained in:
parent
b02b2f39a8
commit
b2cfc6d619
1
TODO.md
1
TODO.md
|
|
@ -3,3 +3,4 @@
|
||||||
- 完善获取分类,分类下的数量列表,现在只实现当前分类,没有包含下钻分类
|
- 完善获取分类,分类下的数量列表,现在只实现当前分类,没有包含下钻分类
|
||||||
- 完善用户发帖数量等字段
|
- 完善用户发帖数量等字段
|
||||||
- doc文档上输出
|
- doc文档上输出
|
||||||
|
- 文章分类id和别名拆分,直接使用别名
|
||||||
|
|
@ -85,6 +85,7 @@ class Document extends BaseModel
|
||||||
if (!$info) {
|
if (!$info) {
|
||||||
return [];
|
return [];
|
||||||
}
|
}
|
||||||
|
$info->comment = (new Comment())->where('document_id', $id)->count();
|
||||||
return $info->toArray();
|
return $info->toArray();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -142,7 +142,7 @@ class Ape extends TagLib
|
||||||
$display = $tag['display'] ?? 1;
|
$display = $tag['display'] ?? 1;
|
||||||
$display = $display == 1 ? 1 : 0;
|
$display = $display == 1 ? 1 : 0;
|
||||||
$parse = '<?php ';
|
$parse = '<?php ';
|
||||||
$parse .= '$__FUN__ =' . "tpl_get_list(\"$orderBy\",$pageSize,\"$typeId\",\"$type\",\"$model\",\"$where\",$display);";
|
$parse .= '$__FUN__ =' . "tpl_get_list(\"$type\",\"$typeId\",\"$where\",\"$model\",\"$orderBy\",$pageSize,$display);";
|
||||||
$parse .= '$__LIST__ = $__FUN__["lists"];$pager = $__FUN__["model"]->render();';
|
$parse .= '$__LIST__ = $__FUN__["lists"];$pager = $__FUN__["model"]->render();';
|
||||||
$parse .= ' ?>';
|
$parse .= ' ?>';
|
||||||
$parse .= '{volist name="__LIST__" id="' . $void . '" key="i"}';
|
$parse .= '{volist name="__LIST__" id="' . $void . '" key="i"}';
|
||||||
|
|
|
||||||
|
|
@ -44,9 +44,7 @@ function get_document_category_list()
|
||||||
{
|
{
|
||||||
//缓存文章菜单
|
//缓存文章菜单
|
||||||
$documentCategory = cache(Data::DATA_DOCUMENT_CATEGORY_LIST);
|
$documentCategory = cache(Data::DATA_DOCUMENT_CATEGORY_LIST);
|
||||||
$documentCategory = null;
|
if (is_null($documentCategory)) {
|
||||||
|
|
||||||
if ($documentCategory === null) {
|
|
||||||
$documentCategory = DocumentCategory::where('status', 1)->order('sort asc')->select()->toArray();
|
$documentCategory = DocumentCategory::where('status', 1)->order('sort asc')->select()->toArray();
|
||||||
$documentList = Document::where('display', 1)
|
$documentList = Document::where('display', 1)
|
||||||
->where('status', 1)
|
->where('status', 1)
|
||||||
|
|
@ -55,14 +53,17 @@ function get_document_category_list()
|
||||||
->column('count(*) as count', 'category_id');
|
->column('count(*) as count', 'category_id');
|
||||||
//TODO 需要实现包含下级分类所有数据的逻辑 使用下面两个函数实现,暂未完成
|
//TODO 需要实现包含下级分类所有数据的逻辑 使用下面两个函数实现,暂未完成
|
||||||
///转换,让id作为数组的键
|
///转换,让id作为数组的键
|
||||||
foreach ($documentCategory as &$item) {
|
$tempList = [];
|
||||||
|
foreach ($documentCategory as $item) {
|
||||||
//根据栏目类型,生成栏目url
|
//根据栏目类型,生成栏目url
|
||||||
$item['url'] = make_category_url($item);
|
$item['url'] = make_category_url($item);
|
||||||
$item['dc_count'] = $documentList[$item['id']] ?? 0;
|
$item['dc_count'] = $documentList[$item['id']] ?? 0;
|
||||||
|
$tempList[$item['id']] = $item;
|
||||||
}
|
}
|
||||||
|
$documentCategory = $tempList;
|
||||||
|
unset($item,$tempList,$documentList);
|
||||||
cache(Data::DATA_DOCUMENT_CATEGORY_LIST, $documentCategory);
|
cache(Data::DATA_DOCUMENT_CATEGORY_LIST, $documentCategory);
|
||||||
}
|
}
|
||||||
|
|
||||||
return $documentCategory;
|
return $documentCategory;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -390,7 +391,7 @@ function tpl_get_prenext($get, $cid = "",$type ="article")
|
||||||
* @throws DbException
|
* @throws DbException
|
||||||
* @throws ModelNotFoundException
|
* @throws ModelNotFoundException
|
||||||
*/
|
*/
|
||||||
function tpl_get_list($orderBy, int $pageSize, $cid, $type, $table = 'article', $where, int $display = 1)
|
function tpl_get_list($type, $cid, $where, string $table = 'article', string $orderBy = '', int $pageSize = 10, int $display = 1)
|
||||||
{
|
{
|
||||||
$documentListModel = (new Document())
|
$documentListModel = (new Document())
|
||||||
->alias('a')
|
->alias('a')
|
||||||
|
|
@ -460,7 +461,7 @@ function tpl_get_list($orderBy, int $pageSize, $cid, $type, $table = 'article',
|
||||||
//获取评论数 跟在文章后面
|
//获取评论数 跟在文章后面
|
||||||
if (!empty($item)){
|
if (!empty($item)){
|
||||||
$commentModel = (new Comment())->field('document_id as id,count(*) as comment')
|
$commentModel = (new Comment())->field('document_id as id,count(*) as comment')
|
||||||
->where("id","in" ,array_column($documentListModel->toArray(),'id'))
|
->where("document_id","in" ,array_column($documentListModel->toArray(),'id'))
|
||||||
->group('id')
|
->group('id')
|
||||||
->select();
|
->select();
|
||||||
}
|
}
|
||||||
|
|
@ -497,7 +498,8 @@ function get_route_query()
|
||||||
*/
|
*/
|
||||||
function make_category_url($item)
|
function make_category_url($item)
|
||||||
{
|
{
|
||||||
return url('/article/detail', ['id' => $item['alias'] ?: $item['id']])->build();
|
// return url('/article/lists', ['id' => $item['alias'] ?: $item['id']])->build();
|
||||||
|
return url('/article/lists', ['id' => $item['id']])->build();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
@ -595,7 +597,7 @@ function tpl_get_article_list($cid, $row, $orderby, $table = 'article', $type =
|
||||||
//获取评论数 跟在文章后面
|
//获取评论数 跟在文章后面
|
||||||
if (!empty($item)){
|
if (!empty($item)){
|
||||||
$commentModel = (new Comment())->field('document_id as id,count(*) as comment')
|
$commentModel = (new Comment())->field('document_id as id,count(*) as comment')
|
||||||
->where("id","in" ,array_column($documentListModel->toArray(),'id'))
|
->where("document_id","in" ,array_column($documentListModel->toArray(),'id'))
|
||||||
->group('id')
|
->group('id')
|
||||||
->select();
|
->select();
|
||||||
}
|
}
|
||||||
|
|
@ -775,7 +777,7 @@ if (!function_exists('tpl_get_tags_list')) {
|
||||||
*/
|
*/
|
||||||
function tpl_get_position($dc, $positionList = array())
|
function tpl_get_position($dc, $positionList = array())
|
||||||
{
|
{
|
||||||
array_push($positionList, $dc);
|
$positionList[] = $dc;
|
||||||
if ($dc['pid'] == 0) {
|
if ($dc['pid'] == 0) {
|
||||||
$htmlStr = '<a href="/">首页</a>';
|
$htmlStr = '<a href="/">首页</a>';
|
||||||
$positionListCount = count($positionList);
|
$positionListCount = count($positionList);
|
||||||
|
|
|
||||||
|
|
@ -77,8 +77,8 @@ class Article extends Base
|
||||||
//判断seo标题是否存在
|
//判断seo标题是否存在
|
||||||
$dc['meta_title'] = $dc['meta_title'] ?: $dc['title'];
|
$dc['meta_title'] = $dc['meta_title'] ?: $dc['title'];
|
||||||
//判断SEO 为空则取系统
|
//判断SEO 为空则取系统
|
||||||
$article['keywords'] = $dc['keywords'] ?: web_config('keywords');
|
$dc['keywords'] = $dc['keywords'] ?: web_config('keywords');
|
||||||
$article['description'] = $dc['description'] ?: web_config('description');
|
$dc['description'] = $dc['description'] ?: web_config('description');
|
||||||
//添加当前页面的位置信息
|
//添加当前页面的位置信息
|
||||||
$dc['position'] = tpl_get_position($dc);
|
$dc['position'] = tpl_get_position($dc);
|
||||||
//输出文章分类
|
//输出文章分类
|
||||||
|
|
@ -138,6 +138,7 @@ class Article extends Base
|
||||||
}
|
}
|
||||||
$article['category_title'] = $dc['title'];
|
$article['category_title'] = $dc['title'];
|
||||||
//判断SEO 为空则取系统
|
//判断SEO 为空则取系统
|
||||||
|
$article['meta_title'] = $article['title'];
|
||||||
$article['keywords'] = $article['keywords'] ?: web_config('keywords');
|
$article['keywords'] = $article['keywords'] ?: web_config('keywords');
|
||||||
$article['description'] = $article['description'] ?: web_config('description');
|
$article['description'] = $article['description'] ?: web_config('description');
|
||||||
//输出文章内容
|
//输出文章内容
|
||||||
|
|
@ -170,6 +171,7 @@ class Article extends Base
|
||||||
public function create_comment(Request $request)
|
public function create_comment(Request $request)
|
||||||
{
|
{
|
||||||
$data = Util::postMore([
|
$data = Util::postMore([
|
||||||
|
['captcha',''],
|
||||||
['document_id', ''],
|
['document_id', ''],
|
||||||
['pid', ''],
|
['pid', ''],
|
||||||
['author', ''],
|
['author', ''],
|
||||||
|
|
@ -192,6 +194,11 @@ class Article extends Base
|
||||||
$data['email'] = $this->userInfo['email']?:'';
|
$data['email'] = $this->userInfo['email']?:'';
|
||||||
$data['url'] = '';
|
$data['url'] = '';
|
||||||
}
|
}
|
||||||
|
//开始判断留言是否显示验证码,显示则需要判断验证码
|
||||||
|
if ($data['captcha'] != "" && !captcha_check($data['captcha'])){
|
||||||
|
// 验证码验证
|
||||||
|
$this->error('验证码不正确', null);
|
||||||
|
}
|
||||||
if ($data['document_id'] == "") $this->error("文章id不能为空");
|
if ($data['document_id'] == "") $this->error("文章id不能为空");
|
||||||
if ($data['content'] == "") $this->error("内容能为空");
|
if ($data['content'] == "") $this->error("内容能为空");
|
||||||
$data['status'] = web_config('comment_review') ? 0 : 1;
|
$data['status'] = web_config('comment_review') ? 0 : 1;
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue