]>
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\">";
35 <li>Three word phrase</li>
42 function hook_article_filter($article) {
43 $owner_uid = $article["owner_uid"];
47 # div#comic - comicpress?
49 if (strpos($article["guid"], "bunicomic.com") !== FALSE ||
50 strpos($article["guid"], "buttersafe.com") !== FALSE ||
51 strpos($article["guid"], "whompcomic.com") !== FALSE ||
52 strpos($article["guid"], "happyjar.com") !== FALSE ||
53 strpos($article["guid"], "csectioncomics.com") !== FALSE) {
55 if (strpos($article["plugin_data"], "af_comics,$owner_uid:") === FALSE) {
58 // lol at people who block clients by user agent
59 // oh noes my ad revenue Q_Q
61 $res = fetch_file_contents($article["link"], false, false, false,
63 "Mozilla/5.0 (compatible; MSIE 10.0; Windows NT 6.1; WOW64; Trident/6.0)");
65 $doc = new DOMDocument();
66 @$doc->loadHTML($res);
71 $xpath = new DOMXPath($doc);
72 $basenode = $xpath->query('//div[@id="comic"]')->item(0);
75 $article["content"] = $doc->saveXML($basenode);
76 $article["plugin_data"] = "af_comics,$owner_uid:" . $article["plugin_data"];
79 } else if (isset($article["stored"]["content"])) {
80 $article["content"] = $article["stored"]["content"];
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"]));
92 $xpath = new DOMXPath($doc);
93 $entries = $xpath->query('(//img[@src])'); // we might also check for img[@class='strip'] I guess...
97 foreach ($entries as $entry) {
99 if (preg_match("/dyn\/str_strip\/.*zoom\.gif$/", $entry->getAttribute("src"), $matches)) {
101 $entry->setAttribute("src",
102 rewrite_relative_url("http://dilbert.com/",
111 $article["content"] = $doc->saveXML($basenode);
112 $article["plugin_data"] = "af_comics,$owner_uid:" . $article["plugin_data"];
115 } else if (isset($article["stored"]["content"])) {
116 $article["content"] = $article["stored"]["content"];
120 if (strpos($article["link"], "explosm.net/comics") !== FALSE) {
121 if (strpos($article["plugin_data"], "af_comics,$owner_uid:") === FALSE) {
123 $doc = new DOMDocument();
124 @$doc->loadHTML(fetch_file_contents($article["link"]));
129 $xpath = new DOMXPath($doc);
130 $entries = $xpath->query('(//img[@src])'); // we might also check for img[@class='strip'] I guess...
134 foreach ($entries as $entry) {
136 if (preg_match("/(http:\/\/.*\/db\/files\/Comics\/.*)/i", $entry->getAttribute("src"), $matches)) {
144 $article["content"] = $doc->saveXML($basenode);
145 $article["plugin_data"] = "af_comics,$owner_uid:" . $article["plugin_data"];
148 } else if (isset($article["stored"]["content"])) {
149 $article["content"] = $article["stored"]["content"];
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"]));
161 $xpath = new DOMXPath($doc);
162 $entries = $xpath->query('(//img[@src])'); // we might also check for img[@class='strip'] I guess...
166 foreach ($entries as $entry) {
168 if (preg_match("/(http:\/\/assets.amuniversal.com\/.*width.*)/i", $entry->getAttribute("src"), $matches)) {
170 $entry->setAttribute("src", $matches[0]);
177 // fallback on the smaller version
178 foreach ($entries as $entry) {
180 if (preg_match("/(http:\/\/assets.amuniversal.com\/.*)/i", $entry->getAttribute("src"), $matches)) {
182 $entry->setAttribute("src", $matches[0]);
190 $article["content"] = $doc->saveXML($basenode);
191 $article["plugin_data"] = "af_comics,$owner_uid:" . $article["plugin_data"];
194 } else if (isset($article["stored"]["content"])) {
195 $article["content"] = $article["stored"]["content"];
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) {
202 if ($debug_enabled) {
203 _debug("af_pennyarcade: Processing comic");
206 $doc = new DOMDocument();
207 $doc->loadHTML(fetch_file_contents($article["link"]));
212 $xpath = new DOMXPath($doc);
213 $basenode = $xpath->query('(//div[@id="comicFrame"])')->item(0);
216 $article["content"] = $doc->saveXML($basenode);
217 $article["plugin_data"] = "af_comics,$owner_uid:" . $article["plugin_data"];
220 } else if (isset($article["stored"]["content"])) {
221 $article["content"] = $article["stored"]["content"];
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");
230 $doc = new DOMDocument();
231 $doc->loadHTML(fetch_file_contents($article["link"]));
234 $xpath = new DOMXPath($doc);
235 $entries = $xpath->query('(//div[@class="post"])');
239 foreach ($entries as $entry) {
243 $meta = $xpath->query('(//div[@class="meta"])')->item(0);
244 if ($meta->parentNode
) { $meta->parentNode
->removeChild($meta); }
246 $header = $xpath->query('(//div[@class="postBody"]/h2)')->item(0);
247 if ($header->parentNode
) { $header->parentNode
->removeChild($header); }
249 $header = $xpath->query('(//div[@class="postBody"]/div[@class="comicPost"])')->item(0);
250 if ($header->parentNode
) { $header->parentNode
->removeChild($header); }
252 $avatar = $xpath->query('(//div[@class="avatar"]//img)')->item(0);
253 $basenode->insertBefore($avatar, $basenode->firstChild
);
255 $uninteresting = $xpath->query('(//div[@class="avatar"])');
256 foreach ($uninteresting as $i) {
257 $i->parentNode
->removeChild($i);
261 $article["content"] = $doc->saveXML($basenode);
262 $article["plugin_data"] = "af_comics,$owner_uid:" . $article["plugin_data"];
265 } else if (isset($article["stored"]["content"])) {
266 $article["content"] = $article["stored"]["content"];
270 if (strpos($article["link"], "threewordphrase.com") !== FALSE) {
271 if (strpos($article["plugin_data"], "af_comics,$owner_uid:") === FALSE) {
273 $doc = new DOMDocument();
274 @$doc->loadHTML(fetch_file_contents($article["link"]));
279 $xpath = new DOMXpath($doc);
281 $basenode = $xpath->query("//td/center/img")->item(0);
284 $article["content"] = $doc->saveXML($basenode);
285 $article["plugin_data"] = "af_comics,$owner_uid:" . $article["plugin_data"];
288 } else if (isset($article["stored"]["content"])) {
289 $article["content"] = $article["stored"]["content"];
296 function api_version() {