<?php
require __DIR__ . '/inc/bootstrap.php';
header('Content-Type: application/rss+xml; charset=utf-8');
$site = setting('site_name', '木漏茶室');
$posts = DB::all('SELECT p.id, p.title, p.content, p.created_at, u.nickname, u.username FROM ' . DB::table('posts') . ' p
                  LEFT JOIN ' . DB::table('users') . ' u ON u.id = p.user_id
                  WHERE p.status = 1 AND p.author_only = 0 ORDER BY p.id DESC LIMIT 30');
echo '<?xml version="1.0" encoding="UTF-8"?>' . "\n";
?>
<rss version="2.0"><channel>
<title><?= e($site) ?></title>
<link><?= e(base_url('index.php')) ?></link>
<description><?= e(setting('site_intro', '一室茶香，半窗霜雪。')) ?></description>
<language>zh-CN</language>
<lastBuildDate><?= date(DATE_RSS) ?></lastBuildDate>
<?php foreach ($posts as $p): ?>
<item>
  <title><?= e(post_display_title($p, 80)) ?></title>
  <link><?= e(page_url('post', ['id' => $p['id']])) ?></link>
  <guid isPermaLink="true"><?= e(page_url('post', ['id' => $p['id']])) ?></guid>
  <author><?= e(display_name($p)) ?></author>
  <pubDate><?= date(DATE_RSS, strtotime($p['created_at'])) ?></pubDate>
  <description><?= e(plain_excerpt($p['content'], 200)) ?></description>
</item>
<?php endforeach; ?>
</channel></rss>
