From 6f398dcfc6bb0c58902266c9117c0e1d03f5bb47 Mon Sep 17 00:00:00 2001 From: Andrew Dolgov Date: Mon, 5 Jun 2017 12:53:06 +0300 Subject: [PATCH] af_comics updates: 1. move preferences to Feeds tab 2. update CAD comic with support for sillies 3. add support for loading updated/third-party filters from filters.local (would override bundled filters) --- plugins/af_comics/filters.local/.empty | 0 plugins/af_comics/filters/af_comics_cad.php | 15 ++++++++++--- plugins/af_comics/init.php | 24 +++++++++++++++------ 3 files changed, 29 insertions(+), 10 deletions(-) create mode 100644 plugins/af_comics/filters.local/.empty diff --git a/plugins/af_comics/filters.local/.empty b/plugins/af_comics/filters.local/.empty new file mode 100644 index 000000000..e69de29bb diff --git a/plugins/af_comics/filters/af_comics_cad.php b/plugins/af_comics/filters/af_comics_cad.php index 7c0670918..6846f3cb0 100644 --- a/plugins/af_comics/filters/af_comics_cad.php +++ b/plugins/af_comics/filters/af_comics_cad.php @@ -6,14 +6,23 @@ class Af_Comics_Cad extends Af_ComicFilter { } function process(&$article) { - if (strpos($article["link"], "cad-comic.com/cad/") !== FALSE) { + if (strpos($article["link"], "cad-comic.com") !== FALSE) { if (strpos($article["title"], "News:") === FALSE) { + global $fetch_last_error_content; + $doc = new DOMDocument(); - if (@$doc->loadHTML(fetch_file_contents($article["link"]))) { + $res = fetch_file_contents($article["link"], false, false, false, + false, false, 0, + "Mozilla/5.0 (Windows NT 6.1; WOW64; rv:50.0) Gecko/20100101 Firefox/50.0"); + + if (!$res && $fetch_last_error_content) + $res = $fetch_last_error_content; + + if (@$doc->loadHTML($res)) { $xpath = new DOMXPath($doc); - $basenode = $xpath->query('(//img[contains(@src, "/comics/cad-")])')->item(0); + $basenode = $xpath->query('//div[@class="comicpage"]/a/img')->item(0); if ($basenode) { $article["content"] = $doc->saveXML($basenode); diff --git a/plugins/af_comics/init.php b/plugins/af_comics/init.php index 15af1d1a6..09e903379 100644 --- a/plugins/af_comics/init.php +++ b/plugins/af_comics/init.php @@ -19,23 +19,31 @@ class Af_Comics extends Plugin { require_once __DIR__ . "/filter_base.php"; - $filters = glob(__DIR__ . "/filters/*.php"); + $filters = array_merge(glob(__DIR__ . "/filters.local/*.php"), glob(__DIR__ . "/filters/*.php")); + $names = []; foreach ($filters as $file) { - require_once $file; $filter_name = preg_replace("/\..*$/", "", basename($file)); - $filter = new $filter_name(); + if (array_search($filter_name, $names) === FALSE) { + if (!class_exists($filter_name)) { + require_once $file; + } - if (is_subclass_of($filter, "Af_ComicFilter")) { - array_push($this->filters, $filter); + array_push($names, $filter_name); + + $filter = new $filter_name(); + + if (is_subclass_of($filter, "Af_ComicFilter")) { + array_push($this->filters, $filter); + array_push($names, $filter_name); + } } } - } function hook_prefs_tab($args) { - if ($args != "prefPrefs") return; + if ($args != "prefFeeds") return; print "
"; @@ -59,6 +67,8 @@ class Af_Comics extends Plugin { print "

".__('GoComics requires a specific URL to workaround their lack of feed support: http://feeds.feedburner.com/uclick/comic_name (e.g. http://www.gocomics.com/garfield uses http://feeds.feedburner.com/uclick/garfield).')."

"; + print "

".__('Drop any updated filters into filters.local in plugin directory.')."

"; + print "
"; }