]> git.wh0rd.org - tt-rss.git/blame - plugins/af_explosm/init.php
remove $link
[tt-rss.git] / plugins / af_explosm / init.php
CommitLineData
0e44c2a0
AD
1<?php
2class Af_Explosm extends Plugin {
3
0e44c2a0
AD
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) {
0e44c2a0
AD
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
e02555c1
AD
21 if (strpos($article["link"], "explosm.net/comics") !== FALSE) {
22 if (strpos($article["plugin_data"], "explosm,$owner_uid:") === FALSE) {
0e44c2a0 23
e02555c1
AD
24 $doc = new DOMDocument();
25 @$doc->loadHTML(fetch_file_contents($article["link"]));
0e44c2a0 26
e02555c1 27 $basenode = false;
0e44c2a0 28
e02555c1
AD
29 if ($doc) {
30 $xpath = new DOMXPath($doc);
31 $entries = $xpath->query('(//img[@src])'); // we might also check for img[@class='strip'] I guess...
0e44c2a0 32
e02555c1 33 $matches = array();
0e44c2a0 34
e02555c1 35 foreach ($entries as $entry) {
0e44c2a0 36
e02555c1 37 if (preg_match("/(http:\/\/.*\/db\/files\/Comics\/.*)/i", $entry->getAttribute("src"), $matches)) {
0e44c2a0 38
e02555c1
AD
39 $basenode = $entry;
40 break;
41 }
0e44c2a0 42 }
0e44c2a0 43
e02555c1 44 if ($basenode) {
cc38c8e5 45 $article["content"] = $doc->saveXML($basenode);
e02555c1
AD
46 $article["plugin_data"] = "explosm,$owner_uid:" . $article["plugin_data"];
47 }
0e44c2a0 48 }
e02555c1
AD
49 } else if (isset($article["stored"]["content"])) {
50 $article["content"] = $article["stored"]["content"];
0e44c2a0
AD
51 }
52 }
53
54 return $article;
55 }
56}
57?>