]> git.wh0rd.org - tt-rss.git/blob - plugins/af_explosm/init.php
remove $link
[tt-rss.git] / plugins / af_explosm / init.php
1 <?php
2 class Af_Explosm extends Plugin {
3
4 private $host;
5
6 function about() {
7 return array(1.0,
8 "Strip unnecessary stuff from Cyanide and Happiness feeds",
9 "fox");
10 }
11
12 function init($host) {
13 $this->host = $host;
14
15 $host->add_hook($host::HOOK_ARTICLE_FILTER, $this);
16 }
17
18 function hook_article_filter($article) {
19 $owner_uid = $article["owner_uid"];
20
21 if (strpos($article["link"], "explosm.net/comics") !== FALSE) {
22 if (strpos($article["plugin_data"], "explosm,$owner_uid:") === FALSE) {
23
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:\/\/.*\/db\/files\/Comics\/.*)/i", $entry->getAttribute("src"), $matches)) {
38
39 $basenode = $entry;
40 break;
41 }
42 }
43
44 if ($basenode) {
45 $article["content"] = $doc->saveXML($basenode);
46 $article["plugin_data"] = "explosm,$owner_uid:" . $article["plugin_data"];
47 }
48 }
49 } else if (isset($article["stored"]["content"])) {
50 $article["content"] = $article["stored"]["content"];
51 }
52 }
53
54 return $article;
55 }
56 }
57 ?>