/** * @test */ public function parseCoreData() { $item = $this->getTestItemObject(); $actual = $this->coreDataParser->parseCoreData(Tx_Yag_Domain_FileSystem_Div::makePathAbsolute($item->getSourceuri())); $this->assertEquals(240, $actual['dpi']); $this->assertTrue(in_array($actual['colorSpace'], array('RGB', 'sRGB'))); }
/** * Constructor for file system class * * @param string $rootDirectory Path to root directory for filesystem * @throws Exception */ public function __construct($rootDirectory) { $absoluteRootDirectory = Tx_Yag_Domain_FileSystem_Div::makePathAbsolute($rootDirectory); if (!file_exists($absoluteRootDirectory)) { throw new Exception('Directory ' . $absoluteRootDirectory . ' does not exist!', 1287524902); } $this->rootDirectory = $rootDirectory; }
/** * 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); } }
/** * Initializes properties */ protected function init() { $this->setRequiredValue('sourceUri', 'Source Uri of this system image not set! 1298831563'); if (!file_exists(Tx_Yag_Domain_FileSystem_Div::makePathAbsolute($this->getSourceUri()))) { throw new Exception('Imagesource ' . Tx_Yag_Domain_FileSystem_Div::makePathAbsolute($this->getSourceUri()) . ' defined by system image not found. 1298833321'); } $this->setValueIfExistsAndNotNothing('title'); $this->setValueIfExistsAndNotNothing('description'); }
/** * Returns a (local copy of) a file for processing it. When changing the * file, you have to take care of replacing the current version yourself! * * @param \TYPO3\CMS\Core\Resource\FileInterface $file * @param bool $writable Set this to FALSE if you only need the file for read operations. This might speed up things, e.g. by using a cached local version. Never modify the file if you have set this flag! * @return string The path to the file on the local disk */ public function getFileForLocalProcessing(\TYPO3\CMS\Core\Resource\FileInterface $file, $writable = true) { error_log('FAL DRIVER: ' . __FUNCTION__); if (!$file->isIndexed() || !$file->getProperty('yagItem') instanceof \Tx_Yag_Domain_Model_Item) { $identifier = $file->getIdentifier(); $fileInfo = $this->getFileInfoByIdentifier($identifier); $sourceUri = $this->yagFileSystemDiv->makePathAbsolute($fileInfo['sourceUri']); } else { $item = $file->getProperty('yagItem'); $sourceUri = $this->yagFileSystemDiv->makePathAbsolute($item->getSourceuri()); } return $sourceUri; }
/** * Create and return a new System Image * This image is persisted in the image database * * @param Tx_Yag_Domain_Configuration_Image_SysImageConfig $sysImageConfig * @return Tx_Yag_Domain_Model_Item */ protected function createNewSystemImage(Tx_Yag_Domain_Configuration_Image_SysImageConfig $sysImageConfig) { $sysImage = GeneralUtility::makeInstance('Tx_Yag_Domain_Model_Item'); $sysImage->setSourceuri($sysImageConfig->getSourceUri()); $sysImage->setFilename(basename($sysImageConfig->getSourceUri())); $sysImage->setTitle($sysImageConfig->getTitle()); $sysImage->setDescription($sysImageConfig->getDescription()); list($width, $height, $type, $attr) = getimagesize(Tx_Yag_Domain_FileSystem_Div::makePathAbsolute($sysImageConfig->getSourceUri())); $sysImage->setWidth($width); $sysImage->setHeight($height); $this->add($sysImage); return $sysImage; }
/** * @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()); } }
/** * (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(); } $processedFile = $this->getImageResource($origFile, $sourcePathAndFileName, $resolutionConfiguration); $resultImagePathAbsolute = $processedFile->getForLocalProcessing(); $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 ($resultImagePathAbsolute == $processedFile->getOriginalFile()->getForLocalProcessing()) { // 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($processedFile->getProperty('width')); $resolutionFile->setHeight($processedFile->getProperty('height')); if (TYPO3_MODE === 'BE') { $this->resetFrontendEnvironment(); } return $processedFile; }
/** * Get a file resolution * * @param Tx_Yag_Domain_Model_Item $item * @param Tx_Yag_Domain_Configuration_Image_ResolutionConfig $resolutionConfiguration * * @return Tx_Yag_Domain_Model_ResolutionFileCache */ public function getItemFileResolutionPathByConfiguration(Tx_Yag_Domain_Model_Item $item, Tx_Yag_Domain_Configuration_Image_ResolutionConfig $resolutionConfiguration) { $resolutionFile = $this->getResolutionFileFromLocalCache($resolutionConfiguration, $item); if ($resolutionFile == NULL) { $resolutionFile = $this->resolutionFileCacheRepository->getResolutionByItem($item, $resolutionConfiguration); } if ($resolutionFile == NULL || !file_exists(Tx_Yag_Domain_FileSystem_Div::makePathAbsolute($resolutionFile->getPath()))) { $resolutionFile = $this->imageProcessor->generateResolution($item, $resolutionConfiguration); } $this->addResolutionFiletoLocalCache($resolutionFile); return $resolutionFile; }
/** * 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; }
/** * As we have our own resolution file cache system * we dont want to polute the TYPO3 cache_imagesizes table. * So we remove the generated image (messy, but the only way ...) * * @param $imageResource filename to remove from table * @param $originalFileName */ protected function typo3CleanUp($imageResource, $originalFileName) { $GLOBALS['TYPO3_DB']->exec_DELETEquery('cache_imagesizes', 'filename = ' . $GLOBALS['TYPO3_DB']->fullQuoteStr($imageResource[3], 'cache_imagesizes')); $GLOBALS['TYPO3_DB']->exec_DELETEquery('cache_typo3temp_log', 'orig_filename = ' . $GLOBALS['TYPO3_DB']->fullQuoteStr(Tx_Yag_Domain_FileSystem_Div::makePathAbsolute($originalFileName), 'cache_typo3temp_log')); unset($GLOBALS['TSFE']->tmpl->fileCache[$imageResource['fileCacheHash']]); }
/** * Returns directory of original files (absolute path on server) * * @return string Original files root path */ public function getOrigFilesRootAbsolute() { return Tx_Yag_Domain_FileSystem_Div::makePathAbsolute($this->getOrigFilesRoot()); }