[BUGFIX] fallbackRendering is always called
[Packages/TYPO3.CMS.git] / typo3 / sysext / css_styled_content / Classes / Controller / CssStyledContentController.php
1 <?php
2 namespace TYPO3\CMS\CssStyledContent\Controller;
3
4 /***************************************************************
5 * Copyright notice
6 *
7 * (c) 1999-2013 Kasper Skårhøj (kasperYYYY@typo3.com)
8 * All rights reserved
9 *
10 * This script is part of the TYPO3 project. The TYPO3 project is
11 * free software; you can redistribute it and/or modify
12 * it under the terms of the GNU General Public License as published by
13 * the Free Software Foundation; either version 2 of the License, or
14 * (at your option) any later version.
15 *
16 * The GNU General Public License can be found at
17 * http://www.gnu.org/copyleft/gpl.html.
18 * A copy is found in the textfile GPL.txt and important notices to the license
19 * from the author is found in LICENSE.txt distributed with these scripts.
20 *
21 *
22 * This script is distributed in the hope that it will be useful,
23 * but WITHOUT ANY WARRANTY; without even the implied warranty of
24 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
25 * GNU General Public License for more details.
26 *
27 * This copyright notice MUST APPEAR in all copies of the script!
28 ***************************************************************/
29
30 /**
31 * Plugin class - instantiated from TypoScript.
32 * Rendering some content elements from tt_content table.
33 *
34 * @author Kasper Skårhøj <kasperYYYY@typo3.com>
35 */
36 class CssStyledContentController extends \TYPO3\CMS\Frontend\Plugin\AbstractPlugin {
37
38 /**
39 * Same as class name
40 *
41 * @todo Define visibility
42 */
43 public $prefixId = 'tx_cssstyledcontent_pi1';
44
45 /**
46 * Path to this script relative to the extension dir.
47 *
48 * @todo Define visibility
49 */
50 public $scriptRelPath = 'pi1/class.tx_cssstyledcontent_pi1.php';
51
52 /**
53 * The extension key
54 *
55 * @todo Define visibility
56 */
57 public $extKey = 'css_styled_content';
58
59 /**
60 * @todo Define visibility
61 */
62 public $conf = array();
63
64 /***********************************
65 * Rendering of Content Elements:
66 ***********************************/
67
68 /**
69 * Rendering the "Bulletlist" type content element, called from TypoScript (tt_content.bullets.20)
70 *
71 * @param string $content Content input. Not used, ignore.
72 * @param array $conf TypoScript configuration
73 * @return string HTML output.
74 */
75 public function render_bullets($content, $conf) {
76 // Look for hook before running default code for function
77 if ($hookObj = $this->hookRequest('render_bullets')) {
78 return $hookObj->render_bullets($content, $conf);
79 } else {
80 // Get bodytext field content, returning blank if empty:
81 $field = isset($conf['field']) && trim($conf['field']) ? trim($conf['field']) : 'bodytext';
82 $content = trim($this->cObj->data[$field]);
83 if (!strcmp($content, '')) {
84 return '';
85 }
86 // Split into single lines:
87 $lines = \TYPO3\CMS\Core\Utility\GeneralUtility::trimExplode(LF, $content);
88 foreach ($lines as &$val) {
89 $val = '<li>' . $this->cObj->stdWrap($val, $conf['innerStdWrap.']) . '</li>';
90 }
91 unset($val);
92 // Set header type:
93 $type = intval($this->cObj->data['layout']);
94 // Compile list:
95 $out = '
96 <ul class="csc-bulletlist csc-bulletlist-' . $type . '">' . implode('', $lines) . '
97 </ul>';
98 // Calling stdWrap:
99 if ($conf['stdWrap.']) {
100 $out = $this->cObj->stdWrap($out, $conf['stdWrap.']);
101 }
102 // Return value
103 return $out;
104 }
105 }
106
107 /**
108 * Rendering the "Table" type content element, called from TypoScript (tt_content.table.20)
109 *
110 * @param string $content Content input. Not used, ignore.
111 * @param array $conf TypoScript configuration
112 * @return string HTML output.
113 */
114 public function render_table($content, $conf) {
115 // Look for hook before running default code for function
116 if ($hookObj = $this->hookRequest('render_table')) {
117 return $hookObj->render_table($content, $conf);
118 } else {
119 // Init FlexForm configuration
120 $this->pi_initPIflexForm();
121 // Get bodytext field content
122 $field = isset($conf['field']) && trim($conf['field']) ? trim($conf['field']) : 'bodytext';
123 $content = trim($this->cObj->data[$field]);
124 if (!strcmp($content, '')) {
125 return '';
126 }
127 // get flexform values
128 $caption = trim(htmlspecialchars($this->pi_getFFvalue($this->cObj->data['pi_flexform'], 'acctables_caption')));
129 $useTfoot = trim($this->pi_getFFvalue($this->cObj->data['pi_flexform'], 'acctables_tfoot'));
130 $headerPos = $this->pi_getFFvalue($this->cObj->data['pi_flexform'], 'acctables_headerpos');
131 $noStyles = $this->pi_getFFvalue($this->cObj->data['pi_flexform'], 'acctables_nostyles');
132 $tableClass = $this->pi_getFFvalue($this->cObj->data['pi_flexform'], 'acctables_tableclass');
133 $delimiter = trim($this->pi_getFFvalue($this->cObj->data['pi_flexform'], 'tableparsing_delimiter', 's_parsing'));
134 if ($delimiter) {
135 $delimiter = chr(intval($delimiter));
136 } else {
137 $delimiter = '|';
138 }
139 $quotedInput = trim($this->pi_getFFvalue($this->cObj->data['pi_flexform'], 'tableparsing_quote', 's_parsing'));
140 if ($quotedInput) {
141 $quotedInput = chr(intval($quotedInput));
142 } else {
143 $quotedInput = '';
144 }
145 // Generate id prefix for accessible header
146 $headerScope = $headerPos == 'top' ? 'col' : 'row';
147 $headerIdPrefix = $headerScope . $this->cObj->data['uid'] . '-';
148 // Split into single lines (will become table-rows):
149 $rows = \TYPO3\CMS\Core\Utility\GeneralUtility::trimExplode(LF, $content);
150 reset($rows);
151 // Find number of columns to render:
152 $cols = \TYPO3\CMS\Core\Utility\MathUtility::forceIntegerInRange($this->cObj->data['cols'] ? $this->cObj->data['cols'] : count(explode($delimiter, current($rows))), 0, 100);
153 // Traverse rows (rendering the table here)
154 $rCount = count($rows);
155 foreach ($rows as $k => $v) {
156 $cells = explode($delimiter, $v);
157 $newCells = array();
158 for ($a = 0; $a < $cols; $a++) {
159 // Remove quotes if needed
160 if ($quotedInput && substr($cells[$a], 0, 1) == $quotedInput && substr($cells[$a], -1, 1) == $quotedInput) {
161 $cells[$a] = substr($cells[$a], 1, -1);
162 }
163 if (!strcmp(trim($cells[$a]), '')) {
164 $cells[$a] = '&nbsp;';
165 }
166 $cellAttribs = $noStyles ? '' : ($a > 0 && $cols - 1 == $a ? ' class="td-last td-' . $a . '"' : ' class="td-' . $a . '"');
167 if ($headerPos == 'top' && !$k || $headerPos == 'left' && !$a) {
168 $scope = ' scope="' . $headerScope . '"';
169 $scope .= ' id="' . $headerIdPrefix . ($headerScope == 'col' ? $a : $k) . '"';
170 $newCells[$a] = '
171 <th' . $cellAttribs . $scope . '>' . $this->cObj->stdWrap($cells[$a], $conf['innerStdWrap.']) . '</th>';
172 } else {
173 if (empty($headerPos)) {
174 $accessibleHeader = '';
175 } else {
176 $accessibleHeader = ' headers="' . $headerIdPrefix . ($headerScope == 'col' ? $a : $k) . '"';
177 }
178 $newCells[$a] = '
179 <td' . $cellAttribs . $accessibleHeader . '>' . $this->cObj->stdWrap($cells[$a], $conf['innerStdWrap.']) . '</td>';
180 }
181 }
182 if (!$noStyles) {
183 $oddEven = $k % 2 ? 'tr-odd' : 'tr-even';
184 $rowAttribs = $k > 0 && $rCount - 1 == $k ? ' class="' . $oddEven . ' tr-last"' : ' class="' . $oddEven . ' tr-' . $k . '"';
185 }
186 $rows[$k] = '
187 <tr' . $rowAttribs . '>' . implode('', $newCells) . '
188 </tr>';
189 }
190 $addTbody = 0;
191 $tableContents = '';
192 if ($caption) {
193 $tableContents .= '
194 <caption>' . $caption . '</caption>';
195 }
196 if ($headerPos == 'top' && $rows[0]) {
197 $tableContents .= '<thead>' . $rows[0] . '
198 </thead>';
199 unset($rows[0]);
200 $addTbody = 1;
201 }
202 if ($useTfoot) {
203 $tableContents .= '
204 <tfoot>' . $rows[($rCount - 1)] . '</tfoot>';
205 unset($rows[$rCount - 1]);
206 $addTbody = 1;
207 }
208 $tmpTable = implode('', $rows);
209 if ($addTbody) {
210 $tmpTable = '<tbody>' . $tmpTable . '</tbody>';
211 }
212 $tableContents .= $tmpTable;
213 // Set header type:
214 $type = intval($this->cObj->data['layout']);
215 // Table tag params.
216 $tableTagParams = $this->getTableAttributes($conf, $type);
217 if (!$noStyles) {
218 $tableTagParams['class'] = 'contenttable contenttable-' . $type . ($tableClass ? ' ' . $tableClass : '') . $tableTagParams['class'];
219 } elseif ($tableClass) {
220 $tableTagParams['class'] = $tableClass;
221 }
222 // Compile table output:
223 $out = '
224 <table ' . \TYPO3\CMS\Core\Utility\GeneralUtility::implodeAttributes($tableTagParams) . '>' . $tableContents . '
225 </table>';
226 // Calling stdWrap:
227 if ($conf['stdWrap.']) {
228 $out = $this->cObj->stdWrap($out, $conf['stdWrap.']);
229 }
230 // Return value
231 return $out;
232 }
233 }
234
235 /**
236 * Rendering the "Filelinks" type content element, called from TypoScript (tt_content.uploads.20)
237 *
238 * @param string $content Content input. Not used, ignore.
239 * @param array $conf TypoScript configuration
240 * @return string HTML output.
241 */
242 public function render_uploads($content, $conf) {
243 // Look for hook before running default code for function
244 if ($hookObj = $this->hookRequest('render_uploads')) {
245 return $hookObj->render_uploads($content, $conf);
246 } else {
247 // Loading language-labels
248 $this->pi_loadLL();
249 $out = '';
250 // Set layout type:
251 $type = intval($this->cObj->data['layout']);
252 // See if the file path variable is set, this takes precedence
253 $filePathConf = $this->cObj->stdWrap($conf['filePath'], $conf['filePath.']);
254 if ($filePathConf) {
255 $fileList = $this->cObj->filelist($filePathConf);
256 list($path) = explode('|', $filePathConf);
257 } else {
258 // Get the list of files from the field
259 $field = trim($conf['field']) ? trim($conf['field']) : 'media';
260 $fileList = $this->cObj->data[$field];
261 $path = 'uploads/media/';
262 if (is_array($GLOBALS['TCA']['tt_content']['columns'][$field]) && !empty($GLOBALS['TCA']['tt_content']['columns'][$field]['config']['uploadfolder'])) {
263 // In TCA-Array folders are saved without trailing slash, so $path.$fileName won't work
264 $path = $GLOBALS['TCA']['tt_content']['columns'][$field]['config']['uploadfolder'] . '/';
265 }
266 }
267 $path = trim($path);
268 // Explode into an array:
269 $fileArray = \TYPO3\CMS\Core\Utility\GeneralUtility::trimExplode(',', $fileList, 1);
270 // If there were files to list...:
271 if (count($fileArray)) {
272 // Get the descriptions for the files (if any):
273 $descriptions = \TYPO3\CMS\Core\Utility\GeneralUtility::trimExplode(LF, $this->cObj->data['imagecaption']);
274 // Get the titles for the files (if any)
275 $titles = \TYPO3\CMS\Core\Utility\GeneralUtility::trimExplode(LF, $this->cObj->data['titleText']);
276 // Get the alternative text for icons/thumbnails
277 $altTexts = \TYPO3\CMS\Core\Utility\GeneralUtility::trimExplode(LF, $this->cObj->data['altText']);
278 // Add the target to linkProc when explicitly set
279 if ($this->cObj->data['target']) {
280 $conf['linkProc.']['target'] = $this->cObj->data['target'];
281 unset($conf['linkProc.']['target.']);
282 }
283 // Adding hardcoded TS to linkProc configuration:
284 $conf['linkProc.']['path.']['current'] = 1;
285 if ($conf['linkProc.']['combinedLink']) {
286 $conf['linkProc.']['icon'] = $type > 0 ? 1 : 0;
287 } else {
288 // Always render icon - is inserted by PHP if needed.
289 $conf['linkProc.']['icon'] = 1;
290 // Temporary, internal split-token!
291 $conf['linkProc.']['icon.']['wrap'] = ' | //**//';
292 // ALways link the icon
293 $conf['linkProc.']['icon_link'] = 1;
294 }
295 $conf['linkProc.']['icon_image_ext_list'] = $type == 2 || $type == 3 ? $GLOBALS['TYPO3_CONF_VARS']['GFX']['imagefile_ext'] : '';
296 // If the layout is type 2 or 3 we will render an image based icon if possible.
297 if ($conf['labelStdWrap.']) {
298 $conf['linkProc.']['labelStdWrap.'] = $conf['labelStdWrap.'];
299 }
300 if ($conf['useSpacesInLinkText'] || $conf['stripFileExtensionFromLinkText']) {
301 $conf['linkProc.']['removePrependedNumbers'] = 0;
302 }
303 // Traverse the files found:
304 $filesData = array();
305 foreach ($fileArray as $key => $fileName) {
306 $absPath = \TYPO3\CMS\Core\Utility\GeneralUtility::getFileAbsFileName(\TYPO3\CMS\Core\Utility\GeneralUtility::resolveBackPath($path . $fileName));
307 if (@is_file($absPath)) {
308 $fI = pathinfo($fileName);
309 $filesData[$key] = array();
310 $currentPath = $path;
311 if (\TYPO3\CMS\Core\Utility\GeneralUtility::isFirstPartOfStr($fileName, '../../')) {
312 $currentPath = '';
313 $fileName = substr($fileName, 6);
314 }
315 $filesData[$key]['filename'] = $fileName;
316 $filesData[$key]['path'] = $currentPath;
317 $filesData[$key]['filesize'] = filesize($absPath);
318 $filesData[$key]['fileextension'] = strtolower($fI['extension']);
319 $filesData[$key]['description'] = trim($descriptions[$key]);
320 $conf['linkProc.']['title'] = trim($titles[$key]);
321 if (isset($altTexts[$key]) && !empty($altTexts[$key])) {
322 $altText = trim($altTexts[$key]);
323 } else {
324 $altText = sprintf($this->pi_getLL('uploads.icon'), $fileName);
325 }
326 $conf['linkProc.']['altText'] = ($conf['linkProc.']['iconCObject.']['altText'] = $altText);
327 $this->cObj->setCurrentVal($currentPath);
328 $GLOBALS['TSFE']->register['ICON_REL_PATH'] = $currentPath . $fileName;
329 $GLOBALS['TSFE']->register['filename'] = $filesData[$key]['filename'];
330 $GLOBALS['TSFE']->register['path'] = $filesData[$key]['path'];
331 $GLOBALS['TSFE']->register['fileSize'] = $filesData[$key]['filesize'];
332 $GLOBALS['TSFE']->register['fileExtension'] = $filesData[$key]['fileextension'];
333 $GLOBALS['TSFE']->register['description'] = $filesData[$key]['description'];
334 $filesData[$key]['linkedFilenameParts'] = $this->beautifyFileLink(explode('//**//', $this->cObj->filelink($fileName, $conf['linkProc.'])), $fileName, $conf['useSpacesInLinkText'], $conf['stripFileExtensionFromLinkText']);
335 }
336 }
337 // optionSplit applied to conf to allow differnt settings per file
338 $splitConf = $GLOBALS['TSFE']->tmpl->splitConfArray($conf, count($filesData));
339 // Now, lets render the list!
340 $outputEntries = array();
341 foreach ($filesData as $key => $fileData) {
342 $GLOBALS['TSFE']->register['linkedIcon'] = $fileData['linkedFilenameParts'][0];
343 $GLOBALS['TSFE']->register['linkedLabel'] = $fileData['linkedFilenameParts'][1];
344 $GLOBALS['TSFE']->register['filename'] = $fileData['filename'];
345 $GLOBALS['TSFE']->register['path'] = $fileData['path'];
346 $GLOBALS['TSFE']->register['description'] = $fileData['description'];
347 $GLOBALS['TSFE']->register['fileSize'] = $fileData['filesize'];
348 $GLOBALS['TSFE']->register['fileExtension'] = $fileData['fileextension'];
349 $outputEntries[] = $this->cObj->cObjGetSingle($splitConf[$key]['itemRendering'], $splitConf[$key]['itemRendering.']);
350 }
351 if (isset($conf['outerWrap'])) {
352 // Wrap around the whole content
353 $outerWrap = $this->cObj->stdWrap($conf['outerWrap'], $conf['outerWrap.']);
354 } else {
355 // Table tag params
356 $tableTagParams = $this->getTableAttributes($conf, $type);
357 $tableTagParams['class'] = 'csc-uploads csc-uploads-' . $type;
358 $outerWrap = '<table ' . \TYPO3\CMS\Core\Utility\GeneralUtility::implodeAttributes($tableTagParams) . '>|</table>';
359 }
360 // Compile it all into table tags:
361 $out = $this->cObj->wrap(implode('', $outputEntries), $outerWrap);
362 }
363 // Calling stdWrap:
364 if ($conf['stdWrap.']) {
365 $out = $this->cObj->stdWrap($out, $conf['stdWrap.']);
366 }
367 // Return value
368 return $out;
369 }
370 }
371
372 /**
373 * Returns an array containing width relations for $colCount columns.
374 *
375 * Tries to use "colRelations" setting given by TS.
376 * uses "1:1" column relations by default.
377 *
378 * @param array $conf TS configuration for img
379 * @param integer $colCount number of columns
380 * @return array
381 */
382 protected function getImgColumnRelations($conf, $colCount) {
383 $relations = array();
384 $equalRelations = array_fill(0, $colCount, 1);
385 $colRelationsTypoScript = trim($this->cObj->stdWrap($conf['colRelations'], $conf['colRelations.']));
386 if ($colRelationsTypoScript) {
387 // Try to use column width relations given by TS
388 $relationParts = explode(':', $colRelationsTypoScript);
389 // Enough columns defined?
390 if (count($relationParts) >= $colCount) {
391 $out = array();
392 for ($a = 0; $a < $colCount; $a++) {
393 $currentRelationValue = intval($relationParts[$a]);
394 if ($currentRelationValue >= 1) {
395 $out[$a] = $currentRelationValue;
396 } else {
397 \TYPO3\CMS\Core\Utility\GeneralUtility::devLog('colRelations used with a value smaller than 1 therefore colRelations setting is ignored.', $this->extKey, 2);
398 unset($out);
399 break;
400 }
401 }
402 if (max($out) / min($out) <= 10) {
403 $relations = $out;
404 } else {
405 \TYPO3\CMS\Core\Utility\GeneralUtility::devLog('The difference in size between the largest and smallest colRelation was not within a factor of ten therefore colRelations setting is ignored..', $this->extKey, 2);
406 }
407 }
408 }
409 return $relations ? $relations : $equalRelations;
410 }
411
412 /**
413 * Returns an array containing the image widths for an image row with $colCount columns.
414 *
415 * @param array $conf TS configuration of img
416 * @param integer $colCount number of columns
417 * @param integer $netW max usable width for images (without spaces and borders)
418 * @return array
419 */
420 protected function getImgColumnWidths($conf, $colCount, $netW) {
421 $columnWidths = array();
422 $colRelations = $this->getImgColumnRelations($conf, $colCount);
423 $accumWidth = 0;
424 $accumDesiredWidth = 0;
425 $relUnitCount = array_sum($colRelations);
426 for ($a = 0; $a < $colCount; $a++) {
427 // This much width is available for the remaining images in this row (int)
428 $availableWidth = $netW - $accumWidth;
429 // Theoretical width of resized image. (float)
430 $desiredWidth = $netW / $relUnitCount * $colRelations[$a];
431 // Add this width. $accumDesiredWidth becomes the desired horizontal position
432 $accumDesiredWidth += $desiredWidth;
433 // Calculate width by comparing actual and desired horizontal position.
434 // this evenly distributes rounding errors across all images in this row.
435 $suggestedWidth = round($accumDesiredWidth - $accumWidth);
436 // finalImgWidth may not exceed $availableWidth
437 $finalImgWidth = (int) min($availableWidth, $suggestedWidth);
438 $accumWidth += $finalImgWidth;
439 $columnWidths[$a] = $finalImgWidth;
440 }
441 return $columnWidths;
442 }
443
444 /**
445 * Rendering the IMGTEXT content element, called from TypoScript (tt_content.textpic.20)
446 *
447 * @param string $content Content input. Not used, ignore.
448 * @param array $conf TypoScript configuration. See TSRef "IMGTEXT". This function aims to be compatible.
449 * @return string HTML output.
450 * @coauthor Ernesto Baschny <ernst@cron-it.de>
451 * @coauthor Patrick Broens <patrick@patrickbroens.nl>
452 */
453 public function render_textpic($content, $conf) {
454 // Look for hook before running default code for function
455 if (method_exists($this, 'hookRequest') && ($hookObj = $this->hookRequest('render_textpic'))) {
456 return $hookObj->render_textpic($content, $conf);
457 }
458 $renderMethod = $this->cObj->stdWrap($conf['renderMethod'], $conf['renderMethod.']);
459 // Render using the default IMGTEXT code (table-based)
460 if (!$renderMethod || $renderMethod == 'table') {
461 return $this->cObj->IMGTEXT($conf);
462 }
463 // Specific configuration for the chosen rendering method
464 if (is_array($conf['rendering.'][$renderMethod . '.'])) {
465 $conf = $this->cObj->joinTSarrays($conf, $conf['rendering.'][$renderMethod . '.']);
466 }
467 // Image or Text with Image?
468 if (is_array($conf['text.'])) {
469 $content = $this->cObj->stdWrap($this->cObj->cObjGet($conf['text.'], 'text.'), $conf['text.']);
470 }
471 $imgList = trim($this->cObj->stdWrap($conf['imgList'], $conf['imgList.']));
472 if (!$imgList) {
473 // No images, that's easy
474 if (is_array($conf['stdWrap.'])) {
475 return $this->cObj->stdWrap($content, $conf['stdWrap.']);
476 }
477 return $content;
478 }
479 $imgs = \TYPO3\CMS\Core\Utility\GeneralUtility::trimExplode(',', $imgList);
480 $imgStart = intval($this->cObj->stdWrap($conf['imgStart'], $conf['imgStart.']));
481 $imgCount = count($imgs) - $imgStart;
482 $imgMax = intval($this->cObj->stdWrap($conf['imgMax'], $conf['imgMax.']));
483 if ($imgMax) {
484 $imgCount = \TYPO3\CMS\Core\Utility\MathUtility::forceIntegerInRange($imgCount, 0, $imgMax);
485 }
486 $imgPath = $this->cObj->stdWrap($conf['imgPath'], $conf['imgPath.']);
487 // Does we need to render a "global caption" (below the whole image block)?
488 $renderGlobalCaption = !$conf['captionSplit'] && !$conf['imageTextSplit'] && is_array($conf['caption.']);
489 if ($imgCount == 1) {
490 // If we just have one image, the caption relates to the image, so it is not "global"
491 $renderGlobalCaption = FALSE;
492 }
493 // Use the calculated information (amount of images, if global caption is wanted) to choose a different rendering method for the images-block
494 $GLOBALS['TSFE']->register['imageCount'] = $imgCount;
495 $GLOBALS['TSFE']->register['renderGlobalCaption'] = $renderGlobalCaption;
496 if ($conf['fallbackRendering']) {
497 $fallbackRenderMethod = $this->cObj->cObjGetSingle($conf['fallbackRendering'], $conf['fallbackRendering.']);
498 }
499 if ($fallbackRenderMethod && is_array($conf['rendering.'][$fallbackRenderMethod . '.'])) {
500 $conf = $this->cObj->joinTSarrays($conf, $conf['rendering.'][$fallbackRenderMethod . '.']);
501 }
502 // Set the accessibility mode which uses a different type of markup, used 4.7+
503 $accessibilityMode = FALSE;
504 if (strpos(strtolower($renderMethod), 'caption') || strpos(strtolower($fallbackRenderMethod), 'caption')) {
505 $accessibilityMode = TRUE;
506 }
507 // Global caption
508 $globalCaption = '';
509 if ($renderGlobalCaption) {
510 $globalCaption = $this->cObj->stdWrap($this->cObj->cObjGet($conf['caption.'], 'caption.'), $conf['caption.']);
511 }
512 // Positioning
513 $position = $this->cObj->stdWrap($conf['textPos'], $conf['textPos.']);
514 // 0,1,2 = center,right,left
515 $imagePosition = $position & 7;
516 // 0,8,16,24 (above,below,intext,intext-wrap)
517 $contentPosition = $position & 24;
518 $textMargin = intval($this->cObj->stdWrap($conf['textMargin'], $conf['textMargin.']));
519 if (!$conf['textMargin_outOfText'] && $contentPosition < 16) {
520 $textMargin = 0;
521 }
522 $colspacing = intval($this->cObj->stdWrap($conf['colSpace'], $conf['colSpace.']));
523 $border = intval($this->cObj->stdWrap($conf['border'], $conf['border.'])) ? 1 : 0;
524 $borderThickness = intval($this->cObj->stdWrap($conf['borderThick'], $conf['borderThick.']));
525 $borderThickness = $borderThickness ? $borderThickness : 1;
526 $borderSpace = $conf['borderSpace'] && $border ? intval($conf['borderSpace']) : 0;
527 // Generate cols
528 $cols = intval($this->cObj->stdWrap($conf['cols'], $conf['cols.']));
529 $colCount = $cols > 1 ? $cols : 1;
530 if ($colCount > $imgCount) {
531 $colCount = $imgCount;
532 }
533 $rowCount = ceil($imgCount / $colCount);
534 // Generate rows
535 $rows = intval($this->cObj->stdWrap($conf['rows'], $conf['rows.']));
536 if ($rows > 1) {
537 $rowCount = $rows;
538 if ($rowCount > $imgCount) {
539 $rowCount = $imgCount;
540 }
541 $colCount = $rowCount > 1 ? ceil($imgCount / $rowCount) : $imgCount;
542 }
543 // Max Width
544 $maxW = intval($this->cObj->stdWrap($conf['maxW'], $conf['maxW.']));
545 $maxWInText = intval($this->cObj->stdWrap($conf['maxWInText'], $conf['maxWInText.']));
546 $fiftyPercentWidthInText = round($maxW / 100 * 50);
547 // in Text
548 if ($contentPosition >= 16) {
549 if (!$maxWInText) {
550 // If maxWInText is not set, it's calculated to the 50% of the max
551 $maxW = $fiftyPercentWidthInText;
552 } else {
553 $maxW = $maxWInText;
554 }
555 }
556 // max usuable width for images (without spacers and borders)
557 $netW = $maxW - $colspacing * ($colCount - 1) - $colCount * $border * ($borderThickness + $borderSpace) * 2;
558 // Specify the maximum width for each column
559 $columnWidths = $this->getImgColumnWidths($conf, $colCount, $netW);
560 $image_compression = intval($this->cObj->stdWrap($conf['image_compression'], $conf['image_compression.']));
561 $image_effects = intval($this->cObj->stdWrap($conf['image_effects'], $conf['image_effects.']));
562 $image_frames = intval($this->cObj->stdWrap($conf['image_frames.']['key'], $conf['image_frames.']['key.']));
563 // EqualHeight
564 $equalHeight = intval($this->cObj->stdWrap($conf['equalH'], $conf['equalH.']));
565 if ($equalHeight) {
566 // Initiate gifbuilder object in order to get dimensions AND calculate the imageWidth's
567 $gifCreator = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance('TYPO3\\CMS\\Frontend\\Imaging\\GifBuilder');
568 $gifCreator->init();
569 $relations_cols = array();
570 // contains the individual width of all images after scaling to $equalHeight
571 $imgWidths = array();
572 for ($a = 0; $a < $imgCount; $a++) {
573 $imgKey = $a + $imgStart;
574 $imgInfo = $gifCreator->getImageDimensions($imgPath . $imgs[$imgKey]);
575 // relationship between the original height and the wished height
576 $rel = $imgInfo[1] / $equalHeight;
577 // if relations is zero, then the addition of this value is omitted as the image is not expected to display because of some error.
578 if ($rel) {
579 $imgWidths[$a] = $imgInfo[0] / $rel;
580 // counts the total width of the row with the new height taken into consideration.
581 $relations_cols[floor($a / $colCount)] += $imgWidths[$a];
582 }
583 }
584 }
585 // Fetches pictures
586 $splitArr = array();
587 $splitArr['imgObjNum'] = $conf['imgObjNum'];
588 $splitArr = $GLOBALS['TSFE']->tmpl->splitConfArray($splitArr, $imgCount);
589 // Contains the width of every image row
590 $imageRowsFinalWidths = array();
591 // Array index of $imgsTag will be the same as in $imgs, but $imgsTag only contains the images that are actually shown
592 $imgsTag = array();
593 $origImages = array();
594 $rowIdx = 0;
595 for ($a = 0; $a < $imgCount; $a++) {
596 $imgKey = $a + $imgStart;
597 // if the image cannot be interpreted as integer (therefore filename and no FAL id), add the image path
598 if (\TYPO3\CMS\Core\Utility\MathUtility::canBeInterpretedAsInteger($imgs[$imgKey])) {
599 $totalImagePath = intval($imgs[$imgKey]);
600 } else {
601 $totalImagePath = $imgPath . $imgs[$imgKey];
602 }
603 // register IMG_NUM is kept for backwards compatibility
604 $GLOBALS['TSFE']->register['IMAGE_NUM'] = $imgKey;
605 $GLOBALS['TSFE']->register['IMAGE_NUM_CURRENT'] = $imgKey;
606 $GLOBALS['TSFE']->register['ORIG_FILENAME'] = $totalImagePath;
607 $this->cObj->data[$this->cObj->currentValKey] = $totalImagePath;
608 $imgObjNum = intval($splitArr[$a]['imgObjNum']);
609 $imgConf = $conf[$imgObjNum . '.'];
610 if ($equalHeight) {
611 if ($a % $colCount == 0) {
612 // A new row starts
613 // Reset accumulated net width
614 $accumWidth = 0;
615 // Reset accumulated desired width
616 $accumDesiredWidth = 0;
617 $rowTotalMaxW = $relations_cols[$rowIdx];
618 if ($rowTotalMaxW > $netW && $netW > 0) {
619 $scale = $rowTotalMaxW / $netW;
620 } else {
621 $scale = 1;
622 }
623 $desiredHeight = $equalHeight / $scale;
624 $rowIdx++;
625 }
626 // This much width is available for the remaining images in this row (int)
627 $availableWidth = $netW - $accumWidth;
628 // Theoretical width of resized image. (float)
629 $desiredWidth = $imgWidths[$a] / $scale;
630 // Add this width. $accumDesiredWidth becomes the desired horizontal position
631 $accumDesiredWidth += $desiredWidth;
632 // Calculate width by comparing actual and desired horizontal position.
633 // this evenly distributes rounding errors across all images in this row.
634 $suggestedWidth = round($accumDesiredWidth - $accumWidth);
635 // finalImgWidth may not exceed $availableWidth
636 $finalImgWidth = (int) min($availableWidth, $suggestedWidth);
637 $accumWidth += $finalImgWidth;
638 $imgConf['file.']['width'] = $finalImgWidth;
639 $imgConf['file.']['height'] = round($desiredHeight);
640 // other stuff will be calculated accordingly:
641 unset($imgConf['file.']['maxW']);
642 unset($imgConf['file.']['maxH']);
643 unset($imgConf['file.']['minW']);
644 unset($imgConf['file.']['minH']);
645 unset($imgConf['file.']['width.']);
646 unset($imgConf['file.']['maxW.']);
647 unset($imgConf['file.']['maxH.']);
648 unset($imgConf['file.']['minW.']);
649 unset($imgConf['file.']['minH.']);
650 } else {
651 $imgConf['file.']['maxW'] = $columnWidths[$a % $colCount];
652 }
653 $titleInLink = $this->cObj->stdWrap($imgConf['titleInLink'], $imgConf['titleInLink.']);
654 $titleInLinkAndImg = $this->cObj->stdWrap($imgConf['titleInLinkAndImg'], $imgConf['titleInLinkAndImg.']);
655 $oldATagParms = $GLOBALS['TSFE']->ATagParams;
656 if ($titleInLink) {
657 // Title in A-tag instead of IMG-tag
658 $titleText = trim($this->cObj->stdWrap($imgConf['titleText'], $imgConf['titleText.']));
659 if ($titleText) {
660 // This will be used by the IMAGE call later:
661 $GLOBALS['TSFE']->ATagParams .= ' title="' . $titleText . '"';
662 }
663 }
664 if ($imgConf || $imgConf['file']) {
665 if ($this->cObj->image_effects[$image_effects]) {
666 $imgConf['file.']['params'] .= ' ' . $this->cObj->image_effects[$image_effects];
667 }
668 if ($image_frames) {
669 if (is_array($conf['image_frames.'][$image_frames . '.'])) {
670 $imgConf['file.']['m.'] = $conf['image_frames.'][$image_frames . '.'];
671 }
672 }
673 if ($image_compression && $imgConf['file'] != 'GIFBUILDER') {
674 if ($image_compression == 1) {
675 $tempImport = $imgConf['file.']['import'];
676 $tempImport_dot = $imgConf['file.']['import.'];
677 unset($imgConf['file.']);
678 $imgConf['file.']['import'] = $tempImport;
679 $imgConf['file.']['import.'] = $tempImport_dot;
680 } elseif (isset($this->cObj->image_compression[$image_compression])) {
681 $imgConf['file.']['params'] .= ' ' . $this->cObj->image_compression[$image_compression]['params'];
682 $imgConf['file.']['ext'] = $this->cObj->image_compression[$image_compression]['ext'];
683 unset($imgConf['file.']['ext.']);
684 }
685 }
686 if ($titleInLink && !$titleInLinkAndImg) {
687 // Check if the image will be linked
688 $link = $this->cObj->imageLinkWrap('', $totalImagePath, $imgConf['imageLinkWrap.']);
689 if ($link) {
690 // Title in A-tag only (set above: ATagParams), not in IMG-tag
691 unset($imgConf['titleText']);
692 unset($imgConf['titleText.']);
693 $imgConf['emptyTitleHandling'] = 'removeAttr';
694 }
695 }
696 $imgsTag[$imgKey] = $this->cObj->IMAGE($imgConf);
697 } else {
698 // currentValKey !!!
699 $imgsTag[$imgKey] = $this->cObj->IMAGE(array('file' => $totalImagePath));
700 }
701 // Restore our ATagParams
702 $GLOBALS['TSFE']->ATagParams = $oldATagParms;
703 // Store the original filepath
704 $origImages[$imgKey] = $GLOBALS['TSFE']->lastImageInfo;
705 if ($GLOBALS['TSFE']->lastImageInfo[0] == 0) {
706 $imageRowsFinalWidths[floor($a / $colCount)] += $this->cObj->data['imagewidth'];
707 } else {
708 $imageRowsFinalWidths[floor($a / $colCount)] += $GLOBALS['TSFE']->lastImageInfo[0];
709 }
710 }
711 // How much space will the image-block occupy?
712 $imageBlockWidth = max($imageRowsFinalWidths) + $colspacing * ($colCount - 1) + $colCount * $border * ($borderSpace + $borderThickness) * 2;
713 $GLOBALS['TSFE']->register['rowwidth'] = $imageBlockWidth;
714 $GLOBALS['TSFE']->register['rowWidthPlusTextMargin'] = $imageBlockWidth + $textMargin;
715 // noRows is in fact just one ROW, with the amount of columns specified, where the images are placed in.
716 // noCols is just one COLUMN, each images placed side by side on each row
717 $noRows = $this->cObj->stdWrap($conf['noRows'], $conf['noRows.']);
718 $noCols = $this->cObj->stdWrap($conf['noCols'], $conf['noCols.']);
719 // noRows overrides noCols. They cannot exist at the same time.
720 if ($noRows) {
721 $noCols = 0;
722 $rowCount = 1;
723 }
724 if ($noCols) {
725 $colCount = 1;
726 }
727 // Edit icons:
728 if (!is_array($conf['editIcons.'])) {
729 $conf['editIcons.'] = array();
730 }
731 $editIconsHTML = $conf['editIcons'] && $GLOBALS['TSFE']->beUserLogin ? $this->cObj->editIcons('', $conf['editIcons'], $conf['editIcons.']) : '';
732 // If noRows, we need multiple imagecolumn wraps
733 $imageWrapCols = 1;
734 if ($noRows) {
735 $imageWrapCols = $colCount;
736 }
737 // User wants to separate the rows, but only do that if we do have rows
738 $separateRows = $this->cObj->stdWrap($conf['separateRows'], $conf['separateRows.']);
739 if ($noRows) {
740 $separateRows = 0;
741 }
742 if ($rowCount == 1) {
743 $separateRows = 0;
744 }
745 if ($accessibilityMode) {
746 $imagesInColumns = round($imgCount / ($rowCount * $colCount), 0, PHP_ROUND_HALF_UP);
747 // Apply optionSplit to the list of classes that we want to add to each column
748 $addClassesCol = $conf['addClassesCol'];
749 if (isset($conf['addClassesCol.'])) {
750 $addClassesCol = $this->cObj->stdWrap($addClassesCol, $conf['addClassesCol.']);
751 }
752 $addClassesColConf = $GLOBALS['TSFE']->tmpl->splitConfArray(array('addClassesCol' => $addClassesCol), $colCount);
753 // Apply optionSplit to the list of classes that we want to add to each image
754 $addClassesImage = $conf['addClassesImage'];
755 if (isset($conf['addClassesImage.'])) {
756 $addClassesImage = $this->cObj->stdWrap($addClassesImage, $conf['addClassesImage.']);
757 }
758 $addClassesImageConf = $GLOBALS['TSFE']->tmpl->splitConfArray(array('addClassesImage' => $addClassesImage), $imagesInColumns);
759 $rows = array();
760 $currentImage = 0;
761 // Set the class for the caption (split or global)
762 $classCaptionAlign = array(
763 'center' => 'csc-textpic-caption-c',
764 'right' => 'csc-textpic-caption-r',
765 'left' => 'csc-textpic-caption-l'
766 );
767 $captionAlign = $this->cObj->stdWrap($conf['captionAlign'], $conf['captionAlign.']);
768 // Iterate over the rows
769 for ($rowCounter = 1; $rowCounter <= $rowCount; $rowCounter++) {
770 $rowColumns = array();
771 // Iterate over the columns
772 for ($columnCounter = 1; $columnCounter <= $colCount; $columnCounter++) {
773 $columnImages = array();
774 // Iterate over the amount of images allowed in a column
775 for ($imagesCounter = 1; $imagesCounter <= $imagesInColumns; $imagesCounter++) {
776 $image = NULL;
777 $splitCaption = NULL;
778 $imageMarkers = ($captionMarkers = array());
779 $single = '&nbsp;';
780 // Set the key of the current image
781 $imageKey = $currentImage + $imgStart;
782 // Register IMAGE_NUM_CURRENT for the caption
783 $GLOBALS['TSFE']->register['IMAGE_NUM_CURRENT'] = $imageKey;
784 $this->cObj->data[$this->cObj->currentValKey] = $origImages[$imageKey]['origFile'];
785 // Get the image if not an empty cell
786 if (isset($imgsTag[$imageKey])) {
787 $image = $this->cObj->stdWrap($imgsTag[$imageKey], $conf['imgTagStdWrap.']);
788 // Add the edit icons
789 if ($editIconsHTML) {
790 $image .= $this->cObj->stdWrap($editIconsHTML, $conf['editIconsStdWrap.']);
791 }
792 // Wrap the single image
793 $single = $this->cObj->stdWrap($image, $conf['singleStdWrap.']);
794 // Get the caption
795 if (!$renderGlobalCaption) {
796 $imageMarkers['caption'] = $this->cObj->stdWrap($this->cObj->cObjGet($conf['caption.'], 'caption.'), $conf['caption.']);
797 if ($captionAlign) {
798 $captionMarkers['classes'] = ' ' . $classCaptionAlign[$captionAlign];
799 }
800 $imageMarkers['caption'] = $this->cObj->substituteMarkerArray($imageMarkers['caption'], $captionMarkers, '###|###', 1, 1);
801 }
802 if ($addClassesImageConf[$imagesCounter - 1]['addClassesImage']) {
803 $imageMarkers['classes'] = ' ' . $addClassesImageConf[($imagesCounter - 1)]['addClassesImage'];
804 }
805 }
806 $columnImages[] = $this->cObj->substituteMarkerArray($single, $imageMarkers, '###|###', 1, 1);
807 $currentImage++;
808 }
809 $rowColumn = $this->cObj->stdWrap(implode(LF, $columnImages), $conf['columnStdWrap.']);
810 // Start filling the markers for columnStdWrap
811 $columnMarkers = array();
812 if ($addClassesColConf[$columnCounter - 1]['addClassesCol']) {
813 $columnMarkers['classes'] = ' ' . $addClassesColConf[($columnCounter - 1)]['addClassesCol'];
814 }
815 $rowColumns[] = $this->cObj->substituteMarkerArray($rowColumn, $columnMarkers, '###|###', 1, 1);
816 }
817 if ($noRows) {
818 $rowConfiguration = $conf['noRowsStdWrap.'];
819 } elseif ($rowCounter == $rowCount) {
820 $rowConfiguration = $conf['lastRowStdWrap.'];
821 } else {
822 $rowConfiguration = $conf['rowStdWrap.'];
823 }
824 $row = $this->cObj->stdWrap(implode(LF, $rowColumns), $rowConfiguration);
825 // Start filling the markers for columnStdWrap
826 $rowMarkers = array();
827 $rows[] = $this->cObj->substituteMarkerArray($row, $rowMarkers, '###|###', 1, 1);
828 }
829 $images = $this->cObj->stdWrap(implode(LF, $rows), $conf['allStdWrap.']);
830 // Start filling the markers for allStdWrap
831 $allMarkers = array();
832 $classes = array();
833 // Add the global caption to the allStdWrap marker array if set
834 if ($globalCaption) {
835 $allMarkers['caption'] = $globalCaption;
836 if ($captionAlign) {
837 $classes[] = $classCaptionAlign[$captionAlign];
838 }
839 }
840 // Set the margin for image + text, no wrap always to avoid multiple stylesheets
841 $noWrapMargin = (int) (($maxWInText ? $maxWInText : $fiftyPercentWidthInText) + intval($this->cObj->stdWrap($conf['textMargin'], $conf['textMargin.'])));
842 $this->addPageStyle('.csc-textpic-intext-right-nowrap .csc-textpic-text', 'margin-right: ' . $noWrapMargin . 'px;');
843 $this->addPageStyle('.csc-textpic-intext-left-nowrap .csc-textpic-text', 'margin-left: ' . $noWrapMargin . 'px;');
844 // Beside Text where the image block width is not equal to maxW
845 if ($contentPosition == 24 && $maxW != $imageBlockWidth) {
846 $noWrapMargin = $imageBlockWidth + $textMargin;
847 // Beside Text, Right
848 if ($imagePosition == 1) {
849 $this->addPageStyle('.csc-textpic-intext-right-nowrap-' . $noWrapMargin . ' .csc-textpic-text', 'margin-right: ' . $noWrapMargin . 'px;');
850 $classes[] = 'csc-textpic-intext-right-nowrap-' . $noWrapMargin;
851 } elseif ($imagePosition == 2) {
852 $this->addPageStyle('.csc-textpic-intext-left-nowrap-' . $noWrapMargin . ' .csc-textpic-text', 'margin-left: ' . $noWrapMargin . 'px;');
853 $classes[] = 'csc-textpic-intext-left-nowrap-' . $noWrapMargin;
854 }
855 }
856 // Add the border class if needed
857 if ($border) {
858 $classes[] = $conf['borderClass'] ? $conf['borderClass'] : 'csc-textpic-border';
859 }
860 // Add the class for equal height if needed
861 if ($equalHeight) {
862 $classes[] = 'csc-textpic-equalheight';
863 }
864 $addClasses = $this->cObj->stdWrap($conf['addClasses'], $conf['addClasses.']);
865 if ($addClasses) {
866 $classes[] = $addClasses;
867 }
868 if ($classes) {
869 $class = ' ' . implode(' ', $classes);
870 }
871 // Fill the markers for the allStdWrap
872 $images = $this->cObj->substituteMarkerArray($images, $allMarkers, '###|###', 1, 1);
873 } else {
874 // Apply optionSplit to the list of classes that we want to add to each image
875 $addClassesImage = $conf['addClassesImage'];
876 if (isset($conf['addClassesImage.'])) {
877 $addClassesImage = $this->cObj->stdWrap($addClassesImage, $conf['addClassesImage.']);
878 }
879 $addClassesImageConf = $GLOBALS['TSFE']->tmpl->splitConfArray(array('addClassesImage' => $addClassesImage), $colCount);
880 // Render the images
881 $images = '';
882 for ($c = 0; $c < $imageWrapCols; $c++) {
883 $tmpColspacing = $colspacing;
884 if ($c == $imageWrapCols - 1 && $imagePosition == 2 || $c == 0 && ($imagePosition == 1 || $imagePosition == 0)) {
885 // Do not add spacing after column if we are first column (left) or last column (center/right)
886 $tmpColspacing = 0;
887 }
888 $thisImages = '';
889 $allRows = '';
890 $maxImageSpace = 0;
891 $imgsTagCount = count($imgsTag);
892 for ($i = $c; $i < $imgsTagCount; $i = $i + $imageWrapCols) {
893 $imgKey = $i + $imgStart;
894 $colPos = $i % $colCount;
895 if ($separateRows && $colPos == 0) {
896 $thisRow = '';
897 }
898 // Render one image
899 if ($origImages[$imgKey][0] == 0) {
900 $imageSpace = $this->cObj->data['imagewidth'] + $border * ($borderSpace + $borderThickness) * 2;
901 } else {
902 $imageSpace = $origImages[$imgKey][0] + $border * ($borderSpace + $borderThickness) * 2;
903 }
904 $GLOBALS['TSFE']->register['IMAGE_NUM'] = $imgKey;
905 $GLOBALS['TSFE']->register['IMAGE_NUM_CURRENT'] = $imgKey;
906 $GLOBALS['TSFE']->register['ORIG_FILENAME'] = $origImages[$imgKey]['origFile'];
907 $GLOBALS['TSFE']->register['imagewidth'] = $origImages[$imgKey][0];
908 $GLOBALS['TSFE']->register['imagespace'] = $imageSpace;
909 $GLOBALS['TSFE']->register['imageheight'] = $origImages[$imgKey][1];
910 if ($imageSpace > $maxImageSpace) {
911 $maxImageSpace = $imageSpace;
912 }
913 $thisImage = '';
914 $thisImage .= $this->cObj->stdWrap($imgsTag[$imgKey], $conf['imgTagStdWrap.']);
915 if (!$renderGlobalCaption) {
916 $thisImage .= $this->cObj->stdWrap($this->cObj->cObjGet($conf['caption.'], 'caption.'), $conf['caption.']);
917 }
918 if ($editIconsHTML) {
919 $thisImage .= $this->cObj->stdWrap($editIconsHTML, $conf['editIconsStdWrap.']);
920 }
921 $thisImage = $this->cObj->stdWrap($thisImage, $conf['oneImageStdWrap.']);
922 $classes = '';
923 if ($addClassesImageConf[$colPos]['addClassesImage']) {
924 $classes = ' ' . $addClassesImageConf[$colPos]['addClassesImage'];
925 }
926 $thisImage = str_replace('###CLASSES###', $classes, $thisImage);
927 if ($separateRows) {
928 $thisRow .= $thisImage;
929 } else {
930 $allRows .= $thisImage;
931 }
932 $GLOBALS['TSFE']->register['columnwidth'] = $maxImageSpace + $tmpColspacing;
933 // Close this row at the end (colCount), or the last row at the final end
934 if ($separateRows && $i + 1 == count($imgsTag)) {
935 // Close the very last row with either normal configuration or lastRow stdWrap
936 $allRows .= $this->cObj->stdWrap($thisRow, is_array($conf['imageLastRowStdWrap.']) ? $conf['imageLastRowStdWrap.'] : $conf['imageRowStdWrap.']);
937 } elseif ($separateRows && $colPos == $colCount - 1) {
938 $allRows .= $this->cObj->stdWrap($thisRow, $conf['imageRowStdWrap.']);
939 }
940 }
941 if ($separateRows) {
942 $thisImages .= $allRows;
943 } else {
944 $thisImages .= $this->cObj->stdWrap($allRows, $conf['noRowsStdWrap.']);
945 }
946 if ($noRows) {
947 // Only needed to make columns, rather than rows:
948 $images .= $this->cObj->stdWrap($thisImages, $conf['imageColumnStdWrap.']);
949 } else {
950 $images .= $thisImages;
951 }
952 }
953 // Add the global caption, if not split
954 if ($globalCaption) {
955 $images .= $globalCaption;
956 }
957 // CSS-classes
958 $captionClass = '';
959 $classCaptionAlign = array(
960 'center' => 'csc-textpic-caption-c',
961 'right' => 'csc-textpic-caption-r',
962 'left' => 'csc-textpic-caption-l'
963 );
964 $captionAlign = $this->cObj->stdWrap($conf['captionAlign'], $conf['captionAlign.']);
965 if ($captionAlign) {
966 $captionClass = $classCaptionAlign[$captionAlign];
967 }
968 $borderClass = '';
969 if ($border) {
970 $borderClass = $conf['borderClass'] ? $conf['borderClass'] : 'csc-textpic-border';
971 }
972 // Multiple classes with all properties, to be styled in CSS
973 $class = '';
974 $class .= $borderClass ? ' ' . $borderClass : '';
975 $class .= $captionClass ? ' ' . $captionClass : '';
976 $class .= $equalHeight ? ' csc-textpic-equalheight' : '';
977 $addClasses = $this->cObj->stdWrap($conf['addClasses'], $conf['addClasses.']);
978 $class .= $addClasses ? ' ' . $addClasses : '';
979 // Do we need a width in our wrap around images?
980 $imgWrapWidth = '';
981 if ($position == 0 || $position == 8) {
982 // For 'center' we always need a width: without one, the margin:auto trick won't work
983 $imgWrapWidth = $imageBlockWidth;
984 }
985 if ($rowCount > 1) {
986 // For multiple rows we also need a width, so that the images will wrap
987 $imgWrapWidth = $imageBlockWidth;
988 }
989 if ($globalCaption) {
990 // If we have a global caption, we need the width so that the caption will wrap
991 $imgWrapWidth = $imageBlockWidth;
992 }
993 // Wrap around the whole image block
994 $GLOBALS['TSFE']->register['totalwidth'] = $imgWrapWidth;
995 if ($imgWrapWidth) {
996 $images = $this->cObj->stdWrap($images, $conf['imageStdWrap.']);
997 } else {
998 $images = $this->cObj->stdWrap($images, $conf['imageStdWrapNoWidth.']);
999 }
1000 }
1001 $output = $this->cObj->cObjGetSingle($conf['layout'], $conf['layout.']);
1002 $output = str_replace('###TEXT###', $content, $output);
1003 $output = str_replace('###IMAGES###', $images, $output);
1004 $output = str_replace('###CLASSES###', $class, $output);
1005 if ($conf['stdWrap.']) {
1006 $output = $this->cObj->stdWrap($output, $conf['stdWrap.']);
1007 }
1008 return $output;
1009 }
1010
1011 /***********************************
1012 * Rendering of Content Element properties
1013 ***********************************/
1014
1015 /**
1016 * Add top or bottom margin to the content element
1017 *
1018 * Constructs and adds a class to the content element. This class selector
1019 * and its declaration are added to the specific page styles.
1020 *
1021 * @param string $content Content input. Not used, ignore.
1022 * @param array $configuration TypoScript configuration
1023 * @return string The class name
1024 */
1025 public function renderSpace($content, array $configuration) {
1026 // Look for hook before running default code for function
1027 if (method_exists($this, 'hookRequest') && ($hookObject = $this->hookRequest('renderSpace'))) {
1028 return $hookObject->renderSpace($content, $configuration);
1029 }
1030 if (isset($configuration['space']) && in_array($configuration['space'], array('before', 'after'))) {
1031 $constant = (int) $configuration['constant'];
1032 if ($configuration['space'] === 'before') {
1033 $value = $constant + $this->cObj->data['spaceBefore'];
1034 $declaration = 'margin-top: ' . $value . 'px;';
1035 } else {
1036 $value = $constant + $this->cObj->data['spaceAfter'];
1037 $declaration = 'margin-bottom: ' . $value . 'px;';
1038 }
1039 if (!empty($value)) {
1040 if ($configuration['classStdWrap.']) {
1041 $className = $this->cObj->stdWrap($value, $configuration['classStdWrap.']);
1042 } else {
1043 $className = $value;
1044 }
1045 $selector = '.' . trim($className);
1046 $this->addPageStyle($selector, $declaration);
1047 return $className;
1048 }
1049 }
1050 }
1051
1052 /************************************
1053 * Helper functions
1054 ************************************/
1055
1056 /**
1057 * Returns a link text string which replaces underscores in filename with
1058 * blanks.
1059 *
1060 * Has the possibility to cut off FileType.
1061 *
1062 * @param array $links
1063 * @param string $fileName
1064 * @param boolean $useSpaces
1065 * @param boolean $cutFileExtension
1066 * @return array modified array with new link text
1067 */
1068 protected function beautifyFileLink(array $links, $fileName, $useSpaces = FALSE, $cutFileExtension = FALSE) {
1069 $linkText = $fileName;
1070 if ($useSpaces) {
1071 $linkText = str_replace('_', ' ', $linkText);
1072 }
1073 if ($cutFileExtension) {
1074 $pos = strrpos($linkText, '.');
1075 $linkText = substr($linkText, 0, $pos);
1076 }
1077 $links[1] = str_replace('>' . $fileName . '<', '>' . htmlspecialchars($linkText) . '<', $links[1]);
1078 return $links;
1079 }
1080
1081 /**
1082 * Returns table attributes for uploads / tables.
1083 *
1084 * @param array $conf TypoScript configuration array
1085 * @param integer $type The "layout" type
1086 * @return array Array with attributes inside.
1087 * @todo Define visibility
1088 */
1089 public function getTableAttributes($conf, $type) {
1090 // Initializing:
1091 $tableTagParams_conf = $conf['tableParams_' . $type . '.'];
1092 $border = $this->cObj->data['table_border'] ? intval($this->cObj->data['table_border']) : $tableTagParams_conf['border'];
1093 $cellSpacing = $this->cObj->data['table_cellspacing'] ? intval($this->cObj->data['table_cellspacing']) : $tableTagParams_conf['cellspacing'];
1094 $cellPadding = $this->cObj->data['table_cellpadding'] ? intval($this->cObj->data['table_cellpadding']) : $tableTagParams_conf['cellpadding'];
1095 $summary = trim(htmlspecialchars($this->pi_getFFvalue($this->cObj->data['pi_flexform'], 'acctables_summary')));
1096 // Create table attributes and classes array:
1097 $tableTagParams = ($classes = array());
1098 // Table attributes for all doctypes except HTML5
1099 if ($GLOBALS['TSFE']->config['config']['doctype'] !== 'html5') {
1100 $tableTagParams['border'] = $border;
1101 $tableTagParams['cellspacing'] = $cellSpacing;
1102 $tableTagParams['cellpadding'] = $cellPadding;
1103 if ($summary) {
1104 $tableTagParams['summary'] = $summary;
1105 }
1106 } else {
1107 if ($border) {
1108 // Border property has changed, now with class
1109 $borderClass = 'contenttable-border-' . $border;
1110 $borderDeclaration = 'border-width: ' . $border . 'px; border-style: solid;';
1111 $this->addPageStyle('.' . $borderClass, $borderDeclaration);
1112 $classes[] = $borderClass;
1113 }
1114 if ($cellSpacing) {
1115 // Border attribute for HTML5 is 1 when there is cell spacing
1116 $tableTagParams['border'] = 1;
1117 // Use CSS3 border-spacing in class to have cell spacing
1118 $cellSpacingClass = 'contenttable-cellspacing-' . $cellSpacing;
1119 $cellSpacingDeclaration = 'border-spacing: ' . $cellSpacing . 'px;';
1120 $this->addPageStyle('.' . $cellSpacingClass, $cellSpacingDeclaration);
1121 $classes[] = $cellSpacingClass;
1122 }
1123 if ($cellPadding) {
1124 // Cell padding property has changed, now with class
1125 $cellPaddingClass = 'contenttable-cellpadding-' . $cellPadding;
1126 $cellSpacingSelector = '.' . $cellPaddingClass . ' td, .' . $cellPaddingClass . ' th';
1127 $cellPaddingDeclaration = 'padding: ' . $cellPadding . 'px;';
1128 $this->addPageStyle($cellSpacingSelector, $cellPaddingDeclaration);
1129 $classes[] = $cellPaddingClass;
1130 }
1131 }
1132 // Background color is class
1133 if (isset($conf['color.'][$this->cObj->data['table_bgColor']]) && !empty($conf['color.'][$this->cObj->data['table_bgColor']])) {
1134 $classes[] = 'contenttable-color-' . $this->cObj->data['table_bgColor'];
1135 }
1136 if (!empty($classes)) {
1137 $tableTagParams['class'] = ' ' . implode(' ', $classes);
1138 }
1139 // Return result:
1140 return $tableTagParams;
1141 }
1142
1143 /**
1144 * Add a style to the page, specific for this page
1145 *
1146 * The selector can be a contextual selector, like '#id .class p'
1147 * The presence of the selector is checked to avoid multiple entries of the
1148 * same selector.
1149 *
1150 * @param string $selector The selector
1151 * @param string $declaration The declaration
1152 * @return void
1153 */
1154 protected function addPageStyle($selector, $declaration) {
1155 if (!isset($GLOBALS['TSFE']->tmpl->setup['plugin.']['tx_cssstyledcontent.']['_CSS_PAGE_STYLE'])) {
1156 $GLOBALS['TSFE']->tmpl->setup['plugin.']['tx_cssstyledcontent.']['_CSS_PAGE_STYLE'] = array();
1157 }
1158 if (!isset($GLOBALS['TSFE']->tmpl->setup['plugin.']['tx_cssstyledcontent.']['_CSS_PAGE_STYLE'][$selector])) {
1159 $GLOBALS['TSFE']->tmpl->setup['plugin.']['tx_cssstyledcontent.']['_CSS_PAGE_STYLE'][$selector] = TAB . $selector . ' { ' . $declaration . ' }';
1160 }
1161 }
1162
1163 /**
1164 * Returns an object reference to the hook object if any
1165 *
1166 * @param string $functionName Name of the function you want to call / hook key
1167 * @return object Hook object, if any. Otherwise NULL.
1168 * @todo Define visibility
1169 */
1170 public function hookRequest($functionName) {
1171 global $TYPO3_CONF_VARS;
1172 // Hook: menuConfig_preProcessModMenu
1173 if ($TYPO3_CONF_VARS['EXTCONF']['css_styled_content']['pi1_hooks'][$functionName]) {
1174 $hookObj = \TYPO3\CMS\Core\Utility\GeneralUtility::getUserObj($TYPO3_CONF_VARS['EXTCONF']['css_styled_content']['pi1_hooks'][$functionName]);
1175 if (method_exists($hookObj, $functionName)) {
1176 $hookObj->pObj = $this;
1177 return $hookObj;
1178 }
1179 }
1180 }
1181
1182 }
1183 ?>