August 2008

Customize your PicasaWeb Album - ShareMyAlbum.com

ShareMyAlbum.com - Customize PicasaWeb Albums
Well here it is, that project I hinted to a few months back. Yeah, took a bit longer to get up and running than I thought, but it’s here!

ShareMyAlbum.com is designed for those of you who just want to make your Picasa Albums pretty, without having to learn php or dig through code. You enter in the Google account associated with your album, select which album you’d like to use, put in an email address and name your album, and you’re up and running. All of the photos from the album are displayed as nice, clean 100px squares which go full screen if you click on them. It’s just that easy.

You can stop there and not do any customization at all, and that’s fine. You can send out the link to your friends, show your mom, do whatever you like. The page will always show the latest photos in your PicasaWeb album, you never have to revisit ShareMyAlbum to update anything. Best of all, we don’t link to your PicasaWeb album directly, so people won’t have access to any photos you don’t want them to have access to.

For those of you who actually want to customize your Picasa album though, you can choose a password and log into ShareMyAlbum.com to edit things. You can choose from a few pre-made themes to spice up your pictures, with more coming all the time. If none of the themes are to your liking, you can upload your own background photo and change all the colors of the text to make it look like you want it to look. You have total control of the look and feel of your album.

I’m pretty happy with the way it’s coming along, while it’s not fully 100% where I want it while I write this post, it’s fully functional and useable. Of course, I’m using the same open source code I posted a few months ago to parse through the Picasa RSS feed and grab all the photos. so even if ShareMyAlbum.com doesn’t do what you want it to, at least you can get some ideas and use the source code to put pictures on your own site, however you want.

I hope you like it, it’s taken longer that I hoped but the end result is pretty sweet I think. Please let me know what you think, I’d love to hear your feedback.

Uncategorized

Comments (1)

Permalink

There Must Be A Better Way…

I’m working on a photo gallery site that’s powered off Google’s Picasa service. Basically, you put in your email address, you name your gallery, and then you put in the RSS feed for your Picasa album, and out comes a nice, customizable gallery you can share with your friends. Three steps, thought it was a pretty cool idea, easy for anyone to use.

The trouble came when I tried to validate everything the user puts in. An email is easy, just check to make sure the email address follows the normal syntax xxx@xxx.xx and send it a test email to confirm. The gallery name is even easier, remove weird characters that would interfere with the URL and check that is doesn’t already exist. The Picasa RSS feed however, was a bit trickier.

I’m using PHP to power this app. To sort through the RSS feed, use a function called simplexml_load_file. That function takes a file I give it, and if it’s properly formatted XML, loads it into an easy to use format. For example, if I want to pull the title and body of each post out of the rss feed, I use the following:


$xml = simplexml_load_file("rssfeed.xml");
$items = $xml->channel;
foreach ($items->item as $item){
$title = $item->title;
$body = $item->description;
}

Pretty simple right? Well that’s the point of this simplexml_load_file function, it works real nice and easy. Here’s the problem though. Most php functions will present you with an error if you send them something they can’t read. For example, if I try to load a file into a page using an include(); function, I can use this code to catch any errors.


try {
if(!@include('/path/to/file.php')) {
throw new Exception('Failed to load');
}
}
catch(Exception $e) {
print $e->getMessage();
}

Again, makes sense right? Well that doesn’t seem to work with simplexml_load_file for some reason. If I pass an invalid file, or improperly formated XML, rather than catching an error and moving on, it takes down the code with crazy errors. I swear, I tried everything to get this to work, but no love. Now, there is a crazy complicated, 50 lines of code option, but that’s excessive for simple validation.

So if there’s no easy way to catch an error on a simplexml_load_file function, how can I possibly validate that the RSS feed a user passes is ok? Well, after hours of research and giving up for the night, it finally dawned on me. There’s no reason I need to load the XML to test if it’s valid. All I need to do is check the url for validity and test the file for something that’s specific to the RSS feed. Scanning through the XML, I found this little piece of markup:


<gphoto:allowPrints>true</gphoto:allowPrints>

Now I’m sure flickr isn’t using that XML tag anywhere. It’s gotta be from Google, and it’s gotta be for photos. All I need to do is confirm this XML exists in the file to confirm 99.9% that the feed is correct. The code for that looks something like this.


$filename = "rss.xml";
$string = "gphoto:allowPrints";
$feed = fopen ($filename,"r");
$contents = fread($feed,filesize($filename));
if(strstr($contents,$string)) {
echo "Valid";
} else {
echo "Invalid";
}

So what’s the point of this post? Well, I wasted at least 2 hours of my life trying to solve a problem the hard way, when I should have just thought about solving the problem the *right* way. I was so convinced that I had to figure out validation of that XML file that I never thought about any other options. Next time you’re stuck on something, just take a step back and think if there’s a better way of doing it instead.

Uncategorized

Comments (1)

Permalink