Initial commit
This commit is contained in:
65
web/public/index.php
Normal file
65
web/public/index.php
Normal file
@@ -0,0 +1,65 @@
|
||||
<?php
|
||||
// public/index.php
|
||||
|
||||
require_once '../vendor/autoload.php';
|
||||
|
||||
use Hpz\Photogal\Database;
|
||||
use Hpz\Photogal\Image;
|
||||
|
||||
$dotenv = Dotenv\Dotenv::createImmutable('../');
|
||||
$dotenv->load();
|
||||
if (!isset($_ENV['DB_FILE_PATH'])) {
|
||||
die('DB_FILE_PATH is not set in the .env file');
|
||||
}
|
||||
if (!file_exists('../' . $_ENV['DB_FILE_PATH'])) {
|
||||
die('Database file does not exist');
|
||||
}
|
||||
|
||||
// Create a new Database connection
|
||||
$dbFilePath = '../' . $_ENV['DB_FILE_PATH'];
|
||||
$database = new Database($dbFilePath);
|
||||
$image = new Image($database);
|
||||
|
||||
// Get the list of albums
|
||||
$albumsQuery = "SELECT DISTINCT album FROM images";
|
||||
$albumsResult = $database->getConnection()->query($albumsQuery);
|
||||
$albums = [];
|
||||
while ($row = $albumsResult->fetchArray(SQLITE3_ASSOC)) {
|
||||
$albums[] = $row['album'];
|
||||
}
|
||||
|
||||
// Fetch the first image from each album
|
||||
$albumPreviews = [];
|
||||
foreach ($albums as $album) {
|
||||
$albumPreviews[$album] = $image->getImages($album, 1, 0)[0] ?? null;
|
||||
}
|
||||
?>
|
||||
|
||||
<!DOCTYPE html>
|
||||
<html lang="en">
|
||||
<head>
|
||||
<meta charset="UTF-8">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||
<title>Photo Gallery - Select Album</title>
|
||||
<link href="/css/styles.css" rel="stylesheet">
|
||||
</head>
|
||||
<body class="bg-gray-100">
|
||||
<div class="container mx-auto p-4">
|
||||
<h1 class="text-3xl font-bold mb-4">Select an Album</h1>
|
||||
<div class="grid grid-cols-2 md:grid-cols-4 gap-4">
|
||||
<?php foreach ($albumPreviews as $album => $image): ?>
|
||||
<?php if ($image): ?>
|
||||
<div class="bg-white shadow-md rounded-lg overflow-hidden">
|
||||
<a href="gallery.php?album=<?= urlencode($album) ?>">
|
||||
<img src="images/<?= $album ?>/thumbs/<?= $image['title'] ?>.webp" alt="<?= htmlspecialchars($album) ?>" class="w-full h-48 object-cover">
|
||||
<div class="p-4">
|
||||
<h2 class="text-xl font-semibold"><?= htmlspecialchars($album) ?></h2>
|
||||
</div>
|
||||
</a>
|
||||
</div>
|
||||
<?php endif; ?>
|
||||
<?php endforeach; ?>
|
||||
</div>
|
||||
</div>
|
||||
</body>
|
||||
</html>
|
||||
Reference in New Issue
Block a user