From c25782f98c2cf3cf370872a38dc74b12371b20d7 Mon Sep 17 00:00:00 2001 From: "J. King" Date: Wed, 4 Nov 2020 20:00:00 -0500 Subject: [PATCH] Partial icon handling skeleton --- lib/Database.php | 18 +++++++++++++++++- lib/Feed.php | 20 +++++++++++++++----- 2 files changed, 32 insertions(+), 6 deletions(-) diff --git a/lib/Database.php b/lib/Database.php index 0df46df7..734fbd4a 100644 --- a/lib/Database.php +++ b/lib/Database.php @@ -1226,7 +1226,7 @@ class Database { [$cHashUC, $tHashUC, $vHashUC] = $this->generateIn($hashesUC, "str"); [$cHashTC, $tHashTC, $vHashTC] = $this->generateIn($hashesTC, "str"); // perform the query - return $articles = $this->db->prepare( + return $this->db->prepare( "SELECT id, edited, guid, url_title_hash, url_content_hash, title_content_hash FROM arsse_articles WHERE feed = ? and (guid in($cId) or url_title_hash in($cHashUT) or url_content_hash in($cHashUC) or title_content_hash in($cHashTC))", 'int', $tId, @@ -1236,6 +1236,22 @@ class Database { )->run($feedID, $vId, $vHashUT, $vHashUC, $vHashTC); } + protected function iconList(string $user, bool $withData = true): Db\Result { + $data = $withData ? "data" : "null as data"; + $out = $this->db->prepare("SELECT id, url, type, $data, next_fetch from arsse_icons")->run()->getRow(); + if (!$out) {} + return $out; + } + + protected function iconGet($id, bool $withData = true, bool $byUrl = false): array { + $field = $byUrl ? "url" : "id"; + $type = $byUrl ? "str" : "int"; + $data = $withData ? "data" : "null as data"; + $out = $this->db->prepare("SELECT id, url, type, $data, next_fetch from arsse_icons where $field = ?", $type)->run($id)->getRow(); + if (!$out) {} + return $out; + } + /** Returns an associative array of result column names and their SQL computations for article queries * * This is used for whitelisting and defining both output column and order-by columns, as well as for resolution of some context options diff --git a/lib/Feed.php b/lib/Feed.php index e6a8ebcf..2dad3269 100644 --- a/lib/Feed.php +++ b/lib/Feed.php @@ -16,7 +16,9 @@ use PicoFeed\Scraper\Scraper; class Feed { public $data = null; - public $favicon; + public $iconUrl; + public $iconType; + public $iconData; public $resource; public $modified = false; public $lastModified; @@ -113,16 +115,24 @@ class Feed { $this->resource->getContent(), $this->resource->getEncoding() )->execute(); - // Grab the favicon for the feed; returns an empty string if it cannot find one. - // Some feeds might use a different domain (eg: feedburner), so the site url is - // used instead of the feed's url. - $this->favicon = (new Favicon)->find($feed->siteUrl); } catch (PicoFeedException $e) { throw new Feed\Exception($this->resource->getUrl(), $e); } catch (\GuzzleHttp\Exception\GuzzleException $e) { // @codeCoverageIgnore throw new Feed\Exception($this->resource->getUrl(), $e); // @codeCoverageIgnore } + // Grab the favicon for the feed, or null if no valid icon is found + // Some feeds might use a different domain (eg: feedburner), so the site url is + // used instead of the feed's url. + $icon = new Favicon; + $this->iconUrl = $icon->find($feed->siteUrl); + $this->iconData = $icon->getContent(); + if (strlen($this->iconData)) { + $this->iconType = $icon->getType(); + } else { + $this->iconUrl = $this->iconData = null; + } + // PicoFeed does not provide valid ids when there is no id element. Its solution // of hashing the url, title, and content together for the id if there is no id // element is stupid. Many feeds are frankenstein mixtures of Atom and RSS, but