Пример #1
0
 /**
  * Perform custom security/access when accessing file
  * Method should issue 403 if access is rejected
  * or 401 if authentication is required
  *
  * @param \TYPO3\CMS\Core\Resource\ResourceInterface $file
  * @return void
  */
 public function checkFileAccess(\TYPO3\CMS\Core\Resource\ResourceInterface $file)
 {
     if (!$file instanceof \TYPO3\CMS\Core\Resource\File) {
         $this->originalFile = $file->getOriginalFile();
     } else {
         $this->originalFile = $file;
     }
     if (!$this->checkPermissions()) {
         if (!$this->isLoggedIn()) {
             if ($this->loginRedirectUrl !== null) {
                 $this->redirectToUrl($this->loginRedirectUrl);
             } else {
                 $this->exitScript('Authentication required!', 401);
             }
         } else {
             if ($this->noAccessRedirectUrl !== null) {
                 $this->redirectToUrl($this->noAccessRedirectUrl);
             } else {
                 $this->exitScript('No access!', 403);
             }
         }
     }
     /** @var \TYPO3\CMS\Extbase\SignalSlot\Dispatcher $signalSlotDispatcher */
     $signalSlotDispatcher = GeneralUtility::makeInstance('TYPO3\\CMS\\Extbase\\SignalSlot\\Dispatcher');
     $signalSlotDispatcher->dispatch(__CLASS__, 'BeforeFileDump', array($file, $this));
     // todo: find a nicer way to force the download. Other hooks are blocked by this
     if (isset($_REQUEST['download'])) {
         $file->getStorage()->dumpFileContents($file, true);
         exit;
     }
 }
 /**
  * This method will be called be the signal slot for retrieving the public URL
  * of a file.
  *
  * If the processed file was not modified (the original file is used) and if
  * that file comes from the storage using the Remote driver the public
  * URL will be modified to read the image from the remote server.
  *
  * @param \TYPO3\CMS\Core\Resource\ResourceStorage $resourceStorage
  * @param \TYPO3\CMS\Core\Resource\Driver\DriverInterface $driver
  * @param \TYPO3\CMS\Core\Resource\ResourceInterface $resourceObject
  * @param bool $relativeToCurrentScript
  * @param $urlData
  */
 public function adjustPublicUrlForProcessedFiles($resourceStorage, $driver, $resourceObject, $relativeToCurrentScript, $urlData)
 {
     if (!$resourceObject instanceof ProcessedFile) {
         return;
     }
     if (!$resourceObject->usesOriginalFile()) {
         return;
     }
     $originalDriver = $this->getDriver($resourceObject->getOriginalFile()->getStorage());
     if (!$originalDriver instanceof RemoteDriver) {
         return;
     }
     $urlData['publicUrl'] = $resourceObject->getOriginalFile()->getPublicUrl($relativeToCurrentScript);
 }
 /**
  * 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");}');
 }
 /**
  * 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;
 }
Пример #5
0
 /**
  * @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');
             }
         }
     }
 }
Пример #6
0
    /**
     * Main function, rendering the content of the rename form
     *
     * @return void
     */
    public function main()
    {
        // Make page header:
        $this->content = $this->doc->startPage($GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.xlf:file_rename.php.pagetitle'));
        $pageContent = $this->doc->header($GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.xlf:file_rename.php.pagetitle'));
        $pageContent .= $this->doc->spacer(5);
        $pageContent .= $this->doc->divider(5);
        if ($this->fileOrFolderObject instanceof \TYPO3\CMS\Core\Resource\Folder) {
            $fileIdentifier = $this->fileOrFolderObject->getCombinedIdentifier();
        } else {
            $fileIdentifier = $this->fileOrFolderObject->getUid();
        }
        $code = '<form action="tce_file.php" method="post" name="editform">';
        // Making the formfields for renaming:
        $code .= '

			<div id="c-rename">
				<input type="text" name="file[rename][0][target]" value="' . htmlspecialchars($this->fileOrFolderObject->getName()) . '"' . $GLOBALS['TBE_TEMPLATE']->formWidth(40) . ' />
				<input type="hidden" name="file[rename][0][data]" value="' . htmlspecialchars($fileIdentifier) . '" />
			</div>
		';
        // Making submit button:
        $code .= '
			<div id="c-submit">
				<input type="submit" value="' . $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.xlf:file_rename.php.submit', TRUE) . '" />
				<input type="submit" value="' . $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.xlf:labels.cancel', TRUE) . '" onclick="backToList(); return false;" />
				<input type="hidden" name="redirect" value="' . htmlspecialchars($this->returnUrl) . '" />
				' . \TYPO3\CMS\Backend\Form\FormEngine::getHiddenTokenField('tceAction') . '
			</div>
		';
        $code .= '</form>';
        // Add the HTML as a section:
        $pageContent .= $code;
        $docHeaderButtons = array('back' => '');
        $docHeaderButtons['csh'] = BackendUtility::cshItem('xMOD_csh_corebe', 'file_rename', $GLOBALS['BACK_PATH']);
        // Back
        if ($this->returnUrl) {
            $docHeaderButtons['back'] = '<a href="' . htmlspecialchars(\TYPO3\CMS\Core\Utility\GeneralUtility::linkThisUrl($this->returnUrl)) . '" class="typo3-goBack" title="' . $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.xlf:labels.goBack', TRUE) . '">' . \TYPO3\CMS\Backend\Utility\IconUtility::getSpriteIcon('actions-view-go-back') . '</a>';
        }
        // Add the HTML as a section:
        $markerArray = array('CSH' => $docHeaderButtons['csh'], 'FUNC_MENU' => BackendUtility::getFuncMenu($this->id, 'SET[function]', $this->MOD_SETTINGS['function'], $this->MOD_MENU['function']), 'CONTENT' => $pageContent, 'PATH' => $this->title);
        $this->content .= $this->doc->moduleBody(array(), $docHeaderButtons, $markerArray);
        $this->content .= $this->doc->endPage();
        $this->content = $this->doc->insertStylesAndJS($this->content);
    }
 /**
  * @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);
     }
 }
Пример #8
0
 /**
  * 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());
 }
Пример #9
0
 /**
  * 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);
 }
Пример #10
0
 /**
  * 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);
 }
Пример #11
0
 /**
  * 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;
 }
Пример #12
0
 /**
  * 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);
 }
 /**
  * @param ResourceInterface $resource
  * @return string
  */
 protected function getResourceSourcePathAndFileName(ResourceInterface $resource)
 {
     $pathAndFilename = $this->resourcesSourcePath . ltrim($resource->getIdentifier(), '/');
     return file_exists($pathAndFilename) ? $pathAndFilename : FALSE;
 }
Пример #15
0
 /**
  * Retrieve data from a file reference
  *
  * @param \TYPO3\CMS\Core\Resource\ResourceInterface|Folder|\TYPO3\CMS\Core\Resource\AbstractFile $originalResource
  * @return array
  */
 protected function transformFileReference($originalResource)
 {
     static $depth = 0;
     if ($originalResource instanceof AbstractFileFolder) {
         if (++$depth > 10) {
             throw new \RuntimeException('Max nesting level');
         }
         $result = $this->transformFileReference($originalResource->getOriginalResource());
         $depth--;
         return $result;
     }
     try {
         if ($originalResource instanceof Folder) {
             $filesInFolder = array();
             foreach ($originalResource->getFiles() as $currentFile) {
                 $filesInFolder[] = $this->transformFileReference($currentFile);
             }
             return $filesInFolder;
         }
         if ($originalResource instanceof FileReference) {
             // This would expose all data
             // return $originalResource->getProperties();
             list($title, $description) = $this->getTitleAndDescription($originalResource);
             return array('name' => $originalResource->getName(), 'mimeType' => $originalResource->getMimeType(), 'url' => $originalResource->getPublicUrl(), 'size' => $originalResource->getSize(), 'title' => $title, 'description' => $description);
         }
         if ($originalResource instanceof FileInterface) {
             return array('name' => $originalResource->getName(), 'mimeType' => $originalResource->getMimeType(), 'url' => $originalResource->getPublicUrl(), 'size' => $originalResource->getSize());
         }
         return array('name' => $originalResource->getName());
     } catch (\RuntimeException $exception) {
         return array();
     }
 }
Пример #16
0
 /**
  * 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>';
 }
Пример #17
0
 /**
  * @param \TYPO3\CMS\Core\Resource\ResourceInterface $originalResource
  */
 public function setOriginalResource(\TYPO3\CMS\Core\Resource\ResourceInterface $originalResource)
 {
     $this->originalResource = $originalResource;
     $this->uidLocal = (int) $originalResource->getOriginalFile()->getUid();
 }
Пример #18
0
 /**
  * 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;
 }
Пример #19
0
 /**
  * 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());
 }