mirror of
https://codeberg.org/PostERG/xamxam.git
synced 2026-05-06 11:09:18 +02:00
129 lines
5.2 KiB
PHP
129 lines
5.2 KiB
PHP
<?php
|
||
// Load configuration
|
||
require_once __DIR__ . '/../config/bootstrap.php';
|
||
require_once APP_ROOT . '/src/Database.php';
|
||
|
||
$page = isset($_GET["page"]) ? intval($_GET["page"]) : 1;
|
||
$year = isset($_GET["year"]) ? intval($_GET["year"]) : null;
|
||
$itemsPerPage = 24; // bigger grid
|
||
|
||
try {
|
||
$db = Database::getInstance();
|
||
$offset = ($page - 1) * $itemsPerPage;
|
||
$availableYears = $db->getAvailableYears();
|
||
|
||
if ($year) {
|
||
$itemsToLoad = $db->searchTheses(['year' => $year], $itemsPerPage, $offset);
|
||
$totalItems = $db->countSearchResults(['year' => $year]);
|
||
} else {
|
||
$itemsToLoad = $db->getPublishedTheses($itemsPerPage, $offset);
|
||
$totalItems = $db->countPublishedTheses();
|
||
}
|
||
|
||
$totalPages = ceil($totalItems / $itemsPerPage);
|
||
} catch (Exception $e) {
|
||
error_log("Error loading theses: " . $e->getMessage());
|
||
$itemsToLoad = [];
|
||
$totalPages = 0;
|
||
$availableYears = [];
|
||
$totalItems = 0;
|
||
}
|
||
|
||
$currentNav = '';
|
||
?>
|
||
<!DOCTYPE html>
|
||
<html lang="fr">
|
||
<head>
|
||
<meta charset="UTF-8">
|
||
<meta name="viewport" content="width=device-width, initial-scale=1">
|
||
<title>Posterg</title>
|
||
<link rel="icon" type="image/svg+xml" href="/assets/admin_favicon.svg">
|
||
<link rel="stylesheet" href="assets/modern-normalize.min.css">
|
||
<link rel="stylesheet" href="assets/common.css">
|
||
<link rel="stylesheet" href="assets/main.css">
|
||
<?php if (php_sapi_name() === 'cli-server'): ?>
|
||
<script>
|
||
(function poll() {
|
||
fetch('/live-reload.php').then(r=>r.json()).then(d=>{
|
||
if(d.changed) location.reload(); else setTimeout(poll,1000);
|
||
}).catch(()=>setTimeout(poll,2000));
|
||
})();
|
||
</script>
|
||
<?php endif; ?>
|
||
</head>
|
||
<body class="home-body">
|
||
|
||
<?php include APP_ROOT . '/templates/nav.php'; ?>
|
||
<?php include APP_ROOT . '/templates/search-bar.php'; ?>
|
||
|
||
<?php if ($year): ?>
|
||
<div class="filter-info">
|
||
Année : <?= htmlspecialchars($year) ?>
|
||
<a href="index.php" class="clear-filter">✕ Réinitialiser</a>
|
||
</div>
|
||
<?php endif; ?>
|
||
|
||
<main class="home-main">
|
||
<div class="cards-container">
|
||
<?php foreach ($itemsToLoad as $item): ?>
|
||
<a href="tfe.php?id=<?= (int)$item["id"] ?>" class="card-link">
|
||
<div class="card">
|
||
<div class="card__media">
|
||
<?php
|
||
// Use first image/video file as thumbnail
|
||
$thumb = null;
|
||
if (!empty($item['files'])) {
|
||
foreach ($item['files'] as $f) {
|
||
$ext = strtolower(pathinfo($f['file_path'], PATHINFO_EXTENSION));
|
||
if (in_array($ext, ['jpg','jpeg','png','gif','webp'])) {
|
||
$thumb = $f['file_path'];
|
||
break;
|
||
}
|
||
}
|
||
}
|
||
// Also check cover image
|
||
if (!$thumb && !empty($item['cover_image'])) {
|
||
$thumb = $item['cover_image'];
|
||
}
|
||
?>
|
||
<?php if ($thumb): ?>
|
||
<img src="/media.php?path=<?= urlencode($thumb) ?>"
|
||
alt="<?= htmlspecialchars($item['title']) ?>"
|
||
loading="lazy">
|
||
<?php else: ?>
|
||
<div class="card__media--placeholder">◻</div>
|
||
<?php endif; ?>
|
||
</div>
|
||
<div class="card__info">
|
||
<p class="authors"><?= htmlspecialchars($item["authors"] ?? '') ?><?php if (!empty($item['authors']) && !empty($item['title'])): ?> – <?php endif; ?><?= htmlspecialchars($item["title"]) ?></p>
|
||
</div>
|
||
</div>
|
||
</a>
|
||
<?php endforeach; ?>
|
||
|
||
<?php if (empty($itemsToLoad)): ?>
|
||
<p style="padding:2rem;color:#666;">Aucun mémoire trouvé.</p>
|
||
<?php endif; ?>
|
||
</div>
|
||
|
||
<?php if ($totalPages > 1): ?>
|
||
<div class="pagination-wrap">
|
||
<?php $yearParam = $year ? '&year=' . (int)$year : ''; ?>
|
||
<a href="?page=1<?= $yearParam ?>"
|
||
class="pagination-btn <?= $page <= 1 ? 'disabled' : '' ?>">«</a>
|
||
<a href="?page=<?= max(1, $page - 1) . $yearParam ?>"
|
||
class="pagination-btn <?= $page <= 1 ? 'disabled' : '' ?>">‹</a>
|
||
<span class="pagination-info">
|
||
<span class="page-current"><?= $page ?></span> / <?= $totalPages ?>
|
||
</span>
|
||
<a href="?page=<?= min($totalPages, $page + 1) . $yearParam ?>"
|
||
class="pagination-btn <?= $page >= $totalPages ? 'disabled' : '' ?>">›</a>
|
||
<a href="?page=<?= $totalPages . $yearParam ?>"
|
||
class="pagination-btn <?= $page >= $totalPages ? 'disabled' : '' ?>">»</a>
|
||
</div>
|
||
<?php endif; ?>
|
||
</main>
|
||
|
||
</body>
|
||
</html>
|