Update af_comics to handle new GoComics site.

This commit is contained in:
JustAMacUser 2017-01-22 02:14:02 -05:00
parent fabfb9fc2a
commit 5800d3d505
2 changed files with 68 additions and 55 deletions

View File

@ -1,53 +0,0 @@
<?php
class Af_Comics_GoComics extends Af_ComicFilter {
function supported() {
return array("GoComics");
}
function process(&$article) {
$owner_uid = $article["owner_uid"];
if (strpos($article["guid"], "gocomics.com") !== FALSE) {
$doc = new DOMDocument();
@$doc->loadHTML(fetch_file_contents($article["link"]));
$basenode = false;
if ($doc) {
$xpath = new DOMXPath($doc);
$entries = $xpath->query("(//img[@class='strip'])");
$matches = array();
if ($entries->length > 1) { // if we have more than one match, then get the zoomed one, which is the second for gocomics
$entry = $entries->item(1); // get the second element (items start at 0)
if (preg_match("/(http:\/\/assets.amuniversal.com\/.*)/i", $entry->getAttribute("src"), $matches)) {
$entry->setAttribute("src", $matches[0]);
$basenode = $entry;
}
}
if (!$basenode) {
// fallback on the smaller version
foreach ($entries as $entry) {
if (preg_match("/(http:\/\/assets.amuniversal.com\/.*)/i", $entry->getAttribute("src"), $matches)) {
$entry->setAttribute("src", $matches[0]);
$basenode = $entry;
break;
}
}
}
if ($basenode) {
$article["content"] = $doc->saveXML($basenode);
}
}
return true;
}
return false;
}
}
?>

View File

@ -5,7 +5,7 @@ class Af_Comics extends Plugin {
private $filters = array();
function about() {
return array(1.0,
return array(2.0,
"Fixes RSS feeds of assorted comic strips",
"fox");
}
@ -13,6 +13,7 @@ class Af_Comics extends Plugin {
function init($host) {
$this->host = $host;
$host->add_hook($host::HOOK_FETCH_FEED, $this);
$host->add_hook($host::HOOK_ARTICLE_FILTER, $this);
$host->add_hook($host::HOOK_PREFS_TAB, $this);
@ -40,7 +41,7 @@ class Af_Comics extends Plugin {
print "<p>" . __("The following comics are currently supported:") . "</p>";
$comics = array();
$comics = array("GoComics");
foreach ($this->filters as $f) {
foreach ($f->supported() as $comic) {
@ -71,6 +72,71 @@ class Af_Comics extends Plugin {
}
// GoComics dropped feed support so it needs to be handled when fetching the feed.
function hook_fetch_feed($feed_data, $fetch_url, $owner_uid, $feed, $last_article_timestamp, $auth_login, $auth_pass) {
if ($auth_login || $auth_pass)
return $feed_data;
if (preg_match('#^https?://feeds.feedburner.com/uclick/([a-z]+)#', $fetch_url, $comic)) {
$site_url = 'http://www.gocomics.com/' . $comic[1];
$article_link = $site_url . date('/Y/m/d');
$body = fetch_file_contents(array('url' => $article_link, 'type' => 'text/html', 'followlocation' => false));
require_once 'lib/MiniTemplator.class.php';
$feed_title = htmlspecialchars($comic[1]);
$site_url = htmlspecialchars($site_url);
$article_link = htmlspecialchars($article_link);
$tpl = new MiniTemplator();
$tpl->readTemplateFromFile('templates/generated_feed.txt');
$tpl->setVariable('FEED_TITLE', $feed_title, true);
$tpl->setVariable('VERSION', VERSION, true);
$tpl->setVariable('FEED_URL', htmlspecialchars($fetch_url), true);
$tpl->setVariable('SELF_URL', $site_url, true);
$tpl->setVariable('ARTICLE_UPDATED_ATOM', date('c'), true);
$tpl->setVariable('ARTICLE_UPDATED_RFC822', date(DATE_RFC822), true);
if ($body) {
$doc = new DOMDocument();
if (@$doc->loadHTML($body)) {
$xpath = new DOMXPath($doc);
$node = $xpath->query('//picture[contains(@class, "item-comic-image")]/img')->item(0);
if ($node) {
$tpl->setVariable('ARTICLE_ID', $article_link, true);
$tpl->setVariable('ARTICLE_LINK', $article_link, true);
$tpl->setVariable('ARTICLE_TITLE', date('l, F d, Y'), true);
$tpl->setVariable('ARTICLE_EXCERPT', '', true);
$tpl->setVariable('ARTICLE_CONTENT', $doc->saveXML($node), true);
$tpl->setVariable('ARTICLE_AUTHOR', '', true);
$tpl->setVariable('ARTICLE_SOURCE_LINK', $site_url, true);
$tpl->setVariable('ARTICLE_SOURCE_TITLE', $feed_title, true);
$tpl->addBlock('entry');
}
}
}
$tpl->addBlock('feed');
$tmp_data = '';
if ($tpl->generateOutputToString($tmp_data))
$feed_data = $tmp_data;
}
return $feed_data;
}
function api_version() {
return 2;
}