[TASK] Optimize invocation of cObj::checkIf
[Packages/TYPO3.CMS.git] / typo3 / sysext / frontend / Classes / ContentObject / ColumnsContentObject.php
1 <?php
2 namespace TYPO3\CMS\Frontend\ContentObject;
3
4 /**
5 * This file is part of the TYPO3 CMS project.
6 *
7 * It is free software; you can redistribute it and/or modify it under
8 * the terms of the GNU General Public License, either version 2
9 * of the License, or any later version.
10 *
11 * For the full copyright and license information, please read the
12 * LICENSE.txt file that was distributed with this source code.
13 *
14 * The TYPO3 project - inspiring people to share!
15 */
16 /**
17 * Contains COLUMNS class object.
18 *
19 * @author Xavier Perseguers <typo3@perseguers.ch>
20 * @author Steffen Kamper <steffen@typo3.org>
21 */
22 class ColumnsContentObject extends AbstractContentObject {
23
24 /**
25 * Rendering the cObject, COLUMNS
26 *
27 * @param array $conf Array of TypoScript properties
28 * @return string Output
29 */
30 public function render($conf = array()) {
31 if (empty($conf) || !empty($conf['if.']) && !$this->cObj->checkIf($conf['if.'])) {
32 return '';
33 }
34
35 $content = '';
36
37 $tdRowCount = 0;
38 $tableParams = isset($conf['tableParams.']) ? $this->cObj->stdWrap($conf['tableParams'], $conf['tableParams.']) : $conf['tableParams'];
39 $tableParams = $tableParams ? ' ' . $tableParams : ' border="0" cellspacing="0" cellpadding="0"';
40 $TDparams = isset($conf['TDParams.']) ? $this->cObj->stdWrap($conf['TDParams'], $conf['TDParams.']) : $conf['TDParams'];
41 $TDparams = $TDparams ? ' ' . $TDparams : ' valign="top"';
42 $rows = isset($conf['rows.']) ? $this->cObj->stdWrap($conf['rows'], $conf['rows.']) : $conf['rows'];
43 $rows = \TYPO3\CMS\Core\Utility\MathUtility::forceIntegerInRange($rows, 2, 20);
44 $totalWidth = isset($conf['totalWidth.']) ? (int)$this->cObj->stdWrap($conf['totalWidth'], $conf['totalWidth.']) : (int)$conf['totalWidth'];
45 $totalGapWidth = 0;
46 $gapData = array(
47 'gapWidth' => isset($conf['gapWidth.']) ? $this->cObj->stdWrap($conf['gapWidth'], $conf['gapWidth.']) : $conf['gapWidth'],
48 'gapBgCol' => isset($conf['gapBgCol.']) ? $this->cObj->stdWrap($conf['gapBgCol'], $conf['gapBgCol.']) : $conf['gapBgCol'],
49 'gapLineThickness' => isset($conf['gapLineThickness.']) ? $this->cObj->stdWrap($conf['gapLineThickness'], $conf['gapLineThickness.']) : $conf['gapLineThickness'],
50 'gapLineCol' => isset($conf['gapLineCol.']) ? $this->cObj->stdWrap($conf['gapLineCol'], $conf['gapLineCol.']) : $conf['gapLineCol']
51 );
52 $gapData = $GLOBALS['TSFE']->tmpl->splitConfArray($gapData, $rows - 1);
53 foreach ($gapData as $val) {
54 $totalGapWidth += (int)$val['gapWidth'];
55 }
56 if ($totalWidth) {
57 $columnWidth = ceil(($totalWidth - $totalGapWidth) / $rows);
58 $TDparams .= ' width="' . $columnWidth . '"';
59 $tableParams .= ' width="' . $totalWidth . '"';
60 } else {
61 $TDparams .= ' width="' . floor(100 / $rows) . '%"';
62 $tableParams .= ' width="100%"';
63 }
64 for ($a = 1; $a <= $rows; $a++) {
65 $tdRowCount++;
66 $content .= '<td' . $TDparams . '>';
67 $content .= $this->cObj->cObjGetSingle($conf[$a], $conf[$a . '.'], $a);
68 $content .= '</td>';
69 if ($a < $rows) {
70 $gapConf = $gapData[$a - 1];
71 $gapWidth = (int)$gapConf['gapWidth'];
72 if ($gapWidth) {
73 $tdPar = $gapConf['gapBgCol'] ? ' bgcolor="' . $gapConf['gapBgCol'] . '"' : '';
74 $gapLine = (int)$gapConf['gapLineThickness'];
75 if ($gapLine) {
76 $gapSurround = \TYPO3\CMS\Core\Utility\MathUtility::forceIntegerInRange(($gapWidth - $gapLine) / 2, 1, 1000);
77 // right gap
78 $content .= '<td' . $tdPar . '><img src="' . $GLOBALS['TSFE']->absRefPrefix . 'clear.gif" width="' . $gapSurround . '" height="1" alt="" title="" /></td>';
79 $tdRowCount++;
80 // line:
81 $GtdPar = $gapConf['gapLineCol'] ? ' bgcolor="' . $gapConf['gapLineCol'] . '"' : ' bgcolor="black"';
82 $content .= '<td' . $GtdPar . '><img src="' . $GLOBALS['TSFE']->absRefPrefix . 'clear.gif" width="' . $gapLine . '" height="1" alt="" title="" /></td>';
83 $tdRowCount++;
84 // left gap
85 $content .= '<td' . $tdPar . '><img src="' . $GLOBALS['TSFE']->absRefPrefix . 'clear.gif" width="' . $gapSurround . '" height="1" alt="" title="" /></td>';
86 $tdRowCount++;
87 } else {
88 $content .= '<td' . $tdPar . '><img src="' . $GLOBALS['TSFE']->absRefPrefix . 'clear.gif" width="' . $gapWidth . '" height="1" alt="" title="" /></td>';
89 $tdRowCount++;
90 }
91 }
92 }
93 }
94 $content = '<tr>' . $content . '</tr>';
95 $content = '<table' . $tableParams . '>' . $content . '</table>';
96 if ($conf['after'] || isset($conf['after.'])) {
97 $content .= $this->cObj->cObjGetSingle($conf['after'], $conf['after.'], 'after');
98 }
99 if (isset($conf['stdWrap.'])) {
100 $content = $this->cObj->stdWrap($content, $conf['stdWrap.']);
101 }
102 return $content;
103 }
104
105 }