TYPO3 CMS  TYPO3_6-2
BackendLayoutWizardController.php
Go to the documentation of this file.
1 <?php
3 
19 
26 
27  // GET vars:
28  // Wizard parameters, coming from TCEforms linking to the wizard.
32  public $P;
33 
40  public $doc;
41 
42  // Accumulated content.
46  public $content;
47 
54  public function init() {
55  $GLOBALS['LANG']->includeLLFile('EXT:lang/locallang_wizards.xlf');
56 
57  // Setting GET vars (used in frameset script):
58  $this->P = GeneralUtility::_GP('P');
59  $this->formName = $this->P['formName'];
60  $this->fieldName = $this->P['itemName'];
61  $hmac_validate = GeneralUtility::hmac($this->formName . $this->fieldName, 'wizard_js');
62  if (!$this->P['hmac'] || ($this->P['hmac'] !== $hmac_validate)) {
63  throw new \InvalidArgumentException('Hmac Validation failed for backend_layout wizard', 1385811397);
64  }
65  $this->md5ID = $this->P['md5ID'];
66  $uid = (int)$this->P['uid'];
67  // Initialize document object:
68  $this->doc = GeneralUtility::makeInstance('TYPO3\\CMS\\Backend\\Template\\DocumentTemplate');
69  $this->doc->backPath = $GLOBALS['BACK_PATH'];
70  $pageRenderer = $this->doc->getPageRenderer();
71  $pageRenderer->addJsFile(\TYPO3\CMS\Core\Utility\ExtensionManagementUtility::extRelPath('cms') . 'layout/res/grideditor.js');
72  $pageRenderer->addJsInlineCode('storeData', '
73  function storeData(data) {
74  if (parent.opener && parent.opener.document && parent.opener.document.' . $this->formName . ' && parent.opener.document.' . $this->formName . '[' . GeneralUtility::quoteJSvalue($this->fieldName) . ']) {
75  parent.opener.document.' . $this->formName . '[' . GeneralUtility::quoteJSvalue($this->fieldName) . '].value = data;
76  parent.opener.TBE_EDITOR.fieldChanged("backend_layout","' . $uid . '","config","data[backend_layout][' . $uid . '][config]");
77  }
78  }
79  ', FALSE);
80  $languageLabels = array(
81  'save' => $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_wizards.xlf:grid_labelSave', TRUE),
82  'title' => $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_wizards.xlf:grid_windowTitle', TRUE),
83  'editCell' => $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_wizards.xlf:grid_editCell', TRUE),
84  'mergeCell' => $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_wizards.xlf:grid_mergeCell', TRUE),
85  'splitCell' => $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_wizards.xlf:grid_splitCell', TRUE),
86  'name' => $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_wizards.xlf:grid_name', TRUE),
87  'column' => $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_wizards.xlf:grid_column', TRUE),
88  'notSet' => $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_wizards.xlf:grid_notSet', TRUE),
89  'nameHelp' => $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_wizards.xlf:grid_nameHelp', TRUE),
90  'columnHelp' => $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_wizards.xlf:grid_columnHelp', TRUE)
91  );
92  $pageRenderer->addInlineLanguageLabelArray($languageLabels);
93  // Select record
94  $record = $GLOBALS['TYPO3_DB']->exec_SELECTgetRows($this->P['field'], $this->P['table'], 'uid=' . (int)$this->P['uid']);
95  if (trim($record[0][$this->P['field']]) == '') {
96  $rows = array(array(array('colspan' => 1, 'rowspan' => 1, 'spanned' => FALSE, 'name' => '')));
97  $colCount = 1;
98  $rowCount = 1;
99  } else {
100  // load TS parser
101  $parser = GeneralUtility::makeInstance('TYPO3\\CMS\\Core\\TypoScript\\Parser\\TypoScriptParser');
102  $parser->parse($record[0][$this->P['field']]);
103  $data = $parser->setup['backend_layout.'];
104  $rows = array();
105  $colCount = $data['colCount'];
106  $rowCount = $data['rowCount'];
107  $dataRows = $data['rows.'];
108  $spannedMatrix = array();
109  for ($i = 1; $i <= $rowCount; $i++) {
110  $cells = array();
111  $row = array_shift($dataRows);
112  $columns = $row['columns.'];
113  for ($j = 1; $j <= $colCount; $j++) {
114  $cellData = array();
115  if (!$spannedMatrix[$i][$j]) {
116  if (is_array($columns) && count($columns)) {
117  $column = array_shift($columns);
118  if (isset($column['colspan'])) {
119  $cellData['colspan'] = (int)$column['colspan'];
120  $columnColSpan = (int)$column['colspan'];
121  if (isset($column['rowspan'])) {
122  $columnRowSpan = (int)$column['rowspan'];
123  for ($spanRow = 0; $spanRow < $columnRowSpan; $spanRow++) {
124  for ($spanColumn = 0; $spanColumn < $columnColSpan; $spanColumn++) {
125  $spannedMatrix[$i + $spanRow][$j + $spanColumn] = 1;
126  }
127  }
128  } else {
129  for ($spanColumn = 0; $spanColumn < $columnColSpan; $spanColumn++) {
130  $spannedMatrix[$i][$j + $spanColumn] = 1;
131  }
132  }
133  } else {
134  $cellData['colspan'] = 1;
135  if (isset($column['rowspan'])) {
136  $columnRowSpan = (int)$column['rowspan'];
137  for ($spanRow = 0; $spanRow < $columnRowSpan; $spanRow++) {
138  $spannedMatrix[$i + $spanRow][$j] = 1;
139  }
140  }
141  }
142  if (isset($column['rowspan'])) {
143  $cellData['rowspan'] = (int)$column['rowspan'];
144  } else {
145  $cellData['rowspan'] = 1;
146  }
147  if (isset($column['name'])) {
148  $cellData['name'] = $column['name'];
149  }
150  if (isset($column['colPos'])) {
151  $cellData['column'] = (int)$column['colPos'];
152  }
153  }
154  } else {
155  $cellData = array('colspan' => 1, 'rowspan' => 1, 'spanned' => 1);
156  }
157  $cells[] = $cellData;
158  }
159  $rows[] = $cells;
160  if (!empty($spannedMatrix[$i]) && is_array($spannedMatrix[$i])) {
161  ksort($spannedMatrix[$i]);
162  }
163  }
164  }
165  $pageRenderer->enableExtJSQuickTips();
166  $pageRenderer->addExtOnReadyCode('
167  t3Grid = new TYPO3.Backend.t3Grid({
168  data: ' . json_encode($rows, JSON_HEX_QUOT | JSON_HEX_TAG | JSON_HEX_AMP | JSON_HEX_APOS) . ',
169  colCount: ' . (int)$colCount . ',
170  rowCount: ' . (int)$rowCount . ',
171  targetElement: \'editor\'
172  });
173  t3Grid.drawTable();
174  ');
175  $this->doc->styleSheetFile_post = \TYPO3\CMS\Core\Utility\ExtensionManagementUtility::extRelPath('cms') . 'layout/res/grideditor.css';
176  }
177 
183  public function main() {
184  $resourcePath = \TYPO3\CMS\Core\Utility\ExtensionManagementUtility::extRelPath('cms') . 'layout/';
185  $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>';
186  $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>';
187  $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>';
188  $content .= $this->doc->spacer(10);
189  $content .= '
190  <table border="0" width="90%" height="90%" id="outer_container">
191  <tr>
192  <td class="editor_cell">
193  <div id="editor">
194  </div>
195  </td>
196  <td width="20" valign="center">
197  <a class="addCol" href="#" title="' . $GLOBALS['LANG']->getLL('grid_addColumn') . '" onclick="t3Grid.addColumn(); t3Grid.drawTable(\'editor\');">
198  <img src="' . $resourcePath . 'res/t3grid-tableright.png" border="0" />
199  </a><br />
200  <a class="removeCol" href="#" title="' . $GLOBALS['LANG']->getLL('grid_removeColumn') . '" onclick="t3Grid.removeColumn(); t3Grid.drawTable(\'editor\');">
201  <img src="' . $resourcePath . 'res/t3grid-tableleft.png" border="0" />
202  </a>
203  </td>
204  </tr>
205  <tr>
206  <td colspan="2" height="20" align="center">
207  <a class="addCol" href="#" title="' . $GLOBALS['LANG']->getLL('grid_addRow') . '" onclick="t3Grid.addRow(); t3Grid.drawTable(\'editor\');">
208  <img src="' . $resourcePath . 'res/t3grid-tabledown.png" border="0" />
209  </a>
210  <a class="removeCol" href="#" title="' . $GLOBALS['LANG']->getLL('grid_removeRow') . '" onclick="t3Grid.removeRow(); t3Grid.drawTable(\'editor\');">
211  <img src="' . $resourcePath . 'res/t3grid-tableup.png" border="0" />
212  </a>
213  </td>
214  </tr>
215  </table>
216  ';
217  $this->content = $content;
218  }
219 
225  public function printContent() {
226  echo $this->doc->render('Grid wizard', $this->content);
227  }
228 
229 }
$uid
Definition: server.php:36
static hmac($input, $additionalSecret='')
static getSpriteIcon($iconName, array $options=array(), array $overlays=array())
if(!defined('TYPO3_MODE')) $GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['t3lib/class.t3lib_userauth.php']['logoff_pre_processing'][]