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