Skip to content

Commit

Permalink
Fallback to GUID if article link is empty (FreshRSS#7051)
Browse files Browse the repository at this point in the history
* Fallback to GUID is entry link is empty
fix FreshRSS#7050

* FILTER_NULL_ON_FAILURE
  • Loading branch information
Alkarex authored Dec 3, 2024
1 parent 7b15636 commit 594ef04
Showing 1 changed file with 14 additions and 3 deletions.
17 changes: 14 additions & 3 deletions app/Models/Entry.php
Original file line number Diff line number Diff line change
Expand Up @@ -376,10 +376,21 @@ public function thumbnail(bool $searchEnclosures = true): ?array {
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)
*/
Expand Down Expand Up @@ -955,7 +966,7 @@ public function toArray(): array {
'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(),
Expand Down

0 comments on commit 594ef04

Please sign in to comment.