f213487e68c815416dfa465d3c717b838add7c0c
[Packages/TYPO3.CMS.git] / typo3 / sysext / impexp / Classes / Controller / ImportExportController.php
1 <?php
2 namespace TYPO3\CMS\Impexp\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\Database\DatabaseConnection;
19 use TYPO3\CMS\Core\Resource\ResourceFactory;
20 use TYPO3\CMS\Core\Utility\GeneralUtility;
21 use TYPO3\CMS\Backend\Utility\BackendUtility;
22 use TYPO3\CMS\Core\Utility\MathUtility;
23 use TYPO3\CMS\Core\Utility\PathUtility;
24 use TYPO3\CMS\Lang\LanguageService;
25
26 /**
27 * Main script class for the Import / Export facility
28 *
29 * @author Kasper Skårhøj <kasperYYYY@typo3.com>
30 */
31 class ImportExportController extends \TYPO3\CMS\Backend\Module\BaseScriptClass {
32
33 /**
34 * @var array|\TYPO3\CMS\Core\Resource\File[]
35 */
36 protected $uploadedFiles = array();
37
38 /**
39 * Array containing the current page.
40 *
41 * @var array
42 */
43 public $pageinfo;
44
45 /**
46 * @var \TYPO3\CMS\Impexp\ImportExport
47 */
48 protected $export;
49
50 /**
51 * @var \TYPO3\CMS\Impexp\ImportExport
52 */
53 protected $import;
54
55 /**
56 * @var \TYPO3\CMS\Core\Utility\File\ExtendedFileUtility
57 */
58 protected $fileProcessor;
59
60 /**
61 * @var string
62 */
63 protected $vC = '';
64
65 /**
66 * @var LanguageService
67 */
68 protected $lang = NULL;
69
70 /**
71 * @var string
72 */
73 protected $treeHTML = '';
74
75 /**
76 * @return void
77 */
78 public function init() {
79 parent::init();
80 $this->vC = GeneralUtility::_GP('vC');
81 $this->lang = $this->getLanguageService();
82 }
83
84 /**
85 * Main module function
86 *
87 * @throws \BadFunctionCallException
88 * @throws \InvalidArgumentException
89 * @return void
90 */
91 public function main() {
92 $this->lang->includeLLFile('EXT:impexp/app/locallang.xlf');
93 // Start document template object:
94 $this->doc = GeneralUtility::makeInstance(\TYPO3\CMS\Backend\Template\DocumentTemplate::class);
95 $this->doc->backPath = $GLOBALS['BACK_PATH'];
96 $this->doc->bodyTagId = 'imp-exp-mod';
97 $this->doc->setModuleTemplate(\TYPO3\CMS\Core\Utility\ExtensionManagementUtility::extRelPath('impexp') . '/app/template.html');
98 $this->pageinfo = BackendUtility::readPageAccess($this->id, $this->perms_clause);
99 // Setting up the context sensitive menu:
100 $this->doc->getContextMenuCode();
101 $this->doc->postCode = $this->doc->wrapScriptTags('if (top.fsMod) top.fsMod.recentIds["web"] = ' . (int)$this->id . ';');
102 $this->doc->form = '<form action="' . htmlspecialchars(BackendUtility::getModuleUrl('xMOD_tximpexp')) . '" method="post" enctype="'
103 . $GLOBALS['TYPO3_CONF_VARS']['SYS']['form_enctype'] . '"><input type="hidden" name="id" value="' . $this->id . '" />';
104 $this->content .= $this->doc->header($this->lang->getLL('title'));
105 $this->content .= $this->doc->spacer(5);
106 // Input data grabbed:
107 $inData = GeneralUtility::_GP('tx_impexp');
108 $this->checkUpload();
109 switch ((string)$inData['action']) {
110 case 'export':
111 // Finally: If upload went well, set the new file as the thumbnail in the $inData array:
112 if (!empty($this->uploadedFiles[0])) {
113 $inData['meta']['thumbnail'] = $this->uploadedFiles[0]->getCombinedIdentifier();
114 }
115 // Call export interface
116 $this->exportData($inData);
117 break;
118 case 'import':
119 // Finally: If upload went well, set the new file as the import file:
120 if (!empty($this->uploadedFiles[0])) {
121 // Only allowed extensions....
122 if (GeneralUtility::inList('t3d,xml', $this->uploadedFiles[0]->getExtension())) {
123 $inData['file'] = $this->uploadedFiles[0]->getCombinedIdentifier();
124 }
125 }
126 // Call import interface:
127 $this->importData($inData);
128 break;
129 }
130 // Setting up the buttons and markers for docheader
131 $docHeaderButtons = $this->getButtons();
132 $markers['CONTENT'] = $this->content;
133 // Build the <body> for the module
134 $this->content = $this->doc->startPage($this->lang->getLL('title'));
135 $this->content .= $this->doc->moduleBody($this->pageinfo, $docHeaderButtons, $markers);
136 $this->content .= $this->doc->endPage();
137 $this->content = $this->doc->insertStylesAndJS($this->content);
138 }
139
140 /**
141 * Print the content
142 *
143 * @return void
144 */
145 public function printContent() {
146 echo $this->content;
147 }
148
149 /**
150 * Create the panel of buttons for submitting the form or otherwise perform operations.
151 *
152 * @return array all available buttons as an associated array
153 */
154 protected function getButtons() {
155 $buttons = array(
156 'view' => '',
157 'shortcut' => ''
158 );
159 if ($this->getBackendUser()->mayMakeShortcut()) {
160 $buttons['shortcut'] = $this->doc->makeShortcutIcon('tx_impexp', '', $this->MCONF['name']);
161 }
162 // Input data grabbed:
163 $inData = GeneralUtility::_GP('tx_impexp');
164 if ((string)$inData['action'] == 'import') {
165 if ($this->id && is_array($this->pageinfo) || $this->getBackendUser()->user['admin'] && !$this->id) {
166 if (is_array($this->pageinfo) && $this->pageinfo['uid']) {
167 // View
168 $onClick = BackendUtility::viewOnClick(
169 $this->pageinfo['uid'],
170 $this->doc->backPath,
171 BackendUtility::BEgetRootLine($this->pageinfo['uid'])
172 );
173 $title = $this->lang->sL('LLL:EXT:lang/locallang_core.xlf:labels.showPage', TRUE);
174 $buttons['view'] = '<a href="#" onclick="' . htmlspecialchars($onClick) . '" title="' . $title . '">'
175 . IconUtility::getSpriteIcon('actions-document-view') . '</a>';
176 }
177 }
178 }
179 return $buttons;
180 }
181
182 /**************************
183 * EXPORT FUNCTIONS
184 **************************/
185
186 /**
187 * Export part of module
188 * Setting content in $this->content
189 *
190 * @param array $inData Content of POST VAR tx_impexp[]..
191 * @throws \InvalidArgumentException
192 * @throws \RuntimeException
193 * @throws \TYPO3\CMS\Core\Resource\Exception\ExistingTargetFileNameException
194 * @return void
195 */
196 public function exportData($inData) {
197 // BUILDING EXPORT DATA:
198 // Processing of InData array values:
199 $inData['pagetree']['maxNumber'] = MathUtility::forceIntegerInRange($inData['pagetree']['maxNumber'], 1, 1000000, 100);
200 $inData['listCfg']['maxNumber'] = MathUtility::forceIntegerInRange($inData['listCfg']['maxNumber'], 1, 1000000, 100);
201 $inData['maxFileSize'] = MathUtility::forceIntegerInRange($inData['maxFileSize'], 1, 1000000, 1000);
202 $inData['filename'] = trim(preg_replace('/[^[:alnum:]._-]*/', '', preg_replace('/\\.(t3d|xml)$/', '', $inData['filename'])));
203 if (strlen($inData['filename'])) {
204 $inData['filename'] .= $inData['filetype'] == 'xml' ? '.xml' : '.t3d';
205 }
206 // Set exclude fields in export object:
207 if (!is_array($inData['exclude'])) {
208 $inData['exclude'] = array();
209 }
210 // Saving/Loading/Deleting presets:
211 $this->processPresets($inData);
212 // Create export object and configure it:
213 $this->export = GeneralUtility::makeInstance(\TYPO3\CMS\Impexp\ImportExport::class);
214 $this->export->init(0, 'export');
215 $this->export->setCharset($this->lang->charSet);
216 $this->export->maxFileSize = $inData['maxFileSize'] * 1024;
217 $this->export->excludeMap = (array)$inData['exclude'];
218 $this->export->softrefCfg = (array)$inData['softrefCfg'];
219 $this->export->extensionDependencies = (array)$inData['extension_dep'];
220 $this->export->showStaticRelations = $inData['showStaticRelations'];
221 $this->export->includeExtFileResources = !$inData['excludeHTMLfileResources'];
222 // Static tables:
223 if (is_array($inData['external_static']['tables'])) {
224 $this->export->relStaticTables = $inData['external_static']['tables'];
225 }
226 // Configure which tables external relations are included for:
227 if (is_array($inData['external_ref']['tables'])) {
228 $this->export->relOnlyTables = $inData['external_ref']['tables'];
229 }
230 $saveFilesOutsideExportFile = FALSE;
231 if (isset($inData['save_export']) && isset($inData['saveFilesOutsideExportFile']) && $inData['saveFilesOutsideExportFile'] === '1') {
232 $this->export->setSaveFilesOutsideExportFile(TRUE);
233 $saveFilesOutsideExportFile = TRUE;
234 }
235 $this->export->setHeaderBasics();
236 // Meta data setting:
237
238 $beUser = $this->getBackendUser();
239 $this->export->setMetaData(
240 $inData['meta']['title'],
241 $inData['meta']['description'],
242 $inData['meta']['notes'],
243 $beUser->user['username'],
244 $beUser->user['realName'],
245 $beUser->user['email']
246 );
247 if ($inData['meta']['thumbnail']) {
248 $theThumb = $this->getFile($inData['meta']['thumbnail']);
249 if ($theThumb !== NULL && $theThumb->exists()) {
250 $this->export->addThumbnail($theThumb->getForLocalProcessing(FALSE));
251 }
252 }
253 // Configure which records to export
254 if (is_array($inData['record'])) {
255 foreach ($inData['record'] as $ref) {
256 $rParts = explode(':', $ref);
257 $this->export->export_addRecord($rParts[0], BackendUtility::getRecord($rParts[0], $rParts[1]));
258 }
259 }
260 // Configure which tables to export
261 if (is_array($inData['list'])) {
262 $db = $this->getDatabaseConnection();
263 foreach ($inData['list'] as $ref) {
264 $rParts = explode(':', $ref);
265 if ($beUser->check('tables_select', $rParts[0])) {
266 $res = $this->exec_listQueryPid($rParts[0], $rParts[1], MathUtility::forceIntegerInRange($inData['listCfg']['maxNumber'], 1));
267 while ($subTrow = $db->sql_fetch_assoc($res)) {
268 $this->export->export_addRecord($rParts[0], $subTrow);
269 }
270 $db->sql_free_result($res);
271 }
272 }
273 }
274 // Pagetree
275 if (isset($inData['pagetree']['id'])) {
276 // Based on click-expandable tree
277 $idH = NULL;
278 if ($inData['pagetree']['levels'] == -1) {
279 $pagetree = GeneralUtility::makeInstance(\TYPO3\CMS\Impexp\LocalPageTree::class);
280 $tree = $pagetree->ext_tree($inData['pagetree']['id'], $this->filterPageIds($this->export->excludeMap));
281 $this->treeHTML = $pagetree->printTree($tree);
282 $idH = $pagetree->buffer_idH;
283 } elseif ($inData['pagetree']['levels'] == -2) {
284 $this->addRecordsForPid($inData['pagetree']['id'], $inData['pagetree']['tables'], $inData['pagetree']['maxNumber']);
285 } else {
286 // Based on depth
287 // Drawing tree:
288 // If the ID is zero, export root
289 if (!$inData['pagetree']['id'] && $beUser->isAdmin()) {
290 $sPage = array(
291 'uid' => 0,
292 'title' => 'ROOT'
293 );
294 } else {
295 $sPage = BackendUtility::getRecordWSOL('pages', $inData['pagetree']['id'], '*', ' AND ' . $this->perms_clause);
296 }
297 if (is_array($sPage)) {
298 $pid = $inData['pagetree']['id'];
299 $tree = GeneralUtility::makeInstance(\TYPO3\CMS\Backend\Tree\View\PageTreeView::class);
300 $tree->init('AND ' . $this->perms_clause . $this->filterPageIds($this->export->excludeMap));
301 $HTML = IconUtility::getSpriteIconForRecord('pages', $sPage);
302 $tree->tree[] = array('row' => $sPage, 'HTML' => $HTML);
303 $tree->buffer_idH = array();
304 if ($inData['pagetree']['levels'] > 0) {
305 $tree->getTree($pid, $inData['pagetree']['levels'], '');
306 }
307 $idH = array();
308 $idH[$pid]['uid'] = $pid;
309 if (count($tree->buffer_idH)) {
310 $idH[$pid]['subrow'] = $tree->buffer_idH;
311 }
312 $pagetree = GeneralUtility::makeInstance(\TYPO3\CMS\Impexp\LocalPageTree::class);
313 $this->treeHTML = $pagetree->printTree($tree->tree);
314 }
315 }
316 // In any case we should have a multi-level array, $idH, with the page structure
317 // here (and the HTML-code loaded into memory for nice display...)
318 if (is_array($idH)) {
319 // Sets the pagetree and gets a 1-dim array in return with the pages (in correct submission order BTW...)
320 $flatList = $this->export->setPageTree($idH);
321 foreach ($flatList as $k => $value) {
322 $this->export->export_addRecord('pages', BackendUtility::getRecord('pages', $k));
323 $this->addRecordsForPid($k, $inData['pagetree']['tables'], $inData['pagetree']['maxNumber']);
324 }
325 }
326 }
327 // After adding ALL records we set relations:
328 for ($a = 0; $a < 10; $a++) {
329 $addR = $this->export->export_addDBRelations($a);
330 if (!count($addR)) {
331 break;
332 }
333 }
334 // Finally files are added:
335 // MUST be after the DBrelations are set so that files from ALL added records are included!
336 $this->export->export_addFilesFromRelations();
337
338 $this->export->export_addFilesFromSysFilesRecords();
339
340 // If the download button is clicked, return file
341 if ($inData['download_export'] || $inData['save_export']) {
342 switch ((string)$inData['filetype']) {
343 case 'xml':
344 $out = $this->export->compileMemoryToFileContent('xml');
345 $fExt = '.xml';
346 break;
347 case 't3d':
348 $this->export->dontCompress = 1;
349 // intentional fall-through
350 default:
351 $out = $this->export->compileMemoryToFileContent();
352 $fExt = ($this->export->doOutputCompress() ? '-z' : '') . '.t3d';
353 }
354 // Filename:
355 $dlFile = $inData['filename'];
356 if (!$dlFile) {
357 $exportName = substr(preg_replace('/[^[:alnum:]_]/', '-', $inData['download_export_name']), 0, 20);
358 $dlFile = 'T3D_' . $exportName . '_' . date('Y-m-d_H-i') . $fExt;
359 }
360
361 // Export for download:
362 if ($inData['download_export']) {
363 $mimeType = 'application/octet-stream';
364 Header('Content-Type: ' . $mimeType);
365 Header('Content-Length: ' . strlen($out));
366 Header('Content-Disposition: attachment; filename=' . basename($dlFile));
367 echo $out;
368 die;
369 }
370 // Export by saving:
371 if ($inData['save_export']) {
372 $saveFolder = $this->getDefaultImportExportFolder();
373 if ($saveFolder !== FALSE && $saveFolder->checkActionPermission('write')) {
374 $temporaryFileName = GeneralUtility::tempnam('export');
375 file_put_contents($temporaryFileName, $out);
376 $file = $saveFolder->addFile($temporaryFileName, $dlFile, 'replace');
377 if ($saveFilesOutsideExportFile) {
378 $filesFolderName = $dlFile . '.files';
379 $filesFolder = $saveFolder->createFolder($filesFolderName);
380 $temporaryFolderForExport = ResourceFactory::getInstance()->retrieveFileOrFolderObject($this->export->getTemporaryFilesPathForExport());
381 $temporaryFilesForExport = $temporaryFolderForExport->getFiles();
382 foreach ($temporaryFilesForExport as $temporaryFileForExport) {
383 $filesFolder->getStorage()->moveFile($temporaryFileForExport, $filesFolder);
384 }
385 $temporaryFolderForExport->delete();
386 }
387
388 $this->content .= $this->doc->section($GLOBALS['LANG']->getLL('exportdata_savedFile'), sprintf($GLOBALS['LANG']->getLL('exportdata_savedInSBytes', TRUE), $file->getPublicUrl(), GeneralUtility::formatSize(strlen($out))), 0, 1);
389 } else {
390 $this->content .= $this->doc->section($GLOBALS['LANG']->getLL('exportdata_problemsSavingFile'), sprintf($GLOBALS['LANG']->getLL('exportdata_badPathS', TRUE), $this->getTemporaryFolderPath()), 0, 1, 2);
391 }
392 }
393 }
394 // OUTPUT to BROWSER:
395 // Now, if we didn't make download file, show configuration form based on export:
396 $menuItems = array();
397 // Export configuration
398 $row = array();
399 $this->makeConfigurationForm($inData, $row);
400 $menuItems[] = array(
401 'label' => $this->lang->getLL('tableselec_configuration'),
402 'content' => '
403 <table border="0" cellpadding="1" cellspacing="1">
404 ' . implode('
405 ', $row) . '
406 </table>
407 '
408 );
409 // File options
410 $row = array();
411 $this->makeSaveForm($inData, $row);
412 $menuItems[] = array(
413 'label' => $this->lang->getLL('exportdata_filePreset'),
414 'content' => '
415 <table border="0" cellpadding="1" cellspacing="1">
416 ' . implode('
417 ', $row) . '
418 </table>
419 '
420 );
421 // File options
422 $row = array();
423 $this->makeAdvancedOptionsForm($inData, $row);
424 $menuItems[] = array(
425 'label' => $this->lang->getLL('exportdata_advancedOptions'),
426 'content' => '
427 <table border="0" cellpadding="1" cellspacing="1">
428 ' . implode('
429 ', $row) . '
430 </table>
431 '
432 );
433 // Generate overview:
434 $overViewContent = $this->export->displayContentOverview();
435 // Print errors that might be:
436 $errors = $this->export->printErrorLog();
437 $menuItems[] = array(
438 'label' => $this->lang->getLL('exportdata_messages'),
439 'content' => $errors,
440 'stateIcon' => $errors ? 2 : 0
441 );
442 // Add hidden fields and create tabs:
443 $content = $this->doc->getDynTabMenu($menuItems, 'tx_impexp_export', -1);
444 $content .= '<input type="hidden" name="tx_impexp[action]" value="export" />';
445 $this->content .= $this->doc->section('', $content, 0, 1);
446 // Output Overview:
447 $this->content .= $this->doc->section($this->lang->getLL('execlistqu_structureToBeExported'), $overViewContent, 0, 1);
448 }
449
450 /**
451 * Adds records to the export object for a specific page id.
452 *
453 * @param int $k Page id for which to select records to add
454 * @param array $tables Array of table names to select from
455 * @param int $maxNumber Max amount of records to select
456 * @return void
457 */
458 public function addRecordsForPid($k, $tables, $maxNumber) {
459 if (!is_array($tables)) {
460 return;
461 }
462 $db = $this->getDatabaseConnection();
463 foreach ($GLOBALS['TCA'] as $table => $value) {
464 if ($table != 'pages' && (in_array($table, $tables) || in_array('_ALL', $tables))) {
465 if ($this->getBackendUser()->check('tables_select', $table) && !$GLOBALS['TCA'][$table]['ctrl']['is_static']) {
466 $res = $this->exec_listQueryPid($table, $k, MathUtility::forceIntegerInRange($maxNumber, 1));
467 while ($subTrow = $db->sql_fetch_assoc($res)) {
468 $this->export->export_addRecord($table, $subTrow);
469 }
470 $db->sql_free_result($res);
471 }
472 }
473 }
474 }
475
476 /**
477 * Selects records from table / pid
478 *
479 * @param string $table Table to select from
480 * @param int $pid Page ID to select from
481 * @param int $limit Max number of records to select
482 * @return \mysqli_result|object Database resource
483 */
484 public function exec_listQueryPid($table, $pid, $limit) {
485 $db = $this->getDatabaseConnection();
486 $orderBy = $GLOBALS['TCA'][$table]['ctrl']['sortby']
487 ? 'ORDER BY ' . $GLOBALS['TCA'][$table]['ctrl']['sortby']
488 : $GLOBALS['TCA'][$table]['ctrl']['default_sortby'];
489 $res = $db->exec_SELECTquery(
490 '*',
491 $table,
492 'pid=' . (int)$pid . BackendUtility::deleteClause($table) . BackendUtility::versioningPlaceholderClause($table),
493 '',
494 $db->stripOrderBy($orderBy),
495 $limit
496 );
497 // Warning about hitting limit:
498 if ($db->sql_num_rows($res) == $limit) {
499 $limitWarning = sprintf($this->lang->getLL('makeconfig_anSqlQueryReturned', TRUE), $limit);
500 $this->content .= $this->doc->section($this->lang->getLL('execlistqu_maxNumberLimit'), $limitWarning, 0, 1, 2);
501 }
502 return $res;
503 }
504
505 /**
506 * Create configuration form
507 *
508 * @param array $inData Form configurat data
509 * @param array $row Table row accumulation variable. This is filled with table rows.
510 * @return void Sets content in $this->content
511 */
512 public function makeConfigurationForm($inData, &$row) {
513 $nameSuggestion = '';
514 // Page tree export options:
515 if (isset($inData['pagetree']['id'])) {
516 $nameSuggestion .= 'tree_PID' . $inData['pagetree']['id'] . '_L' . $inData['pagetree']['levels'];
517 $row[] = '
518 <tr class="tableheader bgColor5">
519 <td colspan="2">' . $this->lang->getLL('makeconfig_exportPagetreeConfiguration', TRUE)
520 . BackendUtility::cshItem('xMOD_tx_impexp', 'pageTreeCfg') . '</td>
521 </tr>';
522 $row[] = '
523 <tr class="bgColor4">
524 <td><strong>' . $this->lang->getLL('makeconfig_pageId', TRUE) . '</strong></td>
525 <td>' . htmlspecialchars($inData['pagetree']['id']) . '<input type="hidden" value="'
526 . htmlspecialchars($inData['pagetree']['id']) . '" name="tx_impexp[pagetree][id]" /></td>
527 </tr>';
528 $row[] = '
529 <tr class="bgColor4">
530 <td><strong>' . $this->lang->getLL('makeconfig_tree', TRUE) . '</strong>'
531 . BackendUtility::cshItem('xMOD_tx_impexp', 'pageTreeDisplay') . '</td>
532 <td>' . ($this->treeHTML ?: $this->lang->getLL('makeconfig_noTreeExportedOnly', TRUE)) . '</td>
533 </tr>';
534 $opt = array(
535 '-2' => $this->lang->getLL('makeconfig_tablesOnThisPage'),
536 '-1' => $this->lang->getLL('makeconfig_expandedTree'),
537 '0' => $this->lang->getLL('makeconfig_onlyThisPage'),
538 '1' => $this->lang->getLL('makeconfig_1Level'),
539 '2' => $this->lang->getLL('makeconfig_2Levels'),
540 '3' => $this->lang->getLL('makeconfig_3Levels'),
541 '4' => $this->lang->getLL('makeconfig_4Levels'),
542 '999' => $this->lang->getLL('makeconfig_infinite')
543 );
544 $row[] = '
545 <tr class="bgColor4">
546 <td><strong>' . $this->lang->getLL('makeconfig_levels', TRUE) . '</strong>'
547 . BackendUtility::cshItem('xMOD_tx_impexp', 'pageTreeMode') . '</td>
548 <td>' . $this->renderSelectBox('tx_impexp[pagetree][levels]', $inData['pagetree']['levels'], $opt) . '</td>
549 </tr>';
550 $row[] = '
551 <tr class="bgColor4">
552 <td><strong>' . $this->lang->getLL('makeconfig_includeTables', TRUE) . '</strong>'
553 . BackendUtility::cshItem('xMOD_tx_impexp', 'pageTreeRecordLimit') . '</td>
554 <td>' . $this->tableSelector('tx_impexp[pagetree][tables]', $inData['pagetree']['tables'], 'pages') . '<br/>
555 ' . $this->lang->getLL('makeconfig_maxNumberOfRecords', TRUE) . '<br/>
556 <input type="text" name="tx_impexp[pagetree][maxNumber]" value="'
557 . htmlspecialchars($inData['pagetree']['maxNumber']) . '"' . $this->doc->formWidth(10) . ' /><br/>
558 </td>
559 </tr>';
560 }
561 // Single record export:
562 if (is_array($inData['record'])) {
563 $row[] = '
564 <tr class="tableheader bgColor5">
565 <td colspan="2">' . $this->lang->getLL('makeconfig_exportSingleRecord', TRUE)
566 . BackendUtility::cshItem('xMOD_tx_impexp', 'singleRecord') . '</td>
567 </tr>';
568 foreach ($inData['record'] as $ref) {
569 $rParts = explode(':', $ref);
570 $tName = $rParts[0];
571 $rUid = $rParts[1];
572 $nameSuggestion .= $tName . '_' . $rUid;
573 $rec = BackendUtility::getRecordWSOL($tName, $rUid);
574 $row[] = '
575 <tr class="bgColor4">
576 <td><strong>' . $this->lang->getLL('makeconfig_record', TRUE) . '</strong></td>
577 <td>' . IconUtility::getSpriteIconForRecord($tName, $rec) . BackendUtility::getRecordTitle($tName, $rec, TRUE)
578 . '<input type="hidden" name="tx_impexp[record][]" value="' . htmlspecialchars(($tName . ':' . $rUid)) . '" /></td>
579 </tr>';
580 }
581 }
582 // Single tables/pids:
583 if (is_array($inData['list'])) {
584 $row[] = '
585 <tr class="tableheader bgColor5">
586 <td colspan="2">' . $this->lang->getLL('makeconfig_exportTablesFromPages', TRUE) . '</td>
587 </tr>';
588 // Display information about pages from which the export takes place
589 $tblList = '';
590 foreach ($inData['list'] as $reference) {
591 $referenceParts = explode(':', $reference);
592 $tableName = $referenceParts[0];
593 if ($this->getBackendUser()->check('tables_select', $tableName)) {
594 // If the page is actually the root, handle it differently
595 // NOTE: we don't compare integers, because the number actually comes from the split string above
596 if ($referenceParts[1] === '0') {
597 $iconAndTitle = IconUtility::getSpriteIcon('apps-pagetree-root') . $GLOBALS['TYPO3_CONF_VARS']['SYS']['sitename'];
598 } else {
599 $record = BackendUtility::getRecordWSOL('pages', $referenceParts[1]);
600 $iconAndTitle = IconUtility::getSpriteIconForRecord('pages', $record)
601 . BackendUtility::getRecordTitle('pages', $record, TRUE);
602 }
603 $tblList .= 'Table "' . $tableName . '" from ' . $iconAndTitle
604 . '<input type="hidden" name="tx_impexp[list][]" value="' . htmlspecialchars($reference) . '" /><br/>';
605 }
606 }
607 $row[] = '
608 <tr class="bgColor4">
609 <td><strong>' . $this->lang->getLL('makeconfig_tablePids', TRUE) . '</strong>'
610 . BackendUtility::cshItem('xMOD_tx_impexp', 'tableList') . '</td>
611 <td>' . $tblList . '</td>
612 </tr>';
613 $row[] = '
614 <tr class="bgColor4">
615 <td><strong>' . $this->lang->getLL('makeconfig_maxNumberOfRecords', TRUE)
616 . BackendUtility::cshItem('xMOD_tx_impexp', 'tableListMaxNumber') . '</strong></td>
617 <td>
618 <input type="text" name="tx_impexp[listCfg][maxNumber]" value="'
619 . htmlspecialchars($inData['listCfg']['maxNumber']) . '"' . $this->doc->formWidth(10) . ' /><br/>
620 </td>
621 </tr>';
622 }
623 $row[] = '
624 <tr class="tableheader bgColor5">
625 <td colspan="2">' . $this->lang->getLL('makeconfig_relationsAndExclusions', TRUE) . '</td>
626 </tr>';
627 // Add relation selector:
628 $row[] = '
629 <tr class="bgColor4">
630 <td><strong>' . $this->lang->getLL('makeconfig_includeRelationsToTables', TRUE) . '</strong>'
631 . BackendUtility::cshItem('xMOD_tx_impexp', 'inclRelations') . '</td>
632 <td>' . $this->tableSelector('tx_impexp[external_ref][tables]', $inData['external_ref']['tables']) . '</td>
633 </tr>';
634 // Add static relation selector:
635 $row[] = '
636 <tr class="bgColor4">
637 <td><strong>' . $this->lang->getLL('makeconfig_useStaticRelationsFor', TRUE) . '</strong>'
638 . BackendUtility::cshItem('xMOD_tx_impexp', 'staticRelations') . '</td>
639 <td>' . $this->tableSelector('tx_impexp[external_static][tables]', $inData['external_static']['tables']) . '<br/>
640 <label for="checkShowStaticRelations">' . $this->lang->getLL('makeconfig_showStaticRelations', TRUE)
641 . '</label> <input type="checkbox" name="tx_impexp[showStaticRelations]" id="checkShowStaticRelations" value="1"'
642 . ($inData['showStaticRelations'] ? ' checked="checked"' : '') . ' />
643 </td>
644 </tr>';
645 // Exclude:
646 $excludeHiddenFields = '';
647 if (is_array($inData['exclude'])) {
648 foreach ($inData['exclude'] as $key => $value) {
649 $excludeHiddenFields .= '<input type="hidden" name="tx_impexp[exclude][' . $key . ']" value="1" />';
650 }
651 }
652 if (count($inData['exclude'])) {
653 $excludedElements = '<em>' . implode(', ', array_keys($inData['exclude'])) . '</em><hr/><label for="checkExclude">'
654 . $this->lang->getLL('makeconfig_clearAllExclusions', TRUE)
655 . '</label> <input type="checkbox" name="tx_impexp[exclude]" id="checkExclude" value="1" />';
656 } else {
657 $excludedElements = $this->lang->getLL('makeconfig_noExcludedElementsYet', TRUE);
658 }
659 $row[] = '
660 <tr class="bgColor4">
661 <td><strong>' . $this->lang->getLL('makeconfig_excludeElements', TRUE) . '</strong>'
662 . BackendUtility::cshItem('xMOD_tx_impexp', 'excludedElements') . '</td>
663 <td>' . $excludeHiddenFields . '
664 ' . $excludedElements . '
665 </td>
666 </tr>';
667 // Add buttons:
668 $row[] = '
669 <tr class="bgColor4">
670 <td>&nbsp;</td>
671 <td>
672 <input class="btn btn-default" type="submit" value="' . $this->lang->getLL('makeadvanc_update', TRUE) . '" />
673 <input type="hidden" name="tx_impexp[download_export_name]" value="' . substr($nameSuggestion, 0, 30) . '" />
674 </td>
675 </tr>';
676 }
677
678 /**
679 * Create advanced options form
680 * Sets content in $this->content
681 *
682 * @param array $inData Form configurat data
683 * @param array $row Table row accumulation variable. This is filled with table rows.
684 * @return void
685 */
686 public function makeAdvancedOptionsForm($inData, &$row) {
687 // Soft references
688 $row[] = '
689 <tr class="tableheader bgColor5">
690 <td colspan="2">' . $this->lang->getLL('makeadvanc_softReferences', TRUE) . '</td>
691 </tr>';
692 $row[] = '
693 <tr class="bgColor4">
694 <td><label for="checkExcludeHTMLfileResources"><strong>'
695 . $this->lang->getLL('makeadvanc_excludeHtmlCssFile', TRUE) . '</strong></label>'
696 . BackendUtility::cshItem('xMOD_tx_impexp', 'htmlCssResources') . '</td>
697 <td><input type="checkbox" name="tx_impexp[excludeHTMLfileResources]" id="checkExcludeHTMLfileResources" value="1"'
698 . ($inData['excludeHTMLfileResources'] ? ' checked="checked"' : '') . ' /></td>
699 </tr>';
700
701 // Files options
702 $row[] = '
703 <tr class="tableheader bgColor5">
704 <td colspan="2">' . $this->lang->getLL('makeadvanc_files', TRUE) . '</td>
705 </tr>';
706 $row[] = '
707 <tr class="bgColor4">
708 <td><label for="saveFilesOutsideExportFile"><strong>'
709 . $this->lang->getLL('makeadvanc_saveFilesOutsideExportFile', TRUE) . '</strong><br />'
710 . $this->lang->getLL('makeadvanc_saveFilesOutsideExportFile_limit', TRUE) . '</label></td>
711 <td><input type="checkbox" name="tx_impexp[saveFilesOutsideExportFile]" id="saveFilesOutsideExportFile" value="1"'
712 . ($inData['saveFilesOutsideExportFile'] ? ' checked="checked"' : '') . ' /></td>
713 </tr>';
714 // Extensions
715 $row[] = '
716 <tr class="tableheader bgColor5">
717 <td colspan="2">' . $this->lang->getLL('makeadvanc_extensionDependencies', TRUE) . '</td>
718 </tr>';
719 $row[] = '
720 <tr class="bgColor4">
721 <td><strong>' . $this->lang->getLL('makeadvanc_selectExtensionsThatThe', TRUE) . '</strong>'
722 . BackendUtility::cshItem('xMOD_tx_impexp', 'extensionDependencies') . '</td>
723 <td>' . $this->extensionSelector('tx_impexp[extension_dep]', $inData['extension_dep']) . '</td>
724 </tr>';
725 // Add buttons:
726 $row[] = '
727 <tr class="bgColor4">
728 <td>&nbsp;</td>
729 <td>
730 <input class="btn btn-default" type="submit" value="' . $this->lang->getLL('makesavefo_update', TRUE) . '" />
731 <input type="hidden" name="tx_impexp[download_export_name]" value="" />
732 </td>
733 </tr>';
734 }
735
736 /**
737 * Create configuration form
738 *
739 * @param array $inData Form configurat data
740 * @param array $row Table row accumulation variable. This is filled with table rows.
741 * @return void Sets content in $this->content
742 */
743 public function makeSaveForm($inData, &$row) {
744 // Presets:
745 $row[] = '
746 <tr class="tableheader bgColor5">
747 <td colspan="2">' . $this->lang->getLL('makesavefo_presets', TRUE) . '</td>
748 </tr>';
749 $opt = array('');
750 $where = '(public>0 OR user_uid=' . (int)$this->getBackendUser()->user['uid'] . ')'
751 . ($inData['pagetree']['id'] ? ' AND (item_uid=' . (int)$inData['pagetree']['id'] . ' OR item_uid=0)' : '');
752 $presets = $this->getDatabaseConnection()->exec_SELECTgetRows('*', 'tx_impexp_presets', $where);
753 if (is_array($presets)) {
754 foreach ($presets as $presetCfg) {
755 $opt[$presetCfg['uid']] = $presetCfg['title'] . ' [' . $presetCfg['uid'] . ']'
756 . ($presetCfg['public'] ? ' [Public]' : '')
757 . ($presetCfg['user_uid'] === $this->getBackendUser()->user['uid'] ? ' [Own]' : '');
758 }
759 }
760 $row[] = '
761 <tr class="bgColor4">
762 <td><strong>' . $this->lang->getLL('makesavefo_presets', TRUE) . '</strong>'
763 . BackendUtility::cshItem('xMOD_tx_impexp', 'presets') . '</td>
764 <td>
765 ' . $this->lang->getLL('makesavefo_selectPreset', TRUE) . '<br/>
766 ' . $this->renderSelectBox('preset[select]', '', $opt) . '
767 <br/>
768 <input class="btn btn-default" type="submit" value="' . $this->lang->getLL('makesavefo_load', TRUE) . '" name="preset[load]" />
769 <input class="btn btn-default" type="submit" value="' . $this->lang->getLL('makesavefo_save', TRUE) . '" name="preset[save]" onclick="return confirm(\'' . $this->lang->getLL('makesavefo_areYouSure', TRUE) . '\');" />
770 <input class="btn btn-default" type="submit" value="' . $this->lang->getLL('makesavefo_delete', TRUE) . '" name="preset[delete]" onclick="return confirm(\'' . $this->lang->getLL('makesavefo_areYouSure', TRUE) . '\');" />
771 <input class="btn btn-default" type="submit" value="' . $this->lang->getLL('makesavefo_merge', TRUE) . '" name="preset[merge]" onclick="return confirm(\'' . $this->lang->getLL('makesavefo_areYouSure', TRUE) . '\');" />
772 <br/>
773 ' . $this->lang->getLL('makesavefo_titleOfNewPreset', TRUE) . '
774 <input type="text" name="tx_impexp[preset][title]" value="'
775 . htmlspecialchars($inData['preset']['title']) . '"' . $this->doc->formWidth(30) . ' /><br/>
776 <label for="checkPresetPublic">' . $this->lang->getLL('makesavefo_public', TRUE) . '</label>
777 <input type="checkbox" name="tx_impexp[preset][public]" id="checkPresetPublic" value="1"'
778 . ($inData['preset']['public'] ? ' checked="checked"' : '') . ' /><br/>
779 </td>
780 </tr>';
781 // Output options:
782 $row[] = '
783 <tr class="tableheader bgColor5">
784 <td colspan="2">' . $this->lang->getLL('makesavefo_outputOptions', TRUE) . '</td>
785 </tr>';
786 // Meta data:
787 $thumbnailFiles = array();
788 foreach ($this->getThumbnailFiles() as $thumbnailFile) {
789 $thumbnailFiles[$thumbnailFile->getCombinedIdentifier()] = $thumbnailFile->getName();
790 }
791 if (!empty($thumbnailFiles)) {
792 array_unshift($thumbnailFiles, '');
793 }
794 $thumbnail = NULL;
795 if (!empty($inData['meta']['thumbnail'])) {
796 $thumbnail = $this->getFile($inData['meta']['thumbnail']);
797 }
798 $saveFolder = $this->getDefaultImportExportFolder();
799
800 $row[] = '
801 <tr class="bgColor4">
802 <td><strong>' . $this->lang->getLL('makesavefo_metaData', TRUE) . '</strong>'
803 . BackendUtility::cshItem('xMOD_tx_impexp', 'metadata') . '</td>
804 <td>
805 ' . $this->lang->getLL('makesavefo_title', TRUE) . ' <br/>
806 <input type="text" name="tx_impexp[meta][title]" value="' . htmlspecialchars($inData['meta']['title']) . '"' . $this->doc->formWidth(30) . ' /><br/>
807 ' . $this->lang->getLL('makesavefo_description', TRUE) . ' <br/>
808 <input type="text" name="tx_impexp[meta][description]" value="' . htmlspecialchars($inData['meta']['description']) . '"' . $this->doc->formWidth(30) . ' /><br/>
809 ' . $this->lang->getLL('makesavefo_notes', TRUE) . ' <br/>
810 <textarea name="tx_impexp[meta][notes]"' . $this->doc->formWidth(30, 1) . '>' . GeneralUtility::formatForTextarea($inData['meta']['notes']) . '</textarea><br/>
811 ' . (!empty($thumbnailFiles) ? '
812 ' . $this->lang->getLL('makesavefo_thumbnail', TRUE) . '<br/>
813 ' . $this->renderSelectBox('tx_impexp[meta][thumbnail]', $inData['meta']['thumbnail'], $thumbnailFiles) : '') . '<br/>
814 ' . ($thumbnail ? '<img src="' . htmlspecialchars($thumbnail->getPublicUrl(TRUE)) . '" vspace="5" style="border: solid black 1px;" alt="" /><br/>' : '') . '
815 ' . $this->lang->getLL('makesavefo_uploadThumbnail', TRUE) . '<br/>
816 ' . ($saveFolder ? '<input type="file" name="upload_1" ' . $this->doc->formWidth(30) . ' size="30" /><br/>
817 <input type="hidden" name="file[upload][1][target]" value="' . htmlspecialchars($saveFolder->getCombinedIdentifier()) . '" />
818 <input type="hidden" name="file[upload][1][data]" value="1" /><br />' : '') . '
819 </td>
820 </tr>';
821 // Add file options:
822 $opt = array();
823 if ($this->export->compress) {
824 $opt['t3d_compressed'] = $this->lang->getLL('makesavefo_t3dFileCompressed');
825 }
826 $opt['t3d'] = $this->lang->getLL('makesavefo_t3dFile');
827 $opt['xml'] = $this->lang->getLL('makesavefo_xml');
828 $fileName = '';
829 if ($saveFolder) {
830 $fileName = sprintf($this->lang->getLL('makesavefo_filenameSavedInS', TRUE), $saveFolder->getCombinedIdentifier())
831 . '<br/>
832 <input type="text" name="tx_impexp[filename]" value="'
833 . htmlspecialchars($inData['filename']) . '"' . $this->doc->formWidth(30) . ' /><br/>';
834 }
835 $row[] = '
836 <tr>
837 <td>
838 <strong>' . $this->lang->getLL('makesavefo_fileFormat', TRUE) . '</strong>'
839 . BackendUtility::cshItem('xMOD_tx_impexp', 'fileFormat') . '
840 </td>
841 <td>
842 ' . $this->renderSelectBox('tx_impexp[filetype]', $inData['filetype'], $opt) . '<br/>
843 ' . $this->lang->getLL('makesavefo_maxSizeOfFiles', TRUE) . '<br/>
844 <input type="text" name="tx_impexp[maxFileSize]" value="' . htmlspecialchars($inData['maxFileSize']) . '"' . $this->doc->formWidth(10) . ' />
845 <br/>
846 ' . $fileName . '
847 </td>
848 </tr>';
849 // Add buttons:
850 $row[] = '
851 <tr>
852 <td>&nbsp;</td>
853 <td>
854 <input class="btn btn-default" type="submit" value="' . $this->lang->getLL('makesavefo_update', TRUE) . '" /> -
855 <input class="btn btn-default" type="submit" value="' . $this->lang->getLL('makesavefo_downloadExport', TRUE) . '" name="tx_impexp[download_export]" />
856 ' . ($saveFolder ? ' - <input class="btn btn-default" type="submit" value="' . $this->lang->getLL('importdata_saveToFilename', TRUE) . '" name="tx_impexp[save_export]" />' : '') . '
857 </td>
858 </tr>';
859 }
860
861 /**************************
862 * IMPORT FUNCTIONS
863 **************************/
864
865 /**
866 * Import part of module
867 *
868 * @param array $inData Content of POST VAR tx_impexp[]..
869 * @throws \BadFunctionCallException
870 * @throws \InvalidArgumentException
871 * @throws \RuntimeException
872 * @return void Setting content in $this->content
873 */
874 public function importData($inData) {
875 $access = is_array($this->pageinfo) ? 1 : 0;
876 $beUser = $this->getBackendUser();
877 if ($this->id && $access || $beUser->user['admin'] && !$this->id) {
878 if ($beUser->user['admin'] && !$this->id) {
879 $this->pageinfo = array('title' => '[root-level]', 'uid' => 0, 'pid' => 0);
880 }
881 if ($inData['new_import']) {
882 unset($inData['import_mode']);
883 }
884 /** @var $import \TYPO3\CMS\Impexp\ImportExport */
885 $import = GeneralUtility::makeInstance(\TYPO3\CMS\Impexp\ImportExport::class);
886 $import->init(0, 'import');
887 $import->update = $inData['do_update'];
888 $import->import_mode = $inData['import_mode'];
889 $import->enableLogging = $inData['enableLogging'];
890 $import->global_ignore_pid = $inData['global_ignore_pid'];
891 $import->force_all_UIDS = $inData['force_all_UIDS'];
892 $import->showDiff = !$inData['notShowDiff'];
893 $import->allowPHPScripts = $inData['allowPHPScripts'];
894 $import->softrefInputValues = $inData['softrefInputValues'];
895 // OUTPUT creation:
896 $menuItems = array();
897 // Make input selector:
898 // must have trailing slash.
899 $path = $this->getDefaultImportExportFolder();
900 $exportFiles = $this->getExportFiles();
901 // Configuration
902 $row = array();
903 $selectOptions = array('');
904 foreach ($exportFiles as $file) {
905 $selectOptions[$file->getCombinedIdentifier()] = $file->getPublicUrl();
906 }
907 $row[] = '
908 <tr>
909 <th colspan="2">' . $this->lang->getLL('importdata_selectFileToImport', TRUE) . '</th>
910 </tr>';
911 $noCompressorAvailable = !$import->compress
912 ? '<br /><span class="typo3-red">' . $this->lang->getLL('importdata_noteNoDecompressorAvailable', TRUE) . '</span>'
913 : '';
914 $row[] = '
915 <tr>
916 <td valign="top">
917 ' . $this->lang->getLL('importdata_file', TRUE) . ''
918 . BackendUtility::cshItem('xMOD_tx_impexp', 'importFile') . '
919 </td>
920 <td>
921 ' . $this->renderSelectBox('tx_impexp[file]', $inData['file'], $selectOptions) . '<br />'
922 . sprintf($this->lang->getLL('importdata_fromPathS', TRUE), $path ? $path->getCombinedIdentifier() : $this->lang->getLL('importdata_no_accessible_file_mount', TRUE)) .
923 $noCompressorAvailable . '
924 </td>
925 </tr>';
926 $row[] = '
927 <tr>
928 <th colspan="2">
929 ' . $this->lang->getLL('importdata_importOptions', TRUE) . '
930 </th>
931 </tr>';
932 $row[] = '
933 <tr>
934 <td valign="top">
935 ' . $this->lang->getLL('importdata_update', TRUE)
936 . BackendUtility::cshItem('xMOD_tx_impexp', 'update') . '
937 </td>
938 <td>
939 <input type="checkbox" name="tx_impexp[do_update]" id="checkDo_update" value="1"'
940 . ($inData['do_update'] ? ' checked="checked"' : '') . ' />
941 <label for="checkDo_update">' . $this->lang->getLL('importdata_updateRecords', TRUE) . '</label>
942 <br/>
943 <em>(' . $this->lang->getLL('importdata_thisOptionRequiresThat', TRUE) . ')</em>' . ($inData['do_update'] ? ' <hr/>
944 <input type="checkbox" name="tx_impexp[global_ignore_pid]" id="checkGlobal_ignore_pid" value="1"'
945 . ($inData['global_ignore_pid'] ? ' checked="checked"' : '') . ' />
946 <label for="checkGlobal_ignore_pid">' . $this->lang->getLL('importdata_ignorePidDifferencesGlobally', TRUE) . '</label><br/>
947 <em>(' . $this->lang->getLL('importdata_ifYouSetThis', TRUE) . ')</em>
948 ' : '') . '
949 </td>
950 </tr>';
951 $allowPhpScripts = $beUser->isAdmin()
952 ? '
953 <input type="checkbox" name="tx_impexp[allowPHPScripts]" id="checkAllowPHPScripts" value="1"'
954 . ($inData['allowPHPScripts'] ? ' checked="checked"' : '') . ' />
955 <label for="checkAllowPHPScripts">' . $this->lang->getLL('importdata_allowToWriteBanned', TRUE) . '</label><br/>'
956 : '';
957 $doUpdate = !$inData['do_update'] && $beUser->isAdmin()
958 ? '
959 <br/>
960 <input type="checkbox" name="tx_impexp[force_all_UIDS]" id="checkForce_all_UIDS" value="1"'
961 . ($inData['force_all_UIDS'] ? ' checked="checked"' : '') . ' />
962 <label for="checkForce_all_UIDS"><span class="typo3-red">'
963 . $this->lang->getLL('importdata_force_all_UIDS', TRUE) . '</span></label><br/>
964 <em>(' . $this->lang->getLL('importdata_force_all_UIDS_descr', TRUE) . ')</em>'
965 : '';
966 $row[] = '<tr>
967 <td valign="top">
968 ' . $this->lang->getLL('importdata_options', TRUE) . BackendUtility::cshItem('xMOD_tx_impexp', 'options') . '
969 </td>
970 <td>
971 <input type="checkbox" name="tx_impexp[notShowDiff]" id="checkNotShowDiff" value="1"'
972 . ($inData['notShowDiff'] ? ' checked="checked"' : '') . ' />
973 <label for="checkNotShowDiff">' . $this->lang->getLL('importdata_doNotShowDifferences', TRUE) . '</label><br/>
974 <em>(' . $this->lang->getLL('importdata_greenValuesAreFrom', TRUE) . ')</em>
975 <br/><br/>
976
977 ' . $allowPhpScripts . $doUpdate . '
978 </td>
979 </tr>';
980 $newImport = !$inData['import_file']
981 ? '<input class="btn btn-default" type="submit" value="' . $this->lang->getLL('importdata_preview', TRUE) . '" />' . ($inData['file']
982 ? ' - <input class="btn btn-default" type="submit" value="' . ($inData['do_update']
983 ? $this->lang->getLL('importdata_update_299e', TRUE)
984 : $this->lang->getLL('importdata_import', TRUE)) . '" name="tx_impexp[import_file]" onclick="return confirm(\''
985 . $this->lang->getLL('importdata_areYouSure', TRUE) . '\');" />'
986 : '')
987 : '<input class="btn btn-default" type="submit" name="tx_impexp[new_import]" value="' . $this->lang->getLL('importdata_newImport', TRUE) . '" />';
988 $row[] = '<tr>
989 <td valign="top">
990 ' . $this->lang->getLL('importdata_action', TRUE) . BackendUtility::cshItem('xMOD_tx_impexp', 'action') . '
991 </td>
992 <td>
993 ' . $newImport . '
994 <input type="hidden" name="tx_impexp[action]" value="import" />
995 </td>
996 </tr>';
997 $row[] = '<tr>
998 <td valign="top">
999 ' . $this->lang->getLL('importdata_enableLogging', TRUE)
1000 . BackendUtility::cshItem('xMOD_tx_impexp', 'enableLogging') . '
1001 </td>
1002 <td>
1003 <input type="checkbox" name="tx_impexp[enableLogging]" id="checkEnableLogging" value="1"'
1004 . ($inData['enableLogging'] ? ' checked="checked"' : '') . ' />
1005 <label for="checkEnableLogging">' . $this->lang->getLL('importdata_writeIndividualDbActions', TRUE) . '</label><br/>
1006 <em>(' . $this->lang->getLL('importdata_thisIsDisabledBy', TRUE) . ')</em>
1007 </td>
1008 </tr>';
1009 $menuItems[] = array(
1010 'label' => $this->lang->getLL('importdata_import', TRUE),
1011 'content' => '
1012 <table border="0" cellpadding="1" cellspacing="1">
1013 ' . implode('
1014 ', $row) . '
1015 </table>
1016 '
1017 );
1018 // Upload file:
1019 $tempFolder = $this->getDefaultImportExportFolder();
1020 if ($tempFolder) {
1021 $row = array();
1022 $row[] = '
1023 <tr>
1024 <th colspan="2">' . $this->lang->getLL('importdata_uploadFileFromLocal', TRUE) . '</th>
1025 </tr>';
1026 $row[] = '
1027 <tr>
1028 <td valign="top">
1029 ' . $this->lang->getLL('importdata_browse', TRUE) . BackendUtility::cshItem('xMOD_tx_impexp', 'upload') . '
1030 </td>
1031 <td>
1032 <input type="file" name="upload_1"' . $this->doc->formWidth(35) . ' size="40" />
1033 <input type="hidden" name="file[upload][1][target]" value="' . htmlspecialchars($tempFolder->getCombinedIdentifier()) . '" />
1034 <input type="hidden" name="file[upload][1][data]" value="1" />
1035 <br />
1036 <input class="btn btn-default" type="submit" name="_upload" value="' . $this->lang->sL('LLL:EXT:lang/locallang_core.xlf:file_upload.php.submit', TRUE) . '" />
1037 <input type="checkbox" name="overwriteExistingFiles" id="checkOverwriteExistingFiles" value="1" checked="checked" />
1038 <label for="checkOverwriteExistingFiles">' . $this->lang->sL('LLL:EXT:lang/locallang_misc.xlf:overwriteExistingFiles', TRUE) . '</label>
1039 </td>
1040 </tr>';
1041 if (GeneralUtility::_POST('_upload')) {
1042 $noFileUploaded = $this->fileProcessor->internalUploadMap[1]
1043 ? $this->lang->getLL('importdata_success', TRUE) . ' ' . $this->uploadedFiles[0]->getName()
1044 : '<span class="typo3-red">' . $this->lang->getLL('importdata_failureNoFileUploaded', TRUE) . '</span>';
1045 $row[] = '<tr class="bgColor4">
1046 <td>' . $this->lang->getLL('importdata_uploadStatus', TRUE) . '</td>
1047 <td>' . $noFileUploaded . '</td>
1048 </tr>';
1049 }
1050 $menuItems[] = array(
1051 'label' => $this->lang->getLL('importdata_upload'),
1052 'content' => '
1053 <table border="0" cellpadding="1" cellspacing="1">
1054 ' . implode('
1055 ', $row) . '
1056 </table>
1057 '
1058 );
1059 }
1060 // Perform import or preview depending:
1061 $overviewContent = '';
1062 $extensionInstallationMessage = '';
1063 $inFile = $this->getFile($inData['file']);
1064 if ($inFile !== NULL && $inFile->exists()) {
1065 $trow = array();
1066 if ($import->loadFile($inFile->getForLocalProcessing(FALSE), 1)) {
1067 // Check extension dependencies:
1068 $extKeysToInstall = array();
1069 if (is_array($import->dat['header']['extensionDependencies'])) {
1070 foreach ($import->dat['header']['extensionDependencies'] as $extKey) {
1071 if (!\TYPO3\CMS\Core\Utility\ExtensionManagementUtility::isLoaded($extKey)) {
1072 $extKeysToInstall[] = $extKey;
1073 }
1074 }
1075 }
1076 if (count($extKeysToInstall)) {
1077 $extensionInstallationMessage = 'Before you can install this T3D file you need to install the extensions "'
1078 . implode('", "', $extKeysToInstall) . '".';
1079 }
1080 if ($inData['import_file']) {
1081 if (!count($extKeysToInstall)) {
1082 $import->importData($this->id);
1083 BackendUtility::setUpdateSignal('updatePageTree');
1084 }
1085 }
1086 $import->display_import_pid_record = $this->pageinfo;
1087 $overviewContent = $import->displayContentOverview();
1088 }
1089 // Meta data output:
1090 $trow[] = '<tr class="bgColor5">
1091 <td colspan="2"><strong>' . $this->lang->getLL('importdata_metaData', TRUE) . '</strong></td>
1092 </tr>';
1093 $trow[] = '<tr class="bgColor4">
1094 <td><strong>' . $this->lang->getLL('importdata_title', TRUE) . '</strong></td>
1095 <td width="95%">' . nl2br(htmlspecialchars($import->dat['header']['meta']['title'])) . '</td>
1096 </tr>';
1097 $trow[] = '<tr class="bgColor4">
1098 <td><strong>' . $this->lang->getLL('importdata_description', TRUE) . '</strong></td>
1099 <td width="95%">' . nl2br(htmlspecialchars($import->dat['header']['meta']['description'])) . '</td>
1100 </tr>';
1101 $trow[] = '<tr class="bgColor4">
1102 <td><strong>' . $this->lang->getLL('importdata_notes', TRUE) . '</strong></td>
1103 <td width="95%">' . nl2br(htmlspecialchars($import->dat['header']['meta']['notes'])) . '</td>
1104 </tr>';
1105 $trow[] = '<tr class="bgColor4">
1106 <td><strong>' . $this->lang->getLL('importdata_packager', TRUE) . '</strong></td>
1107 <td width="95%">' . nl2br(htmlspecialchars(($import->dat['header']['meta']['packager_name']
1108 . ' (' . $import->dat['header']['meta']['packager_username'] . ')'))) . '<br/>
1109 ' . $this->lang->getLL('importdata_email', TRUE) . ' '
1110 . $import->dat['header']['meta']['packager_email'] . '</td>
1111 </tr>';
1112 // Thumbnail icon:
1113 if (is_array($import->dat['header']['thumbnail'])) {
1114 $pI = pathinfo($import->dat['header']['thumbnail']['filename']);
1115 if (GeneralUtility::inList('gif,jpg,png,jpeg', strtolower($pI['extension']))) {
1116 // Construct filename and write it:
1117 $fileName = PATH_site . 'typo3temp/importthumb.' . $pI['extension'];
1118 GeneralUtility::writeFile($fileName, $import->dat['header']['thumbnail']['content']);
1119 // Check that the image really is an image and not a malicious PHP script...
1120 if (getimagesize($fileName)) {
1121 // Create icon tag:
1122 $iconTag = '<img src="' . $this->doc->backPath . '../' . PathUtility::stripPathSitePrefix($fileName)
1123 . '" ' . $import->dat['header']['thumbnail']['imgInfo'][3]
1124 . ' vspace="5" style="border: solid black 1px;" alt="" />';
1125 $trow[] = '<tr class="bgColor4">
1126 <td><strong>' . $this->lang->getLL('importdata_icon', TRUE) . '</strong></td>
1127 <td>' . $iconTag . '</td>
1128 </tr>';
1129 } else {
1130 GeneralUtility::unlink_tempfile($fileName);
1131 }
1132 }
1133 }
1134 $menuItems[] = array(
1135 'label' => $this->lang->getLL('importdata_metaData_1387'),
1136 'content' => '
1137 <table border="0" cellpadding="1" cellspacing="1">
1138 ' . implode('
1139 ', $trow) . '
1140 </table>
1141 '
1142 );
1143 }
1144 // Print errors that might be:
1145 $errors = $import->printErrorLog();
1146 $menuItems[] = array(
1147 'label' => $this->lang->getLL('importdata_messages'),
1148 'content' => $errors,
1149 'stateIcon' => $errors ? 2 : 0
1150 );
1151 // Output tabs:
1152 $content = $this->doc->getDynTabMenu($menuItems, 'tx_impexp_import', -1);
1153 if ($extensionInstallationMessage) {
1154 $content = '<div style="border: 1px black solid; margin: 10px 10px 10px 10px; padding: 10px 10px 10px 10px;">'
1155 . $this->doc->icons(1) . htmlspecialchars($extensionInstallationMessage) . '</div>' . $content;
1156 }
1157 $this->content .= $this->doc->section('', $content, 0, 1);
1158 // Print overview:
1159 if ($overviewContent) {
1160 $this->content .= $this->doc->section($inData['import_file']
1161 ? $this->lang->getLL('importdata_structureHasBeenImported', TRUE)
1162 : $this->lang->getLL('filterpage_structureToBeImported', TRUE), $overviewContent, 0, 1);
1163 }
1164 }
1165 }
1166
1167 /****************************
1168 * Preset functions
1169 ****************************/
1170
1171 /**
1172 * Manipulate presets
1173 *
1174 * @param array $inData In data array, passed by reference!
1175 * @return void
1176 */
1177 public function processPresets(&$inData) {
1178 $presetData = GeneralUtility::_GP('preset');
1179 $err = FALSE;
1180 $msg = '';
1181 // Save preset
1182 $beUser = $this->getBackendUser();
1183 // cast public checkbox to int, since this is a int field and NULL is not allowed
1184 $inData['preset']['public'] = (int)$inData['preset']['public'];
1185 if (isset($presetData['save'])) {
1186 $preset = $this->getPreset($presetData['select']);
1187 // Update existing
1188 if (is_array($preset)) {
1189 if ($beUser->isAdmin() || $preset['user_uid'] === $beUser->user['uid']) {
1190 $fields_values = array(
1191 'public' => $inData['preset']['public'],
1192 'title' => $inData['preset']['title'],
1193 'item_uid' => $inData['pagetree']['id'],
1194 'preset_data' => serialize($inData)
1195 );
1196 $this->getDatabaseConnection()->exec_UPDATEquery('tx_impexp_presets', 'uid=' . (int)$preset['uid'], $fields_values);
1197 $msg = 'Preset #' . $preset['uid'] . ' saved!';
1198 } else {
1199 $msg = 'ERROR: The preset was not saved because you were not the owner of it!';
1200 $err = TRUE;
1201 }
1202 } else {
1203 // Insert new:
1204 $fields_values = array(
1205 'user_uid' => $beUser->user['uid'],
1206 'public' => $inData['preset']['public'],
1207 'title' => $inData['preset']['title'],
1208 'item_uid' => $inData['pagetree']['id'],
1209 'preset_data' => serialize($inData)
1210 );
1211 $this->getDatabaseConnection()->exec_INSERTquery('tx_impexp_presets', $fields_values);
1212 $msg = 'New preset "' . htmlspecialchars($inData['preset']['title']) . '" is created';
1213 }
1214 }
1215 // Delete preset:
1216 if (isset($presetData['delete'])) {
1217 $preset = $this->getPreset($presetData['select']);
1218 if (is_array($preset)) {
1219 // Update existing
1220 if ($beUser->isAdmin() || $preset['user_uid'] === $beUser->user['uid']) {
1221 $this->getDatabaseConnection()->exec_DELETEquery('tx_impexp_presets', 'uid=' . (int)$preset['uid']);
1222 $msg = 'Preset #' . $preset['uid'] . ' deleted!';
1223 } else {
1224 $msg = 'ERROR: You were not the owner of the preset so you could not delete it.';
1225 $err = TRUE;
1226 }
1227 } else {
1228 $msg = 'ERROR: No preset selected for deletion.';
1229 $err = TRUE;
1230 }
1231 }
1232 // Load preset
1233 if (isset($presetData['load']) || isset($presetData['merge'])) {
1234 $preset = $this->getPreset($presetData['select']);
1235 if (is_array($preset)) {
1236 // Update existing
1237 $inData_temp = unserialize($preset['preset_data']);
1238 if (is_array($inData_temp)) {
1239 if (isset($presetData['merge'])) {
1240 // Merge records in:
1241 if (is_array($inData_temp['record'])) {
1242 $inData['record'] = array_merge((array)$inData['record'], $inData_temp['record']);
1243 }
1244 // Merge lists in:
1245 if (is_array($inData_temp['list'])) {
1246 $inData['list'] = array_merge((array)$inData['list'], $inData_temp['list']);
1247 }
1248 } else {
1249 $msg = 'Preset #' . $preset['uid'] . ' loaded!';
1250 $inData = $inData_temp;
1251 }
1252 } else {
1253 $msg = 'ERROR: No configuratio data found in preset record!';
1254 $err = TRUE;
1255 }
1256 } else {
1257 $msg = 'ERROR: No preset selected for loading.';
1258 $err = TRUE;
1259 }
1260 }
1261 // Show message:
1262 if ($msg !== '') {
1263 $this->content .= $this->doc->section('Presets', $msg, 0, 1, $err ? 3 : 1);
1264 }
1265 }
1266
1267 /**
1268 * Get single preset record
1269 *
1270 * @param int $uid Preset record
1271 * @return array Preset record, if any (otherwise FALSE)
1272 */
1273 public function getPreset($uid) {
1274 return $this->getDatabaseConnection()->exec_SELECTgetSingleRow('*', 'tx_impexp_presets', 'uid=' . (int)$uid);
1275 }
1276
1277 /****************************
1278 * Helper functions
1279 ****************************/
1280
1281 /**
1282 * Returns a \TYPO3\CMS\Core\Resource\Folder object for saving export files
1283 * to the server and is also used for uploading import files.
1284 *
1285 * @throws \InvalidArgumentException
1286 * @return NULL|\TYPO3\CMS\Core\Resource\Folder
1287 */
1288 protected function getDefaultImportExportFolder() {
1289 $defaultImportExportFolder = NULL;
1290
1291 $defaultTemporaryFolder = $this->getBackendUser()->getDefaultUploadTemporaryFolder();
1292 if ($defaultTemporaryFolder !== NULL) {
1293
1294 $importExportFolderName = 'importexport';
1295 $createFolder = !$defaultTemporaryFolder->hasFolder($importExportFolderName);
1296 if ($createFolder === TRUE) {
1297 try {
1298 $defaultImportExportFolder = $defaultTemporaryFolder->createFolder($importExportFolderName);
1299 } catch (\TYPO3\CMS\Core\Resource\Exception $folderAccessException) {}
1300 } else {
1301 $defaultImportExportFolder = $defaultTemporaryFolder->getSubfolder($importExportFolderName);
1302 }
1303 }
1304
1305 return $defaultImportExportFolder;
1306 }
1307
1308
1309 /**
1310 * Check if a file has been uploaded
1311 *
1312 * @throws \InvalidArgumentException
1313 * @throws \UnexpectedValueException
1314 * @return void
1315 */
1316 public function checkUpload() {
1317 $file = GeneralUtility::_GP('file');
1318 // Initializing:
1319 $this->fileProcessor = GeneralUtility::makeInstance(\TYPO3\CMS\Core\Utility\File\ExtendedFileUtility::class);
1320 $this->fileProcessor->init(array(), $GLOBALS['TYPO3_CONF_VARS']['BE']['fileExtensions']);
1321 $this->fileProcessor->setActionPermissions();
1322 $this->fileProcessor->dontCheckForUnique = GeneralUtility::_GP('overwriteExistingFiles') ? 1 : 0;
1323 // Checking referer / executing:
1324 $refInfo = parse_url(GeneralUtility::getIndpEnv('HTTP_REFERER'));
1325 $httpHost = GeneralUtility::getIndpEnv('TYPO3_HOST_ONLY');
1326 if (
1327 $httpHost != $refInfo['host']
1328 && !$GLOBALS['$TYPO3_CONF_VARS']['SYS']['doNotCheckReferer']
1329 && $this->vC != $this->getBackendUser()->veriCode()
1330 ) {
1331 $this->fileProcessor->writeLog(0, 2, 1, 'Referer host "%s" and server host "%s" did not match!', array($refInfo['host'], $httpHost));
1332 } else {
1333 $this->fileProcessor->start($file);
1334 $result = $this->fileProcessor->processData();
1335 if (!empty($result['upload'])) {
1336 foreach ($result['upload'] as $uploadedFiles) {
1337 $this->uploadedFiles += $uploadedFiles;
1338 }
1339 }
1340 }
1341 }
1342
1343 /**
1344 * Makes a selector-box from optValues
1345 *
1346 * @param string $prefix Form element name
1347 * @param string $value Current value
1348 * @param array $optValues Options to display (key/value pairs)
1349 * @return string HTML select element
1350 */
1351 public function renderSelectBox($prefix, $value, $optValues) {
1352 $opt = array();
1353 $isSelFlag = 0;
1354 foreach ($optValues as $k => $v) {
1355 $sel = (string)$k === (string)$value ? ' selected="selected"' : '';
1356 if ($sel) {
1357 $isSelFlag++;
1358 }
1359 $opt[] = '<option value="' . htmlspecialchars($k) . '"' . $sel . '>' . htmlspecialchars($v) . '</option>';
1360 }
1361 if (!$isSelFlag && (string)$value !== '') {
1362 $opt[] = '<option value="' . htmlspecialchars($value) . '" selected="selected">'
1363 . htmlspecialchars(('[\'' . $value . '\']')) . '</option>';
1364 }
1365 return '<select name="' . $prefix . '">' . implode('', $opt) . '</select>';
1366 }
1367
1368 /**
1369 * Returns a selector-box with TCA tables
1370 *
1371 * @param string $prefix Form element name prefix
1372 * @param array $value The current values selected
1373 * @param string $excludeList Table names (and the string "_ALL") to exclude. Comma list
1374 * @return string HTML select element
1375 */
1376 public function tableSelector($prefix, $value, $excludeList = '') {
1377 $optValues = array();
1378 if (!GeneralUtility::inList($excludeList, '_ALL')) {
1379 $optValues['_ALL'] = '[' . $this->lang->getLL('ALL_tables') . ']';
1380 }
1381 foreach ($GLOBALS['TCA'] as $table => $_) {
1382 if ($this->getBackendUser()->check('tables_select', $table) && !GeneralUtility::inList($excludeList, $table)) {
1383 $optValues[$table] = $table;
1384 }
1385 }
1386 // make box:
1387 $opt = array();
1388 $opt[] = '<option value=""></option>';
1389 $sel = '';
1390 foreach ($optValues as $k => $v) {
1391 if (is_array($value)) {
1392 $sel = in_array($k, $value) ? ' selected="selected"' : '';
1393 }
1394 $opt[] = '<option value="' . htmlspecialchars($k) . '"' . $sel . '>' . htmlspecialchars($v) . '</option>';
1395 }
1396 return '<select name="' . $prefix . '[]" multiple="multiple" size="'
1397 . MathUtility::forceIntegerInRange(count($opt), 5, 10) . '">' . implode('', $opt) . '</select>';
1398 }
1399
1400 /**
1401 * Returns a selector-box with loaded extension keys
1402 *
1403 * @param string $prefix Form element name prefix
1404 * @param array $value The current values selected
1405 * @return string HTML select element
1406 */
1407 public function extensionSelector($prefix, $value) {
1408 $loadedExtensions = \TYPO3\CMS\Core\Utility\ExtensionManagementUtility::getLoadedExtensionListArray();
1409
1410 // make box:
1411 $opt = array();
1412 $opt[] = '<option value=""></option>';
1413 foreach ($loadedExtensions as $extensionKey) {
1414 $sel = '';
1415 if (is_array($value)) {
1416 $sel = in_array($extensionKey, $value) ? ' selected="selected"' : '';
1417 }
1418 $opt[] = '<option value="' . htmlspecialchars($extensionKey) . '"' . $sel . '>'
1419 . htmlspecialchars($extensionKey) . '</option>';
1420 }
1421 return '<select name="' . $prefix . '[]" multiple="multiple" size="'
1422 . MathUtility::forceIntegerInRange(count($opt), 5, 10) . '">' . implode('', $opt) . '</select>';
1423 }
1424
1425 /**
1426 * Filter page IDs by traversing exclude array, finding all
1427 * excluded pages (if any) and making an AND NOT IN statement for the select clause.
1428 *
1429 * @param array $exclude Exclude array from import/export object.
1430 * @return string AND where clause part to filter out page uids.
1431 */
1432 public function filterPageIds($exclude) {
1433 // Get keys:
1434 $exclude = array_keys($exclude);
1435 // Traverse
1436 $pageIds = array();
1437 foreach ($exclude as $element) {
1438 list($table, $uid) = explode(':', $element);
1439 if ($table === 'pages') {
1440 $pageIds[] = (int)$uid;
1441 }
1442 }
1443 // Add to clause:
1444 if (count($pageIds)) {
1445 return ' AND uid NOT IN (' . implode(',', $pageIds) . ')';
1446 }
1447 return '';
1448 }
1449
1450 /**
1451 * @return \TYPO3\CMS\Core\Authentication\BackendUserAuthentication
1452 */
1453 protected function getBackendUser() {
1454 return $GLOBALS['BE_USER'];
1455 }
1456
1457 /**
1458 * @return DatabaseConnection
1459 */
1460 protected function getDatabaseConnection() {
1461 return $GLOBALS['TYPO3_DB'];
1462 }
1463
1464 /**
1465 * @return LanguageService
1466 */
1467 protected function getLanguageService() {
1468 return $GLOBALS['LANG'];
1469 }
1470
1471 /**
1472 * Gets thumbnail files.
1473 *
1474 * @throws \InvalidArgumentException
1475 * @return array|\TYPO3\CMS\Core\Resource\File[]
1476 */
1477 protected function getThumbnailFiles() {
1478 $thumbnailFiles = array();
1479 $defaultTemporaryFolder = $this->getDefaultImportExportFolder();
1480
1481 if ($defaultTemporaryFolder === NULL) {
1482 return $thumbnailFiles;
1483 }
1484
1485 /** @var $filter \TYPO3\CMS\Core\Resource\Filter\FileExtensionFilter */
1486 $filter = GeneralUtility::makeInstance(\TYPO3\CMS\Core\Resource\Filter\FileExtensionFilter::class);
1487 $filter->setAllowedFileExtensions(array('png', 'gif', 'jpg'));
1488 $defaultTemporaryFolder->getStorage()->addFileAndFolderNameFilter(array($filter, 'filterFileList'));
1489 $thumbnailFiles = $defaultTemporaryFolder->getFiles();
1490
1491 return $thumbnailFiles;
1492 }
1493
1494 /**
1495 * Gets all export files.
1496 *
1497 * @throws \InvalidArgumentException
1498 * @return array|\TYPO3\CMS\Core\Resource\File[]
1499 */
1500 protected function getExportFiles() {
1501 $exportFiles = array();
1502
1503 $folder = $this->getDefaultImportExportFolder();
1504 if ($folder !== FALSE) {
1505
1506 /** @var $filter \TYPO3\CMS\Core\Resource\Filter\FileExtensionFilter */
1507 $filter = GeneralUtility::makeInstance(\TYPO3\CMS\Core\Resource\Filter\FileExtensionFilter::class);
1508 $filter->setAllowedFileExtensions(array('t3d', 'xml'));
1509 $folder->getStorage()->addFileAndFolderNameFilter(array($filter, 'filterFileList'));
1510
1511 $exportFiles = $folder->getFiles();
1512 }
1513
1514 return $exportFiles;
1515 }
1516
1517 /**
1518 * Gets a file by combined identifier.
1519 *
1520 * @param string $combinedIdentifier
1521 * @return NULL|\TYPO3\CMS\Core\Resource\File
1522 */
1523 protected function getFile($combinedIdentifier) {
1524 try {
1525 $file = \TYPO3\CMS\Core\Resource\ResourceFactory::getInstance()->getFileObjectFromCombinedIdentifier($combinedIdentifier);
1526 } catch (\Exception $exception) {
1527 $file = NULL;
1528 }
1529
1530 return $file;
1531 }
1532
1533 }