rss.phtml 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101
  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('entry_before_display', $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. $categories = $item->tags();
  43. if (is_array($categories)) {
  44. foreach ($categories as $category) {
  45. echo "\t\t\t", '<category>', $category, '</category>', "\n";
  46. }
  47. }
  48. $enclosures = iterator_to_array($item->enclosures(false));
  49. $thumbnail = $item->thumbnail(false);
  50. if (!empty($thumbnail['url'])) {
  51. // https://www.rssboard.org/media-rss#media-thumbnails
  52. echo "\t\t\t", '<media:thumbnail url="' . $thumbnail['url']
  53. . (empty($thumbnail['width']) ? '' : '" width="' . $thumbnail['width'])
  54. . (empty($thumbnail['height']) ? '' : '" height="' . $thumbnail['height'])
  55. . (empty($thumbnail['time']) ? '' : '" time="' . $thumbnail['time'])
  56. . '" />', "\n";
  57. // Mostly for MailChimp + Feedbro which do not support <media:thumbnail> https://mailchimp.com/help/rss-merge-tags/
  58. $thumbnail['medium'] ??= 'image';
  59. array_unshift($enclosures, $thumbnail);
  60. }
  61. $urls = [];
  62. foreach ($enclosures as $enclosure) {
  63. if (empty($enclosure['url']) || isset($urls[$enclosure['url']])) {
  64. continue;
  65. }
  66. $urls[$enclosure['url']] = true;
  67. $credits = $enclosure['credit'] ?? [];
  68. if (!is_array($credits)) { // For entries < FreshRSS 1.24
  69. $credits = [$credits];
  70. }
  71. $mediaCredits = '';
  72. foreach ($credits as $credit) {
  73. $mediaCredits = '<media:credit>' . $credit . '</media:credit>';
  74. }
  75. // https://www.rssboard.org/media-rss
  76. echo "\t\t\t", '<media:content url="' . $enclosure['url']
  77. . (empty($enclosure['medium']) ? '' : '" medium="' . $enclosure['medium'])
  78. . (empty($enclosure['type']) ? '' : '" type="' . $enclosure['type'])
  79. . (empty($enclosure['length']) ? '' : '" length="' . $enclosure['length'])
  80. . (empty($enclosure['height']) ? '' : '" height="' . $enclosure['height'])
  81. . (empty($enclosure['width']) ? '' : '" width="' . $enclosure['width'])
  82. . '">'
  83. . (empty($enclosure['title']) ? '' : '<media:title type="html">' . $enclosure['title'] . '</media:title>')
  84. . $mediaCredits
  85. . '</media:content>', "\n";
  86. }
  87. ?>
  88. <description><![CDATA[<?php
  89. echo $item->content(false);
  90. ?>]]></description>
  91. <pubDate><?= date('D, d M Y H:i:s O', $item->date(true)) ?></pubDate>
  92. <guid isPermaLink="false"><?= $item->id() > 0 ? $item->id() : $item->guid() ?></guid>
  93. </item>
  94. <?php } ?>
  95. </channel>
  96. </rss>