Nepal 2011 Scrapbook Photos Hawaii-Maui
 
Angkor Wat Thailand Hong Kong
 
Nepal Annapurna Circuit Faces of Nepal
 
Nepal--Pokhara Nepal--Kathmandu Beautiful Landscapes
 
Canada

////////////////////////////////////////////////////////////////////////////////////////////////////

// Entry point from WordPress
add_shortcode(‘GetPicasaAlbums’, ‘main’);

//————————————————————————————————–
// Function: main
//    Main entry point for the script. Does most of the work.
//
// Parameters
//    None.
//
// Returns:
//    None.
//————————————————————————————————–
function main($atts)
{
// Make sure we’re running an up-to-date version of PHP
$phpVersion = phpversion();
$verArray = explode(‘.’, $phpVersion);
if( (int)$verArray[0] < 5 )
{
echo “‘Get Picasa Albums’ requires PHP version 5 or newer.<br>\n”;
echo “Your server is running version $phpVersion<br>\n”;
exit;
}

// Extract WordPress parameters
extract(shortcode_atts(array(‘user’ => ‘INVALID’, ‘col’ => ’2′, ‘random’ => ‘y’,), $atts));

// Make sure they entered a Picasa username
if( $user == ‘INVALID’ )
{
echo ‘Picasa username required.<br>’;
echo ‘Usage: <br>’;
exit;
}

// Make sure there is an appropriate number of columns to display
if( $col < 1 )
$col = 2;

// Create default variables
$userid = “$user%40googlemail.com”;    // picasa_user_id@gmail.com

// build feed URL
$feedURL = “http://picasaweb.google.com/data/feed/api/user/$userid?kind=album”;
$picasaURL = “http://picasaweb.google.com/$user/”;
$picasaAlbumCache = dirname(__FILE__) . ‘/PicasaAlbumCache’;

// Read feed into SimpleXML object
$sxml = simplexml_load_file($feedURL);

$albumCount = 0;
$titleArray = array();
$rand = 1;

if( $random == ‘n’ )
$rand = -1;

echo “<table>\n”; // Start building the table

// Loop through and get info about each album
foreach( $sxml->entry as $entry )
{
$title = $entry->title;          // October 11, 2008: Cross Country – NLL’s
$gphoto = $entry->children(‘http://schemas.google.com/photos/2007′);
$numphotos = $gphoto->numphotos; // Number of photos in this album
$albumid = $gphoto->id;          // 5257119638771949313
$linkName = $gphoto->name;       // October112008CrossCountryNLLS
$href = $picasaURL . $linkName;  // http://picasaweb.google.com/lepolt/October112008CrossCountryNLLS
$albumfeedURL = “http://picasaweb.google.com/data/feed/api/user/$user/albumid/$albumid”;
$curTimestamp = $entry->updated; // 2008-10-16T11:53:56.000Z
$thumbToUse = ”;                // http://lh3.ggpht.com/lepolt/SPUK9utDpGI/AAAAAAAABQ8/1asIvwXaOYE/s144/2008_101115.JPG

// If we’re using random thumbnails, get one or update cache files
if( $rand != -1 )
{
// Get random number from 0 to $numphotos – 1
$rand = mt_rand(0, ((int)$numphotos – 1));

// Check to see if this albumid file exists…if so, open it and check timestamp
$albumFile = “$picasaAlbumCache/$albumid-$curTimestamp”;
if( file_exists($albumFile) )
{
// Open it into an array
if( $fileArray = file($albumFile) )
{
// We’re up to date, grab a thumbnail
$thumbToUse = $fileArray[$rand];
}
else
{
// Could not read file into array…
}
} // END if( file_exists($albumFile) )
else
{
// Create new file and write all the thumbnail links to the file
UpdateCacheFile($albumFile, $albumfeedURL, $rand, $thumbToUse);
}
} // END if( $rand != 1 )
else
{
$media = $entry->children(‘http://search.yahoo.com/mrss/’);
$thumbnail = $media->group->thumbnail;

// Direct address to thumbnail
$thumbToUse = $thumbnail->attributes()->{‘url’};
}

// Build the table dynamically
if( $albumCount % $col == 0 )
{
// Set title for left column
$titleArray[] = $title;

// This is a new row, create it
echo “<tr>\n”;
}

createCell($thumbToUse, $href);

if( $albumCount % $col !== 0 )
{
// Set title for next column
$titleArray[] = $title;
}

if( ($albumCount+1) % $col == 0 && $albumCount > 0 )
{
// This is the far right column, close the row tag
echo “</tr>\n”;

// Add row with gallery title info
setGalleryTitles($titleArray);

// Clear array
unset($titleArray);

// Add blank row for separation between thumbs
echo “<tr><td>&nbsp;</td></tr>\n”;
}

$albumCount++;

} // END foreach( $sxml->entry as $entry )

// One more row? Yes, if we have an odd number of albums
if( $albumCount % $col !== 0 )
{
echo “</tr>\n”;
while( $albumCount % $col !== 0 )
{
$titleArray[] = ”;
$albumCount++;
}

setGalleryTitles($titleArray);
}

// End table.
echo “</table>\n”;

} // END main()

Comments are closed.

Get Adobe Flash playerPlugin by wpburn.com wordpress themes