From 65eb2ff002015f066f47495bbd41e0412e9071d7 Mon Sep 17 00:00:00 2001 From: ilotterytea Date: Thu, 1 May 2025 01:24:11 +0500 Subject: feat: emote aliases --- public/emotes/index.php | 23 +++++++++++++--- public/emotes/setmanip.php | 66 +++++++++++++++++++++++++++++++++------------- 2 files changed, 68 insertions(+), 21 deletions(-) (limited to 'public/emotes') diff --git a/public/emotes/index.php b/public/emotes/index.php index 04dec65..1606b17 100644 --- a/public/emotes/index.php +++ b/public/emotes/index.php @@ -199,9 +199,15 @@ if (CLIENT_REQUIRES_JSON) { $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 = $db->prepare("SELECT id, name 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; + + $added = false; + + if ($row = $stmt->fetch()) { + $added = true; + $emote_current_name = $row["name"] ?? $emote->get_code(); + } } if (isset($_SESSION["user_role"]) && $_SESSION["user_role"]["permission_emoteset_own"]) { @@ -210,9 +216,20 @@ if (CLIENT_REQUIRES_JSON) { + if ($added) { + ?> + +
+ + + + diff --git a/public/emotes/setmanip.php b/public/emotes/setmanip.php index 5f3174f..8b43b54 100644 --- a/public/emotes/setmanip.php +++ b/public/emotes/setmanip.php @@ -2,6 +2,7 @@ include_once "../../src/config.php"; include "../../src/accounts.php"; include "../../src/alert.php"; +include_once "../../src/utils.php"; if (!authorize_user(true)) { return; @@ -66,29 +67,58 @@ $stmt->execute([$emote_set_id, $emote_id]); $action = $_POST["action"]; -if ($action == "add") { - if ($stmt->rowCount() != 0) { - generate_alert("/emotes?id=$emote_id", "This emote has been already added!"); - exit; - } +switch ($action) { + case "add": { + if ($stmt->rowCount() != 0) { + generate_alert("/emotes?id=$emote_id", "This emote has been already added!"); + exit; + } - $stmt = $db->prepare("INSERT INTO emote_set_contents(emote_set_id, emote_id, added_by) VALUES (?, ?, ?)"); - $stmt->execute([$emote_set_id, $emote_id, $user_id]); + $stmt = $db->prepare("INSERT INTO emote_set_contents(emote_set_id, emote_id, added_by) VALUES (?, ?, ?)"); + $stmt->execute([$emote_set_id, $emote_id, $user_id]); - $db = null; + $db = null; + + generate_alert("/emotes?id=$emote_id", "This emote has been added to your set. Enjoy!", 200); + break; + } + case "remove": { + if ($row = $stmt->fetch()) { + $stmt = $db->prepare("DELETE FROM emote_set_contents WHERE id = ?"); + $stmt->execute([$row["id"]]); + } else { + generate_alert("/emotes?id=$emote_id", "This emote wasn't added!"); + $db = null; + exit; + } - generate_alert("/emotes?id=$emote_id", "This emote has been added to your set. Enjoy!", 200); -} else { - if ($row = $stmt->fetch()) { - $stmt = $db->prepare("DELETE FROM emote_set_contents WHERE id = ?"); - $stmt->execute([$row["id"]]); - } else { - generate_alert("/emotes?id=$emote_id", "This emote wasn't added!"); $db = null; - exit; + + generate_alert("/emotes?id=$emote_id", "This emote has been removed from your set.", 200); + break; } + case "alias": { + if (!isset($_POST["value"])) { + generate_alert("/emotes?id=$emote_id", "No value field"); + exit; + } - $db = null; + $value = str_safe($_POST["value"], EMOTE_NAME_MAX_LENGTH); - generate_alert("/emotes?id=$emote_id", "This emote has been removed from your set.", 200); + if (empty($value)) { + $value = null; + } + + $stmt = $db->prepare("UPDATE emote_set_contents SET name = ? WHERE emote_set_id = ? AND emote_id = ?"); + $stmt->execute([$value, $emote_set_id, $emote_id]); + + $db = null; + + generate_alert("/emotes?id=$emote_id", "Updated emote name!", 200); + break; + } + default: { + generate_alert("/emotes?id=$emote_id", "Unknown action"); + break; + } } \ No newline at end of file -- cgit v1.2.3