コード例 #1
0
 /**
  * Display all information about the files in this batch.
  *
  * @return  void
  */
 public function viewFiles()
 {
     $files = $this->_batch->getFiles();
     if ($files) {
         $this->_write("Files:\n");
         foreach ($files as $file) {
             $title = $this->_batch->getTitleForFile($file);
             $desc = $this->_batch->getDescriptionForFile($file);
             $tags = $this->_batch->getTagsForFile($file);
             $date = $this->_batch->getTakenDateForFile($file);
             $this->_write($file . "\n");
             if ($title) {
                 $this->_write("Title:       {$title}\n");
             }
             if ($tags) {
                 $tags = implode(', ', $tags);
                 $this->_write("Tags:        {$tags}\n");
             }
             if ($date) {
                 if (is_long($date)) {
                     $date = date('Y-m-d H:i:s', $date);
                 }
                 $this->_write("Taken Date:  {$date}\n");
             }
             if ($desc) {
                 $this->_write("Description: {$desc}\n");
             }
             $this->_write("\n");
         }
     } else {
         $this->_write("There are no files in this batch.\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;
 }