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:
198:
199:
200:
201:
202:
203:
204:
205:
206:
207:
208:
209:
210:
211:
212:
213:
214:
215:
216:
217:
218:
219:
220:
221:
222:
|
<?php
/** delete a thread **/
function deletethread($threadid) {
global $db, $n, $thread, $board, $boardid;
/** delete thread **/
$db->query("DELETE FROM bb".$n."_threads WHERE threadid = '$threadid'");
$db->unbuffered_query("DELETE FROM bb".$n."_threads WHERE pollid = '$threadid' AND closed=3", 1);
if ($thread['important'] == 2) $db->unbuffered_query("DELETE FROM bb".$n."_announcements WHERE threadid = '$threadid'", 1);
/** delete subscriptions **/
$db->query("DELETE FROM bb".$n."_subscribethreads WHERE threadid = '$threadid'");
/** delete poll **/
if ($thread['pollid']) {
$db->query("DELETE FROM bb".$n."_polls WHERE pollid = '$thread[pollid]'");
$pollvotes = " OR (id = '$thread[pollid]' AND votemode=1)";
$db->query("DELETE FROM bb".$n."_polloptions WHERE pollid = '$thread[pollid]'");
}
else $pollvotes = '';
/** delete ratings **/
$db->query("DELETE FROM bb".$n."_votes WHERE (id = '$threadid' AND votemode=2)$pollvotes");
/** delete attachments **/
if ($thread['attachments']) {
$result = $db->query("SELECT attachmentid FROM bb".$n."_posts WHERE threadid='$threadid' AND attachmentid>0");
while ($row = $db->fetch_array($result)) $attachmentids .= ",".$row['attachmentid'];
$result = $db->query("SELECT attachmentid, attachmentextension FROM bb".$n."_attachments WHERE attachmentid IN (0$attachmentids)");
while ($row = $db->fetch_array($result)) @unlink("attachments/attachment-".$row['attachmentid'].".".$row['attachmentextension']);
$db->query("DELETE FROM bb".$n."_attachments WHERE attachmentid IN (0$attachmentids)");
}
/** delete userpost **/
if ($board['countuserposts'] == 1) {
$result = $db->query("SELECT COUNT(postid) AS posts, userid FROM bb".$n."_posts WHERE threadid='$threadid' AND visible=1 AND userid>0 GROUP BY userid");
while ($row = $db->fetch_array($result)) $db->query("UPDATE bb".$n."_users SET userposts=userposts-'$row[posts]' WHERE userid='$row[userid]'");
}
/** delete posts **/
$db->query("DELETE FROM bb".$n."_posts WHERE threadid = '$threadid'");
$thread['replycount'] += 1;
/* update global threadcount & postcount */
if ($thread['visible'] == 1) $db->unbuffered_query("UPDATE bb".$n."_stats SET threadcount=threadcount-1, postcount=postcount-'".$thread['replycount']."'", 1);
/* update boardcount */
if ($thread['visible'] == 1) $db->query("UPDATE bb".$n."_boards SET threadcount=threadcount-1, postcount=postcount-'".$thread['replycount']."' WHERE boardid IN ($boardid,$board[parentlist])");
if ($board['lastthreadid'] == $threadid) updateBoardInfo("$boardid,$board[parentlist]", 0, $threadid);
}
/** delete an amount of posts **/
function deleteposts($postids, $threadid, $postcount) {
global $db, $n, $thread, $board, $boardid;
$result = $db->query("SELECT postid, parentpostid FROM bb".$n."_posts WHERE postid IN ($postids) ORDER BY posttime DESC");
while ($row = $db->fetch_array($result)) $db->query("UPDATE bb".$n."_posts SET parentpostid='$row[parentpostid]' WHERE threadid = '".$threadid."' AND parentpostid='$row[postid]'");
/** delete userpost **/
if ($board['countuserposts'] == 1) {
$result = $db->query("SELECT COUNT(postid) AS posts, userid FROM bb".$n."_posts WHERE postid IN ($postids) AND visible=1 AND userid>0 GROUP BY userid");
while ($row = $db->fetch_array($result)) $db->unbuffered_query("UPDATE bb".$n."_users SET userposts=userposts-'$row[posts]' WHERE userid='$row[userid]'", 1);
}
/** delete attachments **/
$attachmentcount = 0;
if ($thread['attachments']) {
$result = $db->query("SELECT attachmentid FROM bb".$n."_posts WHERE postid IN ($postids) AND attachmentid>0");
while ($row = $db->fetch_array($result)) {
$attachmentids .= ",".$row['attachmentid'];
$attachmentcount++;
}
$result = $db->query("SELECT attachmentid, attachmentextension FROM bb".$n."_attachments WHERE attachmentid IN (0$attachmentids)");
while ($row = $db->fetch_array($result)) @unlink("attachments/attachment-".$row['attachmentid'].".".$row['attachmentextension']);
$db->unbuffered_query("DELETE FROM bb".$n."_attachments WHERE attachmentid IN (0$attachmentids)", 1);
}
$db->query("DELETE FROM bb".$n."_posts WHERE postid IN ($postids)");
/* update global postcount */
$db->unbuffered_query("UPDATE bb".$n."_stats SET postcount=postcount-'".$postcount."'", 1);
/* update board & thread count */
$db->query("UPDATE bb".$n."_boards SET postcount=postcount-'$postcount' WHERE boardid IN ($boardid,$board[parentlist])");
$result = $db->query_first("SELECT userid, username, posttime FROM bb".$n."_posts WHERE threadid='$threadid' ORDER BY posttime DESC", 1);
$db->query("UPDATE bb".$n."_threads SET replycount=replycount-'$postcount', lastposttime='$result[posttime]', lastposterid='$result[userid]', lastposter='".addslashes($result['username'])."'".(($attachmentcount != 0) ? (", attachments=attachments-'$attachmentcount'") : (""))." WHERE threadid='$threadid'");
updateBoardInfo("$boardid,$board[parentlist]", $thread['lastposttime']);
}
/** move a thread **/
function movethread($threadid, $mode, $newboardid) {
global $board, $thread, $db, $n, $newboard, $default_prefix;
$boardid = $board['boardid'];
if (!is_array($newboard)) $newboard = $db->query_first("SELECT * FROM bb".$n."_boards WHERE boardid = '$newboardid'");
if ($mode == "onlymove" || $mode == "movewithredirect") {
if ($thread['important'] == 2) {
list($announcements) = $db->query_first("SELECT COUNT(*) FROM bb".$n."_announcements WHERE threadid='$threadid'");
if ($announcements > 1) $db->query("INSERT IGNORE INTO bb".$n."_announcements (boardid,threadid) VALUES ('$newboardid','$threadid')");
else $db->query("UPDATE bb".$n."_announcements SET boardid='$newboardid' WHERE threadid='$threadid' AND boardid='$boardid'");
}
// verify prefix
$prefix = $thread['prefix'];
if ($thread['prefix'] != '') {
// get allowed prefixes in newboard
if ($newboard['prefixuse'] == 1) $ch_prefix = $default_prefix;
if ($newboard['prefixuse'] == 2) $ch_prefix = $default_prefix."\n".$newboard['prefix'];
if ($newboard['prefixuse'] == 3) $ch_prefix = $newboard['prefix'];
else $ch_prefix = "";
$ch_prefix = preg_replace("/\s*\n\s*/", "\n", wbb_trim($ch_prefix));
$ch_prefix = explode("\n", $ch_prefix);
// thread's prefix is not allowed in new board -> delete prefix
if (!in_array($thread['prefix'], $ch_prefix)) {
$prefix='';
}
}
$db->query("DELETE FROM bb".$n."_threads WHERE boardid='$newboardid' AND pollid='$threadid' AND closed='3'");
$db->query("UPDATE bb".$n."_threads SET boardid='$newboardid'".(($thread['prefix']!=$prefix) ? ",prefix='".addslashes($prefix)."'" : "")." WHERE threadid='$threadid'");
if ($mode=="movewithredirect") $db->query("INSERT INTO bb".$n."_threads (boardid,prefix,topic,iconid,starttime,starterid,starter,lastposttime,lastposterid,lastposter,replycount,views,closed,voted,votepoints,pollid,visible) VALUES ('$boardid','".addslashes($prefix)."','".addslashes($thread['topic'])."','$thread[iconid]','$thread[starttime]','$thread[starterid]','".addslashes($thread['starter'])."','$thread[lastposttime]','$thread[lastposterid]','".addslashes($thread['lastposter'])."','$thread[replycount]','$thread[views]','3','$thread[voted]','$thread[votepoints]','$threadid','$thread[visible]')");
$thread['replycount']+=1;
$db->query("UPDATE bb".$n."_boards SET threadcount=threadcount-1, postcount=postcount-'$thread[replycount]' WHERE boardid IN ($boardid,$board[parentlist])");
$db->query("UPDATE bb".$n."_boards SET threadcount=threadcount+1, postcount=postcount+'$thread[replycount]' WHERE boardid IN ($newboardid,$newboard[parentlist])");
if ($board['lastthreadid']==$threadid) updateBoardInfo("$boardid,$board[parentlist]",0,$threadid);
if ($newboard['lastposttime']<=$thread['lastposttime']) updateBoardInfo("$newboardid,$newboard[parentlist]",$thread['lastposttime']);
if ($board['countuserposts']==1 && $newboard['countuserposts']==0) {
$result = $db->query("SELECT COUNT(postid) AS posts, userid FROM bb".$n."_posts WHERE threadid='$threadid' AND visible = 1 AND userid>0 GROUP BY userid");
while ($row=$db->fetch_array($result)) $db->query("UPDATE bb".$n."_users SET userposts=userposts-'$row[posts]' WHERE userid='$row[userid]'");
}
if ($board['countuserposts']==0 && $newboard['countuserposts']==1) {
$result = $db->query("SELECT COUNT(postid) AS posts, userid FROM bb".$n."_posts WHERE threadid='$threadid' AND visible = 1 AND userid>0 GROUP BY userid");
while ($row=$db->fetch_array($result)) $db->query("UPDATE bb".$n."_users SET userposts=userposts+'$row[posts]' WHERE userid='$row[userid]'");
}
}
if ($mode == "copy") {
$db->query("INSERT INTO bb".$n."_threads (boardid,topic,iconid,starttime,starterid,starter,lastposttime,lastposterid,lastposter,replycount,views,closed,voted,votepoints,attachments,pollid,important,visible)
VALUES ('$newboardid','".addslashes($thread[topic])."','$thread[iconid]','$thread[starttime]','$thread[starterid]','".addslashes($thread[starter])."','$thread[lastposttime]','$thread[lastposterid]','".addslashes($thread[lastposter])."','$thread[replycount]','$thread[views]','$thread[closed]','$thread[voted]','$thread[votepoints]','$thread[attachments]','$thread[pollid]','$thread[important]','$thread[visible]')");
$newthreadid = $db->insert_id();
// copy poll (ignore votes)
if ($thread['pollid'] != 0) {
$poll = $db->query_first("SELECT * FROM bb".$n."_polls WHERE pollid='$thread[pollid]'");
$db->query("INSERT INTO bb".$n."_polls (threadid, question, starttime, choicecount, timeout) ".
"VALUES ('$newthreadid', '".addslashes($poll['question'])."', '$poll[starttime]', '$poll[choicecount]', '$poll[timeout]')");
$newpollid = $db->insert_id();
$db->query("UPDATE bb".$n."_threads SET pollid = '$newpollid' WHERE threadid = '$newthreadid'");
$insert_str = '';
$result = $db->query("SELECT * FROM bb".$n."_polloptions WHERE pollid = '$thread[pollid]'");
while ($row = $db->fetch_array($result)) {
$insert_str .= ",('$newpollid', '".addslashes($row['polloption'])."', '$row[votes]', '$row[showorder]')";
}
if ($insert_str != '') $db->query("INSERT INTO bb".$n."_polloptions (pollid, polloption, votes, showorder) VALUES ".wbb_substr($insert_str, 1));
}
$result = $db->query("SELECT * FROM bb".$n."_announcements WHERE threadid='$threadid'");
if ($db->num_rows($result)) {
while ($row=$db->fetch_array($result)) $db->query("INSERT INTO bb".$n."_announcements (boardid,threadid) VALUES ('$row[boardid]','$newthreadid')");
$db->query("INSERT IGNORE INTO bb".$n."_announcements (boardid,threadid) VALUES ('$newboardid','$newthreadid')");
}
$attachmentPostIDs = array();
$newPostIDs = array();
$oldPostIDs = array();
$result = $db->query("SELECT * FROM bb".$n."_posts WHERE threadid='$threadid'");
while ($row = $db->fetch_array($result)) {
$db->query("INSERT INTO bb".$n."_posts (parentpostid,threadid,userid,username,iconid,posttopic,posttime,message,attachmentid,edittime,editorid,editor,editcount,allowsmilies,allowhtml,allowbbcode,allowimages,showsignature,ipaddress,visible,reindex)
VALUES ('".((isset($newPostIDs[$row['parentpostid']]) && $newPostIDs[$row['parentpostid']]) ? ($newPostIDs[$row['parentpostid']]) : ($row['parentpostid']))."','$newthreadid','$row[userid]','".addslashes($row[username])."','$row[iconid]','".addslashes($row[posttopic])."','$row[posttime]','".addslashes($row[message])."','$row[attachmentid]','$row[edittime]','$row[editorid]','".addslashes($row[editor])."','$row[editcount]','$row[allowsmilies]','$row[allowhtml]','$row[allowbbcode]','$row[allowimages]','$row[showsignature]','$row[ipaddress]','$row[visible]','1')");
$newPostIDs[$row['postid']] = $db->insert_id();
if (!isset($newPostIDs[$row['parentpostid']]) && !$newPostIDs[$row['parentpostid']]) {
$oldPostIDs[$row['postid']] = $newPostIDs[$row['postid']];
$oldPostIDs[$newPostIDs[$row['postid']]] = $row['parentpostid'];
}
if ($row['attachmentid']) {
$attachmentPostIDs[$row['postid']] = $newPostIDs[$row['postid']];
}
}
// rebuild threaded view
if (count($oldPostIDs)) {
foreach ($oldPostIDs as $newPostID => $oldparentpostID) {
$db->unbuffered_query("UPDATE bb".$n."_posts SET parentpostid = '".intval($newPostIDs[$oldparentpostID])."' WHERE postid = '".$newPostID."'", 1);
}
}
// copy attachments
if (count($attachmentPostIDs) > 0) {
$result = $db->query("SELECT * FROM bb".$n."_attachments WHERE postid IN (".implode(',', array_keys($attachmentPostIDs)).")");
while ($row = $db->fetch_array($result)) {
$db->query("INSERT INTO bb".$n."_attachments (postid, attachmentname, attachmentextension, attachmentsize, counter) ".
"VALUES ('".$attachmentPostIDs[$row['postid']]."', '".addslashes($row['attachmentname'])."', '".addslashes($row['attachmentextension'])."', '$row[attachmentsize]', '$row[counter]')");
$newattachmentid = $db->insert_id();
@copy('attachments/attachment-'.$row['attachmentid'].'.'.$row['attachmentextension'], 'attachments/attachment-'.$newattachmentid.'.'.$row['attachmentextension']);
@chmod('attachments/attachment-'.$newattachmentid.'.'.$row['attachmentextension'], 0777);
$db->query("UPDATE bb".$n."_posts SET attachmentid = '$newattachmentid' WHERE postid = '".$attachmentPostIDs[$row['postid']]."'");
}
}
$thread['replycount']+=1;
$db->query("UPDATE bb".$n."_boards SET threadcount=threadcount+1, postcount=postcount+'$thread[replycount]' WHERE boardid IN ($newboardid,$newboard[parentlist])");
if ($newboard['lastposttime']<=$thread['lastposttime']) updateBoardInfo("$newboardid,$newboard[parentlist]",$thread['lastposttime']);
if ($newboard['countuserposts']==1) {
$result = $db->query("SELECT COUNT(postid) AS posts, userid FROM bb".$n."_posts WHERE threadid='$newthreadid' AND visible = 1 AND userid>0 GROUP BY userid");
while ($row=$db->fetch_array($result)) $db->query("UPDATE bb".$n."_users SET userposts=userposts+'$row[posts]' WHERE userid='$row[userid]'");
}
/* update global threadcount & postcount */
$db->unbuffered_query("UPDATE bb".$n."_stats SET threadcount=threadcount+1, postcount=postcount+'".$thread['replycount']."'", 1);
}
}
?> |