//These are the variables you have to set ($secret can stay empty)
$email = "";
$password = "";
$api_key = "ENTER YOUR API KEY";
$secret = "ENTER YOUR SECRET";
$pathtoalbumdb = "ENTER PATH TO YOUR ALBUM e.g.: /home/user/www/albums";
//Do you want to let flickr handle the EXIF data in the file, or use the date taken stored by Gallery?
//No other data is taken from Gallery - only date taken, so all other EXIF data will be handled by flickr, if present
//Default lets flickr handle it
$letflickr = true;
//How do you want to upload your photos? 1 is visible to that category, 0 is hidden to that category
//To upload privately, set all of these to 0
$public = "1";
$friends = "1";
$family = "1";
//Allowed extensions
$allowed_ext = "jpg, JPG, jpeg, JPEG, gif, GIF, png, PNG";
//Put the allowed extentions into an array
$allowed = explode(', ', $allowed_ext);
$k = $_GET['gallery'];
$i = $_GET['i'];
$setid = $_GET['setid'];
class AlbumItem {}
class Image {}
class Album {}
class Comment {}
require_once("phpFlickr.php");
$f = new phpFlickr($api_key, $secret);
$f->auth("write");
// Can't get new authentication to work - invalid API key / sig, so using depreciated method in the mean time.
//$f->login($email, $password);
$albumdata = unserialize(file_get_contents($pathtoalbumdb . "albumdb.dat"));
if ( $_GET['gallery'] == "" ) {
for($k = 0; $k < count($albumdata); $k++) {
if ($albumdata[$k] != "PEAR") { //an ugly hack, but gallery can end up adding the PEAR directory to the database, so skip over it if it's there.
//echo "count = ".count($albumdata)."path=".$pathtoalbumdb . "albumdb.dat"."\n";
echo "To transfer " . $albumdata[$k] . ", click here
";
}
}
} else {
//Does a photoset for this album already exist?
//It might do. Let's check
//but not every time...
if ( $_GET['setid'] != "" ) {
$setpresent = true;
} else {
$setpresent = false;
//Could still exist, but we'd be resuming
$sets = $f->photosets_getList();
for ($n = 0; $n < count($sets); $n++) {
if ($sets[photoset][$n][title] == $albumdata[$k])
{
$setpresent = true;
//set the id
$setid = $sets[photoset][$n][id];
}
}
}
$data = file_get_contents($pathtoalbumdb . $albumdata[$k] . "/photos.dat");
$data = unserialize($data);
if ( $i < count($data) ) {
//Image name
$name = $data[$i]->image->name;
//Image type
$type = $data[$i]->image->type;
//Description
$description = $data[$i]->caption;
//Tags
$tags = str_replace(" ", ",", $data[$i]->keywords);
$comment = "";
for($j = 0; $j < count($data[$i]->comments); $j++) {
$comment .= "\n\n".$data[$i]->comments[$j]->name. " said: " . $data[$i]->comments[$j]->commentText;
}
//Add to description of photo
$description .= $comment;
//Does the photo exist in the photoset (if the photoset exists)?
$photoexists = false;
if ($setpresent) {
$photos = $f->photosets_getPhotos($setid);
for ($p = 0; $p < count($photos[photo]); $p++)
{
if ($photos[photo][$p][title] == $name)
{
$photoexists = true;
}
}
}
//Check good file extension
$good = false;
for ($m = 0; $m < count($allowed); $m++)
{
if ($allowed[$m] == $type)
{
$good = true;
}
}
if ( $good && !$photoexists ) {
//i.e. if the file has a valid extension and isn't already in the set...
echo "The image titled '". $name . "' with a description '". $description ."' and tags '".$tags."' found here
";
$photoid = $f->sync_upload($pathtoalbumdb . $albumdata[$k] . "/" . $name . "." . $type, $name, $description, $tags, $public, $friends, $family);
$f->phpFlickr($api_key, $secret);
//$f->login($email, $password);
$f->auth("write");
//Not sure why the 'refresh' above is necessary.
//Without it, when calling either of the functions below I get a "#112 Method not found" error.
if (!$setpresent){
//create set with photo as Primary photo
$setid = $f->photosets_create($albumdata[$k], "", $photoid);
$setid = $setid[id];
} else {
//add photo to set
$f->photosets_addPhoto($setid, $photoid);
}
//Now make the date on the photo correct, if the data is in the photos.dat file
//If there is a year set, assume that the data in this file is true
if ($data[$i]->itemCaptureDate[year] != "" && $letflickr == false ) {
//construct the date line according to the MYSQL format
$date = $data[$i]->itemCaptureDate[year] . "-" . $data[$i]->itemCaptureDate[mon] . "-" . $data[$i]->itemCaptureDate[mday] . " " . $data[$i]->itemCaptureDate[hours] . ":" . $data[$i]->itemCaptureDate[minutes] . ":" . $data[$i]->itemCaptureDate[seconds];
//Set it - again needs the refresh...
$f->phpFlickr($api_key, $secret);
// $f->login($email, $password);
$f->auth("write");
$f->photos_setDates($photoid, $date);
}
} else {
if (!$good) {
echo "The file " . $name . "." . $type . " wasn't uploaded, because it is of a type Flickr won't allow.";
}
if ($photoexists) {
echo "The file " . $name . "." . $type . " wasn't uploaded, because it appears to already be in the photoset.";
}
}
//Go to this page, but for the next photo....
echo '';
}
}
?>