<?php

//The original functions that I used are licensed http://creativecommons.org/licenses/by-nc/3.0/
//My modifications and enhancements use the same license.


//GET THE REMOTE FILE INTO A VARIABLE
function curlit($url)
{
        
$ch curl_init();
        
curl_setopt($chCURLOPT_URL,$url);
        
curl_setopt($chCURLOPT_RETURNTRANSFER,1);
        
$return=curl_exec ($ch);
        
curl_close ($ch);
        return 
$return;
}

//THIS IS BASED ON http://blogoscoped.com/archive/2007-03-22-n84.html
function showAlbumContent($userId$albumName)
{
    
$url 'http://picasaweb.google.com/data/feed/api/user/' .
            
urlencode($userId) . '/album/' urlencode($albumName);
    
$xml curlit($url);
    
$xml str_replace("xmlns='http://www.w3.org/2005/Atom'"''$xml);

    
$dom = new domdocument;
    
$dom->loadXml($xml);
    
    
$xpath = new domxpath($dom);
    
$nodes $xpath->query('//entry');
    foreach (
$nodes as $node) {
        
$tmp[]['src'] = $xpath->query('.//media:thumbnail/@url'$node)->item(0)->textContent;
    }
    return 
$tmp;
}

//THIS IS BASED ON http://blogoscoped.com/archive/2007-03-22-n84.html
function getAlbums($userId)
{
    
$url 'http://picasaweb.google.com/data/feed/api/user/' .
        
urlencode($userId) . '?kind=album';
    
$xml curlit($url);
    
$xml str_replace("xmlns='http://www.w3.org/2005/Atom'"''$xml);

    
$dom = new domdocument;
    
$dom->loadXml($xml);

    
$xpath = new domxpath($dom);
    
$nodes $xpath->query('//entry');
    foreach (
$nodes as $node) {
        
$tmp[] = $xpath->query('title'$node)->item(0)->textContent;
    }
    return 
$tmp;
}

//set the google user id.  my pics are nice, but this should be yours.
$userid 'myles.henderson';
//get the list of albums
$albums getAlbums($userid);
//get a random album 
$album_title $albums[array_rand($albums1)];
//google wants only the letters and numbers in the url
$album_title ereg_replace("[^A-Za-z0-9]"""$album_title);
//get the list of pictures from the album
$pictures showAlbumContent($userid$album_title);
//get a random picture from the album
if(is_array($pictures)){
    
$random_pic $pictures[array_rand($pictures,1)]['src'];
    print 
'<img src="' $random_pic '" alt="">';
}
else{
    print 
'no pictures for album ' $album_title;
}
?>