rss.phtml 3.7 KB

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