]>
git.wh0rd.org - tt-rss.git/blob - plugins/af_comics/init.php
2 class Af_Comics
extends Plugin
{
8 "Fixes RSS feeds of assorted comic strips",
12 function init($host) {
15 $host->add_hook($host::HOOK_ARTICLE_FILTER
, $this);
16 $host->add_hook($host::HOOK_PREFS_TAB
, $this);
19 function hook_prefs_tab($args) {
20 if ($args != "prefPrefs") return;
22 print "<div dojoType=\"dijit.layout.AccordionPane\" title=\"".__('Feeds supported by af_comics')."\">";
24 print_notice("This plugin supports the following comics:");
26 print "<ul class=\"browseFeedList\" style=\"border-width : 1px\">";
36 <li>Three word phrase</li>
43 function hook_article_filter($article) {
44 $owner_uid = $article["owner_uid"];
48 # div#comic - comicpress?
50 if (strpos($article["guid"], "bunicomic.com") !== FALSE ||
51 strpos($article["guid"], "buttersafe.com") !== FALSE ||
52 strpos($article["guid"], "whompcomic.com") !== FALSE ||
53 strpos($article["guid"], "happyjar.com") !== FALSE ||
54 strpos($article["guid"], "csectioncomics.com") !== FALSE) {
56 if (strpos($article["plugin_data"], "af_comics,$owner_uid:") === FALSE) {
59 // lol at people who block clients by user agent
60 // oh noes my ad revenue Q_Q
62 $res = fetch_file_contents($article["link"], false, false, false,
64 "Mozilla/5.0 (compatible; MSIE 10.0; Windows NT 6.1; WOW64; Trident/6.0)");
66 $doc = new DOMDocument();
67 @$doc->loadHTML($res);
72 $xpath = new DOMXPath($doc);
73 $basenode = $xpath->query('//div[@id="comic"]')->item(0);
76 $article["content"] = $doc->saveXML($basenode);
77 $article["plugin_data"] = "af_comics,$owner_uid:" . $article["plugin_data"];
80 } else if (isset($article["stored"]["content"])) {
81 $article["content"] = $article["stored"]["content"];
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"]));
93 $xpath = new DOMXPath($doc);
94 $entries = $xpath->query('(//img[@src])'); // we might also check for img[@class='strip'] I guess...
98 foreach ($entries as $entry) {
100 if (preg_match("/dyn\/str_strip\/.*zoom\.gif$/", $entry->getAttribute("src"), $matches)) {
102 $entry->setAttribute("src",
103 rewrite_relative_url("http://dilbert.com/",
112 $article["content"] = $doc->saveXML($basenode);
113 $article["plugin_data"] = "af_comics,$owner_uid:" . $article["plugin_data"];
116 } else if (isset($article["stored"]["content"])) {
117 $article["content"] = $article["stored"]["content"];
121 if (strpos($article["link"], "explosm.net/comics") !== FALSE) {
122 if (strpos($article["plugin_data"], "af_comics,$owner_uid:") === FALSE) {
124 $doc = new DOMDocument();
125 @$doc->loadHTML(fetch_file_contents($article["link"]));
130 $xpath = new DOMXPath($doc);
131 $entries = $xpath->query('(//img[@src])'); // we might also check for img[@class='strip'] I guess...
135 foreach ($entries as $entry) {
137 if (preg_match("/(http:\/\/.*\/db\/files\/Comics\/.*)/i", $entry->getAttribute("src"), $matches)) {
145 $article["content"] = $doc->saveXML($basenode);
146 $article["plugin_data"] = "af_comics,$owner_uid:" . $article["plugin_data"];
149 } else if (isset($article["stored"]["content"])) {
150 $article["content"] = $article["stored"]["content"];
154 if (strpos($article["link"], "cad-comic.com/cad/") !== FALSE) {
155 if (strpos($article["plugin_data"], "af_comics,$owner_uid:") === FALSE) {
157 $doc = new DOMDocument();
158 @$doc->loadHTML(fetch_file_contents($article["link"]));
163 $xpath = new DOMXPath($doc);
164 $basenode = $xpath->query('(//img[contains(@src, "/comics/cad-")])')->item(0);
167 $article["content"] = $doc->saveXML($basenode);
168 $article["plugin_data"] = "af_comics,$owner_uid:" . $article["plugin_data"];
172 } else if (isset($article["stored"]["content"])) {
173 $article["content"] = $article["stored"]["content"];
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"]));
185 $xpath = new DOMXPath($doc);
186 $entries = $xpath->query('(//img[@src])'); // we might also check for img[@class='strip'] I guess...
190 foreach ($entries as $entry) {
192 if (preg_match("/(http:\/\/assets.amuniversal.com\/.*width.*)/i", $entry->getAttribute("src"), $matches)) {
194 $entry->setAttribute("src", $matches[0]);
201 // fallback on the smaller version
202 foreach ($entries as $entry) {
204 if (preg_match("/(http:\/\/assets.amuniversal.com\/.*)/i", $entry->getAttribute("src"), $matches)) {
206 $entry->setAttribute("src", $matches[0]);
214 $article["content"] = $doc->saveXML($basenode);
215 $article["plugin_data"] = "af_comics,$owner_uid:" . $article["plugin_data"];
218 } else if (isset($article["stored"]["content"])) {
219 $article["content"] = $article["stored"]["content"];
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) {
226 if ($debug_enabled) {
227 _debug("af_pennyarcade: Processing comic");
230 $doc = new DOMDocument();
231 $doc->loadHTML(fetch_file_contents($article["link"]));
236 $xpath = new DOMXPath($doc);
237 $basenode = $xpath->query('(//div[@id="comicFrame"])')->item(0);
240 $article["content"] = $doc->saveXML($basenode);
241 $article["plugin_data"] = "af_comics,$owner_uid:" . $article["plugin_data"];
244 } else if (isset($article["stored"]["content"])) {
245 $article["content"] = $article["stored"]["content"];
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");
254 $doc = new DOMDocument();
255 $doc->loadHTML(fetch_file_contents($article["link"]));
258 $xpath = new DOMXPath($doc);
259 $entries = $xpath->query('(//div[@class="post"])');
263 foreach ($entries as $entry) {
267 $meta = $xpath->query('(//div[@class="meta"])')->item(0);
268 if ($meta->parentNode
) { $meta->parentNode
->removeChild($meta); }
270 $header = $xpath->query('(//div[@class="postBody"]/h2)')->item(0);
271 if ($header->parentNode
) { $header->parentNode
->removeChild($header); }
273 $header = $xpath->query('(//div[@class="postBody"]/div[@class="comicPost"])')->item(0);
274 if ($header->parentNode
) { $header->parentNode
->removeChild($header); }
276 $avatar = $xpath->query('(//div[@class="avatar"]//img)')->item(0);
277 $basenode->insertBefore($avatar, $basenode->firstChild
);
279 $uninteresting = $xpath->query('(//div[@class="avatar"])');
280 foreach ($uninteresting as $i) {
281 $i->parentNode
->removeChild($i);
285 $article["content"] = $doc->saveXML($basenode);
286 $article["plugin_data"] = "af_comics,$owner_uid:" . $article["plugin_data"];
289 } else if (isset($article["stored"]["content"])) {
290 $article["content"] = $article["stored"]["content"];
294 if (strpos($article["link"], "threewordphrase.com") !== FALSE) {
295 if (strpos($article["plugin_data"], "af_comics,$owner_uid:") === FALSE) {
297 $doc = new DOMDocument();
298 @$doc->loadHTML(fetch_file_contents($article["link"]));
303 $xpath = new DOMXpath($doc);
305 $basenode = $xpath->query("//td/center/img")->item(0);
308 $article["content"] = $doc->saveXML($basenode);
309 $article["plugin_data"] = "af_comics,$owner_uid:" . $article["plugin_data"];
312 } else if (isset($article["stored"]["content"])) {
313 $article["content"] = $article["stored"]["content"];
320 function api_version() {