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:
|
<?php
/** connect db **/
require('./lib/config.inc.php');
require('./lib/class_db_mysql.php');
$db = new db($sqlhost, $sqluser, $sqlpassword, $sqldb, $phpversion);
unset($sqlhost, $sqluser, $sqlpassword);
// alle Statistiken updaten
// Snippet aus /acp/otherstuff.php
/** update stats **/
list($threadcount) = $db->query_first("SELECT COUNT(*) FROM bb".$n."_threads WHERE closed<>3 AND visible=1");
list($postcount) = $db->query_first("SELECT COUNT(*) FROM bb".$n."_posts WHERE visible=1");
$user = $db->query_first("SELECT COUNT(*) AS usercount, MAX(userid) AS userid FROM bb".$n."_users");
$db->unbuffered_query("UPDATE bb".$n."_stats SET threadcount='".$threadcount."', postcount='".$postcount."', usercount='".$user['usercount']."', lastuserid='".$user['userid']."'", 1);
/** userposts **/
$perpage = 5000;
if (isset($_REQUEST['page'])) $page = intval($_REQUEST['page']);
else $page = 0;
if ($page < 1) $page = 1;
list($totalcount) = $db->query_first("SELECT COUNT(*) FROM bb".$n."_users");
$pages = ceil($totalcount / $perpage);
if ($page <= $pages) {
$result = $db->query("SELECT userid, userposts FROM bb".$n."_users ORDER BY userid ASC", $perpage, $perpage * ($page - 1));
while ($row = $db->fetch_array($result)) {
list($userposts) = $db->query_first("SELECT COUNT(postid) FROM bb".$n."_posts p, bb".$n."_threads t LEFT JOIN bb".$n."_boards b ON (t.boardid=b.boardid) WHERE t.threadid=p.threadid AND p.userid='$row[userid]' AND p.visible=1 AND b.countuserposts=1");
if ($userposts != $row['userposts']) $db->unbuffered_query("UPDATE bb".$n."_users SET userposts='$userposts' WHERE userid='$row[userid]'", 1);
}
}
/** private message counters **/
$perpage = 5000;
if (isset($_REQUEST['page'])) $page = intval($_REQUEST['page']);
else $page = 0;
if ($page < 1) $page = 1;
list($totalcount) = $db->query_first("SELECT COUNT(*) FROM bb".$n."_users");
$pages = ceil($totalcount / $perpage);
if ($page <= $pages) {
$result = $db->query("SELECT userid, lastvisit FROM bb".$n."_users ORDER BY userid ASC", $perpage, $perpage * ($page - 1));
while ($row = $db->fetch_array($result)) {
// reset counters
$pmtotalcount = 0;
$outbox_count = 0;
$pmnewcount = 0;
$pmunreadcount = 0;
// count PMs in the user's folders (except outbox)
$pm_result = $db->query("SELECT pmr.view, p.sendtime ".
"FROM bb".$n."_privatemessagereceipts pmr ".
"LEFT JOIN bb".$n."_privatemessage p ON (p.privatemessageid = pmr.privatemessageid) ".
"WHERE pmr.recipientid = '$row[userid]' AND pmr.deletepm = 0");
while ($pm_row = $db->fetch_array($pm_result)) {
$pmtotalcount++;
if ($pm_row['view'] == 0) {
$pmunreadcount++;
if ($pm_row['sendtime'] > $row['lastvisit']) $pmnewcount++;
}
}
// count PMs in the user's outbox
list($outbox_count) = $db->query_first("SELECT COUNT(*) FROM bb".$n."_privatemessage WHERE senderid = '".$row['userid']."' AND inoutbox = 1");
$pmtotalcount += $outbox_count;
$pminboxcount = $pmtotalcount - $outbox_count;
$db->unbuffered_query("UPDATE bb".$n."_users SET pmtotalcount='$pmtotalcount', pminboxcount='$pminboxcount', pmnewcount='$pmnewcount', pmunreadcount='$pmunreadcount' WHERE userid='$row[userid]'", 1);
}
}
/** threads **/
$perpage = 5000;
if (isset($_REQUEST['page'])) $page = intval($_REQUEST['page']);
else $page = 0;
if ($page < 1) $page = 1;
list($totalcount) = $db->query_first("SELECT COUNT(*) FROM bb".$n."_threads");
$pages = ceil($totalcount / $perpage);
if ($page <= $pages) {
$result = $db->query("SELECT MIN(p.postid) AS minpost, MAX(p.postid) AS maxpost, t.threadid, MIN(p.posttime) AS starttime, MAX(p.posttime) AS lastposttime,
(COUNT(*)-1) AS posts
FROM bb".$n."_posts p, bb".$n."_threads t
WHERE t.threadid=p.threadid
GROUP BY t.threadid", $perpage, $perpage * ($page - 1));
while ($row = $db->fetch_array($result)) {
$start = $db->query_first("SELECT p.userid, p.username, u.username AS realusername FROM bb".$n."_posts p LEFT JOIN bb".$n."_users u USING(userid) WHERE postid='$row[minpost]'");
$lastpost = $db->query_first("SELECT p.userid, p.username, u.username AS realusername FROM bb".$n."_posts p LEFT JOIN bb".$n."_users u USING(userid) WHERE postid='$row[maxpost]'");
$attachments = $db->query_first("SELECT COUNT(*) as count FROM bb".$n."_posts p, bb".$n."_attachments a WHERE p.threadid = '".$row['threadid']."' AND a.postid = p.postid");
if ($start['userid'] == 0) $starter = $start['username'];
else $starter = $start['realusername'];
if ($lastpost['userid'] == 0) $lastposter = $lastpost['username'];
else $lastposter = $lastpost['realusername'];
$db->unbuffered_query("UPDATE bb".$n."_threads SET attachments='".$attachments['count']."', starttime='$row[starttime]', lastposttime='$row[lastposttime]', starterid='$start[userid]', lastposterid='$lastpost[userid]', starter='".addslashes($starter)."', lastposter='".addslashes($lastposter)."', replycount='$row[posts]' WHERE threadid='$row[threadid]'", 1);
}
}
/** boards **/
$perpage = 100;
if (isset($_REQUEST['page'])) $page = intval($_REQUEST['page']);
else $page = 0;
if ($page < 1) $page = 1;
list($totalcount) = $db->query_first("SELECT COUNT(*) FROM bb".$n."_boards");
$pages = ceil($totalcount / $perpage);
if ($page <= $pages) {
$result = $db->query("SELECT * FROM bb".$n."_boards", $perpage, $perpage * ($page - 1));
while ($row = $db->fetch_array($result)) {
list($threadcount) = $db->query_first("SELECT COUNT(*) FROM bb".$n."_threads WHERE boardid IN ($row[boardid],$row[childlist]) AND visible=1 AND closed <> 3");
list($postcount) = $db->query_first("SELECT COUNT(*) FROM bb".$n."_posts p, bb".$n."_threads t WHERE p.threadid=t.threadid AND t.boardid IN ($row[boardid],$row[childlist]) AND p.visible=1");
$lastpost = $db->query_first("SELECT p.threadid, p.userid, p.username, p.posttime FROM bb".$n."_posts p, bb".$n."_threads t WHERE p.threadid=t.threadid AND t.boardid IN ($row[boardid],$row[childlist]) AND p.visible=1 ORDER BY p.posttime DESC", 1);
$db->unbuffered_query("UPDATE bb".$n."_boards SET lastthreadid='$lastpost[threadid]', lastposttime='$lastpost[posttime]', lastposterid='$lastpost[userid]', lastposter='".addslashes($lastpost['username'])."', postcount='$postcount', threadcount='$threadcount' WHERE boardid='$row[boardid]'", 1);
}
}
/** ranks **/
$perpage = 5000;
if (isset($_REQUEST['page'])) $page = intval($_REQUEST['page']);
else $page = 0;
if ($page < 1) $page = 1;
list($totalcount) = $db->query_first("SELECT COUNT(*) FROM bb".$n."_users");
$pages = ceil($totalcount / $perpage);
if ($page <= $pages) {
$result = $db->query("SELECT userid, rankgroupid, gender, userposts FROM bb".$n."_users", $perpage, $perpage * ($page - 1));
while ($row = $db->fetch_array($result)) {
list($rankid) = $db->query_first("SELECT rankid FROM bb".$n."_ranks WHERE groupid IN ('0','$row[rankgroupid]') AND needposts<='$row[userposts]' AND gender IN ('0','$row[gender]') ORDER BY needposts DESC, gender DESC", 1);
$db->unbuffered_query("UPDATE bb".$n."_users SET rankid='$rankid' WHERE userid='$row[userid]'", 1);
}
}
/** reindex **/
$perpage = 100;
if (isset($_REQUEST['page'])) $page = intval($_REQUEST['page']);
else $page = 0;
if ($page < 1) $page = 1;
if (isset($_REQUEST['totalcount'])) $totalcount = intval($_REQUEST['totalcount']);
else list($totalcount) = $db->query_first("SELECT COUNT(*) FROM bb".$n."_posts WHERE reindex=1");
$pages = ceil($totalcount / $perpage);
$caching = array();
if ($page <= $pages) {
$result = $db->unbuffered_query("SELECT postid, message, posttopic FROM bb".$n."_posts WHERE reindex=1 ORDER BY postid ASC", 0, $perpage);
$postids = "0";
while ($row = $db->fetch_array($result)) {
$caching[] = $row;
$postids .= ",".$row['postid'];
}
$db->unbuffered_query("DELETE FROM bb".$n."_wordmatch WHERE postid IN ($postids)", 1);
$db->query("LOCK TABLES bb".$n."_wordmatch WRITE, bb".$n."_wordlist WRITE;");
foreach ($caching as $key => $val) {
wordmatch($val['postid'], $val['message'], $val['posttopic']);
unset($caching[$key]);
unset($val);
unset($key);
}
$db->query("UNLOCK TABLES;");
$db->unbuffered_query("UPDATE bb".$n."_posts SET reindex=0 WHERE postid IN ($postids)", 1);
}
?>
|