Mod edited
The edited mod is now awaiting moderators' approval.
prepare("SELECT id FROM categories WHERE id = ?");
if (!$statement) {
$errorMessage = "An unexpected error occurred while editing the mod.";
} else {
$statement->bind_param('i', $categoryID);
$statement->execute();
$result = $statement->get_result();
if (!$result) {
$errorMessage = "An unexpected error occurred while editing the mod.";
$statement->close();
} else {
$isCategoryPresent = boolval($result->fetch_assoc());
$statement->close();
if (!$isCategoryPresent) {
$errorMessage = "The selected category doesn't exist.";
} else {
$fileError = false;
$fileExtension = null;
$modPendingUploadDirectory = APP_FSROOT . '/img/mods_pending';
$modUploadDirectory = APP_FSROOT . '/img/mods';
if (isset($_FILES['cover']) && $_FILES['cover']['error'] != UPLOAD_ERR_NO_FILE) {
if ($_FILES['cover']['error'] != UPLOAD_ERR_OK) {
$fileError = true;
$errorMessage = "An unexpected error occurred while uploading the cover image.";
} else {
$fileTmpPath = $_FILES['cover']['tmp_name'];
$fileName = $_FILES['cover']['name'];
$fileSize = $_FILES['cover']['size'];
$fileType = $_FILES['cover']['type'];
$fileExtension = pathinfo($fileName, PATHINFO_EXTENSION);
if ($fileSize > IMAGE_MAX_SIZE) {
$fileError = true;
$errorMessage = "The cover image is too large. Maximum cover image size: " . formatFileSize(IMAGE_MAX_SIZE);
} elseif (!in_array($fileExtension, IMAGE_EXTENSIONS_ALLOWED, true)) {
$fileError = true;
$errorMessage = "Invalid cover image extension.";
} else {
$imageType = exif_imagetype($fileTmpPath);
if (!$imageType || ($fileType && image_type_to_mime_type($imageType) != $fileType)) {
$fileError = true;
$errorMessage = "The cover image is either corrupted or of wrong type.";
} else {
if (!file_exists($modPendingUploadDirectory) && !mkdir($modPendingUploadDirectory, 0777, true)) {
$fileError = true;
$errorMessage = "An unexpected error occurred while uploading the cover image.";
}
if (!$fileError) {
$uploadedCoverImagePathname = $modPendingUploadDirectory . '/' . str_replace(['/', '\\'], '', $modDataToEdit['slug']) . '.' . $fileExtension;
if (!move_uploaded_file($fileTmpPath, $uploadedCoverImagePathname)) {
$fileError = true;
$errorMessage = "An unexpected error occurred while uploading the cover image.";
}
}
}
}
}
} else {
$fileExtension = $modDataToEdit['image_ext'] ? str_replace(['/', '\\'], '', $modDataToEdit['image_ext']) : null;
$liveCoverImagePathname = $modUploadDirectory . '/' . str_replace(['/', '\\'], '', $modDataToEdit['slug']) . '.' . $fileExtension;
if (file_exists($liveCoverImagePathname)) {
if (!file_exists($modPendingUploadDirectory) && !mkdir($modPendingUploadDirectory, 0777, true)) {
$fileError = true;
$errorMessage = "An unexpected error occurred while copying the cover image.";
}
if (!$fileError) {
$pendingCoverImagePathname = $modPendingUploadDirectory . '/' . str_replace(['/', '\\'], '', $modDataToEdit['slug']) . '.' . $fileExtension;
if (!copy($liveCoverImagePathname, $pendingCoverImagePathname)) {
$fileError = true;
$errorMessage = "An unexpected error occurred while copying the cover image.";
}
}
}
}
if (!$fileError) {
$statement = $connection->prepare("REPLACE INTO mods_pending (
id,
name,
slug,
description,
category,
link,
docs_link,
user,
image_ext,
is_paid,
is_rejected
) VALUES (
?,
?,
?,
?,
?,
?,
?,
?,
?,
?,
0
);");
if (!$statement) {
$errorMessage = "An unexpected error occurred while editing the mod.";
} else {
$modID = $modDataToEdit['pending'] ? $modDataToEdit['id'] : null;
$modName = $_POST['name'];
$modSlug = $modDataToEdit['slug'];
$modDescription = isset($_POST['description']) && $_POST['description'] ? $_POST['description'] : null;
$modCategory = $categoryID;
$modLink = $_POST['link'];
$modDocsLink = isset($_POST['docslink']) && $_POST['docslink'] ? $_POST['docslink'] : null;
$modUser = $_SESSION['user'];
$modImageExt = $fileExtension;
$modIsPaid = isset($_POST['paid']) ? 1 : 0;
$statement->bind_param('isssissisi', $modID, $modName, $modSlug, $modDescription, $modCategory, $modLink, $modDocsLink, $modUser, $modImageExt, $modIsPaid);
if (!$statement->execute()) {
$errorMessage = "An unexpected error occurred while editing the mod.";
$statement->close();
} else {
$modEdited = true;
$statement->close();
}
}
}
}
}
}
}
}
if (!$modEdited) {
$pageTitle = "Edit mod";
$pageDescription = "Edit the SVR.JS mod in SVR.JS Mods directory.";
} else {
$pageTitle = "Mod edited";
$pageDescription = "The edited mod is now awaiting moderators' approval.";
}
include 'header.php';
?>
The edited mod is now awaiting moderators' approval.Mod edited
Edit mod