diff options
author | Andrew Dolgov <[email protected]> | 2017-06-04 21:10:06 +0300 |
---|---|---|
committer | Andrew Dolgov <[email protected]> | 2017-06-04 21:10:06 +0300 |
commit | 2816d2cd4bf971faaf12be57d209d0feb21086a2 (patch) | |
tree | 9c95dc45182f0c11769149dca84d0cacc8490a5e /plugins | |
parent | 6fd03996949f32f51bf5ba55bf50d10d1521f22d (diff) | |
parent | ea8d0fd5719fb9e37ef78c903b8801c34263a399 (diff) |
Merge branch 'dilbert-comic-plugin' into 'master'
af_comics_dilbert: More details (title, tags, transcript)
See merge request !56
Diffstat (limited to 'plugins')
-rw-r--r-- | plugins/af_comics/filters/af_comics_dilbert.php | 47 |
1 files changed, 43 insertions, 4 deletions
diff --git a/plugins/af_comics/filters/af_comics_dilbert.php b/plugins/af_comics/filters/af_comics_dilbert.php index 9eed7232a..da5a44dea 100644 --- a/plugins/af_comics/filters/af_comics_dilbert.php +++ b/plugins/af_comics/filters/af_comics_dilbert.php @@ -1,4 +1,5 @@ <?php + class Af_Comics_Dilbert extends Af_ComicFilter { function supported() { @@ -6,10 +7,12 @@ class Af_Comics_Dilbert extends Af_ComicFilter { } function process(&$article) { - if (strpos($article["link"], "dilbert.com") !== FALSE) { + if (strpos($article["guid"], "dilbert.com") !== FALSE || + strpos($article["link"], "/DilbertDailyStrip") !== FALSE) { + $res = fetch_file_contents($article["link"], false, false, false, false, false, 0, - "Mozilla/5.0 (compatible; MSIE 10.0; Windows NT 6.1; WOW64; Trident/6.0)"); + "Mozilla/5.0 (Windows NT 6.1; WOW64; rv:50.0) Gecko/20100101 Firefox/50.0"); global $fetch_last_error_content; @@ -19,14 +22,49 @@ class Af_Comics_Dilbert extends Af_ComicFilter { $doc = new DOMDocument(); @$doc->loadHTML($res); + $basenode = false; + if ($doc) { $xpath = new DOMXPath($doc); - $basenode = $xpath->query('//img[contains(@class, "img-comic")]')->item(0); + // Get the image container + $basenode = $xpath->query('(//div[@class="img-comic-container"]/a[@class="img-comic-link"])')->item(0); + + // Get the comic title + $comic_title = $xpath->query('(//span[@class="comic-title-name"])')->item(0)->textContent; + + // Get tags from the article + $matches = $xpath->query('(//p[contains(@class, "comic-tags")][1]//a)'); + $tags = array(); + + foreach ($matches as $tag) { + // Only strings starting with a number sign are considered tags + if ( substr($tag->textContent, 0, 1) == '#' ) { + $tags[] = mb_strtolower(substr($tag->textContent, 1), 'utf-8'); + } + } + + // Get the current comics transcript and set it + // as the title so it will be visible on mousover + $transcript = $xpath->query('(//div[starts-with(@id, "js-toggle-transcript-")]//p)')->item(0); + if ($transcript) { + $basenode->setAttribute("title", $transcript->textContent); + } if ($basenode) { $article["content"] = $doc->saveXML($basenode); } + + // Add comic title to article type if not empty (mostly Sunday strips) + if ($comic_title) { + $article["title"] = $article["title"] . " - " . $comic_title; + } + + if (!empty($tags)) { + // Ignore existing tags and just replace them all + $article["tags"] = array_unique($tags); + } + } return true; @@ -34,4 +72,5 @@ class Af_Comics_Dilbert extends Af_ComicFilter { return false; } -}
\ No newline at end of file +} +?> |