php-gallery/index.php

119 lines
3.4 KiB
PHP
Raw Normal View History

<?php
require_once __DIR__."/app/required.php";
use App\Account;
use App\Sanity;
$user_info = new Account();
$sanity = new Sanity();
?>
2022-09-21 13:02:38 +00:00
2022-07-20 23:06:21 +00:00
<!DOCTYPE html>
<html>
<head>
<?php require_once __DIR__."/assets/ui/header.php"; ?>
</head>
2022-07-20 23:06:21 +00:00
<body>
2022-09-21 13:02:38 +00:00
<?php
2022-09-21 13:37:45 +00:00
require_once __DIR__."/assets/ui/nav.php";
2022-09-21 13:02:38 +00:00
2022-09-25 12:01:23 +00:00
if (isset($_SESSION['del'])) {
2022-09-21 13:02:38 +00:00
?>
<script>
2022-09-27 21:39:02 +00:00
sniffleAdd("Image Deleted", "Successfully deleted image: <?php echo $_SESSION['del']; ?>", "var(--success)", "assets/icons/trash.svg");
2022-09-21 13:02:38 +00:00
</script>
<?php
2022-09-25 12:01:23 +00:00
unset($_SESSION['del']);
2022-09-21 13:02:38 +00:00
}
2022-09-25 15:49:11 +00:00
if (isset($_SESSION['welc'])) {
?>
<script>
2022-09-27 21:39:02 +00:00
sniffleAdd('O hi <?php echo $_SESSION["username"]; ?>', 'You are now logged in, enjoy your stay!', 'var(--success)', 'assets/icons/hand-waving.svg');
2022-09-25 15:49:11 +00:00
</script>
<?php
unset($_SESSION['welc']);
if ($user_info->is_admin($conn, $_SESSION['id'])) {
$check_sanity = $sanity->get_results();
if (!empty($check_sanity) || isset($check_sanity)) {
?>
<script>
sniffleAdd('Uh oh', 'Website has not passed some Sanity checks, please check your settings for more information', 'var(--warning)', 'assets/icons/warning.svg');
</script>
<?php
}
}
2022-09-25 15:49:11 +00:00
}
2022-09-21 13:02:38 +00:00
?>
2022-08-11 18:28:52 +00:00
<?php
// Reading images from table
$image_request = mysqli_query($conn, "SELECT * FROM images ORDER BY id DESC");
2022-08-11 18:28:52 +00:00
if (!empty($image_request)) {
?>
<div class="info-text defaultFonts">
<?php
// Set time for message
$time = date("H");
$timezone = date("e");
if ($time < "12") {
$time_welc = "Good morning";
} else if ($time >= "12" && $time < "17") {
$time_welc = "Good afternoon";
} else if ($time >= "17" && $time < "19") {
$time_welc = "Good evening";
} else if ($time >= "19") {
$time_welc = "Good night";
}
2022-08-11 18:28:52 +00:00
// Welcome depending on if user is logged in or not
if (isset($_SESSION["username"])) {
echo "<h1>".$time_welc." ".$_SESSION['username']."!</h1>";
} else {
echo "<h1>".$time_welc."!</h1>";
}
2022-08-11 18:28:52 +00:00
// Random welcome message
$welcome_message = $user_settings['welcome_msg'];
echo "<p>".$welcome_message[array_rand($welcome_message, 1)]."</p>";
?>
</div>
<?php
2022-08-11 18:28:52 +00:00
echo "<div class='gallery-root defaultDecoration'>";
2022-08-11 18:28:52 +00:00
while ($image = mysqli_fetch_array($image_request)) {
// Getting thumbnail
if (file_exists("images/thumbnails/".$image['imagename'])) {
$image_path = "images/thumbnails/".$image['imagename'];
} else {
$image_path = "images/".$image['imagename'];
}
// Check for NSFW tag
if (str_contains($image['tags'], "nsfw")) {
echo "<div class='gallery-item'>
2022-09-29 11:56:14 +00:00
<a href='image.php?id=".$image['id']."' class='nsfw-warning'><img class='svg' src='assets/icons/warning_red.svg'><span>NSFW</span></a>
<a href='image.php?id=".$image['id']."'><img class='gallery-image nsfw-blur' loading='lazy' src='".$image_path."' id='".$image['id']."'></a>
</div>";
} else {
echo "<div class='gallery-item'>
2022-09-29 11:56:14 +00:00
<a href='image.php?id=".$image['id']."'><img class='gallery-image' loading='lazy' src='".$image_path."' id='".$image['id']."'></a>
</div>";
}
2022-09-14 14:08:50 +00:00
}
echo "</div>";
} else {
echo "<div class='info-text defaultFonts' style='text-align: center !important;'>
<h1>Nothing here!</h1>
<p>There are no images in the gallery, upload some!</p>
</div>";
2022-09-14 14:08:50 +00:00
}
2022-08-11 18:28:52 +00:00
?>
2022-09-21 13:37:45 +00:00
<?php require_once __DIR__."/assets/ui/footer.php"; ?>
2022-07-20 23:06:21 +00:00
</body>
</html>