[TASK] Move EXT:cms/layout/res/ files to correct location
[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 TYPO3\CMS\Backend\Utility\IconUtility;
18 use TYPO3\CMS\Core\Utility\GeneralUtility;
19
20 /**
21 * Script Class for grid wizard
22 *
23 * @author T3UXW09 Team1 <modernbe@cybercraft.de>
24 */
25 class BackendLayoutWizardController {
26
27 // GET vars:
28 // Wizard parameters, coming from TCEforms linking to the wizard.
29 /**
30 * @var array
31 */
32 public $P;
33
34 /**
35 * Document template object
36 *
37 * @var \TYPO3\CMS\Backend\Template\DocumentTemplate
38 */
39 public $doc;
40
41 // Accumulated content.
42 /**
43 * @var string
44 */
45 public $content;
46
47 /**
48 * Initialises the Class
49 *
50 * @return void
51 * @throws \InvalidArgumentException
52 */
53 public function init() {
54 $GLOBALS['LANG']->includeLLFile('EXT:lang/locallang_wizards.xlf');
55
56 // Setting GET vars (used in frameset script):
57 $this->P = GeneralUtility::_GP('P');
58 $this->formName = $this->P['formName'];
59 $this->fieldName = $this->P['itemName'];
60 $hmac_validate = GeneralUtility::hmac($this->formName . $this->fieldName, 'wizard_js');
61 if (!$this->P['hmac'] || ($this->P['hmac'] !== $hmac_validate)) {
62 throw new \InvalidArgumentException('Hmac Validation failed for backend_layout wizard', 1385811397);
63 }
64 $this->md5ID = $this->P['md5ID'];
65 $uid = (int)$this->P['uid'];
66 // Initialize document object:
67 $this->doc = GeneralUtility::makeInstance(\TYPO3\CMS\Backend\Template\DocumentTemplate::class);
68 $this->doc->backPath = $GLOBALS['BACK_PATH'];
69 $pageRenderer = $this->doc->getPageRenderer();
70 $pageRenderer->addJsFile(\TYPO3\CMS\Core\Utility\ExtensionManagementUtility::extRelPath('backend') . 'Resources/Public/JavaScript/grideditor.js');
71 $pageRenderer->addJsInlineCode('storeData', '
72 function storeData(data) {
73 if (parent.opener && parent.opener.document && parent.opener.document.' . $this->formName . ' && parent.opener.document.' . $this->formName . '[' . GeneralUtility::quoteJSvalue($this->fieldName) . ']) {
74 parent.opener.document.' . $this->formName . '[' . GeneralUtility::quoteJSvalue($this->fieldName) . '].value = data;
75 parent.opener.TBE_EDITOR.fieldChanged("backend_layout","' . $uid . '","config","data[backend_layout][' . $uid . '][config]");
76 }
77 }
78 ', FALSE);
79 $languageLabels = array(
80 'save' => $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_wizards.xlf:grid_labelSave', TRUE),
81 'title' => $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_wizards.xlf:grid_windowTitle', TRUE),
82 'editCell' => $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_wizards.xlf:grid_editCell', TRUE),
83 'mergeCell' => $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_wizards.xlf:grid_mergeCell', TRUE),
84 'splitCell' => $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_wizards.xlf:grid_splitCell', TRUE),
85 'name' => $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_wizards.xlf:grid_name', TRUE),
86 'column' => $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_wizards.xlf:grid_column', TRUE),
87 'notSet' => $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_wizards.xlf:grid_notSet', TRUE),
88 'nameHelp' => $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_wizards.xlf:grid_nameHelp', TRUE),
89 'columnHelp' => $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_wizards.xlf:grid_columnHelp', TRUE)
90 );
91 $pageRenderer->addInlineLanguageLabelArray($languageLabels);
92 // Select record
93 $record = $GLOBALS['TYPO3_DB']->exec_SELECTgetRows($this->P['field'], $this->P['table'], 'uid=' . (int)$this->P['uid']);
94 if (trim($record[0][$this->P['field']]) == '') {
95 $rows = array(array(array('colspan' => 1, 'rowspan' => 1, 'spanned' => FALSE, 'name' => '')));
96 $colCount = 1;
97 $rowCount = 1;
98 } else {
99 // load TS parser
100 $parser = GeneralUtility::makeInstance(\TYPO3\CMS\Core\TypoScript\Parser\TypoScriptParser::class);
101 $parser->parse($record[0][$this->P['field']]);
102 $data = $parser->setup['backend_layout.'];
103 $rows = array();
104 $colCount = $data['colCount'];
105 $rowCount = $data['rowCount'];
106 $dataRows = $data['rows.'];
107 $spannedMatrix = array();
108 for ($i = 1; $i <= $rowCount; $i++) {
109 $cells = array();
110 $row = array_shift($dataRows);
111 $columns = $row['columns.'];
112 for ($j = 1; $j <= $colCount; $j++) {
113 $cellData = array();
114 if (!$spannedMatrix[$i][$j]) {
115 if (is_array($columns) && count($columns)) {
116 $column = array_shift($columns);
117 if (isset($column['colspan'])) {
118 $cellData['colspan'] = (int)$column['colspan'];
119 $columnColSpan = (int)$column['colspan'];
120 if (isset($column['rowspan'])) {
121 $columnRowSpan = (int)$column['rowspan'];
122 for ($spanRow = 0; $spanRow < $columnRowSpan; $spanRow++) {
123 for ($spanColumn = 0; $spanColumn < $columnColSpan; $spanColumn++) {
124 $spannedMatrix[$i + $spanRow][$j + $spanColumn] = 1;
125 }
126 }
127 } else {
128 for ($spanColumn = 0; $spanColumn < $columnColSpan; $spanColumn++) {
129 $spannedMatrix[$i][$j + $spanColumn] = 1;
130 }
131 }
132 } else {
133 $cellData['colspan'] = 1;
134 if (isset($column['rowspan'])) {
135 $columnRowSpan = (int)$column['rowspan'];
136 for ($spanRow = 0; $spanRow < $columnRowSpan; $spanRow++) {
137 $spannedMatrix[$i + $spanRow][$j] = 1;
138 }
139 }
140 }
141 if (isset($column['rowspan'])) {
142 $cellData['rowspan'] = (int)$column['rowspan'];
143 } else {
144 $cellData['rowspan'] = 1;
145 }
146 if (isset($column['name'])) {
147 $cellData['name'] = $column['name'];
148 }
149 if (isset($column['colPos'])) {
150 $cellData['column'] = (int)$column['colPos'];
151 }
152 }
153 } else {
154 $cellData = array('colspan' => 1, 'rowspan' => 1, 'spanned' => 1);
155 }
156 $cells[] = $cellData;
157 }
158 $rows[] = $cells;
159 if (!empty($spannedMatrix[$i]) && is_array($spannedMatrix[$i])) {
160 ksort($spannedMatrix[$i]);
161 }
162 }
163 }
164 $pageRenderer->enableExtJSQuickTips();
165 $pageRenderer->addExtOnReadyCode('
166 t3Grid = new TYPO3.Backend.t3Grid({
167 data: ' . json_encode($rows, JSON_HEX_QUOT | JSON_HEX_TAG | JSON_HEX_AMP | JSON_HEX_APOS) . ',
168 colCount: ' . (int)$colCount . ',
169 rowCount: ' . (int)$rowCount . ',
170 targetElement: \'editor\'
171 });
172 t3Grid.drawTable();
173 ');
174 $this->doc->styleSheetFile_post = \TYPO3\CMS\Core\Utility\ExtensionManagementUtility::extRelPath('backend') . 'Resources/Public/Css/grideditor.css';
175 }
176
177 /**
178 * Main Method, rendering either colorpicker or frameset depending on ->showPicker
179 *
180 * @return void
181 */
182 public function main() {
183 $resourcePath = \TYPO3\CMS\Core\Utility\ExtensionManagementUtility::extRelPath('backend') . 'Resources/Public/Images/BackendLayoutWizard/';
184 $content = '<a href="#" title="' . $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.xlf:rm.saveDoc', TRUE) . '" onclick="storeData(t3Grid.export2LayoutRecord());return true;">' . IconUtility::getSpriteIcon('actions-document-save') . '</a>';
185 $content .= '<a href="#" title="' . $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.xlf:rm.saveCloseDoc', TRUE) . '" onclick="storeData(t3Grid.export2LayoutRecord());window.close();return true;">' . IconUtility::getSpriteIcon('actions-document-save-close') . '</a>';
186 $content .= '<a href="#" title="' . $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.xlf:rm.closeDoc', TRUE) . '" onclick="window.close();return true;">' . IconUtility::getSpriteIcon('actions-document-close') . '</a>';
187 $content .= $this->doc->spacer(10);
188 $content .= '
189 <table border="0" width="90%" height="90%" id="outer_container">
190 <tr>
191 <td class="editor_cell">
192 <div id="editor">
193 </div>
194 </td>
195 <td width="20" valign="center">
196 <a class="addCol" href="#" title="' . $GLOBALS['LANG']->getLL('grid_addColumn') . '" onclick="t3Grid.addColumn(); t3Grid.drawTable(\'editor\');">
197 <img src="' . $resourcePath . 't3grid-tableright.png" border="0" />
198 </a><br />
199 <a class="removeCol" href="#" title="' . $GLOBALS['LANG']->getLL('grid_removeColumn') . '" onclick="t3Grid.removeColumn(); t3Grid.drawTable(\'editor\');">
200 <img src="' . $resourcePath . 't3grid-tableleft.png" border="0" />
201 </a>
202 </td>
203 </tr>
204 <tr>
205 <td colspan="2" height="20" align="center">
206 <a class="addCol" href="#" title="' . $GLOBALS['LANG']->getLL('grid_addRow') . '" onclick="t3Grid.addRow(); t3Grid.drawTable(\'editor\');">
207 <img src="' . $resourcePath . 't3grid-tabledown.png" border="0" />
208 </a>
209 <a class="removeCol" href="#" title="' . $GLOBALS['LANG']->getLL('grid_removeRow') . '" onclick="t3Grid.removeRow(); t3Grid.drawTable(\'editor\');">
210 <img src="' . $resourcePath . 't3grid-tableup.png" border="0" />
211 </a>
212 </td>
213 </tr>
214 </table>
215 ';
216 $this->content = $content;
217 }
218
219 /**
220 * Returns the sourcecode to the browser
221 *
222 * @return void
223 */
224 public function printContent() {
225 echo $this->doc->render('Grid wizard', $this->content);
226 }
227
228 }