<?php
$path = "../../../";
if (file_exists($path . "config/map.php")) {
    $path2 = "config/"; include($path . "config/map.php"); include($path . "config/subdomain.php");
} else {
    include($path . "map.php");
}

include("fonksiyon" . $ver . ".php");
include("cevir.php");
$weburl="https://".$_SERVER['HTTP_HOST'];

// XML başlıkları
header('Content-type: text/xml');
echo '<?xml version="1.0" encoding="UTF-8"?>';
?>
<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">
<?php
$ucats = json_decode(GetArr("u", "categories"), true);
if ($ucats && is_array($ucats)) {
    foreach ($ucats as $xkey => $xvalue) {
        // Üst kategori
        if ($xvalue["ne"] == "ukategori") {
            echo SitemapUrl(linked("x", $xvalue["id"], '', $weburl));

            foreach ($ucats as $ykey => $yvalue) {
                // Alt kategori
                if ($yvalue["ne"] == "ualt_kategori" && $yvalue["c1"] == $xvalue["id"]){
                    
                    echo SitemapUrl(linked("y", $yvalue["id"], '', $weburl));

                    foreach ($ucats as $zkey => $zvalue) {
                        // Alt-Alt kategori
                        if ($zvalue["ne"] == "ualt2_kategori" && $zvalue["c2"] == $yvalue["id"]) {
                            
                            echo SitemapUrl(linked("z", $zvalue["id"], '', $weburl));
                        }
                    }
                }
            }
        }
    }
}

// Sitemap satırı yazdırma fonksiyonu
function SitemapUrl($url) {
    $lastmod = date("Y-m-d") . "T" . date("H:i:s") . "+00:00";
    echo "
    <url>
        <loc>$url</loc>
        <lastmod>$lastmod</lastmod>
        <changefreq>daily</changefreq>
        <priority>0.50</priority>
    </url>";
}
?>
</urlset>