809 lines
28 KiB
PHP
809 lines
28 KiB
PHP
<?php
|
|
if (!defined('SVRJS_MOD_DIRECTORY')) die;
|
|
|
|
// THIS PHP SCRIPT INCLUDE IS JUST FOR HTML PAGES! IT'S NOT INTENDED FOR OTHER FORMATS
|
|
ob_start();
|
|
|
|
// Disable caching
|
|
header("Cache-Control: no-store, no-cache, max-age=0, must-revalidate");
|
|
header("Pragma: no-cache");
|
|
if (COMPRESSION_ENABLED) {
|
|
header("Vary: Accept-Encoding, Cookie");
|
|
} else {
|
|
header("Vary: Cookie");
|
|
}
|
|
|
|
// Remove "Expires" header
|
|
header_remove("Expires");
|
|
|
|
// Enable session strict mode
|
|
ini_set('session.use_strict_mode', '1');
|
|
|
|
// Set session cookie flags
|
|
ini_set('session.cookie_httponly', '1');
|
|
if (isset($_SERVER['HTTPS'])) ini_set('session.cookie_secure', '1');
|
|
|
|
// Register the custom session handler
|
|
$sessionHandler = new MySQLSessionHandler($connection);
|
|
session_set_save_handler(
|
|
array($sessionHandler, 'open'),
|
|
array($sessionHandler, 'close'),
|
|
array($sessionHandler, 'read'),
|
|
array($sessionHandler, 'write'),
|
|
array($sessionHandler, 'destroy'),
|
|
array($sessionHandler, 'gc'),
|
|
array($sessionHandler, 'create_sid'),
|
|
array($sessionHandler, 'validate_sid')
|
|
);
|
|
|
|
if (session_start()) {
|
|
setupHeaders();
|
|
|
|
$csrfToken = "";
|
|
if (isset($_SESSION['csrf'])) {
|
|
$csrfToken = $_SESSION['csrf'];
|
|
} else {
|
|
if (function_exists('random_bytes')) {
|
|
$csrfToken = bin2hex(random_bytes(32));
|
|
} else {
|
|
$csrfToken = '';
|
|
for ($i = 0; $i < 32; $i++) {
|
|
$csrfToken = $csrfToken . bin2hex(rand(0, 255));
|
|
}
|
|
}
|
|
$_SESSION['csrf'] = $csrfToken;
|
|
}
|
|
|
|
if (isset($_SESSION['user'])) {
|
|
$statement = $connection->prepare("SELECT id, username FROM users WHERE id = ? AND is_suspended = 0 AND is_deleted = 0 AND is_verified = 1");
|
|
if (!$statement) {
|
|
unset($_SESSION['user']);
|
|
} else {
|
|
$statement->bind_param("i", $_SESSION['user']);
|
|
$statement->execute();
|
|
|
|
$result = $statement->get_result();
|
|
if (!$result || !$result->fetch_assoc()) {
|
|
unset($_SESSION['user']);
|
|
}
|
|
}
|
|
}
|
|
|
|
$segments = explode('/', isset($_SERVER['PATH_INFO']) ? $_SERVER['PATH_INFO'] : "/");
|
|
array_shift($segments);
|
|
|
|
if (count($segments) == 0 || (count($segments) == 1 && $segments[0] == '')) {
|
|
header("Cache-Control: public, max-age=60");
|
|
header_remove("Pragma");
|
|
include 'page_index.php';
|
|
} elseif (count($segments) == 1 && $segments[0] == 'tos') {
|
|
header("Cache-Control: public, max-age=300");
|
|
header_remove("Pragma");
|
|
include 'page_tos.php';
|
|
} elseif (count($segments) == 1 && $segments[0] == 'search') {
|
|
include 'page_search.php';
|
|
} elseif (count($segments) == 1 && $segments[0] == 'login') {
|
|
include 'page_login.php';
|
|
} elseif (count($segments) == 1 && $segments[0] == 'register') {
|
|
include 'page_register.php';
|
|
} elseif (count($segments) == 1 && $segments[0] == 'logout') {
|
|
include 'page_logout.php';
|
|
} elseif (count($segments) == 1 && $segments[0] == 'forgot-password') {
|
|
include 'page_forgotpassword.php';
|
|
} elseif (count($segments) == 1 && $segments[0] == 'confirm-password') {
|
|
include 'page_confirmpassword.php';
|
|
} elseif (count($segments) == 1 && $segments[0] == 'confirm-registration') {
|
|
include 'page_confirmregistration.php';
|
|
} elseif (count($segments) == 1 && $segments[0] == 'pending-mods') {
|
|
if (!isset($_SESSION['user'])) {
|
|
header("Cache-Control: public, max-age=30");
|
|
header_remove("Pragma");
|
|
header('Location: ' . (URL_REWRITTEN ? APP_ROOT : APP_ROOT . APP_FILENAME . '/') . 'login?redirect=' . urlencode($_SERVER['REQUEST_URI']));
|
|
http_response_code(302);
|
|
} else {
|
|
include 'page_pendingmods.php';
|
|
}
|
|
} elseif (count($segments) == 1 && $segments[0] == 'submit') {
|
|
if (!isset($_SESSION['user'])) {
|
|
header("Cache-Control: public, max-age=30");
|
|
header_remove("Pragma");
|
|
header('Location: ' . (URL_REWRITTEN ? APP_ROOT : APP_ROOT . APP_FILENAME . '/') . 'login?redirect=' . urlencode($_SERVER['REQUEST_URI']));
|
|
http_response_code(302);
|
|
} else {
|
|
include 'page_submit.php';
|
|
}
|
|
} elseif (count($segments) == 1 && $segments[0] == 'confirm-email') {
|
|
if (!isset($_SESSION['user'])) {
|
|
header("Cache-Control: public, max-age=30");
|
|
header_remove("Pragma");
|
|
header('Location: ' . (URL_REWRITTEN ? APP_ROOT : APP_ROOT . APP_FILENAME . '/') . 'login?redirect=' . urlencode($_SERVER['REQUEST_URI']));
|
|
http_response_code(302);
|
|
} else {
|
|
include 'page_confirmemail.php';
|
|
}
|
|
} elseif (count($segments) == 1 && $segments[0] == 'delete-account') {
|
|
if (!isset($_SESSION['user'])) {
|
|
header("Cache-Control: public, max-age=30");
|
|
header_remove("Pragma");
|
|
header('Location: ' . (URL_REWRITTEN ? APP_ROOT : APP_ROOT . APP_FILENAME . '/') . 'login?redirect=' . urlencode($_SERVER['REQUEST_URI']));
|
|
http_response_code(302);
|
|
} else {
|
|
$statement = $connection->prepare("SELECT id, username, password, is_moderator, email FROM users WHERE id = ?");
|
|
if (!$statement) {
|
|
http_response_code(500);
|
|
include 'page_500.php';
|
|
} else {
|
|
$statement->bind_param('i', $_SESSION['user']);
|
|
$statement->execute();
|
|
|
|
$result = $statement->get_result();
|
|
if (!$result) {
|
|
http_response_code(500);
|
|
include 'page_500.php';
|
|
$statement->close();
|
|
} else {
|
|
$userData = $result->fetch_assoc();
|
|
$statement->close();
|
|
|
|
if (!$userData) {
|
|
http_response_code(404);
|
|
include 'page_404.php';
|
|
} else {
|
|
include 'page_deleteaccount.php';
|
|
}
|
|
}
|
|
}
|
|
}
|
|
} elseif (count($segments) == 1 && $segments[0] == 'edit-profile') {
|
|
if (!isset($_SESSION['user'])) {
|
|
header("Cache-Control: public, max-age=30");
|
|
header_remove("Pragma");
|
|
header('Location: ' . (URL_REWRITTEN ? APP_ROOT : APP_ROOT . APP_FILENAME . '/') . 'login?redirect=' . urlencode($_SERVER['REQUEST_URI']));
|
|
http_response_code(302);
|
|
} else {
|
|
$statement = $connection->prepare("SELECT id, username, bio FROM users WHERE id = ?");
|
|
if (!$statement) {
|
|
http_response_code(500);
|
|
include 'page_500.php';
|
|
} else {
|
|
$statement->bind_param('i', $_SESSION['user']);
|
|
$statement->execute();
|
|
|
|
$result = $statement->get_result();
|
|
if (!$result) {
|
|
http_response_code(500);
|
|
include 'page_500.php';
|
|
$statement->close();
|
|
} else {
|
|
$userData = $result->fetch_assoc();
|
|
$statement->close();
|
|
|
|
if (!$userData) {
|
|
http_response_code(404);
|
|
include 'page_404.php';
|
|
} else {
|
|
include 'page_editprofile.php';
|
|
}
|
|
}
|
|
}
|
|
}
|
|
} elseif (count($segments) == 1 && $segments[0] == 'change-user-data') {
|
|
if (!isset($_SESSION['user'])) {
|
|
header("Cache-Control: public, max-age=30");
|
|
header_remove("Pragma");
|
|
header('Location: ' . (URL_REWRITTEN ? APP_ROOT : APP_ROOT . APP_FILENAME . '/') . 'login?redirect=' . urlencode($_SERVER['REQUEST_URI']));
|
|
http_response_code(302);
|
|
} else {
|
|
$statement = $connection->prepare("SELECT id, username, password, email, bio FROM users WHERE id = ?");
|
|
if (!$statement) {
|
|
http_response_code(500);
|
|
include 'page_500.php';
|
|
} else {
|
|
$statement->bind_param('i', $_SESSION['user']);
|
|
$statement->execute();
|
|
|
|
$result = $statement->get_result();
|
|
if (!$result) {
|
|
http_response_code(500);
|
|
include 'page_500.php';
|
|
$statement->close();
|
|
} else {
|
|
$userData = $result->fetch_assoc();
|
|
$statement->close();
|
|
|
|
if (!$userData) {
|
|
http_response_code(404);
|
|
include 'page_404.php';
|
|
} else {
|
|
include 'page_changeuserdata.php';
|
|
}
|
|
}
|
|
}
|
|
}
|
|
} elseif (count($segments) == 2 && $segments[0] == 'category') {
|
|
$statement = $connection->prepare("SELECT id, name, slug FROM categories WHERE slug = ?");
|
|
if (!$statement) {
|
|
http_response_code(500);
|
|
include 'page_500.php';
|
|
} else {
|
|
$statement->bind_param('s', $segments[1]);
|
|
$statement->execute();
|
|
|
|
$result = $statement->get_result();
|
|
if (!$result) {
|
|
http_response_code(500);
|
|
include 'page_500.php';
|
|
$statement->close();
|
|
} else {
|
|
$categoryData = $result->fetch_assoc();
|
|
$statement->close();
|
|
|
|
if (!$categoryData) {
|
|
http_response_code(404);
|
|
include 'page_404.php';
|
|
} else {
|
|
header("Cache-Control: public, max-age=60");
|
|
header_remove("Pragma");
|
|
include 'page_category.php';
|
|
}
|
|
}
|
|
}
|
|
} elseif (count($segments) == 2 && $segments[0] == 'user') {
|
|
$statement = $connection->prepare("SELECT
|
|
users.id AS id,
|
|
users.username AS username,
|
|
users.bio AS bio,
|
|
users.is_suspended AS is_suspended,
|
|
users.is_deleted AS is_deleted,
|
|
COUNT(mods.id) AS mods,
|
|
COUNT(reviews.id) AS reviews
|
|
FROM users
|
|
LEFT JOIN mods ON mods.user = users.id
|
|
AND mods.is_removed = 0
|
|
LEFT JOIN (
|
|
SELECT reviews.id, reviews.user FROM reviews
|
|
JOIN (
|
|
SELECT mods.id AS id FROM mods
|
|
JOIN users ON users.id = mods.user AND users.is_verified = 1 AND users.is_deleted = 0 AND users.is_suspended = 0
|
|
) AS mods ON mods.id = reviews.mod
|
|
) AS reviews ON reviews.user = users.id
|
|
WHERE users.is_verified = 1
|
|
GROUP BY users.id
|
|
HAVING LOWER(users.username) = LOWER(?);");
|
|
if (!$statement) {
|
|
http_response_code(500);
|
|
include 'page_500.php';
|
|
} else {
|
|
$statement->bind_param('s', $segments[1]);
|
|
$statement->execute();
|
|
|
|
$result = $statement->get_result();
|
|
if (!$result) {
|
|
http_response_code(500);
|
|
include 'page_500.php';
|
|
$statement->close();
|
|
} else {
|
|
$userData = $result->fetch_assoc();
|
|
$statement->close();
|
|
|
|
if (!$userData) {
|
|
http_response_code(404);
|
|
include 'page_404.php';
|
|
} elseif ($userData['is_deleted']) {
|
|
header("Cache-Control: public, max-age=300");
|
|
header_remove("Pragma");
|
|
http_response_code(410);
|
|
include 'page_userdeleted.php';
|
|
} elseif ($userData['is_suspended']) {
|
|
header("Cache-Control: public, max-age=300");
|
|
header_remove("Pragma");
|
|
http_response_code(410);
|
|
include 'page_usersuspended.php';
|
|
} else {
|
|
if (!isset($_SESSION['user'])) {
|
|
header("Cache-Control: public, max-age=30");
|
|
header_remove("Pragma");
|
|
}
|
|
include 'page_user.php';
|
|
}
|
|
}
|
|
}
|
|
} elseif (count($segments) == 2 && $segments[0] == 'user-mods') {
|
|
$statement = $connection->prepare("SELECT
|
|
users.id AS id,
|
|
users.username AS username,
|
|
users.bio AS bio,
|
|
users.is_suspended AS is_suspended,
|
|
users.is_deleted AS is_deleted,
|
|
COUNT(mods.id) AS mods
|
|
FROM users
|
|
LEFT JOIN mods ON mods.user = users.id
|
|
AND mods.is_removed = 0
|
|
WHERE users.is_verified = 1
|
|
GROUP BY users.id
|
|
HAVING LOWER(users.username) = LOWER(?);");
|
|
if (!$statement) {
|
|
http_response_code(500);
|
|
include 'page_500.php';
|
|
} else {
|
|
$statement->bind_param('s', $segments[1]);
|
|
$statement->execute();
|
|
|
|
$result = $statement->get_result();
|
|
if (!$result) {
|
|
http_response_code(500);
|
|
include 'page_500.php';
|
|
$statement->close();
|
|
} else {
|
|
$userData = $result->fetch_assoc();
|
|
$statement->close();
|
|
|
|
if (!$userData) {
|
|
http_response_code(404);
|
|
include 'page_404.php';
|
|
} elseif ($userData['is_deleted']) {
|
|
header("Cache-Control: public, max-age=300");
|
|
header_remove("Pragma");
|
|
http_response_code(410);
|
|
include 'page_userdeleted.php';
|
|
} elseif ($userData['is_suspended']) {
|
|
header("Cache-Control: public, max-age=300");
|
|
header_remove("Pragma");
|
|
http_response_code(410);
|
|
include 'page_usersuspended.php';
|
|
} else {
|
|
header("Cache-Control: public, max-age=60");
|
|
header_remove("Pragma");
|
|
include 'page_usermods.php';
|
|
}
|
|
}
|
|
}
|
|
} elseif (count($segments) == 2 && $segments[0] == 'user-reviews') {
|
|
$statement = $connection->prepare("SELECT
|
|
users.id AS id,
|
|
users.username AS username,
|
|
users.bio AS bio,
|
|
users.is_suspended AS is_suspended,
|
|
users.is_deleted AS is_deleted,
|
|
COUNT(reviews.id) AS reviews
|
|
FROM users
|
|
LEFT JOIN (
|
|
SELECT reviews.id, reviews.user FROM reviews
|
|
JOIN (
|
|
SELECT mods.id AS id FROM mods
|
|
JOIN users ON users.id = mods.user AND users.is_verified = 1 AND users.is_deleted = 0 AND users.is_suspended = 0
|
|
) AS mods ON mods.id = reviews.mod
|
|
) AS reviews ON reviews.user = users.id
|
|
WHERE users.is_verified = 1
|
|
GROUP BY users.id
|
|
HAVING LOWER(users.username) = LOWER(?);");
|
|
if (!$statement) {
|
|
http_response_code(500);
|
|
include 'page_500.php';
|
|
} else {
|
|
$statement->bind_param('s', $segments[1]);
|
|
$statement->execute();
|
|
|
|
$result = $statement->get_result();
|
|
if (!$result) {
|
|
http_response_code(500);
|
|
include 'page_500.php';
|
|
$statement->close();
|
|
} else {
|
|
$userData = $result->fetch_assoc();
|
|
$statement->close();
|
|
|
|
if (!$userData) {
|
|
http_response_code(404);
|
|
include 'page_404.php';
|
|
} elseif ($userData['is_deleted']) {
|
|
header("Cache-Control: public, max-age=300");
|
|
header_remove("Pragma");
|
|
http_response_code(410);
|
|
include 'page_userdeleted.php';
|
|
} elseif ($userData['is_suspended']) {
|
|
header("Cache-Control: public, max-age=300");
|
|
header_remove("Pragma");
|
|
http_response_code(410);
|
|
include 'page_usersuspended.php';
|
|
} else {
|
|
header("Cache-Control: public, max-age=60");
|
|
header_remove("Pragma");
|
|
include 'page_userreviews.php';
|
|
}
|
|
}
|
|
}
|
|
} elseif (count($segments) == 2 && $segments[0] == 'mod') {
|
|
$statement = $connection->prepare("SELECT
|
|
mods.id AS id,
|
|
mods.name AS name,
|
|
mods.slug AS slug,
|
|
mods.description AS description,
|
|
categories.name AS category,
|
|
categories.slug AS category_slug,
|
|
mods.link AS link,
|
|
mods.docs_link AS docs_link,
|
|
mods.image_ext AS image_ext,
|
|
mods.is_paid AS is_paid,
|
|
mods.is_removed AS is_removed,
|
|
users.is_suspended AS is_user_suspended,
|
|
users.is_verified AS is_user_verified,
|
|
users.is_deleted AS is_user_deleted,
|
|
users.username AS user,
|
|
users.id AS user_id,
|
|
AVG(reviews.rating) AS rating,
|
|
COUNT(reviews.id) AS reviews
|
|
FROM mods
|
|
LEFT JOIN categories ON categories.id = mods.category
|
|
JOIN users ON users.id = mods.user
|
|
LEFT JOIN (
|
|
SELECT
|
|
reviews.rating AS rating,
|
|
reviews.id AS id,
|
|
reviews.mod AS `mod`
|
|
FROM reviews
|
|
JOIN users ON users.id = reviews.user AND users.is_verified = 1 AND users.is_deleted = 0 AND users.is_suspended = 0
|
|
) AS reviews ON reviews.mod = mods.id
|
|
WHERE mods.slug = ?
|
|
GROUP BY mods.id;");
|
|
if (!$statement) {
|
|
http_response_code(500);
|
|
include 'page_500.php';
|
|
} else {
|
|
$statement->bind_param('s', $segments[1]);
|
|
$statement->execute();
|
|
|
|
$result = $statement->get_result();
|
|
if (!$result) {
|
|
http_response_code(500);
|
|
include 'page_500.php';
|
|
$statement->close();
|
|
} else {
|
|
$modData = $result->fetch_assoc();
|
|
$statement->close();
|
|
|
|
if (!$modData || !$modData['is_user_verified']) {
|
|
http_response_code(404);
|
|
include 'page_404.php';
|
|
} elseif ($modData['is_removed'] || $modData['is_user_suspended'] || $modData['is_user_deleted']) {
|
|
header("Cache-Control: public, max-age=300");
|
|
header_remove("Pragma");
|
|
http_response_code(410);
|
|
include 'page_modremoved.php';
|
|
} else {
|
|
header("Cache-Control: public, max-age=300");
|
|
header_remove("Pragma");
|
|
include 'page_mod.php';
|
|
}
|
|
}
|
|
}
|
|
} elseif (count($segments) == 2 && $segments[0] == 'edit-mod') {
|
|
if (!isset($_SESSION['user'])) {
|
|
header("Cache-Control: public, max-age=30");
|
|
header_remove("Pragma");
|
|
header('Location: ' . (URL_REWRITTEN ? APP_ROOT : APP_ROOT . APP_FILENAME . '/') . 'login?redirect=' . urlencode($_SERVER['REQUEST_URI']));
|
|
http_response_code(302);
|
|
} else {
|
|
$statement = $connection->prepare("SELECT
|
|
mods.id AS id,
|
|
mods.name AS name,
|
|
mods.slug AS slug,
|
|
mods.description AS description,
|
|
mods.category AS category_id,
|
|
mods.link AS link,
|
|
mods.docs_link AS docs_link,
|
|
mods.image_ext AS image_ext,
|
|
mods.is_paid AS is_paid,
|
|
mods.is_removed AS is_removed,
|
|
users.is_suspended AS is_user_suspended,
|
|
users.is_verified AS is_user_verified,
|
|
users.is_deleted AS is_user_deleted,
|
|
users.id AS user_id,
|
|
0 AS pending
|
|
FROM mods
|
|
JOIN users ON users.id = mods.user
|
|
WHERE mods.slug = ?;");
|
|
if (!$statement) {
|
|
http_response_code(500);
|
|
include 'page_500.php';
|
|
} else {
|
|
$statement->bind_param('s', $segments[1]);
|
|
$statement->execute();
|
|
|
|
$result = $statement->get_result();
|
|
if (!$result) {
|
|
http_response_code(500);
|
|
include 'page_500.php';
|
|
$statement->close();
|
|
} else {
|
|
$currentModData = $result->fetch_assoc();
|
|
$statement->close();
|
|
|
|
if ($currentModData && !$currentModData['is_user_verified']) {
|
|
http_response_code(404);
|
|
include 'page_404.php';
|
|
} elseif ($currentModData && ($currentModData['is_removed'] || $currentModData['is_user_suspended'] || $currentModData['is_user_deleted'])) {
|
|
header("Cache-Control: public, max-age=300");
|
|
header_remove("Pragma");
|
|
http_response_code(410);
|
|
include 'page_modremoved.php';
|
|
} elseif ($currentModData && ($currentModData['user_id'] != $_SESSION['user'])) {
|
|
header("Cache-Control: public, max-age=300");
|
|
header_remove("Pragma");
|
|
http_response_code(403);
|
|
include 'page_editmodnotallowed.php';
|
|
} else {
|
|
$statement = $connection->prepare("SELECT
|
|
mods_pending.id AS id,
|
|
mods_pending.name AS name,
|
|
mods_pending.slug AS slug,
|
|
mods_pending.description AS description,
|
|
mods_pending.category AS category_id,
|
|
mods_pending.link AS link,
|
|
mods_pending.docs_link AS docs_link,
|
|
mods_pending.image_ext AS image_ext,
|
|
mods_pending.is_paid AS is_paid,
|
|
mods_pending.is_rejected AS is_rejected,
|
|
users.is_suspended AS is_user_suspended,
|
|
users.is_verified AS is_user_verified,
|
|
users.is_deleted AS is_user_deleted,
|
|
users.id AS user_id,
|
|
1 AS pending
|
|
FROM mods_pending
|
|
JOIN users ON users.id = mods_pending.user
|
|
WHERE mods_pending.slug = ?;");
|
|
if (!$statement) {
|
|
http_response_code(500);
|
|
include 'page_500.php';
|
|
} else {
|
|
$statement->bind_param('s', $segments[1]);
|
|
$statement->execute();
|
|
|
|
$result = $statement->get_result();
|
|
if (!$result) {
|
|
http_response_code(500);
|
|
include 'page_500.php';
|
|
$statement->close();
|
|
} else {
|
|
$pendingModData = $result->fetch_assoc();
|
|
$statement->close();
|
|
|
|
$modDataToEdit = $pendingModData && !($currentModData && $pendingModData['is_rejected']) ? $pendingModData : $currentModData;
|
|
|
|
if (!$modDataToEdit) {
|
|
http_response_code(404);
|
|
include 'page_404.php';
|
|
} elseif ($modDataToEdit['user_id'] != $_SESSION['user']) {
|
|
header("Cache-Control: public, max-age=300");
|
|
header_remove("Pragma");
|
|
http_response_code(403);
|
|
include 'page_editmodnotallowed.php';
|
|
} else {
|
|
include 'page_editmod.php';
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
} elseif (count($segments) == 2 && $segments[0] == 'reviews') {
|
|
$statement = $connection->prepare("SELECT
|
|
mods.id AS id,
|
|
mods.name AS name,
|
|
mods.slug AS slug,
|
|
mods.description AS description,
|
|
categories.name AS category,
|
|
categories.slug AS category_slug,
|
|
mods.link AS link,
|
|
mods.docs_link AS docs_link,
|
|
mods.image_ext AS image_ext,
|
|
mods.is_paid AS is_paid,
|
|
mods.is_removed AS is_removed,
|
|
users.is_suspended AS is_user_suspended,
|
|
users.is_verified AS is_user_verified,
|
|
users.is_deleted AS is_user_deleted,
|
|
users.username AS user,
|
|
users.id AS user_id,
|
|
users.email AS user_email,
|
|
AVG(reviews.rating) AS rating,
|
|
COUNT(reviews.id) AS reviews
|
|
FROM mods
|
|
LEFT JOIN categories ON categories.id = mods.category
|
|
JOIN users ON users.id = mods.user
|
|
LEFT JOIN (
|
|
SELECT
|
|
reviews.rating AS rating,
|
|
reviews.id AS id,
|
|
reviews.mod AS `mod`
|
|
FROM reviews
|
|
JOIN users ON users.id = reviews.user AND users.is_verified = 1 AND users.is_deleted = 0 AND users.is_suspended = 0
|
|
) AS reviews ON reviews.mod = mods.id
|
|
WHERE mods.slug = ?
|
|
GROUP BY mods.id;");
|
|
if (!$statement) {
|
|
http_response_code(500);
|
|
include 'page_500.php';
|
|
} else {
|
|
$statement->bind_param('s', $segments[1]);
|
|
$statement->execute();
|
|
|
|
$result = $statement->get_result();
|
|
if (!$result) {
|
|
http_response_code(500);
|
|
include 'page_500.php';
|
|
$statement->close();
|
|
} else {
|
|
$modData = $result->fetch_assoc();
|
|
$statement->close();
|
|
|
|
if (!$modData || !$modData['is_user_verified']) {
|
|
http_response_code(404);
|
|
include 'page_404.php';
|
|
} elseif ($modData['is_removed'] || $modData['is_user_suspended'] || $modData['is_user_deleted']) {
|
|
header("Cache-Control: public, max-age=300");
|
|
header_remove("Pragma");
|
|
http_response_code(410);
|
|
include 'page_modremoved.php';
|
|
} else {
|
|
if (!isset($_SESSION['user'])) {
|
|
header("Cache-Control: public, max-age=30");
|
|
header_remove("Pragma");
|
|
}
|
|
include 'page_reviews.php';
|
|
}
|
|
}
|
|
}
|
|
} elseif (count($segments) == 2 && $segments[0] == 'discard-mod') {
|
|
if (!isset($_SESSION['user'])) {
|
|
header("Cache-Control: public, max-age=30");
|
|
header_remove("Pragma");
|
|
header('Location: ' . (URL_REWRITTEN ? APP_ROOT : APP_ROOT . APP_FILENAME . '/') . 'login?redirect=' . urlencode($_SERVER['REQUEST_URI']));
|
|
http_response_code(302);
|
|
} else {
|
|
$statement = $connection->prepare("SELECT
|
|
mods_pending.id AS id,
|
|
mods_pending.name AS name,
|
|
mods_pending.slug AS slug,
|
|
mods_pending.description AS description,
|
|
mods_pending.category AS category_id,
|
|
mods_pending.link AS link,
|
|
mods_pending.docs_link AS docs_link,
|
|
mods_pending.image_ext AS image_ext,
|
|
mods_pending.is_paid AS is_paid,
|
|
mods_pending.is_rejected AS is_rejected,
|
|
users.is_suspended AS is_user_suspended,
|
|
users.is_verified AS is_user_verified,
|
|
users.is_deleted AS is_user_deleted,
|
|
users.id AS user_id
|
|
FROM mods_pending
|
|
JOIN users ON users.id = mods_pending.user
|
|
WHERE mods_pending.slug = ?;");
|
|
if (!$statement) {
|
|
http_response_code(500);
|
|
include 'page_500.php';
|
|
} else {
|
|
$statement->bind_param('s', $segments[1]);
|
|
$statement->execute();
|
|
|
|
$result = $statement->get_result();
|
|
if (!$result) {
|
|
http_response_code(500);
|
|
include 'page_500.php';
|
|
$statement->close();
|
|
} else {
|
|
$modDataToDiscard = $result->fetch_assoc();
|
|
$statement->close();
|
|
|
|
if (!$modDataToDiscard || !$modDataToDiscard['is_user_verified']) {
|
|
http_response_code(404);
|
|
include 'page_404.php';
|
|
} elseif (($modDataToDiscard['is_removed'] || $modDataToDiscard['is_user_suspended'] || $modDataToDiscard['is_user_deleted'])) {
|
|
header("Cache-Control: public, max-age=300");
|
|
header_remove("Pragma");
|
|
http_response_code(410);
|
|
include 'page_modremoved.php';
|
|
} elseif ($modDataToDiscard['user_id'] != $_SESSION['user']) {
|
|
header("Cache-Control: public, max-age=300");
|
|
header_remove("Pragma");
|
|
http_response_code(403);
|
|
include 'page_discardmodnotallowed.php';
|
|
} else {
|
|
include 'page_discardmod.php';
|
|
}
|
|
}
|
|
}
|
|
}
|
|
} elseif (count($segments) == 2 && $segments[0] == 'remove-mod') {
|
|
if (!isset($_SESSION['user'])) {
|
|
header("Cache-Control: public, max-age=30");
|
|
header_remove("Pragma");
|
|
header('Location: ' . (URL_REWRITTEN ? APP_ROOT : APP_ROOT . APP_FILENAME . '/') . 'login?redirect=' . urlencode($_SERVER['REQUEST_URI']));
|
|
http_response_code(302);
|
|
} else {
|
|
$statement = $connection->prepare("SELECT
|
|
mods.id AS id,
|
|
mods.name AS name,
|
|
mods.slug AS slug,
|
|
mods.description AS description,
|
|
mods.category AS category_id,
|
|
mods.link AS link,
|
|
mods.docs_link AS docs_link,
|
|
mods.image_ext AS image_ext,
|
|
mods_pending.image_ext AS pending_image_ext,
|
|
mods.is_paid AS is_paid,
|
|
mods.is_removed AS is_removed,
|
|
users.is_suspended AS is_user_suspended,
|
|
users.is_verified AS is_user_verified,
|
|
users.is_deleted AS is_user_deleted,
|
|
users.id AS user_id
|
|
FROM mods
|
|
LEFT JOIN mods_pending ON mods.slug = mods_pending.slug
|
|
JOIN users ON users.id = mods.user
|
|
WHERE mods.slug = ?;");
|
|
if (!$statement) {
|
|
http_response_code(500);
|
|
include 'page_500.php';
|
|
} else {
|
|
$statement->bind_param('s', $segments[1]);
|
|
$statement->execute();
|
|
|
|
$result = $statement->get_result();
|
|
if (!$result) {
|
|
http_response_code(500);
|
|
include 'page_500.php';
|
|
$statement->close();
|
|
} else {
|
|
$modDataToRemove = $result->fetch_assoc();
|
|
$statement->close();
|
|
|
|
if (!$modDataToRemove || !$modDataToRemove['is_user_verified']) {
|
|
http_response_code(404);
|
|
include 'page_404.php';
|
|
} elseif (($modDataToRemove['is_removed'] || $modDataToRemove['is_user_suspended'] || $modDataToRemove['is_user_deleted'])) {
|
|
header("Cache-Control: public, max-age=300");
|
|
header_remove("Pragma");
|
|
http_response_code(410);
|
|
include 'page_modremoved.php';
|
|
} elseif ($modDataToRemove['user_id'] != $_SESSION['user']) {
|
|
header("Cache-Control: public, max-age=300");
|
|
header_remove("Pragma");
|
|
http_response_code(403);
|
|
include 'page_removemodnotallowed.php';
|
|
} else {
|
|
include 'page_removemod.php';
|
|
}
|
|
}
|
|
}
|
|
}
|
|
} else {
|
|
http_response_code(404);
|
|
include 'page_404.php';
|
|
}
|
|
|
|
if (session_id()) session_write_close();
|
|
} else {
|
|
setupHeaders();
|
|
http_response_code(500);
|
|
include 'page_500.php';
|
|
}
|
|
|
|
if (ob_get_status()) {
|
|
$content = ob_get_clean();
|
|
|
|
if ($content && COMPRESSION_ENABLED && isset($_SERVER['HTTP_ACCEPT_ENCODING'])) {
|
|
$acceptEncoding = array_map(function ($encoding) {
|
|
return trim($encoding);
|
|
}, explode(',', $_SERVER['HTTP_ACCEPT_ENCODING']));
|
|
|
|
if (in_array('gzip', $acceptEncoding)) {
|
|
$content = gzencode($content, 9);
|
|
header('Content-Encoding: gzip');
|
|
} elseif (in_array('deflate', $acceptEncoding)) {
|
|
$content = gzdeflate($content, 9);
|
|
header('Content-Encoding: deflate');
|
|
}
|
|
}
|
|
|
|
echo $content;
|
|
}
|