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