TYPO3 CMS  TYPO3_6-2
ImportExportController.php
Go to the documentation of this file.
1 <?php
3 
24 
31 
35  protected $uploadedFiles = array();
36 
42  public $pageinfo;
43 
47  protected $export;
48 
52  protected $import;
53 
57  protected $fileProcessor;
58 
62  protected $vC = '';
63 
67  protected $lang = NULL;
68 
72  protected $treeHTML = '';
73 
77  public function init() {
78  parent::init();
79  $this->vC = GeneralUtility::_GP('vC');
80  $this->lang = $this->getLanguageService();
81  }
82 
89  public function main() {
90  $this->lang->includeLLFile('EXT:impexp/app/locallang.xlf');
91  // Start document template object:
92  $this->doc = GeneralUtility::makeInstance('TYPO3\\CMS\\Backend\\Template\\DocumentTemplate');
93  $this->doc->backPath = $GLOBALS['BACK_PATH'];
94  $this->doc->bodyTagId = 'imp-exp-mod';
95  $this->doc->setModuleTemplate(\TYPO3\CMS\Core\Utility\ExtensionManagementUtility::extRelPath('impexp') . '/app/template.html');
96  $this->pageinfo = BackendUtility::readPageAccess($this->id, $this->perms_clause);
97  // Setting up the context sensitive menu:
98  $this->doc->getContextMenuCode();
99  $this->doc->postCode = $this->doc->wrapScriptTags('if (top.fsMod) top.fsMod.recentIds["web"] = ' . (int)$this->id . ';');
100  $this->doc->form = '<form action="' . htmlspecialchars($GLOBALS['MCONF']['_']) . '" method="post" enctype="'
101  . $GLOBALS['TYPO3_CONF_VARS']['SYS']['form_enctype'] . '"><input type="hidden" name="id" value="' . $this->id . '" />';
102  $this->content .= $this->doc->header($this->lang->getLL('title'));
103  $this->content .= $this->doc->spacer(5);
104  // Input data grabbed:
105  $inData = GeneralUtility::_GP('tx_impexp');
106  $this->checkUpload();
107  switch ((string) $inData['action']) {
108  case 'export':
109  // Finally: If upload went well, set the new file as the thumbnail in the $inData array:
110  if (!empty($this->uploadedFiles[0])) {
111  $inData['meta']['thumbnail'] = $this->uploadedFiles[0]->getCombinedIdentifier();
112  }
113  // Call export interface
114  $this->exportData($inData);
115  break;
116  case 'import':
117  $backendUser = $this->getBackendUser();
118  $isEnabledForNonAdmin = $backendUser->getTSConfig('options.impexp.enableImportForNonAdminUser');
119  if (!$backendUser->isAdmin() && empty($isEnabledForNonAdmin['value'])) {
120  throw new \RuntimeException(
121  'Import module is disabled for non admin users and '
122  . 'userTsConfig options.impexp.enableImportForNonAdminUser is not enabled.',
123  1464435459
124  );
125  }
126  // Finally: If upload went well, set the new file as the import file:
127  if (!empty($this->uploadedFiles[0])) {
128  // Only allowed extensions....
129  if (GeneralUtility::inList('t3d,xml', $this->uploadedFiles[0]->getExtension())) {
130  $inData['file'] = $this->uploadedFiles[0]->getCombinedIdentifier();
131  }
132  }
133  // Call import interface:
134  $this->importData($inData);
135  break;
136  }
137  // Setting up the buttons and markers for docheader
138  $docHeaderButtons = $this->getButtons();
139  $markers['CONTENT'] = $this->content;
140  // Build the <body> for the module
141  $this->content = $this->doc->startPage($this->lang->getLL('title'));
142  $this->content .= $this->doc->moduleBody($this->pageinfo, $docHeaderButtons, $markers);
143  $this->content .= $this->doc->endPage();
144  $this->content = $this->doc->insertStylesAndJS($this->content);
145  }
146 
153  public function printContent() {
154  echo $this->content;
155  }
156 
162  protected function getButtons() {
163  $buttons = array(
164  'view' => '',
165  'shortcut' => ''
166  );
167  if ($this->getBackendUser()->mayMakeShortcut()) {
168  $buttons['shortcut'] = $this->doc->makeShortcutIcon('tx_impexp', '', $this->MCONF['name']);
169  }
170  // Input data grabbed:
171  $inData = GeneralUtility::_GP('tx_impexp');
172  if ((string) $inData['action'] == 'import') {
173  if ($this->id && is_array($this->pageinfo) || $this->getBackendUser()->user['admin'] && !$this->id) {
174  if (is_array($this->pageinfo) && $this->pageinfo['uid']) {
175  // View
176  $onClick = BackendUtility::viewOnClick(
177  $this->pageinfo['uid'],
178  $this->doc->backPath,
179  BackendUtility::BEgetRootLine($this->pageinfo['uid'])
180  );
181  $title = $this->lang->sL('LLL:EXT:lang/locallang_core.xlf:labels.showPage', TRUE);
182  $buttons['view'] = '<a href="#" onclick="' . htmlspecialchars($onClick) . '" title="' . $title . '">'
183  . IconUtility::getSpriteIcon('actions-document-view') . '</a>';
184  }
185  }
186  }
187  return $buttons;
188  }
189 
190  /**************************
191  * EXPORT FUNCTIONS
192  **************************/
193 
201  public function exportData($inData) {
202  // BUILDING EXPORT DATA:
203  // Processing of InData array values:
204  $inData['pagetree']['maxNumber'] = MathUtility::forceIntegerInRange($inData['pagetree']['maxNumber'], 1, 1000000, 100);
205  $inData['listCfg']['maxNumber'] = MathUtility::forceIntegerInRange($inData['listCfg']['maxNumber'], 1, 1000000, 100);
206  $inData['maxFileSize'] = MathUtility::forceIntegerInRange($inData['maxFileSize'], 1, 1000000, 1000);
207  $inData['filename'] = trim(preg_replace('/[^[:alnum:]._-]*/', '', preg_replace('/\\.(t3d|xml)$/', '', $inData['filename'])));
208  if (strlen($inData['filename'])) {
209  $inData['filename'] .= $inData['filetype'] == 'xml' ? '.xml' : '.t3d';
210  }
211  // Set exclude fields in export object:
212  if (!is_array($inData['exclude'])) {
213  $inData['exclude'] = array();
214  }
215  // Saving/Loading/Deleting presets:
216  $this->processPresets($inData);
217  // Create export object and configure it:
218  $this->export = GeneralUtility::makeInstance('TYPO3\\CMS\\Impexp\\ImportExport');
219  $this->export->init(0, 'export');
220  $this->export->setCharset($this->lang->charSet);
221  $this->export->maxFileSize = $inData['maxFileSize'] * 1024;
222  $this->export->excludeMap = (array) $inData['exclude'];
223  $this->export->softrefCfg = (array) $inData['softrefCfg'];
224  $this->export->extensionDependencies = (array) $inData['extension_dep'];
225  $this->export->showStaticRelations = $inData['showStaticRelations'];
226  $this->export->includeExtFileResources = !$inData['excludeHTMLfileResources'];
227  // Static tables:
228  if (is_array($inData['external_static']['tables'])) {
229  $this->export->relStaticTables = $inData['external_static']['tables'];
230  }
231  // Configure which tables external relations are included for:
232  if (is_array($inData['external_ref']['tables'])) {
233  $this->export->relOnlyTables = $inData['external_ref']['tables'];
234  }
235  $this->export->setHeaderBasics();
236  // Meta data setting:
237 
238  $beUser = $this->getBackendUser();
239  $this->export->setMetaData(
240  $inData['meta']['title'],
241  $inData['meta']['description'],
242  $inData['meta']['notes'],
243  $beUser->user['username'],
244  $beUser->user['realName'],
245  $beUser->user['email']
246  );
247  if ($inData['meta']['thumbnail']) {
248  $theThumb = $this->getFile($inData['meta']['thumbnail']);
249  if ($theThumb !== NULL && $theThumb->exists()) {
250  $this->export->addThumbnail($theThumb->getForLocalProcessing(FALSE));
251  }
252  }
253  // Configure which records to export
254  if (is_array($inData['record'])) {
255  foreach ($inData['record'] as $ref) {
256  $rParts = explode(':', $ref);
257  $this->export->export_addRecord($rParts[0], BackendUtility::getRecord($rParts[0], $rParts[1]));
258  }
259  }
260  // Configure which tables to export
261  if (is_array($inData['list'])) {
262  $db = $this->getDatabaseConnection();
263  foreach ($inData['list'] as $ref) {
264  $rParts = explode(':', $ref);
265  if ($beUser->check('tables_select', $rParts[0])) {
266  $res = $this->exec_listQueryPid($rParts[0], $rParts[1], MathUtility::forceIntegerInRange($inData['listCfg']['maxNumber'], 1));
267  while ($subTrow = $db->sql_fetch_assoc($res)) {
268  $this->export->export_addRecord($rParts[0], $subTrow);
269  }
270  $db->sql_free_result($res);
271  }
272  }
273  }
274  // Pagetree
275  if (isset($inData['pagetree']['id'])) {
276  // Based on click-expandable tree
277  $idH = NULL;
278  if ($inData['pagetree']['levels'] == -1) {
279  $pagetree = GeneralUtility::makeInstance('TYPO3\\CMS\\Impexp\\LocalPageTree');
280  $tree = $pagetree->ext_tree($inData['pagetree']['id'], $this->filterPageIds($this->export->excludeMap));
281  $this->treeHTML = $pagetree->printTree($tree);
282  $idH = $pagetree->buffer_idH;
283  } elseif ($inData['pagetree']['levels'] == -2) {
284  $this->addRecordsForPid($inData['pagetree']['id'], $inData['pagetree']['tables'], $inData['pagetree']['maxNumber']);
285  } else {
286  // Based on depth
287  // Drawing tree:
288  // If the ID is zero, export root
289  if (!$inData['pagetree']['id'] && $beUser->isAdmin()) {
290  $sPage = array(
291  'uid' => 0,
292  'title' => 'ROOT'
293  );
294  } else {
295  $sPage = BackendUtility::getRecordWSOL('pages', $inData['pagetree']['id'], '*', ' AND ' . $this->perms_clause);
296  }
297  if (is_array($sPage)) {
298  $pid = $inData['pagetree']['id'];
299  $tree = GeneralUtility::makeInstance('TYPO3\\CMS\\Backend\\Tree\\View\\PageTreeView');
300  $tree->init('AND ' . $this->perms_clause . $this->filterPageIds($this->export->excludeMap));
301  $HTML = IconUtility::getSpriteIconForRecord('pages', $sPage);
302  $tree->tree[] = array('row' => $sPage, 'HTML' => $HTML);
303  $tree->buffer_idH = array();
304  if ($inData['pagetree']['levels'] > 0) {
305  $tree->getTree($pid, $inData['pagetree']['levels'], '');
306  }
307  $idH = array();
308  $idH[$pid]['uid'] = $pid;
309  if (count($tree->buffer_idH)) {
310  $idH[$pid]['subrow'] = $tree->buffer_idH;
311  }
312  $pagetree = GeneralUtility::makeInstance('TYPO3\\CMS\\Impexp\\LocalPageTree');
313  $this->treeHTML = $pagetree->printTree($tree->tree);
314  }
315  }
316  // In any case we should have a multi-level array, $idH, with the page structure
317  // here (and the HTML-code loaded into memory for nice display...)
318  if (is_array($idH)) {
319  // Sets the pagetree and gets a 1-dim array in return with the pages (in correct submission order BTW...)
320  $flatList = $this->export->setPageTree($idH);
321  foreach ($flatList as $k => $value) {
322  $this->export->export_addRecord('pages', BackendUtility::getRecord('pages', $k));
323  $this->addRecordsForPid($k, $inData['pagetree']['tables'], $inData['pagetree']['maxNumber']);
324  }
325  }
326  }
327  // After adding ALL records we set relations:
328  for ($a = 0; $a < 10; $a++) {
329  $addR = $this->export->export_addDBRelations($a);
330  if (!count($addR)) {
331  break;
332  }
333  }
334  // Finally files are added:
335  // MUST be after the DBrelations are set so that files from ALL added records are included!
336  $this->export->export_addFilesFromRelations();
337 
338  $this->export->export_addFilesFromSysFilesRecords();
339 
340  // If the download button is clicked, return file
341  if ($inData['download_export'] || $inData['save_export']) {
342  switch ((string) $inData['filetype']) {
343  case 'xml':
344  $out = $this->export->compileMemoryToFileContent('xml');
345  $fExt = '.xml';
346  break;
347  case 't3d':
348  $this->export->dontCompress = 1;
349  // intentional fall-through
350  default:
351  $out = $this->export->compileMemoryToFileContent();
352  $fExt = ($this->export->doOutputCompress() ? '-z' : '') . '.t3d';
353  }
354  // Filename:
355  $dlFile = $inData['filename'];
356  if (!$dlFile) {
357  $exportName = substr(preg_replace('/[^[:alnum:]_]/', '-', $inData['download_export_name']), 0, 20);
358  $dlFile = 'T3D_' . $exportName . '_' . date('Y-m-d_H-i') . $fExt;
359  }
360 
361  // Export for download:
362  if ($inData['download_export']) {
363  $mimeType = 'application/octet-stream';
364  Header('Content-Type: ' . $mimeType);
365  Header('Content-Length: ' . strlen($out));
366  Header('Content-Disposition: attachment; filename=' . basename($dlFile));
367  echo $out;
368  die;
369  }
370  // Export by saving:
371  if ($inData['save_export']) {
372  $saveFolder = $this->getDefaultImportExportFolder();
373  if ($saveFolder !== FALSE && $saveFolder->checkActionPermission('write')) {
374  $temporaryFileName = GeneralUtility::tempnam('export');
375  file_put_contents($temporaryFileName, $out);
376  $file = $saveFolder->addFile($temporaryFileName, $dlFile, 'replace');
377  $file = $this->getIndexerService()->indexFile($file);
378  $this->content .= $this->doc->section($GLOBALS['LANG']->getLL('exportdata_savedFile'), sprintf($GLOBALS['LANG']->getLL('exportdata_savedInSBytes', TRUE), $file->getPublicUrl(), GeneralUtility::formatSize(strlen($out))), 0, 1);
379  } else {
380  $this->content .= $this->doc->section($GLOBALS['LANG']->getLL('exportdata_problemsSavingFile'), sprintf($GLOBALS['LANG']->getLL('exportdata_badPathS', TRUE), $this->getTemporaryFolderPath()), 0, 1, 2);
381  }
382  }
383  }
384  // OUTPUT to BROWSER:
385  // Now, if we didn't make download file, show configuration form based on export:
386  $menuItems = array();
387  // Export configuration
388  $row = array();
389  $this->makeConfigurationForm($inData, $row);
390  $menuItems[] = array(
391  'label' => $this->lang->getLL('tableselec_configuration'),
392  'content' => '
393  <table border="0" cellpadding="1" cellspacing="1">
394  ' . implode('
395  ', $row) . '
396  </table>
397  '
398  );
399  // File options
400  $row = array();
401  $this->makeSaveForm($inData, $row);
402  $menuItems[] = array(
403  'label' => $this->lang->getLL('exportdata_filePreset'),
404  'content' => '
405  <table border="0" cellpadding="1" cellspacing="1">
406  ' . implode('
407  ', $row) . '
408  </table>
409  '
410  );
411  // File options
412  $row = array();
413  $this->makeAdvancedOptionsForm($inData, $row);
414  $menuItems[] = array(
415  'label' => $this->lang->getLL('exportdata_advancedOptions'),
416  'content' => '
417  <table border="0" cellpadding="1" cellspacing="1">
418  ' . implode('
419  ', $row) . '
420  </table>
421  '
422  );
423  // Generate overview:
424  $overViewContent = $this->export->displayContentOverview();
425  // Print errors that might be:
426  $errors = $this->export->printErrorLog();
427  $menuItems[] = array(
428  'label' => $this->lang->getLL('exportdata_messages'),
429  'content' => $errors,
430  'stateIcon' => $errors ? 2 : 0
431  );
432  // Add hidden fields and create tabs:
433  $content = $this->doc->getDynTabMenu($menuItems, 'tx_impexp_export', -1);
434  $content .= '<input type="hidden" name="tx_impexp[action]" value="export" />';
435  $this->content .= $this->doc->section('', $content, 0, 1);
436  // Output Overview:
437  $this->content .= $this->doc->section($this->lang->getLL('execlistqu_structureToBeExported'), $overViewContent, 0, 1);
438  }
439 
449  public function addRecordsForPid($k, $tables, $maxNumber) {
450  if (!is_array($tables)) {
451  return;
452  }
453  $db = $this->getDatabaseConnection();
454  foreach ($GLOBALS['TCA'] as $table => $value) {
455  if ($table != 'pages' && (in_array($table, $tables) || in_array('_ALL', $tables))) {
456  if ($this->getBackendUser()->check('tables_select', $table) && !$GLOBALS['TCA'][$table]['ctrl']['is_static']) {
457  $res = $this->exec_listQueryPid($table, $k, MathUtility::forceIntegerInRange($maxNumber, 1));
458  while ($subTrow = $db->sql_fetch_assoc($res)) {
459  $this->export->export_addRecord($table, $subTrow);
460  }
461  $db->sql_free_result($res);
462  }
463  }
464  }
465  }
466 
476  public function exec_listQueryPid($table, $pid, $limit) {
477  $db = $this->getDatabaseConnection();
478  $orderBy = $GLOBALS['TCA'][$table]['ctrl']['sortby']
479  ? 'ORDER BY ' . $GLOBALS['TCA'][$table]['ctrl']['sortby']
480  : $GLOBALS['TCA'][$table]['ctrl']['default_sortby'];
481  $res = $db->exec_SELECTquery(
482  '*',
483  $table,
484  'pid=' . (int)$pid . BackendUtility::deleteClause($table) . BackendUtility::versioningPlaceholderClause($table),
485  '',
486  $db->stripOrderBy($orderBy),
487  $limit
488  );
489  // Warning about hitting limit:
490  if ($db->sql_num_rows($res) == $limit) {
491  $limitWarning = sprintf($this->lang->getLL('makeconfig_anSqlQueryReturned', TRUE), $limit);
492  $this->content .= $this->doc->section($this->lang->getLL('execlistqu_maxNumberLimit'), $limitWarning, 0, 1, 2);
493  }
494  return $res;
495  }
496 
505  public function makeConfigurationForm($inData, &$row) {
506  $nameSuggestion = '';
507  // Page tree export options:
508  if (isset($inData['pagetree']['id'])) {
509  $nameSuggestion .= 'tree_PID' . $inData['pagetree']['id'] . '_L' . $inData['pagetree']['levels'];
510  $row[] = '
511  <tr class="tableheader bgColor5">
512  <td colspan="2">' . $this->lang->getLL('makeconfig_exportPagetreeConfiguration', TRUE)
513  . BackendUtility::cshItem('xMOD_tx_impexp', 'pageTreeCfg', $GLOBALS['BACK_PATH'], '') . '</td>
514  </tr>';
515  $row[] = '
516  <tr class="bgColor4">
517  <td><strong>' . $this->lang->getLL('makeconfig_pageId', TRUE) . '</strong></td>
518  <td>' . htmlspecialchars($inData['pagetree']['id']) . '<input type="hidden" value="'
519  . htmlspecialchars($inData['pagetree']['id']) . '" name="tx_impexp[pagetree][id]" /></td>
520  </tr>';
521  $row[] = '
522  <tr class="bgColor4">
523  <td><strong>' . $this->lang->getLL('makeconfig_tree', TRUE) . '</strong>'
524  . BackendUtility::cshItem('xMOD_tx_impexp', 'pageTreeDisplay', $GLOBALS['BACK_PATH'], '') . '</td>
525  <td>' . ($this->treeHTML ?: $this->lang->getLL('makeconfig_noTreeExportedOnly', TRUE)) . '</td>
526  </tr>';
527  $opt = array(
528  '-2' => $this->lang->getLL('makeconfig_tablesOnThisPage'),
529  '-1' => $this->lang->getLL('makeconfig_expandedTree'),
530  '0' => $this->lang->getLL('makeconfig_onlyThisPage'),
531  '1' => $this->lang->getLL('makeconfig_1Level'),
532  '2' => $this->lang->getLL('makeconfig_2Levels'),
533  '3' => $this->lang->getLL('makeconfig_3Levels'),
534  '4' => $this->lang->getLL('makeconfig_4Levels'),
535  '999' => $this->lang->getLL('makeconfig_infinite')
536  );
537  $row[] = '
538  <tr class="bgColor4">
539  <td><strong>' . $this->lang->getLL('makeconfig_levels', TRUE) . '</strong>'
540  . BackendUtility::cshItem('xMOD_tx_impexp', 'pageTreeMode', $GLOBALS['BACK_PATH'], '') . '</td>
541  <td>' . $this->renderSelectBox('tx_impexp[pagetree][levels]', $inData['pagetree']['levels'], $opt) . '</td>
542  </tr>';
543  $row[] = '
544  <tr class="bgColor4">
545  <td><strong>' . $this->lang->getLL('makeconfig_includeTables', TRUE) . '</strong>'
546  . BackendUtility::cshItem('xMOD_tx_impexp', 'pageTreeRecordLimit', $GLOBALS['BACK_PATH'], '') . '</td>
547  <td>' . $this->tableSelector('tx_impexp[pagetree][tables]', $inData['pagetree']['tables'], 'pages') . '<br/>
548  ' . $this->lang->getLL('makeconfig_maxNumberOfRecords', TRUE) . '<br/>
549  <input type="text" name="tx_impexp[pagetree][maxNumber]" value="'
550  . htmlspecialchars($inData['pagetree']['maxNumber']) . '"' . $this->doc->formWidth(10) . ' /><br/>
551  </td>
552  </tr>';
553  }
554  // Single record export:
555  if (is_array($inData['record'])) {
556  $row[] = '
557  <tr class="tableheader bgColor5">
558  <td colspan="2">' . $this->lang->getLL('makeconfig_exportSingleRecord', TRUE)
559  . BackendUtility::cshItem('xMOD_tx_impexp', 'singleRecord', $GLOBALS['BACK_PATH'], '') . '</td>
560  </tr>';
561  foreach ($inData['record'] as $ref) {
562  $rParts = explode(':', $ref);
563  $tName = $rParts[0];
564  $rUid = $rParts[1];
565  $nameSuggestion .= $tName . '_' . $rUid;
566  $rec = BackendUtility::getRecordWSOL($tName, $rUid);
567  if (!empty($rec)) {
568  $row[] = '
569  <tr class="bgColor4">
570  <td><strong>' . $this->lang->getLL('makeconfig_record', TRUE) . '</strong></td>
571  <td>' . IconUtility::getSpriteIconForRecord($tName, $rec) . BackendUtility::getRecordTitle($tName, $rec, TRUE)
572  . '<input type="hidden" name="tx_impexp[record][]" value="' . htmlspecialchars(($tName . ':' . $rUid)) . '" /></td>
573  </tr>';
574  }
575  }
576  }
577  // Single tables/pids:
578  if (is_array($inData['list'])) {
579  $row[] = '
580  <tr class="tableheader bgColor5">
581  <td colspan="2">' . $this->lang->getLL('makeconfig_exportTablesFromPages', TRUE) . '</td>
582  </tr>';
583  // Display information about pages from which the export takes place
584  $tblList = '';
585  foreach ($inData['list'] as $reference) {
586  $referenceParts = explode(':', $reference);
587  $tableName = $referenceParts[0];
588  if ($this->getBackendUser()->check('tables_select', $tableName)) {
589  // If the page is actually the root, handle it differently
590  // NOTE: we don't compare integers, because the number actually comes from the split string above
591  if ($referenceParts[1] === '0') {
592  $iconAndTitle = IconUtility::getSpriteIcon('apps-pagetree-root') . $GLOBALS['TYPO3_CONF_VARS']['SYS']['sitename'];
593  } else {
594  $record = BackendUtility::getRecordWSOL('pages', $referenceParts[1]);
595  $iconAndTitle = IconUtility::getSpriteIconForRecord('pages', $record)
596  . BackendUtility::getRecordTitle('pages', $record, TRUE);
597  }
598  $tblList .= 'Table "' . $tableName . '" from ' . $iconAndTitle
599  . '<input type="hidden" name="tx_impexp[list][]" value="' . htmlspecialchars($reference) . '" /><br/>';
600  }
601  }
602  $row[] = '
603  <tr class="bgColor4">
604  <td><strong>' . $this->lang->getLL('makeconfig_tablePids', TRUE) . '</strong>'
605  . BackendUtility::cshItem('xMOD_tx_impexp', 'tableList', $GLOBALS['BACK_PATH'], '') . '</td>
606  <td>' . $tblList . '</td>
607  </tr>';
608  $row[] = '
609  <tr class="bgColor4">
610  <td><strong>' . $this->lang->getLL('makeconfig_maxNumberOfRecords', TRUE)
611  . BackendUtility::cshItem('xMOD_tx_impexp', 'tableListMaxNumber', $GLOBALS['BACK_PATH'], '') . '</strong></td>
612  <td>
613  <input type="text" name="tx_impexp[listCfg][maxNumber]" value="'
614  . htmlspecialchars($inData['listCfg']['maxNumber']) . '"' . $this->doc->formWidth(10) . ' /><br/>
615  </td>
616  </tr>';
617  }
618  $row[] = '
619  <tr class="tableheader bgColor5">
620  <td colspan="2">' . $this->lang->getLL('makeconfig_relationsAndExclusions', TRUE) . '</td>
621  </tr>';
622  // Add relation selector:
623  $row[] = '
624  <tr class="bgColor4">
625  <td><strong>' . $this->lang->getLL('makeconfig_includeRelationsToTables', TRUE) . '</strong>'
626  . BackendUtility::cshItem('xMOD_tx_impexp', 'inclRelations', $GLOBALS['BACK_PATH'], '') . '</td>
627  <td>' . $this->tableSelector('tx_impexp[external_ref][tables]', $inData['external_ref']['tables']) . '</td>
628  </tr>';
629  // Add static relation selector:
630  $row[] = '
631  <tr class="bgColor4">
632  <td><strong>' . $this->lang->getLL('makeconfig_useStaticRelationsFor', TRUE) . '</strong>'
633  . BackendUtility::cshItem('xMOD_tx_impexp', 'staticRelations', $GLOBALS['BACK_PATH'], '') . '</td>
634  <td>' . $this->tableSelector('tx_impexp[external_static][tables]', $inData['external_static']['tables']) . '<br/>
635  <label for="checkShowStaticRelations">' . $this->lang->getLL('makeconfig_showStaticRelations', TRUE)
636  . '</label> <input type="checkbox" name="tx_impexp[showStaticRelations]" id="checkShowStaticRelations" value="1"'
637  . ($inData['showStaticRelations'] ? ' checked="checked"' : '') . ' />
638  </td>
639  </tr>';
640  // Exclude:
641  $excludeHiddenFields = '';
642  if (is_array($inData['exclude'])) {
643  foreach ($inData['exclude'] as $key => $value) {
644  $excludeHiddenFields .= '<input type="hidden" name="tx_impexp[exclude][' . $key . ']" value="1" />';
645  }
646  }
647  if (count($inData['exclude'])) {
648  $excludedElements = '<em>' . implode(', ', array_keys($inData['exclude'])). '</em><hr/><label for="checkExclude">'
649  . $this->lang->getLL('makeconfig_clearAllExclusions', TRUE)
650  . '</label> <input type="checkbox" name="tx_impexp[exclude]" id="checkExclude" value="1" />';
651  } else {
652  $excludedElements = $this->lang->getLL('makeconfig_noExcludedElementsYet', TRUE);
653  }
654  $row[] = '
655  <tr class="bgColor4">
656  <td><strong>' . $this->lang->getLL('makeconfig_excludeElements', TRUE) . '</strong>'
657  . BackendUtility::cshItem('xMOD_tx_impexp', 'excludedElements', $GLOBALS['BACK_PATH'], '') . '</td>
658  <td>' . $excludeHiddenFields . '
659  ' . $excludedElements . '
660  </td>
661  </tr>';
662  // Add buttons:
663  $row[] = '
664  <tr class="bgColor4">
665  <td>&nbsp;</td>
666  <td>
667  <input type="submit" value="' . $this->lang->getLL('makeadvanc_update', TRUE) . '" />
668  <input type="hidden" name="tx_impexp[download_export_name]" value="' . substr($nameSuggestion, 0, 30) . '" />
669  </td>
670  </tr>';
671  }
672 
681  public function makeAdvancedOptionsForm($inData, &$row) {
682  // Soft references
683  $row[] = '
684  <tr class="tableheader bgColor5">
685  <td colspan="2">' . $this->lang->getLL('makeadvanc_softReferences', TRUE) . '</td>
686  </tr>';
687  $row[] = '
688  <tr class="bgColor4">
689  <td><label for="checkExcludeHTMLfileResources"><strong>'
690  . $this->lang->getLL('makeadvanc_excludeHtmlCssFile', TRUE) . '</strong></label>'
691  . BackendUtility::cshItem('xMOD_tx_impexp', 'htmlCssResources', $GLOBALS['BACK_PATH'], '') . '</td>
692  <td><input type="checkbox" name="tx_impexp[excludeHTMLfileResources]" id="checkExcludeHTMLfileResources" value="1"'
693  . ($inData['excludeHTMLfileResources'] ? ' checked="checked"' : '') . ' /></td>
694  </tr>';
695  // Extensions
696  $row[] = '
697  <tr class="tableheader bgColor5">
698  <td colspan="2">' . $this->lang->getLL('makeadvanc_extensionDependencies', TRUE) . '</td>
699  </tr>';
700  $row[] = '
701  <tr class="bgColor4">
702  <td><strong>' . $this->lang->getLL('makeadvanc_selectExtensionsThatThe', TRUE) . '</strong>'
703  . BackendUtility::cshItem('xMOD_tx_impexp', 'extensionDependencies', $GLOBALS['BACK_PATH'], '') . '</td>
704  <td>' . $this->extensionSelector('tx_impexp[extension_dep]', $inData['extension_dep']) . '</td>
705  </tr>';
706  // Add buttons:
707  $row[] = '
708  <tr class="bgColor4">
709  <td>&nbsp;</td>
710  <td>
711  <input type="submit" value="' . $this->lang->getLL('makesavefo_update', TRUE) . '" />
712  <input type="hidden" name="tx_impexp[download_export_name]" value="" />
713  </td>
714  </tr>';
715  }
716 
725  public function makeSaveForm($inData, &$row) {
726  // Presets:
727  $row[] = '
728  <tr class="tableheader bgColor5">
729  <td colspan="2">' . $this->lang->getLL('makesavefo_presets', TRUE) . '</td>
730  </tr>';
731  $opt = array('');
732  $where = '(public>0 OR user_uid=' . (int)$this->getBackendUser()->user['uid'] . ')'
733  . ($inData['pagetree']['id'] ? ' AND (item_uid=' . (int)$inData['pagetree']['id'] . ' OR item_uid=0)' : '');
734  $presets = $this->getDatabaseConnection()->exec_SELECTgetRows('*', 'tx_impexp_presets', $where);
735  if (is_array($presets)) {
736  foreach ($presets as $presetCfg) {
737  $opt[$presetCfg['uid']] = $presetCfg['title'] . ' [' . $presetCfg['uid'] . ']'
738  . ($presetCfg['public'] ? ' [Public]' : '')
739  . ($presetCfg['user_uid'] === $this->getBackendUser()->user['uid'] ? ' [Own]' : '');
740  }
741  }
742  $row[] = '
743  <tr class="bgColor4">
744  <td><strong>' . $this->lang->getLL('makesavefo_presets', TRUE) . '</strong>'
745  . BackendUtility::cshItem('xMOD_tx_impexp', 'presets', $GLOBALS['BACK_PATH'], '') . '</td>
746  <td>
747  ' . $this->lang->getLL('makesavefo_selectPreset', TRUE) . '<br/>
748  ' . $this->renderSelectBox('preset[select]', '', $opt) . '
749  <br/>
750  <input type="submit" value="' . $this->lang->getLL('makesavefo_load', TRUE) . '" name="preset[load]" />
751  <input type="submit" value="' . $this->lang->getLL('makesavefo_save', TRUE) . '" name="preset[save]" onclick="return confirm(\'' . $this->lang->getLL('makesavefo_areYouSure', TRUE) . '\');" />
752  <input type="submit" value="' . $this->lang->getLL('makesavefo_delete', TRUE) . '" name="preset[delete]" onclick="return confirm(\'' . $this->lang->getLL('makesavefo_areYouSure', TRUE) . '\');" />
753  <input type="submit" value="' . $this->lang->getLL('makesavefo_merge', TRUE) . '" name="preset[merge]" onclick="return confirm(\'' . $this->lang->getLL('makesavefo_areYouSure', TRUE) . '\');" />
754  <br/>
755  ' . $this->lang->getLL('makesavefo_titleOfNewPreset', TRUE) . '
756  <input type="text" name="tx_impexp[preset][title]" value="'
757  . htmlspecialchars($inData['preset']['title']) . '"' . $this->doc->formWidth(30) . ' /><br/>
758  <label for="checkPresetPublic">' . $this->lang->getLL('makesavefo_public', TRUE) . '</label>
759  <input type="checkbox" name="tx_impexp[preset][public]" id="checkPresetPublic" value="1"'
760  . ($inData['preset']['public'] ? ' checked="checked"' : '') . ' /><br/>
761  </td>
762  </tr>';
763  // Output options:
764  $row[] = '
765  <tr class="tableheader bgColor5">
766  <td colspan="2">' . $this->lang->getLL('makesavefo_outputOptions', TRUE) . '</td>
767  </tr>';
768  // Meta data:
769  $thumbnailFiles = array();
770  foreach ($this->getThumbnailFiles() as $thumbnailFile) {
771  $thumbnailFiles[$thumbnailFile->getCombinedIdentifier()] = $thumbnailFile->getName();
772  }
773  if (!empty($thumbnailFiles)) {
774  array_unshift($thumbnailFiles, '');
775  }
776  $thumbnail = NULL;
777  if (!empty($inData['meta']['thumbnail'])) {
778  $thumbnail = $this->getFile($inData['meta']['thumbnail']);
779  }
780  $saveFolder = $this->getDefaultImportExportFolder();
781 
782  $row[] = '
783  <tr class="bgColor4">
784  <td><strong>' . $this->lang->getLL('makesavefo_metaData', TRUE) . '</strong>'
785  . BackendUtility::cshItem('xMOD_tx_impexp', 'metadata', $GLOBALS['BACK_PATH'], '') . '</td>
786  <td>
787  ' . $this->lang->getLL('makesavefo_title', TRUE) . ' <br/>
788  <input type="text" name="tx_impexp[meta][title]" value="' . htmlspecialchars($inData['meta']['title']) . '"' . $this->doc->formWidth(30) . ' /><br/>
789  ' . $this->lang->getLL('makesavefo_description', TRUE) . ' <br/>
790  <input type="text" name="tx_impexp[meta][description]" value="' . htmlspecialchars($inData['meta']['description']) . '"' . $this->doc->formWidth(30) . ' /><br/>
791  ' . $this->lang->getLL('makesavefo_notes', TRUE) . ' <br/>
792  <textarea name="tx_impexp[meta][notes]"' . $this->doc->formWidth(30, 1) . '>' . GeneralUtility::formatForTextarea($inData['meta']['notes']) . '</textarea><br/>
793  ' . (!empty($thumbnailFiles) ? '
794  ' . $this->lang->getLL('makesavefo_thumbnail', TRUE) . '<br/>
795  ' . $this->renderSelectBox('tx_impexp[meta][thumbnail]', $inData['meta']['thumbnail'], $thumbnailFiles) : '') . '<br/>
796  ' . ($thumbnail ? '<img src="' . htmlspecialchars($thumbnail->getPublicUrl(TRUE)) . '" vspace="5" style="border: solid black 1px;" alt="" /><br/>' : '') . '
797  ' . $this->lang->getLL('makesavefo_uploadThumbnail', TRUE) . '<br/>
798  ' . ($saveFolder ? '<input type="file" name="upload_1" ' . $this->doc->formWidth(30) . ' size="30" /><br/>
799  <input type="hidden" name="file[upload][1][target]" value="' . htmlspecialchars($saveFolder->getCombinedIdentifier()) . '" />
800  <input type="hidden" name="file[upload][1][data]" value="1" /><br />' : '') . '
801  </td>
802  </tr>';
803  // Add file options:
804  $opt = array();
805  if ($this->export->compress) {
806  $opt['t3d_compressed'] = $this->lang->getLL('makesavefo_t3dFileCompressed');
807  }
808  $opt['t3d'] = $this->lang->getLL('makesavefo_t3dFile');
809  $opt['xml'] = $this->lang->getLL('makesavefo_xml');
810  $fileName = '';
811  if ($saveFolder) {
812  $fileName = sprintf($this->lang->getLL('makesavefo_filenameSavedInS', TRUE), $saveFolder->getCombinedIdentifier())
813  . '<br/>
814  <input type="text" name="tx_impexp[filename]" value="'
815  . htmlspecialchars($inData['filename']) . '"' . $this->doc->formWidth(30) . ' /><br/>';
816  }
817  $row[] = '
818  <tr class="bgColor4">
819  <td><strong>' . $this->lang->getLL('makesavefo_fileFormat', TRUE) . '</strong>'
820  . BackendUtility::cshItem('xMOD_tx_impexp', 'fileFormat', $GLOBALS['BACK_PATH'], '') . '</td>
821  <td>' . $this->renderSelectBox('tx_impexp[filetype]', $inData['filetype'], $opt) . '<br/>
822  ' . $this->lang->getLL('makesavefo_maxSizeOfFiles', TRUE) . '<br/>
823  <input type="text" name="tx_impexp[maxFileSize]" value="'
824  . htmlspecialchars($inData['maxFileSize']) . '"' . $this->doc->formWidth(10) . ' /><br/>
825  ' . $fileName . '
826  </td>
827  </tr>';
828  // Add buttons:
829  $row[] = '
830  <tr class="bgColor4">
831  <td>&nbsp;</td>
832  <td><input type="submit" value="' . $this->lang->getLL('makesavefo_update', TRUE)
833  . '" /> - <input type="submit" value="' . $this->lang->getLL('makesavefo_downloadExport', TRUE)
834  . '" name="tx_impexp[download_export]" />' . ($saveFolder ? ' - <input type="submit" value="'
835  . $this->lang->getLL('importdata_saveToFilename', TRUE) . '" name="tx_impexp[save_export]" />' : '') . '</td>
836  </tr>';
837  }
838 
839  /**************************
840  * IMPORT FUNCTIONS
841  **************************/
842 
850  public function importData($inData) {
851  $access = is_array($this->pageinfo) ? 1 : 0;
852  $beUser = $this->getBackendUser();
853  if ($this->id && $access || $beUser->user['admin'] && !$this->id) {
854  if ($beUser->user['admin'] && !$this->id) {
855  $this->pageinfo = array('title' => '[root-level]', 'uid' => 0, 'pid' => 0);
856  }
857  if ($inData['new_import']) {
858  unset($inData['import_mode']);
859  }
861  $import = GeneralUtility::makeInstance('TYPO3\\CMS\\Impexp\\ImportExport');
862  $import->init(0, 'import');
863  $import->update = $inData['do_update'];
864  $import->import_mode = $inData['import_mode'];
865  $import->enableLogging = $inData['enableLogging'];
866  $import->global_ignore_pid = $inData['global_ignore_pid'];
867  $import->force_all_UIDS = $inData['force_all_UIDS'];
868  $import->showDiff = !$inData['notShowDiff'];
869  $import->allowPHPScripts = $inData['allowPHPScripts'];
870  $import->softrefInputValues = $inData['softrefInputValues'];
871  // OUTPUT creation:
872  $menuItems = array();
873  // Make input selector:
874  // must have trailing slash.
875  $path = $this->getDefaultImportExportFolder();
876  $exportFiles = $this->getExportFiles();
877  // Configuration
878  $row = array();
879  $selectOptions = array('');
880  foreach ($exportFiles as $file) {
881  $selectOptions[$file->getCombinedIdentifier()] = $file->getPublicUrl();
882  }
883  $row[] = '<tr class="bgColor5">
884  <td colspan="2"><strong>' . $this->lang->getLL('importdata_selectFileToImport', TRUE) . '</strong></td>
885  </tr>';
886  $noCompressorAvailable = !$import->compress
887  ? '<br /><span class="typo3-red">' . $this->lang->getLL('importdata_noteNoDecompressorAvailable', TRUE) . '</span>'
888  : '';
889  $row[] = '<tr class="bgColor4">
890  <td><strong>' . $this->lang->getLL('importdata_file', TRUE) . '</strong>'
891  . BackendUtility::cshItem('xMOD_tx_impexp', 'importFile', $GLOBALS['BACK_PATH'], '') . '</td>
892  <td>' . $this->renderSelectBox('tx_impexp[file]', $inData['file'], $selectOptions) . '<br />'
893  . sprintf($this->lang->getLL('importdata_fromPathS', TRUE), $path ? $path->getCombinedIdentifier() : $this->lang->getLL('importdata_no_accessible_file_mount', TRUE)) .
894  $noCompressorAvailable . '</td>
895  </tr>';
896  $row[] = '<tr class="bgColor5">
897  <td colspan="2"><strong>' . $this->lang->getLL('importdata_importOptions', TRUE) . '</strong></td>
898  </tr>';
899  $row[] = '<tr class="bgColor4">
900  <td><strong>' . $this->lang->getLL('importdata_update', TRUE) . '</strong>'
901  . BackendUtility::cshItem('xMOD_tx_impexp', 'update', $GLOBALS['BACK_PATH'], '') . '</td>
902  <td>
903  <input type="checkbox" name="tx_impexp[do_update]" id="checkDo_update" value="1"'
904  . ($inData['do_update'] ? ' checked="checked"' : '') . ' />
905  <label for="checkDo_update">' . $this->lang->getLL('importdata_updateRecords', TRUE) . '</label><br/>
906  <em>(' . $this->lang->getLL('importdata_thisOptionRequiresThat', TRUE) . ')</em>' . ($inData['do_update'] ? ' <hr/>
907  <input type="checkbox" name="tx_impexp[global_ignore_pid]" id="checkGlobal_ignore_pid" value="1"'
908  . ($inData['global_ignore_pid'] ? ' checked="checked"' : '') . ' />
909  <label for="checkGlobal_ignore_pid">' . $this->lang->getLL('importdata_ignorePidDifferencesGlobally', TRUE) . '</label><br/>
910  <em>(' . $this->lang->getLL('importdata_ifYouSetThis', TRUE) . ')</em>
911  ' : '') . '</td>
912  </tr>';
913  $allowPhpScripts = $beUser->isAdmin()
914  ? '
915  <input type="checkbox" name="tx_impexp[allowPHPScripts]" id="checkAllowPHPScripts" value="1"'
916  . ($inData['allowPHPScripts'] ? ' checked="checked"' : '') . ' />
917  <label for="checkAllowPHPScripts">' . $this->lang->getLL('importdata_allowToWriteBanned', TRUE) . '</label><br/>'
918  : '';
919  $doUpdate = !$inData['do_update'] && $beUser->isAdmin()
920  ? '
921  <br/>
922  <input type="checkbox" name="tx_impexp[force_all_UIDS]" id="checkForce_all_UIDS" value="1"'
923  . ($inData['force_all_UIDS'] ? ' checked="checked"' : '') . ' />
924  <label for="checkForce_all_UIDS"><span class="typo3-red">'
925  . $this->lang->getLL('importdata_force_all_UIDS', TRUE) . '</span></label><br/>
926  <em>(' . $this->lang->getLL('importdata_force_all_UIDS_descr', TRUE) . ')</em>'
927  : '';
928  $row[] = '<tr class="bgColor4">
929  <td><strong>' . $this->lang->getLL('importdata_options', TRUE) . '</strong>'
930  . BackendUtility::cshItem('xMOD_tx_impexp', 'options', $GLOBALS['BACK_PATH'], '') . '</td>
931  <td>
932  <input type="checkbox" name="tx_impexp[notShowDiff]" id="checkNotShowDiff" value="1"'
933  . ($inData['notShowDiff'] ? ' checked="checked"' : '') . ' />
934  <label for="checkNotShowDiff">' . $this->lang->getLL('importdata_doNotShowDifferences', TRUE) . '</label><br/>
935  <em>(' . $this->lang->getLL('importdata_greenValuesAreFrom', TRUE) . ')</em>
936  <br/><br/>
937 
938  ' . $allowPhpScripts . $doUpdate . '
939  </td>
940  </tr>';
941  $newImport = !$inData['import_file']
942  ? '<input type="submit" value="' . $this->lang->getLL('importdata_preview', TRUE) . '" />' . ($inData['file']
943  ? ' - <input type="submit" value="' . ($inData['do_update']
944  ? $this->lang->getLL('importdata_update_299e', TRUE)
945  : $this->lang->getLL('importdata_import', TRUE)) . '" name="tx_impexp[import_file]" onclick="return confirm(\''
946  . $this->lang->getLL('importdata_areYouSure', TRUE) . '\');" />'
947  : '')
948  : '<input type="submit" name="tx_impexp[new_import]" value="' . $this->lang->getLL('importdata_newImport', TRUE) . '" />';
949  $row[] = '<tr class="bgColor4">
950  <td><strong>' . $this->lang->getLL('importdata_action', TRUE) . '</strong>'
951  . BackendUtility::cshItem('xMOD_tx_impexp', 'action', $GLOBALS['BACK_PATH'], '') . '</td>
952  <td>' . $newImport . '
953  <input type="hidden" name="tx_impexp[action]" value="import" /></td>
954  </tr>';
955  $row[] = '<tr class="bgColor4">
956  <td><strong>' . $this->lang->getLL('importdata_enableLogging', TRUE) . '</strong>'
957  . BackendUtility::cshItem('xMOD_tx_impexp', 'enableLogging', $GLOBALS['BACK_PATH'], '') . '</td>
958  <td>
959  <input type="checkbox" name="tx_impexp[enableLogging]" id="checkEnableLogging" value="1"'
960  . ($inData['enableLogging'] ? ' checked="checked"' : '') . ' />
961  <label for="checkEnableLogging">' . $this->lang->getLL('importdata_writeIndividualDbActions', TRUE) . '</label><br/>
962  <em>(' . $this->lang->getLL('importdata_thisIsDisabledBy', TRUE) . ')</em>
963  </td>
964  </tr>';
965  $menuItems[] = array(
966  'label' => $this->lang->getLL('importdata_import', TRUE),
967  'content' => '
968  <table border="0" cellpadding="1" cellspacing="1">
969  ' . implode('
970  ', $row) . '
971  </table>
972  '
973  );
974  // Upload file:
975  $tempFolder = $this->getDefaultImportExportFolder();
976  if ($tempFolder) {
977  $row = array();
978  $row[] = '<tr class="bgColor5">
979  <td colspan="2"><strong>' . $this->lang->getLL('importdata_uploadFileFromLocal', TRUE) . '</strong></td>
980  </tr>';
981  $row[] = '<tr class="bgColor4">
982  <td>' . $this->lang->getLL('importdata_browse', TRUE)
983  . BackendUtility::cshItem('xMOD_tx_impexp', 'upload', $GLOBALS['BACK_PATH'], '') . '</td>
984  <td>
985 
986  <input type="file" name="upload_1"' . $this->doc->formWidth(35) . ' size="40" />
987  <input type="hidden" name="file[upload][1][target]" value="' . htmlspecialchars($tempFolder->getCombinedIdentifier()) . '" />
988  <input type="hidden" name="file[upload][1][data]" value="1" /><br />
989 
990  <input type="submit" name="_upload" value="' . $this->lang->sL('LLL:EXT:lang/locallang_core.xlf:file_upload.php.submit', TRUE) . '" />
991  <input type="checkbox" name="overwriteExistingFiles" id="checkOverwriteExistingFiles" value="1" checked="checked" /> <label for="checkOverwriteExistingFiles">'
992  . $this->lang->sL('LLL:EXT:lang/locallang_misc.xlf:overwriteExistingFiles', TRUE) . '</label>
993  </td>
994  </tr>';
995  if (GeneralUtility::_POST('_upload')) {
996  $noFileUploaded = $this->fileProcessor->internalUploadMap[1]
997  ? $this->lang->getLL('importdata_success', TRUE) . ' ' . $this->uploadedFiles[0]->getName()
998  : '<span class="typo3-red">' . $this->lang->getLL('importdata_failureNoFileUploaded', TRUE) . '</span>';
999  $row[] = '<tr class="bgColor4">
1000  <td>' . $this->lang->getLL('importdata_uploadStatus', TRUE) . '</td>
1001  <td>' . $noFileUploaded . '</td>
1002  </tr>';
1003  }
1004  $menuItems[] = array(
1005  'label' => $this->lang->getLL('importdata_upload'),
1006  'content' => '
1007  <table border="0" cellpadding="1" cellspacing="1">
1008  ' . implode('
1009  ', $row) . '
1010  </table>
1011  '
1012  );
1013  }
1014  // Perform import or preview depending:
1015  $overviewContent = '';
1016  $extensionInstallationMessage = '';
1017  $inFile = $this->getFile($inData['file']);
1018  if ($inFile !== NULL && $inFile->exists()) {
1019  $trow = array();
1020  if ($import->loadFile($inFile->getForLocalProcessing(FALSE), 1)) {
1021  // Check extension dependencies:
1022  $extKeysToInstall = array();
1023  if (is_array($import->dat['header']['extensionDependencies'])) {
1024  foreach ($import->dat['header']['extensionDependencies'] as $extKey) {
1025  if (!empty($extKey) && !\TYPO3\CMS\Core\Utility\ExtensionManagementUtility::isLoaded($extKey)) {
1026  $extKeysToInstall[] = $extKey;
1027  }
1028  }
1029  }
1030  if (count($extKeysToInstall)) {
1031  $extensionInstallationMessage = 'Before you can install this T3D file you need to install the extensions "'
1032  . implode('", "', $extKeysToInstall) . '".';
1033  }
1034  if ($inData['import_file']) {
1035  if (!count($extKeysToInstall)) {
1036  $import->importData($this->id);
1037  BackendUtility::setUpdateSignal('updatePageTree');
1038  }
1039  }
1040  $import->display_import_pid_record = $this->pageinfo;
1041  $overviewContent = $import->displayContentOverview();
1042  }
1043  // Meta data output:
1044  $trow[] = '<tr class="bgColor5">
1045  <td colspan="2"><strong>' . $this->lang->getLL('importdata_metaData', TRUE) . '</strong></td>
1046  </tr>';
1047  $trow[] = '<tr class="bgColor4">
1048  <td><strong>' . $this->lang->getLL('importdata_title', TRUE) . '</strong></td>
1049  <td width="95%">' . nl2br(htmlspecialchars($import->dat['header']['meta']['title'])) . '</td>
1050  </tr>';
1051  $trow[] = '<tr class="bgColor4">
1052  <td><strong>' . $this->lang->getLL('importdata_description', TRUE) . '</strong></td>
1053  <td width="95%">' . nl2br(htmlspecialchars($import->dat['header']['meta']['description'])) . '</td>
1054  </tr>';
1055  $trow[] = '<tr class="bgColor4">
1056  <td><strong>' . $this->lang->getLL('importdata_notes', TRUE) . '</strong></td>
1057  <td width="95%">' . nl2br(htmlspecialchars($import->dat['header']['meta']['notes'])) . '</td>
1058  </tr>';
1059  $trow[] = '<tr class="bgColor4">
1060  <td><strong>' . $this->lang->getLL('importdata_packager', TRUE) . '</strong></td>
1061  <td width="95%">' . nl2br(htmlspecialchars(($import->dat['header']['meta']['packager_name']
1062  . ' (' . $import->dat['header']['meta']['packager_username'] . ')'))) . '<br/>
1063  ' . $this->lang->getLL('importdata_email', TRUE) . ' '
1064  . $import->dat['header']['meta']['packager_email'] . '</td>
1065  </tr>';
1066  // Thumbnail icon:
1067  if (is_array($import->dat['header']['thumbnail'])) {
1068  $pI = pathinfo($import->dat['header']['thumbnail']['filename']);
1069  if (GeneralUtility::inList('gif,jpg,png,jpeg', strtolower($pI['extension']))) {
1070  // Construct filename and write it:
1071  $fileName = PATH_site . 'typo3temp/importthumb.' . $pI['extension'];
1072  GeneralUtility::writeFile($fileName, $import->dat['header']['thumbnail']['content']);
1073  // Check that the image really is an image and not a malicious PHP script...
1074  if (getimagesize($fileName)) {
1075  // Create icon tag:
1076  $iconTag = '<img src="' . $this->doc->backPath . '../' . PathUtility::stripPathSitePrefix($fileName)
1077  . '" ' . $import->dat['header']['thumbnail']['imgInfo'][3]
1078  . ' vspace="5" style="border: solid black 1px;" alt="" />';
1079  $trow[] = '<tr class="bgColor4">
1080  <td><strong>' . $this->lang->getLL('importdata_icon', TRUE) . '</strong></td>
1081  <td>' . $iconTag . '</td>
1082  </tr>';
1083  } else {
1084  GeneralUtility::unlink_tempfile($fileName);
1085  }
1086  }
1087  }
1088  $menuItems[] = array(
1089  'label' => $this->lang->getLL('importdata_metaData_1387'),
1090  'content' => '
1091  <table border="0" cellpadding="1" cellspacing="1">
1092  ' . implode('
1093  ', $trow) . '
1094  </table>
1095  '
1096  );
1097  }
1098  // Print errors that might be:
1099  $errors = $import->printErrorLog();
1100  $menuItems[] = array(
1101  'label' => $this->lang->getLL('importdata_messages'),
1102  'content' => $errors,
1103  'stateIcon' => $errors ? 2 : 0
1104  );
1105  // Output tabs:
1106  $content = $this->doc->getDynTabMenu($menuItems, 'tx_impexp_import', -1);
1107  if ($extensionInstallationMessage) {
1108  $content = '<div style="border: 1px black solid; margin: 10px 10px 10px 10px; padding: 10px 10px 10px 10px;">'
1109  . $this->doc->icons(1) . htmlspecialchars($extensionInstallationMessage) . '</div>' . $content;
1110  }
1111  $this->content .= $this->doc->section('', $content, 0, 1);
1112  // Print overview:
1113  if ($overviewContent) {
1114  $this->content .= $this->doc->section($inData['import_file']
1115  ? $this->lang->getLL('importdata_structureHasBeenImported', TRUE)
1116  : $this->lang->getLL('filterpage_structureToBeImported', TRUE), $overviewContent, 0, 1);
1117  }
1118  }
1119  }
1120 
1121  /****************************
1122  * Preset functions
1123  ****************************/
1124 
1132  public function processPresets(&$inData) {
1133  $presetData = GeneralUtility::_GP('preset');
1134  $err = FALSE;
1135  $msg = '';
1136  // Save preset
1137  $beUser = $this->getBackendUser();
1138  // cast public checkbox to int, since this is a int field and NULL is not allowed
1139  $inData['preset']['public'] = (int)$inData['preset']['public'];
1140  if (isset($presetData['save'])) {
1141  $preset = $this->getPreset($presetData['select']);
1142  // Update existing
1143  if (is_array($preset)) {
1144  if ($beUser->isAdmin() || $preset['user_uid'] === $beUser->user['uid']) {
1145  $fields_values = array(
1146  'public' => $inData['preset']['public'],
1147  'title' => $inData['preset']['title'],
1148  'item_uid' => $inData['pagetree']['id'],
1149  'preset_data' => serialize($inData)
1150  );
1151  $this->getDatabaseConnection()->exec_UPDATEquery('tx_impexp_presets', 'uid=' . (int)$preset['uid'], $fields_values);
1152  $msg = 'Preset #' . $preset['uid'] . ' saved!';
1153  } else {
1154  $msg = 'ERROR: The preset was not saved because you were not the owner of it!';
1155  $err = TRUE;
1156  }
1157  } else {
1158  // Insert new:
1159  $fields_values = array(
1160  'user_uid' => $beUser->user['uid'],
1161  'public' => $inData['preset']['public'],
1162  'title' => $inData['preset']['title'],
1163  'item_uid' => $inData['pagetree']['id'],
1164  'preset_data' => serialize($inData)
1165  );
1166  $this->getDatabaseConnection()->exec_INSERTquery('tx_impexp_presets', $fields_values);
1167  $msg = 'New preset "' . htmlspecialchars($inData['preset']['title']) . '" is created';
1168  }
1169  }
1170  // Delete preset:
1171  if (isset($presetData['delete'])) {
1172  $preset = $this->getPreset($presetData['select']);
1173  if (is_array($preset)) {
1174  // Update existing
1175  if ($beUser->isAdmin() || $preset['user_uid'] === $beUser->user['uid']) {
1176  $this->getDatabaseConnection()->exec_DELETEquery('tx_impexp_presets', 'uid=' . (int)$preset['uid']);
1177  $msg = 'Preset #' . $preset['uid'] . ' deleted!';
1178  } else {
1179  $msg = 'ERROR: You were not the owner of the preset so you could not delete it.';
1180  $err = TRUE;
1181  }
1182  } else {
1183  $msg = 'ERROR: No preset selected for deletion.';
1184  $err = TRUE;
1185  }
1186  }
1187  // Load preset
1188  if (isset($presetData['load']) || isset($presetData['merge'])) {
1189  $preset = $this->getPreset($presetData['select']);
1190  if (is_array($preset)) {
1191  // Update existing
1192  $inData_temp = unserialize($preset['preset_data']);
1193  if (is_array($inData_temp)) {
1194  if (isset($presetData['merge'])) {
1195  // Merge records in:
1196  if (is_array($inData_temp['record'])) {
1197  $inData['record'] = array_merge((array) $inData['record'], $inData_temp['record']);
1198  }
1199  // Merge lists in:
1200  if (is_array($inData_temp['list'])) {
1201  $inData['list'] = array_merge((array) $inData['list'], $inData_temp['list']);
1202  }
1203  } else {
1204  $msg = 'Preset #' . $preset['uid'] . ' loaded!';
1205  $inData = $inData_temp;
1206  }
1207  } else {
1208  $msg = 'ERROR: No configuratio data found in preset record!';
1209  $err = TRUE;
1210  }
1211  } else {
1212  $msg = 'ERROR: No preset selected for loading.';
1213  $err = TRUE;
1214  }
1215  }
1216  // Show message:
1217  if ($msg !== '') {
1218  $this->content .= $this->doc->section('Presets', $msg, 0, 1, $err ? 3 : 1);
1219  }
1220  }
1221 
1229  public function getPreset($uid) {
1230  return $this->getDatabaseConnection()->exec_SELECTgetSingleRow('*', 'tx_impexp_presets', 'uid=' . (int)$uid);
1231  }
1232 
1233  /****************************
1234  * Helper functions
1235  ****************************/
1236 
1244  public function userTempFolder() {
1245  GeneralUtility::logDeprecatedFunction();
1246  return $this->getDefaultImportExportFolder()->getPublicUrl();
1247  }
1248 
1256  public function userSaveFolder() {
1257  GeneralUtility::logDeprecatedFunction();
1258  return $this->getDefaultImportExportFolder()->getPublicUrl();
1259  }
1260 
1267  protected function getDefaultImportExportFolder() {
1268  $defaultImportExportFolder = NULL;
1269 
1270  $defaultTemporaryFolder = $this->getBackendUser()->getDefaultUploadTemporaryFolder();
1271  if ($defaultTemporaryFolder !== NULL) {
1272 
1273  $importExportFolderName = 'importexport';
1274  $createFolder = !$defaultTemporaryFolder->hasFolder($importExportFolderName);
1275  if ($createFolder === TRUE) {
1276  try {
1277  $defaultImportExportFolder = $defaultTemporaryFolder->createFolder($importExportFolderName);
1278  } catch (\TYPO3\CMS\Core\Resource\Exception $folderAccessException) {}
1279  } else {
1280  $defaultImportExportFolder = $defaultTemporaryFolder->getSubfolder($importExportFolderName);
1281  }
1282  }
1283 
1284  return $defaultImportExportFolder;
1285  }
1286 
1287 
1288 
1295  public function checkUpload() {
1296  $file = GeneralUtility::_GP('file');
1297  // Initializing:
1298  $this->fileProcessor = GeneralUtility::makeInstance('TYPO3\\CMS\\Core\\Utility\\File\\ExtendedFileUtility');
1299  $this->fileProcessor->init(array(), $GLOBALS['TYPO3_CONF_VARS']['BE']['fileExtensions']);
1300  $this->fileProcessor->setActionPermissions();
1301  $this->fileProcessor->dontCheckForUnique = GeneralUtility::_GP('overwriteExistingFiles') ? 1 : 0;
1302  // Checking referer / executing:
1303  $refInfo = parse_url(GeneralUtility::getIndpEnv('HTTP_REFERER'));
1304  $httpHost = GeneralUtility::getIndpEnv('TYPO3_HOST_ONLY');
1305  if (
1306  $httpHost != $refInfo['host']
1307  && !$GLOBALS['$TYPO3_CONF_VARS']['SYS']['doNotCheckReferer']
1308  && $this->vC != $this->getBackendUser()->veriCode()
1309  ) {
1310  $this->fileProcessor->writeLog(0, 2, 1, 'Referer host "%s" and server host "%s" did not match!', array($refInfo['host'], $httpHost));
1311  } else {
1312  $this->fileProcessor->start($file);
1313  $result = $this->fileProcessor->processData();
1314  if (!empty($result['upload'])) {
1315  foreach ($result['upload'] as $uploadedFiles) {
1316  $this->uploadedFiles += $uploadedFiles;
1317  }
1318  }
1319  }
1320  }
1321 
1331  public function renderSelectBox($prefix, $value, $optValues) {
1332  $opt = array();
1333  $isSelFlag = 0;
1334  foreach ($optValues as $k => $v) {
1335  $sel = (string)$k === (string)$value ? ' selected="selected"' : '';
1336  if ($sel) {
1337  $isSelFlag++;
1338  }
1339  $opt[] = '<option value="' . htmlspecialchars($k) . '"' . $sel . '>' . htmlspecialchars($v) . '</option>';
1340  }
1341  if (!$isSelFlag && (string)$value !== '') {
1342  $opt[] = '<option value="' . htmlspecialchars($value) . '" selected="selected">'
1343  . htmlspecialchars(('[\'' . $value . '\']')) . '</option>';
1344  }
1345  return '<select name="' . $prefix . '">' . implode('', $opt) . '</select>';
1346  }
1347 
1357  public function tableSelector($prefix, $value, $excludeList = '') {
1358  $optValues = array();
1359  if (!GeneralUtility::inList($excludeList, '_ALL')) {
1360  $optValues['_ALL'] = '[' . $this->lang->getLL('ALL_tables') . ']';
1361  }
1362  foreach ($GLOBALS['TCA'] as $table => $_) {
1363  if ($this->getBackendUser()->check('tables_select', $table) && !GeneralUtility::inList($excludeList, $table)) {
1364  $optValues[$table] = $table;
1365  }
1366  }
1367  // make box:
1368  $opt = array();
1369  $opt[] = '<option value=""></option>';
1370  $sel = '';
1371  foreach ($optValues as $k => $v) {
1372  if (is_array($value)) {
1373  $sel = in_array($k, $value) ? ' selected="selected"' : '';
1374  }
1375  $opt[] = '<option value="' . htmlspecialchars($k) . '"' . $sel . '>' . htmlspecialchars($v) . '</option>';
1376  }
1377  return '<select name="' . $prefix . '[]" multiple="multiple" size="'
1378  . MathUtility::forceIntegerInRange(count($opt), 5, 10) . '">' . implode('', $opt) . '</select>';
1379  }
1380 
1389  public function extensionSelector($prefix, $value) {
1390  $loadedExtensions = \TYPO3\CMS\Core\Utility\ExtensionManagementUtility::getLoadedExtensionListArray();
1391 
1392  // make box:
1393  $opt = array();
1394  $opt[] = '<option value=""></option>';
1395  foreach ($loadedExtensions as $extensionKey) {
1396  $sel = '';
1397  if (is_array($value)) {
1398  $sel = in_array($extensionKey, $value) ? ' selected="selected"' : '';
1399  }
1400  $opt[] = '<option value="' . htmlspecialchars($extensionKey) . '"' . $sel . '>'
1401  . htmlspecialchars($extensionKey) . '</option>';
1402  }
1403  return '<select name="' . $prefix . '[]" multiple="multiple" size="'
1404  . MathUtility::forceIntegerInRange(count($opt), 5, 10) . '">' . implode('', $opt) . '</select>';
1405  }
1406 
1415  public function filterPageIds($exclude) {
1416  // Get keys:
1417  $exclude = array_keys($exclude);
1418  // Traverse
1419  $pageIds = array();
1420  foreach ($exclude as $element) {
1421  list($table, $uid) = explode(':', $element);
1422  if ($table === 'pages') {
1423  $pageIds[] = (int)$uid;
1424  }
1425  }
1426  // Add to clause:
1427  if (count($pageIds)) {
1428  return ' AND uid NOT IN (' . implode(',', $pageIds) . ')';
1429  }
1430  return '';
1431  }
1432 
1436  protected function getBackendUser() {
1437  return $GLOBALS['BE_USER'];
1438  }
1439 
1443  protected function getDatabaseConnection() {
1444  return $GLOBALS['TYPO3_DB'];
1445  }
1446 
1450  protected function getLanguageService() {
1451  return $GLOBALS['LANG'];
1452  }
1453 
1459  protected function getThumbnailFiles() {
1460  $thumbnailFiles = array();
1461  $defaultTemporaryFolder = $this->getDefaultImportExportFolder();
1462 
1463  if ($defaultTemporaryFolder === NULL) {
1464  return $thumbnailFiles;
1465  }
1466 
1468  $filter = GeneralUtility::makeInstance('TYPO3\\CMS\\Core\\Resource\\Filter\\FileExtensionFilter');
1469  $filter->setAllowedFileExtensions(array('png', 'gif', 'jpg'));
1470  $defaultTemporaryFolder->getStorage()->addFileAndFolderNameFilter(array($filter, 'filterFileList'));
1471  $thumbnailFiles = $defaultTemporaryFolder->getFiles();
1472 
1473  return $thumbnailFiles;
1474  }
1475 
1481  protected function getExportFiles() {
1482  $exportFiles = array();
1483 
1484  $folder = $this->getDefaultImportExportFolder();
1485  if ($folder !== NULL) {
1486 
1488  $filter = GeneralUtility::makeInstance('TYPO3\\CMS\\Core\\Resource\\Filter\\FileExtensionFilter');
1489  $filter->setAllowedFileExtensions(array('t3d', 'xml'));
1490  $folder->getStorage()->addFileAndFolderNameFilter(array($filter, 'filterFileList'));
1491 
1492  $exportFiles = $folder->getFiles();
1493  }
1494 
1495  return $exportFiles;
1496  }
1497 
1504  protected function getFile($combinedIdentifier) {
1505  try {
1506  $file = \TYPO3\CMS\Core\Resource\ResourceFactory::getInstance()->getFileObjectFromCombinedIdentifier($combinedIdentifier);
1507  } catch (\Exception $exception) {
1508  $file = NULL;
1509  }
1510 
1511  return $file;
1512  }
1513 
1520  protected function getIndexerService() {
1521  return GeneralUtility::makeInstance('TYPO3\\CMS\\Core\\Resource\\Service\\IndexerService');
1522  }
1523 
1524 
1525 }
static getRecordWSOL($table, $uid, $fields=' *', $where='', $useDeleteClause=TRUE, $unsetMovePointers=FALSE)
static readPageAccess($id, $perms_clause)
static BEgetRootLine($uid, $clause='', $workspaceOL=FALSE)
static forceIntegerInRange($theInt, $min, $max=2000000000, $defaultValue=0)
Definition: MathUtility.php:32
static cshItem($table, $field, $BACK_PATH, $wrap='', $onlyIconMode=FALSE, $styleAttrib='')
die
Definition: index.php:6
static viewOnClick($pageUid, $backPath='', $rootLine='', $anchorSection='', $alternativeUrl='', $additionalGetVars='', $switchFocus=TRUE)
static getRecordTitle($table, $row, $prep=FALSE, $forceResult=TRUE)
static getSpriteIconForRecord($table, array $row, array $options=array())
static tempnam($filePrefix, $fileSuffix='')
static getSpriteIcon($iconName, array $options=array(), array $overlays=array())
static formatSize($sizeInBytes, $labels='')
if(!defined('TYPO3_MODE')) $GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['t3lib/class.t3lib_userauth.php']['logoff_pre_processing'][]
static deleteClause($table, $tableAlias='')