]>
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 $entries = $xpath->query('(//div[@class="post comic"])');
215 foreach ($entries as $entry) {
220 $article["content"] = $doc->saveXML($basenode);
221 $article["plugin_data"] = "af_comics,$owner_uid:" . $article["plugin_data"];
224 } else if (isset($article["stored"]["content"])) {
225 $article["content"] = $article["stored"]["content"];
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");
234 $doc = new DOMDocument();
235 $doc->loadHTML(fetch_file_contents($article["link"]));
238 $xpath = new DOMXPath($doc);
239 $entries = $xpath->query('(//div[@class="post"])');
243 foreach ($entries as $entry) {
247 $uninteresting = $xpath->query('(//div[@class="heading"])');
248 foreach ($uninteresting as $i) {
249 $i->parentNode
->removeChild($i);
253 $article["content"] = $doc->saveXML($basenode);
254 $article["plugin_data"] = "af_comics,$owner_uid:" . $article["plugin_data"];
257 } else if (isset($article["stored"]["content"])) {
258 $article["content"] = $article["stored"]["content"];
262 if (strpos($article["link"], "threewordphrase.com") !== FALSE) {
263 if (strpos($article["plugin_data"], "af_comics,$owner_uid:") === FALSE) {
265 $doc = new DOMDocument();
266 @$doc->loadHTML(fetch_file_contents($article["link"]));
271 $xpath = new DOMXpath($doc);
273 $basenode = $xpath->query("//td/center/img")->item(0);
276 $article["content"] = $doc->saveXML($basenode);
277 $article["plugin_data"] = "af_comics,$owner_uid:" . $article["plugin_data"];
280 } else if (isset($article["stored"]["content"])) {
281 $article["content"] = $article["stored"]["content"];
288 function api_version() {