Repository navigation
Expand file tree
/
Copy pathfeed.php
More file actions
39 lines (34 loc) · 1.52 KB
/
Copy pathfeed.php
File metadata and controls
39 lines (34 loc) · 1.52 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
<?php
// secondwheel-engine/feed.php — RSS 2.0 feed
$config = require __DIR__ . '/config.php';
date_default_timezone_set($config['timezone']);
require_once __DIR__ . '/lib/render.php';
$posts = sw_discover_posts($config['posts_dir']);
$base = rtrim($config['base_url'], '/');
header('Content-Type: application/rss+xml; charset=utf-8');
$items = '';
foreach (array_slice($posts, 0, 20) as $p) {
$meta = $p['meta'];
$title = $meta['title'] ?? $p['slug'];
$link = $base . '/post/' . rawurlencode($p['slug']);
$summary = $meta['summary'] ?? '';
$date = $meta['date'] ?? '';
$pubDate = $date ? date(DATE_RSS, strtotime($date)) : '';
$items .= ' <item>' . "\n";
$items .= ' <title>' . sw_e($title) . '</title>' . "\n";
$items .= ' <link>' . sw_e($link) . '</link>' . "\n";
$items .= ' <guid isPermaLink="true">' . sw_e($link) . '</guid>' . "\n";
if ($pubDate) $items .= ' <pubDate>' . $pubDate . '</pubDate>' . "\n";
if ($summary) $items .= ' <description>' . sw_e($summary) . '</description>' . "\n";
$items .= ' </item>' . "\n";
}
echo '<?xml version="1.0" encoding="UTF-8"?>' . "\n";
?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom">
<channel>
<title><?= sw_e($config['site_title']) ?></title>
<link><?= sw_e($base . '/') ?></link>
<description><?= sw_e($config['site_title']) ?></description>
<atom:link href="<?= sw_e($base . '/feed.php') ?>" rel="self" type="application/rss+xml" />
<?= $items ?> </channel>
</rss>