public
Last active

Simple RSS feed creation for @PHPQuickFix

  • Download Gist
gistfile1.aw
PHP
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49
<?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);
?>

Please sign in to comment on this gist.

Something went wrong with that request. Please try again.