[BUGFIX] Unable to edit file metadata
[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\ResourceFactory;
19
20 /**
21 * Utility class to render TCEforms information about a sys_file record
22 */
23 class FileInfoHook
24 {
25 /**
26 * User function for sys_file (element)
27 *
28 * @param array $propertyArray the array with additional configuration options.
29 * @return string The HTML code for the TCEform field
30 */
31 public function renderFileInfo(array $propertyArray)
32 {
33 $fileRecord = $propertyArray['row'];
34 $fileObject = null;
35 if ($fileRecord['uid'] > 0) {
36 $fileObject = ResourceFactory::getInstance()->getFileObject((int)$fileRecord['uid']);
37 }
38 return $this->renderFileInformationContent($fileObject);
39 }
40
41 /**
42 * User function for sys_file_meta (element)
43 *
44 * @param array $propertyArray the array with additional configuration options.
45 * @return string The HTML code for the TCEform field
46 */
47 public function renderFileMetadataInfo(array $propertyArray)
48 {
49 $fileMetadataRecord = $propertyArray['row'];
50 $fileObject = null;
51 if (!empty($fileMetadataRecord['file']) && $fileMetadataRecord['file'][0] > 0) {
52 $fileObject = ResourceFactory::getInstance()->getFileObject((int)$fileMetadataRecord['file'][0]);
53 }
54
55 return $this->renderFileInformationContent($fileObject);
56 }
57
58
59 /**
60 * Renders a HTML Block with file information
61 *
62 * @param \TYPO3\CMS\Core\Resource\File $file
63 * @return string
64 */
65 protected function renderFileInformationContent(\TYPO3\CMS\Core\Resource\File $file = null)
66 {
67 if ($file !== null) {
68 $processedFile = $file->process(\TYPO3\CMS\Core\Resource\ProcessedFile::CONTEXT_IMAGEPREVIEW, array('width' => 150, 'height' => 150));
69 $previewImage = $processedFile->getPublicUrl(true);
70 $content = '';
71 if ($file->isMissing()) {
72 $flashMessage = \TYPO3\CMS\Core\Resource\Utility\BackendUtility::getFlashMessageForMissingFile($file);
73 $content .= $flashMessage->render();
74 }
75 if ($previewImage) {
76 $content .= '<img src="' . htmlspecialchars($previewImage) . '" ' .
77 'width="' . $processedFile->getProperty('width') . '" ' .
78 'height="' . $processedFile->getProperty('height') . '" ' .
79 'alt="" class="t3-tceforms-sysfile-imagepreview" />';
80 }
81 $content .= '<strong>' . htmlspecialchars($file->getName()) . '</strong>';
82 $content .= ' (' . htmlspecialchars(\TYPO3\CMS\Core\Utility\GeneralUtility::formatSize($file->getSize())) . 'bytes)<br />';
83 $content .= BackendUtility::getProcessedValue('sys_file', 'type', $file->getType()) . ' (' . $file->getMimeType() . ')<br />';
84 $content .= $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_misc.xlf:fileMetaDataLocation', true) . ': ';
85 $content .= htmlspecialchars($file->getStorage()->getName()) . ' - ' . htmlspecialchars($file->getIdentifier()) . '<br />';
86 $content .= '<br />';
87 } else {
88 $content = '<h2>' . $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_misc.xlf:fileMetaErrorInvalidRecord', true) . '</h2>';
89 }
90
91 return $content;
92 }
93 }