diff --git a/init.php b/init.php
index 9761c3d..bb74107 100644
--- a/init.php
+++ b/init.php
@@ -7,257 +7,336 @@
* Most important: Keep it simple. Follow one pattern.
*/
-define('ADD_IDS', True);
+define('ADD_IDS', False);
+define("GDORN_DEBUG", False);
class gdorn_comics extends Plugin {
- function about() {
- return array(0.1,
- 'Yet more stupid-simple comic-fetching.',
- 'gdorn');
- }
+ function about() {
+ return array(
+ 0.1,
+ 'Yet more stupid-simple comic-fetching.',
+ 'gdorn'
+ );
+ }
- function init($host) {
- /**
- * When debugging or writing a new fetcher, use the two RENDER hooks.
- * These work in realtime, but don't cache, so they're slow.
- *
- * So once you are happy with your fetcher, use the ARTICLE_FILTER hook.
- */
-// $host->add_hook($host::HOOK_ARTICLE_FILTER, $this);
- $host->add_hook($host::HOOK_RENDER_ARTICLE_CDM, $this);
- $host->add_hook($host::HOOK_RENDER_ARTICLE, $this);
- }
+ function init($host) {
+ /**
+ * When debugging or writing a new fetcher, use the two RENDER hooks.
+ * These work in realtime, but don't cache, so they're slow.
+ *
+ * So once you are happy with your fetcher, use the ARTICLE_FILTER hook.
+ */
+ // $host->add_hook($host::HOOK_ARTICLE_FILTER, $this);
+ $host->add_hook($host::HOOK_RENDER_ARTICLE_CDM, $this);
+ $host->add_hook($host::HOOK_RENDER_ARTICLE, $this);
+ }
- function hook_render_article_cdm($article) {
- return $this->mangle_article($article);
- }
+ function hook_render_article_cdm($article) {
+ return $this->mangle_article($article);
+ }
- function hook_render_article($article) {
- return $this->mangle_article($article);
- }
+ function hook_render_article($article) {
+ try {
+ return $this->mangle_article($article);
+ }
+ catch (Exception $e) {
+ $article['content'] .= "
Error processing via gdorn_comics plugin!
" . $e->getMessage();
+ }
+ }
- function mangle_article($article) {
- // Eat That Toast bog-standard example
- if (strpos($article['link'], 'eatthattoast.com/comic/') !== FALSE) {
- $article['content'] = preg_replace('#(/[0-9-]+)-150x150\.gif#', '$1.gif', $article['content']);
- $article['content'] = preg_replace('#(width|height)="150"#', '', $article['content']);
- }
- // Joy of Tech
- elseif (strpos($article['link'], 'www.geekculture.com/joyoftech/') !== FALSE) {
- $xpath = $this->get_xpath_dealie($article['link']);
- $article['content'] = $this->get_img_tags($xpath, '//p[@class="Maintext"]//img[contains(@src, "joyimages")]', $article);
- }
- // Order of the Stick
-// elseif (strpos(strtolower($article['link']), 'giantitp.com/comics/') !== FALSE) {
-// $xpath = $this->get_xpath_dealie($article['link']);
-// $article['content'] = $this->get_img_tags($xpath, '//td/img[contains(@src, "/comics/images/")]', $article);
-// }
- // Girls with Slingshots
- elseif (strpos($article['link'], 'girlswithslingshots.com/comic/') !== FALSE) {
- $xpath = $this->get_xpath_dealie($article['link']);
- $article['content'] = $this->get_img_tags($xpath, "//div[@id='comicbody']//img", $article);
- }
- // CTRL+ALT+DEL Sillies
- elseif (strpos($article['link'], 'cad-comic.com/sillies/') !== FALSE) {
- $xpath = $this->get_xpath_dealie($article['link']);
- $article['content'] = $this->get_img_tags($xpath, "//div[@id='content']/img", $article);
- }
- // CTRL+ALT+DEL
- elseif (strpos($article['link'], 'cad-comic.com/cad/') !== FALSE) {
- $xpath = $this->get_xpath_dealie($article['link']);
- $article['content'] = $this->get_img_tags($xpath, "//div[@id='content']/img", $article);
- }
- // Three Panel Soul
- elseif (strpos($article['link'], 'threepanelsoul.com/2') !== FALSE) {
- $xpath = $this->get_xpath_dealie($article['link']);
- $article['content'] = $this->get_img_tags($xpath, "//div[@id='comic']/img", $article);
- }
- // Two Lumps
- elseif (strpos($article['link'], 'twolumps.net/d/') !== FALSE) {
- $xpath = $this->get_xpath_dealie($article['link']);
- $article['content'] = $this->get_img_tags($xpath, "//img[@class='ksc' and contains(@src, 'comics')]", $article);
- }
- // Breaking Cat News
- elseif (strpos($article['link'], 'breakingcatnews.com/comic/') !== FALSE) {
- $xpath = $this->get_xpath_dealie($article['link']);
- $article['content'] = $this->get_img_tags($xpath, "//div[@id='comic']/img", $article);
- }
- // Something Positive
- elseif (strpos($article['link'], 'somethingpositive.net') !== FALSE) {
- $xpath = $this->get_xpath_dealie($article['link']);
- $article['content'] = $this->get_img_tags($xpath, "//img[starts-with(@src, 'sp') and contains(@src, 'png')]", $article);
- }
- // Timothy Winchester (People I Know)
- elseif (strpos($article['link'], 'www.timothywinchester.com/2') !== FALSE) {
- $xpath = $this->get_xpath_dealie($article['link']);
- $orig_content = strip_tags($article['content']);
- $article['content'] = $this->get_img_tags($xpath, "//div[@class='singleImage']/img[@class='magicfields']", $article);
- $article['content'] .= "
$orig_content";
- }
- // Awkward Zombie
- elseif (strpos($article['link'], 'awkwardzombie.com/index.php?comic') !== FALSE) {
- $xpath = $this->get_xpath_dealie($article['link']);
- $orig_content = strip_tags($article['content']);
- $article['content'] = $this->get_img_tags($xpath, "//div[@id='comic']/img", $article);
- $article['content'] .= "
$orig_content
"; - //also append the blarg post because that's small, interesting, - //and sometimes necessary for old fogeys like me to get what game it's about - $entries = $xpath->query("//div[@id='blarg']/div[last()]"); - foreach ($entries as $entry){ - $article['content'] .= "" . $entry->textContent . "
"; - } - } - // Camp Weedonwantcha - elseif (strpos($article['link'], 'campcomic.com/comic/') !== FALSE) { - $xpath = $this->get_xpath_dealie($article['link']); - $article['content'] = $this->get_img_tags($xpath, "//div[@id='comic']//img", $article); + function mangle_article($article) { + // Penny Arcade + if (strpos($article["link"], "penny-arcade.com") !== FALSE && strpos($article["title"], "Comic:") !== FALSE) { + $xpath = $this->get_xpath_dealie($article['link']); + $article['content'] = $this->get_img_tags($xpath, '(//div[@id="comicFrame"])', $article); + } elseif (strpos($article["link"], "explosm.net/comics") !== FALSE) { + $xpath = $this->get_xpath_dealie($article['link']); + $article['content'] = $this->get_img_tags($xpath, '(//img[@id="main-comic"])', $article); + } + // Joy of Tech + elseif (strpos($article['link'], 'www.geekculture.com/joyoftech/') !== FALSE) { + $xpath = $this->get_xpath_dealie($article['link']); + $article['content'] = $this->get_img_tags($xpath, '//p[@class="Maintext"]//img[contains(@src, "joyimages")]', $article); + } /* OotS uses some kind of referer check which prevents fetch_file_contents() from retrieving the image. + // Order of the Stick + elseif (strpos(strtolower($article['link']), 'giantitp.com/comics/') !== FALSE) { + $xpath = $this->get_xpath_dealie($article['link']); + $article['content'] = $this->get_img_tags($xpath, '//td/img[contains(@src, "/comics/images/")]', $article); + } + */ + // Girls with Slingshots + elseif (strpos($article['link'], 'girlswithslingshots.com/comic/') !== FALSE) { + $xpath = $this->get_xpath_dealie($article['link']); + $article['content'] = $this->get_img_tags($xpath, "//div[@id='comicbody']//img", $article); + } + // CTRL+ALT+DEL Sillies + elseif (strpos($article['link'], 'cad-comic.com/sillies/') !== FALSE) { + $xpath = $this->get_xpath_dealie($article['link']); + $article['content'] = $this->get_img_tags($xpath, "//div[@id='content']/img", $article); + } + // CTRL+ALT+DEL + elseif (strpos($article['link'], 'cad-comic.com/cad/') !== FALSE) { + $xpath = $this->get_xpath_dealie($article['link']); + $article['content'] = $this->get_img_tags($xpath, "//div[@id='content']/img", $article); + } + // Three Panel Soul + elseif (strpos($article['link'], 'threepanelsoul.com/2') !== FALSE) { + $xpath = $this->get_xpath_dealie($article['link']); + $article['content'] = $this->get_img_tags($xpath, "//div[@id='comic']/img", $article); + } + // Two Lumps + elseif (strpos($article['link'], 'twolumps.net/d/') !== FALSE) { + $xpath = $this->get_xpath_dealie($article['link']); + $article['content'] = $this->get_img_tags($xpath, "//img[@class='ksc' and contains(@src, 'comics')]", $article); + } + // Breaking Cat News + elseif (strpos($article['link'], 'breakingcatnews.com/comic/') !== FALSE) { + $xpath = $this->get_xpath_dealie($article['link']); + $article['content'] = $this->get_img_tags($xpath, "//div[@id='comic']/img", $article); + } + // Something Positive + elseif (strpos($article['link'], 'somethingpositive.net') !== FALSE) { + $xpath = $this->get_xpath_dealie($article['link']); + $article['content'] = $this->get_img_tags($xpath, "//img[starts-with(@src, 'sp') and contains(@src, 'png')]", $article); + } + // Timothy Winchester (People I Know) + elseif (strpos($article['link'], 'www.timothywinchester.com/2') !== FALSE) { + $xpath = $this->get_xpath_dealie($article['link']); + $orig_content = strip_tags($article['content']); + $article['content'] = $this->get_img_tags($xpath, "//div[@class='singleImage']/img[@class='magicfields']", $article); + $article['content'] .= "$orig_content
"; + //also append the blarg post because that's small, interesting, + //and sometimes necessary for old fogeys like me to get what game it's about + $entries = $xpath->query("//div[@id='blarg']/div[last()]"); + foreach ($entries as $entry) { + $article['content'] .= "" . $entry->textContent . "
"; + } + } + // Camp Weedonwantcha + elseif (strpos($article['link'], 'campcomic.com/comic/') !== FALSE) { + $xpath = $this->get_xpath_dealie($article['link']); + $article['content'] = $this->get_img_tags($xpath, "//div[@id='comic']//img", $article); + } + // Poly In Pictures + elseif (strpos($article['link'], 'polyinpictures.com/comic/') !== FALSE) { + $xpath = $this->get_xpath_dealie($article['link']); + $article['content'] = $this->get_img_tags($xpath, "//div[@id='comic']//img", $article); + } + // Dilbert + elseif (strpos($article['link'], 'dilbert.com/strip/') !== FALSE) { + $xpath = $this->get_xpath_dealie($article['link']); + $article['content'] = $this->get_img_tags($xpath, "//div[@class='img-comic-container']//img", $article); + } + // Scenes From A Multiverse (to get alt tags) + elseif (strpos($article['link'], 'amultiverse.com/comic/') !== FALSE) { + $xpath = $this->get_xpath_dealie($article['link']); + $article['content'] = $this->get_img_tags($xpath, "//div[@id='comic']//img", $article); + } + // Dead Philosophers + elseif (strpos($article['link'], 'dead-philosophers.com/?p') !== FALSE) { + $xpath = $this->get_xpath_dealie($article['link']); + $article['content'] = $this->get_img_tags($xpath, "//div[@id='comic-1']//img", $article); + } + // Dinosaur Comics Cleanup + elseif (strpos($article['link'], 'qwantz.com/index.php?comic') !== FALSE) { + $xpath = $this->get_xpath_dealie($article['link']); + $article['content'] = $this->get_img_tags($xpath, "//img[@class='comic']", $article); + //also get the blog + $entries = $xpath->query("//span[@class='rss-content']"); + foreach ($entries as $entry) { + $article['content'] .= "" . $entry->ownerDocument->saveXML($entry) . "
"; + } + } + // XKCD (alt tags we don't need to call out for) + elseif (strpos($article['content'], 'imgs.xkcd.com/comics/') !== FALSE) { + $doc = new DOMDocument(); + $doc->loadHTML($article['content']); + $xpath = new DOMXpath($doc); + $imgs = $xpath->query('//img'); //doesn't get simpler than this + foreach ($imgs as $img) { + $article['content'] .= "" . $entry->ownerDocument->saveXML($entry) . "
"; - } - } - // XKCD (alt tags we don't need to call out for) - elseif (strpos($article['content'], 'imgs.xkcd.com/comics/') !== FALSE) { - $doc = new DOMDocument(); - $doc->loadHTML($article['content']); - $xpath = new DOMXpath($doc); - $imgs = $xpath->query('//img'); //doesn't get simpler than this - foreach($imgs as $img){ - $article['content'] .= "