]>
Commit | Line | Data |
---|---|---|
cfd83e0e | 1 | <?php |
0862a602 | 2 | class Af_GoComics extends Plugin { |
cfd83e0e AD |
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) { | |
cfd83e0e AD |
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 | ||
e02555c1 AD |
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"])); | |
cfd83e0e | 24 | |
e02555c1 | 25 | $basenode = false; |
cfd83e0e | 26 | |
e02555c1 AD |
27 | if ($doc) { |
28 | $xpath = new DOMXPath($doc); | |
29 | $entries = $xpath->query('(//img[@src])'); // we might also check for img[@class='strip'] I guess... | |
cfd83e0e | 30 | |
e02555c1 | 31 | $matches = array(); |
cfd83e0e | 32 | |
e02555c1 | 33 | foreach ($entries as $entry) { |
cfd83e0e | 34 | |
e02555c1 | 35 | if (preg_match("/(http:\/\/assets.amuniversal.com\/.*)/i", $entry->getAttribute("src"), $matches)) { |
cfd83e0e | 36 | |
e02555c1 AD |
37 | $entry->setAttribute("src", $matches[0]); |
38 | $basenode = $entry; | |
39 | break; | |
40 | } | |
cfd83e0e | 41 | } |
cfd83e0e | 42 | |
e02555c1 | 43 | if ($basenode) { |
cc38c8e5 | 44 | $article["content"] = $doc->saveXML($basenode); |
e02555c1 AD |
45 | $article["plugin_data"] = "gocomics,$owner_uid:" . $article["plugin_data"]; |
46 | } | |
cfd83e0e | 47 | } |
e02555c1 AD |
48 | } else if (isset($article["stored"]["content"])) { |
49 | $article["content"] = $article["stored"]["content"]; | |
cfd83e0e AD |
50 | } |
51 | } | |
52 | ||
53 | return $article; | |
54 | } | |
55 | } | |
56 | ?> |