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