[TASK] Add functional tests for copying a record into another language
[Packages/TYPO3.CMS.git] / typo3 / sysext / frontend / Classes / ContentObject / FileContentObject.php
1 <?php
2 namespace TYPO3\CMS\Frontend\ContentObject;
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\Core\Type\File\ImageInfo;
18 use TYPO3\CMS\Core\Utility\GeneralUtility;
19 use TYPO3\CMS\Frontend\Controller\TypoScriptFrontendController;
20 use TYPO3\CMS\Frontend\Resource\FilePathSanitizer;
21
22 /**
23 * Contains FILE class object.
24 */
25 class FileContentObject extends AbstractContentObject
26 {
27 /**
28 * Rendering the cObject, FILE
29 *
30 * @param array $conf Array of TypoScript properties
31 * @return string Output
32 */
33 public function render($conf = [])
34 {
35 $theValue = '';
36 $file = isset($conf['file.']) ? $this->cObj->stdWrap($conf['file'], $conf['file.']) : $conf['file'];
37 try {
38 $file = GeneralUtility::makeInstance(FilePathSanitizer::class)->sanitize($file);
39 if (file_exists($file)) {
40 $fileInfo = GeneralUtility::split_fileref($file);
41 $extension = $fileInfo['fileext'];
42 if ($extension === 'jpg' || $extension === 'jpeg' || $extension === 'gif' || $extension === 'png') {
43 $imageInfo = GeneralUtility::makeInstance(ImageInfo::class, $file);
44 $altParameters = trim($this->cObj->getAltParam($conf, false));
45 $theValue = '<img src="'
46 . htmlspecialchars($this->getTypoScriptFrontendController()->absRefPrefix . $file)
47 . '" width="' . (int)$imageInfo->getWidth() . '" height="' . (int)$imageInfo->getHeight()
48 . '"' . $this->cObj->getBorderAttr(' border="0"') . ' ' . $altParameters . ' />';
49 } elseif (filesize($file) < 1024 * 1024) {
50 $theValue = file_get_contents($file);
51 }
52 }
53 } catch (\TYPO3\CMS\Core\Resource\Exception $e) {
54 // do nothing
55 }
56 $linkWrap = isset($conf['linkWrap.']) ? $this->cObj->stdWrap($conf['linkWrap'], $conf['linkWrap.']) : $conf['linkWrap'];
57 if ($linkWrap) {
58 $theValue = $this->cObj->linkWrap($theValue, $linkWrap);
59 }
60 $wrap = isset($conf['wrap.']) ? $this->cObj->stdWrap($conf['wrap'], $conf['wrap.']) : $conf['wrap'];
61 if ($wrap) {
62 $theValue = $this->cObj->wrap($theValue, $wrap);
63 }
64 if (isset($conf['stdWrap.'])) {
65 $theValue = $this->cObj->stdWrap($theValue, $conf['stdWrap.']);
66 }
67 return $theValue;
68 }
69
70 /**
71 * @return TypoScriptFrontendController
72 */
73 protected function getTypoScriptFrontendController()
74 {
75 return $GLOBALS['TSFE'];
76 }
77 }