v1.0.0.0
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 p.id, p.title, p.slug, p.excerpt, p.published_at FROM products p WHERE p.status = 'published' ORDER BY p.published_at DESC LIMIT 30"
- )->fetchAll();
-
- header('Content-Type: application/rss+xml; charset=utf-8');
-
- echo '<?xml version="1.0" encoding="UTF-8"?>' . "\n";
- echo '<rss version="2.0"><channel>' . "\n";
- echo '<title>' . htmlspecialchars($settings['site_name']) . '</title>' . "\n";
- $channelLanguage = Languages::current();
- $channelLink = $channelLanguage === '' ? $baseUrl . '/index.php' : rtrim((string) Config::get('APP_URL', ''), '/') . Languages::homeUrl($channelLanguage);
- echo '<link>' . htmlspecialchars($channelLink) . '</link>' . "\n";
- if ($channelLanguage !== '') {
- echo '<language>' . htmlspecialchars($channelLanguage) . '</language>' . "\n";
- }
- echo '<description>' . htmlspecialchars($settings['site_description']) . '</description>' . "\n";
-
- foreach ($products as $product) {
- $url = rtrim(Config::get('APP_URL', ''), '/') . SiteFront::productUrl($product['slug']);
- echo '<item>';
- echo '<title>' . htmlspecialchars($product['title']) . '</title>';
- echo '<link>' . htmlspecialchars($url) . '</link>';
- echo '<guid>' . htmlspecialchars($url) . '</guid>';
- echo '<description>' . htmlspecialchars($product['excerpt']) . '</description>';
- echo '<pubDate>' . htmlspecialchars(date(DATE_RSS, strtotime($product['published_at']))) . '</pubDate>';
- echo '</item>' . "\n";
- }
-
- echo '</channel></rss>';
-