How I built icant.co.uk – source code
Wednesday, June 3rd, 2009 at 3:24 pmAfter my talk at FOWA in Cambridge yesterday I showed off that http://icant.co.uk is fully driven by YUI and YQL and maintained elsewhere. I’ve recorded a screencast about this earlier which is also available for download as a M4V but hadn’t released the code yet.
So here goes – this is the PHP source of icant.co.uk (without the HTML which is more or less done with YUI grids builder
// get all the feeds to grab the data
$feeds = array(
'http://feeds2.feedburner.com/wait-till-i/gwZf',
'http://feeds.delicious.com/v2/rss/codepo8/myvideos?count=15',
'http://feeds.delicious.com/v2/rss/codepo8/sandbox',
'http://feeds.delicious.com/v2/rss/codepo8/icantarticles',
'http://www.slideshare.net/rss/user/cheilmann'
);
// assemble the YQL statement
$yql = 'select meta.views,content.thumbnail,content.description,title,'.
'link,description from rss where url in ';
$yql .= "('" . join($feeds,"','") . "')";
// assemble the request url
$root = 'http://query.yahooapis.com/v1/public/yql?q=';
$url = $root . urlencode($yql) . '&format=json';
// get the feeds and populate the data to echo out in the HTML
$feeds = renderFeeds($url);
$blog = $feeds['blog'];
$videos = $feeds['videos'];
$articles = $feeds['articles'];
$presentations = $feeds['slides'];
// this function loads all the feeds and turns them into HTML
function renderFeeds($url){
// grab the content from YQL via cURL
$c = getStuff($url);
// as the content comes back as JSON, turn it into PHP objects
$x = json_decode($c);
// reset counter for videos and presentations
$count = 0;
$vidcount = 0;
// start new array to return
$out = array();
// loop over YQL results, if they exist.
if($x->query->results->item){
foreach($x->query->results->item as $i){
// if the link comes from the blog, add to the blog HTML
if(strstr($i->link,'wait-till-i')){
$out['blog'] .= '' . $i->title .
'
';
}
// if the description contains an embed code, add to videos
// (I use delicious for video bookmarks and add the embed code
// as a description, check here:
// http://feeds.delicious.com/v2/rss/codepo8/myvideos)
if(strstr($i->description,'