amélioration de l'affichage des nouveaux chapitres
modification de la logique, la partie publique ne prend en compte que la date publication
This commit is contained in:
parent
a82699c84e
commit
7dfd600936
@ -29,10 +29,19 @@ try {
|
||||
$chapterUpdated = false;
|
||||
foreach ($story['chapters'] as &$chapter) {
|
||||
if ($chapter['id'] === $chapterId) {
|
||||
$wasInDraft = $chapter['draft'] ?? false;
|
||||
$chapter['title'] = $title;
|
||||
$chapter['content'] = $content;
|
||||
$chapter['draft'] = $draft;
|
||||
$chapter['updated'] = date('Y-m-d');
|
||||
|
||||
// Si le chapitre passe de brouillon à publié, ajouter la date de publication
|
||||
if ($wasInDraft && !$draft) {
|
||||
$chapter['published'] = date('Y-m-d H:i:s');
|
||||
// Marquer le roman comme ayant du nouveau contenu
|
||||
$story['publicUpdated'] = date('Y-m-d H:i:s');
|
||||
}
|
||||
|
||||
$chapterUpdated = true;
|
||||
break;
|
||||
}
|
||||
|
@ -931,6 +931,30 @@ body {
|
||||
word-break: break-word;
|
||||
}
|
||||
|
||||
/* Modification des styles pour les chapitres en brouillon */
|
||||
.new-chapter {
|
||||
border-left: 3px solid #5a8c54;
|
||||
padding-left: calc(var(--spacing-sm) + 1.5rem) !important;
|
||||
}
|
||||
|
||||
.chapters-list .draft-chapter::before {
|
||||
content: "\f249";
|
||||
left: calc(var(--spacing-sm) + 0.3rem);
|
||||
}
|
||||
|
||||
.new-label {
|
||||
font-size: 0.8em;
|
||||
background-color: #5a8c54;
|
||||
color: var(--text-primary);
|
||||
padding: 2px 6px;
|
||||
border-radius: 10px;
|
||||
margin-left: 8px;
|
||||
display: inline-block;
|
||||
vertical-align: middle;
|
||||
position: relative;
|
||||
z-index: 1;
|
||||
}
|
||||
|
||||
@media (max-width: 768px) {
|
||||
.chapters-list a {
|
||||
padding-right: var(--spacing-xs);
|
||||
|
59
chapitre.php
59
chapitre.php
@ -120,21 +120,50 @@ $config = Config::load();
|
||||
<aside class="chapters-menu">
|
||||
<h2>Chapitres</h2>
|
||||
<ul class="chapters-list">
|
||||
<?php
|
||||
foreach ($visibleChapters as $chapter):
|
||||
$isDraft = $chapter['draft'] ?? false;
|
||||
?>
|
||||
<li>
|
||||
<a href="?story=<?= urlencode($storyId) ?>&chapter=<?= urlencode($chapter['id']) ?>"
|
||||
class="<?= $chapter['id'] === $chapterId ? 'current-chapter' : '' ?> <?= $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; ?>
|
||||
</ul>
|
||||
<?php
|
||||
// Vérifier que chapters est un tableau avant de le filtrer
|
||||
$chapters = $story['chapters'] ?? [];
|
||||
|
||||
// Filtrer les chapitres pour n'afficher que les chapitres publiés
|
||||
// ou les brouillons si l'utilisateur a les droits
|
||||
$visibleChapters = [];
|
||||
foreach ($chapters as $chapter) {
|
||||
if (!($chapter['draft'] ?? false) || $canViewDrafts) {
|
||||
$visibleChapters[] = $chapter;
|
||||
}
|
||||
}
|
||||
|
||||
if (empty($visibleChapters)): ?>
|
||||
<p>Aucun chapitre publié disponible pour le moment.</p>
|
||||
<?php else:
|
||||
foreach ($visibleChapters as $chapter):
|
||||
$isDraft = $chapter['draft'] ?? false;
|
||||
$isNew = false;
|
||||
|
||||
// Vérifier si le chapitre est nouveau (publié il y a moins d'une semaine)
|
||||
// Utiliser 'created' puisque c'est ce champ qui est présent dans vos données
|
||||
if (isset($chapter['created'])) {
|
||||
$publishedTime = strtotime($chapter['created']);
|
||||
$weekAgo = strtotime('-1 week');
|
||||
$isNew = $publishedTime > $weekAgo && !$isDraft;
|
||||
}
|
||||
?>
|
||||
<li>
|
||||
<a href="chapitre.php?story=<?= urlencode($story['id']) ?>&chapter=<?= urlencode($chapter['id']) ?>"
|
||||
class="<?= $chapter['id'] === $chapterId ? 'current-chapter' : '' ?> <?= $isDraft ? 'draft-chapter' : ($isNew ? 'new-chapter' : '') ?>">
|
||||
<span class="chapter-title"><?= htmlspecialchars($chapter['title']) ?></span>
|
||||
<?php if ($isDraft && $canViewDrafts): ?>
|
||||
<span class="draft-label">(Brouillon)</span>
|
||||
<?php elseif ($isNew): ?>
|
||||
<span class="new-label">(Nouveau)</span>
|
||||
<?php endif; ?>
|
||||
</a>
|
||||
</li>
|
||||
<?php
|
||||
endforeach;
|
||||
endif;
|
||||
?>
|
||||
</ul>
|
||||
</aside>
|
||||
</div>
|
||||
|
||||
|
@ -18,15 +18,7 @@ class Stories {
|
||||
}
|
||||
return json_decode(file_get_contents($file), true);
|
||||
}
|
||||
|
||||
public static function save($story) {
|
||||
// Ajout de l'heure à la date de mise à jour
|
||||
$story['updated'] = date('Y-m-d H:i:s');
|
||||
|
||||
$file = self::$storiesDir . $story['id'] . '.json';
|
||||
return file_put_contents($file, json_encode($story, JSON_PRETTY_PRINT));
|
||||
}
|
||||
|
||||
|
||||
public static function formatDate($date) {
|
||||
if (strlen($date) > 10) { // Si la date contient aussi l'heure
|
||||
$datetime = DateTime::createFromFormat('Y-m-d H:i:s', $date);
|
||||
@ -36,4 +28,54 @@ class Stories {
|
||||
return $datetime ? $datetime->format('d/m/Y') : '';
|
||||
}
|
||||
}
|
||||
|
||||
public static function save($story) {
|
||||
// Mise à jour de la date standard pour tout changement
|
||||
$story['updated'] = date('Y-m-d H:i:s');
|
||||
|
||||
// Vérification si c'est une création initiale
|
||||
$isNew = !file_exists(self::$storiesDir . $story['id'] . '.json');
|
||||
|
||||
// Vérification si un nouveau chapitre a été ajouté ou un chapitre est passé de draft à publié
|
||||
$existingStory = $isNew ? null : self::get($story['id']);
|
||||
$updatePublicDate = $isNew; // Déjà true si c'est un nouveau roman
|
||||
|
||||
if (!$isNew && isset($existingStory['chapters']) && isset($story['chapters'])) {
|
||||
// Vérifier les nouveaux chapitres ou changements de statut
|
||||
foreach ($story['chapters'] as $chapter) {
|
||||
$found = false;
|
||||
foreach ($existingStory['chapters'] as $oldChapter) {
|
||||
if ($oldChapter['id'] === $chapter['id']) {
|
||||
$found = true;
|
||||
// Chapitre passé de brouillon à publié
|
||||
if (($oldChapter['draft'] ?? false) && !($chapter['draft'] ?? false)) {
|
||||
$updatePublicDate = true;
|
||||
// Ajouter une date de publication au chapitre
|
||||
$chapter['published'] = date('Y-m-d H:i:s');
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
// Nouveau chapitre
|
||||
if (!$found && !($chapter['draft'] ?? false)) {
|
||||
$updatePublicDate = true;
|
||||
// S'assurer que le nouveau chapitre a une date de publication
|
||||
if (!isset($chapter['published'])) {
|
||||
$chapter['published'] = date('Y-m-d H:i:s');
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Mettre à jour la date publique si nécessaire
|
||||
if ($updatePublicDate) {
|
||||
$story['publicUpdated'] = date('Y-m-d H:i:s');
|
||||
} else if (!isset($story['publicUpdated'])) {
|
||||
// S'assurer que le champ existe
|
||||
$story['publicUpdated'] = $story['created'] ?? date('Y-m-d H:i:s');
|
||||
}
|
||||
|
||||
$file = self::$storiesDir . $story['id'] . '.json';
|
||||
return file_put_contents($file, json_encode($story, JSON_PRETTY_PRINT));
|
||||
}
|
||||
}
|
@ -11,9 +11,9 @@ usort($stories, function($a, $b) {
|
||||
return strtotime($b['updated']) - strtotime($a['updated']);
|
||||
});
|
||||
|
||||
// Fonction pour vérifier si un roman est une nouvelle parution (moins d'une semaine)
|
||||
// Fonction pour vérifier si un roman est une nouvelle parution
|
||||
function isNewRelease($story) {
|
||||
$updateTime = strtotime($story['updated']);
|
||||
$updateTime = strtotime($story['publicUpdated'] ?? $story['updated']);
|
||||
$weekAgo = strtotime('-1 week');
|
||||
return $updateTime > $weekAgo;
|
||||
}
|
||||
|
52
roman.php
52
roman.php
@ -45,9 +45,7 @@ $canViewDrafts = Auth::check() && Auth::canAccessStory($storyId);
|
||||
<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>
|
||||
<a href="index.php" class="about-button">Accueil</a>
|
||||
</div>
|
||||
<h1><?= htmlspecialchars($story['title']) ?></h1>
|
||||
</header>
|
||||
@ -63,24 +61,41 @@ $canViewDrafts = Auth::check() && Auth::canAccessStory($storyId);
|
||||
<?php if (!empty($story['chapters'])): ?>
|
||||
<ul class="chapters-list">
|
||||
<?php
|
||||
// Vérifier que chapters est un tableau avant de le filtrer
|
||||
$chapters = $story['chapters'] ?? [];
|
||||
|
||||
// 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;
|
||||
});
|
||||
$visibleChapters = [];
|
||||
foreach ($chapters as $chapter) {
|
||||
if (!($chapter['draft'] ?? false) || $canViewDrafts) {
|
||||
$visibleChapters[] = $chapter;
|
||||
}
|
||||
}
|
||||
|
||||
if (empty($visibleChapters)): ?>
|
||||
<p>Aucun chapitre publié disponible pour le moment.</p>
|
||||
<?php else:
|
||||
foreach ($visibleChapters as $chapter):
|
||||
$isDraft = $chapter['draft'] ?? false;
|
||||
$isNew = false;
|
||||
|
||||
// Vérifier si le chapitre est nouveau (publié il y a moins d'une semaine)
|
||||
// Utiliser 'created' puisque c'est ce champ qui est présent dans vos données
|
||||
if (isset($chapter['created'])) {
|
||||
$publishedTime = strtotime($chapter['created']);
|
||||
$weekAgo = strtotime('-1 week');
|
||||
$isNew = $publishedTime > $weekAgo && !$isDraft;
|
||||
}
|
||||
?>
|
||||
<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>
|
||||
class="<?= $isDraft ? 'draft-chapter' : ($isNew ? 'new-chapter' : '') ?>">
|
||||
<span class="chapter-title"><?= htmlspecialchars($chapter['title']) ?></span>
|
||||
<?php if ($isDraft && $canViewDrafts): ?>
|
||||
<span class="draft-label">Brouillon</span>
|
||||
<span class="draft-label">(Brouillon)</span>
|
||||
<?php elseif ($isNew): ?>
|
||||
<span class="new-label">(Nouveau)</span>
|
||||
<?php endif; ?>
|
||||
</a>
|
||||
</li>
|
||||
@ -99,25 +114,6 @@ $canViewDrafts = Auth::check() && Auth::canAccessStory($storyId);
|
||||
<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');
|
||||
|
@ -1 +1 @@
|
||||
1.3.1
|
||||
1.3.2
|
Loading…
x
Reference in New Issue
Block a user