From e0ed3971661b3800d32fe9fe591c02c4546caafd Mon Sep 17 00:00:00 2001 From: liyukun <1099438829@qq.com> Date: Fri, 31 Dec 2021 00:29:08 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=E4=BA=8C=E7=BA=A7=E8=AF=84?= =?UTF-8?q?=E8=AE=BA=E5=B1=95=E7=A4=BA=20=E4=BC=98=E5=8C=96=E4=BB=A3?= =?UTF-8?q?=E7=A0=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/common/taglib/Ape.php | 42 ++++++++++-------- app/index/common.php | 93 +++++++++++++++++++++++++++------------ 2 files changed, 89 insertions(+), 46 deletions(-) diff --git a/app/common/taglib/Ape.php b/app/common/taglib/Ape.php index 98e0aed..255406a 100644 --- a/app/common/taglib/Ape.php +++ b/app/common/taglib/Ape.php @@ -61,6 +61,9 @@ class Ape extends TagLib /** * 文章列表 + * @param $tag + * @param $content + * @return string */ public function tagArclist($tag, $content) { @@ -100,6 +103,9 @@ class Ape extends TagLib /** * 栏目分类-单个 + * @param $tag + * @param $content + * @return string */ public function tagType($tag, $content) { @@ -120,6 +126,9 @@ class Ape extends TagLib /** * 列表分页 + * @param $tag + * @param $content + * @return string */ public function tagList($tag, $content) { @@ -165,6 +174,9 @@ class Ape extends TagLib /** * 友情链接 + * @param $tag + * @param $content + * @return string */ public function tagFlink($tag, $content) { @@ -204,26 +216,11 @@ class Ape extends TagLib return $parse; } - /** - * 执行SQL - */ - public function tagSql($tag, $content) - { - if (!isset($tag['sql'])) { - return ''; - } - $sql = $tag['sql']; - $parse = 'query(\"$sql\");"; - $parse .= ' ?>'; - $parse .= '{volist name="__LIST__" id="field"}'; - $parse .= $content; - $parse .= '{/volist}'; - return $parse; - } - /** * 获取单篇文章 + * @param $tag + * @param $content + * @return string */ public function tagArticle($tag, $content) { @@ -244,6 +241,9 @@ class Ape extends TagLib /** * 文章标签 + * @param $tag + * @param $content + * @return bool|string */ public function tagTags($tag, $content) { @@ -279,7 +279,11 @@ class Ape extends TagLib $orderBy = isset($tag['orderBy']) ? $tag['orderBy'] : 'id asc'; $parse = 'render();'; + if ($type == 'top') { + $parse .= '$__LIST__ = $__FUN__["lists"];$pager = $__FUN__["model"]->render();'; + } else { + $parse .= '$__LIST__ = $__FUN__["lists"];'; + } $parse .= ' ?>'; $parse .= '{volist name="__LIST__" id="' . $void . '" key="i"}'; $parse .= $content; diff --git a/app/index/common.php b/app/index/common.php index 9ad15f4..ad1d367 100644 --- a/app/index/common.php +++ b/app/index/common.php @@ -1,17 +1,20 @@ alias('a') - ->join(config('database.prefix') . 'document_category b', 'a.category_id=b.id', 'LEFT') - ->join(config('database.prefix') . "document_$table c", 'a.id=c.id', 'LEFT') + ->leftJoin(config('database.prefix') . 'document_category b', 'a.category_id=b.id') + ->leftJoin(config('database.prefix') . "document_$table c", 'a.id=c.id') ->where("a.type='$table'") ->where('a.status', 1) ->where('b.status', 1) @@ -365,7 +373,7 @@ function tpl_get_list($orderby, $pageSize, $cid, $type, $table = 'article', $whe $documentListModel = $documentListModel->where('a.id', 'in', array_column($tagList, 'document_id')); break; } - $documentListModel = $documentListModel->order($orderby); + $documentListModel = $documentListModel->order($orderBy); //获取当前请求的请求参数,以确定分页是否要带上这些请求参数 $query = request()->query(); if ($query) { @@ -400,6 +408,8 @@ function get_route_query() /** * 根据栏目类型,生成栏目url + * @param $item + * @return mixed|string */ function make_category_url($item) { @@ -410,10 +420,13 @@ function make_category_url($item) } elseif ((int)$item['type'] == 2) { return $item['link_str']; } + return false; } /** * 生成文章url + * @param $item + * @return mixed|string */ function make_detail_url($item) { @@ -432,8 +445,8 @@ function make_detail_url($item) function tpl_get_article($id, $table) { $documentModel = Document::alias('a') - ->join(config('database.prefix') . 'document_category b', 'a.category_id=b.id', 'LEFT') - ->join(config('database.prefix') . "document_$table c", 'a.id=c.id', 'LEFT') + ->leftJoin(config('database.prefix') . 'document_category b', 'a.category_id=b.id') + ->leftJoin(config('database.prefix') . "document_$table c", 'a.id=c.id') ->where('a.status', 1)->where('a.id', $id)->where("a.type='$table'") ->field('a.*,b.title as category_title,c.*'); @@ -633,18 +646,30 @@ function tpl_get_position($dc, $positionList = array()) { array_push($positionList, $dc); if ($dc['pid'] == 0) { - $htmlstr = '首页'; + $htmlStr = '首页'; $positionListCount = count($positionList); for ($x = $positionListCount - 1; $x >= 0; $x--) { - $htmlstr = $htmlstr . '>' . $positionList[$x]['title'] . ''; + $htmlStr = $htmlStr . '>' . $positionList[$x]['title'] . ''; } - return $htmlstr; + return $htmlStr; } //获取父级栏目分类 $parentDc = get_document_category($dc['pid']); return tpl_get_position($parentDc, $positionList); } +function get_comment_children($parentIds){ + $list = $commentModel = Comment::where('status', 1)->where('pid','in', $parentIds)->select()->toArray(); + if (empty($list)){ + return $list; + } + foreach ($list as &$item){ + $item['reply_url'] = url('article/create_comment?pid=' . $item['id'])->build();; + } + unset($item); + return array_merge($list,get_comment_children(array_column($list,'id'))); +} + /** * 获取文章评论列表 * @param $id @@ -656,9 +681,9 @@ function tpl_get_position($dc, $positionList = array()) * @author 李玉坤 * @date 2021-12-05 23:54 */ -function tpl_get_comment_list($id, $type, $pageSize = 10, $orderBy) +function tpl_get_comment_list($id, $type, $pageSize, $orderBy) { - $commentModel = \app\common\model\Comment::where('status', 1)->order($orderBy); + $commentModel = Comment::where('status', 1)->order($orderBy); switch ($type) { case 'top': //获取所有的一级评论 @@ -666,13 +691,16 @@ function tpl_get_comment_list($id, $type, $pageSize = 10, $orderBy) break; case 'son': //获取栏目下文章 - $commentModel = $commentModel->where('pid', $id); + return [ + 'model' => $commentModel, + 'lists' => get_comment_children([$id]) + ]; break; } //获取当前请求的请求参数,以确定分页是否要带上这些请求参数 $query = request()->query(); if ($query) { - $commentModel = $commentModel->paginate($pageSize, false, ['query' => get_route_query()]); + $commentModel = $commentModel->paginate($pageSize, false); } else { $commentModel = $commentModel->paginate($pageSize); } @@ -681,23 +709,34 @@ function tpl_get_comment_list($id, $type, $pageSize = 10, $orderBy) $item['reply_url'] = url('article/create_comment?pid=' . $item['id'])->build();; $lists[$key] = $item; } - $re = [ + return [ 'model' => $commentModel, 'lists' => $lists ]; - return $re; } /** * 获取评论数量 * @param $documentId + * @param string $type * @return int * @author 李玉坤 * @date 2021-12-05 23:16 */ -function get_comment_count($documentId) +function get_comment_count($documentId, $type = 'top') { - return \app\common\model\Comment::where('document_id', $documentId)->where('status', 1)->count(); + $commentModel = Comment::where('status', 1); + switch ($type) { + case 'top': + //获取所有的一级评论 + $commentModel = $commentModel->where('document_id', $documentId)->where('pid', 0); + break; + case 'son': + //获取栏目下文章 + $commentModel = $commentModel->where('pid', $documentId); + break; + } + return $commentModel->count(); }