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