forked from typecho-fans/plugins
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathAction.php
114 lines (105 loc) · 4.6 KB
/
Action.php
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
<?php
if (!defined('__TYPECHO_ROOT_DIR__')) exit;
class PostsCategoryChange_Action extends Typecho_Widget implements Widget_Interface_Do
{
private $db;
private $prefix;
public function action()
{
$user = Typecho_Widget::widget('Widget_User');
$user->pass('administrator');
$this->options = Typecho_Widget::widget('Widget_Options');
$this->db = Typecho_Db::get();
$this->prefix = $this->db->getPrefix();
$this->on($this->request->is('do=change-category'))->makeChange();
$this->on($this->request->is('do=change-status'))->changeStatus();
exit;
}
public function makeChange()
{
$cids = $this->request->filter('int')->getArray('cid');
$mid = $this->request->filter('int')->get('mid');
if(empty($cids)) {
echo json_encode(['code'=>-1,'msg'=>'大佬,至少选择一篇文章!']);
return;
} else if(empty($mid)) {
echo json_encode(['code'=>-1,'msg'=>'大佬,请选择一个分类!']);
return;
} else {
$cid = implode(',',$cids);
$select = 'SELECT cid FROM '.$this->prefix.'contents where cid in('.$cid.') and type="post"';
$res = $this->db->fetchAll($this->db->query($select));
if(empty($res)) {
echo json_encode(['code'=>-1,'msg'=>'f**k,别特么瞎jb搞!']);
return;
} else {
$post_cid = '';
foreach ($res as $value) {
$post_cid .= $value['cid'].',';
}
$post_cid = trim($post_cid,',');
$select = 'SELECT mid,type FROM '.$this->prefix.'metas where type="category"';
$res = $this->db->fetchAll($this->db->query($select));
$category_mid = '';
foreach ($res as $value) {
$category_mid .= $value['mid'].',';
}
$category_mid = trim($category_mid,',');
$res = $this->db->fetchAll($this->db->query($select));
$update = $this->db->update($this->prefix.'relationships')->rows(array('mid'=>$mid))->where('cid in ('.$post_cid.') AND mid IN ('.$category_mid.')');
$row = @$this->db->query($update);
if($row) {
echo json_encode(['code'=>1,'msg'=>'本次成功更新'.$row.'篇文章!']);
return;
} else {
echo json_encode(['code'=>-1,'msg'=>'更新失败']);
return;
}
}
}
}
public function changeStatus()
{
$cids = $this->request->filter('int')->getArray('cid');
$status = $this->request->filter('int')->get('status');
if(empty($cids)) {
echo json_encode(['code'=>-1,'msg'=>'大佬,至少选择一篇文章!']);
return;
} else if(empty($status)) {
echo json_encode(['code'=>-1,'msg'=>'大佬,请选择一个文章状态!']);
return;
} else {
$status_arr = [
'1'=>'publish',
'2'=>'hidden',
'3'=>'private'
];
if(!array_key_exists($status,$status_arr)) {
echo json_encode(['code'=>-1,'msg'=>'f**k,别特么瞎jb搞!']);
return ;
} else {
$status = $status_arr[$status];
}
$cid = implode(',',$cids);
$select = 'SELECT cid,status FROM '.$this->prefix.'contents where cid in('.$cid.') and type="post"';
$res = $this->db->fetchAll($this->db->query($select));
if(empty($res)) {
echo json_encode(['code'=>-1,'msg'=>'f**k,别特么瞎jb搞!']);
return;
} else {
$count = 0;
foreach ($res as $value) {
$update = $this->db->update($this->prefix.'contents')->rows(array('status'=>$status))->where('cid in ('.$value['cid'].')');
@$this->db->query($update) && $count ++;
}
if($count>0) {
echo json_encode(['code'=>1,'msg'=>'本次成功更新'.$count.'篇文章!']);
return;
} else {
echo json_encode(['code'=>-1,'msg'=>'更新失败']);
return;
}
}
}
}
}