svrjs-mods-directory/moderation/reviews.php

84 lines
2.9 KiB
PHP
Raw Normal View History

2024-12-27 15:05:54 +01:00
<?php
define("SVRJS_MOD_DIRECTORY", null);
define("SVRJS_MOD_DIRECTORY_MODERATION", null);
include '../config.php';
$appModerationRoot = dirname($_SERVER['SCRIPT_NAME']);
if ($appModerationRoot[strlen($appModerationRoot) - 1] != "/") $appModerationRoot = $appModerationRoot . '/';
$appRoot = dirname($_SERVER['SCRIPT_NAME'], 2);
if ($appRoot[strlen($appRoot) - 1] != "/") $appRoot = $appRoot . '/';
define('APP_ROOT', $appRoot);
define('APP_FSROOT', dirname(__FILE__, 2));
define('APP_MODERATION_FILENAME', basename($_SERVER['SCRIPT_NAME']));
define('APP_MODERATION_ROOT', $appModerationRoot);
include '../vendor/autoload.php';
include '../includes/init.php';
include '../includes/moderation_init.php';
$pageTitle = number_format(PAGE_REVIEWS, 0) . " latest reviews";
include '../includes/moderation_header.php';
?>
<h1><?php echo htmlspecialchars(number_format(PAGE_REVIEWS, 0)); ?> latest reviews</h1>
<?php
$statement = $connection->prepare('SELECT
reviews.id AS id,
reviews.rating AS rating,
reviews.review AS review,
mods.name AS mod_name,
mods.slug AS mod_slug,
users.username AS user,
users.id AS user_id
FROM reviews
JOIN (
SELECT mods.id AS id, mods.is_removed AS is_removed, mods.name AS name, mods.slug AS slug 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
JOIN users ON users.id = reviews.user
WHERE mods.is_removed = 0
AND users.is_suspended = 0
AND users.is_deleted = 0
AND users.is_verified = 1
ORDER BY reviews.id DESC
LIMIT ?;');
if (!$statement) {
echo "<p>An unexpected error occurred while fetching reviews.</p>";
} else {
$shownReviews = PAGE_REVIEWS;
$statement->bind_param('i', $shownReviews);
$statement->execute();
$result = $statement->get_result();
if (!$result) {
echo "<p>An unexpected error occurred while fetching reviews.</p>";
$statement->close();
} else {
$reviewsPresent = false;
while ($review = $result->fetch_assoc()) {
$reviewsPresent = true;
echo '<div class="review"><div class="review-header">';
$stars = round($review['rating']);
echo '<span class="rating-stars">';
for ($i = 0; $i < $stars; $i++) {
echo '<span class="rating-star rating-star-higlighted">&starf;</span>';
}
for ($i = $stars; $i < 5; $i++) {
echo '<span class="rating-star">&starf;</span>';
}
echo ' | by <a href="' . htmlspecialchars(APP_MODERATION_ROOT . 'user.php?user=' . urlencode($review['user'])) . '">' . htmlspecialchars($review['user']) . '</a> | on ' . htmlspecialchars($review['mod_name']) . '</div><p>' . str_replace(["\r\n", "\n", "\r"], '<br/>', htmlspecialchars($review['review'])) . '</div>';
}
if (!$reviewsPresent) {
echo '<p>No reviews.</p>';
}
$statement->close();
}
}
?>
<?php
include '../includes/moderation_footer.php';
include '../includes/moderation_final.php';
include '../includes/final.php';
?>