diff options
| author | 2024-12-03 14:06:14 +0100 | |
|---|---|---|
| committer | 2024-12-03 14:06:14 +0100 | |
| commit | 594ef04df21c76e0771314e1203bd478232c73b9 (patch) | |
| tree | bee474c145772b12837e31763063d599255f42bc | |
| parent | 7b1563696e0996499d4e6129d49f43b077051ee5 (diff) | |
Fallback to GUID if article link is empty (#7051)
* Fallback to GUID is entry link is empty
fix https://github.com/FreshRSS/FreshRSS/issues/7050
* FILTER_NULL_ON_FAILURE
| -rw-r--r-- | app/Models/Entry.php | 17 |
1 files changed, 14 insertions, 3 deletions
diff --git a/app/Models/Entry.php b/app/Models/Entry.php index 6030451f2..7c0d02ddb 100644 --- a/app/Models/Entry.php +++ b/app/Models/Entry.php @@ -376,10 +376,21 @@ HTML; return null; } - /** @return string HTML-encoded link of the entry */ - public function link(): string { + /** + * @param bool $raw Set to true to return the raw link, + * false (default) to attempt a fallback to the GUID if the link is empty. + * @return string HTML-encoded link of the entry + */ + public function link(bool $raw = false): string { + if ($this->link === '' && !$raw) { + // Use the GUID as a fallback if it looks like a URL + if (filter_var($this->guid, FILTER_VALIDATE_URL, FILTER_NULL_ON_FAILURE) !== null) { + return $this->guid; + } + } return $this->link; } + /** * @phpstan-return ($raw is false ? string : int) */ @@ -955,7 +966,7 @@ HTML; 'title' => $this->title(), 'author' => $this->authors(true), 'content' => $this->content(false), - 'link' => $this->link(), + 'link' => $this->link(raw: true), 'date' => $this->date(true), 'lastSeen' => $this->lastSeen(), 'hash' => $this->hash(), |
