Clipboard.php 45.7 KB
Newer Older
1
2
3
<?php
namespace TYPO3\CMS\Backend\Clipboard;

4
/*
5
 * This file is part of the TYPO3 CMS project.
6
 *
7
8
9
 * It is free software; you can redistribute it and/or modify it under
 * the terms of the GNU General Public License, either version 2
 * of the License, or any later version.
10
 *
11
12
 * For the full copyright and license information, please read the
 * LICENSE.txt file that was distributed with this source code.
13
 *
14
15
 * The TYPO3 project - inspiring people to share!
 */
Nicole Cordes's avatar
Nicole Cordes committed
16
17

use TYPO3\CMS\Backend\Utility\BackendUtility;
18
use TYPO3\CMS\Core\Database\ConnectionPool;
19
use TYPO3\CMS\Core\Database\Query\Restriction\DeletedRestriction;
20
21
use TYPO3\CMS\Core\Imaging\Icon;
use TYPO3\CMS\Core\Imaging\IconFactory;
22
use TYPO3\CMS\Core\Imaging\IconProvider\SvgIconProvider;
Nicole Cordes's avatar
Nicole Cordes committed
23
use TYPO3\CMS\Core\Resource\ResourceFactory;
24
use TYPO3\CMS\Core\Type\Bitmask\JsConfirmation;
Nicole Cordes's avatar
Nicole Cordes committed
25
use TYPO3\CMS\Core\Utility\ExtensionManagementUtility;
26
use TYPO3\CMS\Core\Utility\GeneralUtility;
Nicole Cordes's avatar
Nicole Cordes committed
27
28
use TYPO3\CMS\Core\Utility\MathUtility;

29
30
31
/**
 * TYPO3 clipboard for records and files
 */
