From ccb132523a4ee740d5b576574e9f44668021fbe6 Mon Sep 17 00:00:00 2001 From: Alexandre Alapetite Date: Sun, 13 Oct 2024 15:28:45 +0200 Subject: New feed mode: HTML + XPath + JSON dot notation (JSON in HTML) (#6888) * New feed mode: HTML + XPath + JSON dot notation (JSON in HTML) Same as `JSON+DotNotation` but first extracting the JSON string from an HTML document thanks to an XPath expression. Example: `//script[@type='application/json']` fix https://github.com/FreshRSS/FreshRSS/discussions/6876 * JavaScript UI to show/hide new field * Casing xPathToJson * Slight renaming --- app/Controllers/feedController.php | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) (limited to 'app/Controllers/feedController.php') diff --git a/app/Controllers/feedController.php b/app/Controllers/feedController.php index 105099966..2b757177c 100755 --- a/app/Controllers/feedController.php +++ b/app/Controllers/feedController.php @@ -260,7 +260,7 @@ class FreshRSS_feed_Controller extends FreshRSS_ActionController { if (!empty($xPathSettings)) { $attributes['xpath'] = $xPathSettings; } - } elseif ($feed_kind === FreshRSS_Feed::KIND_JSON_DOTNOTATION) { + } elseif ($feed_kind === FreshRSS_Feed::KIND_JSON_DOTNOTATION || $feed_kind === FreshRSS_Feed::KIND_HTML_XPATH_JSON_DOTNOTATION) { $jsonSettings = []; if (Minz_Request::paramString('jsonFeedTitle') !== '') { $jsonSettings['feedTitle'] = Minz_Request::paramString('jsonFeedTitle', true); @@ -298,6 +298,9 @@ class FreshRSS_feed_Controller extends FreshRSS_ActionController { if (!empty($jsonSettings)) { $attributes['json_dotnotation'] = $jsonSettings; } + if (Minz_Request::paramString('xPathToJson', plaintext: true) !== '') { + $attributes['xPathToJson'] = Minz_Request::paramString('xPathToJson', plaintext: true); + } } try { @@ -509,6 +512,11 @@ class FreshRSS_feed_Controller extends FreshRSS_ActionController { if ($simplePie === null) { throw new FreshRSS_Feed_Exception('JSON Feed parsing failed for [' . $feed->url(false) . ']'); } + } elseif ($feed->kind() === FreshRSS_Feed::KIND_HTML_XPATH_JSON_DOTNOTATION) { + $simplePie = $feed->loadJson(); + if ($simplePie === null) { + throw new FreshRSS_Feed_Exception('HTML+XPath+JSON parsing failed for [' . $feed->url(false) . ']'); + } } else { $simplePie = $feed->load(false, $feedIsNew); } -- cgit v1.2.3