opml.phtml 3.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  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'] = ['namespace' => FreshRSS_Export_Service::FRSS_NAMESPACE, 'value' => $xPathSettings['item'] ?? null];
  23. $outline['frss:xPathItemTitle'] = ['namespace' => FreshRSS_Export_Service::FRSS_NAMESPACE, 'value' => $xPathSettings['itemTitle'] ?? null];
  24. $outline['frss:xPathItemContent'] = ['namespace' => FreshRSS_Export_Service::FRSS_NAMESPACE, 'value' => $xPathSettings['itemContent'] ?? null];
  25. $outline['frss:xPathItemUri'] = ['namespace' => FreshRSS_Export_Service::FRSS_NAMESPACE, 'value' => $xPathSettings['itemUri'] ?? null];
  26. $outline['frss:xPathItemAuthor'] = ['namespace' => FreshRSS_Export_Service::FRSS_NAMESPACE, 'value' => $xPathSettings['itemAuthor'] ?? null];
  27. $outline['frss:xPathItemTimestamp'] = ['namespace' => FreshRSS_Export_Service::FRSS_NAMESPACE, 'value' => $xPathSettings['itemTimestamp'] ?? null];
  28. $outline['frss:xPathItemTimeformat'] = ['namespace' => FreshRSS_Export_Service::FRSS_NAMESPACE, 'value' => $xPathSettings['itemTimeformat'] ?? null];
  29. $outline['frss:xPathItemThumbnail'] = ['namespace' => FreshRSS_Export_Service::FRSS_NAMESPACE, 'value' => $xPathSettings['itemThumbnail'] ?? null];
  30. $outline['frss:xPathItemCategories'] = ['namespace' => FreshRSS_Export_Service::FRSS_NAMESPACE, 'value' => $xPathSettings['itemCategories'] ?? null];
  31. $outline['frss:xPathItemUid'] = ['namespace' => FreshRSS_Export_Service::FRSS_NAMESPACE, 'value' => $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'] = ['namespace' => FreshRSS_Export_Service::FRSS_NAMESPACE, 'value' => $filters];
  40. }
  41. if ($feed->pathEntries() != '') {
  42. $outline['frss:cssFullContent'] = ['namespace' => FreshRSS_Export_Service::FRSS_NAMESPACE, 'value' => $feed->pathEntries()];
  43. }
  44. if ($feed->attributes('path_entries_filter') != '') {
  45. $outline['frss:cssFullContentFilter'] = ['namespace' => FreshRSS_Export_Service::FRSS_NAMESPACE, 'value' => $feed->attributes('path_entries_filter')];
  46. }
  47. $outlines[] = $outline;
  48. }
  49. return $outlines;
  50. }
  51. /** @var FreshRSS_View $this */
  52. $opml_array = array(
  53. 'head' => array(
  54. 'title' => FreshRSS_Context::$system_conf->title,
  55. 'dateCreated' => date('D, d M Y H:i:s')
  56. ),
  57. 'body' => array()
  58. );
  59. if (!empty($this->categories)) {
  60. foreach ($this->categories as $key => $cat) {
  61. $outline = [
  62. 'text' => htmlspecialchars_decode($cat->name(), ENT_QUOTES),
  63. '@outlines' => feedsToOutlines($cat->feeds(), $this->excludeMutedFeeds),
  64. ];
  65. if ($cat->kind() === FreshRSS_Category::KIND_DYNAMIC_OPML) {
  66. $outline['frss:opmlUrl'] = ['namespace' => FreshRSS_Export_Service::FRSS_NAMESPACE, 'value' => $cat->attributes('opml_url')];;
  67. }
  68. $opml_array['body'][$key] = $outline;
  69. }
  70. }
  71. if (!empty($this->feeds)) {
  72. $opml_array['body'][] = feedsToOutlines($this->feeds, $this->excludeMutedFeeds);
  73. }
  74. echo libopml_render($opml_array);