forked from Xkeeper0/jul
-
Notifications
You must be signed in to change notification settings - Fork 1
/
admin-repair.php
261 lines (230 loc) · 8.41 KB
/
admin-repair.php
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
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
<?php
$meta['cache'] = true;
require "lib/common.php";
admincheck();
$_POST['run'] = filter_int($_POST['run']);
if ($_POST['run'])
check_token($_POST['auth']);
pageheader("Thread Repair System");
print adminlinkbar();
switch ($_POST['run']) {
case 0:
?>
<style>
.opt { padding: 8px 0; text-align: left; margin: auto; width: 600px }
.opt > input, .opt > div { display: inline-block; vertical-align: middle }
</style>
<form method="POST" action="?">
<table class='table'>
<tr><td class='tdbgh center'>Thread Repair System</td></tr>
<tr><td class='tdbg1 center'>
This page is intended to perform "repair" tasks, which may or may not take a while to finish.<br/>
Please don't flood it with requests.</br>
<br/>
Select the task to perform:<br/>
<?=
_opt(1,
"Fix counters",
"Repairs threads and forums with broken reply counts.
<br>This problem causes \"phantom pages\" (e.g., too few or too many pages displayed).")
._opt(2,
"Fix thread last reply data",
"Repairs threads with broken 'last reply' times/users.
<br>This problem causes bumped threads that shouldn't be, especially with badly deleted posts.")
?>
<input type="submit" name="submit" value="Start"/><?= auth_tag() ?>
</td></tr>
</table>
</form>
<?php
break;
case 1:
print "
<table class='table'>
<tr><td class='tdbgh center'>Thread Repair System</td></tr>
<tr><td class='tdbg1 center'>Now running.
</td></tr>
</table>
<br>
<table class='table'>
<tr>
<td class='tdbgh center'>id#</td>
<td class='tdbgh center'>Name</td>
<td class='tdbgh center'>Reports</td>
<td class='tdbgh center'>Real</td>
<td class='tdbgh center'>Err</td>
<td class='tdbgh center'>Status</td>
</tr>
";
$threads = $sql->query("
SELECT p.thread, t.title threadname,
COUNT(p.id) 'real', ((COUNT(p.id) - 1) - CAST(t.replies AS SIGNED)) offset, t.replies
FROM posts p
LEFT JOIN threads t ON p.thread = t.id
GROUP BY p.thread
HAVING offset != 0 OR offset IS NULL
ORDER BY ISNULL(threadname) ASC, p.thread DESC
");
$count = "";
$update = $sql->prepare("UPDATE threads SET replies = ? WHERE id = ?");
while ($data = $sql->fetch($threads)) {
$status = "";
if ($data['replies'] === NULL) {
$status = "<span style='color: #ff8080'>Invalid thread</span>";
$data['threadname'] = "<em>(Deleted thread)</em>";
$data['replies'] = $data['offset'] = "—";
} else {
$status = _status($sql->execute($update, [$data['real']-1, $data['thread']]));
$count++;
$data['replies']++;
$data['threadname'] = htmlspecialchars($data['threadname']);
}
print "
<tr>
<td class='tdbg1 center'><a href='thread.php?id={$data['thread']}'>{$data['thread']}</a></td>
<td class='tdbg2'><a href='thread.php?id={$data['thread']}'>{$data['threadname']}</a></td>
<td class='tdbg1 right'>{$data['replies']}</td>
<td class='tdbg1 right'>{$data['real']}</td>
<td class='tdbg2 right b'>{$data['offset']}</td>
<td class='tdbg1'>{$status}</td>
</tr>";
}
if ($count) {
print "<tr><td class='tdbgc center' colspan=6>$count thread". ($count != 1 ? "s" : "") ." updated.</td></tr>";
} else {
print "<tr><td class='tdbg1 center' colspan=6> <br>No problems found.<br> </td></tr>";
}
print "</table>
<br>
<table class='table'>
<tr><td class='tdbgh center'>Forum Repair System</td></tr>
<tr><td class='tdbg1 center'>Now running.
</td></tr>
</table>
<br>
<table class='table'>
<tr>
<td class='tdbgh center' rowspan='2'>id#</td>
<td class='tdbgh center' rowspan='2'>Forum Name</td>
<td class='tdbgh center' colspan='3'>Posts</td>
<td class='tdbgh center' colspan='3'>Threads</td>
<td class='tdbgh center' rowspan='2'>Status</td>
</tr>
<tr>
<td class='tdbgh center'>Reports</td>
<td class='tdbgh center'>Real</td>
<td class='tdbgh center'>Err</td>
<td class='tdbgh center'>Reports</td>
<td class='tdbgh center'>Real</td>
<td class='tdbgh center'>Err</td>
</tr>";
$forums = $sql->query("
SELECT f.id, f.title forumname,
COUNT(p.id) preal, (COUNT(p.id) - CAST(f.numposts AS SIGNED)) poffset, f.numposts,
COUNT(DISTINCT(t.id)) treal, (COUNT(DISTINCT(t.id)) - CAST(f.numthreads AS SIGNED)) toffset, f.numthreads
FROM forums f
LEFT JOIN threads t ON f.id = t.forum
LEFT JOIN posts p ON t.id = p.thread
GROUP BY f.id
HAVING poffset != 0 OR toffset != 0
ORDER BY f.id ASC
");
$count = "";
$update = $sql->prepare("UPDATE forums SET numposts = ?, numthreads = ? WHERE id = ?");
while ($data = $sql->fetch($forums)) {
$status = _status($sql->execute($update, [$data['preal'], $data['treal'], $data['id']]));
$count++;
print "
<tr>
<td class='tdbg1 center'><a href='forum.php?id={$data['id']}'>{$data['id']}</a></td>
<td class='tdbg2'><a href='forum.php?id={$data['id']}'>".htmlspecialchars($data['forumname'])."</a></td>
<td class='tdbg1 right'>{$data['numposts']}</td>
<td class='tdbg1 right'>{$data['preal']}</td>
<td class='tdbg2 right b'>{$data['poffset']}</td>
<td class='tdbg1 right'>{$data['numthreads']}</td>
<td class='tdbg1 right'>{$data['treal']}</td>
<td class='tdbg2 right b'>{$data['toffset']}</td>
<td class='tdbg1'>{$status}</td>
</tr>";
}
if ($count) {
print "<tr><td class='tdbgc center' colspan=9>$count forum". ($count != 1 ? "s" : "") ." updated.</td></tr>";
} else {
print "<tr><td class='tdbg1 center' colspan=9> <br>No problems found.<br> </td></tr>";
}
print "</table>";
break;
case 2:
print "
<table class='table'>
<tr><td class='tdbgh center'>Thread Repair System II</td></tr>
<tr><td class='tdbg1 center'>Now running.
</td></tr>
</table>
<br>
<table class='table'>
<tr>
<td class='tdbgh center'>id#</td>
<td class='tdbgh center'>Name</td>
<td class='tdbgh center'>Reported Date</td>
<td class='tdbgh center'>Real Date</td>
<td class='tdbgh center'>Difference</td>
<td class='tdbgh center'>Status</td>
</tr>
";
$threads = $sql->query("
SELECT t.id, t.title, t.lastpostdate, p.date as realdate
FROM threads t
LEFT JOIN (SELECT MAX(date) as date, thread FROM posts GROUP BY thread) p ON p.thread = t.id
WHERE t.lastpostdate != p.date
ORDER BY t.id DESC
");
$count = "";
$update = $sql->prepare("UPDATE threads SET lastposter = ?, lastpostdate = ? WHERE id = ?");
while ($data = $sql->fetch($threads)) {
$status = "";
if (!$data['lastpostdate'] && $data['realdate'] === NULL) {
$status = "<font color=#ff8888>Broken thread</font>";
} else {
$userd = $sql->fetchq("SELECT date, user FROM posts WHERE thread = '{$data['id']}' ORDER BY date DESC LIMIT 1");
$status = _status($sql->execute($update, [$userd['user'], $userd['date'], $data['id']]));
$count++;
}
print "
<tr>
<td class='tdbg1 center'>{$data['id']}</td>
<td class='tdbg2'><a href='thread.php?id={$data['id']}'>".htmlspecialchars($data['title'])."</a></td>
<td class='tdbg1 center'>".($data['lastpostdate'] ? printdate($data['lastpostdate']) : "-")."</td>
<td class='tdbg1 center'>".($data['realdate'] ? printdate($data['realdate']) : "-")."</td>
<td class='tdbg1 center'>".timeunits2($data['lastpostdate'] - $data['realdate'])."</td>
<td class='tdbg2'>{$status}</td>
</tr>";
}
if ($count) {
print "<tr><td class='tdbgc center' colspan=6>$count thread". ($count != 1 ? "s" : "") ." updated.</td></tr>";
} else {
print "<tr><td class='tdbgc center' colspan=6>Nothing to repair.</td></tr>";
}
print "</table>";
break;
default:
errorpage("Invalid selection.");
}
if ($_POST['run'])
print '<div class="tdbg1 center" style="margin-top: 16px">Click <a href="?">here</a> to return to the previous page.</div>';
pagefooter();
function _opt($id, $title, $desc) {
print '
<div class="opt">
<input type="radio" name="run" id="lx'.$id.'" value="'.$id.'">
<div class="lbl">
<label for="lx'.$id.'">'.$title.'</label>
<div class="fonts">'.$desc.'</div>
</div>
</div>';
}
function _status($status) {
return $status
? "<span style='color: #80ff80'>Updated</span>"
: "<span style='color: #ff0000'>Error</span>";
}