I had the feeling that my customers might be having trouble finding their photos using the current gallery navigation. The problem is that you can only look at a limited number of galleries at once, and the “gallery overview” page doesn’t look much different from an actual gallery. You can try it for yourself here:
http://prints.goodlux.com/
I myself have trouble finding galleries where I left them, I can only imagine it’s much more difficult for a customer to navigate this visual tree. I thought it would be great if there was a more straightforward approach…just a simple list of galleries, ordered from the current date on backwards into the past, so the latest things I’ve photographed would be on top, and the others down at the bottom of the list.
Having a list like this would make it simple for a client to find their images, based on the date it was photographed or they could use the search feature of their broswer to do a text search. Basically, I wanted it to look like this:
http://goodlux.com/clients/
Since no one else really seemed to be using the ExposureManager uploader API for much of anything, I decided to give it a whirl. The API allows a user to query their directory tree structure for the purpose of uploading files. While I’m not interested in uploading files, this API gave more than enough information to make the more use navigation system above.
From the documentation provided, it was a little difficult to get started with accessing the API from PHP, so I’ve written some hints here.
First of all, you will need to log in to the API over https. To do this, I used PHP’s version of cURL. The function looks like this:
function submitHttpPost($url, $postParams = null, $timeout = 30) {
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt ($ch, CURLOPT_HTTPHEADER, Array("Content-Type:application/xml"));
curl_setopt($ch, CURLOPT_POSTFIELDS, $postParams);
curl_setopt($ch, CURLOPT_FAILONERROR, 1);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 3);
curl_setopt($ch, CURLOPT_TIMEOUT,$timeout);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 1);
set_time_limit(10 + $timeout + 5);
$result = curl_exec($ch);
curl_close($ch);
return $result;
}
The $url you provide to the function here is the login url specific to your account:
$url = 'https://{your em username}.exposuremanager.com/rest/login';
The $postParams variable is your login information. It should look something like this:
$authinfo = '<auth login="joePhotog" password="soS3cr3T" />';
It’s very important that the sting looks just like this, or the API will throw out errors. I spent a lot of time banging my head on the table trying to get this right.
So to use this function, your code will look something like this:
$resp = submitHttpPost($url, $authinfo);
$xml = new SimpleXMLElement($resp);
Now you are authenticated, and the results of the login transaction are stored as a SimpleXMLElement in the $xml variable.
Next you will want to query your gallery tree…to do that, you will need some different setting with cURL
function submitHttpGet($url, $session_id, $timeout=30)
{
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt ($ch, CURLOPT_COOKIE, 'EM_LA_SESSIONID='.$session_id);
curl_setopt($ch, CURLOPT_FAILONERROR, 1);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 3);
curl_setopt($ch, CURLOPT_TIMEOUT,$timeout);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 1);
// set the PHP script's timeout to be greater than CURL's
set_time_limit(10 + $timeout + 5);
$result = curl_exec($ch);
curl_close($ch);
return $result;
}
This time, the $url that you are passing is the URL for the galleries
$url2 ='https://{your em username}.exposuremanager.com/rest/galleries';
The code to get your gallery tree looks like this:
$gal = submitHttpGet($url2, $xml['session_id']);
To make the response into a SimpleXMLElement, again you would use:
$xml2 = new SimpleXMLElement($gal);
And there you have it…your gallery tree as XML.
A few more notes. The information provided by the API is very simple. Bascially you just the gallery name an the URI for the REST version of the gallery. You will have to do some string replacements to have it pointing to acutal URLs for the web version of the galleries. Also, I was able to sort out the galleries by date, because each gallery that I post has the date in the name field, in this format: 2007_09_22. Further, my code ignores any galleries that don’t start with a date. So the top-level galleries that I use for sorting do not show up on the list.
Without this information, there would be no way to sort the galleries chronologcally, or provide the dates. Hopefully the API will be extended….for starters, it would be really nice for instance if you could see if the gallery was public or private, if it were passsword protected, the date the gallery was created, and it would be great if you could get the URL for the gallery thumbnail.
Hope this helps!