From b2952843f50c7b5d2e8aafd62fadb4674acc59b1 Mon Sep 17 00:00:00 2001 From: Andrew Dolgov Date: Mon, 15 Nov 2021 23:22:21 +0300 Subject: * DiskCache: add download() helper * Af_Comics_Gocomics_FarSide: cache linked images because it seems to be required anyway --- plugins/af_comics/filters/af_comics_gocomics_farside.php | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) (limited to 'plugins') diff --git a/plugins/af_comics/filters/af_comics_gocomics_farside.php b/plugins/af_comics/filters/af_comics_gocomics_farside.php index 0399015ab..e4e230516 100644 --- a/plugins/af_comics/filters/af_comics_gocomics_farside.php +++ b/plugins/af_comics/filters/af_comics_gocomics_farside.php @@ -50,8 +50,22 @@ class Af_Comics_Gocomics_FarSide extends Af_ComicFilter { if ($content_node) { $imgs = $xpath->query('//img[@data-src]', $content_node); + $cache = new DiskCache("images"); + foreach ($imgs as $img) { - $img->setAttribute('src', $img->getAttribute('data-src')); + $image_url = $img->getAttribute('data-src'); + $local_filename = sha1($image_url); + + if ($image_url) { + $img->setAttribute('src', $image_url); + + // try to cache image locally because they just 401 us otherwise + if (!$cache->exists($local_filename)) { + Debug::log("[Af_Comics_Gocomics_FarSide] caching: $image_url", Debug::LOG_VERBOSE); + $res = $cache->download($image_url, sha1($image_url), ["http_referrer" => $image_url]); + Debug::log("[Af_Comics_Gocomics_FarSide] cache result: $res", Debug::LOG_VERBOSE); + } + } } $junk_elems = $xpath->query("//*[@data-shareable-popover]"); -- cgit v1.2.3