<?php
require_once './include/inc.fo_init.php';

if (CMS::getCurrentSite()->getField('SIT_NOINDEX')) {
    http_response_code(404);
    return;
}

header("Content-Type: text/xml;charset=UTF-8");
echo '<?xml version="1.0" encoding="UTF-8"?>';
?>
<sitemapindex xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">
<?php
$aSitemap = glob(PHYSICAL_PATH . 'sitemap.*.php');
foreach ($aSitemap as $file) {
    $filename = basename($file);
    if (preg_match('/(sitemap\.[^\.]+)\.php/', $filename, $matche)) {
        echo '<sitemap>
                <loc>' . CMS::getCurrentSite()->getHostname() . SERVER_ROOT . $matche[1] . '.xml</loc>
                <lastmod>' . date('Y-m-d') . '</lastmod>
            </sitemap>';
    }
}
?>
</sitemapindex>
