From 3f5765a05536a5b1e524bb4f4ffd290ff23a24af Mon Sep 17 00:00:00 2001 From: ilotterytea Date: Wed, 14 May 2025 23:52:11 +0500 Subject: feat: emote deletion --- public/emotes/delete.php | 47 +++++++++++++++++++++++++++++++++ public/emotes/index.php | 19 +++++++++++++ public/static/img/icons/bin.png | Bin 0 -> 475 bytes public/static/img/icons/link_break.png | Bin 0 -> 657 bytes 4 files changed, 66 insertions(+) create mode 100644 public/emotes/delete.php create mode 100644 public/static/img/icons/bin.png create mode 100644 public/static/img/icons/link_break.png diff --git a/public/emotes/delete.php b/public/emotes/delete.php new file mode 100644 index 0000000..6252e45 --- /dev/null +++ b/public/emotes/delete.php @@ -0,0 +1,47 @@ +prepare("SELECT uploaded_by, code FROM emotes WHERE id = ?"); +$stmt->execute([$emote_id]); + +if ($row = $stmt->fetch()) { + if ($row["uploaded_by"] === $user_id) { + $unlink = intval($_POST["unlink"] ?? "0") == 1; + + if ($unlink) { + $stmt = $db->prepare("UPDATE emotes SET uploaded_by = NULL WHERE id = ? AND uploaded_by = ?"); + $stmt->execute([$emote_id, $user_id]); + generate_alert("/emotes/?id=$emote_id", 'Your authorship has been removed for the emote "' . $row["code"] . '"', 200); + } else { + $stmt = $db->prepare("DELETE FROM emotes WHERE id = ? AND uploaded_by = ?"); + $stmt->execute([$emote_id, $user_id]); + + $path = $_SERVER["DOCUMENT_ROOT"] . "/static/userdata/emotes/$emote_id"; + array_map("unlink", glob("$path/*.*")); + rmdir($path); + + generate_alert("/emotes", 'Emote "' . $row["code"] . '" has been removed from the servers', 200); + } + } else { + generate_alert("/emotes", "You don't own the emote \"" . $row["code"] . "\"", 403); + } +} else { + generate_alert("/emotes", "Emote ID $emote_id not found", 404); +} \ No newline at end of file diff --git a/public/emotes/index.php b/public/emotes/index.php index 68ae983..afa24ad 100644 --- a/public/emotes/index.php +++ b/public/emotes/index.php @@ -292,6 +292,25 @@ if (CLIENT_REQUIRES_JSON) { ; } ?> + + get_uploaded_by() === $_SESSION["user_id"]): ?> +
+ + +
+
+ + + +
+