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
282
283
284
285
286
287
288
289
|
<?php
include "../../src/emote.php";
include "../../src/accounts.php";
include_once "../../src/config.php";
include "../../src/partials.php";
include "../../src/utils.php";
include "../../src/alert.php";
authorize_user();
$db = new PDO(DB_URL, DB_USER, DB_PASS);
function display_list_emotes(PDO &$db, int $page, int $limit): array
{
$search = "%" . ($_GET["q"] ?? "") . "%";
$user_id = $_SESSION["user_id"] ?? "-1";
$offset = $page * $limit;
$stmt = $db->prepare("SELECT e.*,
CASE WHEN EXISTS (
SELECT 1
FROM emote_set_contents ec
INNER JOIN emote_sets es ON es.id = ec.emote_set_id
WHERE ec.emote_id = e.id AND es.owner_id = ?
) THEN 1 ELSE 0 END AS is_in_user_set
FROM emotes e WHERE e.code LIKE ?
ORDER BY e.created_at ASC
LIMIT ? OFFSET ?
");
$stmt->bindParam(1, $user_id, PDO::PARAM_INT);
$stmt->bindParam(2, $search, PDO::PARAM_STR);
$stmt->bindParam(3, $limit, PDO::PARAM_INT);
$stmt->bindParam(4, $offset, PDO::PARAM_INT);
$stmt->execute();
$emotes = [];
$rows = $stmt->fetchAll();
foreach ($rows as $row) {
array_push($emotes, new Emote(
$row["id"],
$row["code"],
$row["ext"],
intval(strtotime($row["created_at"])),
$row["uploaded_by"],
$row["is_in_user_set"]
));
}
return $emotes;
}
function display_emote(PDO &$db, int $id)
{
$stmt = $db->prepare("SELECT * FROM emotes WHERE id = ?");
$stmt->execute([$id]);
$emote = null;
if ($row = $stmt->fetch()) {
$emote = new Emote(
$row["id"],
$row["code"],
$row["ext"],
intval(strtotime($row["created_at"])),
$row["uploaded_by"],
false
);
}
if ($emote == null) {
header("Location: /404.php");
exit;
}
return $emote;
}
$emotes = null;
$emote = null;
$id = $_GET["id"] ?? "";
$db = new PDO(DB_URL, DB_USER, DB_PASS);
if ($id == "" || !is_numeric($id)) {
$page = intval($_GET["p"] ?? "0");
$limit = 50;
$emotes = display_list_emotes($db, $page, $limit);
} else {
$emote = display_emote($db, intval($id));
}
?>
<html>
<head>
<title><?php
echo empty($emotes) ? "Emote " . $emote->get_code() : "Emotes"
?> - alright.party</title>
<link rel="stylesheet" href="/static/style.css">
</head>
<body>
<div class="container">
<div class="wrapper">
<?php html_navigation_bar() ?>
<section class="content row">
<section class="sidebar">
<?php html_navigation_search() ?>
</section>
<section class="content">
<?php display_alert() ?>
<section class="box">
<div class="box navtab">
<?php echo empty($emotes) ? "Emote - " . $emote->get_code() : "Emotes" ?>
</div>
<?php
if (empty($emotes)) { ?>
<div class="box content">
<div class="emote-showcase">
<img src="/static/userdata/emotes/<?php echo $emote->get_id() . '/' . '1x.' . $emote->get_ext() ?>"
alt="<?php echo $emote->get_code() ?>">
<img src="/static/userdata/emotes/<?php echo $emote->get_id() . '/' . '2x.' . $emote->get_ext() ?>"
alt="<?php echo $emote->get_code() ?>">
<img src="/static/userdata/emotes/<?php echo $emote->get_id() . '/' . '3x.' . $emote->get_ext() ?>"
alt="<?php echo $emote->get_code() ?>">
</div>
</div>
</section>
<section class="box items row">
<?php if (isset($_SESSION["user_id"])) {
echo '' ?>
<div class="items row left full">
<?php
$added = false;
if (isset($_SESSION["user_emote_set_id"])) {
$stmt = $db->prepare("SELECT id FROM emote_set_contents WHERE emote_set_id = ? AND emote_id = ?");
$stmt->execute([$_SESSION["user_emote_set_id"], $emote->get_id()]);
$added = $stmt->rowCount() > 0;
}
?>
<form action="/emotes/setmanip.php" method="POST">
<input type="text" name="id" value="<?php echo $emote->get_id() ?>"
style="display: none;">
<?php
if ($added) { ?>
<input type="text" name="action" value="remove" style="display: none;">
<button type="submit" class="red">Remove from my channel</button>
<?php
} else { ?>
<input type="text" name="action" value="add" style="display: none;">
<button type="submit" class="green">Add to my channel</button>
<?php
}
?>
</form>
</div>
<div class="items row right full">
<?php
$stmt = $db->prepare("SELECT rate FROM ratings WHERE user_id = ? AND emote_id = ?");
$stmt->execute([$_SESSION["user_id"], $id]);
if ($row = $stmt->fetch()) {
echo 'You gave <img src="/static/img/icons/ratings/' . $row["rate"] . '.png" width="16" height="16"';
echo 'title="' . RATING_NAMES[$row["rate"]] . '">';
} else {
foreach (RATING_NAMES as $key => $value) {
echo '<form action="/emotes/rate.php" method="POST">';
echo '<input type="text" name="id" value="' . $emote->get_id() . '"style="display: none;">';
echo "<input type=\"text\" name=\"rate\" value=\"$key\" style=\"display:none;\">";
echo '<button type="submit" class="transparent">';
echo "<img
src=\"/static/img/icons/ratings/$key.png\" alt=\"$value!\"
title=\"IT'S A $value!\">";
echo '</button></form>';
}
}
?>
<a class="button red" href="/emotes/report.php?id=<?php echo $emote->get_id() ?>">Report
emote</a>
</div>
<?php
} else {
echo '' ?>
<p><a href="/account/login">Log in</a> to get additional features...</p>
<?php
}
?>
</section>
<section class="box">
<table class="vertical">
<tr>
<th>Uploader</th>
<td><?php
$username = "anonymous";
$link = "#";
if ($emote->get_uploaded_by()) {
$db = new PDO(DB_URL, DB_USER, DB_PASS);
$stmt = $db->prepare("SELECT username FROM users WHERE id = ?");
$stmt->execute([$emote->get_uploaded_by()]);
if ($row = $stmt->fetch()) {
$username = $row["username"];
$link = "/users.php?id=" . $emote->get_uploaded_by();
}
$db = null;
}
echo "<a href=\"$link\">";
echo $username;
echo "</a>";
echo ', <span title="';
echo date("M d, Y H:i:s", $emote->get_created_at());
echo ' UTC">about ' . format_timestamp(time() - $emote->get_created_at()) . " ago</span>";
?></td>
</tr>
<tr>
<th>Rating</th>
<td>Not rated</td>
</tr>
</table>
</section>
<section class="box">
<div class="content">
<?php
$db = new PDO(DB_URL, DB_USER, DB_PASS);
$stmt = $db->prepare("SELECT users.id, users.username
FROM users
INNER JOIN emote_sets AS es ON es.owner_id = users.id
INNER JOIN emote_set_contents AS ec ON ec.emote_set_id = es.id
WHERE ec.emote_id = ?");
$stmt->execute([$emote->get_id()]);
$count = $stmt->rowCount();
$db = null;
if ($count > 0) {
echo "<p>Added in $count channels</p>";
} else {
echo "No one has added this emote yet... :'(";
}
?>
<div class="items row">
<?php
while ($row = $stmt->fetch()) {
echo '<a href="/users.php?id=' . $row["id"] . '">' . $row["username"] . '</a>';
}
?>
</div>
</div>
<?php
} else { ?>
<div class="box content items">
<?php
foreach ($emotes as $e) {
echo '<a class="box emote" href="emotes?id=' . $e->get_id() . '">';
if ($e->is_added_by_user()) {
echo '<img src="/static/img/icons/yes.png" class="emote-check" />';
}
echo '<img src="/static/userdata/emotes/' . $e->get_id() . '/2x.' . $e->get_ext() . '" alt="' . $e->get_code() . '"/>';
echo '<p>' . $e->get_code() . '</p>';
echo '</a>';
}
?>
</div>
<?php
}
?>
</section>
</section>
</section>
</div>
</div>
</body>
</html>
|