Mejf
By: a guest | Feb 25th, 2010 | Syntax:
PHP | Size: 5.10 KB | Hits: 371 | Expires: Never
#!/usr/bin/php
<?php
// Fill these in...
$user = "";
$pass = "";
$apiKey = "fd1e8237b859ceead8b6bc0549913e6fe254c609";
$userid = -1;
// The code below is for finding out your userid.
$rightTag = false;
function startTag($prs, $data) {
global $rightTag;
if ($data == "USERID")
$rightTag = true;
}
function contents($prs, $data) {
global $rightTag, $userid;
if ($rightTag) {
$userid = (int) $data;
$rightTag = false;
echo "userid: $userid\n";
}
}
$userinfoForm = "https://api.myphotodiary.com" . "/login_status.xml";
$exec = "curl -H \"Expect:\" -u \"" . $user . ":" . $pass . "\" -F \"api_key=" . $apiKey . "\" " . $userinfoForm;
// echo "$xml\n";
function error($msg, $exit=true) {
if ($exit)
}
function confirm($msg) {
return 1
- (int
) shell_exec("zenity --question --ok-label=Yes --cancel-label=No --text=".escapeshellarg($msg).">/dev/null; echo $?");
}
function input($msg, $default="", $width=200) {
$targ = "";
foreach ($default as $t) {
}
$default = $targ;
} else {
}
return trim(shell_exec("zenity --entry --text=\"$msg\" --entry-text=$default --width=$width"));
}
function exif2timestamp($exifString) {
$exifPieces = explode(":", $exifString);
return strtotime($exifPieces[0] . "-" . $exifPieces[1] . "-" . $exifPieces[2] . ":" . $exifPieces[3] . ":" . $exifPieces[4
]);
}
$picture = $argv[1];
} else {
$picture = trim(shell_exec("zenity --file-selection --file-filter=\"*.jpg\""));
}
error("File does not exist: $picture");
}
//var_dump($exif);
if ($exif && isset($exif['Orientation'])) {
$or = $exif['Orientation'];
switch ($or) {
case 1: break;
case 3: $rot = 2; break;
case 6: $rot = 1; break;
case 8: $rot = 3; break;
default:
error("Invalid EXIF rotation: $or");
}
}
echo date("Y n j\n", exif2timestamp
($exif['DateTime']));
$edate = array('y' => (int
) date("Y", exif2timestamp
($exif['DateTime'])), 'm' => (int
) date("n", exif2timestamp
($exif['DateTime'])), 'd' => (int
) date("j", exif2timestamp
($exif['DateTime'])));
$title = input
("Enter title", file(getenv("HOME")."/.bdbuploadertitle"));
$text = input
("Enter description", file(getenv("HOME")."/.bdbuploadertext"), 600
);
error("Can not have empty description!");
}
// Extract date from directory
echo "$dir\n";
$dateok = false;
if ($ex && count($ex) == 3
) {
$ddate = array('y' => (int
) $ex[0], 'm' => (int
) $ex[1], 'd' => (int
) $ex[2
]);
$dateok = confirm("Is the date {$ddate['y']}-{$ddate['m']}-{$ddate['d']} (found by directory) ok?");
}
if (!$dateok) {
$year = (int
) input
("Enter year", date("Y"));
$month = (int
) input
("Enter month", date("n"));
$day = (int
) input
("Enter day", date("j"));
$date = array('y' => $year, 'm' => $month, 'd' => $day);
} else {
$date = $ddate;
}
if (!checkdate($date['m'], $date['d'], $date['y'])) {
error("Invalid date: {$date['y']}-{$date['m']}-{$date['d']}");
}
echo "Uploading file $picture, '$title', '$text', date: {$date['y']}-{$date['m']}-{$date['d']}\n";
do {
curl_setopt($ch, CURLOPT_URL
, "https://api.myphotodiary.com/users/$userid/images/dates/{$date['y']}/{$date['m']}/{$date['d']}.json");
$parm = array("image" => "@$picture", "title" => "$title", "text" => "$text");
$parm["rotation"] = $rot;
if ($response == NULL) {
$tryagain = confirm
("Failed (".curl_error($ch).") to upload file: $picture, Title: $title, Text: $text. Try again?");
} else {
$tryagain = false;
shell_exec("notify-send \"File ".basename($picture)." successfully uploaded to date {$date['y']}-{$date['m']}-{$date['d']}!\"");
}
} while ($tryagain);
?>