]>
Commit | Line | Data |
---|---|---|
901dd67a AD |
1 | <?php |
2 | class 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 | ||
32 | if (!$basenode) { | |
33 | // fallback on the smaller version | |
34 | foreach ($entries as $entry) { | |
35 | ||
36 | if (preg_match("/(http:\/\/assets.amuniversal.com\/.*)/i", $entry->getAttribute("src"), $matches)) { | |
37 | ||
38 | $entry->setAttribute("src", $matches[0]); | |
39 | $basenode = $entry; | |
40 | break; | |
41 | } | |
42 | } | |
43 | } | |
44 | ||
45 | if ($basenode) { | |
46 | $article["content"] = $doc->saveXML($basenode); | |
47 | $article["plugin_data"] = "af_comics,$owner_uid:" . $article["plugin_data"]; | |
48 | } | |
49 | } | |
50 | } else if (isset($article["stored"]["content"])) { | |
51 | $article["content"] = $article["stored"]["content"]; | |
52 | } | |
53 | ||
54 | return true; | |
55 | } | |
56 | ||
57 | return false; | |
58 | } | |
59 | } | |
60 | ?> |