rss.phtml 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111
  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. <channel>
  9. <title><?= $this->rss_title ?></title>
  10. <link><?= $this->html_url ?></link>
  11. <description><?= $this->description ?: _t('index.feed.rss_of', $this->rss_title) ?></description>
  12. <pubDate><?= date('D, d M Y H:i:s O') ?></pubDate>
  13. <lastBuildDate><?= gmdate('D, d M Y H:i:s') ?> GMT</lastBuildDate>
  14. <atom:link href="<?= $this->rss_url ?>" rel="self" type="application/rss+xml" />
  15. <?php if ($this->image_url !== ''): ?>
  16. <image>
  17. <url><?= $this->image_url ?></url>
  18. <title><?= $this->rss_title ?></title>
  19. <link><?= $this->html_url ?></link>
  20. </image>
  21. <?php endif; ?>
  22. <?php
  23. foreach ($this->entries as $item) {
  24. if (!$this->internal_rendering) {
  25. /** @var FreshRSS_Entry|null $item */
  26. $item = Minz_ExtensionManager::callHook(Minz_HookType::EntryBeforeDisplay, $item);
  27. if ($item === null) {
  28. continue;
  29. }
  30. }
  31. ?>
  32. <item>
  33. <title><?= $item->title() ?></title>
  34. <link><?= $item->link() ?></link>
  35. <?php
  36. $authors = $item->authors();
  37. if (is_array($authors)) {
  38. foreach ($authors as $author) {
  39. echo "\t\t\t", '<dc:creator>', $author, '</dc:creator>', "\n";
  40. }
  41. }
  42. if ($this->publishLabelsInsteadOfTags) {
  43. $categories = $this->entryIdsTagNames['e_' . $item->id()] ?? [];
  44. if (is_array($categories)) {
  45. foreach ($categories as $category) {
  46. echo "\t\t\t", '<category>', $category, '</category>', "\n";
  47. }
  48. }
  49. } else {
  50. $categories = $item->tags();
  51. if (is_array($categories)) {
  52. foreach ($categories as $category) {
  53. echo "\t\t\t", '<category>', $category, '</category>', "\n";
  54. }
  55. }
  56. }
  57. $enclosures = iterator_to_array($item->enclosures(false), preserve_keys: false); // TODO: Optimise: avoid iterator_to_array if possible
  58. $thumbnail = $item->thumbnail(false);
  59. if (!empty($thumbnail['url'])) {
  60. // https://www.rssboard.org/media-rss#media-thumbnails
  61. echo "\t\t\t", '<media:thumbnail url="' . $thumbnail['url']
  62. . (empty($thumbnail['width']) ? '' : '" width="' . $thumbnail['width'])
  63. . (empty($thumbnail['height']) ? '' : '" height="' . $thumbnail['height'])
  64. . (empty($thumbnail['time']) ? '' : '" time="' . $thumbnail['time'])
  65. . '" />', "\n";
  66. // Mostly for MailChimp + Feedbro which do not support <media:thumbnail> https://mailchimp.com/help/rss-merge-tags/
  67. $thumbnail['medium'] ??= 'image';
  68. array_unshift($enclosures, $thumbnail);
  69. }
  70. $urls = [];
  71. foreach ($enclosures as $enclosure) {
  72. if (empty($enclosure['url']) || isset($urls[$enclosure['url']])) {
  73. continue;
  74. }
  75. $urls[$enclosure['url']] = true;
  76. $credits = $enclosure['credit'] ?? [];
  77. if (!is_array($credits)) { // For entries < FreshRSS 1.24
  78. $credits = [$credits];
  79. }
  80. $mediaCredits = '';
  81. foreach ($credits as $credit) {
  82. $mediaCredits = '<media:credit>' . $credit . '</media:credit>';
  83. }
  84. // https://www.rssboard.org/media-rss
  85. echo "\t\t\t", '<media:content url="' . $enclosure['url']
  86. . (empty($enclosure['medium']) ? '' : '" medium="' . $enclosure['medium'])
  87. . (empty($enclosure['type']) ? '' : '" type="' . $enclosure['type'])
  88. . (empty($enclosure['length']) ? '' : '" length="' . $enclosure['length'])
  89. . (empty($enclosure['height']) ? '' : '" height="' . $enclosure['height'])
  90. . (empty($enclosure['width']) ? '' : '" width="' . $enclosure['width'])
  91. . '">'
  92. . (empty($enclosure['title']) ? '' : '<media:title type="html">' . $enclosure['title'] . '</media:title>')
  93. . $mediaCredits
  94. . '</media:content>', "\n";
  95. }
  96. ?>
  97. <description><![CDATA[<?php
  98. echo $item->content(false);
  99. ?>]]></description>
  100. <pubDate><?= date('D, d M Y H:i:s O', $item->date(true)) ?></pubDate>
  101. <guid isPermaLink="false"><?= $item->id() > 0 ? $item->id() : $item->guid() ?></guid>
  102. </item>
  103. <?php } ?>
  104. </channel>
  105. </rss>