/** * Render the path * * @param string $path * @return string */ public function render($path = '') { if ($path == '') { $path = $this->renderChildren(); } if (file_exists(\TYPO3\CMS\Core\Utility\GeneralUtility::getFileAbsFileName($path))) { return $this->fileSystemDiv->getFileRelFileName($path); } else { return sprintf('The given Path %s was not found', htmlspecialchars($path)); } }
/** * @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'))); }
/** * 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'); }
/** * Creates path for original files on server. * If path does not exist, it will be created if given parameter is true. * * @param Tx_Yag_Domain_Model_Album $album * @param bool $createIfNotExists If set to true, directory will be created if it does not exist * @return string Path for original images (absolute) * @throws Exception */ public function getOrigFileDirectoryPathForAlbum(Tx_Yag_Domain_Model_Album $album, $createIfNotExists = true) { $path = Tx_Yag_Domain_Configuration_ConfigurationBuilderFactory::getInstance()->buildExtensionConfiguration()->getOrigFilesRootAbsolute() . '/' . $album->getUid() . '/'; if ($createIfNotExists) { $success = Tx_Yag_Domain_FileSystem_Div::checkDirAndCreateIfMissing($path); if (!$success) { throw new Exception(sprintf('The original file path %s for album %s could not be created!', $path, $album->getUid()), 1404452464); } } return $path; }
/** * Shows results for importing images from directory * * @param string $directory * @param Tx_Yag_Domain_Model_Album $album * @param bool $crawlRecursive If set to true, subdirs will also be crawled * @param bool $noDuplicates If set to true, items that are already imported to album won't be imported twice * @return string The HTML source for import from directory action * @rbacNeedsAccess * @rbacObject Album * @rbacAction edit */ public function importFromDirectoryAction($directory, Tx_Yag_Domain_Model_Album $album, $crawlRecursive = FALSE, $noDuplicates = FALSE) { // Directory must be within fileadmin $directory = Tx_Yag_Domain_FileSystem_Div::getT3BasePath() . $directory; $importer = Tx_Yag_Domain_Import_DirectoryImporter_ImporterBuilder::getInstance()->getInstanceByDirectoryAndAlbum($directory, $album); $importer->setNoDuplicates($noDuplicates); $importer->setCrawlRecursive($crawlRecursive); $importer->runImport(); $this->addFlashMessage(\TYPO3\CMS\Extbase\Utility\LocalizationUtility::translate('tx_yag_controller_directoryimportcontroller_importfromdirectory.importsuccessfull', $this->extensionName, array($importer->getItemsImported())), '', \TYPO3\CMS\Core\Messaging\FlashMessage::OK); $this->yagContext->setAlbum($album); $this->forward('list', 'ItemList'); }
/** * Runs actual import. Unpacks zip file to a directory and * runs directory importer to actually import the files contained * in zip file. */ public function runImport() { // Unpack zip file $tempDir = Tx_Yag_Domain_FileSystem_Div::tempdir(sys_get_temp_dir(), 'yag_zip_extraction'); $this->unzipArchive($this->zipFilename, $tempDir); // Initialize directory crawler on extracted file's directory and run import $directoryImporter = Tx_Yag_Domain_Import_DirectoryImporter_ImporterBuilder::getInstance()->getInstanceByDirectoryAndAlbum($tempDir, $this->album); $directoryImporter->setMoveFilesToOrigsDirectoryToTrue(); // Files will be moved to origs directory before they are processed $directoryImporter->setCrawlRecursive(TRUE); $directoryImporter->runImport(); $this->itemsImported = $directoryImporter->getItemsImported(); }
/** * 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; }
/** * @return string */ public function getFileName() { $parameters = array(); if ($this->itemListData->count() > 0) { $item = $this->itemListData->getFirstRow()->getCell('image')->getValue(); /** @var Tx_Yag_Domain_Model_Item $item */ $parameters = array('album' => $item->getAlbum()->getName(), 'gallery' => $item->getAlbum()->getGallery()->getName()); } $formattedFileName = Tx_PtExtlist_Utility_RenderValue::renderDataByConfigArray($parameters, $this->fileNameFormat); if (substr(strtolower($formattedFileName), -4, 4) != '.zip') { $formattedFileName .= '.zip'; } $formattedFileName = $this->fileSystemDiv->cleanFileName($formattedFileName); return $formattedFileName; }
/** * @param $imageName * @return string */ protected function getMeaningfulTempFilePrefix($imageName) { if ($this->processorConfiguration->getMeaningfulTempFilePrefix() > 0 && $imageName != '') { $cleanFileName = $this->fileSystemDiv->cleanFileName($imageName); if ($GLOBALS['TYPO3_CONF_VARS']['SYS']['UTF8filesystem']) { $t3libCsInstance = GeneralUtility::makeInstance('TYPO3\\CMS\\Core\\Charset\\CharsetConverter'); /** @var $t3libCsInstance \TYPO3\CMS\Core\Charset\CharsetConverter */ $meaningfulPrefix = $t3libCsInstance->substr('utf-8', $cleanFileName, 0, $this->processorConfiguration->getMeaningfulTempFilePrefix()); } else { $meaningfulPrefix = substr($cleanFileName, 0, $this->processorConfiguration->getMeaningfulTempFilePrefix()); } $meaningfulPrefix .= '_'; return $meaningfulPrefix; } return ''; }
/** * Moves a file from given filepath to directory for original images for album * * If an item is given, UID of item is used as filename for item in original items directory * * @param string $filePath Full qualified filepath of file to move * @param Tx_Yag_Domain_Model_Item $item Item that should hold file (not modified, make sure to set sourceuri manually! * @return string * @throws Exception */ protected function moveFileToOrigsDirectory($filePath, Tx_Yag_Domain_Model_Item $item = null) { // Create path to move file to $origsFilePath = $this->fileManager->getOrigFileDirectoryPathForAlbum($this->album); $fileSuffix = pathinfo($filePath, PATHINFO_EXTENSION); if ($item !== null) { if ($item->getOriginalFilename()) { $origsFilePath .= $item->getUid() . '_' . $this->fileSystemDiv->cleanFileName($item->getOriginalFilename()); } else { $origsFilePath .= $item->getUid() . '.' . $fileSuffix; // if we get an item, we use UID of item as a part of the filename } } else { $origsFilePath .= Tx_Yag_Domain_FileSystem_Div::getFilenameFromFilePath($filePath); // if we do not get one, we use filename of given filepart } if (!rename($filePath, $origsFilePath)) { throw new Exception('Could not move file ' . $filePath . ' to ' . $origsFilePath, 1294176900); } // Set appropriate file mask $this->setFileMask($origsFilePath); return $origsFilePath; }
/** * Runs actual import. * * Crawls given directory for images using file crawler. * Each image found in this directory is added to the given album. */ public function runImport() { $files = $this->fileCrawler->getFilesForGivenDirectory($this->directory, $this->crawlRecursive); $this->initItemSorting(); foreach ($files as $filePath) { // Prevent import, if noDuplicates is set to true and we already have item imported in album if ($this->noDuplicates && $this->album->containsItemByHash(md5_file($filePath))) { continue; } $origFilePath = $filePath; $item = null; if ($this->moveFilesToOrigsDirectory) { $item = $this->getNewPersistedItem(); $filePath = $this->moveFileToOrigsDirectory($filePath, $item); } else { $item = $this->objectManager->get('Tx_Yag_Domain_Model_Item'); } $item->setOriginalFilename(Tx_Yag_Domain_FileSystem_Div::getFilenameFromFilePath($origFilePath)); // We increase item sorting with each item that has to be imported $item->setSorting(++$this->itemSorting); $this->importFileByFilename($filePath, $item); $this->itemsImported++; } $this->runPostImportAction(); }
/** * (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; }
/** * Returns a list of subdirs encoded for filetree widget * * @return string ul/li - encoded subdirectory list */ public function getSubDirsAction() { $encodedFiles = ''; $fileSystemDiv = $this->objectManager->get('Tx_Yag_Domain_FileSystem_Div'); /** @var Tx_Yag_Domain_FileSystem_Div $fileSystemDiv */ $t3basePath = Tx_Yag_Domain_FileSystem_Div::getT3BasePath(); $submittedPath = urldecode(GeneralUtility::_POST('dir')); if ($submittedPath) { $pathToBeScanned = $t3basePath . $submittedPath; $files = $fileSystemDiv->getBackendAccessibleDirectoryEntries($pathToBeScanned); if (count($files)) { // All dirs foreach ($files as $file) { if (is_dir($pathToBeScanned . $file)) { $encodedFiles .= "<li class=\"directory collapsed\"><a href=\"#\" rel=\"" . $submittedPath . $file . "/\">" . $file . "</a></li>"; } } foreach ($files as $file) { if (!is_dir($pathToBeScanned . $file)) { $ext = preg_replace('/^.*\\./', '', $file); $encodedFiles .= "<li class=\"file ext_{$ext}\"><a href=\"#\" rel=\"" . htmlentities($submittedPath . $file) . "\">" . htmlentities($file) . "</a></li>"; } } } } else { $mountDirs = $fileSystemDiv->getBackendFileMountPaths(); // All dirs foreach ($mountDirs as $directory) { $directory = substr($directory, -1, 1) == '/' ? substr($directory, 0, -1) : $directory; $directory = str_replace($t3basePath, '', $directory); if (is_dir($t3basePath . $directory)) { $encodedFiles .= "<li class=\"directory collapsed\"><a href=\"#\" rel=\"" . $directory . "/\">" . basename($directory) . "</a></li>"; } } } $encodedFiles = "<ul class=\"jqueryFileTree\" style=\"display: none;\">" . $encodedFiles . "</ul>"; $this->returnDataAndShutDown($encodedFiles); }
/** * @test * @dataProvider checkDirAndCreateIfMissingDataProvider */ public function checkDirAndCreateIfMissing($directoryToCreate) { $result = $this->fileSystemDiv->checkDirAndCreateIfMissing($directoryToCreate); $this->assertTrue($result); $this->assertTrue(is_dir($directoryToCreate)); }
/** * Creates a path for a given ID and returns path * * @param int $fileId * @return string Absolute path for given File ID */ public function createAndGetAbsolutePathById($fileId) { $path = $this->getAbsolutePathById($fileId); Tx_Yag_Domain_FileSystem_Div::checkDirAndCreateIfMissing(PATH_site . $path); return $path; }
/** * 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()); }
/** * 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); } }
/** * @return int CacheSize */ public function getCacheSize() { $cacheDirectoryRoot = $this->configurationBuilder->buildExtensionConfiguration()->getHashFilesystemRootAbsolute(); return Tx_Yag_Domain_FileSystem_Div::getDirSize($cacheDirectoryRoot); }
/** * Set the TS defined custom paths in view * * @param \TYPO3\CMS\Extbase\Mvc\View\ViewInterface $view * @throws Exception */ protected function setCustomPathsInView(\TYPO3\CMS\Extbase\Mvc\View\ViewInterface $view) { $templatePathAndFilename = null; // We can overwrite a template via TS using plugin.yag.settings.controller.<ControllerName>.<actionName>.template if ($this->configurationBuilder) { $templatePathAndFilename = $this->configurationBuilder->buildThemeConfiguration()->getTemplate($this->request->getControllerName(), $this->request->getControllerActionName()); $this->objectManager->get('Tx_Yag_Utility_HeaderInclusion')->includeThemeDefinedHeader($this->configurationBuilder->buildThemeConfiguration()); } if (!$templatePathAndFilename) { $templatePathAndFilename = $this->settings['controller'][$this->request->getControllerName()][$this->request->getControllerActionName()]['template']; } if (isset($templatePathAndFilename) && strlen($templatePathAndFilename) > 0) { /** * Format Overlay */ if ($this->request->getFormat() && strtolower($this->request->getFormat()) !== 'html') { $templatePathAndFilename = Tx_Yag_Domain_FileSystem_Div::concatenatePaths(array(dirname($templatePathAndFilename), basename($templatePathAndFilename, '.html') . '.' . $this->request->getFormat())); } if (file_exists(GeneralUtility::getFileAbsFileName($templatePathAndFilename))) { $view->setTemplatePathAndFilename(GeneralUtility::getFileAbsFileName($templatePathAndFilename)); } else { throw new Exception('Given template path and filename could not be found or resolved: ' . $templatePathAndFilename . ' 1284655109'); } } }
/** * 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; }
/** * Expand the EXT to a relative path * * @param string $filename * @return string * @deprecated Use Tx_Yag_Domain_FileSystem_Div::getFileRelFileName instead */ public function getFileRelFileName($filename) { return $this->fileSystemDiv->getFileRelFileName($filename); }
public function getAlbumPath() { return \Tx_Yag_Domain_FileSystem_Div::concatenatePaths(array($this->getGalleryPath(), $this->albumName . '|' . $this->albumUid)); }
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()); }
/** * 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']]); }