コード例 #1
0
ファイル: YagDriver.php プロジェクト: kabarakh/yag
 /**
  * Returns a folder by its identifier.
  *
  * @param string $identifier
  * @return \TYPO3\CMS\Core\Resource\Folder
  */
 public function getFolder($identifier)
 {
     if ($identifier === '/' || $identifier === '/_processed_/') {
         return parent::getFOlder($identifier);
     }
     $pathInfo = $this->buildPathInfo($identifier);
     $identifier = $pathInfo->getFalPath();
     $name = $this->getNameFromIdentifier($identifier);
     return \TYPO3\CMS\Core\Resource\ResourceFactory::getInstance()->createFolderObject($this->storage, $identifier, $name);
 }
コード例 #2
0
 /**
  * Getter function to return the folder where the files can
  * be processed. does not check for access rights here
  *
  * @todo check if we need to implement "is writable" capability
  * @return \TYPO3\CMS\Core\Resource\Folder the processing folder, can be empty as well, if the storage doesn't have a processing folder
  */
 public function getProcessingFolder()
 {
     if (!isset($this->processingFolder)) {
         $processingFolder = self::DEFAULT_ProcessingFolder;
         if (!empty($this->storageRecord['processingfolder'])) {
             $processingFolder = $this->storageRecord['processingfolder'];
         }
         $processingFolder = '/' . trim($processingFolder, '/') . '/';
         // this way, we also worry about deeplinked folders like typo3temp/_processed_
         if ($this->driver->folderExists($processingFolder) === FALSE) {
             $processingFolderParts = explode('/', $processingFolder);
             $parentFolder = $this->driver->getRootLevelFolder();
             foreach ($processingFolderParts as $folderPart) {
                 if (!$this->driver->folderExistsInFolder($folderPart, $parentFolder)) {
                     $parentFolder = $this->driver->createFolder($folderPart, $parentFolder);
                 } else {
                     $parentFolder = $parentFolder->getSubfolder($folderPart);
                 }
             }
         }
         $this->processingFolder = $this->driver->getFolder($processingFolder);
     }
     return $this->processingFolder;
 }
コード例 #3
0
 /**
  * @test
  */
 public function isCaseSensitiveFileSystemReturnsTrueIfNothingIsConfigured()
 {
     $this->assertTrue($this->fixture->isCaseSensitiveFileSystem());
 }
