ea9cad7dfc8384e30d3122f0ea2bffbc5ecf1812
[Packages/TYPO3.CMS.git] / typo3 / sysext / compatibility6 / Classes / ContentObject / ColumnsContentObject.php
1 <?php
2 namespace TYPO3\CMS\Compatibility6\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 /**
18 * Contains COLUMNS content object.
19 */
20 class ColumnsContentObject extends \TYPO3\CMS\Frontend\ContentObject\AbstractContentObject {
21
22 /**
23 * Rendering the cObject, COLUMNS
24 *
25 * @param array $conf Array of TypoScript properties
26 * @return string Output
27 */
28 public function render($conf = array()) {
29 if (empty($conf) || !empty($conf['if.']) && !$this->cObj->checkIf($conf['if.'])) {
30 return '';
31 }
32
33 $content = '';
34
35 $tdRowCount = 0;
36 $tableParams = isset($conf['tableParams.']) ? $this->cObj->stdWrap($conf['tableParams'], $conf['tableParams.']) : $conf['tableParams'];
37 $tableParams = $tableParams ? ' ' . $tableParams : ' border="0" cellspacing="0" cellpadding="0"';
38 $TDparams = isset($conf['TDParams.']) ? $this->cObj->stdWrap($conf['TDParams'], $conf['TDParams.']) : $conf['TDParams'];
39 $TDparams = $TDparams ? ' ' . $TDparams : ' valign="top"';
40 $rows = isset($conf['rows.']) ? $this->cObj->stdWrap($conf['rows'], $conf['rows.']) : $conf['rows'];
41 $rows = \TYPO3\CMS\Core\Utility\MathUtility::forceIntegerInRange($rows, 2, 20);
42 $totalWidth = isset($conf['totalWidth.']) ? (int)$this->cObj->stdWrap($conf['totalWidth'], $conf['totalWidth.']) : (int)$conf['totalWidth'];
43 $totalGapWidth = 0;
44 $gapData = array(
45 'gapWidth' => isset($conf['gapWidth.']) ? $this->cObj->stdWrap($conf['gapWidth'], $conf['gapWidth.']) : $conf['gapWidth'],
46 'gapBgCol' => isset($conf['gapBgCol.']) ? $this->cObj->stdWrap($conf['gapBgCol'], $conf['gapBgCol.']) : $conf['gapBgCol'],
47 'gapLineThickness' => isset($conf['gapLineThickness.']) ? $this->cObj->stdWrap($conf['gapLineThickness'], $conf['gapLineThickness.']) : $conf['gapLineThickness'],
48 'gapLineCol' => isset($conf['gapLineCol.']) ? $this->cObj->stdWrap($conf['gapLineCol'], $conf['gapLineCol.']) : $conf['gapLineCol']
49 );
50 $gapData = $GLOBALS['TSFE']->tmpl->splitConfArray($gapData, $rows - 1);
51 foreach ($gapData as $val) {
52 $totalGapWidth += (int)$val['gapWidth'];
53 }
54 if ($totalWidth) {
55 $columnWidth = ceil(($totalWidth - $totalGapWidth) / $rows);
56 $TDparams .= ' width="' . $columnWidth . '"';
57 $tableParams .= ' width="' . $totalWidth . '"';
58 } else {
59 $TDparams .= ' width="' . floor(100 / $rows) . '%"';
60 $tableParams .= ' width="100%"';
61 }
62 for ($a = 1; $a <= $rows; $a++) {
63 $tdRowCount++;
64 $content .= '<td' . $TDparams . '>';
65 $content .= $this->cObj->cObjGetSingle($conf[$a], $conf[$a . '.'], $a);
66 $content .= '</td>';
67 if ($a < $rows) {
68 $gapConf = $gapData[$a - 1];
69 $gapWidth = (int)$gapConf['gapWidth'];
70 if ($gapWidth) {
71 $tdPar = $gapConf['gapBgCol'] ? ' bgcolor="' . $gapConf['gapBgCol'] . '"' : '';
72 $gapLine = (int)$gapConf['gapLineThickness'];
73 if ($gapLine) {
74 $gapSurround = \TYPO3\CMS\Core\Utility\MathUtility::forceIntegerInRange(($gapWidth - $gapLine) / 2, 1, 1000);
75 // right gap
76 $content .= '<td' . $tdPar . '><img src="' . $GLOBALS['TSFE']->absRefPrefix . 'clear.gif" width="' . $gapSurround . '" height="1" alt="" title="" /></td>';
77 $tdRowCount++;
78 // line:
79 $GtdPar = $gapConf['gapLineCol'] ? ' bgcolor="' . $gapConf['gapLineCol'] . '"' : ' bgcolor="black"';
80 $content .= '<td' . $GtdPar . '><img src="' . $GLOBALS['TSFE']->absRefPrefix . 'clear.gif" width="' . $gapLine . '" height="1" alt="" title="" /></td>';
81 $tdRowCount++;
82 // left gap
83 $content .= '<td' . $tdPar . '><img src="' . $GLOBALS['TSFE']->absRefPrefix . 'clear.gif" width="' . $gapSurround . '" height="1" alt="" title="" /></td>';
84 $tdRowCount++;
85 } else {
86 $content .= '<td' . $tdPar . '><img src="' . $GLOBALS['TSFE']->absRefPrefix . 'clear.gif" width="' . $gapWidth . '" height="1" alt="" title="" /></td>';
87 $tdRowCount++;
88 }
89 }
90 }
91 }
92 $content = '<tr>' . $content . '</tr>';
93 $content = '<table' . $tableParams . '>' . $content . '</table>';
94 if ($conf['after'] || isset($conf['after.'])) {
95 $content .= $this->cObj->cObjGetSingle($conf['after'], $conf['after.'], 'after');
96 }
97 if (isset($conf['stdWrap.'])) {
98 $content = $this->cObj->stdWrap($content, $conf['stdWrap.']);
99 }
100 return $content;
101 }
102
103 }