[BUGFIX] Impexp is broken
authorPhilipp Gampe <philipp.gampe@typo3.org>
Sun, 25 Nov 2012 04:26:17 +0000 (05:26 +0100)
committerHelmut Hummel <helmut.hummel@typo3.org>
Sun, 25 Nov 2012 08:17:22 +0000 (09:17 +0100)
The autoloader assumes that classes are located inside Classes, but the
directory is still lower case classes.

Rename the directory to conform to the default behavior.

Fixes: #43280
Releases: 6.0

Change-Id: Id8fc4c4e2f5290a45d4aac62ca577d6fdbfb5266
Reviewed-on: http://review.typo3.org/16720
Reviewed-by: Helmut Hummel
Tested-by: Helmut Hummel
20 files changed:
typo3/sysext/impexp/Classes/Clickmenu.php [new file with mode: 0644]
typo3/sysext/impexp/Classes/Controller/ImportExportController.php [new file with mode: 0644]
typo3/sysext/impexp/Classes/Controller/ModuleFunctionController.php [new file with mode: 0644]
typo3/sysext/impexp/Classes/ImportExport.php [new file with mode: 0644]
typo3/sysext/impexp/Classes/LocalPageTree.php [new file with mode: 0644]
typo3/sysext/impexp/Classes/Task/ImportExportTask.php [new file with mode: 0644]
typo3/sysext/impexp/Classes/class.tx_impexp_localpagetree.php [new file with mode: 0644]
typo3/sysext/impexp/app/index.php
typo3/sysext/impexp/class.tx_impexp.php
typo3/sysext/impexp/class.tx_impexp_clickmenu.php
typo3/sysext/impexp/classes/Clickmenu.php [deleted file]
typo3/sysext/impexp/classes/Controller/ImportExportController.php [deleted file]
typo3/sysext/impexp/classes/Controller/ModuleFunctionController.php [deleted file]
typo3/sysext/impexp/classes/ImportExport.php [deleted file]
typo3/sysext/impexp/classes/LocalPageTree.php [deleted file]
typo3/sysext/impexp/classes/Task/ImportExportTask.php [deleted file]
typo3/sysext/impexp/classes/class.tx_impexp_localpagetree.php [deleted file]
typo3/sysext/impexp/ext_autoload.php
typo3/sysext/impexp/modfunc1/class.tx_impexp_modfunc1.php
typo3/sysext/impexp/task/class.tx_impexp_task.php

