<?php

header("Content-Type: application/xml; charset=utf-8");

$con = mysqli_connect(
    "localhost",
    "mercadoajato",
    "guarana1",
    "mercadoajato"
);

mysqli_set_charset($con, "utf8");

$site_url = "https://www.mercadoajato.com.br";

echo '<?xml version="1.0" encoding="UTF-8"?>';

?>

<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">

<url>
<loc>https://www.mercadoajato.com.br/</loc>
<changefreq>hourly</changefreq>
<priority>1.0</priority>
</url>

<?php

$paginas = [
    "bolsafamilia.php",
    "inss.php",
    "fgts.php",
    "bpc.php",
    "emprestimo.php",
    "cotidiano.php",
    "economia.php",
    "cultura.php",
    "esportes.php"
];

foreach($paginas as $pagina){

echo "
<url>
<loc>$site_url/$pagina</loc>
<changefreq>daily</changefreq>
<priority>0.8</priority>
</url>
";

}

$sql = "SELECT slug, data FROM artigos ORDER BY id DESC LIMIT 1000";

$res = mysqli_query($con, $sql);

while($row = mysqli_fetch_assoc($res)){

$slug = htmlspecialchars($row['slug']);

$data = date('Y-m-d', strtotime($row['data']));

echo "
<url>
<loc>$site_url/noticia.php?slug=$slug</loc>
<lastmod>$data</lastmod>
<changefreq>weekly</changefreq>
<priority>0.9</priority>
</url>
";

}

mysqli_close($con);

?>

</urlset>