作者:camrun9
项目:fal_securedownloa
/**
* renders <f:then> child if the current logged in FE user has access to the given asset
* otherwise renders <f:else> child.
*
* @param Folder $folder
* @param File $file
* @return bool|string
*/
public function render(Folder $folder, File $file = NULL)
{
/** @var $checkPermissionsService \BeechIt\FalSecuredownload\Security\CheckPermissions */
$checkPermissionsService = GeneralUtility::makeInstance('BeechIt\\FalSecuredownload\\Security\\CheckPermissions');
$userFeGroups = $this->getFeUserGroups();
$access = FALSE;
// check folder access
if ($checkPermissionsService->checkFolderRootLineAccess($folder, $userFeGroups)) {
if ($file === NULL) {
$access = TRUE;
} else {
$feGroups = $file->getProperty('fe_groups');
if ($feGroups !== '') {
$access = $checkPermissionsService->matchFeGroupsWithFeUser($feGroups, $userFeGroups);
} else {
$access = TRUE;
}
}
}
if ($access) {
return $this->renderThenChild();
} else {
return $this->renderElseChild();
}
}
作者:viso
项目:medi
/**
* @param File $file
* @return string
*/
protected function getUri(File $file)
{
$metadataProperties = $file->_getMetaData();
$parameterName = sprintf('edit[sys_file_metadata][%s]', $metadataProperties['uid']);
$uri = BackendUtility::getModuleUrl('record_edit', array($parameterName => 'edit', 'returnUrl' => BackendUtility::getModuleUrl(GeneralUtility::_GP('M'), $this->getAdditionalParameters())));
return $uri;
}
作者:TYPO3Incubato
项目:TYPO3.CM
/**
* 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, array('width' => 150, 'height' => 150));
$previewImage = $processedFile->getPublicUrl(true);
$content = '';
if ($file->isMissing()) {
$flashMessage = \TYPO3\CMS\Core\Resource\Utility\BackendUtility::getFlashMessageForMissingFile($file);
$content .= $flashMessage->render();
}
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 .= $lang->sL('LLL:EXT:lang/locallang_misc.xlf:fileMetaDataLocation', true) . ': ';
$content .= htmlspecialchars($file->getStorage()->getName()) . ' - ' . htmlspecialchars($file->getIdentifier()) . '<br />';
$content .= '<br />';
} else {
$content = '<h2>' . $lang->sL('LLL:EXT:lang/locallang_misc.xlf:fileMetaErrorInvalidRecord', true) . '</h2>';
}
return $content;
}
作者:neufein
项目:ext-tik
/**
* Checks if the given file can be processed by this Extractor
*
* @param Resource\File $file
* @return boolean
*/
public function canProcess(Resource\File $file)
{
// TODO use MIME type instead of extension
// tika.jar --list-supported-types -> cache supported types
// compare to file's MIME type
return in_array($file->getProperty('extension'), $this->supportedFileTypes);
}
作者:khanhdeu
项目:typo3tes
/**
* This test accounts for an inconsistency in the Storage–Driver interface of FAL: The driver returns the MIME
* type in a field "mimetype", while the file object and the database table use mime_type.
* The test is placed in the test case for AbstractFile because the broken functionality resides there, though
* it is only triggered when constructing a File instance with an index record.
*
* @test
*/
public function storageIsNotAskedForMimeTypeForPersistedRecord()
{
$mockedStorage = $this->getMockBuilder('TYPO3\\CMS\\Core\\Resource\\ResourceStorage')->disableOriginalConstructor()->getMock();
$mockedStorage->expects($this->never())->method('getFileInfoByIdentifier')->with('/foo', 'mimetype');
$subject = new File(array('identifier' => '/foo', 'mime_type' => 'my/mime-type'), $mockedStorage);
$this->assertEquals('my/mime-type', $subject->getMimeType());
}
作者:vip3ou
项目:TYPO3.CM
/**
* Get Online Media item id
*
* @param File $file
* @return string
*/
public function getOnlineMediaId(File $file)
{
if (!isset($this->onlineMediaIdCache[$file->getUid()])) {
// By definition these files only contain the ID of the remote media source
$this->onlineMediaIdCache[$file->getUid()] = trim($file->getContents());
}
return $this->onlineMediaIdCache[$file->getUid()];
}
作者:grauru
项目:testgit_t3
/**
* Get helper class for given File
*
* @param File $file
* @return bool|OnlineMediaHelperInterface
*/
public function getOnlineMediaHelper(File $file)
{
$registeredHelpers = $GLOBALS['TYPO3_CONF_VARS']['SYS']['fal']['onlineMediaHelpers'];
if (isset($registeredHelpers[$file->getExtension()])) {
return GeneralUtility::makeInstance($registeredHelpers[$file->getExtension()], $file->getExtension());
}
return false;
}
作者:rickymathe
项目:TYPO3.CM
/**
* This test accounts for an inconsistency in the Storage–Driver interface of FAL: The driver returns the MIME
* type in a field "mimetype", while the file object and the database table use mime_type.
* The test is placed in the test case for AbstractFile because the broken functionality resides there, though
* it is only triggered when constructing a File instance with an index record.
*
* @test
*/
public function storageIsNotAskedForMimeTypeForPersistedRecord()
{
/** @var ResourceStorage|\PHPUnit_Framework_MockObject_MockObject $mockedStorage */
$mockedStorage = $this->getMockBuilder(ResourceStorage::class)->disableOriginalConstructor()->getMock();
$mockedStorage->expects($this->never())->method('getFileInfoByIdentifier')->with('/foo', 'mimetype');
$subject = new File(array('identifier' => '/foo', 'mime_type' => 'my/mime-type'), $mockedStorage);
$this->assertEquals('my/mime-type', $subject->getMimeType());
}
作者:viso
项目:medi
/**
* Returns a default template.
*
* @param File $file
* @return string
*/
protected function getDefaultTemplate(File $file)
{
$template = '%size Ko';
if ($file->getType() == File::FILETYPE_IMAGE) {
$template = '%width x %height - ' . $template;
}
return $template;
}
作者:khanhdeu
项目:typo3tes
/**
* Sets up this test case.
*/
protected function setUp()
{
$this->fileResourceMock = $this->getMock('TYPO3\\CMS\\Core\\Resource\\File', array('toArray', 'getModificationTime', 'getExtension'), array(), '', FALSE);
$this->folderResourceMock = $this->getMock('TYPO3\\CMS\\Core\\Resource\\Folder', array('getIdentifier'), array(), '', FALSE);
$this->mockFileProcessor = $this->getMock('TYPO3\\CMS\\Core\\Utility\\File\\ExtendedFileUtility', array('getErrorMessages'), array(), '', FALSE);
$this->fileResourceMock->expects($this->any())->method('toArray')->will($this->returnValue(array('id' => 'foo')));
$this->fileResourceMock->expects($this->any())->method('getModificationTime')->will($this->returnValue(123456789));
$this->fileResourceMock->expects($this->any())->method('getExtension')->will($this->returnValue('html'));
}
作者:rickymathe
项目:TYPO3.CM
/**
* Sets up this test case.
*/
protected function setUp()
{
$this->fileResourceMock = $this->getMock(\TYPO3\CMS\Core\Resource\File::class, array('toArray', 'getModificationTime', 'getExtension'), array(), '', false);
$this->folderResourceMock = $this->getMock(\TYPO3\CMS\Core\Resource\Folder::class, array('getIdentifier'), array(), '', false);
$this->mockFileProcessor = $this->getMock(\TYPO3\CMS\Core\Utility\File\ExtendedFileUtility::class, array('getErrorMessages'), array(), '', false);
$this->fileResourceMock->expects($this->any())->method('toArray')->will($this->returnValue(array('id' => 'foo')));
$this->fileResourceMock->expects($this->any())->method('getModificationTime')->will($this->returnValue(123456789));
$this->fileResourceMock->expects($this->any())->method('getExtension')->will($this->returnValue('html'));
$this->request = new ServerRequest();
$this->response = new Response();
}
作者:neufein
项目:ext-tik
/**
* Takes a file reference and extracts its meta data.
*
* @param \TYPO3\CMS\Core\Resource\File $file
* @return array
*/
public function extractMetaData(File $file)
{
$localTempFilePath = $file->getForLocalProcessing(FALSE);
$query = GeneralUtility::makeInstance('ApacheSolrForTypo3\\Tika\\Service\\Tika\\SolrCellQuery', $localTempFilePath);
$query->setExtractOnly();
$response = $this->solr->extract($query);
$metaData = $this->solrResponseToArray($response[1]);
$this->cleanupTempFile($localTempFilePath, $file);
$this->log('Meta Data Extraction using Solr', array('file' => $file, 'solr connection' => (array) $this->solr, 'query' => (array) $query, 'response' => $response, 'meta data' => $metaData));
return $metaData;
}
作者:smichaelse
项目:vh
/**
* Fixes a bug in TYPO3 6.2.0 that the properties metadata is not overlayed on localization.
*
* @param File $file
* @return array
*/
public static function getFileArray(File $file)
{
$properties = $file->getProperties();
$stat = $file->getStorage()->getFileInfo($file);
$array = $file->toArray();
foreach ($properties as $key => $value) {
$array[$key] = $value;
}
foreach ($stat as $key => $value) {
$array[$key] = $value;
}
return $array;
}
作者:Ecode
项目:natural-carousel-typo
/**
* Resize image and garantees a minimum size for each dimension
* @param File $file
* @return File|ProcessedFile
*/
public function createProcessedThumbnail(File $file)
{
$minSize = 84;
$width = (int) $file->getProperty('width');
$height = (int) $file->getProperty('height');
$ratio = $width / $height;
if ($width > $height) {
$configuration = ['maxWidth' => ceil($minSize * $ratio), 'height' => $minSize];
} else {
$configuration = ['width' => $minSize, 'maxHeight' => ceil($minSize / $ratio)];
}
$file = $file->process(ProcessedFile::CONTEXT_IMAGECROPSCALEMASK, $configuration);
return $file;
}
作者:plan2ne
项目:TYPO3.CM
/**
* Creates a magic image
*
* @param Resource\File $imageFileObject: the original image file
* @param array $fileConfiguration (width, height)
* @return Resource\ProcessedFile
*/
public function createMagicImage(Resource\File $imageFileObject, array $fileConfiguration)
{
// Process dimensions
$maxWidth = MathUtility::forceIntegerInRange($fileConfiguration['width'], 0, $this->magicImageMaximumWidth);
$maxHeight = MathUtility::forceIntegerInRange($fileConfiguration['height'], 0, $this->magicImageMaximumHeight);
if (!$maxWidth) {
$maxWidth = $this->magicImageMaximumWidth;
}
if (!$maxHeight) {
$maxHeight = $this->magicImageMaximumHeight;
}
// Create the magic image
$magicImage = $imageFileObject->process(Resource\ProcessedFile::CONTEXT_IMAGECROPSCALEMASK, array('width' => $maxWidth . 'm', 'height' => $maxHeight . 'm'));
return $magicImage;
}
作者:TYPO3Incubato
项目:TYPO3.CM
/**
* Generate the name of of the new File
*
* @return string
*/
public function generateProcessedFileNameWithoutExtension()
{
$name = $this->originalFile->getNameWithoutExtension();
$name .= '_' . $this->originalFile->getUid();
$name .= '_' . $this->calculateChecksum();
return $name;
}
作者:viso
项目:medi
/**
* Render a thumbnail of a media
*
* @throws MissingTcaConfigurationException
* @return string
*/
public function create()
{
if (empty($this->file)) {
throw new MissingTcaConfigurationException('Missing File object. Forgotten to set a file?', 1355933144);
}
// Default class name
$className = 'Fab\\Media\\Thumbnail\\FallBackThumbnailProcessor';
if (File::FILETYPE_IMAGE == $this->file->getType()) {
$className = 'Fab\\Media\\Thumbnail\\ImageThumbnailProcessor';
} elseif (File::FILETYPE_AUDIO == $this->file->getType()) {
$className = 'Fab\\Media\\Thumbnail\\AudioThumbnailProcessor';
} elseif (File::FILETYPE_VIDEO == $this->file->getType()) {
$className = 'Fab\\Media\\Thumbnail\\VideoThumbnailProcessor';
} elseif (File::FILETYPE_APPLICATION == $this->file->getType() || File::FILETYPE_TEXT == $this->file->getType()) {
$className = 'Fab\\Media\\Thumbnail\\ApplicationThumbnailProcessor';
}
/** @var $processorInstance \Fab\Media\Thumbnail\ThumbnailProcessorInterface */
$processorInstance = GeneralUtility::makeInstance($className);
$thumbnail = '';
if ($this->file->exists()) {
$thumbnail = $processorInstance->setThumbnailService($this)->create();
} else {
$logger = Logger::getInstance($this);
$logger->warning(sprintf('Resource not found for File uid "%s" at %s', $this->file->getUid(), $this->file->getIdentifier()));
}
return $thumbnail;
}
作者:s-nune
项目:fal_securedownloa
/**
* 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;
}
作者:mneuhau
项目:ke_searc
/**
* return file path
*
* @return string Filepath (f.e. /var/www/fileadmin/)
*/
public function getPath()
{
if ($this->file !== NULL) {
return $this->file->getForLocalProcessing(FALSE);
} else {
return $this->fileInfo['path'];
}
}
作者:teaminmedias-pluswer
项目:ke_searc
/**
* return file path
* @return string Filepath (f.e. /var/www/fileadmin/)
*/
public function getPath()
{
if ($this->file !== null) {
return $this->file->getForLocalProcessing(false);
} else {
return $this->fileInfo['path'];
}
}