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