ba30ed741c6fdaaf5d019f4afd070cfe8f1d00c3
[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 \TYPO3\CMS\Frontend\ContentObject\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 $content = '';
32 if (is_array($conf) && $this->cObj->checkIf($conf['if.'])) {
33 $tdRowCount = 0;
34 $tableParams = isset($conf['tableParams.']) ? $this->cObj->stdWrap($conf['tableParams'], $conf['tableParams.']) : $conf['tableParams'];
35 $tableParams = $tableParams ? ' ' . $tableParams : ' border="0" cellspacing="0" cellpadding="0"';
36 $TDparams = isset($conf['TDParams.']) ? $this->cObj->stdWrap($conf['TDParams'], $conf['TDParams.']) : $conf['TDParams'];
37 $TDparams = $TDparams ? ' ' . $TDparams : ' valign="top"';
38 $rows = isset($conf['rows.']) ? $this->cObj->stdWrap($conf['rows'], $conf['rows.']) : $conf['rows'];
39 $rows = \TYPO3\CMS\Core\Utility\MathUtility::forceIntegerInRange($rows, 2, 20);
40 $totalWidth = isset($conf['totalWidth.']) ? (int)$this->cObj->stdWrap($conf['totalWidth'], $conf['totalWidth.']) : (int)$conf['totalWidth'];
41 $columnWidth = 0;
42 $totalGapWidth = 0;
43 $gapData = array(
44 'gapWidth' => isset($conf['gapWidth.']) ? $this->cObj->stdWrap($conf['gapWidth'], $conf['gapWidth.']) : $conf['gapWidth'],
45 'gapBgCol' => isset($conf['gapBgCol.']) ? $this->cObj->stdWrap($conf['gapBgCol'], $conf['gapBgCol.']) : $conf['gapBgCol'],
46 'gapLineThickness' => isset($conf['gapLineThickness.']) ? $this->cObj->stdWrap($conf['gapLineThickness'], $conf['gapLineThickness.']) : $conf['gapLineThickness'],
47 'gapLineCol' => isset($conf['gapLineCol.']) ? $this->cObj->stdWrap($conf['gapLineCol'], $conf['gapLineCol.']) : $conf['gapLineCol']
48 );
49 $gapData = $GLOBALS['TSFE']->tmpl->splitConfArray($gapData, $rows - 1);
50 foreach ($gapData as $val) {
51 $totalGapWidth += (int)$val['gapWidth'];
52 }
53 if ($totalWidth) {
54 $columnWidth = ceil(($totalWidth - $totalGapWidth) / $rows);
55 $TDparams .= ' width="' . $columnWidth . '"';
56 $tableParams .= ' width="' . $totalWidth . '"';
57 } else {
58 $TDparams .= ' width="' . floor(100 / $rows) . '%"';
59 $tableParams .= ' width="100%"';
60 }
61 for ($a = 1; $a <= $rows; $a++) {
62 $tdRowCount++;
63 $content .= '<td' . $TDparams . '>';
64 $content .= $this->cObj->cObjGetSingle($conf[$a], $conf[$a . '.'], $a);
65 $content .= '</td>';
66 if ($a < $rows) {
67 $gapConf = $gapData[$a - 1];
68 $gapWidth = (int)$gapConf['gapWidth'];
69 if ($gapWidth) {
70 $tdPar = $gapConf['gapBgCol'] ? ' bgcolor="' . $gapConf['gapBgCol'] . '"' : '';
71 $gapLine = (int)$gapConf['gapLineThickness'];
72 if ($gapLine) {
73 $gapSurround = \TYPO3\CMS\Core\Utility\MathUtility::forceIntegerInRange(($gapWidth - $gapLine) / 2, 1, 1000);
74 // right gap
75 $content .= '<td' . $tdPar . '><img src="' . $GLOBALS['TSFE']->absRefPrefix . 'clear.gif" width="' . $gapSurround . '" height="1" alt="" title="" /></td>';
76 $tdRowCount++;
77 // line:
78 $GtdPar = $gapConf['gapLineCol'] ? ' bgcolor="' . $gapConf['gapLineCol'] . '"' : ' bgcolor="black"';
79 $content .= '<td' . $GtdPar . '><img src="' . $GLOBALS['TSFE']->absRefPrefix . 'clear.gif" width="' . $gapLine . '" height="1" alt="" title="" /></td>';
80 $tdRowCount++;
81 // left gap
82 $content .= '<td' . $tdPar . '><img src="' . $GLOBALS['TSFE']->absRefPrefix . 'clear.gif" width="' . $gapSurround . '" height="1" alt="" title="" /></td>';
83 $tdRowCount++;
84 } else {
85 $content .= '<td' . $tdPar . '><img src="' . $GLOBALS['TSFE']->absRefPrefix . 'clear.gif" width="' . $gapWidth . '" height="1" alt="" title="" /></td>';
86 $tdRowCount++;
87 }
88 }
89 }
90 }
91 $content = '<tr>' . $content . '</tr>';
92 $content = '<table' . $tableParams . '>' . $content . '</table>';
93 if ($conf['after'] || isset($conf['after.'])) {
94 $content .= $this->cObj->cObjGetSingle($conf['after'], $conf['after.'], 'after');
95 }
96 if (isset($conf['stdWrap.'])) {
97 $content = $this->cObj->stdWrap($content, $conf['stdWrap.']);
98 }
99 }
100 return $content;
101 }
102
103 }