From d93351e0e5fffde6922f38d19a5848273aef6c40 Mon Sep 17 00:00:00 2001 From: ilotterytea Date: Thu, 24 Apr 2025 14:07:48 +0500 Subject: feat: emotesets --- public/emotesets.php | 191 +++++++++++++++++++++++++++++++++++++++++++++++++++ public/index.php | 1 + src/partials.php | 1 + 3 files changed, 193 insertions(+) create mode 100644 public/emotesets.php diff --git a/public/emotesets.php b/public/emotesets.php new file mode 100644 index 0000000..69df158 --- /dev/null +++ b/public/emotesets.php @@ -0,0 +1,191 @@ +prepare("SELECT * FROM emote_sets WHERE is_global = true"); + $stmt->execute(); + + if ($row = $stmt->fetch(PDO::FETCH_ASSOC)) { + $emote_set = $row; + + $stmt = $db->prepare("SELECT e.* FROM emotes e + JOIN emote_set_contents esc ON esc.emote_id = e.id + WHERE emote_set_id = ?"); + $stmt->execute([$emote_set["id"]]); + + $emote_set["emotes"] = $stmt->fetchAll(PDO::FETCH_ASSOC); + + foreach ($emote_set["emotes"] as &$e) { + if ($uploader_id = $e["uploaded_by"]) { + $stmt = $db->prepare("SELECT id, username FROM users WHERE id = ?"); + $stmt->execute([$uploader_id]); + $e["uploaded_by"] = $stmt->fetch(PDO::FETCH_ASSOC); + } + } + } +} else if (intval($id) <= 0 && intval($alias_id) <= 0) { + $page = intval($_GET["p"] ?? "0"); + $limit = 20; + $offset = $page * $limit; + + $stmt = $db->prepare("SELECT * FROM emote_sets LIMIT ? OFFSET ?"); + $stmt->bindParam(1, $limit, PDO::PARAM_INT); + $stmt->bindParam(2, $offset, PDO::PARAM_INT); + $stmt->execute(); + + $emote_sets = $stmt->fetchAll(PDO::FETCH_ASSOC); + + foreach ($emote_sets as &$e) { + $stmt = $db->prepare("SELECT e.* FROM emotes e + JOIN emote_set_contents esc ON esc.emote_set_id = ? + WHERE e.id = esc.emote_id + LIMIT 5"); + $stmt->execute([$e["id"]]); + + $e["emotes"] = $stmt->fetchAll(PDO::FETCH_ASSOC); + } +} else if (intval($alias_id) > 0) { + $alias_id = intval($alias_id); + $stmt = $db->prepare("SELECT es.* FROM emote_sets es + INNER JOIN connections co ON co.alias_id = ? + WHERE co.user_id = es.owner_id + "); + $stmt->execute([$alias_id]); + + if ($row = $stmt->fetch(PDO::FETCH_ASSOC)) { + $emote_set = $row; + + $stmt = $db->prepare("SELECT e.* FROM emotes e + JOIN emote_set_contents esc ON esc.emote_set_id = ? + WHERE esc.emote_id = e.id"); + $stmt->execute([$emote_set["id"]]); + + $emote_set["emotes"] = $stmt->fetchAll(PDO::FETCH_ASSOC); + + foreach ($emote_set["emotes"] as &$e) { + if ($e["uploaded_by"]) { + $stmt = $db->prepare("SELECT id, username FROM users WHERE id = ?"); + $stmt->execute([$e["uploaded_by"]]); + $e["uploaded_by"] = $stmt->fetch(PDO::FETCH_ASSOC); + } + } + } +} else { + $id = intval($id); + $stmt = $db->prepare("SELECT * FROM emote_sets WHERE id = ?"); + $stmt->execute([$id]); + + if ($row = $stmt->fetch(PDO::FETCH_ASSOC)) { + $emote_set = $row; + + $stmt = $db->prepare("SELECT e.* FROM emotes e + JOIN emote_set_contents esc ON esc.emote_set_id = ? + WHERE esc.emote_id = e.id"); + $stmt->execute([$emote_set["id"]]); + + $emote_set["emotes"] = $stmt->fetchAll(PDO::FETCH_ASSOC); + } +} + +if (CLIENT_REQUIRES_JSON) { + if ($emote_sets != null) { + json_response([ + "status_code" => 200, + "message" => null, + "data" => $emote_sets + ]); + exit; + } else if ($emote_set != null) { + json_response([ + "status_code" => 200, + "message" => null, + "data" => $emote_set + ]); + exit; + } else { + json_response([ + "status_code" => 404, + "message" => "Emoteset(s) not found", + "data" => null + ], 404); + exit; + } +} +?> + + + + + <?php echo $emote_sets != null ? (count($emote_sets) . " emotesets") : ('"' . $emote_set["name"] . '" emoteset') ?> + - alright.party + + + + + +
+
+ +
+ +
+
+ + +
+
+
+
+
+ + + \ No newline at end of file diff --git a/public/index.php b/public/index.php index a9b88bd..2a6311f 100644 --- a/public/index.php +++ b/public/index.php @@ -15,6 +15,7 @@ include_once "../src/config.php";
Emotes + Emotesets Users Upload Account diff --git a/src/partials.php b/src/partials.php index cf28f28..2e7ee56 100644 --- a/src/partials.php +++ b/src/partials.php @@ -9,6 +9,7 @@ function html_navigation_bar()