From 50ba6bbe07b0bb86eb07e3212ba2e22cb2878cf2 Mon Sep 17 00:00:00 2001 From: ORelio Date: Mon, 30 Aug 2021 10:58:06 +0200 Subject: UI: Add optional thumbnail and summary on feed items (#3805) * UI: Add optional thumbnail and summary on feed items Implements #561 * UI: Thumbnail: Own column, Custom size, Lazy load * UI: Thumbnail: Remove unnecessary CSS rule Remove rule already defined in base theme, no override needed * CSS lint + RTL * Improve thumbail and summary generation * Support img alt * Missing htmlspecialchars Co-authored-by: Alexandre Alapetite --- app/Models/ConfigurationSetter.php | 10 ++++++++++ app/Models/Entry.php | 36 +++++++++++++++++++++++++++++++++--- 2 files changed, 43 insertions(+), 3 deletions(-) (limited to 'app/Models') diff --git a/app/Models/ConfigurationSetter.php b/app/Models/ConfigurationSetter.php index 6fc056eb2..ee58ebe5b 100644 --- a/app/Models/ConfigurationSetter.php +++ b/app/Models/ConfigurationSetter.php @@ -254,6 +254,16 @@ class FreshRSS_ConfigurationSetter { private function _topline_read(&$data, $value) { $data['topline_read'] = $this->handleBool($value); } + private function _topline_thumbnail(&$data, $value) { + $value = strtolower($value); + if (!in_array($value, array('none', 'portrait', 'square', 'landscape'))) { + $value = 'none'; + } + $data['topline_thumbnail'] = $value; + } + private function _topline_summary(&$data, $value) { + $data['topline_summary'] = $this->handleBool($value); + } private function _topline_display_authors(&$data, $value) { $data['topline_display_authors'] = $this->handleBool($value); } 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, '

content, 'loadHTML($this->content, LIBXML_NONET | LIBXML_NOERROR | LIBXML_NOWARNING); + $dom->loadHTML('' . $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; } -- cgit v1.2.3