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