<?php
include 'config/db.php';

header("Content-Type: application/rss+xml; charset=UTF-8");

$baseUrl = "https://nibru.edu.iq/";

echo '<?xml version="1.0" encoding="UTF-8"?>';
?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom">
<channel>
    <title>أخبار جامعة النبراس الأهلية</title>
    <link><?php echo $baseUrl; ?></link>
    <description>آخر أخبار وفعاليات جامعة النبراس الأهلية في صلاح الدين</description>
    <language>ar</language>
    <atom:link href="<?php echo $baseUrl; ?>rss.xml" rel="self" type="application/rss+xml"/>

<?php
$result = $conn->query("SELECT * FROM news ORDER BY created_at DESC LIMIT 20");

while($row = $result->fetch_assoc()):
    $link = $baseUrl . "pages/news-details.php?id=" . $row['id'];
?>
    <item>
        <title><?php echo htmlspecialchars($row['title']); ?></title>
        <link><?php echo $link; ?></link>
        <guid isPermaLink="true"><?php echo $link; ?></guid>
        <pubDate><?php echo date(DATE_RSS, strtotime($row['created_at'])); ?></pubDate>
        <description><![CDATA[<?php echo mb_substr(strip_tags($row['content']), 0, 300); ?>]]></description>
    </item>
<?php endwhile; ?>

</channel>
</rss>
