rss.phtml 3.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  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. // https://www.rssboard.org/media-rss
  62. echo "\t\t\t", '<media:content url="' . $enclosure['url']
  63. . (empty($enclosure['medium']) ? '' : '" medium="' . $enclosure['medium'])
  64. . (empty($enclosure['type']) ? '' : '" type="' . $enclosure['type'])
  65. . (empty($enclosure['length']) ? '' : '" length="' . $enclosure['length'])
  66. . (empty($enclosure['height']) ? '' : '" height="' . $enclosure['height'])
  67. . (empty($enclosure['width']) ? '' : '" width="' . $enclosure['width'])
  68. . '">'
  69. . (empty($enclosure['title']) ? '' : '<media:title type="html">' . $enclosure['title'] . '</media:title>')
  70. . (empty($enclosure['credit']) ? '' : '<media:credit>' . $enclosure['credit'] . '</media:credit>')
  71. . '</media:content>', "\n";
  72. }
  73. ?>
  74. <description><![CDATA[<?php
  75. echo $item->content(false);
  76. ?>]]></description>
  77. <pubDate><?= date('D, d M Y H:i:s O', $item->date(true)) ?></pubDate>
  78. <guid isPermaLink="false"><?= $item->id() > 0 ? $item->id() : $item->guid() ?></guid>
  79. </item>
  80. <?php } ?>
  81. </channel>
  82. </rss>