rss.phtml 3.5 KB

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