]> git.wh0rd.org - tt-rss.git/blame - plugins/af_comics/filters/af_comics_gocomics.php
af_comics_gocomics: fix indenting
[tt-rss.git] / plugins / af_comics / filters / af_comics_gocomics.php
CommitLineData
901dd67a
AD
1<?php
2class Af_Comics_GoComics extends Af_ComicFilter {
3
4 function supported() {
5 return array("GoComics");
6 }
7
8 function process(&$article) {
9 $owner_uid = $article["owner_uid"];
10
11 if (strpos($article["guid"], "gocomics.com") !== FALSE) {
12 if (strpos($article["plugin_data"], "af_comics,$owner_uid:") === FALSE) {
13 $doc = new DOMDocument();
14 @$doc->loadHTML(fetch_file_contents($article["link"]));
15
16 $basenode = false;
17
18 if ($doc) {
19 $xpath = new DOMXPath($doc);
d35bd9a2 20 $entries = $xpath->query("(//img[@class='strip'])");
901dd67a
AD
21
22 $matches = array();
23
d35bd9a2 24 if ($entries->length > 1) { // if we have more than one match, then get the zoomed one, which is the second for gocomics
25 $entry = $entries->item(1); // get the second element (items start at 0)
26 if (preg_match("/(http:\/\/assets.amuniversal.com\/.*)/i", $entry->getAttribute("src"), $matches)) {
901dd67a
AD
27 $entry->setAttribute("src", $matches[0]);
28 $basenode = $entry;
901dd67a
AD
29 }
30 }
31
9203929c
AD
32 if (!$basenode) {
33 // fallback on the smaller version
34 foreach ($entries as $entry) {
35 if (preg_match("/(http:\/\/assets.amuniversal.com\/.*)/i", $entry->getAttribute("src"), $matches)) {
36 $entry->setAttribute("src", $matches[0]);
37 $basenode = $entry;
38 break;
39 }
40 }
41 }
901dd67a
AD
42
43 if ($basenode) {
44 $article["content"] = $doc->saveXML($basenode);
45 $article["plugin_data"] = "af_comics,$owner_uid:" . $article["plugin_data"];
46 }
47 }
48 } else if (isset($article["stored"]["content"])) {
49 $article["content"] = $article["stored"]["content"];
50 }
51
52 return true;
53 }
54
55 return false;
56 }
57}
58?>