prepare("DELETE FROM emotes WHERE id = ?"); $stmt->execute([$id]); $db = null; array_map("unlink", glob("$path/*.*")); rmdir($path); } include "{$_SERVER['DOCUMENT_ROOT']}/lib/utils.php"; include "{$_SERVER['DOCUMENT_ROOT']}/lib/images.php"; $max_width = CONFIG['emote']['maxsizex']; $max_height = CONFIG['emote']['maxsizey']; if ($_SERVER['REQUEST_METHOD'] != "POST") { include "{$_SERVER['DOCUMENT_ROOT']}/lib/partials.php"; echo '' ?> Upload an emote - <?= CONFIG['instance']['name'] ?>

Image*

Emote name*


test

Emote source:
Tags [?]:
$path, 'manually_downloaded' => true ]; } $code = str_safe($_POST["code"] ?? "", CONFIG['emote']['maxnamelength']); if ($code == "" || !preg_match(CONFIG['emote']['nameregex'], $code)) { generate_alert("/emotes/upload.php", "Invalid code"); exit; } $notes = str_safe($_POST["notes"] ?? "", CONFIG['emote']['maxcommentlength']); if (empty($notes)) { $notes = null; } $source = str_safe($_POST["source"] ?? "", null); if (empty($source)) { $source = null; } $visibility = clamp(isset($_POST["visibility"]) ? intval($_POST["visibility"]) : CONFIG['emote']['defaultvisibility'], 0, 2); if (CONFIG['mod']['approve'] && $visibility == 1 && CONFIG['emote']['defaultvisibility'] != 1) { $visibility = 2; } // creating a new emote record $id = bin2hex(random_bytes(16)); $stmt = $db->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 { // 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 (CONFIG['emote']['storeoriginal']) { $ext = get_file_extension($image["tmp_name"]) ?? ""; move_uploaded_file($image["tmp_name"], "$path/original.$ext"); unlink($image["tmp_name"]); } } $tags = str_safe($_POST["tags"] ?? "", null); $tags_processed = []; if (!empty($tags) && CONFIG['tags']['enable']) { $tags = explode(" ", $tags); $count = 0; foreach ($tags as $tag) { if (CONFIG['tags']['maxcount'] > 0 && $count >= CONFIG['tags']['maxcount']) { break; } if (!preg_match(CONFIG['tags']['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 (CONFIG['account']['log'] && $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);