summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorilotterytea <iltsu@alright.party>2025-05-15 19:00:27 +0500
committerilotterytea <iltsu@alright.party>2025-05-15 19:00:27 +0500
commit0fa1dcad656bd664a009561d81a1b3b53363482f (patch)
tree2c1bec0b8e9d473edd581ce8e9dc93c80ba421c7 /src
parenta241d3983d1cb79d455053a1f41cae0366fcaa71 (diff)
upd: optimized code in emotesets.php
Diffstat (limited to 'src')
-rw-r--r--src/emote.php42
1 files changed, 42 insertions, 0 deletions
diff --git a/src/emote.php b/src/emote.php
index ce3b930..170a991 100644
--- a/src/emote.php
+++ b/src/emote.php
@@ -79,6 +79,48 @@ class Emote
}
}
+function fetch_all_emotes_from_emoteset(PDO &$db, string $emote_set_id, string $user_id, int|null $limit = null): array
+{
+ // fetching emotes
+ $sql = "SELECT
+ e.id, e.created_at,
+ CASE
+ WHEN esc.code IS NOT NULL THEN esc.code
+ ELSE e.code
+ END AS code,
+ CASE
+ WHEN esc.code IS NOT NULL THEN e.code
+ ELSE NULL
+ END AS original_code,
+ CASE WHEN up.private_profile = FALSE OR up.id = ? THEN e.uploaded_by ELSE NULL END AS uploaded_by
+ FROM emotes e
+ LEFT JOIN user_preferences up ON up.id = e.uploaded_by
+ INNER JOIN emote_set_contents AS esc
+ ON esc.emote_set_id = ?
+ WHERE esc.emote_id = e.id";
+
+ if ($limit) {
+ $sql .= " LIMIT $limit";
+ }
+
+ $stmt = $db->prepare($sql);
+ $stmt->execute([$user_id, $emote_set_id]);
+
+ $emotes = $stmt->fetchAll(PDO::FETCH_ASSOC);
+
+ // fetching uploaders
+ foreach ($emotes as $e) {
+ if ($e["uploaded_by"]) {
+ $stmt = $db->prepare("SELECT id, username FROM users WHERE id = ?");
+ $stmt->execute([$e["uploaded_by"]]);
+
+ $e["uploaded_by"] = $stmt->fetch(PDO::FETCH_ASSOC);
+ }
+ }
+
+ return $emotes;
+}
+
function html_random_emote(PDO &$db)
{
$stmt = $db->prepare("SELECT id, code FROM emotes WHERE visibility = 1 ORDER BY RAND() LIMIT 1");