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

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

// Página inicial
echo '<url>';
echo '<loc>https://www.versododia.com.br/index.php</loc>';
echo '<lastmod>' . date('Y-m-d') . '</lastmod>';
echo '<changefreq>daily</changefreq>';
echo '<priority>1.0</priority>';
echo '</url>';

// Página de mensagens
echo '<url>';
echo '<loc>https://www.versododia.com.br/mensagens.php</loc>';
echo '<lastmod>' . date('Y-m-d') . '</lastmod>';
echo '<changefreq>daily</changefreq>';
echo '<priority>0.9</priority>';
echo '</url>';

// Página sobre
echo '<url>';
echo '<loc>https://www.versododia.com.br/sobre.php</loc>';
echo '<lastmod>' . date('Y-m-d') . '</lastmod>';
echo '<changefreq>monthly</changefreq>';
echo '<priority>0.8</priority>';
echo '</url>';

// Todas as mensagens (posts)
$sql = "SELECT id, data_postagem FROM mensagens ORDER BY data_postagem DESC";
$result = mysqli_query($conn, $sql);

while($row = mysqli_fetch_assoc($result)) {
    echo '<url>';
    echo '<loc>https://www.versododia.com.br/post.php?id=' . $row['id'] . '</loc>';
    echo '<lastmod>' . date('Y-m-d', strtotime($row['data_postagem'])) . '</lastmod>';
    echo '<changefreq>never</changefreq>';
    echo '<priority>0.7</priority>';
    echo '</url>';
}

echo '</urlset>';
mysql_close($conn);
?>
