From 89ece0799385d8cce050e89ab587d8d6206fa2ae Mon Sep 17 00:00:00 2001 From: taoser Date: Wed, 7 Sep 2022 15:20:00 +0800 Subject: [PATCH] =?UTF-8?q?tag=E8=A1=A8=E5=A2=9E=E5=8A=A0keywords=E3=80=81?= =?UTF-8?q?description=E3=80=81title=E5=AD=97=E6=AE=B5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/BaseController.php | 154 ++++++++-------- app/admin/controller/Forum.php | 18 +- app/admin/controller/Set.php | 2 +- app/admin/controller/Tag.php | 13 +- app/admin/controller/Upgrade.php | 2 +- app/admin/route/route.php | 2 - app/admin/view/forum/edit.html | 4 +- app/admin/view/set/system/website.html | 12 +- app/admin/view/tag/add.html | 18 ++ app/admin/view/tag/edit.html | 18 ++ app/admin/view/tag/index.html | 11 +- app/common/model/Article.php | 63 ++++++- app/common/model/Comment.php | 6 +- app/common/model/MessageTo.php | 13 +- app/common/model/Sign.php | 7 +- app/common/model/Slider.php | 4 +- app/index/controller/Article.php | 58 +++--- app/index/controller/Message.php | 27 +-- app/index/controller/Tag.php | 6 +- app/index/lang/zh-cn.php | 4 +- app/install/data/taoler.sql | 5 +- extend/taoler/com/Message.php | 18 +- view/taoler/index/article/add.html | 185 ++++++++++---------- view/taoler/index/article/ask/detail.html | 2 + view/taoler/index/article/edit.html | 143 ++++++++++----- view/taoler/index/article/news/detail.html | 2 + view/taoler/index/article/posts/detail.html | 2 + view/taoler/index/public/header.html | 2 +- view/taoler/index/tag/index.html | 15 +- view/taoler/index/user/home.html | 5 - view/taoler/index/user/set.html | 6 +- 31 files changed, 502 insertions(+), 325 deletions(-) diff --git a/app/BaseController.php b/app/BaseController.php index 3538a99..c6cb3a7 100644 --- a/app/BaseController.php +++ b/app/BaseController.php @@ -292,84 +292,98 @@ abstract class BaseController /** * 关键词 + * 通过百度分词接口获取关键词或者标签 + * flag 1.为word时获取分词,2.为tag时获取标签 * * @return void */ public function setKeywords($data) { $keywords = []; + // 百度分词自动生成关键词 + if(!empty(config('taoler.baidu.client_id')) == true) { + //headers数组内的格式 + $headers = array(); + $headers[] = "Content-Type:application/json"; - if($data['flag'] == 'on') { - // 百度分词自动生成关键词 - if(!empty(config('taoler.baidu.client_id')) == true) { - $url = 'https://aip.baidubce.com/rpc/2.0/nlp/v1/lexer?charset=UTF-8&access_token='.config('taoler.baidu.access_token'); + switch($data['flag']) { + //分词 + case 'word': + $url = 'https://aip.baidubce.com/rpc/2.0/nlp/v1/lexer?charset=UTF-8&access_token='.config('taoler.baidu.access_token'); + $body = ["text" => $data['keywords']]; + break; + //标签 + case 'tag': + $url = 'https://aip.baidubce.com/rpc/2.0/nlp/v1/keyword?charset=UTF-8&access_token='.config('taoler.baidu.access_token'); + $body = ['title' => $data['keywords'], 'content'=>$data['content']]; + break; + default: + $url = 'https://aip.baidubce.com/rpc/2.0/nlp/v1/lexer?charset=UTF-8&access_token='.config('taoler.baidu.access_token'); + $body = ["text" => $data['keywords']]; + } + + $postBody = json_encode($body); + $curl = curl_init(); + curl_setopt($curl, CURLOPT_URL, $url); + curl_setopt($curl, CURLOPT_POST, true); + curl_setopt($curl, CURLOPT_HTTPHEADER, $headers);//设置请求头 + curl_setopt($curl, CURLOPT_POSTFIELDS, $postBody);//设置请求体 + curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1); + curl_setopt($curl, CURLOPT_CUSTOMREQUEST, 'POST');//使用一个自定义的请求信息来代替"GET"或"HEAD"作为HTTP请求。(这个加不加没啥影响) + $datas = curl_exec($curl); + if($datas == false) { + echo '接口无法链接'; + } else { + $res = stripos($datas,'error_code'); + // 接收返回的数据 + $dataItem = json_decode($datas); + if($res == false) { + // 数据正常 + $items = $dataItem->items; + foreach($items as $item) { + + switch($data['flag']) { + case 'word': + if($item->pos == 'n' && !in_array($item->item,$keywords)){ + $keywords[] = $item->item; + } + break; + case 'tag': + if(!in_array($item->tag,$keywords)){ + $keywords[] = $item->tag; + } + break; + default: + if($item->pos == 'n' && !in_array($item->item,$keywords)){ + $keywords[] = $item->item; + } + } + } + } else { + // 接口正常但获取数据失败,可能参数错误,重新获取token + $url = 'https://aip.baidubce.com/oauth/2.0/token'; + $post_data['grant_type'] = config('taoler.baidu.grant_type');; + $post_data['client_id'] = config('taoler.baidu.client_id'); + $post_data['client_secret'] = config('taoler.baidu.client_secret'); - //headers数组内的格式 - $headers = array(); - $headers[] = "Content-Type:application/json"; - $body = array( - "text" => $data['$keywords'] - ); - $postBody = json_encode($body); - $curl = curl_init(); - curl_setopt($curl, CURLOPT_URL, $url); - curl_setopt($curl, CURLOPT_POST, true); - curl_setopt($curl, CURLOPT_HTTPHEADER, $headers);//设置请求头 - curl_setopt($curl, CURLOPT_POSTFIELDS, $postBody);//设置请求体 - curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1); - curl_setopt($curl, CURLOPT_CUSTOMREQUEST, 'POST');//使用一个自定义的请求信息来代替"GET"或"HEAD"作为HTTP请求。(这个加不加没啥影响) - $datas = curl_exec($curl); - if($datas == false) { - echo '接口无法链接'; - } else { - $res = stripos($datas,'error_code'); - // 接收返回的数据 - $dataItem = json_decode($datas); - if($res == false) { - // 数据正常 - $items = $dataItem->items; - foreach($items as $item) { - if($item->pos == 'n' && !in_array($item->item,$keywords)){ - $keywords[] = $item->item; - } - } - } else { - // 接口正常但获取数据失败,可能参数错误,重新获取token - $url = 'https://aip.baidubce.com/oauth/2.0/token'; - $post_data['grant_type'] = config('taoler.baidu.grant_type');; - $post_data['client_id'] = config('taoler.baidu.client_id'); - $post_data['client_secret'] = config('taoler.baidu.client_secret'); - - $o = ""; - foreach ( $post_data as $k => $v ) - { - $o.= "$k=" . urlencode( $v ). "&" ; - } - $post_data = substr($o,0,-1); - $res = $this->request_post($url, $post_data); - // 写入token - SetArr::name('taoler')->edit([ - 'baidu'=> [ - 'access_token' => json_decode($res)->access_token, - ] - ]); - echo 'api接口数据错误 - '; - echo $dataItem->error_msg; - } - } - } - } else { - // 手动添加关键词 - // 中文一个或者多个空格转换为英文空格 - $str = preg_replace('/\s+/',' ',$data['keywords']); - $att = explode(' ', $str); - foreach($att as $v){ - if ($v !='') { - $keywords[] = $v; - } - } - } - + $o = ""; + foreach ( $post_data as $k => $v ) + { + $o.= "$k=" . urlencode( $v ). "&" ; + } + $post_data = substr($o,0,-1); + $res = $this->request_post($url, $post_data); + // 写入token + SetArr::name('taoler')->edit([ + 'baidu'=> [ + 'access_token' => json_decode($res)->access_token, + ] + ]); + echo 'api接口数据错误 - '; + echo $dataItem->error_msg; + } + } + } return json(['code'=>0,'data'=>$keywords]); } diff --git a/app/admin/controller/Forum.php b/app/admin/controller/Forum.php index 41394a3..6176219 100644 --- a/app/admin/controller/Forum.php +++ b/app/admin/controller/Forum.php @@ -409,11 +409,11 @@ class Forum extends AdminController public function edit($id) { $article = Article::find($id); - if(Request::isAjax()){ + $data = Request::only(['id','cate_id','title','title_color','content','upzip','keywords','description','captcha']); $tagId = input('tagid'); - $data['user_id'] = 1; + //调用验证器 $validate = new \app\common\validate\Article(); $res = $validate->scene('Artadd')->check($data); @@ -466,20 +466,8 @@ class Forum extends AdminController return $editRes; } } - // 查询标签 - $tag = $article->tags; - $tags = []; - if(!is_null($tag)) { - $attr = explode(',',$tag); - foreach($attr as $key => $v){ - if ($v !='') { - $tags[] = $v; - } - } - - } - View::assign(['article'=>$article,'tags'=>$tags]); + View::assign(['article'=>$article]); //1.查询分类表获取所有分类 $cateList = Db::name('cate')->where(['status'=>1,'delete_time'=>0])->order('sort','asc')->cache('catename',3600)->select(); diff --git a/app/admin/controller/Set.php b/app/admin/controller/Set.php index a49cf08..fad8966 100644 --- a/app/admin/controller/Set.php +++ b/app/admin/controller/Set.php @@ -336,7 +336,7 @@ class Set extends AdminController $arr['url_rewrite'][$k] = ''; } } - if(empty($arr['url_rewrite']['cate_as'])) return json(['code'=>-1,'msg'=>'分类不能为空']); + // if(empty($arr['url_rewrite']['cate_as'])) return json(['code'=>-1,'msg'=>'分类不能为空']); if(!array_key_exists('url_rewrite',config('taoler'))){ $result = SetArr::name('taoler')->add($arr); diff --git a/app/admin/controller/Tag.php b/app/admin/controller/Tag.php index 0e2f4c8..79fa35d 100644 --- a/app/admin/controller/Tag.php +++ b/app/admin/controller/Tag.php @@ -41,7 +41,7 @@ class Tag extends AdminController if(count($tags)) { $arr = ['code'=>0, 'msg'=>'', 'count' => count($tags)]; foreach($tags as $k=>$v) { - $arr['data'][] = ['id'=>$v['id'],'name'=>$v['name'], 'ename'=>$v['ename'],'time'=>$v['create_time']]; + $arr['data'][] = ['id'=>$v['id'],'name'=>$v['name'], 'ename'=>$v['ename'], 'keywords'=>$v['keywords'], 'description'=>$v['description'], 'title'=>$v['title'],'time'=>$v['create_time']]; } } else { $arr = ['code'=>-1, 'msg'=>'没有数据']; @@ -52,7 +52,10 @@ class Tag extends AdminController public function add() { if(Request::isAjax()) { - $data = Request::only(['name','ename']); + $data = Request::only(['name','ename','keywords','description','title']); + // 把,转换为,并去空格->转为数组->去掉空数组->再转化为带,号的字符串 + $data['keywords'] = implode(',',array_filter(explode(',',trim(str_replace(',',',',$data['keywords']))))); + $tagModel = new TagModel; $res = $tagModel->saveTag($data); if($res == true){ @@ -67,13 +70,17 @@ class Tag extends AdminController $tagModel = new TagModel; if(Request::isAjax()) { - $data = Request::only(['name','ename','id']); + $data = Request::only(['name','ename','id','keywords','description','title']); + // 把,转换为,并去空格->转为数组->去掉空数组->再转化为带,号的字符串 + $data['keywords'] = implode(',',array_filter(explode(',',trim(str_replace(',',',',$data['keywords']))))); + $res =$tagModel::update($data); if($res == true){ return json(['code'=>0,'msg'=>'设置成功']); } } $tag = $tagModel->getTag(input('id')); + View::assign('tag',$tag); return view(); } diff --git a/app/admin/controller/Upgrade.php b/app/admin/controller/Upgrade.php index 3fd6e33..81a1a19 100644 --- a/app/admin/controller/Upgrade.php +++ b/app/admin/controller/Upgrade.php @@ -378,7 +378,7 @@ class Upgrade extends AdminController */ public function database_operation($file) { - $mysqli = new mysqli('localhost','root','root','test'); + $mysqli = new \mysqli('localhost','root','root','test'); if($mysqli->connect_errno) { return json(['code'=>0,'msg'=>'Connect failed:'.$mysqli->connect_error]); diff --git a/app/admin/route/route.php b/app/admin/route/route.php index b298f58..bbac4d4 100644 --- a/app/admin/route/route.php +++ b/app/admin/route/route.php @@ -21,6 +21,4 @@ Route::get("$detail_as$", '\app\index\controller\Article@detail') ]) ->name('article_detail'); -//tag - diff --git a/app/admin/view/forum/edit.html b/app/admin/view/forum/edit.html index 12b4195..a6940b3 100644 --- a/app/admin/view/forum/edit.html +++ b/app/admin/view/forum/edit.html @@ -104,14 +104,14 @@ var artId = "{$article.id}"; var addTags = xmSelect.render({ el: '#tag', name: 'tagid', - layVerify: 'required', + layVerify: '', layVerType: 'msg', paging: true, pageSize: 5, data: [] }); //2.动态赋值 -$.get("{:url('tag/getArtTag')}",{id:artId},function(res){ +$.get("{:url('tag/getArticleTag')}",{id:artId},function(res){ if(res.code == 0){ addTags.setValue( res.data diff --git a/app/admin/view/set/system/website.html b/app/admin/view/set/system/website.html index c27ba2e..f9fe0af 100644 --- a/app/admin/view/set/system/website.html +++ b/app/admin/view/set/system/website.html @@ -339,16 +339,16 @@
- +
-
如:www.aieok.com
+
访问则为www.aieok.com
- +
-
如:admin.aieok.com
+
访问则为admin.aieok.com
@@ -388,14 +388,14 @@
- +
如:www.aieok.com/article/1.html
- +
diff --git a/app/admin/view/tag/add.html b/app/admin/view/tag/add.html index 3377f77..62e34f6 100644 --- a/app/admin/view/tag/add.html +++ b/app/admin/view/tag/add.html @@ -25,6 +25,24 @@
+
+ +
+ +
+
+
+ +
+ +
+
+
+ +
+ +
+
diff --git a/app/admin/view/tag/edit.html b/app/admin/view/tag/edit.html index db41135..6dcb958 100644 --- a/app/admin/view/tag/edit.html +++ b/app/admin/view/tag/edit.html @@ -23,6 +23,24 @@
+
+ +
+ +
+
+
+ +
+ +
+
+
+ +
+ +
+
diff --git a/app/admin/view/tag/index.html b/app/admin/view/tag/index.html index 1c329e6..212e5b4 100644 --- a/app/admin/view/tag/index.html +++ b/app/admin/view/tag/index.html @@ -56,8 +56,11 @@ ,page: true //开启分页 ,cols: [[ //表头 {type: 'numbers', fixed: 'left'} - ,{field: 'name', title: '名称', width:200} - ,{field: 'ename', title: '别名', minWidth:300} + ,{field: 'name', title: '名称', width:100} + ,{field: 'ename', title: '别名', width:100} + ,{field: 'keywords', title: '关键词', width:150} + ,{field: 'description', title: '摘要', minWidth:300} + ,{field: 'title', title: 'seo标题', width:200} ,{field: 'time', title: '时间', minWidth:100} ,{fixed: 'right', title:'操作', toolbar: '#barDemo', width:150} ]] @@ -105,7 +108,7 @@ title: '编辑Tag', content: 'edit.html?id='+ id, maxmin: true, - area : ['400px' , '300px'], + area : ['450px' , '80%'], btn: ['确定', '取消'], yes: function(index, layero){ var iframeWindow = window['layui-layer-iframe'+ index] @@ -144,7 +147,7 @@ title: '添加Tag', content: 'add.html', maxmin: true, - area : ['400px' , '300px'], + area : ['450px' , '80%'], btn: ['确定', '取消'], yes: function(index, layero){ var iframeWindow = window['layui-layer-iframe'+ index] diff --git a/app/common/model/Article.php b/app/common/model/Article.php index d6c4e46..eb21d9d 100644 --- a/app/common/model/Article.php +++ b/app/common/model/Article.php @@ -324,7 +324,13 @@ class Article extends Model } } - // 标签列表 + /** + * 标签列表 + * + * @param [type] $tagId 标签id + * @param [type] $limit 输出数量 + * @return void + */ public function getAllTags($tagId) { $allTags = $this::hasWhere('taglist',['tag_id'=>$tagId]) @@ -335,7 +341,6 @@ class Article extends Model }]) ->where(['status'=>1]) ->order('pv desc') - ->limit(50) ->append(['url']) ->select() ->toArray(); @@ -343,6 +348,60 @@ class Article extends Model return $allTags; } + /** + * 相关文章(标签) + * 相同标签文章,不包含自己 + * @param [type] $tagId + * @param [type] $limit + * @return void + */ + public function getRelationTags($tagId,$id,$limit) + { + $allTags = $this::hasWhere('taglist',['tag_id'=>$tagId]) + ->with(['user' => function($query){ + $query->field('id,name,nickname,user_img,area_id,vip'); + },'cate' => function($query){ + $query->where('delete_time',0)->field('id,catename,ename'); + }]) + ->where(['status'=>1]) + // ->where('article.id', '<>', $id) + ->order('pv desc') + ->limit($limit) + ->append(['url']) + ->select() + ->toArray(); + + return $allTags; + } + + /** + * 上下文 + * + * @param [type] $id 当前文章ID + * @param [type] $cid 当前分类ID + * @return void + */ + public function getPrevNextArticle($id,$cid) + { + //上一篇 + $previous = $this::field('id,title,cate_id') + ->where([ + ['id', '<', $id], + ['cate_id', '=', $cid], + ['status', '=',1] + ])->order('id desc')->limit(1)->append(['url'])->select()->toArray(); + + //下一篇 + $next = $this::field('id,title,cate_id') + ->where([ + ['id', '>', $id], + ['cate_id', '=', $cid], + ['status', '=',1] + ])->limit(1)->append(['url'])->select()->toArray(); + + return ['previous' => $previous, 'next' => $next]; + } + // 获取url public function getUrlAttr($value,$data) { diff --git a/app/common/model/Comment.php b/app/common/model/Comment.php index 32abcf2..4a61339 100644 --- a/app/common/model/Comment.php +++ b/app/common/model/Comment.php @@ -2,7 +2,7 @@ /* * @Author: TaoLer * @Date: 2021-12-06 16:04:50 - * @LastEditTime: 2022-08-15 13:37:58 + * @LastEditTime: 2022-08-16 12:18:29 * @LastEditors: TaoLer * @Description: 评论模型 * @FilePath: \TaoLer\app\common\model\Comment.php @@ -83,9 +83,9 @@ class Comment extends Model public function getUserCommentList(int $id) { $userCommList = $this::field('id,user_id,create_time,delete_time,article_id,content') ->with(['article' => function(\think\model\Relation $query){ - $query->withField('id,title,cate_id,delete_time')->where(['status' => 1,'delete_time' => 0]); + $query->withField('id,title,cate_id,delete_time')->where(['status' => 1]); }]) - ->where(['user_id' => $id,'status' => 1,'delete_time'=>0]) + ->where(['user_id' => $id,'status' => 1]) //->append(['url']) ->order(['create_time' => 'desc']) //->cache(3600) diff --git a/app/common/model/MessageTo.php b/app/common/model/MessageTo.php index 3adda36..cf4738c 100644 --- a/app/common/model/MessageTo.php +++ b/app/common/model/MessageTo.php @@ -2,17 +2,16 @@ /* * @Author: TaoLer <317927823@qq.com> * @Date: 2021-12-06 16:04:50 - * @LastEditTime: 2022-07-27 21:25:14 + * @LastEditTime: 2022-08-16 12:01:52 * @LastEditors: TaoLer * @Description: 优化版 - * @FilePath: \github\TaoLer\app\common\model\MessageTo.php + * @FilePath: \TaoLer\app\common\model\MessageTo.php * Copyright (c) 2020~2022 https://www.aieok.com All rights reserved. */ namespace app\common\model; use think\Model; use think\model\concern\SoftDelete; -use think\Db; class MessageTo extends Model { @@ -34,9 +33,11 @@ class MessageTo extends Model //得到消息数 public function getMsgNum($id) { - $msg = $this::field('id')->where(['receve_id'=>$id,'is_read'=>0])->column('id'); - if(!is_null($msg)) { - return count($msg); + $msg = $this::where(['receve_id'=>$id,'is_read'=>0])->column('id'); + if($num = count($msg)) { + return $num; + } else { + return 0; } } diff --git a/app/common/model/Sign.php b/app/common/model/Sign.php index e7bb132..7e6319a 100644 --- a/app/common/model/Sign.php +++ b/app/common/model/Sign.php @@ -2,18 +2,15 @@ /* * @Author: TaoLer <317927823@qq.com> * @Date: 2021-12-06 16:04:50 - * @LastEditTime: 2022-08-14 07:32:32 + * @LastEditTime: 2022-08-16 12:20:49 * @LastEditors: TaoLer * @Description: 签到模型 - * @FilePath: \github\TaoLer\app\common\model\Sign.php + * @FilePath: \TaoLer\app\common\model\Sign.php * Copyright (c) 2020~2022 https://www.aieok.com All rights reserved. */ namespace app\common\model; use think\Model; -use think\model\concern\SoftDelete; -use think\Db; -use think\facade\Session; class Sign extends Model { diff --git a/app/common/model/Slider.php b/app/common/model/Slider.php index 201c0a2..02c5713 100644 --- a/app/common/model/Slider.php +++ b/app/common/model/Slider.php @@ -2,7 +2,7 @@ /* * @Author: TaoLer * @Date: 2021-12-06 16:04:50 - * @LastEditTime: 2022-06-28 13:54:55 + * @LastEditTime: 2022-08-16 12:21:14 * @LastEditors: TaoLer * @Description: 链接设置 * @FilePath: \TaoLer\app\common\model\Slider.php @@ -43,7 +43,7 @@ class Slider extends Model { $sliders = Cache::get('slider'.$type); if(!$sliders){ - $sliders = $this::where(['slid_status'=>1,'delete_time'=>0,'slid_type'=>$type])->whereTime('slid_over','>=',time())->select()->toArray(); + $sliders = $this::where(['slid_status'=>1,'slid_type'=>$type])->whereTime('slid_over','>=',time())->select()->toArray(); Cache::tag('tagSlider'.$type)->set('slider'.$type,$sliders,3600); } return $sliders; diff --git a/app/index/controller/Article.php b/app/index/controller/Article.php index 4466c44..bc6c957 100644 --- a/app/index/controller/Article.php +++ b/app/index/controller/Article.php @@ -91,22 +91,29 @@ class Article extends BaseController //赞列表 $userZanList = []; $userZan = UserZan::where(['article_id'=>$id,'type'=>1])->select(); - foreach($userZan as $v){ - $userZanList[] = ['userImg'=>$v->user->user_img,'name'=>$v->user->name]; + if(count($userZan)) { + foreach($userZan as $v){ + $userZanList[] = ['userImg'=>$v->user->user_img,'name'=>$v->user->name]; + } } + // 设置内容的tag内链 $artDetail['content'] = $this->setArtTagLink($artDetail['content']); // 标签 $tags = []; + $relationArticle = []; $artTags = Db::name('taglist')->where('article_id',$id)->select(); - // halt($artTags); - foreach($artTags as $v) { - $tag = Db::name('tag')->find($v['tag_id']); - $tags[] = ['name'=>$tag['name'],'url'=> (string) url('tag_list',['ename'=>$tag['ename']])]; - } - + if(count($artTags)) { + foreach($artTags as $v) { + $tag = Db::name('tag')->find($v['tag_id']); + if(!is_null($tag)) + $tags[] = ['name'=>$tag['name'],'url'=> (string) url('tag_list',['ename'=>$tag['ename']])]; + } + //相关帖子 + $relationArticle = $article->getRelationTags($artTags[0]['tag_id'],$id,5); + } $tpl = Db::name('cate')->where('id', $artDetail['cate_id'])->value('detpl'); $download = $artDetail['upzip'] ? download($artDetail['upzip'],'file') : ''; @@ -115,6 +122,19 @@ class Article extends BaseController Db::name('article')->where('id',$id)->inc('pv')->update(); $pv = Db::name('article')->field('pv')->where('id',$id)->value('pv'); + //上一篇下一篇 + $upDownArt = $article->getPrevNextArticle($id,$artDetail['cate_id']); + if(empty($upDownArt['previous'][0])) { + $previous = '前面已经没有了!'; + } else { + $previous = ''; + } + if(empty($upDownArt['next'][0])) { + $next = '已经是最新的内容了!'; + } else { + $next = ''; + } + //评论 $comments = $this->getComments($id, $page); //最新评论时间 @@ -128,7 +148,7 @@ class Article extends BaseController //分类钻展赞助 $ad_comm = $ad->getSliderList(7); //push - $push_js = Db::name('push_jscode')->where(['delete_time'=>0])->cache(true)->select(); + $push_js = Db::name('push_jscode')->where(['delete_time'=>0,'type'=>1])->cache(true)->select(); View::assign([ 'article' => $artDetail, @@ -137,6 +157,9 @@ class Article extends BaseController 'ad_art' => $ad_artImg, 'ad_comm' => $ad_comm, 'tags' => $tags, + 'relationArticle' => $relationArticle, + 'previous' => $previous, + 'next' => $next, 'page' => $page, 'comments' => $comments, 'push_js' => $push_js, @@ -310,7 +333,6 @@ class Article extends BaseController if(Request::isAjax()){ $data = Request::only(['id','cate_id','title','title_color','user_id','content','upzip','keywords','description','captcha']); $tagId = input('tagid'); - // 验证码 if(Config::get('taoler.config.post_captcha') == 1) @@ -372,20 +394,8 @@ class Article extends BaseController return $editRes; } } - // 查询标签 - $tag = $article->tags; - $tags = []; - if(!is_null($tag)) { - $attr = explode(',',$tag); - foreach($attr as $key => $v){ - if ($v !='') { - $tags[] = $v; - } - } - - } - View::assign(['article'=>$article,'tags'=>$tags,'jspage'=>'jie']); + View::assign(['article'=>$article,'jspage'=>'jie']); // 编辑多模板支持 $tpl = Db::name('cate')->where('id', $article['cate_id'])->value('detpl'); $appName = $this->app->http->getName(); @@ -471,7 +481,7 @@ class Article extends BaseController */ public function keywords() { - $data = Request::only(['keywords','flag']); + $data = Request::only(['flag','keywords','content']); return $this->setKeywords($data); } diff --git a/app/index/controller/Message.php b/app/index/controller/Message.php index 8a56c8f..d4ea961 100644 --- a/app/index/controller/Message.php +++ b/app/index/controller/Message.php @@ -2,10 +2,10 @@ /* * @Author: TaoLer <317927823@qq.com> * @Date: 2021-12-06 16:04:50 - * @LastEditTime: 2022-07-27 21:29:43 + * @LastEditTime: 2022-08-16 12:12:11 * @LastEditors: TaoLer * @Description: 优化版 - * @FilePath: \github\TaoLer\app\index\controller\Message.php + * @FilePath: \TaoLer\app\index\controller\Message.php * Copyright (c) 2020~2022 https://www.aieok.com All rights reserved. */ namespace app\index\controller; @@ -25,10 +25,10 @@ class Message extends BaseController { $messgeto = new MessageTo(); $num = $messgeto->getMsgNum($this->uid); - if(!is_null($num)){ + if($num){ $res = ['status' =>0,'count' => $num, 'msg' => 'ok']; } else { - $res = ['status' =>-1,'count' => 0, 'msg' => 'message error']; + $res = ['status' =>0,'count' => 0, 'msg' => 'no message']; } return json($res); } @@ -37,18 +37,18 @@ class Message extends BaseController public function find() { $msg = MessageApi::receveMsg($this->uid); - $count = $msg->count(); + + $count = count($msg); $res = []; if($count){ $res = ['status'=>0,'msg'=>'','count'=>$count]; foreach ($msg as $k => $v){ - $data = ['id'=>$v['id'],'name'=>$v['name'],'title'=>$v['title'],'content'=>$v['content'],'time'=>date("Y-m-d H:i",$v['create_time']),'link'=>$v['link'],'read'=>$v['is_read'] ? '已读':'未读','type'=>$v['message_type']]; - $res['rows'][] = $data; + $res['rows'][] = ['id'=>$v['id'],'name'=>$v['name'],'title'=>$v['title'],'content'=>$v['content'],'time'=>date("Y-m-d H:i",$v['create_time']),'link'=>$v['link'],'read'=>$v['is_read'] ? '已读':'未读','type'=>$v['message_type']]; + } } else { - $res = ['status'=>-1,'msg'=>'message find error','rows'=>''];; + $res = ['status'=>0,'msg'=>'message find error','rows'=>''];; } - //var_dump($res); return json($res); } @@ -57,9 +57,12 @@ class Message extends BaseController { $id =input('id'); if($id){ - $msg = MessageTo::field('id,message_id')->with(['messages' => function($query){ - $query->where('delete_time',0)->field('id,content'); - }])->where('id',$id)->find(); + $msg = MessageTo::field('id,message_id') + ->with(['messages' => function($query){ + $query->field('id,content'); + }]) + ->where('id',$id) + ->find(); //改变读状态 if($msg->is_read == 0){ $result = $msg->update(['id'=>$id,'is_read'=>1]); diff --git a/app/index/controller/Tag.php b/app/index/controller/Tag.php index 48db8bb..34d35ac 100644 --- a/app/index/controller/Tag.php +++ b/app/index/controller/Tag.php @@ -31,9 +31,9 @@ class Tag extends BaseController { // $tagEname = Request::param('ename'); - $tagId = Db::name('tag')->where('ename',$tagEname)->value('id'); + $tag = Db::name('tag')->where('ename',$tagEname)->find(); - $artList = Article::getAllTags($tagId); + $artList = Article::getAllTags($tag['id']); $slider = new Slider(); //首页右栏 $ad_comm = $slider->getSliderList(2); @@ -41,7 +41,7 @@ class Tag extends BaseController $artHot = Article::getArtHot(10); $assign = [ - 'tag'=>$tagEname, + 'tag'=>$tag, 'artList'=>$artList, 'ad_comm'=>$ad_comm, 'artHot'=>$artHot, diff --git a/app/index/lang/zh-cn.php b/app/index/lang/zh-cn.php index 55269e1..a9d45f1 100644 --- a/app/index/lang/zh-cn.php +++ b/app/index/lang/zh-cn.php @@ -88,6 +88,8 @@ return [ 'special column' => '选择专栏', 'tags' => '标签', 'add tags' => '添加标签', + 'add keywords' => '添加关键词', + 'description' => '描述', //Sign in/up 'username' => '用户', @@ -107,7 +109,7 @@ return [ 'register now' => '立即注册', 'mail/username/mobile' => '邮箱/用户名/手机号', '6-16 characters' => '6-16 字符', - 'strong type encryption' => '经过强类型加密', + 'strong type encryption' => '强类型加密', 'it cannot be changed' => '不能更改', 'the only way to get back your password' => '找回密码唯一途径', 'please input the password' => '请输入密码', diff --git a/app/install/data/taoler.sql b/app/install/data/taoler.sql index c3e25c9..c3e5baf 100644 --- a/app/install/data/taoler.sql +++ b/app/install/data/taoler.sql @@ -489,7 +489,7 @@ CREATE TABLE `tao_system` ( `uptype` varchar(255) NOT NULL DEFAULT '0' COMMENT '上传文件类型', `copyright` varchar(100) NOT NULL DEFAULT '' COMMENT '版权', `keywords` tinytext NOT NULL COMMENT '网站关键字', - `descript` tinytext NOT NULL COMMENT '网站描述', + `descript` text NOT NULL COMMENT '网站描述', `state` tinytext CHARACTER SET utf8 COLLATE utf8_general_ci COMMENT '网站声明', `is_open` enum('0','1') NOT NULL DEFAULT '1' COMMENT '是否开启站点1开启0关闭', `is_comment` enum('0','1') NOT NULL DEFAULT '1' COMMENT '是否开启评论1开启0关闭', @@ -519,6 +519,9 @@ CREATE TABLE `tao_tag` ( `id` int(10) NOT NULL AUTO_INCREMENT COMMENT 'tag自增id', `name` varchar(20) NOT NULL COMMENT '名称', `ename` varchar(20) NOT NULL COMMENT '英文名', + `keywords` varchar(255) NOT NULL COMMENT '关键词', + `description` text NOT NULL COMMENT '摘要', + `title` varchar(100) NOT NULL COMMENT '标签', `create_time` int NOT NULL COMMENT '创建时间', `update_time` int NOT NULL COMMENT '更新时间', PRIMARY KEY (`id`), diff --git a/extend/taoler/com/Message.php b/extend/taoler/com/Message.php index 7d963d3..3665ae5 100644 --- a/extend/taoler/com/Message.php +++ b/extend/taoler/com/Message.php @@ -1,4 +1,13 @@ + * @Date: 2021-12-06 16:04:50 + * @LastEditTime: 2022-08-16 12:09:28 + * @LastEditors: TaoLer + * @Description: 优化版 + * @FilePath: \TaoLer\extend\taoler\com\Message.php + * Copyright (c) 2020~2022 https://www.aieok.com All rights reserved. + */ namespace taoler\com; @@ -45,7 +54,7 @@ class Message */ public static function receveMsg($uid) { - $msg = Db::name('message_to') + return Db::name('message_to') ->alias('t') ->join('message m','t.message_id = m.id' ) ->join('user u','t.send_id = u.id') @@ -53,8 +62,7 @@ class Message ->where('t.receve_id',$uid) ->where(['t.delete_time'=>0]) ->order(['t.is_read'=>'asc','t.create_time'=>'desc']) - ->select(); - return $msg; + ->select()->toArray(); } /** @@ -67,10 +75,10 @@ class Message public static function insertMsg(int $uid) { //得到所有系统消息 - $sysmsg = MessageModel::where(['type'=>0,'delete_time'=>0])->select(); + $sysmsg = MessageModel::where(['type'=>0])->select(); foreach($sysmsg as $smg){ //检验通知ID是否被写入个人收件箱 - $msgId = Db::name('message_to')->where('message_id',$smg['id'])->find(); + $msgId = Db::name('message_to')->where(['message_id'=>$smg['id'],'delete_time'=>0])->find(); if(!$msgId){ $result = MessageTo::create(['send_id'=>$smg['user_id'],'receve_id'=>$uid,'message_id'=>$smg['id'],'message_type'=>$smg['type']]); } diff --git a/view/taoler/index/article/add.html b/view/taoler/index/article/add.html index 85916bd..d636374 100644 --- a/view/taoler/index/article/add.html +++ b/view/taoler/index/article/add.html @@ -44,7 +44,7 @@
{/if} -
+
- +
- +
-
- + {//描述} +
+
- +
{//关键词} -
- +
+
- +
{//tag} @@ -154,19 +147,23 @@
-{include file="public/menu" /} {/block} +{include file="public/menu" /} +{/block} {block name="script"} {:hook('taonyeditor')}