From 01b39d985c9f194a35c690a18149cbb06fc7b0d3 Mon Sep 17 00:00:00 2001 From: Andrew Dolgov Date: Sun, 14 Nov 2021 18:00:03 +0300 Subject: deal with the rest of warnings in plugin.php --- plugins/af_comics/init.php | 1 + 1 file changed, 1 insertion(+) (limited to 'plugins/af_comics') diff --git a/plugins/af_comics/init.php b/plugins/af_comics/init.php index 84d95a2ba..a9a8f3faa 100755 --- a/plugins/af_comics/init.php +++ b/plugins/af_comics/init.php @@ -1,6 +1,7 @@ $filters */ private $filters = array(); function about() { -- cgit v1.2.3 From d17b79311e9c80576a8bf392b9d1dbee7fa8fbdc Mon Sep 17 00:00:00 2001 From: Andrew Dolgov Date: Sun, 14 Nov 2021 20:33:37 +0300 Subject: set missing annotations in af_comics --- plugins/af_comics/filter_base.php | 18 ++++++++++++++++++ plugins/af_comics/filters/af_comics_tfd.php | 2 +- 2 files changed, 19 insertions(+), 1 deletion(-) (limited to 'plugins/af_comics') diff --git a/plugins/af_comics/filter_base.php b/plugins/af_comics/filter_base.php index 5c82bc870..83bc48184 100644 --- a/plugins/af_comics/filter_base.php +++ b/plugins/af_comics/filter_base.php @@ -1,20 +1,38 @@ */ public abstract function supported(); + + /** + * @param array $article + * @return bool + */ public abstract function process(&$article); public function __construct(/*PluginHost $host*/) { } + /** + * @param string $url + * @return string|false + */ public function on_subscribe($url) { return false; } + /** + * @param string $url + * @return array{"title": string, "site_url": string}|false + */ public function on_basic_info($url) { return false; } + /** + * @param string $url + * @return string|false + */ public function on_fetch($url) { return false; } diff --git a/plugins/af_comics/filters/af_comics_tfd.php b/plugins/af_comics/filters/af_comics_tfd.php index 19ca43a24..2010da37e 100644 --- a/plugins/af_comics/filters/af_comics_tfd.php +++ b/plugins/af_comics/filters/af_comics_tfd.php @@ -12,7 +12,7 @@ class Af_Comics_Tfd extends Af_ComicFilter { false, false, 0, "Mozilla/5.0 (compatible; MSIE 10.0; Windows NT 6.1; WOW64; Trident/6.0)"); - if (!$res) return $article; + if (!$res) return false; $doc = new DOMDocument(); -- cgit v1.2.3 From aa924d9ee7674cfe649d498ce3cbcdb093bca956 Mon Sep 17 00:00:00 2001 From: Andrew Dolgov Date: Mon, 15 Nov 2021 08:26:02 +0300 Subject: deal with several DOMElement-related errors --- plugins/af_comics/filters/af_comics_comicpress.php | 2 +- plugins/af_comics/filters/af_comics_dilbert.php | 2 +- plugins/af_comics/filters/af_comics_gocomics.php | 1 + 3 files changed, 3 insertions(+), 2 deletions(-) (limited to 'plugins/af_comics') diff --git a/plugins/af_comics/filters/af_comics_comicpress.php b/plugins/af_comics/filters/af_comics_comicpress.php index 741d59672..93bfde7e7 100755 --- a/plugins/af_comics/filters/af_comics_comicpress.php +++ b/plugins/af_comics/filters/af_comics_comicpress.php @@ -32,7 +32,7 @@ class Af_Comics_ComicPress extends Af_ComicFilter { return true; } - // buni-specific + /** @var DOMElement|false $webtoon_link (buni specific) */ $webtoon_link = $xpath->query("//a[contains(@href,'www.webtoons.com')]")->item(0); if ($webtoon_link) { diff --git a/plugins/af_comics/filters/af_comics_dilbert.php b/plugins/af_comics/filters/af_comics_dilbert.php index 49fa54cfa..80a8a0221 100644 --- a/plugins/af_comics/filters/af_comics_dilbert.php +++ b/plugins/af_comics/filters/af_comics_dilbert.php @@ -22,7 +22,7 @@ class Af_Comics_Dilbert extends Af_ComicFilter { if ($res && $doc->loadHTML($res)) { $xpath = new DOMXPath($doc); - // Get the image container + /** @var DOMElement|false $basenode (image container) */ $basenode = $xpath->query('(//div[@class="img-comic-container"]/a[@class="img-comic-link"])')->item(0); // Get the comic title diff --git a/plugins/af_comics/filters/af_comics_gocomics.php b/plugins/af_comics/filters/af_comics_gocomics.php index 71d387918..f474312ae 100644 --- a/plugins/af_comics/filters/af_comics_gocomics.php +++ b/plugins/af_comics/filters/af_comics_gocomics.php @@ -50,6 +50,7 @@ class Af_Comics_Gocomics extends Af_ComicFilter { if (@$doc->loadHTML($body)) { $xpath = new DOMXPath($doc); + /** @var DOMElement|false $node */ $node = $xpath->query('//picture[contains(@class, "item-comic-image")]/img')->item(0); if ($node) { -- cgit v1.2.3 From 109b702ed0cd31a0dc8466b8127882d263705d8d Mon Sep 17 00:00:00 2001 From: wn_ Date: Mon, 15 Nov 2021 12:24:38 +0000 Subject: Minor fix to DOMNodeList#item() potential type (null vs false) --- plugins/af_comics/filters/af_comics_comicpress.php | 2 +- plugins/af_comics/filters/af_comics_dilbert.php | 2 +- plugins/af_comics/filters/af_comics_gocomics.php | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) (limited to 'plugins/af_comics') diff --git a/plugins/af_comics/filters/af_comics_comicpress.php b/plugins/af_comics/filters/af_comics_comicpress.php index 93bfde7e7..89837d074 100755 --- a/plugins/af_comics/filters/af_comics_comicpress.php +++ b/plugins/af_comics/filters/af_comics_comicpress.php @@ -32,7 +32,7 @@ class Af_Comics_ComicPress extends Af_ComicFilter { return true; } - /** @var DOMElement|false $webtoon_link (buni specific) */ + /** @var DOMElement|null $webtoon_link (buni specific) */ $webtoon_link = $xpath->query("//a[contains(@href,'www.webtoons.com')]")->item(0); if ($webtoon_link) { diff --git a/plugins/af_comics/filters/af_comics_dilbert.php b/plugins/af_comics/filters/af_comics_dilbert.php index 80a8a0221..a1c59b94c 100644 --- a/plugins/af_comics/filters/af_comics_dilbert.php +++ b/plugins/af_comics/filters/af_comics_dilbert.php @@ -22,7 +22,7 @@ class Af_Comics_Dilbert extends Af_ComicFilter { if ($res && $doc->loadHTML($res)) { $xpath = new DOMXPath($doc); - /** @var DOMElement|false $basenode (image container) */ + /** @var DOMElement|null $basenode (image container) */ $basenode = $xpath->query('(//div[@class="img-comic-container"]/a[@class="img-comic-link"])')->item(0); // Get the comic title diff --git a/plugins/af_comics/filters/af_comics_gocomics.php b/plugins/af_comics/filters/af_comics_gocomics.php index f474312ae..732f7d0b8 100644 --- a/plugins/af_comics/filters/af_comics_gocomics.php +++ b/plugins/af_comics/filters/af_comics_gocomics.php @@ -50,7 +50,7 @@ class Af_Comics_Gocomics extends Af_ComicFilter { if (@$doc->loadHTML($body)) { $xpath = new DOMXPath($doc); - /** @var DOMElement|false $node */ + /** @var DOMElement|null $node */ $node = $xpath->query('//picture[contains(@class, "item-comic-image")]/img')->item(0); if ($node) { -- cgit v1.2.3 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/af_comics') 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