<?php
/* =====================================================
   MASTER SITEMAP.PHP
   Otomatis membaca semua child sitemap
   Auto lastmod harian
   GSC Friendly + Siap Upload
===================================================== */

date_default_timezone_set('Asia/Jakarta');

/* =========================
   HEADER XML
========================= */
header("Content-Type: application/xml; charset=UTF-8");

/* =========================
   DOMAIN
========================= */
$domain = 'https://www.iniprimbons.com';

/* =========================
   DAFTAR CHILD SITEMAP
========================= */
$sitemaps = [

'sitemap-konsultasi.php',
'sitemap-artimimpi.php',
'sitemap-artinama.php',
'sitemap-ramalanharian.php',
'sitemap-ramalanjodoh.php'

];

/* =========================
   XML START
========================= */
echo '<?xml version="1.0" encoding="UTF-8"?>' . "\n";
echo '<sitemapindex xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">' . "\n";

/* =========================
   LOOP CHILD SITEMAP
========================= */
foreach($sitemaps as $file){

$path = __DIR__ . '/' . $file;

/* jika file ada gunakan filemtime */
if(file_exists($path)){
    $lastmod = date('Y-m-d', filemtime($path));
}else{
    $lastmod = date('Y-m-d');
}

echo '<sitemap>' . "\n";
echo '<loc>' . htmlspecialchars($domain.'/'.$file, ENT_QUOTES, 'UTF-8') . '</loc>' . "\n";
echo '<lastmod>' . $lastmod . '</lastmod>' . "\n";
echo '</sitemap>' . "\n";

}

echo '</sitemapindex>';
?>