Esempio n. 1
0
 /**
  * Moves uploaded file to $destDir. If $oldPath is given by copying from there
  * (used in case of ftp uploads). Otherwise the wordpress built-in upload handler
  * is called that copies from the temporary upload directory.
  *
  * @param string $destDir
  * @param string $oldPath
  * @return array	containing info on uploaded file.
  */
 function _handleUpload($destDir, $oldPath = '')
 {
     $destDir = rtrim($destDir, '/\\');
     PhotoQHelper::debug('destDir: ' . $destDir);
     if ($oldPath === '') {
         /*try to use the functions provided by wordpress, however there is no way to
         		specify the upload path other than changing the option, so we do this */
         //save the old value
         $oldUploadPath = get_option('upload_path');
         update_option('upload_path', $destDir);
         //do the same for yearmonth_folders
         $oldYMFolders = get_option('uploads_use_yearmonth_folders');
         update_option('uploads_use_yearmonth_folders', 0);
         //turn this off
         //set the options that we override
         $overrides = array('action' => 'save');
         $overrides['test_form'] = false;
         //don't test the form, swfupload is not (yet) able to send additional post vars.
         $overrides['mimes'] = apply_filters('upload_mimes', array('jpg|jpeg|jpe' => 'image/jpeg', 'gif' => 'image/gif', 'png' => 'image/png', 'bmp' => 'image/bmp', 'tif|tiff' => 'image/tiff'));
         PhotoQHelper::debug('uploadPhoto: start upload');
         //upload the thing
         $file = wp_handle_upload($_FILES['Filedata'], $overrides);
         //PhotoQHelper::debug(print_r($file, true));
         //reset upload options to saved ones
         update_option('upload_path', $oldUploadPath);
         update_option('uploads_use_yearmonth_folders', $oldYMFolders);
     } else {
         /* ftp upload */
         $newPath = $destDir . '/' . basename($oldPath);
         //move file if we have permissions, otherwise copy file
         //suppress warnings if original could not be deleted due to missing permissions
         $ok = @PhotoQHelper::moveFileIfNotExists($oldPath, $newPath);
         if (!$ok) {
             $file['error'] = "Unable to move {$oldPath} to {$newPath}";
         }
         $file['file'] = $newPath;
     }
     //check for errors
     if (isset($file['error'])) {
         // return new PhotoQErrorMessage($file['error']);
         $this->_errStack->push(PHOTOQ_FILE_UPLOAD_FAILED, 'error', array('errMsg' => $file['error']));
         return false;
     }
     //get the path to the new file
     $path = $file['file'];
     PhotoQHelper::debug('uploadPhoto: upload ok, path: ' . $path);
     return $path;
 }
Esempio n. 2
0
 /**
  * Something like this will be used to allow users to switch imgdir
  *
  */
 function _moveImgDir($oldImgDir, $includingOriginal = true)
 {
     //$oldImgDir = $this->_oc->getOldValues('imgdir');
     //move all dirs to the new place
     $newImgDir = $this->_oc->getImgDir();
     $dirs2move = $this->_getOldImgDirContent($oldImgDir, $includingOriginal);
     foreach ($dirs2move as $dir2move) {
         $moveTo = $this->_oc->getImgDir() . basename($dir2move);
         if (!PhotoQHelper::moveFileIfNotExists($dir2move, $moveTo)) {
             $this->_errStack->push(PHOTOQ_COULD_NOT_MOVE, 'error', array('source' => $dir2move, 'dest' => $moveTo));
         }
         //else
         // @todo we might want to use sth like this to make it more flexible for users who
         //already messed up with their imgdir
         //	PhotoQHelper::mergeDirs($dir2move, $moveTo);
     }
     //update the watermark directory database entry
     $oldWatermarkPath = get_option("wimpq_watermark");
     if ($oldWatermarkPath) {
         $oldWMFolder = $oldImgDir . 'photoQWatermark/';
         $newWMFolder = $newImgDir . 'photoQWatermark/';
         $newWatermarkPath = str_replace($oldWMFolder, $newWMFolder, $oldWatermarkPath);
         update_option("wimpq_watermark", $newWatermarkPath);
     }
     /*
     //$publishedPhotos = $this->_db->getAllPublishedPhotos();
     
     
     
     
     //get all photo posts, foreach size, rebuild the photo
     foreach ( $this->_db->getAllPublishedPhotos() as $photo ){
     	$photo->rebuild( array(), false, true, 
     		true, ($oldImgDir).$this->_oc->ORIGINAL_IDENTIFIER, $this->_oc->getImgDir().$this->_oc->ORIGINAL_IDENTIFIER);
     }
     */
 }