diff --git a/TODO.md b/TODO.md index e44dc7b..718caac 100644 --- a/TODO.md +++ b/TODO.md @@ -2,4 +2,5 @@ - 完善euapi主题 - 完善获取分类,分类下的数量列表,现在只实现当前分类,没有包含下钻分类 - 完善用户发帖数量等字段 -- doc文档上输出 \ No newline at end of file +- doc文档上输出 +- 文章分类id和别名拆分,直接使用别名 \ No newline at end of file diff --git a/app/common/model/Document.php b/app/common/model/Document.php index e427c0d..a94ace2 100644 --- a/app/common/model/Document.php +++ b/app/common/model/Document.php @@ -85,6 +85,7 @@ class Document extends BaseModel if (!$info) { return []; } + $info->comment = (new Comment())->where('document_id', $id)->count(); return $info->toArray(); } diff --git a/app/common/taglib/Ape.php b/app/common/taglib/Ape.php index 02fcb43..5babacc 100644 --- a/app/common/taglib/Ape.php +++ b/app/common/taglib/Ape.php @@ -142,7 +142,7 @@ class Ape extends TagLib $display = $tag['display'] ?? 1; $display = $display == 1 ? 1 : 0; $parse = 'render();'; $parse .= ' ?>'; $parse .= '{volist name="__LIST__" id="' . $void . '" key="i"}'; diff --git a/app/index/common.php b/app/index/common.php index c3ba85c..5de5497 100644 --- a/app/index/common.php +++ b/app/index/common.php @@ -44,9 +44,7 @@ function get_document_category_list() { //缓存文章菜单 $documentCategory = cache(Data::DATA_DOCUMENT_CATEGORY_LIST); - $documentCategory = null; - - if ($documentCategory === null) { + if (is_null($documentCategory)) { $documentCategory = DocumentCategory::where('status', 1)->order('sort asc')->select()->toArray(); $documentList = Document::where('display', 1) ->where('status', 1) @@ -55,14 +53,17 @@ function get_document_category_list() ->column('count(*) as count', 'category_id'); //TODO 需要实现包含下级分类所有数据的逻辑 使用下面两个函数实现,暂未完成 ///转换,让id作为数组的键 - foreach ($documentCategory as &$item) { + $tempList = []; + foreach ($documentCategory as $item) { //根据栏目类型,生成栏目url $item['url'] = make_category_url($item); $item['dc_count'] = $documentList[$item['id']] ?? 0; + $tempList[$item['id']] = $item; } + $documentCategory = $tempList; + unset($item,$tempList,$documentList); cache(Data::DATA_DOCUMENT_CATEGORY_LIST, $documentCategory); } - return $documentCategory; } @@ -390,7 +391,7 @@ function tpl_get_prenext($get, $cid = "",$type ="article") * @throws DbException * @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()) ->alias('a') @@ -460,7 +461,7 @@ function tpl_get_list($orderBy, int $pageSize, $cid, $type, $table = 'article', //获取评论数 跟在文章后面 if (!empty($item)){ $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') ->select(); } @@ -497,7 +498,8 @@ function get_route_query() */ 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)){ $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') ->select(); } @@ -775,7 +777,7 @@ if (!function_exists('tpl_get_tags_list')) { */ function tpl_get_position($dc, $positionList = array()) { - array_push($positionList, $dc); + $positionList[] = $dc; if ($dc['pid'] == 0) { $htmlStr = '首页'; $positionListCount = count($positionList); diff --git a/app/index/controller/Article.php b/app/index/controller/Article.php index 38920e0..c5c4956 100644 --- a/app/index/controller/Article.php +++ b/app/index/controller/Article.php @@ -77,8 +77,8 @@ class Article extends Base //判断seo标题是否存在 $dc['meta_title'] = $dc['meta_title'] ?: $dc['title']; //判断SEO 为空则取系统 - $article['keywords'] = $dc['keywords'] ?: web_config('keywords'); - $article['description'] = $dc['description'] ?: web_config('description'); + $dc['keywords'] = $dc['keywords'] ?: web_config('keywords'); + $dc['description'] = $dc['description'] ?: web_config('description'); //添加当前页面的位置信息 $dc['position'] = tpl_get_position($dc); //输出文章分类 @@ -138,6 +138,7 @@ class Article extends Base } $article['category_title'] = $dc['title']; //判断SEO 为空则取系统 + $article['meta_title'] = $article['title']; $article['keywords'] = $article['keywords'] ?: web_config('keywords'); $article['description'] = $article['description'] ?: web_config('description'); //输出文章内容 @@ -170,6 +171,7 @@ class Article extends Base public function create_comment(Request $request) { $data = Util::postMore([ + ['captcha',''], ['document_id', ''], ['pid', ''], ['author', ''], @@ -192,6 +194,11 @@ class Article extends Base $data['email'] = $this->userInfo['email']?:''; $data['url'] = ''; } + //开始判断留言是否显示验证码,显示则需要判断验证码 + if ($data['captcha'] != "" && !captcha_check($data['captcha'])){ + // 验证码验证 + $this->error('验证码不正确', null); + } if ($data['document_id'] == "") $this->error("文章id不能为空"); if ($data['content'] == "") $this->error("内容能为空"); $data['status'] = web_config('comment_review') ? 0 : 1;