2020-01-01 13:17:19 +08:00
|
|
|
|
<?php
|
2022-08-02 21:13:36 +08:00
|
|
|
|
|
2020-01-01 13:17:19 +08:00
|
|
|
|
namespace app\index\controller;
|
|
|
|
|
|
|
|
|
|
use app\common\controller\BaseController;
|
2023-05-05 12:03:45 +08:00
|
|
|
|
use think\App;
|
2020-01-01 13:17:19 +08:00
|
|
|
|
use think\facade\View;
|
|
|
|
|
use think\facade\Request;
|
|
|
|
|
use think\facade\Db;
|
2020-03-11 11:33:17 +08:00
|
|
|
|
use think\facade\Cache;
|
2023-05-05 12:03:45 +08:00
|
|
|
|
use think\facade\Session;
|
2020-04-29 18:03:15 +08:00
|
|
|
|
use think\facade\Config;
|
2022-08-16 15:21:08 +08:00
|
|
|
|
use app\common\model\Cate;
|
2020-01-01 13:17:19 +08:00
|
|
|
|
use app\common\model\Comment;
|
2022-08-02 21:13:36 +08:00
|
|
|
|
use app\common\model\UserZan;
|
2022-08-16 15:29:04 +08:00
|
|
|
|
use app\common\model\PushJscode;
|
2020-03-29 19:57:18 +08:00
|
|
|
|
use taoler\com\Message;
|
2020-11-25 15:29:48 +08:00
|
|
|
|
use app\common\lib\Msgres;
|
2022-08-16 15:21:08 +08:00
|
|
|
|
|
2020-01-01 13:17:19 +08:00
|
|
|
|
class Article extends BaseController
|
|
|
|
|
{
|
|
|
|
|
protected $middleware = [
|
2020-12-14 15:04:38 +08:00
|
|
|
|
'logincheck' => ['except' => ['cate','detail','download'] ],
|
2020-01-01 13:17:19 +08:00
|
|
|
|
];
|
2023-05-05 12:03:45 +08:00
|
|
|
|
|
|
|
|
|
protected $model;
|
|
|
|
|
|
|
|
|
|
public function __construct(App $app)
|
|
|
|
|
{
|
|
|
|
|
parent::__construct($app);
|
2023-05-05 12:07:11 +08:00
|
|
|
|
$this->model = new \app\common\model\Article();
|
2023-05-05 12:03:45 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//文章分类
|
2021-03-20 16:32:23 +08:00
|
|
|
|
public function cate()
|
|
|
|
|
{
|
2022-08-16 15:21:08 +08:00
|
|
|
|
$cate = new Cate();
|
2022-08-16 15:29:04 +08:00
|
|
|
|
//动态参数
|
|
|
|
|
$ename = Request::param('ename');
|
|
|
|
|
$type = Request::param('type','all');
|
|
|
|
|
$page = Request::param('page',1);
|
|
|
|
|
|
|
|
|
|
// 分类信息
|
2022-08-16 15:21:08 +08:00
|
|
|
|
$cateInfo = $cate->getCateInfo($ename);
|
|
|
|
|
|
2022-01-07 14:45:35 +08:00
|
|
|
|
//分页url
|
|
|
|
|
$url = url('cate_page',['ename'=>$ename,'type'=>$type,'page'=>$page]);
|
|
|
|
|
//返回最后/前面的字符串
|
|
|
|
|
$path = substr($url,0,strrpos($url,"/"));
|
2022-01-07 14:43:42 +08:00
|
|
|
|
|
2020-11-27 16:25:08 +08:00
|
|
|
|
//分类列表
|
2023-05-05 12:07:11 +08:00
|
|
|
|
$artList = $this->model->getCateList($ename,$type,$page);
|
2020-01-01 13:17:19 +08:00
|
|
|
|
// 热议文章
|
2023-05-05 12:07:11 +08:00
|
|
|
|
$artHot = $this->model->getArtHot(10);
|
|
|
|
|
|
2022-08-02 21:13:36 +08:00
|
|
|
|
|
2022-08-16 15:29:04 +08:00
|
|
|
|
$assignArr = [
|
2022-08-16 15:21:08 +08:00
|
|
|
|
'ename'=>$ename,
|
|
|
|
|
'cateinfo'=> $cateInfo,
|
|
|
|
|
'type'=>$type,
|
|
|
|
|
'artList'=>$artList,
|
|
|
|
|
'artHot'=>$artHot,
|
|
|
|
|
'path'=>$path,
|
|
|
|
|
'jspage'=>'jie'
|
2022-08-16 15:29:04 +08:00
|
|
|
|
];
|
|
|
|
|
View::assign($assignArr);
|
|
|
|
|
|
|
|
|
|
$cateView = is_null($cateInfo) ? 'article/cate' : 'article/' . $cateInfo->detpl . '/cate';
|
|
|
|
|
return View::fetch($cateView);
|
2020-01-01 13:17:19 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//文章详情页
|
2022-01-07 14:45:35 +08:00
|
|
|
|
public function detail()
|
2020-01-01 13:17:19 +08:00
|
|
|
|
{
|
2022-01-07 14:43:42 +08:00
|
|
|
|
$id = input('id');
|
2022-08-16 15:29:04 +08:00
|
|
|
|
$page = input('page',1);
|
2022-01-07 14:43:42 +08:00
|
|
|
|
//输出内容
|
2023-05-05 12:03:45 +08:00
|
|
|
|
$artDetail = $this->model->getArtDetail($id);
|
2023-05-05 12:06:07 +08:00
|
|
|
|
if($artDetail->read_type == 1 && session('art_pass_'.$id) != $artDetail->art_pass) {
|
|
|
|
|
$artDetail->content = '本文已加密!请输入正确密码查看!';
|
2023-05-05 12:03:45 +08:00
|
|
|
|
}
|
|
|
|
|
|
2022-08-16 15:29:04 +08:00
|
|
|
|
if(is_null($artDetail)){
|
|
|
|
|
// 抛出 HTTP 异常
|
|
|
|
|
throw new \think\exception\HttpException(404, '无内容');
|
|
|
|
|
}
|
2022-08-02 21:13:36 +08:00
|
|
|
|
//用户个人tag标签
|
2023-05-05 12:06:07 +08:00
|
|
|
|
$userTags = $this->model->where(['user_id' => $artDetail['user_id'],'status'=>1])->where('keywords','<>','')->column('keywords');
|
2022-08-02 21:13:36 +08:00
|
|
|
|
//转换为字符串
|
|
|
|
|
$tagStr = implode(",",$userTags);
|
|
|
|
|
//转换为数组并去重
|
|
|
|
|
$tagArr = array_unique(explode(",",$tagStr));
|
|
|
|
|
$userTagCount = count($tagArr);
|
|
|
|
|
|
|
|
|
|
//赞列表
|
|
|
|
|
$userZanList = [];
|
|
|
|
|
$userZan = UserZan::where(['article_id'=>$id,'type'=>1])->select();
|
2022-09-07 15:20:00 +08:00
|
|
|
|
if(count($userZan)) {
|
|
|
|
|
foreach($userZan as $v){
|
|
|
|
|
$userZanList[] = ['userImg'=>$v->user->user_img,'name'=>$v->user->name];
|
|
|
|
|
}
|
2022-08-02 21:13:36 +08:00
|
|
|
|
}
|
2023-05-05 12:06:07 +08:00
|
|
|
|
|
2022-08-02 21:13:36 +08:00
|
|
|
|
// 设置内容的tag内链
|
2023-05-05 12:06:07 +08:00
|
|
|
|
$artDetail->content = $this->setArtTagLink($artDetail->content);
|
2022-08-02 20:47:28 +08:00
|
|
|
|
|
2022-08-16 15:29:04 +08:00
|
|
|
|
// 标签
|
|
|
|
|
$tags = [];
|
2022-09-07 15:20:00 +08:00
|
|
|
|
$relationArticle = [];
|
2022-08-16 15:29:04 +08:00
|
|
|
|
$artTags = Db::name('taglist')->where('article_id',$id)->select();
|
2022-09-07 15:20:00 +08:00
|
|
|
|
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']])];
|
|
|
|
|
}
|
|
|
|
|
//相关帖子
|
2023-05-05 12:06:07 +08:00
|
|
|
|
$relationArticle = $this->model->getRelationTags($artTags[0]['tag_id'],$id,5);
|
2022-09-07 15:20:00 +08:00
|
|
|
|
}
|
2022-08-02 21:13:36 +08:00
|
|
|
|
|
|
|
|
|
$tpl = Db::name('cate')->where('id', $artDetail['cate_id'])->value('detpl');
|
2022-01-07 14:43:42 +08:00
|
|
|
|
$download = $artDetail['upzip'] ? download($artDetail['upzip'],'file') : '';
|
|
|
|
|
|
|
|
|
|
//浏览pv
|
|
|
|
|
Db::name('article')->where('id',$id)->inc('pv')->update();
|
2020-03-13 22:59:38 +08:00
|
|
|
|
$pv = Db::name('article')->field('pv')->where('id',$id)->value('pv');
|
2023-05-05 12:06:07 +08:00
|
|
|
|
$artDetail->pv = $pv;
|
2022-01-07 14:43:42 +08:00
|
|
|
|
|
2022-09-07 15:20:00 +08:00
|
|
|
|
//上一篇下一篇
|
2023-05-05 12:06:07 +08:00
|
|
|
|
$upDownArt = $this->model->getPrevNextArticle($id,$artDetail['cate_id']);
|
2022-09-07 15:20:00 +08:00
|
|
|
|
if(empty($upDownArt['previous'][0])) {
|
|
|
|
|
$previous = '前面已经没有了!';
|
|
|
|
|
} else {
|
|
|
|
|
$previous = '<a href="' . $upDownArt['previous'][0]['url'] . '" rel="prev">' . $upDownArt['previous'][0]['title'] . '</a>';
|
|
|
|
|
}
|
|
|
|
|
if(empty($upDownArt['next'][0])) {
|
|
|
|
|
$next = '已经是最新的内容了!';
|
|
|
|
|
} else {
|
|
|
|
|
$next = '<a href="' . $upDownArt['next'][0]['url'] . '" rel="prev">' . $upDownArt['next'][0]['title'] . '</a>';
|
|
|
|
|
}
|
|
|
|
|
|
2022-01-07 14:43:42 +08:00
|
|
|
|
//评论
|
2022-01-07 14:45:35 +08:00
|
|
|
|
$comments = $this->getComments($id, $page);
|
2022-08-02 21:13:36 +08:00
|
|
|
|
//最新评论时间
|
|
|
|
|
$lrDate_time = Db::name('comment')->where('article_id', $id)->max('update_time',false) ?? time();
|
2020-01-01 13:17:19 +08:00
|
|
|
|
// 热议文章
|
2023-05-05 12:06:07 +08:00
|
|
|
|
$artHot = $this->model->getArtHot(10);
|
2022-08-02 21:13:36 +08:00
|
|
|
|
//push
|
2022-09-07 15:20:00 +08:00
|
|
|
|
$push_js = Db::name('push_jscode')->where(['delete_time'=>0,'type'=>1])->cache(true)->select();
|
2023-05-05 12:00:22 +08:00
|
|
|
|
|
2022-08-02 20:47:28 +08:00
|
|
|
|
View::assign([
|
|
|
|
|
'article' => $artDetail,
|
|
|
|
|
'pv' => $pv,
|
|
|
|
|
'artHot' => $artHot,
|
|
|
|
|
'tags' => $tags,
|
2022-09-07 15:20:00 +08:00
|
|
|
|
'relationArticle' => $relationArticle,
|
|
|
|
|
'previous' => $previous,
|
|
|
|
|
'next' => $next,
|
2022-08-02 20:47:28 +08:00
|
|
|
|
'page' => $page,
|
|
|
|
|
'comments' => $comments,
|
|
|
|
|
'push_js' => $push_js,
|
2022-08-02 21:13:36 +08:00
|
|
|
|
'cid' => $id,
|
|
|
|
|
'lrDate_time' => $lrDate_time,
|
|
|
|
|
'userZanList' => $userZanList,
|
|
|
|
|
'userTagCount'=> $userTagCount,
|
|
|
|
|
'jspage' => 'jie',
|
2023-05-05 12:03:45 +08:00
|
|
|
|
'passJieMi' => session('art_pass_'.$id),
|
2022-08-02 20:47:28 +08:00
|
|
|
|
$download,
|
|
|
|
|
]);
|
2022-08-02 21:13:36 +08:00
|
|
|
|
|
2021-08-03 17:33:48 +08:00
|
|
|
|
return View::fetch('article/'.$tpl.'/detail');
|
2020-01-01 13:17:19 +08:00
|
|
|
|
}
|
|
|
|
|
|
2022-01-07 14:45:35 +08:00
|
|
|
|
//评论内容
|
|
|
|
|
public function getComments($id, $page)
|
|
|
|
|
{
|
|
|
|
|
$comment = new Comment;
|
|
|
|
|
return $comment->getComment($id, $page);
|
|
|
|
|
}
|
|
|
|
|
|
2020-01-01 13:17:19 +08:00
|
|
|
|
//文章评论
|
|
|
|
|
public function comment()
|
|
|
|
|
{
|
2022-08-02 21:13:36 +08:00
|
|
|
|
// 检验发帖是否开放
|
|
|
|
|
if(config('taoler.config.is_reply') == 0 ) return json(['code'=>-1,'msg'=>'抱歉,系统维护中,暂时禁止评论!']);
|
|
|
|
|
|
2020-11-30 17:13:55 +08:00
|
|
|
|
if (Request::isAjax()){
|
|
|
|
|
//获取评论
|
|
|
|
|
$data = Request::only(['content','article_id','user_id']);
|
|
|
|
|
$sendId = $data['user_id'];
|
2021-12-25 13:52:30 +08:00
|
|
|
|
$art = Db::name('article')->field('id,status,is_reply,delete_time')->find($data['article_id']);
|
2022-08-02 21:13:36 +08:00
|
|
|
|
|
2021-12-25 13:52:30 +08:00
|
|
|
|
if($art['delete_time'] != 0 || $art['status'] != 1 || $art['is_reply'] != 1){
|
|
|
|
|
return json(['code'=>-1, 'msg'=>'评论不可用状态']);
|
|
|
|
|
}
|
2020-11-30 17:13:55 +08:00
|
|
|
|
if(empty($data['content'])){
|
2022-08-02 21:13:36 +08:00
|
|
|
|
return json(['code'=>-1, 'msg'=>'评论不能为空!']);
|
2021-06-07 17:53:24 +08:00
|
|
|
|
}
|
2021-10-12 16:46:49 +08:00
|
|
|
|
$superAdmin = Db::name('user')->where('id',$sendId)->value('auth');
|
|
|
|
|
$data['status'] = $superAdmin ? 1 : Config::get('taoler.config.commnets_check');
|
2021-08-04 18:44:24 +08:00
|
|
|
|
$msg = $data['status'] ? '留言成功' : '留言成功,请等待审核';
|
2021-06-07 17:53:24 +08:00
|
|
|
|
|
2020-11-30 17:13:55 +08:00
|
|
|
|
//用户留言存入数据库
|
|
|
|
|
if (Comment::create($data)) {
|
|
|
|
|
//站内信
|
2022-08-02 21:13:36 +08:00
|
|
|
|
$article = Db::name('article')->field('id,title,user_id,cate_id')->where('id',$data['article_id'])->find();
|
2023-03-16 22:30:36 +08:00
|
|
|
|
// 获取分类ename,appname
|
|
|
|
|
$cateName = Db::name('cate')->field('ename,appname')->find($article['cate_id']);
|
2022-08-02 21:13:36 +08:00
|
|
|
|
//$link = (string) url('article_detail',['id'=>$data['article_id']]);
|
2023-03-16 22:30:36 +08:00
|
|
|
|
$link = $this->getRouteUrl($data['article_id'], $cateName['ename'], $cateName['appname']);
|
2020-11-30 17:13:55 +08:00
|
|
|
|
|
|
|
|
|
//评论中回复@user comment
|
|
|
|
|
$preg = "/@([^@\s]*)\s/";
|
|
|
|
|
preg_match($preg,$data['content'],$username);
|
|
|
|
|
if(isset($username[1])){
|
|
|
|
|
$receveId = Db::name('user')->whereOr('nickname', $username[1])->whereOr('name', $username[1])->value('id');
|
|
|
|
|
} else {
|
|
|
|
|
$receveId = $article['user_id'];
|
|
|
|
|
}
|
2023-03-16 22:33:28 +08:00
|
|
|
|
$data = ['title' => $article['title'], 'content' => '评论通知', 'link' => $link, 'user_id' => $sendId, 'type' => 2]; //type=2为评论留言
|
|
|
|
|
Message::sendMsg($sendId, $receveId, $data);
|
|
|
|
|
if(Config::get('taoler.config.email_notice')) hook('mailtohook',[$this->showUser(1)['email'],'评论审核通知','Hi亲爱的管理员:</br>用户'.$this->showUser($this->uid)['name'].'刚刚对 <b>' . $article['title'] . '</b> 发表了评论,请尽快处理。']);
|
2021-08-04 18:44:24 +08:00
|
|
|
|
$res = ['code'=>0, 'msg'=>$msg];
|
2020-03-28 21:41:07 +08:00
|
|
|
|
} else {
|
2020-11-30 17:13:55 +08:00
|
|
|
|
$res = ['code'=>-1, 'msg'=>'留言失败'];
|
2020-03-28 21:41:07 +08:00
|
|
|
|
}
|
2020-11-30 17:13:55 +08:00
|
|
|
|
return json($res);
|
2020-01-01 13:17:19 +08:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2020-11-23 17:03:25 +08:00
|
|
|
|
/**
|
|
|
|
|
* 添加帖子文章
|
|
|
|
|
* @return string|\think\Response|\think\response\Json|void
|
|
|
|
|
*/
|
2020-01-01 13:17:19 +08:00
|
|
|
|
public function add()
|
2020-11-23 17:03:25 +08:00
|
|
|
|
{
|
|
|
|
|
if (Request::isAjax()) {
|
2022-08-02 21:13:36 +08:00
|
|
|
|
// 检验发帖是否开放
|
|
|
|
|
if(config('taoler.config.is_post') == 0 ) return json(['code'=>-1,'msg'=>'抱歉,系统维护中,暂时禁止发帖!']);
|
2022-08-16 15:29:04 +08:00
|
|
|
|
// 数据
|
2023-05-05 12:03:45 +08:00
|
|
|
|
$data = Request::only(['cate_id', 'title', 'title_color','read_type','art_pass', 'content', 'upzip', 'keywords', 'description', 'captcha']);
|
2023-03-16 22:35:59 +08:00
|
|
|
|
$data['user_id'] = $this->uid;
|
2022-08-16 15:29:04 +08:00
|
|
|
|
$tagId = input('tagid');
|
2022-08-02 21:13:36 +08:00
|
|
|
|
|
2022-04-17 17:05:20 +08:00
|
|
|
|
// 验证码
|
2022-08-16 15:29:04 +08:00
|
|
|
|
if(Config::get('taoler.config.post_captcha') == 1) {
|
2022-04-17 17:09:19 +08:00
|
|
|
|
if(!captcha_check($data['captcha'])){
|
2022-04-17 17:05:20 +08:00
|
|
|
|
return json(['code'=>-1,'msg'=> '验证码失败']);
|
|
|
|
|
};
|
|
|
|
|
}
|
2022-04-17 17:09:19 +08:00
|
|
|
|
|
2022-08-16 15:29:04 +08:00
|
|
|
|
// 验证器
|
2022-04-17 17:09:19 +08:00
|
|
|
|
$validate = new \app\common\validate\Article;
|
|
|
|
|
$result = $validate->scene('Artadd')->check($data);
|
2020-11-23 17:03:25 +08:00
|
|
|
|
if (true !== $result) {
|
2020-11-25 15:29:48 +08:00
|
|
|
|
return Msgres::error($validate->getError());
|
2020-11-23 17:03:25 +08:00
|
|
|
|
}
|
2021-06-07 17:53:24 +08:00
|
|
|
|
|
2022-04-17 17:09:19 +08:00
|
|
|
|
// 获取内容图片音视频标识
|
2021-06-07 17:53:24 +08:00
|
|
|
|
$iva= $this->hasIva($data['content']);
|
|
|
|
|
$data = array_merge($data,$iva);
|
2022-08-16 15:21:08 +08:00
|
|
|
|
|
2022-08-16 15:29:04 +08:00
|
|
|
|
// 处理内容
|
2022-08-16 15:21:08 +08:00
|
|
|
|
$data['content'] = $this->downUrlPicsReaplace($data['content']);
|
2022-09-23 11:03:10 +08:00
|
|
|
|
// 把中文,转换为英文,并去空格->转为数组->去掉空数组->再转化为带,号的字符串
|
2022-08-16 15:29:04 +08:00
|
|
|
|
$data['keywords'] = implode(',',array_filter(explode(',',trim(str_replace(',',',',$data['keywords'])))));
|
2023-05-05 12:07:11 +08:00
|
|
|
|
$data['description'] = strip_tags($this->filterEmoji($data['description']));
|
2023-03-16 22:30:36 +08:00
|
|
|
|
// 获取分类ename,appname
|
|
|
|
|
$cateName = Db::name('cate')->field('ename,appname')->find($data['cate_id']);
|
|
|
|
|
|
2023-05-05 12:07:11 +08:00
|
|
|
|
$result = $this->model->add($data);
|
2021-08-04 18:44:24 +08:00
|
|
|
|
if ($result['code'] == 1) {
|
2022-09-23 11:03:10 +08:00
|
|
|
|
// 获取到的最新ID
|
2022-08-16 15:29:04 +08:00
|
|
|
|
$aid = $result['data']['id'];
|
|
|
|
|
//写入taglist表
|
|
|
|
|
$tagArr = [];
|
|
|
|
|
if(isset($tagId)) {
|
|
|
|
|
$tagIdArr = explode(',',$tagId);
|
|
|
|
|
foreach($tagIdArr as $tid) {
|
|
|
|
|
$tagArr[] = ['article_id'=>$aid,'tag_id'=>$tid,'create_time'=>time()];
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
Db::name('taglist')->insertAll($tagArr);
|
|
|
|
|
|
2022-08-02 20:48:54 +08:00
|
|
|
|
// 清除文章tag缓存
|
|
|
|
|
Cache::tag('tagArtDetail')->clear();
|
|
|
|
|
// 发提醒邮件
|
2022-11-20 21:56:09 +08:00
|
|
|
|
if(Config::get('taoler.config.email_notice')) hook('mailtohook',[$this->showUser(1)['email'],'发帖审核通知','Hi亲爱的管理员:</br>用户'.$this->showUser($this->uid)['name'].'刚刚发表了 <b>'.$data['title'].'</b> 新的帖子,请尽快处理。']);
|
2022-08-02 21:13:36 +08:00
|
|
|
|
|
2023-05-05 11:58:42 +08:00
|
|
|
|
$link = $this->getRouteUrl((int)$aid, $cateName['ename']);
|
|
|
|
|
|
|
|
|
|
hook('SeoBaiduPush', ['link'=>$link]); // 推送给百度收录接口
|
2022-08-02 21:13:36 +08:00
|
|
|
|
|
|
|
|
|
$url = $result['data']['status'] ? $link : (string)url('index/');
|
2023-05-05 11:58:42 +08:00
|
|
|
|
return Msgres::success($result['msg'], $url);
|
2020-11-23 17:03:25 +08:00
|
|
|
|
}
|
2023-05-05 11:58:42 +08:00
|
|
|
|
return Msgres::error('add_error');
|
2020-06-19 16:30:27 +08:00
|
|
|
|
}
|
2022-08-02 21:13:36 +08:00
|
|
|
|
|
2022-08-16 15:29:04 +08:00
|
|
|
|
|
|
|
|
|
// 子模块自定义自适应add.html模板
|
2022-09-07 15:21:56 +08:00
|
|
|
|
$cate = Db::name('cate')->field('id,detpl')->where('ename', input('cate'))->find();
|
|
|
|
|
// 子模块下有add.html模板
|
|
|
|
|
if(!empty($cate)) {
|
|
|
|
|
$cid = $cate['id'];
|
|
|
|
|
} else {
|
|
|
|
|
$cate['detpl'] = '';
|
|
|
|
|
$cid = '';
|
|
|
|
|
}
|
|
|
|
|
// 模板路径
|
2022-08-02 21:13:36 +08:00
|
|
|
|
$appName = $this->app->http->getName();
|
|
|
|
|
$viewRoot = root_path() . config('view.view_dir_name') . DIRECTORY_SEPARATOR . $appName . DIRECTORY_SEPARATOR;
|
2022-09-07 15:21:56 +08:00
|
|
|
|
$view = 'article' . DIRECTORY_SEPARATOR . $cate['detpl'] . DIRECTORY_SEPARATOR . 'add.html';
|
2022-08-02 21:13:36 +08:00
|
|
|
|
$vfile = $viewRoot . $view;
|
2022-09-07 15:21:56 +08:00
|
|
|
|
|
|
|
|
|
//子模块下存在add模板则调用,否则调用article/add.html
|
2022-08-02 21:13:36 +08:00
|
|
|
|
$addTpl = is_file($vfile) ? $vfile : 'add';
|
|
|
|
|
|
2022-09-07 15:21:56 +08:00
|
|
|
|
View::assign(['jspage'=>'jie','cid'=>$cid]);
|
2022-08-02 21:13:36 +08:00
|
|
|
|
return View::fetch($addTpl);
|
2020-06-19 16:30:27 +08:00
|
|
|
|
}
|
2020-01-01 13:17:19 +08:00
|
|
|
|
|
2020-11-23 17:03:25 +08:00
|
|
|
|
/**
|
|
|
|
|
* 编辑文章
|
|
|
|
|
* @param $id
|
|
|
|
|
* @return string|\think\Response|\think\response\Json|void
|
|
|
|
|
* @throws \think\db\exception\DataNotFoundException
|
|
|
|
|
* @throws \think\db\exception\DbException
|
|
|
|
|
* @throws \think\db\exception\ModelNotFoundException
|
|
|
|
|
*/
|
2020-02-19 14:59:09 +08:00
|
|
|
|
public function edit($id)
|
2020-01-01 13:17:19 +08:00
|
|
|
|
{
|
2023-05-05 12:07:11 +08:00
|
|
|
|
$article = $this->model->find($id);
|
2022-04-17 17:09:19 +08:00
|
|
|
|
|
2020-01-01 13:17:19 +08:00
|
|
|
|
if(Request::isAjax()){
|
2023-05-05 12:04:46 +08:00
|
|
|
|
$data = Request::only(['id','cate_id','title','title_color','read_type','art_pass','content','upzip','keywords','description','captcha']);
|
2022-08-16 15:29:04 +08:00
|
|
|
|
$tagId = input('tagid');
|
|
|
|
|
|
2022-04-17 17:05:20 +08:00
|
|
|
|
// 验证码
|
|
|
|
|
if(Config::get('taoler.config.post_captcha') == 1)
|
|
|
|
|
{
|
2022-04-17 17:09:19 +08:00
|
|
|
|
if(!captcha_check($data['captcha'])){
|
2022-04-17 17:05:20 +08:00
|
|
|
|
return json(['code'=>-1,'msg'=> '验证码失败']);
|
|
|
|
|
};
|
|
|
|
|
}
|
2022-04-17 17:09:19 +08:00
|
|
|
|
//调用验证器
|
|
|
|
|
$validate = new \app\common\validate\Article();
|
|
|
|
|
$res = $validate->scene('Artadd')->check($data);
|
2020-01-01 13:17:19 +08:00
|
|
|
|
|
2021-05-27 18:09:24 +08:00
|
|
|
|
if(true !== $res){
|
2020-11-25 15:29:48 +08:00
|
|
|
|
return Msgres::error($validate->getError());
|
2020-03-15 22:19:10 +08:00
|
|
|
|
} else {
|
2021-06-07 17:53:24 +08:00
|
|
|
|
//获取内容图片音视频标识
|
|
|
|
|
$iva= $this->hasIva($data['content']);
|
|
|
|
|
$data = array_merge($data,$iva);
|
2022-08-16 15:21:08 +08:00
|
|
|
|
|
|
|
|
|
$data['content'] = $this->downUrlPicsReaplace($data['content']);
|
2022-08-16 15:29:04 +08:00
|
|
|
|
// 把,转换为,并去空格->转为数组->去掉空数组->再转化为带,号的字符串
|
|
|
|
|
$data['keywords'] = implode(',',array_filter(explode(',',trim(str_replace(',',',',$data['keywords'])))));
|
2023-05-05 12:07:11 +08:00
|
|
|
|
$data['description'] = strip_tags($this->filterEmoji($data['description']));
|
2022-08-16 15:21:08 +08:00
|
|
|
|
|
2020-01-01 13:17:19 +08:00
|
|
|
|
$result = $article->edit($data);
|
|
|
|
|
if($result == 1) {
|
2022-08-16 15:29:04 +08:00
|
|
|
|
//处理标签
|
|
|
|
|
$artTags = Db::name('taglist')->where('article_id',$id)->column('tag_id','id');
|
|
|
|
|
if(isset($tagId)) {
|
|
|
|
|
$tagIdArr = explode(',',$tagId);
|
|
|
|
|
foreach($artTags as $aid => $tid) {
|
|
|
|
|
if(!in_array($tid,$tagIdArr)){
|
|
|
|
|
//删除被取消的tag
|
|
|
|
|
Db::name('taglist')->delete($aid);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
//查询保留的标签
|
|
|
|
|
$artTags = Db::name('taglist')->where('article_id',$id)->column('tag_id');
|
|
|
|
|
$tagArr = [];
|
|
|
|
|
foreach($tagIdArr as $tid) {
|
|
|
|
|
if(!in_array($tid, $artTags)){
|
|
|
|
|
//新标签
|
|
|
|
|
$tagArr[] = ['article_id'=>$data['id'],'tag_id'=>$tid,'create_time'=>time()];
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
//更新新标签
|
|
|
|
|
Db::name('taglist')->insertAll($tagArr);
|
|
|
|
|
}
|
|
|
|
|
|
2020-11-23 17:03:25 +08:00
|
|
|
|
//删除原有缓存显示编辑后内容
|
2020-04-24 15:07:26 +08:00
|
|
|
|
Cache::delete('article_'.$id);
|
2023-05-05 12:03:45 +08:00
|
|
|
|
Session::delete('art_pass_'.$id);
|
|
|
|
|
|
2023-05-05 11:58:42 +08:00
|
|
|
|
$link = $this->getRouteUrl((int) $id, $article->cate->ename);
|
|
|
|
|
|
|
|
|
|
hook('SeoBaiduPush', ['link'=>$link]); // 推送给百度收录接口
|
|
|
|
|
return Msgres::success('edit_success',$link);
|
2020-01-01 13:17:19 +08:00
|
|
|
|
}
|
2023-05-05 11:58:42 +08:00
|
|
|
|
return Msgres::error($result);
|
2020-01-01 13:17:19 +08:00
|
|
|
|
}
|
|
|
|
|
}
|
2020-02-19 14:59:09 +08:00
|
|
|
|
|
2022-09-07 15:20:00 +08:00
|
|
|
|
View::assign(['article'=>$article,'jspage'=>'jie']);
|
2022-08-02 21:13:36 +08:00
|
|
|
|
// 编辑多模板支持
|
|
|
|
|
$tpl = Db::name('cate')->where('id', $article['cate_id'])->value('detpl');
|
|
|
|
|
$appName = $this->app->http->getName();
|
|
|
|
|
$viewRoot = root_path() . config('view.view_dir_name') . DIRECTORY_SEPARATOR . $appName . DIRECTORY_SEPARATOR;
|
|
|
|
|
$view = 'article' . DIRECTORY_SEPARATOR . $tpl . DIRECTORY_SEPARATOR . 'edit.html';
|
|
|
|
|
$vfile = $viewRoot . $view;
|
|
|
|
|
$editTpl = is_file($vfile) ? $vfile : 'edit';
|
|
|
|
|
|
|
|
|
|
return View::fetch($editTpl);
|
2020-01-01 13:17:19 +08:00
|
|
|
|
}
|
|
|
|
|
|
2022-04-17 17:09:19 +08:00
|
|
|
|
/**
|
|
|
|
|
* 删除
|
|
|
|
|
*
|
|
|
|
|
* @return void
|
|
|
|
|
*/
|
2020-01-01 13:17:19 +08:00
|
|
|
|
public function delete()
|
|
|
|
|
{
|
2023-05-05 12:07:11 +08:00
|
|
|
|
$article = $this->model->find(input('id'));
|
2020-01-01 13:17:19 +08:00
|
|
|
|
$result = $article->together(['comments'])->delete();
|
|
|
|
|
if($result) {
|
2023-05-05 11:58:42 +08:00
|
|
|
|
return Msgres::success('delete_success');
|
2020-01-01 13:17:19 +08:00
|
|
|
|
}
|
2023-05-05 11:58:42 +08:00
|
|
|
|
return Msgres::error('delete_error');
|
2020-01-01 13:17:19 +08:00
|
|
|
|
}
|
2020-11-23 17:03:25 +08:00
|
|
|
|
|
2022-04-17 17:09:19 +08:00
|
|
|
|
/**
|
|
|
|
|
* 上传接口
|
|
|
|
|
*
|
|
|
|
|
* @return void
|
|
|
|
|
*/
|
2021-07-15 19:10:33 +08:00
|
|
|
|
public function uploads()
|
2021-07-07 17:17:58 +08:00
|
|
|
|
{
|
2021-07-15 19:10:33 +08:00
|
|
|
|
$type = Request::param('type');
|
2022-08-16 15:19:21 +08:00
|
|
|
|
return $this->uploadFiles($type);
|
2021-07-07 17:17:58 +08:00
|
|
|
|
}
|
|
|
|
|
|
2022-04-17 17:09:19 +08:00
|
|
|
|
/**
|
|
|
|
|
* 附件下载
|
|
|
|
|
*
|
|
|
|
|
* @param [type] $id
|
|
|
|
|
* @return void
|
|
|
|
|
*/
|
2020-11-23 17:03:25 +08:00
|
|
|
|
public function download($id)
|
|
|
|
|
{
|
|
|
|
|
$zipdir = Db::name('article')->where('id',$id)->value('upzip');
|
|
|
|
|
$zip = substr($zipdir,1);
|
2020-12-14 14:53:33 +08:00
|
|
|
|
Db::name('article')->cache(true)->where('id',$id)->inc('downloads')->update();
|
|
|
|
|
//删除缓存显示下载后数据
|
|
|
|
|
Cache::delete('article_'.$id);
|
2020-11-23 17:03:25 +08:00
|
|
|
|
return download($zip,'my');
|
|
|
|
|
}
|
|
|
|
|
|
2022-04-17 17:09:19 +08:00
|
|
|
|
/**
|
|
|
|
|
* 获取描述,过滤html
|
|
|
|
|
*
|
|
|
|
|
* @return void
|
|
|
|
|
*/
|
|
|
|
|
public function getDescription()
|
|
|
|
|
{
|
|
|
|
|
$data = Request::only(['content']);
|
|
|
|
|
$description = getArtContent($data['content']);
|
|
|
|
|
return json(['code'=>0,'data'=>$description]);
|
|
|
|
|
}
|
|
|
|
|
|
2022-08-02 21:13:36 +08:00
|
|
|
|
/**
|
|
|
|
|
* 标题调用百度关键词词条
|
|
|
|
|
*
|
|
|
|
|
* @return void
|
|
|
|
|
*/
|
|
|
|
|
public function getWordList()
|
|
|
|
|
{
|
|
|
|
|
$title = input('title');
|
2022-08-16 15:19:21 +08:00
|
|
|
|
return $this->getBdiduSearchWordList($title);
|
2022-08-02 21:13:36 +08:00
|
|
|
|
}
|
|
|
|
|
|
2022-04-17 17:09:19 +08:00
|
|
|
|
/**
|
2023-02-11 21:24:02 +08:00
|
|
|
|
* 关键词
|
|
|
|
|
* @return \think\response\Json
|
|
|
|
|
*/
|
2022-08-16 15:29:04 +08:00
|
|
|
|
public function keywords()
|
2020-11-23 17:03:25 +08:00
|
|
|
|
{
|
2022-09-07 15:20:00 +08:00
|
|
|
|
$data = Request::only(['flag','keywords','content']);
|
2023-02-11 21:24:02 +08:00
|
|
|
|
$keywords = $this->setKeywords($data);
|
|
|
|
|
return json(['code'=>0, 'msg' => 'ok', 'data'=> $keywords]);
|
2020-11-23 17:03:25 +08:00
|
|
|
|
}
|
2022-04-17 17:09:19 +08:00
|
|
|
|
|
2022-08-02 21:13:36 +08:00
|
|
|
|
// 文章置顶、加精、评论状态
|
|
|
|
|
public function jieset()
|
|
|
|
|
{
|
2020-01-01 13:17:19 +08:00
|
|
|
|
$data = Request::param();
|
2023-05-05 12:07:11 +08:00
|
|
|
|
$article = $this->model->field('id,is_top,is_hot,is_reply')->find($data['id']);
|
2021-07-23 17:05:43 +08:00
|
|
|
|
switch ($data['field']){
|
|
|
|
|
case 'top':
|
|
|
|
|
if($data['rank']==1){
|
|
|
|
|
$article->save(['is_top' => 1]);
|
|
|
|
|
$res = ['status'=>0,'msg'=>'置顶成功'];
|
|
|
|
|
} else {
|
|
|
|
|
$article->save(['is_top' => 0]);
|
2022-08-02 21:13:36 +08:00
|
|
|
|
$res = ['status'=>0,'msg'=>'置顶已取消'];
|
2021-07-23 17:05:43 +08:00
|
|
|
|
}
|
|
|
|
|
break;
|
|
|
|
|
case 'hot':
|
|
|
|
|
if($data['rank']==1){
|
|
|
|
|
$article->save(['is_hot' => 1]);
|
2022-08-02 21:13:36 +08:00
|
|
|
|
$res = ['status'=>0,'msg'=>'加精成功'];
|
2021-07-23 17:05:43 +08:00
|
|
|
|
} else {
|
|
|
|
|
$article->save(['is_hot' => 0]);
|
2022-08-02 21:13:36 +08:00
|
|
|
|
$res = ['status'=>0,'msg'=>'加精已取消'];
|
2021-07-23 17:05:43 +08:00
|
|
|
|
}
|
|
|
|
|
break;
|
|
|
|
|
case 'reply':
|
|
|
|
|
if($data['rank']==1){
|
|
|
|
|
$article->save(['is_reply' => 1]);
|
2022-08-02 21:13:36 +08:00
|
|
|
|
$res = ['status'=>0,'msg'=>'禁评成功'];
|
2021-07-23 17:05:43 +08:00
|
|
|
|
} else {
|
|
|
|
|
$article->save(['is_reply' => 0]);
|
|
|
|
|
$res = ['status'=>0,'msg'=>'禁评已取消'];
|
|
|
|
|
}
|
|
|
|
|
}
|
2020-04-24 15:07:26 +08:00
|
|
|
|
//删除本贴设置缓存显示编辑后内容
|
|
|
|
|
Cache::delete('article_'.$data['id']);
|
|
|
|
|
//清除文章tag缓存
|
2020-05-13 17:55:29 +08:00
|
|
|
|
Cache::tag('tagArtDetail')->clear();
|
2020-01-01 13:17:19 +08:00
|
|
|
|
return json($res);
|
|
|
|
|
}
|
|
|
|
|
|
2022-08-02 21:13:36 +08:00
|
|
|
|
// 改变标题颜色
|
2020-04-19 14:29:34 +08:00
|
|
|
|
public function titleColor()
|
|
|
|
|
{
|
|
|
|
|
$data = Request::param();
|
2023-05-05 12:07:11 +08:00
|
|
|
|
$result = $this->model->update($data);
|
2020-04-19 14:29:34 +08:00
|
|
|
|
if($result){
|
|
|
|
|
//清除文章缓存
|
|
|
|
|
Cache::tag(['tagArt','tagArtDetail'])->clear();
|
|
|
|
|
$res = ['code'=> 0, 'msg'=>'标题颜色设置成功'];
|
|
|
|
|
}else{
|
|
|
|
|
$res = ['code'=> -1, 'msg'=>'标题颜色设置失败'];
|
|
|
|
|
}
|
|
|
|
|
return json($res);
|
|
|
|
|
}
|
|
|
|
|
|
2022-04-17 17:09:19 +08:00
|
|
|
|
/**
|
|
|
|
|
* 内容中是否有图片视频音频插入
|
|
|
|
|
*
|
|
|
|
|
* @param [type] $content
|
|
|
|
|
* @return boolean
|
|
|
|
|
*/
|
2021-06-07 17:53:24 +08:00
|
|
|
|
public function hasIva($content)
|
|
|
|
|
{
|
|
|
|
|
//判断是否插入图片
|
|
|
|
|
$isHasImg = strpos($content,'img[');
|
|
|
|
|
$data['has_img'] = is_int($isHasImg) ? 1 : 0;
|
|
|
|
|
//判断是否插入视频
|
|
|
|
|
$isHasVideo = strpos($content,'video(');
|
|
|
|
|
$data['has_video'] = is_int($isHasVideo) ? 1 : 0;
|
|
|
|
|
//判断是否插入音频
|
|
|
|
|
$isHasAudio = strpos($content,'audio[');
|
|
|
|
|
$data['has_audio'] = is_int($isHasAudio) ? 1 : 0;
|
|
|
|
|
|
|
|
|
|
return $data;
|
|
|
|
|
}
|
2022-08-02 20:46:01 +08:00
|
|
|
|
|
|
|
|
|
//设置文章内容tag
|
|
|
|
|
protected function setArtTagLink($content)
|
|
|
|
|
{
|
|
|
|
|
// tag链接数组
|
2022-08-16 15:29:04 +08:00
|
|
|
|
$taglink = new PushJscode();
|
|
|
|
|
$tag = $taglink->getAllCodes(2);
|
2022-08-02 20:46:01 +08:00
|
|
|
|
if(count($tag)) {
|
|
|
|
|
foreach($tag as $key=>$value) {
|
2022-08-02 20:48:54 +08:00
|
|
|
|
// 匹配所有
|
|
|
|
|
//$content = str_replace("$key", 'a('.$value.')['.$key.']',$content);
|
2022-08-02 21:13:36 +08:00
|
|
|
|
// 限定匹配数量 '/'.$key.'/'
|
2022-08-16 15:21:08 +08:00
|
|
|
|
|
2022-08-02 21:13:36 +08:00
|
|
|
|
// 匹配不包含[和]的内容
|
2022-08-16 15:21:08 +08:00
|
|
|
|
// $pats = '/(?<!\[)'.$key.'(?!\])/';
|
|
|
|
|
// $pats = '/(?<!<a\s?(.*)?)'.$key.'(?!<\/a>)/';
|
|
|
|
|
//$pats = '/'.$key.'(?!<\/a>)/';
|
2022-09-07 15:21:56 +08:00
|
|
|
|
|
|
|
|
|
//1.不匹配 $key</a>已经存在链接的情况
|
|
|
|
|
//2.或不匹配 alt="$key等等等" $key后面有"这种情况
|
|
|
|
|
$pats = '/' . $value['name'] . '\s?(?!<\/a>|\s?\S*")/is';
|
2022-08-16 15:21:08 +08:00
|
|
|
|
|
|
|
|
|
preg_match($pats,$content,$arr);
|
|
|
|
|
|
2022-08-02 21:13:36 +08:00
|
|
|
|
// 开启和关闭编辑器使用不同的链接方式
|
2022-08-16 15:29:04 +08:00
|
|
|
|
$rpes = hook('taonystatus') ? '<a href="' . $value['jscode'] . '" target="_blank" title="' . $value['name'] . '" style="font-weight: bold;color:#31BDEC">' . $value['name'] . '</a>' : 'a(' . $value['jscode'] . ')[' . $value['name'] . ']';
|
2022-08-02 21:13:36 +08:00
|
|
|
|
|
|
|
|
|
$content = preg_replace($pats,$rpes,$content,2);
|
2022-08-02 20:46:01 +08:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return $content;
|
|
|
|
|
}
|
2022-08-02 20:48:54 +08:00
|
|
|
|
|
2022-08-16 15:21:08 +08:00
|
|
|
|
//点赞文章
|
2022-08-02 21:13:36 +08:00
|
|
|
|
public function userZanArticle()
|
|
|
|
|
{
|
|
|
|
|
//
|
|
|
|
|
if(Request::isPost()) {
|
|
|
|
|
$data = Request::post();
|
|
|
|
|
$data['user_id'] = $this->uid;
|
|
|
|
|
$userZan = Db::name('user_zan')->where(['user_id'=>$this->uid,'article_id'=>$data['article_id']])->find();
|
|
|
|
|
if($userZan){
|
|
|
|
|
return json(['code'=> -1, 'msg'=>'您已赞过了哦']);
|
|
|
|
|
}
|
|
|
|
|
$res = Db::name('user_zan')->insert($data);
|
|
|
|
|
if($res) {
|
|
|
|
|
return json(['code'=> 0, 'msg'=>'点赞成功']);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2022-08-02 20:48:54 +08:00
|
|
|
|
}
|
2022-09-07 15:21:56 +08:00
|
|
|
|
|
2023-05-05 12:03:45 +08:00
|
|
|
|
/**
|
|
|
|
|
* 分类树
|
|
|
|
|
* @return \think\response\Json
|
|
|
|
|
*/
|
|
|
|
|
public function getCateTree()
|
|
|
|
|
{
|
|
|
|
|
$data = $this->showNav();
|
|
|
|
|
$count = count($data);
|
|
|
|
|
$tree = [];
|
|
|
|
|
if($count){
|
|
|
|
|
$tree = ['code'=>0, 'msg'=>'ok','count'=>$count];
|
|
|
|
|
$tree['data'] = $data;
|
|
|
|
|
}
|
2022-09-07 15:21:56 +08:00
|
|
|
|
|
2023-05-05 12:03:45 +08:00
|
|
|
|
return json($tree);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public function jiemi()
|
|
|
|
|
{
|
|
|
|
|
$param = Request::param();
|
|
|
|
|
$article = $this->model->find($param['id']);
|
|
|
|
|
if($article['art_pass'] == $param['art_pass']) {
|
|
|
|
|
session('art_pass_'.$param['id'], $param['art_pass']);
|
|
|
|
|
return json(['code' => 0, 'msg' => '解密成功']);
|
|
|
|
|
}
|
|
|
|
|
return json(['code' => -1, 'msg' => '解密失败']);
|
|
|
|
|
}
|
2022-08-16 15:21:08 +08:00
|
|
|
|
|
2020-01-01 13:17:19 +08:00
|
|
|
|
}
|