Skip to content

Commit

Permalink
[FurAffinityBridge] Fix if search result contains hidden submission (#…
Browse files Browse the repository at this point in the history
…3637)

* Reverts to preview submission if full is hidden

* Reverts to preview submission if full is hidden

* revert

* added fallback to higher res preview if SWF

* amend
  • Loading branch information
mruac authored Aug 29, 2023
1 parent 00a18a1 commit 9e33a15
Showing 1 changed file with 45 additions and 44 deletions.
89 changes: 45 additions & 44 deletions bridges/FurAffinityBridge.php
Original file line number Diff line number Diff line change
Expand Up @@ -892,60 +892,51 @@ private function itemsFromSubmissionList($html, $limit)
$item = [];

$submissionURL = $figure->find('b u a', 0)->href;
$imgURL = 'https:' . $figure->find('b u a img', 0)->src;
$imgURL = $figure->find('b u a img', 0)->src;

$item['uri'] = $submissionURL;
$item['title'] = html_entity_decode(
$figure->find('figcaption p a[href*=/view/]', 0)->title
);
$item['author'] = $figure->find('figcaption p a[href*=/user/]', 0)->title;

$item['content'] = "<a href=\"$submissionURL\"> <img src=\"{$imgURL}\" referrerpolicy=\"no-referrer\"/></a>";

if ($this->getInput('full') === true) {
$submissionHTML = $this->getFASimpleHTMLDOM($submissionURL, $cache);

$stats = $submissionHTML->find('.stats-container', 0);
$popupDate = $stats->find('.popup_date', 0);
if ($popupDate) {
$item['timestamp'] = strtotime($popupDate->title);
}

$var = $submissionHTML->find('.actions a[href^=https://d.facdn]', 0);
if ($var) {
$item['enclosures'] = [$var->href];
}

foreach ($stats->find('#keywords a') as $keyword) {
$item['categories'][] = $keyword->plaintext;
}

$previewSrc = $submissionHTML->find('#submissionImg', 0)
->{'data-preview-src'};
if ($previewSrc) {
$imgURL = 'https:' . $previewSrc;
if (!$this->isHiddenSubmission($submissionHTML)) {
$stats = $submissionHTML->find('.stats-container', 0);
$popupDate = $stats->find('.popup_date', 0);
if ($popupDate) {
$item['timestamp'] = strtotime($popupDate->title);
}

$var = $submissionHTML->find('.actions a[href^=https://d.facdn]', 0);
if ($var) {
$item['enclosures'] = [$var->href];
}

foreach ($stats->find('#keywords a') as $keyword) {
$item['categories'][] = $keyword->plaintext;
}

$previewSrc = $submissionHTML->find('#submissionImg', 0);
if ($previewSrc) {
$imgURL = 'https:' . $previewSrc->{'data-preview-src'};
} else {
$imgURL = $submissionHTML->find('[property="og:image"]', 0)->{'content'};
}

$description = $submissionHTML->find('div.submission-description', 0);
if ($description) {
$this->setReferrerPolicy($description);
$description = trim($description->innertext);
} else {
$description = '';
}

$item['content'] = "<a href=\"$submissionURL\"> <img src=\"{$imgURL}\" referrerpolicy=\"no-referrer\"/></a><p>{$description}</p>";
}

$description = $submissionHTML->find('div.submission-description', 0);
if ($description) {
$this->setReferrerPolicy($description);
$description = trim($description->innertext);
} else {
$description = '';
}

$item['content'] = <<<EOD
<a href="$submissionURL">
<img src="{$imgURL}" referrerpolicy="no-referrer" />
</a>
<p>
{$description}
</p>
EOD;
} else {
$item['content'] = <<<EOD
<a href="$submissionURL">
<img src="$imgURL" referrerpolicy="no-referrer" />
</a>
EOD;
}

$this->items[] = $item;
Expand All @@ -964,4 +955,14 @@ private function setReferrerPolicy(&$html)
$img->referrerpolicy = 'no-referrer';
}
}

private function isHiddenSubmission($html)
{
//Disabled accounts prevents their userpage, gallery, favorites and journals from being viewed.
//Submissions can require maturity limit or logged-in account.
$system_message = $html->find('.section-body.alignleft', 0);
$system_message = $system_message ? $system_message->plaintext : '';

return str_contains($system_message, 'System Message');
}
}

0 comments on commit 9e33a15

Please sign in to comment.