opml.phtml 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  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:xPathItemThumbnail'] = ['namespace' => FreshRSS_Export_Service::FRSS_NAMESPACE, 'value' => $xPathSettings['itemThumbnail'] ?? null];
  29. $outline['frss:xPathItemCategories'] = ['namespace' => FreshRSS_Export_Service::FRSS_NAMESPACE, 'value' => $xPathSettings['itemCategories'] ?? null];
  30. }
  31. if (!empty($feed->filtersAction('read'))) {
  32. $filters = '';
  33. foreach ($feed->filtersAction('read') as $filterRead) {
  34. $filters .= $filterRead->getRawInput() . "\n";
  35. }
  36. $filters = trim($filters);
  37. $outline['frss:filtersActionRead'] = ['namespace' => FreshRSS_Export_Service::FRSS_NAMESPACE, 'value' => $filters];
  38. }
  39. if ($feed->pathEntries() != '') {
  40. $outline['frss:cssFullContent'] = ['namespace' => FreshRSS_Export_Service::FRSS_NAMESPACE, 'value' => $feed->pathEntries()];
  41. }
  42. $outlines[] = $outline;
  43. }
  44. return $outlines;
  45. }
  46. /** @var FreshRSS_View $this */
  47. $opml_array = array(
  48. 'head' => array(
  49. 'title' => FreshRSS_Context::$system_conf->title,
  50. 'dateCreated' => date('D, d M Y H:i:s')
  51. ),
  52. 'body' => array()
  53. );
  54. if (!empty($this->categories)) {
  55. foreach ($this->categories as $key => $cat) {
  56. $outline = [
  57. 'text' => htmlspecialchars_decode($cat->name(), ENT_QUOTES),
  58. '@outlines' => feedsToOutlines($cat->feeds(), $this->excludeMutedFeeds),
  59. ];
  60. if ($cat->kind() === FreshRSS_Category::KIND_DYNAMIC_OPML) {
  61. $outline['frss:opmlUrl'] = ['namespace' => FreshRSS_Export_Service::FRSS_NAMESPACE, 'value' => $cat->attributes('opml_url')];;
  62. }
  63. $opml_array['body'][$key] = $outline;
  64. }
  65. }
  66. if (!empty($this->feeds)) {
  67. $opml_array['body'][] = feedsToOutlines($this->feeds, $this->excludeMutedFeeds);
  68. }
  69. echo libopml_render($opml_array);