<?php
  header('Content-Type: application/xml; charset=utf-8');
  include ('widgets/connectdb.php');
  $baseUrl = 'https://www.sciencecatalogs.com';

  $staticUrls = [
      [
          'loc' => $baseUrl . '/',
          'lastmod' => '2026-07-25',
          'changefreq' => 'daily',
          'priority' => '1.0'
      ],
      [
          'loc' => $baseUrl . '/about',
          'lastmod' => '2026-07-25',
          'changefreq' => 'monthly',
          'priority' => '0.8'
      ],
      [
          'loc' => $baseUrl . '/contact',
          'lastmod' => '2026-07-25',
          'changefreq' => 'monthly',
          'priority' => '0.8'
      ],
      [
          'loc' => $baseUrl . '/page/privacy-policy',
          'lastmod' => '2026-07-25',
          'changefreq' => 'yearly',
          'priority' => '0.4'
      ],
      [
          'loc' => $baseUrl . '/page/terms-of-use',
          'lastmod' => '2026-07-25',
          'changefreq' => 'yearly',
          'priority' => '0.4'
      ],
      [
          'loc' => $baseUrl . '/page/refund-policy',
          'lastmod' => '2026-07-25',
          'changefreq' => 'yearly',
          'priority' => '0.4'
      ],
      [
          'loc' => $baseUrl . '/insights',
          'lastmod' => '2026-07-25',
          'changefreq' => 'daily',
          'priority' => '0.9'
      ],
      [
          'loc' => $baseUrl . '/journals',
          'lastmod' => '2026-07-25',
          'changefreq' => 'daily',
          'priority' => '0.9'
      ],
      [
          'loc' => $baseUrl . '/conferences',
          'lastmod' => '2026-07-25',
          'changefreq' => 'daily',
          'priority' => '0.9'
      ],
      [
          'loc' => $baseUrl . '/books',
          'lastmod' => '2026-07-25',
          'changefreq' => 'daily',
          'priority' => '0.9'
      ],
      [
          'loc' => $baseUrl . '/proceedings',
          'lastmod' => '2026-07-25',
          'changefreq' => 'daily',
          'priority' => '0.9'
      ],
      [
          'loc' => $baseUrl . '/plagiarism-checker',
          'lastmod' => '2026-07-25',
          'changefreq' => 'daily',
          'priority' => '0.9'
      ],
      [
          'loc' => $baseUrl . '/literature-discovery',
          'lastmod' => '2026-07-25',
          'changefreq' => 'daily',
          'priority' => '0.9'
      ],
      [
          'loc' => $baseUrl . '/scholars-post',
          'lastmod' => '2026-07-25',
          'changefreq' => 'daily',
          'priority' => '0.9'
      ],
      [
          'loc' => $baseUrl . '/scinexid',
          'lastmod' => '2026-07-25',
          'changefreq' => 'daily',
          'priority' => '0.9'
      ],
      [
          'loc' => $baseUrl . '/global-research-library',
          'lastmod' => '2026-07-25',
          'changefreq' => 'daily',
          'priority' => '0.9'
      ]
  ];

  $sql2="SELECT * FROM blog_posts
    WHERE bp_status=2
    ORDER BY bp_id";
    $statement2 = $connect->prepare($sql2);
    $statement2->execute();
    $result2 = $statement2->fetchAll();
								

  echo '<?xml version="1.0" encoding="UTF-8"?>' . "\n";
  echo '<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">' . "\n";

  foreach ($staticUrls as $u) {
      echo "  <url>\n";
      echo '    <loc>' . htmlspecialchars($u['loc'], ENT_XML1 | ENT_QUOTES, 'UTF-8') . "</loc>\n";
      echo '    <lastmod>' . htmlspecialchars($u['lastmod'], ENT_XML1 | ENT_QUOTES, 'UTF-8') . "</lastmod>\n";
      echo '    <changefreq>' . htmlspecialchars($u['changefreq'], ENT_XML1 | ENT_QUOTES, 'UTF-8') . "</changefreq>\n";
      echo '    <priority>' . htmlspecialchars($u['priority'], ENT_XML1 | ENT_QUOTES, 'UTF-8') . "</priority>\n";
      echo "  </url>\n";
  }
  
      foreach($result2 as $row) {
          $dt = new DateTime($row['bp_date']);
          $loc = $baseUrl . '/insight/' . $row['bp_permalink'];

          echo "  <url>\n";
          echo '    <loc>' . htmlspecialchars($loc, ENT_XML1 | ENT_QUOTES, 'UTF-8') . "</loc>\n";
          echo '    <lastmod>' . $dt->format('Y-m-d\TH:i:sP') . "</lastmod>\n";
          echo '    <changefreq>weekly</changefreq>' . "\n";
          echo '    <priority>0.7</priority>' . "\n";
          echo "  </url>\n";
      }

  echo "</urlset>\n";

  $connect = null;
?>