summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorilotterytea <iltsu@alright.party>2025-05-11 16:52:46 +0500
committerilotterytea <iltsu@alright.party>2025-05-11 16:56:01 +0500
commitf2690a42235297c357bcd8abbf6e194db7b7bd57 (patch)
tree1b0a221cd89903ed901b1d28047a493fa4a1317c
parent7d0b7ed296d35025e04e19dc2604c8feca72383e (diff)
feat: store original uploads
-rw-r--r--public/emotes/index.php8
-rw-r--r--public/emotes/upload.php5
-rw-r--r--public/system/emotes/index.php16
-rw-r--r--src/config.sample.php1
-rw-r--r--src/images.php9
5 files changed, 38 insertions, 1 deletions
diff --git a/public/emotes/index.php b/public/emotes/index.php
index e9e93cb..811ada2 100644
--- a/public/emotes/index.php
+++ b/public/emotes/index.php
@@ -195,6 +195,14 @@ if (CLIENT_REQUIRES_JSON) {
echo "Emote - " . $emote->get_code();
echo '<div class="row small-gap" style="margin-left:auto">';
+ $original_path = "/static/userdata/emotes/" . $emote->get_id();
+ $files = glob($_SERVER["DOCUMENT_ROOT"] . $original_path . "/original.*");
+
+ if (!empty($files)) {
+ $filename = basename($files[0]);
+ echo "<a href='$original_path/$filename' target='_BLANK'><img src='/static/img/icons/emotes/emote.png' alt='[Show original]' title='Show original' /></a>";
+ }
+
$stmt = $db->prepare("
SELECT MAX(es.is_featured) AS is_featured, MAX(es.is_global) AS is_global
FROM emote_sets es
diff --git a/public/emotes/upload.php b/public/emotes/upload.php
index f890ec2..8b197a2 100644
--- a/public/emotes/upload.php
+++ b/public/emotes/upload.php
@@ -387,6 +387,11 @@ if ($is_manual) {
abort_upload($path, $db, $id);
exit;
}
+
+ if (EMOTE_STORE_ORIGINAL) {
+ $ext = get_file_extension($image["tmp_name"]) ?? "";
+ move_uploaded_file($image["tmp_name"], "$path/original.$ext");
+ }
}
if (ACCOUNT_LOG_ACTIONS) {
diff --git a/public/system/emotes/index.php b/public/system/emotes/index.php
index 3fc0b14..79dfc28 100644
--- a/public/system/emotes/index.php
+++ b/public/system/emotes/index.php
@@ -101,7 +101,21 @@ if (isset($_GET["id"])) {
<section class="content">
<!-- Emote showcase -->
<section class="box">
- <div class="box navtab">Emote - <?php echo $emote["code"] ?></div>
+ <div class="box navtab row">
+ <?php
+ echo "Emote - " . $emote["code"];
+ echo '<div class="row small-gap" style="margin-left:auto">';
+
+ $original_path = "/static/userdata/emotes/" . $emote["id"];
+ $files = glob($_SERVER["DOCUMENT_ROOT"] . $original_path . "/original.*");
+
+ if (!empty($files)) {
+ $filename = basename($files[0]);
+ echo "<a href='$original_path/$filename' target='_BLANK'><img src='/static/img/icons/emotes/emote.png' alt='[Show original]' title='Show original' /></a>";
+ }
+ echo '</div>';
+ ?>
+ </div>
<div class="box content">
<div class="emote-showcase">
<img src="/static/userdata/emotes/<?php echo $emote["id"] ?>/1x.webp"
diff --git a/src/config.sample.php b/src/config.sample.php
index 9a50d2d..6998835 100644
--- a/src/config.sample.php
+++ b/src/config.sample.php
@@ -28,6 +28,7 @@ define("EMOTE_COMMENT_MAX_LENGTH", 100); // Max length for emote comment.
define("EMOTE_VISIBILITY_DEFAULT", 2); // Default visibility for emotes. 0 - unlisted, 1 - public, 2 - pending approval (same as unlisted).
define("EMOTE_MAX_SIZE", [128, 128]); // Max size of emote.
define("EMOTE_NAME_REGEX", "/^[A-Za-z0-9_]+$/"); // RegEx filter for emote names.
+define("EMOTE_STORE_ORIGINAL", true); // Store original uploads of emotes.
// EMOTESETS
define("EMOTESET_PUBLIC_LIST", true); // Show emotesets public.
diff --git a/src/images.php b/src/images.php
index a9caf88..837ebaf 100644
--- a/src/images.php
+++ b/src/images.php
@@ -29,6 +29,15 @@ function resize_image(string $src_path, string $dst_path, int $max_width, int $m
return $result_code;
}
+function get_file_extension(string $path): string|null
+{
+ if ($file = getimagesize($path)) {
+ return image_type_to_extension(intval($file[2]), false);
+ }
+
+ return null;
+}
+
function does_file_meet_requirements(string $path, int $max_width, int $max_height): array
{
$file = getimagesize($path);