104 lines
3.2 KiB
PHP
104 lines
3.2 KiB
PHP
<?php
|
|
session_start();
|
|
// index.php - SPA
|
|
require_once __DIR__ . '/includes/config.php';
|
|
|
|
// Replicate what admin_auth.php does for the "check" action
|
|
$logged_in = !empty($_SESSION['is_admin']);
|
|
|
|
// Auto-generate navigation items from pages/
|
|
$pages_dir = __DIR__ . '/pages';
|
|
$nav_order = $CONFIG['nav_order'] ?? [];
|
|
$nav_admin = $CONFIG['nav_admin'] ?? [];
|
|
$nav_hidden = $CONFIG['nav_hidden'] ?? [];
|
|
$nav_bar = [];
|
|
$nav_bar_admin = [];
|
|
|
|
if (is_dir($pages_dir)) {
|
|
foreach (glob($pages_dir . '/*.php') as $file) {
|
|
$base = strtolower(basename($file, '.php'));
|
|
if (in_array($base, ['_template', 'error'])) continue; // skip special files
|
|
if (in_array($base, array_map('strtolower', $nav_hidden))) continue;
|
|
$label = ucfirst($base);
|
|
|
|
if (in_array($base, array_map('strtolower', $nav_admin))) {
|
|
if (!empty($_SESSION['is_admin'])) {
|
|
$nav_bar_admin[] = $label;
|
|
}
|
|
} else {
|
|
$nav_bar[] = $label;
|
|
}
|
|
}
|
|
}
|
|
// Optional: order nav_bar according to $nav_order
|
|
$ordered = [];
|
|
foreach ($nav_order as $o) {
|
|
foreach ($nav_bar as $key => $label) {
|
|
if (strtolower($label) === $o) {
|
|
$ordered[] = $label;
|
|
unset($nav_bar[$key]);
|
|
}
|
|
}
|
|
}
|
|
$nav_bar = array_merge($ordered, $nav_bar);
|
|
unset($nav_order,$nav_admin,$nav_hidden);
|
|
|
|
?>
|
|
<!doctype html>
|
|
<html lang="en">
|
|
<head>
|
|
<meta charset="utf-8">
|
|
<meta name="viewport" content="width=device-width,initial-scale=1">
|
|
<title><?= htmlspecialchars($CONFIG['site_name']) ?></title>
|
|
<link rel="stylesheet" href="css/style.css">
|
|
</head>
|
|
<body>
|
|
<header class="site-header">
|
|
<div class="header-inner">
|
|
<div class="brand">
|
|
<h1><?= htmlspecialchars($CONFIG['site_name']) ?></h1>
|
|
<small class="muted">Embedded gallery</small>
|
|
</div>
|
|
|
|
<nav class="nav" id="navBar">
|
|
<?php
|
|
foreach ($nav_bar as $page) {
|
|
echo '<button class="nav-btn" data-page="' . htmlspecialchars(lcfirst($page)) . '">' .
|
|
htmlspecialchars($page) . '</button>';
|
|
}
|
|
if (isset($logged_in) && $logged_in === TRUE){
|
|
foreach ($nav_bar_admin as $page) {
|
|
echo '<button class="nav-btn" data-page="' . htmlspecialchars(lcfirst($page)) . '">' .
|
|
htmlspecialchars($page) . '</button>';
|
|
}
|
|
}
|
|
?>
|
|
</nav>
|
|
|
|
<div class="controls">
|
|
<input id="searchInput" class="search" placeholder="Search..." />
|
|
<button id="adminLock" class="lock-btn" title="Admin Login">🔒</button>
|
|
<button id="themeToggle" class="theme-btn" aria-label="Toggle theme">🌙</button>
|
|
</div>
|
|
</div>
|
|
</header>
|
|
<main id="content" class="content" data-default-page="home">
|
|
<div class="center">
|
|
<p class="loading">Loading…</p>
|
|
</div>
|
|
</main>
|
|
|
|
<footer class="site-footer">
|
|
<small>© <?= date('Y') ?> <?= htmlspecialchars($CONFIG['site_name']) ?></small>
|
|
</footer>
|
|
|
|
<!-- GLightbox -->
|
|
<link rel="stylesheet" href="dist/css/glightbox.min.css">
|
|
<script src="dist/js/glightbox.min.js"></script>
|
|
|
|
|
|
|
|
<script src="js/app.js" defer></script>
|
|
</body>
|
|
</html>
|
|
<?php unset($nav_bar,$nav_bar_admin,$logged_in); ?>
|