summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorilotterytea <iltsu@alright.party>2025-04-20 10:48:08 +0500
committerilotterytea <iltsu@alright.party>2025-04-20 10:48:08 +0500
commitc474b61f3c741e86a3273b2f4c2017de05eb1085 (patch)
tree731f9da3f21852c1bab44ae6ebb49346762c83ae
parent3b6c6e5774dec41a16da03d1bb8497b448cfa564 (diff)
feat: show emote uploader
-rw-r--r--public/emotes/index.php8
-rw-r--r--src/emote.php9
-rw-r--r--src/emotes/single_page.php83
3 files changed, 70 insertions, 30 deletions
diff --git a/public/emotes/index.php b/public/emotes/index.php
index c73b3d0..b603cc0 100644
--- a/public/emotes/index.php
+++ b/public/emotes/index.php
@@ -1,5 +1,7 @@
<?php
include "../../src/emote.php";
+include "../../src/accounts.php";
+authorize_user();
function display_list_emotes(int $page, int $limit): array
{
@@ -16,7 +18,8 @@ function display_list_emotes(int $page, int $limit): array
$row["id"],
$row["code"],
$row["ext"],
- intval(strtotime($row["created_at"]))
+ intval(strtotime($row["created_at"])),
+ $row["uploaded_by"]
));
}
@@ -35,7 +38,8 @@ function display_emote(int $id)
$row["id"],
$row["code"],
$row["ext"],
- intval(strtotime($row["created_at"]))
+ intval(strtotime($row["created_at"])),
+ $row["uploaded_by"]
);
}
diff --git a/src/emote.php b/src/emote.php
index 5d39e42..d00886a 100644
--- a/src/emote.php
+++ b/src/emote.php
@@ -4,14 +4,16 @@ class Emote
public string $id;
public string $code;
public string $ext;
+ public string|null $uploaded_by;
public int $created_at;
- function __construct($id, $code, $ext, $created_at)
+ function __construct($id, $code, $ext, $created_at, $uploaded_by)
{
$this->id = $id;
$this->code = $code;
$this->ext = $ext;
$this->created_at = $created_at;
+ $this->uploaded_by = $uploaded_by;
}
function get_id()
@@ -33,4 +35,9 @@ class Emote
{
return $this->created_at;
}
+
+ function get_uploaded_by()
+ {
+ return $this->uploaded_by;
+ }
}
diff --git a/src/emotes/single_page.php b/src/emotes/single_page.php
index db4f332..fb87789 100644
--- a/src/emotes/single_page.php
+++ b/src/emotes/single_page.php
@@ -31,31 +31,40 @@
</section>
<section class="box items row">
- <div class="items row left full">
- <form action="/emotes/add.php" method="POST">
- <input type="text" name="id" value="<?php echo $emote->get_id() ?>"
- style="display: none;">
- <button type="submit" class="green">Add to my channel</button>
- </form>
- </div>
- <div class="items row right full">
- <form action="/emotes/rate.php" method="POST">
- <input type="text" name="id" value="<?php echo $emote->get_id() ?>"
- style="display: none;">
- <input type="text" name="rate" value="5" style="display:none;">
- <button type="submit" class="transparent gem"><img src="/static/img/icons/gem.png"
- alt="GEM!" title="IT'S A GEM!"></button>
- </form>
- <form action="/emotes/rate.php" method="POST">
- <input type="text" name="id" value="<?php echo $emote->get_id() ?>"
- style="display: none;">
- <input type="text" name="rate" value="1" style="display:none;">
- <button type="submit" class="transparent coal"><img src="/static/img/icons/coal.png"
- alt="COAL!" title="IT'S A COAL!"></button>
- </form>
- <a class="button red" href="/emotes/report.php?id=<?php echo $emote->get_id() ?>">Report
- emote</a>
- </div>
+ <?php if (isset($_SESSION["user_id"])) {
+ echo '' ?>
+ <div class="items row left full">
+ <form action="/emotes/add.php" method="POST">
+ <input type="text" name="id" value="<?php echo $emote->get_id() ?>"
+ style="display: none;">
+ <button type="submit" class="green">Add to my channel</button>
+ </form>
+ </div>
+ <div class="items row right full">
+ <form action="/emotes/rate.php" method="POST">
+ <input type="text" name="id" value="<?php echo $emote->get_id() ?>"
+ style="display: none;">
+ <input type="text" name="rate" value="5" style="display:none;">
+ <button type="submit" class="transparent gem"><img src="/static/img/icons/gem.png"
+ alt="GEM!" title="IT'S A GEM!"></button>
+ </form>
+ <form action="/emotes/rate.php" method="POST">
+ <input type="text" name="id" value="<?php echo $emote->get_id() ?>"
+ style="display: none;">
+ <input type="text" name="rate" value="1" style="display:none;">
+ <button type="submit" class="transparent coal"><img src="/static/img/icons/coal.png"
+ alt="COAL!" title="IT'S A COAL!"></button>
+ </form>
+ <a class="button red" href="/emotes/report.php?id=<?php echo $emote->get_id() ?>">Report
+ emote</a>
+ </div>
+ <?php
+ } else {
+ echo '' ?>
+ <p><a href="/account/login">Log in</a> to get additional features...</p>
+ <?php
+ }
+ ?>
</section>
<section class="box">
@@ -63,8 +72,28 @@
<tr>
<th>Uploader</th>
<td><?php
- echo '<a href="/users/' . "0" . '">' . "someone" . '</a>, ';
- echo date("d M Y", $emote->get_created_at());
+ $username = "anonymous";
+ $link = "#";
+
+ if ($emote->get_uploaded_by()) {
+ $db = new SQLite3("../../database.db");
+ $stmt = $db->prepare("SELECT username FROM users WHERE id = :id");
+ $stmt->bindValue(":id", $emote->get_uploaded_by());
+ $results = $stmt->execute();
+
+ if ($row = $results->fetchArray()) {
+ $username = $row["username"];
+ $link = "/users/" . $emote->get_uploaded_by();
+ }
+
+ $db->close();
+ }
+
+ echo "<a href=\"$link\">";
+ echo $username;
+ echo "</a>";
+
+ echo ", " . date("d M Y", $emote->get_created_at());
?></td>
</tr>
<tr>