opml.phtml 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  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) {
  19. $outline['type'] = FreshRSS_Export_Service::TYPE_HTML_XPATH;
  20. /** @var array<string,string> */
  21. $xPathSettings = $feed->attributes('xpath');
  22. $outline['frss:xPathItem'] = $xPathSettings['item'] ?? null;
  23. $outline['frss:xPathItemTitle'] = $xPathSettings['itemTitle'] ?? null;
  24. $outline['frss:xPathItemContent'] = $xPathSettings['itemContent'] ?? null;
  25. $outline['frss:xPathItemUri'] = $xPathSettings['itemUri'] ?? null;
  26. $outline['frss:xPathItemAuthor'] = $xPathSettings['itemAuthor'] ?? null;
  27. $outline['frss:xPathItemTimestamp'] = $xPathSettings['itemTimestamp'] ?? null;
  28. $outline['frss:xPathItemTimeformat'] = $xPathSettings['itemTimeformat'] ?? null;
  29. $outline['frss:xPathItemThumbnail'] = $xPathSettings['itemThumbnail'] ?? null;
  30. $outline['frss:xPathItemCategories'] = $xPathSettings['itemCategories'] ?? null;
  31. $outline['frss:xPathItemUid'] = $xPathSettings['itemUid'] ?? null;
  32. }
  33. if (!empty($feed->filtersAction('read'))) {
  34. $filters = '';
  35. foreach ($feed->filtersAction('read') as $filterRead) {
  36. $filters .= $filterRead->getRawInput() . "\n";
  37. }
  38. $filters = trim($filters);
  39. $outline['frss:filtersActionRead'] = $filters;
  40. }
  41. if ($feed->pathEntries() != '') {
  42. $outline['frss:cssFullContent'] = htmlspecialchars_decode($feed->pathEntries(), ENT_QUOTES);
  43. }
  44. if ($feed->attributes('path_entries_filter') != '') {
  45. $outline['frss:cssFullContentFilter'] = $feed->attributes('path_entries_filter');
  46. }
  47. $outlines[] = $outline;
  48. }
  49. return $outlines;
  50. }
  51. /** @var FreshRSS_View $this */
  52. $opml_array = [
  53. 'namespaces' => [
  54. 'frss' => FreshRSS_Export_Service::FRSS_NAMESPACE,
  55. ],
  56. 'head' => [
  57. 'title' => FreshRSS_Context::$system_conf->title,
  58. 'dateCreated' => new DateTime(),
  59. ],
  60. 'body' => [],
  61. ];
  62. if (!empty($this->categories)) {
  63. foreach ($this->categories as $key => $cat) {
  64. $outline = [
  65. 'text' => htmlspecialchars_decode($cat->name(), ENT_QUOTES),
  66. '@outlines' => feedsToOutlines($cat->feeds(), $this->excludeMutedFeeds),
  67. ];
  68. if ($cat->kind() === FreshRSS_Category::KIND_DYNAMIC_OPML) {
  69. $outline['frss:opmlUrl'] = $cat->attributes('opml_url');
  70. }
  71. $opml_array['body'][$key] = $outline;
  72. }
  73. }
  74. if (!empty($this->feeds)) {
  75. $opml_array['body'][] = feedsToOutlines($this->feeds, $this->excludeMutedFeeds);
  76. }
  77. $libopml = new \marienfressinaud\LibOpml\LibOpml(true);
  78. echo $libopml->render($opml_array);