summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorilotterytea <iltsu@alright.party>2025-04-21 17:33:46 +0500
committerilotterytea <iltsu@alright.party>2025-04-21 17:33:46 +0500
commit92ea7a326b4430f3dbeb94f150df680e432f5ddf (patch)
tree0fa7d96a4c45837d4c41b5e84b3c7c1aa16286be
parent3c97031c879a227018dbdc4189b896a0a8998b06 (diff)
feat: check emote if it has been already added
-rw-r--r--public/emotes/index.php24
-rw-r--r--public/static/style.css13
-rw-r--r--src/emote.php9
-rw-r--r--src/emotes/multiple_page.php5
4 files changed, 45 insertions, 6 deletions
diff --git a/public/emotes/index.php b/public/emotes/index.php
index 9421e65..63bc9da 100644
--- a/public/emotes/index.php
+++ b/public/emotes/index.php
@@ -7,11 +7,23 @@ authorize_user();
function display_list_emotes(int $page, int $limit): array
{
+ $user_id = $_SESSION["user_id"] ?? "-1";
$offset = $page * $limit;
$db = new PDO(DB_URL, DB_USER, DB_PASS);
- $stmt = $db->prepare("SELECT * FROM emotes ORDER BY created_at ASC LIMIT ? OFFSET ?");
- $stmt->bindParam(1, $limit, PDO::PARAM_INT);
- $stmt->bindParam(2, $offset, PDO::PARAM_INT);
+ $stmt = $db->prepare("SELECT e.*,
+ CASE WHEN EXISTS (
+ SELECT 1
+ FROM emote_set_contents ec
+ INNER JOIN emote_sets es ON es.id = ec.emote_set_id
+ WHERE ec.emote_id = e.id AND es.owner_id = ?
+ ) THEN 1 ELSE 0 END AS is_in_user_set
+ FROM emotes e
+ ORDER BY e.created_at ASC
+ LIMIT ? OFFSET ?
+ ");
+ $stmt->bindParam(1, $user_id, PDO::PARAM_INT);
+ $stmt->bindParam(2, $limit, PDO::PARAM_INT);
+ $stmt->bindParam(3, $offset, PDO::PARAM_INT);
$stmt->execute();
$emotes = [];
@@ -24,7 +36,8 @@ function display_list_emotes(int $page, int $limit): array
$row["code"],
$row["ext"],
intval(strtotime($row["created_at"])),
- $row["uploaded_by"]
+ $row["uploaded_by"],
+ $row["is_in_user_set"]
));
}
@@ -45,7 +58,8 @@ function display_emote(int $id)
$row["code"],
$row["ext"],
intval(strtotime($row["created_at"])),
- $row["uploaded_by"]
+ $row["uploaded_by"],
+ false
);
}
diff --git a/public/static/style.css b/public/static/style.css
index 933e46e..86013be 100644
--- a/public/static/style.css
+++ b/public/static/style.css
@@ -330,6 +330,19 @@ a.box:hover {
border-color: #9f5050;
}
+.emote-check {
+ position: relative;
+ left: 35px;
+ top: 10px;
+ width: 24px;
+ height: 24px;
+ z-index: 2;
+}
+
+.emote:has(.emote-check) img {
+ margin-top: -15px;
+}
+
/**
-------------
ACCOUNTS
diff --git a/src/emote.php b/src/emote.php
index d00886a..2fd30c0 100644
--- a/src/emote.php
+++ b/src/emote.php
@@ -6,14 +6,16 @@ class Emote
public string $ext;
public string|null $uploaded_by;
public int $created_at;
+ public bool $is_in_user_set;
- function __construct($id, $code, $ext, $created_at, $uploaded_by)
+ function __construct($id, $code, $ext, $created_at, $uploaded_by, $is_in_user_set)
{
$this->id = $id;
$this->code = $code;
$this->ext = $ext;
$this->created_at = $created_at;
$this->uploaded_by = $uploaded_by;
+ $this->is_in_user_set = $is_in_user_set;
}
function get_id()
@@ -40,4 +42,9 @@ class Emote
{
return $this->uploaded_by;
}
+
+ function is_added_by_user()
+ {
+ return $this->is_in_user_set;
+ }
}
diff --git a/src/emotes/multiple_page.php b/src/emotes/multiple_page.php
index 8e2b4d7..25c4c9c 100644
--- a/src/emotes/multiple_page.php
+++ b/src/emotes/multiple_page.php
@@ -23,6 +23,11 @@
if (isset($emotes)) {
foreach ($emotes as $e) {
echo "<a class=\"box emote\" href=\"/emotes/" . $e->get_id() . "\">";
+
+ if ($e->is_added_by_user()) {
+ echo '<img src="/static/img/icons/yes.png" class="emote-check" />';
+ }
+
echo "<img src=\"/static/userdata/emotes/" . $e->get_id() . "/2x." . $e->get_ext() . "\" alt=\"" . $e->get_code() . "\"/>";
echo "<p>" . $e->get_code() . "</p>";
echo "</a>";