<?php
header('Content-Type: application/xml; charset=utf-8');
require_once __DIR__ . '/includes/functions.php';

$baseUrl = config('site_url');
echo '<?xml version="1.0" encoding="UTF-8"?>' . "\n";
echo '<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">' . "\n";

$pages = [
    'index.php',
    'radio.php',
    'tv.php',
    'nosotros.php',
    'contacto.php',
    'buscar.php',
];

foreach ($pages as $page) {
    echo '  <url>' . "\n";
    echo '    <loc>' . $baseUrl . '/' . $page . '</loc>' . "\n";
    echo '    <changefreq>daily</changefreq>' . "\n";
    echo '    <priority>0.8</priority>' . "\n";
    echo '  </url>' . "\n";
}

foreach (db()->getActivos('radios') as $radio) {
    echo '  <url>' . "\n";
    echo '    <loc>' . $baseUrl . '/radio.php?slug=' . sanitize($radio['slug']) . '</loc>' . "\n";
    echo '    <changefreq>weekly</changefreq>' . "\n";
    echo '    <priority>0.6</priority>' . "\n";
    echo '  </url>' . "\n";
}

foreach (db()->getActivos('tv') as $canal) {
    echo '  <url>' . "\n";
    echo '    <loc>' . $baseUrl . '/tv.php?slug=' . sanitize($canal['slug']) . '</loc>' . "\n";
    echo '    <changefreq>weekly</changefreq>' . "\n";
    echo '    <priority>0.6</priority>' . "\n";
    echo '  </url>' . "\n";
}

foreach (db()->getActivos('categorias') as $cat) {
    echo '  <url>' . "\n";
    echo '    <loc>' . $baseUrl . '/categoria.php?slug=' . sanitize($cat['slug']) . '</loc>' . "\n";
    echo '    <changefreq>weekly</changefreq>' . "\n";
    echo '    <priority>0.5</priority>' . "\n";
    echo '  </url>' . "\n";
}

echo '</urlset>' . "\n";
?>
