1
1
Fork 0
mirror of https://code.mensbeam.com/MensBeam/Arsse.git synced 2024-12-22 21:22:40 +00:00

Partial icon handling skeleton

This commit is contained in:
J. King 2020-11-04 20:00:00 -05:00
parent af675479b8
commit c25782f98c
2 changed files with 32 additions and 6 deletions

View file

@ -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

View file

@ -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