table_home_doing.php
3.93 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
<?php
/**
* [Discuz!] (C)2001-2099 Comsenz Inc.
* This is NOT a freeware, use is subject to license terms
*
* $Id: table_home_doing.php 30377 2012-05-24 09:52:22Z zhengqingpeng $
*/
if(!defined('IN_DISCUZ')) {
exit('Access Denied');
}
class table_home_doing extends discuz_table
{
public function __construct() {
$this->_table = 'home_doing';
$this->_pk = 'doid';
parent::__construct();
}
public function update_replynum_by_doid($inc_replynum, $doid) {
return DB::query('UPDATE %t SET replynum=replynum+\'%d\' WHERE doid=%d', array($this->_table, $inc_replynum, $doid));
}
public function delete_by_uid($uid) {
if(!$uid) {
return null;
}
return DB::delete($this->_table, DB::field('uid', $uid));
}
public function fetch_all_by_uid_doid($uids, $bannedids = '', $paramorderby = '', $startrow = 0, $items = 0, $status = true, $allfileds = false) {
$parameter = array($this->_table);
$orderby = $paramorderby && in_array($paramorderby, array('dateline', 'replynum')) ? 'ORDER BY '.DB::order($paramorderby, 'DESC') : 'ORDER BY '.DB::order('dateline', 'DESC');
$wheres = array();
if($uids) {
$parameter[] = $uids;
$wheres[] = 'uid IN (%n)';
}
if($bannedids) {
$parameter[] = $bannedids;
$wheres[] = 'doid NOT IN (%n)';
}
if($status) {
$wheres[] = ' status = 0';
}
$wheresql = !empty($wheres) && is_array($wheres) ? ' WHERE '.implode(' AND ', $wheres) : '';
if(empty($wheresql)) {
return null;
}
return DB::fetch_all('SELECT '.($allfileds ? '*' : 'doid').' FROM %t '.$wheresql.' '.$orderby.DB::limit($startrow, $items), $parameter);
}
public function fetch_all_search($start, $limit, $fetchtype, $uids, $useip, $keywords, $lengthlimit, $starttime, $endtime, $basickeywords = 0, $doid = '', $findex = '') {
$parameter = array($this->_table);
$wherearr = array();
if($doid) {
$parameter[] = (array)$doid;
$wherearr[] = 'doid IN(%n)';
}
if(is_array($uids) && count($uids)) {
$parameter[] = $uids;
$wherearr[] = 'uid IN(%n)';
}
if($useip) {
$parameter[] = str_replace('*', '%', $useip);
$wherearr[] = 'ip LIKE %s';
}
if($keywords) {
if(!$basickeywords) {
$sqlkeywords = '';
$or = '';
$keywords = explode(',', str_replace(' ', '', $keywords));
for($i = 0; $i < count($keywords); $i++) {
$keywords[$i] = addslashes(stripsearchkey($keywords[$i]));
if(preg_match("/\{(\d+)\}/", $keywords[$i])) {
$keywords[$i] = preg_replace("/\\\{(\d+)\\\}/", ".{0,\\1}", preg_quote($keywords[$i], '/'));
$sqlkeywords .= " $or message REGEXP '".$keywords[$i]."'";
} else {
$sqlkeywords .= " $or message LIKE '%".$keywords[$i]."%'";
}
$or = 'OR';
}
$parameter[] = $sqlkeywords;
$wherearr[] = '%i';
} else {
$parameter[] = '%'.$basickeywords.'%';
$wherearr[] = 'message LIKE %s';
}
}
if($lengthlimit) {
$parameter[] = intval($lengthlimit);
$wherearr[] = 'LENGTH(message) < %d';
}
if($starttime) {
$parameter[] = is_numeric($starttime) ? $starttime : strtotime($starttime);
$wherearr[] = 'dateline>%d';
}
if($endtime) {
$parameter[] = is_numeric($endtime) ? $endtime : strtotime($endtime);
$wherearr[] = 'dateline<%d';
}
if($fetchtype == 3) {
$selectfield = "count(*)";
} elseif ($fetchtype == 2) {
$selectfield = "doid";
} else {
$selectfield = "*";
$parameter[] = DB::limit($start, $limit);
$ordersql = ' ORDER BY dateline DESC %i';
}
if($findex) {
$findex = 'USE INDEX(dateline)';
}
$wheresql = !empty($wherearr) && is_array($wherearr) ? ' WHERE '.implode(' AND ', $wherearr) : '';
if($fetchtype == 3) {
return DB::result_first("SELECT $selectfield FROM %t $wheresql", $parameter);
} else {
return DB::fetch_all("SELECT $selectfield FROM %t {$findex} $wheresql $ordersql", $parameter);
}
}
}
?>