<?php
// Buffer everything so we can guarantee the XML declaration is the very
// first byte of output, even if an include below prints/leaks anything.
ob_start();
error_reporting(0);
ini_set('display_errors', '0');

$base_url = "https://smartstudyweb.com";

$posts = [];
if (file_exists(__DIR__ . '/data/posts.php')) {
    // Isolate this include in its own buffer so any stray whitespace, a
    // BOM, or a stray echo/print inside data/posts.php can never leak into
    // our XML output (this is the #1 cause of Search Console's "Unsupported
    // file format" error on PHP-generated sitemaps). We only keep the
    // $posts variable it sets — any printed output from the include itself
    // is discarded.
    ob_start();
    require __DIR__ . '/data/posts.php';
    ob_end_clean();
}

// Wipe out anything that may have leaked into our own buffer above this
// point (from the include, from a stray warning, etc.) so the XML
// declaration below is guaranteed to be the first byte we send.
ob_clean();

header('Content-Type: application/xml; charset=UTF-8');

echo '<?xml version="1.0" encoding="UTF-8"?>';
?>

<urlset
xmlns="http://www.sitemaps.org/schemas/sitemap/0.9"
xmlns:image="http://www.google.com/schemas/sitemap-image/1.1">

  <url>
    <loc><?= $base_url ?>/</loc>
    <lastmod><?= date('c') ?></lastmod>
    <changefreq>daily</changefreq>
    <priority>1.0</priority>
  </url>

<?php if (!empty($posts) && is_array($posts)): ?>
<?php foreach ($posts as $post): ?>
<?php
    if (empty($post['slug'])) continue;
    $slug = htmlspecialchars($post['slug'], ENT_XML1, 'UTF-8');
    $lastmod = !empty($post['date']) ? date('c', strtotime($post['date'])) : date('c');
?>

  <url>
    <loc><?= $base_url ?>/<?= $slug ?>.html</loc>
    <lastmod><?= $lastmod ?></lastmod>
    <changefreq>daily</changefreq>
    <priority>0.8</priority>
  </url>

  <url>
    <loc><?= $base_url ?>/amp/<?= $slug ?>.html</loc>
    <lastmod><?= $lastmod ?></lastmod>
    <changefreq>daily</changefreq>
    <priority>0.6</priority>
  </url>

  <url>
<loc>https://smartstudyweb.com/mbbs-admission-india.html</loc>
</url>
 <url>
<loc>https://smartstudyweb.com/fmge-exam-india-eligibility.html</loc>
</url>
<url>
<loc>https://smartstudyweb.com/mbbs/mbbs-admission-in-india.html</loc>
</url>


<?php endforeach; ?>
<?php endif; ?>

<!-- ===== NEET PG MD/MS fees & state-wise cutoffs — hub + all 15 state pages ===== -->
<?php
$neetpg_base = "https://www.smartstudyweb.com";
$neetpg_lastmod = date('c');
$neetpg_pages = [
    ['loc' => '/neet-pg-fees-cutoffs-all-india.html',       'priority' => '0.9'],
    ['loc' => '/neet-pg-cutoff-fees-karnataka.html',        'priority' => '0.8'],
    ['loc' => '/neet-pg-cutoff-fees-maharashtra.html',      'priority' => '0.8'],
    ['loc' => '/neet-pg-cutoff-fees-punjab.html',           'priority' => '0.8'],
    ['loc' => '/neet-pg-cutoff-fees-haryana.html',          'priority' => '0.8'],
    ['loc' => '/neet-pg-cutoff-fees-himachal-pradesh.html', 'priority' => '0.8'],
    ['loc' => '/neet-pg-cutoff-fees-rajasthan.html',        'priority' => '0.8'],
    ['loc' => '/neet-pg-cutoff-fees-uttar-pradesh.html',    'priority' => '0.8'],
    ['loc' => '/neet-pg-cutoff-fees-madhya-pradesh.html',   'priority' => '0.8'],
    ['loc' => '/neet-pg-cutoff-fees-tamil-nadu.html',       'priority' => '0.8'],
    ['loc' => '/neet-pg-cutoff-fees-kerala.html',           'priority' => '0.8'],
    ['loc' => '/neet-pg-cutoff-fees-bihar.html',            'priority' => '0.8'],
    ['loc' => '/neet-pg-cutoff-fees-andhra-pradesh.html',   'priority' => '0.8'],
    ['loc' => '/neet-pg-cutoff-fees-jammu-kashmir.html',    'priority' => '0.8'],
    ['loc' => '/neet-pg-cutoff-fees-uttarakhand.html',      'priority' => '0.8'],
    ['loc' => '/neet-pg-cutoff-fees-telangana.html',        'priority' => '0.8'],
];
foreach ($neetpg_pages as $np):
?>
  <url>
    <loc><?= $neetpg_base . $np['loc'] ?></loc>
    <lastmod><?= $neetpg_lastmod ?></lastmod>
    <changefreq>weekly</changefreq>
    <priority><?= $np['priority'] ?></priority>
  </url>
<?php endforeach; ?>

</urlset>
<?php
ob_end_flush();
// Intentionally no closing PHP tag — this avoids any trailing whitespace
// after it being sent as extra bytes following </urlset>.