]> git.wh0rd.org - tt-rss.git/blame - plugins/af_pennyarcade/init.php
Merge pull request #52 from markwaters/master
[tt-rss.git] / plugins / af_pennyarcade / init.php
CommitLineData
37d2fe4c 1<?php
0862a602 2class Af_PennyArcade extends Plugin {
37d2fe4c
AD
3
4 private $link;
5 private $host;
6
7 function about() {
8 return array(1.0,
9 "Strip unnecessary stuff from PA 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
e02555c1
AD
23 if (strpos($article["link"], "penny-arcade.com") !== FALSE && strpos($article["title"], "Comic:") !== FALSE) {
24 if (strpos($article["plugin_data"], "pennyarcade,$owner_uid:") === FALSE) {
37d2fe4c 25
e02555c1
AD
26 $doc = new DOMDocument();
27 @$doc->loadHTML(fetch_file_contents($article["link"]));
37d2fe4c 28
e02555c1 29 $basenode = false;
37d2fe4c 30
e02555c1
AD
31 if ($doc) {
32 $xpath = new DOMXPath($doc);
33 $entries = $xpath->query('(//img[@src])'); // we might also check for img[@class='strip'] I guess...
37d2fe4c 34
e02555c1 35 $matches = array();
37d2fe4c 36
e02555c1 37 foreach ($entries as $entry) {
37d2fe4c 38
e02555c1 39 if (preg_match("/(http:\/\/art.penny-arcade.com\/.*)/i", $entry->getAttribute("src"), $matches)) {
37d2fe4c 40
e02555c1
AD
41 $basenode = $entry;
42 break;
43 }
37d2fe4c 44 }
37d2fe4c 45
e02555c1
AD
46 if ($basenode) {
47 $article["content"] = $doc->saveXML($basenode, LIBXML_NOEMPTYTAG);
48 $article["plugin_data"] = "pennyarcade,$owner_uid:" . $article["plugin_data"];
49 }
37d2fe4c 50 }
e02555c1
AD
51 } else if (isset($article["stored"]["content"])) {
52 $article["content"] = $article["stored"]["content"];
37d2fe4c
AD
53 }
54 }
55
56 return $article;
57 }
58}
59?>