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