Bläddra i källkod

OPML export/import of unicity criteria (#8243)

Found during https://github.com/FreshRSS/FreshRSS/discussions/8242#discussioncomment-15052838
Alexandre Alapetite 4 månader sedan
förälder
incheckning
06d34f9b8e
3 ändrade filer med 19 tillägg och 0 borttagningar
  1. 9 0
      app/Services/ImportService.php
  2. 8 0
      app/views/helpers/export/opml.phtml
  3. 2 0
      docs/en/developers/OPML.md

+ 9 - 0
app/Services/ImportService.php

@@ -186,6 +186,15 @@ class FreshRSS_Import_Service {
 				default => FreshRSS_Feed::PRIORITY_MAIN_STREAM,
 			});
 
+			if (isset($feed_elt['frss:unicityCriteria']) && $feed_elt['frss:unicityCriteria'] !== 'id'
+				&& preg_match('/^[a-z:_-]{2,64}$/', $feed_elt['frss:unicityCriteria'])) {
+				$feed->_attribute('unicityCriteria', $feed_elt['frss:unicityCriteria']);
+			}
+
+			if (filter_var($feed_elt['frss:unicityCriteriaForced'] ?? '', FILTER_VALIDATE_BOOLEAN)) {
+				$feed->_attribute('unicityCriteriaForced', true);
+			}
+
 			if (isset($feed_elt['frss:cssFullContent'])) {
 				$feed->_pathEntries(Minz_Helper::htmlspecialchars_utf8($feed_elt['frss:cssFullContent']));
 			}

+ 8 - 0
app/views/helpers/export/opml.phtml

@@ -47,6 +47,14 @@ function feedsToOutlines(array $feeds, bool $excludeMutedFeeds = false): array {
 			default => null,
 		};
 
+		if ($feed->attributeString('unicityCriteria') != '' && $feed->attributeString('unicityCriteria') !== 'id') {
+			$outline['frss:unicityCriteria'] = $feed->attributeString('unicityCriteria');
+		}
+
+		if ($feed->attributeBoolean('unicityCriteriaForced')) {
+			$outline['frss:unicityCriteriaForced'] = 'true';
+		}
+
 		if ($feed->kind() === FreshRSS_Feed::KIND_HTML_XPATH || $feed->kind() === FreshRSS_Feed::KIND_XML_XPATH) {
 			/** @var array<string,string> */
 			$xPathSettings = $feed->attributeArray('xpath') ?? [];

+ 2 - 0
docs/en/developers/OPML.md

@@ -90,6 +90,8 @@ A number of [cURL options](https://curl.se/libcurl/c/curl_easy_setopt.html) are
 ### Miscellaneous
 
 * `frss:priority`: Used for priority / visibility of the articles of that feed. Can be: `important`, `main` (default), `category`, `feed`, `hidden`.
+* `frss:unicityCriteria`: Criteria used for the unicity of articles. E.g. `id` (default), `link`, `sha1:link_published`, `sha1:link_published_title`, `sha1:title`, [etc](https://github.com/FreshRSS/FreshRSS/blob/1c92d55917029d291d00009b674d8552934a69ec/app/Models/Feed.php#L652-L666).
+* `frss:unicityCriteriaForced`: Boolean to force the usage of the selected unicity criterion even in the case of many duplicates (otherwise, the default behaviour is to fall back to a more precise unicity criteria).
 * `frss:cssFullContent`: [CSS Selector](https://developer.mozilla.org/en-US/docs/Web/CSS/CSS_Selectors) to enable the download and extraction of the matching HTML section of each articles’ Web address.
 	* Example: `div.main, .summary`
 * `frss:cssContentFilter`: [CSS Selector](https://developer.mozilla.org/en-US/docs/Web/CSS/CSS_Selectors) to remove the matching HTML elements from the article content or from the full content retrieved by `frss:cssFullContent`.