<?php
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:news="http://www.google.com/schemas/sitemap-news/0.9"
        xmlns:image="http://www.google.com/schemas/sitemap-image/1.1">
  <!-- 固定页 -->
  <url><loc>https://www.tjxmlbx.com/</loc><changefreq>daily</changefreq><priority>1.0</priority></url>
  <url><loc>https://www.tjxmlbx.com/about/</loc><changefreq>monthly</changefreq><priority>0.6</priority></url>
  <url><loc>https://www.tjxmlbx.com/contact/</loc><changefreq>monthly</changefreq><priority>0.6</priority></url>
  <url><loc>https://www.tjxmlbx.com/q/</loc><changefreq>weekly</changefreq><priority>0.8</priority></url>
  <url><loc>https://www.tjxmlbx.com/outlets/</loc><changefreq>weekly</changefreq><priority>0.8</priority></url>
  <url><loc>https://www.tjxmlbx.com/search</loc><changefreq>weekly</changefreq><priority>0.5</priority></url>
  
  <?php
  // 栏目列表页
  $sorts = get_all_active_sorts();
  foreach ($sorts as $s) {
      echo "<url><loc>https://www.tjxmlbx.com/{$s['filename']}/</loc><changefreq>daily</changefreq><priority>0.9</priority></url>\n";
  }

  // 文章详情页
  $pdo = get_db();
  $articles = $pdo->query("SELECT c.id, c.date, s.filename FROM ay_content c LEFT JOIN ay_content_sort s ON c.scode = s.scode WHERE c.status = 1 ORDER BY c.date DESC LIMIT 10000")->fetchAll();
  foreach ($articles as $a) {
      $slug = $a['filename'] ?? 'kongtiaoweixiu';
      $lastmod = date('Y-m-d', strtotime($a['date'] ?? 'now'));
      echo "<url><loc>https://www.tjxmlbx.com/{$slug}/{$a['id']}.html</loc><lastmod>{$lastmod}</lastmod><changefreq>monthly</changefreq><priority>0.7</priority></url>\n";
  }

  // 问答页
  $qas = $pdo->query("SELECT id, date FROM ay_qa WHERE status = 1 LIMIT 5000")->fetchAll();
  foreach ($qas as $qa) {
      $lastmod = date('Y-m-d', strtotime($qa['date'] ?? 'now'));
      echo "<url><loc>https://www.tjxmlbx.com/q/{$qa['id']}.html</loc><lastmod>{$lastmod}</lastmod><changefreq>monthly</changefreq><priority>0.7</priority></url>\n";
  }
  ?>
</urlset>
