[FOLLOWUP][TASK] Import/Export (impexp) move to Fluid standalone view
[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 * The constructor
257 */
258 public function __construct()
259 {
260 $this->iconFactory = GeneralUtility::makeInstance(IconFactory::class);
261 }
262
263 /**************************
264 * Initialize
265 *************************/
266
267 /**
268 * Init the object, both import and export
269 *
270 * @return void
271 */
272 public function init()
273 {
274 $this->compress = function_exists('gzcompress');
275 $this->fileadminFolderName = !empty($GLOBALS['TYPO3_CONF_VARS']['BE']['fileadminDir']) ? rtrim($GLOBALS['TYPO3_CONF_VARS']['BE']['fileadminDir'], '/') : 'fileadmin';
276 }
277
278 /********************************************************
279 * Visual rendering of import/export memory, $this->dat
280 ********************************************************/
281
282 /**
283 * Displays an overview of the header-content.
284 *
285 * @return array The view data
286 */
287 public function displayContentOverview()
288 {
289 // Check extension dependencies:
290 if (is_array($this->dat['header']['extensionDependencies'])) {
291 foreach ($this->dat['header']['extensionDependencies'] as $extKey) {
292 if (!ExtensionManagementUtility::isLoaded($extKey)) {
293 $this->error('DEPENDENCY: The extension with key "' . $extKey . '" must be installed!');
294 }
295 }
296 }
297 // Probably this is done to save memory space?
298 unset($this->dat['files']);
299
300 $viewData = array();
301 // Traverse header:
302 if (is_array($this->dat['header'])) {
303 $this->remainHeader = $this->dat['header'];
304 // If there is a page tree set, show that:
305 if (is_array($this->dat['header']['pagetree'])) {
306 reset($this->dat['header']['pagetree']);
307 $lines = array();
308 $this->traversePageTree($this->dat['header']['pagetree'], $lines);
309
310 $viewData['dat'] = $this->dat;
311 $viewData['update'] = $this->update;
312 $viewData['showDiff'] = $this->showDiff;
313 if (!empty($lines)) {
314 foreach ($lines as &$r) {
315 $r['controls'] = $this->renderControls($r);
316 $r['fileSize'] = GeneralUtility::formatSize($r['size']);
317 $r['message'] = ($r['msg'] && !$this->doesImport ? '<span class="text-danger">' . htmlspecialchars($r['msg']) . '</span>' : '');
318 }
319 $viewData['pagetreeLines'] = $lines;
320 } else {
321 $viewData['pagetreeLines'] = array();
322 }
323 }
324 // Print remaining records that were not contained inside the page tree:
325 if (is_array($this->remainHeader['records'])) {
326 $lines = array();
327 if (is_array($this->remainHeader['records']['pages'])) {
328 $this->traversePageRecords($this->remainHeader['records']['pages'], $lines);
329 }
330 $this->traverseAllRecords($this->remainHeader['records'], $lines);
331 if (!empty($lines)) {
332 foreach ($lines as &$r) {
333 $r['controls'] = $this->renderControls($r);
334 $r['fileSize'] = GeneralUtility::formatSize($r['size']);
335 $r['message'] = ($r['msg'] && !$this->doesImport ? '<span class="text-danger">' . htmlspecialchars($r['msg']) . '</span>' : '');
336 }
337 $viewData['remainingRecords'] = $lines;
338 }
339 }
340 }
341
342 return $viewData;
343 }
344
345 /**
346 * Go through page tree for display
347 *
348 * @param array $pT Page tree array with uid/subrow (from ->dat[header][pagetree]
349 * @param array $lines Output lines array (is passed by reference and modified)
350 * @param string $preCode Pre-HTML code
351 * @return void
352 */
353 public function traversePageTree($pT, &$lines, $preCode = '')
354 {
355 foreach ($pT as $k => $v) {
356 // Add this page:
357 $this->singleRecordLines('pages', $k, $lines, $preCode);
358 // Subrecords:
359 if (is_array($this->dat['header']['pid_lookup'][$k])) {
360 foreach ($this->dat['header']['pid_lookup'][$k] as $t => $recUidArr) {
361 if ($t != 'pages') {
362 foreach ($recUidArr as $ruid => $value) {
363 $this->singleRecordLines($t, $ruid, $lines, $preCode . '&nbsp;&nbsp;&nbsp;&nbsp;');
364 }
365 }
366 }
367 unset($this->remainHeader['pid_lookup'][$k]);
368 }
369 // Subpages, called recursively:
370 if (is_array($v['subrow'])) {
371 $this->traversePageTree($v['subrow'], $lines, $preCode . '&nbsp;&nbsp;&nbsp;&nbsp;');
372 }
373 }
374 }
375
376 /**
377 * Go through remaining pages (not in tree)
378 *
379 * @param array $pT Page tree array with uid/subrow (from ->dat[header][pagetree]
380 * @param array $lines Output lines array (is passed by reference and modified)
381 * @return void
382 */
383 public function traversePageRecords($pT, &$lines)
384 {
385 foreach ($pT as $k => $rHeader) {
386 $this->singleRecordLines('pages', $k, $lines, '', 1);
387 // Subrecords:
388 if (is_array($this->dat['header']['pid_lookup'][$k])) {
389 foreach ($this->dat['header']['pid_lookup'][$k] as $t => $recUidArr) {
390 if ($t != 'pages') {
391 foreach ($recUidArr as $ruid => $value) {
392 $this->singleRecordLines($t, $ruid, $lines, '&nbsp;&nbsp;&nbsp;&nbsp;');
393 }
394 }
395 }
396 unset($this->remainHeader['pid_lookup'][$k]);
397 }
398 }
399 }
400
401 /**
402 * Go through ALL records (if the pages are displayed first, those will not be amoung these!)
403 *
404 * @param array $pT Page tree array with uid/subrow (from ->dat[header][pagetree]
405 * @param array $lines Output lines array (is passed by reference and modified)
406 * @return void
407 */
408 public function traverseAllRecords($pT, &$lines)
409 {
410 foreach ($pT as $t => $recUidArr) {
411 $this->addGeneralErrorsByTable($t);
412 if ($t != 'pages') {
413 $preCode = '';
414 foreach ($recUidArr as $ruid => $value) {
415 $this->singleRecordLines($t, $ruid, $lines, $preCode, 1);
416 }
417 }
418 }
419 }
420
421 /**
422 * Log general error message for a given table
423 *
424 * @param string $table database table name
425 * @return void
426 */
427 protected function addGeneralErrorsByTable($table)
428 {
429 if ($this->update && $table === 'sys_file') {
430 $this->error('Updating sys_file records is not supported! They will be imported as new records!');
431 }
432 if ($this->force_all_UIDS && $table === 'sys_file') {
433 $this->error('Forcing uids of sys_file records is not supported! They will be imported as new records!');
434 }
435 }
436
437 /**
438 * Add entries for a single record
439 *
440 * @param string $table Table name
441 * @param int $uid Record uid
442 * @param array $lines Output lines array (is passed by reference and modified)
443 * @param string $preCode Pre-HTML code
444 * @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.
445 * @return void
446 */
447 public function singleRecordLines($table, $uid, &$lines, $preCode, $checkImportInPidRecord = false)
448 {
449 // Get record:
450 $record = $this->dat['header']['records'][$table][$uid];
451 unset($this->remainHeader['records'][$table][$uid]);
452 if (!is_array($record) && !($table === 'pages' && !$uid)) {
453 $this->error('MISSING RECORD: ' . $table . ':' . $uid);
454 }
455 // Begin to create the line arrays information record, pInfo:
456 $pInfo = array();
457 $pInfo['ref'] = $table . ':' . $uid;
458 // Unknown table name:
459 $lang = $this->getLanguageService();
460 if ($table === '_SOFTREF_') {
461 $pInfo['preCode'] = $preCode;
462 $pInfo['title'] = '<em>' . $lang->getLL('impexpcore_singlereco_softReferencesFiles', true) . '</em>';
463 } elseif (!isset($GLOBALS['TCA'][$table])) {
464 // Unknown table name:
465 $pInfo['preCode'] = $preCode;
466 $pInfo['msg'] = 'UNKNOWN TABLE \'' . $pInfo['ref'] . '\'';
467 $pInfo['title'] = '<em>' . htmlspecialchars($record['title']) . '</em>';
468 } else {
469 // Otherwise, set table icon and title.
470 // Import Validation (triggered by $this->display_import_pid_record) will show messages if import is not possible of various items.
471 if (is_array($this->display_import_pid_record) && !empty($this->display_import_pid_record)) {
472 if ($checkImportInPidRecord) {
473 if (!$this->getBackendUser()->doesUserHaveAccess($this->display_import_pid_record, ($table === 'pages' ? 8 : 16))) {
474 $pInfo['msg'] .= '\'' . $pInfo['ref'] . '\' cannot be INSERTED on this page! ';
475 }
476 if (!$this->checkDokType($table, $this->display_import_pid_record['doktype']) && !$GLOBALS['TCA'][$table]['ctrl']['rootLevel']) {
477 $pInfo['msg'] .= '\'' . $table . '\' cannot be INSERTED on this page type (change page type to \'Folder\'.) ';
478 }
479 }
480 if (!$this->getBackendUser()->check('tables_modify', $table)) {
481 $pInfo['msg'] .= 'You are not allowed to CREATE \'' . $table . '\' tables! ';
482 }
483 if ($GLOBALS['TCA'][$table]['ctrl']['readOnly']) {
484 $pInfo['msg'] .= 'TABLE \'' . $table . '\' is READ ONLY! ';
485 }
486 if ($GLOBALS['TCA'][$table]['ctrl']['adminOnly'] && !$this->getBackendUser()->isAdmin()) {
487 $pInfo['msg'] .= 'TABLE \'' . $table . '\' is ADMIN ONLY! ';
488 }
489 if ($GLOBALS['TCA'][$table]['ctrl']['is_static']) {
490 $pInfo['msg'] .= 'TABLE \'' . $table . '\' is a STATIC TABLE! ';
491 }
492 if ((int)$GLOBALS['TCA'][$table]['ctrl']['rootLevel'] === 1) {
493 $pInfo['msg'] .= 'TABLE \'' . $table . '\' will be inserted on ROOT LEVEL! ';
494 }
495 $diffInverse = false;
496 $recInf = null;
497 if ($this->update) {
498 // In case of update-PREVIEW we swap the diff-sources.
499 $diffInverse = true;
500 $recInf = $this->doesRecordExist($table, $uid, $this->showDiff ? '*' : '');
501 $pInfo['updatePath'] = $recInf ? htmlspecialchars($this->getRecordPath($recInf['pid'])) : '<strong>NEW!</strong>';
502 // Mode selector:
503 $optValues = array();
504 $optValues[] = $recInf ? $lang->getLL('impexpcore_singlereco_update') : $lang->getLL('impexpcore_singlereco_insert');
505 if ($recInf) {
506 $optValues['as_new'] = $lang->getLL('impexpcore_singlereco_importAsNew');
507 }
508 if ($recInf) {
509 if (!$this->global_ignore_pid) {
510 $optValues['ignore_pid'] = $lang->getLL('impexpcore_singlereco_ignorePid');
511 } else {
512 $optValues['respect_pid'] = $lang->getLL('impexpcore_singlereco_respectPid');
513 }
514 }
515 if (!$recInf && $this->getBackendUser()->isAdmin()) {
516 $optValues['force_uid'] = sprintf($lang->getLL('impexpcore_singlereco_forceUidSAdmin'), $uid);
517 }
518 $optValues['exclude'] = $lang->getLL('impexpcore_singlereco_exclude');
519 if ($table === 'sys_file') {
520 $pInfo['updateMode'] = '';
521 } else {
522 $pInfo['updateMode'] = $this->renderSelectBox('tx_impexp[import_mode][' . $table . ':' . $uid . ']', $this->import_mode[$table . ':' . $uid], $optValues);
523 }
524 }
525 // Diff view:
526 if ($this->showDiff) {
527 // For IMPORTS, get new id:
528 if ($newUid = $this->import_mapId[$table][$uid]) {
529 $diffInverse = false;
530 $recInf = $this->doesRecordExist($table, $newUid, '*');
531 BackendUtility::workspaceOL($table, $recInf);
532 }
533 if (is_array($recInf)) {
534 $pInfo['showDiffContent'] = $this->compareRecords($recInf, $this->dat['records'][$table . ':' . $uid]['data'], $table, $diffInverse);
535 }
536 }
537 }
538 $pInfo['preCode'] = $preCode . '<span title="' . htmlspecialchars($table . ':' . $uid) . '">'
539 . $this->iconFactory->getIconForRecord($table, (array)$this->dat['records'][$table . ':' . $uid]['data'], Icon::SIZE_SMALL)->render()
540 . '</span>';
541 $pInfo['title'] = htmlspecialchars($record['title']);
542 // View page:
543 if ($table === 'pages') {
544 $viewID = $this->mode === 'export' ? $uid : ($this->doesImport ? $this->import_mapId['pages'][$uid] : 0);
545 if ($viewID) {
546 $pInfo['title'] = '<a href="#" onclick="' . htmlspecialchars(BackendUtility::viewOnClick($viewID)) . 'return false;">' . $pInfo['title'] . '</a>';
547 }
548 }
549 }
550 $pInfo['class'] = $table == 'pages' ? 'bgColor4-20' : 'bgColor4';
551 $pInfo['type'] = 'record';
552 $pInfo['size'] = $record['size'];
553 $lines[] = $pInfo;
554 // File relations:
555 if (is_array($record['filerefs'])) {
556 $this->addFiles($record['filerefs'], $lines, $preCode);
557 }
558 // DB relations
559 if (is_array($record['rels'])) {
560 $this->addRelations($record['rels'], $lines, $preCode);
561 }
562 // Soft ref
563 if (!empty($record['softrefs'])) {
564 $preCode_A = $preCode . '&nbsp;&nbsp;&nbsp;&nbsp;';
565 $preCode_B = $preCode . '&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;';
566 foreach ($record['softrefs'] as $info) {
567 $pInfo = array();
568 $pInfo['preCode'] = $preCode_A . $this->iconFactory->getIcon('status-status-reference-soft', Icon::SIZE_SMALL)->render();
569 $pInfo['title'] = '<em>' . $info['field'] . ', "' . $info['spKey'] . '" </em>: <span title="' . htmlspecialchars($info['matchString']) . '">' . htmlspecialchars(GeneralUtility::fixed_lgd_cs($info['matchString'], 60)) . '</span>';
570 if ($info['subst']['type']) {
571 if (strlen($info['subst']['title'])) {
572 $pInfo['title'] .= '<br/>' . $preCode_B . '<strong>' . $lang->getLL('impexpcore_singlereco_title', true) . '</strong> ' . htmlspecialchars(GeneralUtility::fixed_lgd_cs($info['subst']['title'], 60));
573 }
574 if (strlen($info['subst']['description'])) {
575 $pInfo['title'] .= '<br/>' . $preCode_B . '<strong>' . $lang->getLL('impexpcore_singlereco_descr', true) . '</strong> ' . htmlspecialchars(GeneralUtility::fixed_lgd_cs($info['subst']['description'], 60));
576 }
577 $pInfo['title'] .= '<br/>' . $preCode_B . ($info['subst']['type'] == 'file' ? $lang->getLL('impexpcore_singlereco_filename', true) . ' <strong>' . $info['subst']['relFileName'] . '</strong>' : '') . ($info['subst']['type'] == 'string' ? $lang->getLL('impexpcore_singlereco_value', true) . ' <strong>' . $info['subst']['tokenValue'] . '</strong>' : '') . ($info['subst']['type'] == 'db' ? $lang->getLL('impexpcore_softrefsel_record', true) . ' <strong>' . $info['subst']['recordRef'] . '</strong>' : '');
578 }
579 $pInfo['ref'] = 'SOFTREF';
580 $pInfo['size'] = '';
581 $pInfo['class'] = 'bgColor3';
582 $pInfo['type'] = 'softref';
583 $pInfo['_softRefInfo'] = $info;
584 $pInfo['type'] = 'softref';
585 $mode = $this->softrefCfg[$info['subst']['tokenID']]['mode'];
586 if ($info['error'] && $mode !== 'editable' && $mode !== 'exclude') {
587 $pInfo['msg'] .= $info['error'];
588 }
589 $lines[] = $pInfo;
590 // Add relations:
591 if ($info['subst']['type'] == 'db') {
592 list($tempTable, $tempUid) = explode(':', $info['subst']['recordRef']);
593 $this->addRelations(array(array('table' => $tempTable, 'id' => $tempUid, 'tokenID' => $info['subst']['tokenID'])), $lines, $preCode_B, array(), '');
594 }
595 // Add files:
596 if ($info['subst']['type'] == 'file') {
597 $this->addFiles(array($info['file_ID']), $lines, $preCode_B, '', $info['subst']['tokenID']);
598 }
599 }
600 }
601 }
602
603 /**
604 * Add DB relations entries for a record's rels-array
605 *
606 * @param array $rels Array of relations
607 * @param array $lines Output lines array (is passed by reference and modified)
608 * @param string $preCode Pre-HTML code
609 * @param array $recurCheck Recursivity check stack
610 * @param string $htmlColorClass Alternative HTML color class to use.
611 * @return void
612 * @access private
613 * @see singleRecordLines()
614 */
615 public function addRelations($rels, &$lines, $preCode, $recurCheck = array(), $htmlColorClass = '')
616 {
617 foreach ($rels as $dat) {
618 $table = $dat['table'];
619 $uid = $dat['id'];
620 $pInfo = array();
621 $pInfo['ref'] = $table . ':' . $uid;
622 if (in_array($pInfo['ref'], $recurCheck)) {
623 continue;
624 }
625 $iconName = 'status-status-checked';
626 $iconClass = '';
627 $staticFixed = false;
628 $record = null;
629 if ($uid > 0) {
630 $record = $this->dat['header']['records'][$table][$uid];
631 if (!is_array($record)) {
632 if ($this->isTableStatic($table) || $this->isExcluded($table, $uid) || $dat['tokenID'] && !$this->includeSoftref($dat['tokenID'])) {
633 $pInfo['title'] = htmlspecialchars('STATIC: ' . $pInfo['ref']);
634 $iconClass = 'text-info';
635 $staticFixed = true;
636 } else {
637 $doesRE = $this->doesRecordExist($table, $uid);
638 $lostPath = $this->getRecordPath($table === 'pages' ? $doesRE['uid'] : $doesRE['pid']);
639 $pInfo['title'] = htmlspecialchars($pInfo['ref']);
640 $pInfo['title'] = '<span title="' . htmlspecialchars($lostPath) . '">' . $pInfo['title'] . '</span>';
641 $pInfo['msg'] = 'LOST RELATION' . (!$doesRE ? ' (Record not found!)' : ' (Path: ' . $lostPath . ')');
642 $iconClass = 'text-danger';
643 $iconName = 'status-dialog-warning';
644 }
645 } else {
646 $pInfo['title'] = htmlspecialchars($record['title']);
647 $pInfo['title'] = '<span title="' . htmlspecialchars($this->getRecordPath(($table === 'pages' ? $record['uid'] : $record['pid']))) . '">' . $pInfo['title'] . '</span>';
648 }
649 } else {
650 // 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
651 $pInfo['title'] = htmlspecialchars('FIXED: ' . $pInfo['ref']);
652 $staticFixed = true;
653 }
654
655 $icon = '<span class="' . $iconClass . '" title="' . htmlspecialchars($pInfo['ref']) . '">' . $this->iconFactory->getIcon($iconName, Icon::SIZE_SMALL)->render() . '</span>';
656
657 $pInfo['preCode'] = $preCode . '&nbsp;&nbsp;&nbsp;&nbsp;' . $icon;
658 $pInfo['class'] = $htmlColorClass ?: 'bgColor3';
659 $pInfo['type'] = 'rel';
660 if (!$staticFixed || $this->showStaticRelations) {
661 $lines[] = $pInfo;
662 if (is_array($record) && is_array($record['rels'])) {
663 $this->addRelations($record['rels'], $lines, $preCode . '&nbsp;&nbsp;', array_merge($recurCheck, array($pInfo['ref'])), $htmlColorClass);
664 }
665 }
666 }
667 }
668
669 /**
670 * Add file relation entries for a record's rels-array
671 *
672 * @param array $rels Array of file IDs
673 * @param array $lines Output lines array (is passed by reference and modified)
674 * @param string $preCode Pre-HTML code
675 * @param string $htmlColorClass Alternative HTML color class to use.
676 * @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!)
677 * @return void
678 * @access private
679 * @see singleRecordLines()
680 */
681 public function addFiles($rels, &$lines, $preCode, $htmlColorClass = '', $tokenID = '')
682 {
683 foreach ($rels as $ID) {
684 // Process file:
685 $pInfo = array();
686 $fI = $this->dat['header']['files'][$ID];
687 if (!is_array($fI)) {
688 if (!$tokenID || $this->includeSoftref($tokenID)) {
689 $pInfo['msg'] = 'MISSING FILE: ' . $ID;
690 $this->error('MISSING FILE: ' . $ID);
691 } else {
692 return;
693 }
694 }
695 $pInfo['preCode'] = $preCode . '&nbsp;&nbsp;&nbsp;&nbsp;' . $this->iconFactory->getIcon('status-status-reference-hard', Icon::SIZE_SMALL)->render();
696 $pInfo['title'] = htmlspecialchars($fI['filename']);
697 $pInfo['ref'] = 'FILE';
698 $pInfo['size'] = $fI['filesize'];
699 $pInfo['class'] = $htmlColorClass ?: 'bgColor3';
700 $pInfo['type'] = 'file';
701 // If import mode and there is a non-RTE softreference, check the destination directory:
702 if ($this->mode === 'import' && $tokenID && !$fI['RTE_ORIG_ID']) {
703 if (isset($fI['parentRelFileName'])) {
704 $pInfo['msg'] = 'Seems like this file is already referenced from within an HTML/CSS file. That takes precedence. ';
705 } else {
706 $testDirPrefix = PathUtility::dirname($fI['relFileName']) . '/';
707 $testDirPrefix2 = $this->verifyFolderAccess($testDirPrefix);
708 if (!$testDirPrefix2) {
709 $pInfo['msg'] = 'ERROR: There are no available filemounts to write file in! ';
710 } elseif ($testDirPrefix !== $testDirPrefix2) {
711 $pInfo['msg'] = 'File will be attempted written to "' . $testDirPrefix2 . '". ';
712 }
713 }
714 // Check if file exists:
715 if (file_exists(PATH_site . $fI['relFileName'])) {
716 if ($this->update) {
717 $pInfo['updatePath'] .= 'File exists.';
718 } else {
719 $pInfo['msg'] .= 'File already exists! ';
720 }
721 }
722 // Check extension:
723 $fileProcObj = $this->getFileProcObj();
724 if ($fileProcObj->actionPerms['addFile']) {
725 $testFI = GeneralUtility::split_fileref(PATH_site . $fI['relFileName']);
726 if (!$this->allowPHPScripts && !$fileProcObj->checkIfAllowed($testFI['fileext'], $testFI['path'], $testFI['file'])) {
727 $pInfo['msg'] .= 'File extension was not allowed!';
728 }
729 } else {
730 $pInfo['msg'] = 'You user profile does not allow you to create files on the server!';
731 }
732 }
733 $pInfo['showDiffContent'] = PathUtility::stripPathSitePrefix($this->fileIDMap[$ID]);
734 $lines[] = $pInfo;
735 unset($this->remainHeader['files'][$ID]);
736 // RTE originals:
737 if ($fI['RTE_ORIG_ID']) {
738 $ID = $fI['RTE_ORIG_ID'];
739 $pInfo = array();
740 $fI = $this->dat['header']['files'][$ID];
741 if (!is_array($fI)) {
742 $pInfo['msg'] = 'MISSING RTE original FILE: ' . $ID;
743 $this->error('MISSING RTE original FILE: ' . $ID);
744 }
745 $pInfo['showDiffContent'] = PathUtility::stripPathSitePrefix($this->fileIDMap[$ID]);
746 $pInfo['preCode'] = $preCode . '&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;' . $this->iconFactory->getIcon('status-status-reference-hard', Icon::SIZE_SMALL)->render();
747 $pInfo['title'] = htmlspecialchars($fI['filename']) . ' <em>(Original)</em>';
748 $pInfo['ref'] = 'FILE';
749 $pInfo['size'] = $fI['filesize'];
750 $pInfo['class'] = $htmlColorClass ?: 'bgColor3';
751 $pInfo['type'] = 'file';
752 $lines[] = $pInfo;
753 unset($this->remainHeader['files'][$ID]);
754 }
755 // External resources:
756 if (is_array($fI['EXT_RES_ID'])) {
757 foreach ($fI['EXT_RES_ID'] as $extID) {
758 $pInfo = array();
759 $fI = $this->dat['header']['files'][$extID];
760 if (!is_array($fI)) {
761 $pInfo['msg'] = 'MISSING External Resource FILE: ' . $extID;
762 $this->error('MISSING External Resource FILE: ' . $extID);
763 } else {
764 $pInfo['updatePath'] = $fI['parentRelFileName'];
765 }
766 $pInfo['showDiffContent'] = PathUtility::stripPathSitePrefix($this->fileIDMap[$extID]);
767 $pInfo['preCode'] = $preCode . '&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;' . $this->iconFactory->getIcon('actions-insert-reference', Icon::SIZE_SMALL)->render();
768 $pInfo['title'] = htmlspecialchars($fI['filename']) . ' <em>(Resource)</em>';
769 $pInfo['ref'] = 'FILE';
770 $pInfo['size'] = $fI['filesize'];
771 $pInfo['class'] = $htmlColorClass ?: 'bgColor3';
772 $pInfo['type'] = 'file';
773 $lines[] = $pInfo;
774 unset($this->remainHeader['files'][$extID]);
775 }
776 }
777 }
778 }
779
780 /**
781 * Verifies that a table is allowed on a certain doktype of a page
782 *
783 * @param string $checkTable Table name to check
784 * @param int $doktype doktype value.
785 * @return bool TRUE if OK
786 */
787 public function checkDokType($checkTable, $doktype)
788 {
789 $allowedTableList = isset($GLOBALS['PAGES_TYPES'][$doktype]['allowedTables']) ? $GLOBALS['PAGES_TYPES'][$doktype]['allowedTables'] : $GLOBALS['PAGES_TYPES']['default']['allowedTables'];
790 $allowedArray = GeneralUtility::trimExplode(',', $allowedTableList, true);
791 // If all tables or the table is listed as an allowed type, return TRUE
792 if (strstr($allowedTableList, '*') || in_array($checkTable, $allowedArray)) {
793 return true;
794 }
795 return false;
796 }
797
798 /**
799 * Render input controls for import or export
800 *
801 * @param array $r Configuration for element
802 * @return string HTML
803 */
804 public function renderControls($r)
805 {
806 if ($this->mode === 'export') {
807 if ($r['type'] === 'record') {
808 return '<input type="checkbox" name="tx_impexp[exclude][' . $r['ref'] . ']" id="checkExclude' . $r['ref'] . '" value="1" /> <label for="checkExclude' . $r['ref'] . '">' . $this->getLanguageService()->getLL('impexpcore_singlereco_exclude', true) . '</label>';
809 } else {
810 return $r['type'] == 'softref' ? $this->softrefSelector($r['_softRefInfo']) : '';
811 }
812 } else {
813 // During import
814 // For softreferences with editable fields:
815 if ($r['type'] == 'softref' && is_array($r['_softRefInfo']['subst']) && $r['_softRefInfo']['subst']['tokenID']) {
816 $tokenID = $r['_softRefInfo']['subst']['tokenID'];
817 $cfg = $this->softrefCfg[$tokenID];
818 if ($cfg['mode'] === 'editable') {
819 return (strlen($cfg['title']) ? '<strong>' . htmlspecialchars($cfg['title']) . '</strong><br/>' : '') . htmlspecialchars($cfg['description']) . '<br/>
820 <input type="text" name="tx_impexp[softrefInputValues][' . $tokenID . ']" value="' . htmlspecialchars((isset($this->softrefInputValues[$tokenID]) ? $this->softrefInputValues[$tokenID] : $cfg['defValue'])) . '" />';
821 }
822 }
823 }
824 return '';
825 }
826
827 /**
828 * Selectorbox with export options for soft references
829 *
830 * @param array $cfg Softref configuration array. An export box is shown only if a substitution scheme is found for the soft reference.
831 * @return string Selector box HTML
832 */
833 public function softrefSelector($cfg)
834 {
835 // Looking for file ID if any:
836 $fI = $cfg['file_ID'] ? $this->dat['header']['files'][$cfg['file_ID']] : array();
837 // Substitution scheme has to be around and RTE images MUST be exported.
838 if (is_array($cfg['subst']) && $cfg['subst']['tokenID'] && !$fI['RTE_ORIG_ID']) {
839 // Create options:
840 $optValues = array();
841 $optValues[''] = '';
842 $optValues['editable'] = $this->getLanguageService()->getLL('impexpcore_softrefsel_editable');
843 $optValues['exclude'] = $this->getLanguageService()->getLL('impexpcore_softrefsel_exclude');
844 // Get current value:
845 $value = $this->softrefCfg[$cfg['subst']['tokenID']]['mode'];
846 // Render options selector:
847 $selectorbox = $this->renderSelectBox(('tx_impexp[softrefCfg][' . $cfg['subst']['tokenID'] . '][mode]'), $value, $optValues) . '<br/>';
848 if ($value === 'editable') {
849 $descriptionField = '';
850 // Title:
851 if (strlen($cfg['subst']['title'])) {
852 $descriptionField .= '
853 <input type="hidden" name="tx_impexp[softrefCfg][' . $cfg['subst']['tokenID'] . '][title]" value="' . htmlspecialchars($cfg['subst']['title']) . '" />
854 <strong>' . htmlspecialchars($cfg['subst']['title']) . '</strong><br/>';
855 }
856 // Description:
857 if (!strlen($cfg['subst']['description'])) {
858 $descriptionField .= '
859 ' . $this->getLanguageService()->getLL('impexpcore_printerror_description', true) . '<br/>
860 <input type="text" name="tx_impexp[softrefCfg][' . $cfg['subst']['tokenID'] . '][description]" value="' . htmlspecialchars($this->softrefCfg[$cfg['subst']['tokenID']]['description']) . '" />';
861 } else {
862 $descriptionField .= '
863
864 <input type="hidden" name="tx_impexp[softrefCfg][' . $cfg['subst']['tokenID'] . '][description]" value="' . htmlspecialchars($cfg['subst']['description']) . '" />' . htmlspecialchars($cfg['subst']['description']);
865 }
866 // Default Value:
867 $descriptionField .= '<input type="hidden" name="tx_impexp[softrefCfg][' . $cfg['subst']['tokenID'] . '][defValue]" value="' . htmlspecialchars($cfg['subst']['tokenValue']) . '" />';
868 } else {
869 $descriptionField = '';
870 }
871 return $selectorbox . $descriptionField;
872 }
873 return '';
874 }
875
876 /**
877 * Verifies that the input path (relative to PATH_site) is found in the backend users filemounts.
878 * If it doesn't it will try to find another relative filemount for the user and return an alternative path prefix for the file.
879 *
880 * @param string $dirPrefix Path relative to PATH_site
881 * @param bool $noAlternative If set, Do not look for alternative path! Just return FALSE
882 * @return string|bool If a path is available that will be returned, otherwise FALSE.
883 */
884 public function verifyFolderAccess($dirPrefix, $noAlternative = false)
885 {
886 $fileProcObj = $this->getFileProcObj();
887 // Check, if dirPrefix is inside a valid Filemount for user:
888 $result = $fileProcObj->checkPathAgainstMounts(PATH_site . $dirPrefix);
889 // If not, try to find another relative filemount and use that instead:
890 if (!$result) {
891 if ($noAlternative) {
892 return false;
893 }
894 // Find first web folder:
895 $result = $fileProcObj->findFirstWebFolder();
896 // If that succeeded, return the path to it:
897 if ($result) {
898 // Remove the "fileadmin/" prefix of input path - and append the rest to the return value:
899 if (GeneralUtility::isFirstPartOfStr($dirPrefix, $this->fileadminFolderName . '/')) {
900 $dirPrefix = substr($dirPrefix, strlen($this->fileadminFolderName . '/'));
901 }
902 return PathUtility::stripPathSitePrefix($fileProcObj->mounts[$result]['path'] . $dirPrefix);
903 }
904 } else {
905 return $dirPrefix;
906 }
907 return false;
908 }
909
910 /*****************************
911 * Helper functions of kinds
912 *****************************/
913
914 /**
915 *
916 * @return string
917 */
918 protected function getTemporaryFolderName()
919 {
920 $temporaryPath = PATH_site . 'typo3temp/';
921 do {
922 $temporaryFolderName = $temporaryPath . 'export_temp_files_' . mt_rand(1, PHP_INT_MAX);
923 } while (is_dir($temporaryFolderName));
924 GeneralUtility::mkdir($temporaryFolderName);
925 return $temporaryFolderName;
926 }
927
928 /**
929 * Recursively flattening the idH array
930 *
931 * @param array $idH Page uid hierarchy
932 * @param array $a Accumulation array of pages (internal, don't set from outside)
933 * @return array Array with uid-uid pairs for all pages in the page tree.
934 * @see Import::flatInversePageTree_pid()
935 */
936 public function flatInversePageTree($idH, $a = array())
937 {
938 if (is_array($idH)) {
939 $idH = array_reverse($idH);
940 foreach ($idH as $k => $v) {
941 $a[$v['uid']] = $v['uid'];
942 if (is_array($v['subrow'])) {
943 $a = $this->flatInversePageTree($v['subrow'], $a);
944 }
945 }
946 }
947 return $a;
948 }
949
950 /**
951 * Returns TRUE if the input table name is to be regarded as a static relation (that is, not exported etc).
952 *
953 * @param string $table Table name
954 * @return bool TRUE, if table is marked static
955 */
956 public function isTableStatic($table)
957 {
958 if (is_array($GLOBALS['TCA'][$table])) {
959 return $GLOBALS['TCA'][$table]['ctrl']['is_static'] || in_array($table, $this->relStaticTables) || in_array('_ALL', $this->relStaticTables);
960 }
961 return false;
962 }
963
964 /**
965 * Returns TRUE if the input table name is to be included as relation
966 *
967 * @param string $table Table name
968 * @return bool TRUE, if table is marked static
969 */
970 public function inclRelation($table)
971 {
972 return is_array($GLOBALS['TCA'][$table])
973 && (in_array($table, $this->relOnlyTables) || in_array('_ALL', $this->relOnlyTables))
974 && $this->getBackendUser()->check('tables_select', $table);
975 }
976
977 /**
978 * Returns TRUE if the element should be excluded as static record.
979 *
980 * @param string $table Table name
981 * @param int $uid UID value
982 * @return bool TRUE, if table is marked static
983 */
984 public function isExcluded($table, $uid)
985 {
986 return (bool)$this->excludeMap[$table . ':' . $uid];
987 }
988
989 /**
990 * Returns TRUE if soft reference should be included in exported file.
991 *
992 * @param string $tokenID Token ID for soft reference
993 * @return bool TRUE if softreference media should be included
994 */
995 public function includeSoftref($tokenID)
996 {
997 $mode = $this->softrefCfg[$tokenID]['mode'];
998 return $tokenID && $mode !== 'exclude' && $mode !== 'editable';
999 }
1000
1001 /**
1002 * Checking if a PID is in the webmounts of the user
1003 *
1004 * @param int $pid Page ID to check
1005 * @return bool TRUE if OK
1006 */
1007 public function checkPID($pid)
1008 {
1009 if (!isset($this->checkPID_cache[$pid])) {
1010 $this->checkPID_cache[$pid] = (bool)$this->getBackendUser()->isInWebMount($pid);
1011 }
1012 return $this->checkPID_cache[$pid];
1013 }
1014
1015 /**
1016 * Checks if the position of an updated record is configured to be corrected. This can be disabled globally and changed for elements individually.
1017 *
1018 * @param string $table Table name
1019 * @param int $uid Uid or record
1020 * @return bool TRUE if the position of the record should be updated to match the one in the import structure
1021 */
1022 public function dontIgnorePid($table, $uid)
1023 {
1024 return $this->import_mode[$table . ':' . $uid] !== 'ignore_pid' && (!$this->global_ignore_pid || $this->import_mode[$table . ':' . $uid] === 'respect_pid');
1025 }
1026
1027 /**
1028 * Checks if the record exists
1029 *
1030 * @param string $table Table name
1031 * @param int $uid UID of record
1032 * @param string $fields Field list to select. Default is "uid,pid
1033 * @return array Result of \TYPO3\CMS\Backend\Utility\BackendUtility::getRecord() which means the record if found, otherwise FALSE
1034 */
1035 public function doesRecordExist($table, $uid, $fields = '')
1036 {
1037 return BackendUtility::getRecord($table, $uid, $fields ? $fields : 'uid,pid');
1038 }
1039
1040 /**
1041 * Returns the page title path of a PID value. Results are cached internally
1042 *
1043 * @param int $pid Record PID to check
1044 * @return string The path for the input PID
1045 */
1046 public function getRecordPath($pid)
1047 {
1048 if (!isset($this->cache_getRecordPath[$pid])) {
1049 $clause = $this->getBackendUser()->getPagePermsClause(1);
1050 $this->cache_getRecordPath[$pid] = (string)BackendUtility::getRecordPath($pid, $clause, 20);
1051 }
1052 return $this->cache_getRecordPath[$pid];
1053 }
1054
1055 /**
1056 * Makes a selector-box from optValues
1057 *
1058 * @param string $prefix Form element name
1059 * @param string $value Current value
1060 * @param array $optValues Options to display (key/value pairs)
1061 * @return string HTML select element
1062 */
1063 public function renderSelectBox($prefix, $value, $optValues)
1064 {
1065 $opt = array();
1066 $isSelFlag = 0;
1067 foreach ($optValues as $k => $v) {
1068 $sel = (string)$k === (string)$value ? ' selected="selected"' : '';
1069 if ($sel) {
1070 $isSelFlag++;
1071 }
1072 $opt[] = '<option value="' . htmlspecialchars($k) . '"' . $sel . '>' . htmlspecialchars($v) . '</option>';
1073 }
1074 if (!$isSelFlag && (string)$value !== '') {
1075 $opt[] = '<option value="' . htmlspecialchars($value) . '" selected="selected">' . htmlspecialchars(('[\'' . $value . '\']')) . '</option>';
1076 }
1077 return '<select name="' . $prefix . '">' . implode('', $opt) . '</select>';
1078 }
1079
1080 /**
1081 * Compares two records, the current database record and the one from the import memory.
1082 * Will return HTML code to show any differences between them!
1083 *
1084 * @param array $databaseRecord Database record, all fields (new values)
1085 * @param array $importRecord Import memorys record for the same table/uid, all fields (old values)
1086 * @param string $table The table name of the record
1087 * @param bool $inverseDiff Inverse the diff view (switch red/green, needed for pre-update difference view)
1088 * @return string HTML
1089 */
1090 public function compareRecords($databaseRecord, $importRecord, $table, $inverseDiff = false)
1091 {
1092 // Initialize:
1093 $output = array();
1094 $diffUtility = GeneralUtility::makeInstance(DiffUtility::class);
1095 // Check if both inputs are records:
1096 if (is_array($databaseRecord) && is_array($importRecord)) {
1097 // Traverse based on database record
1098 foreach ($databaseRecord as $fN => $value) {
1099 if (is_array($GLOBALS['TCA'][$table]['columns'][$fN]) && $GLOBALS['TCA'][$table]['columns'][$fN]['config']['type'] != 'passthrough') {
1100 if (isset($importRecord[$fN])) {
1101 if (trim($databaseRecord[$fN]) !== trim($importRecord[$fN])) {
1102 // Create diff-result:
1103 $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));
1104 }
1105 unset($importRecord[$fN]);
1106 }
1107 }
1108 }
1109 // Traverse remaining in import record:
1110 foreach ($importRecord as $fN => $value) {
1111 if (is_array($GLOBALS['TCA'][$table]['columns'][$fN]) && $GLOBALS['TCA'][$table]['columns'][$fN]['config']['type'] !== 'passthrough') {
1112 $output[$fN] = '<strong>Field missing</strong> in database';
1113 }
1114 }
1115 // Create output:
1116 if (!empty($output)) {
1117 $tRows = array();
1118 foreach ($output as $fN => $state) {
1119 $tRows[] = '
1120 <tr>
1121 <td class="bgColor5">' . $this->getLanguageService()->sL($GLOBALS['TCA'][$table]['columns'][$fN]['label'], true) . ' (' . htmlspecialchars($fN) . ')</td>
1122 <td class="bgColor4">' . $state . '</td>
1123 </tr>
1124 ';
1125 }
1126 $output = '<table border="0" cellpadding="0" cellspacing="1">' . implode('', $tRows) . '</table>';
1127 } else {
1128 $output = 'Match';
1129 }
1130 return '<strong class="text-nowrap">[' . htmlspecialchars(($table . ':' . $importRecord['uid'] . ' => ' . $databaseRecord['uid'])) . ']:</strong> ' . $output;
1131 }
1132 return 'ERROR: One of the inputs were not an array!';
1133 }
1134
1135 /**
1136 * Creates the original file name for a copy-RTE image (magic type)
1137 *
1138 * @param string $string RTE copy filename, eg. "RTEmagicC_user_pm_icon_01.gif.gif
1139 * @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!
1140 */
1141 public function getRTEoriginalFilename($string)
1142 {
1143 // If "magic image":
1144 if (GeneralUtility::isFirstPartOfStr($string, 'RTEmagicC_')) {
1145 // Find original file:
1146 $pI = pathinfo(substr($string, strlen('RTEmagicC_')));
1147 $filename = substr($pI['basename'], 0, -strlen(('.' . $pI['extension'])));
1148 $origFilePath = 'RTEmagicP_' . $filename;
1149 return $origFilePath;
1150 }
1151 return null;
1152 }
1153
1154 /**
1155 * Returns file processing object, initialized only once.
1156 *
1157 * @return ExtendedFileUtility File processor object
1158 */
1159 public function getFileProcObj()
1160 {
1161 if ($this->fileProcObj === null) {
1162 $this->fileProcObj = GeneralUtility::makeInstance(ExtendedFileUtility::class);
1163 $this->fileProcObj->init(array(), $GLOBALS['TYPO3_CONF_VARS']['BE']['fileExtensions']);
1164 $this->fileProcObj->setActionPermissions();
1165 }
1166 return $this->fileProcObj;
1167 }
1168
1169 /**
1170 * Call Hook
1171 *
1172 * @param string $name Name of the hook
1173 * @param array $params Array with params
1174 * @return void
1175 */
1176 public function callHook($name, $params)
1177 {
1178 if (is_array($GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['ext/impexp/class.tx_impexp.php'][$name])) {
1179 foreach ($GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['ext/impexp/class.tx_impexp.php'][$name] as $hook) {
1180 GeneralUtility::callUserFunction($hook, $params, $this);
1181 }
1182 }
1183 }
1184
1185 /*****************************
1186 * Error handling
1187 *****************************/
1188
1189 /**
1190 * Sets error message in the internal error log
1191 *
1192 * @param string $msg Error message
1193 * @return void
1194 */
1195 public function error($msg)
1196 {
1197 $this->errorLog[] = $msg;
1198 }
1199
1200 /**
1201 * Returns a table with the error-messages.
1202 *
1203 * @return string HTML print of error log
1204 */
1205 public function printErrorLog()
1206 {
1207 return !empty($this->errorLog) ? DebugUtility::viewArray($this->errorLog) : '';
1208 }
1209
1210 /**
1211 * @return BackendUserAuthentication
1212 */
1213 protected function getBackendUser()
1214 {
1215 return $GLOBALS['BE_USER'];
1216 }
1217
1218 /**
1219 * @return DatabaseConnection
1220 */
1221 protected function getDatabaseConnection()
1222 {
1223 return $GLOBALS['TYPO3_DB'];
1224 }
1225
1226 /**
1227 * @return LanguageService
1228 */
1229 protected function getLanguageService()
1230 {
1231 return $GLOBALS['LANG'];
1232 }
1233
1234 }