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