Search

>
prepare('SELECT COUNT(mods.id) AS count FROM mods JOIN users ON users.id = mods.user WHERE mods.is_removed = 0 AND users.is_suspended = 0 AND users.is_deleted = 0 AND users.is_verified = 1 AND ( MATCH (mods.name, mods.description) AGAINST (? IN NATURAL LANGUAGE MODE) OR mods.name LIKE ? OR mods.description LIKE ? );'); if (!$countStatement) { echo "

An unexpected error occurred while fetching mods.

"; } else { $countStatement->bind_param('sss', $searchQuery, $queryLike, $queryLike); $countStatement->execute(); $countResult = $countStatement->get_result(); if (!$countResult) { echo "

An unexpected error occurred while fetching mods.

"; $countStatement->close(); } else { $countRow = $countResult->fetch_assoc(); $countStatement->close(); if (!$countRow) { echo "

An unexpected error occurred while fetching mods.

"; } else { $modCount = $countRow['count']; $totalPages = ceil($modCount / PAGE_MODS); $statement = $connection->prepare('SELECT mods.id AS id, mods.name AS name, mods.slug AS slug, mods.description AS description, mods.image_ext AS image_ext, mods.is_paid AS is_paid, categories.name AS category, categories.slug AS category_slug, users.username AS user, users.id AS user_id, AVG(reviews.rating) AS rating, COUNT(reviews.id) AS reviews, MATCH (mods.name, mods.description) AGAINST (? IN NATURAL LANGUAGE MODE) AS score FROM mods LEFT JOIN categories ON categories.id = mods.category 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 JOIN users ON users.id = mods.user WHERE mods.is_removed = 0 AND users.is_suspended = 0 AND users.is_deleted = 0 AND users.is_verified = 1 GROUP BY mods.id HAVING ( score > 0 OR mods.name LIKE ? OR mods.description LIKE ? ) ORDER BY score DESC, IFNULL(rating, 0) DESC, reviews DESC LIMIT ?,?;'); if (!$statement) { echo "

An unexpected error occurred while fetching mods.

"; } else { $pageNumber = isset($_GET['page']) && filter_var($_GET['page'], FILTER_VALIDATE_INT) ? intval($_GET['page']) : 1; $firstNumber = PAGE_MODS * ($pageNumber - 1); $pageMods = PAGE_MODS; $statement->bind_param('sssii', $searchQuery, $queryLike, $queryLike, $firstNumber, $pageMods); $statement->execute(); $result = $statement->get_result(); if (!$result) { echo "

An unexpected error occurred while fetching mods.

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

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

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

Publisher: ' . htmlspecialchars($mod['user']) . '' . (isset($_SESSION['user']) && $_SESSION['user'] == $mod['user_id'] ? ' | Edit mod' : '') . '

' . ($mod['rating'] ? '' . htmlspecialchars(number_format($mod['rating'], 2)) . ' ★' : '') . ' ' . ($mod['is_paid'] ? 'Paid' : 'Gratis') . '
'; } if ($modsPresent) { echo '
'; } else { echo '

No mods found matching the “' . htmlspecialchars($searchQuery) . '” query.

'; } $statement->close(); if ($totalPages > 1) { $begPage = $pageNumber - 2; $endPage = $pageNumber + 2; if ($endPage > $totalPages) { $begPage -= $endPage - $totalPages; $endPage = $totalPages; } if ($begPage < 1) { $endPage += 1 - $begPage; $begPage = 1; } echo ''; } } } } } } } ?>