v1.0.0.1
StocketBase
- <?php
-
- declare(strict_types=1);
-
- require_once __DIR__ . '/includes/config.php';
- require_once __DIR__ . '/includes/database.php';
- require_once __DIR__ . '/includes/site-front.php';
-
- $settings = SiteFront::settings();
-
- if ($settings['sitemap_rss_enabled'] !== '1') {
- http_response_code(404);
- exit;
- }
-
- $db = Database::site();
- $baseUrl = rtrim(Config::get('APP_URL', ''), '/') . Config::get('APP_BASE_PATH', '');
-
- $products = $db->query("SELECT id, slug, updated_at FROM products WHERE status = 'published' ORDER BY updated_at DESC")->fetchAll();
- $pages = $db->query("SELECT slug, updated_at FROM pages WHERE status = 'published' AND is_home = 0")->fetchAll();
- $categories = $db->query('SELECT slug FROM categories')->fetchAll();
-
- header('Content-Type: application/xml; charset=utf-8');
-
- echo '<?xml version="1.0" encoding="UTF-8"?>' . "\n";
- echo '<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">' . "\n";
-
- echo '<url><loc>' . htmlspecialchars($baseUrl . '/index.php') . '</loc></url>' . "\n";
-
- foreach ($categories as $category) {
- echo '<url><loc>' . htmlspecialchars($baseUrl . '/category.php?slug=' . urlencode($category['slug'])) . '</loc></url>' . "\n";
- }
-
- foreach ($pages as $page) {
- echo '<url><loc>' . htmlspecialchars($baseUrl . '/page.php?slug=' . urlencode($page['slug'])) . '</loc>';
- echo '<lastmod>' . htmlspecialchars(date('c', strtotime($page['updated_at']))) . '</lastmod></url>' . "\n";
- }
-
- foreach ($products as $product) {
- echo '<url><loc>' . htmlspecialchars(rtrim(Config::get('APP_URL', ''), '/') . SiteFront::productUrl($product['slug'])) . '</loc>';
- echo '<lastmod>' . htmlspecialchars(date('c', strtotime($product['updated_at']))) . '</lastmod></url>' . "\n";
- }
-
- if (Languages::enabled()) {
- $origin = rtrim(Config::get('APP_URL', ''), '/');
-
- foreach (Languages::activeCodes() as $languageCode) {
- echo '<url><loc>' . htmlspecialchars($origin . Languages::homeUrl($languageCode)) . '</loc></url>' . "\n";
- }
- }
-
- echo '</urlset>';
-