<?php
header('Content-Type: application/xml; charset=utf-8');
require_once 'db.php';
$base = 'https://webmahekindia.com';
$today = date('Y-m-d');
echo '<?xml version="1.0" encoding="UTF-8"?>';
?>
<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">
    <url><loc><?=$base?>/</loc><lastmod><?=$today?></lastmod><changefreq>weekly</changefreq><priority>1.0</priority></url>
    <url><loc><?=$base?>/about.php</loc><lastmod><?=$today?></lastmod><changefreq>monthly</changefreq><priority>0.9</priority></url>
    <url><loc><?=$base?>/review.php</loc><lastmod><?=$today?></lastmod><changefreq>monthly</changefreq><priority>0.6</priority></url>
    <url><loc><?=$base?>/all-reviews.php</loc><lastmod><?=$today?></lastmod><changefreq>weekly</changefreq><priority>0.7</priority></url>
    <url><loc><?=$base?>/portfolio.php</loc><lastmod><?=$today?></lastmod><changefreq>weekly</changefreq><priority>0.8</priority></url>
    <url><loc><?=$base?>/blog/</loc><lastmod><?=$today?></lastmod><changefreq>daily</changefreq><priority>0.9</priority></url>
<?php
// Blog posts
$blogs = $pdo->query("SELECT slug, updated_at FROM blogs WHERE is_published=1 ORDER BY created_at DESC")->fetchAll();
foreach ($blogs as $b):
?>
    <url><loc><?=$base?>/blog/<?=$b['slug']?></loc><lastmod><?=date('Y-m-d',strtotime($b['updated_at']))?></lastmod><changefreq>monthly</changefreq><priority>0.8</priority></url>
<?php endforeach;
// Pages
$pages = $pdo->query("SELECT slug, updated_at FROM pages WHERE is_active=1")->fetchAll();
foreach ($pages as $p):
?>
    <url><loc><?=$base?>/page.php?slug=<?=$p['slug']?></loc><lastmod><?=date('Y-m-d',strtotime($p['updated_at']))?></lastmod><changefreq>monthly</changefreq><priority>0.7</priority></url>
<?php endforeach; ?>
</urlset>
