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