<?php
require_once __DIR__.'/config.php';
header('Content-Type: application/rss+xml; charset=utf-8');
$articles = DB()->fetchAll('SELECT a.*,c.name as cname FROM '.DB_PREFIX.'article a LEFT JOIN '.DB_PREFIX.'category c ON a.category_id=c.id WHERE a.status=1 ORDER BY a.id DESC LIMIT 20');
$sitename = h($GLOBALS['setting']['site_name'] ?? '博客');
$sitedesc = h($GLOBALS['setting']['site_description'] ?? '');
echo '<?xml version="1.0" encoding="UTF-8"?>'."\n";
?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom">
<channel>
    <title><?=$sitename?></title>
    <link><?=SITE_URL?>/</link>
    <description><?=$sitedesc?></description>
    <language>zh-CN</language>
    <lastBuildDate><?=date('r')?></lastBuildDate>
    <atom:link href="<?=SITE_URL?>/rss.xml" rel="self" type="application/rss+xml"/>
    <?php foreach($articles as $a): ?>
    <item>
        <title><?=h($a['title'])?></title>
        <link><?=url('article',['id'=>$a['id']])?></link>
        <description><?=h(strCut(strip_tags($a['content']??''),200))?></description>
        <category><?=h($a['cname'])?></category>
        <pubDate><?=date('r', strtotime($a['created_at']))?></pubDate>
        <guid><?=url('article',['id'=>$a['id']])?></guid>
    </item>
    <?php endforeach; ?>
</channel>
</rss>
