68 lines
2.4 KiB
PHP
68 lines
2.4 KiB
PHP
<?php
|
|
|
|
declare(strict_types=1);
|
|
|
|
define('BASE_PATH', realpath(__DIR__ . '/../'));
|
|
|
|
if (session_status() === PHP_SESSION_NONE) {
|
|
$isHttps = !empty($_SERVER['HTTPS']) && $_SERVER['HTTPS'] !== 'off';
|
|
session_set_cookie_params(['lifetime' => 0, 'path' => '/', 'secure' => $isHttps, 'httponly' => true, 'samesite' => 'Lax']);
|
|
session_start();
|
|
}
|
|
|
|
require_once BASE_PATH . '/src/auth.php';
|
|
require_once BASE_PATH . '/config/config.php';
|
|
require_once BASE_PATH . '/src/ArticleManager.php';
|
|
|
|
$articles = new ArticleManager(BASE_PATH . '/data');
|
|
|
|
$now = time();
|
|
$base = rtrim(APP_URL, '/');
|
|
|
|
$items = array_filter(
|
|
$articles->getAll(publishedOnly: true),
|
|
static fn (array $a): bool => strtotime((string)($a['published_at'] ?? '')) <= $now
|
|
);
|
|
|
|
$lastBuild = '';
|
|
foreach ($items as $a) {
|
|
$ts = strtotime((string)($a['updated_at'] ?? $a['published_at'] ?? ''));
|
|
if ($ts && $ts > strtotime($lastBuild ?: '1970-01-01')) {
|
|
$lastBuild = date(DATE_RSS, $ts);
|
|
}
|
|
}
|
|
if ($lastBuild === '') {
|
|
$lastBuild = date(DATE_RSS);
|
|
}
|
|
|
|
header('Content-Type: application/rss+xml; charset=UTF-8');
|
|
header('X-Content-Type-Options: nosniff');
|
|
|
|
echo '<?xml version="1.0" encoding="UTF-8"?>' . "\n";
|
|
?>
|
|
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom">
|
|
<channel>
|
|
<title>varlog</title>
|
|
<link><?= htmlspecialchars($base) ?></link>
|
|
<description>Journal personnel de Cédrix — informatique, hack et loisirs techniques.</description>
|
|
<language>fr</language>
|
|
<lastBuildDate><?= htmlspecialchars($lastBuild) ?></lastBuildDate>
|
|
<atom:link href="<?= htmlspecialchars($base . '/feed') ?>" rel="self" type="application/rss+xml"/>
|
|
<?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);
|
|
$desc = htmlspecialchars(mb_strimwidth(strip_tags($article['content'] ?? ''), 0, 300, '…'), ENT_XML1);
|
|
$guid = htmlspecialchars($base . '/post/' . rawurlencode($article['slug'] ?? ''), ENT_XML1);
|
|
?>
|
|
<item>
|
|
<title><?= $title ?></title>
|
|
<link><?= htmlspecialchars($link) ?></link>
|
|
<description><?= $desc ?></description>
|
|
<pubDate><?= htmlspecialchars($pubDate) ?></pubDate>
|
|
<guid isPermaLink="true"><?= $guid ?></guid>
|
|
</item>
|
|
<?php endforeach; ?>
|
|
</channel>
|
|
</rss>
|