<?xml version="1.0" encoding="UTF-8"?>
<?php
// RSS feed için header
header('Content-Type: application/rss+xml; charset=utf-8');

// Konfigürasyon dosyasını dahil et
require_once 'includes/config.php';

// Son 20 haberi al
$articles = [];
if ($db) {
    try {
        $articles = $db->fetchAll("
            SELECT a.*, c.name as category_name, 
                   u.first_name, u.last_name
            FROM articles a
            LEFT JOIN categories c ON a.category_id = c.id
            LEFT JOIN users u ON a.author_id = u.id
            WHERE a.status = 'yayinda'
            ORDER BY a.publish_at DESC
            LIMIT 20
        ");
    } catch (Exception $e) {
        $articles = [];
    }
}
?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:content="http://purl.org/rss/1.0/modules/content/">
    <channel>
        <title><?php echo htmlspecialchars($site_settings['site_title']); ?></title>
        <link>https://ses72.com</link>
        <description><?php echo htmlspecialchars($site_settings['site_description']); ?></description>
        <language>tr</language>
        <lastBuildDate><?php echo date('r'); ?></lastBuildDate>
        <atom:link href="https://ses72.com/rss.xml" rel="self" type="application/rss+xml"/>
        <image>
            <title><?php echo htmlspecialchars($site_settings['site_title']); ?></title>
            <url>https://ses72.com/image.png</url>
            <link>https://ses72.com</link>
            <width>144</width>
            <height>144</height>
        </image>
        
        <?php foreach ($articles as $article): ?>
        <item>
            <title><?php echo htmlspecialchars($article['title']); ?></title>
            <link>https://ses72.com/haber/<?php echo htmlspecialchars($article['slug']); ?></link>
            <guid>https://ses72.com/haber/<?php echo htmlspecialchars($article['slug']); ?></guid>
            <description><![CDATA[<?php echo htmlspecialchars($article['excerpt'] ?: substr(strip_tags($article['content']), 0, 300)); ?>]]></description>
            <content:encoded><![CDATA[<?php echo $article['content']; ?>]]></content:encoded>
            <category><?php echo htmlspecialchars($article['category_name']); ?></category>
            <author><?php echo htmlspecialchars(trim($article['first_name'] . ' ' . $article['last_name']) ?: 'Ses72'); ?></author>
            <pubDate><?php echo date('r', strtotime($article['publish_at'] ?: $article['created_at'])); ?></pubDate>
        </item>
        <?php endforeach; ?>
    </channel>
</rss>

