<?php
/**
 * RSS订阅源 - rss.xml
 */
require_once 'config.php';

$db = getDB();
$articles = $db->query("SELECT * FROM articles ORDER BY created_at DESC LIMIT 50")->fetchAll(PDO::FETCH_ASSOC);

header('Content-Type: application/rss+xml; charset=utf-8');
echo '<?xml version="1.0" encoding="UTF-8"?>' . PHP_EOL;
?>
<rss version="2.0"
  xmlns:atom="http://www.w3.org/2005/Atom"
  xmlns:content="http://purl.org/rss/1.0/modules/content/"
  xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>TikTok知识库</title>
    <link>http://localhost/tiktok_knowledge/</link>
    <description>TikTok出海知识分享平台，涵盖认知入门、账号运营、变现方式、Shop入驻、直播带货、广告投放、达人合作等全链路内容</description>
    <language>zh-cn</language>
    <lastBuildDate><?php echo date('D, d M Y H:i:s O'); ?></lastBuildDate>
    <atom:link href="<?php echo SITE_URL; ?>/rss.xml" rel="self" type="application/rss+xml"/>
    <image>
        <url><?php echo SITE_URL; ?>/og.php</url>
        <title>TikTok知识库</title>
        <link>http://localhost/tiktok_knowledge/</link>
    </image>
    <?php foreach ($articles as $article): ?>
    <item>
        <title><![CDATA[<?php echo $article['title']; ?>]]></title>
        <link><?php echo SITE_URL; ?>/article.php?slug=<?php echo urlencode($article['slug']); ?></link>
        <guid isPermaLink="true"><?php echo SITE_URL; ?>/article.php?slug=<?php echo urlencode($article['slug']); ?></guid>
        <description><![CDATA[<?php echo $article['description']; ?>]]></description>
        <pubDate><?php echo date('D, d M Y H:i:s O', strtotime($article['created_at'] ?? 'now')); ?></pubDate>
        <dc:creator><?php echo htmlspecialchars($article['author'] ?? 'TikTok知识库'); ?></dc:creator>
    </item>
    <?php endforeach; ?>
  </channel>
</rss>
