]>
git.wh0rd.org - tt-rss.git/blob - plugins/af_comics/init.php
e8b5a00ccbd4ae0e921a4c94a72ac6844e6c11d5
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\">";
34 <li>Three word phrase</li>
41 function hook_article_filter($article) {
42 $owner_uid = $article["owner_uid"];
46 # div#comic - comicpress?
48 if (strpos($article["guid"], "bunicomic.com") !== FALSE ||
49 strpos($article["guid"], "buttersafe.com") !== FALSE ||
50 strpos($article["guid"], "whompcomic.com") !== FALSE ||
51 strpos($article["guid"], "csectioncomics.com") !== FALSE) {
53 if (strpos($article["plugin_data"], "af_comics,$owner_uid:") === FALSE) {
55 $doc = new DOMDocument();
56 @$doc->loadHTML(fetch_file_contents($article["link"]));
61 $xpath = new DOMXPath($doc);
62 $basenode = $xpath->query('//div[@id="comic"]')->item(0);
65 $article["content"] = $doc->saveXML($basenode);
66 $article["plugin_data"] = "af_comics,$owner_uid:" . $article["plugin_data"];
69 } else if (isset($article["stored"]["content"])) {
70 $article["content"] = $article["stored"]["content"];
74 if (strpos($article["guid"], "dilbert.com") !== FALSE) {
75 if (strpos($article["plugin_data"], "af_comics,$owner_uid:") === FALSE) {
76 $doc = new DOMDocument();
77 @$doc->loadHTML(fetch_file_contents($article["link"]));
82 $xpath = new DOMXPath($doc);
83 $entries = $xpath->query('(//img[@src])'); // we might also check for img[@class='strip'] I guess...
87 foreach ($entries as $entry) {
89 if (preg_match("/dyn\/str_strip\/.*zoom\.gif$/", $entry->getAttribute("src"), $matches)) {
91 $entry->setAttribute("src",
92 rewrite_relative_url("http://dilbert.com/",
101 $article["content"] = $doc->saveXML($basenode);
102 $article["plugin_data"] = "af_comics,$owner_uid:" . $article["plugin_data"];
105 } else if (isset($article["stored"]["content"])) {
106 $article["content"] = $article["stored"]["content"];
110 if (strpos($article["link"], "explosm.net/comics") !== FALSE) {
111 if (strpos($article["plugin_data"], "af_comics,$owner_uid:") === FALSE) {
113 $doc = new DOMDocument();
114 @$doc->loadHTML(fetch_file_contents($article["link"]));
119 $xpath = new DOMXPath($doc);
120 $entries = $xpath->query('(//img[@src])'); // we might also check for img[@class='strip'] I guess...
124 foreach ($entries as $entry) {
126 if (preg_match("/(http:\/\/.*\/db\/files\/Comics\/.*)/i", $entry->getAttribute("src"), $matches)) {
134 $article["content"] = $doc->saveXML($basenode);
135 $article["plugin_data"] = "af_comics,$owner_uid:" . $article["plugin_data"];
138 } else if (isset($article["stored"]["content"])) {
139 $article["content"] = $article["stored"]["content"];
143 if (strpos($article["guid"], "gocomics.com") !== FALSE) {
144 if (strpos($article["plugin_data"], "af_comics,$owner_uid:") === FALSE) {
145 $doc = new DOMDocument();
146 @$doc->loadHTML(fetch_file_contents($article["link"]));
151 $xpath = new DOMXPath($doc);
152 $entries = $xpath->query('(//img[@src])'); // we might also check for img[@class='strip'] I guess...
156 foreach ($entries as $entry) {
158 if (preg_match("/(http:\/\/assets.amuniversal.com\/.*width.*)/i", $entry->getAttribute("src"), $matches)) {
160 $entry->setAttribute("src", $matches[0]);
167 // fallback on the smaller version
168 foreach ($entries as $entry) {
170 if (preg_match("/(http:\/\/assets.amuniversal.com\/.*)/i", $entry->getAttribute("src"), $matches)) {
172 $entry->setAttribute("src", $matches[0]);
180 $article["content"] = $doc->saveXML($basenode);
181 $article["plugin_data"] = "af_comics,$owner_uid:" . $article["plugin_data"];
184 } else if (isset($article["stored"]["content"])) {
185 $article["content"] = $article["stored"]["content"];
189 if (strpos($article["link"], "penny-arcade.com") !== FALSE && strpos($article["title"], "Comic:") !== FALSE) {
190 if (strpos($article["plugin_data"], "af_comics,$owner_uid:") === FALSE) {
192 if ($debug_enabled) {
193 _debug("af_pennyarcade: Processing comic");
196 $doc = new DOMDocument();
197 $doc->loadHTML(fetch_file_contents($article["link"]));
202 $xpath = new DOMXPath($doc);
203 $entries = $xpath->query('(//div[@class="post comic"])');
205 foreach ($entries as $entry) {
210 $article["content"] = $doc->saveXML($basenode);
211 $article["plugin_data"] = "af_comics,$owner_uid:" . $article["plugin_data"];
214 } else if (isset($article["stored"]["content"])) {
215 $article["content"] = $article["stored"]["content"];
219 if (strpos($article["link"], "penny-arcade.com") !== FALSE && strpos($article["title"], "News Post:") !== FALSE) {
220 if (strpos($article["plugin_data"], "af_comics,$owner_uid:") === FALSE) {
221 if ($debug_enabled) {
222 _debug("af_pennyarcade: Processing news post");
224 $doc = new DOMDocument();
225 $doc->loadHTML(fetch_file_contents($article["link"]));
228 $xpath = new DOMXPath($doc);
229 $entries = $xpath->query('(//div[@class="post"])');
233 foreach ($entries as $entry) {
237 $uninteresting = $xpath->query('(//div[@class="heading"])');
238 foreach ($uninteresting as $i) {
239 $i->parentNode
->removeChild($i);
243 $article["content"] = $doc->saveXML($basenode);
244 $article["plugin_data"] = "af_comics,$owner_uid:" . $article["plugin_data"];
247 } else if (isset($article["stored"]["content"])) {
248 $article["content"] = $article["stored"]["content"];
252 if (strpos($article["link"], "threewordphrase.com") !== FALSE) {
253 if (strpos($article["plugin_data"], "af_comics,$owner_uid:") === FALSE) {
255 $doc = new DOMDocument();
256 @$doc->loadHTML(fetch_file_contents($article["link"]));
261 $xpath = new DOMXpath($doc);
263 $basenode = $xpath->query("//td/center/img")->item(0);
266 $article["content"] = $doc->saveXML($basenode);
267 $article["plugin_data"] = "af_comics,$owner_uid:" . $article["plugin_data"];
270 } else if (isset($article["stored"]["content"])) {
271 $article["content"] = $article["stored"]["content"];
278 function api_version() {