diff --git a/app/common/taglib/Ape.php b/app/common/taglib/Ape.php index b166089..927b4a2 100644 --- a/app/common/taglib/Ape.php +++ b/app/common/taglib/Ape.php @@ -17,6 +17,8 @@ class Ape extends TagLib{ 'advert'=> ['attr' => 'type,row,void', 'close' => 1], 'sql'=> ['attr' => 'sql', 'close' => 1], 'article'=> ['attr' => 'id,void,model', 'close' => 1], + 'comment'=> ['attr' => 'id,void,orderby,pagesize', 'close' => 1], + 'relevant'=> ['attr' => 'id,model,void,row', 'close' => 1], 'tags'=> ['attr' => 'tags,void', 'close' => 1], ]; @@ -180,7 +182,7 @@ class Ape extends TagLib{ } /** - * poster + * tagBanner */ public function tagBanner($tag,$content) { @@ -280,4 +282,55 @@ class Ape extends TagLib{ return $parse; } + /** + * 文章回复列表 + * @param $tag + * @param $content + * @return bool|string + * @author 李玉坤 + * @date 2021-11-27 23:44 + */ + public function tagComment($tag,$content) + { + if(!isset($tag['id'])){ + return ''; + } + $documentId = $tag['id']; + $void=isset($tag['void'])?$tag['void']:'field'; + $orderBy=isset($tag['orderby'])?$tag['orderby']:'sort asc,create_time desc'; + $pageSize=isset($tag['pagesize'])?$tag['pagesize']:15; + $parse = ''; + $parse .= '{volist name="$__LIST__" id="'.$void.'"}'; + $parse .= $content; + $parse .= '{/volist}'; + return $parse; + } + + /** + * 文章推荐列表 + * @param $tag + * @param $content + * @return string + * @author 李玉坤 + * @date 2021-11-28 0:52 + */ + public function tagRelevant($tag,$content) + { + if(!isset($tag['id'])){ + return ''; + } + $documentId = $tag['id']; + $void=isset($tag['void'])?$tag['void']:'field'; + $row=isset($tag['row'])?$tag['row']:100; + $model=isset($tag['model'])?$tag['model']:'article'; + $parse = ''; + $parse .= '{volist name="$__LIST__" id="'.$void.'"}'; + $parse .= $content; + $parse .= '{/volist}'; + return $parse; + } } \ No newline at end of file diff --git a/app/index/common.php b/app/index/common.php index c09e91d..3c275aa 100644 --- a/app/index/common.php +++ b/app/index/common.php @@ -282,7 +282,6 @@ function tpl_get_prenext($get, $cid = false, $none) if (!$get) { $get = 'next'; } - $document = Document::where('display', 1)->where('status', 1); $document = $get == 'pre' ? $document->where("id", '<', $id) : $document->where("id", '>', $id); @@ -664,6 +663,88 @@ function tpl_get_position($dc, $positionList = array()) return tpl_get_position($parentDc, $positionList); } +/** + * 获取文章评论列表 + * @param $documentId + * @param $orderBy + * @param $pageSize + * @return array + * @throws \think\db\exception\DbException + * @author 李玉坤 + * @date 2021-11-28 0:51 + */ +function tpl_get_comment_list($documentId,$orderBy, $pageSize) +{ + $commentList = \app\common\model\Comment::where('document_id',$documentId)->where('status', 1)->order($orderBy); + //获取当前请求的请求参数,以确定分页是否要带上这些请求参数 + $query = request()->query(); + if ($query) { + $commentList = $commentList->paginate($pageSize, false, ['query' => getRouteQuery()]); + } else { + $commentList = $commentList->paginate($pageSize); + } + $lists = []; + foreach ($commentList as $key => $item) { + //生成文章url + $item['url'] = aurl($item); + $lists[$key] = $item; + } + $re = [ + 'model' => $commentList, + 'lists' => $lists + ]; + return $re; +} + +/** + * 获取文章相关文章 + * @param $documentId + * @param $row + * @param string $table + * @return Document[]|array|\think\Collection + * @throws \think\db\exception\DataNotFoundException + * @throws \think\db\exception\DbException + * @throws \think\db\exception\ModelNotFoundException + * @author 李玉坤 + * @date 2021-11-28 1:02 + */ +function tpl_get_relevant_list($documentId, $row, $table = 'article') +{ + $count = Document::where('type',$table) + ->where('status', 1)->count(); //获取总记录数 + $id = (new Document())->getPK(); + $min = Document::where('type',$table) + ->where('status', 1)->min($id); //统计某个字段最小数据 + if($count < $row){$row = $count;} + $i = 1; + $flag = 0; + $ary = array(); + while($i<=$row){ + $rundnum = rand($min, $count);//抽取随机数 + if($flag != $rundnum){ + //过滤重复 + if(!in_array($rundnum,$ary)){ + $ary[] = $rundnum; + $flag = $rundnum; + }else{ + $i--; + } + $i++; + } + } + $relevantList = Document::where('type',$table) + ->where('status', 1) + ->where( $id,'<>',$documentId) + ->where($id,'in',$ary) + ->limit($row)->select(); + $lists = []; + foreach ($relevantList as $key => $item) { + //生成文章url + $item['url'] = aurl($item); + $lists[$key] = $item; + } + return $relevantList; +} //获取顶级栏目名 function GetTopTypename($id = false) @@ -796,4 +877,5 @@ function ismobile() } } return false; -} \ No newline at end of file +} + diff --git a/public/template/default/pc/article/detail.html b/public/template/default/pc/article/detail.html index 6ea6877..432a436 100644 --- a/public/template/default/pc/article/detail.html +++ b/public/template/default/pc/article/detail.html @@ -190,7 +190,7 @@