-
Notifications
You must be signed in to change notification settings - Fork 1
/
index.php
281 lines (264 loc) · 14.3 KB
/
index.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
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
<?php
$PageTitle = "Home";
require "base.php";
require 'header.php';
?>
welcome to OMDB - a place to rate maps! discover new maps, check out people's ratings, AND STUFF. <br>
<span style="color:grey;">
<?php
$stmt = $conn->prepare("SELECT (SELECT COUNT(*) FROM `users`), COUNT(*) FROM `users` WHERE `LastAccessedSite` >= NOW() - INTERVAL 24 HOUR;");
$stmt->execute();
$result = $stmt->get_result();
$row = $result->fetch_row();
$usersCount = $row[0];
$usersOnlineCount = $row[1];
$stmt->close();
$stmt = $conn->prepare("SELECT COUNT(*) FROM `ratings`");
$stmt->execute();
$result = $stmt->get_result();
$ratingsCount = $result->fetch_row()[0];
$stmt->close();
$stmt = $conn->prepare("SELECT COUNT(*) FROM `comments`");
$stmt->execute();
$result = $stmt->get_result();
$commentsCount = $result->fetch_row()[0];
$stmt->close();
?>
<span title='<?php echo $usersOnlineCount; ?> within the last day' style='border-bottom:1px dotted white;'><?php echo $usersCount; ?> users</span>,
<?php echo $ratingsCount; ?> ratings,
<?php echo $commentsCount; ?> comments
</span>
<hr>
<div class="flex-container column-when-mobile-container">
<div class="flex-child column-when-mobile" style="width:40%;height:36em;overflow-y:scroll;position:relative;">
<?php
$stmt = $conn->prepare("SELECT r.*, b.DifficultyName, b.SetID FROM `ratings` r INNER JOIN `beatmaps` b ON r.BeatmapID = b.BeatmapID INNER JOIN `users` u on r.UserID = u.UserID WHERE b.Mode = ? and b.blacklisted = 0 and u.HideRatings = 0 ORDER BY r.date DESC LIMIT 60;");
$stmt->bind_param("i", $mode);
$stmt->execute();
$result = $stmt->get_result();
while($row = $result->fetch_assoc()) {
?>
<div class="flex-container ratingContainer alternating-bg">
<div class="flex-child" style="margin-left:0.5em;">
<a href="/mapset/<?php echo $row["SetID"]; ?>"><img src="https://b.ppy.sh/thumb/<?php echo $row["SetID"]; ?>l.jpg" class="diffThumb"/ onerror="this.onerror=null; this.src='/charts/INF.png';"></a>
</div>
<div class="flex-child">
<a style="display:flex;" href="/profile/<?php echo $row["UserID"]; ?>">
<img src="https://s.ppy.sh/a/<?php echo $row["UserID"]; ?>" style="height:24px;width:24px;" title="<?php echo GetUserNameFromId($row["UserID"], $conn); ?>"/>
</a>
</div>
<div class="flex-child" style="flex:0 0 66%;">
<a style="display:flex;" href="/profile/<?php echo $row["UserID"]; ?>">
<?php echo GetUserNameFromId($row["UserID"], $conn); ?>
</a>
<?php
echo RenderUserRating($conn, $row) . " on " . "<a href='/mapset/" . $row["SetID"] . "'>" . mb_strimwidth(htmlspecialchars($row["DifficultyName"]), 0, 35, "...") . "</a>";
?>
</div>
</div>
<?php
}
$stmt->close();
?>
</div>
<div class="flex-child column-when-mobile" style="width:60%;height:36em;overflow-y:scroll;">
<?php
$stmt = $conn->prepare("(SELECT c.*, 'beatmap' AS comment_type, NULL as Name, NULL as ProposalID
FROM comments c
WHERE NOT EXISTS (
SELECT 1
FROM user_relations r
WHERE c.UserID = r.UserIDTo AND r.UserIDFrom = ? AND r.type = 2
) AND EXISTS (
SELECT 1
FROM beatmaps b
WHERE b.SetID = c.SetID AND b.Mode = ?
)
)
UNION ALL
(
SELECT dpc.*, 'descriptor_proposal' AS comment_type, p.Name, dpc.ProposalID
FROM descriptor_proposal_comments dpc
LEFT JOIN descriptor_proposals p ON p.ProposalID = dpc.ProposalID
WHERE 1
)
ORDER BY date DESC
LIMIT 20;");
$stmt->bind_param("ii", $userId, $mode);
$stmt->execute();
$result = $stmt->get_result();
while ($row = $result->fetch_assoc()) {
$linkID = $row['comment_type'] === 'beatmap' ? "/mapset/{$row["SetID"]}" : "/descriptor/proposal/?id={$row["ProposalID"]}";
?>
<div class="flex-container ratingContainer alternating-bg">
<div class="flex-child" style="margin-left:0.5em;">
<?php if ($row["comment_type"] == 'beatmap') { ?>
<a href="/mapset/<?php echo $row["SetID"]; ?>"><img src="https://b.ppy.sh/thumb/<?php echo $row["SetID"]; ?>l.jpg" class="diffThumb"/ onerror="this.onerror=null; this.src='/charts/INF.png';"></a>
<?php } else { ?>
<div style="height: 32px;width: 32px;font-size: 16px;text-align:center;line-height: 32px;">
<i class="icon-pencil"></i>
</div>
<?php } ?>
</div>
<div class="flex-child">
<div>
<a href="/profile/<?php echo $row["UserID"]; ?>">
<img src="https://s.ppy.sh/a/<?php echo $row["UserID"]; ?>" style="height:24px;width:24px;" title="<?php echo GetUserNameFromId($row["UserID"], $conn); ?>"/>
<span><?php echo GetUserNameFromId($row["UserID"], $conn); ?></span>
</a>
<span>
<?php if ($row["comment_type"] == 'descriptor_proposal') { ?>
on <a href="<?php echo $linkID; ?>"><?php echo $row["Name"]; ?> descriptor</a>
<?php } ?>
</span>
</div>
<div style="flex:0 0 auto;text-overflow:ellipsis;min-width:0%;">
<a style="color:white;" href="<?php echo $linkID; ?>">
<?php
echo htmlspecialchars(mb_strimwidth($row["Comment"], 0, 180, "..."));
?>
</a>
</div>
</div>
</div>
<?php
}
$stmt->close();
?>
</div>
</div>
<br>
<div class="flex-container" style="width:100%;background-color:DarkSlateGrey;justify-content: space-around;padding:0px;">
<br>
<?php
$usedSets = array();
$stmt = $conn->prepare("SELECT * FROM cache_home_recent_maps WHERE Mode = ? ORDER BY Timestamp DESC;");
$stmt->bind_param("i", $mode);
$stmt->execute();
$result = $stmt->get_result();
while($row = $result->fetch_assoc()) {
if (in_array($row["SetID"], $usedSets))
continue;
if (sizeof($usedSets) >= 8)
break;
$artist = GetUserNameFromId($row["CreatorID"], $conn);
?>
<div class="flex-child" style="text-align:center;width:11%;padding:0.5em;display: inline-block;margin-left:auto;margin-right:auto;">
<a href="/mapset/<?php echo $row["SetID"]; ?>"><img src="https://b.ppy.sh/thumb/<?php echo $row["SetID"]; ?>l.jpg" class="diffThumb" style="aspect-ratio: 1 / 1;width:90%;height:auto;" onerror="this.onerror=null; this.src='/charts/INF.png';"></a><br>
<span class="subtext">
<a href="/mapset/<?php echo $row["SetID"]; ?>"><?php echo "{$row["Metadata"]}"; ?></a><br>
by <a href="/profile/<?php echo $row["CreatorID"]; ?>"><?php echo $artist; ?></a> <br>
<?php echo GetHumanTime($row["Timestamp"]); ?>
</span>
</div>
<?php
$usedSets[] = $row["SetID"];
}
$stmt->close();
?>
</div>
<br>
<div class="flex-container column-when-mobile-container">
<div class="flex-child column-when-mobile" style="width:50%;height:40em;background-color: darkslategray;padding: 0.5em;box-sizing:border-box;">
<h2 style="margin-top:0;">Highest charting map of the week</h2>
<?php
$stmt = $conn->prepare(
"SELECT b.BeatmapID, b.SetID, s.DateRanked, b.DifficultyName, b.WeightedAvg, b.RatingCount, b.ChartRank, b.ChartYearRank, s.Title
FROM beatmaps b
JOIN cache_home_best_map c ON b.BeatmapID = c.BeatmapID
JOIN beatmapsets s on b.SetID = s.SetID
WHERE
b.Rating IS NOT NULL
AND b.Mode = ?
LIMIT 1;");
$stmt->bind_param("i", $mode);
$stmt->execute();
$result = $stmt->get_result();
if ($result->num_rows >= 1) {
$result = $result->fetch_assoc();
$year = date("Y", strtotime($result['DateRanked']));
$stmt = $conn->prepare("
SELECT d.DescriptorID, d.Name
FROM descriptor_votes
JOIN descriptors d on descriptor_votes.DescriptorID = d.DescriptorID
WHERE BeatmapID = ?
GROUP BY DescriptorID
HAVING SUM(CASE WHEN Vote = 1 THEN 1 ELSE 0 END) > (SUM(CASE WHEN Vote = 0 THEN 1 ELSE 0 END) + 0)
ORDER BY (SUM(CASE WHEN Vote = 1 THEN 1 ELSE 0 END) - SUM(CASE WHEN Vote = 0 THEN 1 ELSE 0 END)) DESC, DescriptorID
LIMIT 5;");
$stmt->bind_param("i", $result["BeatmapID"]);
$stmt->execute();
$descriptorResult = $stmt->get_result();
} else {
$result = null;
}
$stmt->close();
?>
<?php if ($result != null) { ?>
<div style="width:100%;text-align:center;">
<a href="/mapset/<?php echo $result["SetID"]; ?>"><img src="https://assets.ppy.sh/beatmaps/<?php echo $result["SetID"]; ?>/covers/cover.jpg" style="width:100%;" onerror="this.onerror=null; this.src='/charts/INF.png';"></a>
<br><br>
<b><a href="/mapset/<?php echo $result["SetID"]; ?>"><?php echo "{$result["Title"]} [{$result["DifficultyName"]}]";?></a></b><br>
by <?php RenderBeatmapCreators($result['BeatmapID'], $conn); ?> <br>
<span class="subText map-descriptors">
<?php
$descriptorLinks = array();
while($descriptor = $descriptorResult->fetch_assoc()){
$descriptorLink = '<a style="color:inherit;" href="../descriptor/?id=' . $descriptor["DescriptorID"] . '">' . $descriptor["Name"] . '</a>';
$descriptorLinks[] = $descriptorLink;
}
echo implode(', ', $descriptorLinks);
?>
</span>
<br><br>
Ranked <?php echo date("M jS, Y", strtotime($result['DateRanked'])); ?> <br>
<b><?php echo number_format($result["WeightedAvg"], 2); ?></b> <span class="subText">/ 5.00 from <span style="color:white"><?php echo $result["RatingCount"]; ?></span> votes</span><br>
<b>#<?php echo $result["ChartYearRank"]; ?></b> for <a href="/charts/?y=<?php echo $year;?>&p=<?php echo ceil($result["ChartYearRank"] / 50); ?>"><?php echo $year;?></a>, <b>#<?php echo $result["ChartRank"]; ?></b> <a href="/charts/?y=all-time&p=<?php echo ceil($result["ChartRank"] / 50); ?>">overall</a><br>
</div>
<?php } else { echo "no maps for this week :("; } ?>
</div>
<div class="flex-child column-when-mobile" style="width:50%;height:40em;">
<?php
$stmt = $conn->prepare("SELECT b.BeatmapID, b.SetID, s.Title, b.DifficultyName, COUNT(r.BeatmapID) as num_ratings
FROM beatmaps b
JOIN beatmapsets s on b.SetID = s.SetID
INNER JOIN ratings r ON b.BeatmapID = r.BeatmapID
WHERE r.date >= NOW() - INTERVAL 1 WEEK
AND b.Mode = ? AND b.blacklisted = 0
GROUP BY b.BeatmapID
ORDER BY num_ratings DESC
LIMIT 25;");
$stmt->bind_param("i", $mode);
$stmt->execute();
$result = $stmt->get_result();
$usedSets = array();
while($row = $result->fetch_assoc()) {
if (in_array($row["SetID"], $usedSets))
continue;
?>
<div class="flex-container ratingContainer alternating-bg" style="height:4em;">
<div class="flex-child" style="min-width:2em;text-align:center;">
#<?php echo sizeof($usedSets) + 1; ?>
</div>
<div class="flex-child">
<a href="/mapset/<?php echo $row["SetID"]; ?>"><img src="https://b.ppy.sh/thumb/<?php echo $row["SetID"]; ?>l.jpg" class="diffThumb" onerror="this.onerror=null; this.src='/charts/INF.png';"></a>
</div>
<div class="flex-child" style="text-overflow: ellipsis;overflow:hidden;">
<a href="/mapset/<?php echo $row["SetID"]; ?>"><?php echo "{$row["Title"]} [{$row["DifficultyName"]}]";?></a>
</div>
<div class="flex-child" style="margin-left: auto;text-align:right;min-width:6em;">
<?php echo $row["num_ratings"];?> ratings
</div>
</div>
<?php
if (sizeof($usedSets) == 9)
break;
$usedSets[] = $row["SetID"];
}
$stmt->close();
?>
</div>
</div>
<?php
require 'footer.php';
?>