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