/** * Updates an image in a Picasa Web Album. This method can be used for updating just the meta data or the meta data and image itself. * Passing null to any of the meta data parameters will cause that value in the album to not update. * To just update the meta data and not the image itself, pass null to $newImageLocation and $type, and make sure at least * one of the meta data parameters is not null. To update just the image contents and not the meta data, make sure all * meta data parameters are null and the image location is not. * * @access public * @param string $username The username on the account that the image is in. * @param string $albumid The id number of the album to that the image is in. * @param string $imageid The id number of the image to update. * @param string $title The title that the image will be given. Optional, the default is null. * @param string $summary A summary of what is in the image. Optional, the default is null. * @param string $keywords A comma-delimited list of keywords associated with the image. Optional, the default is null. * @param string $commentingEnabled Set to true if other users should be able to comment on the image and false * if they shouldn't. Optional, the default is null. * @param string $timestamp The number of miliseconds after the Unix epoch (January 1st, 1970) that the image was taken (roughly). * @param string $gmlPosition The location in the world that this image was taken. The format is latitude and longitude, * separated by a space. Optional, the default is null. * @param string $newImageLocation The path to the image on the local file system or network. * You can specify a URL. This parameter can be null, in which * case only the meta data will be updated. * @param string $type The type of image that is being uploaded. Picasa currently accepts "image/bmp", * "image/gif", "image/jpeg", and "image/png". This parameter can be null if the * $locationOnDisk parameter is also null, in which case on the meta data of the image * will be updated and the image itself will stay the same. * @return Picasa_Image The image that was updated. * @throws {@link Picasa_Exception} If something was wrong with the post to Picasa. A specific subclass of * {@link Picasa_Exception} will be thrown based on what kind of problem was * encountered, unless the type of error was unknown, in which case {@link Picasa_Exception} * itself will be thrown. * @link http://code.google.com/support/bin/answer.py?answer=63316&topic=10973 */ public function updateImage($username, $albumid, $imageid, $title = null, $summary = null, $keywords = null, $commentingEnabled = null, $timestamp = null, $gmlPosition = null, $newImageLocation = null, $type = null) { $host = Picasa::$PICASA_URL; $uploadImage = $this->getImageByIdAsEntry($username, $albumid, $imageid); $data = ""; $binaryUpdate = false; $metaUpdate = false; // Check to see if this will be a multipart document if ($title != null || $summary != null || $keywords != null || $commentingEnabled != null || $timestamp != null || $gmlPosition != null) { $metaUpdate = true; } if ($newImageLocation != null) { $binaryUpdate = true; } // Get the XML for the meta data if ($metaUpdate) { if ($title == null) { $title = $uploadImage->getTitle(); } if ($summary == null) { $summary = $uploadImage->getDescription(); } if ($commentingEnabled == null) { $commentingEnabled = $uploadImage->getCommentingEnabled(); } if ($timestamp == null) { $timestamp = $uploadImage->getTimestamp(); } $metaXML = Picasa::constructImageXML($title, $summary, $keywords, $commentingEnabled, $timestamp, $gmlPosition); } // Get the binary data if ($binaryUpdate) { if ($type == null) { throw new Picasa_Exception("Image must be accompanied by type."); } $fileContents = @file_get_contents($newImageLocation); if ($fileContents === false) { throw new Picasa_Exception_FileNotFoundException("The specified file could not be found."); } } if ($metaUpdate && $binaryUpdate) { $size = strlen($fileContents); $path = '/data/media/api/user/'; $contentType = "multipart/related; boundary=\"END_OF_PART\""; $authHeader = array(1 => $this->getAuthHeader(), 2 => "MIME-version: 1.0\r\n"); $data = "\r\n\r\nMedia multipart posting\r\n--END_OF_PART\r\nContent-Type: application/atom+xml\r\n\r\n{$metaXML}\r\n--END_OF_PART\r\nContent-Type: {$type}\r\n\r\n{$fileContents}\r\n--END_OF_PART--"; } else { if ($metaUpdate) { $contentType = "application/atom+xml"; $authHeader = array(1 => $this->getAuthHeader()); $path = '/data/entry/api/user/'; $size = strlen($metaXML); $data = $metaXML; } else { if ($binaryUpdate) { $size = strlen($fileContents); $path = '/data/media/api/user/'; $contentType = "{$type}"; $authHeader = array(1 => $this->getAuthHeader(), 2 => "MIME-version: 1.0\r\n"); $data = $fileContents; } else { // If nothing was sent for updating, just return the image return $uploadImage; } } } $path .= $username . '/albumid/' . $albumid . '/photoid/' . $imageid . '/' . $uploadImage->getVersion(); try { Picasa::do_request($host, $path, $data, "PUT", $authHeader, $contentType); } catch (Picasa_Exception $e) { throw Picasa::getExceptionFromInvalidPost($e->getResponse(), $e->getMessage()); } try { $retObj = $this->getImageById($username, $albumid, $imageid); } catch (Picasa_Exception $e) { throw new Picasa_Exception("The image was successfully updated but then the following error was encountered: " . $e->getMessage(), $e->getResponse(), $e->getUrl()); } return $retObj; }