Skip to content

Instantly share code, notes, and snippets.

@enygma
Created December 1, 2011 03:45
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save enygma/1413370 to your computer and use it in GitHub Desktop.
Save enygma/1413370 to your computer and use it in GitHub Desktop.
Simple RSS feed creation for @PHPQuickFix
<?php
$jsonCacheFile = './quickfix.json';
$gimmieFeed = 'https://gimmebar.com/api/v0/public/assets/phpquickfix';
$wgetCmd = 'wget -O'.$jsonCacheFile.' '.$gimmieFeed;
// look for the cache file
if(!is_file($jsonCacheFile) || (is_file($jsonCacheFile) && filemtime($jsonCacheFile)<strtotime('-1 minute')) ){
// fetch the latest content from gimmiebar
exec($wgetCmd);
}
$json = file_get_contents($jsonCacheFile);
// build it out into a RSS feed
$itemList = '';
$data = json_decode($json);
foreach($data->records as $item){
$itemList .= sprintf('<item>
<title>%s</title>
<link>%s</link>
<description>%s</description>
<pubDate>%s</pubDate>
</item>'."\n",
$item->title,
htmlspecialchars($item->source),
$item->title.' : '.$item->description,
date('r',$item->date));
}
header('Content-type: text/xml; ; charset=UTF-8');
echo sprintf(
'<rss version="2.0">
<channel>
<title>phpquickfix - get your fix now!</title>
<description>Quick hits of PHP news coming your way</description>
<language>en-us</language>
<pubDate>%s</pubDate>
%s
</channel>
<title>phpquickfix - get your fix now!</title>
<description>Quick hits of PHP news coming your way</description>
<language>en-us</language>
<pubDate>%s</pubDate>
%s
</channel>
</rss>
',date('r'),$itemList);
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment