"MDL-16341, add upload function for flickrlib"
authordongsheng <dongsheng>
Mon, 3 Nov 2008 03:22:55 +0000 (03:22 +0000)
committerdongsheng <dongsheng>
Mon, 3 Nov 2008 03:22:55 +0000 (03:22 +0000)
lib/flickrlib.php
portfolio/type/flickr/lib.php

index 14473e3..983c1b4 100755 (executable)
@@ -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;
+        }       
+    }
 }
 ?>
index dd64cae..2cdfb3d 100755 (executable)
@@ -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'),