rss.phtml 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  1. <?php
  2. declare(strict_types=1);
  3. /** @var FreshRSS_View $this */
  4. ?>
  5. <?= '<?xml version="1.0" encoding="UTF-8" ?>'; ?>
  6. <rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:media="http://search.yahoo.com/mrss/"
  7. <?= $this->rss_base == '' ? '' : ' xml:base="' . $this->rss_base . '"' ?>
  8. >
  9. <channel>
  10. <title><?= $this->rss_title ?></title>
  11. <link><?= $this->internal_rendering ? htmlspecialchars($this->rss_url, ENT_NOQUOTES, 'UTF-8') : Minz_Url::display('', 'html', true) ?></link>
  12. <description><?= _t('index.feed.rss_of', $this->rss_title) ?></description>
  13. <pubDate><?= date('D, d M Y H:i:s O') ?></pubDate>
  14. <lastBuildDate><?= gmdate('D, d M Y H:i:s') ?> GMT</lastBuildDate>
  15. <atom:link href="<?= $this->internal_rendering ? htmlspecialchars($this->rss_url, ENT_COMPAT, 'UTF-8') :
  16. Minz_Url::display($this->rss_url, 'html', true) ?>" rel="self" type="application/rss+xml" />
  17. <?php
  18. /** @var FreshRSS_Entry */
  19. foreach ($this->entries as $item) {
  20. if (!$this->internal_rendering) {
  21. /** @var FreshRSS_Entry */
  22. $item = Minz_ExtensionManager::callHook('entry_before_display', $item);
  23. if ($item == null) {
  24. continue;
  25. }
  26. }
  27. ?>
  28. <item>
  29. <title><?= $item->title() ?></title>
  30. <link><?= $item->link() ?></link>
  31. <?php
  32. $authors = $item->authors();
  33. if (is_array($authors)) {
  34. foreach ($authors as $author) {
  35. echo "\t\t\t", '<dc:creator>', $author, '</dc:creator>', "\n";
  36. }
  37. }
  38. $categories = $item->tags();
  39. if (is_array($categories)) {
  40. foreach ($categories as $category) {
  41. echo "\t\t\t", '<category>', $category, '</category>', "\n";
  42. }
  43. }
  44. $enclosures = iterator_to_array($item->enclosures(false));
  45. $thumbnail = $item->thumbnail(false);
  46. if (!empty($thumbnail['url'])) {
  47. // https://www.rssboard.org/media-rss#media-thumbnails
  48. echo "\t\t\t", '<media:thumbnail url="' . $thumbnail['url']
  49. . (empty($thumbnail['width']) ? '' : '" width="' . $thumbnail['width'])
  50. . (empty($thumbnail['height']) ? '' : '" height="' . $thumbnail['height'])
  51. . (empty($thumbnail['time']) ? '' : '" time="' . $thumbnail['time'])
  52. . '" />', "\n";
  53. // Mostly for MailChimp + Feedbro which do not support <media:thumbnail> https://mailchimp.com/help/rss-merge-tags/
  54. $thumbnail['medium'] ??= 'image';
  55. array_unshift($enclosures, $thumbnail);
  56. }
  57. $urls = [];
  58. foreach ($enclosures as $enclosure) {
  59. if (empty($enclosure['url']) || isset($urls[$enclosure['url']])) {
  60. continue;
  61. }
  62. $urls[$enclosure['url']] = true;
  63. // https://www.rssboard.org/media-rss
  64. echo "\t\t\t", '<media:content url="' . $enclosure['url']
  65. . (empty($enclosure['medium']) ? '' : '" medium="' . $enclosure['medium'])
  66. . (empty($enclosure['type']) ? '' : '" type="' . $enclosure['type'])
  67. . (empty($enclosure['length']) ? '' : '" length="' . $enclosure['length'])
  68. . (empty($enclosure['height']) ? '' : '" height="' . $enclosure['height'])
  69. . (empty($enclosure['width']) ? '' : '" width="' . $enclosure['width'])
  70. . '">'
  71. . (empty($enclosure['title']) ? '' : '<media:title type="html">' . $enclosure['title'] . '</media:title>')
  72. . (empty($enclosure['credit']) ? '' : '<media:credit>' . $enclosure['credit'] . '</media:credit>')
  73. . '</media:content>', "\n";
  74. }
  75. ?>
  76. <description><![CDATA[<?php
  77. echo $item->content(false);
  78. ?>]]></description>
  79. <pubDate><?= date('D, d M Y H:i:s O', $item->date(true)) ?></pubDate>
  80. <guid isPermaLink="false"><?= $item->id() > 0 ? $item->id() : $item->guid() ?></guid>
  81. </item>
  82. <?php } ?>
  83. </channel>
  84. </rss>