Exemple #1
0
 /**
  * Process the upload (can be called via ajax from pluploader
  *
  * @param   array   &$file               file info
  * @param   string  $myFileDir           user selected upload folder
  * @param   int     $repeatGroupCounter  repeat group counter
  *
  * @return	string	location of uploaded file
  */
 protected function _processIndUpload(&$file, $myFileDir = '', $repeatGroupCounter = 0)
 {
     $params = $this->getParams();
     $storage = $this->getStorage();
     // $$$ hugh - check if we need to blow away the cached filepath, set in validation
     $myFileName = $storage->cleanName($file['name'], $repeatGroupCounter);
     if ($myFileName != $file['name']) {
         $file['name'] = $myFileName;
         unset($this->_filePaths[$repeatGroupCounter]);
     }
     $tmpFile = $file['tmp_name'];
     $uploader = $this->getFormModel()->getUploader();
     if ($params->get('ul_file_types') == '') {
         $params->set('ul_file_types', implode(',', $this->_getAllowedExtension()));
     }
     $err = null;
     // Set FTP credentials, if given
     jimport('joomla.client.helper');
     JClientHelper::setCredentialsFromRequest('ftp');
     if ($myFileName == '') {
         return;
     }
     $filepath = $this->_getFilePath($repeatGroupCounter);
     if (!FabrikUploader::canUpload($file, $err, $params)) {
         $this->setError(100, $file['name'] . ': ' . JText::_($err));
     }
     if ($storage->exists($filepath)) {
         switch ($params->get('ul_file_increment', 0)) {
             case 0:
                 break;
             case 1:
                 $filepath = FabrikUploader::incrementFileName($filepath, $filepath, 1);
                 break;
             case 2:
                 $storage->delete($filepath);
                 break;
         }
     }
     if (!$storage->upload($tmpFile, $filepath)) {
         $uploader->moveError = true;
         $this->setError(100, JText::sprintf('PLG_ELEMENT_FILEUPLOAD_UPLOAD_ERR', $tmpFile, $filepath));
         return;
     }
     $filepath = $storage->getUploadedFilePath();
     jimport('joomla.filesystem.path');
     $storage->setPermissions($filepath);
     // $$$ hugh @TODO - shouldn't we check to see if it's actually an image before we do any of this stuff???
     // Resize main image
     $oImage = FabimageHelper::loadLib($params->get('image_library'));
     $oImage->setStorage($storage);
     /* $$$ hugh - removing default of 200, otherwise we ALWAYS resize, whereas
      * tooltip on these options say 'leave blank for no resizing'
      */
     $mainWidth = $params->get('fu_main_max_width', '');
     $mainHeight = $params->get('fu_main_max_height', '');
     if ($mainWidth != '' || $mainHeight != '') {
         // $$$ rob ensure that both values are integers otherwise resize fails
         if ($mainHeight == '') {
             $mainHeight = (int) $mainWidth;
         }
         if ($mainWidth == '') {
             $mainWidth = (int) $mainHeight;
         }
         $oImage->resize($mainWidth, $mainHeight, $filepath, $filepath);
     }
     // $$$ hugh - if it's a PDF, make sure option is set to attempt PDF thumb
     $make_thumbnail = $params->get('make_thumbnail') == '1' ? true : false;
     if (JFile::getExt($filepath) == 'pdf' && $params->get('fu_make_pdf_thumb', '0') == '0') {
         $make_thumbnail = false;
     }
     if ($make_thumbnail) {
         $thumbPath = $storage->clean(JPATH_SITE . '/' . $params->get('thumb_dir') . '/' . $myFileDir . '/', false);
         $w = new FabrikWorker();
         $thumbPath = $w->parseMessageForPlaceHolder($thumbPath);
         $thumbPrefix = $params->get('thumb_prefix');
         $maxWidth = $params->get('thumb_max_width', 125);
         $maxHeight = $params->get('thumb_max_height', 125);
         if ($thumbPath != '') {
             if (!$storage->folderExists($thumbPath)) {
                 if (!$storage->createFolder($thumbPath)) {
                     JError::raiseError(21, "Could not make dir {$thumbPath} ");
                 }
             }
         }
         $fileURL = $storage->getFileUrl(str_replace(COM_FABRIK_BASE, '', $filepath));
         $destThumbFile = $storage->_getThumb($fileURL);
         $destThumbFile = $storage->urlToPath($destThumbFile);
         $oImage->resize($maxWidth, $maxHeight, $filepath, $destThumbFile);
         $storage->setPermissions($destThumbFile);
     }
     $storage->setPermissions($filepath);
     $storage->finalFilePathParse($filepath);
     return $filepath;
 }
