]> git.wh0rd.org - tt-rss.git/blame - plugins/af_comics/init.php
af_comics: fix for PA new layout
[tt-rss.git] / plugins / af_comics / init.php
CommitLineData
de0d8d10
AD
1<?php
2class Af_Comics extends Plugin {
3
4 private $host;
5
6 function about() {
7 return array(1.0,
8 "Fixes RSS feeds of assorted comic strips",
9 "fox");
10 }
11
12 function init($host) {
13 $this->host = $host;
14
15 $host->add_hook($host::HOOK_ARTICLE_FILTER, $this);
16 $host->add_hook($host::HOOK_PREFS_TAB, $this);
17 }
18
19 function hook_prefs_tab($args) {
20 if ($args != "prefPrefs") return;
21
22 print "<div dojoType=\"dijit.layout.AccordionPane\" title=\"".__('Feeds supported by af_comics')."\">";
23
24 print_notice("This plugin supports the following comics:");
25
26 print "<ul class=\"browseFeedList\" style=\"border-width : 1px\">";
27 print "<li>Buni</li>
28 <li>Buttersafe</li>
29 <li>CSection</li>
30 <li>Dilbert</li>
31 <li>Explosm</li>
32 <li>GoComics</li>
f826070c 33 <li>Happy Jar</li>
de0d8d10
AD
34 <li>Penny Arcade</li>
35 <li>Three word phrase</li>
36 <li>Whomp</li>";
37 print "</ul>";
38
39 print "</div>";
40 }
41
42 function hook_article_filter($article) {
43 $owner_uid = $article["owner_uid"];
44
45 $found = false;
46
47 # div#comic - comicpress?
48
49 if (strpos($article["guid"], "bunicomic.com") !== FALSE ||
50 strpos($article["guid"], "buttersafe.com") !== FALSE ||
51 strpos($article["guid"], "whompcomic.com") !== FALSE ||
f826070c 52 strpos($article["guid"], "happyjar.com") !== FALSE ||
de0d8d10
AD
53 strpos($article["guid"], "csectioncomics.com") !== FALSE) {
54
55 if (strpos($article["plugin_data"], "af_comics,$owner_uid:") === FALSE) {
56
f826070c
AD
57
58 // lol at people who block clients by user agent
59 // oh noes my ad revenue Q_Q
60
61 $res = fetch_file_contents($article["link"], false, false, false,
62 false, false, 0,
63 "Mozilla/5.0 (compatible; MSIE 10.0; Windows NT 6.1; WOW64; Trident/6.0)");
64
de0d8d10 65 $doc = new DOMDocument();
f826070c 66 @$doc->loadHTML($res);
de0d8d10
AD
67
68 $basenode = false;
69
70 if ($doc) {
71 $xpath = new DOMXPath($doc);
72 $basenode = $xpath->query('//div[@id="comic"]')->item(0);
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
84 if (strpos($article["guid"], "dilbert.com") !== FALSE) {
85 if (strpos($article["plugin_data"], "af_comics,$owner_uid:") === FALSE) {
86 $doc = new DOMDocument();
87 @$doc->loadHTML(fetch_file_contents($article["link"]));
88
89 $basenode = false;
90
91 if ($doc) {
92 $xpath = new DOMXPath($doc);
93 $entries = $xpath->query('(//img[@src])'); // we might also check for img[@class='strip'] I guess...
94
95 $matches = array();
96
97 foreach ($entries as $entry) {
98
99 if (preg_match("/dyn\/str_strip\/.*zoom\.gif$/", $entry->getAttribute("src"), $matches)) {
100
101 $entry->setAttribute("src",
102 rewrite_relative_url("http://dilbert.com/",
103 $matches[0]));
104
105 $basenode = $entry;
106 break;
107 }
108 }
109
110 if ($basenode) {
111 $article["content"] = $doc->saveXML($basenode);
112 $article["plugin_data"] = "af_comics,$owner_uid:" . $article["plugin_data"];
113 }
114 }
115 } else if (isset($article["stored"]["content"])) {
116 $article["content"] = $article["stored"]["content"];
117 }
118 }
119
120 if (strpos($article["link"], "explosm.net/comics") !== FALSE) {
121 if (strpos($article["plugin_data"], "af_comics,$owner_uid:") === FALSE) {
122
123 $doc = new DOMDocument();
124 @$doc->loadHTML(fetch_file_contents($article["link"]));
125
126 $basenode = false;
127
128 if ($doc) {
129 $xpath = new DOMXPath($doc);
130 $entries = $xpath->query('(//img[@src])'); // we might also check for img[@class='strip'] I guess...
131
132 $matches = array();
133
134 foreach ($entries as $entry) {
135
136 if (preg_match("/(http:\/\/.*\/db\/files\/Comics\/.*)/i", $entry->getAttribute("src"), $matches)) {
137
138 $basenode = $entry;
139 break;
140 }
141 }
142
143 if ($basenode) {
144 $article["content"] = $doc->saveXML($basenode);
145 $article["plugin_data"] = "af_comics,$owner_uid:" . $article["plugin_data"];
146 }
147 }
148 } else if (isset($article["stored"]["content"])) {
149 $article["content"] = $article["stored"]["content"];
150 }
151 }
152
153 if (strpos($article["guid"], "gocomics.com") !== FALSE) {
154 if (strpos($article["plugin_data"], "af_comics,$owner_uid:") === FALSE) {
155 $doc = new DOMDocument();
156 @$doc->loadHTML(fetch_file_contents($article["link"]));
157
158 $basenode = false;
159
160 if ($doc) {
161 $xpath = new DOMXPath($doc);
162 $entries = $xpath->query('(//img[@src])'); // we might also check for img[@class='strip'] I guess...
163
164 $matches = array();
165
166 foreach ($entries as $entry) {
167
168 if (preg_match("/(http:\/\/assets.amuniversal.com\/.*width.*)/i", $entry->getAttribute("src"), $matches)) {
169
170 $entry->setAttribute("src", $matches[0]);
171 $basenode = $entry;
172 break;
173 }
174 }
175
176 if (!$basenode) {
177 // fallback on the smaller version
178 foreach ($entries as $entry) {
179
180 if (preg_match("/(http:\/\/assets.amuniversal.com\/.*)/i", $entry->getAttribute("src"), $matches)) {
181
182 $entry->setAttribute("src", $matches[0]);
183 $basenode = $entry;
184 break;
185 }
186 }
187 }
188
189 if ($basenode) {
190 $article["content"] = $doc->saveXML($basenode);
191 $article["plugin_data"] = "af_comics,$owner_uid:" . $article["plugin_data"];
192 }
193 }
194 } else if (isset($article["stored"]["content"])) {
195 $article["content"] = $article["stored"]["content"];
196 }
197 }
198
199 if (strpos($article["link"], "penny-arcade.com") !== FALSE && strpos($article["title"], "Comic:") !== FALSE) {
200 if (strpos($article["plugin_data"], "af_comics,$owner_uid:") === FALSE) {
201
202 if ($debug_enabled) {
203 _debug("af_pennyarcade: Processing comic");
204 }
205
206 $doc = new DOMDocument();
207 $doc->loadHTML(fetch_file_contents($article["link"]));
208
209 $basenode = false;
210
211 if ($doc) {
212 $xpath = new DOMXPath($doc);
abe24e39 213 $basenode = $xpath->query('(//div[@id="comicFrame"])')->item(0);
de0d8d10
AD
214
215 if ($basenode) {
216 $article["content"] = $doc->saveXML($basenode);
217 $article["plugin_data"] = "af_comics,$owner_uid:" . $article["plugin_data"];
218 }
219 }
220 } else if (isset($article["stored"]["content"])) {
221 $article["content"] = $article["stored"]["content"];
222 }
223 }
224
225 if (strpos($article["link"], "penny-arcade.com") !== FALSE && strpos($article["title"], "News Post:") !== FALSE) {
226 if (strpos($article["plugin_data"], "af_comics,$owner_uid:") === FALSE) {
227 if ($debug_enabled) {
228 _debug("af_pennyarcade: Processing news post");
229 }
230 $doc = new DOMDocument();
231 $doc->loadHTML(fetch_file_contents($article["link"]));
232
233 if ($doc) {
234 $xpath = new DOMXPath($doc);
235 $entries = $xpath->query('(//div[@class="post"])');
236
237 $basenode = false;
238
239 foreach ($entries as $entry) {
240 $basenode = $entry;
241 }
242
243 $uninteresting = $xpath->query('(//div[@class="heading"])');
244 foreach ($uninteresting as $i) {
245 $i->parentNode->removeChild($i);
246 }
247
248 if ($basenode){
249 $article["content"] = $doc->saveXML($basenode);
250 $article["plugin_data"] = "af_comics,$owner_uid:" . $article["plugin_data"];
251 }
252 }
253 } else if (isset($article["stored"]["content"])) {
254 $article["content"] = $article["stored"]["content"];
255 }
256 }
257
258 if (strpos($article["link"], "threewordphrase.com") !== FALSE) {
259 if (strpos($article["plugin_data"], "af_comics,$owner_uid:") === FALSE) {
260
261 $doc = new DOMDocument();
262 @$doc->loadHTML(fetch_file_contents($article["link"]));
263
264 $basenode = false;
265
266 if ($doc) {
267 $xpath = new DOMXpath($doc);
268
269 $basenode = $xpath->query("//td/center/img")->item(0);
270
271 if ($basenode) {
272 $article["content"] = $doc->saveXML($basenode);
273 $article["plugin_data"] = "af_comics,$owner_uid:" . $article["plugin_data"];
274 }
275 }
276 } else if (isset($article["stored"]["content"])) {
277 $article["content"] = $article["stored"]["content"];
278 }
279 }
280
281 return $article;
282 }
283
284 function api_version() {
285 return 2;
286 }
287
288}
289?>