table_security_evilpost.php
8.18 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
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
<?php
/**
* [Discuz!] (C)2001-2099 Comsenz Inc.
* This is NOT a freeware, use is subject to license terms
*
* $Id: table_security_evilpost.php 29265 2012-03-31 06:03:26Z yexinhao $
*/
if(!defined('IN_DISCUZ')) {
exit('Access Denied');
}
class table_security_evilpost extends discuz_table {
public function __construct() {
$this->_table = 'security_evilpost';
$this->_pk = 'pid';
parent::__construct();
}
public function fetch_all_report($limit = 20) {
return DB::fetch_all("SELECT * FROM %t WHERE isreported = 0 AND operateresult > 0 LIMIT %d", array($this->_table, $limit));
}
public function range_by_operateresult($operateresult, $start, $limit) {
return DB::fetch_all('SELECT * FROM %t WHERE ' . DB::field('operateresult', $operateresult) . ' ' . DB::limit($start, $limit), array($this->_table), $this->_pk);
}
public function count_by_type($type) {
$type = $type ? 1 : 0;
$count = (int) DB::result_first("SELECT count(*) FROM %t WHERE type = %d", array($this->_table, $type));
return $count;
}
public function fetch_range_by_type($type, $start, $perPage = '20', $orderBy = 'createtime') {
$type = $type ? 1 : 0;
$orderSql = " ORDER BY $orderBy DESC ";
$limitSql = DB::limit($start, $perPage);
$return = DB::fetch_all("SELECT * FROM %t WHERE type = %d %i %i", array($this->_table, $type, $orderSql, $limitSql));
return $return;
}
public function update_result($operateResult, $pids) {
$operateResult = $operateResult ? 1 : 0;
if (!isset($pids)) {
return false;
}
$updateData = array('operateresult' => $operateResult);
$updateCondition = DB::field('pid', $pids);
return DB::update($this->_table, $updateData, $updateCondition);
}
public function update_reported($isReported, $pids) {
$isReported = $isReported ? 1 : 0;
if (!isset($pids)) {
return false;
}
$updateData = array('isreported' => $isReported);
$updateCondition = DB::field('pid', $pids);
return DB::update($this->_table, $updateData, $updateCondition);
}
public function update_by_pid_type($data, $pid, $type) {
if(!empty($data) && is_array($data)) {
return DB::update($this->_table, $data, array(DB::field($this->_pk, $pid), DB::field('type', $type)));
}
return 0;
}
public function update_by_tid($ids, $data) {
if(!empty($data) && is_array($data)) {
return DB::update($this->_table, $data, DB::field('tid', $ids));
}
return 0;
}
public function count_by_recyclebine($fid = 0, $isgroup = 0, $author = array(), $username = array(), $pstarttime = 0, $pendtime = 0, $mstarttime = 0, $mendtime = 0, $keywords = '') {
$sql = $this->recyclebine_where($fid, $isgroup, $author, $username, $pstarttime, $pendtime, $mstarttime, $mendtime, $keywords);
return DB::result_first('SELECT COUNT(*) FROM '.DB::table('forum_thread').' t INNER JOIN '.DB::table('security_evilpost').' s ON s.tid = t.tid LEFT JOIN '.DB::table('forum_threadmod').' tm ON tm.tid=t.tid '.$sql[0], $sql[1]);
}
private function recyclebine_where($fid = 0, $isgroup = 0, $authors = array(), $username = array(), $pstarttime = 0, $pendtime = 0, $mstarttime = 0, $mendtime = 0, $keywords = '') {
$parameter = array();
$wherearr = array('t.displayorder=-1', 'tm.action=\'DEL\'', 's.type=1');
if($fid) {
$parameter[] = $fid;
$wherearr[] = is_array($fid) ? 't.fid IN(%n)' : 't.fid=%d';
}
if($isgroup) {
$wherearr[] = 't.isgroup=1';
}
if(!empty($authors)) {
$parameter[] = $authors;
$wherearr[] = is_array($authors) ? 't.author IN(%n)' : 't.author=%s';
}
if(!empty($username)) {
$parameter[] = $username;
$wherearr[] = is_array($username) ? 'tm.username IN(%n)' : 'tm.username=%s';
}
if($pstarttime) {
$parameter[] = $pstarttime;
$wherearr[] = 't.dateline>=%d';
}
if($pendtime) {
$parameter[] = $pendtime;
$wherearr[] = 't.dateline<%d';
}
if($mstarttime) {
$parameter[] = $mstarttime;
$wherearr[] = 'tm.dateline>=%d';
}
if($mendtime) {
$parameter[] = $mendtime;
$wherearr[] = 'tm.dateline<%d';
}
if($keywords) {
$keysql = array();
foreach(explode(',', str_replace(' ', '', $keywords)) as $keyword) {
$parameter[] = '%'.$keywords.'%';
$keysql[] = "t.subject LIKE %s";
}
if($keysql) {
$wherearr[] = '('.implode(' OR ', $keysql).')';
}
}
$wheresql = !empty($wherearr) && is_array($wherearr) ? ' WHERE '.implode(' AND ', $wherearr) : '';
return array($wheresql, $parameter);
}
public function fetch_all_by_recyclebine($fid = 0, $isgroup = 0, $author = array(), $username = array(), $pstarttime = 0, $pendtime = 0, $mstarttime = 0, $mendtime = 0, $keywords = '', $start = 0, $limit = 0) {
$sql = $this->recyclebine_where($fid, $isgroup, $author, $username, $pstarttime, $pendtime, $mstarttime, $mendtime, $keywords);
return DB::fetch_all('SELECT f.name AS forumname, f.allowsmilies, f.allowhtml, f.allowbbcode, f.allowimgcode,
t.tid, t.fid, t.authorid, t.author, t.subject, t.views, t.replies, t.dateline, t.posttableid,
tm.uid AS moduid, tm.username AS modusername, tm.dateline AS moddateline, tm.action AS modaction, tm.reason
FROM '.DB::table('forum_thread').' t INNER JOIN '.DB::table('security_evilpost').' s ON s.tid = t.tid LEFT JOIN '.DB::table('forum_threadmod').' tm ON tm.tid=t.tid
LEFT JOIN '.DB::table('forum_forum').' f ON f.fid=t.fid '.$sql[0].' ORDER BY t.dateline DESC '.DB::limit($start, $limit), $sql[1]);
}
public function count_by_search($tableid, $tid = null, $keywords = null, $invisible =null, $fid = null, $authorid = null, $author = null, $starttime = null, $endtime = null, $useip = null, $first = null) {
$sql = '';
$sql .= $tid ? ' AND '.DB::field('tid', $invisible) : '';
$sql .= $invisible !== null ? ' AND '.DB::field('invisible', $invisible) : '';
$sql .= $first !== null ? ' AND '.DB::field('first', $first) : '';
$sql .= $fid ? ' AND '.DB::field('fid', $fid) : '';
$sql .= $authorid !== null ? ' AND '.DB::field('authorid', $authorid) : '';
$sql .= $author ? ' AND '.DB::field('author', $author) : '';
$sql .= $starttime ? ' AND '.DB::field('dateline', $starttime, '>=') : '';
$sql .= $endtime ? ' AND '.DB::field('dateline', $endtime, '<') : '';
$sql .= $useip ? ' AND '.DB::field('useip', $useip, 'like') : '';
$sql .= ' AND s.type = 0';
if(trim($keywords)) {
$sqlkeywords = $or = '';
foreach(explode(',', str_replace(' ', '', $keywords)) as $keyword) {
$sqlkeywords .= " $or message LIKE '%$keyword%'";
$or = 'OR';
}
$sql .= " AND ($sqlkeywords)";
}
if($sql) {
return DB::result_first('SELECT COUNT(*) FROM %t t INNER JOIN '.DB::table('security_evilpost').' s ON s.pid = t.pid WHERE 1 %i', array(C::t('forum_post')->get_tablename($tableid), $sql));
} else {
return 0;
}
}
public function fetch_all_by_search($tableid, $tid = null, $keywords = null, $invisible = null, $fid = null, $authorid = null, $author = null, $starttime = null, $endtime = null, $useip = null, $first = null, $start = null, $limit = null) {
$sql = '';
$sql .= $tid ? ' AND '.DB::field('tid', $tid) : '';
$sql .= $invisible !== null ? ' AND '.DB::field('invisible', $invisible) : '';
$sql .= $first !== null ? ' AND '.DB::field('first', $first) : '';
$sql .= $fid ? ' AND '.DB::field('fid', $fid) : '';
$sql .= $authorid !== null ? ' AND '.DB::field('authorid', $authorid) : '';
$sql .= $author ? ' AND '.DB::field('author', $author) : '';
$sql .= $starttime ? ' AND '.DB::field('dateline', $starttime, '>=') : '';
$sql .= $endtime ? ' AND '.DB::field('dateline', $endtime, '<') : '';
$sql .= $useip ? ' AND '.DB::field('useip', $useip, 'like') : '';
$sql .= ' AND s.type = 0';
if(trim($keywords)) {
$sqlkeywords = $or = '';
foreach(explode(',', str_replace(' ', '', $keywords)) as $keyword) {
$sqlkeywords .= " $or message LIKE '%$keyword%'";
$or = 'OR';
}
$sql .= " AND ($sqlkeywords)";
}
if($sql) {
return DB::fetch_all('SELECT * FROM %t t INNER JOIN '.DB::table('security_evilpost').' s ON s.pid = t.pid WHERE 1 %i ORDER BY dateline DESC %i', array(C::t('forum_post')->get_tablename($tableid), $sql, DB::limit($start, $limit)));
} else {
return array();
}
}
}