<?php
require_once __DIR__ . '/config.php';
if (!IS_INSTALLED) { header('Location: setup.php'); exit; }
require_once ROOT_PATH . '/includes/db.php';
require_once ROOT_PATH . '/includes/functions.php';
require_once ROOT_PATH . '/includes/auth.php';
require_once ROOT_PATH . '/includes/markdown.php';
$slug = trim($_GET['slug'] ?? '');
$page = $slug ? get_page($slug) : null;
if (!$page || (!$page['enabled'] && !has_role('editor'))) {
http_response_code(404); die('Page not found.');
}
$parentPage = !empty($page['parent_id']) ? get_page_by_id((int)$page['parent_id']) : null;
$subPages = get_subpages((int)$page['id']);
$meta = build_meta([
'title' => h($page['title']) . ' — ' . get_setting('site_title', SITE_NAME),
'og_type' => 'website',
]);
include ROOT_PATH . '/includes/header.php';
?>
<div class="breadcrumb">
<a href="<?= h(base_url()) ?>">Home</a>
<?php if ($parentPage): ?>
› <a href="<?= h(base_url('page/' . rawurlencode($parentPage['slug']))) ?>"><?= h($parentPage['title']) ?></a>
<?php endif; ?>
› <?= h($page['title']) ?>
</div>
<?php if (!$page['enabled']): ?>
<div class="flash flash-info">⚠ This page is disabled and not publicly visible.</div>
<?php endif; ?>
<div class="window doc-window" style="max-width:900px;margin:0 auto">
<div class="win-titlebar">📄 <?= h($page['title']) ?>
<?php if (has_role('editor')): ?>
<div class="win-actions">
<a href="<?= h(base_url('admin/pages.php?edit=' . $page['slug'])) ?>" class="button btn-sm">✎ Edit</a>
</div>
<?php endif; ?>
</div>
<div class="win-body">
<div class="markdown-body">
<?= md($page['content']) ?>
</div>
<?php if (!empty($subPages)): ?>
<div style="margin-top:16px;border-top:1px solid var(--border-mid,#A0A0A0);padding-top:12px">
<strong style="font-size:12px;display:block;margin-bottom:8px">📄 Sub-pages</strong>
<ul style="margin:0;padding-left:18px;list-style:disc">
<?php foreach ($subPages as $sp): ?>
<li style="margin-bottom:4px">
<a href="<?= h(base_url('page/' . rawurlencode($sp['slug']))) ?>"><?= h($sp['nav_label'] ?: $sp['title']) ?></a>
</li>
<?php endforeach; ?>
</ul>
</div>
<?php endif; ?>
</div>
</div>
<?php include ROOT_PATH . '/includes/footer.php'; ?>