Friday, January 13, 2006

More AJAX - a Flickr Slideshow

As if I didn't have enough places with uploaded photos, I recently joined Flickr. Intrigued by the RSS Feeds, I thought of a great idea - build an AJAX slide show from a Flickr RSS feed!

I saved the RSS XML to my laptop for working offline, and designed a simple slideshow that reads the RSS, and loops through the pictures. I then put it to work at a domain that I hadn't really used before - http://www.worldjewish.info. The slideshow program polls Flickr every 15 minutes for a new RSS feed. The code isn't polished or commented, but I promise to do so soon and make it available for the masses.

One caveat though - XMLHTTP will not allow you to cross-script - i.e. an XMLHttp object on a page served off of www.bonerosity.com can't read an XML doc from www.flickr.com . So, with a little help from my buddy Heshy , I wrote this PHP wrapper script. The script runs on my server, but retreives the XML data so that my XMLHttpObject thinks that the data is from the same server.

Here is the code (Note, I don't program PHP much, so it definitely isn't elegant):


< ?php $url=$_GET["url"]; //Pass the url in foreach(array_keys($_GET) as $getKey) { if($getKey<>"url")
{

$url=$url."&".$getKey."=".$_GET[$getKey];
}
}
//echo $url
$httpfile = file_get_contents($url);
header("Content-Type: text/xml; charset=utf-8");
echo $httpfile;
?>

No comments: