"MDL-16341, add upload function for flickrlib"

This commit is contained in:
dongsheng 2008-11-03 03:22:55 +00:00
parent c1ded42472
commit b3e6e8047b
2 changed files with 51 additions and 1 deletions

View File

@ -1079,5 +1079,55 @@ class phpFlickr {
$this->request("flickr.urls.lookupUser", array("url"=>$url));
return $this->parsed_response ? $this->parsed_response['user'] : false;
}
/**
* upload a photo to flickr
* @param string $photo must be the path of the file
* @param string $title
* @param string $description
* @param string $tags
* @param string $is_public
* @param string $is_friend
* @param string $is_family
* @return boolean
*/
function upload ($photo, $title = null, $description = null, $tags = null, $is_public = null, $is_friend = null, $is_family = null) {
global $SESSION;
$args = array("async" => 1, "api_key" => $this->api_key, "title" => $title, "description" => $description, "tags" => $tags, "is_public" => $is_public, "is_friend" => $is_friend, "is_family" => $is_family);
if (!empty($this->email)) {
$args = array_merge($args, array("email" => $this->email));
}
if (!empty($this->password)) {
$args = array_merge($args, array("password" => $this->password));
}
// TODO:
// should we request a token if it is not valid?
if (!empty($this->token)) {
$args = array_merge($args, array("auth_token" => $this->token));
}
ksort($args);
$auth_sig = "";
foreach ($args as $key => $data) {
if ($data !== null) {
$auth_sig .= $key . $data;
} else {
unset($args[$key]);
}
}
if (!empty($this->secret)) {
$api_sig = md5($this->secret . $auth_sig);
$args['api_sig'] = $api_sig;
}
$photo = realpath($photo);
$args['photo'] = '@'.$photo;
if ($response = $this->curl->post($this->Upload, $args)) {
return true;
} else {
return false;
}
}
}
?>

View File

@ -26,7 +26,7 @@ class portfolio_plugin_flickr extends portfolio_plugin_push_base {
$filesize = $file->get_filesize();
if ($file->is_valid_image()) {
$return = $this->flickr->request ('upload', array('photo' => $file,
$return = $this->flickr->upload ('upload', array('photo' => $file,
'title' => $this->get_export_config('title'),
'description' => $this->get_export_config('description'),
'tags' => $this->get_export_config('tags'),