]> git.wh0rd.org - tt-rss.git/blame - plugins/af_comics/init.php
af_comics: add happyjar
[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);
213 $entries = $xpath->query('(//div[@class="post comic"])');
214
215 foreach ($entries as $entry) {
216 $basenode = $entry;
217 }
218
219 if ($basenode) {
220 $article["content"] = $doc->saveXML($basenode);
221 $article["plugin_data"] = "af_comics,$owner_uid:" . $article["plugin_data"];
222 }
223 }
224 } else if (isset($article["stored"]["content"])) {
225 $article["content"] = $article["stored"]["content"];
226 }
227 }
228
229 if (strpos($article["link"], "penny-arcade.com") !== FALSE && strpos($article["title"], "News Post:") !== FALSE) {
230 if (strpos($article["plugin_data"], "af_comics,$owner_uid:") === FALSE) {
231 if ($debug_enabled) {
232 _debug("af_pennyarcade: Processing news post");
233 }
234 $doc = new DOMDocument();
235 $doc->loadHTML(fetch_file_contents($article["link"]));
236
237 if ($doc) {
238 $xpath = new DOMXPath($doc);
239 $entries = $xpath->query('(//div[@class="post"])');
240
241 $basenode = false;
242
243 foreach ($entries as $entry) {
244 $basenode = $entry;
245 }
246
247 $uninteresting = $xpath->query('(//div[@class="heading"])');
248 foreach ($uninteresting as $i) {
249 $i->parentNode->removeChild($i);
250 }
251
252 if ($basenode){
253 $article["content"] = $doc->saveXML($basenode);
254 $article["plugin_data"] = "af_comics,$owner_uid:" . $article["plugin_data"];
255 }
256 }
257 } else if (isset($article["stored"]["content"])) {
258 $article["content"] = $article["stored"]["content"];
259 }
260 }
261
262 if (strpos($article["link"], "threewordphrase.com") !== FALSE) {
263 if (strpos($article["plugin_data"], "af_comics,$owner_uid:") === FALSE) {
264
265 $doc = new DOMDocument();
266 @$doc->loadHTML(fetch_file_contents($article["link"]));
267
268 $basenode = false;
269
270 if ($doc) {
271 $xpath = new DOMXpath($doc);
272
273 $basenode = $xpath->query("//td/center/img")->item(0);
274
275 if ($basenode) {
276 $article["content"] = $doc->saveXML($basenode);
277 $article["plugin_data"] = "af_comics,$owner_uid:" . $article["plugin_data"];
278 }
279 }
280 } else if (isset($article["stored"]["content"])) {
281 $article["content"] = $article["stored"]["content"];
282 }
283 }
284
285 return $article;
286 }
287
288 function api_version() {
289 return 2;
290 }
291
292}
293?>