summaryrefslogtreecommitdiff
path: root/public
diff options
context:
space:
mode:
Diffstat (limited to 'public')
-rw-r--r--public/emotes/index.php20
1 files changed, 19 insertions, 1 deletions
diff --git a/public/emotes/index.php b/public/emotes/index.php
index 475e119..b3834c3 100644
--- a/public/emotes/index.php
+++ b/public/emotes/index.php
@@ -29,7 +29,7 @@ function display_list_emotes(PDO &$db, int $page, int $limit): array
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, COALESCE(SUM(r.rate), 0) AS rating
+ ) THEN 1 ELSE 0 END AS is_in_user_set, COALESCE(COUNT(r.rate), 0) AS rating
FROM emotes e
LEFT JOIN ratings AS r ON r.emote_id = e.id
WHERE e.code LIKE ?
@@ -89,6 +89,15 @@ function display_emote(PDO &$db, int $id)
}
if ($emote == null) {
+ if (CLIENT_REQUIRES_JSON) {
+ json_response([
+ "status_code" => 404,
+ "message" => "Emote ID $id does not exist",
+ "data" => null
+ ], 404);
+ exit;
+ }
+
header("Location: /404.php");
exit;
}
@@ -110,6 +119,15 @@ if ($id == "" || !is_numeric($id)) {
} else {
$emote = display_emote($db, intval($id));
}
+
+if (CLIENT_REQUIRES_JSON) {
+ json_response([
+ "status_code" => 200,
+ "message" => null,
+ "data" => $emotes ?? $emote
+ ]);
+ exit;
+}
?>
<html>