<?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">
  <url><loc>https://apple.pro/</loc><priority>1.0</priority></url>
<?php
$blogs = glob(__DIR__.'/blogs/*.sqlite');
foreach($blogs as $f) {
    $name = basename($f, '.sqlite');
    if($name[0]==='.') continue;
    echo "<url><loc>https://$name.apple.pro/</loc><priority>0.8</priority></url>
";
    $db = new SQLite3($f);
    $r = $db->query("SELECT slug, updated_at FROM posts WHERE published=1 ORDER BY updated_at DESC");
    while($row = $r->fetchArray(SQLITE3_ASSOC)) {
        $slug = htmlspecialchars($row['slug']);
        $date = date('Y-m-d', strtotime($row['updated_at']));
        echo "<url><loc>https://$name.apple.pro/?p=$slug</loc><lastmod>$date</lastmod><priority>0.6</priority></url>
";
    }
    $db->close();
}
?>
</urlset>
