[TASK] Call explicit render() on icon objects
[Packages/TYPO3.CMS.git] / typo3 / sysext / backend / Classes / Controller / BackendLayoutWizardController.php
1 <?php
2 namespace TYPO3\CMS\Backend\Controller;
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 use Psr\Http\Message\ServerRequestInterface;
18 use Psr\Http\Message\ResponseInterface;
19 use TYPO3\CMS\Backend\Template\DocumentTemplate;
20 use TYPO3\CMS\Backend\Utility\BackendUtility;
21 use TYPO3\CMS\Core\Imaging\Icon;
22 use TYPO3\CMS\Core\Imaging\IconFactory;
23 use TYPO3\CMS\Core\Page\PageRenderer;
24 use TYPO3\CMS\Core\TypoScript\Parser\TypoScriptParser;
25 use TYPO3\CMS\Core\Utility\GeneralUtility;
26 use TYPO3\CMS\Core\Utility\ExtensionManagementUtility;
27
28
29 /**
30 * Script Class for grid wizard
31 */
32 class BackendLayoutWizardController {
33
34 // GET vars:
35 // Wizard parameters, coming from TCEforms linking to the wizard.
36 /**
37 * @var array
38 */
39 public $P;
40
41 /**
42 * Document template object
43 *
44 * @var \TYPO3\CMS\Backend\Template\DocumentTemplate
45 */
46 public $doc;
47
48 // Accumulated content.
49 /**
50 * @var string
51 */
52 public $content;
53
54 /**
55 * @var string
56 */
57 public $formName;
58
59 /**
60 * @var string
61 */
62 public $fieldName;
63
64 /**
65 * Constructor
66 */
67 public function __construct(){
68 $this->init();
69 }
70
71 /**
72 * Initialises the Class
73 *
74 * @return void
75 * @throws \InvalidArgumentException
76 */
77 public function init() {
78 $lang = $this->getLanguageService();
79 $lang->includeLLFile('EXT:lang/locallang_wizards.xlf');
80
81 // Setting GET vars (used in frameset script):
82 $this->P = GeneralUtility::_GP('P');
83 $this->formName = $this->P['formName'];
84 $this->fieldName = $this->P['itemName'];
85 $hmac_validate = GeneralUtility::hmac($this->formName . $this->fieldName, 'wizard_js');
86 if (!$this->P['hmac'] || ($this->P['hmac'] !== $hmac_validate)) {
87 throw new \InvalidArgumentException('Hmac Validation failed for backend_layout wizard', 1385811397);
88 }
89 $uid = (int)$this->P['uid'];
90 // Initialize document object:
91 $this->doc = GeneralUtility::makeInstance(DocumentTemplate::class);
92 $pageRenderer = GeneralUtility::makeInstance(PageRenderer::class);
93 $pageRenderer->loadExtJS();
94 $pageRenderer->addJsFile(ExtensionManagementUtility::extRelPath('backend') . 'Resources/Public/JavaScript/grideditor.js');
95 $pageRenderer->loadRequireJsModule('TYPO3/CMS/Backend/Tooltip');
96 $pageRenderer->addInlineSetting('ContextHelp', 'moduleUrl', BackendUtility::getModuleUrl('help_CshmanualCshmanual', array(
97 'tx_cshmanual_help_cshmanualcshmanual' => array(
98 'controller' => 'Help',
99 'action' => 'detail'
100 )
101 )));
102 $pageRenderer->addJsInlineCode('storeData', '
103 function storeData(data) {
104 if (parent.opener && parent.opener.document && parent.opener.document.' . $this->formName . ' && parent.opener.document.' . $this->formName . '[' . GeneralUtility::quoteJSvalue($this->fieldName) . ']) {
105 parent.opener.document.' . $this->formName . '[' . GeneralUtility::quoteJSvalue($this->fieldName) . '].value = data;
106 parent.opener.TBE_EDITOR.fieldChanged("backend_layout","' . $uid . '","config","data[backend_layout][' . $uid . '][config]");
107 }
108 }
109 ', FALSE);
110 $languageLabels = array(
111 'save' => $lang->sL('LLL:EXT:lang/locallang_wizards.xlf:grid_labelSave', TRUE),
112 'title' => $lang->sL('LLL:EXT:lang/locallang_wizards.xlf:grid_windowTitle', TRUE),
113 'editCell' => $lang->sL('LLL:EXT:lang/locallang_wizards.xlf:grid_editCell', TRUE),
114 'mergeCell' => $lang->sL('LLL:EXT:lang/locallang_wizards.xlf:grid_mergeCell', TRUE),
115 'splitCell' => $lang->sL('LLL:EXT:lang/locallang_wizards.xlf:grid_splitCell', TRUE),
116 'name' => $lang->sL('LLL:EXT:lang/locallang_wizards.xlf:grid_name', TRUE),
117 'column' => $lang->sL('LLL:EXT:lang/locallang_wizards.xlf:grid_column', TRUE),
118 'notSet' => $lang->sL('LLL:EXT:lang/locallang_wizards.xlf:grid_notSet', TRUE),
119 'nameHelp' => $lang->sL('LLL:EXT:lang/locallang_wizards.xlf:grid_nameHelp', TRUE),
120 'columnHelp' => $lang->sL('LLL:EXT:lang/locallang_wizards.xlf:grid_columnHelp', TRUE)
121 );
122 $pageRenderer->addInlineLanguageLabelArray($languageLabels);
123 // Select record
124 $record = $this->getDatabaseConnection()->exec_SELECTgetRows($this->P['field'], $this->P['table'], 'uid=' . (int)$this->P['uid']);
125 if (trim($record[0][$this->P['field']]) == '') {
126 $rows = array(array(array('colspan' => 1, 'rowspan' => 1, 'spanned' => FALSE, 'name' => '')));
127 $colCount = 1;
128 $rowCount = 1;
129 } else {
130 // load TS parser
131 $parser = GeneralUtility::makeInstance(TypoScriptParser::class);
132 $parser->parse($record[0][$this->P['field']]);
133 $data = $parser->setup['backend_layout.'];
134 $rows = array();
135 $colCount = $data['colCount'];
136 $rowCount = $data['rowCount'];
137 $dataRows = $data['rows.'];
138 $spannedMatrix = array();
139 for ($i = 1; $i <= $rowCount; $i++) {
140 $cells = array();
141 $row = array_shift($dataRows);
142 $columns = $row['columns.'];
143 for ($j = 1; $j <= $colCount; $j++) {
144 $cellData = array();
145 if (!$spannedMatrix[$i][$j]) {
146 if (is_array($columns) && !empty($columns)) {
147 $column = array_shift($columns);
148 if (isset($column['colspan'])) {
149 $cellData['colspan'] = (int)$column['colspan'];
150 $columnColSpan = (int)$column['colspan'];
151 if (isset($column['rowspan'])) {
152 $columnRowSpan = (int)$column['rowspan'];
153 for ($spanRow = 0; $spanRow < $columnRowSpan; $spanRow++) {
154 for ($spanColumn = 0; $spanColumn < $columnColSpan; $spanColumn++) {
155 $spannedMatrix[$i + $spanRow][$j + $spanColumn] = 1;
156 }
157 }
158 } else {
159 for ($spanColumn = 0; $spanColumn < $columnColSpan; $spanColumn++) {
160 $spannedMatrix[$i][$j + $spanColumn] = 1;
161 }
162 }
163 } else {
164 $cellData['colspan'] = 1;
165 if (isset($column['rowspan'])) {
166 $columnRowSpan = (int)$column['rowspan'];
167 for ($spanRow = 0; $spanRow < $columnRowSpan; $spanRow++) {
168 $spannedMatrix[$i + $spanRow][$j] = 1;
169 }
170 }
171 }
172 if (isset($column['rowspan'])) {
173 $cellData['rowspan'] = (int)$column['rowspan'];
174 } else {
175 $cellData['rowspan'] = 1;
176 }
177 if (isset($column['name'])) {
178 $cellData['name'] = $column['name'];
179 }
180 if (isset($column['colPos'])) {
181 $cellData['column'] = (int)$column['colPos'];
182 }
183 }
184 } else {
185 $cellData = array('colspan' => 1, 'rowspan' => 1, 'spanned' => 1);
186 }
187 $cells[] = $cellData;
188 }
189 $rows[] = $cells;
190 if (!empty($spannedMatrix[$i]) && is_array($spannedMatrix[$i])) {
191 ksort($spannedMatrix[$i]);
192 }
193 }
194 }
195 $pageRenderer->addExtOnReadyCode('
196 t3Grid = new TYPO3.Backend.t3Grid({
197 data: ' . json_encode($rows, JSON_HEX_QUOT | JSON_HEX_TAG | JSON_HEX_AMP | JSON_HEX_APOS) . ',
198 colCount: ' . (int)$colCount . ',
199 rowCount: ' . (int)$rowCount . ',
200 targetElement: \'editor\'
201 });
202 t3Grid.drawTable();
203 ');
204 $this->doc->styleSheetFile_post = ExtensionManagementUtility::extRelPath('backend') . 'Resources/Public/Css/grideditor.css';
205 }
206
207 /**
208 * Injects the request object for the current request or subrequest
209 * As this controller goes only through the main() method, it is rather simple for now
210 *
211 * @param ServerRequestInterface $request
212 * @param ResponseInterface $response
213 * @return ResponseInterface
214 */
215 public function mainAction(ServerRequestInterface $request, ResponseInterface $response) {
216 $this->main();
217 $response->getBody()->write($this->doc->render('Grid wizard', $this->content));
218 return $response;
219 }
220
221 /**
222 * Main Method, rendering either colorpicker or frameset depending on ->showPicker
223 *
224 * @return void
225 */
226 public function main() {
227 /** @var IconFactory $iconFactory */
228 $iconFactory = GeneralUtility::makeInstance(IconFactory::class);
229 $lang = $this->getLanguageService();
230 $resourcePath = ExtensionManagementUtility::extRelPath('backend') . 'Resources/Public/Images/BackendLayoutWizard/';
231 $content = '<a href="#" title="' . $lang->sL('LLL:EXT:lang/locallang_core.xlf:rm.saveDoc', TRUE) . '" onclick="storeData(t3Grid.export2LayoutRecord());return true;">' . $iconFactory->getIcon('actions-document-save', Icon::SIZE_SMALL)->render() . '</a>';
232 $content .= '<a href="#" title="' . $lang->sL('LLL:EXT:lang/locallang_core.xlf:rm.saveCloseDoc', TRUE) . '" onclick="storeData(t3Grid.export2LayoutRecord());window.close();return true;">' . $iconFactory->getIcon('actions-document-save-close', Icon::SIZE_SMALL)->render() . '</a>';
233 $content .= '<a href="#" title="' . $lang->sL('LLL:EXT:lang/locallang_core.xlf:rm.closeDoc', TRUE) . '" onclick="window.close();return true;">' . $iconFactory->getIcon('actions-document-close', Icon::SIZE_SMALL)->render() . '</a>';
234 $content .= $this->doc->spacer(10);
235 $content .= '
236 <table border="0" width="90%" height="90%" id="outer_container">
237 <tr>
238 <td class="editor_cell">
239 <div id="editor">
240 </div>
241 </td>
242 <td width="20" valign="center">
243 <a class="addCol" href="#" title="' . $lang->getLL('grid_addColumn') . '" onclick="t3Grid.addColumn(); t3Grid.drawTable(\'editor\');">
244 <img src="' . $resourcePath . 't3grid-tableright.png" border="0" />
245 </a><br />
246 <a class="removeCol" href="#" title="' . $lang->getLL('grid_removeColumn') . '" onclick="t3Grid.removeColumn(); t3Grid.drawTable(\'editor\');">
247 <img src="' . $resourcePath . 't3grid-tableleft.png" border="0" />
248 </a>
249 </td>
250 </tr>
251 <tr>
252 <td colspan="2" height="20" align="center">
253 <a class="addCol" href="#" title="' . $lang->getLL('grid_addRow') . '" onclick="t3Grid.addRow(); t3Grid.drawTable(\'editor\');">
254 <img src="' . $resourcePath . 't3grid-tabledown.png" border="0" />
255 </a>
256 <a class="removeCol" href="#" title="' . $lang->getLL('grid_removeRow') . '" onclick="t3Grid.removeRow(); t3Grid.drawTable(\'editor\');">
257 <img src="' . $resourcePath . 't3grid-tableup.png" border="0" />
258 </a>
259 </td>
260 </tr>
261 </table>
262 ';
263 $this->content = $content;
264 }
265
266 /**
267 * Returns the sourcecode to the browser
268 *
269 * @return void
270 * @deprecated since TYPO3 CMS 7, will be removed in TYPO3 CMS 8, use mainAction() instead
271 */
272 public function printContent() {
273 GeneralUtility::logDeprecatedFunction();
274 echo $this->doc->render('Grid wizard', $this->content);
275 }
276
277 /**
278 * Returns LanguageService
279 *
280 * @return \TYPO3\CMS\Lang\LanguageService
281 */
282 protected function getLanguageService() {
283 return $GLOBALS['LANG'];
284 }
285
286 /**
287 * Returns the database connection
288 *
289 * @return \TYPO3\CMS\Core\Database\DatabaseConnection
290 */
291 protected function getDatabaseConnection() {
292 return $GLOBALS['TYPO3_DB'];
293 }
294
295 }