feat : RSS content, feed catégorie, cookie commentaires, flux erreurs, email preview (v1.6.17)
- RSS : content:encoded (HTML complet) + fix description via plain (#42) - RSS : flux filtré par ?category=nom (#43) - Commentaires : cookie nom/email pour pré-remplir le formulaire (#51) - flux/ : bandeau admin des feeds en erreur (#45) - admin/emails : bouton « Voir ↗ » vers /admin/email-preview/{id} en nouvel onglet (#37) Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
+32
-15
@@ -16,17 +16,24 @@ $articles = new ArticleManager(DATA_PATH);
|
||||
$privateCats = $articles->getPrivateCategories();
|
||||
$Parsedown = new Parsedown();
|
||||
|
||||
$now = time();
|
||||
$base = rtrim(APP_URL, '/');
|
||||
$now = time();
|
||||
$base = rtrim(APP_URL, '/');
|
||||
$filterCat = trim($_GET['category'] ?? '');
|
||||
|
||||
$all = array_values(array_filter(
|
||||
$articles->getAll(publishedOnly: true),
|
||||
static function (array $a) use ($now, $privateCats): bool {
|
||||
static function (array $a) use ($now, $privateCats, $filterCat): bool {
|
||||
if (strtotime((string)($a['published_at'] ?? '')) > $now) {
|
||||
return false;
|
||||
}
|
||||
$cat = trim($a['category'] ?? '');
|
||||
return $cat === '' || !in_array($cat, $privateCats, true);
|
||||
if ($cat !== '' && in_array($cat, $privateCats, true)) {
|
||||
return false;
|
||||
}
|
||||
if ($filterCat !== '' && $cat !== $filterCat) {
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
));
|
||||
|
||||
@@ -42,13 +49,16 @@ if ($after !== '') {
|
||||
}
|
||||
}
|
||||
|
||||
$items = array_slice($all, $offset, FEED_PAGE_SIZE);
|
||||
$items = array_slice($all, $offset, FEED_PAGE_SIZE);
|
||||
$nextCursor = (count($all) > $offset + FEED_PAGE_SIZE)
|
||||
? ($all[$offset + FEED_PAGE_SIZE - 1]['uuid'] ?? null)
|
||||
: null;
|
||||
|
||||
$feedUrl = $base . '/feed';
|
||||
$feedNextUrl = $nextCursor !== null ? $base . '/feed/' . $nextCursor : null;
|
||||
$feedUrl = $base . '/feed' . ($filterCat !== '' ? '?category=' . rawurlencode($filterCat) : '');
|
||||
$feedNextUrl = $nextCursor !== null ? $base . '/feed/' . $nextCursor . ($filterCat !== '' ? '?category=' . rawurlencode($filterCat) : '') : null;
|
||||
|
||||
$channelTitle = siteTitle() . ($filterCat !== '' ? ' — ' . $filterCat : '');
|
||||
$channelDesc = $filterCat !== '' ? 'Articles de la catégorie « ' . $filterCat . ' »' : siteClaim();
|
||||
|
||||
// ─── lastBuildDate ───────────────────────────────────────────────────────────
|
||||
$lastBuild = '';
|
||||
@@ -69,11 +79,12 @@ echo '<?xml version="1.0" encoding="UTF-8"?>' . "\n";
|
||||
?>
|
||||
<rss version="2.0"
|
||||
xmlns:atom="http://www.w3.org/2005/Atom"
|
||||
xmlns:content="http://purl.org/rss/1.0/modules/content/"
|
||||
xmlns:fh="http://purl.org/syndication/history/1.0">
|
||||
<channel>
|
||||
<title><?= htmlspecialchars(siteTitle()) ?></title>
|
||||
<title><?= htmlspecialchars($channelTitle) ?></title>
|
||||
<link><?= htmlspecialchars($base) ?></link>
|
||||
<description><?= htmlspecialchars(siteClaim()) ?></description>
|
||||
<description><?= htmlspecialchars($channelDesc) ?></description>
|
||||
<language><?= htmlspecialchars(siteLang()) ?></language>
|
||||
<lastBuildDate><?= htmlspecialchars($lastBuild) ?></lastBuildDate>
|
||||
|
||||
@@ -91,17 +102,23 @@ echo '<?xml version="1.0" encoding="UTF-8"?>' . "\n";
|
||||
<?php endif; ?>
|
||||
|
||||
<?php foreach ($items as $article):
|
||||
$pubDate = date(DATE_RSS, (int)strtotime((string)($article['published_at'] ?? $article['created_at'] ?? '')));
|
||||
$link = $base . '/post/' . rawurlencode($article['slug'] ?? '');
|
||||
$title = htmlspecialchars($article['title'] ?? '', ENT_XML1);
|
||||
$plain = preg_replace('/\s+/', ' ', strip_tags($Parsedown->text($article['content'] ?? '')));
|
||||
$desc = htmlspecialchars(mb_strimwidth(trim((string)$plain), 0, 300, '…'), ENT_XML1);
|
||||
$guid = htmlspecialchars($base . '/post/' . rawurlencode($article['slug'] ?? ''), ENT_XML1);
|
||||
$pubDate = date(DATE_RSS, (int)strtotime((string)($article['published_at'] ?? $article['created_at'] ?? '')));
|
||||
$link = $base . '/post/' . rawurlencode($article['slug'] ?? '');
|
||||
$title = htmlspecialchars($article['title'] ?? '', ENT_XML1);
|
||||
$plain = preg_replace('/\s+/', ' ', trim($article['plain'] ?? ''));
|
||||
$desc = htmlspecialchars(mb_strimwidth($plain, 0, 300, '…'), ENT_XML1);
|
||||
$guid = htmlspecialchars($base . '/post/' . rawurlencode($article['slug'] ?? ''), ENT_XML1);
|
||||
$mdPath = DATA_PATH . '/' . ($article['uuid'] ?? '') . '/index.md';
|
||||
$rawMd = file_exists($mdPath) ? (string)file_get_contents($mdPath) : '';
|
||||
$fullHtml = $rawMd !== '' ? $Parsedown->text($rawMd) : '';
|
||||
?>
|
||||
<item>
|
||||
<title><?= $title ?></title>
|
||||
<link><?= htmlspecialchars($link) ?></link>
|
||||
<description><?= $desc ?></description>
|
||||
<?php if ($fullHtml !== ''): ?>
|
||||
<content:encoded><![CDATA[<?= $fullHtml ?>]]></content:encoded>
|
||||
<?php endif; ?>
|
||||
<pubDate><?= htmlspecialchars($pubDate) ?></pubDate>
|
||||
<guid isPermaLink="true"><?= $guid ?></guid>
|
||||
</item>
|
||||
|
||||
Reference in New Issue
Block a user