]> git.wh0rd.org Git - tt-rss.git/blob - plugins/af_explosm/init.php
rename plugin main class files
[tt-rss.git] / plugins / af_explosm / init.php
1 <?php
2 class Af_Explosm extends Plugin {
3
4         private $link;
5         private $host;
6
7         function about() {
8                 return array(1.0,
9                         "Strip unnecessary stuff from Cyanide and Happiness 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["link"], "explosm.net/comics") !== FALSE &&
24                                 strpos($article["guid"], "explosm,$owner_uid:") === FALSE) {
25
26                         $doc = new DOMDocument();
27                         @$doc->loadHTML(fetch_file_contents($article["link"]));
28
29                         $basenode = false;
30
31                         if ($doc) {
32                                 $xpath = new DOMXPath($doc);
33                                 $entries = $xpath->query('(//img[@src])'); // we might also check for img[@class='strip'] I guess...
34
35                                 $matches = array();
36
37                                 foreach ($entries as $entry) {
38
39                                         if (preg_match("/(http:\/\/.*\/db\/files\/Comics\/.*)/i", $entry->getAttribute("src"), $matches)) {
40
41                                                 $basenode = $entry;
42                                                 break;
43                                         }
44                                 }
45
46                                 if ($basenode) {
47                                         $article["content"] = $doc->saveXML($basenode, LIBXML_NOEMPTYTAG);
48
49                                         // we need to update guid with owner_uid because our local article is different from the one
50                                         // other users with this plugin disabled might get
51                                         $article["guid"] = "explosm,$owner_uid:" . $article["guid"];
52                                 }
53                         }
54                 }
55
56                 return $article;
57         }
58 }
59 ?>