[TASK] Remove second parameter of getLL part 1/3
[Packages/TYPO3.CMS.git] / typo3 / sysext / impexp / Classes / ImportExport.php
1 <?php
2 namespace TYPO3\CMS\Impexp;
3
4 /*
5 * This file is part of the TYPO3 CMS project.
6 *
7 * It is free software; you can redistribute it and/or modify it under
8 * the terms of the GNU General Public License, either version 2
9 * of the License, or any later version.
10 *
11 * For the full copyright and license information, please read the
12 * LICENSE.txt file that was distributed with this source code.
13 *
14 * The TYPO3 project - inspiring people to share!
15 */
16
17 use TYPO3\CMS\Backend\Utility\BackendUtility;
18 use TYPO3\CMS\Core\Authentication\BackendUserAuthentication;
19 use TYPO3\CMS\Core\Database\DatabaseConnection;
20 use TYPO3\CMS\Core\Imaging\Icon;
21 use TYPO3\CMS\Core\Imaging\IconFactory;
22 use TYPO3\CMS\Core\Utility\DebugUtility;
23 use TYPO3\CMS\Core\Utility\DiffUtility;
24 use TYPO3\CMS\Core\Utility\ExtensionManagementUtility;
25 use TYPO3\CMS\Core\Utility\File\ExtendedFileUtility;
26 use TYPO3\CMS\Core\Utility\GeneralUtility;
27 use TYPO3\CMS\Core\Utility\PathUtility;
28 use TYPO3\CMS\Lang\LanguageService;
29
30 /**
31 * EXAMPLE for using the impexp-class for exporting stuff:
32 *
33 * Create and initialize:
34 * $this->export = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance(\TYPO3\CMS\Impexp\ImportExport::class);
35 * $this->export->init();
36 * Set which tables relations we will allow:
37 * $this->export->relOnlyTables[]="tt_news"; // exclusively includes. See comment in the class
38 *
39 * Adding records:
40 * $this->export->export_addRecord("pages", $this->pageinfo);
41 * $this->export->export_addRecord("pages", \TYPO3\CMS\Backend\Utility\BackendUtility::getRecord("pages", 38));
42 * $this->export->export_addRecord("pages", \TYPO3\CMS\Backend\Utility\BackendUtility::getRecord("pages", 39));
43 * $this->export->export_addRecord("tt_content", \TYPO3\CMS\Backend\Utility\BackendUtility::getRecord("tt_content", 12));
44 * $this->export->export_addRecord("tt_content", \TYPO3\CMS\Backend\Utility\BackendUtility::getRecord("tt_content", 74));
45 * $this->export->export_addRecord("sys_template", \TYPO3\CMS\Backend\Utility\BackendUtility::getRecord("sys_template", 20));
46 *
47 * Adding all the relations (recursively in 5 levels so relations has THEIR relations registered as well)
48 * for($a=0;$a<5;$a++) {
49 * $addR = $this->export->export_addDBRelations($a);
50 * if (empty($addR)) break;
51 * }
52 *
53 * Finally load all the files.
54 * $this->export->export_addFilesFromRelations(); // MUST be after the DBrelations are set so that file from ALL added records are included!
55 *
56 * Write export
57 * $out = $this->export->compileMemoryToFileContent();
58 */
59
60 /**
61 * T3D file Import/Export library (TYPO3 Record Document)
62 */
63 abstract class ImportExport
64 {
65 /**
66 * If set, static relations (not exported) will be shown in overview as well
67 *
68 * @var bool
69 */
70 public $showStaticRelations = false;
71
72 /**
73 * Name of the "fileadmin" folder where files for export/import should be located
74 *
75 * @var string
76 */
77 public $fileadminFolderName = '';
78
79 /**
80 * Whether "import" or "export" mode of object. Set through init() function
81 *
82 * @var string
83 */
84 public $mode = '';
85
86 /**
87 * Updates all records that has same UID instead of creating new!
88 *
89 * @var bool
90 */
91 public $update = false;
92
93 /**
94 * Is set by importData() when an import has been done.
95 *
96 * @var bool
97 */
98 public $doesImport = false;
99
100 /**
101 * If set to a page-record, then the preview display of the content will expect this page-record to be the target
102 * for the import and accordingly display validation information. This triggers the visual view of the
103 * import/export memory to validate if import is possible
104 *
105 * @var array
106 */
107 public $display_import_pid_record = array();
108
109 /**
110 * Setting import modes during update state: as_new, exclude, force_uid
111 *
112 * @var array
113 */
114 public $import_mode = array();
115
116 /**
117 * If set, PID correct is ignored globally
118 *
119 * @var bool
120 */
121 public $global_ignore_pid = false;
122
123 /**
124 * If set, all UID values are forced! (update or import)
125 *
126 * @var bool
127 */
128 public $force_all_UIDS = false;
129
130 /**
131 * If set, a diff-view column is added to the overview.
132 *
133 * @var bool
134 */
135 public $showDiff = false;
136
137 /**
138 * If set, and if the user is admin, allow the writing of PHP scripts to fileadmin/ area.
139 *
140 * @var bool
141 */
142 public $allowPHPScripts = false;
143
144 /**
145 * Array of values to substitute in editable softreferences.
146 *
147 * @var array
148 */
149 public $softrefInputValues = array();
150
151 /**
152 * Mapping between the fileID from import memory and the final filenames they are written to.
153 *
154 * @var array
155 */
156 public $fileIDMap = array();
157
158 /**
159 * Add table names here which are THE ONLY ones which will be included
160 * into export if found as relations. '_ALL' will allow all tables.
161 *
162 * @var array
163 */
164 public $relOnlyTables = array();
165
166 /**
167 * Add tables names here which should not be exported with the file.
168 * (Where relations should be mapped to same UIDs in target system).
169 *
170 * @var array
171 */
172 public $relStaticTables = array();
173
174 /**
175 * Exclude map. Keys are table:uid pairs and if set, records are not added to the export.
176 *
177 * @var array
178 */
179 public $excludeMap = array();
180
181 /**
182 * Soft Reference Token ID modes.
183 *
184 * @var array
185 */
186 public $softrefCfg = array();
187
188 /**
189 * Listing extension dependencies.
190 *
191 * @var array
192 */
193 public $extensionDependencies = array();
194
195 /**
196 * After records are written this array is filled with [table][original_uid] = [new_uid]
197 *
198 * @var array
199 */
200 public $import_mapId = array();
201
202 /**
203 * Error log.
204 *
205 * @var array
206 */
207 public $errorLog = array();
208
209 /**
210 * Cache for record paths
211 *
212 * @var array
213 */
214 public $cache_getRecordPath = array();
215
216 /**
217 * Cache of checkPID values.
218 *
219 * @var array
220 */
221 public $checkPID_cache = array();
222
223 /**
224 * Set internally if the gzcompress function exists
225 * Used by ImportExportController
226 *
227 * @var bool
228 */
229 public $compress = false;
230
231 /**
232 * Internal import/export memory
233 *
234 * @var array
235 */
236 public $dat = array();
237
238 /**
239 * File processing object
240 *
241 * @var ExtendedFileUtility
242 */
243 protected $fileProcObj = null;
244
245 /**
246 * @var array
247 */
248 protected $remainHeader = array();
249
250 /**
251 * @var IconFactory
252 */
253 protected $iconFactory;
254
255 /**
256 * Flag to control whether all disabled records and their children are excluded (true) or included (false). Defaults
257 * to the old behaviour of including everything.
258 *
259 * @var bool
260 */
261 protected $excludeDisabledRecords = false;
262
263 /**
264 * The constructor
265 */
266 public function __construct()
267 {
268 $this->iconFactory = GeneralUtility::makeInstance(IconFactory::class);
269 }
270
271 /**************************
272 * Initialize
273 *************************/
274
275 /**
276 * Init the object, both import and export
277 *
278 * @return void
279 */
280 public function init()
281 {
282 $this->compress = function_exists('gzcompress');
283 $this->fileadminFolderName = !empty($GLOBALS['TYPO3_CONF_VARS']['BE']['fileadminDir']) ? rtrim($GLOBALS['TYPO3_CONF_VARS']['BE']['fileadminDir'], '/') : 'fileadmin';
284 }
285
286 /********************************************************
287 * Visual rendering of import/export memory, $this->dat
288 ********************************************************/
289
290 /**
291 * Displays an overview of the header-content.
292 *
293 * @return array The view data
294 */
295 public function displayContentOverview()
296 {
297 if (!isset($this->dat['header'])) {
298 return [];
299 }
300 // Check extension dependencies:
301 foreach ($this->dat['header']['extensionDependencies'] as $extKey) {
302 if (!empty($extKey) && !ExtensionManagementUtility::isLoaded($extKey)) {
303 $this->error('DEPENDENCY: The extension with key "' . $extKey . '" must be installed!');
304 }
305 }
306
307 // Probably this is done to save memory space?
308 unset($this->dat['files']);
309
310 $viewData = array();
311 // Traverse header:
312 $this->remainHeader = $this->dat['header'];
313 // If there is a page tree set, show that:
314 if (is_array($this->dat['header']['pagetree'])) {
315 reset($this->dat['header']['pagetree']);
316 $lines = array();
317 $this->traversePageTree($this->dat['header']['pagetree'], $lines);
318
319 $viewData['dat'] = $this->dat;
320 $viewData['update'] = $this->update;
321 $viewData['showDiff'] = $this->showDiff;
322 if (!empty($lines)) {
323 foreach ($lines as &$r) {
324 $r['controls'] = $this->renderControls($r);
325 $r['fileSize'] = GeneralUtility::formatSize($r['size']);
326 $r['message'] = ($r['msg'] && !$this->doesImport ? '<span class="text-danger">' . htmlspecialchars($r['msg']) . '</span>' : '');
327 }
328 $viewData['pagetreeLines'] = $lines;
329 } else {
330 $viewData['pagetreeLines'] = array();
331 }
332 }
333 // Print remaining records that were not contained inside the page tree:
334 if (is_array($this->remainHeader['records'])) {
335 $lines = array();
336 if (is_array($this->remainHeader['records']['pages'])) {
337 $this->traversePageRecords($this->remainHeader['records']['pages'], $lines);
338 }
339 $this->traverseAllRecords($this->remainHeader['records'], $lines);
340 if (!empty($lines)) {
341 foreach ($lines as &$r) {
342 $r['controls'] = $this->renderControls($r);
343 $r['fileSize'] = GeneralUtility::formatSize($r['size']);
344 $r['message'] = ($r['msg'] && !$this->doesImport ? '<span class="text-danger">' . htmlspecialchars($r['msg']) . '</span>' : '');
345 }
346 $viewData['remainingRecords'] = $lines;
347 }
348 }
349
350 return $viewData;
351 }
352
353 /**
354 * Go through page tree for display
355 *
356 * @param array $pT Page tree array with uid/subrow (from ->dat[header][pagetree]
357 * @param array $lines Output lines array (is passed by reference and modified)
358 * @param string $preCode Pre-HTML code
359 * @return void
360 */
361 public function traversePageTree($pT, &$lines, $preCode = '')
362 {
363 foreach ($pT as $k => $v) {
364 if ($this->excludeDisabledRecords === true && !$this->isActive('pages', $k)) {
365 $this->excludePageAndRecords($k, $v);
366 continue;
367 }
368
369 // Add this page:
370 $this->singleRecordLines('pages', $k, $lines, $preCode);
371 // Subrecords:
372 if (is_array($this->dat['header']['pid_lookup'][$k])) {
373 foreach ($this->dat['header']['pid_lookup'][$k] as $t => $recUidArr) {
374 if ($t != 'pages') {
375 foreach ($recUidArr as $ruid => $value) {
376 $this->singleRecordLines($t, $ruid, $lines, $preCode . '&nbsp;&nbsp;&nbsp;&nbsp;');
377 }
378 }
379 }
380 unset($this->remainHeader['pid_lookup'][$k]);
381 }
382 // Subpages, called recursively:
383 if (is_array($v['subrow'])) {
384 $this->traversePageTree($v['subrow'], $lines, $preCode . '&nbsp;&nbsp;&nbsp;&nbsp;');
385 }
386 }
387 }
388
389 /**
390 * Test whether a record is active (i.e. not hidden)
391 *
392 * @param string $table Name of the records' database table
393 * @param int $uid Database uid of the record
394 * @return bool true if the record is active, false otherwise
395 */
396 protected function isActive($table, $uid)
397 {
398 return
399 !isset($GLOBALS['TCA'][$table]['ctrl']['enablecolumns']['disabled'])
400 || !(bool)$this->dat['records'][$table . ':' . $uid]['data'][
401 $GLOBALS['TCA']['pages']['ctrl']['enablecolumns']['disabled']
402 ];
403 }
404
405 /**
406 * Exclude a page, its sub pages (recursively) and records placed in them from this import/export
407 *
408 * @param int $pageUid Uid of the page to exclude
409 * @param array $pageTree Page tree array with uid/subrow (from ->dat[header][pagetree]
410 * @return void
411 */
412 protected function excludePageAndRecords($pageUid, $pageTree)
413 {
414 // Prevent having this page appear in "remaining records" table
415 unset($this->remainHeader['records']['pages'][$pageUid]);
416
417 // Subrecords
418 if (is_array($this->dat['header']['pid_lookup'][$pageUid])) {
419 foreach ($this->dat['header']['pid_lookup'][$pageUid] as $table => $recordData) {
420 if ($table != 'pages') {
421 foreach (array_keys($recordData) as $uid) {
422 unset($this->remainHeader['records'][$table][$uid]);
423 }
424 }
425 }
426 unset($this->remainHeader['pid_lookup'][$pageUid]);
427 }
428 // Subpages excluded recursively
429 if (is_array($pageTree['subrow'])) {
430 foreach ($pageTree['subrow'] as $subPageUid => $subPageTree) {
431 $this->excludePageAndRecords($subPageUid, $subPageTree);
432 }
433 }
434 }
435
436 /**
437 * Go through remaining pages (not in tree)
438 *
439 * @param array $pT Page tree array with uid/subrow (from ->dat[header][pagetree]
440 * @param array $lines Output lines array (is passed by reference and modified)
441 * @return void
442 */
443 public function traversePageRecords($pT, &$lines)
444 {
445 foreach ($pT as $k => $rHeader) {
446 $this->singleRecordLines('pages', $k, $lines, '', 1);
447 // Subrecords:
448 if (is_array($this->dat['header']['pid_lookup'][$k])) {
449 foreach ($this->dat['header']['pid_lookup'][$k] as $t => $recUidArr) {
450 if ($t != 'pages') {
451 foreach ($recUidArr as $ruid => $value) {
452 $this->singleRecordLines($t, $ruid, $lines, '&nbsp;&nbsp;&nbsp;&nbsp;');
453 }
454 }
455 }
456 unset($this->remainHeader['pid_lookup'][$k]);
457 }
458 }
459 }
460
461 /**
462 * Go through ALL records (if the pages are displayed first, those will not be amoung these!)
463 *
464 * @param array $pT Page tree array with uid/subrow (from ->dat[header][pagetree]
465 * @param array $lines Output lines array (is passed by reference and modified)
466 * @return void
467 */
468 public function traverseAllRecords($pT, &$lines)
469 {
470 foreach ($pT as $t => $recUidArr) {
471 $this->addGeneralErrorsByTable($t);
472 if ($t != 'pages') {
473 $preCode = '';
474 foreach ($recUidArr as $ruid => $value) {
475 $this->singleRecordLines($t, $ruid, $lines, $preCode, 1);
476 }
477 }
478 }
479 }
480
481 /**
482 * Log general error message for a given table
483 *
484 * @param string $table database table name
485 * @return void
486 */
487 protected function addGeneralErrorsByTable($table)
488 {
489 if ($this->update && $table === 'sys_file') {
490 $this->error('Updating sys_file records is not supported! They will be imported as new records!');
491 }
492 if ($this->force_all_UIDS && $table === 'sys_file') {
493 $this->error('Forcing uids of sys_file records is not supported! They will be imported as new records!');
494 }
495 }
496
497 /**
498 * Add entries for a single record
499 *
500 * @param string $table Table name
501 * @param int $uid Record uid
502 * @param array $lines Output lines array (is passed by reference and modified)
503 * @param string $preCode Pre-HTML code
504 * @param bool $checkImportInPidRecord If you want import validation, you can set this so it checks if the import can take place on the specified page.
505 * @return void
506 */
507 public function singleRecordLines($table, $uid, &$lines, $preCode, $checkImportInPidRecord = false)
508 {
509 // Get record:
510 $record = $this->dat['header']['records'][$table][$uid];
511 unset($this->remainHeader['records'][$table][$uid]);
512 if (!is_array($record) && !($table === 'pages' && !$uid)) {
513 $this->error('MISSING RECORD: ' . $table . ':' . $uid);
514 }
515 // Begin to create the line arrays information record, pInfo:
516 $pInfo = array();
517 $pInfo['ref'] = $table . ':' . $uid;
518 // Unknown table name:
519 $lang = $this->getLanguageService();
520 if ($table === '_SOFTREF_') {
521 $pInfo['preCode'] = $preCode;
522 $pInfo['title'] = '<em>' . htmlspecialchars($lang->getLL('impexpcore_singlereco_softReferencesFiles')) . '</em>';
523 } elseif (!isset($GLOBALS['TCA'][$table])) {
524 // Unknown table name:
525 $pInfo['preCode'] = $preCode;
526 $pInfo['msg'] = 'UNKNOWN TABLE \'' . $pInfo['ref'] . '\'';
527 $pInfo['title'] = '<em>' . htmlspecialchars($record['title']) . '</em>';
528 } else {
529 // prepare data attribute telling whether the record is active or hidden, allowing frontend bulk selection
530 $pInfo['active'] = $this->isActive($table, $uid) ? 'active' : 'hidden';
531
532 // Otherwise, set table icon and title.
533 // Import Validation (triggered by $this->display_import_pid_record) will show messages if import is not possible of various items.
534 if (is_array($this->display_import_pid_record) && !empty($this->display_import_pid_record)) {
535 if ($checkImportInPidRecord) {
536 if (!$this->getBackendUser()->doesUserHaveAccess($this->display_import_pid_record, ($table === 'pages' ? 8 : 16))) {
537 $pInfo['msg'] .= '\'' . $pInfo['ref'] . '\' cannot be INSERTED on this page! ';
538 }
539 if (!$this->checkDokType($table, $this->display_import_pid_record['doktype']) && !$GLOBALS['TCA'][$table]['ctrl']['rootLevel']) {
540 $pInfo['msg'] .= '\'' . $table . '\' cannot be INSERTED on this page type (change page type to \'Folder\'.) ';
541 }
542 }
543 if (!$this->getBackendUser()->check('tables_modify', $table)) {
544 $pInfo['msg'] .= 'You are not allowed to CREATE \'' . $table . '\' tables! ';
545 }
546 if ($GLOBALS['TCA'][$table]['ctrl']['readOnly']) {
547 $pInfo['msg'] .= 'TABLE \'' . $table . '\' is READ ONLY! ';
548 }
549 if ($GLOBALS['TCA'][$table]['ctrl']['adminOnly'] && !$this->getBackendUser()->isAdmin()) {
550 $pInfo['msg'] .= 'TABLE \'' . $table . '\' is ADMIN ONLY! ';
551 }
552 if ($GLOBALS['TCA'][$table]['ctrl']['is_static']) {
553 $pInfo['msg'] .= 'TABLE \'' . $table . '\' is a STATIC TABLE! ';
554 }
555 if ((int)$GLOBALS['TCA'][$table]['ctrl']['rootLevel'] === 1) {
556 $pInfo['msg'] .= 'TABLE \'' . $table . '\' will be inserted on ROOT LEVEL! ';
557 }
558 $diffInverse = false;
559 $recInf = null;
560 if ($this->update) {
561 // In case of update-PREVIEW we swap the diff-sources.
562 $diffInverse = true;
563 $recInf = $this->doesRecordExist($table, $uid, $this->showDiff ? '*' : '');
564 $pInfo['updatePath'] = $recInf ? htmlspecialchars($this->getRecordPath($recInf['pid'])) : '<strong>NEW!</strong>';
565 // Mode selector:
566 $optValues = array();
567 $optValues[] = $recInf ? $lang->getLL('impexpcore_singlereco_update') : $lang->getLL('impexpcore_singlereco_insert');
568 if ($recInf) {
569 $optValues['as_new'] = $lang->getLL('impexpcore_singlereco_importAsNew');
570 }
571 if ($recInf) {
572 if (!$this->global_ignore_pid) {
573 $optValues['ignore_pid'] = $lang->getLL('impexpcore_singlereco_ignorePid');
574 } else {
575 $optValues['respect_pid'] = $lang->getLL('impexpcore_singlereco_respectPid');
576 }
577 }
578 if (!$recInf && $this->getBackendUser()->isAdmin()) {
579 $optValues['force_uid'] = sprintf($lang->getLL('impexpcore_singlereco_forceUidSAdmin'), $uid);
580 }
581 $optValues['exclude'] = $lang->getLL('impexpcore_singlereco_exclude');
582 if ($table === 'sys_file') {
583 $pInfo['updateMode'] = '';
584 } else {
585 $pInfo['updateMode'] = $this->renderSelectBox('tx_impexp[import_mode][' . $table . ':' . $uid . ']', $this->import_mode[$table . ':' . $uid], $optValues);
586 }
587 }
588 // Diff view:
589 if ($this->showDiff) {
590 // For IMPORTS, get new id:
591 if ($newUid = $this->import_mapId[$table][$uid]) {
592 $diffInverse = false;
593 $recInf = $this->doesRecordExist($table, $newUid, '*');
594 BackendUtility::workspaceOL($table, $recInf);
595 }
596 if (is_array($recInf)) {
597 $pInfo['showDiffContent'] = $this->compareRecords($recInf, $this->dat['records'][$table . ':' . $uid]['data'], $table, $diffInverse);
598 }
599 }
600 }
601 $pInfo['preCode'] = $preCode . '<span title="' . htmlspecialchars($table . ':' . $uid) . '">'
602 . $this->iconFactory->getIconForRecord($table, (array)$this->dat['records'][$table . ':' . $uid]['data'], Icon::SIZE_SMALL)->render()
603 . '</span>';
604 $pInfo['title'] = htmlspecialchars($record['title']);
605 // View page:
606 if ($table === 'pages') {
607 $viewID = $this->mode === 'export' ? $uid : ($this->doesImport ? $this->import_mapId['pages'][$uid] : 0);
608 if ($viewID) {
609 $pInfo['title'] = '<a href="#" onclick="' . htmlspecialchars(BackendUtility::viewOnClick($viewID)) . 'return false;">' . $pInfo['title'] . '</a>';
610 }
611 }
612 }
613 $pInfo['type'] = 'record';
614 $pInfo['size'] = $record['size'];
615 $lines[] = $pInfo;
616 // File relations:
617 if (is_array($record['filerefs'])) {
618 $this->addFiles($record['filerefs'], $lines, $preCode);
619 }
620 // DB relations
621 if (is_array($record['rels'])) {
622 $this->addRelations($record['rels'], $lines, $preCode);
623 }
624 // Soft ref
625 if (!empty($record['softrefs'])) {
626 $preCode_A = $preCode . '&nbsp;&nbsp;&nbsp;&nbsp;';
627 $preCode_B = $preCode . '&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;';
628 foreach ($record['softrefs'] as $info) {
629 $pInfo = array();
630 $pInfo['preCode'] = $preCode_A . $this->iconFactory->getIcon('status-status-reference-soft', Icon::SIZE_SMALL)->render();
631 $pInfo['title'] = '<em>' . $info['field'] . ', "' . $info['spKey'] . '" </em>: <span title="' . htmlspecialchars($info['matchString']) . '">' . htmlspecialchars(GeneralUtility::fixed_lgd_cs($info['matchString'], 60)) . '</span>';
632 if ($info['subst']['type']) {
633 if (strlen($info['subst']['title'])) {
634 $pInfo['title'] .= '<br/>' . $preCode_B . '<strong>' . htmlspecialchars($lang->getLL('impexpcore_singlereco_title')) . '</strong> ' . htmlspecialchars(GeneralUtility::fixed_lgd_cs($info['subst']['title'], 60));
635 }
636 if (strlen($info['subst']['description'])) {
637 $pInfo['title'] .= '<br/>' . $preCode_B . '<strong>' . htmlspecialchars($lang->getLL('impexpcore_singlereco_descr')) . '</strong> ' . htmlspecialchars(GeneralUtility::fixed_lgd_cs($info['subst']['description'], 60));
638 }
639 $pInfo['title'] .= '<br/>' . $preCode_B . ($info['subst']['type'] == 'file' ? htmlspecialchars($lang->getLL('impexpcore_singlereco_filename')) . ' <strong>' . $info['subst']['relFileName'] . '</strong>' : '') . ($info['subst']['type'] == 'string' ? htmlspecialchars($lang->getLL('impexpcore_singlereco_value')) . ' <strong>' . $info['subst']['tokenValue'] . '</strong>' : '') . ($info['subst']['type'] == 'db' ? htmlspecialchars($lang->getLL('impexpcore_softrefsel_record')) . ' <strong>' . $info['subst']['recordRef'] . '</strong>' : '');
640 }
641 $pInfo['ref'] = 'SOFTREF';
642 $pInfo['size'] = '';
643 $pInfo['type'] = 'softref';
644 $pInfo['_softRefInfo'] = $info;
645 $pInfo['type'] = 'softref';
646 $mode = $this->softrefCfg[$info['subst']['tokenID']]['mode'];
647 if ($info['error'] && $mode !== 'editable' && $mode !== 'exclude') {
648 $pInfo['msg'] .= $info['error'];
649 }
650 $lines[] = $pInfo;
651 // Add relations:
652 if ($info['subst']['type'] == 'db') {
653 list($tempTable, $tempUid) = explode(':', $info['subst']['recordRef']);
654 $this->addRelations(array(array('table' => $tempTable, 'id' => $tempUid, 'tokenID' => $info['subst']['tokenID'])), $lines, $preCode_B, array(), '');
655 }
656 // Add files:
657 if ($info['subst']['type'] == 'file') {
658 $this->addFiles(array($info['file_ID']), $lines, $preCode_B, '', $info['subst']['tokenID']);
659 }
660 }
661 }
662 }
663
664 /**
665 * Add DB relations entries for a record's rels-array
666 *
667 * @param array $rels Array of relations
668 * @param array $lines Output lines array (is passed by reference and modified)
669 * @param string $preCode Pre-HTML code
670 * @param array $recurCheck Recursivity check stack
671 * @param string $htmlColorClass Alternative HTML color class to use.
672 * @return void
673 * @access private
674 * @see singleRecordLines()
675 */
676 public function addRelations($rels, &$lines, $preCode, $recurCheck = array(), $htmlColorClass = '')
677 {
678 foreach ($rels as $dat) {
679 $table = $dat['table'];
680 $uid = $dat['id'];
681 $pInfo = array();
682 $pInfo['ref'] = $table . ':' . $uid;
683 if (in_array($pInfo['ref'], $recurCheck)) {
684 continue;
685 }
686 $iconName = 'status-status-checked';
687 $iconClass = '';
688 $staticFixed = false;
689 $record = null;
690 if ($uid > 0) {
691 $record = $this->dat['header']['records'][$table][$uid];
692 if (!is_array($record)) {
693 if ($this->isTableStatic($table) || $this->isExcluded($table, $uid) || $dat['tokenID'] && !$this->includeSoftref($dat['tokenID'])) {
694 $pInfo['title'] = htmlspecialchars('STATIC: ' . $pInfo['ref']);
695 $iconClass = 'text-info';
696 $staticFixed = true;
697 } else {
698 $doesRE = $this->doesRecordExist($table, $uid);
699 $lostPath = $this->getRecordPath($table === 'pages' ? $doesRE['uid'] : $doesRE['pid']);
700 $pInfo['title'] = htmlspecialchars($pInfo['ref']);
701 $pInfo['title'] = '<span title="' . htmlspecialchars($lostPath) . '">' . $pInfo['title'] . '</span>';
702 $pInfo['msg'] = 'LOST RELATION' . (!$doesRE ? ' (Record not found!)' : ' (Path: ' . $lostPath . ')');
703 $iconClass = 'text-danger';
704 $iconName = 'status-dialog-warning';
705 }
706 } else {
707 $pInfo['title'] = htmlspecialchars($record['title']);
708 $pInfo['title'] = '<span title="' . htmlspecialchars($this->getRecordPath(($table === 'pages' ? $record['uid'] : $record['pid']))) . '">' . $pInfo['title'] . '</span>';
709 }
710 } else {
711 // Negative values in relation fields. This is typically sys_language fields, fe_users fields etc. They are static values. They CAN theoretically be negative pointers to uids in other tables but this is so rarely used that it is not supported
712 $pInfo['title'] = htmlspecialchars('FIXED: ' . $pInfo['ref']);
713 $staticFixed = true;
714 }
715
716 $icon = '<span class="' . $iconClass . '" title="' . htmlspecialchars($pInfo['ref']) . '">' . $this->iconFactory->getIcon($iconName, Icon::SIZE_SMALL)->render() . '</span>';
717
718 $pInfo['preCode'] = $preCode . '&nbsp;&nbsp;&nbsp;&nbsp;' . $icon;
719 $pInfo['type'] = 'rel';
720 if (!$staticFixed || $this->showStaticRelations) {
721 $lines[] = $pInfo;
722 if (is_array($record) && is_array($record['rels'])) {
723 $this->addRelations($record['rels'], $lines, $preCode . '&nbsp;&nbsp;', array_merge($recurCheck, array($pInfo['ref'])));
724 }
725 }
726 }
727 }
728
729 /**
730 * Add file relation entries for a record's rels-array
731 *
732 * @param array $rels Array of file IDs
733 * @param array $lines Output lines array (is passed by reference and modified)
734 * @param string $preCode Pre-HTML code
735 * @param string $htmlColorClass Alternative HTML color class to use.
736 * @param string $tokenID Token ID if this is a softreference (in which case it only makes sense with a single element in the $rels array!)
737 * @return void
738 * @access private
739 * @see singleRecordLines()
740 */
741 public function addFiles($rels, &$lines, $preCode, $htmlColorClass = '', $tokenID = '')
742 {
743 foreach ($rels as $ID) {
744 // Process file:
745 $pInfo = array();
746 $fI = $this->dat['header']['files'][$ID];
747 if (!is_array($fI)) {
748 if (!$tokenID || $this->includeSoftref($tokenID)) {
749 $pInfo['msg'] = 'MISSING FILE: ' . $ID;
750 $this->error('MISSING FILE: ' . $ID);
751 } else {
752 return;
753 }
754 }
755 $pInfo['preCode'] = $preCode . '&nbsp;&nbsp;&nbsp;&nbsp;' . $this->iconFactory->getIcon('status-status-reference-hard', Icon::SIZE_SMALL)->render();
756 $pInfo['title'] = htmlspecialchars($fI['filename']);
757 $pInfo['ref'] = 'FILE';
758 $pInfo['size'] = $fI['filesize'];
759 $pInfo['type'] = 'file';
760 // If import mode and there is a non-RTE softreference, check the destination directory:
761 if ($this->mode === 'import' && $tokenID && !$fI['RTE_ORIG_ID']) {
762 if (isset($fI['parentRelFileName'])) {
763 $pInfo['msg'] = 'Seems like this file is already referenced from within an HTML/CSS file. That takes precedence. ';
764 } else {
765 $testDirPrefix = PathUtility::dirname($fI['relFileName']) . '/';
766 $testDirPrefix2 = $this->verifyFolderAccess($testDirPrefix);
767 if (!$testDirPrefix2) {
768 $pInfo['msg'] = 'ERROR: There are no available filemounts to write file in! ';
769 } elseif ($testDirPrefix !== $testDirPrefix2) {
770 $pInfo['msg'] = 'File will be attempted written to "' . $testDirPrefix2 . '". ';
771 }
772 }
773 // Check if file exists:
774 if (file_exists(PATH_site . $fI['relFileName'])) {
775 if ($this->update) {
776 $pInfo['updatePath'] .= 'File exists.';
777 } else {
778 $pInfo['msg'] .= 'File already exists! ';
779 }
780 }
781 // Check extension:
782 $fileProcObj = $this->getFileProcObj();
783 if ($fileProcObj->actionPerms['addFile']) {
784 $testFI = GeneralUtility::split_fileref(PATH_site . $fI['relFileName']);
785 if (!$this->allowPHPScripts && !$fileProcObj->checkIfAllowed($testFI['fileext'], $testFI['path'], $testFI['file'])) {
786 $pInfo['msg'] .= 'File extension was not allowed!';
787 }
788 } else {
789 $pInfo['msg'] = 'You user profile does not allow you to create files on the server!';
790 }
791 }
792 $pInfo['showDiffContent'] = PathUtility::stripPathSitePrefix($this->fileIDMap[$ID]);
793 $lines[] = $pInfo;
794 unset($this->remainHeader['files'][$ID]);
795 // RTE originals:
796 if ($fI['RTE_ORIG_ID']) {
797 $ID = $fI['RTE_ORIG_ID'];
798 $pInfo = array();
799 $fI = $this->dat['header']['files'][$ID];
800 if (!is_array($fI)) {
801 $pInfo['msg'] = 'MISSING RTE original FILE: ' . $ID;
802 $this->error('MISSING RTE original FILE: ' . $ID);
803 }
804 $pInfo['showDiffContent'] = PathUtility::stripPathSitePrefix($this->fileIDMap[$ID]);
805 $pInfo['preCode'] = $preCode . '&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;' . $this->iconFactory->getIcon('status-status-reference-hard', Icon::SIZE_SMALL)->render();
806 $pInfo['title'] = htmlspecialchars($fI['filename']) . ' <em>(Original)</em>';
807 $pInfo['ref'] = 'FILE';
808 $pInfo['size'] = $fI['filesize'];
809 $pInfo['type'] = 'file';
810 $lines[] = $pInfo;
811 unset($this->remainHeader['files'][$ID]);
812 }
813 // External resources:
814 if (is_array($fI['EXT_RES_ID'])) {
815 foreach ($fI['EXT_RES_ID'] as $extID) {
816 $pInfo = array();
817 $fI = $this->dat['header']['files'][$extID];
818 if (!is_array($fI)) {
819 $pInfo['msg'] = 'MISSING External Resource FILE: ' . $extID;
820 $this->error('MISSING External Resource FILE: ' . $extID);
821 } else {
822 $pInfo['updatePath'] = $fI['parentRelFileName'];
823 }
824 $pInfo['showDiffContent'] = PathUtility::stripPathSitePrefix($this->fileIDMap[$extID]);
825 $pInfo['preCode'] = $preCode . '&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;' . $this->iconFactory->getIcon('actions-insert-reference', Icon::SIZE_SMALL)->render();
826 $pInfo['title'] = htmlspecialchars($fI['filename']) . ' <em>(Resource)</em>';
827 $pInfo['ref'] = 'FILE';
828 $pInfo['size'] = $fI['filesize'];
829 $pInfo['type'] = 'file';
830 $lines[] = $pInfo;
831 unset($this->remainHeader['files'][$extID]);
832 }
833 }
834 }
835 }
836
837 /**
838 * Verifies that a table is allowed on a certain doktype of a page
839 *
840 * @param string $checkTable Table name to check
841 * @param int $doktype doktype value.
842 * @return bool TRUE if OK
843 */
844 public function checkDokType($checkTable, $doktype)
845 {
846 $allowedTableList = isset($GLOBALS['PAGES_TYPES'][$doktype]['allowedTables']) ? $GLOBALS['PAGES_TYPES'][$doktype]['allowedTables'] : $GLOBALS['PAGES_TYPES']['default']['allowedTables'];
847 $allowedArray = GeneralUtility::trimExplode(',', $allowedTableList, true);
848 // If all tables or the table is listed as an allowed type, return TRUE
849 if (strstr($allowedTableList, '*') || in_array($checkTable, $allowedArray)) {
850 return true;
851 }
852 return false;
853 }
854
855 /**
856 * Render input controls for import or export
857 *
858 * @param array $r Configuration for element
859 * @return string HTML
860 */
861 public function renderControls($r)
862 {
863 if ($this->mode === 'export') {
864 if ($r['type'] === 'record') {
865 return '<input type="checkbox" class="t3js-exclude-checkbox" name="tx_impexp[exclude][' . $r['ref'] . ']" id="checkExclude' . $r['ref'] . '" value="1" /> <label for="checkExclude' . $r['ref'] . '">' . htmlspecialchars($this->getLanguageService()->getLL('impexpcore_singlereco_exclude')) . '</label>';
866 } else {
867 return $r['type'] == 'softref' ? $this->softrefSelector($r['_softRefInfo']) : '';
868 }
869 } else {
870 // During import
871 // For softreferences with editable fields:
872 if ($r['type'] == 'softref' && is_array($r['_softRefInfo']['subst']) && $r['_softRefInfo']['subst']['tokenID']) {
873 $tokenID = $r['_softRefInfo']['subst']['tokenID'];
874 $cfg = $this->softrefCfg[$tokenID];
875 if ($cfg['mode'] === 'editable') {
876 return (strlen($cfg['title']) ? '<strong>' . htmlspecialchars($cfg['title']) . '</strong><br/>' : '') . htmlspecialchars($cfg['description']) . '<br/>
877 <input type="text" name="tx_impexp[softrefInputValues][' . $tokenID . ']" value="' . htmlspecialchars((isset($this->softrefInputValues[$tokenID]) ? $this->softrefInputValues[$tokenID] : $cfg['defValue'])) . '" />';
878 }
879 }
880 }
881 return '';
882 }
883
884 /**
885 * Selectorbox with export options for soft references
886 *
887 * @param array $cfg Softref configuration array. An export box is shown only if a substitution scheme is found for the soft reference.
888 * @return string Selector box HTML
889 */
890 public function softrefSelector($cfg)
891 {
892 // Looking for file ID if any:
893 $fI = $cfg['file_ID'] ? $this->dat['header']['files'][$cfg['file_ID']] : array();
894 // Substitution scheme has to be around and RTE images MUST be exported.
895 if (is_array($cfg['subst']) && $cfg['subst']['tokenID'] && !$fI['RTE_ORIG_ID']) {
896 // Create options:
897 $optValues = array();
898 $optValues[''] = '';
899 $optValues['editable'] = $this->getLanguageService()->getLL('impexpcore_softrefsel_editable');
900 $optValues['exclude'] = $this->getLanguageService()->getLL('impexpcore_softrefsel_exclude');
901 // Get current value:
902 $value = $this->softrefCfg[$cfg['subst']['tokenID']]['mode'];
903 // Render options selector:
904 $selectorbox = $this->renderSelectBox(('tx_impexp[softrefCfg][' . $cfg['subst']['tokenID'] . '][mode]'), $value, $optValues) . '<br/>';
905 if ($value === 'editable') {
906 $descriptionField = '';
907 // Title:
908 if (strlen($cfg['subst']['title'])) {
909 $descriptionField .= '
910 <input type="hidden" name="tx_impexp[softrefCfg][' . $cfg['subst']['tokenID'] . '][title]" value="' . htmlspecialchars($cfg['subst']['title']) . '" />
911 <strong>' . htmlspecialchars($cfg['subst']['title']) . '</strong><br/>';
912 }
913 // Description:
914 if (!strlen($cfg['subst']['description'])) {
915 $descriptionField .= '
916 ' . htmlspecialchars($this->getLanguageService()->getLL('impexpcore_printerror_description')) . '<br/>
917 <input type="text" name="tx_impexp[softrefCfg][' . $cfg['subst']['tokenID'] . '][description]" value="' . htmlspecialchars($this->softrefCfg[$cfg['subst']['tokenID']]['description']) . '" />';
918 } else {
919 $descriptionField .= '
920
921 <input type="hidden" name="tx_impexp[softrefCfg][' . $cfg['subst']['tokenID'] . '][description]" value="' . htmlspecialchars($cfg['subst']['description']) . '" />' . htmlspecialchars($cfg['subst']['description']);
922 }
923 // Default Value:
924 $descriptionField .= '<input type="hidden" name="tx_impexp[softrefCfg][' . $cfg['subst']['tokenID'] . '][defValue]" value="' . htmlspecialchars($cfg['subst']['tokenValue']) . '" />';
925 } else {
926 $descriptionField = '';
927 }
928 return $selectorbox . $descriptionField;
929 }
930 return '';
931 }
932
933 /**
934 * Verifies that the input path (relative to PATH_site) is found in the backend users filemounts.
935 * If it doesn't it will try to find another relative filemount for the user and return an alternative path prefix for the file.
936 *
937 * @param string $dirPrefix Path relative to PATH_site
938 * @param bool $noAlternative If set, Do not look for alternative path! Just return FALSE
939 * @return string|bool If a path is available that will be returned, otherwise FALSE.
940 */
941 public function verifyFolderAccess($dirPrefix, $noAlternative = false)
942 {
943 $fileProcObj = $this->getFileProcObj();
944 // Check, if dirPrefix is inside a valid Filemount for user:
945 $result = $fileProcObj->checkPathAgainstMounts(PATH_site . $dirPrefix);
946 // If not, try to find another relative filemount and use that instead:
947 if (!$result) {
948 if ($noAlternative) {
949 return false;
950 }
951 // Find first web folder:
952 $result = $fileProcObj->findFirstWebFolder();
953 // If that succeeded, return the path to it:
954 if ($result) {
955 // Remove the "fileadmin/" prefix of input path - and append the rest to the return value:
956 if (GeneralUtility::isFirstPartOfStr($dirPrefix, $this->fileadminFolderName . '/')) {
957 $dirPrefix = substr($dirPrefix, strlen($this->fileadminFolderName . '/'));
958 }
959 return PathUtility::stripPathSitePrefix($fileProcObj->mounts[$result]['path'] . $dirPrefix);
960 }
961 } else {
962 return $dirPrefix;
963 }
964 return false;
965 }
966
967 /*****************************
968 * Helper functions of kinds
969 *****************************/
970
971 /**
972 *
973 * @return string
974 */
975 protected function getTemporaryFolderName()
976 {
977 $temporaryPath = PATH_site . 'typo3temp/var/transient/';
978 do {
979 $temporaryFolderName = $temporaryPath . 'export_temp_files_' . mt_rand(1, PHP_INT_MAX);
980 } while (is_dir($temporaryFolderName));
981 GeneralUtility::mkdir($temporaryFolderName);
982 return $temporaryFolderName;
983 }
984
985 /**
986 * Recursively flattening the idH array
987 *
988 * @param array $idH Page uid hierarchy
989 * @param array $a Accumulation array of pages (internal, don't set from outside)
990 * @return array Array with uid-uid pairs for all pages in the page tree.
991 * @see Import::flatInversePageTree_pid()
992 */
993 public function flatInversePageTree($idH, $a = array())
994 {
995 if (is_array($idH)) {
996 $idH = array_reverse($idH);
997 foreach ($idH as $k => $v) {
998 $a[$v['uid']] = $v['uid'];
999 if (is_array($v['subrow'])) {
1000 $a = $this->flatInversePageTree($v['subrow'], $a);
1001 }
1002 }
1003 }
1004 return $a;
1005 }
1006
1007 /**
1008 * Returns TRUE if the input table name is to be regarded as a static relation (that is, not exported etc).
1009 *
1010 * @param string $table Table name
1011 * @return bool TRUE, if table is marked static
1012 */
1013 public function isTableStatic($table)
1014 {
1015 if (is_array($GLOBALS['TCA'][$table])) {
1016 return $GLOBALS['TCA'][$table]['ctrl']['is_static'] || in_array($table, $this->relStaticTables) || in_array('_ALL', $this->relStaticTables);
1017 }
1018 return false;
1019 }
1020
1021 /**
1022 * Returns TRUE if the input table name is to be included as relation
1023 *
1024 * @param string $table Table name
1025 * @return bool TRUE, if table is marked static
1026 */
1027 public function inclRelation($table)
1028 {
1029 return is_array($GLOBALS['TCA'][$table])
1030 && (in_array($table, $this->relOnlyTables) || in_array('_ALL', $this->relOnlyTables))
1031 && $this->getBackendUser()->check('tables_select', $table);
1032 }
1033
1034 /**
1035 * Returns TRUE if the element should be excluded as static record.
1036 *
1037 * @param string $table Table name
1038 * @param int $uid UID value
1039 * @return bool TRUE, if table is marked static
1040 */
1041 public function isExcluded($table, $uid)
1042 {
1043 return (bool)$this->excludeMap[$table . ':' . $uid];
1044 }
1045
1046 /**
1047 * Returns TRUE if soft reference should be included in exported file.
1048 *
1049 * @param string $tokenID Token ID for soft reference
1050 * @return bool TRUE if softreference media should be included
1051 */
1052 public function includeSoftref($tokenID)
1053 {
1054 $mode = $this->softrefCfg[$tokenID]['mode'];
1055 return $tokenID && $mode !== 'exclude' && $mode !== 'editable';
1056 }
1057
1058 /**
1059 * Checking if a PID is in the webmounts of the user
1060 *
1061 * @param int $pid Page ID to check
1062 * @return bool TRUE if OK
1063 */
1064 public function checkPID($pid)
1065 {
1066 if (!isset($this->checkPID_cache[$pid])) {
1067 $this->checkPID_cache[$pid] = (bool)$this->getBackendUser()->isInWebMount($pid);
1068 }
1069 return $this->checkPID_cache[$pid];
1070 }
1071
1072 /**
1073 * Checks if the position of an updated record is configured to be corrected. This can be disabled globally and changed for elements individually.
1074 *
1075 * @param string $table Table name
1076 * @param int $uid Uid or record
1077 * @return bool TRUE if the position of the record should be updated to match the one in the import structure
1078 */
1079 public function dontIgnorePid($table, $uid)
1080 {
1081 return $this->import_mode[$table . ':' . $uid] !== 'ignore_pid' && (!$this->global_ignore_pid || $this->import_mode[$table . ':' . $uid] === 'respect_pid');
1082 }
1083
1084 /**
1085 * Checks if the record exists
1086 *
1087 * @param string $table Table name
1088 * @param int $uid UID of record
1089 * @param string $fields Field list to select. Default is "uid,pid
1090 * @return array Result of \TYPO3\CMS\Backend\Utility\BackendUtility::getRecord() which means the record if found, otherwise FALSE
1091 */
1092 public function doesRecordExist($table, $uid, $fields = '')
1093 {
1094 return BackendUtility::getRecord($table, $uid, $fields ? $fields : 'uid,pid');
1095 }
1096
1097 /**
1098 * Returns the page title path of a PID value. Results are cached internally
1099 *
1100 * @param int $pid Record PID to check
1101 * @return string The path for the input PID
1102 */
1103 public function getRecordPath($pid)
1104 {
1105 if (!isset($this->cache_getRecordPath[$pid])) {
1106 $clause = $this->getBackendUser()->getPagePermsClause(1);
1107 $this->cache_getRecordPath[$pid] = (string)BackendUtility::getRecordPath($pid, $clause, 20);
1108 }
1109 return $this->cache_getRecordPath[$pid];
1110 }
1111
1112 /**
1113 * Makes a selector-box from optValues
1114 *
1115 * @param string $prefix Form element name
1116 * @param string $value Current value
1117 * @param array $optValues Options to display (key/value pairs)
1118 * @return string HTML select element
1119 */
1120 public function renderSelectBox($prefix, $value, $optValues)
1121 {
1122 $opt = array();
1123 $isSelFlag = 0;
1124 foreach ($optValues as $k => $v) {
1125 $sel = (string)$k === (string)$value ? ' selected="selected"' : '';
1126 if ($sel) {
1127 $isSelFlag++;
1128 }
1129 $opt[] = '<option value="' . htmlspecialchars($k) . '"' . $sel . '>' . htmlspecialchars($v) . '</option>';
1130 }
1131 if (!$isSelFlag && (string)$value !== '') {
1132 $opt[] = '<option value="' . htmlspecialchars($value) . '" selected="selected">' . htmlspecialchars(('[\'' . $value . '\']')) . '</option>';
1133 }
1134 return '<select name="' . $prefix . '">' . implode('', $opt) . '</select>';
1135 }
1136
1137 /**
1138 * Compares two records, the current database record and the one from the import memory.
1139 * Will return HTML code to show any differences between them!
1140 *
1141 * @param array $databaseRecord Database record, all fields (new values)
1142 * @param array $importRecord Import memorys record for the same table/uid, all fields (old values)
1143 * @param string $table The table name of the record
1144 * @param bool $inverseDiff Inverse the diff view (switch red/green, needed for pre-update difference view)
1145 * @return string HTML
1146 */
1147 public function compareRecords($databaseRecord, $importRecord, $table, $inverseDiff = false)
1148 {
1149 // Initialize:
1150 $output = array();
1151 $diffUtility = GeneralUtility::makeInstance(DiffUtility::class);
1152 // Check if both inputs are records:
1153 if (is_array($databaseRecord) && is_array($importRecord)) {
1154 // Traverse based on database record
1155 foreach ($databaseRecord as $fN => $value) {
1156 if (is_array($GLOBALS['TCA'][$table]['columns'][$fN]) && $GLOBALS['TCA'][$table]['columns'][$fN]['config']['type'] != 'passthrough') {
1157 if (isset($importRecord[$fN])) {
1158 if (trim($databaseRecord[$fN]) !== trim($importRecord[$fN])) {
1159 // Create diff-result:
1160 $output[$fN] = $diffUtility->makeDiffDisplay(BackendUtility::getProcessedValue($table, $fN, !$inverseDiff ? $importRecord[$fN] : $databaseRecord[$fN], 0, 1, 1), BackendUtility::getProcessedValue($table, $fN, !$inverseDiff ? $databaseRecord[$fN] : $importRecord[$fN], 0, 1, 1));
1161 }
1162 unset($importRecord[$fN]);
1163 }
1164 }
1165 }
1166 // Traverse remaining in import record:
1167 foreach ($importRecord as $fN => $value) {
1168 if (is_array($GLOBALS['TCA'][$table]['columns'][$fN]) && $GLOBALS['TCA'][$table]['columns'][$fN]['config']['type'] !== 'passthrough') {
1169 $output[$fN] = '<strong>Field missing</strong> in database';
1170 }
1171 }
1172 // Create output:
1173 if (!empty($output)) {
1174 $tRows = array();
1175 foreach ($output as $fN => $state) {
1176 $tRows[] = '
1177 <tr>
1178 <td>' . $this->getLanguageService()->sL($GLOBALS['TCA'][$table]['columns'][$fN]['label'], true) . ' (' . htmlspecialchars($fN) . ')</td>
1179 <td>' . $state . '</td>
1180 </tr>
1181 ';
1182 }
1183 $output = '<table class="table table-striped table-hover">' . implode('', $tRows) . '</table>';
1184 } else {
1185 $output = 'Match';
1186 }
1187 return '<strong class="text-nowrap">[' . htmlspecialchars(($table . ':' . $importRecord['uid'] . ' => ' . $databaseRecord['uid'])) . ']:</strong> ' . $output;
1188 }
1189 return 'ERROR: One of the inputs were not an array!';
1190 }
1191
1192 /**
1193 * Creates the original file name for a copy-RTE image (magic type)
1194 *
1195 * @param string $string RTE copy filename, eg. "RTEmagicC_user_pm_icon_01.gif.gif
1196 * @return string|NULL RTE original filename, eg. "RTEmagicP_user_pm_icon_01.gif". If the input filename was NOT prefixed RTEmagicC_ as RTE images would be, NULL is returned!
1197 */
1198 public function getRTEoriginalFilename($string)
1199 {
1200 // If "magic image":
1201 if (GeneralUtility::isFirstPartOfStr($string, 'RTEmagicC_')) {
1202 // Find original file:
1203 $pI = pathinfo(substr($string, strlen('RTEmagicC_')));
1204 $filename = substr($pI['basename'], 0, -strlen(('.' . $pI['extension'])));
1205 $origFilePath = 'RTEmagicP_' . $filename;
1206 return $origFilePath;
1207 }
1208 return null;
1209 }
1210
1211 /**
1212 * Returns file processing object, initialized only once.
1213 *
1214 * @return ExtendedFileUtility File processor object
1215 */
1216 public function getFileProcObj()
1217 {
1218 if ($this->fileProcObj === null) {
1219 $this->fileProcObj = GeneralUtility::makeInstance(ExtendedFileUtility::class);
1220 $this->fileProcObj->init(array(), $GLOBALS['TYPO3_CONF_VARS']['BE']['fileExtensions']);
1221 $this->fileProcObj->setActionPermissions();
1222 }
1223 return $this->fileProcObj;
1224 }
1225
1226 /**
1227 * Call Hook
1228 *
1229 * @param string $name Name of the hook
1230 * @param array $params Array with params
1231 * @return void
1232 */
1233 public function callHook($name, $params)
1234 {
1235 if (is_array($GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['ext/impexp/class.tx_impexp.php'][$name])) {
1236 foreach ($GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['ext/impexp/class.tx_impexp.php'][$name] as $hook) {
1237 GeneralUtility::callUserFunction($hook, $params, $this);
1238 }
1239 }
1240 }
1241
1242 /**
1243 * Set flag to control whether disabled records and their children are excluded (true) or included (false). Defaults
1244 * to the old behaviour of including everything.
1245 *
1246 * @param bool $excludeDisabledRecords Set to true if if all disabled records should be excluded, false otherwise
1247 * @return \TYPO3\CMS\Impexp\ImportExport $this for fluent calls
1248 */
1249 public function setExcludeDisabledRecords($excludeDisabledRecords = false)
1250 {
1251 $this->excludeDisabledRecords = $excludeDisabledRecords;
1252 return $this;
1253 }
1254
1255 /*****************************
1256 * Error handling
1257 *****************************/
1258
1259 /**
1260 * Sets error message in the internal error log
1261 *
1262 * @param string $msg Error message
1263 * @return void
1264 */
1265 public function error($msg)
1266 {
1267 $this->errorLog[] = $msg;
1268 }
1269
1270 /**
1271 * Returns a table with the error-messages.
1272 *
1273 * @return string HTML print of error log
1274 */
1275 public function printErrorLog()
1276 {
1277 return !empty($this->errorLog) ? DebugUtility::viewArray($this->errorLog) : '';
1278 }
1279
1280 /**
1281 * @return BackendUserAuthentication
1282 */
1283 protected function getBackendUser()
1284 {
1285 return $GLOBALS['BE_USER'];
1286 }
1287
1288 /**
1289 * @return DatabaseConnection
1290 */
1291 protected function getDatabaseConnection()
1292 {
1293 return $GLOBALS['TYPO3_DB'];
1294 }
1295
1296 /**
1297 * @return LanguageService
1298 */
1299 protected function getLanguageService()
1300 {
1301 return $GLOBALS['LANG'];
1302 }
1303 }