[BUGFIX] impext: export is broken
[Packages/TYPO3.CMS.git] / typo3 / sysext / impexp / Classes / Controller / ImportExportController.php
1 <?php
2 namespace TYPO3\CMS\Impexp\Controller;
3
4 /**
5 * Main script class for the Import / Export facility
6 *
7 * @author Kasper Skårhøj <kasperYYYY@typo3.com>
8 */
9 class ImportExportController extends \TYPO3\CMS\Backend\Module\BaseScriptClass {
10
11 // Array containing the current page.
12 /**
13 * @todo Define visibility
14 */
15 public $pageinfo;
16
17 /**
18 * Main module function
19 *
20 * @return void
21 * @todo Define visibility
22 */
23 public function main() {
24 // Start document template object:
25 $this->doc = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance('TYPO3\\CMS\\Backend\\Template\\DocumentTemplate');
26 $this->doc->backPath = $GLOBALS['BACK_PATH'];
27 $this->doc->bodyTagId = 'imp-exp-mod';
28 $this->doc->setModuleTemplate(\TYPO3\CMS\Core\Utility\ExtensionManagementUtility::extRelPath('impexp') . '/app/template.html');
29 $this->pageinfo = \TYPO3\CMS\Backend\Utility\BackendUtility::readPageAccess($this->id, $this->perms_clause);
30 // JavaScript
31 $this->doc->JScode = $this->doc->wrapScriptTags('
32 script_ended = 0;
33 function jumpToUrl(URL) { //
34 window.location.href = URL;
35 }
36 ');
37 // Setting up the context sensitive menu:
38 $this->doc->getContextMenuCode();
39 $this->doc->postCode = $this->doc->wrapScriptTags('
40 script_ended = 1;
41 if (top.fsMod) top.fsMod.recentIds["web"] = ' . intval($this->id) . ';
42 ');
43 $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 . '" />';
44 $this->content .= $this->doc->header($GLOBALS['LANG']->getLL('title'));
45 $this->content .= $this->doc->spacer(5);
46 // Input data grabbed:
47 $inData = \TYPO3\CMS\Core\Utility\GeneralUtility::_GP('tx_impexp');
48 $this->checkUpload();
49 switch ((string) $inData['action']) {
50 case 'export':
51 // Finally: If upload went well, set the new file as the thumbnail in the $inData array:
52 if (is_object($this->fileProcessor) && $this->fileProcessor->internalUploadMap[1]) {
53 $inData['meta']['thumbnail'] = md5($this->fileProcessor->internalUploadMap[1]);
54 }
55 // Call export interface
56 $this->exportData($inData);
57 break;
58 case 'import':
59 // Finally: If upload went well, set the new file as the import file:
60 if (is_object($this->fileProcessor) && $this->fileProcessor->internalUploadMap[1]) {
61 $fI = pathinfo($this->fileProcessor->internalUploadMap[1]);
62 // Only allowed extensions....
63 if (\TYPO3\CMS\Core\Utility\GeneralUtility::inList('t3d,xml', strtolower($fI['extension']))) {
64 $inData['file'] = $this->fileProcessor->internalUploadMap[1];
65 }
66 }
67 // Call import interface:
68 $this->importData($inData);
69 break;
70 }
71 // Setting up the buttons and markers for docheader
72 $docHeaderButtons = $this->getButtons();
73 $markers['CONTENT'] = $this->content;
74 // Build the <body> for the module
75 $this->content = $this->doc->startPage($GLOBALS['LANG']->getLL('title'));
76 $this->content .= $this->doc->moduleBody($this->pageinfo, $docHeaderButtons, $markers);
77 $this->content .= $this->doc->endPage();
78 $this->content = $this->doc->insertStylesAndJS($this->content);
79 }
80
81 /**
82 * Print the content
83 *
84 * @return void
85 * @todo Define visibility
86 */
87 public function printContent() {
88 echo $this->content;
89 }
90
91 /**
92 * Create the panel of buttons for submitting the form or otherwise perform operations.
93 *
94 * @return array all available buttons as an associated array
95 */
96 protected function getButtons() {
97 $buttons = array(
98 'view' => '',
99 'shortcut' => ''
100 );
101 if ($GLOBALS['BE_USER']->mayMakeShortcut()) {
102 $buttons['shortcut'] = $this->doc->makeShortcutIcon('tx_impexp', '', $this->MCONF['name']);
103 }
104 // Input data grabbed:
105 $inData = \TYPO3\CMS\Core\Utility\GeneralUtility::_GP('tx_impexp');
106 if ((string) $inData['action'] == 'import') {
107 if ($this->id && is_array($this->pageinfo) || $GLOBALS['BE_USER']->user['admin'] && !$this->id) {
108 if (is_array($this->pageinfo) && $this->pageinfo['uid']) {
109 // View
110 $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>';
111 }
112 }
113 }
114 return $buttons;
115 }
116
117 /**************************
118 *
119 * EXPORT FUNCTIONS
120 *
121 **************************/
122 /**
123 * Export part of module
124 *
125 * @param array $inData Content of POST VAR tx_impexp[]..
126 * @return void Setting content in $this->content
127 * @todo Define visibility
128 */
129 public function exportData($inData) {
130 // BUILDING EXPORT DATA:
131 // Processing of InData array values:
132 $inData['pagetree']['maxNumber'] = \TYPO3\CMS\Core\Utility\MathUtility::forceIntegerInRange($inData['pagetree']['maxNumber'], 1, 10000, 100);
133 $inData['listCfg']['maxNumber'] = \TYPO3\CMS\Core\Utility\MathUtility::forceIntegerInRange($inData['listCfg']['maxNumber'], 1, 10000, 100);
134 $inData['maxFileSize'] = \TYPO3\CMS\Core\Utility\MathUtility::forceIntegerInRange($inData['maxFileSize'], 1, 10000, 1000);
135 $inData['filename'] = trim(preg_replace('/[^[:alnum:]._-]*/', '', preg_replace('/\\.(t3d|xml)$/', '', $inData['filename'])));
136 if (strlen($inData['filename'])) {
137 $inData['filename'] .= $inData['filetype'] == 'xml' ? '.xml' : '.t3d';
138 }
139 // Set exclude fields in export object:
140 if (!is_array($inData['exclude'])) {
141 $inData['exclude'] = array();
142 }
143 // Saving/Loading/Deleting presets:
144 $this->processPresets($inData);
145 // Create export object and configure it:
146 $this->export = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance('TYPO3\\CMS\\Impexp\\ImportExport');
147 $this->export->init(0, 'export');
148 $this->export->setCharset($GLOBALS['LANG']->charSet);
149 $this->export->maxFileSize = $inData['maxFileSize'] * 1024;
150 $this->export->excludeMap = (array) $inData['exclude'];
151 $this->export->softrefCfg = (array) $inData['softrefCfg'];
152 $this->export->extensionDependencies = (array) $inData['extension_dep'];
153 $this->export->showStaticRelations = $inData['showStaticRelations'];
154 $this->export->includeExtFileResources = !$inData['excludeHTMLfileResources'];
155 // Static tables:
156 if (is_array($inData['external_static']['tables'])) {
157 $this->export->relStaticTables = $inData['external_static']['tables'];
158 }
159 // Configure which tables external relations are included for:
160 if (is_array($inData['external_ref']['tables'])) {
161 $this->export->relOnlyTables = $inData['external_ref']['tables'];
162 }
163 $this->export->setHeaderBasics();
164 // Meta data setting:
165 $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']);
166 if ($inData['meta']['thumbnail']) {
167 $tempDir = $this->userTempFolder();
168 if ($tempDir) {
169 $thumbnails = \TYPO3\CMS\Core\Utility\GeneralUtility::getFilesInDir($tempDir, 'png,gif,jpg', 1);
170 $theThumb = $thumbnails[$inData['meta']['thumbnail']];
171 if ($theThumb) {
172 $this->export->addThumbnail($theThumb);
173 }
174 }
175 }
176 // Configure which records to export
177 if (is_array($inData['record'])) {
178 foreach ($inData['record'] as $ref) {
179 $rParts = explode(':', $ref);
180 $this->export->export_addRecord($rParts[0], \TYPO3\CMS\Backend\Utility\BackendUtility::getRecord($rParts[0], $rParts[1]));
181 }
182 }
183 // Configure which tables to export
184 if (is_array($inData['list'])) {
185 foreach ($inData['list'] as $ref) {
186 $rParts = explode(':', $ref);
187 if ($GLOBALS['BE_USER']->check('tables_select', $rParts[0])) {
188 $res = $this->exec_listQueryPid($rParts[0], $rParts[1], \TYPO3\CMS\Core\Utility\MathUtility::forceIntegerInRange($inData['listCfg']['maxNumber'], 1));
189 while ($subTrow = $GLOBALS['TYPO3_DB']->sql_fetch_assoc($res)) {
190 $this->export->export_addRecord($rParts[0], $subTrow);
191 }
192 }
193 }
194 }
195 // Pagetree
196 if (isset($inData['pagetree']['id'])) {
197 // Based on click-expandable tree
198 if ($inData['pagetree']['levels'] == -1) {
199 $pagetree = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance('TYPO3\\CMS\\Impexp\\LocalPageTree');
200 $tree = $pagetree->ext_tree($inData['pagetree']['id'], $this->filterPageIds($this->export->excludeMap));
201 $this->treeHTML = $pagetree->printTree($tree);
202 $idH = $pagetree->buffer_idH;
203 } elseif ($inData['pagetree']['levels'] == -2) {
204 $this->addRecordsForPid($inData['pagetree']['id'], $inData['pagetree']['tables'], $inData['pagetree']['maxNumber']);
205 } else {
206 // Based on depth
207 // Drawing tree:
208 // If the ID is zero, export root
209 if (!$inData['pagetree']['id'] && $GLOBALS['BE_USER']->isAdmin()) {
210 $sPage = array(
211 'uid' => 0,
212 'title' => 'ROOT'
213 );
214 } else {
215 $sPage = \TYPO3\CMS\Backend\Utility\BackendUtility::getRecordWSOL('pages', $inData['pagetree']['id'], '*', ' AND ' . $this->perms_clause);
216 }
217 if (is_array($sPage)) {
218 $pid = $inData['pagetree']['id'];
219 $tree = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance('TYPO3\\CMS\\Backend\\Tree\\View\\PageTreeView');
220 $tree->init('AND ' . $this->perms_clause . $this->filterPageIds($this->export->excludeMap));
221 $HTML = \TYPO3\CMS\Backend\Utility\IconUtility::getSpriteIconForRecord('pages', $sPage);
222 $tree->tree[] = array('row' => $sPage, 'HTML' => $HTML);
223 $tree->buffer_idH = array();
224 if ($inData['pagetree']['levels'] > 0) {
225 $tree->getTree($pid, $inData['pagetree']['levels'], '');
226 }
227 $idH = array();
228 $idH[$pid]['uid'] = $pid;
229 if (count($tree->buffer_idH)) {
230 $idH[$pid]['subrow'] = $tree->buffer_idH;
231 }
232 $pagetree = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance('TYPO3\\CMS\\Impexp\\LocalPageTree');
233 $this->treeHTML = $pagetree->printTree($tree->tree);
234 }
235 }
236 // 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...)
237 if (is_array($idH)) {
238 // Sets the pagetree and gets a 1-dim array in return with the pages (in correct submission order BTW...)
239 $flatList = $this->export->setPageTree($idH);
240 foreach ($flatList as $k => $value) {
241 $this->export->export_addRecord('pages', \TYPO3\CMS\Backend\Utility\BackendUtility::getRecord('pages', $k));
242 $this->addRecordsForPid($k, $inData['pagetree']['tables'], $inData['pagetree']['maxNumber']);
243 }
244 }
245 }
246 // After adding ALL records we set relations:
247 for ($a = 0; $a < 10; $a++) {
248 $addR = $this->export->export_addDBRelations($a);
249 if (!count($addR)) {
250 break;
251 }
252 }
253 // Finally files are added:
254 // MUST be after the DBrelations are set so that files from ALL added records are included!
255 $this->export->export_addFilesFromRelations();
256 // If the download button is clicked, return file
257 if ($inData['download_export'] || $inData['save_export']) {
258 switch ((string) $inData['filetype']) {
259 case 'xml':
260 $out = $this->export->compileMemoryToFileContent('xml');
261 $fExt = '.xml';
262 break;
263 case 't3d':
264 $this->export->dontCompress = 1;
265 default:
266 $out = $this->export->compileMemoryToFileContent();
267 $fExt = ($this->export->doOutputCompress() ? '-z' : '') . '.t3d';
268 break;
269 }
270 // Filename:
271 $dlFile = $inData['filename'] ? $inData['filename'] : 'T3D_' . substr(preg_replace('/[^[:alnum:]_]/', '-', $inData['download_export_name']), 0, 20) . '_' . date('Y-m-d_H-i') . $fExt;
272 // Export for download:
273 if ($inData['download_export']) {
274 $mimeType = 'application/octet-stream';
275 Header('Content-Type: ' . $mimeType);
276 Header('Content-Length: ' . strlen($out));
277 Header('Content-Disposition: attachment; filename=' . basename($dlFile));
278 echo $out;
279 die;
280 }
281 // Export by saving:
282 if ($inData['save_export']) {
283 $savePath = $this->userSaveFolder();
284 $fullName = $savePath . $dlFile;
285 if (\TYPO3\CMS\Core\Utility\GeneralUtility::isAllowedAbsPath($savePath) && @is_dir(dirname($fullName)) && \TYPO3\CMS\Core\Utility\GeneralUtility::isAllowedAbsPath($fullName)) {
286 \TYPO3\CMS\Core\Utility\GeneralUtility::writeFile($fullName, $out);
287 $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);
288 } else {
289 $this->content .= $this->doc->section($GLOBALS['LANG']->getLL('exportdata_problemsSavingFile'), sprintf($GLOBALS['LANG']->getLL('exportdata_badPathS', 1), $fullName), 0, 1, 2);
290 }
291 }
292 }
293 // OUTPUT to BROWSER:
294 // Now, if we didn't make download file, show configuration form based on export:
295 $menuItems = array();
296 // Export configuration
297 $row = array();
298 $this->makeConfigurationForm($inData, $row);
299 $menuItems[] = array(
300 'label' => $GLOBALS['LANG']->getLL('tableselec_configuration'),
301 'content' => '
302 <table border="0" cellpadding="1" cellspacing="1">
303 ' . implode('
304 ', $row) . '
305 </table>
306 '
307 );
308 // File options
309 $row = array();
310 $this->makeSaveForm($inData, $row);
311 $menuItems[] = array(
312 'label' => $GLOBALS['LANG']->getLL('exportdata_filePreset'),
313 'content' => '
314 <table border="0" cellpadding="1" cellspacing="1">
315 ' . implode('
316 ', $row) . '
317 </table>
318 '
319 );
320 // File options
321 $row = array();
322 $this->makeAdvancedOptionsForm($inData, $row);
323 $menuItems[] = array(
324 'label' => $GLOBALS['LANG']->getLL('exportdata_advancedOptions'),
325 'content' => '
326 <table border="0" cellpadding="1" cellspacing="1">
327 ' . implode('
328 ', $row) . '
329 </table>
330 '
331 );
332 // Generate overview:
333 $overViewContent = $this->export->displayContentOverview();
334 // Print errors that might be:
335 $errors = $this->export->printErrorLog();
336 $menuItems[] = array(
337 'label' => $GLOBALS['LANG']->getLL('exportdata_messages'),
338 'content' => $errors,
339 'stateIcon' => $errors ? 2 : 0
340 );
341 // Add hidden fields and create tabs:
342 $content = $this->doc->getDynTabMenu($menuItems, 'tx_impexp_export', -1);
343 $content .= '<input type="hidden" name="tx_impexp[action]" value="export" />';
344 $this->content .= $this->doc->section('', $content, 0, 1);
345 // Output Overview:
346 $this->content .= $this->doc->section($GLOBALS['LANG']->getLL('execlistqu_structureToBeExported'), $overViewContent, 0, 1);
347 }
348
349 /**
350 * Adds records to the export object for a specific page id.
351 *
352 * @param integer $k Page id for which to select records to add
353 * @param array $tables Array of table names to select from
354 * @param integer $maxNumber Max amount of records to select
355 * @return void
356 * @todo Define visibility
357 */
358 public function addRecordsForPid($k, $tables, $maxNumber) {
359 if (is_array($tables)) {
360 foreach ($GLOBALS['TCA'] as $table => $value) {
361 if ($table != 'pages' && (in_array($table, $tables) || in_array('_ALL', $tables))) {
362 if ($GLOBALS['BE_USER']->check('tables_select', $table) && !$GLOBALS['TCA'][$table]['ctrl']['is_static']) {
363 $res = $this->exec_listQueryPid($table, $k, \TYPO3\CMS\Core\Utility\MathUtility::forceIntegerInRange($maxNumber, 1));
364 while ($subTrow = $GLOBALS['TYPO3_DB']->sql_fetch_assoc($res)) {
365 $this->export->export_addRecord($table, $subTrow);
366 }
367 }
368 }
369 }
370 }
371 }
372
373 /**
374 * Selects records from table / pid
375 *
376 * @param string $table Table to select from
377 * @param integer $pid Page ID to select from
378 * @param integer $limit Max number of records to select
379 * @return pointer SQL resource pointer
380 * @todo Define visibility
381 */
382 public function exec_listQueryPid($table, $pid, $limit) {
383 $orderBy = $GLOBALS['TCA'][$table]['ctrl']['sortby'] ? 'ORDER BY ' . $GLOBALS['TCA'][$table]['ctrl']['sortby'] : $GLOBALS['TCA'][$table]['ctrl']['default_sortby'];
384 $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);
385 // Warning about hitting limit:
386 if ($GLOBALS['TYPO3_DB']->sql_num_rows($res) == $limit) {
387 $this->content .= $this->doc->section($GLOBALS['LANG']->getLL('execlistqu_maxNumberLimit'), sprintf($GLOBALS['LANG']->getLL('makeconfig_anSqlQueryReturned', 1), $limit), 0, 1, 2);
388 }
389 return $res;
390 }
391
392 /**
393 * Create configuration form
394 *
395 * @param array $inData Form configurat data
396 * @param array Table row accumulation variable. This is filled with table rows.
397 * @return void Sets content in $this->content
398 * @todo Define visibility
399 */
400 public function makeConfigurationForm($inData, &$row) {
401 global $LANG;
402 $nameSuggestion = '';
403 // Page tree export options:
404 if (isset($inData['pagetree']['id'])) {
405 $nameSuggestion .= 'tree_PID' . $inData['pagetree']['id'] . '_L' . $inData['pagetree']['levels'];
406 $row[] = '
407 <tr class="tableheader bgColor5">
408 <td colspan="2">' . $LANG->getLL('makeconfig_exportPagetreeConfiguration', 1) . \TYPO3\CMS\Backend\Utility\BackendUtility::cshItem('xMOD_tx_impexp', 'pageTreeCfg', $GLOBALS['BACK_PATH'], '') . '</td>
409 </tr>';
410 $row[] = '
411 <tr class="bgColor4">
412 <td><strong>' . $LANG->getLL('makeconfig_pageId', 1) . '</strong></td>
413 <td>' . htmlspecialchars($inData['pagetree']['id']) . '<input type="hidden" value="' . htmlspecialchars($inData['pagetree']['id']) . '" name="tx_impexp[pagetree][id]" /></td>
414 </tr>';
415 $row[] = '
416 <tr class="bgColor4">
417 <td><strong>' . $LANG->getLL('makeconfig_tree', 1) . '</strong>' . \TYPO3\CMS\Backend\Utility\BackendUtility::cshItem('xMOD_tx_impexp', 'pageTreeDisplay', $GLOBALS['BACK_PATH'], '') . '</td>
418 <td>' . ($this->treeHTML ? $this->treeHTML : $LANG->getLL('makeconfig_noTreeExportedOnly', 1)) . '</td>
419 </tr>';
420 $opt = array(
421 '-2' => $LANG->getLL('makeconfig_tablesOnThisPage'),
422 '-1' => $LANG->getLL('makeconfig_expandedTree'),
423 '0' => $LANG->getLL('makeconfig_onlyThisPage'),
424 '1' => $LANG->getLL('makeconfig_1Level'),
425 '2' => $LANG->getLL('makeconfig_2Levels'),
426 '3' => $LANG->getLL('makeconfig_3Levels'),
427 '4' => $LANG->getLL('makeconfig_4Levels'),
428 '999' => $LANG->getLL('makeconfig_infinite')
429 );
430 $row[] = '
431 <tr class="bgColor4">
432 <td><strong>' . $LANG->getLL('makeconfig_levels', 1) . '</strong>' . \TYPO3\CMS\Backend\Utility\BackendUtility::cshItem('xMOD_tx_impexp', 'pageTreeMode', $GLOBALS['BACK_PATH'], '') . '</td>
433 <td>' . $this->renderSelectBox('tx_impexp[pagetree][levels]', $inData['pagetree']['levels'], $opt) . '</td>
434 </tr>';
435 $row[] = '
436 <tr class="bgColor4">
437 <td><strong>' . $LANG->getLL('makeconfig_includeTables', 1) . '</strong>' . \TYPO3\CMS\Backend\Utility\BackendUtility::cshItem('xMOD_tx_impexp', 'pageTreeRecordLimit', $GLOBALS['BACK_PATH'], '') . '</td>
438 <td>' . $this->tableSelector('tx_impexp[pagetree][tables]', $inData['pagetree']['tables'], 'pages') . '<br/>
439 ' . $LANG->getLL('makeconfig_maxNumberOfRecords', 1) . '<br/>
440 <input type="text" name="tx_impexp[pagetree][maxNumber]" value="' . htmlspecialchars($inData['pagetree']['maxNumber']) . '"' . $this->doc->formWidth(10) . ' /><br/>
441 </td>
442 </tr>';
443 }
444 // Single record export:
445 if (is_array($inData['record'])) {
446 $row[] = '
447 <tr class="tableheader bgColor5">
448 <td colspan="2">' . $LANG->getLL('makeconfig_exportSingleRecord', 1) . \TYPO3\CMS\Backend\Utility\BackendUtility::cshItem('xMOD_tx_impexp', 'singleRecord', $GLOBALS['BACK_PATH'], '') . '</td>
449 </tr>';
450 foreach ($inData['record'] as $ref) {
451 $rParts = explode(':', $ref);
452 $tName = $rParts[0];
453 $rUid = $rParts[1];
454 $nameSuggestion .= $tName . '_' . $rUid;
455 $rec = \TYPO3\CMS\Backend\Utility\BackendUtility::getRecordWSOL($tName, $rUid);
456 $row[] = '
457 <tr class="bgColor4">
458 <td><strong>' . $LANG->getLL('makeconfig_record', 1) . '</strong></td>
459 <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>
460 </tr>';
461 }
462 }
463 // Single tables/pids:
464 if (is_array($inData['list'])) {
465 $row[] = '
466 <tr class="tableheader bgColor5">
467 <td colspan="2">' . $LANG->getLL('makeconfig_exportTablesFromPages', 1) . '</td>
468 </tr>';
469 // Display information about pages from which the export takes place
470 $tblList = '';
471 foreach ($inData['list'] as $reference) {
472 $referenceParts = explode(':', $reference);
473 $tableName = $referenceParts[0];
474 if ($GLOBALS['BE_USER']->check('tables_select', $tableName)) {
475 // If the page is actually the root, handle it differently
476 // NOTE: we don't compare integers, because the number actually comes from the split string above
477 if ($referenceParts[1] === '0') {
478 $iconAndTitle = \TYPO3\CMS\Backend\Utility\IconUtility::getSpriteIcon('apps-pagetree-root') . $GLOBALS['TYPO3_CONF_VARS']['SYS']['sitename'];
479 } else {
480 $record = \TYPO3\CMS\Backend\Utility\BackendUtility::getRecordWSOL('pages', $referenceParts[1]);
481 $iconAndTitle = \t3lib_iconworks::getSpriteIconForRecord('pages', $record) . \TYPO3\CMS\Backend\Utility\BackendUtility::getRecordTitle('pages', $record, TRUE);
482 }
483 $tblList .= 'Table "' . $tableName . '" from ' . $iconAndTitle . '<input type="hidden" name="tx_impexp[list][]" value="' . htmlspecialchars($reference) . '" /><br/>';
484 }
485 }
486 $row[] = '
487 <tr class="bgColor4">
488 <td><strong>' . $LANG->getLL('makeconfig_tablePids', 1) . '</strong>' . \TYPO3\CMS\Backend\Utility\BackendUtility::cshItem('xMOD_tx_impexp', 'tableList', $GLOBALS['BACK_PATH'], '') . '</td>
489 <td>' . $tblList . '</td>
490 </tr>';
491 $row[] = '
492 <tr class="bgColor4">
493 <td><strong>' . $LANG->getLL('makeconfig_maxNumberOfRecords', 1) . \TYPO3\CMS\Backend\Utility\BackendUtility::cshItem('xMOD_tx_impexp', 'tableListMaxNumber', $GLOBALS['BACK_PATH'], '') . '</strong></td>
494 <td>
495 <input type="text" name="tx_impexp[listCfg][maxNumber]" value="' . htmlspecialchars($inData['listCfg']['maxNumber']) . '"' . $this->doc->formWidth(10) . ' /><br/>
496 </td>
497 </tr>';
498 }
499 $row[] = '
500 <tr class="tableheader bgColor5">
501 <td colspan="2">' . $LANG->getLL('makeconfig_relationsAndExclusions', 1) . '</td>
502 </tr>';
503 // Add relation selector:
504 $row[] = '
505 <tr class="bgColor4">
506 <td><strong>' . $LANG->getLL('makeconfig_includeRelationsToTables', 1) . '</strong>' . \TYPO3\CMS\Backend\Utility\BackendUtility::cshItem('xMOD_tx_impexp', 'inclRelations', $GLOBALS['BACK_PATH'], '') . '</td>
507 <td>' . $this->tableSelector('tx_impexp[external_ref][tables]', $inData['external_ref']['tables']) . '</td>
508 </tr>';
509 // Add static relation selector:
510 $row[] = '
511 <tr class="bgColor4">
512 <td><strong>' . $LANG->getLL('makeconfig_useStaticRelationsFor', 1) . '</strong>' . \TYPO3\CMS\Backend\Utility\BackendUtility::cshItem('xMOD_tx_impexp', 'staticRelations', $GLOBALS['BACK_PATH'], '') . '</td>
513 <td>' . $this->tableSelector('tx_impexp[external_static][tables]', $inData['external_static']['tables']) . '<br/>
514 <label for="checkShowStaticRelations">' . $LANG->getLL('makeconfig_showStaticRelations', 1) . '</label> <input type="checkbox" name="tx_impexp[showStaticRelations]" id="checkShowStaticRelations" value="1"' . ($inData['showStaticRelations'] ? ' checked="checked"' : '') . ' />
515 </td>
516 </tr>';
517 // Exclude:
518 $excludeHiddenFields = '';
519 if (is_array($inData['exclude'])) {
520 foreach ($inData['exclude'] as $key => $value) {
521 $excludeHiddenFields .= '<input type="hidden" name="tx_impexp[exclude][' . $key . ']" value="1" />';
522 }
523 }
524 $row[] = '
525 <tr class="bgColor4">
526 <td><strong>' . $LANG->getLL('makeconfig_excludeElements', 1) . '</strong>' . \TYPO3\CMS\Backend\Utility\BackendUtility::cshItem('xMOD_tx_impexp', 'excludedElements', $GLOBALS['BACK_PATH'], '') . '</td>
527 <td>' . $excludeHiddenFields . '
528 ' . (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)) . '
529 </td>
530 </tr>';
531 // Add buttons:
532 $row[] = '
533 <tr class="bgColor4">
534 <td>&nbsp;</td>
535 <td>
536 <input type="submit" value="' . $LANG->getLL('makeadvanc_update', 1) . '" />
537 <input type="hidden" name="tx_impexp[download_export_name]" value="' . substr($nameSuggestion, 0, 30) . '" />
538 </td>
539 </tr>';
540 }
541
542 /**
543 * Create advanced options form
544 *
545 * @param array $inData Form configurat data
546 * @param array $row Table row accumulation variable. This is filled with table rows.
547 * @return void Sets content in $this->content
548 * @todo Define visibility
549 */
550 public function makeAdvancedOptionsForm($inData, &$row) {
551 global $LANG;
552 // Soft references
553 $row[] = '
554 <tr class="tableheader bgColor5">
555 <td colspan="2">' . $LANG->getLL('makeadvanc_softReferences', 1) . '</td>
556 </tr>';
557 $row[] = '
558 <tr class="bgColor4">
559 <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>
560 <td><input type="checkbox" name="tx_impexp[excludeHTMLfileResources]" id="checkExcludeHTMLfileResources" value="1"' . ($inData['excludeHTMLfileResources'] ? ' checked="checked"' : '') . ' /></td>
561 </tr>';
562 // Extensions
563 $row[] = '
564 <tr class="tableheader bgColor5">
565 <td colspan="2">' . $LANG->getLL('makeadvanc_extensionDependencies', 1) . '</td>
566 </tr>';
567 $row[] = '
568 <tr class="bgColor4">
569 <td><strong>' . $LANG->getLL('makeadvanc_selectExtensionsThatThe', 1) . '</strong>' . \TYPO3\CMS\Backend\Utility\BackendUtility::cshItem('xMOD_tx_impexp', 'extensionDependencies', $GLOBALS['BACK_PATH'], '') . '</td>
570 <td>' . $this->extensionSelector('tx_impexp[extension_dep]', $inData['extension_dep']) . '</td>
571 </tr>';
572 // Add buttons:
573 $row[] = '
574 <tr class="bgColor4">
575 <td>&nbsp;</td>
576 <td>
577 <input type="submit" value="' . $LANG->getLL('makesavefo_update', 1) . '" />
578 <input type="hidden" name="tx_impexp[download_export_name]" value="' . substr($nameSuggestion, 0, 30) . '" />
579 </td>
580 </tr>';
581 }
582
583 /**
584 * Create configuration form
585 *
586 * @param array $inData Form configurat data
587 * @param array $row Table row accumulation variable. This is filled with table rows.
588 * @return void Sets content in $this->content
589 * @todo Define visibility
590 */
591 public function makeSaveForm($inData, &$row) {
592 global $LANG;
593 // Presets:
594 $row[] = '
595 <tr class="tableheader bgColor5">
596 <td colspan="2">' . $LANG->getLL('makesavefo_presets', 1) . '</td>
597 </tr>';
598 $opt = array('');
599 $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)' : ''));
600 if (is_array($presets)) {
601 foreach ($presets as $presetCfg) {
602 $opt[$presetCfg['uid']] = $presetCfg['title'] . ' [' . $presetCfg['uid'] . ']' . ($presetCfg['public'] ? ' [Public]' : '') . ($presetCfg['user_uid'] === $GLOBALS['BE_USER']->user['uid'] ? ' [Own]' : '');
603 }
604 }
605 $row[] = '
606 <tr class="bgColor4">
607 <td><strong>' . $LANG->getLL('makesavefo_presets', 1) . '</strong>' . \TYPO3\CMS\Backend\Utility\BackendUtility::cshItem('xMOD_tx_impexp', 'presets', $GLOBALS['BACK_PATH'], '') . '</td>
608 <td>
609 ' . $LANG->getLL('makesavefo_selectPreset', 1) . '<br/>
610 ' . $this->renderSelectBox('preset[select]', '', $opt) . '
611 <br/>
612 <input type="submit" value="' . $LANG->getLL('makesavefo_load', 1) . '" name="preset[load]" />
613 <input type="submit" value="' . $LANG->getLL('makesavefo_save', 1) . '" name="preset[save]" onclick="return confirm(\'' . $LANG->getLL('makesavefo_areYouSure', 1) . '\');" />
614 <input type="submit" value="' . $LANG->getLL('makesavefo_delete', 1) . '" name="preset[delete]" onclick="return confirm(\'' . $LANG->getLL('makesavefo_areYouSure', 1) . '\');" />
615 <input type="submit" value="' . $LANG->getLL('makesavefo_merge', 1) . '" name="preset[merge]" onclick="return confirm(\'' . $LANG->getLL('makesavefo_areYouSure', 1) . '\');" />
616 <br/>
617 ' . $LANG->getLL('makesavefo_titleOfNewPreset', 1) . '
618 <input type="text" name="tx_impexp[preset][title]" value="' . htmlspecialchars($inData['preset']['title']) . '"' . $this->doc->formWidth(30) . ' /><br/>
619 <label for="checkPresetPublic">' . $LANG->getLL('makesavefo_public', 1) . '</label>
620 <input type="checkbox" name="tx_impexp[preset][public]" id="checkPresetPublic" value="1"' . ($inData['preset']['public'] ? ' checked="checked"' : '') . ' /><br/>
621 </td>
622 </tr>';
623 // Output options:
624 $row[] = '
625 <tr class="tableheader bgColor5">
626 <td colspan="2">' . $LANG->getLL('makesavefo_outputOptions', 1) . '</td>
627 </tr>';
628 // Meta data:
629 $tempDir = $this->userTempFolder();
630 if ($tempDir) {
631 $thumbnails = \TYPO3\CMS\Core\Utility\GeneralUtility::getFilesInDir($tempDir, 'png,gif,jpg');
632 array_unshift($thumbnails, '');
633 } else {
634 $thumbnails = FALSE;
635 }
636 $row[] = '
637 <tr class="bgColor4">
638 <td><strong>' . $LANG->getLL('makesavefo_metaData', 1) . '</strong>' . \TYPO3\CMS\Backend\Utility\BackendUtility::cshItem('xMOD_tx_impexp', 'metadata', $GLOBALS['BACK_PATH'], '') . '</td>
639 <td>
640 ' . $LANG->getLL('makesavefo_title', 1) . ' <br/>
641 <input type="text" name="tx_impexp[meta][title]" value="' . htmlspecialchars($inData['meta']['title']) . '"' . $this->doc->formWidth(30) . ' /><br/>
642 ' . $LANG->getLL('makesavefo_description', 1) . ' <br/>
643 <input type="text" name="tx_impexp[meta][description]" value="' . htmlspecialchars($inData['meta']['description']) . '"' . $this->doc->formWidth(30) . ' /><br/>
644 ' . $LANG->getLL('makesavefo_notes', 1) . ' <br/>
645 <textarea name="tx_impexp[meta][notes]"' . $this->doc->formWidth(30, 1) . '>' . \TYPO3\CMS\Core\Utility\GeneralUtility::formatForTextarea($inData['meta']['notes']) . '</textarea><br/>
646 ' . (is_array($thumbnails) ? '
647 ' . $LANG->getLL('makesavefo_thumbnail', 1) . '<br/>
648 ' . $this->renderSelectBox('tx_impexp[meta][thumbnail]', $inData['meta']['thumbnail'], $thumbnails) . '<br/>
649 ' . ($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/>' : '') . '
650 ' . $LANG->getLL('makesavefo_uploadThumbnail', 1) . '<br/>
651 <input type="file" name="upload_1" ' . $this->doc->formWidth(30) . ' size="30" /><br/>
652 <input type="hidden" name="file[upload][1][target]" value="' . htmlspecialchars($tempDir) . '" />
653 <input type="hidden" name="file[upload][1][data]" value="1" /><br />
654 ' : '') . '
655 </td>
656 </tr>';
657 // Add file options:
658 $savePath = $this->userSaveFolder();
659 $opt = array();
660 if ($this->export->compress) {
661 $opt['t3d_compressed'] = $LANG->getLL('makesavefo_t3dFileCompressed');
662 }
663 $opt['t3d'] = $LANG->getLL('makesavefo_t3dFile');
664 $opt['xml'] = $LANG->getLL('makesavefo_xml');
665 $row[] = '
666 <tr class="bgColor4">
667 <td><strong>' . $LANG->getLL('makesavefo_fileFormat', 1) . '</strong>' . \TYPO3\CMS\Backend\Utility\BackendUtility::cshItem('xMOD_tx_impexp', 'fileFormat', $GLOBALS['BACK_PATH'], '') . '</td>
668 <td>' . $this->renderSelectBox('tx_impexp[filetype]', $inData['filetype'], $opt) . '<br/>
669 ' . $LANG->getLL('makesavefo_maxSizeOfFiles', 1) . '<br/>
670 <input type="text" name="tx_impexp[maxFileSize]" value="' . htmlspecialchars($inData['maxFileSize']) . '"' . $this->doc->formWidth(10) . ' /><br/>
671 ' . ($savePath ? sprintf($LANG->getLL('makesavefo_filenameSavedInS', 1), substr($savePath, strlen(PATH_site))) . '<br/>
672 <input type="text" name="tx_impexp[filename]" value="' . htmlspecialchars($inData['filename']) . '"' . $this->doc->formWidth(30) . ' /><br/>' : '') . '
673 </td>
674 </tr>';
675 // Add buttons:
676 $row[] = '
677 <tr class="bgColor4">
678 <td>&nbsp;</td>
679 <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>
680 </tr>';
681 }
682
683 /**************************
684 *
685 * IMPORT FUNCTIONS
686 *
687 **************************/
688 /**
689 * Import part of module
690 *
691 * @param array $inData Content of POST VAR tx_impexp[]..
692 * @return void Setting content in $this->content
693 * @todo Define visibility
694 */
695 public function importData($inData) {
696 global $LANG;
697 $access = is_array($this->pageinfo) ? 1 : 0;
698 if ($this->id && $access || $GLOBALS['BE_USER']->user['admin'] && !$this->id) {
699 if ($GLOBALS['BE_USER']->user['admin'] && !$this->id) {
700 $this->pageinfo = array('title' => '[root-level]', 'uid' => 0, 'pid' => 0);
701 }
702 if ($inData['new_import']) {
703 unset($inData['import_mode']);
704 }
705 /** @var $import \TYPO3\CMS\Impexp\ImportExport */
706 $import = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance('TYPO3\\CMS\\Impexp\\ImportExport');
707 $import->init(0, 'import');
708 $import->update = $inData['do_update'];
709 $import->import_mode = $inData['import_mode'];
710 $import->enableLogging = $inData['enableLogging'];
711 $import->global_ignore_pid = $inData['global_ignore_pid'];
712 $import->force_all_UIDS = $inData['force_all_UIDS'];
713 $import->showDiff = !$inData['notShowDiff'];
714 $import->allowPHPScripts = $inData['allowPHPScripts'];
715 $import->softrefInputValues = $inData['softrefInputValues'];
716 // OUTPUT creation:
717 $menuItems = array();
718 // Make input selector:
719 // must have trailing slash.
720 $path = $GLOBALS['TYPO3_CONF_VARS']['BE']['fileadminDir'];
721 $filesInDir = \TYPO3\CMS\Core\Utility\GeneralUtility::getFilesInDir(PATH_site . $path, 't3d,xml', 1, 1);
722 $userPath = $this->userSaveFolder();
723 //Files from User-Dir
724 $filesInUserDir = \TYPO3\CMS\Core\Utility\GeneralUtility::getFilesInDir($userPath, 't3d,xml', 1, 1);
725 $filesInDir = array_merge($filesInUserDir, $filesInDir);
726 if (is_dir(PATH_site . $path . 'export/')) {
727 $filesInDir = array_merge($filesInDir, \TYPO3\CMS\Core\Utility\GeneralUtility::getFilesInDir(PATH_site . $path . 'export/', 't3d,xml', 1, 1));
728 }
729 $tempFolder = $this->userTempFolder();
730 if ($tempFolder) {
731 $temp_filesInDir = \TYPO3\CMS\Core\Utility\GeneralUtility::getFilesInDir($tempFolder, 't3d,xml', 1, 1);
732 $filesInDir = array_merge($filesInDir, $temp_filesInDir);
733 }
734 // Configuration
735 $row = array();
736 $opt = array('');
737 foreach ($filesInDir as $file) {
738 $opt[$file] = substr($file, strlen(PATH_site));
739 }
740 $row[] = '<tr class="bgColor5">
741 <td colspan="2"><strong>' . $LANG->getLL('importdata_selectFileToImport', 1) . '</strong></td>
742 </tr>';
743 $row[] = '<tr class="bgColor4">
744 <td><strong>' . $LANG->getLL('importdata_file', 1) . '</strong>' . \TYPO3\CMS\Backend\Utility\BackendUtility::cshItem('xMOD_tx_impexp', 'importFile', $GLOBALS['BACK_PATH'], '') . '</td>
745 <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>
746 </tr>';
747 $row[] = '<tr class="bgColor5">
748 <td colspan="2"><strong>' . $LANG->getLL('importdata_importOptions', 1) . '</strong></td>
749 </tr>';
750 $row[] = '<tr class="bgColor4">
751 <td><strong>' . $LANG->getLL('importdata_update', 1) . '</strong>' . \TYPO3\CMS\Backend\Utility\BackendUtility::cshItem('xMOD_tx_impexp', 'update', $GLOBALS['BACK_PATH'], '') . '</td>
752 <td>
753 <input type="checkbox" name="tx_impexp[do_update]" id="checkDo_update" value="1"' . ($inData['do_update'] ? ' checked="checked"' : '') . ' />
754 <label for="checkDo_update">' . $LANG->getLL('importdata_updateRecords', 1) . '</label><br/>
755 <em>(' . $LANG->getLL('importdata_thisOptionRequiresThat', 1) . ')</em>' . ($inData['do_update'] ? ' <hr/>
756 <input type="checkbox" name="tx_impexp[global_ignore_pid]" id="checkGlobal_ignore_pid" value="1"' . ($inData['global_ignore_pid'] ? ' checked="checked"' : '') . ' />
757 <label for="checkGlobal_ignore_pid">' . $LANG->getLL('importdata_ignorePidDifferencesGlobally', 1) . '</label><br/>
758 <em>(' . $LANG->getLL('importdata_ifYouSetThis', 1) . ')</em>
759 ' : '') . '</td>
760 </tr>';
761 $row[] = '<tr class="bgColor4">
762 <td><strong>' . $LANG->getLL('importdata_options', 1) . '</strong>' . \TYPO3\CMS\Backend\Utility\BackendUtility::cshItem('xMOD_tx_impexp', 'options', $GLOBALS['BACK_PATH'], '') . '</td>
763 <td>
764 <input type="checkbox" name="tx_impexp[notShowDiff]" id="checkNotShowDiff" value="1"' . ($inData['notShowDiff'] ? ' checked="checked"' : '') . ' />
765 <label for="checkNotShowDiff">' . $LANG->getLL('importdata_doNotShowDifferences', 1) . '</label><br/>
766 <em>(' . $LANG->getLL('importdata_greenValuesAreFrom', 1) . ')</em>
767 <br/><br/>
768
769 ' . ($GLOBALS['BE_USER']->isAdmin() ? '
770 <input type="checkbox" name="tx_impexp[allowPHPScripts]" id="checkAllowPHPScripts" value="1"' . ($inData['allowPHPScripts'] ? ' checked="checked"' : '') . ' />
771 <label for="checkAllowPHPScripts">' . $LANG->getLL('importdata_allowToWriteBanned', 1) . '</label><br/>' : '') . (!$inData['do_update'] && $GLOBALS['BE_USER']->isAdmin() ? '
772 <br/>
773 <input type="checkbox" name="tx_impexp[force_all_UIDS]" id="checkForce_all_UIDS" value="1"' . ($inData['force_all_UIDS'] ? ' checked="checked"' : '') . ' />
774 <label for="checkForce_all_UIDS"><span class="typo3-red">' . $LANG->getLL('importdata_force_all_UIDS', 1) . '</span></label><br/>
775 <em>(' . $LANG->getLL('importdata_force_all_UIDS_descr', 1) . ')</em>' : '') . '
776 </td>
777 </tr>';
778 $row[] = '<tr class="bgColor4">
779 <td><strong>' . $LANG->getLL('importdata_action', 1) . '</strong>' . \TYPO3\CMS\Backend\Utility\BackendUtility::cshItem('xMOD_tx_impexp', 'action', $GLOBALS['BACK_PATH'], '') . '</td>
780 <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) . '" />') . '
781 <input type="hidden" name="tx_impexp[action]" value="import" /></td>
782 </tr>';
783 $row[] = '<tr class="bgColor4">
784 <td><strong>' . $LANG->getLL('importdata_enableLogging', 1) . '</strong>' . \TYPO3\CMS\Backend\Utility\BackendUtility::cshItem('xMOD_tx_impexp', 'enableLogging', $GLOBALS['BACK_PATH'], '') . '</td>
785 <td>
786 <input type="checkbox" name="tx_impexp[enableLogging]" id="checkEnableLogging" value="1"' . ($inData['enableLogging'] ? ' checked="checked"' : '') . ' />
787 <label for="checkEnableLogging">' . $LANG->getLL('importdata_writeIndividualDbActions', 1) . '</label><br/>
788 <em>(' . $LANG->getLL('importdata_thisIsDisabledBy', 1) . ')</em>
789 </td>
790 </tr>';
791 $menuItems[] = array(
792 'label' => $LANG->getLL('importdata_import', 1),
793 'content' => '
794 <table border="0" cellpadding="1" cellspacing="1">
795 ' . implode('
796 ', $row) . '
797 </table>
798 '
799 );
800 // Upload file:
801 $tempFolder = $this->userTempFolder();
802 if ($tempFolder) {
803 $row = array();
804 $row[] = '<tr class="bgColor5">
805 <td colspan="2"><strong>' . $LANG->getLL('importdata_uploadFileFromLocal', 1) . '</strong></td>
806 </tr>';
807 $row[] = '<tr class="bgColor4">
808 <td>' . $LANG->getLL('importdata_browse', 1) . \TYPO3\CMS\Backend\Utility\BackendUtility::cshItem('xMOD_tx_impexp', 'upload', $GLOBALS['BACK_PATH'], '') . '</td>
809 <td>
810
811 <input type="file" name="upload_1"' . $this->doc->formWidth(35) . ' size="40" />
812 <input type="hidden" name="file[upload][1][target]" value="' . htmlspecialchars($tempFolder) . '" />
813 <input type="hidden" name="file[upload][1][data]" value="1" /><br />
814
815 <input type="submit" name="_upload" value="' . $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.php:file_upload.php.submit', 1) . '" />
816 <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>
817 </td>
818 </tr>';
819 if (\TYPO3\CMS\Core\Utility\GeneralUtility::_POST('_upload')) {
820 $row[] = '<tr class="bgColor4">
821 <td>' . $LANG->getLL('importdata_uploadStatus', 1) . '</td>
822 <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>
823 </tr>';
824 }
825 $menuItems[] = array(
826 'label' => $LANG->getLL('importdata_upload'),
827 'content' => '
828 <table border="0" cellpadding="1" cellspacing="1">
829 ' . implode('
830 ', $row) . '
831 </table>
832 '
833 );
834 }
835 // Perform import or preview depending:
836 $overviewContent = '';
837 $extensionInstallationMessage = '';
838 $emURL = '';
839 $inFile = \TYPO3\CMS\Core\Utility\GeneralUtility::getFileAbsFileName($inData['file']);
840 if ($inFile && @is_file($inFile)) {
841 $trow = array();
842 if ($import->loadFile($inFile, 1)) {
843 // Check extension dependencies:
844 $extKeysToInstall = array();
845 if (is_array($import->dat['header']['extensionDependencies'])) {
846 foreach ($import->dat['header']['extensionDependencies'] as $extKey) {
847 if (!\TYPO3\CMS\Core\Utility\ExtensionManagementUtility::isLoaded($extKey)) {
848 $extKeysToInstall[] = $extKey;
849 }
850 }
851 }
852 if (count($extKeysToInstall)) {
853 $passParams = \TYPO3\CMS\Core\Utility\GeneralUtility::_POST('tx_impexp');
854 unset($passParams['import_mode']);
855 unset($passParams['import_file']);
856 $thisScriptUrl = \TYPO3\CMS\Core\Utility\GeneralUtility::getIndpEnv('REQUEST_URI') . '?M=xMOD_tximpexp&id=' . $this->id . \TYPO3\CMS\Core\Utility\GeneralUtility::implodeArrayForUrl('tx_impexp', $passParams);
857 $emURL = $this->doc->backPath . \TYPO3\CMS\Core\Utility\ExtensionManagementUtility::extRelPath('em') . 'classes/index.php?CMD[requestInstallExtensions]=' . implode(',', $extKeysToInstall) . '&returnUrl=' . rawurlencode($thisScriptUrl);
858 $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.';
859 }
860 if ($inData['import_file']) {
861 if (!count($extKeysToInstall)) {
862 $import->importData($this->id);
863 \TYPO3\CMS\Backend\Utility\BackendUtility::setUpdateSignal('updatePageTree');
864 } else {
865 \TYPO3\CMS\Core\Utility\HttpUtility::redirect($emURL);
866 }
867 }
868 $import->display_import_pid_record = $this->pageinfo;
869 $overviewContent = $import->displayContentOverview();
870 }
871 // Meta data output:
872 $trow[] = '<tr class="bgColor5">
873 <td colspan="2"><strong>' . $LANG->getLL('importdata_metaData', 1) . '</strong></td>
874 </tr>';
875 $opt = array('');
876 foreach ($filesInDir as $file) {
877 $opt[$file] = substr($file, strlen(PATH_site));
878 }
879 $trow[] = '<tr class="bgColor4">
880 <td><strong>' . $LANG->getLL('importdata_title', 1) . '</strong></td>
881 <td width="95%">' . nl2br(htmlspecialchars($import->dat['header']['meta']['title'])) . '</td>
882 </tr>';
883 $trow[] = '<tr class="bgColor4">
884 <td><strong>' . $LANG->getLL('importdata_description', 1) . '</strong></td>
885 <td width="95%">' . nl2br(htmlspecialchars($import->dat['header']['meta']['description'])) . '</td>
886 </tr>';
887 $trow[] = '<tr class="bgColor4">
888 <td><strong>' . $LANG->getLL('importdata_notes', 1) . '</strong></td>
889 <td width="95%">' . nl2br(htmlspecialchars($import->dat['header']['meta']['notes'])) . '</td>
890 </tr>';
891 $trow[] = '<tr class="bgColor4">
892 <td><strong>' . $LANG->getLL('importdata_packager', 1) . '</strong></td>
893 <td width="95%">' . nl2br(htmlspecialchars(($import->dat['header']['meta']['packager_name'] . ' (' . $import->dat['header']['meta']['packager_username'] . ')'))) . '<br/>
894 ' . $LANG->getLL('importdata_email', 1) . ' ' . $import->dat['header']['meta']['packager_email'] . '</td>
895 </tr>';
896 // Thumbnail icon:
897 if (is_array($import->dat['header']['thumbnail'])) {
898 $pI = pathinfo($import->dat['header']['thumbnail']['filename']);
899 if (\TYPO3\CMS\Core\Utility\GeneralUtility::inList('gif,jpg,png,jpeg', strtolower($pI['extension']))) {
900 // Construct filename and write it:
901 $fileName = PATH_site . 'typo3temp/importthumb.' . $pI['extension'];
902 \TYPO3\CMS\Core\Utility\GeneralUtility::writeFile($fileName, $import->dat['header']['thumbnail']['content']);
903 // Check that the image really is an image and not a malicious PHP script...
904 if (getimagesize($fileName)) {
905 // Create icon tag:
906 $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="" />';
907 $trow[] = '<tr class="bgColor4">
908 <td><strong>' . $LANG->getLL('importdata_icon', 1) . '</strong></td>
909 <td>' . $iconTag . '</td>
910 </tr>';
911 } else {
912 \TYPO3\CMS\Core\Utility\GeneralUtility::unlink_tempfile($fileName);
913 }
914 }
915 }
916 $menuItems[] = array(
917 'label' => $LANG->getLL('importdata_metaData_1387'),
918 'content' => '
919 <table border="0" cellpadding="1" cellspacing="1">
920 ' . implode('
921 ', $trow) . '
922 </table>
923 '
924 );
925 }
926 // Print errors that might be:
927 $errors = $import->printErrorLog();
928 $menuItems[] = array(
929 'label' => $LANG->getLL('importdata_messages'),
930 'content' => $errors,
931 'stateIcon' => $errors ? 2 : 0
932 );
933 // Output tabs:
934 $content = $this->doc->getDynTabMenu($menuItems, 'tx_impexp_import', -1);
935 if ($extensionInstallationMessage) {
936 $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;
937 }
938 $this->content .= $this->doc->section('', $content, 0, 1);
939 // Print overview:
940 if ($overviewContent) {
941 $this->content .= $this->doc->section($inData['import_file'] ? $LANG->getLL('importdata_structureHasBeenImported', 1) : $LANG->getLL('filterpage_structureToBeImported', 1), $overviewContent, 0, 1);
942 }
943 }
944 }
945
946 /****************************
947 *
948 * Preset functions
949 *
950 ****************************/
951 /**
952 * Manipulate presets
953 *
954 * @param array $inData In data array, passed by reference!
955 * @return void
956 * @todo Define visibility
957 */
958 public function processPresets(&$inData) {
959 $presetData = \TYPO3\CMS\Core\Utility\GeneralUtility::_GP('preset');
960 $err = FALSE;
961 // Save preset
962 if (isset($presetData['save'])) {
963 $preset = $this->getPreset($presetData['select']);
964 // Update existing
965 if (is_array($preset)) {
966 if ($GLOBALS['BE_USER']->isAdmin() || $preset['user_uid'] === $GLOBALS['BE_USER']->user['uid']) {
967 $fields_values = array(
968 'public' => $inData['preset']['public'],
969 'title' => $inData['preset']['title'],
970 'item_uid' => $inData['pagetree']['id'],
971 'preset_data' => serialize($inData)
972 );
973 $GLOBALS['TYPO3_DB']->exec_UPDATEquery('tx_impexp_presets', 'uid=' . intval($preset['uid']), $fields_values);
974 $msg = 'Preset #' . $preset['uid'] . ' saved!';
975 } else {
976 $msg = 'ERROR: The preset was not saved because you were not the owner of it!';
977 $err = TRUE;
978 }
979 } else {
980 // Insert new:
981 $fields_values = array(
982 'user_uid' => $GLOBALS['BE_USER']->user['uid'],
983 'public' => $inData['preset']['public'],
984 'title' => $inData['preset']['title'],
985 'item_uid' => $inData['pagetree']['id'],
986 'preset_data' => serialize($inData)
987 );
988 $GLOBALS['TYPO3_DB']->exec_INSERTquery('tx_impexp_presets', $fields_values);
989 $msg = 'New preset "' . htmlspecialchars($inData['preset']['title']) . '" is created';
990 }
991 }
992 // Delete preset:
993 if (isset($presetData['delete'])) {
994 $preset = $this->getPreset($presetData['select']);
995 if (is_array($preset)) {
996 // Update existing
997 if ($GLOBALS['BE_USER']->isAdmin() || $preset['user_uid'] === $GLOBALS['BE_USER']->user['uid']) {
998 $GLOBALS['TYPO3_DB']->exec_DELETEquery('tx_impexp_presets', 'uid=' . intval($preset['uid']));
999 $msg = 'Preset #' . $preset['uid'] . ' deleted!';
1000 } else {
1001 $msg = 'ERROR: You were not the owner of the preset so you could not delete it.';
1002 $err = TRUE;
1003 }
1004 } else {
1005 $msg = 'ERROR: No preset selected for deletion.';
1006 $err = TRUE;
1007 }
1008 }
1009 // Load preset
1010 if (isset($presetData['load']) || isset($presetData['merge'])) {
1011 $preset = $this->getPreset($presetData['select']);
1012 if (is_array($preset)) {
1013 // Update existing
1014 $inData_temp = unserialize($preset['preset_data']);
1015 if (is_array($inData_temp)) {
1016 if (isset($presetData['merge'])) {
1017 // Merge records in:
1018 if (is_array($inData_temp['record'])) {
1019 $inData['record'] = array_merge((array) $inData['record'], $inData_temp['record']);
1020 }
1021 // Merge lists in:
1022 if (is_array($inData_temp['list'])) {
1023 $inData['list'] = array_merge((array) $inData['list'], $inData_temp['list']);
1024 }
1025 } else {
1026 $msg = 'Preset #' . $preset['uid'] . ' loaded!';
1027 $inData = $inData_temp;
1028 }
1029 } else {
1030 $msg = 'ERROR: No configuratio data found in preset record!';
1031 $err = TRUE;
1032 }
1033 } else {
1034 $msg = 'ERROR: No preset selected for loading.';
1035 $err = TRUE;
1036 }
1037 }
1038 // Show message:
1039 if (strlen($msg)) {
1040 $this->content .= $this->doc->section('Presets', $msg, 0, 1, $err ? 3 : 1);
1041 }
1042 }
1043
1044 /**
1045 * Get single preset record
1046 *
1047 * @param integer $uid Preset record
1048 * @return array Preset record, if any (otherwise FALSE)
1049 * @todo Define visibility
1050 */
1051 public function getPreset($uid) {
1052 $preset = $GLOBALS['TYPO3_DB']->exec_SELECTgetSingleRow('*', 'tx_impexp_presets', 'uid=' . intval($uid));
1053 return $preset;
1054 }
1055
1056 /****************************
1057 *
1058 * Helper functions
1059 *
1060 ****************************/
1061 /**
1062 * Returns first temporary folder of the user account (from $FILEMOUNTS)
1063 *
1064 * @return string Absolute path to first "_temp_" folder of the current user, otherwise blank.
1065 * @todo Define visibility
1066 */
1067 public function userTempFolder() {
1068 global $FILEMOUNTS;
1069 foreach ($FILEMOUNTS as $filePathInfo) {
1070 $tempFolder = $filePathInfo['path'] . '_temp_/';
1071 if (@is_dir($tempFolder)) {
1072 return $tempFolder;
1073 }
1074 }
1075 }
1076
1077 /**
1078 * Returns folder where user can save export files.
1079 *
1080 * @return string Absolute path to folder where export files can be saved.
1081 * @todo Define visibility
1082 */
1083 public function userSaveFolder() {
1084 global $FILEMOUNTS;
1085 reset($FILEMOUNTS);
1086 $filePathInfo = current($FILEMOUNTS);
1087 if (is_array($filePathInfo)) {
1088 $tempFolder = $filePathInfo['path'] . '_temp_/';
1089 if (!@is_dir($tempFolder)) {
1090 $tempFolder = $filePathInfo['path'];
1091 if (!@is_dir($tempFolder)) {
1092 return FALSE;
1093 }
1094 }
1095 return $tempFolder;
1096 }
1097 }
1098
1099 /**
1100 * Check if a file has been uploaded
1101 *
1102 * @return void
1103 * @todo Define visibility
1104 */
1105 public function checkUpload() {
1106 $file = \TYPO3\CMS\Core\Utility\GeneralUtility::_GP('file');
1107 // Initializing:
1108 $this->fileProcessor = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance('TYPO3\\CMS\\Core\\Utility\\File\\ExtendedFileUtility');
1109 $this->fileProcessor->init($GLOBALS['FILEMOUNTS'], $GLOBALS['TYPO3_CONF_VARS']['BE']['fileExtensions']);
1110 $this->fileProcessor->init_actionPerms($GLOBALS['BE_USER']->getFileoperationPermissions());
1111 $this->fileProcessor->dontCheckForUnique = \TYPO3\CMS\Core\Utility\GeneralUtility::_GP('overwriteExistingFiles') ? 1 : 0;
1112 // Checking referer / executing:
1113 $refInfo = parse_url(\TYPO3\CMS\Core\Utility\GeneralUtility::getIndpEnv('HTTP_REFERER'));
1114 $httpHost = \TYPO3\CMS\Core\Utility\GeneralUtility::getIndpEnv('TYPO3_HOST_ONLY');
1115 if ($httpHost != $refInfo['host'] && $this->vC != $GLOBALS['BE_USER']->veriCode() && !$GLOBALS['$TYPO3_CONF_VARS']['SYS']['doNotCheckReferer']) {
1116 $this->fileProcessor->writeLog(0, 2, 1, 'Referer host "%s" and server host "%s" did not match!', array($refInfo['host'], $httpHost));
1117 } else {
1118 $this->fileProcessor->start($file);
1119 $this->fileProcessor->processData();
1120 }
1121 }
1122
1123 /**
1124 * Makes a selector-box from optValues
1125 *
1126 * @param string $prefix Form element name
1127 * @param string $value Current value
1128 * @param array $optValues Options to display (key/value pairs)
1129 * @return string HTML select element
1130 * @todo Define visibility
1131 */
1132 public function renderSelectBox($prefix, $value, $optValues) {
1133 $opt = array();
1134 $isSelFlag = 0;
1135 foreach ($optValues as $k => $v) {
1136 $sel = !strcmp($k, $value) ? ' selected="selected"' : '';
1137 if ($sel) {
1138 $isSelFlag++;
1139 }
1140 $opt[] = '<option value="' . htmlspecialchars($k) . '"' . $sel . '>' . htmlspecialchars($v) . '</option>';
1141 }
1142 if (!$isSelFlag && strcmp('', $value)) {
1143 $opt[] = '<option value="' . htmlspecialchars($value) . '" selected="selected">' . htmlspecialchars(('[\'' . $value . '\']')) . '</option>';
1144 }
1145 return '<select name="' . $prefix . '">' . implode('', $opt) . '</select>';
1146 }
1147
1148 /**
1149 * Returns a selector-box with TCA tables
1150 *
1151 * @param string $prefix Form element name prefix
1152 * @param array $value The current values selected
1153 * @param string $excludeList Table names (and the string "_ALL") to exclude. Comma list
1154 * @return string HTML select element
1155 * @todo Define visibility
1156 */
1157 public function tableSelector($prefix, $value, $excludeList = '') {
1158 $optValues = array();
1159 if (!\TYPO3\CMS\Core\Utility\GeneralUtility::inList($excludeList, '_ALL')) {
1160 $optValues['_ALL'] = '[' . $GLOBALS['LANG']->getLL('ALL_tables') . ']';
1161 }
1162 foreach ($GLOBALS['TCA'] as $table => $_) {
1163 if ($GLOBALS['BE_USER']->check('tables_select', $table) && !\TYPO3\CMS\Core\Utility\GeneralUtility::inList($excludeList, $table)) {
1164 $optValues[$table] = $table;
1165 }
1166 }
1167 // make box:
1168 $opt = array();
1169 $opt[] = '<option value=""></option>';
1170 foreach ($optValues as $k => $v) {
1171 if (is_array($value)) {
1172 $sel = in_array($k, $value) ? ' selected="selected"' : '';
1173 }
1174 $opt[] = '<option value="' . htmlspecialchars($k) . '"' . $sel . '>' . htmlspecialchars($v) . '</option>';
1175 }
1176 return '<select name="' . $prefix . '[]" multiple="multiple" size="' . \TYPO3\CMS\Core\Utility\MathUtility::forceIntegerInRange(count($opt), 5, 10) . '">' . implode('', $opt) . '</select>';
1177 }
1178
1179 /**
1180 * Returns a selector-box with loaded extension keys
1181 *
1182 * @param string $prefix Form element name prefix
1183 * @param array $value The current values selected
1184 * @return string HTML select element
1185 * @todo Define visibility
1186 */
1187 public function extensionSelector($prefix, $value) {
1188 global $TYPO3_LOADED_EXT;
1189 $extTrav = array_keys($TYPO3_LOADED_EXT);
1190 // make box:
1191 $opt = array();
1192 $opt[] = '<option value=""></option>';
1193 foreach ($extTrav as $v) {
1194 if (is_array($value)) {
1195 $sel = in_array($v, $value) ? ' selected="selected"' : '';
1196 }
1197 $opt[] = '<option value="' . htmlspecialchars($v) . '"' . $sel . '>' . htmlspecialchars($v) . '</option>';
1198 }
1199 return '<select name="' . $prefix . '[]" multiple="multiple" size="' . \TYPO3\CMS\Core\Utility\MathUtility::forceIntegerInRange(count($opt), 5, 10) . '">' . implode('', $opt) . '</select>';
1200 }
1201
1202 /**
1203 * Filter page IDs by traversing exclude array, finding all excluded pages (if any) and making an AND NOT IN statement for the select clause.
1204 *
1205 * @param array $exclude Exclude array from import/export object.
1206 * @return string AND where clause part to filter out page uids.
1207 * @todo Define visibility
1208 */
1209 public function filterPageIds($exclude) {
1210 // Get keys:
1211 $exclude = array_keys($exclude);
1212 // Traverse
1213 $pageIds = array();
1214 foreach ($exclude as $element) {
1215 list($table, $uid) = explode(':', $element);
1216 if ($table === 'pages') {
1217 $pageIds[] = intval($uid);
1218 }
1219 }
1220 // Add to clause:
1221 if (count($pageIds)) {
1222 return ' AND uid NOT IN (' . implode(',', $pageIds) . ')';
1223 }
1224 }
1225
1226 }
1227
1228
1229 ?>