]> git.wh0rd.org - tt-rss.git/blob - plugins/af_pennyarcade/init.php
Merge pull request #83 from kythyria/master
[tt-rss.git] / plugins / af_pennyarcade / init.php
1 <?php
2 class Af_PennyArcade extends Plugin {
3
4 private $link;
5 private $host;
6
7 function about() {
8 return array(1.1,
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
23 if (strpos($article["link"], "penny-arcade.com") !== FALSE && strpos($article["title"], "Comic:") !== FALSE) {
24 if (strpos($article["plugin_data"], "pennyarcade,$owner_uid:") === FALSE) {
25
26 if ($debug_enabled) {
27 _debug("af_pennyarcade: Processing comic");
28 }
29
30 $doc = new DOMDocument();
31 $doc->loadHTML(fetch_file_contents($article["link"]));
32
33 $basenode = false;
34
35 if ($doc) {
36 $xpath = new DOMXPath($doc);
37 $entries = $xpath->query('(//div[@class="post comic"])');
38
39 foreach ($entries as $entry) {
40 $basenode = $entry;
41 }
42
43 if ($basenode) {
44 $article["content"] = $doc->saveXML($basenode);
45 $article["plugin_data"] = "pennyarcade,$owner_uid:" . $article["plugin_data"];
46 }
47 }
48 } else if (isset($article["stored"]["content"])) {
49 $article["content"] = $article["stored"]["content"];
50 }
51 }
52
53 if (strpos($article["link"], "penny-arcade.com") !== FALSE && strpos($article["title"], "News Post:") !== FALSE) {
54 if (strpos($article["plugin_data"], "pennyarcade,$owner_uid:") === FALSE) {
55 if ($debug_enabled) {
56 _debug("af_pennyarcade: Processing news post");
57 }
58 $doc = new DOMDocument();
59 $doc->loadHTML(fetch_file_contents($article["link"]));
60
61 if ($doc) {
62 $xpath = new DOMXPath($doc);
63 $entries = $xpath->query('(//div[@class="post"])');
64
65 $basenode = false;
66
67 foreach ($entries as $entry) {
68 $basenode = $entry;
69 }
70
71 $uninteresting = $xpath->query('(//div[@class="heading"])');
72 foreach ($uninteresting as $i) {
73 $i->parentNode->removeChild($i);
74 }
75
76 if ($basenode){
77 $article["content"] = $doc->saveXML($basenode);
78 $article["plugin_data"] = "pennyarcade,$owner_uid:" . $article["plugin_data"];
79 }
80 }
81 } else if (isset($article["stored"]["content"])) {
82 $article["content"] = $article["stored"]["content"];
83 }
84 }
85
86 return $article;
87 }
88 }
89 ?>