/** * Init * * @return void * @throws \RuntimeException * @throws InsufficientFileAccessPermissionsException */ protected function init() { // Initialize GPvars: $this->uid = (int) GeneralUtility::_GP('uid'); $lang = $this->getLanguageService(); $this->returnUrl = GeneralUtility::sanitizeLocalUrl(GeneralUtility::_GP('returnUrl')); // Cleaning and checking uid if ($this->uid > 0) { $this->fileOrFolderObject = ResourceFactory::getInstance()->retrieveFileOrFolderObject('file:' . $this->uid); } if (!$this->fileOrFolderObject) { $title = $lang->sL('LLL:EXT:lang/locallang_mod_file_list.xlf:paramError', true); $message = $lang->sL('LLL:EXT:lang/locallang_mod_file_list.xlf:targetNoDir', true); throw new \RuntimeException($title . ': ' . $message, 1436895930); } if ($this->fileOrFolderObject->getStorage()->getUid() === 0) { throw new InsufficientFileAccessPermissionsException('You are not allowed to access files outside your storages', 1436895931); } // If a folder should be renamed, AND the returnURL should go to the old directory name, the redirect is forced // so the redirect will NOT end in an error message // this case only happens if you select the folder itself in the foldertree and then use the clickmenu to // rename the folder if ($this->fileOrFolderObject instanceof Folder) { $parsedUrl = parse_url($this->returnUrl); $queryParts = GeneralUtility::explodeUrl2Array(urldecode($parsedUrl['query'])); if ($queryParts['id'] === $this->fileOrFolderObject->getCombinedIdentifier()) { $this->returnUrl = str_replace(urlencode($queryParts['id']), urlencode($this->fileOrFolderObject->getStorage()->getRootLevelFolder()->getCombinedIdentifier()), $this->returnUrl); } } $pathInfo = ['combined_identifier' => $this->fileOrFolderObject->getCombinedIdentifier()]; $this->moduleTemplate->getDocHeaderComponent()->setMetaInformation($pathInfo); $this->moduleTemplate->getPageRenderer()->loadRequireJsModule('TYPO3/CMS/Backend/ClickMenu'); $this->moduleTemplate->addJavaScriptCode('ReplaceFileOnlineJavaScript', 'function backToList() {top.goToModule("file_FilelistList");}'); }
/** * Constructor function for class * * @return void * @todo Define visibility */ public function init() { // Initialize GPvars: $this->target = \TYPO3\CMS\Core\Utility\GeneralUtility::_GP('target'); $this->returnUrl = \TYPO3\CMS\Core\Utility\GeneralUtility::sanitizeLocalUrl(\TYPO3\CMS\Core\Utility\GeneralUtility::_GP('returnUrl')); // Cleaning and checking target if ($this->target) { $this->fileOrFolderObject = \TYPO3\CMS\Core\Resource\ResourceFactory::getInstance()->retrieveFileOrFolderObject($this->target); } if (!$this->fileOrFolderObject) { $title = $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_mod_file_list.xml:paramError', TRUE); $message = $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_mod_file_list.xml:targetNoDir', TRUE); throw new \RuntimeException($title . ': ' . $message, 1294586844); } // If a folder should be renamed, AND the returnURL should go to the old directory name, the redirect is forced // so the redirect will NOT end in a error message // this case only happens if you select the folder itself in the foldertree and then use the clickmenu to // rename the folder if ($this->fileOrFolderObject instanceof \TYPO3\CMS\Core\Resource\Folder) { $parsedUrl = parse_url($this->returnUrl); $queryParts = \TYPO3\CMS\Core\Utility\GeneralUtility::explodeUrl2Array(urldecode($parsedUrl['query'])); if ($queryParts['id'] === $this->fileOrFolderObject->getCombinedIdentifier()) { $this->returnUrl = str_replace(urlencode($queryParts['id']), urlencode($this->fileOrFolderObject->getStorage()->getRootLevelFolder()->getCombinedIdentifier()), $this->returnUrl); } } // Setting icon and title $icon = \TYPO3\CMS\Backend\Utility\IconUtility::getSpriteIcon('apps-filetree-root'); $this->title = $icon . htmlspecialchars($this->fileOrFolderObject->getStorage()->getName()) . ': ' . htmlspecialchars($this->fileOrFolderObject->getIdentifier()); // Setting template object $this->doc = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance('TYPO3\\CMS\\Backend\\Template\\DocumentTemplate'); $this->doc->setModuleTemplate('templates/file_rename.html'); $this->doc->backPath = $GLOBALS['BACK_PATH']; $this->doc->JScode = $this->doc->wrapScriptTags(' function backToList() { // top.goToModule("file_list"); } '); }
/** * Publishes a persistent resource to the web accessible resources directory * * @param ResourceInterface $resource The resource to publish * @return mixed Either the web URI of the published resource or FALSE if the resource source file doesn't exist or the resource could not be published for other reasons */ public function publishResource(ResourceInterface $resource) { $this->setResourcesSourcePath($this->getResourcesSourcePathByResourceStorage($resource->getStorage())); $publishedResourcePathAndFilename = $this->buildResourcePublishPathAndFilename($resource); $publishedResourceWebUri = $this->buildResourceWebUri($resource); if (!file_exists($publishedResourcePathAndFilename)) { $unpublishedResourcePathAndFilename = $this->getResourceSourcePathAndFileName($resource); if ($unpublishedResourcePathAndFilename === FALSE) { return FALSE; } $this->mirrorFile($unpublishedResourcePathAndFilename, $publishedResourcePathAndFilename); } return $publishedResourceWebUri; }
/** * @param \TYPO3\CMS\Core\Resource\ResourceInterface $resource * @param $iconName * @param array $options * @param array $overlays */ public function overrideResourceIcon(\TYPO3\CMS\Core\Resource\ResourceInterface $resource, &$iconName, array &$options, array &$overlays) { if (!$resource->getStorage()->isPublic()) { /** @var $checkPermissionsService \BeechIt\FalSecuredownload\Security\CheckPermissions */ $checkPermissionsService = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance('BeechIt\\FalSecuredownload\\Security\\CheckPermissions'); $currentPermissionsCheck = $resource->getStorage()->getEvaluatePermissions(); $resource->getStorage()->setEvaluatePermissions(false); if ($resource instanceof \TYPO3\CMS\Core\Resource\Folder) { $folder = $resource; } else { $folder = $resource->getParentFolder(); } if ($resource instanceof \TYPO3\CMS\Core\Resource\File && $resource->getProperty('fe_groups')) { $overlays['status-overlay-access-restricted'] = array(); // check if there are permissions set on this specific folder } elseif ($folder === $resource && $checkPermissionsService->getFolderPermissions($folder) !== false) { $overlays['status-overlay-access-restricted'] = array(); // check if there are access restrictions in the root line of this folder } elseif (!$checkPermissionsService->checkFolderRootLineAccess($folder, false)) { $overlays['extensions-fal_securedownload-overlay-permissions'] = array(); } $resource->getStorage()->setEvaluatePermissions($currentPermissionsCheck); } }
/** * Publishes a persistent resource to the web accessible resources directory * * @param ResourceInterface $resource The resource to publish * @return mixed Either the web URI of the published resource or FALSE if the resource source file doesn't exist or the resource could not be published for other reasons */ public function publishResource(ResourceInterface $resource) { $publicUrl = FALSE; // We only manipulate the URL if we are in the backend or in FAL mode in FE (otherwise we parse the HTML) if (!$this->getRequestContext()->isFrontendRequest() || $this->configurationManager->getValue('enableFileAbstractionLayerHandling')) { $this->setResourcesSourcePath($this->getResourcesSourcePathByResourceStorage($resource->getStorage())); if ($this->isSourcePathInDocumentRoot()) { if (!$this->isPubliclyAvailable($resource)) { $publicUrl = $this->buildUri($this->getResourceUri($resource)); } } else { // TODO: Maybe implement this case? // We need to use absolute paths then or copy the files around, or... } } return $publicUrl; }
/** * Checks if a resource (file or folder) is within the given folder * * @param Folder $folder * @param ResourceInterface $resource * @return bool * @throws \InvalidArgumentException */ public function isWithinFolder(Folder $folder, ResourceInterface $resource) { if ($folder->getStorage() !== $this) { throw new \InvalidArgumentException('Given folder "' . $folder->getIdentifier() . '" is not part of this storage!', 1422709241); } if ($folder->getStorage() !== $resource->getStorage()) { return false; } return $this->driver->isWithin($folder->getIdentifier(), $resource->getIdentifier()); }
/** * This method is used throughout the TYPO3 Backend to show icons for files and folders * * The method takes care of the translation of file extension to proper icon and for folders * it will return the icon depending on the role of the folder. * * If the given resource is a folder there are some additional options that can be used: * - mount-root => TRUE (to indicate this is the root of a mount) * - folder-open => TRUE (to indicate that the folder is opened in the file tree) * * There is a hook in place to manipulate the icon name and overlays. * * @param \TYPO3\CMS\Core\Resource\ResourceInterface $resource * @param array $options An associative array with additional options and attributes for the tag. See self::getSpriteIcon() * @param array $overlays An associative array with the icon-name as key, and the options for this overlay as an array again (see the parameter $options again) * @return string * @throws \UnexpectedValueException */ public static function getSpriteIconForResource(\TYPO3\CMS\Core\Resource\ResourceInterface $resource, array $options = array(), array $overlays = array()) { // Folder if ($resource instanceof \TYPO3\CMS\Core\Resource\FolderInterface) { $iconName = NULL; $role = $resource->getRole(); // non browsable storage if ($resource->getStorage()->isBrowsable() === FALSE && !empty($options['mount-root'])) { $iconName = 'apps-filetree-folder-locked'; } else { // storage root if ($resource->getStorage()->getRootLevelFolder()->getIdentifier() === $resource->getIdentifier()) { $iconName = 'apps-filetree-root'; } // user/group mount root if (!empty($options['mount-root'])) { $iconName = 'apps-filetree-mount'; if ($role === \TYPO3\CMS\Core\Resource\FolderInterface::ROLE_READONLY_MOUNT) { $overlays['status-overlay-locked'] = array(); } elseif ($role === \TYPO3\CMS\Core\Resource\FolderInterface::ROLE_USER_MOUNT) { $overlays['status-overlay-access-restricted'] = array(); } } if ($iconName === NULL) { // in folder tree view $options['folder-open'] can define a open folder icon if (!empty($options['folder-open'])) { $iconName = 'apps-filetree-folder-opened'; } else { $iconName = 'apps-filetree-folder-default'; } if ($role === \TYPO3\CMS\Core\Resource\FolderInterface::ROLE_TEMPORARY) { $iconName = 'apps-filetree-folder-temp'; } elseif ($role === \TYPO3\CMS\Core\Resource\FolderInterface::ROLE_RECYCLER) { $iconName = 'apps-filetree-folder-recycler'; } } // if locked add overlay if ($resource instanceof \TYPO3\CMS\Core\Resource\InaccessibleFolder || !$resource->getStorage()->isBrowsable() || !$resource->getStorage()->checkFolderActionPermission('add', $resource)) { $overlays['status-overlay-locked'] = array(); } } // File } else { $iconName = self::mapFileExtensionToSpriteIconName($resource->getExtension()); if ($resource instanceof \TYPO3\CMS\Core\Resource\File && $resource->isMissing()) { $overlays['status-overlay-missing'] = array(); } } // Hook: allow some other process to influence the choice of icon and overlays if (is_array($GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['t3lib/class.t3lib_iconworks.php']['overrideResourceIcon'])) { foreach ($GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['t3lib/class.t3lib_iconworks.php']['overrideResourceIcon'] as $classRef) { $hookObject = GeneralUtility::getUserObj($classRef); if (!$hookObject instanceof IconUtilityOverrideResourceIconHookInterface) { throw new \UnexpectedValueException('$hookObject must implement interface TYPO3\\CMS\\Backend\\Utility\\IconUtilityOverrideResourceIconHookInterface', 1393574895); } $hookObject->overrideResourceIcon($resource, $iconName, $options, $overlays); } } unset($options['mount-root']); unset($options['folder-open']); return self::getSpriteIcon($iconName, $options, $overlays); }
/** * Like ->getHeader() but for files and folders * Returns the icon with the path of the file/folder set in the alt/title attribute. Shows the name after the icon. * * @param \TYPO3\CMS\Core\Resource\ResourceInterface $resource * @param array $tWrap is an array with indexes 0 and 1 each representing HTML-tags (start/end) which will wrap the title * @param bool $enableClickMenu If TRUE, render click menu code around icon image * @return string */ public function getResourceHeader(\TYPO3\CMS\Core\Resource\ResourceInterface $resource, $tWrap = array('', ''), $enableClickMenu = true) { try { $path = $resource->getStorage()->getName() . $resource->getParentFolder()->getIdentifier(); $iconImgTag = '<span title="' . htmlspecialchars($path) . '">' . $this->iconFactory->getIconForResource($resource, Icon::SIZE_SMALL)->render() . '</span>'; } catch (\TYPO3\CMS\Core\Resource\Exception\ResourceDoesNotExistException $e) { $iconImgTag = ''; } if ($enableClickMenu && $resource instanceof \TYPO3\CMS\Core\Resource\File) { $metaData = $resource->_getMetaData(); $iconImgTag = BackendUtility::wrapClickMenuOnIcon($iconImgTag, 'sys_file_metadata', $metaData['uid']); } return '<span class="typo3-moduleHeader">' . $iconImgTag . $tWrap[0] . htmlspecialchars(GeneralUtility::fixed_lgd_cs($resource->getName(), 45)) . $tWrap[1] . '</span>'; }
/** * Get FeGroups that are allowed to view a file/folder (checks full rootline) * * @param ResourceInterface $resource * @return string */ public function getPermissions(ResourceInterface $resource) { $currentPermissionsCheck = $resource->getStorage()->getEvaluatePermissions(); $resource->getStorage()->setEvaluatePermissions(false); $feGroups = array(); // loop trough the root line of an folder and check the permissions of every folder foreach ($this->getFolderRootLine($resource->getParentFolder()) as $folder) { // fetch folder permissions record $folderRecord = $this->utilityService->getFolderRecord($folder); // if record found check permissions if ($folderRecord) { if ($feGroups === array()) { $feGroups = GeneralUtility::trimExplode(',', $folderRecord['fe_groups'], true); } if ($folderRecord['fe_groups']) { $feGroups = GeneralUtility::keepItemsInArray($feGroups, $folderRecord['fe_groups']); } break; } } if ($resource instanceof File && $resource->getProperty('fe_groups')) { $feGroups = GeneralUtility::keepItemsInArray($feGroups, $resource->getProperty('fe_groups')); } $resource->getStorage()->setEvaluatePermissions($currentPermissionsCheck); return implode(',', $feGroups); }
/** * This method is used throughout the TYPO3 Backend to show icons for files and folders * * The method takes care of the translation of file extension to proper icon and for folders * it will return the icon depending on the role of the folder. * * If the given resource is a folder there are some additional options that can be used: * - mount-root => TRUE (to indicate this is the root of a mount) * - folder-open => TRUE (to indicate that the folder is opened in the file tree) * * There is a hook in place to manipulate the icon name and overlays. * * @param ResourceInterface $resource * @param string $size "large" "small" or "default", see the constants of the Icon class * @param string $overlayIdentifier * @param array $options An associative array with additional options. * @return Icon */ public function getIconForResource(ResourceInterface $resource, $size = Icon::SIZE_DEFAULT, $overlayIdentifier = null, array $options = array()) { $iconIdentifier = null; // Folder if ($resource instanceof FolderInterface) { // non browsable storage if ($resource->getStorage()->isBrowsable() === false && !empty($options['mount-root'])) { $iconIdentifier = 'apps-filetree-folder-locked'; } else { // storage root if ($resource->getStorage()->getRootLevelFolder()->getIdentifier() === $resource->getIdentifier()) { $iconIdentifier = 'apps-filetree-root'; } $role = is_callable([$resource, 'getRole']) ? $resource->getRole() : ''; // user/group mount root if (!empty($options['mount-root'])) { $iconIdentifier = 'apps-filetree-mount'; if ($role === FolderInterface::ROLE_READONLY_MOUNT) { $overlayIdentifier = 'overlay-locked'; } elseif ($role === FolderInterface::ROLE_USER_MOUNT) { $overlayIdentifier = 'overlay-restricted'; } } if ($iconIdentifier === null) { // in folder tree view $options['folder-open'] can define an open folder icon if (!empty($options['folder-open'])) { $iconIdentifier = 'apps-filetree-folder-opened'; } else { $iconIdentifier = 'apps-filetree-folder-default'; } if ($role === FolderInterface::ROLE_TEMPORARY) { $iconIdentifier = 'apps-filetree-folder-temp'; } elseif ($role === FolderInterface::ROLE_RECYCLER) { $iconIdentifier = 'apps-filetree-folder-recycler'; } } // if locked add overlay if ($resource instanceof InaccessibleFolder || !$resource->getStorage()->isBrowsable() || !$resource->getStorage()->checkFolderActionPermission('add', $resource)) { $overlayIdentifier = 'overlay-locked'; } } // File } elseif ($resource instanceof File) { $mimeTypeIcon = $this->iconRegistry->getIconIdentifierForMimeType($resource->getMimeType()); // Check if we find a exact matching mime type if ($mimeTypeIcon !== null) { $iconIdentifier = $mimeTypeIcon; } else { $fileExtensionIcon = $this->iconRegistry->getIconIdentifierForFileExtension($resource->getExtension()); if ($fileExtensionIcon !== 'mimetypes-other-other') { // Fallback 1: icon by file extension $iconIdentifier = $fileExtensionIcon; } else { // Fallback 2: icon by mime type with subtype replaced by * $mimeTypeParts = explode('/', $resource->getMimeType()); $mimeTypeIcon = $this->iconRegistry->getIconIdentifierForMimeType($mimeTypeParts[0] . '/*'); if ($mimeTypeIcon !== null) { $iconIdentifier = $mimeTypeIcon; } else { // Fallback 3: use 'mimetypes-other-other' $iconIdentifier = $fileExtensionIcon; } } } if ($resource->isMissing()) { $overlayIdentifier = 'overlay-missing'; } } unset($options['mount-root']); unset($options['folder-open']); list($iconIdentifier, $overlayIdentifier) = $this->emitBuildIconForResourceSignal($resource, $size, $options, $iconIdentifier, $overlayIdentifier); return $this->getIcon($iconIdentifier, $size, $overlayIdentifier); }
/** * Like ->getHeader() but for files and folders * Returns the icon with the path of the file/folder set in the alt/title attribute. Shows the name after the icon. * * @param \TYPO3\CMS\Core\Resource\ResourceInterface $resource * @param array $tWrap is an array with indexes 0 and 1 each representing HTML-tags (start/end) which will wrap the title * @param bool $enableClickMenu If TRUE, render click menu code around icon image * @return string */ public function getResourceHeader(\TYPO3\CMS\Core\Resource\ResourceInterface $resource, $tWrap = array('', ''), $enableClickMenu = TRUE) { $path = $resource->getStorage()->getName() . $resource->getParentFolder()->getIdentifier(); $iconImgTag = IconUtility::getSpriteIconForResource($resource, array('title' => htmlspecialchars($path))); if ($enableClickMenu && $resource instanceof \TYPO3\CMS\Core\Resource\File) { $metaData = $resource->_getMetaData(); $iconImgTag = $this->wrapClickMenuOnIcon($iconImgTag, 'sys_file_metadata', $metaData['uid']); } return '<span class="typo3-moduleHeader">' . $iconImgTag . $tWrap[0] . htmlspecialchars(GeneralUtility::fixed_lgd_cs($resource->getName(), 45)) . $tWrap[1] . '</span>'; }
/** * This method is used throughout the TYPO3 Backend to show icons for files and folders * * The method takes care of the translation of file extension to proper icon and for folders * it will return the icon depending on the role of the folder. * * If the given resource is a folder there are some additional options that can be used: * - mount-root => TRUE (to indicate this is the root of a mount) * - folder-open => TRUE (to indicate that the folder is opened in the file tree) * * There is a hook in place to manipulate the icon name and overlays. * * @param ResourceInterface $resource * @param string $size "large" "small" or "default", see the constants of the Icon class * @param string $overlayIdentifier * @param array $options An associative array with additional options. * @return Icon */ public function getIconForResource(ResourceInterface $resource, $size = Icon::SIZE_DEFAULT, $overlayIdentifier = null, array $options = array()) { $iconIdentifier = null; // Folder if ($resource instanceof FolderInterface) { // non browsable storage if ($resource->getStorage()->isBrowsable() === false && !empty($options['mount-root'])) { $iconIdentifier = 'apps-filetree-folder-locked'; } else { // storage root if ($resource->getStorage()->getRootLevelFolder()->getIdentifier() === $resource->getIdentifier()) { $iconIdentifier = 'apps-filetree-root'; } $role = is_callable([$resource, 'getRole']) ? $resource->getRole() : ''; // user/group mount root if (!empty($options['mount-root'])) { $iconIdentifier = 'apps-filetree-mount'; if ($role === FolderInterface::ROLE_READONLY_MOUNT) { $overlayIdentifier = 'overlay-locked'; } elseif ($role === FolderInterface::ROLE_USER_MOUNT) { $overlayIdentifier = 'overlay-restricted'; } } if ($iconIdentifier === null) { // in folder tree view $options['folder-open'] can define an open folder icon if (!empty($options['folder-open'])) { $iconIdentifier = 'apps-filetree-folder-opened'; } else { $iconIdentifier = 'apps-filetree-folder-default'; } if ($role === FolderInterface::ROLE_TEMPORARY) { $iconIdentifier = 'apps-filetree-folder-temp'; } elseif ($role === FolderInterface::ROLE_RECYCLER) { $iconIdentifier = 'apps-filetree-folder-recycler'; } } // if locked add overlay if ($resource instanceof InaccessibleFolder || !$resource->getStorage()->isBrowsable() || !$resource->getStorage()->checkFolderActionPermission('add', $resource)) { $overlayIdentifier = 'overlay-locked'; } } // File } else { if ($resource instanceof File && $resource->isMissing()) { $overlayIdentifier = 'overlay-missing'; } $iconRegistry = GeneralUtility::makeInstance(IconRegistry::class); $iconIdentifier = $iconRegistry->getIconIdentifierForFileExtension($resource->getExtension()); } unset($options['mount-root']); unset($options['folder-open']); list($iconIdentifier, $overlayIdentifier) = $this->emitBuildIconForResourceSignal($resource, $size, $options, $iconIdentifier, $overlayIdentifier); return $this->getIcon($iconIdentifier, $size, $overlayIdentifier); }