Merge branch 'af-comics-gocomics-feed' into 'master'
Update af_comics plugin to support GoComics. Updates the af_comics plugin to support new GoComics site, which dropped native RSS feeds. See merge request !42
This commit is contained in:
commit
fa287f6b11
3 changed files with 70 additions and 56 deletions
3
include/functions.php
Executable file → Normal file
3
include/functions.php
Executable file → Normal file
|
@ -368,6 +368,7 @@
|
|||
$timeout = isset($options["timeout"]) ? $options["timeout"] : false;
|
||||
$timestamp = isset($options["timestamp"]) ? $options["timestamp"] : 0;
|
||||
$useragent = isset($options["useragent"]) ? $options["useragent"] : false;
|
||||
$followlocation = isset($options["followlocation"]) ? $options["followlocation"] : true;
|
||||
|
||||
$url = ltrim($url, ' ');
|
||||
$url = str_replace(' ', '%20', $url);
|
||||
|
@ -388,7 +389,7 @@
|
|||
|
||||
curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, $timeout ? $timeout : FILE_FETCH_CONNECT_TIMEOUT);
|
||||
curl_setopt($ch, CURLOPT_TIMEOUT, $timeout ? $timeout : FILE_FETCH_TIMEOUT);
|
||||
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, !ini_get("open_basedir"));
|
||||
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, !ini_get("open_basedir") && $followlocation);
|
||||
curl_setopt($ch, CURLOPT_MAXREDIRS, 20);
|
||||
curl_setopt($ch, CURLOPT_BINARYTRANSFER, true);
|
||||
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
}
|
||||
?>
|
|
@ -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;
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue