From 57472eab3c7b035392c6a5aa240593ecaa7d1ccf Mon Sep 17 00:00:00 2001 From: ilotterytea Date: Mon, 8 Dec 2025 21:53:36 +0500 Subject: upd: moved all /public/ files to the root folder --- emotes/upload.php | 552 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 552 insertions(+) create mode 100644 emotes/upload.php (limited to 'emotes/upload.php') diff --git a/emotes/upload.php b/emotes/upload.php new file mode 100644 index 0000000..644e4b6 --- /dev/null +++ b/emotes/upload.php @@ -0,0 +1,552 @@ +prepare("DELETE FROM emotes WHERE id = ?"); + $stmt->execute([$id]); + $db = null; + + array_map("unlink", glob("$path/*.*")); + rmdir($path); +} + +include "../../src/utils.php"; +include "../../src/images.php"; + +$max_width = EMOTE_MAX_SIZE[0]; +$max_height = EMOTE_MAX_SIZE[1]; + +if ($_SERVER['REQUEST_METHOD'] != "POST") { + include "../../src/partials.php"; + + echo '' ?> + + + + Upload an emote - <?php echo INSTANCE_NAME ?> + + + + + +
+
+ + + +
+
+
+ +
+
+

Image*

+ + + + + +
+ + +
+ +

Emote name*

+ + +
+ +
+

test

+
+ + + + + + + + + + + + + + + +
Emote source: +
Tags [?]: +
+ +
+ + +
+ + +
+
+
+ + +
+ + +
+
+
+ + + + + + + prepare("INSERT INTO emotes(id, code, notes, source, uploaded_by, visibility) VALUES (?, ?, ?, ?, ?, ?)"); +$stmt->execute([$id, $code, $notes, $source, $uploaded_by, $visibility]); + +$path = "../static/userdata/emotes/$id"; + +if (!is_dir($path)) { + mkdir($path, 0777, true); +} + +if ($is_manual) { + $image_1x = $_FILES["file-1x"]; + $image_2x = $_FILES["file-2x"]; + $image_3x = $_FILES["file-3x"]; + + $file_1x = does_file_meet_requirements($image_1x["tmp_name"], $max_width / 4, $max_height / 4); + $file_2x = does_file_meet_requirements($image_2x["tmp_name"], $max_width / 2, $max_height / 2); + $file_3x = does_file_meet_requirements($image_3x["tmp_name"], $max_width, $max_height); + + if (!$file_1x[0] || !$file_2x[0] || !$file_3x[0]) { + generate_alert("/emotes/upload.php", "Files don't meet requirements"); + abort_upload($path, $db, $id); + exit; + } + + if ( + !move_uploaded_file($image_1x["tmp_name"], "$path/1x.$file_1x[1]") || + !move_uploaded_file($image_2x["tmp_name"], "$path/2x.$file_2x[1]") || + !move_uploaded_file($image_3x["tmp_name"], "$path/3x.$file_3x[1]") + ) { + generate_alert("/emotes/upload.php", "Failed to move the uploaded files"); + abort_upload($path, $db, $id); + exit; + } +} else { + $image = $_FILES["file"]; + // resizing the image + if ($err = create_image_bundle($image["tmp_name"], $path, $max_width, $max_height)) { + generate_alert("/emotes/upload.php", "Error occurred while processing images ($err)", 500); + 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"); + } +} + +$tags = str_safe($_POST["tags"] ?? "", null); +$tags_processed = []; + +if (!empty($tags) && TAGS_ENABLE) { + $tags = explode(" ", $tags); + + $count = 0; + + foreach ($tags as $tag) { + if (TAGS_MAX_COUNT > 0 && $count >= TAGS_MAX_COUNT) { + break; + } + + if (!preg_match(TAGS_CODE_REGEX, $tag)) { + continue; + } + + $tag_id = null; + + $stmt = $db->prepare("SELECT id FROM tags WHERE code = ?"); + $stmt->execute([$tag]); + + if ($row = $stmt->fetch()) { + $tag_id = $row["id"]; + } else { + $tag_id = bin2hex(random_bytes(16)); + $db->prepare("INSERT INTO tags(id, code) VALUES (?, ?)")->execute([$tag_id, $tag]); + } + + $db->prepare("INSERT INTO tag_assigns(tag_id, emote_id) VALUES (?, ?)")->execute([$tag_id, $id]); + + $count++; + array_push($tags_processed, $tag); + } +} + +$emote_data = [ + "id" => $id, + "code" => $code, + "visibility" => $visibility, + "uploaded_by" => match ($uploaded_by == null) { + true => null, + false => [ + "id" => $uploaded_by, + "username" => $uploader_name + ] + }, + "notes" => $notes, + "source" => $source, + "tags" => $tags_processed +]; + +if (ACCOUNT_LOG_ACTIONS && $uploaded_by != null) { + $db->prepare("INSERT INTO actions(user_id, action_type, action_payload) VALUES (?, ?, ?)") + ->execute([ + $uploaded_by, + "EMOTE_CREATE", + json_encode([ + "emote" => $emote_data + ]) + ]); +} + + +$db = null; + +if (CLIENT_REQUIRES_JSON) { + json_response([ + "status_code" => 201, + "message" => null, + "data" => $emote_data + ], 201); + exit; +} + +header("Location: /emotes?id=$id", true, 307); \ No newline at end of file -- cgit v1.2.3