]>
Commit | Line | Data |
---|---|---|
de0d8d10 AD |
1 | <?php |
2 | class 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> | |
52265e19 | 30 | <li>Ctrl+Alt+Del</li> |
de0d8d10 AD |
31 | <li>Dilbert</li> |
32 | <li>Explosm</li> | |
33 | <li>GoComics</li> | |
f826070c | 34 | <li>Happy Jar</li> |
de0d8d10 AD |
35 | <li>Penny Arcade</li> |
36 | <li>Three word phrase</li> | |
37 | <li>Whomp</li>"; | |
38 | print "</ul>"; | |
39 | ||
40 | print "</div>"; | |
41 | } | |
42 | ||
43 | function hook_article_filter($article) { | |
44 | $owner_uid = $article["owner_uid"]; | |
45 | ||
46 | $found = false; | |
47 | ||
48 | # div#comic - comicpress? | |
49 | ||
50 | if (strpos($article["guid"], "bunicomic.com") !== FALSE || | |
51 | strpos($article["guid"], "buttersafe.com") !== FALSE || | |
52 | strpos($article["guid"], "whompcomic.com") !== FALSE || | |
f826070c | 53 | strpos($article["guid"], "happyjar.com") !== FALSE || |
de0d8d10 AD |
54 | strpos($article["guid"], "csectioncomics.com") !== FALSE) { |
55 | ||
56 | if (strpos($article["plugin_data"], "af_comics,$owner_uid:") === FALSE) { | |
57 | ||
f826070c AD |
58 | |
59 | // lol at people who block clients by user agent | |
60 | // oh noes my ad revenue Q_Q | |
61 | ||
62 | $res = fetch_file_contents($article["link"], false, false, false, | |
63 | false, false, 0, | |
64 | "Mozilla/5.0 (compatible; MSIE 10.0; Windows NT 6.1; WOW64; Trident/6.0)"); | |
65 | ||
de0d8d10 | 66 | $doc = new DOMDocument(); |
f826070c | 67 | @$doc->loadHTML($res); |
de0d8d10 AD |
68 | |
69 | $basenode = false; | |
70 | ||
71 | if ($doc) { | |
72 | $xpath = new DOMXPath($doc); | |
73 | $basenode = $xpath->query('//div[@id="comic"]')->item(0); | |
74 | ||
75 | if ($basenode) { | |
76 | $article["content"] = $doc->saveXML($basenode); | |
77 | $article["plugin_data"] = "af_comics,$owner_uid:" . $article["plugin_data"]; | |
78 | } | |
79 | } | |
80 | } else if (isset($article["stored"]["content"])) { | |
81 | $article["content"] = $article["stored"]["content"]; | |
82 | } | |
83 | } | |
84 | ||
85 | if (strpos($article["guid"], "dilbert.com") !== FALSE) { | |
86 | if (strpos($article["plugin_data"], "af_comics,$owner_uid:") === FALSE) { | |
87 | $doc = new DOMDocument(); | |
88 | @$doc->loadHTML(fetch_file_contents($article["link"])); | |
89 | ||
90 | $basenode = false; | |
91 | ||
92 | if ($doc) { | |
93 | $xpath = new DOMXPath($doc); | |
94 | $entries = $xpath->query('(//img[@src])'); // we might also check for img[@class='strip'] I guess... | |
95 | ||
96 | $matches = array(); | |
97 | ||
98 | foreach ($entries as $entry) { | |
99 | ||
100 | if (preg_match("/dyn\/str_strip\/.*zoom\.gif$/", $entry->getAttribute("src"), $matches)) { | |
101 | ||
102 | $entry->setAttribute("src", | |
103 | rewrite_relative_url("http://dilbert.com/", | |
104 | $matches[0])); | |
105 | ||
106 | $basenode = $entry; | |
107 | break; | |
108 | } | |
109 | } | |
110 | ||
111 | if ($basenode) { | |
112 | $article["content"] = $doc->saveXML($basenode); | |
113 | $article["plugin_data"] = "af_comics,$owner_uid:" . $article["plugin_data"]; | |
114 | } | |
115 | } | |
116 | } else if (isset($article["stored"]["content"])) { | |
117 | $article["content"] = $article["stored"]["content"]; | |
118 | } | |
119 | } | |
120 | ||
121 | if (strpos($article["link"], "explosm.net/comics") !== FALSE) { | |
122 | if (strpos($article["plugin_data"], "af_comics,$owner_uid:") === FALSE) { | |
123 | ||
124 | $doc = new DOMDocument(); | |
125 | @$doc->loadHTML(fetch_file_contents($article["link"])); | |
126 | ||
127 | $basenode = false; | |
128 | ||
129 | if ($doc) { | |
130 | $xpath = new DOMXPath($doc); | |
131 | $entries = $xpath->query('(//img[@src])'); // we might also check for img[@class='strip'] I guess... | |
132 | ||
133 | $matches = array(); | |
134 | ||
135 | foreach ($entries as $entry) { | |
136 | ||
137 | if (preg_match("/(http:\/\/.*\/db\/files\/Comics\/.*)/i", $entry->getAttribute("src"), $matches)) { | |
138 | ||
139 | $basenode = $entry; | |
140 | break; | |
141 | } | |
142 | } | |
143 | ||
144 | if ($basenode) { | |
145 | $article["content"] = $doc->saveXML($basenode); | |
146 | $article["plugin_data"] = "af_comics,$owner_uid:" . $article["plugin_data"]; | |
147 | } | |
148 | } | |
149 | } else if (isset($article["stored"]["content"])) { | |
150 | $article["content"] = $article["stored"]["content"]; | |
52265e19 AD |
151 | } |
152 | } | |
153 | ||
154 | if (strpos($article["link"], "cad-comic.com/cad/") !== FALSE) { | |
155 | if (strpos($article["plugin_data"], "af_comics,$owner_uid:") === FALSE) { | |
156 | ||
157 | $doc = new DOMDocument(); | |
158 | @$doc->loadHTML(fetch_file_contents($article["link"])); | |
159 | ||
160 | $basenode = false; | |
161 | ||
162 | if ($doc) { | |
163 | $xpath = new DOMXPath($doc); | |
164 | $basenode = $xpath->query('(//img[contains(@src, "/comics/cad-")])')->item(0); | |
165 | ||
166 | if ($basenode) { | |
167 | $article["content"] = $doc->saveXML($basenode); | |
168 | $article["plugin_data"] = "af_comics,$owner_uid:" . $article["plugin_data"]; | |
169 | } | |
170 | } | |
171 | ||
172 | } else if (isset($article["stored"]["content"])) { | |
173 | $article["content"] = $article["stored"]["content"]; | |
de0d8d10 AD |
174 | } |
175 | } | |
176 | ||
177 | if (strpos($article["guid"], "gocomics.com") !== FALSE) { | |
178 | if (strpos($article["plugin_data"], "af_comics,$owner_uid:") === FALSE) { | |
179 | $doc = new DOMDocument(); | |
180 | @$doc->loadHTML(fetch_file_contents($article["link"])); | |
181 | ||
182 | $basenode = false; | |
183 | ||
184 | if ($doc) { | |
185 | $xpath = new DOMXPath($doc); | |
186 | $entries = $xpath->query('(//img[@src])'); // we might also check for img[@class='strip'] I guess... | |
187 | ||
188 | $matches = array(); | |
189 | ||
190 | foreach ($entries as $entry) { | |
191 | ||
192 | if (preg_match("/(http:\/\/assets.amuniversal.com\/.*width.*)/i", $entry->getAttribute("src"), $matches)) { | |
193 | ||
194 | $entry->setAttribute("src", $matches[0]); | |
195 | $basenode = $entry; | |
196 | break; | |
197 | } | |
198 | } | |
199 | ||
200 | if (!$basenode) { | |
201 | // fallback on the smaller version | |
202 | foreach ($entries as $entry) { | |
203 | ||
204 | if (preg_match("/(http:\/\/assets.amuniversal.com\/.*)/i", $entry->getAttribute("src"), $matches)) { | |
205 | ||
206 | $entry->setAttribute("src", $matches[0]); | |
207 | $basenode = $entry; | |
208 | break; | |
209 | } | |
210 | } | |
211 | } | |
212 | ||
213 | if ($basenode) { | |
214 | $article["content"] = $doc->saveXML($basenode); | |
215 | $article["plugin_data"] = "af_comics,$owner_uid:" . $article["plugin_data"]; | |
216 | } | |
217 | } | |
218 | } else if (isset($article["stored"]["content"])) { | |
219 | $article["content"] = $article["stored"]["content"]; | |
220 | } | |
221 | } | |
222 | ||
223 | if (strpos($article["link"], "penny-arcade.com") !== FALSE && strpos($article["title"], "Comic:") !== FALSE) { | |
224 | if (strpos($article["plugin_data"], "af_comics,$owner_uid:") === FALSE) { | |
225 | ||
226 | if ($debug_enabled) { | |
227 | _debug("af_pennyarcade: Processing comic"); | |
228 | } | |
229 | ||
230 | $doc = new DOMDocument(); | |
231 | $doc->loadHTML(fetch_file_contents($article["link"])); | |
232 | ||
233 | $basenode = false; | |
234 | ||
235 | if ($doc) { | |
236 | $xpath = new DOMXPath($doc); | |
abe24e39 | 237 | $basenode = $xpath->query('(//div[@id="comicFrame"])')->item(0); |
de0d8d10 AD |
238 | |
239 | if ($basenode) { | |
240 | $article["content"] = $doc->saveXML($basenode); | |
241 | $article["plugin_data"] = "af_comics,$owner_uid:" . $article["plugin_data"]; | |
242 | } | |
243 | } | |
244 | } else if (isset($article["stored"]["content"])) { | |
245 | $article["content"] = $article["stored"]["content"]; | |
246 | } | |
247 | } | |
248 | ||
249 | if (strpos($article["link"], "penny-arcade.com") !== FALSE && strpos($article["title"], "News Post:") !== FALSE) { | |
250 | if (strpos($article["plugin_data"], "af_comics,$owner_uid:") === FALSE) { | |
251 | if ($debug_enabled) { | |
252 | _debug("af_pennyarcade: Processing news post"); | |
253 | } | |
254 | $doc = new DOMDocument(); | |
255 | $doc->loadHTML(fetch_file_contents($article["link"])); | |
256 | ||
257 | if ($doc) { | |
258 | $xpath = new DOMXPath($doc); | |
259 | $entries = $xpath->query('(//div[@class="post"])'); | |
260 | ||
261 | $basenode = false; | |
262 | ||
263 | foreach ($entries as $entry) { | |
264 | $basenode = $entry; | |
265 | } | |
266 | ||
267 | $uninteresting = $xpath->query('(//div[@class="heading"])'); | |
268 | foreach ($uninteresting as $i) { | |
269 | $i->parentNode->removeChild($i); | |
270 | } | |
271 | ||
272 | if ($basenode){ | |
273 | $article["content"] = $doc->saveXML($basenode); | |
274 | $article["plugin_data"] = "af_comics,$owner_uid:" . $article["plugin_data"]; | |
275 | } | |
276 | } | |
277 | } else if (isset($article["stored"]["content"])) { | |
278 | $article["content"] = $article["stored"]["content"]; | |
279 | } | |
280 | } | |
281 | ||
282 | if (strpos($article["link"], "threewordphrase.com") !== FALSE) { | |
283 | if (strpos($article["plugin_data"], "af_comics,$owner_uid:") === FALSE) { | |
284 | ||
285 | $doc = new DOMDocument(); | |
286 | @$doc->loadHTML(fetch_file_contents($article["link"])); | |
287 | ||
288 | $basenode = false; | |
289 | ||
290 | if ($doc) { | |
291 | $xpath = new DOMXpath($doc); | |
292 | ||
293 | $basenode = $xpath->query("//td/center/img")->item(0); | |
294 | ||
295 | if ($basenode) { | |
296 | $article["content"] = $doc->saveXML($basenode); | |
297 | $article["plugin_data"] = "af_comics,$owner_uid:" . $article["plugin_data"]; | |
298 | } | |
299 | } | |
300 | } else if (isset($article["stored"]["content"])) { | |
301 | $article["content"] = $article["stored"]["content"]; | |
302 | } | |
303 | } | |
304 | ||
305 | return $article; | |
306 | } | |
307 | ||
308 | function api_version() { | |
309 | return 2; | |
310 | } | |
311 | ||
312 | } | |
313 | ?> |