table_forum_postcomment.php
7.39 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
<?php
/**
* [Discuz!] (C)2001-2099 Comsenz Inc.
* This is NOT a freeware, use is subject to license terms
*
* $Id: table_forum_postcomment.php 32456 2013-01-21 05:18:56Z monkey $
*/
if(!defined('IN_DISCUZ')) {
exit('Access Denied');
}
class table_forum_postcomment extends discuz_table
{
public function __construct() {
$this->_table = 'forum_postcomment';
$this->_pk = 'id';
parent::__construct();
}
public function count_by_authorid($authorid) {
return DB::result_first('SELECT COUNT(*) FROM %t WHERE authorid=%d', array($this->_table, $authorid));
}
public function count_by_pid($pid, $authorid = null, $score = null) {
return DB::result_first('SELECT COUNT(*) FROM %t WHERE pid=%d '.($authorid ? ' AND '.DB::field('authorid', $authorid) : null).($score ? ' AND '.DB::field('score', $score) : null), array($this->_table, $pid, $authorid, $score));
}
public function count_by_tid($tid, $authorid = null, $score = null) {
return DB::result_first('SELECT COUNT(*) FROM %t WHERE tid=%d '.($authorid ? ' AND '.DB::field('authorid', $authorid) : null).($score ? ' AND '.DB::field('score', $score) : null), array($this->_table, $tid, $authorid, $score));
}
public function count_by_search($tid = null, $pid = null, $authorid = null, $starttime = null, $endtime = null, $ip = null, $message = null) {
$sql = '';
$tid && $sql .= ' AND '.DB::field('tid', $tid);
$pid && $sql .= ' AND '.DB::field('pid', $pid);
$authorid && $sql .= ' AND '.DB::field('authorid', $authorid);
$starttime && $sql .= ' AND '.DB::field('dateline', $starttime, '>=');
$endtime && $sql .= ' AND '.DB::field('dateline', $endtime, '<');
$ip && $sql .= ' AND '.DB::field('useip', str_replace('*', '%', $ip), 'like');
if($message) {
$sqlmessage = '';
$or = '';
$message = explode(',', str_replace(' ', '', $message));
for($i = 0; $i < count($message); $i++) {
if(preg_match("/\{(\d+)\}/", $message[$i])) {
$message[$i] = preg_replace("/\\\{(\d+)\\\}/", ".{0,\\1}", preg_quote($message[$i], '/'));
$sqlmessage .= " $or comment REGEXP '".$message[$i]."'";
} else {
$sqlmessage .= " $or ".DB::field('comment', '%'.$message[$i].'%', 'like');
}
$or = 'OR';
}
$sql .= " AND ($sqlmessage)";
}
return DB::result_first('SELECT COUNT(*) FROM %t WHERE authorid>-1 %i', array($this->_table, $sql));
}
public function fetch_all_by_search($tid = null, $pid = null, $authorid = null, $starttime = null, $endtime = null, $ip = null, $message = null, $start = null, $limit = null) {
$sql = '';
$tid && $sql .= ' AND '.DB::field('tid', $tid);
$pid && $sql .= ' AND '.DB::field('pid', $pid);
$authorid && $sql .= ' AND '.DB::field('authorid', $authorid);
$starttime && $sql .= ' AND '.DB::field('dateline', $starttime, '>=');
$endtime && $sql .= ' AND '.DB::field('dateline', $endtime, '<');
$ip && $sql .= ' AND '.DB::field('useip', str_replace('*', '%', $ip), 'like');
if($message) {
$sqlmessage = '';
$or = '';
$message = explode(',', str_replace(' ', '', $message));
for($i = 0; $i < count($message); $i++) {
if(preg_match("/\{(\d+)\}/", $message[$i])) {
$message[$i] = preg_replace("/\\\{(\d+)\\\}/", ".{0,\\1}", preg_quote($message[$i], '/'));
$sqlmessage .= " $or comment REGEXP '".$message[$i]."'";
} else {
$sqlmessage .= " $or ".DB::field('comment', '%'.$message[$i].'%', 'like');
}
$or = 'OR';
}
$sql .= " AND ($sqlmessage)";
}
return DB::fetch_all('SELECT * FROM %t WHERE authorid>-1 %i ORDER BY dateline DESC '.DB::limit($start, $limit), array($this->_table, $sql));
}
public function fetch_all_by_authorid($authorid, $start, $limit) {
return DB::fetch_all('SELECT * FROM %t WHERE authorid=%d ORDER BY dateline DESC '.DB::limit($start, $limit), array($this->_table, $authorid));
}
public function fetch_all_by_pid($pids) {
if(empty($pids)) {
return array();
}
return DB::fetch_all('SELECT * FROM %t WHERE '.DB::field('pid', $pids).' ORDER BY dateline DESC', array($this->_table));
}
public function fetch_all_by_pid_score($pid, $score) {
return DB::fetch_all('SELECT * FROM %t WHERE pid=%d AND score=%d', array($this->_table, $pid, $score));
}
public function fetch_standpoint_by_pid($pid) {
return DB::fetch_first('SELECT * FROM %t WHERE pid=%d AND authorid=-1', array($this->_table, $pid));
}
public function update_by_pid($pids, $data, $unbuffered = false, $low_priority = false, $authorid = null) {
if(empty($data)) {
return false;
}
$where = array();
$where[] = DB::field('pid', $pids);
$authorid !== null && $where[] = DB::field('authorid', $authorid);
return DB::update($this->_table, $data, implode(' AND ', $where), $unbuffered, $low_priority);
}
public function delete_by_authorid($authorids, $unbuffered = false, $rpid = false) {
if(empty($authorids)) {
return false;
}
$where = array();
$where[] = DB::field('authorid', $authorids);
$rpid && $where[] = DB::field('rpid', 0, '>');
return DB::delete($this->_table, implode(' AND ', $where), null, $unbuffered);
}
public function delete_by_tid($tids, $unbuffered = false, $authorids = null) {
$where = array();
$where[] = DB::field('tid', $tids);
$authorids !== null && !(is_array($authorids) && empty($authorids)) && $where[] = DB::field('authorid', $authorids);
return DB::delete($this->_table, implode(' AND ', $where), null, $unbuffered);
}
public function delete_by_pid($pids, $unbuffered = false, $authorid = null) {
$where = array();
$where[] = DB::field('pid', $pids);
$authorid !== null && !(is_array($authorid) && empty($authorid)) && $where[] = DB::field('authorid', $authorid);
return DB::delete($this->_table, implode(' AND ', $where), null, $unbuffered);
}
public function delete_by_rpid($rpids, $unbuffered = false) {
if(empty($rpids)) {
return false;
}
return DB::delete($this->_table, DB::field('rpid', $rpids), null, $unbuffered);
}
public function fetch_postcomment_by_pid($pids, $postcache, $commentcount, $totalcomment, $commentnumber) {
$query = DB::query("SELECT * FROM ".DB::table('forum_postcomment')." WHERE pid IN (".dimplode($pids).') ORDER BY dateline DESC');
$commentcount = $comments = array();
while($comment = DB::fetch($query)) {
if($comment['authorid'] > '-1') {
$commentcount[$comment['pid']]++;
}
if(count($comments[$comment['pid']]) < $commentnumber && $comment['authorid'] > '-1') {
$comment['avatar'] = avatar($comment['authorid'], 'small');
$comment['comment'] = str_replace(array('[b]', '[/b]', '[/color]'), array('<b>', '</b>', '</font>'), preg_replace("/\[color=([#\w]+?)\]/i", "<font color=\"\\1\">", $comment['comment']));
$comments[$comment['pid']][] = $comment;
}
if($comment['authorid'] == '-1') {
$cic = 0;
$totalcomment[$comment['pid']] = preg_replace('/<i>([\.\d]+)<\/i>/e', "'<i class=\"cmstarv\" style=\"background-position:20px -'.(intval(\\1) * 16).'px\">'.sprintf('%1.1f', \\1).'</i>'.(\$cic++ % 2 ? '<br />' : '');", $comment['comment']);
}
$postcache[$comment['pid']]['comment']['count'] = $commentcount[$comment['pid']];
$postcache[$comment['pid']]['comment']['data'] = $comments[$comment['pid']];
$postcache[$comment['pid']]['comment']['totalcomment'] = $totalcomment[$comment['pid']];
}
return array($comments, $postcache, $commentcount, $totalcomment);
}
}
?>