/** * (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; }
/** * Remove the file if it is located within its album path. * That means, it does not remove files located in an other directory (like files imported by the directory importer) * * @param Tx_Yag_Domain_Model_Item $item */ public function removeImageFileFromAlbumDirectory(Tx_Yag_Domain_Model_Item $item) { $albumPath = $this->getOrigFileDirectoryPathForAlbum($item->getAlbum()); $imageFilePath = Tx_Yag_Domain_FileSystem_Div::makePathAbsolute($item->getSourceuri()); if (\TYPO3\CMS\Core\Utility\GeneralUtility::isFirstPartOfStr($imageFilePath, $albumPath) && file_exists($imageFilePath)) { unlink($imageFilePath); } }
protected function buildItemObjectInfo(PathInfo $pathInfo, \Tx_Yag_Domain_Model_Item $item) { return array('size' => $item->getFilesize(), 'atime' => $item->getTstamp()->getTimestamp(), 'mtime' => $item->getTstamp()->getTimestamp(), 'ctime' => $item->getCrdate()->getTimestamp(), 'mimetype' => 'image/jpeg', 'yagItem' => $item, 'name' => $item->getOriginalFilename(), 'identifier' => \Tx_Yag_Domain_FileSystem_Div::concatenatePaths(array($pathInfo->getAlbumPath(), $item->getTitle() . ' |' . $item->getUid())), 'storage' => $this->storage->getUid(), 'description' => $item->getDescription(), 'title' => $item->getTitle(), 'height' => $item->getHeight(), 'width' => $item->getWidth(), 'sourceUri' => $item->getSourceuri()); }
/** * @param Tx_Yag_Domain_Model_Item $item * @return string */ protected function getFilePathOfResolution(Tx_Yag_Domain_Model_Item $item) { if ($this->resolutionIdentifier === 'original') { return Tx_Yag_Domain_FileSystem_Div::makePathAbsolute($item->getSourceuri()); } else { return Tx_Yag_Domain_FileSystem_Div::makePathAbsolute($item->getResolutionByConfig($this->getRequestedResolutionConfig())->getPath()); } }
/** * Retrieve a resolution file from local cache * * @param Tx_Yag_Domain_Configuration_Image_ResolutionConfig $resolutionConfiguration * @param Tx_Yag_Domain_Model_Item $item * @return Tx_Yag_Domain_Model_ResolutionFileCache|null */ protected function getResolutionFileFromLocalCache(Tx_Yag_Domain_Configuration_Image_ResolutionConfig $resolutionConfiguration, Tx_Yag_Domain_Model_Item $item) { $objectIdentifier = md5($resolutionConfiguration->getParameterHash() . $item->getSourceuri()); if (array_key_exists($objectIdentifier, $this->localResolutionFileCache)) { return $this->localResolutionFileCache[$objectIdentifier]; } return NULL; }
/** * Sends an item as download. The fileHash (or at least a part of 5 characters) is used to avoid grabbing the whole * database by incrementing the itemUid. * * @param Tx_Yag_Domain_Model_Item $item * @param string $fileHash */ public function downloadAction(Tx_Yag_Domain_Model_Item $item, $fileHash) { $requestedFileName = Tx_Yag_Domain_FileSystem_Div::makePathAbsolute($item->getSourceuri()); $hashLength = strlen($fileHash) > 5 ? 5 : strlen($fileHash); if ($fileHash == '' || $fileHash !== substr($item->getFilehash(), 0, $hashLength) || !is_readable($requestedFileName)) { $this->flashMessageContainer->add('The requested file was not found.', 'File not found', FlashMessage::ERROR); $this->forward('index', 'Error'); } $this->response->setHeader('Cache-control', 'public', true); $this->response->setHeader('Content-Description', 'File transfer', true); $this->response->setHeader('Content-Disposition', 'attachment; filename="' . $item->getOriginalFilename() . '"', true); $this->response->setHeader('Content-Type', $item->getItemType(), true); $this->response->setHeader('Content-Transfer-Encoding', 'binary', true); $this->response->sendHeaders(); @readfile($requestedFileName); exit; }