TYPO3 CMS  TYPO3_8-7
FileInfoElement.php
Go to the documentation of this file.
1 <?php
2 declare(strict_types = 1);
4 
5 /*
6  * This file is part of the TYPO3 CMS project.
7  *
8  * It is free software; you can redistribute it and/or modify it under
9  * the terms of the GNU General Public License, either version 2
10  * of the License, or any later version.
11  *
12  * For the full copyright and license information, please read the
13  * LICENSE.txt file that was distributed with this source code.
14  *
15  * The TYPO3 project - inspiring people to share!
16  */
17 
24 
31 {
32 
38  public function render(): array
39  {
40  $resultArray = $this->initializeResultArray();
41 
42  $fileUid = 0;
43  if ($this->data['tableName'] === 'sys_file') {
44  $fileUid = (int)$this->data['databaseRow']['uid'];
45  } elseif ($this->data['tableName'] === 'sys_file_metadata') {
46  $fileUid = (int)$this->data['databaseRow']['file'][0];
47  }
48 
49  $fileObject = null;
50  if ($fileUid > 0) {
51  $fileObject = ResourceFactory::getInstance()->getFileObject($fileUid);
52  }
53  $resultArray['html'] = $this->renderFileInformationContent($fileObject);
54  return $resultArray;
55  }
56 
63  protected function renderFileInformationContent(File $file = null): string
64  {
66  $lang = $GLOBALS['LANG'];
67 
68  if ($file !== null) {
69  $content = '';
70  if ($file->isMissing()) {
71  $content .= '<span class="label label-danger label-space-right">'
72  . htmlspecialchars($lang->sL('LLL:EXT:lang/Resources/Private/Language/locallang_core.xlf:warning.file_missing'))
73  . '</span>';
74  }
75  if (GeneralUtility::inList($GLOBALS['TYPO3_CONF_VARS']['GFX']['imagefile_ext'], $file->getExtension())) {
76  $processedFile = $file->process(ProcessedFile::CONTEXT_IMAGEPREVIEW, ['width' => 150, 'height' => 150]);
77  $previewImage = $processedFile->getPublicUrl(true);
78  if ($previewImage) {
79  $content .= '<img src="' . htmlspecialchars($previewImage) . '" ' .
80  'width="' . $processedFile->getProperty('width') . '" ' .
81  'height="' . $processedFile->getProperty('height') . '" ' .
82  'alt="" class="t3-tceforms-sysfile-imagepreview" />';
83  }
84  }
85  $content .= '<strong>' . htmlspecialchars($file->getName()) . '</strong>';
86  $content .= ' (' . htmlspecialchars(GeneralUtility::formatSize($file->getSize())) . 'bytes)<br />';
87  $content .= BackendUtility::getProcessedValue('sys_file', 'type', $file->getType()) . ' (' . $file->getMimeType() . ')<br />';
88  $content .= htmlspecialchars($lang->sL('LLL:EXT:lang/Resources/Private/Language/locallang_misc.xlf:fileMetaDataLocation')) . ': ';
89  $content .= htmlspecialchars($file->getStorage()->getName()) . ' - ' . htmlspecialchars($file->getIdentifier()) . '<br />';
90  $content .= '<br />';
91  } else {
92  $content = '<h2>' . htmlspecialchars($lang->sL('LLL:EXT:lang/Resources/Private/Language/locallang_misc.xlf:fileMetaErrorInvalidRecord')) . '</h2>';
93  }
94 
95  return $content;
96  }
97 }
static formatSize($sizeInBytes, $labels='', $base=0)
if(TYPO3_MODE==='BE') $GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['t3lib/class.t3lib_tsfebeuserauth.php']['frontendEditingController']['default']