/** * Renders a HTML Block with file information * * @param File $file * @return string */ protected function renderFileInformationContent(File $file = null) { /** @var LanguageService $lang */ $lang = $GLOBALS['LANG']; if ($file !== null) { $processedFile = $file->process(ProcessedFile::CONTEXT_IMAGEPREVIEW, ['width' => 150, 'height' => 150]); $previewImage = $processedFile->getPublicUrl(true); $content = ''; if ($file->isMissing()) { $content .= '<span class="label label-danger label-space-right">' . htmlspecialchars($lang->sL('LLL:EXT:lang/Resources/Private/Language/locallang_core.xlf:warning.file_missing')) . '</span>'; } if ($previewImage) { $content .= '<img src="' . htmlspecialchars($previewImage) . '" ' . 'width="' . $processedFile->getProperty('width') . '" ' . 'height="' . $processedFile->getProperty('height') . '" ' . 'alt="" class="t3-tceforms-sysfile-imagepreview" />'; } $content .= '<strong>' . htmlspecialchars($file->getName()) . '</strong>'; $content .= ' (' . htmlspecialchars(GeneralUtility::formatSize($file->getSize())) . 'bytes)<br />'; $content .= BackendUtility::getProcessedValue('sys_file', 'type', $file->getType()) . ' (' . $file->getMimeType() . ')<br />'; $content .= htmlspecialchars($lang->sL('LLL:EXT:lang/Resources/Private/Language/locallang_misc.xlf:fileMetaDataLocation')) . ': '; $content .= htmlspecialchars($file->getStorage()->getName()) . ' - ' . htmlspecialchars($file->getIdentifier()) . '<br />'; $content .= '<br />'; } else { $content = '<h2>' . htmlspecialchars($lang->sL('LLL:EXT:lang/Resources/Private/Language/locallang_misc.xlf:fileMetaErrorInvalidRecord')) . '</h2>'; } return $content; }
/** * Injects a local file, which is a processing result into the object. * * @param string $filePath * @return void * @throws \RuntimeException */ public function updateWithLocalFile($filePath) { if ($this->identifier === null) { throw new \RuntimeException('Cannot update original file!', 1350582054); } $processingFolder = $this->originalFile->getStorage()->getProcessingFolder(); $addedFile = $this->storage->updateProcessedFile($filePath, $this, $processingFolder); // Update some related properties $this->identifier = $addedFile->getIdentifier(); $this->originalFileSha1 = $this->originalFile->getSha1(); if ($addedFile instanceof AbstractFile) { $this->updateProperties($addedFile->getProperties()); } $this->deleted = false; $this->updated = true; }
/** * 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 array of meta-data properties * * @param File $file * @return array */ public function findByFile(File $file) { $record = $this->findByFileUid($file->getUid()); // It could be possible that the meta information is freshly // created and inserted into the database. If this is the case // we have to take care about correct meta information for width and // height in case of an image. if (!empty($record['newlyCreated'])) { if ($file->getType() === File::FILETYPE_IMAGE && $file->getStorage()->getDriverType() === 'Local') { $fileNameAndPath = $file->getForLocalProcessing(false); $imageInfo = GeneralUtility::makeInstance(FileType\ImageInfo::class, $fileNameAndPath); $additionalMetaInformation = array('width' => $imageInfo->getWidth(), 'height' => $imageInfo->getHeight()); $this->update($file->getUid(), $additionalMetaInformation); } $record = $this->findByFileUid($file->getUid()); } return $record; }
/** * Initialize * * @throws \TYPO3\CMS\Core\Resource\Exception\InsufficientFileAccessPermissionsException */ protected function init() { // Initialize GPvars: $this->target = GeneralUtility::_GP('target'); $this->returnUrl = GeneralUtility::sanitizeLocalUrl(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 = $this->getLanguageService()->sL('LLL:EXT:lang/locallang_mod_file_list.xlf:paramError', TRUE); $message = $this->getLanguageService()->sL('LLL:EXT:lang/locallang_mod_file_list.xlf:targetNoDir', TRUE); throw new \RuntimeException($title . ': ' . $message, 1294586844); } if ($this->fileOrFolderObject->getStorage()->getUid() === 0) { throw new \TYPO3\CMS\Core\Resource\Exception\InsufficientFileAccessPermissionsException('You are not allowed to access files outside your storages', 1375889840); } // 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 = 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 = GeneralUtility::makeInstance(\TYPO3\CMS\Backend\Template\DocumentTemplate::class); $this->doc->setModuleTemplate('EXT:backend/Resources/Private/Templates/file_rename.html'); $this->doc->backPath = $GLOBALS['BACK_PATH']; $this->doc->JScode = $this->doc->wrapScriptTags(' function backToList() { // top.goToModule("file_list"); } '); }
/** * Initialize * * @throws \TYPO3\CMS\Core\Resource\Exception\InsufficientFileAccessPermissionsException */ protected function init() { // Initialize GPvars: $this->target = GeneralUtility::_GP('target'); $this->returnUrl = GeneralUtility::sanitizeLocalUrl(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 = $this->getLanguageService()->sL('LLL:EXT:lang/locallang_mod_file_list.xlf:paramError', true); $message = $this->getLanguageService()->sL('LLL:EXT:lang/locallang_mod_file_list.xlf:targetNoDir', true); throw new \RuntimeException($title . ': ' . $message, 1294586844); } if ($this->fileOrFolderObject->getStorage()->getUid() === 0) { throw new \TYPO3\CMS\Core\Resource\Exception\InsufficientFileAccessPermissionsException('You are not allowed to access files outside your storages', 1375889840); } // 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 \TYPO3\CMS\Core\Resource\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); } } // building pathInfo for metaInformation $pathInfo = ['combined_identifier' => $this->fileOrFolderObject->getCombinedIdentifier()]; $this->moduleTemplate->getDocHeaderComponent()->setMetaInformation($pathInfo); // Setting up the context sensitive menu $this->moduleTemplate->getPageRenderer()->loadRequireJsModule('TYPO3/CMS/Backend/ClickMenu'); // Add javaScript $this->moduleTemplate->addJavaScriptCode('RenameFileInlineJavaScript', 'function backToList() {top.goToModule("file_FilelistList");}'); }
/** * Returns a where clause to find a file in database * * @param File $file * * @return string */ protected function getWhereClauseForFile(File $file) { if ((int) $file->_getPropertyRaw('uid') > 0) { $where = 'uid=' . (int) $file->getUid(); } else { $where = sprintf('storage=%u AND identifier LIKE %s', (int) $file->getStorage()->getUid(), $this->getDatabaseConnection()->fullQuoteStr($file->_getPropertyRaw('identifier'), $this->table)); } return $where; }
/** * Returns an index record of a file, or FALSE if the file is not indexed. * * @TODO : throw an exception if nothing found, for consistent handling as in AbstractRepository? * @param \TYPO3\CMS\Core\Resource\File $fileObject * @return bool|array */ public function getFileIndexRecord(\TYPO3\CMS\Core\Resource\File $fileObject) { $storageUid = $fileObject->getStorage()->getUid(); $identifier = $fileObject->getIdentifier(); $row = $GLOBALS['TYPO3_DB']->exec_SELECTgetSingleRow('*', $this->table, sprintf('storage=%u AND identifier=%s', $storageUid, $GLOBALS['TYPO3_DB']->fullQuoteStr($identifier, $this->table))); if (!is_array($row)) { return FALSE; } else { return $row; } }
/** * Get user permissions * * @param string|File $file * @param string $content * @param array $additionalFields * @param array $indexRecordValues * @param \tx_kesearch_indexer_types_file $indexer */ public function modifyFileIndexEntry($file, $content, $additionalFields, &$indexRecordValues, $indexer) { if ($file instanceof File && !$file->getStorage()->isPublic()) { $indexRecordValues['fe_group'] = $this->checkPermissionsService->getPermissions($file); } }
/** * Get the storage the original file is located in * * @return ResourceStorage */ public function getStorage() { return $this->originalFile->getStorage(); }
/** * Checks the index status of a file and returns FALSE if the file is not * indexed, the uid otherwise. * * @param File $fileObject * @return boolean|integer * @deprecated since TYPO3 6.2, will be removed two versions later - use FileIndexRepository::isIndexed */ public function getFileIndexStatus(File $fileObject) { GeneralUtility::logDeprecatedFunction(); $storageUid = $fileObject->getStorage()->getUid(); $identifier = $fileObject->getIdentifier(); $row = $this->getFileIndexRepository()->findOneByStorageUidAndIdentifier($storageUid, $identifier); return is_array($row) ? $row['uid'] : FALSE; }
/** * Handle file upload for an existing file. * * @param File $file * @return string */ public function updateAction(File $file) { $uploadedFile = $this->handleUpload(); if (!is_object($uploadedFile)) { return htmlspecialchars(json_encode($uploadedFile), ENT_NOQUOTES); } /** @var $file File */ $targetFolder = $file->getStorage()->getFolder(dirname($file->getIdentifier())); try { $storage = $file->getStorage(); $storage->replaceFile($file, $uploadedFile->getFileWithAbsolutePath()); // Run the indexer for extracting metadata. $this->getMediaIndexer($file->getStorage())->updateIndex($file)->extractMetadata($file); // Clear cache on pages holding a reference to this file. $this->getCacheService()->clearCache($file); $response = array('success' => TRUE, 'uid' => $file->getUid(), 'name' => $file->getName(), 'thumbnail' => $this->getThumbnailService($file)->create(), 'fileInfo' => $this->getMetadataViewHelper()->render($file)); } catch (UploadException $e) { $response = array('error' => 'The upload has failed, no uploaded file found!'); } catch (InsufficientUserPermissionsException $e) { $response = array('error' => 'You are not allowed to upload files!'); } catch (UploadSizeException $e) { $response = array('error' => vsprintf('The uploaded file "%s" exceeds the size-limit', array($uploadedFile->getName()))); } catch (InsufficientFolderWritePermissionsException $e) { $response = array('error' => vsprintf('Destination path "%s" was not within your mount points!', array($targetFolder->getIdentifier()))); } catch (IllegalFileExtensionException $e) { $response = array('error' => vsprintf('Extension of file name "%s" is not allowed in "%s"!', array($uploadedFile->getName(), $targetFolder->getIdentifier()))); } catch (ExistingTargetFileNameException $e) { $response = array('error' => vsprintf('No unique filename available in "%s"!', array($targetFolder->getIdentifier()))); } catch (\RuntimeException $e) { $response = array('error' => vsprintf('Uploaded file could not be moved! Write-permission problem in "%s"?', array($targetFolder->getIdentifier()))); } // to pass data through iframe you will need to encode all html tags header("Content-Type: text/plain"); return htmlspecialchars(json_encode($response), ENT_NOQUOTES); }