[TASK] Optimize invocation of cObj::checkIf
[Packages/TYPO3.CMS.git] / typo3 / sysext / frontend / Classes / ContentObject / TableRenderer.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 * Rendering of tables for content positioning
18 *
19 * @see ContentObjectRenderer::CTABLE()
20 * @author Kasper Skårhøj <kasperYYYY@typo3.com>
21 */
22 class TableRenderer {
23
24 // offset, x
25 /**
26 * @todo Define visibility
27 */
28 public $offX = 0;
29
30 // offset, y
31 /**
32 * @todo Define visibility
33 */
34 public $offY = 0;
35
36 // top menu
37 /**
38 * @todo Define visibility
39 */
40 public $tm = '';
41
42 // left menu
43 /**
44 * @todo Define visibility
45 */
46 public $lm = '';
47
48 // right menu
49 /**
50 * @todo Define visibility
51 */
52 public $rm = '';
53
54 // bottom menu
55 /**
56 * @todo Define visibility
57 */
58 public $bm = '';
59
60 // content
61 /**
62 * @todo Define visibility
63 */
64 public $content = '';
65
66 // top menu TDparams
67 /**
68 * @todo Define visibility
69 */
70 public $tmTDparams = 'valign="top"';
71
72 // left menu TDparams
73 /**
74 * @todo Define visibility
75 */
76 public $lmTDparams = 'valign="top"';
77
78 // right menu TDparams
79 /**
80 * @todo Define visibility
81 */
82 public $rmTDparams = 'valign="top"';
83
84 // bottom menu TDparams
85 /**
86 * @todo Define visibility
87 */
88 public $bmTDparams = 'valign="top"';
89
90 // content TDparams
91 /**
92 * @todo Define visibility
93 */
94 public $contentTDparams = 'valign="top"';
95
96 // content margin, left
97 /**
98 * @todo Define visibility
99 */
100 public $cMl = 1;
101
102 // content margin, right
103 /**
104 * @todo Define visibility
105 */
106 public $cMr = 1;
107
108 // content margin, top
109 /**
110 * @todo Define visibility
111 */
112 public $cMt = 0;
113
114 // content margin, bottom
115 /**
116 * @todo Define visibility
117 */
118 public $cMb = 1;
119
120 // Places a little gif-spacer in the bottom of the content frame
121 /**
122 * @todo Define visibility
123 */
124 public $contentW = 0;
125
126 /**
127 * @todo Define visibility
128 */
129 public $tableParams = 'border="0" cellspacing="0" cellpadding="0"';
130
131 /**
132 * Wrapping internal vars ->tm, ->lm, ->rm, ->bm and ->content in a table where each content part is stored in a cell.
133 * The two arguments to this function defines some offsets and margins to use in the arrangement of the content in the table.
134 *
135 * @param string $offset List of offset parameters; x,y
136 * @param string $cMargins List of margin parameters; left, top, right, bottom
137 * @return string The content strings wrapped in a <table> as the parameters defined
138 * @see \TYPO3\CMS\Frontend\ContentObject\ContentObjectRenderer::CTABLE()
139 * @todo Define visibility
140 */
141 public function start($offset, $cMargins) {
142 $offArr = \TYPO3\CMS\Core\Utility\GeneralUtility::intExplode(',', $offset);
143 $cMargArr = \TYPO3\CMS\Core\Utility\GeneralUtility::intExplode(',', $cMargins);
144 $cols = 0;
145 $rows = 0;
146 if ($this->lm) {
147 $cols++;
148 }
149 if ($this->rm) {
150 $cols++;
151 }
152 if ($cMargArr[0]) {
153 $cols++;
154 }
155 if ($cMargArr[2]) {
156 $cols++;
157 }
158 if ($cMargArr[1] || $cMargArr[3] || $this->tm || $this->bm || $this->content || $this->contentW) {
159 $cols++;
160 }
161 if ($cMargArr[1]) {
162 $rows++;
163 }
164 if ($cMargArr[3]) {
165 $rows++;
166 }
167 if ($this->tm) {
168 $rows++;
169 }
170 if ($this->bm) {
171 $rows++;
172 }
173 if ($this->content) {
174 $rows++;
175 }
176 if ($this->contentW) {
177 $rows++;
178 }
179 if (!$rows && $cols) {
180 // If there are no rows in the middle but still som columns...
181 $rows = 1;
182 }
183 if ($rows && $cols) {
184 $res = LF . '<table ' . $this->tableParams . '>';
185 // Top offset:
186 if ($offArr[1]) {
187 $xoff = $offArr[0] ? 1 : 0;
188 if ($cols + $xoff > 1) {
189 $colspan = ' colspan="' . ($cols + $xoff) . '"';
190 }
191 $res .= '<tr><td' . $colspan . '><img src="' . $GLOBALS['TSFE']->absRefPrefix . 'clear.gif" width="1" height="' . $offArr[1] . '" alt="" title="" /></td></tr>';
192 }
193 // The rows:
194 if ($rows > 1) {
195 $rowspan = ' rowspan="' . $rows . '"';
196 }
197 $res .= '<tr>';
198 if ($offArr[0]) {
199 $res .= '<td' . $rowspan . '><img src="' . $GLOBALS['TSFE']->absRefPrefix . 'clear.gif" height="1" width="' . $offArr[0] . '" alt="" title="" /></td>';
200 }
201 if ($this->lm) {
202 $res .= '<td' . $rowspan . ' ' . $this->lmTDparams . '>' . $this->lm . '</td>';
203 }
204 if ($cMargArr[0]) {
205 $res .= '<td' . $rowspan . '><img src="' . $GLOBALS['TSFE']->absRefPrefix . 'clear.gif" height="1" width="' . $cMargArr[0] . '" alt="" title="" /></td>';
206 }
207 // Content...
208 $middle = array();
209 if ($this->tm) {
210 $middle[] = '<td ' . $this->tmTDparams . '>' . $this->tm . '</td>';
211 }
212 if ($cMargArr[1]) {
213 $middle[] = '<td><img src="' . $GLOBALS['TSFE']->absRefPrefix . 'clear.gif" width="1" height="' . $cMargArr[1] . '" alt="" title="" /></td>';
214 }
215 if ($this->content) {
216 $middle[] = '<td ' . $this->contentTDparams . '>' . $this->content . '</td>';
217 }
218 if ($cMargArr[3]) {
219 $middle[] = '<td><img src="' . $GLOBALS['TSFE']->absRefPrefix . 'clear.gif" width="1" height="' . $cMargArr[3] . '" alt="" title="" /></td>';
220 }
221 if ($this->bm) {
222 $middle[] = '<td ' . $this->bmTDparams . '>' . $this->bm . '</td>';
223 }
224 if ($this->contentW) {
225 $middle[] = '<td><img src="' . $GLOBALS['TSFE']->absRefPrefix . 'clear.gif" height="1" width="' . $this->contentW . '" alt="" title="" /></td>';
226 }
227 if (isset($middle[0])) {
228 $res .= $middle[0];
229 }
230 // Left of content
231 if ($cMargArr[2]) {
232 $res .= '<td' . $rowspan . '><img src="' . $GLOBALS['TSFE']->absRefPrefix . 'clear.gif" height="1" width="' . $cMargArr[2] . '" alt="" title="" /></td>';
233 }
234 if ($this->rm) {
235 $res .= '<td' . $rowspan . ' ' . $this->rmTDparams . '>' . $this->rm . '</td>';
236 }
237 $res .= '</tr>';
238 // More than the two rows
239 $mCount = count($middle);
240 for ($a = 1; $a < $mCount; $a++) {
241 $res .= '<tr>' . $middle[$a] . '</tr>';
242 }
243 $res .= '</table>';
244 return $res;
245 }
246 }
247
248 }