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