From 10cde47798f2a7b10a84a22f53aeddab1ceea720 Mon Sep 17 00:00:00 2001 From: ilotterytea Date: Sun, 20 Apr 2025 12:30:40 +0500 Subject: feat: upload page --- public/emotes/upload.php | 156 ++++++++++++++++++++++++++++++++++++++++++++--- public/index.php | 2 +- public/static/style.css | 26 ++++++-- 3 files changed, 169 insertions(+), 15 deletions(-) (limited to 'public') diff --git a/public/emotes/upload.php b/public/emotes/upload.php index 6d43daf..b0a3b71 100644 --- a/public/emotes/upload.php +++ b/public/emotes/upload.php @@ -1,4 +1,7 @@ prepare("DELETE FROM emotes WHERE id = :id"); @@ -15,8 +18,12 @@ function abort_upload(string $path, SQLite3 $db, string $id, string $response_te include "../../src/utils.php"; include "../../src/images.php"; +// TODO: make it configurable later +$max_width = max(128, 1); +$max_height = max(128, 1); + if ($_SERVER['REQUEST_METHOD'] != "POST") { - echo 'imagine there is a page'; + echo_upload_page(); exit; } @@ -57,10 +64,13 @@ if (is_null(list($mime, $ext) = get_mime_and_ext($image["tmp_name"]))) { // creating a new emote record $db = new SQLite3("../../database.db"); -$stmt = $db->prepare("INSERT INTO emotes(code, mime, ext) VALUES (:code, :mime, :ext)"); +$uploaded_by = $_SESSION["user_id"] ?? null; + +$stmt = $db->prepare("INSERT INTO emotes(code, mime, ext, uploaded_by) VALUES (:code, :mime, :ext, :uploaded_by)"); $stmt->bindValue(":code", $code); $stmt->bindValue(":mime", $mime); $stmt->bindValue(":ext", $ext); +$stmt->bindValue(":uploaded_by", $uploaded_by); $results = $stmt->execute(); $id = $db->lastInsertRowID(); @@ -84,10 +94,6 @@ if (!is_dir($path)) { // resizing the image -// TODO: make it configurable later -$max_width = max(128, 1); -$max_height = max(128, 1); - // 3x image $resized_image = resize_image($image["tmp_name"], "$path/3x", $max_width, $max_height); if ($resized_image) { @@ -117,10 +123,144 @@ if (isset($_SERVER["HTTP_ACCEPT"]) && $_SERVER["HTTP_ACCEPT"] == "application/js "id" => $id, "code" => $code, "ext" => $ext, - "mime" => $mime + "mime" => $mime, + "uploaded_by" => $uploaded_by ] ]); exit; } -header("Location: /emotes/$id", true, 307); \ No newline at end of file +header("Location: /emotes/$id", true, 307); + +function echo_upload_page() +{ + include "../../src/partials.php"; + + echo '' ?> + + + + Upload an emote at alright.party + + + + +
+
+ + +
+
+ +
+
+

Emote name

+ +

Image

+ + +
+ +
+ + +
+ + + +
+
+
+ + +
+
+
+ + + + + + + Chat clients -
+
diff --git a/public/static/style.css b/public/static/style.css index 1700079..1687616 100644 --- a/public/static/style.css +++ b/public/static/style.css @@ -44,6 +44,16 @@ input { border: 1px solid gray; } +form { + display: flex; + flex-direction: column; + gap: 4px; +} + +.row { + flex-direction: row; +} + .container { width: 100%; min-height: 100vh; @@ -131,6 +141,16 @@ button, color: black; } +button:disabled { + color: gray; +} + +button:disabled:hover { + cursor: not-allowed; + background: lightgray; + color: gray; +} + button:hover, .button:hover { background: #b9b9b9; @@ -319,12 +339,6 @@ a.box:hover { gap: 16px; } -.accman form { - display: flex; - flex-direction: column; - gap: 4px; -} - .accman h1 { font-size: 26px; } -- cgit v1.2.3