From 509c8cae6381ec46af7c8303eb92fda6ce496a4a Mon Sep 17 00:00:00 2001 From: Alexandre Alapetite Date: Mon, 4 Jul 2022 09:53:26 +0200 Subject: Dynamic OPML (#4407) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * Dynamic OPML draft #fix https://github.com/FreshRSS/FreshRSS/issues/4191 * Export dynamic OPML http://opml.org/spec2.opml#1629043127000 * Restart with simpler approach * Minor revert * Export dynamic OPML also for single feeds * Special category type for importing dynamic OPML * Parameter for excludeMutedFeeds * Details * More draft * i18n * Fix update * Draft manual import working * Working manual refresh * Draft automatic update * Working Web refresh + fixes * Import/export dynamic OPML settings * Annoying numerous lines in SQL logs * Fix minor JavaScript error * Fix auto adding new columns * Add require * Add missing 🗲 * Missing space * Disable adding new feeds to dynamic categories * Link from import * i18n typo * Improve theme icon function * Fix pink-dark --- app/views/helpers/export/opml.phtml | 55 +++++++++++++++++++++++++------------ 1 file changed, 38 insertions(+), 17 deletions(-) (limited to 'app/views/helpers/export') diff --git a/app/views/helpers/export/opml.phtml b/app/views/helpers/export/opml.phtml index 64c02c302..f99754138 100644 --- a/app/views/helpers/export/opml.phtml +++ b/app/views/helpers/export/opml.phtml @@ -1,21 +1,14 @@ array( - 'title' => FreshRSS_Context::$system_conf->title, - 'dateCreated' => date('D, d M Y H:i:s') - ), - 'body' => array() -); - -foreach ($this->categories as $key => $cat) { - $opml_array['body'][$key] = array( - 'text' => htmlspecialchars_decode($cat->name(), ENT_QUOTES), - '@outlines' => array() - ); - - foreach ($cat->feeds() as $feed) { +/** + * @param array $feeds + */ +function feedsToOutlines($feeds, $excludeMutedFeeds = false): array { + $outlines = []; + foreach ($feeds as $feed) { + if ($feed->mute() && $excludeMutedFeeds) { + continue; + } $outline = [ 'text' => htmlspecialchars_decode($feed->name(), ENT_QUOTES), 'type' => FreshRSS_Export_Service::TYPE_RSS_ATOM, @@ -47,8 +40,36 @@ foreach ($this->categories as $key => $cat) { if ($feed->pathEntries() != '') { $outline['frss:cssFullContent'] = ['namespace' => FreshRSS_Export_Service::FRSS_NAMESPACE, 'value' => $feed->pathEntries()]; } - $opml_array['body'][$key]['@outlines'][] = $outline; + $outlines[] = $outline; } + return $outlines; +} + +/** @var FreshRSS_View $this */ + +$opml_array = array( + 'head' => array( + 'title' => FreshRSS_Context::$system_conf->title, + 'dateCreated' => date('D, d M Y H:i:s') + ), + 'body' => array() +); + +if (!empty($this->categories)) { + foreach ($this->categories as $key => $cat) { + $outline = [ + 'text' => htmlspecialchars_decode($cat->name(), ENT_QUOTES), + '@outlines' => feedsToOutlines($cat->feeds(), $this->excludeMutedFeeds), + ]; + if ($cat->kind() === FreshRSS_Category::KIND_DYNAMIC_OPML) { + $outline['frss:opmlUrl'] = ['namespace' => FreshRSS_Export_Service::FRSS_NAMESPACE, 'value' => $cat->attributes('opml_url')];; + } + $opml_array['body'][$key] = $outline; + } +} + +if (!empty($this->feeds)) { + $opml_array['body'][] = feedsToOutlines($this->feeds, $this->excludeMutedFeeds); } echo libopml_render($opml_array); -- cgit v1.2.3