]> git.wh0rd.org - tt-rss.git/blob - plugins/af_comics/filters/af_comics_pa.php
plugins: remove obsolete plugin_data/stored stuff
[tt-rss.git] / plugins / af_comics / filters / af_comics_pa.php
1 <?php
2 class Af_Comics_Pa extends Af_ComicFilter {
3
4 function supported() {
5 return array("Penny Arcade");
6 }
7
8 function process(&$article) {
9 if (strpos($article["link"], "penny-arcade.com") !== FALSE && strpos($article["title"], "Comic:") !== FALSE) {
10
11 if ($debug_enabled) {
12 _debug("af_pennyarcade: Processing comic");
13 }
14
15 $doc = new DOMDocument();
16 $doc->loadHTML(fetch_file_contents($article["link"]));
17
18 $basenode = false;
19
20 if ($doc) {
21 $xpath = new DOMXPath($doc);
22 $basenode = $xpath->query('(//div[@id="comicFrame"])')->item(0);
23
24 if ($basenode) {
25 $article["content"] = $doc->saveXML($basenode);
26 }
27 }
28
29 return true;
30 }
31
32 if (strpos($article["link"], "penny-arcade.com") !== FALSE && strpos($article["title"], "News Post:") !== FALSE) {
33 if ($debug_enabled) {
34 _debug("af_pennyarcade: Processing news post");
35 }
36 $doc = new DOMDocument();
37 $doc->loadHTML(fetch_file_contents($article["link"]));
38
39 if ($doc) {
40 $xpath = new DOMXPath($doc);
41 $entries = $xpath->query('(//div[@class="post"])');
42
43 $basenode = false;
44
45 foreach ($entries as $entry) {
46 $basenode = $entry;
47 }
48
49 $meta = $xpath->query('(//div[@class="meta"])')->item(0);
50 if ($meta->parentNode) { $meta->parentNode->removeChild($meta); }
51
52 $header = $xpath->query('(//div[@class="postBody"]/h2)')->item(0);
53 if ($header->parentNode) { $header->parentNode->removeChild($header); }
54
55 $header = $xpath->query('(//div[@class="postBody"]/div[@class="comicPost"])')->item(0);
56 if ($header->parentNode) { $header->parentNode->removeChild($header); }
57
58 $avatar = $xpath->query('(//div[@class="avatar"]//img)')->item(0);
59 $basenode->insertBefore($avatar, $basenode->firstChild);
60
61 $uninteresting = $xpath->query('(//div[@class="avatar"])');
62 foreach ($uninteresting as $i) {
63 $i->parentNode->removeChild($i);
64 }
65
66 if ($basenode){
67 $article["content"] = $doc->saveXML($basenode);
68 }
69 }
70
71 return true;
72 }
73
74 return false;
75 }
76 }
77 ?>