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