‪TYPO3CMS  10.4
Clipboard.php
Go to the documentation of this file.
1 <?php
2 
3 /*
4  * This file is part of the TYPO3 CMS project.
5  *
6  * It is free software; you can redistribute it and/or modify it under
7  * the terms of the GNU General Public License, either version 2
8  * of the License, or any later version.
9  *
10  * For the full copyright and license information, please read the
11  * LICENSE.txt file that was distributed with this source code.
12  *
13  * The TYPO3 project - inspiring people to share!
14  */
15 
17 
36 
43 {
47  public ‪$numberTabs = 3;
48 
70  public ‪$clipData = [];
71 
75  public ‪$changed = 0;
76 
80  public ‪$current = '';
81 
85  public ‪$lockToNormal = 0;
86 
92  public ‪$fileMode = false;
93 
97  protected ‪$iconFactory;
98 
102  protected ‪$view;
103 
109  public function ‪__construct()
110  {
111  $this->iconFactory = GeneralUtility::makeInstance(IconFactory::class);
112  $this->view = $this->‪getStandaloneView();
113  }
114 
115  /*****************************************
116  *
117  * Initialize
118  *
119  ****************************************/
123  public function ‪initializeClipboard()
124  {
125  $userTsConfig = $this->‪getBackendUser()->‪getTSConfig();
126  // Get data
127  ‪$clipData = $this->‪getBackendUser()->‪getModuleData('clipboard', $userTsConfig['options.']['saveClipboard'] ? '' : 'ses');
128  $this->numberTabs = ‪MathUtility::forceIntegerInRange((int)($userTsConfig['options.']['clipboardNumberPads'] ?? 3), 0, 20);
129  // Resets/reinstates the clipboard pads
130  $this->clipData['normal'] = is_array(‪$clipData['normal']) ? ‪$clipData['normal'] : [];
131  for ($a = 1; $a <= ‪$this->numberTabs; $a++) {
132  $this->clipData['tab_' . $a] = is_array(‪$clipData['tab_' . $a]) ? ‪$clipData['tab_' . $a] : [];
133  }
134  // Setting the current pad pointer ($this->current))
135  $this->clipData['current'] = ($this->current = isset($this->clipData[‪$clipData['current']]) ? ‪$clipData['current'] : 'normal');
136  }
137 
143  public function ‪lockToNormal()
144  {
145  $this->‪lockToNormal = 1;
146  $this->current = 'normal';
147  }
148 
160  public function ‪setCmd($cmd)
161  {
162  if (is_array($cmd['el'])) {
163  foreach ($cmd['el'] as $k => $v) {
164  if ($this->current === 'normal') {
165  unset($this->clipData['normal']);
166  }
167  if ($v) {
168  $this->clipData[‪$this->current]['el'][$k] = $v;
169  } else {
170  $this->‪removeElement($k);
171  }
172  $this->changed = 1;
173  }
174  }
175  // Change clipboard pad (if not locked to normal)
176  if ($cmd['setP']) {
177  $this->‪setCurrentPad($cmd['setP']);
178  }
179  // Remove element (value = item ident: DB; '[tablename]|[uid]' FILE: '_FILE|[shortmd5 hash of path]'
180  if ($cmd['remove']) {
181  $this->‪removeElement($cmd['remove']);
182  $this->changed = 1;
183  }
184  // Remove all on current pad (value = pad-ident)
185  if ($cmd['removeAll']) {
186  $this->clipData[$cmd['removeAll']] = [];
187  $this->changed = 1;
188  }
189  // Set copy mode of the tab
190  if (isset($cmd['setCopyMode'])) {
191  $this->clipData[‪$this->current]['mode'] = $cmd['setCopyMode'] ? 'copy' : '';
192  $this->changed = 1;
193  }
194  }
195 
201  public function ‪setCurrentPad($padIdent)
202  {
203  // Change clipboard pad (if not locked to normal)
204  if (!$this->‪lockToNormal && $this->current != $padIdent) {
205  if (isset($this->clipData[$padIdent])) {
206  $this->clipData['current'] = ($this->current = $padIdent);
207  }
208  if ($this->current !== 'normal' || !$this->‪isElements()) {
209  $this->clipData[‪$this->current]['mode'] = '';
210  }
211  // Setting mode to default (move) if no items on it or if not 'normal'
212  $this->changed = 1;
213  }
214  }
215 
220  public function ‪endClipboard()
221  {
222  if ($this->changed) {
223  $this->‪saveClipboard();
224  }
225  $this->changed = 0;
226  }
227 
236  public function ‪cleanUpCBC($CBarr, $table, $removeDeselected = 0)
237  {
238  if (is_array($CBarr)) {
239  foreach ($CBarr as $k => $v) {
240  $p = explode('|', $k);
241  if ((string)$p[0] != (string)$table || $removeDeselected && !$v) {
242  unset($CBarr[$k]);
243  }
244  }
245  }
246  return $CBarr;
247  }
248 
249  /*****************************************
250  *
251  * Clipboard HTML renderings
252  *
253  ****************************************/
260  public function ‪printClipboard()
261  {
262  $languageService = $this->‪getLanguageService();
263  $elementCount = count($this->‪elFromTable($this->fileMode ? '_FILE' : ''));
264  // CopyMode Selector menu
265  $copyModeUrl = GeneralUtility::linkThisScript();
266  $this->view->assign('actionCopyModeUrl', $copyModeUrl . '&CB[setCopyMode]=#clip_head');
267  $this->view->assign('actionCopyModeUrl1', $copyModeUrl . '&CB[setCopyMode]=1#clip_head');
268  $this->view->assign('currentMode', $this->‪currentMode());
269  $this->view->assign('elementCount', $elementCount);
270 
271  if ($elementCount) {
272  $removeAllUrl = GeneralUtility::linkThisScript(['CB' => ['removeAll' => $this->current]]);
273  $this->view->assign('removeAllUrl', $removeAllUrl);
274 
275  // Selector menu + clear button
276  $optionArray = [];
277  // Import / Export link:
279  $uriBuilder = GeneralUtility::makeInstance(UriBuilder::class);
280  $url = $uriBuilder->buildUriFromRoute('tx_impexp_export', $this->‪exportClipElementParameters());
281  $optionArray[] = [
282  'label' => $this->‪clLabel('export', 'rm'),
283  'uri' => (string)$url
284  ];
285  }
286  // Edit:
287  if (!$this->fileMode) {
288  $optionArray[] = [
289  'label' => $this->‪clLabel('edit', 'rm'),
290  'uri' => '#',
291  'additionalAttributes' => [
292  'onclick' => htmlspecialchars('window.location.href=' . GeneralUtility::quoteJSvalue($this->‪editUrl() . '&returnUrl=') . '+encodeURIComponent(window.location.href);'),
293  ]
294  ];
295  }
296 
297  // Delete referenced elements:
298  $confirmationCheck = false;
299  if ($this->‪getBackendUser()->jsConfirmation(‪JsConfirmation::DELETE)) {
300  $confirmationCheck = true;
301  }
302 
303  $confirmationMessage = sprintf(
304  $languageService->sL('LLL:EXT:core/Resources/Private/Language/locallang_core.xlf:mess.deleteClip'),
305  $elementCount
306  );
307  $title = $languageService
308  ->sL('LLL:EXT:core/Resources/Private/Language/locallang_core.xlf:labels.clipboard.delete_elements');
309  $returnUrl = $this->‪deleteUrl(true, $this->fileMode);
310  $btnOkText = $languageService
311  ->sL('LLL:EXT:backend/Resources/Private/Language/locallang_alt_doc.xlf:buttons.confirm.delete_elements.yes');
312  $btnCancelText = $languageService
313  ->sL('LLL:EXT:backend/Resources/Private/Language/locallang_alt_doc.xlf:buttons.confirm.delete_elements.no');
314  $optionArray[] = [
315  'label' => htmlspecialchars($title),
316  'uri' => $returnUrl,
317  'additionalAttributes' => [
318  'class' => $confirmationCheck ? 't3js-modal-trigger' : '',
319  ],
320  'data' => [
321  'severity' => 'warning',
322  'button-close-text' => htmlspecialchars($btnCancelText),
323  'button-ok-text' => htmlspecialchars($btnOkText),
324  'content' => htmlspecialchars($confirmationMessage),
325  'title' => htmlspecialchars($title)
326  ]
327  ];
328 
329  // Clear clipboard
330  $optionArray[] = [
331  'label' => $languageService->sL('LLL:EXT:core/Resources/Private/Language/locallang_core.xlf:labels.clipboard.clear_clipboard'),
332  'uri' => $removeAllUrl . '#clip_head'
333  ];
334  $this->view->assign('optionArray', $optionArray);
335  }
336 
337  // Print header and content for the NORMAL tab:
338  $this->view->assign('current', $this->current);
339  $tabArray = [];
340  $tabArray['normal'] = [
341  'id' => 'normal',
342  'number' => 0,
343  'url' => GeneralUtility::linkThisScript(['CB' => ['setP' => 'normal']]),
344  'description' => 'labels.normal-description',
345  'label' => 'labels.normal',
346  'padding' => $this->‪padTitle('normal')
347  ];
348  if ($this->current === 'normal') {
349  $tabArray['normal']['content'] = $this->‪getContentFromTab('normal');
350  }
351  // Print header and content for the NUMERIC tabs:
352  for ($a = 1; $a <= ‪$this->numberTabs; $a++) {
353  $tabArray['tab_' . $a] = [
354  'id' => 'tab_' . $a,
355  'number' => $a,
356  'url' => GeneralUtility::linkThisScript(['CB' => ['setP' => 'tab_' . $a]]),
357  'description' => 'labels.cliptabs-description',
358  'label' => 'labels.cliptabs-name',
359  'padding' => $this->‪padTitle('tab_' . $a)
360  ];
361  if ($this->current === 'tab_' . $a) {
362  $tabArray['tab_' . $a]['content'] = $this->‪getContentFromTab('tab_' . $a);
363  }
364  }
365  $this->view->assign('clipboardHeader', ‪BackendUtility::wrapInHelp('xMOD_csh_corebe', 'list_clipboard', $this->‪clLabel('clipboard', 'buttons')));
366  $this->view->assign('tabArray', $tabArray);
367  return $this->view->render();
368  }
369 
377  public function ‪getContentFromTab($pad)
378  {
379  $lines = [];
380  if (is_array($this->clipData[$pad]['el'] ?? false)) {
381  foreach ($this->clipData[$pad]['el'] as $k => $v) {
382  if ($v) {
383  [$table, $uid] = explode('|', $k);
384  // Rendering files/directories on the clipboard
385  if ($table === '_FILE') {
386  $fileObject = GeneralUtility::makeInstance(ResourceFactory::class)->retrieveFileOrFolderObject($v);
387  if ($fileObject) {
388  $thumb = [];
389  $folder = $fileObject instanceof ‪Folder;
390  $size = $folder ? '' : '(' . GeneralUtility::formatSize((int)$fileObject->getSize()) . 'bytes)';
391  if (!$folder && $fileObject->isImage()) {
392  $thumb = [
393  'image' => $fileObject->process(‪ProcessedFile::CONTEXT_IMAGEPREVIEW, [])->getPublicUrl(true),
394  'title' => htmlspecialchars($fileObject->getName())
395  ];
396  }
397  $lines[] = [
398  'icon' => '<span title="' . htmlspecialchars($fileObject->getName() . ' ' . $size) . '">' . $this->iconFactory->getIconForResource(
399  $fileObject,
401  )->render() . '</span>',
402  'title' => $this->‪linkItemText(htmlspecialchars(GeneralUtility::fixed_lgd_cs(
403  $fileObject->getName(),
404  $this->getBackendUser()->uc['titleLen']
405  )), $fileObject->getName()),
406  'thumb' => $thumb,
407  'infoDataDispatch' => [
408  'action' => 'TYPO3.InfoWindow.showItem',
409  'args' => GeneralUtility::jsonEncodeForHtmlAttribute([$table, $v], false),
410  ],
411  'removeLink' => $this->‪removeUrl('_FILE', GeneralUtility::shortMD5($v))
412  ];
413  } else {
414  // If the file did not exist (or is illegal) then it is removed from the clipboard immediately:
415  unset($this->clipData[$pad]['el'][$k]);
416  $this->changed = 1;
417  }
418  } else {
419  // Rendering records:
420  $rec = ‪BackendUtility::getRecordWSOL($table, (int)$uid);
421  if (is_array($rec)) {
422  $lines[] = [
423  'icon' => $this->‪linkItemText($this->iconFactory->getIconForRecord(
424  $table,
425  $rec,
427  )->render(), $rec, $table),
428  'title' => $this->‪linkItemText(htmlspecialchars(GeneralUtility::fixed_lgd_cs(‪BackendUtility::getRecordTitle(
429  $table,
430  $rec
431  ), $this->‪getBackendUser()->uc['titleLen'])), $rec, $table),
432  'infoDataDispatch' => [
433  'action' => 'TYPO3.InfoWindow.showItem',
434  'args' => GeneralUtility::jsonEncodeForHtmlAttribute([$table, (int)$uid], false),
435  ],
436  'removeLink' => $this->‪removeUrl($table, $uid)
437  ];
438 
439  $localizationData = $this->‪getLocalizations($table, $rec);
440  if (!empty($localizationData)) {
441  $lines = array_merge($lines, $localizationData);
442  }
443  } else {
444  unset($this->clipData[$pad]['el'][$k]);
445  $this->changed = 1;
446  }
447  }
448  }
449  }
450  }
451  $this->‪endClipboard();
452  return $lines;
453  }
454 
460  public function ‪hasElements()
461  {
462  foreach ($this->clipData as $data) {
463  if (isset($data['el']) && is_array($data['el']) && !empty($data['el'])) {
464  return true;
465  }
466  }
467 
468  return false;
469  }
470 
478  public function ‪getLocalizations($table, $parentRec)
479  {
480  $lines = [];
481  $tcaCtrl = ‪$GLOBALS['TCA'][$table]['ctrl'];
482  $workspaceId = (int)$this->‪getBackendUser()->workspace;
483 
485  $queryBuilder = GeneralUtility::makeInstance(ConnectionPool::class)->getQueryBuilderForTable($table);
486  $queryBuilder->getRestrictions()
487  ->removeAll()
488  ->add(GeneralUtility::makeInstance(DeletedRestriction::class));
489 
490  $queryBuilder
491  ->select('*')
492  ->from($table)
493  ->where(
494  $queryBuilder->expr()->eq(
495  $tcaCtrl['transOrigPointerField'],
496  $queryBuilder->createNamedParameter($parentRec['uid'], \PDO::PARAM_INT)
497  ),
498  $queryBuilder->expr()->neq(
499  $tcaCtrl['languageField'],
500  $queryBuilder->createNamedParameter(0, \PDO::PARAM_INT)
501  ),
502  $queryBuilder->expr()->gt(
503  'pid',
504  $queryBuilder->createNamedParameter(-1, \PDO::PARAM_INT)
505  )
506  )
507  ->orderBy($tcaCtrl['languageField']);
508 
510  $queryBuilder->getRestrictions()->add(
511  GeneralUtility::makeInstance(WorkspaceRestriction::class, $workspaceId)
512  );
513  }
514  $rows = $queryBuilder->execute()->fetchAll();
515  if (is_array($rows)) {
516  foreach ($rows as $rec) {
517  $lines[] = [
518  'icon' => $this->iconFactory->getIconForRecord($table, $rec, ‪Icon::SIZE_SMALL)->render(),
519  'title' => htmlspecialchars(GeneralUtility::fixed_lgd_cs(‪BackendUtility::getRecordTitle($table, $rec), $this->‪getBackendUser()->uc['titleLen']))
520  ];
521  }
522  }
523  }
524  return $lines;
525  }
526 
533  public function ‪padTitle($pad)
534  {
535  $el = count($this->‪elFromTable($this->fileMode ? '_FILE' : '', $pad));
536  if ($el) {
537  return ' (' . ($pad === 'normal' ? ($this->clipData['normal']['mode'] === 'copy' ? $this->‪clLabel('copy', 'cm') : $this->‪clLabel('cut', 'cm')) : htmlspecialchars((string)$el)) . ')';
538  }
539  return '';
540  }
541 
550  public function ‪linkItemText($str, $rec, $table = '')
551  {
552  $uriBuilder = GeneralUtility::makeInstance(UriBuilder::class);
553  if (is_array($rec) && $table) {
554  if ($this->fileMode) {
555  $str = '<span class="text-muted">' . $str . '</span>';
556  } else {
557  $str = '<a href="' . htmlspecialchars((string)$uriBuilder->buildUriFromRoute('web_list', ['id' => $rec['pid']])) . '">' . $str . '</a>';
558  }
559  } elseif (file_exists($rec)) {
560  if (!$this->fileMode) {
561  $str = '<span class="text-muted">' . $str . '</span>';
562  } elseif (‪ExtensionManagementUtility::isLoaded('filelist')) {
563  $str = '<a href="' . htmlspecialchars((string)$uriBuilder->buildUriFromRoute('file_list', ['id' => ‪PathUtility::dirname($rec)])) . '">' . $str . '</a>';
564  }
565  }
566  return $str;
567  }
568 
579  public function ‪selUrlDB($table, $uid, $copy = 0, $deselect = 0, $baseArray = [])
580  {
581  $CB = ['el' => [rawurlencode($table . '|' . $uid) => $deselect ? 0 : 1]];
582  if ($copy) {
583  $CB['setCopyMode'] = 1;
584  }
585  $baseArray['CB'] = $CB;
586  return GeneralUtility::linkThisScript($baseArray);
587  }
588 
598  public function ‪selUrlFile($path, $copy = 0, $deselect = 0, $baseArray = [])
599  {
600  $CB = ['el' => [rawurlencode('_FILE|' . GeneralUtility::shortMD5($path)) => $deselect ? '' : $path]];
601  if ($copy) {
602  $CB['setCopyMode'] = 1;
603  }
604  $baseArray['CB'] = $CB;
605  return GeneralUtility::linkThisScript($baseArray);
606  }
607 
619  public function ‪pasteUrl($table, $uid, $setRedirect = true, array $update = null)
620  {
621  $urlParameters = [
622  'CB[paste]' => $table . '|' . $uid,
623  'CB[pad]' => ‪$this->current
624  ];
625  if ($setRedirect) {
626  $urlParameters['redirect'] = GeneralUtility::linkThisScript(['CB' => '']);
627  }
628  if (is_array($update)) {
629  $urlParameters['CB[update]'] = $update;
630  }
631  $uriBuilder = GeneralUtility::makeInstance(UriBuilder::class);
632  return (string)$uriBuilder->buildUriFromRoute($table === '_FILE' ? 'tce_file' : 'tce_db', $urlParameters);
633  }
634 
642  public function ‪deleteUrl($setRedirect = true, $file = false)
643  {
644  $urlParameters = [
645  'CB[delete]' => 1,
646  'CB[pad]' => ‪$this->current
647  ];
648  if ($setRedirect) {
649  $urlParameters['redirect'] = GeneralUtility::linkThisScript(['CB' => '']);
650  }
651  $uriBuilder = GeneralUtility::makeInstance(UriBuilder::class);
652  return (string)$uriBuilder->buildUriFromRoute($file ? 'tce_file' : 'tce_db', $urlParameters);
653  }
654 
662  public function ‪editUrl()
663  {
664  $parameters = [];
665  // All records
666  $elements = $this->‪elFromTable('');
667  foreach ($elements as $tP => $value) {
668  [$table, $uid] = explode('|', $tP);
669  $parameters['edit[' . $table . '][' . $uid . ']'] = 'edit';
670  }
671  $uriBuilder = GeneralUtility::makeInstance(UriBuilder::class);
672  return (string)$uriBuilder->buildUriFromRoute('record_edit', $parameters);
673  }
674 
683  public function ‪removeUrl($table, $uid)
684  {
685  return GeneralUtility::linkThisScript(['CB' => ['remove' => $table . '|' . $uid]]);
686  }
687 
698  public function ‪confirmMsgText($table, $rec, $type, $clElements, $columnLabel = '')
699  {
700  if ($this->‪getBackendUser()->jsConfirmation(‪JsConfirmation::COPY_MOVE_PASTE)) {
701  $labelKey = 'LLL:EXT:core/Resources/Private/Language/locallang_core.xlf:mess.' . ($this->‪currentMode() === 'copy' ? 'copy' : 'move') . ($this->current === 'normal' ? '' : 'cb') . '_' . $type;
702  $msg = $this->‪getLanguageService()->sL($labelKey . ($columnLabel ? '_colPos' : ''));
703  if ($table === '_FILE') {
704  $thisRecTitle = ‪PathUtility::basename($rec);
705  if ($this->current === 'normal') {
706  $selItem = reset($clElements);
707  $selRecTitle = ‪PathUtility::basename($selItem);
708  } else {
709  $selRecTitle = count($clElements);
710  }
711  } else {
712  $thisRecTitle = $table === 'pages' && !is_array($rec) ? ‪$GLOBALS['TYPO3_CONF_VARS']['SYS']['sitename'] : ‪BackendUtility::getRecordTitle($table, $rec);
713  if ($this->current === 'normal') {
714  $selItem = $this->‪getSelectedRecord();
715  $selRecTitle = $selItem['_RECORD_TITLE'];
716  } else {
717  $selRecTitle = count($clElements);
718  }
719  }
720  // @TODO
721  // This can get removed as soon as the "_colPos" label is translated
722  // into all available locallang languages.
723  if (!$msg && $columnLabel) {
724  $thisRecTitle .= ' | ' . $columnLabel;
725  $msg = $this->‪getLanguageService()->sL($labelKey);
726  }
727 
728  // Message
729  $conf = sprintf(
730  $msg,
731  GeneralUtility::fixed_lgd_cs($selRecTitle, 30),
732  GeneralUtility::fixed_lgd_cs($thisRecTitle, 30),
733  GeneralUtility::fixed_lgd_cs($columnLabel, 30)
734  );
735  } else {
736  $conf = '';
737  }
738  return $conf;
739  }
740 
748  public function ‪clLabel($key, $Akey = 'labels')
749  {
750  return htmlspecialchars($this->‪getLanguageService()->sL('LLL:EXT:core/Resources/Private/Language/locallang_core.xlf:' . $Akey . '.' . $key));
751  }
752 
758  protected function ‪exportClipElementParameters()
759  {
760  // Init
761  $pad = ‪$this->current;
762  $params = [];
763  // Traverse items:
764  if (is_array($this->clipData[$pad]['el'] ?? false)) {
765  foreach ($this->clipData[$pad]['el'] as $k => $v) {
766  if ($v) {
767  [$table, $uid] = explode('|', $k);
768  // Rendering files/directories on the clipboard
769  if ($table === '_FILE') {
770  $file = GeneralUtility::makeInstance(ResourceFactory::class)->getObjectFromCombinedIdentifier($v);
771  if ($file instanceof ‪AbstractFile) {
772  $params['tx_impexp']['record'][] = 'sys_file:' . $file->getUid();
773  }
774  } else {
775  // Rendering records:
776  $rec = ‪BackendUtility::getRecord($table, (int)$uid);
777  if (is_array($rec)) {
778  $params['tx_impexp']['record'][] = $table . ':' . $uid;
779  }
780  }
781  }
782  }
783  }
784  return $params;
785  }
786 
787  /*****************************************
788  *
789  * Helper functions
790  *
791  ****************************************/
797  public function ‪removeElement($el)
798  {
799  unset($this->clipData[$this->current]['el'][$el]);
800  $this->changed = 1;
801  }
802 
809  public function ‪saveClipboard()
810  {
811  $this->‪getBackendUser()->‪pushModuleData('clipboard', $this->clipData);
812  }
813 
819  public function ‪currentMode()
820  {
821  return ($this->clipData[$this->current]['mode'] ?? '') === 'copy' ? 'copy' : 'cut';
822  }
823 
828  public function ‪cleanCurrent()
829  {
830  if (is_array($this->clipData[$this->current]['el'] ?? false)) {
831  foreach ($this->clipData[$this->current]['el'] as $k => $v) {
832  [$table, $uid] = explode('|', $k);
833  if ($table !== '_FILE') {
834  if (!$v || !is_array(‪BackendUtility::getRecord($table, (int)$uid, 'uid'))) {
835  unset($this->clipData[$this->current]['el'][$k]);
836  $this->changed = 1;
837  }
838  } else {
839  if (!$v) {
840  unset($this->clipData[$this->current]['el'][$k]);
841  $this->changed = 1;
842  } else {
843  try {
844  GeneralUtility::makeInstance(ResourceFactory::class)->retrieveFileOrFolderObject($v);
845  } catch (ResourceDoesNotExistException $e) {
846  // The file has been deleted in the meantime, so just remove it silently
847  unset($this->clipData[$this->current]['el'][$k]);
848  }
849  }
850  }
851  }
852  }
853  }
854 
862  public function ‪elFromTable($matchTable = '', $pad = '')
863  {
864  $pad = $pad ?: ‪$this->current;
865  $list = [];
866  if (is_array($this->clipData[$pad]['el'] ?? false)) {
867  foreach ($this->clipData[$pad]['el'] as $k => $v) {
868  if ($v) {
869  [$table, $uid] = explode('|', $k);
870  if ($table !== '_FILE') {
871  if ((!$matchTable || (string)$table == (string)$matchTable) && ‪$GLOBALS['TCA'][$table]) {
872  $list[$k] = $pad === 'normal' ? $v : $uid;
873  }
874  } else {
875  if ((string)$table == (string)$matchTable) {
876  $list[$k] = $v;
877  }
878  }
879  }
880  }
881  }
882  return $list;
883  }
884 
893  public function ‪isSelected($table, $uid)
894  {
895  $k = $table . '|' . $uid;
896  return !empty($this->clipData[$this->current]['el'][$k]) ? ($this->current === 'normal' ? $this->‪currentMode() : 1) : '';
897  }
898 
908  public function ‪getSelectedRecord($table = '', $uid = '')
909  {
910  if (!$table && !$uid) {
911  $elArr = $this->‪elFromTable('');
912  reset($elArr);
913  [$table, $uid] = explode('|', (string)key($elArr));
914  }
915  if ($this->‪isSelected($table, (int)$uid)) {
916  $selRec = ‪BackendUtility::getRecordWSOL($table, (int)$uid);
917  $selRec['_RECORD_TITLE'] = ‪BackendUtility::getRecordTitle($table, $selRec);
918  return $selRec;
919  }
920  return [];
921  }
922 
928  public function ‪isElements()
929  {
930  return is_array($this->clipData[$this->current]['el']) && !empty($this->clipData[$this->current]['el']);
931  }
932 
951  public function ‪makePasteCmdArray($ref, $CMD, array $update = null)
952  {
953  [$pTable, $pUid] = explode('|', $ref);
954  $pUid = (int)$pUid;
955  // pUid must be set and if pTable is not set (that means paste ALL elements)
956  // the uid MUST be positive/zero (pointing to page id)
957  if ($pTable || $pUid >= 0) {
958  $elements = $this->‪elFromTable($pTable);
959  // So the order is preserved.
960  $elements = array_reverse($elements);
961  $mode = $this->‪currentMode() === 'copy' ? 'copy' : 'move';
962  // Traverse elements and make CMD array
963  foreach ($elements as $tP => $value) {
964  [$table, $uid] = explode('|', $tP);
965  if (!is_array($CMD[$table])) {
966  $CMD[$table] = [];
967  }
968  if (is_array($update)) {
969  $CMD[$table][$uid][$mode] = [
970  'action' => 'paste',
971  'target' => $pUid,
972  'update' => $update,
973  ];
974  } else {
975  $CMD[$table][$uid][$mode] = $pUid;
976  }
977  if ($mode === 'move') {
978  $this->‪removeElement($tP);
979  }
980  }
981  $this->‪endClipboard();
982  }
983  return $CMD;
984  }
985 
992  public function ‪makeDeleteCmdArray($CMD)
993  {
994  // all records
995  $elements = $this->‪elFromTable('');
996  foreach ($elements as $tP => $value) {
997  [$table, $uid] = explode('|', $tP);
998  if (!is_array($CMD[$table])) {
999  $CMD[$table] = [];
1000  }
1001  $CMD[$table][$uid]['delete'] = 1;
1002  $this->‪removeElement($tP);
1003  }
1004  $this->‪endClipboard();
1005  return $CMD;
1006  }
1007 
1008  /*****************************************
1009  *
1010  * FOR USE IN tce_file.php:
1011  *
1012  ****************************************/
1021  public function ‪makePasteCmdArray_file($ref, $FILE)
1022  {
1023  [$pTable, $pUid] = explode('|', $ref);
1024  $elements = $this->‪elFromTable('_FILE');
1025  $mode = $this->‪currentMode() === 'copy' ? 'copy' : 'move';
1026  // Traverse elements and make CMD array
1027  foreach ($elements as $tP => $path) {
1028  $FILE[$mode][] = ['data' => $path, 'target' => $pUid];
1029  if ($mode === 'move') {
1030  $this->‪removeElement($tP);
1031  }
1032  }
1033  $this->‪endClipboard();
1034  return $FILE;
1035  }
1036 
1043  public function ‪makeDeleteCmdArray_file($FILE)
1044  {
1045  $elements = $this->‪elFromTable('_FILE');
1046  // Traverse elements and make CMD array
1047  foreach ($elements as $tP => $path) {
1048  $FILE['delete'][] = ['data' => $path];
1049  $this->‪removeElement($tP);
1050  }
1051  $this->‪endClipboard();
1052  return $FILE;
1053  }
1054 
1060  protected function ‪getLanguageService()
1061  {
1062  return ‪$GLOBALS['LANG'];
1063  }
1064 
1070  protected function ‪getBackendUser()
1071  {
1072  return ‪$GLOBALS['BE_USER'];
1073  }
1082  protected function ‪getStandaloneView()
1083  {
1085  ‪$view = GeneralUtility::makeInstance(StandaloneView::class);
1086  ‪$view->‪setLayoutRootPaths([GeneralUtility::getFileAbsFileName('EXT:backend/Resources/Private/Layouts')]);
1087  ‪$view->‪setPartialRootPaths([GeneralUtility::getFileAbsFileName('EXT:backend/Resources/Private/Partials')]);
1088  ‪$view->‪setTemplateRootPaths([GeneralUtility::getFileAbsFileName('EXT:backend/Resources/Private/Templates')]);
1089 
1090  ‪$view->‪setTemplatePathAndFilename(GeneralUtility::getFileAbsFileName('EXT:backend/Resources/Private/Templates/Clipboard/Main.html'));
1091 
1093  return ‪$view;
1094  }
1095 }
‪TYPO3\CMS\Core\Imaging\Icon\SIZE_SMALL
‪const SIZE_SMALL
Definition: Icon.php:30
‪TYPO3\CMS\Backend\Clipboard\Clipboard\__construct
‪__construct()
Definition: Clipboard.php:101
‪TYPO3\CMS\Backend\Clipboard\Clipboard\makePasteCmdArray_file
‪array makePasteCmdArray_file($ref, $FILE)
Definition: Clipboard.php:1013
‪TYPO3\CMS\Backend\Clipboard\Clipboard\setCurrentPad
‪setCurrentPad($padIdent)
Definition: Clipboard.php:193
‪TYPO3\CMS\Core\Resource\ProcessedFile\CONTEXT_IMAGEPREVIEW
‪const CONTEXT_IMAGEPREVIEW
Definition: ProcessedFile.php:52
‪TYPO3\CMS\Core\Utility\PathUtility
Definition: PathUtility.php:24
‪TYPO3\CMS\Backend\Clipboard\Clipboard
Definition: Clipboard.php:43
‪TYPO3\CMS\Backend\Clipboard\Clipboard\getSelectedRecord
‪array getSelectedRecord($table='', $uid='')
Definition: Clipboard.php:900
‪TYPO3\CMS\Backend\Clipboard\Clipboard\cleanUpCBC
‪array cleanUpCBC($CBarr, $table, $removeDeselected=0)
Definition: Clipboard.php:228
‪TYPO3\CMS\Core\Utility\PathUtility\dirname
‪static string dirname($path)
Definition: PathUtility.php:186
‪TYPO3\CMS\Backend\Clipboard\Clipboard\printClipboard
‪string printClipboard()
Definition: Clipboard.php:252
‪TYPO3\CMS\Core\Imaging\Icon
Definition: Icon.php:26
‪TYPO3\CMS\Backend\Clipboard\Clipboard\isElements
‪bool isElements()
Definition: Clipboard.php:920
‪TYPO3\CMS\Backend\Clipboard\Clipboard\removeElement
‪removeElement($el)
Definition: Clipboard.php:789
‪TYPO3\CMS\Core\Authentication\BackendUserAuthentication\getTSConfig
‪array getTSConfig()
Definition: BackendUserAuthentication.php:1217
‪TYPO3\CMS\Core\Utility\MathUtility\forceIntegerInRange
‪static int forceIntegerInRange($theInt, $min, $max=2000000000, $defaultValue=0)
Definition: MathUtility.php:32
‪TYPO3\CMS\Backend\Clipboard\Clipboard\lockToNormal
‪lockToNormal()
Definition: Clipboard.php:135
‪TYPO3\CMS\Backend\Clipboard\Clipboard\removeUrl
‪string removeUrl($table, $uid)
Definition: Clipboard.php:675
‪TYPO3\CMS\Core\Imaging\IconFactory
Definition: IconFactory.php:33
‪TYPO3\CMS\Backend\Clipboard\Clipboard\clLabel
‪string clLabel($key, $Akey='labels')
Definition: Clipboard.php:740
‪TYPO3\CMS\Backend\Clipboard\Clipboard\getLanguageService
‪TYPO3 CMS Core Localization LanguageService getLanguageService()
Definition: Clipboard.php:1052
‪TYPO3\CMS\Backend\Clipboard\Clipboard\isSelected
‪string isSelected($table, $uid)
Definition: Clipboard.php:885
‪TYPO3\CMS\Core\Type\Bitmask\JsConfirmation\COPY_MOVE_PASTE
‪const COPY_MOVE_PASTE
Definition: JsConfirmation.php:34
‪TYPO3\CMS\Backend\Clipboard\Clipboard\initializeClipboard
‪initializeClipboard()
Definition: Clipboard.php:115
‪TYPO3\CMS\Backend\Utility\BackendUtility\wrapInHelp
‪static string wrapInHelp($table, $field, $text='', array $overloadHelpText=[])
Definition: BackendUtility.php:2260
‪TYPO3\CMS\Core\Utility\PathUtility\basename
‪static string basename($path)
Definition: PathUtility.php:165
‪TYPO3\CMS\Fluid\View\StandaloneView\getRequest
‪TYPO3 CMS Extbase Mvc Request getRequest()
Definition: StandaloneView.php:116
‪TYPO3\CMS\Backend\Clipboard\Clipboard\pasteUrl
‪string pasteUrl($table, $uid, $setRedirect=true, array $update=null)
Definition: Clipboard.php:611
‪TYPO3\CMS\Core\Utility\ExtensionManagementUtility
Definition: ExtensionManagementUtility.php:43
‪TYPO3\CMS\Backend\Utility\BackendUtility\isTableWorkspaceEnabled
‪static bool isTableWorkspaceEnabled($table)
Definition: BackendUtility.php:4021
‪TYPO3\CMS\Backend\Clipboard\Clipboard\confirmMsgText
‪string confirmMsgText($table, $rec, $type, $clElements, $columnLabel='')
Definition: Clipboard.php:690
‪TYPO3\CMS\Core\Type\Bitmask\JsConfirmation\DELETE
‪const DELETE
Definition: JsConfirmation.php:39
‪TYPO3\CMS\Backend\Clipboard\Clipboard\currentMode
‪string currentMode()
Definition: Clipboard.php:811
‪TYPO3\CMS\Backend\Clipboard\Clipboard\hasElements
‪bool hasElements()
Definition: Clipboard.php:452
‪TYPO3\CMS\Core\Resource\AbstractFile
Definition: AbstractFile.php:26
‪TYPO3\CMS\Backend\Clipboard\Clipboard\makeDeleteCmdArray_file
‪array makeDeleteCmdArray_file($FILE)
Definition: Clipboard.php:1035
‪TYPO3\CMS\Backend\Clipboard\Clipboard\makePasteCmdArray
‪array makePasteCmdArray($ref, $CMD, array $update=null)
Definition: Clipboard.php:943
‪TYPO3\CMS\Backend\Routing\UriBuilder
Definition: UriBuilder.php:38
‪TYPO3\CMS\Backend\Clipboard\Clipboard\getBackendUser
‪TYPO3 CMS Core Authentication BackendUserAuthentication getBackendUser()
Definition: Clipboard.php:1062
‪TYPO3\CMS\Core\Authentication\AbstractUserAuthentication\getModuleData
‪mixed getModuleData($module, $type='')
Definition: AbstractUserAuthentication.php:1181
‪TYPO3\CMS\Backend\Clipboard\Clipboard\padTitle
‪string padTitle($pad)
Definition: Clipboard.php:525
‪TYPO3\CMS\Backend\Clipboard\Clipboard\setCmd
‪setCmd($cmd)
Definition: Clipboard.php:152
‪TYPO3\CMS\Core\Resource\Folder
Definition: Folder.php:37
‪TYPO3\CMS\Core\Resource\ResourceFactory
Definition: ResourceFactory.php:41
‪TYPO3\CMS\Backend\Clipboard\Clipboard\$fileMode
‪bool $fileMode
Definition: Clipboard.php:86
‪TYPO3\CMS\Backend\Clipboard\Clipboard\linkItemText
‪string linkItemText($str, $rec, $table='')
Definition: Clipboard.php:542
‪TYPO3\CMS\Core\Resource\Exception\ResourceDoesNotExistException
Definition: ResourceDoesNotExistException.php:24
‪TYPO3\CMS\Core\Authentication\AbstractUserAuthentication\pushModuleData
‪pushModuleData($module, $data, $noSave=0)
Definition: AbstractUserAuthentication.php:1161
‪TYPO3\CMS\Backend\Utility\BackendUtility\getRecordTitle
‪static string getRecordTitle($table, $row, $prep=false, $forceResult=true)
Definition: BackendUtility.php:1541
‪TYPO3\CMS\Extbase\Mvc\Request\setControllerExtensionName
‪setControllerExtensionName($controllerExtensionName)
Definition: Request.php:193
‪TYPO3\CMS\Backend\Clipboard\Clipboard\$iconFactory
‪IconFactory $iconFactory
Definition: Clipboard.php:90
‪TYPO3\CMS\Fluid\View\AbstractTemplateView\setTemplatePathAndFilename
‪setTemplatePathAndFilename($templatePathAndFilename)
Definition: AbstractTemplateView.php:103
‪TYPO3\CMS\Backend\Clipboard\Clipboard\$current
‪string $current
Definition: Clipboard.php:76
‪TYPO3\CMS\Backend\Utility\BackendUtility
Definition: BackendUtility.php:75
‪TYPO3\CMS\Backend\Utility\BackendUtility\getRecordWSOL
‪static array getRecordWSOL( $table, $uid, $fields=' *', $where='', $useDeleteClause=true, $unsetMovePointers=false)
Definition: BackendUtility.php:139
‪TYPO3\CMS\Backend\Clipboard\Clipboard\selUrlDB
‪string selUrlDB($table, $uid, $copy=0, $deselect=0, $baseArray=[])
Definition: Clipboard.php:571
‪TYPO3\CMS\Backend\Clipboard\Clipboard\$clipData
‪array $clipData
Definition: Clipboard.php:68
‪TYPO3\CMS\Backend\Clipboard\Clipboard\$view
‪StandaloneView $view
Definition: Clipboard.php:94
‪TYPO3\CMS\Backend\Utility\BackendUtility\getRecord
‪static array null getRecord($table, $uid, $fields=' *', $where='', $useDeleteClause=true)
Definition: BackendUtility.php:95
‪TYPO3\CMS\Backend\Clipboard\Clipboard\endClipboard
‪endClipboard()
Definition: Clipboard.php:212
‪TYPO3\CMS\Core\Resource\ProcessedFile
Definition: ProcessedFile.php:44
‪TYPO3\CMS\Backend\Clipboard\Clipboard\makeDeleteCmdArray
‪array makeDeleteCmdArray($CMD)
Definition: Clipboard.php:984
‪TYPO3\CMS\Backend\Clipboard\Clipboard\deleteUrl
‪string deleteUrl($setRedirect=true, $file=false)
Definition: Clipboard.php:634
‪TYPO3\CMS\Backend\Clipboard\Clipboard\getLocalizations
‪array getLocalizations($table, $parentRec)
Definition: Clipboard.php:470
‪TYPO3\CMS\Backend\Clipboard\Clipboard\saveClipboard
‪saveClipboard()
Definition: Clipboard.php:801
‪TYPO3\CMS\Fluid\View\StandaloneView
Definition: StandaloneView.php:34
‪TYPO3\CMS\Backend\Utility\BackendUtility\isTableLocalizable
‪static bool isTableLocalizable($table)
Definition: BackendUtility.php:578
‪$GLOBALS
‪$GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['adminpanel']['modules']
Definition: ext_localconf.php:5
‪TYPO3\CMS\Core\Database\Query\Restriction\DeletedRestriction
Definition: DeletedRestriction.php:28
‪TYPO3\CMS\Backend\Clipboard\Clipboard\getContentFromTab
‪array getContentFromTab($pad)
Definition: Clipboard.php:369
‪TYPO3\CMS\Backend\Clipboard\Clipboard\cleanCurrent
‪cleanCurrent()
Definition: Clipboard.php:820
‪TYPO3\CMS\Core\Utility\MathUtility
Definition: MathUtility.php:22
‪TYPO3\CMS\Fluid\View\AbstractTemplateView\setLayoutRootPaths
‪setLayoutRootPaths(array $layoutRootPaths)
Definition: AbstractTemplateView.php:167
‪TYPO3\CMS\Backend\Clipboard\Clipboard\selUrlFile
‪string selUrlFile($path, $copy=0, $deselect=0, $baseArray=[])
Definition: Clipboard.php:590
‪TYPO3\CMS\Backend\Clipboard\Clipboard\$changed
‪int $changed
Definition: Clipboard.php:72
‪TYPO3\CMS\Core\Database\ConnectionPool
Definition: ConnectionPool.php:46
‪TYPO3\CMS\Fluid\View\AbstractTemplateView\setPartialRootPaths
‪setPartialRootPaths(array $partialRootPaths)
Definition: AbstractTemplateView.php:134
‪TYPO3\CMS\Backend\Clipboard
Definition: Clipboard.php:16
‪TYPO3\CMS\Core\Utility\GeneralUtility
Definition: GeneralUtility.php:46
‪TYPO3\CMS\Core\Utility\ExtensionManagementUtility\isLoaded
‪static bool isLoaded($key)
Definition: ExtensionManagementUtility.php:114
‪TYPO3\CMS\Core\Type\Bitmask\JsConfirmation
Definition: JsConfirmation.php:25
‪TYPO3\CMS\Backend\Clipboard\Clipboard\$numberTabs
‪int $numberTabs
Definition: Clipboard.php:46
‪TYPO3\CMS\Backend\Clipboard\Clipboard\getStandaloneView
‪StandaloneView getStandaloneView()
Definition: Clipboard.php:1074
‪TYPO3\CMS\Backend\Clipboard\Clipboard\editUrl
‪string editUrl()
Definition: Clipboard.php:654
‪TYPO3\CMS\Backend\Clipboard\Clipboard\elFromTable
‪array elFromTable($matchTable='', $pad='')
Definition: Clipboard.php:854
‪TYPO3\CMS\Backend\Clipboard\Clipboard\$lockToNormal
‪int $lockToNormal
Definition: Clipboard.php:80
‪TYPO3\CMS\Backend\Clipboard\Clipboard\exportClipElementParameters
‪array exportClipElementParameters()
Definition: Clipboard.php:750
‪TYPO3\CMS\Fluid\View\AbstractTemplateView\setTemplateRootPaths
‪setTemplateRootPaths(array $templateRootPaths)
Definition: AbstractTemplateView.php:114
‪TYPO3\CMS\Core\Database\Query\Restriction\WorkspaceRestriction
Definition: WorkspaceRestriction.php:39