<?php
header('Content-Type: application/xml; charset=utf-8');
require_once __DIR__ . '/includes/db.php';
$db   = getDB();
$base = 'https://kino-michi.com';
$today = date('Y-m-d');
?>
<?= '<?xml version="1.0" encoding="UTF-8"?>' ?>
<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">

  <url><loc><?= $base ?>/</loc><changefreq>daily</changefreq><priority>1.0</priority><lastmod><?= $today ?></lastmod></url>
  <url><loc><?= $base ?>/news.php</loc><changefreq>hourly</changefreq><priority>0.9</priority><lastmod><?= $today ?></lastmod></url>
  <url><loc><?= $base ?>/board/</loc><changefreq>hourly</changefreq><priority>0.8</priority><lastmod><?= $today ?></lastmod></url>
  <url><loc><?= $base ?>/review/</loc><changefreq>daily</changefreq><priority>0.8</priority><lastmod><?= $today ?></lastmod></url>
  <url><loc><?= $base ?>/event/</loc><changefreq>daily</changefreq><priority>0.7</priority><lastmod><?= $today ?></lastmod></url>
  <url><loc><?= $base ?>/event/new.php</loc><changefreq>monthly</changefreq><priority>0.4</priority></url>
  <url><loc><?= $base ?>/policy.php</loc><changefreq>monthly</changefreq><priority>0.3</priority></url>
  <url><loc><?= $base ?>/contact.php</loc><changefreq>monthly</changefreq><priority>0.3</priority></url>

<?php
// スレッド一覧
$threads = $db->query("SELECT id, updated_at FROM threads ORDER BY updated_at DESC LIMIT 200")->fetchAll();
foreach ($threads as $t): ?>
  <url><loc><?= $base ?>/board/thread.php?id=<?= (int)$t['id'] ?></loc><changefreq>daily</changefreq><priority>0.6</priority><lastmod><?= date('Y-m-d', strtotime($t['updated_at'])) ?></lastmod></url>
<?php endforeach; ?>

<?php
// レビュー一覧
$reviews = $db->query("SELECT id, created_at FROM reviews WHERE approved=1 ORDER BY created_at DESC LIMIT 200")->fetchAll();
foreach ($reviews as $r): ?>
  <url><loc><?= $base ?>/review/view.php?id=<?= (int)$r['id'] ?></loc><changefreq>monthly</changefreq><priority>0.7</priority><lastmod><?= date('Y-m-d', strtotime($r['created_at'])) ?></lastmod></url>
<?php endforeach; ?>

</urlset>
