]> git.wh0rd.org - tt-rss.git/blame - plugins/af_gocomics/init.php
prevent article filters from modifying article GUID; add separate plugin_data field...
[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
b30abdad 23 if (strpos($article["guid"], "gocomics.com") !== FALSE && strpos($article["plugin_data"], "gocomics,$owner_uid:") === FALSE) {
cfd83e0e
AD
24 $doc = new DOMDocument();
25 @$doc->loadHTML(fetch_file_contents($article["link"]));
26
27 $basenode = false;
28
29 if ($doc) {
30 $xpath = new DOMXPath($doc);
31 $entries = $xpath->query('(//img[@src])'); // we might also check for img[@class='strip'] I guess...
32
33 $matches = array();
34
35 foreach ($entries as $entry) {
36
37 if (preg_match("/(http:\/\/assets.amuniversal.com\/.*)/i", $entry->getAttribute("src"), $matches)) {
38
39 $entry->setAttribute("src", $matches[0]);
40 $basenode = $entry;
41 break;
42 }
43 }
44
45 if ($basenode) {
46 $article["content"] = $doc->saveXML($basenode, LIBXML_NOEMPTYTAG);
cfd83e0e
AD
47 }
48 }
80715cae 49
b30abdad 50 $article["plugin_data"] = "gocomics,$owner_uid:" . $article["plugin_data"];
cfd83e0e
AD
51 }
52
53 return $article;
54 }
55}
56?>