diff options
Diffstat (limited to 'app/Models/Entry.php')
| -rw-r--r-- | app/Models/Entry.php | 36 |
1 files changed, 33 insertions, 3 deletions
diff --git a/app/Models/Entry.php b/app/Models/Entry.php index 9057cecf8..66e554e22 100644 --- a/app/Models/Entry.php +++ b/app/Models/Entry.php @@ -59,13 +59,19 @@ class FreshRSS_Entry extends Minz_Model { public function content() { return $this->content; } - public function enclosures() { + + public function enclosures($searchBodyImages = false) { $results = []; try { - if (strpos($this->content, '<p class="enclosure-content') !== false) { + $searchEnclosures = strpos($this->content, '<p class="enclosure-content') !== false; + $searchBodyImages &= (stripos($this->content, '<img') !== false); + $xpath = null; + if ($searchEnclosures || $searchBodyImages) { $dom = new DOMDocument(); - $dom->loadHTML($this->content, LIBXML_NONET | LIBXML_NOERROR | LIBXML_NOWARNING); + $dom->loadHTML('<?xml version="1.0" encoding="UTF-8" ?>' . $this->content, LIBXML_NONET | LIBXML_NOERROR | LIBXML_NOWARNING); $xpath = new DOMXpath($dom); + } + if ($searchEnclosures) { $enclosures = $xpath->query('//div[@class="enclosure"]/p[@class="enclosure-content"]/*[@src]'); foreach ($enclosures as $enclosure) { $results[] = [ @@ -75,12 +81,36 @@ class FreshRSS_Entry extends Minz_Model { ]; } } + if ($searchBodyImages) { + $images = $xpath->query('//img'); + foreach ($images as $img) { + $src = $img->getAttribute('src'); + if ($src == null) { + $src = $img->getAttribute('data-src'); + } + if ($src != null) { + $results[] = [ + 'url' => $src, + 'alt' => $img->getAttribute('alt'), + ]; + } + } + } return $results; } catch (Exception $ex) { return $results; } } + public function thumbnail() { + foreach ($this->enclosures(true) as $enclosure) { + if (!empty($enclosure['url']) && empty($enclosure['type'])) { + return $enclosure; + } + } + return null; + } + public function link() { return $this->link; } |
