Recently I've moved the web albums of my kids from my own webserver to Google Picasa. But... I wanted to keep my nice javascript based carousel
In the current code I already had some PHP-code that creates the content of the carousel using an array. Now I added two new features in the 'website'.
- Config files
- Downloading the RSS (XML) feed and cache it
- Extract the URLs with the photos from the XML feed.
1. Config files
One 'global' config:
<?php
cacheLocation="/tmp/picasa-cache/";
$cacheTTL = 60;
?>
Per album I've a config.php in that directory, so for example we've the following content:
<?php
$xmlURL='http://picasaweb.google.com/data/feed/base/user/k/id/123456970123ASBD1?alt=rss';
$AlbumDescription="Rick de Rijk";
$PicasaURL="http://picasaweb.google.com/paderijk/Rick";
$ShortName="rick";
$xmlFile="$cacheLocation/$ShortName.xml";
?>
2. Download the RSS (XML) feed and cache it:
<?php
# Code that takes care of the caching
#
if (!(file_exists($xmlFile) &&
(time() - $cacheTTL < filemtime($xmlFile))
)) {
//unlink($xmlFile);
$data = file_get_contents($xmlURL);
$f = file_put_contents($xmlFile, $data);
}
?>
3. Extract the URLs with the photos from the feed
<?php
$foto_array = array();
$xml = new SimpleXMLElement($xmlFile, null, true);
$urls = $xml->xpath("channel/item/enclosure/@url");
foreach ($urls as $image_url)
{
array_push($foto_array, $image_url);
}
?>
That's all