diff --git a/typo3/sysext/impexp/Classes/Clickmenu.php b/typo3/sysext/impexp/Classes/Clickmenu.php
new file mode 100644 (file)
index 0000000..960d343
--- /dev/null
@@ -0,0 +1,93 @@
+<?php
+namespace TYPO3\CMS\Impexp;
+
+/***************************************************************
+ *  Copyright notice
+ *
+ *  (c) 1999-2011 Kasper Skårhøj (kasperYYYY@typo3.com)
+ *  All rights reserved
+ *
+ *  This script is part of the TYPO3 project. The TYPO3 project is
+ *  free software; you can redistribute it and/or modify
+ *  it under the terms of the GNU General Public License as published by
+ *  the Free Software Foundation; either version 2 of the License, or
+ *  (at your option) any later version.
+ *
+ *  The GNU General Public License can be found at
+ *  http://www.gnu.org/copyleft/gpl.html.
+ *  A copy is found in the textfile GPL.txt and important notices to the license
+ *  from the author is found in LICENSE.txt distributed with these scripts.
+ *
+ *
+ *  This script is distributed in the hope that it will be useful,
+ *  but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ *  GNU General Public License for more details.
+ *
+ *  This copyright notice MUST APPEAR in all copies of the script!
+ ***************************************************************/
+/**
+ * Adding Import/Export clickmenu item
+ *
+ * Revised for TYPO3 3.6 December/2003 by Kasper Skårhøj
+ * XHTML compliant
+ *
+ * @author Kasper Skårhøj <kasperYYYY@typo3.com>
+ */
+/**
+ * Adding Import/Export clickmenu item
+ *
+ * @author Kasper Skårhøj <kasperYYYY@typo3.com>
+ */
+class Clickmenu {
+
+       /**
+        * Processing of clickmenu items
+        *
+        * @param object $backRef Reference to parent
+        * @param array $menuItems Menu items array to modify
+        * @param string $table Table name
+        * @param integer $uid Uid of the record
+        * @return array Menu item array, returned after modification
+        * @todo Skinning for icons...
+        * @todo Define visibility
+        */
+       public function main(&$backRef, $menuItems, $table, $uid) {
+               $localItems = array();
+               // Show import/export on second level menu OR root level.
+               if ($backRef->cmLevel && \t3lib_div::_GP('subname') == 'moreoptions' || $table === 'pages' && $uid == 0) {
+                       $LL = $this->includeLL();
+                       $modUrl = $backRef->backPath . t3lib_extMgm::extRelPath('impexp') . 'app/index.php';
+                       $url = $modUrl . '?tx_impexp[action]=export&id=' . ($table == 'pages' ? $uid : $backRef->rec['pid']);
+                       if ($table == 'pages') {
+                               $url .= '&tx_impexp[pagetree][id]=' . $uid;
+                               $url .= '&tx_impexp[pagetree][levels]=0';
+                               $url .= '&tx_impexp[pagetree][tables][]=_ALL';
+                       } else {
+                               $url .= '&tx_impexp[record][]=' . rawurlencode(($table . ':' . $uid));
+                               $url .= '&tx_impexp[external_ref][tables][]=_ALL';
+                       }
+                       $localItems[] = $backRef->linkItem($GLOBALS['LANG']->makeEntities($GLOBALS['LANG']->getLLL('export', $LL)), $backRef->excludeIcon(\t3lib_iconWorks::getSpriteIcon('actions-document-export-t3d')), $backRef->urlRefForCM($url), 1);
+                       if ($table == 'pages') {
+                               $url = $modUrl . '?id=' . $uid . '&table=' . $table . '&tx_impexp[action]=import';
+                               $localItems[] = $backRef->linkItem($GLOBALS['LANG']->makeEntities($GLOBALS['LANG']->getLLL('import', $LL)), $backRef->excludeIcon(\t3lib_iconWorks::getSpriteIcon('actions-document-import-t3d')), $backRef->urlRefForCM($url), 1);
+                       }
+               }
+               return array_merge($menuItems, $localItems);
+       }
+
+       /**
+        * Include local lang file and return $LOCAL_LANG array loaded.
+        *
+        * @return array Local lang array
+        * @todo Define visibility
+        */
+       public function includeLL() {
+               global $LANG;
+               return $LANG->includeLLFile('EXT:impexp/app/locallang.php', FALSE);
+       }
+
+}
+
+
+?>
\ No newline at end of file
diff --git a/typo3/sysext/impexp/Classes/Controller/ImportExportController.php b/typo3/sysext/impexp/Classes/Controller/ImportExportController.php
new file mode 100644 (file)
index 0000000..58776ca
--- /dev/null
@@ -0,0 +1,1229 @@
+<?php
+namespace TYPO3\CMS\Impexp\Controller;
+
+/**
+ * Main script class for the Import / Export facility
+ *
+ * @author Kasper Skårhøj <kasperYYYY@typo3.com>
+ */
+class ImportExportController extends \TYPO3\CMS\Backend\Module\BaseScriptClass {
+
+       // Array containing the current page.
+       /**
+        * @todo Define visibility
+        */
+       public $pageinfo;
+
+       /**
+        * Main module function
+        *
+        * @return void
+        * @todo Define visibility
+        */
+       public function main() {
+               // Start document template object:
+               $this->doc = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance('TYPO3\\CMS\\Backend\\Template\\DocumentTemplate');
+               $this->doc->backPath = $GLOBALS['BACK_PATH'];
+               $this->doc->bodyTagId = 'imp-exp-mod';
+               $this->doc->setModuleTemplate(\TYPO3\CMS\Core\Utility\ExtensionManagementUtility::extRelPath('impexp') . '/app/template.html');
+               $this->pageinfo = \TYPO3\CMS\Backend\Utility\BackendUtility::readPageAccess($this->id, $this->perms_clause);
+               // JavaScript
+               $this->doc->JScode = $this->doc->wrapScriptTags('
+                       script_ended = 0;
+                       function jumpToUrl(URL) {       //
+                               window.location.href = URL;
+                       }
+               ');
+               // Setting up the context sensitive menu:
+               $this->doc->getContextMenuCode();
+               $this->doc->postCode = $this->doc->wrapScriptTags('
+                       script_ended = 1;
+                       if (top.fsMod) top.fsMod.recentIds["web"] = ' . intval($this->id) . ';
+               ');
+               $this->doc->form = '<form action="' . htmlspecialchars($GLOBALS['MCONF']['_']) . '" method="post" enctype="' . $GLOBALS['TYPO3_CONF_VARS']['SYS']['form_enctype'] . '"><input type="hidden" name="id" value="' . $this->id . '" />';
+               $this->content .= $this->doc->header($GLOBALS['LANG']->getLL('title'));
+               $this->content .= $this->doc->spacer(5);
+               // Input data grabbed:
+               $inData = \TYPO3\CMS\Core\Utility\GeneralUtility::_GP('tx_impexp');
+               $this->checkUpload();
+               switch ((string) $inData['action']) {
+               case 'export':
+                       // Finally: If upload went well, set the new file as the thumbnail in the $inData array:
+                       if (is_object($this->fileProcessor) && $this->fileProcessor->internalUploadMap[1]) {
+                               $inData['meta']['thumbnail'] = md5($this->fileProcessor->internalUploadMap[1]);
+                       }
+                       // Call export interface
+                       $this->exportData($inData);
+                       break;
+               case 'import':
+                       // Finally: If upload went well, set the new file as the import file:
+                       if (is_object($this->fileProcessor) && $this->fileProcessor->internalUploadMap[1]) {
+                               $fI = pathinfo($this->fileProcessor->internalUploadMap[1]);
+                               // Only allowed extensions....
+                               if (\TYPO3\CMS\Core\Utility\GeneralUtility::inList('t3d,xml', strtolower($fI['extension']))) {
+                                       $inData['file'] = $this->fileProcessor->internalUploadMap[1];
+                               }
+                       }
+                       // Call import interface:
+                       $this->importData($inData);
+                       break;
+               }
+               // Setting up the buttons and markers for docheader
+               $docHeaderButtons = $this->getButtons();
+               $markers['CONTENT'] = $this->content;
+               // Build the <body> for the module
+               $this->content = $this->doc->startPage($GLOBALS['LANG']->getLL('title'));
+               $this->content .= $this->doc->moduleBody($this->pageinfo, $docHeaderButtons, $markers);
+               $this->content .= $this->doc->endPage();
+               $this->content = $this->doc->insertStylesAndJS($this->content);
+       }
+
+       /**
+        * Print the content
+        *
+        * @return void
+        * @todo Define visibility
+        */
+       public function printContent() {
+               echo $this->content;
+       }
+
+       /**
+        * Create the panel of buttons for submitting the form or otherwise perform operations.
+        *
+        * @return array all available buttons as an associated array
+        */
+       protected function getButtons() {
+               $buttons = array(
+                       'view' => '',
+                       'shortcut' => ''
+               );
+               if ($GLOBALS['BE_USER']->mayMakeShortcut()) {
+                       $buttons['shortcut'] = $this->doc->makeShortcutIcon('tx_impexp', '', $this->MCONF['name']);
+               }
+               // Input data grabbed:
+               $inData = \TYPO3\CMS\Core\Utility\GeneralUtility::_GP('tx_impexp');
+               if ((string) $inData['action'] == 'import') {
+                       if ($this->id && is_array($this->pageinfo) || $GLOBALS['BE_USER']->user['admin'] && !$this->id) {
+                               if (is_array($this->pageinfo) && $this->pageinfo['uid']) {
+                                       // View
+                                       $buttons['view'] = '<a href="#" onclick="' . htmlspecialchars(\TYPO3\CMS\Backend\Utility\BackendUtility::viewOnClick($this->pageinfo['uid'], $this->doc->backPath, \TYPO3\CMS\Backend\Utility\BackendUtility::BEgetRootLine($this->pageinfo['uid']))) . '" title="' . $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.php:labels.showPage', TRUE) . '">' . \TYPO3\CMS\Backend\Utility\IconUtility::getSpriteIcon('actions-document-view') . '</a>';
+                               }
+                       }
+               }
+               return $buttons;
+       }
+
+       /**************************
+        *
+        * EXPORT FUNCTIONS
+        *
+        **************************/
+       /**
+        * Export part of module
+        *
+        * @param array $inData Content of POST VAR tx_impexp[]..
+        * @return void Setting content in $this->content
+        * @todo Define visibility
+        */
+       public function exportData($inData) {
+               // BUILDING EXPORT DATA:
+               // Processing of InData array values:
+               $inData['pagetree']['maxNumber'] = \TYPO3\CMS\Core\Utility\MathUtility::forceIntegerInRange($inData['pagetree']['maxNumber'], 1, 10000, 100);
+               $inData['listCfg']['maxNumber'] = \TYPO3\CMS\Core\Utility\MathUtility::forceIntegerInRange($inData['listCfg']['maxNumber'], 1, 10000, 100);
+               $inData['maxFileSize'] = \TYPO3\CMS\Core\Utility\MathUtility::forceIntegerInRange($inData['maxFileSize'], 1, 10000, 1000);
+               $inData['filename'] = trim(preg_replace('/[^[:alnum:]._-]*/', '', preg_replace('/\\.(t3d|xml)$/', '', $inData['filename'])));
+               if (strlen($inData['filename'])) {
+                       $inData['filename'] .= $inData['filetype'] == 'xml' ? '.xml' : '.t3d';
+               }
+               // Set exclude fields in export object:
+               if (!is_array($inData['exclude'])) {
+                       $inData['exclude'] = array();
+               }
+               // Saving/Loading/Deleting presets:
+               $this->processPresets($inData);
+               // Create export object and configure it:
+               $this->export = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance('TYPO3\\CMS\\Impexp\\ImportExport');
+               $this->export->init(0, 'export');
+               $this->export->setCharset($GLOBALS['LANG']->charSet);
+               $this->export->maxFileSize = $inData['maxFileSize'] * 1024;
+               $this->export->excludeMap = (array) $inData['exclude'];
+               $this->export->softrefCfg = (array) $inData['softrefCfg'];
+               $this->export->extensionDependencies = (array) $inData['extension_dep'];
+               $this->export->showStaticRelations = $inData['showStaticRelations'];
+               $this->export->includeExtFileResources = !$inData['excludeHTMLfileResources'];
+               // Static tables:
+               if (is_array($inData['external_static']['tables'])) {
+                       $this->export->relStaticTables = $inData['external_static']['tables'];
+               }
+               // Configure which tables external relations are included for:
+               if (is_array($inData['external_ref']['tables'])) {
+                       $this->export->relOnlyTables = $inData['external_ref']['tables'];
+               }
+               $this->export->setHeaderBasics();
+               // Meta data setting:
+               $this->export->setMetaData($inData['meta']['title'], $inData['meta']['description'], $inData['meta']['notes'], $GLOBALS['BE_USER']->user['username'], $GLOBALS['BE_USER']->user['realName'], $GLOBALS['BE_USER']->user['email']);
+               if ($inData['meta']['thumbnail']) {
+                       $tempDir = $this->userTempFolder();
+                       if ($tempDir) {
+                               $thumbnails = \TYPO3\CMS\Core\Utility\GeneralUtility::getFilesInDir($tempDir, 'png,gif,jpg', 1);
+                               $theThumb = $thumbnails[$inData['meta']['thumbnail']];
+                               if ($theThumb) {
+                                       $this->export->addThumbnail($theThumb);
+                               }
+                       }
+               }
+               // Configure which records to export
+               if (is_array($inData['record'])) {
+                       foreach ($inData['record'] as $ref) {
+                               $rParts = explode(':', $ref);
+                               $this->export->export_addRecord($rParts[0], \TYPO3\CMS\Backend\Utility\BackendUtility::getRecord($rParts[0], $rParts[1]));
+                       }
+               }
+               // Configure which tables to export
+               if (is_array($inData['list'])) {
+                       foreach ($inData['list'] as $ref) {
+                               $rParts = explode(':', $ref);
+                               if ($GLOBALS['BE_USER']->check('tables_select', $rParts[0])) {
+                                       $res = $this->exec_listQueryPid($rParts[0], $rParts[1], \TYPO3\CMS\Core\Utility\MathUtility::forceIntegerInRange($inData['listCfg']['maxNumber'], 1));
+                                       while ($subTrow = $GLOBALS['TYPO3_DB']->sql_fetch_assoc($res)) {
+                                               $this->export->export_addRecord($rParts[0], $subTrow);
+                                       }
+                               }
+                       }
+               }
+               // Pagetree
+               if (isset($inData['pagetree']['id'])) {
+                       // Based on click-expandable tree
+                       if ($inData['pagetree']['levels'] == -1) {
+                               $pagetree = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance('tx_impexp_localPageTree');
+                               $tree = $pagetree->ext_tree($inData['pagetree']['id'], $this->filterPageIds($this->export->excludeMap));
+                               $this->treeHTML = $pagetree->printTree($tree);
+                               $idH = $pagetree->buffer_idH;
+                       } elseif ($inData['pagetree']['levels'] == -2) {
+                               $this->addRecordsForPid($inData['pagetree']['id'], $inData['pagetree']['tables'], $inData['pagetree']['maxNumber']);
+                       } else {
+                               // Based on depth
+                               // Drawing tree:
+                               // If the ID is zero, export root
+                               if (!$inData['pagetree']['id'] && $GLOBALS['BE_USER']->isAdmin()) {
+                                       $sPage = array(
+                                               'uid' => 0,
+                                               'title' => 'ROOT'
+                                       );
+                               } else {
+                                       $sPage = \TYPO3\CMS\Backend\Utility\BackendUtility::getRecordWSOL('pages', $inData['pagetree']['id'], '*', ' AND ' . $this->perms_clause);
+                               }
+                               if (is_array($sPage)) {
+                                       $pid = $inData['pagetree']['id'];
+                                       $tree = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance('TYPO3\\CMS\\Backend\\Tree\\View\\PageTreeView');
+                                       $tree->init('AND ' . $this->perms_clause . $this->filterPageIds($this->export->excludeMap));
+                                       $HTML = \TYPO3\CMS\Backend\Utility\IconUtility::getSpriteIconForRecord('pages', $sPage);
+                                       $tree->tree[] = array('row' => $sPage, 'HTML' => $HTML);
+                                       $tree->buffer_idH = array();
+                                       if ($inData['pagetree']['levels'] > 0) {
+                                               $tree->getTree($pid, $inData['pagetree']['levels'], '');
+                                       }
+                                       $idH = array();
+                                       $idH[$pid]['uid'] = $pid;
+                                       if (count($tree->buffer_idH)) {
+                                               $idH[$pid]['subrow'] = $tree->buffer_idH;
+                                       }
+                                       $pagetree = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance('TYPO3\\CMS\\Impexp\\ImportExport_localPageTree');
+                                       $this->treeHTML = $pagetree->printTree($tree->tree);
+                               }
+                       }
+                       // In any case we should have a multi-level array, $idH, with the page structure here (and the HTML-code loaded into memory for nice display...)
+                       if (is_array($idH)) {
+                               // Sets the pagetree and gets a 1-dim array in return with the pages (in correct submission order BTW...)
+                               $flatList = $this->export->setPageTree($idH);
+                               foreach ($flatList as $k => $value) {
+                                       $this->export->export_addRecord('pages', \TYPO3\CMS\Backend\Utility\BackendUtility::getRecord('pages', $k));
+                                       $this->addRecordsForPid($k, $inData['pagetree']['tables'], $inData['pagetree']['maxNumber']);
+                               }
+                       }
+               }
+               // After adding ALL records we set relations:
+               for ($a = 0; $a < 10; $a++) {
+                       $addR = $this->export->export_addDBRelations($a);
+                       if (!count($addR)) {
+                               break;
+                       }
+               }
+               // Finally files are added:
+               // MUST be after the DBrelations are set so that files from ALL added records are included!
+               $this->export->export_addFilesFromRelations();
+               // If the download button is clicked, return file
+               if ($inData['download_export'] || $inData['save_export']) {
+                       switch ((string) $inData['filetype']) {
+                       case 'xml':
+                               $out = $this->export->compileMemoryToFileContent('xml');
+                               $fExt = '.xml';
+                               break;
+                       case 't3d':
+                               $this->export->dontCompress = 1;
+                       default:
+                               $out = $this->export->compileMemoryToFileContent();
+                               $fExt = ($this->export->doOutputCompress() ? '-z' : '') . '.t3d';
+                               break;
+                       }
+                       // Filename:
+                       $dlFile = $inData['filename'] ? $inData['filename'] : 'T3D_' . substr(preg_replace('/[^[:alnum:]_]/', '-', $inData['download_export_name']), 0, 20) . '_' . date('Y-m-d_H-i') . $fExt;
+                       // Export for download:
+                       if ($inData['download_export']) {
+                               $mimeType = 'application/octet-stream';
+                               Header('Content-Type: ' . $mimeType);
+                               Header('Content-Length: ' . strlen($out));
+                               Header('Content-Disposition: attachment; filename=' . basename($dlFile));
+                               echo $out;
+                               die;
+                       }
+                       // Export by saving:
+                       if ($inData['save_export']) {
+                               $savePath = $this->userSaveFolder();
+                               $fullName = $savePath . $dlFile;
+                               if (\TYPO3\CMS\Core\Utility\GeneralUtility::isAllowedAbsPath($savePath) && @is_dir(dirname($fullName)) && \TYPO3\CMS\Core\Utility\GeneralUtility::isAllowedAbsPath($fullName)) {
+                                       \TYPO3\CMS\Core\Utility\GeneralUtility::writeFile($fullName, $out);
+                                       $this->content .= $this->doc->section($GLOBALS['LANG']->getLL('exportdata_savedFile'), sprintf($GLOBALS['LANG']->getLL('exportdata_savedInSBytes', 1), substr($savePath . $dlFile, strlen(PATH_site)), \TYPO3\CMS\Core\Utility\GeneralUtility::formatSize(strlen($out))), 0, 1);
+                               } else {
+                                       $this->content .= $this->doc->section($GLOBALS['LANG']->getLL('exportdata_problemsSavingFile'), sprintf($GLOBALS['LANG']->getLL('exportdata_badPathS', 1), $fullName), 0, 1, 2);
+                               }
+                       }
+               }
+               // OUTPUT to BROWSER:
+               // Now, if we didn't make download file, show configuration form based on export:
+               $menuItems = array();
+               // Export configuration
+               $row = array();
+               $this->makeConfigurationForm($inData, $row);
+               $menuItems[] = array(
+                       'label' => $GLOBALS['LANG']->getLL('tableselec_configuration'),
+                       'content' => '
+                               <table border="0" cellpadding="1" cellspacing="1">
+                                       ' . implode('
+                                       ', $row) . '
+                               </table>
+                       '
+               );
+               // File options
+               $row = array();
+               $this->makeSaveForm($inData, $row);
+               $menuItems[] = array(
+                       'label' => $GLOBALS['LANG']->getLL('exportdata_filePreset'),
+                       'content' => '
+                               <table border="0" cellpadding="1" cellspacing="1">
+                                       ' . implode('
+                                       ', $row) . '
+                               </table>
+                       '
+               );
+               // File options
+               $row = array();
+               $this->makeAdvancedOptionsForm($inData, $row);
+               $menuItems[] = array(
+                       'label' => $GLOBALS['LANG']->getLL('exportdata_advancedOptions'),
+                       'content' => '
+                               <table border="0" cellpadding="1" cellspacing="1">
+                                       ' . implode('
+                                       ', $row) . '
+                               </table>
+                       '
+               );
+               // Generate overview:
+               $overViewContent = $this->export->displayContentOverview();
+               // Print errors that might be:
+               $errors = $this->export->printErrorLog();
+               $menuItems[] = array(
+                       'label' => $GLOBALS['LANG']->getLL('exportdata_messages'),
+                       'content' => $errors,
+                       'stateIcon' => $errors ? 2 : 0
+               );
+               // Add hidden fields and create tabs:
+               $content = $this->doc->getDynTabMenu($menuItems, 'tx_impexp_export', -1);
+               $content .= '<input type="hidden" name="tx_impexp[action]" value="export" />';
+               $this->content .= $this->doc->section('', $content, 0, 1);
+               // Output Overview:
+               $this->content .= $this->doc->section($GLOBALS['LANG']->getLL('execlistqu_structureToBeExported'), $overViewContent, 0, 1);
+       }
+
+       /**
+        * Adds records to the export object for a specific page id.
+        *
+        * @param integer $k Page id for which to select records to add
+        * @param array $tables Array of table names to select from
+        * @param integer $maxNumber Max amount of records to select
+        * @return void
+        * @todo Define visibility
+        */
+       public function addRecordsForPid($k, $tables, $maxNumber) {
+               if (is_array($tables)) {
+                       foreach ($GLOBALS['TCA'] as $table => $value) {
+                               if ($table != 'pages' && (in_array($table, $tables) || in_array('_ALL', $tables))) {
+                                       if ($GLOBALS['BE_USER']->check('tables_select', $table) && !$GLOBALS['TCA'][$table]['ctrl']['is_static']) {
+                                               $res = $this->exec_listQueryPid($table, $k, \TYPO3\CMS\Core\Utility\MathUtility::forceIntegerInRange($maxNumber, 1));
+                                               while ($subTrow = $GLOBALS['TYPO3_DB']->sql_fetch_assoc($res)) {
+                                                       $this->export->export_addRecord($table, $subTrow);
+                                               }
+                                       }
+                               }
+                       }
+               }
+       }
+
+       /**
+        * Selects records from table / pid
+        *
+        * @param string $table Table to select from
+        * @param integer $pid Page ID to select from
+        * @param integer $limit Max number of records to select
+        * @return pointer SQL resource pointer
+        * @todo Define visibility
+        */
+       public function exec_listQueryPid($table, $pid, $limit) {
+               $orderBy = $GLOBALS['TCA'][$table]['ctrl']['sortby'] ? 'ORDER BY ' . $GLOBALS['TCA'][$table]['ctrl']['sortby'] : $GLOBALS['TCA'][$table]['ctrl']['default_sortby'];
+               $res = $GLOBALS['TYPO3_DB']->exec_SELECTquery('*', $table, 'pid=' . intval($pid) . \TYPO3\CMS\Backend\Utility\BackendUtility::deleteClause($table) . \TYPO3\CMS\Backend\Utility\BackendUtility::versioningPlaceholderClause($table), '', $GLOBALS['TYPO3_DB']->stripOrderBy($orderBy), $limit);
+               // Warning about hitting limit:
+               if ($GLOBALS['TYPO3_DB']->sql_num_rows($res) == $limit) {
+                       $this->content .= $this->doc->section($GLOBALS['LANG']->getLL('execlistqu_maxNumberLimit'), sprintf($GLOBALS['LANG']->getLL('makeconfig_anSqlQueryReturned', 1), $limit), 0, 1, 2);
+               }
+               return $res;
+       }
+
+       /**
+        * Create configuration form
+        *
+        * @param array $inData Form configurat data
+        * @param array  Table row accumulation variable. This is filled with table rows.
+        * @return void Sets content in $this->content
+        * @todo Define visibility
+        */
+       public function makeConfigurationForm($inData, &$row) {
+               global $LANG;
+               $nameSuggestion = '';
+               // Page tree export options:
+               if (isset($inData['pagetree']['id'])) {
+                       $nameSuggestion .= 'tree_PID' . $inData['pagetree']['id'] . '_L' . $inData['pagetree']['levels'];
+                       $row[] = '
+                               <tr class="tableheader bgColor5">
+                                       <td colspan="2">' . $LANG->getLL('makeconfig_exportPagetreeConfiguration', 1) . \TYPO3\CMS\Backend\Utility\BackendUtility::cshItem('xMOD_tx_impexp', 'pageTreeCfg', $GLOBALS['BACK_PATH'], '') . '</td>
+                               </tr>';
+                       $row[] = '
+                               <tr class="bgColor4">
+                                       <td><strong>' . $LANG->getLL('makeconfig_pageId', 1) . '</strong></td>
+                                       <td>' . htmlspecialchars($inData['pagetree']['id']) . '<input type="hidden" value="' . htmlspecialchars($inData['pagetree']['id']) . '" name="tx_impexp[pagetree][id]" /></td>
+                               </tr>';
+                       $row[] = '
+                               <tr class="bgColor4">
+                                       <td><strong>' . $LANG->getLL('makeconfig_tree', 1) . '</strong>' . \TYPO3\CMS\Backend\Utility\BackendUtility::cshItem('xMOD_tx_impexp', 'pageTreeDisplay', $GLOBALS['BACK_PATH'], '') . '</td>
+                                       <td>' . ($this->treeHTML ? $this->treeHTML : $LANG->getLL('makeconfig_noTreeExportedOnly', 1)) . '</td>
+                               </tr>';
+                       $opt = array(
+                               '-2' => $LANG->getLL('makeconfig_tablesOnThisPage'),
+                               '-1' => $LANG->getLL('makeconfig_expandedTree'),
+                               '0' => $LANG->getLL('makeconfig_onlyThisPage'),
+                               '1' => $LANG->getLL('makeconfig_1Level'),
+                               '2' => $LANG->getLL('makeconfig_2Levels'),
+                               '3' => $LANG->getLL('makeconfig_3Levels'),
+                               '4' => $LANG->getLL('makeconfig_4Levels'),
+                               '999' => $LANG->getLL('makeconfig_infinite')
+                       );
+                       $row[] = '
+                               <tr class="bgColor4">
+                                       <td><strong>' . $LANG->getLL('makeconfig_levels', 1) . '</strong>' . \TYPO3\CMS\Backend\Utility\BackendUtility::cshItem('xMOD_tx_impexp', 'pageTreeMode', $GLOBALS['BACK_PATH'], '') . '</td>
+                                       <td>' . $this->renderSelectBox('tx_impexp[pagetree][levels]', $inData['pagetree']['levels'], $opt) . '</td>
+                               </tr>';
+                       $row[] = '
+                               <tr class="bgColor4">
+                                       <td><strong>' . $LANG->getLL('makeconfig_includeTables', 1) . '</strong>' . \TYPO3\CMS\Backend\Utility\BackendUtility::cshItem('xMOD_tx_impexp', 'pageTreeRecordLimit', $GLOBALS['BACK_PATH'], '') . '</td>
+                                       <td>' . $this->tableSelector('tx_impexp[pagetree][tables]', $inData['pagetree']['tables'], 'pages') . '<br/>
+                                               ' . $LANG->getLL('makeconfig_maxNumberOfRecords', 1) . '<br/>
+                                               <input type="text" name="tx_impexp[pagetree][maxNumber]" value="' . htmlspecialchars($inData['pagetree']['maxNumber']) . '"' . $this->doc->formWidth(10) . ' /><br/>
+                                       </td>
+                               </tr>';
+               }
+               // Single record export:
+               if (is_array($inData['record'])) {
+                       $row[] = '
+                               <tr class="tableheader bgColor5">
+                                       <td colspan="2">' . $LANG->getLL('makeconfig_exportSingleRecord', 1) . \TYPO3\CMS\Backend\Utility\BackendUtility::cshItem('xMOD_tx_impexp', 'singleRecord', $GLOBALS['BACK_PATH'], '') . '</td>
+                               </tr>';
+                       foreach ($inData['record'] as $ref) {
+                               $rParts = explode(':', $ref);
+                               $tName = $rParts[0];
+                               $rUid = $rParts[1];
+                               $nameSuggestion .= $tName . '_' . $rUid;
+                               $rec = \TYPO3\CMS\Backend\Utility\BackendUtility::getRecordWSOL($tName, $rUid);
+                               $row[] = '
+                               <tr class="bgColor4">
+                                       <td><strong>' . $LANG->getLL('makeconfig_record', 1) . '</strong></td>
+                                       <td>' . \t3lib_iconworks::getSpriteIconForRecord($tName, $rec) . \TYPO3\CMS\Backend\Utility\BackendUtility::getRecordTitle($tName, $rec, TRUE) . '<input type="hidden" name="tx_impexp[record][]" value="' . htmlspecialchars(($tName . ':' . $rUid)) . '" /></td>
+                               </tr>';
+                       }
+               }
+               // Single tables/pids:
+               if (is_array($inData['list'])) {
+                       $row[] = '
+                               <tr class="tableheader bgColor5">
+                                       <td colspan="2">' . $LANG->getLL('makeconfig_exportTablesFromPages', 1) . '</td>
+                               </tr>';
+                       // Display information about pages from which the export takes place
+                       $tblList = '';
+                       foreach ($inData['list'] as $reference) {
+                               $referenceParts = explode(':', $reference);
+                               $tableName = $referenceParts[0];
+                               if ($GLOBALS['BE_USER']->check('tables_select', $tableName)) {
+                                       // If the page is actually the root, handle it differently
+                                       // NOTE: we don't compare integers, because the number actually comes from the split string above
+                                       if ($referenceParts[1] === '0') {
+                                               $iconAndTitle = \TYPO3\CMS\Backend\Utility\IconUtility::getSpriteIcon('apps-pagetree-root') . $GLOBALS['TYPO3_CONF_VARS']['SYS']['sitename'];
+                                       } else {
+                                               $record = \TYPO3\CMS\Backend\Utility\BackendUtility::getRecordWSOL('pages', $referenceParts[1]);
+                                               $iconAndTitle = \t3lib_iconworks::getSpriteIconForRecord('pages', $record) . \TYPO3\CMS\Backend\Utility\BackendUtility::getRecordTitle('pages', $record, TRUE);
+                                       }
+                                       $tblList .= 'Table "' . $tableName . '" from ' . $iconAndTitle . '<input type="hidden" name="tx_impexp[list][]" value="' . htmlspecialchars($reference) . '" /><br/>';
+                               }
+                       }
+                       $row[] = '
+                       <tr class="bgColor4">
+                               <td><strong>' . $LANG->getLL('makeconfig_tablePids', 1) . '</strong>' . \TYPO3\CMS\Backend\Utility\BackendUtility::cshItem('xMOD_tx_impexp', 'tableList', $GLOBALS['BACK_PATH'], '') . '</td>
+                               <td>' . $tblList . '</td>
+                       </tr>';
+                       $row[] = '
+                               <tr class="bgColor4">
+                                       <td><strong>' . $LANG->getLL('makeconfig_maxNumberOfRecords', 1) . \TYPO3\CMS\Backend\Utility\BackendUtility::cshItem('xMOD_tx_impexp', 'tableListMaxNumber', $GLOBALS['BACK_PATH'], '') . '</strong></td>
+                                       <td>
+                                               <input type="text" name="tx_impexp[listCfg][maxNumber]" value="' . htmlspecialchars($inData['listCfg']['maxNumber']) . '"' . $this->doc->formWidth(10) . ' /><br/>
+                                       </td>
+                               </tr>';
+               }
+               $row[] = '
+                       <tr class="tableheader bgColor5">
+                               <td colspan="2">' . $LANG->getLL('makeconfig_relationsAndExclusions', 1) . '</td>
+                       </tr>';
+               // Add relation selector:
+               $row[] = '
+                               <tr class="bgColor4">
+                                       <td><strong>' . $LANG->getLL('makeconfig_includeRelationsToTables', 1) . '</strong>' . \TYPO3\CMS\Backend\Utility\BackendUtility::cshItem('xMOD_tx_impexp', 'inclRelations', $GLOBALS['BACK_PATH'], '') . '</td>
+                                       <td>' . $this->tableSelector('tx_impexp[external_ref][tables]', $inData['external_ref']['tables']) . '</td>
+                               </tr>';
+               // Add static relation selector:
+               $row[] = '
+                               <tr class="bgColor4">
+                                       <td><strong>' . $LANG->getLL('makeconfig_useStaticRelationsFor', 1) . '</strong>' . \TYPO3\CMS\Backend\Utility\BackendUtility::cshItem('xMOD_tx_impexp', 'staticRelations', $GLOBALS['BACK_PATH'], '') . '</td>
+                                       <td>' . $this->tableSelector('tx_impexp[external_static][tables]', $inData['external_static']['tables']) . '<br/>
+                                               <label for="checkShowStaticRelations">' . $LANG->getLL('makeconfig_showStaticRelations', 1) . '</label> <input type="checkbox" name="tx_impexp[showStaticRelations]" id="checkShowStaticRelations" value="1"' . ($inData['showStaticRelations'] ? ' checked="checked"' : '') . ' />
+                                               </td>
+                               </tr>';
+               // Exclude:
+               $excludeHiddenFields = '';
+               if (is_array($inData['exclude'])) {
+                       foreach ($inData['exclude'] as $key => $value) {
+                               $excludeHiddenFields .= '<input type="hidden" name="tx_impexp[exclude][' . $key . ']" value="1" />';
+                       }
+               }
+               $row[] = '
+                               <tr class="bgColor4">
+                                       <td><strong>' . $LANG->getLL('makeconfig_excludeElements', 1) . '</strong>' . \TYPO3\CMS\Backend\Utility\BackendUtility::cshItem('xMOD_tx_impexp', 'excludedElements', $GLOBALS['BACK_PATH'], '') . '</td>
+                                       <td>' . $excludeHiddenFields . '
+                                       ' . (count($inData['exclude']) ? '<em>' . implode(', ', array_keys($inData['exclude'])) . '</em><hr/><label for="checkExclude">' . $LANG->getLL('makeconfig_clearAllExclusions', 1) . '</label> <input type="checkbox" name="tx_impexp[exclude]" id="checkExclude" value="1" />' : $LANG->getLL('makeconfig_noExcludedElementsYet', 1)) . '
+                                       </td>
+                               </tr>';
+               // Add buttons:
+               $row[] = '
+                               <tr class="bgColor4">
+                                       <td>&nbsp;</td>
+                                       <td>
+                                               <input type="submit" value="' . $LANG->getLL('makeadvanc_update', 1) . '" />
+                                               <input type="hidden" name="tx_impexp[download_export_name]" value="' . substr($nameSuggestion, 0, 30) . '" />
+                                       </td>
+                               </tr>';
+       }
+
+       /**
+        * Create advanced options form
+        *
+        * @param array $inData Form configurat data
+        * @param array $row Table row accumulation variable. This is filled with table rows.
+        * @return void Sets content in $this->content
+        * @todo Define visibility
+        */
+       public function makeAdvancedOptionsForm($inData, &$row) {
+               global $LANG;
+               // Soft references
+               $row[] = '
+                       <tr class="tableheader bgColor5">
+                               <td colspan="2">' . $LANG->getLL('makeadvanc_softReferences', 1) . '</td>
+                       </tr>';
+               $row[] = '
+                               <tr class="bgColor4">
+                                       <td><label for="checkExcludeHTMLfileResources"><strong>' . $LANG->getLL('makeadvanc_excludeHtmlCssFile', 1) . '</strong></label>' . \TYPO3\CMS\Backend\Utility\BackendUtility::cshItem('xMOD_tx_impexp', 'htmlCssResources', $GLOBALS['BACK_PATH'], '') . '</td>
+                                       <td><input type="checkbox" name="tx_impexp[excludeHTMLfileResources]" id="checkExcludeHTMLfileResources" value="1"' . ($inData['excludeHTMLfileResources'] ? ' checked="checked"' : '') . ' /></td>
+                               </tr>';
+               // Extensions
+               $row[] = '
+                       <tr class="tableheader bgColor5">
+                               <td colspan="2">' . $LANG->getLL('makeadvanc_extensionDependencies', 1) . '</td>
+                       </tr>';
+               $row[] = '
+                               <tr class="bgColor4">
+                                       <td><strong>' . $LANG->getLL('makeadvanc_selectExtensionsThatThe', 1) . '</strong>' . \TYPO3\CMS\Backend\Utility\BackendUtility::cshItem('xMOD_tx_impexp', 'extensionDependencies', $GLOBALS['BACK_PATH'], '') . '</td>
+                                       <td>' . $this->extensionSelector('tx_impexp[extension_dep]', $inData['extension_dep']) . '</td>
+                               </tr>';
+               // Add buttons:
+               $row[] = '
+                               <tr class="bgColor4">
+                                       <td>&nbsp;</td>
+                                       <td>
+                                               <input type="submit" value="' . $LANG->getLL('makesavefo_update', 1) . '" />
+                                               <input type="hidden" name="tx_impexp[download_export_name]" value="' . substr($nameSuggestion, 0, 30) . '" />
+                                       </td>
+                               </tr>';
+       }
+
+       /**
+        * Create configuration form
+        *
+        * @param array $inData Form configurat data
+        * @param array $row Table row accumulation variable. This is filled with table rows.
+        * @return void Sets content in $this->content
+        * @todo Define visibility
+        */
+       public function makeSaveForm($inData, &$row) {
+               global $LANG;
+               // Presets:
+               $row[] = '
+                       <tr class="tableheader bgColor5">
+                               <td colspan="2">' . $LANG->getLL('makesavefo_presets', 1) . '</td>
+                       </tr>';
+               $opt = array('');
+               $presets = $GLOBALS['TYPO3_DB']->exec_SELECTgetRows('*', 'tx_impexp_presets', '(public>0 OR user_uid=' . intval($GLOBALS['BE_USER']->user['uid']) . ')' . ($inData['pagetree']['id'] ? ' AND (item_uid=' . intval($inData['pagetree']['id']) . ' OR item_uid=0)' : ''));
+               if (is_array($presets)) {
+                       foreach ($presets as $presetCfg) {
+                               $opt[$presetCfg['uid']] = $presetCfg['title'] . ' [' . $presetCfg['uid'] . ']' . ($presetCfg['public'] ? ' [Public]' : '') . ($presetCfg['user_uid'] === $GLOBALS['BE_USER']->user['uid'] ? ' [Own]' : '');
+                       }
+               }
+               $row[] = '
+                               <tr class="bgColor4">
+                                       <td><strong>' . $LANG->getLL('makesavefo_presets', 1) . '</strong>' . \TYPO3\CMS\Backend\Utility\BackendUtility::cshItem('xMOD_tx_impexp', 'presets', $GLOBALS['BACK_PATH'], '') . '</td>
+                                       <td>
+                                               ' . $LANG->getLL('makesavefo_selectPreset', 1) . '<br/>
+                                               ' . $this->renderSelectBox('preset[select]', '', $opt) . '
+                                               <br/>
+                                               <input type="submit" value="' . $LANG->getLL('makesavefo_load', 1) . '" name="preset[load]" />
+                                               <input type="submit" value="' . $LANG->getLL('makesavefo_save', 1) . '" name="preset[save]" onclick="return confirm(\'' . $LANG->getLL('makesavefo_areYouSure', 1) . '\');" />
+                                               <input type="submit" value="' . $LANG->getLL('makesavefo_delete', 1) . '" name="preset[delete]" onclick="return confirm(\'' . $LANG->getLL('makesavefo_areYouSure', 1) . '\');" />
+                                               <input type="submit" value="' . $LANG->getLL('makesavefo_merge', 1) . '" name="preset[merge]" onclick="return confirm(\'' . $LANG->getLL('makesavefo_areYouSure', 1) . '\');" />
+                                               <br/>
+                                               ' . $LANG->getLL('makesavefo_titleOfNewPreset', 1) . '
+                                               <input type="text" name="tx_impexp[preset][title]" value="' . htmlspecialchars($inData['preset']['title']) . '"' . $this->doc->formWidth(30) . ' /><br/>
+                                               <label for="checkPresetPublic">' . $LANG->getLL('makesavefo_public', 1) . '</label>
+                                               <input type="checkbox" name="tx_impexp[preset][public]" id="checkPresetPublic" value="1"' . ($inData['preset']['public'] ? ' checked="checked"' : '') . ' /><br/>
+                                       </td>
+                               </tr>';
+               // Output options:
+               $row[] = '
+                       <tr class="tableheader bgColor5">
+                               <td colspan="2">' . $LANG->getLL('makesavefo_outputOptions', 1) . '</td>
+                       </tr>';
+               // Meta data:
+               $tempDir = $this->userTempFolder();
+               if ($tempDir) {
+                       $thumbnails = \TYPO3\CMS\Core\Utility\GeneralUtility::getFilesInDir($tempDir, 'png,gif,jpg');
+                       array_unshift($thumbnails, '');
+               } else {
+                       $thumbnails = FALSE;
+               }
+               $row[] = '
+                               <tr class="bgColor4">
+                                       <td><strong>' . $LANG->getLL('makesavefo_metaData', 1) . '</strong>' . \TYPO3\CMS\Backend\Utility\BackendUtility::cshItem('xMOD_tx_impexp', 'metadata', $GLOBALS['BACK_PATH'], '') . '</td>
+                                       <td>
+                                                       ' . $LANG->getLL('makesavefo_title', 1) . ' <br/>
+                                                       <input type="text" name="tx_impexp[meta][title]" value="' . htmlspecialchars($inData['meta']['title']) . '"' . $this->doc->formWidth(30) . ' /><br/>
+                                                       ' . $LANG->getLL('makesavefo_description', 1) . ' <br/>
+                                                       <input type="text" name="tx_impexp[meta][description]" value="' . htmlspecialchars($inData['meta']['description']) . '"' . $this->doc->formWidth(30) . ' /><br/>
+                                                       ' . $LANG->getLL('makesavefo_notes', 1) . ' <br/>
+                                                       <textarea name="tx_impexp[meta][notes]"' . $this->doc->formWidth(30, 1) . '>' . \TYPO3\CMS\Core\Utility\GeneralUtility::formatForTextarea($inData['meta']['notes']) . '</textarea><br/>
+                                                       ' . (is_array($thumbnails) ? '
+                                                       ' . $LANG->getLL('makesavefo_thumbnail', 1) . '<br/>
+                                                       ' . $this->renderSelectBox('tx_impexp[meta][thumbnail]', $inData['meta']['thumbnail'], $thumbnails) . '<br/>
+                                                       ' . ($inData['meta']['thumbnail'] ? '<img src="' . $this->doc->backPath . '../' . substr($tempDir, strlen(PATH_site)) . $thumbnails[$inData['meta']['thumbnail']] . '" vspace="5" style="border: solid black 1px;" alt="" /><br/>' : '') . '
+                                                       ' . $LANG->getLL('makesavefo_uploadThumbnail', 1) . '<br/>
+                                                       <input type="file" name="upload_1" ' . $this->doc->formWidth(30) . ' size="30" /><br/>
+                                                               <input type="hidden" name="file[upload][1][target]" value="' . htmlspecialchars($tempDir) . '" />
+                                                               <input type="hidden" name="file[upload][1][data]" value="1" /><br />
+                                                       ' : '') . '
+                                               </td>
+                               </tr>';
+               // Add file options:
+               $savePath = $this->userSaveFolder();
+               $opt = array();
+               if ($this->export->compress) {
+                       $opt['t3d_compressed'] = $LANG->getLL('makesavefo_t3dFileCompressed');
+               }
+               $opt['t3d'] = $LANG->getLL('makesavefo_t3dFile');
+               $opt['xml'] = $LANG->getLL('makesavefo_xml');
+               $row[] = '
+                               <tr class="bgColor4">
+                                       <td><strong>' . $LANG->getLL('makesavefo_fileFormat', 1) . '</strong>' . \TYPO3\CMS\Backend\Utility\BackendUtility::cshItem('xMOD_tx_impexp', 'fileFormat', $GLOBALS['BACK_PATH'], '') . '</td>
+                                       <td>' . $this->renderSelectBox('tx_impexp[filetype]', $inData['filetype'], $opt) . '<br/>
+                                               ' . $LANG->getLL('makesavefo_maxSizeOfFiles', 1) . '<br/>
+                                               <input type="text" name="tx_impexp[maxFileSize]" value="' . htmlspecialchars($inData['maxFileSize']) . '"' . $this->doc->formWidth(10) . ' /><br/>
+                                               ' . ($savePath ? sprintf($LANG->getLL('makesavefo_filenameSavedInS', 1), substr($savePath, strlen(PATH_site))) . '<br/>
+                                               <input type="text" name="tx_impexp[filename]" value="' . htmlspecialchars($inData['filename']) . '"' . $this->doc->formWidth(30) . ' /><br/>' : '') . '
+                                       </td>
+                               </tr>';
+               // Add buttons:
+               $row[] = '
+                               <tr class="bgColor4">
+                                       <td>&nbsp;</td>
+                                       <td><input type="submit" value="' . $LANG->getLL('makesavefo_update', 1) . '" /> - <input type="submit" value="' . $LANG->getLL('makesavefo_downloadExport', 1) . '" name="tx_impexp[download_export]" />' . ($savePath ? ' - <input type="submit" value="' . $LANG->getLL('importdata_saveToFilename', 1) . '" name="tx_impexp[save_export]" />' : '') . '</td>
+                               </tr>';
+       }
+
+       /**************************
+        *
+        * IMPORT FUNCTIONS
+        *
+        **************************/
+       /**
+        * Import part of module
+        *
+        * @param array $inData Content of POST VAR tx_impexp[]..
+        * @return void Setting content in $this->content
+        * @todo Define visibility
+        */
+       public function importData($inData) {
+               global $LANG;
+               $access = is_array($this->pageinfo) ? 1 : 0;
+               if ($this->id && $access || $GLOBALS['BE_USER']->user['admin'] && !$this->id) {
+                       if ($GLOBALS['BE_USER']->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 = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance('TYPO3\\CMS\\Impexp\\ImportExport');
+                       $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 = $GLOBALS['TYPO3_CONF_VARS']['BE']['fileadminDir'];
+                       $filesInDir = \TYPO3\CMS\Core\Utility\GeneralUtility::getFilesInDir(PATH_site . $path, 't3d,xml', 1, 1);
+                       $userPath = $this->userSaveFolder();
+                       //Files from User-Dir
+                       $filesInUserDir = \TYPO3\CMS\Core\Utility\GeneralUtility::getFilesInDir($userPath, 't3d,xml', 1, 1);
+                       $filesInDir = array_merge($filesInUserDir, $filesInDir);
+                       if (is_dir(PATH_site . $path . 'export/')) {
+                               $filesInDir = array_merge($filesInDir, \TYPO3\CMS\Core\Utility\GeneralUtility::getFilesInDir(PATH_site . $path . 'export/', 't3d,xml', 1, 1));
+                       }
+                       $tempFolder = $this->userTempFolder();
+                       if ($tempFolder) {
+                               $temp_filesInDir = \TYPO3\CMS\Core\Utility\GeneralUtility::getFilesInDir($tempFolder, 't3d,xml', 1, 1);
+                               $filesInDir = array_merge($filesInDir, $temp_filesInDir);
+                       }
+                       // Configuration
+                       $row = array();
+                       $opt = array('');
+                       foreach ($filesInDir as $file) {
+                               $opt[$file] = substr($file, strlen(PATH_site));
+                       }
+                       $row[] = '<tr class="bgColor5">
+                                       <td colspan="2"><strong>' . $LANG->getLL('importdata_selectFileToImport', 1) . '</strong></td>
+                               </tr>';
+                       $row[] = '<tr class="bgColor4">
+                               <td><strong>' . $LANG->getLL('importdata_file', 1) . '</strong>' . \TYPO3\CMS\Backend\Utility\BackendUtility::cshItem('xMOD_tx_impexp', 'importFile', $GLOBALS['BACK_PATH'], '') . '</td>
+                               <td>' . $this->renderSelectBox('tx_impexp[file]', $inData['file'], $opt) . '<br />' . sprintf($LANG->getLL('importdata_fromPathS', 1), $path) . (!$import->compress ? '<br /><span class="typo3-red">' . $LANG->getLL('importdata_noteNoDecompressorAvailable', 1) . '</span>' : '') . '</td>
+                               </tr>';
+                       $row[] = '<tr class="bgColor5">
+                                       <td colspan="2"><strong>' . $LANG->getLL('importdata_importOptions', 1) . '</strong></td>
+                               </tr>';
+                       $row[] = '<tr class="bgColor4">
+                               <td><strong>' . $LANG->getLL('importdata_update', 1) . '</strong>' . \TYPO3\CMS\Backend\Utility\BackendUtility::cshItem('xMOD_tx_impexp', 'update', $GLOBALS['BACK_PATH'], '') . '</td>
+                               <td>
+                                       <input type="checkbox" name="tx_impexp[do_update]" id="checkDo_update" value="1"' . ($inData['do_update'] ? ' checked="checked"' : '') . ' />
+                                       <label for="checkDo_update">' . $LANG->getLL('importdata_updateRecords', 1) . '</label><br/>
+                               <em>(' . $LANG->getLL('importdata_thisOptionRequiresThat', 1) . ')</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">' . $LANG->getLL('importdata_ignorePidDifferencesGlobally', 1) . '</label><br/>
+                                       <em>(' . $LANG->getLL('importdata_ifYouSetThis', 1) . ')</em>
+                                       ' : '') . '</td>
+                               </tr>';
+                       $row[] = '<tr class="bgColor4">
+                               <td><strong>' . $LANG->getLL('importdata_options', 1) . '</strong>' . \TYPO3\CMS\Backend\Utility\BackendUtility::cshItem('xMOD_tx_impexp', 'options', $GLOBALS['BACK_PATH'], '') . '</td>
+                               <td>
+                                       <input type="checkbox" name="tx_impexp[notShowDiff]" id="checkNotShowDiff" value="1"' . ($inData['notShowDiff'] ? ' checked="checked"' : '') . ' />
+                                       <label for="checkNotShowDiff">' . $LANG->getLL('importdata_doNotShowDifferences', 1) . '</label><br/>
+                                       <em>(' . $LANG->getLL('importdata_greenValuesAreFrom', 1) . ')</em>
+                                       <br/><br/>
+
+                                       ' . ($GLOBALS['BE_USER']->isAdmin() ? '
+                                       <input type="checkbox" name="tx_impexp[allowPHPScripts]" id="checkAllowPHPScripts" value="1"' . ($inData['allowPHPScripts'] ? ' checked="checked"' : '') . ' />
+                                       <label for="checkAllowPHPScripts">' . $LANG->getLL('importdata_allowToWriteBanned', 1) . '</label><br/>' : '') . (!$inData['do_update'] && $GLOBALS['BE_USER']->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="typo3-red">' . $LANG->getLL('importdata_force_all_UIDS', 1) . '</span></label><br/>
+                                       <em>(' . $LANG->getLL('importdata_force_all_UIDS_descr', 1) . ')</em>' : '') . '
+                               </td>
+                               </tr>';
+                       $row[] = '<tr class="bgColor4">
+                               <td><strong>' . $LANG->getLL('importdata_action', 1) . '</strong>' . \TYPO3\CMS\Backend\Utility\BackendUtility::cshItem('xMOD_tx_impexp', 'action', $GLOBALS['BACK_PATH'], '') . '</td>
+                               <td>' . (!$inData['import_file'] ? '<input type="submit" value="' . $LANG->getLL('importdata_preview', 1) . '" />' . ($inData['file'] ? ' - <input type="submit" value="' . ($inData['do_update'] ? $LANG->getLL('importdata_update_299e', 1) : $LANG->getLL('importdata_import', 1)) . '" name="tx_impexp[import_file]" onclick="return confirm(\'' . $LANG->getLL('importdata_areYouSure', 1) . '\');" />' : '') : '<input type="submit" name="tx_impexp[new_import]" value="' . $LANG->getLL('importdata_newImport', 1) . '" />') . '
+                                       <input type="hidden" name="tx_impexp[action]" value="import" /></td>
+                               </tr>';
+                       $row[] = '<tr class="bgColor4">
+                               <td><strong>' . $LANG->getLL('importdata_enableLogging', 1) . '</strong>' . \TYPO3\CMS\Backend\Utility\BackendUtility::cshItem('xMOD_tx_impexp', 'enableLogging', $GLOBALS['BACK_PATH'], '') . '</td>
+                               <td>
+                                       <input type="checkbox" name="tx_impexp[enableLogging]" id="checkEnableLogging" value="1"' . ($inData['enableLogging'] ? ' checked="checked"' : '') . ' />
+                                       <label for="checkEnableLogging">' . $LANG->getLL('importdata_writeIndividualDbActions', 1) . '</label><br/>
+                                       <em>(' . $LANG->getLL('importdata_thisIsDisabledBy', 1) . ')</em>
+                               </td>
+                               </tr>';
+                       $menuItems[] = array(
+                               'label' => $LANG->getLL('importdata_import', 1),
+                               'content' => '
+                                       <table border="0" cellpadding="1" cellspacing="1">
+                                               ' . implode('
+                                               ', $row) . '
+                                       </table>
+                               '
+                       );
+                       // Upload file:
+                       $tempFolder = $this->userTempFolder();
+                       if ($tempFolder) {
+                               $row = array();
+                               $row[] = '<tr class="bgColor5">
+                                               <td colspan="2"><strong>' . $LANG->getLL('importdata_uploadFileFromLocal', 1) . '</strong></td>
+                                       </tr>';
+                               $row[] = '<tr class="bgColor4">
+                                               <td>' . $LANG->getLL('importdata_browse', 1) . \TYPO3\CMS\Backend\Utility\BackendUtility::cshItem('xMOD_tx_impexp', 'upload', $GLOBALS['BACK_PATH'], '') . '</td>
+                                               <td>
+
+                                                               <input type="file" name="upload_1"' . $this->doc->formWidth(35) . ' size="40" />
+                                                               <input type="hidden" name="file[upload][1][target]" value="' . htmlspecialchars($tempFolder) . '" />
+                                                               <input type="hidden" name="file[upload][1][data]" value="1" /><br />
+
+                                                               <input type="submit" name="_upload" value="' . $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.php:file_upload.php.submit', 1) . '" />
+                                                               <input type="checkbox" name="overwriteExistingFiles" id="checkOverwriteExistingFiles" value="1" checked="checked" /> <label for="checkOverwriteExistingFiles">' . $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_misc.php:overwriteExistingFiles', 1) . '</label>
+                                               </td>
+                                       </tr>';
+                               if (\TYPO3\CMS\Core\Utility\GeneralUtility::_POST('_upload')) {
+                                       $row[] = '<tr class="bgColor4">
+                                                       <td>' . $LANG->getLL('importdata_uploadStatus', 1) . '</td>
+                                                       <td>' . ($this->fileProcessor->internalUploadMap[1] ? $LANG->getLL('importdata_success', 1) . ' ' . substr($this->fileProcessor->internalUploadMap[1], strlen(PATH_site)) : '<span class="typo3-red">' . $LANG->getLL('importdata_failureNoFileUploaded', 1) . '</span>') . '</td>
+                                               </tr>';
+                               }
+                               $menuItems[] = array(
+                                       'label' => $LANG->getLL('importdata_upload'),
+                                       'content' => '
+                                               <table border="0" cellpadding="1" cellspacing="1">
+                                                       ' . implode('
+                                                       ', $row) . '
+                                               </table>
+                                       '
+                               );
+                       }
+                       // Perform import or preview depending:
+                       $overviewContent = '';
+                       $extensionInstallationMessage = '';
+                       $emURL = '';
+                       $inFile = \TYPO3\CMS\Core\Utility\GeneralUtility::getFileAbsFileName($inData['file']);
+                       if ($inFile && @is_file($inFile)) {
+                               $trow = array();
+                               if ($import->loadFile($inFile, 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 (count($extKeysToInstall)) {
+                                               $passParams = \TYPO3\CMS\Core\Utility\GeneralUtility::_POST('tx_impexp');
+                                               unset($passParams['import_mode']);
+                                               unset($passParams['import_file']);
+                                               $thisScriptUrl = \TYPO3\CMS\Core\Utility\GeneralUtility::getIndpEnv('REQUEST_URI') . '?M=xMOD_tximpexp&id=' . $this->id . \TYPO3\CMS\Core\Utility\GeneralUtility::implodeArrayForUrl('tx_impexp', $passParams);
+                                               $emURL = $this->doc->backPath . \TYPO3\CMS\Core\Utility\ExtensionManagementUtility::extRelPath('em') . 'classes/index.php?CMD[requestInstallExtensions]=' . implode(',', $extKeysToInstall) . '&returnUrl=' . rawurlencode($thisScriptUrl);
+                                               $extensionInstallationMessage = 'Before you can install this T3D file you need to install the extensions "' . implode('", "', $extKeysToInstall) . '". Clicking Import will first take you to the Extension Manager so these dependencies can be resolved.';
+                                       }
+                                       if ($inData['import_file']) {
+                                               if (!count($extKeysToInstall)) {
+                                                       $import->importData($this->id);
+                                                       \TYPO3\CMS\Backend\Utility\BackendUtility::setUpdateSignal('updatePageTree');
+                                               } else {
+                                                       \TYPO3\CMS\Core\Utility\HttpUtility::redirect($emURL);
+                                               }
+                                       }
+                                       $import->display_import_pid_record = $this->pageinfo;
+                                       $overviewContent = $import->displayContentOverview();
+                               }
+                               // Meta data output:
+                               $trow[] = '<tr class="bgColor5">
+                                               <td colspan="2"><strong>' . $LANG->getLL('importdata_metaData', 1) . '</strong></td>
+                                       </tr>';
+                               $opt = array('');
+                               foreach ($filesInDir as $file) {
+                                       $opt[$file] = substr($file, strlen(PATH_site));
+                               }
+                               $trow[] = '<tr class="bgColor4">
+                                       <td><strong>' . $LANG->getLL('importdata_title', 1) . '</strong></td>
+                                       <td width="95%">' . nl2br(htmlspecialchars($import->dat['header']['meta']['title'])) . '</td>
+                                       </tr>';
+                               $trow[] = '<tr class="bgColor4">
+                                       <td><strong>' . $LANG->getLL('importdata_description', 1) . '</strong></td>
+                                       <td width="95%">' . nl2br(htmlspecialchars($import->dat['header']['meta']['description'])) . '</td>
+                                       </tr>';
+                               $trow[] = '<tr class="bgColor4">
+                                       <td><strong>' . $LANG->getLL('importdata_notes', 1) . '</strong></td>
+                                       <td width="95%">' . nl2br(htmlspecialchars($import->dat['header']['meta']['notes'])) . '</td>
+                                       </tr>';
+                               $trow[] = '<tr class="bgColor4">
+                                       <td><strong>' . $LANG->getLL('importdata_packager', 1) . '</strong></td>
+                                       <td width="95%">' . nl2br(htmlspecialchars(($import->dat['header']['meta']['packager_name'] . ' (' . $import->dat['header']['meta']['packager_username'] . ')'))) . '<br/>
+                                               ' . $LANG->getLL('importdata_email', 1) . ' ' . $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 (\TYPO3\CMS\Core\Utility\GeneralUtility::inList('gif,jpg,png,jpeg', strtolower($pI['extension']))) {
+                                               // Construct filename and write it:
+                                               $fileName = PATH_site . 'typo3temp/importthumb.' . $pI['extension'];
+                                               \TYPO3\CMS\Core\Utility\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="' . $this->doc->backPath . '../' . substr($fileName, strlen(PATH_site)) . '" ' . $import->dat['header']['thumbnail']['imgInfo'][3] . ' vspace="5" style="border: solid black 1px;" alt="" />';
+                                                       $trow[] = '<tr class="bgColor4">
+                                                               <td><strong>' . $LANG->getLL('importdata_icon', 1) . '</strong></td>
+                                                               <td>' . $iconTag . '</td>
+                                                               </tr>';
+                                               } else {
+                                                       \TYPO3\CMS\Core\Utility\GeneralUtility::unlink_tempfile($fileName);
+                                               }
+                                       }
+                               }
+                               $menuItems[] = array(
+                                       'label' => $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' => $LANG->getLL('importdata_messages'),
+                               'content' => $errors,
+                               'stateIcon' => $errors ? 2 : 0
+                       );
+                       // Output tabs:
+                       $content = $this->doc->getDynTabMenu($menuItems, 'tx_impexp_import', -1);
+                       if ($extensionInstallationMessage) {
+                               $content = '<div style="border: 1px black solid; margin: 10px 10px 10px 10px; padding: 10px 10px 10px 10px;">' . $this->doc->icons(1) . htmlspecialchars($extensionInstallationMessage) . '</div>' . $content;
+                       }
+                       $this->content .= $this->doc->section('', $content, 0, 1);
+                       // Print overview:
+                       if ($overviewContent) {
+                               $this->content .= $this->doc->section($inData['import_file'] ? $LANG->getLL('importdata_structureHasBeenImported', 1) : $LANG->getLL('filterpage_structureToBeImported', 1), $overviewContent, 0, 1);
+                       }
+               }
+       }
+
+       /****************************
+        *
+        * Preset functions
+        *
+        ****************************/
+       /**
+        * Manipulate presets
+        *
+        * @param array $inData In data array, passed by reference!
+        * @return void
+        * @todo Define visibility
+        */
+       public function processPresets(&$inData) {
+               $presetData = \TYPO3\CMS\Core\Utility\GeneralUtility::_GP('preset');
+               $err = FALSE;
+               // Save preset
+               if (isset($presetData['save'])) {
+                       $preset = $this->getPreset($presetData['select']);
+                       // Update existing
+                       if (is_array($preset)) {
+                               if ($GLOBALS['BE_USER']->isAdmin() || $preset['user_uid'] === $GLOBALS['BE_USER']->user['uid']) {
+                                       $fields_values = array(
+                                               'public' => $inData['preset']['public'],
+                                               'title' => $inData['preset']['title'],
+                                               'item_uid' => $inData['pagetree']['id'],
+                                               'preset_data' => serialize($inData)
+                                       );
+                                       $GLOBALS['TYPO3_DB']->exec_UPDATEquery('tx_impexp_presets', 'uid=' . intval($preset['uid']), $fields_values);
+                                       $msg = 'Preset #' . $preset['uid'] . ' saved!';
+                               } else {
+                                       $msg = 'ERROR: The preset was not saved because you were not the owner of it!';
+                                       $err = TRUE;
+                               }
+                       } else {
+                               // Insert new:
+                               $fields_values = array(
+                                       'user_uid' => $GLOBALS['BE_USER']->user['uid'],
+                                       'public' => $inData['preset']['public'],
+                                       'title' => $inData['preset']['title'],
+                                       'item_uid' => $inData['pagetree']['id'],
+                                       'preset_data' => serialize($inData)
+                               );
+                               $GLOBALS['TYPO3_DB']->exec_INSERTquery('tx_impexp_presets', $fields_values);
+                               $msg = 'New preset "' . htmlspecialchars($inData['preset']['title']) . '" is created';
+                       }
+               }
+               // Delete preset:
+               if (isset($presetData['delete'])) {
+                       $preset = $this->getPreset($presetData['select']);
+                       if (is_array($preset)) {
+                               // Update existing
+                               if ($GLOBALS['BE_USER']->isAdmin() || $preset['user_uid'] === $GLOBALS['BE_USER']->user['uid']) {
+                                       $GLOBALS['TYPO3_DB']->exec_DELETEquery('tx_impexp_presets', 'uid=' . intval($preset['uid']));
+                                       $msg = 'Preset #' . $preset['uid'] . ' deleted!';
+                               } else {
+                                       $msg = 'ERROR: You were not the owner of the preset so you could not delete it.';
+                                       $err = TRUE;
+                               }
+                       } else {
+                               $msg = 'ERROR: No preset selected for deletion.';
+                               $err = TRUE;
+                       }
+               }
+               // Load preset
+               if (isset($presetData['load']) || isset($presetData['merge'])) {
+                       $preset = $this->getPreset($presetData['select']);
+                       if (is_array($preset)) {
+                               // Update existing
+                               $inData_temp = unserialize($preset['preset_data']);
+                               if (is_array($inData_temp)) {
+                                       if (isset($presetData['merge'])) {
+                                               // Merge records in:
+                                               if (is_array($inData_temp['record'])) {
+                                                       $inData['record'] = array_merge((array) $inData['record'], $inData_temp['record']);
+                                               }
+                                               // Merge lists in:
+                                               if (is_array($inData_temp['list'])) {
+                                                       $inData['list'] = array_merge((array) $inData['list'], $inData_temp['list']);
+                                               }
+                                       } else {
+                                               $msg = 'Preset #' . $preset['uid'] . ' loaded!';
+                                               $inData = $inData_temp;
+                                       }
+                               } else {
+                                       $msg = 'ERROR: No configuratio data found in preset record!';
+                                       $err = TRUE;
+                               }
+                       } else {
+                               $msg = 'ERROR: No preset selected for loading.';
+                               $err = TRUE;
+                       }
+               }
+               // Show message:
+               if (strlen($msg)) {
+                       $this->content .= $this->doc->section('Presets', $msg, 0, 1, $err ? 3 : 1);
+               }
+       }
+
+       /**
+        * Get single preset record
+        *
+        * @param integer $uid Preset record
+        * @return array Preset record, if any (otherwise FALSE)
+        * @todo Define visibility
+        */
+       public function getPreset($uid) {
+               $preset = $GLOBALS['TYPO3_DB']->exec_SELECTgetSingleRow('*', 'tx_impexp_presets', 'uid=' . intval($uid));
+               return $preset;
+       }
+
+       /****************************
+        *
+        * Helper functions
+        *
+        ****************************/
+       /**
+        * Returns first temporary folder of the user account (from $FILEMOUNTS)
+        *
+        * @return string Absolute path to first "_temp_" folder of the current user, otherwise blank.
+        * @todo Define visibility
+        */
+       public function userTempFolder() {
+               global $FILEMOUNTS;
+               foreach ($FILEMOUNTS as $filePathInfo) {
+                       $tempFolder = $filePathInfo['path'] . '_temp_/';
+                       if (@is_dir($tempFolder)) {
+                               return $tempFolder;
+                       }
+               }
+       }
+
+       /**
+        * Returns folder where user can save export files.
+        *
+        * @return string Absolute path to folder where export files can be saved.
+        * @todo Define visibility
+        */
+       public function userSaveFolder() {
+               global $FILEMOUNTS;
+               reset($FILEMOUNTS);
+               $filePathInfo = current($FILEMOUNTS);
+               if (is_array($filePathInfo)) {
+                       $tempFolder = $filePathInfo['path'] . '_temp_/';
+                       if (!@is_dir($tempFolder)) {
+                               $tempFolder = $filePathInfo['path'];
+                               if (!@is_dir($tempFolder)) {
+                                       return FALSE;
+                               }
+                       }
+                       return $tempFolder;
+               }
+       }
+
+       /**
+        * Check if a file has been uploaded
+        *
+        * @return void
+        * @todo Define visibility
+        */
+       public function checkUpload() {
+               $file = \TYPO3\CMS\Core\Utility\GeneralUtility::_GP('file');
+               // Initializing:
+               $this->fileProcessor = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance('TYPO3\\CMS\\Core\\Utility\\File\\ExtendedFileUtility');
+               $this->fileProcessor->init($GLOBALS['FILEMOUNTS'], $GLOBALS['TYPO3_CONF_VARS']['BE']['fileExtensions']);
+               $this->fileProcessor->init_actionPerms($GLOBALS['BE_USER']->getFileoperationPermissions());
+               $this->fileProcessor->dontCheckForUnique = \TYPO3\CMS\Core\Utility\GeneralUtility::_GP('overwriteExistingFiles') ? 1 : 0;
+               // Checking referer / executing:
+               $refInfo = parse_url(\TYPO3\CMS\Core\Utility\GeneralUtility::getIndpEnv('HTTP_REFERER'));
+               $httpHost = \TYPO3\CMS\Core\Utility\GeneralUtility::getIndpEnv('TYPO3_HOST_ONLY');
+               if ($httpHost != $refInfo['host'] && $this->vC != $GLOBALS['BE_USER']->veriCode() && !$GLOBALS['$TYPO3_CONF_VARS']['SYS']['doNotCheckReferer']) {
+                       $this->fileProcessor->writeLog(0, 2, 1, 'Referer host "%s" and server host "%s" did not match!', array($refInfo['host'], $httpHost));
+               } else {
+                       $this->fileProcessor->start($file);
+                       $this->fileProcessor->processData();
+               }
+       }
+
+       /**
+        * Makes a selector-box from optValues
+        *
+        * @param string $prefix Form element name
+        * @param string $value Current value
+        * @param array $optValues Options to display (key/value pairs)
+        * @return string HTML select element
+        * @todo Define visibility
+        */
+       public function renderSelectBox($prefix, $value, $optValues) {
+               $opt = array();
+               $isSelFlag = 0;
+               foreach ($optValues as $k => $v) {
+                       $sel = !strcmp($k, $value) ? ' selected="selected"' : '';
+                       if ($sel) {
+                               $isSelFlag++;
+                       }
+                       $opt[] = '<option value="' . htmlspecialchars($k) . '"' . $sel . '>' . htmlspecialchars($v) . '</option>';
+               }
+               if (!$isSelFlag && strcmp('', $value)) {
+                       $opt[] = '<option value="' . htmlspecialchars($value) . '" selected="selected">' . htmlspecialchars(('[\'' . $value . '\']')) . '</option>';
+               }
+               return '<select name="' . $prefix . '">' . implode('', $opt) . '</select>';
+       }
+
+       /**
+        * Returns a selector-box with TCA tables
+        *
+        * @param string $prefix Form element name prefix
+        * @param array $value The current values selected
+        * @param string $excludeList Table names (and the string "_ALL") to exclude. Comma list
+        * @return string HTML select element
+        * @todo Define visibility
+        */
+       public function tableSelector($prefix, $value, $excludeList = '') {
+               $optValues = array();
+               if (!\TYPO3\CMS\Core\Utility\GeneralUtility::inList($excludeList, '_ALL')) {
+                       $optValues['_ALL'] = '[' . $GLOBALS['LANG']->getLL('ALL_tables') . ']';
+               }
+               foreach ($GLOBALS['TCA'] as $table => $_) {
+                       if ($GLOBALS['BE_USER']->check('tables_select', $table) && !\TYPO3\CMS\Core\Utility\GeneralUtility::inList($excludeList, $table)) {
+                               $optValues[$table] = $table;
+                       }
+               }
+               // make box:
+               $opt = array();
+               $opt[] = '<option value=""></option>';
+               foreach ($optValues as $k => $v) {
+                       if (is_array($value)) {
+                               $sel = in_array($k, $value) ? ' selected="selected"' : '';
+                       }
+                       $opt[] = '<option value="' . htmlspecialchars($k) . '"' . $sel . '>' . htmlspecialchars($v) . '</option>';
+               }
+               return '<select name="' . $prefix . '[]" multiple="multiple" size="' . \TYPO3\CMS\Core\Utility\MathUtility::forceIntegerInRange(count($opt), 5, 10) . '">' . implode('', $opt) . '</select>';
+       }
+
+       /**
+        * Returns a selector-box with loaded extension keys
+        *
+        * @param string $prefix Form element name prefix
+        * @param array $value The current values selected
+        * @return string HTML select element
+        * @todo Define visibility
+        */
+       public function extensionSelector($prefix, $value) {
+               global $TYPO3_LOADED_EXT;
+               $extTrav = array_keys($TYPO3_LOADED_EXT);
+               // make box:
+               $opt = array();
+               $opt[] = '<option value=""></option>';
+               foreach ($extTrav as $v) {
+                       if (is_array($value)) {
+                               $sel = in_array($v, $value) ? ' selected="selected"' : '';
+                       }
+                       $opt[] = '<option value="' . htmlspecialchars($v) . '"' . $sel . '>' . htmlspecialchars($v) . '</option>';
+               }
+               return '<select name="' . $prefix . '[]" multiple="multiple" size="' . \TYPO3\CMS\Core\Utility\MathUtility::forceIntegerInRange(count($opt), 5, 10) . '">' . implode('', $opt) . '</select>';
+       }
+
+       /**
+        * Filter page IDs by traversing exclude array, finding all excluded pages (if any) and making an AND NOT IN statement for the select clause.
+        *
+        * @param array $exclude Exclude array from import/export object.
+        * @return string AND where clause part to filter out page uids.
+        * @todo Define visibility
+        */
+       public function filterPageIds($exclude) {
+               // Get keys:
+               $exclude = array_keys($exclude);
+               // Traverse
+               $pageIds = array();
+               foreach ($exclude as $element) {
+                       list($table, $uid) = explode(':', $element);
+                       if ($table === 'pages') {
+                               $pageIds[] = intval($uid);
+                       }
+               }
+               // Add to clause:
+               if (count($pageIds)) {
+                       return ' AND uid NOT IN (' . implode(',', $pageIds) . ')';
+               }
+       }
+
+}
+
+
+?>
\ No newline at end of file
diff --git a/typo3/sysext/impexp/Classes/Controller/ModuleFunctionController.php b/typo3/sysext/impexp/Classes/Controller/ModuleFunctionController.php
new file mode 100644 (file)
index 0000000..319bef9
--- /dev/null
@@ -0,0 +1,137 @@
+<?php
+namespace TYPO3\CMS\Impexp\Controller;
+
+/**
+ * Export Preset listing for the task center
+ *
+ * @author Kasper Skårhøj <kasperYYYY@typo3.com>
+ */
+class ModuleFunctionController extends mod_user_task {
+
+       /**
+        * Create preset overview for task center overview.
+        *
+        * @return string HTML for the task center overview listing.
+        * @todo Define visibility
+        */
+       public function overview_main() {
+               global $LANG;
+               // Create preset links:
+               $presets = $this->getPresets();
+               $opt = array();
+               if (is_array($presets)) {
+                       foreach ($presets as $presetCfg) {
+                               $title = strlen($presetCfg['title']) ? $presetCfg['title'] : '[' . $presetCfg['uid'] . ']';
+                               $opt[] = '
+                                       <tr class="bgColor4">
+                                               <td nowrap="nowrap"><a href="index.php?SET[function]=tx_impexp&display=' . $presetCfg['uid'] . '">' . htmlspecialchars(\TYPO3\CMS\Core\Utility\GeneralUtility::fixed_lgd_cs($title, 30)) . '</a>&nbsp;</td>
+                                               <td>' . ($presetCfg['item_uid'] ? $presetCfg['item_uid'] : '&nbsp;') . '</td>
+                                               <td>' . ($presetCfg['public'] ? '[Public]' : '&nbsp;') . '</td>
+                                               <td>' . ($presetCfg['user_uid'] === $GLOBALS['BE_USER']->user['uid'] ? '[Own]' : '&nbsp;') . '</td>
+                                       </tr>';
+                       }
+                       if (sizeof($opt) > 0) {
+                               $presets = '<table border="0" cellpadding="0" cellspacing="1" class="lrPadding">' . implode('', $opt) . '</table>';
+                               $presets .= '<a href="index.php?SET[function]=tx_impexp"><em>' . $LANG->getLL('link_allRecs') . '</em></a>';
+                       } else {
+                               $presets = '';
+                       }
+                       $icon = '<img src="' . $this->backPath . \TYPO3\CMS\Core\Utility\ExtensionManagementUtility::extRelPath('impexp') . 'export.gif" width="18" height="16" class="absmiddle" alt="" />';
+                       $config = $this->mkMenuConfig($icon . $this->headLink('tx_impexp_modfunc1', 1), '', $presets);
+               }
+               return $config;
+       }
+
+       /**
+        * Main Task center module
+        *
+        * @return string HTML content.
+        * @todo Define visibility
+        */
+       public function main() {
+               if ($id = \TYPO3\CMS\Core\Utility\GeneralUtility::_GP('display')) {
+                       return $this->urlInIframe($this->backPath . \TYPO3\CMS\Core\Utility\ExtensionManagementUtility::extRelPath('impexp') . 'app/index.php?tx_impexp[action]=export&preset[load]=1&preset[select]=' . $id, 1);
+               } else {
+                       // Thumbnail folder and files:
+                       $tempDir = $this->userTempFolder();
+                       if ($tempDir) {
+                               $thumbnails = \TYPO3\CMS\Core\Utility\GeneralUtility::getFilesInDir($tempDir, 'png,gif,jpg', 1);
+                       }
+                       $clause = $GLOBALS['BE_USER']->getPagePermsClause(1);
+                       $usernames = \TYPO3\CMS\Backend\Utility\BackendUtility::getUserNames();
+                       // Create preset links:
+                       $presets = $this->getPresets();
+                       $opt = array();
+                       $opt[] = '
+                       <tr class="bgColor5 tableheader">
+                               <td>Icon:</td>
+                               <td>Preset Title:</td>
+                               <td>Public</td>
+                               <td>Owner:</td>
+                               <td>Page:</td>
+                               <td>Path:</td>
+                               <td>Meta data:</td>
+                       </tr>';
+                       if (is_array($presets)) {
+                               foreach ($presets as $presetCfg) {
+                                       $configuration = unserialize($presetCfg['preset_data']);
+                                       $thumbnailFile = $thumbnails[$configuration['meta']['thumbnail']];
+                                       $title = strlen($presetCfg['title']) ? $presetCfg['title'] : '[' . $presetCfg['uid'] . ']';
+                                       $opt[] = '
+                                       <tr class="bgColor4">
+                                               <td>' . ($thumbnailFile ? '<img src="' . $this->backPath . '../' . substr($tempDir, strlen(PATH_site)) . basename($thumbnailFile) . '" hspace="2" width="70" style="border: solid black 1px;" alt="" /><br />' : '&nbsp;') . '</td>
+                                               <td nowrap="nowrap"><a href="index.php?SET[function]=tx_impexp&display=' . $presetCfg['uid'] . '">' . htmlspecialchars(\TYPO3\CMS\Core\Utility\GeneralUtility::fixed_lgd_cs($title, 30)) . '</a>&nbsp;</td>
+                                               <td>' . ($presetCfg['public'] ? 'Yes' : '&nbsp;') . '</td>
+                                               <td>' . ($presetCfg['user_uid'] === $GLOBALS['BE_USER']->user['uid'] ? 'Own' : '[' . $usernames[$presetCfg['user_uid']]['username'] . ']') . '</td>
+                                               <td>' . ($configuration['pagetree']['id'] ? $configuration['pagetree']['id'] : '&nbsp;') . '</td>
+                                               <td>' . htmlspecialchars(($configuration['pagetree']['id'] ? \TYPO3\CMS\Backend\Utility\BackendUtility::getRecordPath($configuration['pagetree']['id'], $clause, 20) : '[Single Records]')) . '</td>
+                                               <td>
+                                                       <strong>' . htmlspecialchars($configuration['meta']['title']) . '</strong><br />' . htmlspecialchars($configuration['meta']['description']) . ($configuration['meta']['notes'] ? '<br /><br /><strong>Notes:</strong> <em>' . htmlspecialchars($configuration['meta']['notes']) . '</em>' : '') . '
+                                               </td>
+                                       </tr>';
+                               }
+                               $content = '<table border="0" cellpadding="0" cellspacing="1" class="lrPadding">' . implode('', $opt) . '</table>';
+                       }
+               }
+               // Output:
+               $theOutput .= $this->pObj->doc->spacer(5);
+               $theOutput .= $this->pObj->doc->section('Export presets', $content, 0, 1);
+               return $theOutput;
+       }
+
+       /*****************************
+        *
+        * Helper functions
+        *
+        *****************************/
+       /**
+        * Select presets for this user
+        *
+        * @return array Array of preset records
+        * @todo Define visibility
+        */
+       public function getPresets() {
+               $presets = $GLOBALS['TYPO3_DB']->exec_SELECTgetRows('*', 'tx_impexp_presets', '(public>0 OR user_uid=' . intval($GLOBALS['BE_USER']->user['uid']) . ')', '', 'item_uid DESC, title');
+               return $presets;
+       }
+
+       /**
+        * Returns first temporary folder of the user account (from $FILEMOUNTS)
+        *
+        * @return string Absolute path to first "_temp_" folder of the current user, otherwise blank.
+        * @todo Define visibility
+        */
+       public function userTempFolder() {
+               global $FILEMOUNTS;
+               foreach ($FILEMOUNTS as $filePathInfo) {
+                       $tempFolder = $filePathInfo['path'] . '_temp_/';
+                       if (@is_dir($tempFolder)) {
+                               return $tempFolder;
+                       }
+               }
+       }
+
+}
+
+
+?>
\ No newline at end of file
diff --git a/typo3/sysext/impexp/Classes/ImportExport.php b/typo3/sysext/impexp/Classes/ImportExport.php
new file mode 100644 (file)
index 0000000..8cd4eb3
--- /dev/null
@@ -0,0 +1,3153 @@
+<?php
+namespace TYPO3\CMS\Impexp;
+
+/***************************************************************
+ *  Copyright notice
+ *
+ *  (c) 1999-2011 Kasper Skårhøj (kasperYYYY@typo3.com)
+ *  All rights reserved
+ *
+ *  This script is part of the TYPO3 project. The TYPO3 project is
+ *  free software; you can redistribute it and/or modify
+ *  it under the terms of the GNU General Public License as published by
+ *  the Free Software Foundation; either version 2 of the License, or
+ *  (at your option) any later version.
+ *
+ *  The GNU General Public License can be found at
+ *  http://www.gnu.org/copyleft/gpl.html.
+ *  A copy is found in the textfile GPL.txt and important notices to the license
+ *  from the author is found in LICENSE.txt distributed with these scripts.
+ *
+ *
+ *  This script is distributed in the hope that it will be useful,
+ *  but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ *  GNU General Public License for more details.
+ *
+ *  This copyright notice MUST APPEAR in all copies of the script!
+ ***************************************************************/
+/**
+ * T3D file Import/Export library (TYPO3 Record Document)
+ *
+ * @author Kasper Skårhøj <kasperYYYY@typo3.com>
+ */
+/**
+ * EXAMPLE for using the impexp-class for exporting stuff:
+ *
+ * Create and initialize:
+ * $this->export = t3lib_div::makeInstance('tx_impexp');
+ * $this->export->init();
+ * Set which tables relations we will allow:
+ * $this->export->relOnlyTables[]="tt_news";   // exclusively includes. See comment in the class
+ *
+ * Adding records:
+ * $this->export->export_addRecord("pages", $this->pageinfo);
+ * $this->export->export_addRecord("pages", t3lib_BEfunc::getRecord("pages", 38));
+ * $this->export->export_addRecord("pages", t3lib_BEfunc::getRecord("pages", 39));
+ * $this->export->export_addRecord("tt_content", t3lib_BEfunc::getRecord("tt_content", 12));
+ * $this->export->export_addRecord("tt_content", t3lib_BEfunc::getRecord("tt_content", 74));
+ * $this->export->export_addRecord("sys_template", t3lib_BEfunc::getRecord("sys_template", 20));
+ *
+ * Adding all the relations (recursively in 5 levels so relations has THEIR relations registered as well)
+ * for($a=0;$a<5;$a++) {
+ * $addR = $this->export->export_addDBRelations($a);
+ * if (!count($addR)) break;
+ * }
+ *
+ * Finally load all the files.
+ * $this->export->export_addFilesFromRelations();      // MUST be after the DBrelations are set so that file from ALL added records are included!
+ *
+ * Write export
+ * $out = $this->export->compileMemoryToFileContent();
+ */
+/**
+ * T3D file Import/Export library (TYPO3 Record Document)
+ *
+ * @author Kasper Skårhøj <kasperYYYY@typo3.com>
+ */
+class ImportExport {
+
+       // Configuration, general
+       // If set, static relations (not exported) will be shown in overview as well
+       /**
+        * @todo Define visibility
+        */
+       public $showStaticRelations = FALSE;
+
+       // Name of the "fileadmin" folder where files for export/import should be located
+       /**
+        * @todo Define visibility
+        */
+       public $fileadminFolderName = '';
+
+       // Whether "import" or "export" mode of object. Set through init() function
+       /**
+        * @todo Define visibility
+        */
+       public $mode = '';
+
+       // Updates all records that has same UID instead of creating new!
+       /**
+        * @todo Define visibility
+        */
+       public $update = FALSE;
+
+       // Is set by importData() when an import has been done.
+       /**
+        * @todo Define visibility
+        */
+       public $doesImport = FALSE;
+
+       // Configuration, import
+       // If set to a page-record, then the preview display of the content will expect this page-record to be the target
+       // for the import and accordingly display validation information. This triggers the visual view of the
+       // import/export memory to validate if import is possible
+       /**
+        * @todo Define visibility
+        */
+       public $display_import_pid_record = '';
+
+       // Used to register the forged UID values for imported records that we want to create with the same UIDs as in the import file. Admin-only feature.
+       /**
+        * @todo Define visibility
+        */
+       public $suggestedInsertUids = array();
+
+       // Setting import modes during update state: as_new, exclude, force_uid
+       /**
+        * @todo Define visibility
+        */
+       public $import_mode = array();
+
+       // If set, PID correct is ignored globally
+       /**
+        * @todo Define visibility
+        */
+       public $global_ignore_pid = FALSE;
+
+       // If set, all UID values are forced! (update or import)
+       /**
+        * @todo Define visibility
+        */
+       public $force_all_UIDS = FALSE;
+
+       // If set, a diff-view column is added to the overview.
+       /**
+        * @todo Define visibility
+        */
+       public $showDiff = FALSE;
+
+       // If set, and if the user is admin, allow the writing of PHP scripts to fileadmin/ area.
+       /**
+        * @todo Define visibility
+        */
+       public $allowPHPScripts = FALSE;
+
+       // Disable logging when importing
+       /**
+        * @todo Define visibility
+        */
+       public $enableLogging = FALSE;
+
+       // Array of values to substitute in editable softreferences.
+       /**
+        * @todo Define visibility
+        */
+       public $softrefInputValues = array();
+
+       // Mapping between the fileID from import memory and the final filenames they are written to.
+       /**
+        * @todo Define visibility
+        */
+       public $fileIDMap = array();
+
+       // Configuration, export
+       // 1MB max file size
+       /**
+        * @todo Define visibility
+        */
+       public $maxFileSize = 1000000;
+
+       // 1MB max record size
+       /**
+        * @todo Define visibility
+        */
+       public $maxRecordSize = 1000000;
+
+       // 10MB max export size
+       /**
+        * @todo Define visibility
+        */
+       public $maxExportSize = 10000000;
+
+       // add table names here which are THE ONLY ones which will be included into export if found as relations. '_ALL' will allow all tables.
+       /**
+        * @todo Define visibility
+        */
+       public $relOnlyTables = array();
+
+       // add tables names here which should not be exported with the file. (Where relations should be mapped to same UIDs in target system).
+       /**
+        * @todo Define visibility
+        */
+       public $relStaticTables = array();
+
+       // Exclude map. Keys are table:uid  pairs and if set, records are not added to the export.
+       /**
+        * @todo Define visibility
+        */
+       public $excludeMap = array();
+
+       // Soft Reference Token ID modes.
+       /**
+        * @todo Define visibility
+        */
+       public $softrefCfg = array();
+
+       // Listing extension dependencies.
+       /**
+        * @todo Define visibility
+        */
+       public $extensionDependencies = array();
+
+       // Set  by user: If set, compression in t3d files is disabled
+       /**
+        * @todo Define visibility
+        */
+       public $dontCompress = 0;
+
+       // Boolean, if set, HTML file resources are included.
+       /**
+        * @todo Define visibility
+        */
+       public $includeExtFileResources = 0;
+
+       // Files with external media (HTML/css style references inside)
+       /**
+        * @todo Define visibility
+        */
+       public $extFileResourceExtensions = 'html,htm,css';
+
+       // Internal, dynamic:
+       // After records are written this array is filled with [table][original_uid] = [new_uid]
+       /**
+        * @todo Define visibility
+        */
+       public $import_mapId = array();
+
+       // Keys are [tablename]:[new NEWxxx ids (or when updating it is uids)] while values are arrays with table/uid of the original record it is based on. By the array keys the new ids can be looked up inside tcemain
+       /**
+        * @todo Define visibility
+        */
+       public $import_newId = array();
+
+       // Page id map for page tree (import)
+       /**
+        * @todo Define visibility
+        */
+       public $import_newId_pids = array();
+
+       // Internal data accumulation for writing records during import
+       /**
+        * @todo Define visibility
+        */
+       public $import_data = array();
+
+       // Error log.
+       /**
+        * @todo Define visibility
+        */
+       public $errorLog = array();
+
+       // Cache for record paths
+       /**
+        * @todo Define visibility
+        */
+       public $cache_getRecordPath = array();
+
+       // Cache of checkPID values.
+       /**
+        * @todo Define visibility
+        */
+       public $checkPID_cache = array();
+
+       // Set internally if the gzcompress function exists
+       /**
+        * @todo Define visibility
+        */
+       public $compress = 0;
+
+       // Internal import/export memory
+       /**
+        * @todo Define visibility
+        */
+       public $dat = array();
+
+       /**
+        * File processing object
+        *
+        * @var \TYPO3\CMS\Core\Utility\File\ExtendedFileUtility
+        * @todo Define visibility
+        */
+       public $fileProcObj = '';
+
+       /**************************
+        *
+        * Initialize
+        *
+        *************************/
+       /**
+        * Init the object, both import and export
+        *
+        * @param boolean $dontCompress If set, compression in t3d files is disabled
+        * @param string $mode Mode of usage, either "import" or "export
+        * @return void
+        * @todo Define visibility
+        */
+       public function init($dontCompress = 0, $mode = '') {
+               $this->compress = function_exists('gzcompress');
+               $this->dontCompress = $dontCompress;
+               $this->mode = $mode;
+               $this->fileadminFolderName = !empty($GLOBALS['TYPO3_CONF_VARS']['BE']['fileadminDir']) ? rtrim($GLOBALS['TYPO3_CONF_VARS']['BE']['fileadminDir'], '/') : 'fileadmin';
+       }
+
+       /**************************
+        *
+        * Export / Init + Meta Data
+        *
+        *************************/
+       /**
+        * Set header basics
+        *
+        * @return void
+        * @todo Define visibility
+        */
+       public function setHeaderBasics() {
+               // Initializing:
+               if (is_array($this->softrefCfg)) {
+                       foreach ($this->softrefCfg as $key => $value) {
+                               if (!strlen($value['mode'])) {
+                                       unset($this->softrefCfg[$key]);
+                               }
+                       }
+               }
+               // Setting in header memory:
+               // Version of file format
+               $this->dat['header']['XMLversion'] = '1.0';
+               // Initialize meta data array (to put it in top of file)
+               $this->dat['header']['meta'] = array();
+               // Add list of tables to consider static
+               $this->dat['header']['relStaticTables'] = $this->relStaticTables;
+               // The list of excluded records
+               $this->dat['header']['excludeMap'] = $this->excludeMap;
+               // Soft Reference mode for elements
+               $this->dat['header']['softrefCfg'] = $this->softrefCfg;
+               // List of extensions the import depends on.
+               $this->dat['header']['extensionDependencies'] = $this->extensionDependencies;
+       }
+
+       /**
+        * Set charset
+        *
+        * @param string $charset Charset for the content in the export. During import the character set will be converted if the target system uses another charset.
+        * @return void
+        * @todo Define visibility
+        */
+       public function setCharset($charset) {
+               $this->dat['header']['charset'] = $charset;
+       }
+
+       /**
+        * Sets meta data
+        *
+        * @param string $title Title of the export
+        * @param string $description Description of the export
+        * @param string $notes Notes about the contents
+        * @param string $packager_username Backend Username of the packager (the guy making the export)
+        * @param string $packager_name Real name of the packager
+        * @param string $packager_email Email of the packager
+        * @return void
+        * @todo Define visibility
+        */
+       public function setMetaData($title, $description, $notes, $packager_username, $packager_name, $packager_email) {
+               $this->dat['header']['meta'] = array(
+                       'title' => $title,
+                       'description' => $description,
+                       'notes' => $notes,
+                       'packager_username' => $packager_username,
+                       'packager_name' => $packager_name,
+                       'packager_email' => $packager_email,
+                       'TYPO3_version' => TYPO3_version,
+                       'created' => strftime('%A %e. %B %Y', $GLOBALS['EXEC_TIME'])
+               );
+       }
+
+       /**
+        * Sets a thumbnail image to the exported file
+        *
+        * @param string $imgFilepath Filename reference, gif, jpg, png. Absolute path.
+        * @return void
+        * @todo Define visibility
+        */
+       public function addThumbnail($imgFilepath) {
+               if (@is_file($imgFilepath)) {
+                       $imgInfo = @getimagesize($imgFilepath);
+                       if (is_array($imgInfo)) {
+                               $fileContent = \TYPO3\CMS\Core\Utility\GeneralUtility::getUrl($imgFilepath);
+                               $this->dat['header']['thumbnail'] = array(
+                                       'imgInfo' => $imgInfo,
+                                       'content' => $fileContent,
+                                       'filesize' => strlen($fileContent),
+                                       'filemtime' => filemtime($imgFilepath),
+                                       'filename' => basename($imgFilepath)
+                               );
+                       }
+               }
+       }
+
+       /**************************
+        *
+        * Export / Init Page tree
+        *
+        *************************/
+       /**
+        * Sets the page-tree array in the export header and returns the array in a flattened version
+        *
+        * @param array $idH Hierarchy of ids, the page tree: array([uid] => array("uid" => [uid], "subrow" => array(.....)), [uid] => ....)
+        * @return array The hierarchical page tree converted to a one-dimensional list of pages
+        * @todo Define visibility
+        */
+       public function setPageTree($idH) {
+               $this->dat['header']['pagetree'] = $this->unsetExcludedSections($idH);
+               return $this->flatInversePageTree($this->dat['header']['pagetree']);
+       }
+
+       /**
+        * Removes entries in the page tree which are found in ->excludeMap[]
+        *
+        * @param array $idH Page uid hierarchy
+        * @return array Modified input array
+        * @access private
+        * @see setPageTree()
+        * @todo Define visibility
+        */
+       public function unsetExcludedSections($idH) {
+               if (is_array($idH)) {
+                       foreach ($idH as $k => $v) {
+                               if ($this->excludeMap['pages:' . $idH[$k]['uid']]) {
+                                       unset($idH[$k]);
+                               } elseif (is_array($idH[$k]['subrow'])) {
+                                       $idH[$k]['subrow'] = $this->unsetExcludedSections($idH[$k]['subrow']);
+                               }
+                       }
+               }
+               return $idH;
+       }
+
+       /**
+        * Recursively flattening the idH array (for setPageTree() function)
+        *
+        * @param array $idH Page uid hierarchy
+        * @param array $a Accumulation array of pages (internal, don't set from outside)
+        * @return array Array with uid-uid pairs for all pages in the page tree.
+        * @see flatInversePageTree_pid()
+        * @todo Define visibility
+        */
+       public function flatInversePageTree($idH, $a = array()) {
+               if (is_array($idH)) {
+                       $idH = array_reverse($idH);
+                       foreach ($idH as $k => $v) {
+                               $a[$v['uid']] = $v['uid'];
+                               if (is_array($v['subrow'])) {
+                                       $a = $this->flatInversePageTree($v['subrow'], $a);
+                               }
+                       }
+               }
+               return $a;
+       }
+
+       /**
+        * Recursively flattening the idH array (for setPageTree() function), setting PIDs as values
+        *
+        * @param array $idH Page uid hierarchy
+        * @param array $a Accumulation array of pages (internal, don't set from outside)
+        * @param integer $pid PID value (internal)
+        * @return array Array with uid-pid pairs for all pages in the page tree.
+        * @see flatInversePageTree()
+        * @todo Define visibility
+        */
+       public function flatInversePageTree_pid($idH, $a = array(), $pid = -1) {
+               if (is_array($idH)) {
+                       $idH = array_reverse($idH);
+                       foreach ($idH as $k => $v) {
+                               $a[$v['uid']] = $pid;
+                               if (is_array($v['subrow'])) {
+                                       $a = $this->flatInversePageTree_pid($v['subrow'], $a, $v['uid']);
+                               }
+                       }
+               }
+               return $a;
+       }
+
+       /**************************
+        *
+        * Export
+        *
+        *************************/
+       /**
+        * Adds the record $row from $table.
+        * No checking for relations done here. Pure data.
+        *
+        * @param string $table Table name
+        * @param array $row Record row.
+        * @param integer $relationLevel (Internal) if the record is added as a relation, this is set to the "level" it was on.
+        * @return void
+        * @todo Define visibility
+        */
+       public function export_addRecord($table, $row, $relationLevel = 0) {
+               \TYPO3\CMS\Backend\Utility\BackendUtility::workspaceOL($table, $row);
+               if (strcmp($table, '') && is_array($row) && $row['uid'] > 0 && !$this->excludeMap[($table . ':' . $row['uid'])]) {
+                       if ($this->checkPID($table === 'pages' ? $row['uid'] : $row['pid'])) {
+                               if (!isset($this->dat['records'][($table . ':' . $row['uid'])])) {
+                                       // Prepare header info:
+                                       $headerInfo = array();
+                                       $headerInfo['uid'] = $row['uid'];
+                                       $headerInfo['pid'] = $row['pid'];
+                                       $headerInfo['title'] = \TYPO3\CMS\Core\Utility\GeneralUtility::fixed_lgd_cs(\TYPO3\CMS\Backend\Utility\BackendUtility::getRecordTitle($table, $row), 40);
+                                       $headerInfo['size'] = strlen(serialize($row));
+                                       if ($relationLevel) {
+                                               $headerInfo['relationLevel'] = $relationLevel;
+                                       }
+                                       // If record content is not too large in size, set the header content and add the rest:
+                                       if ($headerInfo['size'] < $this->maxRecordSize) {
+                                               // Set the header summary:
+                                               $this->dat['header']['records'][$table][$row['uid']] = $headerInfo;
+                                               // Create entry in the PID lookup:
+                                               $this->dat['header']['pid_lookup'][$row['pid']][$table][$row['uid']] = 1;
+                                               // Initialize reference index object:
+                                               $refIndexObj = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance('TYPO3\\CMS\\Core\\Database\\ReferenceIndex');
+                                               // Yes to workspace overlays for exporting....
+                                               $refIndexObj->WSOL = TRUE;
+                                               // Data:
+                                               $this->dat['records'][$table . ':' . $row['uid']] = array();
+                                               $this->dat['records'][$table . ':' . $row['uid']]['data'] = $row;
+                                               $this->dat['records'][$table . ':' . $row['uid']]['rels'] = $refIndexObj->getRelations($table, $row);
+                                               $this->errorLog = array_merge($this->errorLog, $refIndexObj->errorLog);
+                                               // Merge error logs.
+                                               // Add information about the relations in the record in the header:
+                                               $this->dat['header']['records'][$table][$row['uid']]['rels'] = $this->flatDBrels($this->dat['records'][$table . ':' . $row['uid']]['rels']);
+                                               // Add information about the softrefs to header:
+                                               $this->dat['header']['records'][$table][$row['uid']]['softrefs'] = $this->flatSoftRefs($this->dat['records'][$table . ':' . $row['uid']]['rels']);
+                                       } else {
+                                               $this->error('Record ' . $table . ':' . $row['uid'] . ' was larger than maxRecordSize (' . \TYPO3\CMS\Core\Utility\GeneralUtility::formatSize($this->maxRecordSize) . ')');
+                                       }
+                               } else {
+                                       $this->error('Record ' . $table . ':' . $row['uid'] . ' already added.');
+                               }
+                       } else {
+                               $this->error('Record ' . $table . ':' . $row['uid'] . ' was outside your DB mounts!');
+                       }
+               }
+       }
+
+       /**
+        * This analyses the existing added records, finds all database relations to records and adds these records to the export file.
+        * This function can be called repeatedly until it returns an empty array. In principle it should not allow to infinite recursivity, but you better set a limit...
+        * Call this BEFORE the ext_addFilesFromRelations (so files from added relations are also included of course)
+        *
+        * @param integer $relationLevel Recursion level
+        * @return array overview of relations found and added: Keys [table]:[uid], values array with table and id
+        * @see export_addFilesFromRelations()
+        * @todo Define visibility
+        */
+       public function export_addDBRelations($relationLevel = 0) {
+               // Initialize:
+               $addR = array();
+               // Traverse all "rels" registered for "records"
+               if (is_array($this->dat['records'])) {
+                       foreach ($this->dat['records'] as $k => $value) {
+                               if (is_array($this->dat['records'][$k])) {
+                                       foreach ($this->dat['records'][$k]['rels'] as $fieldname => $vR) {
+                                               // For all DB types of relations:
+                                               if ($vR['type'] == 'db') {
+                                                       foreach ($vR['itemArray'] as $fI) {
+                                                               $this->export_addDBRelations_registerRelation($fI, $addR);
+                                                       }
+                                               }
+                                               // For all flex/db types of relations:
+                                               if ($vR['type'] == 'flex') {
+                                                       // DB relations in flex form fields:
+                                                       if (is_array($vR['flexFormRels']['db'])) {
+                                                               foreach ($vR['flexFormRels']['db'] as $subList) {
+                                                                       foreach ($subList as $fI) {
+                                                                               $this->export_addDBRelations_registerRelation($fI, $addR);
+                                                                       }
+                                                               }
+                                                       }
+                                                       // DB oriented soft references in flex form fields:
+                                                       if (is_array($vR['flexFormRels']['softrefs'])) {
+                                                               foreach ($vR['flexFormRels']['softrefs'] as $subList) {
+                                                                       foreach ($subList['keys'] as $spKey => $elements) {
+                                                                               foreach ($elements as $el) {
+                                                                                       if ($el['subst']['type'] === 'db' && $this->includeSoftref($el['subst']['tokenID'])) {
+                                                                                               list($tempTable, $tempUid) = explode(':', $el['subst']['recordRef']);
+                                                                                               $fI = array(
+                                                                                                       'table' => $tempTable,
+                                                                                                       'id' => $tempUid
+                                                                                               );
+                                                                                               $this->export_addDBRelations_registerRelation($fI, $addR, $el['subst']['tokenID']);
+                                                                                       }
+                                                                               }
+                                                                       }
+                                                               }
+                                                       }
+                                               }
+                                               // In any case, if there are soft refs:
+                                               if (is_array($vR['softrefs']['keys'])) {
+                                                       foreach ($vR['softrefs']['keys'] as $spKey => $elements) {
+                                                               foreach ($elements as $el) {
+                                                                       if ($el['subst']['type'] === 'db' && $this->includeSoftref($el['subst']['tokenID'])) {
+                                                                               list($tempTable, $tempUid) = explode(':', $el['subst']['recordRef']);
+                                                                               $fI = array(
+                                                                                       'table' => $tempTable,
+                                                                                       'id' => $tempUid
+                                                                               );
+                                                                               $this->export_addDBRelations_registerRelation($fI, $addR, $el['subst']['tokenID']);
+                                                                       }
+                                                               }
+                                                       }
+                                               }
+                                       }
+                               }
+                       }
+               } else {
+                       $this->error('There were no records available.');
+               }
+               // Now, if there were new records to add, do so:
+               if (count($addR)) {
+                       foreach ($addR as $fI) {
+                               // Get and set record:
+                               $row = \TYPO3\CMS\Backend\Utility\BackendUtility::getRecord($fI['table'], $fI['id']);
+                               if (is_array($row)) {
+                                       $this->export_addRecord($fI['table'], $row, $relationLevel + 1);
+                               }
+                               // Set status message
+                               // Relation pointers always larger than zero except certain "select" types with negative values pointing to uids - but that is not supported here.
+                               if ($fI['id'] > 0) {
+                                       $rId = $fI['table'] . ':' . $fI['id'];
+                                       if (!isset($this->dat['records'][$rId])) {
+                                               $this->dat['records'][$rId] = 'NOT_FOUND';
+                                               $this->error('Relation record ' . $rId . ' was not found!');
+                                       }
+                               }
+                       }
+               }
+               // Return overview of relations found and added
+               return $addR;
+       }
+
+       /**
+        * Helper function for export_addDBRelations()
+        *
+        * @param array $fI Array with table/id keys to add
+        * @param array $addR Add array, passed by reference to be modified
+        * @param string $tokenID Softref Token ID, if applicable.
+        * @return void
+        * @see export_addDBRelations()
+        * @todo Define visibility
+        */
+       public function export_addDBRelations_registerRelation($fI, &$addR, $tokenID = '') {
+               $rId = $fI['table'] . ':' . $fI['id'];
+               if (isset($GLOBALS['TCA'][$fI['table']]) && !$this->isTableStatic($fI['table']) && !$this->isExcluded($fI['table'], $fI['id']) && (!$tokenID || $this->includeSoftref($tokenID)) && $this->inclRelation($fI['table'])) {
+                       if (!isset($this->dat['records'][$rId])) {
+                               // Set this record to be included since it is not already.
+                               $addR[$rId] = $fI;
+                       }
+               }
+       }
+
+       /**
+        * This adds all files in relations.
+        * Call this method AFTER adding all records including relations.
+        *
+        * @return void
+        * @see export_addDBRelations()
+        * @todo Define visibility
+        */
+       public function export_addFilesFromRelations() {
+               // Traverse all "rels" registered for "records"
+               if (is_array($this->dat['records'])) {
+                       foreach ($this->dat['records'] as $k => $value) {
+                               if (is_array($this->dat['records'][$k]['rels'])) {
+                                       foreach ($this->dat['records'][$k]['rels'] as $fieldname => $vR) {
+                                               // For all file type relations:
+                                               if ($vR['type'] == 'file') {
+                                                       foreach ($vR['newValueFiles'] as $key => $fI) {
+                                                               $this->export_addFile($fI, $k, $fieldname);
+                                                               // Remove the absolute reference to the file so it doesn't expose absolute paths from source server:
+                                                               unset($this->dat['records'][$k]['rels'][$fieldname]['newValueFiles'][$key]['ID_absFile']);
+                                                       }
+                                               }
+                                               // For all flex type relations:
+                                               if ($vR['type'] == 'flex') {
+                                                       if (is_array($vR['flexFormRels']['file'])) {
+                                                               foreach ($vR['flexFormRels']['file'] as $key => $subList) {
+                                                                       foreach ($subList as $subKey => $fI) {
+                                                                               $this->export_addFile($fI, $k, $fieldname);
+                                                                               // Remove the absolute reference to the file so it doesn't expose absolute paths from source server:
+                                                                               unset($this->dat['records'][$k]['rels'][$fieldname]['flexFormRels']['file'][$key][$subKey]['ID_absFile']);
+                                                                       }
+                                                               }
+                                                       }
+                                                       // DB oriented soft references in flex form fields:
+                                                       if (is_array($vR['flexFormRels']['softrefs'])) {
+                                                               foreach ($vR['flexFormRels']['softrefs'] as $key => $subList) {
+                                                                       foreach ($subList['keys'] as $spKey => $elements) {
+                                                                               foreach ($elements as $subKey => $el) {
+                                                                                       if ($el['subst']['type'] === 'file' && $this->includeSoftref($el['subst']['tokenID'])) {
+                                                                                               // Create abs path and ID for file:
+                                                                                               $ID_absFile = \TYPO3\CMS\Core\Utility\GeneralUtility::getFileAbsFileName(PATH_site . $el['subst']['relFileName']);
+                                                                                               $ID = md5($ID_absFile);
+                                                                                               if ($ID_absFile) {
+                                                                                                       if (!$this->dat['files'][$ID]) {
+                                                                                                               $fI = array(
+                                                                                                                       'filename' => basename($ID_absFile),
+                                                                                                                       'ID_absFile' => $ID_absFile,
+                                                                                                                       'ID' => $ID,
+                                                                                                                       'relFileName' => $el['subst']['relFileName']
+                                                                                                               );
+                                                                                                               $this->export_addFile($fI, '_SOFTREF_');
+                                                                                                       }
+                                                                                                       $this->dat['records'][$k]['rels'][$fieldname]['flexFormRels']['softrefs'][$key]['keys'][$spKey][$subKey]['file_ID'] = $ID;
+                                                                                               }
+                                                                                       }
+                                                                               }
+                                                                       }
+                                                               }
+                                                       }
+                                               }
+                                               // In any case, if there are soft refs:
+                                               if (is_array($vR['softrefs']['keys'])) {
+                                                       foreach ($vR['softrefs']['keys'] as $spKey => $elements) {
+                                                               foreach ($elements as $subKey => $el) {
+                                                                       if ($el['subst']['type'] === 'file' && $this->includeSoftref($el['subst']['tokenID'])) {
+                                                                               // Create abs path and ID for file:
+                                                                               $ID_absFile = \TYPO3\CMS\Core\Utility\GeneralUtility::getFileAbsFileName(PATH_site . $el['subst']['relFileName']);
+                                                                               $ID = md5($ID_absFile);
+                                                                               if ($ID_absFile) {
+                                                                                       if (!$this->dat['files'][$ID]) {
+                                                                                               $fI = array(
+                                                                                                       'filename' => basename($ID_absFile),
+                                                                                                       'ID_absFile' => $ID_absFile,
+                                                                                                       'ID' => $ID,
+                                                                                                       'relFileName' => $el['subst']['relFileName']
+                                                                                               );
+                                                                                               $this->export_addFile($fI, '_SOFTREF_');
+                                                                                       }
+                                                                                       $this->dat['records'][$k]['rels'][$fieldname]['softrefs']['keys'][$spKey][$subKey]['file_ID'] = $ID;
+                                                                               }
+                                                                       }
+                                                               }
+                                                       }
+                                               }
+                                       }
+                               }
+                       }
+               } else {
+                       $this->error('There were no records available.');
+               }
+       }
+
+       /**
+        * Adds a files content to the export memory
+        *
+        * @param array $fI File information with three keys: "filename" = filename without path, "ID_absFile" = absolute filepath to the file (including the filename), "ID" = md5 hash of "ID_absFile". "relFileName" is optional for files attached to records, but mandatory for soft referenced files (since the relFileName determines where such a file should be stored!)
+        * @param string $recordRef If the file is related to a record, this is the id on the form [table]:[id]. Information purposes only.
+        * @param string $fieldname If the file is related to a record, this is the field name it was related to. Information purposes only.
+        * @return void
+        * @todo Define visibility
+        */
+       public function export_addFile($fI, $recordRef = '', $fieldname = '') {
+               if (@is_file($fI['ID_absFile'])) {
+                       if (filesize($fI['ID_absFile']) < $this->maxFileSize) {
+                               $fileRec = array();
+                               $fileRec['filesize'] = filesize($fI['ID_absFile']);
+                               $fileRec['filename'] = basename($fI['ID_absFile']);
+                               $fileRec['filemtime'] = filemtime($fI['ID_absFile']);
+                               //for internal type file_reference
+                               $fileRec['relFileRef'] = substr($fI['ID_absFile'], strlen(PATH_site));
+                               if ($recordRef) {
+                                       $fileRec['record_ref'] = $recordRef . '/' . $fieldname;
+                               }
+                               if ($fI['relFileName']) {
+                                       $fileRec['relFileName'] = $fI['relFileName'];
+                               }
+                               // Setting this data in the header
+                               $this->dat['header']['files'][$fI['ID']] = $fileRec;
+                               // ... and for the recordlisting, why not let us know WHICH relations there was...
+                               if ($recordRef && $recordRef !== '_SOFTREF_') {
+                                       $refParts = explode(':', $recordRef, 2);
+                                       if (!is_array($this->dat['header']['records'][$refParts[0]][$refParts[1]]['filerefs'])) {
+                                               $this->dat['header']['records'][$refParts[0]][$refParts[1]]['filerefs'] = array();
+                                       }
+                                       $this->dat['header']['records'][$refParts[0]][$refParts[1]]['filerefs'][] = $fI['ID'];
+                               }
+                               // ... and finally add the heavy stuff:
+                               $fileRec['content'] = \TYPO3\CMS\Core\Utility\GeneralUtility::getUrl($fI['ID_absFile']);
+                               $fileRec['content_md5'] = md5($fileRec['content']);
+                               $this->dat['files'][$fI['ID']] = $fileRec;
+                               // For soft references, do further processing:
+                               if ($recordRef === '_SOFTREF_') {
+                                       // RTE files?
+                                       if ($RTEoriginal = $this->getRTEoriginalFilename(basename($fI['ID_absFile']))) {
+                                               $RTEoriginal_absPath = dirname($fI['ID_absFile']) . '/' . $RTEoriginal;
+                                               if (@is_file($RTEoriginal_absPath)) {
+                                                       $RTEoriginal_ID = md5($RTEoriginal_absPath);
+                                                       $fileRec = array();
+                                                       $fileRec['filesize'] = filesize($RTEoriginal_absPath);
+                                                       $fileRec['filename'] = basename($RTEoriginal_absPath);
+                                                       $fileRec['filemtime'] = filemtime($RTEoriginal_absPath);
+                                                       $fileRec['record_ref'] = '_RTE_COPY_ID:' . $fI['ID'];
+                                                       $this->dat['header']['files'][$fI['ID']]['RTE_ORIG_ID'] = $RTEoriginal_ID;
+                                                       // Setting this data in the header
+                                                       $this->dat['header']['files'][$RTEoriginal_ID] = $fileRec;
+                                                       // ... and finally add the heavy stuff:
+                                                       $fileRec['content'] = \TYPO3\CMS\Core\Utility\GeneralUtility::getUrl($RTEoriginal_absPath);
+                                                       $fileRec['content_md5'] = md5($fileRec['content']);
+                                                       $this->dat['files'][$RTEoriginal_ID] = $fileRec;
+                                               } else {
+                                                       $this->error('RTE original file "' . substr($RTEoriginal_absPath, strlen(PATH_site)) . '" was not found!');
+                                               }
+                                       }
+                                       // Files with external media?
+                                       // This is only done with files grabbed by a softreference parser since it is deemed improbable that hard-referenced files should undergo this treatment.
+                                       $html_fI = pathinfo(basename($fI['ID_absFile']));
+                                       if ($this->includeExtFileResources && \TYPO3\CMS\Core\Utility\GeneralUtility::inList($this->extFileResourceExtensions, strtolower($html_fI['extension']))) {
+                                               $uniquePrefix = '###' . md5($GLOBALS['EXEC_TIME']) . '###';
+                                               if (strtolower($html_fI['extension']) === 'css') {
+                                                       $prefixedMedias = explode($uniquePrefix, preg_replace('/(url[[:space:]]*\\([[:space:]]*["\']?)([^"\')]*)(["\']?[[:space:]]*\\))/i', '\\1' . $uniquePrefix . '\\2' . $uniquePrefix . '\\3', $fileRec['content']));
+                                               } else {
+                                                       // html, htm:
+                                                       $htmlParser = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance('TYPO3\\CMS\\Core\\Html\\HtmlParser');
+                                                       $prefixedMedias = explode($uniquePrefix, $htmlParser->prefixResourcePath($uniquePrefix, $fileRec['content'], array(), $uniquePrefix));
+                                               }
+                                               $htmlResourceCaptured = FALSE;
+                                               foreach ($prefixedMedias as $k => $v) {
+                                                       if ($k % 2) {
+                                                               $EXTres_absPath = \TYPO3\CMS\Core\Utility\GeneralUtility::resolveBackPath(dirname($fI['ID_absFile']) . '/' . $v);
+                                                               $EXTres_absPath = \TYPO3\CMS\Core\Utility\GeneralUtility::getFileAbsFileName($EXTres_absPath);
+                                                               if ($EXTres_absPath && \TYPO3\CMS\Core\Utility\GeneralUtility::isFirstPartOfStr($EXTres_absPath, PATH_site . $this->fileadminFolderName . '/') && @is_file($EXTres_absPath)) {
+                                                                       $htmlResourceCaptured = TRUE;
+                                                                       $EXTres_ID = md5($EXTres_absPath);
+                                                                       $this->dat['header']['files'][$fI['ID']]['EXT_RES_ID'][] = $EXTres_ID;
+                                                                       $prefixedMedias[$k] = '{EXT_RES_ID:' . $EXTres_ID . '}';
+                                                                       // Add file to memory if it is not set already:
+                                                                       if (!isset($this->dat['header']['files'][$EXTres_ID])) {
+                                                                               $fileRec = array();
+                                                                               $fileRec['filesize'] = filesize($EXTres_absPath);
+                                                                               $fileRec['filename'] = basename($EXTres_absPath);
+                                                                               $fileRec['filemtime'] = filemtime($EXTres_absPath);
+                                                                               $fileRec['record_ref'] = '_EXT_PARENT_:' . $fI['ID'];
+                                                                               // Media relative to the HTML file.
+                                                                               $fileRec['parentRelFileName'] = $v;
+                                                                               // Setting this data in the header
+                                                                               $this->dat['header']['files'][$EXTres_ID] = $fileRec;
+                                                                               // ... and finally add the heavy stuff:
+                                                                               $fileRec['content'] = \TYPO3\CMS\Core\Utility\GeneralUtility::getUrl($EXTres_absPath);
+                                                                               $fileRec['content_md5'] = md5($fileRec['content']);
+                                                                               $this->dat['files'][$EXTres_ID] = $fileRec;
+                                                                       }
+                                                               }
+                                                       }
+                                               }
+                                               if ($htmlResourceCaptured) {
+                                                       $this->dat['files'][$fI['ID']]['tokenizedContent'] = implode('', $prefixedMedias);
+                                               }
+                                       }
+                               }
+                       } else {
+                               $this->error($fI['ID_absFile'] . ' was larger (' . \TYPO3\CMS\Core\Utility\GeneralUtility::formatSize(filesize($fI['ID_absFile'])) . ') than the maxFileSize (' . \TYPO3\CMS\Core\Utility\GeneralUtility::formatSize($this->maxFileSize) . ')! Skipping.');
+                       }
+               } else {
+                       $this->error($fI['ID_absFile'] . ' was not a file! Skipping.');
+               }
+       }
+
+       /**
+        * DB relations flattend to 1-dim array.
+        * The list will be unique, no table/uid combination will appear twice.
+        *
+        * @param array $dbrels 2-dim Array of database relations organized by table key
+        * @return array 1-dim array where entries are table:uid and keys are array with table/id
+        * @todo Define visibility
+        */
+       public function flatDBrels($dbrels) {
+               $list = array();
+               foreach ($dbrels as $dat) {
+                       if ($dat['type'] == 'db') {
+                               foreach ($dat['itemArray'] as $i) {
+                                       $list[$i['table'] . ':' . $i['id']] = $i;
+                               }
+                       }
+                       if ($dat['type'] == 'flex' && is_array($dat['flexFormRels']['db'])) {
+                               foreach ($dat['flexFormRels']['db'] as $subList) {
+                                       foreach ($subList as $i) {
+                                               $list[$i['table'] . ':' . $i['id']] = $i;
+                                       }
+                               }
+                       }
+               }
+               return $list;
+       }
+
+       /**
+        * Soft References flattend to 1-dim array.
+        *
+        * @param array $dbrels 2-dim Array of database relations organized by table key
+        * @return array 1-dim array where entries are arrays with properties of the soft link found and keys are a unique combination of field, spKey, structure path if applicable and token ID
+        * @todo Define visibility
+        */
+       public function flatSoftRefs($dbrels) {
+               $list = array();
+               foreach ($dbrels as $field => $dat) {
+                       if (is_array($dat['softrefs']['keys'])) {
+                               foreach ($dat['softrefs']['keys'] as $spKey => $elements) {
+                                       if (is_array($elements)) {
+                                               foreach ($elements as $subKey => $el) {
+                                                       $lKey = $field . ':' . $spKey . ':' . $subKey;
+                                                       $list[$lKey] = array_merge(array('field' => $field, 'spKey' => $spKey), $el);
+                                                       // Add file_ID key to header - slightly "risky" way of doing this because if the calculation changes for the same value in $this->records[...] this will not work anymore!
+                                                       if ($el['subst'] && $el['subst']['relFileName']) {
+                                                               $list[$lKey]['file_ID'] = md5(PATH_site . $el['subst']['relFileName']);
+                                                       }
+                                               }
+                                       }
+                               }
+                       }
+                       if ($dat['type'] == 'flex' && is_array($dat['flexFormRels']['softrefs'])) {
+                               foreach ($dat['flexFormRels']['softrefs'] as $structurePath => $subSoftrefs) {
+                                       if (is_array($subSoftrefs['keys'])) {
+                                               foreach ($subSoftrefs['keys'] as $spKey => $elements) {
+                                                       foreach ($elements as $subKey => $el) {
+                                                               $lKey = $field . ':' . $structurePath . ':' . $spKey . ':' . $subKey;
+                                                               $list[$lKey] = array_merge(array('field' => $field, 'spKey' => $spKey, 'structurePath' => $structurePath), $el);
+                                                               // Add file_ID key to header - slightly "risky" way of doing this because if the calculation changes for the same value in $this->records[...] this will not work anymore!
+                                                               if ($el['subst'] && $el['subst']['relFileName']) {
+                                                                       $list[$lKey]['file_ID'] = md5(PATH_site . $el['subst']['relFileName']);
+                                                               }
+                                                       }
+                                               }
+                                       }
+                               }
+                       }
+               }
+               return $list;
+       }
+
+       /**************************
+        *
+        * File Output
+        *
+        *************************/
+       /**
+        * This compiles and returns the data content for an exported file
+        *
+        * @param string $type Type of output; "xml" gives xml, otherwise serialized array, possibly compressed.
+        * @return string The output file stream
+        * @todo Define visibility
+        */
+       public function compileMemoryToFileContent($type = '') {
+               if ($type == 'xml') {
+                       $out = $this->createXML();
+               } else {
+                       $compress = $this->doOutputCompress();
+                       $out = '';
+                       // adding header:
+                       $out .= $this->addFilePart(serialize($this->dat['header']), $compress);
+                       // adding records:
+                       $out .= $this->addFilePart(serialize($this->dat['records']), $compress);
+                       // adding files:
+                       $out .= $this->addFilePart(serialize($this->dat['files']), $compress);
+               }
+               return $out;
+       }
+
+       /**
+        * Creates XML string from input array
+        *
+        * @return string XML content
+        * @todo Define visibility
+        */
+       public function createXML() {
+               // Options:
+               $options = array(
+                       'alt_options' => array(
+                               '/header' => array(
+                                       'disableTypeAttrib' => TRUE,
+                                       'clearStackPath' => TRUE,
+                                       'parentTagMap' => array(
+                                               'files' => 'file',
+                                               'records' => 'table',
+                                               'table' => 'rec',
+                                               'rec:rels' => 'relations',
+                                               'relations' => 'element',
+                                               'filerefs' => 'file',
+                                               'pid_lookup' => 'page_contents',
+                                               'header:relStaticTables' => 'static_tables',
+                                               'static_tables' => 'tablename',
+                                               'excludeMap' => 'item',
+                                               'softrefCfg' => 'softrefExportMode',
+                                               'extensionDependencies' => 'extkey',
+                                               'softrefs' => 'softref_element'
+                                       ),
+                                       'alt_options' => array(
+                                               '/pagetree' => array(
+                                                       'disableTypeAttrib' => TRUE,
+                                                       'useIndexTagForNum' => 'node',
+                                                       'parentTagMap' => array(
+                                                               'node:subrow' => 'node'
+                                                       )
+                                               ),
+                                               '/pid_lookup/page_contents' => array(
+                                                       'disableTypeAttrib' => TRUE,
+                                                       'parentTagMap' => array(
+                                                               'page_contents' => 'table'
+                                                       ),
+                                                       'grandParentTagMap' => array(
+                                                               'page_contents/table' => 'item'
+                                                       )
+                                               )
+                                       )
+                               ),
+                               '/records' => array(
+                                       'disableTypeAttrib' => TRUE,
+                                       'parentTagMap' => array(
+                                               'records' => 'tablerow',
+                                               'tablerow:data' => 'fieldlist',
+                                               'tablerow:rels' => 'related',
+                                               'related' => 'field',
+                                               'field:itemArray' => 'relations',
+                                               'field:newValueFiles' => 'filerefs',
+                                               'field:flexFormRels' => 'flexform',
+                                               'relations' => 'element',
+                                               'filerefs' => 'file',
+                                               'flexform:db' => 'db_relations',
+                                               'flexform:file' => 'file_relations',
+                                               'flexform:softrefs' => 'softref_relations',
+                                               'softref_relations' => 'structurePath',
+                                               'db_relations' => 'path',
+                                               'file_relations' => 'path',
+                                               'path' => 'element',
+                                               'keys' => 'softref_key',
+                                               'softref_key' => 'softref_element'
+                                       ),
+                                       'alt_options' => array(
+                                               '/records/tablerow/fieldlist' => array(
+                                                       'useIndexTagForAssoc' => 'field'
+                                               )
+                                       )
+                               ),
+                               '/files' => array(
+                                       'disableTypeAttrib' => TRUE,
+                                       'parentTagMap' => array(
+                                               'files' => 'file'
+                                       )
+                               )
+                       )
+               );
+               // Creating XML file from $outputArray:
+               $charset = $this->dat['header']['charset'] ? $this->dat['header']['charset'] : 'utf-8';
+               $XML = '<?xml version="1.0" encoding="' . $charset . '" standalone="yes" ?>' . LF;
+               $XML .= \TYPO3\CMS\Core\Utility\GeneralUtility::array2xml($this->dat, '', 0, 'T3RecordDocument', 0, $options);
+               return $XML;
+       }
+
+       /**
+        * Returns TRUE if the output should be compressed.
+        *
+        * @return boolean TRUE if compression is possible AND requested.
+        * @todo Define visibility
+        */
+       public function doOutputCompress() {
+               return $this->compress && !$this->dontCompress;
+       }
+
+       /**
+        * Returns a content part for a filename being build.
+        *
+        * @param array $data Data to store in part
+        * @param boolean $compress Compress file?
+        * @return string Content stream.
+        * @todo Define visibility
+        */
+       public function addFilePart($data, $compress = FALSE) {
+               if ($compress) {
+                       $data = gzcompress($data);
+               }
+               return md5($data) . ':' . ($compress ? '1' : '0') . ':' . str_pad(strlen($data), 10, '0', STR_PAD_LEFT) . ':' . $data . ':';
+       }
+
+       /***********************
+        *
+        * Import
+        *
+        ***********************/
+       /**
+        * Imports the internal data array to $pid.
+        *
+        * @param integer $pid Page ID in which to import the content
+        * @return void
+        * @todo Define visibility
+        */
+       public function importData($pid) {
+               // Set this flag to indicate that an import is being/has been done.
+               $this->doesImport = 1;
+               // Initialize:
+               // These vars MUST last for the whole section not being cleared. They are used by the method setRelations() which are called at the end of the import session.
+               $this->import_mapId = array();
+               $this->import_newId = array();
+               $this->import_newId_pids = array();
+               // Temporary files stack initialized:
+               $this->unlinkFiles = array();
+               $this->alternativeFileName = array();
+               $this->alternativeFilePath = array();
+               // Write records, first pages, then the rest
+               // Fields with "hard" relations to database, files and flexform fields are kept empty during this run
+               $this->writeRecords_pages($pid);
+               $this->writeRecords_records($pid);
+               // Finally all the file and DB record references must be fixed. This is done after all records have supposedly been written to database:
+               // $this->import_mapId will indicate two things: 1) that a record WAS written to db and 2) that it has got a new id-number.
+               $this->setRelations();
+               // And when all DB relations are in place, we can fix file and DB relations in flexform fields (since data structures often depends on relations to a DS record):
+               $this->setFlexFormRelations();
+               // Unlink temporary files:
+               $this->unlinkTempFiles();
+               // Finally, traverse all records and process softreferences with substitution attributes.
+               $this->processSoftReferences();
+       }
+
+       /**
+        * Writing pagetree/pages to database:
+        *
+        * @param integer $pid PID in which to import. If the operation is an update operation, the root of the page tree inside will be moved to this PID unless it is the same as the root page from the import
+        * @return void
+        * @see writeRecords_records()
+        * @todo Define visibility
+        */
+       public function writeRecords_pages($pid) {
+               // First, write page structure if any:
+               if (is_array($this->dat['header']['records']['pages'])) {
+                       // $pageRecords is a copy of the pages array in the imported file. Records here are unset one by one when the addSingle function is called.
+                       $pageRecords = $this->dat['header']['records']['pages'];
+                       $this->import_data = array();
+                       // First add page tree if any
+                       if (is_array($this->dat['header']['pagetree'])) {
+                               $pagesFromTree = $this->flatInversePageTree($this->dat['header']['pagetree']);
+                               foreach ($pagesFromTree as $uid) {
+                                       $thisRec = $this->dat['header']['records']['pages'][$uid];
+                                       // PID: Set the main $pid, unless a NEW-id is found
+                                       $setPid = isset($this->import_newId_pids[$thisRec['pid']]) ? $this->import_newId_pids[$thisRec['pid']] : $pid;
+                                       $this->addSingle('pages', $uid, $setPid);
+                                       unset($pageRecords[$uid]);
+                               }
+                       }
+                       // Then add all remaining pages not in tree on root level:
+                       if (count($pageRecords)) {
+                               $remainingPageUids = array_keys($pageRecords);
+                               foreach ($remainingPageUids as $pUid) {
+                                       $this->addSingle('pages', $pUid, $pid);
+                               }
+                       }
+                       // Now write to database:
+                       $tce = $this->getNewTCE();
+                       $this->callHook('before_writeRecordsPages', array(
+                               'tce' => &$tce,
+                               'data' => &$this->import_data
+                       ));
+                       $tce->suggestedInsertUids = $this->suggestedInsertUids;
+                       $tce->start($this->import_data, array());
+                       $tce->process_datamap();
+                       $this->callHook('after_writeRecordsPages', array(
+                               'tce' => &$tce
+                       ));
+                       // post-processing: Registering new ids (end all tcemain sessions with this)
+                       $this->addToMapId($tce->substNEWwithIDs);
+                       // In case of an update, order pages from the page tree correctly:
+                       if ($this->update && is_array($this->dat['header']['pagetree'])) {
+                               $this->writeRecords_pages_order($pid);
+                       }
+               }
+       }
+
+       /**
+        * Organize all updated pages in page tree so they are related like in the import file
+        * Only used for updates and when $this->dat['header']['pagetree'] is an array.
+        *
+        * @param integer $pid Page id in which to import
+        * @return void
+        * @access private
+        * @see writeRecords_pages(), writeRecords_records_order()
+        * @todo Define visibility
+        */
+       public function writeRecords_pages_order($pid) {
+               $cmd_data = array();
+               // Get uid-pid relations and traverse them in order to map to possible new IDs
+               $pidsFromTree = $this->flatInversePageTree_pid($this->dat['header']['pagetree']);
+               foreach ($pidsFromTree as $origPid => $newPid) {
+                       if ($newPid >= 0 && $this->dontIgnorePid('pages', $origPid)) {
+                               // If the page had a new id (because it was created) use that instead!
+                               if (substr($this->import_newId_pids[$origPid], 0, 3) === 'NEW') {
+                                       if ($this->import_mapId['pages'][$origPid]) {
+                                               $mappedPid = $this->import_mapId['pages'][$origPid];
+                                               $cmd_data['pages'][$mappedPid]['move'] = $newPid;
+                                       }
+                               } else {
+                                       $cmd_data['pages'][$origPid]['move'] = $newPid;
+                               }
+                       }
+               }
+               // Execute the move commands if any:
+               if (count($cmd_data)) {
+                       $tce = $this->getNewTCE();
+                       $this->callHook('before_writeRecordsPagesOrder', array(
+                               'tce' => &$tce,
+                               'data' => &$cmd_data
+                       ));
+                       $tce->start(array(), $cmd_data);
+                       $tce->process_cmdmap();
+                       $this->callHook('after_writeRecordsPagesOrder', array(
+                               'tce' => &$tce
+                       ));
+               }
+       }
+
+       /**
+        * Write all database records except pages (writtein in writeRecords_pages())
+        *
+        * @param integer $pid Page id in which to import
+        * @return void
+        * @see writeRecords_pages()
+        * @todo Define visibility
+        */
+       public function writeRecords_records($pid) {
+               // Write the rest of the records
+               $this->import_data = array();
+               if (is_array($this->dat['header']['records'])) {
+                       foreach ($this->dat['header']['records'] as $table => $recs) {
+                               if ($table != 'pages') {
+                                       foreach ($recs as $uid => $thisRec) {
+                                               // PID: Set the main $pid, unless a NEW-id is found
+                                               $setPid = isset($this->import_mapId['pages'][$thisRec['pid']]) ? $this->import_mapId['pages'][$thisRec['pid']] : $pid;
+                                               if (is_array($GLOBALS['TCA'][$table]) && $GLOBALS['TCA'][$table]['ctrl']['rootLevel']) {
+                                                       $setPid = 0;
+                                               }
+                                               // Add record:
+                                               $this->addSingle($table, $uid, $setPid);
+                                       }
+                               }
+                       }
+               } else {
+                       $this->error('Error: No records defined in internal data array.');
+               }
+               // Now write to database:
+               $tce = $this->getNewTCE();
+               $this->callHook('before_writeRecordsRecords', array(
+                       'tce' => &$tce,
+                       'data' => &$this->import_data
+               ));
+               $tce->suggestedInsertUids = $this->suggestedInsertUids;
+               // Because all records are being submitted in their correct order with positive pid numbers - and so we should reverse submission order internally.
+               $tce->reverseOrder = 1;
+               $tce->start($this->import_data, array());
+               $tce->process_datamap();
+               $this->callHook('after_writeRecordsRecords', array(
+                       'tce' => &$tce
+               ));
+               // post-processing: Removing files and registering new ids (end all tcemain sessions with this)
+               $this->addToMapId($tce->substNEWwithIDs);
+               // In case of an update, order pages from the page tree correctly:
+               if ($this->update) {
+                       $this->writeRecords_records_order($pid);
+               }
+       }
+
+       /**
+        * Organize all updated record to their new positions.
+        * Only used for updates
+        *
+        * @param integer $mainPid Main PID into which we import.
+        * @return void
+        * @access private
+        * @see writeRecords_records(), writeRecords_pages_order()
+        * @todo Define visibility
+        */
+       public function writeRecords_records_order($mainPid) {
+               $cmd_data = array();
+               if (is_array($this->dat['header']['pagetree'])) {
+                       $pagesFromTree = $this->flatInversePageTree($this->dat['header']['pagetree']);
+               } else {
+                       $pagesFromTree = array();
+               }
+               if (is_array($this->dat['header']['pid_lookup'])) {
+                       foreach ($this->dat['header']['pid_lookup'] as $pid => $recList) {
+                               $newPid = isset($this->import_mapId['pages'][$pid]) ? $this->import_mapId['pages'][$pid] : $mainPid;
+                               if (\TYPO3\CMS\Core\Utility\MathUtility::canBeInterpretedAsInteger($newPid)) {
+                                       foreach ($recList as $tableName => $uidList) {
+                                               // If $mainPid===$newPid then we are on root level and we can consider to move pages as well!
+                                               // (they will not be in the page tree!)
+                                               if (($tableName != 'pages' || !$pagesFromTree[$pid]) && is_array($uidList)) {
+                                                       $uidList = array_reverse(array_keys($uidList));
+                                                       foreach ($uidList as $uid) {
+                                                               if ($this->dontIgnorePid($tableName, $uid)) {
+                                                                       $cmd_data[$tableName][$uid]['move'] = $newPid;
+                                                               } else {
+
+                                                               }
+                                                       }
+                                               }
+                                       }
+                               }
+                       }
+               }
+               // Execute the move commands if any:
+               if (count($cmd_data)) {
+                       $tce = $this->getNewTCE();
+                       $this->callHook('before_writeRecordsRecordsOrder', array(
+                               'tce' => &$tce,
+                               'data' => &$cmd_data
+                       ));
+                       $tce->start(array(), $cmd_data);
+                       $tce->process_cmdmap();
+                       $this->callHook('after_writeRecordsRecordsOrder', array(
+                               'tce' => &$tce
+                       ));
+               }
+       }
+
+       /**
+        * Adds a single record to the $importData array. Also copies files to tempfolder.
+        * However all File/DB-references and flexform field contents are set to blank for now! That is done with setRelations() later
+        *
+        * @param string $table Table name (from import memory)
+        * @param integer $uid Record UID (from import memory)
+        * @param integer $pid Page id
+        * @return void
+        * @see writeRecords()
+        * @todo Define visibility
+        */
+       public function addSingle($table, $uid, $pid) {
+               if ($this->import_mode[$table . ':' . $uid] !== 'exclude') {
+                       $record = $this->dat['records'][$table . ':' . $uid]['data'];
+                       if (is_array($record)) {
+                               if ($this->update && $this->doesRecordExist($table, $uid) && $this->import_mode[$table . ':' . $uid] !== 'as_new') {
+                                       $ID = $uid;
+                               } else {
+                                       $ID = uniqid('NEW');
+                               }
+                               $this->import_newId[$table . ':' . $ID] = array('table' => $table, 'uid' => $uid);
+                               if ($table == 'pages') {
+                                       $this->import_newId_pids[$uid] = $ID;
+                               }
+                               // Set main record data:
+                               $this->import_data[$table][$ID] = $record;
+                               $this->import_data[$table][$ID]['tx_impexp_origuid'] = $this->import_data[$table][$ID]['uid'];
+                               // Reset permission data:
+                               if ($table === 'pages') {
+                                       // Have to reset the user/group IDs so pages are owned by importing user. Otherwise strange things may happen for non-admins!
+                                       unset($this->import_data[$table][$ID]['perms_userid']);
+                                       unset($this->import_data[$table][$ID]['perms_groupid']);
+                               }
+                               // PID and UID:
+                               unset($this->import_data[$table][$ID]['uid']);
+                               // Updates:
+                               if (\TYPO3\CMS\Core\Utility\MathUtility::canBeInterpretedAsInteger($ID)) {
+                                       unset($this->import_data[$table][$ID]['pid']);
+                               } else {
+                                       // Inserts:
+                                       $this->import_data[$table][$ID]['pid'] = $pid;
+                                       if (($this->import_mode[$table . ':' . $uid] === 'force_uid' && $this->update || $this->force_all_UIDS) && $GLOBALS['BE_USER']->isAdmin()) {
+                                               $this->import_data[$table][$ID]['uid'] = $uid;
+                                               $this->suggestedInsertUids[$table . ':' . $uid] = 'DELETE';
+                                       }
+                               }
+                               // Setting db/file blank:
+                               foreach ($this->dat['records'][$table . ':' . $uid]['rels'] as $field => $config) {
+                                       switch ((string) $config['type']) {
+                                       case 'db':
+
+                                       case 'file':
+                                               // Fixed later in ->setRelations() [because we need to know ALL newly created IDs before we can map relations!]
+                                               // In the meantime we set NO values for relations:
+                                               $this->import_data[$table][$ID][$field] = '';
+                                               break;
+                                       case 'flex':
+                                               // Fixed later in setFlexFormRelations()
+                                               // In the meantime we set NO value for flexforms - this is mainly because file references inside will not be processed properly; In fact references will point to no file or existing files (in which case there will be double-references which is a big problem of course!)
+                                               $this->import_data[$table][$ID][$field] = '';
+                                               break;
+                                       }
+                               }
+                       } elseif ($table . ':' . $uid != 'pages:0') {
+                               // On root level we don't want this error message.
+                               $this->error('Error: no record was found in data array!', 1);
+                       }
+               }
+       }
+
+       /**
+        * Registers the substNEWids in memory.
+        *
+        * @param array $substNEWwithIDs From tcemain to be merged into internal mapping variable in this object
+        * @return void
+        * @see writeRecords()
+        * @todo Define visibility
+        */
+       public function addToMapId($substNEWwithIDs) {
+               foreach ($this->import_data as $table => $recs) {
+                       foreach ($recs as $id => $value) {
+                               $old_uid = $this->import_newId[$table . ':' . $id]['uid'];
+                               if (isset($substNEWwithIDs[$id])) {
+                                       $this->import_mapId[$table][$old_uid] = $substNEWwithIDs[$id];
+                               } elseif ($this->update) {
+                                       // Map same ID to same ID....
+                                       $this->import_mapId[$table][$old_uid] = $id;
+                               } else {
+                                       $this->error('Possible error: ' . $table . ':' . $old_uid . ' had no new id assigned to it. This indicates that the record was not added to database during import. Please check changelog!', 1);
+                               }
+                       }
+               }
+       }
+
+       /**
+        * Returns a new $TCE object
+        *
+        * @return object $TCE object
+        * @todo Define visibility
+        */
+       public function getNewTCE() {
+               $tce = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance('TYPO3\\CMS\\Core\\DataHandling\\DataHandler');
+               $tce->stripslashes_values = 0;
+               $tce->dontProcessTransformations = 1;
+               $tce->enableLogging = $this->enableLogging;
+               $tce->alternativeFileName = $this->alternativeFileName;
+               $tce->alternativeFilePath = $this->alternativeFilePath;
+               return $tce;
+       }
+
+       /**
+        * Cleaning up all the temporary files stored in typo3temp/ folder
+        *
+        * @return void
+        * @todo Define visibility
+        */
+       public function unlinkTempFiles() {
+               foreach ($this->unlinkFiles as $fileName) {
+                       if (\TYPO3\CMS\Core\Utility\GeneralUtility::isFirstPartOfStr($fileName, PATH_site . 'typo3temp/')) {
+                               \TYPO3\CMS\Core\Utility\GeneralUtility::unlink_tempfile($fileName);
+                               clearstatcache();
+                               if (is_file($fileName)) {
+                                       $this->error('Error: ' . $fileName . ' was NOT unlinked as it should have been!', 1);
+                               }
+                       } else {
+                               $this->error('Error: ' . $fileName . ' was not in temp-path. Not removed!', 1);
+                       }
+               }
+               $this->unlinkFiles = array();
+       }
+
+       /***************************
+        *
+        * Import / Relations setting
+        *
+        ***************************/
+       /**
+        * At the end of the import process all file and DB relations should be set properly (that is relations to imported records are all re-created so imported records are correctly related again)
+        * Relations in flexform fields are processed in setFlexFormRelations() after this function
+        *
+        * @return void
+        * @see setFlexFormRelations()
+        * @todo Define visibility
+        */
+       public function setRelations() {
+               $updateData = array();
+               // import_newId contains a register of all records that was in the import memorys "records" key
+               foreach ($this->import_newId as $nId => $dat) {
+                       $table = $dat['table'];
+                       $uid = $dat['uid'];
+                       // original UID - NOT the new one!
+                       // If the record has been written and received a new id, then proceed:
+                       if (is_array($this->import_mapId[$table]) && isset($this->import_mapId[$table][$uid])) {
+                               $thisNewUid = \TYPO3\CMS\Backend\Utility\BackendUtility::wsMapId($table, $this->import_mapId[$table][$uid]);
+                               if (is_array($this->dat['records'][$table . ':' . $uid]['rels'])) {
+                                       // Traverse relation fields of each record
+                                       foreach ($this->dat['records'][$table . ':' . $uid]['rels'] as $field => $config) {
+                                               switch ((string) $config['type']) {
+                                               case 'db':
+                                                       if (is_array($config['itemArray']) && count($config['itemArray'])) {
+                                                               $valArray = $this->setRelations_db($config['itemArray']);
+                                                               $updateData[$table][$thisNewUid][$field] = implode(',', $valArray);
+                                                       }
+                                                       break;
+                                               case 'file':
+                                                       if (is_array($config['newValueFiles']) && count($config['newValueFiles'])) {
+                                                               $valArr = array();
+                                                               foreach ($config['newValueFiles'] as $fI) {
+                                                                       $valArr[] = $this->import_addFileNameToBeCopied($fI);
+                                                               }
+                                                               $updateData[$table][$thisNewUid][$field] = implode(',', $valArr);
+                                                       }
+                                                       break;
+                                               }
+                                       }
+                               } else {
+                                       $this->error('Error: no record was found in data array!', 1);
+                               }
+                       } else {
+                               $this->error('Error: this records is NOT created it seems! (' . $table . ':' . $uid . ')', 1);
+                       }
+               }
+               if (count($updateData)) {
+                       $tce = $this->getNewTCE();
+                       $this->callHook('before_setRelation', array(
+                               'tce' => &$tce,
+                               'data' => &$updateData
+                       ));
+                       $tce->start($updateData, array());
+                       $tce->process_datamap();
+                       $this->callHook('after_setRelations', array(
+                               'tce' => &$tce
+                       ));
+               }
+       }
+
+       /**
+        * Maps relations for database
+        *
+        * @param array $itemArray Array of item sets (table/uid) from a dbAnalysis object
+        * @return array Array with values [table]_[uid]. These values have the regular tcemain-input group/select type which means they will automatically be processed into a uid-list or MM relations.
+        * @todo Define visibility
+        */
+       public function setRelations_db($itemArray) {
+               $valArray = array();
+               foreach ($itemArray as $relDat) {
+                       if (is_array($this->import_mapId[$relDat['table']]) && isset($this->import_mapId[$relDat['table']][$relDat['id']])) {
+                               $valArray[] = $relDat['table'] . '_' . $this->import_mapId[$relDat['table']][$relDat['id']];
+                       } elseif ($this->isTableStatic($relDat['table']) || $this->isExcluded($relDat['table'], $relDat['id']) || $relDat['id'] < 0) {
+                               // Checking for less than zero because some select types could contain negative values, eg. fe_groups (-1, -2) and sys_language (-1 = ALL languages). This must be handled on both export and import.
+                               $valArray[] = $relDat['table'] . '_' . $relDat['id'];
+                       } else {
+                               $this->error('Lost relation: ' . $relDat['table'] . ':' . $relDat['id'], 1);
+                       }
+               }
+               return $valArray;
+       }
+
+       /**
+        * Writes the file from import array to temp dir and returns the filename of it.
+        *
+        * @param array $fI File information with three keys: "filename" = filename without path, "ID_absFile" = absolute filepath to the file (including the filename), "ID" = md5 hash of "ID_absFile
+        * @return string Absolute filename of the temporary filename of the file. In ->alternativeFileName the original name is set.
+        * @todo Define visibility
+        */
+       public function import_addFileNameToBeCopied($fI) {
+               if (is_array($this->dat['files'][$fI['ID']])) {
+                       $tmpFile = \TYPO3\CMS\Core\Utility\GeneralUtility::tempnam('import_temp_');
+                       \TYPO3\CMS\Core\Utility\GeneralUtility::writeFile($tmpFile, $this->dat['files'][$fI['ID']]['content']);
+                       clearstatcache();
+                       if (@is_file($tmpFile)) {
+                               $this->unlinkFiles[] = $tmpFile;
+                               if (filesize($tmpFile) == $this->dat['files'][$fI['ID']]['filesize']) {
+                                       $this->alternativeFileName[$tmpFile] = $fI['filename'];
+                                       $this->alternativeFilePath[$tmpFile] = $this->dat['files'][$fI['ID']]['relFileRef'];
+                                       return $tmpFile;
+                               } else {
+                                       $this->error('Error: temporary file ' . $tmpFile . ' had a size (' . filesize($tmpFile) . ') different from the original (' . $this->dat['files'][$fI['ID']]['filesize'] . ')', 1);
+                               }
+                       } else {
+                               $this->error('Error: temporary file ' . $tmpFile . ' was not written as it should have been!', 1);
+                       }
+               } else {
+                       $this->error('Error: No file found for ID ' . $fI['ID'], 1);
+               }
+       }
+
+       /**
+        * After all DB relations has been set in the end of the import (see setRelations()) then it is time to correct all relations inside of FlexForm fields.
+        * The reason for doing this after is that the setting of relations may affect (quite often!) which data structure is used for the flexforms field!
+        *
+        * @return void
+        * @see setRelations()
+        * @todo Define visibility
+        */
+       public function setFlexFormRelations() {
+               $updateData = array();
+               // import_newId contains a register of all records that was in the import memorys "records" key
+               foreach ($this->import_newId as $nId => $dat) {
+                       $table = $dat['table'];
+                       $uid = $dat['uid'];
+                       // original UID - NOT the new one!
+                       // If the record has been written and received a new id, then proceed:
+                       if (is_array($this->import_mapId[$table]) && isset($this->import_mapId[$table][$uid])) {
+                               $thisNewUid = \TYPO3\CMS\Backend\Utility\BackendUtility::wsMapId($table, $this->import_mapId[$table][$uid]);
+                               if (is_array($this->dat['records'][$table . ':' . $uid]['rels'])) {
+                                       \TYPO3\CMS\Core\Utility\GeneralUtility::loadTCA($table);
+                                       // Traverse relation fields of each record
+                                       foreach ($this->dat['records'][$table . ':' . $uid]['rels'] as $field => $config) {
+                                               switch ((string) $config['type']) {
+                                               case 'flex':
+                                                       // Get XML content and set as default value (string, non-processed):
+                                                       $updateData[$table][$thisNewUid][$field] = $this->dat['records'][$table . ':' . $uid]['data'][$field];
+                                                       // If there has been registered relations inside the flex form field, run processing on the content:
+                                                       if (count($config['flexFormRels']['db']) || count($config['flexFormRels']['file'])) {
+                                                               $origRecordRow = \TYPO3\CMS\Backend\Utility\BackendUtility::getRecord($table, $thisNewUid, '*');
+                                                               // This will fetch the new row for the element (which should be updated with any references to data structures etc.)
+                                                               $conf = $GLOBALS['TCA'][$table]['columns'][$field]['config'];
+                                                               if (is_array($origRecordRow) && is_array($conf) && $conf['type'] === 'flex') {
+                                                                       // Get current data structure and value array:
+                                                                       $dataStructArray = \TYPO3\CMS\Backend\Utility\BackendUtility::getFlexFormDS($conf, $origRecordRow, $table);
+                                                                       $currentValueArray = \TYPO3\CMS\Core\Utility\GeneralUtility::xml2array($updateData[$table][$thisNewUid][$field]);
+                                                                       // Do recursive processing of the XML data:
+                                                                       $iteratorObj = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance('TYPO3\\CMS\\Core\\DataHandling\\DataHandler');
+                                                                       $iteratorObj->callBackObj = $this;
+                                                                       $currentValueArray['data'] = $iteratorObj->checkValue_flex_procInData($currentValueArray['data'], array(), array(), $dataStructArray, array($table, $thisNewUid, $field, $config), 'remapListedDBRecords_flexFormCallBack');
+                                                                       // The return value is set as an array which means it will be processed by tcemain for file and DB references!
+                                                                       if (is_array($currentValueArray['data'])) {
+                                                                               $updateData[$table][$thisNewUid][$field] = $currentValueArray;
+                                                                       }
+                                                               }
+                                                       }
+                                                       break;
+                                               }
+                                       }
+                               } else {
+                                       $this->error('Error: no record was found in data array!', 1);
+                               }
+                       } else {
+                               $this->error('Error: this records is NOT created it seems! (' . $table . ':' . $uid . ')', 1);
+                       }
+               }
+               if (count($updateData)) {
+                       $tce = $this->getNewTCE();
+                       $this->callHook('before_setFlexFormRelations', array(
+                               'tce' => &$tce,
+                               'data' => &$updateData
+                       ));
+                       $tce->start($updateData, array());
+                       $tce->process_datamap();
+                       $this->callHook('after_setFlexFormRelations', array(
+                               'tce' => &$tce
+                       ));
+               }
+       }
+
+       /**
+        * Callback function for traversing the FlexForm structure in relation to remapping database relations
+        *
+        * @param array $pParams Set of parameters in numeric array: table, uid, field
+        * @param array $dsConf TCA config for field (from Data Structure of course)
+        * @param string $dataValue Field value (from FlexForm XML)
+        * @param string $dataValue_ext1 Not used
+        * @param string $dataValue_ext2 Not used
+        * @param string $path Path of where the data structure of the element is found
+        * @return array Array where the "value" key carries the value.
+        * @see setFlexFormRelations()
+        * @todo Define visibility
+        */
+       public function remapListedDBRecords_flexFormCallBack($pParams, $dsConf, $dataValue, $dataValue_ext1, $dataValue_ext2, $path) {
+               // Extract parameters:
+               list($table, $uid, $field, $config) = $pParams;
+               // In case the $path is used as index without a trailing slash we will remove that
+               if (!is_array($config['flexFormRels']['db'][$path]) && is_array($config['flexFormRels']['db'][rtrim($path, '/')])) {
+                       $path = rtrim($path, '/');
+               }
+               if (is_array($config['flexFormRels']['db'][$path])) {
+                       $valArray = $this->setRelations_db($config['flexFormRels']['db'][$path]);
+                       $dataValue = implode(',', $valArray);
+               }
+               if (is_array($config['flexFormRels']['file'][$path])) {
+                       foreach ($config['flexFormRels']['file'][$path] as $fI) {
+                               $valArr[] = $this->import_addFileNameToBeCopied($fI);
+                       }
+                       $dataValue = implode(',', $valArr);
+               }
+               return array('value' => $dataValue);
+       }
+
+       /**************************
+        *
+        * Import / Soft References
+        *
+        *************************/
+       /**
+        * Processing of soft references
+        *
+        * @return void
+        * @todo Define visibility
+        */
+       public function processSoftReferences() {
+               // Initialize:
+               $inData = array();
+               // Traverse records:
+               if (is_array($this->dat['header']['records'])) {
+                       foreach ($this->dat['header']['records'] as $table => $recs) {
+                               foreach ($recs as $uid => $thisRec) {
+                                       // If there are soft references defined, traverse those:
+                                       if (isset($GLOBALS['TCA'][$table]) && is_array($thisRec['softrefs'])) {
+                                               \TYPO3\CMS\Core\Utility\GeneralUtility::loadTCA($table);
+                                               // First traversal is to collect softref configuration and split them up based on fields. This could probably also have been done with the "records" key instead of the header.
+                                               $fieldsIndex = array();
+                                               foreach ($thisRec['softrefs'] as $softrefDef) {
+                                                       // If a substitution token is set:
+                                                       if ($softrefDef['field'] && is_array($softrefDef['subst']) && $softrefDef['subst']['tokenID']) {
+                                                               $fieldsIndex[$softrefDef['field']][$softrefDef['subst']['tokenID']] = $softrefDef;
+                                                       }
+                                               }
+                                               // The new id:
+                                               $thisNewUid = \TYPO3\CMS\Backend\Utility\BackendUtility::wsMapId($table, $this->import_mapId[$table][$uid]);
+                                               // Now, if there are any fields that require substitution to be done, lets go for that:
+                                               foreach ($fieldsIndex as $field => $softRefCfgs) {
+                                                       if (is_array($GLOBALS['TCA'][$table]['columns'][$field])) {
+                                                               $conf = $GLOBALS['TCA'][$table]['columns'][$field]['config'];
+                                                               if ($conf['type'] === 'flex') {
+                                                                       // This will fetch the new row for the element (which should be updated with any references to data structures etc.)
+                                                                       $origRecordRow = \TYPO3\CMS\Backend\Utility\BackendUtility::getRecord($table, $thisNewUid, '*');
+                                                                       if (is_array($origRecordRow)) {
+                                                                               // Get current data structure and value array:
+                                                                               $dataStructArray = \TYPO3\CMS\Backend\Utility\BackendUtility::getFlexFormDS($conf, $origRecordRow, $table);
+                                                                               $currentValueArray = \TYPO3\CMS\Core\Utility\GeneralUtility::xml2array($origRecordRow[$field]);
+                                                                               // Do recursive processing of the XML data:
+                                                                               /** @var $iteratorObj \TYPO3\CMS\Core\DataHandling\DataHandler */
+                                                                               $iteratorObj = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance('TYPO3\\CMS\\Core\\DataHandling\\DataHandler');
+                                                                               $iteratorObj->callBackObj = $this;
+                                                                               $currentValueArray['data'] = $iteratorObj->checkValue_flex_procInData($currentValueArray['data'], array(), array(), $dataStructArray, array($table, $uid, $field, $softRefCfgs), 'processSoftReferences_flexFormCallBack');
+                                                                               // The return value is set as an array which means it will be processed by tcemain for file and DB references!
+                                                                               if (is_array($currentValueArray['data'])) {
+                                                                                       $inData[$table][$thisNewUid][$field] = $currentValueArray;
+                                                                               }
+                                                                       }
+                                                               } else {
+                                                                       // Get tokenizedContent string and proceed only if that is not blank:
+                                                                       $tokenizedContent = $this->dat['records'][$table . ':' . $uid]['rels'][$field]['softrefs']['tokenizedContent'];
+                                                                       if (strlen($tokenizedContent) && is_array($softRefCfgs)) {
+                                                                               $inData[$table][$thisNewUid][$field] = $this->processSoftReferences_substTokens($tokenizedContent, $softRefCfgs, $table, $uid);
+                                                                       }
+                                                               }
+                                                       }
+                                               }
+                                       }
+                               }
+                       }
+               }
+               // Now write to database:
+               $tce = $this->getNewTCE();
+               $this->callHook('before_processSoftReferences', array(
+                       'tce' => &$tce,
+                       'data' => &$inData
+               ));
+               $tce->enableLogging = TRUE;
+               $tce->start($inData, array());
+               $tce->process_datamap();
+               $this->callHook('after_processSoftReferences', array(
+                       'tce' => &$tce
+               ));
+       }
+
+       /**
+        * Callback function for traversing the FlexForm structure in relation to remapping softreference relations
+        *
+        * @param array $pParams Set of parameters in numeric array: table, uid, field
+        * @param array $dsConf TCA config for field (from Data Structure of course)
+        * @param string $dataValue Field value (from FlexForm XML)
+        * @param string $dataValue_ext1 Not used
+        * @param string $dataValue_ext2 Not used
+        * @param string $path Path of where the data structure where the element is found
+        * @return array Array where the "value" key carries the value.
+        * @see setFlexFormRelations()
+        * @todo Define visibility
+        */
+       public function processSoftReferences_flexFormCallBack($pParams, $dsConf, $dataValue, $dataValue_ext1, $dataValue_ext2, $path) {
+               // Extract parameters:
+               list($table, $origUid, $field, $softRefCfgs) = $pParams;
+               if (is_array($softRefCfgs)) {
+                       // First, find all soft reference configurations for this structure path (they are listed flat in the header):
+                       $thisSoftRefCfgList = array();
+                       foreach ($softRefCfgs as $sK => $sV) {
+                               if ($sV['structurePath'] === $path) {
+                                       $thisSoftRefCfgList[$sK] = $sV;
+                               }
+                       }
+                       // If any was found, do processing:
+                       if (count($thisSoftRefCfgList)) {
+                               // Get tokenizedContent string and proceed only if that is not blank:
+                               $tokenizedContent = $this->dat['records'][$table . ':' . $origUid]['rels'][$field]['flexFormRels']['softrefs'][$path]['tokenizedContent'];
+                               if (strlen($tokenizedContent)) {
+                                       $dataValue = $this->processSoftReferences_substTokens($tokenizedContent, $thisSoftRefCfgList, $table, $origUid);
+                               }
+                       }
+               }
+               // Return
+               return array('value' => $dataValue);
+       }
+
+       /**
+        * Substition of softreference tokens
+        *
+        * @param string $tokenizedContent Content of field with soft reference tokens in.
+        * @param array $softRefCfgs Soft reference configurations
+        * @param string $table Table for which the processing occurs
+        * @param string $uid UID of record from table
+        * @return string The input content with tokens substituted according to entries in softRefCfgs
+        * @todo Define visibility
+        */
+       public function processSoftReferences_substTokens($tokenizedContent, $softRefCfgs, $table, $uid) {
+               // traverse each softref type for this field:
+               foreach ($softRefCfgs as $cfg) {
+                       // Get token ID:
+                       $tokenID = $cfg['subst']['tokenID'];
+                       // Default is current token value:
+                       $insertValue = $cfg['subst']['tokenValue'];
+                       // Based on mode:
+                       switch ((string) $this->softrefCfg[$tokenID]['mode']) {
+                       case 'exclude':
+                               // Exclude is a simple passthrough of the value
+                               break;
+                       case 'editable':
+                               // Editable always picks up the value from this input array:
+                               $insertValue = $this->softrefInputValues[$tokenID];
+                               break;
+                       default:
+                               // Mapping IDs/creating files: Based on type, look up new value:
+                               switch ((string) $cfg['subst']['type']) {
+                                       case 'file':
+                                               // Create / Overwrite file:
+                                               $insertValue = $this->processSoftReferences_saveFile($cfg['subst']['relFileName'], $cfg, $table, $uid);
+                                               break;
+                                       case 'db':
+                                       default:
+                                               // Trying to map database element if found in the mapID array:
+                                               list($tempTable, $tempUid) = explode(':', $cfg['subst']['recordRef']);
+                                               if (isset($this->import_mapId[$tempTable][$tempUid])) {
+                                                       $insertValue = \TYPO3\CMS\Backend\Utility\BackendUtility::wsMapId($tempTable, $this->import_mapId[$tempTable][$tempUid]);
+                                                       // Look if reference is to a page and the original token value was NOT an integer - then we assume is was an alias and try to look up the new one!
+                                                       if ($tempTable === 'pages' && !\TYPO3\CMS\Core\Utility\MathUtility::canBeInterpretedAsInteger($cfg['subst']['tokenValue'])) {
+                                                               $recWithUniqueValue = \TYPO3\CMS\Backend\Utility\BackendUtility::getRecord($tempTable, $insertValue, 'alias');
+                                                               if ($recWithUniqueValue['alias']) {
+                                                                       $insertValue = $recWithUniqueValue['alias'];
+                                                               }
+                                                       }
+                                               }
+                                               break;
+                               }
+                               break;
+                       }
+                       // Finally, swap the soft reference token in tokenized content with the insert value:
+                       $tokenizedContent = str_replace('{softref:' . $tokenID . '}', $insertValue, $tokenizedContent);
+               }
+               return $tokenizedContent;
+       }
+
+       /**
+        * Process a soft reference file
+        *
+        * @param string $relFileName Old Relative filename
+        * @param array $cfg soft reference configuration array
+        * @param string $table Table for which the processing occurs
+        * @param string $uid UID of record from table
+        * @return string New relative filename (value to insert instead of the softref token)
+        * @todo Define visibility
+        */
+       public function processSoftReferences_saveFile($relFileName, $cfg, $table, $uid) {
+               if ($fileHeaderInfo = $this->dat['header']['files'][$cfg['file_ID']]) {
+                       // Initialize; Get directory prefix for file and find possible RTE filename
+                       $dirPrefix = dirname($relFileName) . '/';
+                       $rteOrigName = $this->getRTEoriginalFilename(basename($relFileName));
+                       // If filename looks like an RTE file, and the directory is in "uploads/", then process as a RTE file!
+                       if ($rteOrigName && \TYPO3\CMS\Core\Utility\GeneralUtility::isFirstPartOfStr($dirPrefix, 'uploads/')) {
+                               // RTE:
+                               // First, find unique RTE file name:
+                               if (@is_dir((PATH_site . $dirPrefix))) {
+                                       // From the "original" RTE filename, produce a new "original" destination filename which is unused. Even if updated, the image should be unique. Currently the problem with this is that it leaves a lot of unused RTE images...
+                                       $fileProcObj = $this->getFileProcObj();
+                                       $origDestName = $fileProcObj->getUniqueName($rteOrigName, PATH_site . $dirPrefix);
+                                       // Create copy file name:
+                                       $pI = pathinfo($relFileName);
+                                       $copyDestName = dirname($origDestName) . '/RTEmagicC_' . substr(basename($origDestName), 10) . '.' . $pI['extension'];
+                                       if (!@is_file($copyDestName) && !@is_file($origDestName) && $origDestName === \TYPO3\CMS\Core\Utility\GeneralUtility::getFileAbsFileName($origDestName) && $copyDestName === \TYPO3\CMS\Core\Utility\GeneralUtility::getFileAbsFileName($copyDestName)) {
+                                               if ($this->dat['header']['files'][$fileHeaderInfo['RTE_ORIG_ID']]) {
+                                                       // Write the copy and original RTE file to the respective filenames:
+                                                       $this->writeFileVerify($copyDestName, $cfg['file_ID'], TRUE);
+                                                       $this->writeFileVerify($origDestName, $fileHeaderInfo['RTE_ORIG_ID'], TRUE);
+                                                       // Return the relative path of the copy file name:
+                                                       return substr($copyDestName, strlen(PATH_site));
+                                               } else {
+                                                       $this->error('ERROR: Could not find original file ID');
+                                               }
+                                       } else {
+                                               $this->error('ERROR: The destination filenames "' . $copyDestName . '" and "' . $origDestName . '" either existed or have non-valid names');
+                                       }
+                               } else {
+                                       $this->error('ERROR: "' . PATH_site . $dirPrefix . '" was not a directory, so could not process file "' . $relFileName . '"');
+                               }
+                       } elseif (\TYPO3\CMS\Core\Utility\GeneralUtility::isFirstPartOfStr($dirPrefix, $this->fileadminFolderName . '/')) {
+                               // File in fileadmin/ folder:
+                               // Create file (and possible resources)
+                               $newFileName = $this->processSoftReferences_saveFile_createRelFile($dirPrefix, basename($relFileName), $cfg['file_ID'], $table, $uid);
+                               if (strlen($newFileName)) {
+                                       $relFileName = $newFileName;
+                               } else {
+                                       $this->error('ERROR: No new file created for "' . $relFileName . '"');
+                               }
+                       } else {
+                               $this->error('ERROR: Sorry, cannot operate on non-RTE files which are outside the fileadmin folder.');
+                       }
+               } else {
+                       $this->error('ERROR: Could not find file ID in header.');
+               }
+               // Return (new) filename relative to PATH_site:
+               return $relFileName;
+       }
+
+       /**
+        * Create file in directory and return the new (unique) filename
+        *
+        * @param string $origDirPrefix Directory prefix, relative, with trailing slash
+        * @param string $fileName Filename (without path)
+        * @param string $fileID File ID from import memory
+        * @param string $table Table for which the processing occurs
+        * @param string $uid UID of record from table
+        * @return string New relative filename, if any
+        * @todo Define visibility
+        */
+       public function processSoftReferences_saveFile_createRelFile($origDirPrefix, $fileName, $fileID, $table, $uid) {
+               // If the fileID map contains an entry for this fileID then just return the relative filename of that entry; we don't want to write another unique filename for this one!
+               if ($this->fileIDMap[$fileID]) {
+                       return substr($this->fileIDMap[$fileID], strlen(PATH_site));
+               }
+               // Verify FileMount access to dir-prefix. Returns the best alternative relative path if any
+               $dirPrefix = $this->verifyFolderAccess($origDirPrefix);
+               if ($dirPrefix && (!$this->update || $origDirPrefix === $dirPrefix) && $this->checkOrCreateDir($dirPrefix)) {
+                       $fileHeaderInfo = $this->dat['header']['files'][$fileID];
+                       $updMode = $this->update && $this->import_mapId[$table][$uid] === $uid && $this->import_mode[$table . ':' . $uid] !== 'as_new';
+                       // Create new name for file:
+                       // Must have same ID in map array (just for security, is not really needed) and NOT be set "as_new".
+                       if ($updMode) {
+                               $newName = PATH_site . $dirPrefix . $fileName;
+                       } else {
+                               // Create unique filename:
+                               $fileProcObj = $this->getFileProcObj();
+                               $newName = $fileProcObj->getUniqueName($fileName, PATH_site . $dirPrefix);
+                       }
+                       // Write main file:
+                       if ($this->writeFileVerify($newName, $fileID)) {
+                               // If the resource was an HTML/CSS file with resources attached, we will write those as well!
+                               if (is_array($fileHeaderInfo['EXT_RES_ID'])) {
+                                       $tokenizedContent = $this->dat['files'][$fileID]['tokenizedContent'];
+                                       $tokenSubstituted = FALSE;
+                                       $fileProcObj = $this->getFileProcObj();
+                                       if ($updMode) {
+                                               foreach ($fileHeaderInfo['EXT_RES_ID'] as $res_fileID) {
+                                                       if ($this->dat['files'][$res_fileID]['filename']) {
+                                                               // Resolve original filename:
+                                                               $relResourceFileName = $this->dat['files'][$res_fileID]['parentRelFileName'];
+                                                               $absResourceFileName = \TYPO3\CMS\Core\Utility\GeneralUtility::resolveBackPath(PATH_site . $origDirPrefix . $relResourceFileName);
+                                                               $absResourceFileName = \TYPO3\CMS\Core\Utility\GeneralUtility::getFileAbsFileName($absResourceFileName);
+                                                               if ($absResourceFileName && \TYPO3\CMS\Core\Utility\GeneralUtility::isFirstPartOfStr($absResourceFileName, PATH_site . $this->fileadminFolderName . '/')) {
+                                                                       $destDir = substr(dirname($absResourceFileName) . '/', strlen(PATH_site));
+                                                                       if ($this->verifyFolderAccess($destDir, TRUE) && $this->checkOrCreateDir($destDir)) {
+                                                                               $this->writeFileVerify($absResourceFileName, $res_fileID);
+                                                                       } else {
+                                                                               $this->error('ERROR: Could not create file in directory "' . $destDir . '"');
+                                                                       }
+                                                               } else {
+                                                                       $this->error('ERROR: Could not resolve path for "' . $relResourceFileName . '"');
+                                                               }
+                                                               $tokenizedContent = str_replace('{EXT_RES_ID:' . $res_fileID . '}', $relResourceFileName, $tokenizedContent);
+                                                               $tokenSubstituted = TRUE;
+                                                       }
+                                               }
+                                       } else {
+                                               // Create the resouces directory name (filename without extension, suffixed "_FILES")
+                                               $resourceDir = dirname($newName) . '/' . preg_replace('/\\.[^.]*$/', '', basename($newName)) . '_FILES';
+                                               if (\TYPO3\CMS\Core\Utility\GeneralUtility::mkdir($resourceDir)) {
+                                                       foreach ($fileHeaderInfo['EXT_RES_ID'] as $res_fileID) {
+                                                               if ($this->dat['files'][$res_fileID]['filename']) {
+                                                                       $absResourceFileName = $fileProcObj->getUniqueName($this->dat['files'][$res_fileID]['filename'], $resourceDir);
+                                                                       $relResourceFileName = substr($absResourceFileName, strlen(dirname($resourceDir)) + 1);
+                                                                       $this->writeFileVerify($absResourceFileName, $res_fileID);
+                                                                       $tokenizedContent = str_replace('{EXT_RES_ID:' . $res_fileID . '}', $relResourceFileName, $tokenizedContent);
+                                                                       $tokenSubstituted = TRUE;
+                                                               }
+                                                       }
+                                               }
+                                       }
+                                       // If substitutions has been made, write the content to the file again:
+                                       if ($tokenSubstituted) {
+                                               \TYPO3\CMS\Core\Utility\GeneralUtility::writeFile($newName, $tokenizedContent);
+                                       }
+                               }
+                               return substr($newName, strlen(PATH_site));
+                       }
+               }
+       }
+
+       /**
+        * Writes a file from the import memory having $fileID to file name $fileName which must be an absolute path inside PATH_site
+        *
+        * @param string $fileName Absolute filename inside PATH_site to write to
+        * @param string $fileID File ID from import memory
+        * @param boolean $bypassMountCheck Bypasses the checking against filemounts - only for RTE files!
+        * @return boolean Returns TRUE if it went well. Notice that the content of the file is read again, and md5 from import memory is validated.
+        * @todo Define visibility
+        */
+       public function writeFileVerify($fileName, $fileID, $bypassMountCheck = FALSE) {
+               $fileProcObj = $this->getFileProcObj();
+               if ($fileProcObj->actionPerms['newFile']) {
+                       // Just for security, check again. Should actually not be necessary.
+                       if ($fileProcObj->checkPathAgainstMounts($fileName) || $bypassMountCheck) {
+                               $fI = \TYPO3\CMS\Core\Utility\GeneralUtility::split_fileref($fileName);
+                               if ($fileProcObj->checkIfAllowed($fI['fileext'], $fI['path'], $fI['file']) || $this->allowPHPScripts && $GLOBALS['BE_USER']->isAdmin()) {
+                                       if (\TYPO3\CMS\Core\Utility\GeneralUtility::getFileAbsFileName($fileName)) {
+                                               if ($this->dat['files'][$fileID]) {
+                                                       \TYPO3\CMS\Core\Utility\GeneralUtility::writeFile($fileName, $this->dat['files'][$fileID]['content']);
+                                                       $this->fileIDMap[$fileID] = $fileName;
+                                                       if (md5(\TYPO3\CMS\Core\Utility\GeneralUtility::getUrl($fileName)) == $this->dat['files'][$fileID]['content_md5']) {
+                                                               return TRUE;
+                                                       } else {
+                                                               $this->error('ERROR: File content "' . $fileName . '" was corrupted');
+                                                       }
+                                               } else {
+                                                       $this->error('ERROR: File ID "' . $fileID . '" could not be found');
+                                               }
+                                       } else {
+                                               $this->error('ERROR: Filename "' . $fileName . '" was not a valid relative file path!');
+                                       }
+                               } else {
+                                       $this->error('ERROR: Filename "' . $fileName . '" failed against extension check or deny-pattern!');
+                               }
+                       } else {
+                               $this->error('ERROR: Filename "' . $fileName . '" was not allowed in destination path!');
+                       }
+               } else {
+                       $this->error('ERROR: You did not have sufficient permissions to write the file "' . $fileName . '"');
+               }
+       }
+
+       /**
+        * Returns TRUE if directory exists  and if it doesn't it will create directory and return TRUE if that succeeded.
+        *
+        * @param string $dirPrefix Directory to create. Having a trailing slash. Must be in fileadmin/. Relative to PATH_site
+        * @return boolean TRUE, if directory exists (was created)
+        * @todo Define visibility
+        */
+       public function checkOrCreateDir($dirPrefix) {
+               // Split dir path and remove first directory (which should be "fileadmin")
+               $filePathParts = explode('/', $dirPrefix);
+               $firstDir = array_shift($filePathParts);
+               if ($firstDir === $this->fileadminFolderName && \TYPO3\CMS\Core\Utility\GeneralUtility::getFileAbsFileName($dirPrefix)) {
+                       $pathAcc = '';
+                       foreach ($filePathParts as $dirname) {
+                               $pathAcc .= '/' . $dirname;
+                               if (strlen($dirname)) {
+                                       if (!@is_dir((PATH_site . $this->fileadminFolderName . $pathAcc))) {
+                                               if (!\TYPO3\CMS\Core\Utility\GeneralUtility::mkdir((PATH_site . $this->fileadminFolderName . $pathAcc))) {
+                                                       $this->error('ERROR: Directory could not be created....B');
+                                                       return FALSE;
+                                               }
+                                       }
+                               } elseif ($dirPrefix === $this->fileadminFolderName . $pathAcc) {
+                                       return TRUE;
+                               } else {
+                                       $this->error('ERROR: Directory could not be created....A');
+                               }
+                       }
+               }
+       }
+
+       /**
+        * Verifies that the input path (relative to PATH_site) is found in the backend users filemounts.
+        * If it doesn't it will try to find another relative filemount for the user and return an alternative path prefix for the file.
+        *
+        * @param string $dirPrefix Path relative to PATH_site
+        * @param boolean $noAlternative If set, Do not look for alternative path! Just return FALSE
+        * @return string If a path is available that will be returned, otherwise FALSE.
+        * @todo Define visibility
+        */
+       public function verifyFolderAccess($dirPrefix, $noAlternative = FALSE) {
+               $fileProcObj = $this->getFileProcObj();
+               // Check, if dirPrefix is inside a valid Filemount for user:
+               $result = $fileProcObj->checkPathAgainstMounts(PATH_site . $dirPrefix);
+               // If not, try to find another relative filemount and use that instead:
+               if (!$result) {
+                       if ($noAlternative) {
+                               return FALSE;
+                       }
+                       // Find first web folder:
+                       $result = $fileProcObj->findFirstWebFolder();
+                       // If that succeeded, return the path to it:
+                       if ($result) {
+                               // Remove the "fileadmin/" prefix of input path - and append the rest to the return value:
+                               if (\TYPO3\CMS\Core\Utility\GeneralUtility::isFirstPartOfStr($dirPrefix, $this->fileadminFolderName . '/')) {
+                                       $dirPrefix = substr($dirPrefix, strlen($this->fileadminFolderName . '/'));
+                               }
+                               return substr($fileProcObj->mounts[$result]['path'] . $dirPrefix, strlen(PATH_site));
+                       }
+               } else {
+                       return $dirPrefix;
+               }
+       }
+
+       /**************************
+        *
+        * File Input
+        *
+        *************************/
+       /**
+        * Loads the header section/all of the $filename into memory
+        *
+        * @param string $filename Filename, absolute
+        * @param boolean $all If set, all information is loaded (header, records and files). Otherwise the default is to read only the header information
+        * @return boolean TRUE if the operation went well
+        * @todo Define visibility
+        */
+       public function loadFile($filename, $all = 0) {
+               if (@is_file($filename)) {
+                       $fI = pathinfo($filename);
+                       if (strtolower($fI['extension']) == 'xml') {
+                               // XML:
+                               $xmlContent = \TYPO3\CMS\Core\Utility\GeneralUtility::getUrl($filename);
+                               if (strlen($xmlContent)) {
+                                       $this->dat = \TYPO3\CMS\Core\Utility\GeneralUtility::xml2array($xmlContent, '', TRUE);
+                                       if (is_array($this->dat)) {
+                                               if ($this->dat['_DOCUMENT_TAG'] === 'T3RecordDocument' && is_array($this->dat['header']) && is_array($this->dat['records'])) {
+                                                       $this->loadInit();
+                                                       return TRUE;
+                                               } else {
+                                                       $this->error('XML file did not contain proper XML for TYPO3 Import');
+                                               }
+                                       } else {
+                                               $this->error('XML could not be parsed: ' . $this->dat);
+                                       }
+                               } else {
+                                       $this->error('Error opening file: ' . $filename);
+                               }
+                       } else {
+                               // T3D
+                               if ($fd = fopen($filename, 'rb')) {
+                                       $this->dat['header'] = $this->getNextFilePart($fd, 1, 'header');
+                                       if ($all) {
+                                               $this->dat['records'] = $this->getNextFilePart($fd, 1, 'records');
+                                               $this->dat['files'] = $this->getNextFilePart($fd, 1, 'files');
+                                       }
+                                       $this->loadInit();
+                                       return TRUE;
+                               } else {
+                                       $this->error('Error opening file: ' . $filename);
+                               }
+                               fclose($fd);
+                       }
+               } else {
+                       $this->error('Filename not found: ' . $filename);
+               }
+               return FALSE;
+       }
+
+       /**
+        * Returns the next content part form the fileresource (t3d), $fd
+        *
+        * @param pointer $fd File pointer
+        * @param boolean $unserialize If set, the returned content is unserialized into an array, otherwise you get the raw string
+        * @param string $name For error messages this indicates the section of the problem.
+        * @return string Data string
+        * @access private
+        * @see loadFile()
+        * @todo Define visibility
+        */
+       public function getNextFilePart($fd, $unserialize = 0, $name = '') {
+               $initStrLen = 32 + 1 + 1 + 1 + 10 + 1;
+               // Getting header data
+               $initStr = fread($fd, $initStrLen);
+               $initStrDat = explode(':', $initStr);
+               if (strstr($initStrDat[0], 'Warning') == FALSE) {
+                       if (!strcmp($initStrDat[3], '')) {
+                               $datString = fread($fd, intval($initStrDat[2]));
+                               fread($fd, 1);
+                               if (!strcmp(md5($datString), $initStrDat[0])) {
+                                       if ($initStrDat[1]) {
+                                               if ($this->compress) {
+                                                       $datString = gzuncompress($datString);
+                                               } else {
+                                                       $this->error('Content read error: This file requires decompression, but this server does not offer gzcompress()/gzuncompress() functions.', 1);
+                                               }
+                                       }
+                                       return $unserialize ? unserialize($datString) : $datString;
+                               } else {
+                                       $this->error('MD5 check failed (' . $name . ')');
+                               }
+                       } else {
+                               $this->error('File read error: InitString had a wrong length. (' . $name . ')');
+                       }
+               } else {
+                       $this->error('File read error: Warning message in file. (' . $initStr . fgets($fd) . ')');
+               }
+       }
+
+       /**
+        * Loads T3D file content into the $this->dat array
+        * (This function can be used to test the output strings from ->compileMemoryToFileContent())
+        *
+        * @param string $filecontent File content
+        * @return void
+        * @todo Define visibility
+        */
+       public function loadContent($filecontent) {
+               $pointer = 0;
+               $this->dat['header'] = $this->getNextContentPart($filecontent, $pointer, 1, 'header');
+               $this->dat['records'] = $this->getNextContentPart($filecontent, $pointer, 1, 'records');
+               $this->dat['files'] = $this->getNextContentPart($filecontent, $pointer, 1, 'files');
+               $this->loadInit();
+       }
+
+       /**
+        * Returns the next content part from the $filecontent
+        *
+        * @param string $filecontent File content string
+        * @param integer $pointer File pointer (where to read from)
+        * @param boolean $unserialize If set, the returned content is unserialized into an array, otherwise you get the raw string
+        * @param string $name For error messages this indicates the section of the problem.
+        * @return string Data string
+        * @todo Define visibility
+        */
+       public function getNextContentPart($filecontent, &$pointer, $unserialize = 0, $name = '') {
+               $initStrLen = 32 + 1 + 1 + 1 + 10 + 1;
+               // getting header data
+               $initStr = substr($filecontent, $pointer, $initStrLen);
+               $pointer += $initStrLen;
+               $initStrDat = explode(':', $initStr);
+               if (!strcmp($initStrDat[3], '')) {
+                       $datString = substr($filecontent, $pointer, intval($initStrDat[2]));
+                       $pointer += intval($initStrDat[2]) + 1;
+                       if (!strcmp(md5($datString), $initStrDat[0])) {
+                               if ($initStrDat[1]) {
+                                       if ($this->compress) {
+                                               $datString = gzuncompress($datString);
+                                       } else {
+                                               $this->error('Content read error: This file requires decompression, but this server does not offer gzcompress()/gzuncompress() functions.', 1);
+                                       }
+                               }
+                               return $unserialize ? unserialize($datString) : $datString;
+                       } else {
+                               $this->error('MD5 check failed (' . $name . ')');
+                       }
+               } else {
+                       $this->error('Content read error: InitString had a wrong length. (' . $name . ')');
+               }
+       }
+
+       /**
+        * Setting up the object based on the recently loaded ->dat array
+        *
+        * @return void
+        * @todo Define visibility
+        */
+       public function loadInit() {
+               $this->relStaticTables = (array) $this->dat['header']['relStaticTables'];
+               $this->excludeMap = (array) $this->dat['header']['excludeMap'];
+               $this->softrefCfg = (array) $this->dat['header']['softrefCfg'];
+               $this->extensionDependencies = (array) $this->dat['header']['extensionDependencies'];
+               $this->fixCharsets();
+       }
+
+       /**
+        * Fix charset of import memory if different from system charset
+        *
+        * @return void
+        * @see loadInit()
+        * @todo Define visibility
+        */
+       public function fixCharsets() {
+               global $LANG;
+               $importCharset = $this->dat['header']['charset'];
+               if ($importCharset) {
+                       if ($importCharset !== $LANG->charSet) {
+                               $this->error('CHARSET: Converting charset of input file (' . $importCharset . ') to the system charset (' . $LANG->charSet . ')');
+                               // Convert meta data:
+                               if (is_array($this->dat['header']['meta'])) {
+                                       $LANG->csConvObj->convArray($this->dat['header']['meta'], $importCharset, $LANG->charSet);
+                               }
+                               // Convert record headers:
+                               if (is_array($this->dat['header']['records'])) {
+                                       $LANG->csConvObj->convArray($this->dat['header']['records'], $importCharset, $LANG->charSet);
+                               }
+                               // Convert records themselves:
+                               if (is_array($this->dat['records'])) {
+                                       $LANG->csConvObj->convArray($this->dat['records'], $importCharset, $LANG->charSet);
+                               }
+                       }
+               } else {
+                       $this->error('CHARSET: No charset found in import file!');
+               }
+       }
+
+       /********************************************************
+        *
+        * Visual rendering of import/export memory, $this->dat
+        *
+        ********************************************************/
+       /**
+        * Displays an overview of the header-content.
+        *
+        * @return string HTML content
+        * @todo Define visibility
+        */
+       public function displayContentOverview() {
+               global $LANG;
+               // Check extension dependencies:
+               if (is_array($this->dat['header']['extensionDependencies'])) {
+                       foreach ($this->dat['header']['extensionDependencies'] as $extKey) {
+                               if (!\TYPO3\CMS\Core\Utility\ExtensionManagementUtility::isLoaded($extKey)) {
+                                       $this->error('DEPENDENCY: The extension with key "' . $extKey . '" must be installed!');
+                               }
+                       }
+               }
+               // Probably this is done to save memory space?
+               unset($this->dat['files']);
+               // Traverse header:
+               $this->remainHeader = $this->dat['header'];
+               if (is_array($this->remainHeader)) {
+                       // If there is a page tree set, show that:
+                       if (is_array($this->dat['header']['pagetree'])) {
+                               reset($this->dat['header']['pagetree']);
+                               $lines = array();
+                               $this->traversePageTree($this->dat['header']['pagetree'], $lines);
+                               $rows = array();
+                               $rows[] = '
+                               <tr class="bgColor5 tableheader">
+                                       <td>' . $LANG->getLL('impexpcore_displaycon_controls', 1) . '</td>
+                                       <td>' . $LANG->getLL('impexpcore_displaycon_title', 1) . '</td>
+                                       <td>' . $LANG->getLL('impexpcore_displaycon_size', 1) . '</td>
+                                       <td>' . $LANG->getLL('impexpcore_displaycon_message', 1) . '</td>
+                                       ' . ($this->update ? '<td>' . $LANG->getLL('impexpcore_displaycon_updateMode', 1) . '</td>' : '') . '
+                                       ' . ($this->update ? '<td>' . $LANG->getLL('impexpcore_displaycon_currentPath', 1) . '</td>' : '') . '
+                                       ' . ($this->showDiff ? '<td>' . $LANG->getLL('impexpcore_displaycon_result', 1) . '</td>' : '') . '
+                               </tr>';
+                               foreach ($lines as $r) {
+                                       $rows[] = '
+                                       <tr class="' . $r['class'] . '">
+                                               <td>' . $this->renderControls($r) . '</td>
+                                               <td nowrap="nowrap">' . $r['preCode'] . $r['title'] . '</td>
+                                               <td nowrap="nowrap">' . \TYPO3\CMS\Core\Utility\GeneralUtility::formatSize($r['size']) . '</td>
+                                               <td nowrap="nowrap">' . ($r['msg'] && !$this->doesImport ? '<span class="typo3-red">' . htmlspecialchars($r['msg']) . '</span>' : '') . '</td>
+                                               ' . ($this->update ? '<td nowrap="nowrap">' . $r['updateMode'] . '</td>' : '') . '
+                                               ' . ($this->update ? '<td nowrap="nowrap">' . $r['updatePath'] . '</td>' : '') . '
+                                               ' . ($this->showDiff ? '<td>' . $r['showDiffContent'] . '</td>' : '') . '
+                                       </tr>';
+                               }
+                               $out = '
+                                       <strong>' . $LANG->getLL('impexpcore_displaycon_insidePagetree', 1) . '</strong>
+                                       <br /><br />
+                                       <table border="0" cellpadding="0" cellspacing="1">' . implode('', $rows) . '</table>
+                                       <br /><br />';
+                       }
+                       // Print remaining records that were not contained inside the page tree:
+                       $lines = array();
+                       if (is_array($this->remainHeader['records'])) {
+                               if (is_array($this->remainHeader['records']['pages'])) {
+                                       $this->traversePageRecords($this->remainHeader['records']['pages'], $lines);
+                               }
+                               $this->traverseAllRecords($this->remainHeader['records'], $lines);
+                               if (count($lines)) {
+                                       $rows = array();
+                                       $rows[] = '
+                                       <tr class="bgColor5 tableheader">
+                                               <td>' . $LANG->getLL('impexpcore_displaycon_controls', 1) . '</td>
+                                               <td>' . $LANG->getLL('impexpcore_displaycon_title', 1) . '</td>
+                                               <td>' . $LANG->getLL('impexpcore_displaycon_size', 1) . '</td>
+                                               <td>' . $LANG->getLL('impexpcore_displaycon_message', 1) . '</td>
+                                               ' . ($this->update ? '<td>' . $LANG->getLL('impexpcore_displaycon_updateMode', 1) . '</td>' : '') . '
+                                               ' . ($this->update ? '<td>' . $LANG->getLL('impexpcore_displaycon_currentPath', 1) . '</td>' : '') . '
+                                               ' . ($this->showDiff ? '<td>' . $LANG->getLL('impexpcore_displaycon_result', 1) . '</td>' : '') . '
+                                       </tr>';
+                                       foreach ($lines as $r) {
+                                               $rows[] = '<tr class="' . $r['class'] . '">
+                                                       <td>' . $this->renderControls($r) . '</td>
+                                                       <td nowrap="nowrap">' . $r['preCode'] . $r['title'] . '</td>
+                                                       <td nowrap="nowrap">' . \TYPO3\CMS\Core\Utility\GeneralUtility::formatSize($r['size']) . '</td>
+                                                       <td nowrap="nowrap">' . ($r['msg'] && !$this->doesImport ? '<span class="typo3-red">' . htmlspecialchars($r['msg']) . '</span>' : '') . '</td>
+                                                       ' . ($this->update ? '<td nowrap="nowrap">' . $r['updateMode'] . '</td>' : '') . '
+                                                       ' . ($this->update ? '<td nowrap="nowrap">' . $r['updatePath'] . '</td>' : '') . '
+                                                       ' . ($this->showDiff ? '<td>' . $r['showDiffContent'] . '</td>' : '') . '
+                                               </tr>';
+                                       }
+                                       $out .= '
+                                               <strong>' . $LANG->getLL('impexpcore_singlereco_outsidePagetree', 1) . '</strong>
+                                               <br /><br />
+                                               <table border="0" cellpadding="0" cellspacing="1">' . implode('', $rows) . '</table>';
+                               }
+                       }
+               }
+               return $out;
+       }
+
+       /**
+        * Go through page tree for display
+        *
+        * @param array $pT Page tree array with uid/subrow (from ->dat[header][pagetree]
+        * @param array $lines Output lines array (is passed by reference and modified)
+        * @param string $preCode Pre-HTML code
+        * @return void
+        * @todo Define visibility
+        */
+       public function traversePageTree($pT, &$lines, $preCode = '') {
+               foreach ($pT as $k => $v) {
+                       // Add this page:
+                       $this->singleRecordLines('pages', $k, $lines, $preCode);
+                       // Subrecords:
+                       if (is_array($this->dat['header']['pid_lookup'][$k])) {
+                               foreach ($this->dat['header']['pid_lookup'][$k] as $t => $recUidArr) {
+                                       if ($t != 'pages') {
+                                               foreach ($recUidArr as $ruid => $value) {
+                                                       $this->singleRecordLines($t, $ruid, $lines, $preCode . '&nbsp;&nbsp;&nbsp;&nbsp;');
+                                               }
+                                       }
+                               }
+                               unset($this->remainHeader['pid_lookup'][$k]);
+                       }
+                       // Subpages, called recursively:
+                       if (is_array($v['subrow'])) {
+                               $this->traversePageTree($v['subrow'], $lines, $preCode . '&nbsp;&nbsp;&nbsp;&nbsp;');
+                       }
+               }
+       }
+
+       /**
+        * Go through remaining pages (not in tree)
+        *
+        * @param array $pT Page tree array with uid/subrow (from ->dat[header][pagetree]
+        * @param array $lines Output lines array (is passed by reference and modified)
+        * @return void
+        * @todo Define visibility
+        */
+       public function traversePageRecords($pT, &$lines) {
+               foreach ($pT as $k => $rHeader) {
+                       $this->singleRecordLines('pages', $k, $lines, '', 1);
+                       // Subrecords:
+                       if (is_array($this->dat['header']['pid_lookup'][$k])) {
+                               foreach ($this->dat['header']['pid_lookup'][$k] as $t => $recUidArr) {
+                                       if ($t != 'pages') {
+                                               foreach ($recUidArr as $ruid => $value) {
+                                                       $this->singleRecordLines($t, $ruid, $lines, '&nbsp;&nbsp;&nbsp;&nbsp;');
+                                               }
+                                       }
+                               }
+                               unset($this->remainHeader['pid_lookup'][$k]);
+                       }
+               }
+       }
+
+       /**
+        * Go through ALL records (if the pages are displayed first, those will not be amoung these!)
+        *
+        * @param array $pT Page tree array with uid/subrow (from ->dat[header][pagetree]
+        * @param array $lines Output lines array (is passed by reference and modified)
+        * @return void
+        * @todo Define visibility
+        */
+       public function traverseAllRecords($pT, &$lines) {
+               foreach ($pT as $t => $recUidArr) {
+                       if ($t != 'pages') {
+                               $preCode = '';
+                               foreach ($recUidArr as $ruid => $value) {
+                                       $this->singleRecordLines($t, $ruid, $lines, $preCode, 1);
+                               }
+                       }
+               }
+       }
+
+       /**
+        * Add entries for a single record
+        *
+        * @param string $table Table name
+        * @param integer $uid Record uid
+        * @param array $lines Output lines array (is passed by reference and modified)
+        * @param string $preCode Pre-HTML code
+        * @param boolean $checkImportInPidRecord If you want import validation, you can set this so it checks if the import can take place on the specified page.
+        * @return void
+        * @todo Define visibility
+        */
+       public function singleRecordLines($table, $uid, &$lines, $preCode, $checkImportInPidRecord = 0) {
+               global $LANG;
+               // Get record:
+               $record = $this->dat['header']['records'][$table][$uid];
+               unset($this->remainHeader['records'][$table][$uid]);
+               if (!is_array($record) && !($table === 'pages' && !$uid)) {
+                       $this->error('MISSING RECORD: ' . $table . ':' . $uid, 1);
+               }
+               // Begin to create the line arrays information record, pInfo:
+               $pInfo = array();
+               $pInfo['ref'] = $table . ':' . $uid;
+               // Unknown table name:
+               if ($table === '_SOFTREF_') {
+                       $pInfo['preCode'] = $preCode;
+                       $pInfo['title'] = '<em>' . $GLOBALS['LANG']->getLL('impexpcore_singlereco_softReferencesFiles', 1) . '</em>';
+               } elseif (!isset($GLOBALS['TCA'][$table])) {
+                       // Unknown table name:
+                       $pInfo['preCode'] = $preCode;
+                       $pInfo['msg'] = 'UNKNOWN TABLE \'' . $pInfo['ref'] . '\'';
+                       $pInfo['title'] = '<em>' . htmlspecialchars($record['title']) . '</em>';
+               } else {
+                       // Otherwise, set table icon and title.
+                       // Import Validation (triggered by $this->display_import_pid_record) will show messages if import is not possible of various items.
+                       if (is_array($this->display_import_pid_record)) {
+                               if ($checkImportInPidRecord) {
+                                       if (!$GLOBALS['BE_USER']->doesUserHaveAccess($this->display_import_pid_record, ($table === 'pages' ? 8 : 16))) {
+                                               $pInfo['msg'] .= '\'' . $pInfo['ref'] . '\' cannot be INSERTED on this page! ';
+                                       }
+                                       if (!$this->checkDokType($table, $this->display_import_pid_record['doktype']) && !$GLOBALS['TCA'][$table]['ctrl']['rootLevel']) {
+                                               $pInfo['msg'] .= '\'' . $table . '\' cannot be INSERTED on this page type (change page type to \'Folder\'.) ';
+                                       }
+                               }
+                               if (!$GLOBALS['BE_USER']->check('tables_modify', $table)) {
+                                       $pInfo['msg'] .= 'You are not allowed to CREATE \'' . $table . '\' tables! ';
+                               }
+                               if ($GLOBALS['TCA'][$table]['ctrl']['readOnly']) {
+                                       $pInfo['msg'] .= 'TABLE \'' . $table . '\' is READ ONLY! ';
+                               }
+                               if ($GLOBALS['TCA'][$table]['ctrl']['adminOnly'] && !$GLOBALS['BE_USER']->isAdmin()) {
+                                       $pInfo['msg'] .= 'TABLE \'' . $table . '\' is ADMIN ONLY! ';
+                               }
+                               if ($GLOBALS['TCA'][$table]['ctrl']['is_static']) {
+                                       $pInfo['msg'] .= 'TABLE \'' . $table . '\' is a STATIC TABLE! ';
+                               }
+                               if ($GLOBALS['TCA'][$table]['ctrl']['rootLevel']) {
+                                       $pInfo['msg'] .= 'TABLE \'' . $table . '\' will be inserted on ROOT LEVEL! ';
+                               }
+                               $diffInverse = FALSE;
+                               if ($this->update) {
+                                       // In case of update-PREVIEW we swap the diff-sources.
+                                       $diffInverse = TRUE;
+                                       $recInf = $this->doesRecordExist($table, $uid, $this->showDiff ? '*' : '');
+                                       $pInfo['updatePath'] = $recInf ? htmlspecialchars($this->getRecordPath($recInf['pid'])) : '<strong>NEW!</strong>';
+                                       // Mode selector:
+                                       $optValues = array();
+                                       $optValues[] = $recInf ? $LANG->getLL('impexpcore_singlereco_update') : $LANG->getLL('impexpcore_singlereco_insert');
+                                       if ($recInf) {
+                                               $optValues['as_new'] = $LANG->getLL('impexpcore_singlereco_importAsNew');
+                                       }
+                                       if ($recInf) {
+                                               if (!$this->global_ignore_pid) {
+                                                       $optValues['ignore_pid'] = $LANG->getLL('impexpcore_singlereco_ignorePid');
+                                               } else {
+                                                       $optValues['respect_pid'] = $LANG->getLL('impexpcore_singlereco_respectPid');
+                                               }
+                                       }
+                                       if (!$recInf && $GLOBALS['BE_USER']->isAdmin()) {
+                                               $optValues['force_uid'] = sprintf($LANG->getLL('impexpcore_singlereco_forceUidSAdmin'), $uid);
+                                       }
+                                       $optValues['exclude'] = $LANG->getLL('impexpcore_singlereco_exclude');
+                                       $pInfo['updateMode'] = $this->renderSelectBox('tx_impexp[import_mode][' . $table . ':' . $uid . ']', $this->import_mode[$table . ':' . $uid], $optValues);
+                               }
+                               // Diff vieiw:
+                               if ($this->showDiff) {
+                                       // For IMPORTS, get new id:
+                                       if ($newUid = $this->import_mapId[$table][$uid]) {
+                                               $diffInverse = FALSE;
+                                               $recInf = $this->doesRecordExist($table, $newUid, '*');
+                                               \TYPO3\CMS\Backend\Utility\BackendUtility::workspaceOL($table, $recInf);
+                                       }
+                                       if (is_array($recInf)) {
+                                               $pInfo['showDiffContent'] = $this->compareRecords($recInf, $this->dat['records'][$table . ':' . $uid]['data'], $table, $diffInverse);
+                                       }
+                               }
+                       }
+                       $pInfo['preCode'] = $preCode . \t3lib_iconworks::getSpriteIconForRecord($table, (array) $this->dat['records'][($table . ':' . $uid)]['data'], array('title' => htmlspecialchars(($table . ':' . $uid))));
+                       $pInfo['title'] = htmlspecialchars($record['title']);
+                       // View page:
+                       if ($table === 'pages') {
+                               $viewID = $this->mode === 'export' ? $uid : ($this->doesImport ? $this->import_mapId['pages'][$uid] : 0);
+                               if ($viewID) {
+                                       $pInfo['title'] = '<a href="#" onclick="' . htmlspecialchars(\TYPO3\CMS\Backend\Utility\BackendUtility::viewOnClick($viewID, $GLOBALS['BACK_PATH'])) . 'return false;">' . $pInfo['title'] . '</a>';
+                               }
+                       }
+               }
+               $pInfo['class'] = $table == 'pages' ? 'bgColor4-20' : 'bgColor4';
+               $pInfo['type'] = 'record';
+               $pInfo['size'] = $record['size'];
+               $lines[] = $pInfo;
+               // File relations:
+               if (is_array($record['filerefs'])) {
+                       $this->addFiles($record['filerefs'], $lines, $preCode);
+               }
+               // DB relations
+               if (is_array($record['rels'])) {
+                       $this->addRelations($record['rels'], $lines, $preCode);
+               }
+               // Soft ref
+               if (count($record['softrefs'])) {
+                       $preCode_A = $preCode . '&nbsp;&nbsp;&nbsp;&nbsp;';
+                       $preCode_B = $preCode . '&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;';
+                       foreach ($record['softrefs'] as $info) {
+                               $pInfo = array();
+                               $pInfo['preCode'] = $preCode_A . \TYPO3\CMS\Backend\Utility\IconUtility::getSpriteIcon('status-status-reference-soft');
+                               $pInfo['title'] = '<em>' . $info['field'] . ', "' . $info['spKey'] . '" </em>: <span title="' . htmlspecialchars($info['matchString']) . '">' . htmlspecialchars(\TYPO3\CMS\Core\Utility\GeneralUtility::fixed_lgd_cs($info['matchString'], 60)) . '</span>';
+                               if ($info['subst']['type']) {
+                                       if (strlen($info['subst']['title'])) {
+                                               $pInfo['title'] .= '<br/>' . $preCode_B . '<strong>' . $LANG->getLL('impexpcore_singlereco_title', 1) . '</strong> ' . htmlspecialchars(\TYPO3\CMS\Core\Utility\GeneralUtility::fixed_lgd_cs($info['subst']['title'], 60));
+                                       }
+                                       if (strlen($info['subst']['description'])) {
+                                               $pInfo['title'] .= '<br/>' . $preCode_B . '<strong>' . $LANG->getLL('impexpcore_singlereco_descr', 1) . '</strong> ' . htmlspecialchars(\TYPO3\CMS\Core\Utility\GeneralUtility::fixed_lgd_cs($info['subst']['description'], 60));
+                                       }
+                                       $pInfo['title'] .= '<br/>' . $preCode_B . ($info['subst']['type'] == 'file' ? $LANG->getLL('impexpcore_singlereco_filename', 1) . ' <strong>' . $info['subst']['relFileName'] . '</strong>' : '') . ($info['subst']['type'] == 'string' ? $LANG->getLL('impexpcore_singlereco_value', 1) . ' <strong>' . $info['subst']['tokenValue'] . '</strong>' : '') . ($info['subst']['type'] == 'db' ? $LANG->getLL('impexpcore_softrefsel_record', 1) . ' <strong>' . $info['subst']['recordRef'] . '</strong>' : '');
+                               }
+                               $pInfo['ref'] = 'SOFTREF';
+                               $pInfo['size'] = '';
+                               $pInfo['class'] = 'bgColor3';
+                               $pInfo['type'] = 'softref';
+                               $pInfo['_softRefInfo'] = $info;
+                               $pInfo['type'] = 'softref';
+                               if ($info['error'] && !\TYPO3\CMS\Core\Utility\GeneralUtility::inList('editable,exclude', $this->softrefCfg[$info['subst']['tokenID']]['mode'])) {
+                                       $pInfo['msg'] .= $info['error'];
+                               }
+                               $lines[] = $pInfo;
+                               // Add relations:
+                               if ($info['subst']['type'] == 'db') {
+                                       list($tempTable, $tempUid) = explode(':', $info['subst']['recordRef']);
+                                       $this->addRelations(array(array('table' => $tempTable, 'id' => $tempUid, 'tokenID' => $info['subst']['tokenID'])), $lines, $preCode_B, array(), '');
+                               }
+                               // Add files:
+                               if ($info['subst']['type'] == 'file') {
+                                       $this->addFiles(array($info['file_ID']), $lines, $preCode_B, '', $info['subst']['tokenID']);
+                               }
+                       }
+               }
+       }
+
+       /**
+        * Add DB relations entries for a record's rels-array
+        *
+        * @param array $rels Array of relations
+        * @param array $lines Output lines array (is passed by reference and modified)
+        * @param string $preCode Pre-HTML code
+        * @param array $recurCheck Recursivity check stack
+        * @param string $htmlColorClass Alternative HTML color class to use.
+        * @return void
+        * @access private
+        * @see singleRecordLines()
+        * @todo Define visibility
+        */
+       public function addRelations($rels, &$lines, $preCode, $recurCheck = array(), $htmlColorClass = '') {
+               foreach ($rels as $dat) {
+                       $table = $dat['table'];
+                       $uid = $dat['id'];
+                       $pInfo = array();
+                       $Iprepend = '';
+                       $staticFixed = FALSE;
+                       $pInfo['ref'] = $table . ':' . $uid;
+                       if (!in_array($pInfo['ref'], $recurCheck)) {
+                               if ($uid > 0) {
+                                       $record = $this->dat['header']['records'][$table][$uid];
+                                       if (!is_array($record)) {
+                                               if ($this->isTableStatic($table) || $this->isExcluded($table, $uid) || $dat['tokenID'] && !$this->includeSoftref($dat['tokenID'])) {
+                                                       $pInfo['title'] = htmlspecialchars('STATIC: ' . $pInfo['ref']);
+                                                       $Iprepend = '_static';
+                                                       $staticFixed = TRUE;
+                                               } else {
+                                                       $doesRE = $this->doesRecordExist($table, $uid);
+                                                       $lostPath = $this->getRecordPath($table === 'pages' ? $doesRE['uid'] : $doesRE['pid']);
+                                                       $pInfo['title'] = htmlspecialchars($pInfo['ref']);
+                                                       $pInfo['title'] = '<span title="' . htmlspecialchars($lostPath) . '">' . $pInfo['title'] . '</span>';
+                                                       $pInfo['msg'] = 'LOST RELATION' . (!$doesRE ? ' (Record not found!)' : ' (Path: ' . $lostPath . ')');
+                                                       $Iprepend = '_lost';
+                                               }
+                                       } else {
+                                               $pInfo['title'] = htmlspecialchars($record['title']);
+                                               $pInfo['title'] = '<span title="' . htmlspecialchars($this->getRecordPath(($table === 'pages' ? $record['uid'] : $record['pid']))) . '">' . $pInfo['title'] . '</span>';
+                                       }
+                               } else {
+                                       // Negative values in relation fields. This is typically sys_language fields, fe_users fields etc. They are static values. They CAN theoretically be negative pointers to uids in other tables but this is so rarely used that it is not supported
+                                       $pInfo['title'] = htmlspecialchars('FIXED: ' . $pInfo['ref']);
+                                       $staticFixed = TRUE;
+                               }
+                               $pInfo['preCode'] = $preCode . '&nbsp;&nbsp;&nbsp;&nbsp;<img' . \TYPO3\CMS\Backend\Utility\IconUtility::skinImg($GLOBALS['BACK_PATH'], ('gfx/rel_db' . $Iprepend . '.gif'), 'width="13" height="12"') . ' align="top" title="' . htmlspecialchars($pInfo['ref']) . '" alt="" />';
+                               $pInfo['class'] = $htmlColorClass ? $htmlColorClass : 'bgColor3';
+                               $pInfo['type'] = 'rel';
+                               if (!$staticFixed || $this->showStaticRelations) {
+                                       $lines[] = $pInfo;
+                                       if (is_array($record) && is_array($record['rels'])) {
+                                               $this->addRelations($record['rels'], $lines, $preCode . '&nbsp;&nbsp;', array_merge($recurCheck, array($pInfo['ref'])), $htmlColorClass);
+                                       }
+                               }
+                       } else {
+                               $this->error($pInfo['ref'] . ' was recursive...');
+                       }
+               }
+       }
+
+       /**
+        * Add file relation entries for a record's rels-array
+        *
+        * @param array $rels Array of file IDs
+        * @param array $lines Output lines array (is passed by reference and modified)
+        * @param string $preCode Pre-HTML code
+        * @param string $htmlColorClass Alternative HTML color class to use.
+        * @param string $tokenID Token ID if this is a softreference (in which case it only makes sense with a single element in the $rels array!)
+        * @return void
+        * @access private
+        * @see singleRecordLines()
+        * @todo Define visibility
+        */
+       public function addFiles($rels, &$lines, $preCode, $htmlColorClass = '', $tokenID = '') {
+               foreach ($rels as $ID) {
+                       // Process file:
+                       $pInfo = array();
+                       $fI = $this->dat['header']['files'][$ID];
+                       if (!is_array($fI)) {
+                               if (!$tokenID || $this->includeSoftref($tokenID)) {
+                                       $pInfo['msg'] = 'MISSING FILE: ' . $ID;
+                                       $this->error('MISSING FILE: ' . $ID, 1);
+                               } else {
+                                       return;
+                               }
+                       }
+                       $pInfo['preCode'] = $preCode . '&nbsp;&nbsp;&nbsp;&nbsp;' . \TYPO3\CMS\Backend\Utility\IconUtility::getSpriteIcon('status-status-reference-hard');
+                       $pInfo['title'] = htmlspecialchars($fI['filename']);
+                       $pInfo['ref'] = 'FILE';
+                       $pInfo['size'] = $fI['filesize'];
+                       $pInfo['class'] = $htmlColorClass ? $htmlColorClass : 'bgColor3';
+                       $pInfo['type'] = 'file';
+                       // If import mode and there is a non-RTE softreference, check the destination directory:
+                       if ($this->mode === 'import' && $tokenID && !$fI['RTE_ORIG_ID']) {
+                               if (isset($fI['parentRelFileName'])) {
+                                       $pInfo['msg'] = 'Seems like this file is already referenced from within an HTML/CSS file. That takes precedence. ';
+                               } else {
+                                       $testDirPrefix = dirname($fI['relFileName']) . '/';
+                                       $testDirPrefix2 = $this->verifyFolderAccess($testDirPrefix);
+                                       if (!$testDirPrefix2) {
+                                               $pInfo['msg'] = 'ERROR: There are no available filemounts to write file in! ';
+                                       } elseif (strcmp($testDirPrefix, $testDirPrefix2)) {
+                                               $pInfo['msg'] = 'File will be attempted written to "' . $testDirPrefix2 . '". ';
+                                       }
+                               }
+                               // Check if file exists:
+                               if (file_exists(PATH_site . $fI['relFileName'])) {
+                                       if ($this->update) {
+                                               $pInfo['updatePath'] .= 'File exists.';
+                                       } else {
+                                               $pInfo['msg'] .= 'File already exists! ';
+                                       }
+                               }
+                               // Check extension:
+                               $fileProcObj = $this->getFileProcObj();
+                               if ($fileProcObj->actionPerms['newFile']) {
+                                       $testFI = \TYPO3\CMS\Core\Utility\GeneralUtility::split_fileref(PATH_site . $fI['relFileName']);
+                                       if (!$this->allowPHPScripts && !$fileProcObj->checkIfAllowed($testFI['fileext'], $testFI['path'], $testFI['file'])) {
+                                               $pInfo['msg'] .= 'File extension was not allowed!';
+                                       }
+                               } else {
+                                       $pInfo['msg'] = 'You user profile does not allow you to create files on the server!';
+                               }
+                       }
+                       $pInfo['showDiffContent'] = substr($this->fileIDMap[$ID], strlen(PATH_site));
+                       $lines[] = $pInfo;
+                       unset($this->remainHeader['files'][$ID]);
+                       // RTE originals:
+                       if ($fI['RTE_ORIG_ID']) {
+                               $ID = $fI['RTE_ORIG_ID'];
+                               $pInfo = array();
+                               $fI = $this->dat['header']['files'][$ID];
+                               if (!is_array($fI)) {
+                                       $pInfo['msg'] = 'MISSING RTE original FILE: ' . $ID;
+                                       $this->error('MISSING RTE original FILE: ' . $ID, 1);
+                               }
+                               $pInfo['showDiffContent'] = substr($this->fileIDMap[$ID], strlen(PATH_site));
+                               $pInfo['preCode'] = $preCode . '&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;' . \TYPO3\CMS\Backend\Utility\IconUtility::getSpriteIcon('actions-reference-file');
+                               $pInfo['title'] = htmlspecialchars($fI['filename']) . ' <em>(Original)</em>';
+                               $pInfo['ref'] = 'FILE';
+                               $pInfo['size'] = $fI['filesize'];
+                               $pInfo['class'] = $htmlColorClass ? $htmlColorClass : 'bgColor3';
+                               $pInfo['type'] = 'file';
+                               $lines[] = $pInfo;
+                               unset($this->remainHeader['files'][$ID]);
+                       }
+                       // External resources:
+                       if (is_array($fI['EXT_RES_ID'])) {
+                               foreach ($fI['EXT_RES_ID'] as $ID) {
+                                       $pInfo = array();
+                                       $fI = $this->dat['header']['files'][$ID];
+                                       if (!is_array($fI)) {
+                                               $pInfo['msg'] = 'MISSING External Resource FILE: ' . $ID;
+                                               $this->error('MISSING External Resource FILE: ' . $ID, 1);
+                                       } else {
+                                               $pInfo['updatePath'] = $fI['parentRelFileName'];
+                                       }
+                                       $pInfo['showDiffContent'] = substr($this->fileIDMap[$ID], strlen(PATH_site));
+                                       $pInfo['preCode'] = $preCode . '&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;' . \TYPO3\CMS\Backend\Utility\IconUtility::getSpriteIcon('actions-insert-reference');
+                                       $pInfo['title'] = htmlspecialchars($fI['filename']) . ' <em>(Resource)</em>';
+                                       $pInfo['ref'] = 'FILE';
+                                       $pInfo['size'] = $fI['filesize'];
+                                       $pInfo['class'] = $htmlColorClass ? $htmlColorClass : 'bgColor3';
+                                       $pInfo['type'] = 'file';
+                                       $lines[] = $pInfo;
+                                       unset($this->remainHeader['files'][$ID]);
+                               }
+                       }
+               }
+       }
+
+       /**
+        * Verifies that a table is allowed on a certain doktype of a page
+        *
+        * @param string $checkTable Table name to check
+        * @param integer $doktype doktype value.
+        * @return boolean TRUE if OK
+        * @todo Define visibility
+        */
+       public function checkDokType($checkTable, $doktype) {
+               global $PAGES_TYPES;
+               $allowedTableList = isset($PAGES_TYPES[$doktype]['allowedTables']) ? $PAGES_TYPES[$doktype]['allowedTables'] : $PAGES_TYPES['default']['allowedTables'];
+               $allowedArray = \TYPO3\CMS\Core\Utility\GeneralUtility::trimExplode(',', $allowedTableList, 1);
+               // If all tables or the table is listed as a allowed type, return TRUE
+               if (strstr($allowedTableList, '*') || in_array($checkTable, $allowedArray)) {
+                       return TRUE;
+               }
+       }
+
+       /**
+        * Render input controls for import or export
+        *
+        * @param array $r Configuration for element
+        * @return string HTML
+        * @todo Define visibility
+        */
+       public function renderControls($r) {
+               global $LANG;
+               if ($this->mode === 'export') {
+                       return $r['type'] == 'record' ? '<input type="checkbox" name="tx_impexp[exclude][' . $r['ref'] . ']" id="checkExclude' . $r['ref'] . '" value="1" /> <label for="checkExclude' . $r['ref'] . '">' . $LANG->getLL('impexpcore_singlereco_exclude', 1) . '</label>' : ($r['type'] == 'softref' ? $this->softrefSelector($r['_softRefInfo']) : '');
+               } else {
+                       // During import
+                       // For softreferences with editable fields:
+                       if ($r['type'] == 'softref' && is_array($r['_softRefInfo']['subst']) && $r['_softRefInfo']['subst']['tokenID']) {
+                               $tokenID = $r['_softRefInfo']['subst']['tokenID'];
+                               $cfg = $this->softrefCfg[$tokenID];
+                               if ($cfg['mode'] === 'editable') {
+                                       return (strlen($cfg['title']) ? '<strong>' . htmlspecialchars($cfg['title']) . '</strong><br/>' : '') . htmlspecialchars($cfg['description']) . '<br/>
+                                               <input type="text" name="tx_impexp[softrefInputValues][' . $tokenID . ']" value="' . htmlspecialchars((isset($this->softrefInputValues[$tokenID]) ? $this->softrefInputValues[$tokenID] : $cfg['defValue'])) . '" />';
+                               }
+                       }
+               }
+       }
+
+       /**
+        * Selectorbox with export options for soft references
+        *
+        * @param array $cfg Softref configuration array. An export box is shown only if a substitution scheme is found for the soft reference.
+        * @return string Selector box HTML
+        * @todo Define visibility
+        */
+       public function softrefSelector($cfg) {
+               global $LANG;
+               // Looking for file ID if any:
+               $fI = $cfg['file_ID'] ? $this->dat['header']['files'][$cfg['file_ID']] : array();
+               // Substitution scheme has to be around and RTE images MUST be exported.
+               if (is_array($cfg['subst']) && $cfg['subst']['tokenID']&nb