]>
Commit | Line | Data |
---|---|---|
901dd67a AD |
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 | $owner_uid = $article["owner_uid"]; | |
10 | ||
11 | if (strpos($article["link"], "penny-arcade.com") !== FALSE && strpos($article["title"], "Comic:") !== FALSE) { | |
12 | if (strpos($article["plugin_data"], "af_comics,$owner_uid:") === FALSE) { | |
13 | ||
14 | if ($debug_enabled) { | |
15 | _debug("af_pennyarcade: Processing comic"); | |
16 | } | |
17 | ||
18 | $doc = new DOMDocument(); | |
19 | $doc->loadHTML(fetch_file_contents($article["link"])); | |
20 | ||
21 | $basenode = false; | |
22 | ||
23 | if ($doc) { | |
24 | $xpath = new DOMXPath($doc); | |
25 | $basenode = $xpath->query('(//div[@id="comicFrame"])')->item(0); | |
26 | ||
27 | if ($basenode) { | |
28 | $article["content"] = $doc->saveXML($basenode); | |
29 | $article["plugin_data"] = "af_comics,$owner_uid:" . $article["plugin_data"]; | |
30 | } | |
31 | } | |
32 | } else if (isset($article["stored"]["content"])) { | |
33 | $article["content"] = $article["stored"]["content"]; | |
34 | } | |
35 | ||
36 | return true; | |
37 | } | |
38 | ||
39 | if (strpos($article["link"], "penny-arcade.com") !== FALSE && strpos($article["title"], "News Post:") !== FALSE) { | |
40 | if (strpos($article["plugin_data"], "af_comics,$owner_uid:") === FALSE) { | |
41 | if ($debug_enabled) { | |
42 | _debug("af_pennyarcade: Processing news post"); | |
43 | } | |
44 | $doc = new DOMDocument(); | |
45 | $doc->loadHTML(fetch_file_contents($article["link"])); | |
46 | ||
47 | if ($doc) { | |
48 | $xpath = new DOMXPath($doc); | |
49 | $entries = $xpath->query('(//div[@class="post"])'); | |
50 | ||
51 | $basenode = false; | |
52 | ||
53 | foreach ($entries as $entry) { | |
54 | $basenode = $entry; | |
55 | } | |
56 | ||
57 | $meta = $xpath->query('(//div[@class="meta"])')->item(0); | |
58 | if ($meta->parentNode) { $meta->parentNode->removeChild($meta); } | |
59 | ||
60 | $header = $xpath->query('(//div[@class="postBody"]/h2)')->item(0); | |
61 | if ($header->parentNode) { $header->parentNode->removeChild($header); } | |
62 | ||
63 | $header = $xpath->query('(//div[@class="postBody"]/div[@class="comicPost"])')->item(0); | |
64 | if ($header->parentNode) { $header->parentNode->removeChild($header); } | |
65 | ||
66 | $avatar = $xpath->query('(//div[@class="avatar"]//img)')->item(0); | |
67 | $basenode->insertBefore($avatar, $basenode->firstChild); | |
68 | ||
69 | $uninteresting = $xpath->query('(//div[@class="avatar"])'); | |
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"] = "af_comics,$owner_uid:" . $article["plugin_data"]; | |
77 | } | |
78 | } | |
79 | } else if (isset($article["stored"]["content"])) { | |
80 | $article["content"] = $article["stored"]["content"]; | |
81 | } | |
82 | ||
83 | return true; | |
84 | } | |
85 | ||
86 | return false; | |
87 | } | |
88 | } | |
89 | ?> |