[TASK] Introduce Enum constants for t3ver_state
[Packages/TYPO3.CMS.git] / typo3 / sysext / frontend / Classes / ContentObject / ColumnsContentObject.php
1 <?php
2 namespace TYPO3\CMS\Frontend\ContentObject;
3
4 /***************************************************************
5 * Copyright notice
6 *
7 * (c) 2010-2013 Xavier Perseguers <typo3@perseguers.ch>
8 * (c) 2010-2013 Steffen Kamper <steffen@typo3.org>
9 * All rights reserved
10 *
11 * This script is part of the TYPO3 project. The TYPO3 project is
12 * free software; you can redistribute it and/or modify
13 * it under the terms of the GNU General Public License as published by
14 * the Free Software Foundation; either version 2 of the License, or
15 * (at your option) any later version.
16 *
17 * The GNU General Public License can be found at
18 * http://www.gnu.org/copyleft/gpl.html.
19 * A copy is found in the textfile GPL.txt and important notices to the license
20 * from the author is found in LICENSE.txt distributed with these scripts.
21 *
22 *
23 * This script is distributed in the hope that it will be useful,
24 * but WITHOUT ANY WARRANTY; without even the implied warranty of
25 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
26 * GNU General Public License for more details.
27 *
28 * This copyright notice MUST APPEAR in all copies of the script!
29 ***************************************************************/
30 /**
31 * Contains COLUMNS class object.
32 *
33 * @author Xavier Perseguers <typo3@perseguers.ch>
34 * @author Steffen Kamper <steffen@typo3.org>
35 */
36 class ColumnsContentObject extends \TYPO3\CMS\Frontend\ContentObject\AbstractContentObject {
37
38 /**
39 * Rendering the cObject, COLUMNS
40 *
41 * @param array $conf Array of TypoScript properties
42 * @return string Output
43 */
44 public function render($conf = array()) {
45 $content = '';
46 if (is_array($conf) && $this->cObj->checkIf($conf['if.'])) {
47 $tdRowCount = 0;
48 $tableParams = isset($conf['tableParams.']) ? $this->cObj->stdWrap($conf['tableParams'], $conf['tableParams.']) : $conf['tableParams'];
49 $tableParams = $tableParams ? ' ' . $tableParams : ' border="0" cellspacing="0" cellpadding="0"';
50 $TDParams = isset($conf['TDParams.']) ? $this->cObj->stdWrap($conf['TDParams'], $conf['TDParams.']) : $conf['TDParams'];
51 $TDparams = $TDparams ? ' ' . $TDparams : ' valign="top"';
52 $rows = isset($conf['rows.']) ? $this->cObj->stdWrap($conf['rows'], $conf['rows.']) : $conf['rows'];
53 $rows = \TYPO3\CMS\Core\Utility\MathUtility::forceIntegerInRange($rows, 2, 20);
54 $totalWidth = isset($conf['totalWidth.']) ? intval($this->cObj->stdWrap($conf['totalWidth'], $conf['totalWidth.'])) : intval($conf['totalWidth']);
55 $columnWidth = 0;
56 $totalGapWidth = 0;
57 $gapData = array(
58 'gapWidth' => isset($conf['gapWidth.']) ? $this->cObj->stdWrap($conf['gapWidth'], $conf['gapWidth.']) : $conf['gapWidth'],
59 'gapBgCol' => isset($conf['gapBgCol.']) ? $this->cObj->stdWrap($conf['gapBgCol'], $conf['gapBgCol.']) : $conf['gapBgCol'],
60 'gapLineThickness' => isset($conf['gapLineThickness.']) ? $this->cObj->stdWrap($conf['gapLineThickness'], $conf['gapLineThickness.']) : $conf['gapLineThickness'],
61 'gapLineCol' => isset($conf['gapLineCol.']) ? $this->cObj->stdWrap($conf['gapLineCol'], $conf['gapLineCol.']) : $conf['gapLineCol']
62 );
63 $gapData = $GLOBALS['TSFE']->tmpl->splitConfArray($gapData, $rows - 1);
64 foreach ($gapData as $val) {
65 $totalGapWidth += intval($val['gapWidth']);
66 }
67 if ($totalWidth) {
68 $columnWidth = ceil(($totalWidth - $totalGapWidth) / $rows);
69 $TDparams .= ' width="' . $columnWidth . '"';
70 $tableParams .= ' width="' . $totalWidth . '"';
71 } else {
72 $TDparams .= ' width="' . floor(100 / $rows) . '%"';
73 $tableParams .= ' width="100%"';
74 }
75 for ($a = 1; $a <= $rows; $a++) {
76 $tdRowCount++;
77 $content .= '<td' . $TDparams . '>';
78 $content .= $this->cObj->cObjGetSingle($conf[$a], $conf[$a . '.'], $a);
79 $content .= '</td>';
80 if ($a < $rows) {
81 $gapConf = $gapData[$a - 1];
82 $gapWidth = intval($gapConf['gapWidth']);
83 if ($gapWidth) {
84 $tdPar = $gapConf['gapBgCol'] ? ' bgcolor="' . $gapConf['gapBgCol'] . '"' : '';
85 $gapLine = intval($gapConf['gapLineThickness']);
86 if ($gapLine) {
87 $gapSurround = \TYPO3\CMS\Core\Utility\MathUtility::forceIntegerInRange(($gapWidth - $gapLine) / 2, 1, 1000);
88 // right gap
89 $content .= '<td' . $tdPar . '><img src="' . $GLOBALS['TSFE']->absRefPrefix . 'clear.gif" width="' . $gapSurround . '" height="1" alt="" title="" /></td>';
90 $tdRowCount++;
91 // line:
92 $GtdPar = $gapConf['gapLineCol'] ? ' bgcolor="' . $gapConf['gapLineCol'] . '"' : ' bgcolor="black"';
93 $content .= '<td' . $GtdPar . '><img src="' . $GLOBALS['TSFE']->absRefPrefix . 'clear.gif" width="' . $gapLine . '" height="1" alt="" title="" /></td>';
94 $tdRowCount++;
95 // left gap
96 $content .= '<td' . $tdPar . '><img src="' . $GLOBALS['TSFE']->absRefPrefix . 'clear.gif" width="' . $gapSurround . '" height="1" alt="" title="" /></td>';
97 $tdRowCount++;
98 } else {
99 $content .= '<td' . $tdPar . '><img src="' . $GLOBALS['TSFE']->absRefPrefix . 'clear.gif" width="' . $gapWidth . '" height="1" alt="" title="" /></td>';
100 $tdRowCount++;
101 }
102 }
103 }
104 }
105 $content = '<tr>' . $content . '</tr>';
106 $content = '<table' . $tableParams . '>' . $content . '</table>';
107 if ($conf['after'] || isset($conf['after.'])) {
108 $content .= $this->cObj->cObjGetSingle($conf['after'], $conf['after.'], 'after');
109 }
110 if (isset($conf['stdWrap.'])) {
111 $content = $this->cObj->stdWrap($content, $conf['stdWrap.']);
112 }
113 }
114 return $content;
115 }
116
117 }