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