2015-07-28 15:15:57 +08:00
|
|
|
<?php
|
|
|
|
|
namespace User\Controller;
|
|
|
|
|
use Think\Controller;
|
|
|
|
|
|
|
|
|
|
/**
|
2017-02-03 12:32:57 +08:00
|
|
|
* @Author: Zhou Yuyang <1009465756@qq.com> 10:28 2017/02/02
|
2016-12-03 21:42:04 +08:00
|
|
|
* @Copyright 2015-2020 SISMO
|
|
|
|
|
* @Project homepage https://github.com/CNSISMO
|
2017-02-03 12:32:57 +08:00
|
|
|
* @Version 2.0
|
2015-07-28 15:15:57 +08:00
|
|
|
*/
|
2017-02-03 12:32:57 +08:00
|
|
|
|
2015-07-28 15:15:57 +08:00
|
|
|
|
2015-10-06 20:25:13 +08:00
|
|
|
class PostController extends BaseController
|
2015-07-28 15:15:57 +08:00
|
|
|
{
|
2017-02-07 17:41:22 +08:00
|
|
|
|
2015-07-28 15:15:57 +08:00
|
|
|
public function index($key="")
|
|
|
|
|
{
|
|
|
|
|
if($key == ""){
|
|
|
|
|
$model = D('PostView');
|
|
|
|
|
}else{
|
|
|
|
|
$where['post.title'] = array('like',"%$key%");
|
|
|
|
|
$where['member.username'] = array('like',"%$key%");
|
|
|
|
|
$where['category.title'] = array('like',"%$key%");
|
|
|
|
|
$where['_logic'] = 'or';
|
|
|
|
|
$model = D('PostView')->where($where);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
$id = session('userId');
|
2017-02-07 17:41:22 +08:00
|
|
|
$count = $model->where($where)->where('user_id='.$id)->count();
|
|
|
|
|
$Page = new \Extend\Page($count,20);
|
|
|
|
|
$show = $Page->show();
|
2015-07-28 15:15:57 +08:00
|
|
|
$post = $model->limit($Page->firstRow.','.$Page->listRows)->where($where)->order('post.id DESC')->where('user_id='.$id)->select();
|
|
|
|
|
$this->assign('model', $post);
|
|
|
|
|
$this->assign('page',$show);
|
|
|
|
|
$this->display();
|
|
|
|
|
}
|
2017-02-07 17:41:22 +08:00
|
|
|
|
|
|
|
|
|
2015-07-28 15:15:57 +08:00
|
|
|
public function add()
|
|
|
|
|
{
|
|
|
|
|
//默认显示添加表单
|
|
|
|
|
if (!IS_POST) {
|
2016-01-25 10:53:12 +08:00
|
|
|
$tmodel= M('setting');
|
|
|
|
|
$title = $tmodel->where('id=1')->select();
|
|
|
|
|
$this->assign('title', $title);
|
2015-07-28 15:15:57 +08:00
|
|
|
$this->assign("category",getSortedCategory(M('category')->select()));
|
|
|
|
|
$this->display();
|
|
|
|
|
}
|
|
|
|
|
if (IS_POST) {
|
|
|
|
|
//如果用户提交数据
|
|
|
|
|
$model = D("Post");
|
2017-05-31 23:03:37 +08:00
|
|
|
$model->create_time = time();
|
2017-02-07 17:41:22 +08:00
|
|
|
$data = I();
|
2016-01-26 14:09:59 +08:00
|
|
|
if (!$model->field('title,user_id,cate_id,content')->create()) {
|
2015-07-28 15:15:57 +08:00
|
|
|
// 如果创建失败 表示验证没有通过 输出错误提示信息
|
|
|
|
|
$this->error($model->getError());
|
|
|
|
|
exit();
|
|
|
|
|
} else {
|
|
|
|
|
if ($model->add()) {
|
2017-02-07 17:41:22 +08:00
|
|
|
require "./././././ThinkPHP/Library/Org/Net/Mail.class.php";
|
|
|
|
|
$time = date("Y-m-d h:i:sa");
|
|
|
|
|
$con='您好,安全应急响应中心新增一份漏洞报告《 '.$data['title'].'》。请您及时登陆后台查看。';
|
|
|
|
|
SendMail('1009465756@qq.com','新增漏洞报告提示',$con,'安全应急响应中心');
|
|
|
|
|
$this->success("报告成功", U('post/index'));
|
2015-07-28 15:15:57 +08:00
|
|
|
} else {
|
2017-02-07 17:41:22 +08:00
|
|
|
$this->error("报告失败");
|
2015-07-28 15:15:57 +08:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
2016-01-24 11:54:16 +08:00
|
|
|
|
|
|
|
|
public function view(){
|
2017-02-03 12:32:57 +08:00
|
|
|
$rid = I('get.rid',0,'intval');
|
|
|
|
|
$model = M("Post");
|
2016-01-24 11:54:16 +08:00
|
|
|
$id = session('userId');
|
2017-02-03 12:32:57 +08:00
|
|
|
$comment = M('comment')->where(array('post_id'=>$rid))->select();
|
|
|
|
|
$post = $model->where(array('user_id'=>$id,'id'=>$rid))->find();
|
2016-01-25 10:53:12 +08:00
|
|
|
$tmodel= M('setting');
|
|
|
|
|
$title = $tmodel->where('id=1')->select();
|
|
|
|
|
$this->assign('title', $title);
|
2016-01-24 11:54:16 +08:00
|
|
|
$this->assign('model', $post);
|
2017-02-03 12:32:57 +08:00
|
|
|
$this->assign('comment',$comment);
|
2016-01-24 11:54:16 +08:00
|
|
|
$this->display();
|
|
|
|
|
}
|
2017-02-03 12:32:57 +08:00
|
|
|
|
|
|
|
|
public function comment()
|
|
|
|
|
{
|
|
|
|
|
if (!IS_POST) {
|
|
|
|
|
$this->error("非法请求");
|
|
|
|
|
}
|
|
|
|
|
if (IS_POST) {
|
|
|
|
|
$data = I();
|
|
|
|
|
$data['update_time'] = time();
|
|
|
|
|
$data['user_id'] = session('username');
|
|
|
|
|
$model = M("Comment");
|
|
|
|
|
if ($model->add($data)) {
|
|
|
|
|
$this->success("评论成功", U('post/index'));
|
|
|
|
|
} else {
|
|
|
|
|
$this->error("评论失败");
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
2015-07-28 15:15:57 +08:00
|
|
|
}
|