コード例 #1
0
    /**
     * Import part of module
     *
     * @param array $inData Content of POST VAR tx_impexp[]..
     * @throws \BadFunctionCallException
     * @throws \InvalidArgumentException
     * @throws \RuntimeException
     * @return void Setting content in $this->content
     */
    public function importData($inData)
    {
        $access = is_array($this->pageinfo) ? 1 : 0;
        $beUser = $this->getBackendUser();
        if ($this->id && $access || $beUser->user['admin'] && !$this->id) {
            if ($beUser->user['admin'] && !$this->id) {
                $this->pageinfo = array('title' => '[root-level]', 'uid' => 0, 'pid' => 0);
            }
            if ($inData['new_import']) {
                unset($inData['import_mode']);
            }
            /** @var $import \TYPO3\CMS\Impexp\ImportExport */
            $import = GeneralUtility::makeInstance(\TYPO3\CMS\Impexp\ImportExport::class);
            $import->init(0, 'import');
            $import->update = $inData['do_update'];
            $import->import_mode = $inData['import_mode'];
            $import->enableLogging = $inData['enableLogging'];
            $import->global_ignore_pid = $inData['global_ignore_pid'];
            $import->force_all_UIDS = $inData['force_all_UIDS'];
            $import->showDiff = !$inData['notShowDiff'];
            $import->allowPHPScripts = $inData['allowPHPScripts'];
            $import->softrefInputValues = $inData['softrefInputValues'];
            // OUTPUT creation:
            $menuItems = array();
            // Make input selector:
            // must have trailing slash.
            $path = $this->getDefaultImportExportFolder();
            $exportFiles = $this->getExportFiles();
            $this->shortcutName .= ' (' . $this->pageinfo['title'] . ')';
            // Configuration
            $row = array();
            $selectOptions = array('');
            foreach ($exportFiles as $file) {
                $selectOptions[$file->getCombinedIdentifier()] = $file->getPublicUrl();
            }
            $row[] = '
				<tr>
					<th colspan="2">' . $this->lang->getLL('importdata_selectFileToImport', true) . '</th>
				</tr>';
            $noCompressorAvailable = !$import->compress ? '<br /><span class="text-danger">' . $this->lang->getLL('importdata_noteNoDecompressorAvailable', true) . '</span>' : '';
            $row[] = '
				<tr>
					<td valign="top">
						' . $this->lang->getLL('importdata_file', true) . '' . BackendUtility::cshItem('xMOD_tx_impexp', 'importFile') . '
					</td>
					<td>
						' . $this->renderSelectBox('tx_impexp[file]', $inData['file'], $selectOptions) . '<br />' . sprintf($this->lang->getLL('importdata_fromPathS', true), $path ? $path->getCombinedIdentifier() : $this->lang->getLL('importdata_no_accessible_file_mount', true)) . $noCompressorAvailable . '
					</td>
				</tr>';
            $row[] = '
				<tr>
					<th colspan="2">
						' . $this->lang->getLL('importdata_importOptions', true) . '
					</th>
				</tr>';
            $row[] = '
				<tr>
					<td valign="top">
						' . $this->lang->getLL('importdata_update', true) . BackendUtility::cshItem('xMOD_tx_impexp', 'update') . '
					</td>
					<td>
						<input type="checkbox" name="tx_impexp[do_update]" id="checkDo_update" value="1"' . ($inData['do_update'] ? ' checked="checked"' : '') . ' />
						<label for="checkDo_update">' . $this->lang->getLL('importdata_updateRecords', true) . '</label>
						<br/>
						<em>(' . $this->lang->getLL('importdata_thisOptionRequiresThat', true) . ')</em>' . ($inData['do_update'] ? '	<hr/>
						<input type="checkbox" name="tx_impexp[global_ignore_pid]" id="checkGlobal_ignore_pid" value="1"' . ($inData['global_ignore_pid'] ? ' checked="checked"' : '') . ' />
						<label for="checkGlobal_ignore_pid">' . $this->lang->getLL('importdata_ignorePidDifferencesGlobally', true) . '</label><br/>
						<em>(' . $this->lang->getLL('importdata_ifYouSetThis', true) . ')</em>
						' : '') . '
					</td>
				</tr>';
            $allowPhpScripts = $beUser->isAdmin() ? '
					<input type="checkbox" name="tx_impexp[allowPHPScripts]" id="checkAllowPHPScripts" value="1"' . ($inData['allowPHPScripts'] ? ' checked="checked"' : '') . ' />
					<label for="checkAllowPHPScripts">' . $this->lang->getLL('importdata_allowToWriteBanned', true) . '</label><br/>' : '';
            $doUpdate = !$inData['do_update'] && $beUser->isAdmin() ? '
					<br/>
					<input type="checkbox" name="tx_impexp[force_all_UIDS]" id="checkForce_all_UIDS" value="1"' . ($inData['force_all_UIDS'] ? ' checked="checked"' : '') . ' />
					<label for="checkForce_all_UIDS"><span class="text-danger">' . $this->lang->getLL('importdata_force_all_UIDS', true) . '</span></label><br/>
					<em>(' . $this->lang->getLL('importdata_force_all_UIDS_descr', true) . ')</em>' : '';
            $row[] = '<tr>
					<td valign="top">
						' . $this->lang->getLL('importdata_options', true) . BackendUtility::cshItem('xMOD_tx_impexp', 'options') . '
					</td>
					<td>
						<input type="checkbox" name="tx_impexp[notShowDiff]" id="checkNotShowDiff" value="1"' . ($inData['notShowDiff'] ? ' checked="checked"' : '') . ' />
						<label for="checkNotShowDiff">' . $this->lang->getLL('importdata_doNotShowDifferences', true) . '</label><br/>
						<em>(' . $this->lang->getLL('importdata_greenValuesAreFrom', true) . ')</em>
						<br/><br/>

						' . $allowPhpScripts . $doUpdate . '
					</td>
				</tr>';
            $newImport = !$inData['import_file'] ? '<input class="btn btn-default" type="submit" value="' . $this->lang->getLL('importdata_preview', true) . '" />' . ($inData['file'] ? ' - <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'] ? $this->lang->getLL('importdata_update_299e', true) : $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) . '" />' : '') : '<input class="btn btn-default" type="submit" name="tx_impexp[new_import]" value="' . $this->lang->getLL('importdata_newImport', true) . '" />';
            $row[] = '<tr>
					<td valign="top">
						' . $this->lang->getLL('importdata_action', true) . BackendUtility::cshItem('xMOD_tx_impexp', 'action') . '
					</td>
					<td>
						' . $newImport . '
						<input type="hidden" name="tx_impexp[action]" value="import" />
					</td>
				</tr>';
            $row[] = '<tr>
				<td valign="top">
					' . $this->lang->getLL('importdata_enableLogging', true) . BackendUtility::cshItem('xMOD_tx_impexp', 'enableLogging') . '
				</td>
				<td>
					<input type="checkbox" name="tx_impexp[enableLogging]" id="checkEnableLogging" value="1"' . ($inData['enableLogging'] ? ' checked="checked"' : '') . ' />
					<label for="checkEnableLogging">' . $this->lang->getLL('importdata_writeIndividualDbActions', true) . '</label><br/>
					<em>(' . $this->lang->getLL('importdata_thisIsDisabledBy', true) . ')</em>
				</td>
				</tr>';
            $menuItems[] = array('label' => $this->lang->getLL('importdata_import', true), 'content' => '
					<table border="0" cellpadding="1" cellspacing="1">
						' . implode('
						', $row) . '
					</table>
				');
            // Upload file:
            $tempFolder = $this->getDefaultImportExportFolder();
            if ($tempFolder) {
                $row = array();
                $row[] = '
					<tr>
						<th colspan="2">' . $this->lang->getLL('importdata_uploadFileFromLocal', true) . '</th>
					</tr>';
                $row[] = '
					<tr>
						<td valign="top">
							' . $this->lang->getLL('importdata_browse', true) . BackendUtility::cshItem('xMOD_tx_impexp', 'upload') . '
						</td>
						<td>
							<input type="file" name="upload_1" size="40" />
							<input type="hidden" name="file[upload][1][target]" value="' . htmlspecialchars($tempFolder->getCombinedIdentifier()) . '" />
							<input type="hidden" name="file[upload][1][data]" value="1" />
							<br />
							<input class="btn btn-default" type="submit" name="_upload" value="' . $this->lang->sL('LLL:EXT:lang/locallang_core.xlf:file_upload.php.submit', true) . '" />
							<input type="checkbox" name="overwriteExistingFiles" id="checkOverwriteExistingFiles" value="1" checked="checked" />
							<label for="checkOverwriteExistingFiles">' . $this->lang->sL('LLL:EXT:lang/locallang_misc.xlf:overwriteExistingFiles', true) . '</label>
						</td>
					</tr>';
                if (GeneralUtility::_POST('_upload')) {
                    $noFileUploaded = $this->fileProcessor->internalUploadMap[1] ? $this->lang->getLL('importdata_success', true) . ' ' . $this->uploadedFiles[0]->getName() : '<span class="text-danger">' . $this->lang->getLL('importdata_failureNoFileUploaded', true) . '</span>';
                    $row[] = '<tr class="bgColor4">
							<td>' . $this->lang->getLL('importdata_uploadStatus', true) . '</td>
							<td>' . $noFileUploaded . '</td>
						</tr>';
                }
                $menuItems[] = array('label' => $this->lang->getLL('importdata_upload'), 'content' => '
						<table border="0" cellpadding="1" cellspacing="1">
							' . implode('
							', $row) . '
						</table>
					');
            }
            // Perform import or preview depending:
            $overviewContent = '';
            $extensionInstallationMessage = '';
            $inFile = $this->getFile($inData['file']);
            if ($inFile !== null && $inFile->exists()) {
                $trow = array();
                if ($import->loadFile($inFile->getForLocalProcessing(false), 1)) {
                    // Check extension dependencies:
                    $extKeysToInstall = array();
                    if (is_array($import->dat['header']['extensionDependencies'])) {
                        foreach ($import->dat['header']['extensionDependencies'] as $extKey) {
                            if (!\TYPO3\CMS\Core\Utility\ExtensionManagementUtility::isLoaded($extKey)) {
                                $extKeysToInstall[] = $extKey;
                            }
                        }
                    }
                    if (!empty($extKeysToInstall)) {
                        $extensionInstallationMessage = 'Before you can install this T3D file you need to install the extensions "' . implode('", "', $extKeysToInstall) . '".';
                    }
                    if ($inData['import_file']) {
                        if (empty($extKeysToInstall)) {
                            $import->importData($this->id);
                            BackendUtility::setUpdateSignal('updatePageTree');
                        }
                    }
                    $import->display_import_pid_record = $this->pageinfo;
                    $overviewContent = $import->displayContentOverview();
                }
                // Meta data output:
                $trow[] = '<tr class="bgColor5">
						<td colspan="2"><strong>' . $this->lang->getLL('importdata_metaData', true) . '</strong></td>
					</tr>';
                $trow[] = '<tr class="bgColor4">
					<td><strong>' . $this->lang->getLL('importdata_title', true) . '</strong></td>
					<td width="95%">' . nl2br(htmlspecialchars($import->dat['header']['meta']['title'])) . '</td>
					</tr>';
                $trow[] = '<tr class="bgColor4">
					<td><strong>' . $this->lang->getLL('importdata_description', true) . '</strong></td>
					<td width="95%">' . nl2br(htmlspecialchars($import->dat['header']['meta']['description'])) . '</td>
					</tr>';
                $trow[] = '<tr class="bgColor4">
					<td><strong>' . $this->lang->getLL('importdata_notes', true) . '</strong></td>
					<td width="95%">' . nl2br(htmlspecialchars($import->dat['header']['meta']['notes'])) . '</td>
					</tr>';
                $trow[] = '<tr class="bgColor4">
					<td><strong>' . $this->lang->getLL('importdata_packager', true) . '</strong></td>
					<td width="95%">' . nl2br(htmlspecialchars($import->dat['header']['meta']['packager_name'] . ' (' . $import->dat['header']['meta']['packager_username'] . ')')) . '<br/>
						' . $this->lang->getLL('importdata_email', true) . ' ' . $import->dat['header']['meta']['packager_email'] . '</td>
					</tr>';
                // Thumbnail icon:
                if (is_array($import->dat['header']['thumbnail'])) {
                    $pI = pathinfo($import->dat['header']['thumbnail']['filename']);
                    if (GeneralUtility::inList('gif,jpg,png,jpeg', strtolower($pI['extension']))) {
                        // Construct filename and write it:
                        $fileName = PATH_site . 'typo3temp/importthumb.' . $pI['extension'];
                        GeneralUtility::writeFile($fileName, $import->dat['header']['thumbnail']['content']);
                        // Check that the image really is an image and not a malicious PHP script...
                        if (getimagesize($fileName)) {
                            // Create icon tag:
                            $iconTag = '<img src="../' . PathUtility::stripPathSitePrefix($fileName) . '" ' . $import->dat['header']['thumbnail']['imgInfo'][3] . ' vspace="5" style="border: solid black 1px;" alt="" />';
                            $trow[] = '<tr class="bgColor4">
								<td><strong>' . $this->lang->getLL('importdata_icon', true) . '</strong></td>
								<td>' . $iconTag . '</td>
								</tr>';
                        } else {
                            GeneralUtility::unlink_tempfile($fileName);
                        }
                    }
                }
                $menuItems[] = array('label' => $this->lang->getLL('importdata_metaData_1387'), 'content' => '
						<table border="0" cellpadding="1" cellspacing="1">
							' . implode('
							', $trow) . '
						</table>
					');
            }
            // Print errors that might be:
            $errors = $import->printErrorLog();
            $menuItems[] = array('label' => $this->lang->getLL('importdata_messages'), 'content' => $errors, 'stateIcon' => $errors ? 2 : 0);
            // Output tabs:
            $content = $this->moduleTemplate->getDynamicTabMenu($menuItems, 'tx_impexp_import', 1, false, true, false);
            if ($extensionInstallationMessage) {
                $content = '<div style="border: 1px black solid; margin: 10px 10px 10px 10px; padding: 10px 10px 10px 10px;">' . $this->moduleTemplate->icons(1) . htmlspecialchars($extensionInstallationMessage) . '</div>' . $content;
            }
            $this->content .= $this->moduleTemplate->section('', $content, 0, 1);
            // Print overview:
            if ($overviewContent) {
                $this->content .= $this->moduleTemplate->section($inData['import_file'] ? $this->lang->getLL('importdata_structureHasBeenImported', true) : $this->lang->getLL('filterpage_structureToBeImported', true), $overviewContent, 0, 1);
            }
        }
    }