Last active
October 26, 2017 13:59
-
-
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
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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