aboutsummaryrefslogtreecommitdiff
path: root/app/Models/Entry.php
diff options
context:
space:
mode:
authorGravatar Alexandre Alapetite <alexandre@alapetite.fr> 2024-09-09 10:38:45 +0200
committerGravatar GitHub <noreply@github.com> 2024-09-09 10:38:45 +0200
commitfeffa5598c4c18433d3a8a61e52d94f57ce2f066 (patch)
tree1fc7b023102b361d6dd0c213865a40cd543cf7a0 /app/Models/Entry.php
parentaf0498fe679fe00f4b0ea07bb55c15e6deca8840 (diff)
Apply CSS selector filter also when not using full content (#6786)
Before, removing content from articles was only possible when fetching full article contents. With this PR, the same cleaning can be applied to the normal content provided by RSS feeds.
Diffstat (limited to 'app/Models/Entry.php')
-rw-r--r--app/Models/Entry.php38
1 files changed, 33 insertions, 5 deletions
diff --git a/app/Models/Entry.php b/app/Models/Entry.php
index a4b8e1366..968e81499 100644
--- a/app/Models/Entry.php
+++ b/app/Models/Entry.php
@@ -856,7 +856,7 @@ HTML;
if ($path_entries_filter !== '') {
$filterednodes = $xpath->query((new Gt\CssXPath\Translator($path_entries_filter))->asXPath(), $node) ?: [];
foreach ($filterednodes as $filterednode) {
- if ($filterednode->parentNode === null) {
+ if (!($filterednode instanceof DOMElement) || $filterednode->parentNode === null) {
continue;
}
$filterednode->parentNode->removeChild($filterednode);
@@ -872,15 +872,20 @@ HTML;
}
}
+ /**
+ * @return bool True if the content was modified, false otherwise
+ */
public function loadCompleteContent(bool $force = false): bool {
// Gestion du contenu
// Trying to fetch full article content even when feeds do not propose it
$feed = $this->feed();
- if ($feed != null && trim($feed->pathEntries()) != '') {
+ if ($feed === null) {
+ return false;
+ }
+ if (trim($feed->pathEntries()) != '') {
$entryDAO = FreshRSS_Factory::createEntryDao();
$entry = $force ? null : $entryDAO->searchByGuid($this->feedId, $this->guid);
-
- if ($entry) {
+ if ($entry !== null) {
// l’article existe déjà en BDD, en se contente de recharger ce contenu
$this->content = $entry->content(false);
} else {
@@ -902,7 +907,6 @@ HTML;
$this->content = $fullContent;
break;
}
-
return true;
}
} catch (Exception $e) {
@@ -910,6 +914,30 @@ HTML;
Minz_Log::warning($e->getMessage());
}
}
+ } elseif (trim($feed->attributeString('path_entries_filter') ?? '') !== '') {
+ $doc = new DOMDocument();
+ $utf8BOM = "\xEF\xBB\xBF";
+ if (!$doc->loadHTML($utf8BOM . $this->content, LIBXML_NONET | LIBXML_NOERROR | LIBXML_NOWARNING)) {
+ return false;
+ }
+ $modified = false;
+ $xpath = new DOMXPath($doc);
+ $filterednodes = $xpath->query((new Gt\CssXPath\Translator($feed->attributeString('path_entries_filter') ?? '', '//'))->asXPath()) ?: [];
+ foreach ($filterednodes as $filterednode) {
+ if (!($filterednode instanceof DOMElement) || $filterednode->parentNode === null) {
+ continue;
+ }
+ $filterednode->parentNode->removeChild($filterednode);
+ $modified = true;
+ }
+ if ($modified) {
+ $html = $doc->saveHTML();
+ if (!is_string($html)) {
+ return false;
+ }
+ $this->content = $html;
+ }
+ return $modified;
}
return false;
}