32
33
34
35
36
37
class Clipboard
{
    /**
     * @var int
     */
    public $numberTabs = 3;
38

39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
    /**
     * Clipboard data kept here
     *
     * Keys:
     * 'normal'
     * 'tab_[x]' where x is >=1 and denotes the pad-number
     * 'mode'	:	'copy' means copy-mode, default = moving ('cut')
     * 'el'	:	Array of elements:
     * DB: keys = '[tablename]|[uid]'	eg. 'tt_content:123'
     * DB: values = 1 (basically insignificant)
     * FILE: keys = '_FILE|[shortmd5 of path]'	eg. '_FILE|9ebc7e5c74'
     * FILE: values = The full filepath, eg. '/www/htdocs/typo3/32/dummy/fileadmin/sem1_3_examples/alternative_index.php'
     * or 'C:/www/htdocs/typo3/32/dummy/fileadmin/sem1_3_examples/alternative_index.php'
     *
     * 'current' pointer to current tab (among the above...)
     *
     * The virtual tablename '_FILE' will always indicate files/folders. When checking for elements from eg. 'all tables'
     * (by using an empty string) '_FILE' entries are excluded (so in effect only DB elements are counted)
     *
     * @var array
     */
60
    public $clipData = [];
61

62
63
64
65
    /**
     * @var int
     */
    public $changed = 0;
66

67
68
69
70
    /**
     * @var string
     */
    public $current = '';
71

72
73
74
75
    /**
     * @var int
     */
    public $lockToNormal = 0;
76

77
78
79
80
81
82
    /**
     * If set, clipboard is displaying files.
     *
     * @var int
     */
    public $fileMode = 0;
83

84
85
86
87
    /**
     * @var IconFactory
     */
    protected $iconFactory;
88

89
90
91
92
93
94
95
    /**
     * Construct
     */
    public function __construct()
    {
        $this->iconFactory = GeneralUtility::makeInstance(IconFactory::class);
    }
96

97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
    /*****************************************
     *
     * Initialize
     *
     ****************************************/
    /**
     * Initialize the clipboard from the be_user session
     *
     * @return void
     */
    public function initializeClipboard()
    {
        // Get data
        $clipData = $this->getBackendUser()->getModuleData('clipboard', $this->getBackendUser()->getTSConfigVal('options.saveClipboard') ? '' : 'ses');
        // NumberTabs
        $clNP = $this->getBackendUser()->getTSConfigVal('options.clipboardNumberPads');
        if (MathUtility::canBeInterpretedAsInteger($clNP) && $clNP >= 0) {
            $this->numberTabs = MathUtility::forceIntegerInRange($clNP, 0, 20);
        }
        // Resets/reinstates the clipboard pads
117
        $this->clipData['normal'] = is_array($clipData['normal']) ? $clipData['normal'] : [];
118
        for ($a = 1; $a <= $this->numberTabs; $a++) {
119
            $this->clipData['tab_' . $a] = is_array($clipData['tab_' . $a]) ? $clipData['tab_' . $a] : [];
120
121
122
123
        }
        // Setting the current pad pointer ($this->current))
        $this->clipData['current'] = ($this->current = isset($this->clipData[$clipData['current']]) ? $clipData['current'] : 'normal');
    }
124

125
126
127
128
129
130
131
132
133
134
135
136
    /**
     * Call this method after initialization if you want to lock the clipboard to operate on the normal pad only.
     * Trying to switch pad through ->setCmd will not work.
     * This is used by the clickmenu since it only allows operation on single elements at a time (that is the "normal" pad)
     *
     * @return void
     */
    public function lockToNormal()
    {
        $this->lockToNormal = 1;
        $this->current = 'normal';
    }
137

138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
    /**
     * The array $cmd may hold various keys which notes some action to take.
     * Normally perform only one action at a time.
     * In scripts like db_list.php / filelist/mod1/index.php the GET-var CB is used to control the clipboard.
     *
     * Selecting / Deselecting elements
     * Array $cmd['el'] has keys = element-ident, value = element value (see description of clipData array in header)
     * Selecting elements for 'copy' should be done by simultaneously setting setCopyMode.
     *
     * @param array $cmd Array of actions, see function description
     * @return void
     */
    public function setCmd($cmd)
    {
        if (is_array($cmd['el'])) {
            foreach ($cmd['el'] as $k => $v) {
                if ($this->current == 'normal') {
                    unset($this->clipData['normal']);
                }
                if ($v) {
                    $this->clipData[$this->current]['el'][$k] = $v;
                } else {
                    $this->removeElement($k);
                }
                $this->changed = 1;
            }
        }
        // Change clipboard pad (if not locked to normal)
        if ($cmd['setP']) {
            $this->setCurrentPad($cmd['setP']);
        }
        // Remove element	(value = item ident: DB; '[tablename]|[uid]'    FILE: '_FILE|[shortmd5 hash of path]'
        if ($cmd['remove']) {
            $this->removeElement($cmd['remove']);
            $this->changed = 1;
        }
        // Remove all on current pad (value = pad-ident)
        if ($cmd['removeAll']) {
176
            $this->clipData[$cmd['removeAll']] = [];
177
178
179
180
181
182
183
184
            $this->changed = 1;
        }
        // Set copy mode of the tab
        if (isset($cmd['setCopyMode'])) {
            $this->clipData[$this->current]['mode'] = $this->isElements() ? ($cmd['setCopyMode'] ? 'copy' : '') : '';
            $this->changed = 1;
        }
    }
185

186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
    /**
     * Setting the current pad on clipboard
     *
     * @param string $padIdent Key in the array $this->clipData
     * @return void
     */
    public function setCurrentPad($padIdent)
    {
        // Change clipboard pad (if not locked to normal)
        if (!$this->lockToNormal && $this->current != $padIdent) {
            if (isset($this->clipData[$padIdent])) {
                $this->clipData['current'] = ($this->current = $padIdent);
            }
            if ($this->current != 'normal' || !$this->isElements()) {
                $this->clipData[$this->current]['mode'] = '';
            }
            // Setting mode to default (move) if no items on it or if not 'normal'
            $this->changed = 1;
        }
    }
206

207
208
209
210
211
212
213
214
215
216
217
218
219
    /**
     * Call this after initialization and setCmd in order to save the clipboard to the user session.
     * The function will check if the internal flag ->changed has been set and if so, save the clipboard. Else not.
     *
     * @return void
     */
    public function endClipboard()
    {
        if ($this->changed) {
            $this->saveClipboard();
        }
        $this->changed = 0;
    }
220

221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
    /**
     * Cleans up an incoming element array $CBarr (Array selecting/deselecting elements)
     *
     * @param array $CBarr Element array from outside ("key" => "selected/deselected")
     * @param string $table The 'table which is allowed'. Must be set.
     * @param bool|int $removeDeselected Can be set in order to remove entries which are marked for deselection.
     * @return array Processed input $CBarr
     */
    public function cleanUpCBC($CBarr, $table, $removeDeselected = 0)
    {
        if (is_array($CBarr)) {
            foreach ($CBarr as $k => $v) {
                $p = explode('|', $k);
                if ((string)$p[0] != (string)$table || $removeDeselected && !$v) {
                    unset($CBarr[$k]);
                }
            }
        }
        return $CBarr;
    }
241

242
243
244
245
246
247
248
249
250
251
252
253
    /*****************************************
     *
     * Clipboard HTML renderings
     *
     ****************************************/
    /**
     * Prints the clipboard
     *
     * @return string HTML output
     */
    public function printClipboard()
    {
254
        $languageService = $this->getLanguageService();
255
        $out = [];
256
257
258
        $elementCount = count($this->elFromTable($this->fileMode ? '_FILE' : ''));
        // Copymode Selector menu
        $copymodeUrl = GeneralUtility::linkThisScript();
259
260
        $moveLabel = htmlspecialchars($languageService->sL('LLL:EXT:lang/locallang_misc.xlf:moveElements'));
        $copyLabel = htmlspecialchars($languageService->sL('LLL:EXT:lang/locallang_misc.xlf:copyElements'));
261

262
        $copymodeSelector = '
263
			<div class="btn-group">
264
265
				<button class="btn btn-default dropdown-toggle" type="button" id="copymodeSelector" data-toggle="dropdown" aria-haspopup="true" aria-expanded="true">
					' . ($this->currentMode() === 'copy' ? $copyLabel : $moveLabel) . '
266
267
					<span class="caret"></span>
				</button>
268
				<ul class="dropdown-menu" aria-labelledby="copymodeSelector">
269
270
					<li><a href="#" onclick="document.getElementById(\'clipboard_form\').method=\'POST\'; document.getElementById(\'clipboard_form\').action=' . htmlspecialchars(GeneralUtility::quoteJSvalue($copymodeUrl . '&CB[setCopyMode]=')) . '; document.getElementById(\'clipboard_form\').submit(); return true;">' . $moveLabel . '</a></li>
					<li><a href="#" onclick="document.getElementById(\'clipboard_form\').method=\'POST\'; document.getElementById(\'clipboard_form\').action=' . htmlspecialchars(GeneralUtility::quoteJSvalue($copymodeUrl . '&CB[setCopyMode]=1')) . '; document.getElementById(\'clipboard_form\').submit(); return true;">' . $copyLabel . '</a></li>
271
272
273
274
				</ul>
			</div>
			';

275
276
277
        $deleteLink = '';
        $menuSelector = '';
        if ($elementCount) {
278
            $removeAllUrl = GeneralUtility::linkThisScript(['CB' => ['removeAll' => $this->current]]);
279
280

            // Selector menu + clear button
281
            $optionArray = [];
282
283
284
            // Import / Export link:
            if (ExtensionManagementUtility::isLoaded('impexp')) {
                $url = BackendUtility::getModuleUrl('xMOD_tximpexp', $this->exportClipElementParameters());
285
                $optionArray[] = '<li><a href="' . htmlspecialchars($url) . '">' . $this->clLabel('export', 'rm') . '</a></li>';
286
287
288
289
290
291
292
            }
            // Edit:
            if (!$this->fileMode) {
                $optionArray[] = '<li><a href="#" onclick="' . htmlspecialchars(('window.location.href=' . GeneralUtility::quoteJSvalue($this->editUrl() . '&returnUrl=') . '+top.rawurlencode(window.location.href);')) . '">' . $this->clLabel('edit', 'rm') . '</a></li>';
            }

            // Delete referenced elements:
293
            $confirmationCheck = false;
294
            if ($this->getBackendUser()->jsConfirmation(JsConfirmation::DELETE)) {
295
                $confirmationCheck = true;
296
            }
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
            $confirmationMessage = sprintf(
                $languageService->sL('LLL:EXT:lang/locallang_core.xlf:mess.deleteClip'),
                $elementCount
            );
            $title = $languageService
                ->sL('LLL:EXT:lang/locallang_core.xlf:labels.clipboard.delete_elements');
            $returnUrl = $this->deleteUrl(1, ($this->fileMode ? 1 : 0));
            $btnOkText = $languageService
                ->sL('LLL:EXT:lang/locallang_alt_doc.xlf:buttons.confirm.delete_elements.yes');
            $btnCancelText = $languageService
                ->sL('LLL:EXT:lang/locallang_alt_doc.xlf:buttons.confirm.delete_elements.no');
            $optionArray[] = '<li><a'
                . (($confirmationCheck) ? ' class="t3js-modal-trigger"' : '')
                . ' href="' . htmlspecialchars($returnUrl) . '"'
                . ' data-severity="warning"'
                . ' data-button-close-text="' . htmlspecialchars($btnCancelText) . '"'
                . ' data-button-ok-text="' . htmlspecialchars($btnOkText) . '"'
                . ' data-content="' . htmlspecialchars($confirmationMessage) . '"'
                . ' data-title="' . htmlspecialchars($title) . '">'
                . htmlspecialchars($title) . '</a></li>';
317
318

            // Clear clipboard
319
320
            $optionArray[] = '<li><a href="' . htmlspecialchars($removeAllUrl) . '#clip_head">' . htmlspecialchars($languageService->sL('LLL:EXT:lang/locallang_core.xlf:labels.clipboard.clear_clipboard')) . '</a></li>';
            $deleteLink = '<a class="btn btn-danger" href="' . htmlspecialchars($removeAllUrl) . '#clip_head" title="' . htmlspecialchars($languageService->sL('LLL:EXT:lang/locallang_core.xlf:buttons.clear')) . '">' . $this->iconFactory->getIcon('actions-document-close', Icon::SIZE_SMALL)->render(SvgIconProvider::MARKUP_IDENTIFIER_INLINE) . '</a>';
321

322
323
            // menuSelector
            $menuSelector = '
324
			<div class="btn-group">
325
326
				<button class="btn btn-default dropdown-toggle" type="button" id="menuSelector" data-toggle="dropdown" aria-haspopup="true" aria-expanded="true">
					' . $this->clLabel('menu', 'rm') . '
327
328
					<span class="caret"></span>
				</button>
329
				<ul class="dropdown-menu" aria-labelledby="menuSelector">
330
331
332
333
					' . implode('', $optionArray) . '
				</ul>
			</div>
			';
334
        }
335

336
        $out[] = '
337
			<tr>
338
				<td colspan="2" nowrap="nowrap" width="95%">' . $copymodeSelector . ' ' . $menuSelector . '</td>
339
				<td nowrap="nowrap" class="col-control">' . $deleteLink . '</td>
340
			</tr>';
341

342
343
344
345
        // Print header and content for the NORMAL tab:
        // check for current item so it can be wrapped in strong tag
        $current = ($this->current == 'normal');
        $out[] = '
346
			<tr>
347
				<td colspan="3"><a href="' . htmlspecialchars(GeneralUtility::linkThisScript(['CB' => ['setP' => 'normal']])) . '#clip_head" title="' . $this->clLabel('normal-description') . '">'
348
349
350
                    . '<span class="t3-icon fa ' . ($current ? 'fa-check-circle' : 'fa-circle-o') . '"></span>'
                    . $this->padTitleWrap($this->clLabel('normal'), 'normal', $current)
                    . '</a></td>
351
			</tr>';
352
353
354
355
356
357
358
359
        if ($this->current == 'normal') {
            $out = array_merge($out, $this->printContentFromTab('normal'));
        }
        // Print header and content for the NUMERIC tabs:
        for ($a = 1; $a <= $this->numberTabs; $a++) {
            // check for current item so it can be wrapped in strong tag
            $current = ($this->current == 'tab_' . $a);
            $out[] = '
360
				<tr>
361
					<td colspan="3"><a href="' . htmlspecialchars(GeneralUtility::linkThisScript(['CB' => ['setP' => ('tab_' . $a)]])) . '#clip_head" title="' . $this->clLabel('cliptabs-description') . '">'
362
363
364
                        . '<span class="t3-icon fa ' . ($current ? 'fa-check-circle' : 'fa-circle-o') . '"></span>'
                        . $this->padTitleWrap(sprintf($this->clLabel('cliptabs-name'), $a), ('tab_' . $a), $current)
                        . '</a></td>
365
				</tr>';
366
367
368
369
370
371
            if ($this->current == 'tab_' . $a) {
                $out = array_merge($out, $this->printContentFromTab('tab_' . $a));
            }
        }
        // Wrap accumulated rows in a table:
        $output = '<a name="clip_head"></a>
372
373
374
375

			<!--
				TYPO3 Clipboard:
			-->
376
			<div class="row">
377
				<div class="col-sm-12">
378
379
380
381
382
383
384
385
386
					<div class="panel panel-default">
						<div class="panel-heading">' . BackendUtility::wrapInHelp('xMOD_csh_corebe', 'list_clipboard', $this->clLabel('clipboard', 'buttons')) . '</div>
						<table class="table">
							' . implode('', $out) . '
						</table>
					</div>
				</div>
			</div>
		';
387
388
389
390
391
        // Wrap in form tag:
        $output = '<form action="" id="clipboard_form">' . $output . '</form>';
        // Return the accumulated content:
        return $output;
    }
392

393
394
395
396
397
398
399
400
401
    /**
     * Print the content on a pad. Called from ->printClipboard()
     *
     * @access private
     * @param string $pad Pad reference
     * @return array Array with table rows for the clipboard.
     */
    public function printContentFromTab($pad)
    {
402
        $lines = [];
403
404
405
406
407
408
409
410
411
412
413
414
415
        if (is_array($this->clipData[$pad]['el'])) {
            foreach ($this->clipData[$pad]['el'] as $k => $v) {
                if ($v) {
                    list($table, $uid) = explode('|', $k);
                    // Rendering files/directories on the clipboard
                    if ($table == '_FILE') {
                        $fileObject = ResourceFactory::getInstance()->retrieveFileOrFolderObject($v);
                        if ($fileObject) {
                            $thumb = '';
                            $folder = $fileObject instanceof \TYPO3\CMS\Core\Resource\Folder;
                            $size = $folder ? '' : '(' . GeneralUtility::formatSize($fileObject->getSize()) . 'bytes)';
                            $icon = '<span title="' . htmlspecialchars($fileObject->getName() . ' ' . $size) . '">' . $this->iconFactory->getIconForResource($fileObject, Icon::SIZE_SMALL)->render() . '</span>';
                            if (!$folder && GeneralUtility::inList($GLOBALS['TYPO3_CONF_VARS']['GFX']['imagefile_ext'], $fileObject->getExtension())) {
416
                                $processedFile = $fileObject->process(\TYPO3\CMS\Core\Resource\ProcessedFile::CONTEXT_IMAGEPREVIEW, []);
417
418
419
420
421
422
423
424
425
                                if ($processedFile) {
                                    $thumbUrl = $processedFile->getPublicUrl(true);
                                    $thumb = '<br /><img src="' . htmlspecialchars($thumbUrl) . '" ' .
                                            'width="' . $processedFile->getProperty('width') . '" ' .
                                            'height="' . $processedFile->getProperty('height') . '" ' .
                                            'title="' . htmlspecialchars($fileObject->getName()) . '" alt="" />';
                                }
                            }
                            $lines[] = '
426
								<tr>
427
428
									<td nowrap="nowrap" class="col-icon">' . $icon . '</td>
									<td nowrap="nowrap" width="95%">' . $this->linkItemText(htmlspecialchars(GeneralUtility::fixed_lgd_cs($fileObject->getName(), $this->getBackendUser()->uc['titleLen'])), $fileObject->getName()) . ($pad == 'normal' ? ' <strong>(' . ($this->clipData['normal']['mode'] == 'copy' ? $this->clLabel('copy', 'cm') : $this->clLabel('cut', 'cm')) . ')</strong>' : '') . '&nbsp;' . $thumb . '</td>
429
430
									<td nowrap="nowrap" class="col-control">
										<div class="btn-group">
431
											<a class="btn btn-default" href="#" onclick="' . htmlspecialchars(('top.launchView(' . GeneralUtility::quoteJSvalue($table) . ', ' . GeneralUtility::quoteJSvalue($v) . '); return false;')) . '"title="' . $this->clLabel('info', 'cm') . '">' . $this->iconFactory->getIcon('actions-document-info', Icon::SIZE_SMALL)->render() . '</a>' . '<a class="btn btn-default" href="' . htmlspecialchars($this->removeUrl('_FILE', GeneralUtility::shortMD5($v))) . '#clip_head" title="' . $this->clLabel('removeItem') . '">' . $this->iconFactory->getIcon('actions-selection-delete', Icon::SIZE_SMALL)->render() . '</a>
432
433
										</div>
									</td>
434
								</tr>';
435
436
437
438
439
440
441
442
443
444
                        } else {
                            // If the file did not exist (or is illegal) then it is removed from the clipboard immediately:
                            unset($this->clipData[$pad]['el'][$k]);
                            $this->changed = 1;
                        }
                    } else {
                        // Rendering records:
                        $rec = BackendUtility::getRecordWSOL($table, $uid);
                        if (is_array($rec)) {
                            $lines[] = '
445
								<tr>
446
									<td nowrap="nowrap" class="col-icon">' . $this->linkItemText($this->iconFactory->getIconForRecord($table, $rec, Icon::SIZE_SMALL)->render(), $rec, $table) . '</td>
447
									<td nowrap="nowrap" width="95%">' . $this->linkItemText(htmlspecialchars(GeneralUtility::fixed_lgd_cs(BackendUtility::getRecordTitle($table, $rec), $this->getBackendUser()->uc['titleLen'])), $rec, $table) . ($pad == 'normal' ? ' <strong>(' . ($this->clipData['normal']['mode'] == 'copy' ? $this->clLabel('copy', 'cm') : $this->clLabel('cut', 'cm')) . ')</strong>' : '') . '&nbsp;</td>
448
449
									<td nowrap="nowrap" class="col-control">
										<div class="btn-group">
450
											<a class="btn btn-default" href="#" onclick="' . htmlspecialchars(('top.launchView(' . GeneralUtility::quoteJSvalue($table) . ', \'' . (int)$uid . '\'); return false;')) . '" title="' . $this->clLabel('info', 'cm') . '">' . $this->iconFactory->getIcon('actions-document-info', Icon::SIZE_SMALL)->render() . '</a>' . '<a class="btn btn-default" href="' . htmlspecialchars($this->removeUrl($table, $uid)) . '#clip_head" title="' . $this->clLabel('removeItem') . '">' . $this->iconFactory->getIcon('actions-selection-delete', Icon::SIZE_SMALL)->render() . '</a>
451
452
										</div>
									</td>
453
								</tr>';
454
                            $localizationData = $this->getLocalizations($table, $rec, '', $pad);
455
456
457
458
459
460
461
462
463
464
465
466
467
468
                            if ($localizationData) {
                                $lines[] = $localizationData;
                            }
                        } else {
                            unset($this->clipData[$pad]['el'][$k]);
                            $this->changed = 1;
                        }
                    }
                }
            }
        }
        $this->endClipboard();
        return $lines;
    }
469

470
471
472
473
474
475
476
477
478
479
480
481
    /**
     * Returns true if the clipboard contains elements
     *
     * @return bool
     */
    public function hasElements()
    {
        foreach ($this->clipData as $data) {
            if (isset($data['el']) && is_array($data['el']) && !empty($data['el'])) {
                return true;
            }
        }
482

483
484
        return false;
    }
485

486
487
488
489
490
491
492
493
494
495
496
    /**
     * Gets all localizations of the current record.
     *
     * @param string $table The table
     * @param array $parentRec The current record
     * @param string $bgColClass Class for the background color of a column
     * @param string $pad Pad reference
     * @return string HTML table rows
     */
    public function getLocalizations($table, $parentRec, $bgColClass, $pad)
    {
497
        $lines = [];
498
        $tcaCtrl = $GLOBALS['TCA'][$table]['ctrl'];
499
        if ($table !== 'pages' && BackendUtility::isTableLocalizable($table) && !$tcaCtrl['transOrigPointerTable']) {
500
            $queryBuilder = GeneralUtility::makeInstance(ConnectionPool::class)->getQueryBuilderForTable($table);
501
502
503
504
            $queryBuilder->getRestrictions()
                ->removeAll()
                ->add(GeneralUtility::makeInstance(DeletedRestriction::class));

505
506
507
            $queryBuilder
                ->select('*')
                ->from($table)
508
509
510
511
512
                ->where(
                    $queryBuilder->expr()->eq($tcaCtrl['transOrigPointerField'], (int)$parentRec['uid']),
                    $queryBuilder->expr()->neq($tcaCtrl['languageField'], 0)
                );

513
            if (isset($tcaCtrl['versioningWS']) && $tcaCtrl['versioningWS']) {
514
                $queryBuilder->andWhere($queryBuilder->expr()->eq('t3ver_wsid', (int)$parentRec['t3ver_wsid']));
515
            }
516
            $rows = $queryBuilder->execute()->fetchAll();
517
518
519
520
521
522
523
524
            if (is_array($rows)) {
                $modeData = '';
                if ($pad == 'normal') {
                    $mode = $this->clipData['normal']['mode'] == 'copy' ? 'copy' : 'cut';
                    $modeData = ' <strong>(' . $this->clLabel($mode, 'cm') . ')</strong>';
                }
                foreach ($rows as $rec) {
                    $lines[] = '
525
					<tr>
526
						<td nowrap="nowrap" class="col-icon">' . $this->iconFactory->getIconForRecord($table, $rec, Icon::SIZE_SMALL)->render() . '</td>
527
						<td nowrap="nowrap" width="95%">' . htmlspecialchars(GeneralUtility::fixed_lgd_cs(BackendUtility::getRecordTitle($table, $rec), $this->getBackendUser()->uc['titleLen'])) . $modeData . '</td>
528
						<td nowrap="nowrap" class="col-control"></td>
529
					</tr>';
530
531
532
533
534
                }
            }
        }
        return implode('', $lines);
    }
535

536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
    /**
     * Wraps title of pad in bold-tag and maybe the number of elements if any.
     * Only applies bold-tag if the item is active
     *
     * @param string  $str String (already htmlspecialchars()'ed)
     * @param string  $pad Pad reference
     * @param bool $active is currently active
     * @return string HTML output (htmlspecialchar'ed content inside of tags.)
     */
    public function padTitleWrap($str, $pad, $active)
    {
        $el = count($this->elFromTable($this->fileMode ? '_FILE' : '', $pad));
        if ($el) {
            $str .=  ' (' . ($pad == 'normal' ? ($this->clipData['normal']['mode'] == 'copy' ? $this->clLabel('copy', 'cm') : $this->clLabel('cut', 'cm')) : htmlspecialchars($el)) . ')';
        }
        if ($active === true) {
            return '<strong>' . $str . '</strong>';
        } else {
            return '<span class="text-muted">' . $str . '</span>';
        }
    }
557

558
559
560
561
562
563
564
565
566
567
568
569
570
571
    /**
     * Wraps the title of the items listed in link-tags. The items will link to the page/folder where they originate from
     *
     * @param string $str Title of element - must be htmlspecialchar'ed on beforehand.
     * @param mixed $rec If array, a record is expected. If string, its a path
     * @param string $table Table name
     * @return string
     */
    public function linkItemText($str, $rec, $table = '')
    {
        if (is_array($rec) && $table) {
            if ($this->fileMode) {
                $str = '<span class="text-muted">' . $str . '</span>';
            } else {
572
                $str = '<a href="' . htmlspecialchars(BackendUtility::getModuleUrl('web_list', ['id' => $rec['pid']])) . '">' . $str . '</a>';
573
574
575
576
577
578
            }
        } elseif (file_exists($rec)) {
            if (!$this->fileMode) {
                $str = '<span class="text-muted">' . $str . '</span>';
            } else {
                if (ExtensionManagementUtility::isLoaded('filelist')) {
579
                    $str = '<a href="' . htmlspecialchars(BackendUtility::getModuleUrl('file_list', ['id' => dirname($rec)])) . '">' . $str . '</a>';
580
581
582
583
584
                }
            }
        }
        return $str;
    }
585

586
587
588
589
590
591
592
593
594
595
    /**
     * Returns the select-url for database elements
     *
     * @param string $table Table name
     * @param int $uid Uid of record
     * @param bool|int $copy If set, copymode will be enabled
     * @param bool|int $deselect If set, the link will deselect, otherwise select.
     * @param array $baseArray The base array of GET vars to be sent in addition. Notice that current GET vars WILL automatically be included.
     * @return string URL linking to the current script but with the CB array set to select the element with table/uid
     */
596
    public function selUrlDB($table, $uid, $copy = 0, $deselect = 0, $baseArray = [])
597
    {
598
        $CB = ['el' => [rawurlencode($table . '|' . $uid) => $deselect ? 0 : 1]];
599
600
601
602
603
604
        if ($copy) {
            $CB['setCopyMode'] = 1;
        }
        $baseArray['CB'] = $CB;
        return GeneralUtility::linkThisScript($baseArray);
    }
605

606
607
608
609
610
611
612
613
614
    /**
     * Returns the select-url for files
     *
     * @param string $path Filepath
     * @param bool|int $copy If set, copymode will be enabled
     * @param bool|int $deselect If set, the link will deselect, otherwise select.
     * @param array $baseArray The base array of GET vars to be sent in addition. Notice that current GET vars WILL automatically be included.
     * @return string URL linking to the current script but with the CB array set to select the path
     */
615
    public function selUrlFile($path, $copy = 0, $deselect = 0, $baseArray = [])
616
    {
617
        $CB = ['el' => [rawurlencode('_FILE|' . GeneralUtility::shortMD5($path)) => $deselect ? '' : $path]];
618
619
620
621
622
623
        if ($copy) {
            $CB['setCopyMode'] = 1;
        }
        $baseArray['CB'] = $CB;
        return GeneralUtility::linkThisScript($baseArray);
    }
624

625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
    /**
     * pasteUrl of the element (database and file)
     * For the meaning of $table and $uid, please read from ->makePasteCmdArray!!!
     * The URL will point to tce_file or tce_db depending in $table
     *
     * @param string $table Tablename (_FILE for files)
     * @param mixed $uid "destination": can be positive or negative indicating how the paste is done (paste into / paste after)
     * @param bool $setRedirect If set, then the redirect URL will point back to the current script, but with CB reset.
     * @param array|NULL $update Additional key/value pairs which should get set in the moved/copied record (via DataHandler)
     * @return string
     */
    public function pasteUrl($table, $uid, $setRedirect = true, array $update = null)
    {
        $urlParameters = [
            'vC' => $this->getBackendUser()->veriCode(),
            'prErr' => 1,
            'uPT' => 1,
            'CB[paste]' => $table . '|' . $uid,
            'CB[pad]' => $this->current
        ];
        if ($setRedirect) {
646
            $urlParameters['redirect'] = GeneralUtility::linkThisScript(['CB' => '']);
647
648
649
650
651
652
        }
        if (is_array($update)) {
            $urlParameters['CB[update]'] = $update;
        }
        return BackendUtility::getModuleUrl($table === '_FILE' ? 'tce_file' : 'tce_db', $urlParameters);
    }
653

654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
    /**
     * deleteUrl for current pad
     *
     * @param bool|int $setRedirect If set, then the redirect URL will point back to the current script, but with CB reset.
     * @param bool|int $file If set, then the URL will link to the tce_file.php script in the typo3/ dir.
     * @return string
     */
    public function deleteUrl($setRedirect = 1, $file = 0)
    {
        $urlParameters = [
            'vC' => $this->getBackendUser()->veriCode(),
            'prErr' => 1,
            'uPT' => 1,
            'CB[delete]' => 1,
            'CB[pad]' => $this->current
        ];
        if ($setRedirect) {
671
            $urlParameters['redirect'] = GeneralUtility::linkThisScript(['CB' => '']);
672
673
674
        }
        return BackendUtility::getModuleUrl($file ? 'tce_file' : 'tce_db', $urlParameters);
    }
675

676
677
678
679
680
681
682
683
684
    /**
     * editUrl of all current elements
     * ONLY database
     * Links to FormEngine
     *
     * @return string The URL to FormEngine with parameters.
     */
    public function editUrl()
    {
685
        $parameters = [];
686
687
688
689
690
691
692
693
        // All records
        $elements = $this->elFromTable('');
        foreach ($elements as $tP => $value) {
            list($table, $uid) = explode('|', $tP);
            $parameters['edit[' . $table . '][' . $uid . ']'] = 'edit';
        }
        return BackendUtility::getModuleUrl('record_edit', $parameters);
    }
694

695
696
697
698
699
700
701
702
703
704
    /**
     * Returns the remove-url (file and db)
     * for file $table='_FILE' and $uid = shortmd5 hash of path
     *
     * @param string $table Tablename
     * @param string $uid Uid integer/shortmd5 hash
     * @return string URL
     */
    public function removeUrl($table, $uid)
    {
705
        return GeneralUtility::linkThisScript(['CB' => ['remove' => $table . '|' . $uid]]);
706
    }
707

708
709
710
711
712
713
714
715
716
    /**
     * Returns confirm JavaScript message
     *
     * @param string $table Table name
     * @param mixed $rec For records its an array, for files its a string (path)
     * @param string $type Type-code
     * @param array $clElements Array of selected elements
     * @param string $columnLabel Name of the content column
     * @return string JavaScript "confirm" message
717
     * @deprecated since TYPO3 v8, will be removed in TYPO3 v9
718
719
     */
    public function confirmMsg($table, $rec, $type, $clElements, $columnLabel = '')
720
    {
721
        GeneralUtility::logDeprecatedFunction();
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
        $message = $this->confirmMsgText($table, $rec, $type, $clElements, $columnLabel);
        if (!empty($message)) {
            $message = 'confirm(' . GeneralUtility::quoteJSvalue($message) . ');';
        }
        return $message;
    }

