diff options
| author | 2023-08-13 15:11:22 +0200 | |
|---|---|---|
| committer | 2023-08-13 15:11:22 +0200 | |
| commit | d165ed1fb6096d5bd0558d3ed637e53bc728baa7 (patch) | |
| tree | 4b563dcd60d467d684e06524f3772de8160d54ff /app/Models/Entry.php | |
| parent | 54592fa1fdb80b4865c76b530135aaa0eac438c7 (diff) | |
Fix hash of articles with loadCompleteContent (#5576)
* Fix hash of articles with loadCompleteContent
The detection of modified articles was wrong for feeds using loadCompleteContent. Indeed, the hash is supposed to computed on the content provided by the server of the RSS feed, excluding further modifications.
Furthermore, read hash from database instead of recomputing it all the time.
Slightly related to https://github.com/FreshRSS/FreshRSS/pull/5574
* Explicit SQL alias
* PHPDocs
Diffstat (limited to 'app/Models/Entry.php')
| -rw-r--r-- | app/Models/Entry.php | 17 |
1 files changed, 13 insertions, 4 deletions
diff --git a/app/Models/Entry.php b/app/Models/Entry.php index 77f39f256..7da27e409 100644 --- a/app/Models/Entry.php +++ b/app/Models/Entry.php @@ -61,7 +61,7 @@ class FreshRSS_Entry extends Minz_Model { } /** @param array{'id'?:string,'id_feed'?:int,'guid'?:string,'title'?:string,'author'?:string,'content'?:string,'link'?:string,'date'?:int|string,'lastSeen'?:int, - * 'is_read'?:bool|int,'is_favorite'?:bool|int,'tags'?:string|array<string>,'attributes'?:string,'thumbnail'?:string,'timestamp'?:string} $dao */ + * 'hash'?:string,'is_read'?:bool|int,'is_favorite'?:bool|int,'tags'?:string|array<string>,'attributes'?:string,'thumbnail'?:string,'timestamp'?:string} $dao */ public static function fromArray(array $dao): FreshRSS_Entry { if (empty($dao['content'])) { $dao['content'] = ''; @@ -101,6 +101,9 @@ class FreshRSS_Entry extends Minz_Model { if (!empty($dao['attributes'])) { $entry->_attributes('', $dao['attributes']); } + if (!empty($dao['hash'])) { + $entry->_hash($dao['hash']); + } return $entry; } @@ -148,6 +151,13 @@ class FreshRSS_Entry extends Minz_Model { } /** + * Provides the original content without additional content potentially added by loadCompleteContent(). + */ + public function originalContent(): string { + return preg_replace('#<!-- FULLCONTENT start //-->.*<!-- FULLCONTENT end //-->#s', '', $this->content); + } + + /** * @param bool $withEnclosures Set to true to include the enclosures in the returned HTML, false otherwise. * @param bool $allowDuplicateEnclosures Set to false to remove obvious enclosure duplicates (based on simple string comparison), true otherwise. * @return string HTML content @@ -412,7 +422,7 @@ HTML; public function hash(): string { if ($this->hash == '') { //Do not include $this->date because it may be automatically generated when lacking - $this->hash = md5($this->link . $this->title . $this->authors(true) . $this->content . $this->tags(true)); + $this->hash = md5($this->link . $this->title . $this->authors(true) . $this->originalContent() . $this->tags(true)); } return $this->hash; } @@ -473,7 +483,6 @@ HTML; } /** @param int|string $value */ public function _date($value): void { - $this->hash = ''; $value = intval($value); $this->date = $value > 1 ? $value : time(); } @@ -770,7 +779,7 @@ HTML; ); if ('' !== $fullContent) { $fullContent = "<!-- FULLCONTENT start //-->{$fullContent}<!-- FULLCONTENT end //-->"; - $originalContent = preg_replace('#<!-- FULLCONTENT start //-->.*<!-- FULLCONTENT end //-->#s', '', $this->content()); + $originalContent = $this->originalContent(); switch ($feed->attributes('content_action')) { case 'prepend': $this->content = $fullContent . $originalContent; |
