as I stumbled upon NASA Astronomy Picture of the Day (http://apod.nasa.gov/) and wondered about them having a RSS feed, I subscribed to it in my tt-rss instance (which really works like a charm). As I realised, they just integrate a very small thumbnail in their feed, I created my first plugin to fetch the bigger image from the linked site, based on the jp_stuttman and the af_feedmod plugins. If someone is interested:
create a folder large_apod in the plugins.local directory of your tt-rss instance
create a file init.php and paste the following into it:
<?php
class large_apod extends Plugin {
private $host;
function about() {
return array(1.0,
"Display large images in NASA APOD feed",
"t0t4");
}
function init($host) {
$this->host = $host;
$host->add_hook($host::HOOK_ARTICLE_FILTER, $this);
}
function hook_article_filter($article) {
global $fetch_last_content_type;
if (strpos($article['link'], 'apod.nasa.gov') === false) return $article; // skip other URLs
if (isset($article['stored']['content'])) {
$article['content'] = $article['stored']['content'];
return $article; // skip already stored content
}
$doc = new DOMDocument();
$link = trim($article['link']);
$html = fetch_file_contents($link);
$content_type = $fetch_last_content_type;
$charset = false;
if ($content_type) {
preg_match('/charset=(\S+)/', $content_type, $matches);
if (isset($matches[1]) && !empty($matches[1])) $charset = $matches[1];
}
if ($charset) {
$html = iconv($charset, 'utf-8', $html);
$charset = 'utf-8';
$html = '<?xml encoding="' . $charset . '">' . $html;
}
@$doc->loadHTML($html);
if ($doc) {
$basenode = false;
$xpath = new DOMXPath($doc);
$entries = $xpath->query('(//img)');
if ($entries->length > 0) $basenode = $entries->item(0);
if ($basenode) {
$article['content'] = $doc->saveXML($basenode);
}
}
return $article;
}
function api_version() {
return 2;
}
}
?>
activate it in the preferences and resubscribe to the feed.
Please feel free to use it and please don’t slap me if it’s not working at your installation, suggestions to improve it are welcome.
Many thanks indeed. I just tried it and it worked for me.
Is there a chance of you expending this to allow for a fixed size of the image & support the NASA image of the day? Their photos are generally huge in RSS.
I just switched to the Docker installation from the old host installation. I followed all the instructions for copying over themes and plugins and now I am getting this in the error log:
Uncaught Error: Call to undefined function iconv() in /var/www/html/tt-rss/plugins.local/large_apod/init.php:39 Stack trace: #0 /var/www/html/tt-rss/classes/rssutils.php(814): large_apod->hook_article_filter(Array) #1 /var/www/html/tt-rss/update.php(264): RSSUtils::update_rss_feed(‘573’, true) #2 {main} thrown
Not sure if this is an issue with the plugin or with my Docker setup. Thanks.
if you’re using docker hub setup the plugin should start working next time image is updated. if you’re using dynamic setup you’ll have to pull scripts & rebuild the image.
thanks fox. searching led me to believe that was the case but I didn’t want to come in here assuming since i am still figuring docker out and this plugin is pretty old. i got my containers updated and everything is working. thanks again for the effort.