Exemple #1
0
 function getOptions()
 {
     require_once COM_FABRIK_FRONTEND . DS . 'helpers' . DS . 'image.php';
     $imageLibs = FabimageHelper::getLibs();
     if (empty($imageLibs)) {
         return JHTML::_('select.option', JText::_('NO MAGE LIBRARY FOUND'));
     }
     return $imageLibs;
 }
Exemple #2
0
 /**
  * Method to get the field options.
  *
  * @return  array  The field option objects.
  */
 protected function getOptions()
 {
     require_once COM_FABRIK_FRONTEND . '/helpers/image.php';
     $imageLibs = FabimageHelper::getLibs();
     if (empty($imageLibs)) {
         return JHTML::_('select.option', JText::_('COM_FABRIK_IMAGELIBS_NOT_FOUND'));
     }
     return $imageLibs;
 }
Exemple #3
0
 public static function getLibs()
 {
     $libs = array();
     $gds = FabimageHelper::testGD();
     foreach ($gds as $key => $val) {
         $libs[] = JHTML::_('select.option', $key, $val);
     }
     $im = FabimageHelper::testImagemagick();
     foreach ($im as $key => $val) {
         $libs[] = JHTML::_('select.option', $key, $val);
     }
     return $libs;
 }
Exemple #4
0
 /**
  *
  */
 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;
         }
     }
 }
Exemple #5
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 #6
0
 /**
  * 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;
 }
Exemple #7
0
 /**
  * Do the plug-in action
  *
  * @param   array $opts Custom options
  *
  * @return  bool
  */
 public function process($opts = array())
 {
     $params = $this->getParams();
     $input = $this->app->input;
     $model = $this->getModel();
     $ids = $input->get('ids', array(), 'array');
     $downloadPdf = $params->get('download_pdfs', '0') === '1';
     $downloadTable = $params->get('download_table');
     $downloadFk = $params->get('download_fk');
     $downloadFile = $params->get('download_file');
     $download_width = $params->get('download_width');
     $download_height = $params->get('download_height');
     $downloadResize = $download_width || $download_height ? true : false;
     $fileList = array();
     $zipErr = '';
     if ($downloadPdf) {
         $fileList = $this->getPDFs('ids');
     } elseif (empty($downloadFk) && empty($downloadFile) && empty($downloadTable)) {
         return;
     } elseif (empty($downloadFk) && empty($downloadTable) && !empty($downloadFile)) {
         $downloadFiles = explode(',', $downloadFile);
         foreach ($ids as $id) {
             $row = $model->getRow($id);
             foreach ($downloadFiles as $dl) {
                 $dl = trim($dl);
                 if (isset($row->{$dl}) && !empty($row->{$dl})) {
                     $tmpFiles = explode(GROUPSPLITTER, $row->{$dl});
                     foreach ($tmpFiles as $tmpFile) {
                         $thisFile = JPATH_SITE . '/' . $tmpFile;
                         if (JFile::exists($thisFile)) {
                             $fileList[] = $thisFile;
                         }
                     }
                 }
             }
         }
     } else {
         $db = FabrikWorker::getDbo();
         $query = $db->getQuery(true);
         $query->select($db->qn($downloadFile))->from($db->qn($downloadTable))->where($db->qn($downloadFk) . ' IN (' . implode(',', $db->q($ids)) . ')');
         $db->setQuery($query);
         $results = $db->loadObjectList();
         foreach ($results as $result) {
             $thisFile = JPATH_SITE . '/' . $result->{$downloadFile};
             if (is_file($thisFile)) {
                 $fileList[] = $thisFile;
             }
         }
     }
     if (!empty($fileList)) {
         if ($downloadResize) {
             ini_set('max_execution_time', 300);
             require_once COM_FABRIK_FRONTEND . '/helpers/image.php';
             $storage = $this->getStorage();
             $downloadImageLibrary = $params->get('download_image_library');
             $oImage = FabimageHelper::loadLib($downloadImageLibrary);
             $oImage->setStorage($storage);
         }
         /**
          * $$$ hugh - system tmp dir is sometimes not readable, i.e. on restrictive open_base_dir setups,
          * so use J! tmp folder instead.
          * $zipFile = tempname(sys_get_temp_dir(), "zip");
          */
         $zipFile = tempnam($this->config->get('tmp_path'), "zip");
         $zipFileBasename = basename($zipFile);
         $zip = new ZipArchive();
         $zipRes = $zip->open($zipFile, ZipArchive::CREATE);
         if ($zipRes === true) {
             $zipTotal = 0;
             $tmpFiles = array();
             foreach ($fileList as $thisFile) {
                 $thisBaseName = basename($thisFile);
                 if ($downloadResize && $oImage->getImgType($thisFile)) {
                     $tmpFile = '/tmp/' . $thisBaseName;
                     $oImage->resize($download_width, $download_height, $thisFile, $tmpFile);
                     $thisFile = $tmpFile;
                     $tmpFiles[] = $tmpFile;
                 }
                 $zipAdd = $zip->addFile($thisFile, $thisBaseName);
                 if ($zipAdd === true) {
                     $zipTotal++;
                 } else {
                     $zipErr .= FText::_('ZipArchive add error: ' . $zipAdd);
                 }
             }
             if (!$zip->close()) {
                 $zipErr = FText::_('ZipArchive close error') . $zip->status;
             }
             if ($downloadResize) {
                 foreach ($tmpFiles as $tmpFile) {
                     $storage->delete($tmpFile);
                 }
             }
             if ($downloadPdf) {
                 foreach ($fileList as $tmpFile) {
                     JFile::delete($tmpFile);
                 }
             }
             if ($zipTotal > 0) {
                 // Stream the file to the client
                 $fileSize = filesize($zipFile);
                 if ($fileSize > 0) {
                     header('Content-Type: application/zip');
                     header('Content-Length: ' . filesize($zipFile));
                     header('Content-Disposition: attachment; filename="' . $zipFileBasename . '.zip"');
                     echo file_get_contents($zipFile);
                     JFile::delete($zipFile);
                     exit;
                 } else {
                     $zipErr .= FText::_('PLG_FABRIK_LIST_DOWNLOAD_ZIP_EMPTY');
                 }
             }
         } else {
             $zipErr = FText::_('ZipArchive open error, cannot create file : ' . $zipFile . ' : ' . $zipRes);
         }
     } else {
         $zipErr = FText::_("PLG_FABRIK_LIST_DOWNLOAD_ZIP_NO_FILES");
     }
     if (empty($zipErr)) {
         return true;
     } else {
         $this->msg = $zipErr;
         return false;
     }
 }
