]>
git.wh0rd.org - tt-rss.git/blob - plugins/af_comics/filters/af_comics_dilbert.php
565b44657c9c096d75889ccdda6a7ba4ed9e4ec0
3 class Af_Comics_Dilbert
extends Af_ComicFilter
{
6 return array("Dilbert");
9 function process(&$article) {
10 if (strpos($article["link"], "dilbert.com") !== FALSE ||
11 strpos($article["link"], "/DilbertDailyStrip") !== FALSE) {
13 $res = fetch_file_contents($article["link"], false, false, false,
15 "Mozilla/5.0 (Windows NT 6.1; WOW64; rv:50.0) Gecko/20100101 Firefox/50.0");
17 global $fetch_last_error_content;
19 if (!$res && $fetch_last_error_content)
20 $res = $fetch_last_error_content;
22 $doc = new DOMDocument();
24 if (@$doc->loadHTML($res)) {
25 $xpath = new DOMXPath($doc);
27 // Get the image container
28 $basenode = $xpath->query('(//div[@class="img-comic-container"]/a[@class="img-comic-link"])')->item(0);
30 // Get the comic title
31 $comic_title = $xpath->query('(//span[@class="comic-title-name"])')->item(0)->textContent
;
33 // Get tags from the article
34 $matches = $xpath->query('(//p[contains(@class, "comic-tags")][1]//a)');
37 foreach ($matches as $tag) {
38 // Only strings starting with a number sign are considered tags
39 if ( substr($tag->textContent
, 0, 1) == '#' ) {
40 $tags[] = mb_strtolower(substr($tag->textContent
, 1), 'utf-8');
44 // Get the current comics transcript and set it
45 // as the title so it will be visible on mousover
46 $transcript = $xpath->query('(//div[starts-with(@id, "js-toggle-transcript-")]//p)')->item(0);
48 $basenode->setAttribute("title", $transcript->textContent
);
52 $article["content"] = $doc->saveXML($basenode);
55 // Add comic title to article type if not empty (mostly Sunday strips)
57 $article["title"] = $article["title"] . " - " . $comic_title;
61 // Ignore existing tags and just replace them all
62 $article["tags"] = array_unique($tags);