コード例 #4
0
 /**
  * This method actually does the processing of files locally
  *
  * takes the original file (on remote storages this will be fetched from the remote server)
  * does the IM magic on the local server by creating a temporary typo3temp/ file
  * copies the typo3temp/ file to the processingfolder of the target storage
  * removes the typo3temp/ file
  *
  * @param \TYPO3\CMS\Core\Resource\ProcessedFile $processedFile
  * @param \TYPO3\CMS\Core\Resource\FileInterface $file
  * @param array $configuration
  * @return void
  */
 protected function processImageCropResizeMask(\TYPO3\CMS\Core\Resource\ProcessedFile $processedFile, \TYPO3\CMS\Core\Resource\FileInterface $file, array $configuration)
 {
     // checks to see if m (the mask array) is defined
     $doMasking = is_array($configuration['maskImages']) && $GLOBALS['TYPO3_CONF_VARS']['GFX']['im'];
     // @todo: is it ok that we use tslib (=FE) here?
     /** @var $gifBuilder tslib_gifbuilder */
     $gifBuilder = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance('tslib_gifbuilder');
     $gifBuilder->init();
     // @todo: this is not clean yet
     if (!trim($configuration['fileExtension'])) {
         $configuration['fileExtension'] = 'web';
         $targetFileExtension = $file->getExtension();
     } elseif ($doMasking) {
         $targetFileExtension = $file->getExtension() == $gifBuilder->gifExtension ? $gifBuilder->gifExtension : 'jpg';
     } else {
         $targetFileExtension = $configuration['fileExtension'];
     }
     $originalFileName = $file->getForLocalProcessing(FALSE);
     $targetFolder = $this->storage->getProcessingFolder();
     $targetFileName = 'previewcrm_' . $processedFile->calculateChecksum() . '.' . $targetFileExtension;
     // @todo: implement meaningful TempFileIndex
     if ($configuration['useSample']) {
         $gifBuilder->scalecmd = '-sample';
     }
     $options = array();
     if ($configuration['maxWidth']) {
         $options['maxW'] = $configuration['maxWidth'];
     }
     if ($configuration['maxHeight']) {
         $options['maxH'] = $configuration['maxHeight'];
     }
     if ($configuration['minWidth']) {
         $options['minW'] = $configuration['minWidth'];
     }
     if ($configuration['minHeight']) {
         $options['minH'] = $configuration['minHeight'];
     }
     $options['noScale'] = $configuration['noScale'];
     $configuration['additionalParameters'] = $this->modifyImageMagickStripProfileParameters($configuration['additionalParameters'], $configuration);
     // Do the actual processing
     if (!$targetFolder->hasFile($targetFileName)) {
         if (!$doMasking) {
             // Normal situation (no masking)
             // the result info is an array with 0=width,1=height,2=extension,3=filename
             list($targetWidth, $targetHeight, $targetExtension, $temporaryFileName) = $gifBuilder->imageMagickConvert($originalFileName, $configuration['fileExtension'], $configuration['width'], $configuration['height'], $configuration['additionalParameters'], $configuration['frame'], $options);
         } else {
             $temporaryFileName = $gifBuilder->tempPath . $targetFileName;
             $maskImage = $configuration['maskImages']['maskImage'];
             $maskBackgroundImage = $configuration['maskImages']['backgroundImage'];
             if ($maskImage instanceof \TYPO3\CMS\Core\Resource\FileInterface && $maskBackgroundImage instanceof \TYPO3\CMS\Core\Resource\FileInterface) {
                 $negate = $GLOBALS['TYPO3_CONF_VARS']['GFX']['im_negate_mask'] ? ' -negate' : '';
                 $temporaryExtension = 'png';
                 if ($GLOBALS['TYPO3_CONF_VARS']['GFX']['im_mask_temp_ext_gif']) {
                     // If ImageMagick version 5+
                     $temporaryExtension = $gifBuilder->gifExtension;
                 }
                 $tempFileInfo = $gifBuilder->imageMagickConvert($originalFileName, $temporaryExtension, $configuration['width'], $configuration['height'], $configuration['additionalParameters'], $configuration['frame'], $options);
                 if (is_array($tempFileInfo)) {
                     $maskBottomImage = $configuration['maskImages']['maskBottomImage'];
                     if ($maskBottomImage instanceof $maskBottomImage) {
                         $maskBottomImageMask = $configuration['maskImages']['maskBottomImageMask'];
                     }
                     //	Scaling:	****
                     $tempScale = array();
                     $command = '-geometry ' . $tempFileInfo[0] . 'x' . $tempFileInfo[1] . '!';
                     $command = $this->modifyImageMagickStripProfileParameters($command, $configuration);
                     $tmpStr = $gifBuilder->randomName();
                     //	m_mask
                     $tempScale['m_mask'] = $tmpStr . '_mask.' . $temporaryExtension;
                     $gifBuilder->imageMagickExec($maskImage->getForLocalProcessing(TRUE), $tempScale['m_mask'], $command . $negate);
                     //	m_bgImg
                     $tempScale['m_bgImg'] = $tmpStr . '_bgImg.' . trim($GLOBALS['TYPO3_CONF_VARS']['GFX']['im_mask_temp_ext_noloss']);
                     $gifBuilder->imageMagickExec($maskBackgroundImage->getForLocalProcessing(), $tempScale['m_bgImg'], $command);
                     //	m_bottomImg / m_bottomImg_mask
                     if ($maskBottomImage instanceof \TYPO3\CMS\Core\Resource\FileInterface && $maskBottomImageMask instanceof \TYPO3\CMS\Core\Resource\FileInterface) {
                         $tempScale['m_bottomImg'] = $tmpStr . '_bottomImg.' . $temporaryExtension;
                         $gifBuilder->imageMagickExec($maskBottomImage->getForLocalProcessing(), $tempScale['m_bottomImg'], $command);
                         $tempScale['m_bottomImg_mask'] = $tmpStr . '_bottomImg_mask.' . $temporaryExtension;
                         $gifBuilder->imageMagickExec($maskBottomImageMask->getForLocalProcessing(), $tempScale['m_bottomImg_mask'], $command . $negate);
                         // BEGIN combining:
                         // The image onto the background
                         $gifBuilder->combineExec($tempScale['m_bgImg'], $tempScale['m_bottomImg'], $tempScale['m_bottomImg_mask'], $tempScale['m_bgImg']);
                     }
                     // The image onto the background
                     $gifBuilder->combineExec($tempScale['m_bgImg'], $tempFileInfo[3], $tempScale['m_mask'], $temporaryFileName);
                     // Unlink the temp-images...
                     foreach ($tempScale as $file) {
                         if (@is_file($file)) {
                             unlink($file);
                         }
                     }
                 }
             }
             // Finish off
             list($targetWidth, $targetHeight) = $gifBuilder->getImageDimensions($temporaryFileName);
         }
         // Temporary image was created
         if (file_exists($temporaryFileName)) {
             $updatedProperties = array('width' => $targetWidth, 'height' => $targetHeight);
             // ImageMagick did not have to do anything, as it is already there...
             if ($originalFileName !== $temporaryFileName) {
                 \TYPO3\CMS\Core\Utility\GeneralUtility::fixPermissions($temporaryFileName);
                 // Copy the temporary file to the processedFolder
                 // this is done here, as the driver can do this without worrying
                 // about existing ProcessedFile objects
                 // or permissions in the storage
                 // for "remote" storages this means "uploading" the file to the storage again
                 // for the virtual storage, it is merely a thing of "copying a file from typo3temp/ to typo3temp/_processed_"
                 $this->driver->addFile($temporaryFileName, $targetFolder, $targetFileName, $processedFile);
                 // Remove the temporary file as it's not needed anymore
                 \TYPO3\CMS\Core\Utility\GeneralUtility::unlink_tempfile($temporaryFileName);
             } else {
             }
             $processedFile->updateProperties($updatedProperties);
             $processedFile->setProcessed(TRUE);
         }
     }
 }
