Article.php
4.42 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
<?php
/**
* tpshop
* ============================================================================
* 版权所有 2015-2027 深圳搜豹网络科技有限公司,并保留所有权利。
* 网站地址: http://www.tp-shop.cn
* ----------------------------------------------------------------------------
* 这不是一个自由软件!您只能在不用于商业目的的前提下对程序代码进行修改和使用 .
* 不允许对程序代码以任何形式任何目的的再发布。
* ============================================================================
* Author: 当燃
* Date: 2015-09-09
*/
namespace app\manager\controller;
use think\Page;
use think\Db;
class Article extends Base {
public function _initialize()
{
parent::_initialize();
}
public function articleList(){
$Article = M('news');
$list = array();
$p = input('p/d', 1);
$pagenum = input('pagenum/d', 20);
$where = array();
$keywords = I('keywords');
$keywords && $where['title'] = array('like', '%' . $keywords . '%');
$res = $Article->where($where)->order('article_id desc')->page("$p,$pagenum")->select();
$count = $Article->where($where)->count();// 查询满足要求的总记录数
$pager = new Page($count,$pagenum);// 实例化分页类 传入总记录数和每页显示的记录数
$page = $pager->show();//分页显示输出
$oldurl="";
$this->assign('oldurl', $oldurl);
$this->assign('list',$res);// 赋值数据集
$this->assign('page',$page);// 赋值分页输出
$this->assign('pager',$pager);
$this->assign('keywords',$keywords);
$this->assign('pagenum',$pagenum);
return $this->fetch('articleList');
}
public function article(){
$act = I('get.act','add');
$info = array();
$info['publish_time'] = time();
$info['publish_etime'] = time()+60*60*24*7;
$info['is_open'] = 1;
$article_id = I('get.article_id/d');
if($article_id){
$info = M('news')->where('article_id', $article_id)->find();
}
$this->assign('act',$act);
$this->assign('info',$info);
$this->initEditor();
return $this->fetch();
}
/**
* 初始化编辑器链接
* @param $post_id post_id
*/
private function initEditor()
{
$this->assign("URL_upload", U('Manager/Ueditor/imageUp',array('savepath'=>'article','savepath1'=>'temp')));
$this->assign("URL_fileUp", U('Manager/Ueditor/fileUp',array('savepath'=>'article','savepath1'=>'temp')));
$this->assign("URL_scrawlUp", U('Manager/Ueditor/scrawlUp',array('savepath'=>'article','savepath1'=>'temp')));
$this->assign("URL_getRemoteImage", U('Manager/Ueditor/getRemoteImage',array('savepath'=>'article','savepath1'=>'temp')));
$this->assign("URL_imageManager", U('Manager/Ueditor/imageManager',array('savepath'=>'article','savepath1'=>'temp')));
$this->assign("URL_imageUp", U('Manager/Ueditor/imageUp',array('savepath'=>'article','savepath1'=>'temp')));
$this->assign("URL_getMovie", U('Manager/Ueditor/getMovie',array('savepath'=>'article','savepath1'=>'temp')));
$this->assign("URL_Home", "");
}
public function aticleHandle(){
$data = I('post.');
$data['content'] = I('content'); // 文章内容单独过滤
$data['publish_time'] = strtotime($data['publish_time']);
$data['publish_etime'] = strtotime($data['publish_etime']);
$url = $this->request->server('HTTP_REFERER');
$referurl = !empty($url) ? $url : U('Manager/Article/articleList');
//$data['content'] = htmlspecialchars(stripslashes($_POST['content']));
if($data['act'] == 'add'){
$data['click'] = mt_rand(1000,1300);
$data['add_time'] = time();
$r = M('news')->add($data);
}
if($data['act'] == 'edit'){
$r = M('news')->where('article_id', $data['article_id'])->save($data);
}
if($data['act'] == 'del'){
$r = M('news')->where('article_id', $data['article_id'])->delete();
if($r) exit(json_encode(1));
}
if($data['act'] == 'edit') {
$this->success("操作成功",U('Manager/Article/articleList'));
}else{
$this->success("操作成功",$referurl);
}
}
}