/** * Force download of the file. * * @param File $file * @param bool $forceDownload * @return bool|string */ public function downloadAction(File $file, $forceDownload = FALSE) { if ($file->exists() && $file->getStorage()->isWithinFileMountBoundaries($file->getParentFolder())) { // Emit signal before downloading the file. $this->emitBeforeDownloadSignal($file); // Read the file and dump it with the flag "forceDownload" set to TRUE or FALSE. $file->getStorage()->dumpFileContents($file, $forceDownload); $result = TRUE; } else { $result = 'Access denied!'; } return $result; }
/** * Check file access for given FeGroups combination * * @param \TYPO3\CMS\Core\Resource\File $file * @param bool|array $userFeGroups FALSE = no login, array() fe groups of user * @return bool */ public function checkFileAccess($file, $userFeGroups) { // all files in public storage are accessible if ($file->getStorage()->isPublic()) { return true; // check folder access } elseif ($this->checkFolderRootLineAccess($file->getParentFolder(), $userFeGroups)) { // access to folder then check file privileges if present $feGroups = $file->getProperty('fe_groups'); if ($feGroups !== '') { return $this->matchFeGroupsWithFeUser($feGroups, $userFeGroups); } return true; } return false; }
/** * Returns the parent folder. * * @return FolderInterface */ public function getParentFolder() { return $this->originalFile->getParentFolder(); }
/** * @param File $image * @param File $listFolder * @param File $categoryFolder * @param int $listPage * @param int $categoryPage * @return string */ public function listAction(File $image = null, File $listFolder = null, File $categoryFolder = null, $listPage = 1, $categoryPage = 1) { if ($this->configurationInvalid) { return $this->getErrorMessageForActionName('List'); } $this->view->assign('currentImage', $image); $this->view->assign('currentCategoryPage', $categoryPage); $this->view->assign('currentCategoryFolder', $categoryFolder); // overwrite $selectedFolder when a image from category is clicked $selectedFolder = $this->selectedFolder; if ($listFolder !== null) { /** @var Folder $parentFolder */ $parentFolder = $listFolder->getParentFolder(); if ($this->folderIsInsideSelectedStorage($parentFolder)) { $selectedFolder = $parentFolder; } } // get all items to display $itemsToPaginate = $this->selectedStorage->getFilesInFolder($selectedFolder); $this->view->assign('currentListFolder', $this->getFolderImage($selectedFolder)); $this->assignPaginationParams($itemsToPaginate, $listPage); if ($this->settings['list']['useLightBox']) { /** @var \TYPO3\CMS\Frontend\ContentObject\ContentObjectRenderer $contentObjectRenderer */ $contentObjectRenderer = $this->configurationManager->getContentObject(); // lightbox rel attribute is taken from global constants, see typoscript setup $this->view->assign('lightboxRelAttribute', $contentObjectRenderer->cObjGetSingle($this->settings['lightboxRelAttribute']['_typoScriptNodeValue'], $this->settings['lightboxRelAttribute'])); } // maxImageWidth is taken from tt_content, see typoscript setup $this->view->assign('maxImageWidth', $this->settings['maxImageWidth']['_typoScriptNodeValue']); }
/** * A file is about to be added as a *replacement* of an existing * one. * * @param File $file * @param string $uploadedFileName * @return void */ public function postFileReplace(File $file, $uploadedFileName) { $folder = $file->getParentFolder(); $storageConfiguration = $folder->getStorage()->getConfiguration(); $storageRecord = $folder->getStorage()->getStorageRecord(); if ($storageRecord['driver'] !== 'Local') { // Unfortunately unsupported yet return; } $targetDirectory = $storageConfiguration['pathType'] === 'relative' ? PATH_site : ''; $targetDirectory .= rtrim(rtrim($storageConfiguration['basePath'], '/') . $folder->getIdentifier(), '/'); $targetFileName = $targetDirectory . '/' . $file->getName(); $this->processFile($targetFileName, PathUtility::basename($targetFileName), $targetDirectory, $file); $this->populateMetadata($file, $folder); }