コード例 #1
0
 /**
  * Display all information about the creation of a photoset.
  *
  * @return  void
  */
 public function viewSet()
 {
     if ($this->_batch->isSetWanted()) {
         $title = trim($this->_batch->getSetTitle());
         $desc = trim($this->_batch->getSetDescription());
         $this->_write("A photoset titled '{$title}' will be created. ");
         if ($desc) {
             $this->_write("Its description will be:\n{$desc}");
         }
         $this->_write("\n");
     } else {
         $this->_write("No photoset will be created.\n");
     }
 }
コード例 #2
0
ファイル: Uploader.php プロジェクト: seeminglee/smldata
 /**
  * Upload a batch of files to Flickr.
  *
  * @param   Phlickr_Uploader $uploader
  * @param   Phlickr_Framework_IUploadBatch $batch Provides a list of files
  *          and information on them.
  * @param   Phlickr_Framework_IUploadListener $listener Listens to event
  *          notifications on the status of the upload process.
  * @return  array An array of Phlickr_AuthedPhoto objects with the ids as
  *          the keys.
  * @uses    upload() to do the actual file uploads.
  * @uses    Phlickr_AuthedPhotosetList::create() to create the photoset
  *          if it's requested.
  * @uses    Phlickr_AuthedPhotoset::editPhotos() to put the photos into the
  *          set and select the primary photo.
  * @uses    Phlickr_AuthedPhoto::setTaken() to set the taken date if it's
  *          provided.
  * @since   0.2.5
  */
 function uploadBatch(Phlickr_Framework_IUploadBatch $batch, Phlickr_Framework_IUploadListener $listener)
 {
     // array of uploaded photo objects keyed by id
     $photos = array();
     // array of photo ids keyed by original filename
     $photoIds = array();
     // notify that the upload is starting
     $listener->beforeUpload();
     foreach ($batch->getFiles() as $file) {
         // notify that a file will be uploaded
         $listener->beforeFileUpload($file);
         // fetch the info for the photo
         $title = $batch->getTitleForFile($file);
         $desc = $batch->getDescriptionForFile($file);
         $tags = $batch->getTagsForFile($file);
         // upload it
         try {
             $photoId = $this->upload($file, $title, $desc, $tags);
             // some times it takes a second for the photo to show up.
             try {
                 $photo = new Phlickr_AuthedPhoto($this->_api, $photoId);
             } catch (Phlickr_MethodFailureException $ex) {
                 // give it 10 seconds and try again.
                 sleep(10);
                 $photo = new Phlickr_AuthedPhoto($this->_api, $photoId);
             }
             // keep a filename:id mapping...
             $photoIds[$file] = $photoId;
             // ... and a id:photo mapping
             $photos[$photoId] = $photo;
             // notify of success
             $listener->afterFileUpload($file, $photo);
         } catch (Phlickr_Exception $ex) {
             // notify of failure
             $listener->failedFileUpload($file, $ex);
         }
         // assign the taken date if one is provided
         try {
             $taken = $batch->getTakenDateForFile($file);
             if ($taken) {
                 $photo->setTaken($taken);
             }
         } catch (Phlickr_Exception $ex) {
             // don't worry about it.
         }
     }
     // create a photo set? only if we've got photos and a name.
     if ($photoIds && $batch->isSetWanted()) {
         // figure out the primary photo (if none was specified use the
         // first image)
         if (array_key_exists($batch->getSetPrimary(), $photoIds)) {
             $primaryId = $photoIds[$batch->getSetPrimary()];
         } else {
             // reset $photoIds so we can use current() to find the first value
             reset($photoIds);
             $primaryId = current($photoIds);
         }
         // create the photoset
         $list = new Phlickr_AuthedPhotosetList($this->_api);
         $set = $list->create($batch->getSetTitle(), $batch->getSetDescription(), $primaryId);
         // add the photos to the set
         $set->editPhotos($primaryId, $photoIds);
         // notify of the photoset creation
         $listener->afterCreatePhotoset($set);
     }
     // notify that the upload is complete
     $listener->afterUpload($photos);
     return $photos;
 }