diff options
Diffstat (limited to 'public/emotes')
| -rw-r--r-- | public/emotes/index.php | 23 | ||||
| -rw-r--r-- | public/emotes/setmanip.php | 66 |
2 files changed, 68 insertions, 21 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 |
