]> git.wh0rd.org Git - tt-rss.git/blob - plugins/af_comics/filters/af_comics_gocomics.php
plugins: remove obsolete plugin_data/stored stuff
[tt-rss.git] / plugins / af_comics / filters / af_comics_gocomics.php
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                                 $doc = new DOMDocument();
13                                 @$doc->loadHTML(fetch_file_contents($article["link"]));
14
15                                 $basenode = false;
16
17                                 if ($doc) {
18                                         $xpath = new DOMXPath($doc);
19                                         $entries = $xpath->query("(//img[@class='strip'])");
20
21                                         $matches = array();
22
23                                         if ($entries->length > 1) { // if we have more than one match, then get the zoomed one, which is the second for gocomics
24                                                 $entry = $entries->item(1); // get the second element (items start at 0)
25                                                 if (preg_match("/(http:\/\/assets.amuniversal.com\/.*)/i", $entry->getAttribute("src"), $matches)) {
26                                                         $entry->setAttribute("src", $matches[0]);
27                                                         $basenode = $entry;
28                                                 }
29                                         }
30
31                                         if (!$basenode) {
32                                                 // fallback on the smaller version
33                                                 foreach ($entries as $entry) {
34                                                         if (preg_match("/(http:\/\/assets.amuniversal.com\/.*)/i", $entry->getAttribute("src"), $matches)) {
35                                                                 $entry->setAttribute("src", $matches[0]);
36                                                                 $basenode = $entry;
37                                                                 break;
38                                                         }
39                                                 }
40                                         }
41
42                                         if ($basenode) {
43                                                 $article["content"] = $doc->saveXML($basenode);
44                                         }
45                                 }
46
47                         return true;
48                 }
49
50                 return false;
51         }
52 }
53 ?>