aboutsummaryrefslogtreecommitdiff
path: root/app/Models/Feed.php
diff options
context:
space:
mode:
authorGravatar Alexandre Alapetite <alexandre@alapetite.fr> 2025-03-24 14:08:43 +0100
committerGravatar GitHub <noreply@github.com> 2025-03-24 14:08:43 +0100
commit9114b9a06a6ff668827c4b0fb68fb549d2c50470 (patch)
tree9dd5d20412e325b15fcc4bcb7fe5af442b94a598 /app/Models/Feed.php
parentb0a3ae1e7af2a1485439439463ceed3dc2057f65 (diff)
Support multiple JSON fragments in HTML+XPath+JSON mode (#7369)
* Support multiple JSON fragments in HTML+XPath+JSON mode fix https://github.com/FreshRSS/FreshRSS/discussions/7352#discussioncomment-12295475 E.g. HTML with one `<script type="application/ld+json">...</script>` per item. * Better help messages
Diffstat (limited to 'app/Models/Feed.php')
-rw-r--r--app/Models/Feed.php21
1 files changed, 19 insertions, 2 deletions
diff --git a/app/Models/Feed.php b/app/Models/Feed.php
index 57bf9d7a4..072948e1b 100644
--- a/app/Models/Feed.php
+++ b/app/Models/Feed.php
@@ -725,8 +725,25 @@ class FreshRSS_Feed extends Minz_Model {
}
$xpath = new DOMXPath($doc);
- $json = @$xpath->evaluate('normalize-space(' . $xPathToJson . ')');
- return is_string($json) ? $json : null;
+ $jsonFragments = @$xpath->evaluate($xPathToJson);
+ if ($jsonFragments === false) {
+ return null;
+ }
+ if (is_string($jsonFragments)) {
+ return $jsonFragments;
+ }
+ if ($jsonFragments instanceof DOMNodeList && $jsonFragments->length > 0) {
+ // If the result is a list, then aggregate as a JSON array
+ $result = [];
+ foreach ($jsonFragments as $node) {
+ $json = json_decode($node->textContent, true);
+ if (json_last_error() === JSON_ERROR_NONE && is_array($json)) {
+ $result[] = $json;
+ }
+ }
+ return json_encode($result, JSON_UNESCAPED_SLASHES | JSON_UNESCAPED_UNICODE) ?: null;
+ }
+ return null;
}
public function loadJson(): ?\SimplePie\SimplePie {