From 8c148952a95ee756038bc0e7afbf52f63249227f Mon Sep 17 00:00:00 2001 From: ilotterytea Date: Wed, 30 Apr 2025 00:49:05 +0500 Subject: feat: emote visibility --- public/emotes/index.php | 38 ++++++++++++++++++++++++++------------ public/emotes/upload.php | 34 ++++++++++++++++++++++++++-------- 2 files changed, 52 insertions(+), 20 deletions(-) (limited to 'public/emotes') diff --git a/public/emotes/index.php b/public/emotes/index.php index b6308a5..dc406f5 100644 --- a/public/emotes/index.php +++ b/public/emotes/index.php @@ -31,7 +31,7 @@ function display_list_emotes(PDO &$db, string $search, string $sort_by, int $pag ) THEN 1 ELSE 0 END AS is_in_user_set, COALESCE(COUNT(r.rate), 0) AS rating FROM emotes e LEFT JOIN ratings AS r ON r.emote_id = e.id - WHERE e.code LIKE ? + WHERE e.code LIKE ? AND e.visibility = 1 GROUP BY e.id, e.code, e.created_at ORDER BY $sort @@ -65,7 +65,8 @@ function display_list_emotes(PDO &$db, string $search, string $sort_by, int $pag intval(strtotime($row["created_at"])), $uploader, $row["is_in_user_set"], - $row["rating"] + $row["rating"], + $row["visibility"] )); } @@ -84,15 +85,18 @@ function display_emote(PDO &$db, int $id) $emote = null; if ($row = $stmt->fetch()) { - $emote = new Emote( - $row["id"], - $row["code"], - $row["ext"], - intval(strtotime($row["created_at"])), - $row["uploaded_by"], - false, - ["total" => $row["total_rating"], "average" => $row["average_rating"]] - ); + if ($row["id"] != null) { + $emote = new Emote( + $row["id"], + $row["code"], + $row["ext"], + intval(strtotime($row["created_at"])), + $row["uploaded_by"], + false, + ["total" => $row["total_rating"], "average" => $row["average_rating"]], + $row["visibility"] + ); + } } if ($emote == null) { @@ -128,7 +132,7 @@ $sort_by = $_GET["sort_by"] ?? ""; if ($id == "" || !is_numeric($id)) { $emotes = display_list_emotes($db, $search, $sort_by, $page, $limit); - $stmt = $db->prepare("SELECT COUNT(*) FROM emotes WHERE code LIKE ?"); + $stmt = $db->prepare("SELECT COUNT(*) FROM emotes WHERE code LIKE ? AND visibility = 1"); $stmt->execute([$search]); $total_emotes = $stmt->fetch()[0]; $total_pages = ceil($total_emotes / $limit); @@ -329,6 +333,16 @@ if (CLIENT_REQUIRES_JSON) { } ?> + + Visibility + get_visibility() == 1) { + echo 'Public'; + } else { + echo 'Unlisted'; + } + ?> + diff --git a/public/emotes/upload.php b/public/emotes/upload.php index 4e90632..5563323 100644 --- a/public/emotes/upload.php +++ b/public/emotes/upload.php @@ -70,16 +70,15 @@ if ($_SERVER['REQUEST_METHOD'] != "POST") {
- + +
- +

test

+
- @@ -162,6 +161,23 @@ if ($_SERVER['REQUEST_METHOD'] != "POST") { e.target.value = validCode; } }); + + const visibility = document.getElementById("form-visibility"); + visibility.addEventListener("change", (e) => { + set_form_visibility_description(visibility.value); + }); + + function set_form_visibility_description(visibility) { + const p = document.getElementById("form-visibility-description"); + + if (visibility == 1) { + p.innerHTML = "Emote won't appear on the public list until it passes a moderator's review. It still can be added to chats."; + } else { + p.innerHTML = "Emote doesn't appear on the public list and won't be subject to moderation checks. It still can be added to chats."; + } + } + + set_form_visibility_description(visibility.value); @@ -204,11 +220,13 @@ if (is_null(list($mime, $ext) = get_mime_and_ext($image["tmp_name"]))) { exit; } +$visibility = intval($_GET["visibility"], "0"); + // creating a new emote record $db = new PDO(DB_URL, DB_USER, DB_PASS); -$stmt = $db->prepare("INSERT INTO emotes(code, mime, ext, uploaded_by) VALUES (?, ?, ?, ?)"); -$stmt->execute([$code, $mime, $ext, $uploaded_by]); +$stmt = $db->prepare("INSERT INTO emotes(code, mime, ext, uploaded_by, visibility) VALUES (?, ?, ?, ?, ?)"); +$stmt->execute([$code, $mime, $ext, $uploaded_by, $visibility]); $id = $db->lastInsertId(); -- cgit v1.2.3