Exemplo n.º 1
0
 /**
  * (non-PHPdoc)
  * @see Classes/Domain/ImageProcessing/Tx_Yag_Domain_ImageProcessing_AbstractProcessor::processFile()
  */
 protected function processFile(Tx_Yag_Domain_Configuration_Image_ResolutionConfig $resolutionConfiguration, Tx_Yag_Domain_Model_Item $origFile, Tx_Yag_Domain_Model_ResolutionFileCache $resolutionFile)
 {
     if (TYPO3_MODE === 'BE') {
         $this->simulateFrontendEnvironment();
     }
     // check if the item has a source uri set
     if (trim($origFile->getSourceuri()) == '') {
         throw new Tx_Yag_Exception_InvalidPath('No Source URI set for Item ' . $origFile->getUid(), 1357896895);
     }
     $expectedDirectoryForOrigImage = Tx_Yag_Domain_FileSystem_Div::makePathAbsolute(Tx_Yag_Domain_FileSystem_Div::getPathFromFilePath($origFile->getSourceuri()));
     $sourcePathAndFileName = $origFile->getSourceuri();
     // check for source directory to be existing
     if (!file_exists($expectedDirectoryForOrigImage)) {
         // we "re-create" missing directory so that file-not-found can be handled correctly
         // even if the directory has been deleted (by accident) and we can display
         // a file-not-found image instead of an Exception
         if (!mkdir($expectedDirectoryForOrigImage, 0777, true)) {
             throw new Exception('Tried to create new directory ' . $expectedDirectoryForOrigImage . ' but could not create this directory!', 1345272425);
         }
     }
     // check for source file to be existing
     if (!file_exists(Tx_Yag_Domain_FileSystem_Div::makePathAbsolute($sourcePathAndFileName)) || !is_readable(Tx_Yag_Domain_FileSystem_Div::makePathAbsolute($sourcePathAndFileName))) {
         // if the original image for processed image is missing, we use the file-not-found file as source
         $sourcePathAndFileName = $this->processorConfiguration->getConfigurationBuilder()->buildSysImageConfiguration()->getSysImageConfig('imageNotFound')->getSourceUri();
     }
     $imageResource = $this->getImageResource($origFile, $sourcePathAndFileName, $resolutionConfiguration);
     $resultImagePath = urldecode($imageResource[3]);
     $resultImagePathAbsolute = Tx_Yag_Domain_FileSystem_Div::makePathAbsolute($resultImagePath);
     $imageTarget = $this->generateAbsoluteResolutionPathAndFilename(end(explode(".", $resultImagePathAbsolute)), $origFile->getTitle());
     // check if we have a file
     if (!file_exists($resultImagePathAbsolute) || !is_file($resultImagePathAbsolute)) {
         throw new Exception(sprintf("\n\t\t\t\tTYPO3 image processor was not able to create an output image.\n\t\t\t\tSourceImagePath: %s,\n\t\t\t\tResultImagePath: %s", Tx_Yag_Domain_FileSystem_Div::makePathAbsolute($sourcePathAndFileName), $resultImagePathAbsolute), 1300205628);
     }
     if ($imageResource[3] == $imageResource['origFile']) {
         // the image was not processed, take the original file
         copy($resultImagePathAbsolute, $imageTarget);
     } else {
         rename($resultImagePathAbsolute, $imageTarget);
     }
     // Make sure, that expected image exists
     if (!file_exists($imageTarget)) {
         throw new Exception(sprintf('The result image of the image processing was not moved from the creation path %s to the expected target path %s', $resultImagePathAbsolute, Tx_Yag_Domain_FileSystem_Div::makePathAbsolute($imageTarget)), 1393382624);
     }
     // set resolutionFileObject
     $resolutionFile->setPath($imageTarget);
     $resolutionFile->setWidth($imageResource[0]);
     $resolutionFile->setHeight($imageResource[1]);
     if (TYPO3_MODE === 'BE') {
         $this->resetFrontendEnvironment();
     }
     return $imageResource;
 }
 /**
  * Removes resolution file cache object and file from filesystem
  *
  * @param Tx_Yag_Domain_Model_ResolutionFileCache $resolutionFileCache
  */
 public function remove($resolutionFileCache)
 {
     $cacheFilePath = Tx_Yag_Domain_FileSystem_Div::getT3BasePath() . $resolutionFileCache->getPath();
     if (file_exists($cacheFilePath)) {
         unlink(Tx_Yag_Domain_FileSystem_Div::getT3BasePath() . $resolutionFileCache->getPath());
         parent::remove($resolutionFileCache);
     }
 }
Exemplo n.º 3
0
 /**
  * Add cachefileobjrct to local cache
  * 
  * @param Tx_Yag_Domain_Model_ResolutionFileCache $cacheFileObject
  */
 protected function addResolutionFiletoLocalCache(Tx_Yag_Domain_Model_ResolutionFileCache $cacheFileObject)
 {
     $objectIdentifier = md5($cacheFileObject->getParamhash() . $cacheFileObject->getItem()->getSourceuri());
     $this->localResolutionFileCache[$objectIdentifier] = $cacheFileObject;
 }