[TASK] Add addTop/removeTop row in backend layout wizard
[Packages/TYPO3.CMS.git] / typo3 / sysext / core / Classes / Resource / Hook / FileInfoHook.php
1 <?php
2 namespace TYPO3\CMS\Core\Resource\Hook;
3
4 /*
5 * This file is part of the TYPO3 CMS project.
6 *
7 * It is free software; you can redistribute it and/or modify it under
8 * the terms of the GNU General Public License, either version 2
9 * of the License, or any later version.
10 *
11 * For the full copyright and license information, please read the
12 * LICENSE.txt file that was distributed with this source code.
13 *
14 * The TYPO3 project - inspiring people to share!
15 */
16
17 use TYPO3\CMS\Backend\Utility\BackendUtility;
18 use TYPO3\CMS\Core\Resource\File;
19 use TYPO3\CMS\Core\Resource\ProcessedFile;
20 use TYPO3\CMS\Core\Resource\ResourceFactory;
21 use TYPO3\CMS\Core\Utility\GeneralUtility;
22 use TYPO3\CMS\Lang\LanguageService;
23
24 /**
25 * Utility class to render TCEforms information about a sys_file record
26 */
27 class FileInfoHook
28 {
29 /**
30 * User function for sys_file (element)
31 *
32 * @param array $propertyArray the array with additional configuration options.
33 * @return string The HTML code for the TCEform field
34 */
35 public function renderFileInfo(array $propertyArray)
36 {
37 $fileRecord = $propertyArray['row'];
38 $fileObject = null;
39 if ($fileRecord['uid'] > 0) {
40 $fileObject = ResourceFactory::getInstance()->getFileObject((int)$fileRecord['uid']);
41 }
42 return $this->renderFileInformationContent($fileObject);
43 }
44
45 /**
46 * User function for sys_file_meta (element)
47 *
48 * @param array $propertyArray the array with additional configuration options.
49 * @return string The HTML code for the TCEform field
50 */
51 public function renderFileMetadataInfo(array $propertyArray)
52 {
53 $fileMetadataRecord = $propertyArray['row'];
54 $fileObject = null;
55 if (!empty($fileMetadataRecord['file']) && $fileMetadataRecord['file'][0] > 0) {
56 $fileObject = ResourceFactory::getInstance()->getFileObject((int)$fileMetadataRecord['file'][0]);
57 }
58
59 return $this->renderFileInformationContent($fileObject);
60 }
61
62 /**
63 * Renders a HTML Block with file information
64 *
65 * @param File $file
66 * @return string
67 */
68 protected function renderFileInformationContent(File $file = null)
69 {
70 /** @var LanguageService $lang */
71 $lang = $GLOBALS['LANG'];
72
73 if ($file !== null) {
74 $processedFile = $file->process(ProcessedFile::CONTEXT_IMAGEPREVIEW, ['width' => 150, 'height' => 150]);
75 $previewImage = $processedFile->getPublicUrl(true);
76 $content = '';
77 if ($file->isMissing()) {
78 $content .= '<span class="label label-danger label-space-right">'
79 . htmlspecialchars($lang->sL('LLL:EXT:lang/Resources/Private/Language/locallang_core.xlf:warning.file_missing'))
80 . '</span>';
81 }
82 if ($previewImage) {
83 $content .= '<img src="' . htmlspecialchars($previewImage) . '" ' .
84 'width="' . $processedFile->getProperty('width') . '" ' .
85 'height="' . $processedFile->getProperty('height') . '" ' .
86 'alt="" class="t3-tceforms-sysfile-imagepreview" />';
87 }
88 $content .= '<strong>' . htmlspecialchars($file->getName()) . '</strong>';
89 $content .= ' (' . htmlspecialchars(GeneralUtility::formatSize($file->getSize())) . 'bytes)<br />';
90 $content .= BackendUtility::getProcessedValue('sys_file', 'type', $file->getType()) . ' (' . $file->getMimeType() . ')<br />';
91 $content .= htmlspecialchars($lang->sL('LLL:EXT:lang/Resources/Private/Language/locallang_misc.xlf:fileMetaDataLocation')) . ': ';
92 $content .= htmlspecialchars($file->getStorage()->getName()) . ' - ' . htmlspecialchars($file->getIdentifier()) . '<br />';
93 $content .= '<br />';
94 } else {
95 $content = '<h2>' . htmlspecialchars($lang->sL('LLL:EXT:lang/Resources/Private/Language/locallang_misc.xlf:fileMetaErrorInvalidRecord')) . '</h2>';
96 }
97
98 return $content;
99 }
100 }