/** * */ function _processIndUpload(&$oUploader, $myFileName, $tmpFile, $arrayInc, $myFileDir = '', $file) { $params = $this->getParams(); if ($params->get('ul_file_types') == '') { $params->set('ul_file_types', implode(',', $this->_aDefaultFileTypes)); } $folder = $params->get('ul_directory'); if ($myFileDir != '') { $folder .= JPath::clean(JPATH_SITE . '/' . $myFileDir); } $oUploader->_makeRecursiveFolders($folder); $folder = JPath::clean(JPATH_SITE . '/' . $folder); $err = null; // Set FTP credentials, if given jimport('joomla.client.helper'); JClientHelper::setCredentialsFromRequest('ftp'); if ($myFileName != '') { $filepath = JPath::clean($folder . '/' . JString::strtolower($myFileName)); if (!uploader::canUpload($file, $err, $params)) { return JError::raiseNotice(100, JText::_($err)); } if (JFile::exists($filepath)) { if ($params->get('ul_file_increment', 0)) { $filepath = uploader::incrementFileName($filepath, $filepath, 1); } else { return JError::raiseNotice(100, JText::_('A file of that name already exists')); } } if (!JFile::upload($tmpFile, $filepath)) { $oUploader->moveError = true; JError::raiseWarning(100, JText::_("Error. Unable to upload file (from {$tmpFile} to {$destFile})")); } else { jimport('joomla.filesystem.path'); JPath::setPermissions($destFile); //resize main image $oImage = FabimageHelper::loadLib($params->get('image_library')); $mainWidth = $params->get('fu_main_max_width'); $mainHeight = $params->get('fu_main_max_height'); if ($params->get('make_thumbnail') == '1') { $thumbPath = JPath::clean($params->get('thumb_dir') . '/' . $myFileDir . '/'); $thumbPrefix = $params->get('thumb_prefix'); $maxWidth = $params->get('thumb_max_width'); $maxHeight = $params->get('thumb_max_height'); if ($thumbPath != '') { $oUploader->_makeRecursiveFolders($thumbPath); } $destThumbFile = JPath::clean(JPATH_SITE . '/' . $thumbPath . '/' . $thumbPrefix . basename($filepath)); $msg = $oImage->resize($maxWidth, $maxHeight, $filepath, $destThumbFile); } if ($mainWidth != '' || $mainHeight != '') { $msg = $oImage->resize($mainWidth, $mainHeight, $filepath, $filepath); } $res = str_replace(JPATH_SITE, '', $filepath); return $res; } } }
/** * recursive file name incrementation untill no file with exsiting name * exists * @param string intial file name * @param string this recursions file name * @param 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 = rtrim($f, $version - 1); $newFileName = $f . $version . "." . $ext; $version++; $newFileName = uploader::incrementFileName($origFileName, $newFileName, $version); } return $newFileName; }
/** * process the upload (can be called via ajax from pluploader * @access private * * @param array $file info * @param string user selected upload folder * @param int 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 (!uploader::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 = uploader::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; }