Mejf
By: a guest | Feb 6th, 2010 | Syntax:
PHP | Size: 4.50 KB | Hits: 327 | Expires: Never
#!/usr/bin/php
<?php
// Fill these in...
$user = "";
$pass = "";
// You can get your own apikey here: http://bilddagboken.se/p/apiDoc.html
// 40 characters of hexadecimal fun
$apiKey = "";
$userid = -1;
// The commented code below is for finding out your userid.
// Uncomment the code, read the userid from stdout and insert it into the script.
// Or, uncomment and run the code for every picture you upload. Whatever...
/* $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;
$xml = shell_exec($exec);
// echo "$xml\n";
$prs = xml_parser_create();
xml_set_element_handler($prs, "startTag", null);
xml_set_character_data_handler($prs, "contents");
xml_parse($prs, $xml);*/
$picture = $argv[1];
} else {
$picture = trim(shell_exec("zenity --file-selection --file-filter=\"*.jpg\""));
}
}
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:
shell_exec("zenity --error --text=\"Invalid EXIF rotation: $or\"");
}
}
$title = file(getenv("HOME")."/.bdbuploadertitle");
$title = $title[0];
$title = trim(shell_exec("zenity --entry --text=\"Enter title\" --entry-text=\"".($title?
$title:"")."\""));
$text = $text[0];
$text = trim(shell_exec("zenity --entry --text=\"Enter description\" --entry-text=\"".($text?
$text:"")."\""));
// Extract date from directory
echo "$dir\n";
if ($ex) {
$year = (int) $ex[0];
$month = (int) $ex[1];
$day = (int) $ex[2];
}
$datenotok = (int
) shell_exec("zenity --question --ok-label=Yes --cancel-label=No --text=\"Is the date $year-$month-$day ok?\">/dev/null; echo $?");
if ($datenotok) {
$year = (int
) trim(shell_exec("zenity --entry --text=\"Enter year\" --entry-text=\"`date +%Y`\""));
$month = (int
) trim(shell_exec("zenity --entry --text=\"Enter month\" --entry-text=\"`date +%m`\""));
$day = (int
) trim(shell_exec("zenity --entry --text=\"Enter day\" --entry-text=\"`date +%d`\""));
}
}
echo "Uploading file $picture, '$title', '$text', date: $year-$month-$day\n";
do {
curl_setopt($ch, CURLOPT_URL
, "https://api.myphotodiary.com/users/$userid/images/dates/$year/$month/$day.json");
$parm = array("image" => "@$picture", "title" => "$title", "text" => "$text");
$parm["rotation"] = $rot;
if ($response == NULL) {
} else {
$donttryagain = true;
shell_exec("notify-send \"File ".basename($picture)." successfully uploaded to date $year-$month-$day!\"");
}
} while (!$donttryagain);
?>