[TASK] Mark array2xml_cs() as deprecated, use array2xml() instead
[Packages/TYPO3.CMS.git] / typo3 / sysext / backend / Classes / Controller / Wizard / TableController.php
1 <?php
2 namespace TYPO3\CMS\Backend\Controller\Wizard;
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\ResponseInterface;
18 use Psr\Http\Message\ServerRequestInterface;
19 use TYPO3\CMS\Backend\Template\Components\ButtonBar;
20 use TYPO3\CMS\Backend\Utility\BackendUtility;
21 use TYPO3\CMS\Core\Configuration\FlexForm\FlexFormTools;
22 use TYPO3\CMS\Core\DataHandling\DataHandler;
23 use TYPO3\CMS\Core\Imaging\Icon;
24 use TYPO3\CMS\Core\Imaging\IconFactory;
25 use TYPO3\CMS\Core\Utility\GeneralUtility;
26 use TYPO3\CMS\Core\Utility\HttpUtility;
27 use TYPO3\CMS\Core\Utility\MathUtility;
28 use TYPO3\CMS\Core\Utility\StringUtility;
29
30 /**
31 * Script Class for rendering the Table Wizard
32 */
33 class TableController extends AbstractWizardController
34 {
35 /**
36 * Content accumulation for the module.
37 *
38 * @var string
39 */
40 public $content;
41
42 /**
43 * If TRUE, <input> fields are shown instead of textareas.
44 *
45 * @var bool
46 */
47 public $inputStyle = false;
48
49 /**
50 * If set, the string version of the content is interpreted/written as XML
51 * instead of the original line-based kind. This variable still needs binding
52 * to the wizard parameters - but support is ready!
53 *
54 * @var int
55 */
56 public $xmlStorage = 0;
57
58 /**
59 * Number of new rows to add in bottom of wizard
60 *
61 * @var int
62 */
63 public $numNewRows = 1;
64
65 /**
66 * Name of field in parent record which MAY contain the number of columns for the table
67 * here hardcoded to the value of tt_content. Should be set by FormEngine parameters (from P)
68 *
69 * @var string
70 */
71 public $colsFieldName = 'cols';
72
73 /**
74 * Wizard parameters, coming from FormEngine linking to the wizard.
75 *
76 * @var array
77 */
78 public $P;
79
80 /**
81 * The array which is constantly submitted by the multidimensional form of this wizard.
82 *
83 * @var array
84 */
85 public $TABLECFG;
86
87 /**
88 * Table parsing
89 * quoting of table cells
90 *
91 * @var string
92 */
93 public $tableParsing_quote;
94
95 /**
96 * delimiter between table cells
97 *
98 * @var string
99 */
100 public $tableParsing_delimiter;
101
102 /**
103 * @var IconFactory
104 */
105 protected $iconFactory;
106
107 /**
108 * Constructor
109 */
110 public function __construct()
111 {
112 parent::__construct();
113 $this->getLanguageService()->includeLLFile('EXT:lang/locallang_wizards.xlf');
114 $GLOBALS['SOBE'] = $this;
115
116 $this->init();
117 }
118
119 /**
120 * Initialization of the class
121 *
122 * @return void
123 */
124 protected function init()
125 {
126 // GPvars:
127 $this->P = GeneralUtility::_GP('P');
128 $this->TABLECFG = GeneralUtility::_GP('TABLE');
129 // Setting options:
130 $this->xmlStorage = $this->P['params']['xmlOutput'];
131 $this->numNewRows = MathUtility::forceIntegerInRange($this->P['params']['numNewRows'], 1, 50, 5);
132 // Textareas or input fields:
133 $this->inputStyle = isset($this->TABLECFG['textFields']) ? (bool)$this->TABLECFG['textFields'] : true;
134 // Setting form tag:
135 list($rUri) = explode('#', GeneralUtility::getIndpEnv('REQUEST_URI'));
136 $this->tableParsing_delimiter = '|';
137 $this->tableParsing_quote = '';
138 }
139
140 /**
141 * Injects the request object for the current request or subrequest
142 * As this controller goes only through the main() method, it is rather simple for now
143 *
144 * @param ServerRequestInterface $request
145 * @param ResponseInterface $response
146 * @return ResponseInterface
147 */
148 public function mainAction(ServerRequestInterface $request, ResponseInterface $response)
149 {
150 $this->main();
151 $response->getBody()->write($this->moduleTemplate->renderContent());
152 return $response;
153 }
154
155 /**
156 * Main function, rendering the table wizard
157 *
158 * @return void
159 */
160 public function main()
161 {
162 $this->content .= '<form action="' . htmlspecialchars($rUri) . '" method="post" id="TableController" name="wizardForm">';
163 if ($this->P['table'] && $this->P['field'] && $this->P['uid']) {
164 $this->content .= '<h2>' . $this->getLanguageService()->getLL('table_title', true) . '</h2>'
165 . '<div>' . $this->tableWizard() . '</div>';
166 } else {
167 $this->content .= '<h2>' . $this->getLanguageService()->getLL('table_title', true) . '</h2>'
168 . '<div><span class="text-danger">' . $this->getLanguageService()->getLL('table_noData', true) . '</span></div>';
169 }
170 $this->content .= '</form>';
171 // Setting up the buttons and markers for docHeader
172 $this->getButtons();
173 // Build the <body> for the module
174 $this->moduleTemplate->setContent($this->content);
175 }
176
177 /**
178 * Create the panel of buttons for submitting the form or otherwise perform operations.
179 */
180 protected function getButtons()
181 {
182 $buttonBar = $this->moduleTemplate->getDocHeaderComponent()->getButtonBar();
183 if ($this->P['table'] && $this->P['field'] && $this->P['uid']) {
184 // CSH
185 $cshButton = $buttonBar->makeHelpButton()
186 ->setModuleName('xMOD_csh_corebe')
187 ->setFieldName('wizard_table_wiz');
188 $buttonBar->addButton($cshButton);
189 // Close
190 $closeButton = $buttonBar->makeLinkButton()
191 ->setHref($this->P['returnUrl'])
192 ->setTitle($this->getLanguageService()->sL('LLL:EXT:lang/locallang_core.xlf:rm.closeDoc'))
193 ->setIcon($this->moduleTemplate->getIconFactory()->getIcon('actions-document-close', Icon::SIZE_SMALL));
194 $buttonBar->addButton($closeButton);
195 // Save
196 $saveButton = $buttonBar->makeInputButton()
197 ->setName('_savedok')
198 ->setValue('1')
199 ->setForm('TableController')
200 ->setIcon($this->moduleTemplate->getIconFactory()->getIcon('actions-document-save', Icon::SIZE_SMALL))
201 ->setTitle($this->getLanguageService()->sL('LLL:EXT:lang/locallang_core.xlf:rm.saveDoc'));
202 // Save & Close
203 $saveAndCloseButton = $buttonBar->makeInputButton()
204 ->setName('_saveandclosedok')
205 ->setValue('1')
206 ->setForm('TableController')
207 ->setTitle($this->getLanguageService()->sL('LLL:EXT:lang/locallang_core.xlf:rm.saveCloseDoc'))
208 ->setIcon($this->moduleTemplate->getIconFactory()->getIcon(
209 'actions-document-save-close',
210 Icon::SIZE_SMALL
211 ));
212 $splitButtonElement = $buttonBar->makeSplitButton()
213 ->addItem($saveButton)
214 ->addItem($saveAndCloseButton);
215
216 $buttonBar->addButton($splitButtonElement, ButtonBar::BUTTON_POSITION_LEFT, 3);
217 // Reload
218 $reloadButton = $buttonBar->makeInputButton()
219 ->setName('_refresh')
220 ->setValue('1')
221 ->setForm('TableController')
222 ->setTitle($this->getLanguageService()->getLL('forms_refresh'))
223 ->setIcon($this->moduleTemplate->getIconFactory()->getIcon('actions-refresh', Icon::SIZE_SMALL));
224 $buttonBar->addButton($reloadButton);
225 }
226 }
227
228 /**
229 * Draws the table wizard content
230 *
231 * @return string HTML content for the form.
232 * @throws \RuntimeException
233 */
234 public function tableWizard()
235 {
236 if (!$this->checkEditAccess($this->P['table'], $this->P['uid'])) {
237 throw new \RuntimeException('Wizard Error: No access', 1349692692);
238 }
239 // First, check the references by selecting the record:
240 $row = BackendUtility::getRecord($this->P['table'], $this->P['uid']);
241 if (!is_array($row)) {
242 throw new \RuntimeException('Wizard Error: No reference to record', 1294587125);
243 }
244 // This will get the content of the form configuration code field to us - possibly cleaned up,
245 // saved to database etc. if the form has been submitted in the meantime.
246 $tableCfgArray = $this->getConfigCode($row);
247 // Generation of the Table Wizards HTML code:
248 $content = $this->getTableHTML($tableCfgArray);
249 // Return content:
250 return $content;
251 }
252
253 /*
254 *
255 * Helper functions
256 *
257 */
258
259 /**
260 * Will get and return the configuration code string
261 * Will also save (and possibly redirect/exit) the content if a save button has been pressed
262 *
263 * @param array $row Current parent record row
264 * @return array Table config code in an array
265 * @internal
266 */
267 public function getConfigCode($row)
268 {
269 // Get delimiter settings
270 $flexForm = GeneralUtility::xml2array($row['pi_flexform']);
271 if (is_array($flexForm)) {
272 $this->tableParsing_quote = $flexForm['data']['s_parsing']['lDEF']['tableparsing_quote']['vDEF'] ? chr((int)$flexForm['data']['s_parsing']['lDEF']['tableparsing_quote']['vDEF']) : '';
273 $this->tableParsing_delimiter = $flexForm['data']['s_parsing']['lDEF']['tableparsing_delimiter']['vDEF'] ? chr((int)$flexForm['data']['s_parsing']['lDEF']['tableparsing_delimiter']['vDEF']) : '|';
274 }
275 // If some data has been submitted, then construct
276 if (isset($this->TABLECFG['c'])) {
277 // Process incoming:
278 $this->changeFunc();
279 // Convert to string (either line based or XML):
280 if ($this->xmlStorage) {
281 // Convert the input array to XML:
282 $bodyText = '<?xml version="1.0" encoding="utf-8" standalone="yes" ?>' . LF . GeneralUtility::array2xml($this->TABLECFG['c'], '', 0, 'T3TableWizard');
283 // Setting cfgArr directly from the input:
284 $configuration = $this->TABLECFG['c'];
285 } else {
286 // Convert the input array to a string of configuration code:
287 $bodyText = $this->cfgArray2CfgString($this->TABLECFG['c']);
288 // Create cfgArr from the string based configuration - that way it is cleaned up
289 // and any incompatibilities will be removed!
290 $configuration = $this->cfgString2CfgArray($bodyText, $row[$this->colsFieldName]);
291 }
292 // If a save button has been pressed, then save the new field content:
293 if ($_POST['_savedok'] || $_POST['_saveandclosedok']) {
294 // Get DataHandler object:
295 /** @var DataHandler $dataHandler */
296 $dataHandler = GeneralUtility::makeInstance(DataHandler::class);
297 // Put content into the data array:
298 $data = array();
299 if ($this->P['flexFormPath']) {
300 // Current value of flexForm path:
301 $currentFlexFormData = GeneralUtility::xml2array($row[$this->P['field']]);
302 /** @var FlexFormTools $flexFormTools */
303 $flexFormTools = GeneralUtility::makeInstance(FlexFormTools::class);
304 $flexFormTools->setArrayValueByPath($this->P['flexFormPath'], $currentFlexFormData, $bodyText);
305 $data[$this->P['table']][$this->P['uid']][$this->P['field']] = $currentFlexFormData;
306 } else {
307 $data[$this->P['table']][$this->P['uid']][$this->P['field']] = $bodyText;
308 }
309 // Perform the update:
310 $dataHandler->start($data, array());
311 $dataHandler->process_datamap();
312 // If the save/close button was pressed, then redirect the screen:
313 if ($_POST['_saveandclosedok']) {
314 HttpUtility::redirect(GeneralUtility::sanitizeLocalUrl($this->P['returnUrl']));
315 }
316 }
317 } else {
318 // If nothing has been submitted, load the $bodyText variable from the selected database row:
319 if ($this->xmlStorage) {
320 $configuration = GeneralUtility::xml2array($row[$this->P['field']]);
321 } else {
322 if ($this->P['flexFormPath']) {
323 // Current value of flexForm path:
324 $currentFlexFormData = GeneralUtility::xml2array($row[$this->P['field']]);
325 /** @var FlexFormTools $flexFormTools */
326 $flexFormTools = GeneralUtility::makeInstance(FlexFormTools::class);
327 $configuration = $flexFormTools->getArrayValueByPath(
328 $this->P['flexFormPath'],
329 $currentFlexFormData
330 );
331 $configuration = $this->cfgString2CfgArray($configuration, 0);
332 } else {
333 // Regular line based table configuration:
334 $configuration = $this->cfgString2CfgArray($row[$this->P['field']], $row[$this->colsFieldName]);
335 }
336 }
337 $configuration = is_array($configuration) ? $configuration : array();
338 }
339 return $configuration;
340 }
341
342 /**
343 * Creates the HTML for the Table Wizard:
344 *
345 * @param array $configuration Table config array
346 * @return string HTML for the table wizard
347 * @internal
348 */
349 public function getTableHTML($configuration)
350 {
351 // Traverse the rows:
352 $tRows = array();
353 $k = 0;
354 $countLines = count($configuration);
355 foreach ($configuration as $cellArr) {
356 if (is_array($cellArr)) {
357 // Initialize:
358 $cells = array();
359 $a = 0;
360 // Traverse the columns:
361 foreach ($cellArr as $cellContent) {
362 if ($this->inputStyle) {
363 $cells[] = '<input class="form-control" type="text" name="TABLE[c][' . ($k + 1) * 2 . '][' . ($a + 1) * 2 . ']" value="' . htmlspecialchars($cellContent) . '" />';
364 } else {
365 $cellContent = preg_replace('/<br[ ]?[\\/]?>/i', LF, $cellContent);
366 $cells[] = '<textarea class="form-control" rows="6" name="TABLE[c][' . ($k + 1) * 2 . '][' . ($a + 1) * 2 . ']">' . htmlspecialchars($cellContent) . '</textarea>';
367 }
368 // Increment counter:
369 $a++;
370 }
371 // CTRL panel for a table row (move up/down/around):
372 $onClick = 'document.wizardForm.action+=' . GeneralUtility::quoteJSvalue('#ANC_' . (($k + 1) * 2 - 2)) . ';';
373 $onClick = ' onclick="' . htmlspecialchars($onClick) . '"';
374 $ctrl = '';
375 if ($k !== 0) {
376 $ctrl .= '<button class="btn btn-default" name="TABLE[row_up][' . ($k + 1) * 2 . ']" title="' . $this->getLanguageService()->getLL('table_up', true) . '"' . $onClick . '><span class="t3-icon fa fa-fw fa-angle-up"></span></button>';
377 } else {
378 $ctrl .= '<button class="btn btn-default" name="TABLE[row_bottom][' . ($k + 1) * 2 . ']" title="' . $this->getLanguageService()->getLL('table_bottom', true) . '"' . $onClick . '><span class="t3-icon fa fa-fw fa-angle-double-down"></span></button>';
379 }
380 if ($k + 1 !== $countLines) {
381 $ctrl .= '<button class="btn btn-default" name="TABLE[row_down][' . ($k + 1) * 2 . ']" title="' . $this->getLanguageService()->getLL('table_down', true) . '"' . $onClick . '><span class="t3-icon fa fa-fw fa-angle-down"></span></button>';
382 } else {
383 $ctrl .= '<button class="btn btn-default" name="TABLE[row_top][' . ($k + 1) * 2 . ']" title="' . $this->getLanguageService()->getLL('table_top', true) . '"' . $onClick . '><span class="t3-icon fa fa-fw fa-angle-double-up"></span></button>';
384 }
385 $ctrl .= '<button class="btn btn-default" name="TABLE[row_remove][' . ($k + 1) * 2 . ']" title="' . $this->getLanguageService()->getLL('table_removeRow', true) . '"' . $onClick . '><span class="t3-icon fa fa-fw fa-trash"></span></button>';
386 $ctrl .= '<button class="btn btn-default" name="TABLE[row_add][' . ($k + 1) * 2 . ']" title="' . $this->getLanguageService()->getLL('table_addRow', true) . '"' . $onClick . '><span class="t3-icon fa fa-fw fa-plus"></span></button>';
387 $tRows[] = '
388 <tr>
389 <td>
390 <a name="ANC_' . ($k + 1) * 2 . '"></a>
391 <span class="btn-group' . ($this->inputStyle ? '' : '-vertical') . '">' . $ctrl . '</span>
392 </td>
393 <td>' . implode('</td>
394 <td>', $cells) . '</td>
395 </tr>';
396 // Increment counter:
397 $k++;
398 }
399 }
400 // CTRL panel for a table column (move left/right/around/delete)
401 $cells = array();
402 $cells[] = '';
403 // Finding first row:
404 $firstRow = reset($configuration);
405 if (is_array($firstRow)) {
406 $cols = count($firstRow);
407 for ($a = 1; $a <= $cols; $a++) {
408 $b = $a * 2;
409 $ctrl = '';
410 if ($a !== 1) {
411 $ctrl .= '<button class="btn btn-default" name="TABLE[col_left][' . $b . ']" title="' . $this->getLanguageService()->getLL('table_left', true) . '"><span class="t3-icon fa fa-fw fa-angle-left"></span></button>';
412 } else {
413 $ctrl .= '<button class="btn btn-default" name="TABLE[col_end][' . $b . ']" title="' . $this->getLanguageService()->getLL('table_end', true) . '"><span class="t3-icon fa fa-fw fa-angle-double-right"></span></button>';
414 }
415 if ($a != $cols) {
416 $ctrl .= '<button class="btn btn-default" name="TABLE[col_right][' . $b . ']" title="' . $this->getLanguageService()->getLL('table_right', true) . '"><span class="t3-icon fa fa-fw fa-angle-right"></span></button>';
417 } else {
418 $ctrl .= '<button class="btn btn-default" name="TABLE[col_start][' . $b . ']" title="' . $this->getLanguageService()->getLL('table_start', true) . '"><span class="t3-icon fa fa-fw fa-angle-double-left"></span></button>';
419 }
420 $ctrl .= '<button class="btn btn-default" name="TABLE[col_remove][' . $b . ']" title="' . $this->getLanguageService()->getLL('table_removeColumn', true) . '"><span class="t3-icon fa fa-fw fa-trash"></span></button>';
421 $ctrl .= '<button class="btn btn-default" name="TABLE[col_add][' . $b . ']" title="' . $this->getLanguageService()->getLL('table_addColumn', true) . '"><span class="t3-icon fa fa-fw fa-plus"></span></button>';
422 $cells[] = '<span class="btn-group">' . $ctrl . '</span>';
423 }
424 $tRows[] = '
425 <tfoot>
426 <tr>
427 <td>' . implode('</td>
428 <td>', $cells) . '</td>
429 </tr>
430 </tfoot>';
431 }
432 $content = '';
433 $addSubmitOnClick = 'onclick="document.getElementById(\'TableController\').submit();"';
434 // Implode all table rows into a string, wrapped in table tags.
435 $content .= '
436
437 <!-- Table wizard -->
438 <div class="table-fit table-fit-inline-block">
439 <table id="typo3-tablewizard" class="table table-center">
440 ' . implode('', $tRows) . '
441 </table>
442 </div>';
443 // Input type checkbox:
444 $content .= '
445
446 <!-- Input mode check box: -->
447 <div class="checkbox">
448 <input type="hidden" name="TABLE[textFields]" value="0" />
449 <label for="textFields">
450 <input type="checkbox" ' . $addSubmitOnClick . ' name="TABLE[textFields]" id="textFields" value="1"' . ($this->inputStyle ? ' checked="checked"' : '') . ' />
451 ' . $this->getLanguageService()->getLL('table_smallFields') . '
452 </label>
453 </div>';
454 return $content;
455 }
456
457 /**
458 * Detects if a control button (up/down/around/delete) has been pressed for an item and accordingly it will
459 * manipulate the internal TABLECFG array
460 *
461 * @return void
462 * @internal
463 */
464 public function changeFunc()
465 {
466 if ($this->TABLECFG['col_remove']) {
467 $kk = key($this->TABLECFG['col_remove']);
468 $cmd = 'col_remove';
469 } elseif ($this->TABLECFG['col_add']) {
470 $kk = key($this->TABLECFG['col_add']);
471 $cmd = 'col_add';
472 } elseif ($this->TABLECFG['col_start']) {
473 $kk = key($this->TABLECFG['col_start']);
474 $cmd = 'col_start';
475 } elseif ($this->TABLECFG['col_end']) {
476 $kk = key($this->TABLECFG['col_end']);
477 $cmd = 'col_end';
478 } elseif ($this->TABLECFG['col_left']) {
479 $kk = key($this->TABLECFG['col_left']);
480 $cmd = 'col_left';
481 } elseif ($this->TABLECFG['col_right']) {
482 $kk = key($this->TABLECFG['col_right']);
483 $cmd = 'col_right';
484 } elseif ($this->TABLECFG['row_remove']) {
485 $kk = key($this->TABLECFG['row_remove']);
486 $cmd = 'row_remove';
487 } elseif ($this->TABLECFG['row_add']) {
488 $kk = key($this->TABLECFG['row_add']);
489 $cmd = 'row_add';
490 } elseif ($this->TABLECFG['row_top']) {
491 $kk = key($this->TABLECFG['row_top']);
492 $cmd = 'row_top';
493 } elseif ($this->TABLECFG['row_bottom']) {
494 $kk = key($this->TABLECFG['row_bottom']);
495 $cmd = 'row_bottom';
496 } elseif ($this->TABLECFG['row_up']) {
497 $kk = key($this->TABLECFG['row_up']);
498 $cmd = 'row_up';
499 } elseif ($this->TABLECFG['row_down']) {
500 $kk = key($this->TABLECFG['row_down']);
501 $cmd = 'row_down';
502 } else {
503 $kk = '';
504 $cmd = '';
505 }
506 if ($cmd && MathUtility::canBeInterpretedAsInteger($kk)) {
507 if (StringUtility::beginsWith($cmd, 'row_')) {
508 switch ($cmd) {
509 case 'row_remove':
510 unset($this->TABLECFG['c'][$kk]);
511 break;
512 case 'row_add':
513 for ($a = 1; $a <= $this->numNewRows; $a++) {
514 // Checking if set: The point is that any new row between existing rows
515 // will be TRUE after one row is added while if rows are added in the bottom
516 // of the table there will be no existing rows to stop the addition of new rows
517 // which means it will add up to $this->numNewRows rows then.
518 if (!isset($this->TABLECFG['c'][$kk + $a])) {
519 $this->TABLECFG['c'][$kk + $a] = array();
520 } else {
521 break;
522 }
523 }
524 break;
525 case 'row_top':
526 $this->TABLECFG['c'][1] = $this->TABLECFG['c'][$kk];
527 unset($this->TABLECFG['c'][$kk]);
528 break;
529 case 'row_bottom':
530 $this->TABLECFG['c'][10000000] = $this->TABLECFG['c'][$kk];
531 unset($this->TABLECFG['c'][$kk]);
532 break;
533 case 'row_up':
534 $this->TABLECFG['c'][$kk - 3] = $this->TABLECFG['c'][$kk];
535 unset($this->TABLECFG['c'][$kk]);
536 break;
537 case 'row_down':
538 $this->TABLECFG['c'][$kk + 3] = $this->TABLECFG['c'][$kk];
539 unset($this->TABLECFG['c'][$kk]);
540 break;
541 }
542 ksort($this->TABLECFG['c']);
543 }
544 if (StringUtility::beginsWith($cmd, 'col_')) {
545 foreach ($this->TABLECFG['c'] as $cAK => $value) {
546 switch ($cmd) {
547 case 'col_remove':
548 unset($this->TABLECFG['c'][$cAK][$kk]);
549 break;
550 case 'col_add':
551 $this->TABLECFG['c'][$cAK][$kk + 1] = '';
552 break;
553 case 'col_start':
554 $this->TABLECFG['c'][$cAK][1] = $this->TABLECFG['c'][$cAK][$kk];
555 unset($this->TABLECFG['c'][$cAK][$kk]);
556 break;
557 case 'col_end':
558 $this->TABLECFG['c'][$cAK][1000000] = $this->TABLECFG['c'][$cAK][$kk];
559 unset($this->TABLECFG['c'][$cAK][$kk]);
560 break;
561 case 'col_left':
562 $this->TABLECFG['c'][$cAK][$kk - 3] = $this->TABLECFG['c'][$cAK][$kk];
563 unset($this->TABLECFG['c'][$cAK][$kk]);
564 break;
565 case 'col_right':
566 $this->TABLECFG['c'][$cAK][$kk + 3] = $this->TABLECFG['c'][$cAK][$kk];
567 unset($this->TABLECFG['c'][$cAK][$kk]);
568 break;
569 }
570 ksort($this->TABLECFG['c'][$cAK]);
571 }
572 }
573 }
574 // Convert line breaks to <br /> tags:
575 foreach ($this->TABLECFG['c'] as $a => $value) {
576 foreach ($this->TABLECFG['c'][$a] as $b => $value2) {
577 $this->TABLECFG['c'][$a][$b] = str_replace(
578 LF,
579 '<br />',
580 str_replace(CR, '', $this->TABLECFG['c'][$a][$b])
581 );
582 }
583 }
584 }
585
586 /**
587 * Converts the input array to a configuration code string
588 *
589 * @param array $cfgArr Array of table configuration (follows the input structure from the table wizard POST form)
590 * @return string The array converted into a string with line-based configuration.
591 * @see cfgString2CfgArray()
592 */
593 public function cfgArray2CfgString($cfgArr)
594 {
595 $inLines = array();
596 // Traverse the elements of the table wizard and transform the settings into configuration code.
597 foreach ($cfgArr as $valueA) {
598 $thisLine = array();
599 foreach ($valueA as $valueB) {
600 $thisLine[] = $this->tableParsing_quote
601 . str_replace($this->tableParsing_delimiter, '', $valueB) . $this->tableParsing_quote;
602 }
603 $inLines[] = implode($this->tableParsing_delimiter, $thisLine);
604 }
605 // Finally, implode the lines into a string:
606 return implode(LF, $inLines);
607 }
608
609 /**
610 * Converts the input configuration code string into an array
611 *
612 * @param string $configurationCode Configuration code
613 * @param int $columns Default number of columns
614 * @return array Configuration array
615 * @see cfgArray2CfgString()
616 */
617 public function cfgString2CfgArray($configurationCode, $columns)
618 {
619 // Explode lines in the configuration code - each line is a table row.
620 $tableLines = explode(LF, $configurationCode);
621 // Setting number of columns
622 // auto...
623 if (!$columns && trim($tableLines[0])) {
624 $columns = count(explode($this->tableParsing_delimiter, $tableLines[0]));
625 }
626 $columns = $columns ?: 4;
627 // Traverse the number of table elements:
628 $configurationArray = array();
629 foreach ($tableLines as $key => $value) {
630 // Initialize:
631 $valueParts = explode($this->tableParsing_delimiter, $value);
632 // Traverse columns:
633 for ($a = 0; $a < $columns; $a++) {
634 if ($this->tableParsing_quote
635 && $valueParts[$a][0] === $this->tableParsing_quote
636 && substr($valueParts[$a], -1, 1) === $this->tableParsing_quote
637 ) {
638 $valueParts[$a] = substr(trim($valueParts[$a]), 1, -1);
639 }
640 $configurationArray[$key][$a] = $valueParts[$a];
641 }
642 }
643 return $configurationArray;
644 }
645 }