/** * 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"); } '); }
/** * @param \TYPO3\CMS\Core\Resource\ResourceStorage $resourceStorage * @param \TYPO3\CMS\Core\Resource\Driver\DriverInterface $driver * @param \TYPO3\CMS\Core\Resource\ResourceInterface $resourceObject * @param boolean $relativeToCurrentScript * @param string $urlData */ public function getCdnPublicUrl($resourceStorage, $driver, $resourceObject, $relativeToCurrentScript, $urlData) { if (!$driver instanceof LocalDriver || $this->environmentService->isEnvironmentInBackendMode()) { return; } if (($resourceObject instanceof File || $resourceObject instanceof ProcessedFile) && ($resourceStorage->getCapabilities() & ResourceStorageInterface::CAPABILITY_PUBLIC) == ResourceStorageInterface::CAPABILITY_PUBLIC) { $publicUrl = $driver->getPublicUrl($resourceObject->getIdentifier()); $urlData['publicUrl'] = $GLOBALS['TSFE']->config['config']['cdnBaseUrl'] . $publicUrl; if ($resourceObject instanceof File) { $urlData['publicUrl'] .= '?' . $resourceObject->getModificationTime(); } else { if ($resourceObject instanceof ProcessedFile) { $urlData['publicUrl'] .= '?' . $resourceObject->getProperty('tstamp'); } } } }
/** * Returns the public URL to a file. * * @param \TYPO3\CMS\Core\Resource\ResourceInterface $resource * @param bool $relativeToCurrentScript Determines whether the URL returned should be relative to the current script, in case it is relative at all (only for the LocalDriver) * @return string */ public function getPublicUrl(\TYPO3\CMS\Core\Resource\ResourceInterface $resource, $relativeToCurrentScript = false) { if (\TYPO3\CMS\Core\Utility\GeneralUtility::isFirstPartOfStr($resource->getIdentifier(), '/_processed_/')) { $publicUrl = '../typo3temp/yag' . $resource->getIdentifier(); // TODO: ....!!!! } else { $item = $resource->getProperty('yagItem'); if (!$item instanceof \Tx_Yag_Domain_Model_Item) { $pathInfo = new PathInfo($resource->getIdentifier()); $item = $this->getItem($pathInfo); } $publicUrl = $this->yagFileSystemDiv->getFileRelFileName($item->getSourceuri()); } if ($relativeToCurrentScript) { $publicUrl = PathUtility::getRelativePathTo(PathUtility::dirname(PATH_site . $publicUrl)) . PathUtility::basename($publicUrl); } 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); }
/** * Returns the public URL to a file. For the local driver, this will always * return a path relative to PATH_site. * * @param \TYPO3\CMS\Core\Resource\ResourceInterface $fileOrFolder * @param bool $relativeToCurrentScript Determines whether the URL returned should be relative to the current script, in case it is relative at all (only for the LocalDriver) * @return string */ public function getPublicUrl(\TYPO3\CMS\Core\Resource\ResourceInterface $fileOrFolder, $relativeToCurrentScript = FALSE) { if ($this->configuration['pathType'] === 'relative' && rtrim($this->configuration['basePath'], '/') !== '') { $publicUrl = rtrim($this->configuration['basePath'], '/') . '/' . ltrim($fileOrFolder->getIdentifier(), '/'); } elseif (isset($this->baseUri)) { $publicUrl = $this->baseUri . ltrim($fileOrFolder->getIdentifier(), '/'); } else { throw new \TYPO3\CMS\Core\Resource\Exception('Public URL of file cannot be determined', 1329765518); } // If requested, make the path relative to the current script in order to make it possible // to use the relative file if ($relativeToCurrentScript) { $publicUrl = \TYPO3\CMS\Core\Utility\PathUtility::getRelativePathTo(dirname(PATH_site . $publicUrl)) . basename($publicUrl); } return $publicUrl; }
/** * 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); }
/** * @param ResourceInterface $resource * @return string */ protected function getResourceUri(ResourceInterface $resource) { return PathUtility::getCanonicalPath($this->getResourcesBaseUri() . '/' . $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 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); }
/** * @param ResourceInterface $resource * @return string */ protected function getResourceSourcePathAndFileName(ResourceInterface $resource) { $pathAndFilename = $this->resourcesSourcePath . ltrim($resource->getIdentifier(), '/'); return file_exists($pathAndFilename) ? $pathAndFilename : FALSE; }