Skip to content

Instantly share code, notes, and snippets.

@goodevilgenius
Last active October 26, 2017 13:59
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save goodevilgenius/ec1a3af05246e08be951 to your computer and use it in GitHub Desktop.
Save goodevilgenius/ec1a3af05246e08be951 to your computer and use it in GitHub Desktop.
[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