opml.phtml 3.6 KB

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