diff options
| author | ilotterytea <iltsu@alright.party> | 2025-05-01 01:24:11 +0500 |
|---|---|---|
| committer | ilotterytea <iltsu@alright.party> | 2025-05-01 01:24:11 +0500 |
| commit | 65eb2ff002015f066f47495bbd41e0412e9071d7 (patch) | |
| tree | 90f3be293b7ff7e02f72972f0afb6b7e5125517a /public | |
| parent | ef16637d0f6822f326266f50b496f294ecd53cba (diff) | |
feat: emote aliases
Diffstat (limited to 'public')
| -rw-r--r-- | public/emotes/index.php | 23 | ||||
| -rw-r--r-- | public/emotes/setmanip.php | 66 | ||||
| -rw-r--r-- | public/emotesets.php | 50 | ||||
| -rw-r--r-- | public/static/img/icons/pencil.png | bin | 0 -> 450 bytes | |||
| -rw-r--r-- | public/users.php | 11 |
5 files changed, 121 insertions, 29 deletions
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) { <input type="text" name="id" value="<?php echo $emote->get_id() ?>" style="display: none;"> <?php - if ($added) { ?> + if ($added) { + ?> <input type="text" name="action" value="remove" style="display: none;"> <button type="submit" class="red">Remove from my channel</button> + </form> + <form action="/emotes/setmanip.php" method="POST" class="row"> + <input type="text" name="id" value="<?php echo $emote->get_id() ?>" + style="display: none;"> + <input type="text" name="value" id="emote-alias-input" + value="<?php echo $emote_current_name ?>" + placeholder="<?php echo $emote->get_code() ?>"> + <input type="text" name="action" value="alias" style="display: none;"> + <button type="submit" class="transparent"><img src="/static/img/icons/pencil.png" + alt="Rename" title="Rename"></button> <?php } else { ?> <input type="text" name="action" value="add" style="display: none;"> 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 diff --git a/public/emotesets.php b/public/emotesets.php index fdf32d5..8dfdab0 100644 --- a/public/emotesets.php +++ b/public/emotesets.php @@ -24,9 +24,19 @@ if ($id == "global") { if ($row = $stmt->fetch(PDO::FETCH_ASSOC)) { $emote_set = $row; - $stmt = $db->prepare("SELECT e.* FROM emotes e + $stmt = $db->prepare("SELECT + e.*, + CASE + WHEN esc.name IS NOT NULL THEN esc.name + ELSE e.code + END AS code, + CASE + WHEN esc.name IS NOT NULL THEN e.code + ELSE NULL + END AS original_code + FROM emotes e JOIN emote_set_contents esc ON esc.emote_id = e.id - WHERE emote_set_id = ?"); + WHERE esc.emote_set_id = ?"); $stmt->execute([$emote_set["id"]]); $emote_set["emotes"] = $stmt->fetchAll(PDO::FETCH_ASSOC); @@ -51,10 +61,18 @@ if ($id == "global") { $emote_sets = $stmt->fetchAll(PDO::FETCH_ASSOC); foreach ($emote_sets as &$e) { - $stmt = $db->prepare("SELECT e.* FROM emotes e + $stmt = $db->prepare("SELECT e.*, + CASE + WHEN esc.name IS NOT NULL THEN esc.name + ELSE e.code + END AS code, + CASE + WHEN esc.name IS NOT NULL THEN e.code + ELSE NULL + END AS original_code + FROM emotes e JOIN emote_set_contents esc ON esc.emote_set_id = ? - WHERE e.id = esc.emote_id - LIMIT 5"); + WHERE e.id = esc.emote_id"); $stmt->execute([$e["id"]]); $e["emotes"] = $stmt->fetchAll(PDO::FETCH_ASSOC); @@ -81,7 +99,16 @@ if ($id == "global") { if ($row = $stmt->fetch(PDO::FETCH_ASSOC)) { $emote_set = $row; - $stmt = $db->prepare("SELECT e.* FROM emotes e + $stmt = $db->prepare("SELECT e.*, + CASE + WHEN esc.name IS NOT NULL THEN esc.name + ELSE e.code + END AS code, + CASE + WHEN esc.name IS NOT NULL THEN e.code + ELSE NULL + END AS original_code + FROM emotes e JOIN emote_set_contents esc ON esc.emote_set_id = ? WHERE esc.emote_id = e.id"); $stmt->execute([$emote_set["id"]]); @@ -104,7 +131,16 @@ if ($id == "global") { if ($row = $stmt->fetch(PDO::FETCH_ASSOC)) { $emote_set = $row; - $stmt = $db->prepare("SELECT e.* FROM emotes e + $stmt = $db->prepare("SELECT e.*, + CASE + WHEN esc.name IS NOT NULL THEN esc.name + ELSE e.code + END AS code, + CASE + WHEN esc.name IS NOT NULL THEN e.code + ELSE NULL + END AS original_code + FROM emotes e JOIN emote_set_contents esc ON esc.emote_set_id = ? WHERE esc.emote_id = e.id"); $stmt->execute([$emote_set["id"]]); diff --git a/public/static/img/icons/pencil.png b/public/static/img/icons/pencil.png Binary files differnew file mode 100644 index 0000000..0bfecd5 --- /dev/null +++ b/public/static/img/icons/pencil.png diff --git a/public/users.php b/public/users.php index 914f890..8b62a8a 100644 --- a/public/users.php +++ b/public/users.php @@ -160,7 +160,16 @@ while ($row = $stmt->fetch()) { // getting info about emote set content $em_stmt = $db->prepare( - "SELECT e.id, e.code, e.mime, e.ext, e.created_at, e.uploaded_by FROM emotes e + "SELECT e.id, e.mime, e.ext, e.created_at, e.uploaded_by, + CASE + WHEN esc.name IS NOT NULL THEN esc.name + ELSE e.code + END AS code, + CASE + WHEN esc.name IS NOT NULL THEN e.code + ELSE NULL + END AS original_code + FROM emotes e INNER JOIN emote_set_contents AS esc ON esc.emote_set_id = ? WHERE esc.emote_id = e.id |