Exemple #2
0
 /**
  * Process the upload (can be called via ajax from pluploader)
  *
  * @param   array   &$file               File info
  * @param   string  $myFileDir           User selected upload folder
  * @param   int     $repeatGroupCounter  Repeat group counter
  *
  * @return	string	Location of uploaded file
  */
 protected function _processIndUpload(&$file, $myFileDir = '', $repeatGroupCounter = 0)
 {
     $params = $this->getParams();
     $storage = $this->getStorage();
     $quality = (int) $params->get('image_quality', 100);
     // $$$ hugh - check if we need to blow away the cached file-path, set in validation
     $myFileName = $storage->cleanName($file['name'], $repeatGroupCounter);
     if ($myFileName != $file['name']) {
         $file['name'] = $myFileName;
         unset($this->_filePaths[$repeatGroupCounter]);
     }
     $tmpFile = $file['tmp_name'];
     $uploader = $this->getFormModel()->getUploader();
     if ($params->get('ul_file_types') == '') {
         $params->set('ul_file_types', implode(',', $this->_getAllowedExtension()));
     }
     $err = null;
     // Set FTP credentials, if given
     jimport('joomla.client.helper');
     JClientHelper::setCredentialsFromRequest('ftp');
     if ($myFileName == '') {
         return;
     }
     $filePath = $this->_getFilePath($repeatGroupCounter);
     if (!FabrikUploader::canUpload($file, $err, $params)) {
         $this->setError($file['name'] . ': ' . FText::_($err));
     }
     if ($storage->exists($filePath)) {
         switch ($params->get('ul_file_increment', 0)) {
             case 0:
                 break;
             case 1:
                 $filePath = FabrikUploader::incrementFileName($filePath, $filePath, 1);
                 break;
             case 2:
                 JLog::add('Ind upload Delete file: ' . $filePath . '; user = '******'id'), JLog::WARNING, 'com_fabrik.element.fileupload');
                 $storage->delete($filePath);
                 break;
         }
     }
     if (!$storage->upload($tmpFile, $filePath)) {
         $uploader->moveError = true;
         $this->setError(100, JText::sprintf('PLG_ELEMENT_FILEUPLOAD_UPLOAD_ERR', $tmpFile, $filePath));
         return;
     }
     $filePath = $storage->getUploadedFilePath();
     jimport('joomla.filesystem.path');
     $storage->setPermissions($filePath);
     if (FabrikWorker::isImageExtension($filePath)) {
         $oImage = FabimageHelper::loadLib($params->get('image_library'));
         $oImage->setStorage($storage);
         if ($params->get('upload_use_wip', '0') == '1') {
             if ($params->get('fileupload_storage_type', 'filesystemstorage') == 'filesystemstorage') {
                 $mapElementId = $params->get('fu_map_element');
                 if (!empty($mapElementId)) {
                     $coordinates = $oImage->getExifCoordinates($filePath);
                     if (!empty($coordinates)) {
                         $formModel = $this->getFormModel();
                         $mapElementModel = $formModel->getElement($mapElementId, true);
                         $mapParams = $mapElementModel->getParams();
                         $zoom = $mapParams->get('fb_gm_zoomlevel', '10');
                         $coordinates_str = '(' . $coordinates[0] . ',' . $coordinates[1] . '):' . $zoom;
                         $mapElementName = $mapElementModel->getFullName(true, false);
                         $formModel->updateFormData($mapElementName, $coordinates_str, true);
                     }
                 }
                 $oImage->rotateImageFromExif($filePath, '');
             }
         }
         // Resize main image
         $mainWidth = $params->get('fu_main_max_width', '');
         $mainHeight = $params->get('fu_main_max_height', '');
         if ($mainWidth != '' || $mainHeight != '') {
             // $$$ rob ensure that both values are integers otherwise resize fails
             if ($mainHeight == '') {
                 $mainHeight = (int) $mainWidth;
             }
             if ($mainWidth == '') {
                 $mainWidth = (int) $mainHeight;
             }
             $oImage->resize($mainWidth, $mainHeight, $filePath, $filePath, $quality);
         }
     }
     // $$$ hugh - if it's a PDF, make sure option is set to attempt PDF thumb
     $make_thumbnail = $params->get('make_thumbnail') == '1' ? true : false;
     if (JFile::getExt($filePath) == 'pdf' && $params->get('fu_make_pdf_thumb', '0') == '0') {
         $make_thumbnail = false;
     }
     // $$$ trob - oImage->rezise is only set if isImageExtension
     if (!FabrikWorker::isImageExtension($filePath)) {
         $make_thumbnail = false;
     }
     if ($make_thumbnail) {
         $thumbPath = $storage->clean(JPATH_SITE . '/' . $params->get('thumb_dir') . '/' . $myFileDir . '/', false);
         $w = new FabrikWorker();
         $formModel = $this->getFormModel();
         $thumbPath = $w->parseMessageForRepeats($thumbPath, $formModel->formData, $this, $repeatGroupCounter);
         $thumbPath = $w->parseMessageForPlaceHolder($thumbPath);
         $maxWidth = $params->get('thumb_max_width', 125);
         $maxHeight = $params->get('thumb_max_height', 125);
         if ($thumbPath != '') {
             if (!$storage->folderExists($thumbPath)) {
                 if (!$storage->createFolder($thumbPath)) {
                     throw new RuntimeException("Could not make dir {$thumbPath}");
                 }
             }
         }
         $fileURL = $storage->getFileUrl(str_replace(COM_FABRIK_BASE, '', $filePath));
         $destThumbFile = $storage->_getThumb($fileURL);
         $destThumbFile = $storage->urlToPath($destThumbFile);
         $oImage->resize($maxWidth, $maxHeight, $filePath, $destThumbFile, $quality);
         $storage->setPermissions($destThumbFile);
     }
     $storage->setPermissions($filePath);
     $storage->finalFilePathParse($filePath);
     return $filePath;
 }
Exemple #3
0
 /**
  * Recursive file name incrementation untill no file with exsiting name
  * exists
  *
  * @param   $origFileName  string  intial file name
  * @param   $newFileName   string  this recursions file name
  * @param   $version       int     file version
  *
  * @return  string  new file name
  */
 function incrementFileName($origFileName, $newFileName, $version)
 {
     if (JFile::exists($newFileName)) {
         $bits = explode('.', $newFileName);
         $ext = array_pop($bits);
         $f = implode('.', $bits);
         $f = JString::rtrim($f, $version - 1);
         $newFileName = $f . $version . "." . $ext;
         $version++;
         $newFileName = FabrikUploader::incrementFileName($origFileName, $newFileName, $version);
     }
     return $newFileName;
 }