]> git.wh0rd.org - tt-rss.git/blob - plugins/af_gocomics/init.php
466ec9687a34f525ffa8fa8081dad2df54b8351b
[tt-rss.git] / plugins / af_gocomics / init.php
1 <?php
2 class Af_GoComics extends Plugin {
3
4 private $link;
5 private $host;
6
7 function about() {
8 return array(1.0,
9 "Strip unnecessary stuff from gocomics feeds",
10 "fox");
11 }
12
13 function init($host) {
14 $this->link = $host->get_link();
15 $this->host = $host;
16
17 $host->add_hook($host::HOOK_ARTICLE_FILTER, $this);
18 }
19
20 function hook_article_filter($article) {
21 $owner_uid = $article["owner_uid"];
22
23 if (strpos($article["guid"], "gocomics.com") !== FALSE) {
24 if (strpos($article["plugin_data"], "gocomics,$owner_uid:") === FALSE) {
25 $doc = new DOMDocument();
26 @$doc->loadHTML(fetch_file_contents($article["link"]));
27
28 $basenode = false;
29
30 if ($doc) {
31 $xpath = new DOMXPath($doc);
32 $entries = $xpath->query('(//img[@src])'); // we might also check for img[@class='strip'] I guess...
33
34 $matches = array();
35
36 foreach ($entries as $entry) {
37
38 if (preg_match("/(http:\/\/assets.amuniversal.com\/.*)/i", $entry->getAttribute("src"), $matches)) {
39
40 $entry->setAttribute("src", $matches[0]);
41 $basenode = $entry;
42 break;
43 }
44 }
45
46 if ($basenode) {
47 $article["content"] = $doc->saveXML($basenode);
48 $article["plugin_data"] = "gocomics,$owner_uid:" . $article["plugin_data"];
49 }
50 }
51 } else if (isset($article["stored"]["content"])) {
52 $article["content"] = $article["stored"]["content"];
53 }
54 }
55
56 return $article;
57 }
58 }
59 ?>