Exemple #8
0
 /**
  * Do the plug-in action
  *
  * @param   object  $params  plugin parameters
  * @param   object  &$model  list model
  * @param   array   $opts    custom options
  *
  * @return  bool
  */
 public function process($params, &$model, $opts = array())
 {
     $ids = JRequest::getVar('ids', array(), 'method', 'array');
     $download_table = $params->get('download_table');
     $download_fk = $params->get('download_fk');
     $download_file = $params->get('download_file');
     $download_width = $params->get('download_width');
     $download_height = $params->get('download_height');
     $download_resize = $download_width || $download_height ? true : false;
     $table = $model->getTable();
     $filelist = array();
     $zip_err = '';
     if (empty($download_fk) && empty($download_file) && empty($download_table)) {
         return;
     } elseif (empty($download_fk) && empty($download_table) && !empty($download_file)) {
         foreach ($ids as $id) {
             $row = $model->getRow($id);
             if (isset($row->{$download_file})) {
                 $this_file = JPATH_SITE . '/' . $row->{$download_file};
                 if (is_file($this_file)) {
                     $filelist[] = $this_file;
                 }
             }
         }
     } else {
         $db = FabrikWorker::getDbo();
         $ids_string = implode(',', $ids);
         $query = "SELECT {$download_file} FROM {$download_table} WHERE {$download_fk} IN ({$ids_string})";
         $db->setQuery($query);
         $results = $db->loadObjectList();
         foreach ($results as $result) {
             $this_file = JPATH_SITE . DS . $result->{$download_file};
             if (is_file($this_file)) {
                 $filelist[] = $this_file;
             }
         }
     }
     if (!empty($filelist)) {
         if ($download_resize) {
             ini_set('max_execution_time', 300);
             require_once COM_FABRIK_FRONTEND . '/helpers/image.php';
             $storage = $this->getStorage();
             $download_image_library = $params->get('download_image_library');
             $oImage = FabimageHelper::loadLib($download_image_library);
             $oImage->setStorage($storage);
         }
         $zipfile = tempnam(sys_get_temp_dir(), "zip");
         $zipfile_basename = basename($zipfile);
         $zip = new ZipArchive();
         $zipres = $zip->open($zipfile, ZipArchive::OVERWRITE);
         if ($zipres === true) {
             $ziptot = 0;
             $tmp_files = array();
             foreach ($filelist as $this_file) {
                 $this_basename = basename($this_file);
                 if ($download_resize && $oImage->getImgType($this_file)) {
                     $tmp_file = '/tmp/' . $this_basename;
                     $oImage->resize($download_width, $download_height, $this_file, $tmp_file);
                     $this_file = $tmp_file;
                     $tmp_files[] = $tmp_file;
                 }
                 $zipadd = $zip->addFile($this_file, $this_basename);
                 if ($zipadd === true) {
                     $ziptot++;
                 } else {
                     $zip_err .= JText::_('ZipArchive add error: ' . $zipadd);
                 }
             }
             if (!$zip->close()) {
                 $zip_err = JText::_('ZipArchive close error') . $zip->status;
             }
             if ($download_resize) {
                 foreach ($tmp_files as $tmp_file) {
                     $storage->delete($tmp_file);
                 }
             }
             if ($ziptot > 0) {
                 // Stream the file to the client
                 $filesize = filesize($zipfile);
                 if ($filesize > 0) {
                     header("Content-Type: application/zip");
                     header("Content-Length: " . filesize($zipfile));
                     header("Content-Disposition: attachment; filename=\"{$zipfile_basename}.zip\"");
                     echo JFile::read($zipfile);
                     JFile::delete($zipfile);
                     exit;
                 } else {
                     $zip_err .= JText::_('ZIP is empty');
                 }
             }
         } else {
             $zip_err = JText::_('ZipArchive open error: ' . $zipres);
         }
     } else {
         $zip_err = "No files to ZIP!";
     }
     if (empty($zip_err)) {
         return true;
     } else {
         $this->msg = $zip_err;
         return false;
     }
 }