[TASK] Get rid of "clear.gif" usages
[Packages/TYPO3.CMS.git] / typo3 / sysext / compatibility6 / Classes / ContentObject / OffsetTableContentObject.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 * Rendering of tables for offset
19 */
20 class OffsetTableContentObject extends \TYPO3\CMS\Frontend\ContentObject\AbstractContentObject {
21
22 /**
23 * @var string
24 */
25 public $tableParams = 'border="0" cellspacing="0" cellpadding="0"';
26
27 /**
28 * @var string
29 */
30 public $default_tableParams = 'border="0" cellspacing="0" cellpadding="0"';
31
32 /**
33 * @var string
34 */
35 public $tdParams = ' width="99%" valign="top"';
36
37 /**
38 * Override default constructor to make it possible to instantiate this
39 * class for rendering an offset table not in content object context
40 *
41 * @param \TYPO3\CMS\Frontend\ContentObject\ContentObjectRenderer $cObj
42 */
43 public function __construct(\TYPO3\CMS\Frontend\ContentObject\ContentObjectRenderer $cObj = NULL) {
44 if (!is_null($cObj)) {
45 $this->cObj = $cObj;
46 }
47 }
48
49 /**
50 * Rendering the cObject, OTABLE
51 *
52 * @param array $conf Array of TypoScript properties
53 * @return string Output
54 */
55 public function render($conf = array()) {
56 $tableParams = isset($conf['tableParams.']) ? $this->cObj->stdWrap($conf['tableParams'], $conf['tableParams.']) : $conf['tableParams'];
57 if ($tableParams) {
58 $this->tableParams = $tableParams;
59 }
60 $offset = isset($conf['offset.']) ? $this->cObj->stdWrap($conf['offset'], $conf['offset.']) : $conf['offset'];
61 $content = $this->start($this->cObj->cObjGet($conf), $offset);
62 if (isset($conf['stdWrap.'])) {
63 $content = $this->cObj->stdWrap($content, $conf['stdWrap.']);
64 }
65 return $content;
66 }
67
68 /**
69 * Wrapping the input content string in a table which will space it out from top/left/right/bottom
70 *
71 * @param string $content The HTML content string
72 * @param string $offset List of offset parameters; x,y,r,b,w,h
73 * @return string The HTML content string being wrapped in a <table> offsetting the content as the $offset parameters defined
74 */
75 public function start($content, $offset) {
76 $valPairs = \TYPO3\CMS\Core\Utility\GeneralUtility::intExplode(',', $offset . ',,,,,');
77 if ($valPairs[0] || $valPairs[1] || $valPairs[2] || $valPairs[3] || $valPairs[4] || $valPairs[5]) {
78 // If width is defined AND there has been no change to the default table params,
79 // then extend them to a tablewidth of 1
80 if ($valPairs[4] && $this->default_tableParams == $this->tableParams) {
81 $this->tableParams .= ' width="1"';
82 }
83 // Init:
84 $this->begin = LF . '<table ' . $this->tableParams . '>';
85 $this->end = '</table>';
86 $rows = array();
87 $widthImg = '';
88 $heightImg = '';
89 // If width is required, set so bottom column will display for sure
90 if ($valPairs[4]) {
91 if (!$valPairs[3]) {
92 $valPairs[3] = 1;
93 }
94 $widthImg = '<span style="width: ' . $valPairs[4] . 'px; height: 1px;"></span>';
95
96 }
97 // If height is required, set so right column will display for sure
98 if ($valPairs[5]) {
99 if (!$valPairs[2]) {
100 $valPairs[2] = 1;
101 }
102 $valPairs[2] = 1;
103 $heightImg = '<span style="width: 1px; height: ' . $valPairs[5] . 'px;"></span>';
104 }
105 // First row:
106 // top
107 if ($valPairs[1]) {
108 $rows[1] .= '<tr>';
109 $rows[1] .= '<td><span style="width: ' . ($valPairs[0] ?: 1) . 'px; height: ' . $valPairs[1] . 'px;"></span></td>';
110 if ($valPairs[0]) {
111 $rows[1] .= '<td></td>';
112 }
113 if ($valPairs[2]) {
114 $rows[1] .= '<td></td>';
115 }
116 $rows[1] .= '</tr>';
117 }
118 // Middle row:
119 $rows[2] .= '<tr>';
120 if ($valPairs[0]) {
121 $rows[2] .= $valPairs[1] ? '<td></td>' : '<td><span style="width: ' . $valPairs[0] . 'px; height: 1px;"></span></td>';
122 }
123 $rows[2] .= '<td' . $this->tdParams . '>' . $content . '</td>';
124 if ($valPairs[2]) {
125 $rows[2] .= $valPairs[3] ? '<td>' . $heightImg . '</td>' : '<td><span style="width: ' . $valPairs[2] . 'px; height: ' . ($valPairs[5] ?: 1) . 'px;"></span></td>';
126 }
127 $rows[2] .= '</tr>';
128 // Bottom row:
129 if ($valPairs[3]) {
130 $rows[3] .= '<tr>';
131 if ($valPairs[0]) {
132 $rows[3] .= '<td></td>';
133 }
134 if ($valPairs[2]) {
135 $rows[3] .= '<td>' . $widthImg . '</td>';
136 }
137 $rows[3] .= '<td><span style="width: ' . ($valPairs[2] ?: ($valPairs[4] ?: 1)) . 'px; height: ' . $valPairs[3] . 'px;"></span></td>';
138 $rows[3] .= '</tr>';
139 }
140 return $this->begin . implode('', $rows) . $this->end;
141 } else {
142 return $content;
143 }
144 }
145
146 }