<?xml version="1.0" encoding="UTF-8"?>
<?xml-stylesheet type="text/xsl" href="sitemap.xsl"?>
<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9"
        xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
        xmlns:image="http://www.google.com/schemas/sitemap-image/1.1"
        xmlns:video="http://www.google.com/schemas/sitemap-video/1.1"
        xmlns:news="http://www.google.com/schemas/sitemap-news/0.9"
        xmlns:mobile="http://www.google.com/schemas/sitemap-mobile/1.0"
        xmlns:xhtml="http://www.w3.org/1999/xhtml">

    <!-- Ana Sayfa -->
    <url>
        <loc>https://www.webesk.com/</loc>
        <lastmod><?php echo date('c'); ?></lastmod>
        <changefreq>weekly</changefreq>
        <priority>1.0</priority>
    </url>

    <!-- Hizmetler Sayfası -->
    <url>
        <loc>https://www.webesk.com/hizmetler</loc>
        <lastmod><?php echo date('c'); ?></lastmod>
        <changefreq>monthly</changefreq>
        <priority>0.9</priority>
    </url>

    <!-- Hakkımızda Sayfası -->
    <url>
        <loc>https://www.webesk.com/hakkimizda</loc>
        <lastmod><?php echo date('c'); ?></lastmod>
        <changefreq>monthly</changefreq>
        <priority>0.8</priority>
    </url>

    <!-- İletişim Sayfası -->
    <url>
        <loc>https://www.webesk.com/iletisim</loc>
        <lastmod><?php echo date('c'); ?></lastmod>
        <changefreq>monthly</changefreq>
        <priority>0.8</priority>
    </url>

    <!-- Blog Ana Sayfası -->
    <url>
        <loc>https://www.webesk.com/blog</loc>
        <lastmod><?php echo date('c'); ?></lastmod>
        <changefreq>daily</changefreq>
        <priority>0.9</priority>
    </url>

    <!-- Dinamik Blog Yazıları -->
    <?php
    require_once 'config/database.php';
    
    try {
        $db = new PDO("mysql:host=".DB_HOST.";dbname=".DB_NAME, DB_USER, DB_PASS);
        $db->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
        
        $query = $db->query("SELECT slug, updated_at FROM blog_posts WHERE status = 'published' ORDER BY created_at DESC");
        
        while($post = $query->fetch(PDO::FETCH_ASSOC)) {
            $date = new DateTime($post['updated_at']);
            echo '
    <url>
        <loc>https://www.webesk.com/blog/'.$post['slug'].'</loc>
        <lastmod>'.$date->format('c').'</lastmod>
        <changefreq>weekly</changefreq>
        <priority>0.7</priority>
    </url>';
        }
    } catch(PDOException $e) {
        // Hata durumunda sessizce devam et
    }
    ?>

    <!-- Hizmet Kategorileri -->
    <url>
        <loc>https://www.webesk.com/web-tasarim-hizmetleri</loc>
        <lastmod><?php echo date('c'); ?></lastmod>
        <changefreq>monthly</changefreq>
        <priority>0.8</priority>
    </url>

    <url>
        <loc>https://www.webesk.com/yazilim-gelistirme</loc>
        <lastmod><?php echo date('c'); ?></lastmod>
        <changefreq>monthly</changefreq>
        <priority>0.8</priority>
    </url>

    <url>
        <loc>https://www.webesk.com/e-ticaret-cozumleri</loc>
        <lastmod><?php echo date('c'); ?></lastmod>
        <changefreq>monthly</changefreq>
        <priority>0.8</priority>
    </url>

    <url>
        <loc>https://www.webesk.com/seo-hizmetleri</loc>
        <lastmod><?php echo date('c'); ?></lastmod>
        <changefreq>monthly</changefreq>
        <priority>0.8</priority>
    </url>

    <!-- Referanslar Sayfası -->
    <url>
        <loc>https://www.webesk.com/referanslar</loc>
        <lastmod><?php echo date('c'); ?></lastmod>
        <changefreq>monthly</changefreq>
        <priority>0.7</priority>
    </url>

</urlset>