From 08e8563f94e8b46c08df4c231c838d32365d8f08 Mon Sep 17 00:00:00 2001 From: ilotterytea Date: Tue, 22 Apr 2025 17:19:39 +0500 Subject: feat: show emote rating --- public/emotes/index.php | 59 ++++++++++++++++++++++--- public/static/img/icons/ratings/brimstone.webp | Bin 0 -> 8400 bytes public/static/style.css | 28 ++++++++++++ 3 files changed, 80 insertions(+), 7 deletions(-) create mode 100644 public/static/img/icons/ratings/brimstone.webp (limited to 'public') diff --git a/public/emotes/index.php b/public/emotes/index.php index de0e6ef..475e119 100644 --- a/public/emotes/index.php +++ b/public/emotes/index.php @@ -57,7 +57,8 @@ function display_list_emotes(PDO &$db, int $page, int $limit): array $row["ext"], intval(strtotime($row["created_at"])), $row["uploaded_by"], - $row["is_in_user_set"] + $row["is_in_user_set"], + $row["rating"] )); } @@ -66,8 +67,12 @@ function display_list_emotes(PDO &$db, int $page, int $limit): array function display_emote(PDO &$db, int $id) { - $stmt = $db->prepare("SELECT * FROM emotes WHERE id = ?"); - $stmt->execute([$id]); + $stmt = $db->prepare("SELECT e.*, COALESCE(COUNT(r.rate), 0) as total_rating, + COALESCE(ROUND(AVG(r.rate), 2), 0) AS average_rating + FROM emotes e + LEFT JOIN ratings AS r ON r.emote_id = ? + WHERE e.id = ?"); + $stmt->execute([$id, $id]); $emote = null; @@ -78,7 +83,8 @@ function display_emote(PDO &$db, int $id) $row["ext"], intval(strtotime($row["created_at"])), $row["uploaded_by"], - false + false, + ["total" => $row["total_rating"], "average" => $row["average_rating"]] ); } @@ -222,8 +228,6 @@ if ($id == "" || !is_numeric($id)) { $username = $row["username"]; $link = "/users.php?id=" . $emote->get_uploaded_by(); } - - $db = null; } echo ""; @@ -237,7 +241,48 @@ if ($id == "" || !is_numeric($id)) { Rating - Not rated + get_rating()["total"] < 10) { + echo 'Not rated (' . $emote->get_rating()["total"] . ')'; + } else { + + $rating = $emote->get_rating()["average"]; + + // TODO: make it customizable + list($rating_classname, $rating_name) = match (true) { + in_range($rating, 0.75, 1.0) => [ + "gemerald", + " + + Shiny Gemerald! + + + + " + ], + in_range($rating, 0.25, 0.75) => ["gem", " Gem "], + in_range($rating, -0.25, 0.25) => ["iron", "Iron"], + in_range($rating, -0.75, -0.25) => ["coal", " Coal "], + in_range($rating, -1.0, -0.75) => [ + "brimstone", + " + + + + !!!AVOID THIS CANCER-GIVING BRIMSTONE!!! + + + + " + ] + }; + + echo ''; + echo "$rating_name"; + echo ' (' . $emote->get_rating()["total"] . ')'; + echo ''; + } + ?> diff --git a/public/static/img/icons/ratings/brimstone.webp b/public/static/img/icons/ratings/brimstone.webp new file mode 100644 index 0000000..98b0d62 Binary files /dev/null and b/public/static/img/icons/ratings/brimstone.webp differ diff --git a/public/static/style.css b/public/static/style.css index cb9a996..099764f 100644 --- a/public/static/style.css +++ b/public/static/style.css @@ -358,6 +358,34 @@ a.box:hover { margin-top: -15px; } +/** RATINGS */ +.rating.gemerald { + font-weight: bolder; + text-shadow: 0 0 5px blue; + color: #b4dbeb; +} + +.rating.gemerald img { + filter: hue-rotate(50deg) brightness(1.5); +} + +.rating.gem { + font-weight: bold; + color: #2e7b99; +} + +.rating.coal { + font-weight: bold; + color: #2d3335; + text-shadow: 0 0 2px black; +} + +.rating.brimstone { + font-weight: bolder; + color: orange; + text-shadow: 0 0 4px red; +} + /** ------------- ACCOUNTS -- cgit v1.2.3