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

require_once 'includes/config.php';
require_once 'includes/functions.php';

// Schimbă SITE_URL
define('SITE_URL', 'https://quatidianoblog.it');  // ← DOMENIUL TĂU

$articles = getArticles();

echo '<?xml version="1.0" encoding="UTF-8"?>';
echo '<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">';

// Pagina principală
echo '<url>';
echo '<loc>' . SITE_URL . '/</loc>';
echo '<lastmod>' . date('Y-m-d') . '</lastmod>';
echo '<changefreq>daily</changefreq>';
echo '<priority>1.0</priority>';
echo '</url>';

// Articole
foreach ($articles as $article) {
    if ($article['status'] !== 'published') continue;
    
    echo '<url>';
    echo '<loc>' . SITE_URL . ($article['permalink'] ?? '') . '</loc>';
    echo '<lastmod>' . date('Y-m-d', strtotime($article['created_at'] ?? 'now')) . '</lastmod>';
    echo '<changefreq>weekly</changefreq>';
    echo '<priority>0.8</priority>';
    echo '</url>';
}

// Categorii
$categories = ['gossip', 'tv', 'hot', 'news', 'general'];
foreach ($categories as $cat) {
    echo '<url>';
    echo '<loc>' . SITE_URL . '/?category=' . $cat . '</loc>';
    echo '<lastmod>' . date('Y-m-d') . '</lastmod>';
    echo '<changefreq>weekly</changefreq>';
    echo '<priority>0.5</priority>';
    echo '</url>';
}

echo '</urlset>';