opml.phtml 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100
  1. <?php
  2. /**
  3. * @param array<FreshRSS_Feed> $feeds
  4. */
  5. function feedsToOutlines($feeds, $excludeMutedFeeds = false): array {
  6. $outlines = [];
  7. foreach ($feeds as $feed) {
  8. if ($feed->mute() && $excludeMutedFeeds) {
  9. continue;
  10. }
  11. $outline = [
  12. 'text' => htmlspecialchars_decode($feed->name(), ENT_QUOTES),
  13. 'type' => FreshRSS_Export_Service::TYPE_RSS_ATOM,
  14. 'xmlUrl' => htmlspecialchars_decode($feed->url(), ENT_QUOTES),
  15. 'htmlUrl' => htmlspecialchars_decode($feed->website(), ENT_QUOTES),
  16. 'description' => htmlspecialchars_decode($feed->description(), ENT_QUOTES),
  17. ];
  18. if ($feed->kind() === FreshRSS_Feed::KIND_HTML_XPATH || $feed->kind() === FreshRSS_Feed::KIND_XML_XPATH) {
  19. switch ($feed->kind()) {
  20. case FreshRSS_Feed::KIND_HTML_XPATH:
  21. $outline['type'] = FreshRSS_Export_Service::TYPE_HTML_XPATH;
  22. break;
  23. case FreshRSS_Feed::KIND_XML_XPATH:
  24. $outline['type'] = FreshRSS_Export_Service::TYPE_XML_XPATH;
  25. break;
  26. }
  27. /** @var array<string,string> */
  28. $xPathSettings = $feed->attributes('xpath');
  29. $outline['frss:xPathItem'] = $xPathSettings['item'] ?? null;
  30. $outline['frss:xPathItemTitle'] = $xPathSettings['itemTitle'] ?? null;
  31. $outline['frss:xPathItemContent'] = $xPathSettings['itemContent'] ?? null;
  32. $outline['frss:xPathItemUri'] = $xPathSettings['itemUri'] ?? null;
  33. $outline['frss:xPathItemAuthor'] = $xPathSettings['itemAuthor'] ?? null;
  34. $outline['frss:xPathItemTimestamp'] = $xPathSettings['itemTimestamp'] ?? null;
  35. $outline['frss:xPathItemTimeformat'] = $xPathSettings['itemTimeformat'] ?? null;
  36. $outline['frss:xPathItemThumbnail'] = $xPathSettings['itemThumbnail'] ?? null;
  37. $outline['frss:xPathItemCategories'] = $xPathSettings['itemCategories'] ?? null;
  38. $outline['frss:xPathItemUid'] = $xPathSettings['itemUid'] ?? null;
  39. }
  40. if (!empty($feed->filtersAction('read'))) {
  41. $filters = '';
  42. foreach ($feed->filtersAction('read') as $filterRead) {
  43. $filters .= $filterRead->getRawInput() . "\n";
  44. }
  45. $filters = trim($filters);
  46. $outline['frss:filtersActionRead'] = $filters;
  47. }
  48. if ($feed->pathEntries() != '') {
  49. $outline['frss:cssFullContent'] = htmlspecialchars_decode($feed->pathEntries(), ENT_QUOTES);
  50. }
  51. if ($feed->attributes('path_entries_filter') != '') {
  52. $outline['frss:cssFullContentFilter'] = $feed->attributes('path_entries_filter');
  53. }
  54. $outlines[] = $outline;
  55. }
  56. return $outlines;
  57. }
  58. /** @var FreshRSS_View $this */
  59. $opml_array = [
  60. 'namespaces' => [
  61. 'frss' => FreshRSS_Export_Service::FRSS_NAMESPACE,
  62. ],
  63. 'head' => [
  64. 'title' => FreshRSS_Context::$system_conf->title,
  65. 'dateCreated' => new DateTime(),
  66. ],
  67. 'body' => [],
  68. ];
  69. if (!empty($this->categories)) {
  70. foreach ($this->categories as $key => $cat) {
  71. $outline = [
  72. 'text' => htmlspecialchars_decode($cat->name(), ENT_QUOTES),
  73. '@outlines' => feedsToOutlines($cat->feeds(), $this->excludeMutedFeeds),
  74. ];
  75. if ($cat->kind() === FreshRSS_Category::KIND_DYNAMIC_OPML) {
  76. $outline['frss:opmlUrl'] = $cat->attributes('opml_url');
  77. }
  78. $opml_array['body'][$key] = $outline;
  79. }
  80. }
  81. if (!empty($this->feeds)) {
  82. $opml_array['body'][] = feedsToOutlines($this->feeds, $this->excludeMutedFeeds);
  83. }
  84. $libopml = new \marienfressinaud\LibOpml\LibOpml(true);
  85. echo $libopml->render($opml_array);