6b98a6493aff4e8b8b50c2fab05b97cfe183c0d7
[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 use TYPO3\CMS\Core\Utility\GeneralUtility;
17 use TYPO3\CMS\Frontend\Controller\TypoScriptFrontendController;
18
19 /**
20 * Contains FILE class object.
21 */
22 class FileContentObject extends AbstractContentObject
23 {
24 /**
25 * Rendering the cObject, FILE
26 *
27 * @param array $conf Array of TypoScript properties
28 * @return string Output
29 */
30 public function render($conf = [])
31 {
32 $theValue = '';
33 $file = isset($conf['file.']) ? $this->cObj->stdWrap($conf['file'], $conf['file.']) : $conf['file'];
34 $file = $this->getTypoScriptFrontendController()->tmpl->getFileName($file);
35 if ($file !== null && file_exists($file)) {
36 $fileInfo = GeneralUtility::split_fileref($file);
37 $extension = $fileInfo['fileext'];
38 if ($extension === 'jpg' || $extension === 'jpeg' || $extension === 'gif' || $extension === 'png') {
39 $imgInfo = @getimagesize($file);
40 $altParameters = trim($this->cObj->getAltParam($conf, false));
41 $theValue = '<img src="' . htmlspecialchars($this->getTypoScriptFrontendController()->absRefPrefix . $file) . '" width="' . (int)$imgInfo[0] . '" height="' . (int)$imgInfo[1] . '"' . $this->cObj->getBorderAttr(' border="0"') . ' ' . $altParameters . ' />';
42 } elseif (filesize($file) < 1024 * 1024) {
43 $theValue = file_get_contents($file);
44 }
45 }
46
47 $linkWrap = isset($conf['linkWrap.']) ? $this->cObj->stdWrap($conf['linkWrap'], $conf['linkWrap.']) : $conf['linkWrap'];
48 if ($linkWrap) {
49 $theValue = $this->cObj->linkWrap($theValue, $linkWrap);
50 }
51 $wrap = isset($conf['wrap.']) ? $this->cObj->stdWrap($conf['wrap'], $conf['wrap.']) : $conf['wrap'];
52 if ($wrap) {
53 $theValue = $this->cObj->wrap($theValue, $wrap);
54 }
55 if (isset($conf['stdWrap.'])) {
56 $theValue = $this->cObj->stdWrap($theValue, $conf['stdWrap.']);
57 }
58 return $theValue;
59 }
60
61 /**
62 * @return TypoScriptFrontendController
63 */
64 protected function getTypoScriptFrontendController()
65 {
66 return $GLOBALS['TSFE'];
67 }
68 }