[CLEANUP] Replace count with empty in multiple extensions
[Packages/TYPO3.CMS.git] / typo3 / sysext / compatibility6 / Classes / ContentObject / ImageTextContentObject.php
1 <?php
2 namespace TYPO3\CMS\Compatibility6\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\Utility\GeneralUtility;
18 use TYPO3\CMS\Core\Resource\ResourceFactory;
19
20 /**
21 * Contains IMGTEXT content object.
22 *
23 * @author Xavier Perseguers <typo3@perseguers.ch>
24 * @author Steffen Kamper <steffen@typo3.org>
25 */
26 class ImageTextContentObject extends \TYPO3\CMS\Frontend\ContentObject\AbstractContentObject {
27
28 /**
29 * @var ResourceFactory
30 */
31 protected $fileFactory = NULL;
32
33 /**
34 * Rendering the cObject, IMGTEXT
35 * which is a text w/ image type that works with the image position through tables (pre-CSS styled content-time)
36 *
37 * @param array $conf Array of TypoScript properties
38 * @return string Output
39 */
40 public function render($conf = array()) {
41 $content = '';
42 if (isset($conf['text.'])) {
43 $text = $this->cObj->cObjGet($conf['text.'], 'text.');
44 // this gets the surrounding content
45 $content .= $this->cObj->stdWrap($text, $conf['text.']);
46 }
47 $imgList = isset($conf['imgList.']) ? trim($this->cObj->stdWrap($conf['imgList'], $conf['imgList.'])) : trim($conf['imgList']);
48 if ($imgList) {
49 $imgs = GeneralUtility::trimExplode(',', $imgList, TRUE);
50 $imgStart = isset($conf['imgStart.']) ? (int)$this->cObj->stdWrap($conf['imgStart'], $conf['imgStart.']) : (int)$conf['imgStart'];
51 $imgCount = count($imgs) - $imgStart;
52 $imgMax = isset($conf['imgMax.']) ? (int)$this->cObj->stdWrap($conf['imgMax'], $conf['imgMax.']) : (int)$conf['imgMax'];
53 if ($imgMax) {
54 // Reduces the number of images.
55 $imgCount = \TYPO3\CMS\Core\Utility\MathUtility::forceIntegerInRange($imgCount, 0, $imgMax);
56 }
57 $imgPath = isset($conf['imgPath.']) ? $this->cObj->stdWrap($conf['imgPath'], $conf['imgPath.']) : $conf['imgPath'];
58 // initialisation
59 $caption = '';
60 $captionArray = array();
61 if (!$conf['captionSplit'] && !$conf['imageTextSplit'] && isset($conf['caption.'])) {
62 $caption = $this->cObj->cObjGet($conf['caption.'], 'caption.');
63 // Global caption, no splitting
64 $caption = $this->cObj->stdWrap($caption, $conf['caption.']);
65 }
66 if ($conf['captionSplit'] && $conf['captionSplit.']['cObject']) {
67 $legacyCaptionSplit = 1;
68 $capSplit = isset($conf['captionSplit.']['token.']) ? $this->cObj->stdWrap($conf['captionSplit.']['token'], $conf['captionSplit.']['token.']) : $conf['captionSplit.']['token'];
69 if (!$capSplit) {
70 $capSplit = LF;
71 }
72 $captionArray = explode($capSplit, $this->cObj->cObjGetSingle($conf['captionSplit.']['cObject'], $conf['captionSplit.']['cObject.'], 'captionSplit.cObject'));
73 foreach ($captionArray as $ca_key => $ca_val) {
74 $captionArray[$ca_key] = isset($conf['captionSplit.']['stdWrap.']) ? $this->cObj->stdWrap(trim($captionArray[$ca_key]), $conf['captionSplit.']['stdWrap.']) : trim($captionArray[$ca_key]);
75 }
76 }
77 $tablecode = '';
78 $position = isset($conf['textPos.']) ? $this->cObj->stdWrap($conf['textPos'], $conf['textPos.']) : $conf['textPos'];
79 $tmppos = $position & 7;
80 $contentPosition = $position & 24;
81 $align = $this->cObj->align[$tmppos];
82 $cap = $caption ? 1 : 0;
83 $txtMarg = isset($conf['textMargin.']) ? (int)$this->cObj->stdWrap($conf['textMargin'], $conf['textMargin.']) : (int)$conf['textMargin'];
84 if (!$conf['textMargin_outOfText'] && $contentPosition < 16) {
85 $txtMarg = 0;
86 }
87 $cols = isset($conf['cols.']) ? (int)$this->cObj->stdWrap($conf['cols'], $conf['cols.']) : (int)$conf['cols'];
88 $rows = isset($conf['rows.']) ? (int)$this->cObj->stdWrap($conf['rows'], $conf['rows.']) : (int)$conf['rows'];
89 $colspacing = isset($conf['colSpace.']) ? (int)$this->cObj->stdWrap($conf['colSpace'], $conf['colSpace.']) : (int)$conf['colSpace'];
90 $rowspacing = isset($conf['rowSpace.']) ? (int)$this->cObj->stdWrap($conf['rowSpace'], $conf['rowSpace.']) : (int)$conf['rowSpace'];
91 $border = isset($conf['border.']) ? (int)$this->cObj->stdWrap($conf['border'], $conf['border.']) : (int)$conf['border'];
92 $border = $border ? 1 : 0;
93 if ($border) {
94 $borderColor = isset($conf['borderCol.']) ? $this->cObj->stdWrap($conf['borderCol'], $conf['borderCol.']) : $conf['borderCol'];
95 if (!$borderColor) {
96 $borderColor = 'black';
97 }
98 $borderThickness = isset($conf['borderThick.']) ? (int)$this->cObj->stdWrap($conf['borderThick'], $conf['borderThick.']) : (int)$conf['borderThick'];
99 if (!$borderThickness) {
100 $borderThickness = 'black';
101 }
102 }
103 $caption_align = isset($conf['captionAlign.']) ? $this->cObj->stdWrap($conf['captionAlign'], $conf['captionAlign.']) : $conf['captionAlign'];
104 if (!$caption_align) {
105 $caption_align = $align;
106 }
107 // Generate cols
108 $colCount = $cols > 1 ? $cols : 1;
109 if ($colCount > $imgCount) {
110 $colCount = $imgCount;
111 }
112 $rowCount = $colCount > 1 ? ceil($imgCount / $colCount) : $imgCount;
113 // Generate rows
114 if ($rows > 1) {
115 $rowCount = $rows;
116 if ($rowCount > $imgCount) {
117 $rowCount = $imgCount;
118 }
119 $colCount = $rowCount > 1 ? ceil($imgCount / $rowCount) : $imgCount;
120 }
121 // Max Width
122 $colRelations = isset($conf['colRelations.']) ? trim($this->cObj->stdWrap($conf['colRelations'], $conf['colRelations.'])) : trim($conf['colRelations']);
123 $maxW = isset($conf['maxW.']) ? (int)$this->cObj->stdWrap($conf['maxW'], $conf['maxW.']) : (int)$conf['maxW'];
124 $maxWInText = isset($conf['maxWInText.']) ? (int)$this->cObj->stdWrap($conf['maxWInText'], $conf['maxWInText.']) : (int)$conf['maxWInText'];
125 // If maxWInText is not set, it's calculated to the 50 % of the max...
126 if (!$maxWInText) {
127 $maxWInText = round($maxW / 2);
128 }
129 // inText
130 if ($maxWInText && $contentPosition >= 16) {
131 $maxW = $maxWInText;
132 }
133 // If there is a max width and if colCount is greater than column
134 if ($maxW && $colCount > 0) {
135 $maxW = ceil(($maxW - $colspacing * ($colCount - 1) - $colCount * $border * $borderThickness * 2) / $colCount);
136 }
137 // Create the relation between rows
138 $colMaxW = array();
139 if ($colRelations) {
140 $rel_parts = explode(':', $colRelations);
141 $rel_total = 0;
142 for ($a = 0; $a < $colCount; $a++) {
143 $rel_parts[$a] = (int)$rel_parts[$a];
144 $rel_total += $rel_parts[$a];
145 }
146 if ($rel_total) {
147 for ($a = 0; $a < $colCount; $a++) {
148 $colMaxW[$a] = round($maxW * $colCount / $rel_total * $rel_parts[$a]);
149 }
150 // The difference in size between the largest and smalles must be within a factor of ten.
151 if (min($colMaxW) <= 0 || max($rel_parts) / min($rel_parts) > 10) {
152 $colMaxW = array();
153 }
154 }
155 }
156 $image_compression = isset($conf['image_compression.']) ? (int)$this->cObj->stdWrap($conf['image_compression'], $conf['image_compression.']) : (int)$conf['image_compression'];
157 $image_effects = isset($conf['image_effects.']) ? (int)$this->cObj->stdWrap($conf['image_effects'], $conf['image_effects.']) : (int)$conf['image_effects'];
158 $image_frames = isset($conf['image_frames.']['key.']) ? (int)$this->cObj->stdWrap($conf['image_frames.']['key'], $conf['image_frames.']['key.']) : (int)$conf['image_frames.']['key'];
159 // Fetches pictures
160 $splitArr = array();
161 $splitArr['imgObjNum'] = $conf['imgObjNum'];
162 $splitArr = $GLOBALS['TSFE']->tmpl->splitConfArray($splitArr, $imgCount);
163 // EqualHeight
164 $equalHeight = isset($conf['equalH.']) ? (int)$this->cObj->stdWrap($conf['equalH'], $conf['equalH.']) : (int)$conf['equalH'];
165 // Initiate gifbuilder object in order to get dimensions AND calculate the imageWidth's
166 if ($equalHeight) {
167 $gifCreator = GeneralUtility::makeInstance(\TYPO3\CMS\Frontend\Imaging\GifBuilder::class);
168 $gifCreator->init();
169 $relations = array();
170 $relations_cols = array();
171 $totalMaxW = $maxW * $colCount;
172 for ($a = 0; $a < $imgCount; $a++) {
173 $imgKey = $a + $imgStart;
174 $imgInfo = $gifCreator->getImageDimensions($imgPath . $imgs[$imgKey]);
175 // relationship between the original height and the wished height
176 $relations[$a] = $imgInfo[1] / $equalHeight;
177 // if relations is zero, then the addition of this value is omitted as
178 // the image is not expected to display because of some error.
179 if ($relations[$a]) {
180 // Counts the total width of the row with the new height taken into consideration.
181 $relations_cols[floor($a / $colCount)] += $imgInfo[0] / $relations[$a];
182 }
183 }
184 }
185 // Contains the width of every image row
186 $imageRowsFinalWidths = array();
187 $imageRowsMaxHeights = array();
188 $imgsTag = array();
189 $origImages = array();
190 for ($a = 0; $a < $imgCount; $a++) {
191 $GLOBALS['TSFE']->register['IMAGE_NUM'] = $a;
192 $GLOBALS['TSFE']->register['IMAGE_NUM_CURRENT'] = $a;
193 $imgKey = $a + $imgStart;
194 if (\TYPO3\CMS\Core\Utility\MathUtility::canBeInterpretedAsInteger($imgs[$imgKey])) {
195 $this->setCurrentFileInContentObjectRenderer(intval($imgs[$imgKey]));
196 }
197 $totalImagePath = $imgPath . $imgs[$imgKey];
198 $this->cObj->data[$this->cObj->currentValKey] = $totalImagePath;
199 $imgObjNum = (int)$splitArr[$a]['imgObjNum'];
200 $imgConf = $conf[$imgObjNum . '.'];
201 if ($equalHeight) {
202 $scale = 1;
203 if ($totalMaxW) {
204 $rowTotalMaxW = $relations_cols[floor($a / $colCount)];
205 if ($rowTotalMaxW > $totalMaxW) {
206 $scale = $rowTotalMaxW / $totalMaxW;
207 }
208 }
209 // Transfer info to the imageObject. Please note, that
210 $imgConf['file.']['height'] = round($equalHeight / $scale);
211 unset($imgConf['file.']['width'], $imgConf['file.']['maxW'], $imgConf['file.']['maxH'], $imgConf['file.']['minW'], $imgConf['file.']['minH'], $imgConf['file.']['width.'], $imgConf['file.']['maxW.'], $imgConf['file.']['maxH.'], $imgConf['file.']['minW.'], $imgConf['file.']['minH.']);
212 // Setting this to zero, so that it doesn't disturb
213 $maxW = 0;
214 }
215 if ($maxW) {
216 if (!empty($colMaxW)) {
217 $imgConf['file.']['maxW'] = $colMaxW[$a % $colCount];
218 } else {
219 $imgConf['file.']['maxW'] = $maxW;
220 }
221 }
222 // Image Object supplied:
223 if (is_array($imgConf)) {
224 if ($this->cObj->image_effects[$image_effects]) {
225 $imgConf['file.']['params'] .= ' ' . $this->cObj->image_effects[$image_effects];
226 }
227 if ($image_frames) {
228 if (is_array($conf['image_frames.'][$image_frames . '.'])) {
229 $imgConf['file.']['m.'] = $conf['image_frames.'][$image_frames . '.'];
230 }
231 }
232 if ($image_compression && $imgConf['file'] != 'GIFBUILDER') {
233 if ($image_compression == 1) {
234 $tempImport = $imgConf['file.']['import'];
235 $tempImport_dot = $imgConf['file.']['import.'];
236 unset($imgConf['file.']);
237 $imgConf['file.']['import'] = $tempImport;
238 $imgConf['file.']['import.'] = $tempImport_dot;
239 } elseif (isset($this->cObj->image_compression[$image_compression])) {
240 $imgConf['file.']['params'] .= ' ' . $this->cObj->image_compression[$image_compression]['params'];
241 $imgConf['file.']['ext'] = $this->cObj->image_compression[$image_compression]['ext'];
242 unset($imgConf['file.']['ext.']);
243 }
244 }
245 // "alt", "title" and "longdesc" attributes:
246 if ($imgConf['altText'] === '' && !is_array($imgConf['altText.'])) {
247 $imgConf['altText'] = $conf['altText'];
248 $imgConf['altText.'] = $conf['altText.'];
249 }
250 if ($imgConf['titleText'] === '' && !is_array($imgConf['titleText.'])) {
251 $imgConf['titleText'] = $conf['titleText'];
252 $imgConf['titleText.'] = $conf['titleText.'];
253 }
254 if ($imgConf['longdescURL'] === '' && !is_array($imgConf['longdescURL.'])) {
255 $imgConf['longdescURL'] = $conf['longdescURL'];
256 $imgConf['longdescURL.'] = $conf['longdescURL.'];
257 }
258 } else {
259 $imgConf = array(
260 'altText' => $conf['altText'],
261 'titleText' => $conf['titleText'],
262 'longdescURL' => $conf['longdescURL'],
263 'file' => $totalImagePath
264 );
265 }
266 $imgsTag[$imgKey] = $this->cObj->cObjGetSingle('IMAGE', $imgConf);
267 // Store the original filepath
268 $origImages[$imgKey] = $GLOBALS['TSFE']->lastImageInfo;
269 $imageRowsFinalWidths[floor($a / $colCount)] += $GLOBALS['TSFE']->lastImageInfo[0];
270 if ($GLOBALS['TSFE']->lastImageInfo[1] > $imageRowsMaxHeights[floor($a / $colCount)]) {
271 $imageRowsMaxHeights[floor($a / $colCount)] = $GLOBALS['TSFE']->lastImageInfo[1];
272 }
273 }
274 // Calculating the tableWidth:
275 // TableWidth problems: It creates problems if the pictures are NOT as wide as the tableWidth.
276 $tableWidth = max($imageRowsFinalWidths) + $colspacing * ($colCount - 1) + $colCount * $border * $borderThickness * 2;
277 // Make table for pictures
278 $index = ($imgIndex = $imgStart);
279 $noRows = isset($conf['noRows.']) ? $this->cObj->stdWrap($conf['noRows'], $conf['noRows.']) : $conf['noRows'];
280 $noCols = isset($conf['noCols.']) ? $this->cObj->stdWrap($conf['noCols'], $conf['noCols.']) : $conf['noCols'];
281 if ($noRows) {
282 $noCols = 0;
283 }
284 // noRows overrides noCols. They cannot exist at the same time.
285 if ($equalHeight) {
286 $noCols = 1;
287 $noRows = 0;
288 }
289 $rowCount_temp = 1;
290 $colCount_temp = $colCount;
291 if ($noRows) {
292 $rowCount_temp = $rowCount;
293 $rowCount = 1;
294 }
295 if ($noCols) {
296 $colCount = 1;
297 }
298 // col- and rowspans calculated
299 $colspan = $colspacing ? $colCount * 2 - 1 : $colCount;
300 $rowspan = ($rowspacing ? $rowCount * 2 - 1 : $rowCount) + $cap;
301 // Edit icons:
302 if (!is_array($conf['editIcons.'])) {
303 $conf['editIcons.'] = array();
304 }
305 $editIconsHTML = $conf['editIcons'] && $GLOBALS['TSFE']->beUserLogin ? $this->cObj->editIcons('', $conf['editIcons'], $conf['editIcons.']) : '';
306 // Strech out table:
307 $tablecode = '';
308 $flag = 0;
309 $noStretchAndMarginCells = isset($conf['noStretchAndMarginCells.']) ? $this->cObj->stdWrap($conf['noStretchAndMarginCells'], $conf['noStretchAndMarginCells.']) : $conf['noStretchAndMarginCells'];
310 if ($noStretchAndMarginCells != 1) {
311 $tablecode .= '<tr>';
312 if ($txtMarg && $align == 'right') {
313 // If right aligned, the textborder is added on the right side
314 $tablecode .= '<td rowspan="' . ($rowspan + 1) . '" valign="top"><img src="' . $GLOBALS['TSFE']->absRefPrefix . 'clear.gif" width="' . $txtMarg . '" height="1" alt="" title="" />' . ($editIconsHTML ? '<br />' . $editIconsHTML : '') . '</td>';
315 $editIconsHTML = '';
316 $flag = 1;
317 }
318 $tablecode .= '<td colspan="' . $colspan . '"><img src="' . $GLOBALS['TSFE']->absRefPrefix . 'clear.gif" width="' . $tableWidth . '" height="1" alt="" /></td>';
319 if ($txtMarg && $align == 'left') {
320 // If left aligned, the textborder is added on the left side
321 $tablecode .= '<td rowspan="' . ($rowspan + 1) . '" valign="top"><img src="' . $GLOBALS['TSFE']->absRefPrefix . 'clear.gif" width="' . $txtMarg . '" height="1" alt="" title="" />' . ($editIconsHTML ? '<br />' . $editIconsHTML : '') . '</td>';
322 $editIconsHTML = '';
323 $flag = 1;
324 }
325 if ($flag) {
326 $tableWidth += $txtMarg + 1;
327 }
328 $tablecode .= '</tr>';
329 }
330 // draw table
331 // Looping through rows. If 'noRows' is set, this is '1 time', but $rowCount_temp will hold the actual number of rows!
332 for ($c = 0; $c < $rowCount; $c++) {
333 // If this is NOT the first time in the loop AND if space is required, a row-spacer is added. In case of "noRows" rowspacing is done further down.
334 if ($c && $rowspacing) {
335 $tablecode .= '<tr><td colspan="' . $colspan . '"><img src="' . $GLOBALS['TSFE']->absRefPrefix . 'clear.gif" width="1" height="' . $rowspacing . '"' . $this->cObj->getBorderAttr(' border="0"') . ' alt="" title="" /></td></tr>';
336 }
337 // starting row
338 $tablecode .= '<tr>';
339 // Looping through the columns
340 for ($b = 0; $b < $colCount_temp; $b++) {
341 // If this is NOT the first iteration AND if column space is required. In case of "noCols", the space is done without a separate cell.
342 if ($b && $colspacing) {
343 if (!$noCols) {
344 $tablecode .= '<td><img src="' . $GLOBALS['TSFE']->absRefPrefix . 'clear.gif" width="' . $colspacing . '" height="1"' . $this->cObj->getBorderAttr(' border="0"') . ' alt="" title="" /></td>';
345 } else {
346 $colSpacer = '<img src="' . $GLOBALS['TSFE']->absRefPrefix . 'clear.gif" width="' . ($border ? $colspacing - 6 : $colspacing) . '" height="' . ($imageRowsMaxHeights[$c] + ($border ? $borderThickness * 2 : 0)) . '"' . $this->cObj->getBorderAttr(' border="0"') . ' align="' . ($border ? 'left' : 'top') . '" alt="" title="" />';
347 $colSpacer = '<td valign="top">' . $colSpacer . '</td>';
348 // added 160301, needed for the new "noCols"-table...
349 $tablecode .= $colSpacer;
350 }
351 }
352 if (!$noCols || $noCols && !$b) {
353 // starting the cell. If "noCols" this cell will hold all images in the row, otherwise only a single image.
354 $tablecode .= '<td valign="top">';
355 if ($noCols) {
356 $tablecode .= '<table width="' . $imageRowsFinalWidths[$c] . '" border="0" cellpadding="0" cellspacing="0"><tr>';
357 }
358 }
359 // Looping through the rows IF "noRows" is set. "noRows" means that the rows of images is not rendered
360 // by physical table rows but images are all in one column and spaced apart with clear-gifs. This loop is
361 // only one time if "noRows" is not set.
362 for ($a = 0; $a < $rowCount_temp; $a++) {
363 // register previous imgIndex
364 $GLOBALS['TSFE']->register['IMAGE_NUM'] = $imgIndex;
365 $imgIndex = $index + $a * $colCount_temp;
366 $GLOBALS['TSFE']->register['IMAGE_NUM_CURRENT'] = $imgIndex;
367 if ($imgsTag[$imgIndex]) {
368 // Puts distance between the images IF "noRows" is set and this is the first iteration of the loop
369 if ($rowspacing && $noRows && $a) {
370 $tablecode .= '<img src="' . $GLOBALS['TSFE']->absRefPrefix . 'clear.gif" width="1" height="' . $rowspacing . '" alt="" title="" /><br />';
371 }
372 if ($legacyCaptionSplit) {
373 $thisCaption = $captionArray[$imgIndex];
374 } elseif (($conf['captionSplit'] || $conf['imageTextSplit']) && isset($conf['caption.'])) {
375 $thisCaption = $this->cObj->cObjGet($conf['caption.'], 'caption.');
376 $thisCaption = $this->cObj->stdWrap($thisCaption, $conf['caption.']);
377 }
378 $imageHTML = $imgsTag[$imgIndex] . '<br />';
379 // this is necessary if the tablerows are supposed to space properly together! "noRows" is excluded because else the images "layer" together.
380 $Talign = !trim($thisCaption) && !$noRows ? ' align="left"' : '';
381 if ($border) {
382 $imageHTML = '<table border="0" cellpadding="' . $borderThickness . '" cellspacing="0" bgcolor="' . $borderColor . '"' . $Talign . '><tr><td>' . $imageHTML . '</td></tr></table>';
383 }
384 $imageHTML .= $editIconsHTML;
385 $editIconsHTML = '';
386 // Adds caption.
387 $imageHTML .= $thisCaption;
388 if ($noCols) {
389 $imageHTML = '<td valign="top">' . $imageHTML . '</td>';
390 }
391 // If noCols, put in table cell.
392 $tablecode .= $imageHTML;
393 }
394 }
395 $index++;
396 if (!$noCols || $noCols && $b + 1 == $colCount_temp) {
397 if ($noCols) {
398 $tablecode .= '</tr></table>';
399 }
400 // In case of "noCols" we must finish the table that surrounds the images in the row.
401 $tablecode .= '</td>';
402 }
403 }
404 // ending row
405 $tablecode .= '</tr>';
406 }
407 if ($c) {
408 switch ($contentPosition) {
409 case '0':
410
411 case '8':
412 // below
413 switch ($align) {
414 case 'center':
415 $table_align = 'margin-left: auto; margin-right: auto';
416 break;
417 case 'right':
418 $table_align = 'margin-left: auto; margin-right: 0px';
419 break;
420 default:
421 // Most of all: left
422 $table_align = 'margin-left: 0px; margin-right: auto';
423 }
424 $table_align = 'style="' . $table_align . '"';
425 break;
426 case '16':
427 // in text
428 $table_align = 'align="' . $align . '"';
429 break;
430 default:
431 $table_align = '';
432 }
433 // Table-tag is inserted
434 $tablecode = '<table' . ($tableWidth ? ' width="' . $tableWidth . '"' : '') . ' border="0" cellspacing="0" cellpadding="0" ' . $table_align . ' class="imgtext-table">' . $tablecode;
435 // If this value is not long since reset.
436 if ($editIconsHTML) {
437 $tablecode .= '<tr><td colspan="' . $colspan . '">' . $editIconsHTML . '</td></tr>';
438 $editIconsHTML = '';
439 }
440 if ($cap) {
441 $tablecode .= '<tr><td colspan="' . $colspan . '" align="' . $caption_align . '">' . $caption . '</td></tr>';
442 }
443 $tablecode .= '</table>';
444 if (isset($conf['tableStdWrap.'])) {
445 $tablecode = $this->cObj->stdWrap($tablecode, $conf['tableStdWrap.']);
446 }
447 }
448 $spaceBelowAbove = isset($conf['spaceBelowAbove.']) ? (int)$this->cObj->stdWrap($conf['spaceBelowAbove'], $conf['spaceBelowAbove.']) : (int)$conf['spaceBelowAbove'];
449 switch ($contentPosition) {
450 case '0':
451 // above
452 $output = '<div style="text-align:' . $align . ';">' . $tablecode . '</div>' . $this->cObj->wrapSpace($content, ($spaceBelowAbove . '|0'));
453 break;
454 case '8':
455 // below
456 $output = $this->cObj->wrapSpace($content, ('0|' . $spaceBelowAbove)) . '<div style="text-align:' . $align . ';">' . $tablecode . '</div>';
457 break;
458 case '16':
459 // in text
460 $output = $tablecode . $content;
461 break;
462 case '24':
463 // in text, no wrap
464 $theResult = '';
465 $theResult .= '<table border="0" cellspacing="0" cellpadding="0" class="imgtext-nowrap"><tr>';
466 if ($align == 'right') {
467 $theResult .= '<td valign="top">' . $content . '</td><td valign="top">' . $tablecode . '</td>';
468 } else {
469 $theResult .= '<td valign="top">' . $tablecode . '</td><td valign="top">' . $content . '</td>';
470 }
471 $theResult .= '</tr></table>';
472 $output = $theResult;
473 break;
474 }
475 } else {
476 $output = $content;
477 }
478 if (isset($conf['stdWrap.'])) {
479 $output = $this->cObj->stdWrap($output, $conf['stdWrap.']);
480 }
481 return $output;
482 }
483
484 /**
485 * Loads the file reference object and sets it in the
486 * currentFile property of the ContentObjectRenderer.
487 *
488 * This makes the file data available during image rendering.
489 *
490 * @param int $fileUid The UID of the file reference that should be loaded.
491 * @return void
492 */
493 protected function setCurrentFileInContentObjectRenderer($fileUid) {
494 $imageFile = $this->getFileFactory()->getFileReferenceObject($fileUid);
495 $this->cObj->setCurrentFile($imageFile);
496 }
497
498 /**
499 * Returns the file factory.
500 *
501 * @return ResourceFactory
502 */
503 protected function getFileFactory() {
504 if ($this->fileFactory === NULL) {
505 $this->fileFactory = GeneralUtility::makeInstance(ResourceFactory::class);
506 }
507
508 return $this->fileFactory;
509 }
510 }