コード例 #5
0
 public function __construct(array $configuration = array())
 {
     parent::__construct($configuration);
 }
コード例 #6
0
 /**
  * Entry method for use as file list filter.
  *
  * We have to use -1 as the „don't include“ return value, as call_user_func() will return FALSE
  * if calling the method failed and thus we can't use that as a return value.
  *
  * @param string $itemName
  * @param string $itemIdentifier
  * @param string $parentIdentifier
  * @param array $additionalInformation Additional information about the inspected item
  * @param \TYPO3\CMS\Core\Resource\Driver\AbstractDriver $driver
  * @return boolean|integer -1 if the file should not be included in a listing
  */
 public function filterFileList($itemName, $itemIdentifier, $parentIdentifier, array $additionalInformation, \TYPO3\CMS\Core\Resource\Driver\AbstractDriver $driver)
 {
     $returnCode = TRUE;
     // Early return in case no file filters are set at all
     if ($this->allowedFileExtensions === NULL && $this->disallowedFileExtensions === NULL) {
         return $returnCode;
     }
     // Check that this is a file and not a folder
     if ($driver->fileExists($itemIdentifier)) {
         $file = $driver->getFile($itemIdentifier);
         if (!$this->isAllowed($file)) {
             $returnCode = -1;
         }
     }
     return $returnCode;
 }