Instantly share code, notes, and snippets.

Embed
What would you like to do?
[Explosm feed] A feed generator for Cyanide & Happiness which includes the images #comics
<?php
/**
* Generates a Cyanide & Happiness feed with the images included
* Caches the results to be nice to the server
* Requires memcache and simplehtmldom
* Gist: https://gist.github.com/ec1a3af05246e08be951
*/
// See http://simplehtmldom.sourceforge.net/
require_once('simple_html_dom.php');
$mem = new Memcache;
$mem->addServer('localhost');
$feed = "http://feeds.feedburner.com/Explosm";
$feed_src = $mem->get($feed);
if (empty($feed_src)) {
$feed_src = file_get_contents($feed);
$mem->set($feed, $feed_src, 0, 43200);
}
$xml = new simplexmlelement($feed_src);
header("Content-type: application/rss+xml");
foreach($xml->channel->item as $item) {
$url = $item->link;
$html = file_get_html($url);
$img_tag = $mem->get($url . '[img]');
if (empty($img_tag)) {
$img_tag = $html->find('#main-comic')[0]->outertext;
$mem->set($url . '[img]', $img_tag);
}
$item->description = $img_tag;
}
echo $xml->asxml();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment