<?php
while(ob_get_level()){ob_end_clean();}
header('Content-Type:application/xml;charset=utf-8',true);
require_once(__DIR__.'/pex-includes/pex-cholo.php');
echo'<?xml version="1.0" encoding="UTF-8"?>'."\n";
echo'<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">'."\n";
echo'<url><loc>https://perunews.com/</loc><lastmod>'.date('Y-m-d').'</lastmod><changefreq>hourly</changefreq><priority>1.0</priority></url>'."\n";
if(isset($pdo)&&$pdo instanceof PDO){
try{
$stmt=$pdo->query("SELECT DISTINCT categoria_slug FROM vw_pex_post WHERE categoria_slug IS NOT NULL AND categoria_slug!='' ORDER BY categoria_slug");
if($stmt){while($row=$stmt->fetch(PDO::FETCH_ASSOC)){$s=trim($row['categoria_slug']);if(preg_match('/^[a-z0-9\-]+$/i',$s)){echo'<url><loc>https://perunews.com/'.$s.'/</loc><lastmod>'.date('Y-m-d').'</lastmod><changefreq>daily</changefreq><priority>0.8</priority></url>'."\n";}}}
$stmt=$pdo->query("SELECT post_id,categoria_slug FROM vw_pex_post ORDER BY post_id DESC LIMIT 1000");
if($stmt){while($row=$stmt->fetch(PDO::FETCH_ASSOC)){$s=!empty($row['categoria_slug'])?trim($row['categoria_slug']):'noticias';$id=(int)$row['post_id'];if(preg_match('/^[a-z0-9\-]+$/i',$s)&&$id>0){echo'<url><loc>https://perunews.com/'.$s.'/post/'.$id.'</loc><lastmod>'.date('Y-m-d').'</lastmod><changefreq>weekly</changefreq><priority>0.6</priority></url>'."\n";}}}
}catch(PDOException $e){error_log('sitemap:'.$e->getMessage());}}
echo'</urlset>';