From 53a2e84af1ef1f35d835ef439260157038c70a46 Mon Sep 17 00:00:00 2001 From: ilotterytea Date: Thu, 15 May 2025 01:44:01 +0500 Subject: feat: tags --- public/emotes/index.php | 46 +++++++++++++++++++++++++++++--------- public/emotes/upload.php | 57 ++++++++++++++++++++++++++++++++++++++++++++---- 2 files changed, 89 insertions(+), 14 deletions(-) (limited to 'public/emotes') diff --git a/public/emotes/index.php b/public/emotes/index.php index afa24ad..78828e1 100644 --- a/public/emotes/index.php +++ b/public/emotes/index.php @@ -36,18 +36,23 @@ function display_list_emotes(PDO &$db, string $search, string $sort_by, int $pag FROM emotes e LEFT JOIN user_preferences up ON up.id = e.uploaded_by LEFT JOIN ratings AS r ON r.emote_id = e.id - WHERE e.code LIKE ? AND e.visibility = 1 + LEFT JOIN tag_assigns ta ON ta.emote_id = e.id + LEFT JOIN tags t ON t.id = ta.tag_id + WHERE (t.code = ? OR e.code LIKE ?) AND e.visibility = 1 GROUP BY e.id, e.code, e.created_at ORDER BY $sort LIMIT ? OFFSET ? "); + $sql_search = "%$search%"; + $stmt->bindParam(1, $current_user_id, PDO::PARAM_STR); $stmt->bindParam(2, $user_id, PDO::PARAM_INT); $stmt->bindParam(3, $search, PDO::PARAM_STR); - $stmt->bindParam(4, $limit, PDO::PARAM_INT); - $stmt->bindParam(5, $offset, PDO::PARAM_INT); + $stmt->bindParam(4, $sql_search, PDO::PARAM_STR); + $stmt->bindParam(5, $limit, PDO::PARAM_INT); + $stmt->bindParam(6, $offset, PDO::PARAM_INT); $stmt->execute(); @@ -78,7 +83,8 @@ function display_list_emotes(PDO &$db, string $search, string $sort_by, int $pag $row["is_in_user_set"], $row["rating"], $row["visibility"], - $row["source"] + $row["source"], + [] )); } @@ -100,6 +106,15 @@ function display_emote(PDO &$db, string $id) if ($row = $stmt->fetch()) { if ($row["id"] != null) { + $stmt = $db->prepare("SELECT t.code FROM tags t + INNER JOIN tag_assigns ta ON ta.emote_id = ? + WHERE t.id = ta.tag_id + "); + $stmt->execute([$row["id"]]); + + $tags = $stmt->fetchAll(PDO::FETCH_ASSOC); + $tags = array_column($tags, "code"); + $emote = new Emote( $row["id"], $row["code"], @@ -109,7 +124,8 @@ function display_emote(PDO &$db, string $id) false, ["total" => $row["total_rating"], "average" => $row["average_rating"]], $row["visibility"], - $row["source"] + $row["source"], + $tags ); } } @@ -142,14 +158,12 @@ $page = max(1, intval($_GET["p"] ?? "1")); $limit = 50; $total_emotes = 0; $total_pages = 0; -$search = "%" . ($_GET["q"] ?? "") . "%"; +$search = $_GET["q"] ?? ""; $sort_by = $_GET["sort_by"] ?? ""; if (empty($id)) { $emotes = display_list_emotes($db, $search, $sort_by, $page, $limit); - $stmt = $db->prepare("SELECT COUNT(*) FROM emotes WHERE code LIKE ? AND visibility = 1"); - $stmt->execute([$search]); - $total_emotes = $stmt->fetch()[0]; + $total_emotes = count($emotes); $total_pages = ceil($total_emotes / $limit); } else { $emote = display_emote($db, $id); @@ -224,7 +238,7 @@ if (CLIENT_REQUIRES_JSON) { } echo ''; } else { - echo "$total_emotes Emotes - Page $page/$total_pages"; + echo "Emotes - Page $page/$total_pages"; } ?> @@ -352,6 +366,18 @@ if (CLIENT_REQUIRES_JSON) {
+ get_tags())): ?> + + + + +
Tags + get_tags() as $tag) { + echo "$tag "; + } + ?> +
Uploader Approval notes -
- - -
+ + + + + + + + + + + +
Emote source:
Tags [?]: +