prepare("SELECT mods_pending.id AS id, mods_pending.is_rejected AS is_rejected, mods_pending.name AS name, mods_pending.slug AS slug, mods_pending.description AS description, mods_pending.image_ext AS image_ext, mods_pending.is_paid AS is_paid, mods_pending.category AS category, mods_pending.link AS link, mods_pending.docs_link AS docs_link, mods_pending.is_paid AS is_paid, users.username AS username, users.email AS user_email, users.id AS user FROM mods_pending JOIN users ON users.id = mods_pending.user AND users.is_suspended = 0 AND users.is_deleted = 0 AND users.is_verified = 1 WHERE mods_pending.id = ?"); if (!$statement) { $errorMessage = "An unexcepted error occurred when checking the pending mod."; } else { $statement->bind_param('i', $pendingModID); $statement->execute(); $result = $statement->get_result(); if (!$result) { $errorMessage = "An unexcepted error occurred when checking the pending mod."; $statement->close(); } else { $modData = $result->fetch_assoc(); $statement->close(); if (!$modData) { $errorMessage = "The pending mod doesn't exist."; } elseif ($modData['is_rejected']) { $errorMessage = "The pending mod is rejected."; } else { if (!isset($_POST['action'])) { $errorMessage = "No action specified."; } elseif ($_POST['action'] == "approve") { $modUploadDirectory = APP_FSROOT . '/img/mods'; $modPendingUploadDirectory = APP_FSROOT . '/img/mods_pending'; $pendingCoverImagePathname = isset($modData['image_ext']) && $modData['image_ext'] ? $modPendingUploadDirectory . '/' . str_replace(['/', '\\'], '', $modData['slug']) . '.' . str_replace(['/', '\\'], '', $modData['image_ext']) : null; $liveCoverImagePathname = isset($modData['image_ext']) && $modData['image_ext'] ? $modUploadDirectory . '/' . str_replace(['/', '\\'], '', $modData['slug']) . '.' . str_replace(['/', '\\'], '', $modData['image_ext']) : null; $fileError = false; if ($pendingCoverImagePathname && file_exists($pendingCoverImagePathname)) { if (!file_exists($modUploadDirectory) && !mkdir($modUploadDirectory, 0777, true)) { $fileError = true; $errorMessage = "An unexpected error occurred while approving the mod."; } if (!$fileError) { if ($liveCoverImagePathname && !rename($pendingCoverImagePathname, $liveCoverImagePathname)) { $fileError = true; $errorMessage = "An unexpected error occurred while approving the mod."; } } } if (!$fileError) { $existingModIDError = false; $existingModID = null; $statement = $connection->prepare('SELECT id FROM mods WHERE slug = ?;'); if (!$statement) { $existingModIDError = true; $errorMessage = "An unexpected error occurred while approving the mod."; } else { $statement->bind_param('s', $modData['slug']); $statement->execute(); $result = $statement->get_result(); if (!$result) { $existingModIDError = true; $errorMessage = "An unexpected error occurred while approving the mod."; $statement->close(); } else { $row = $result->fetch_assoc(); $statement->close(); if ($row && $row['id']) $existingModID = $row['id']; } } if (!$existingModIDError) { $statement = $connection->prepare('REPLACE INTO mods ( id, name, slug, description, category, link, docs_link, user, image_ext, is_paid, is_removed ) VALUES ( ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, 0 );'); if (!$statement) { $errorMessage = "An unexpected error occurred while approving the mod."; } else { $statement->bind_param('isssissisi', $existingModID, $modData['name'], $modData['slug'], $modData['description'], $modData['category'], $modData['link'], $modData['docs_link'], $modData['user'], $modData['image_ext'], $modData['is_paid']); if (!$statement->execute()) { $errorMessage = "An unexpected error occurred while approving the mod."; $statement->close(); } else { $statement->close(); $statement = $connection->prepare('DELETE FROM mods_pending WHERE id = ?'); if (!$statement) { $errorMessage = "An unexpected error occurred while approving the mod."; } else { $statement->bind_param('i', $modData['id']); if (!$statement->execute()) { $errorMessage = "An unexpected error occurred while approving the mod."; $statement->close(); } else { $modApproved = true; $statement->close(); } } } } } } } elseif ($_POST['action'] == "reject") { if (!isset($_POST['reason']) || !$_POST['reason']) { $errorMessage = "You need to specify the reason for rejection."; } else { $statement = $connection->prepare('UPDATE mods_pending SET is_rejected = 1 WHERE id = ?'); if (!$statement) { $errorMessage = "An unexpected error occurred while rejecting the mod."; } else { $statement->bind_param('i', $modData['id']); if (!$statement->execute()) { $errorMessage = "An unexpected error occurred while rejecting the mod."; $statement->close(); } else { $modRejected = true; $statement->close(); } } } } else { $errorMessage = "Unknown action specified."; } } } } } } $pageTitle = "Pending mods"; include '../includes/moderation_header.php'; ?>

Pending mods

' . htmlspecialchars($errorMessage) . '

'; ?> Mod has been approved.

'; } elseif ($modRejected) { echo '

Mod has been rejected.

'; } ?> query('SELECT mods_pending.id AS id, mods_pending.name AS name, mods_pending.slug AS slug, mods_pending.description AS description, mods_pending.image_ext AS image_ext, mods_pending.is_paid AS is_paid, mods_pending.link AS link, mods_pending.docs_link AS docs_link, categories.name AS category, users.username AS user, users.id AS user_id FROM mods_pending LEFT JOIN categories ON categories.id = mods_pending.category JOIN users ON users.id = mods_pending.user AND users.is_suspended = 0 AND users.is_deleted = 0 AND users.is_verified = 1 WHERE mods_pending.is_rejected = 0 ORDER BY mods_pending.id DESC;'); if (!$result) { echo "

An unexpected error occurred while fetching mods.

"; } else { $modsPresent = false; while ($mod = $result->fetch_assoc()) { $modsPresent = true; echo '
' . htmlspecialchars($mod['name']) . ' cover image

' . htmlspecialchars($mod['name']) . '

' . ($mod['is_paid'] ? 'Paid' : 'Gratis') . '

' . (isset($mod['description']) && $mod['description'] ? str_replace(["\r\n", "\n", "\r"], '
', htmlspecialchars(shortenDescription($mod['description']))) : "No description") . '

Publisher: ' . htmlspecialchars($mod['user']) . ' | Category: ' . htmlspecialchars($mod['category']) . '

Download URL: ' . htmlspecialchars($mod['link']) . '

' . ($mod['docs_link'] ? '

Documentation URL: ' . htmlspecialchars($mod['docs_link']) . '

' : '') . '
'; } if (!$modsPresent) { echo '

No mods.

'; } } ?> $modData['username'], "address" => $modData['user_email'] ]], 'Your mod has been approved.', 'Good news for you! Your "' . str_replace(["\r\n", "\n", "\r"], '', $modData['name']) . '" mod has been approved and is now listed on SVR.JS Mods directory!' ); } elseif ($modRejected) { sendEmail( [[ "name" => $modData['username'], "address" => $modData['user_email'] ]], 'Your mod has been rejected.', 'Unfortunately, your "' . str_replace(["\r\n", "\n", "\r"], '', $modData['name']) . "\" mod has been rejected by the moderator. Below is the reason why the moderator rejected this mod:\n\n" . $_POST['reason'] ); } include '../includes/moderation_final.php'; include '../includes/final.php'; ?>