TYPO3 CMS  TYPO3_7-6
BackendLayoutWizardController.php
Go to the documentation of this file.
1 <?php
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 
27 
32 {
33  // GET vars:
34  // Wizard parameters, coming from TCEforms linking to the wizard.
38  public $P;
39 
40  // Accumulated content.
44  public $content;
45 
49  public $formName;
50 
54  public $fieldName;
55 
59  public function __construct()
60  {
61  parent::__construct();
62  $this->init();
63  }
64 
71  public function init()
72  {
73  $lang = $this->getLanguageService();
74  $lang->includeLLFile('EXT:lang/locallang_wizards.xlf');
75 
76  // Setting GET vars (used in frameset script):
77  $this->P = GeneralUtility::_GP('P');
78  $this->formName = $this->P['formName'];
79  $this->fieldName = $this->P['itemName'];
80  $hmac_validate = GeneralUtility::hmac($this->formName . $this->fieldName, 'wizard_js');
81  if (!$this->P['hmac'] || ($this->P['hmac'] !== $hmac_validate)) {
82  throw new \InvalidArgumentException('Hmac Validation failed for backend_layout wizard', 1385811397);
83  }
84  $uid = (int)$this->P['uid'];
85 
87  $pageRenderer = GeneralUtility::makeInstance(PageRenderer::class);
88  $pageRenderer->loadExtJS();
89  $pageRenderer->addJsFile(ExtensionManagementUtility::extRelPath('backend')
90  . 'Resources/Public/JavaScript/grideditor.js');
91  $pageRenderer->loadRequireJsModule('TYPO3/CMS/Backend/Tooltip');
92  $pageRenderer->addInlineSetting(
93  'ContextHelp',
94  'moduleUrl',
95  BackendUtility::getModuleUrl(
96  'help_CshmanualCshmanual',
97  [
98  'tx_cshmanual_help_cshmanualcshmanual' => [
99  'controller' => 'Help',
100  'action' => 'detail'
101  ]
102  ]
103  )
104  );
105  $pageRenderer->addJsInlineCode('storeData', '
106  function storeData(data) {
107  if (parent.opener && parent.opener.document && parent.opener.document.' . $this->formName . ' && parent.opener.document.' . $this->formName . '[' . GeneralUtility::quoteJSvalue($this->fieldName) . ']) {
108  parent.opener.document.' . $this->formName . '[' . GeneralUtility::quoteJSvalue($this->fieldName) . '].value = data;
109  parent.opener.TBE_EDITOR.fieldChanged("backend_layout","' . $uid . '","config","data[backend_layout][' . $uid . '][config]");
110  }
111  }
112  ', false);
113  $languageLabels = [
114  'save' => $lang->sL('LLL:EXT:lang/locallang_wizards.xlf:grid_labelSave', true),
115  'title' => $lang->sL('LLL:EXT:lang/locallang_wizards.xlf:grid_windowTitle', true),
116  'editCell' => $lang->sL('LLL:EXT:lang/locallang_wizards.xlf:grid_editCell', true),
117  'mergeCell' => $lang->sL('LLL:EXT:lang/locallang_wizards.xlf:grid_mergeCell', true),
118  'splitCell' => $lang->sL('LLL:EXT:lang/locallang_wizards.xlf:grid_splitCell', true),
119  'name' => $lang->sL('LLL:EXT:lang/locallang_wizards.xlf:grid_name', true),
120  'column' => $lang->sL('LLL:EXT:lang/locallang_wizards.xlf:grid_column', true),
121  'notSet' => $lang->sL('LLL:EXT:lang/locallang_wizards.xlf:grid_notSet', true),
122  'nameHelp' => $lang->sL('LLL:EXT:lang/locallang_wizards.xlf:grid_nameHelp', true),
123  'columnHelp' => $lang->sL('LLL:EXT:lang/locallang_wizards.xlf:grid_columnHelp', true)
124  ];
125  $pageRenderer->addInlineLanguageLabelArray($languageLabels);
126  // Select record
127  $record = $this->getDatabaseConnection()->exec_SELECTgetRows(
128  $this->P['field'],
129  $this->P['table'],
130  'uid=' . (int)$this->P['uid']
131  );
132  if (trim($record[0][$this->P['field']]) == '') {
133  $rows = [[['colspan' => 1, 'rowspan' => 1, 'spanned' => false, 'name' => '']]];
134  $colCount = 1;
135  $rowCount = 1;
136  } else {
137  // load TS parser
138  $parser = GeneralUtility::makeInstance(TypoScriptParser::class);
139  $parser->parse($record[0][$this->P['field']]);
140  $data = $parser->setup['backend_layout.'];
141  $rows = [];
142  $colCount = $data['colCount'];
143  $rowCount = $data['rowCount'];
144  $dataRows = $data['rows.'];
145  $spannedMatrix = [];
146  for ($i = 1; $i <= $rowCount; $i++) {
147  $cells = [];
148  $row = array_shift($dataRows);
149  $columns = $row['columns.'];
150  for ($j = 1; $j <= $colCount; $j++) {
151  $cellData = [];
152  if (!$spannedMatrix[$i][$j]) {
153  if (is_array($columns) && !empty($columns)) {
154  $column = array_shift($columns);
155  if (isset($column['colspan'])) {
156  $cellData['colspan'] = (int)$column['colspan'];
157  $columnColSpan = (int)$column['colspan'];
158  if (isset($column['rowspan'])) {
159  $columnRowSpan = (int)$column['rowspan'];
160  for ($spanRow = 0; $spanRow < $columnRowSpan; $spanRow++) {
161  for ($spanColumn = 0; $spanColumn < $columnColSpan; $spanColumn++) {
162  $spannedMatrix[$i + $spanRow][$j + $spanColumn] = 1;
163  }
164  }
165  } else {
166  for ($spanColumn = 0; $spanColumn < $columnColSpan; $spanColumn++) {
167  $spannedMatrix[$i][$j + $spanColumn] = 1;
168  }
169  }
170  } else {
171  $cellData['colspan'] = 1;
172  if (isset($column['rowspan'])) {
173  $columnRowSpan = (int)$column['rowspan'];
174  for ($spanRow = 0; $spanRow < $columnRowSpan; $spanRow++) {
175  $spannedMatrix[$i + $spanRow][$j] = 1;
176  }
177  }
178  }
179  if (isset($column['rowspan'])) {
180  $cellData['rowspan'] = (int)$column['rowspan'];
181  } else {
182  $cellData['rowspan'] = 1;
183  }
184  if (isset($column['name'])) {
185  $cellData['name'] = $column['name'];
186  }
187  if (isset($column['colPos'])) {
188  $cellData['column'] = (int)$column['colPos'];
189  }
190  }
191  } else {
192  $cellData = ['colspan' => 1, 'rowspan' => 1, 'spanned' => 1];
193  }
194  $cells[] = $cellData;
195  }
196  $rows[] = $cells;
197  if (!empty($spannedMatrix[$i]) && is_array($spannedMatrix[$i])) {
198  ksort($spannedMatrix[$i]);
199  }
200  }
201  }
202  $pageRenderer->addExtOnReadyCode('
203  t3Grid = new TYPO3.Backend.t3Grid({
204  data: ' . json_encode($rows, JSON_HEX_QUOT | JSON_HEX_TAG | JSON_HEX_AMP | JSON_HEX_APOS) . ',
205  colCount: ' . (int)$colCount . ',
206  rowCount: ' . (int)$rowCount . ',
207  targetElement: \'editor\'
208  });
209  t3Grid.drawTable();
210  ');
211 
212  $this->moduleTemplate->getPageRenderer()->addCssFile(ExtensionManagementUtility::extRelPath('backend')
213  . 'Resources/Public/Css/grideditor.css');
214  }
215 
224  public function mainAction(ServerRequestInterface $request, ResponseInterface $response)
225  {
226  $this->main();
227 
228  $this->setPagePath($this->P['table'], $this->P['uid']);
229 
230  $this->moduleTemplate->setContent($this->content);
231  $response->getBody()->write($this->moduleTemplate->renderContent());
232  return $response;
233  }
234 
241  protected function setPagePath($table, $uid)
242  {
243  $uid = (int)$uid;
244 
245  if ($table === 'pages') {
246  $pageId = $uid;
247  } else {
248  $record = BackendUtility::getRecord($table, $uid, '*', '', false);
249  $pageId = $record['pid'];
250  }
251 
252  $pageAccess = BackendUtility::readPageAccess($pageId, $this->getBackendUser()->getPagePermsClause(1));
253  if (is_array($pageAccess)) {
254  $this->moduleTemplate->getDocHeaderComponent()->setMetaInformation($pageAccess);
255  }
256  }
257 
263  public function main()
264  {
265  $buttonBar = $this->moduleTemplate->getDocHeaderComponent()->getButtonBar();
266  $lang = $this->getLanguageService();
267 
268  $resourcePath = ExtensionManagementUtility::extRelPath('backend')
269  . 'Resources/Public/Images/BackendLayoutWizard/';
270 
271  $saveButton = $buttonBar->makeInputButton()
272  ->setName('_savedok')
273  ->setValue('1')
274  ->setTitle($lang->sL('LLL:EXT:lang/locallang_core.xlf:rm.saveDoc'))
275  ->setOnClick('storeData(t3Grid.export2LayoutRecord());return true;')
276  ->setIcon($this->moduleTemplate->getIconFactory()->getIcon('actions-document-save', Icon::SIZE_SMALL));
277 
278  $saveAndCloseButton = $buttonBar->makeInputButton()
279  ->setName('_savedokandclose')
280  ->setValue('1')
281  ->setTitle($lang->sL('LLL:EXT:lang/locallang_core.xlf:rm.saveCloseDoc'))
282  ->setOnClick('storeData(t3Grid.export2LayoutRecord());window.close();return true;')
283  ->setIcon(
284  $this->moduleTemplate->getIconFactory()->getIcon('actions-document-save-close', Icon::SIZE_SMALL)
285  );
286 
287  $splitButton = $buttonBar->makeSplitButton()
288  ->addItem($saveButton)
289  ->addItem($saveAndCloseButton);
290  $buttonBar->addButton($splitButton);
291 
292  $closeButton = $buttonBar->makeLinkButton()
293  ->setHref('#')
294  ->setTitle($lang->sL('LLL:EXT:lang/locallang_core.xlf:rm.closeDoc'))
295  ->setOnClick('window.close();return true;')
296  ->setIcon($this->moduleTemplate->getIconFactory()->getIcon('actions-document-close', Icon::SIZE_SMALL));
297  $buttonBar->addButton($closeButton, ButtonBar::BUTTON_POSITION_LEFT, 30);
298 
299  $this->content .= '
300  <table border="0" width="90%" height="90%" id="outer_container">
301  <tr>
302  <td class="editor_cell">
303  <div id="editor">
304  </div>
305  </td>
306  <td width="20" valign="center">
307  <a class="addCol" href="#" title="' . $lang->getLL('grid_addColumn') . '" onclick="t3Grid.addColumn(); t3Grid.drawTable(\'editor\');">
308  <img src="' . $resourcePath . 't3grid-tableright.png" border="0" />
309  </a><br />
310  <a class="removeCol" href="#" title="' . $lang->getLL('grid_removeColumn') . '" onclick="t3Grid.removeColumn(); t3Grid.drawTable(\'editor\');">
311  <img src="' . $resourcePath . 't3grid-tableleft.png" border="0" />
312  </a>
313  </td>
314  </tr>
315  <tr>
316  <td colspan="2" height="20" align="center">
317  <a class="addCol" href="#" title="' . $lang->getLL('grid_addRow') . '" onclick="t3Grid.addRow(); t3Grid.drawTable(\'editor\');">
318  <img src="' . $resourcePath . 't3grid-tabledown.png" border="0" />
319  </a>
320  <a class="removeCol" href="#" title="' . $lang->getLL('grid_removeRow') . '" onclick="t3Grid.removeRow(); t3Grid.drawTable(\'editor\');">
321  <img src="' . $resourcePath . 't3grid-tableup.png" border="0" />
322  </a>
323  </td>
324  </tr>
325  </table>
326  ';
327  }
328 
334  protected function getLanguageService()
335  {
336  return $GLOBALS['LANG'];
337  }
338 
344  protected function getDatabaseConnection()
345  {
346  return $GLOBALS['TYPO3_DB'];
347  }
348 
354  protected function getBackendUser()
355  {
356  return $GLOBALS['BE_USER'];
357  }
358 }
static readPageAccess($id, $perms_clause)
static hmac($input, $additionalSecret='')
mainAction(ServerRequestInterface $request, ResponseInterface $response)
$uid
Definition: server.php:38
static getRecord($table, $uid, $fields=' *', $where='', $useDeleteClause=true)
if(TYPO3_MODE==='BE') $GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['t3lib/class.t3lib_tsfebeuserauth.php']['frontendEditingController']['default']