    /**
     * Returns confirm JavaScript message
     *
     * @param string $table Table name
     * @param mixed $rec For records its an array, for files its a string (path)
     * @param string $type Type-code
     * @param array $clElements Array of selected elements
     * @param string $columnLabel Name of the content column
     * @return string the text for a confirm message
     */
    public function confirmMsgText($table, $rec, $type, $clElements, $columnLabel = '')
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
    {
        if ($this->getBackendUser()->jsConfirmation(JsConfirmation::COPY_MOVE_PASTE)) {
            $labelKey = 'LLL:EXT:lang/locallang_core.xlf:mess.' . ($this->currentMode() == 'copy' ? 'copy' : 'move') . ($this->current == 'normal' ? '' : 'cb') . '_' . $type;
            $msg = $this->getLanguageService()->sL($labelKey . ($columnLabel ? '_colPos': ''));
            if ($table == '_FILE') {
                $thisRecTitle = basename($rec);
                if ($this->current == 'normal') {
                    $selItem = reset($clElements);
                    $selRecTitle = basename($selItem);
                } else {
                    $selRecTitle = count($clElements);
                }
            } else {
                $thisRecTitle = $table == 'pages' && !is_array($rec) ? $GLOBALS['TYPO3_CONF_VARS']['SYS']['sitename'] : BackendUtility::getRecordTitle($table, $rec);
                if ($this->current == 'normal') {
                    $selItem = $this->getSelectedRecord();
                    $selRecTitle = $selItem['_RECORD_TITLE'];
                } else {
                    $selRecTitle = count($clElements);
                }
            }
            // @TODO
            // This can get removed as soon as the "_colPos" label is translated
            // into all available locallang languages.
            if (!$msg && $columnLabel) {
                $thisRecTitle .= ' | ' . $columnLabel;
                $msg = $this->getLanguageService()->sL($labelKey);
            }
768

769
            // Message
770
771
772
773
774
775
            $conf = sprintf(
                $msg,
                GeneralUtility::fixed_lgd_cs($selRecTitle, 30),
                GeneralUtility::fixed_lgd_cs($thisRecTitle, 30),
                GeneralUtility::fixed_lgd_cs($columnLabel, 30)
            );
776
777
778
779
780
        } else {
            $conf = '';
        }
        return $conf;
    }
781

782
783
784
785
786
787
788
789
790
791
792
    /**
     * Clipboard label - getting from "EXT:lang/locallang_core.xlf:"
     *
     * @param string $key Label Key
     * @param string $Akey Alternative key to "labels
     * @return string
     */
    public function clLabel($key, $Akey = 'labels')
    {
        return htmlspecialchars($this->getLanguageService()->sL('LLL:EXT:lang/locallang_core.xlf:' . $Akey . '.' . $key));
    }
793

794
795
796
797
798
799
800
801
802
    /**
     * Creates GET parameters for linking to the export module.
     *
     * @return array GET parameters for current clipboard content to be exported
     */
    protected function exportClipElementParameters()
    {
        // Init
        $pad = $this->current;
803
        $params = [];
804
        $params['tx_impexp']['action'] = 'export';
805
806
807
808
809
810
811
812
        // Traverse items:
        if (is_array($this->clipData[$pad]['el'])) {
            foreach ($this->clipData[$pad]['el'] as $k => $v) {
                if ($v) {
                    list($table, $uid) = explode('|', $k);
                    // Rendering files/directories on the clipboard
                    if ($table == '_FILE') {
                        if (file_exists($v) && GeneralUtility::isAllowedAbsPath($v)) {
813
                            $params['tx_impexp'][is_dir($v) ? 'dir' : 'file'][] = $v;
814
815
816
817
818
                        }
                    } else {
                        // Rendering records:
                        $rec = BackendUtility::getRecord($table, $uid);
                        if (is_array($rec)) {
819
                            $params['tx_impexp']['record'][] = $table . ':' . $uid;
820
821
822
823
824
825
826
                        }
                    }
                }
            }
        }
        return $params;
    }
827

828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
    /*****************************************
     *
     * Helper functions
     *
     ****************************************/
    /**
     * Removes element on clipboard
     *
     * @param string $el Key of element in ->clipData array
     * @return void
     */
    public function removeElement($el)
    {
        unset($this->clipData[$this->current]['el'][$el]);
        $this->changed = 1;
    }
844

845
846
847
848
849
850
851
852
853
854
855
    /**
     * Saves the clipboard, no questions asked.
     * Use ->endClipboard normally (as it checks if changes has been done so saving is necessary)
     *
     * @access private
     * @return void
     */
    public function saveClipboard()
    {
        $this->getBackendUser()->pushModuleData('clipboard', $this->clipData);
    }
856

857
858
859
860
861
862
863
864
865
    /**
     * Returns the current mode, 'copy' or 'cut'
     *
     * @return string "copy" or "cut
     */
    public function currentMode()
    {
        return $this->clipData[$this->current]['mode'] == 'copy' ? 'copy' : 'cut';
    }
866

867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
    /**
     * This traverses the elements on the current clipboard pane
     * and unsets elements which does not exist anymore or are disabled.
     *
     * @return void
     */
    public function cleanCurrent()
    {
        if (is_array($this->clipData[$this->current]['el'])) {
            foreach ($this->clipData[$this->current]['el'] as $k => $v) {
                list($table, $uid) = explode('|', $k);
                if ($table != '_FILE') {
                    if (!$v || !is_array(BackendUtility::getRecord($table, $uid, 'uid'))) {
                        unset($this->clipData[$this->current]['el'][$k]);
                        $this->changed = 1;
                    }
                } else {
                    if (!$v) {
                        unset($this->clipData[$this->current]['el'][$k]);
                        $this->changed = 1;
                    } else {
                        try {
                            ResourceFactory::getInstance()->retrieveFileOrFolderObject($v);
                        } catch (\TYPO3\CMS\Core\Resource\Exception\ResourceDoesNotExistException $e) {
                            // The file has been deleted in the meantime, so just remove it silently
                            unset($this->clipData[$this->current]['el'][$k]);
                        }
                    }
                }
            }
        }
    }
899

900
901
902
903
904
905
906
907
908
909
    /**
     * Counts the number of elements from the table $matchTable. If $matchTable is blank, all tables (except '_FILE' of course) is counted.
     *
     * @param string $matchTable Table to match/count for.
     * @param string $pad Can optionally be used to set another pad than the current.
     * @return array Array with keys from the CB.
     */
    public function elFromTable($matchTable = '', $pad = '')
    {
        $pad = $pad ? $pad : $this->current;
910
        $list = [];
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
        if (is_array($this->clipData[$pad]['el'])) {
            foreach ($this->clipData[$pad]['el'] as $k => $v) {
                if ($v) {
                    list($table, $uid) = explode('|', $k);
                    if ($table != '_FILE') {
                        if ((!$matchTable || (string)$table == (string)$matchTable) && $GLOBALS['TCA'][$table]) {
                            $list[$k] = $pad == 'normal' ? $v : $uid;
                        }
                    } else {
                        if ((string)$table == (string)$matchTable) {
                            $list[$k] = $v;
                        }
                    }
                }
            }
        }
        return $list;
    }
929

930
931
932
933
934
935
936
937
938
939
940
941
942
    /**
     * Verifies if the item $table/$uid is on the current pad.
     * If the pad is "normal", the mode value is returned if the element existed. Thus you'll know if the item was copy or cut moded...
     *
     * @param string $table Table name, (_FILE for files...)
     * @param int $uid Element uid (path for files)
     * @return string
     */
    public function isSelected($table, $uid)
    {
        $k = $table . '|' . $uid;
        return $this->clipData[$this->current]['el'][$k] ? ($this->current == 'normal' ? $this->currentMode() : 1) : '';
    }
943

944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
    /**
     * Returns item record $table,$uid if selected on current clipboard
     * If table and uid is blank, the first element is returned.
     * Makes sense only for DB records - not files!
     *
     * @param string $table Table name
     * @param int|string $uid Element uid
     * @return array Element record with extra field _RECORD_TITLE set to the title of the record
     */
    public function getSelectedRecord($table = '', $uid = '')
    {
        if (!$table && !$uid) {
            $elArr = $this->elFromTable('');
            reset($elArr);
            list($table, $uid) = explode('|', key($elArr));
        }
        if ($this->isSelected($table, $uid)) {
            $selRec = BackendUtility::getRecordWSOL($table, $uid);
            $selRec['_RECORD_TITLE'] = BackendUtility::getRecordTitle($table, $selRec);
            return $selRec;
        }
965
        return [];
966
    }
967

968
969
970
971
972
973
974
975
976
    /**
     * Reports if the current pad has elements (does not check file/DB type OR if file/DBrecord exists or not. Only counting array)
     *
     * @return bool TRUE if elements exist.
     */
    public function isElements()
    {
        return is_array($this->clipData[$this->current]['el']) && !empty($this->clipData[$this->current]['el']);
    }
977

978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
    /*****************************************
     *
     * FOR USE IN tce_db.php:
     *
     ****************************************/
    /**
     * Applies the proper paste configuration in the $cmd array send to tce_db.php.
     * $ref is the target, see description below.
     * The current pad is pasted
     *
     * $ref: [tablename]:[paste-uid].
     * Tablename is the name of the table from which elements *on the current clipboard* is pasted with the 'pid' paste-uid.
     * No tablename means that all items on the clipboard (non-files) are pasted. This requires paste-uid to be positive though.
     * so 'tt_content:-3'	means 'paste tt_content elements on the clipboard to AFTER tt_content:3 record
     * 'tt_content:30'	means 'paste tt_content elements on the clipboard into page with id 30
     * ':30'	means 'paste ALL database elements on the clipboard into page with id 30
     * ':-30'	not valid.
     *
     * @param string $ref [tablename]:[paste-uid], see description
     * @param array $CMD Command-array
     * @param NULL|array If additional values should get set in the copied/moved record this will be an array containing key=>value pairs
     * @return array Modified Command-array
     */