142 lines
4.9 KiB
PHP

<?php
require_once 'includes/config.php';
require_once 'includes/auth.php';
require_once 'includes/stories.php';
// Récupération de l'ID du roman depuis l'URL
$storyId = $_GET['id'] ?? '';
if (!$storyId) {
header('Location: index.php');
exit;
}
// Chargement du roman
$story = Stories::get($storyId);
if (!$story) {
header('Location: index.php');
exit;
}
$config = Config::load();
// Vérification des droits d'accès pour voir les chapitres en brouillon
$canViewDrafts = Auth::check() && Auth::canAccessStory($storyId);
?>
<!DOCTYPE html>
<html lang="fr">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title><?= htmlspecialchars($story['title']) ?> - <?= htmlspecialchars($config['site']['name']) ?></title>
<?php if (file_exists(__DIR__ . '/assets/images/site/favicon.png')): ?>
<link rel="icon" type="image/png" href="assets/images/site/favicon.png">
<?php endif; ?>
<link rel="stylesheet" href="assets/css/public.css">
<link rel="stylesheet" href="assets/css/content.css">
<meta name="description" content="<?= htmlspecialchars(strip_tags($story['description'])) ?>">
</head>
<body>
<!-- En-tête avec image de fond -->
<header class="novel-header">
<?php if (!empty($story['cover'])): ?>
<div class="novel-header-background" style="background-image: url('<?= htmlspecialchars($story['cover']) ?>');"></div>
<?php endif; ?>
<div class="header-actions">
<a href="index.php" class="about-button">
<i class="fas fa-home"></i> Accueil
</a>
</div>
<h1><?= htmlspecialchars($story['title']) ?></h1>
</header>
<!-- Contenu principal -->
<div class="novel-content">
<div class="novel-description">
<?= $story['description'] = Config::fixImagePaths($story['description']); ?>
</div>
<aside class="chapters-menu">
<h2>Chapitres</h2>
<?php if (!empty($story['chapters'])): ?>
<ul class="chapters-list">
<?php
// Filtrer les chapitres pour n'afficher que les chapitres publiés
// ou les brouillons si l'utilisateur a les droits
$visibleChapters = array_filter($story['chapters'], function($chapter) use ($canViewDrafts) {
return !($chapter['draft'] ?? false) || $canViewDrafts;
});
if (empty($visibleChapters)): ?>
<p>Aucun chapitre publié disponible pour le moment.</p>
<?php else:
foreach ($visibleChapters as $chapter):
$isDraft = $chapter['draft'] ?? false;
?>
<li>
<a href="chapitre.php?story=<?= urlencode($story['id']) ?>&chapter=<?= urlencode($chapter['id']) ?>"
class="<?= $isDraft ? 'draft-chapter' : '' ?>">
<span class="chapter-title-text"><?= htmlspecialchars($chapter['title']) ?></span>
<?php if ($isDraft && $canViewDrafts): ?>
<span class="draft-label">Brouillon</span>
<?php endif; ?>
</a>
</li>
<?php
endforeach;
endif;
?>
</ul>
<?php else: ?>
<p>Aucun chapitre disponible pour le moment.</p>
<?php endif; ?>
</aside>
</div>
<button class="scroll-top" aria-label="Retour en haut de page">
<i class="fas fa-arrow-up"></i>
</button>
<style>
.draft-chapter {
opacity: 0.7;
border-left: 3px solid var(--accent-primary);
padding-left: 8px !important;
}
.draft-label {
font-size: 0.8em;
background-color: var(--accent-primary);
color: var(--text-tertiary);
padding: 2px 6px;
border-radius: 10px;
margin-left: 8px;
display: inline-block;
vertical-align: middle;
}
</style>
<script>
document.addEventListener('DOMContentLoaded', function() {
const scrollTopBtn = document.querySelector('.scroll-top');
window.addEventListener('scroll', function() {
if (window.pageYOffset > 300) {
scrollTopBtn.classList.add('visible');
} else {
scrollTopBtn.classList.remove('visible');
}
});
scrollTopBtn.addEventListener('click', function() {
window.scrollTo({
top: 0,
behavior: 'smooth'
});
});
});
</script>
</body>
</html>