WebOrbiton
v1.0.0.6

Publisium

49 lines · 2.0 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. $articles = $db->query(
  20. "SELECT a.id, a.title, a.slug, a.excerpt, a.published_at FROM articles a WHERE a.status = 'published'" . Languages::articleFilterSql('a') . " ORDER BY a.published_at DESC LIMIT 30"
  21. )->fetchAll();
  22. $articles = Languages::articles($articles);
  23. ​
  24. header('Content-Type: application/rss+xml; charset=utf-8');
  25. ​
  26. echo '<?xml version="1.0" encoding="UTF-8"?>' . "\n";
  27. echo '<rss version="2.0"><channel>' . "\n";
  28. echo '<title>' . htmlspecialchars($settings['site_name']) . '</title>' . "\n";
  29. $channelLanguage = Languages::current();
  30. $channelLink = $channelLanguage === '' ? rtrim((string) Config::get('APP_URL', ''), '/') . SiteFront::homeUrl('') : rtrim((string) Config::get('APP_URL', ''), '/') . Languages::homeUrl($channelLanguage);
  31. echo '<link>' . htmlspecialchars($channelLink) . '</link>' . "\n";
  32. if ($channelLanguage !== '') {
  33. echo '<language>' . htmlspecialchars($channelLanguage) . '</language>' . "\n";
  34. }
  35. echo '<description>' . htmlspecialchars($settings['site_description']) . '</description>' . "\n";
  36. ​
  37. foreach ($articles as $article) {
  38. $url = rtrim(Config::get('APP_URL', ''), '/') . SiteFront::articleUrl($article['slug']);
  39. echo '<item>';
  40. echo '<title>' . htmlspecialchars($article['title']) . '</title>';
  41. echo '<link>' . htmlspecialchars($url) . '</link>';
  42. echo '<guid>' . htmlspecialchars($url) . '</guid>';
  43. echo '<description>' . htmlspecialchars((string) ($article['excerpt'] ?? '')) . '</description>';
  44. echo '<pubDate>' . htmlspecialchars(date(DATE_RSS, strtotime($article['published_at']))) . '</pubDate>';
  45. echo '</item>' . "\n";
  46. }
  47. ​
  48. echo '</channel></rss>';
  49. ​