<?php
require_once __DIR__ . '/config.php';
require_once __DIR__ . '/includes/db.php';

header('Content-Type: application/xml; charset=utf-8');

echo '<?xml version="1.0" encoding="UTF-8"?>';
?>
<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">
    <url>
        <loc><?= rtrim(SITE_URL, '/') ?>/</loc>
        <priority>1.0</priority>
        <changefreq>daily</changefreq>
    </url>
    
    <?php
    $today = date('Y-m-d');
    
    // Categories
    $categories = $db->query("SELECT slug, created_at FROM categories ORDER BY id");
    foreach ($categories as $c): ?>
    <url>
        <loc><?= rtrim(SITE_URL, '/') ?>/kategor/<?= h($c['slug']) ?></loc>
        <priority>0.8</priority>
        <changefreq>weekly</changefreq>
        <lastmod><?= date('Y-m-d', strtotime($c['created_at'])) ?></lastmod>
    </url>
    <?php endforeach; ?>
    
    <?php
    // Forums
    $forums = $db->query("SELECT slug, created_at FROM forums ORDER BY id");
    foreach ($forums as $f): ?>
    <url>
        <loc><?= rtrim(SITE_URL, '/') ?>/sosyal/<?= h($f['slug']) ?></loc>
        <priority>0.7</priority>
        <changefreq>daily</changefreq>
        <lastmod><?= date('Y-m-d', strtotime($f['created_at'])) ?></lastmod>
    </url>
    <?php endforeach; ?>
    
    <?php
    // Topics
    $topics = $db->query("SELECT slug, created_at FROM topics ORDER BY id LIMIT 1000");
    foreach ($topics as $t): ?>
    <url>
        <loc><?= rtrim(SITE_URL, '/') ?>/topic/<?= h($t['slug']) ?></loc>
        <priority>0.5</priority>
        <changefreq>weekly</changefreq>
        <lastmod><?= date('Y-m-d', strtotime($t['created_at'])) ?></lastmod>
    </url>
    <?php endforeach; ?>
    
    <?php
    // Pages
    $pages = $db->query("SELECT slug, updated_at, created_at FROM pages WHERE is_published = 1");
    foreach ($pages as $p): ?>
    <url>
        <loc><?= rtrim(SITE_URL, '/') ?>/sayfa/<?= h($p['slug']) ?></loc>
        <priority>0.6</priority>
        <changefreq>monthly</changefreq>
        <lastmod><?= date('Y-m-d', strtotime($p['updated_at'] ?? $p['created_at'])) ?></lastmod>
    </url>
    <?php endforeach; ?>
    
    <url>
        <loc><?= rtrim(SITE_URL, '/') ?>/uyeler</loc>
        <priority>0.4</priority>
        <changefreq>weekly</changefreq>
    </url>
    <url>
        <loc><?= rtrim(SITE_URL, '/') ?>/giris</loc>
        <priority>0.3</priority>
        <changefreq>monthly</changefreq>
    </url>
    <url>
        <loc><?= rtrim(SITE_URL, '/') ?>/kayit</loc>
        <priority>0.3</priority>
        <changefreq>monthly</changefreq>
    </url>
</urlset>
>
