]> git.wh0rd.org - tt-rss.git/blame - plugins/af_gocomics/init.php
Merge pull request #52 from markwaters/master
[tt-rss.git] / plugins / af_gocomics / init.php
CommitLineData
cfd83e0e 1<?php
0862a602 2class Af_GoComics extends Plugin {
cfd83e0e
AD
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
e02555c1
AD
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"]));
cfd83e0e 27
e02555c1 28 $basenode = false;
cfd83e0e 29
e02555c1
AD
30 if ($doc) {
31 $xpath = new DOMXPath($doc);
32 $entries = $xpath->query('(//img[@src])'); // we might also check for img[@class='strip'] I guess...
cfd83e0e 33
e02555c1 34 $matches = array();
cfd83e0e 35
e02555c1 36 foreach ($entries as $entry) {
cfd83e0e 37
e02555c1 38 if (preg_match("/(http:\/\/assets.amuniversal.com\/.*)/i", $entry->getAttribute("src"), $matches)) {
cfd83e0e 39
e02555c1
AD
40 $entry->setAttribute("src", $matches[0]);
41 $basenode = $entry;
42 break;
43 }
cfd83e0e 44 }
cfd83e0e 45
e02555c1
AD
46 if ($basenode) {
47 $article["content"] = $doc->saveXML($basenode, LIBXML_NOEMPTYTAG);
48 $article["plugin_data"] = "gocomics,$owner_uid:" . $article["plugin_data"];
49 }
cfd83e0e 50 }
e02555c1
AD
51 } else if (isset($article["stored"]["content"])) {
52 $article["content"] = $article["stored"]["content"];
cfd83e0e
AD
53 }
54 }
55
56 return $article;
57 }
58}
59?>