WebOrbiton
v1.0.0.0

StocketBase

53 lines · 1.9 KB
  1. <?php
  2. ​
  3. declare(strict_types=1);
  4. ​
  5. require_once __DIR__ . '/includes/config.php';
  6. require_once __DIR__ . '/includes/database.php';
  7. require_once __DIR__ . '/includes/site-front.php';
  8. ​
  9. $settings = SiteFront::settings();
  10. ​
  11. if ($settings['sitemap_rss_enabled'] !== '1') {
  12. http_response_code(404);
  13. exit;
  14. }
  15. ​
  16. $db = Database::site();
  17. $baseUrl = rtrim(Config::get('APP_URL', ''), '/') . Config::get('APP_BASE_PATH', '');
  18. ​
  19. $products = $db->query("SELECT id, slug, updated_at FROM products WHERE status = 'published' ORDER BY updated_at DESC")->fetchAll();
  20. $pages = $db->query("SELECT slug, updated_at FROM pages WHERE status = 'published'")->fetchAll();
  21. $categories = $db->query('SELECT slug FROM categories')->fetchAll();
  22. ​
  23. header('Content-Type: application/xml; charset=utf-8');
  24. ​
  25. echo '<?xml version="1.0" encoding="UTF-8"?>' . "\n";
  26. echo '<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">' . "\n";
  27. ​
  28. echo '<url><loc>' . htmlspecialchars($baseUrl . '/index.php') . '</loc></url>' . "\n";
  29. ​
  30. foreach ($categories as $category) {
  31. echo '<url><loc>' . htmlspecialchars($baseUrl . '/category.php?slug=' . urlencode($category['slug'])) . '</loc></url>' . "\n";
  32. }
  33. ​
  34. foreach ($pages as $page) {
  35. echo '<url><loc>' . htmlspecialchars($baseUrl . '/page.php?slug=' . urlencode($page['slug'])) . '</loc>';
  36. echo '<lastmod>' . htmlspecialchars(date('c', strtotime($page['updated_at']))) . '</lastmod></url>' . "\n";
  37. }
  38. ​
  39. foreach ($products as $product) {
  40. echo '<url><loc>' . htmlspecialchars(rtrim(Config::get('APP_URL', ''), '/') . SiteFront::productUrl($product['slug'])) . '</loc>';
  41. echo '<lastmod>' . htmlspecialchars(date('c', strtotime($product['updated_at']))) . '</lastmod></url>' . "\n";
  42. }
  43. ​
  44. if (Languages::enabled()) {
  45. $origin = rtrim(Config::get('APP_URL', ''), '/');
  46. ​
  47. foreach (Languages::activeCodes() as $languageCode) {
  48. echo '<url><loc>' . htmlspecialchars($origin . Languages::homeUrl($languageCode)) . '</loc></url>' . "\n";
  49. }
  50. }
  51. ​
  52. echo '</urlset>';
  53. ​