<?php
require 'config/db.php';

header("Content-Type: application/xml; charset=utf-8");

// Base URL
$base_url = "https://prosubscriptionoffers.com";

echo '<?xml version="1.0" encoding="UTF-8"?>';
?>
<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">
    
    <url>
        <loc><?php echo $base_url; ?>/</loc>
        <changefreq>daily</changefreq>
        <priority>1.0</priority>
    </url>
    <url>
        <loc><?php echo $base_url; ?>/login.php</loc>
        <changefreq>monthly</changefreq>
        <priority>0.8</priority>
    </url>
    <url>
        <loc><?php echo $base_url; ?>/register.php</loc>
        <changefreq>monthly</changefreq>
        <priority>0.8</priority>
    </url>
    <url>
        <loc><?php echo $base_url; ?>/blog.php</loc>
        <changefreq>weekly</changefreq>
        <priority>0.9</priority>
    </url>

    <?php
    $products = $pdo->query("SELECT id, created_at FROM products WHERE is_active = 1 ORDER BY id DESC")->fetchAll();
    foreach($products as $p) {
        $date = date('Y-m-d', strtotime($p['created_at']));
        echo "
    <url>
        <loc>{$base_url}/product.php?id={$p['id']}</loc>
        <lastmod>{$date}</lastmod>
        <changefreq>weekly</changefreq>
        <priority>0.9</priority>
    </url>";
    }
    ?>

    <?php
    $posts = $pdo->query("SELECT slug, created_at FROM posts ORDER BY id DESC")->fetchAll();
    foreach($posts as $post) {
        $date = date('Y-m-d', strtotime($post['created_at']));
        echo "
    <url>
        <loc>{$base_url}/post.php?slug={$post['slug']}</loc>
        <lastmod>{$date}</lastmod>
        <changefreq>monthly</changefreq>
        <priority>0.7</priority>
    </url>";
    }
    ?>

</urlset>