TYPO3CMS  8
 All Classes Namespaces Files Functions Variables Pages
Clipboard.php
Go to the documentation of this file.
1 <?php
2 namespace TYPO3\CMS\Backend\Clipboard;
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 
29 
33 class Clipboard
34 {
38  public $numberTabs = 3;
39 
61  public $clipData = [];
62 
66  public $changed = 0;
67 
71  public $current = '';
72 
76  public $lockToNormal = 0;
77 
83  public $fileMode = 0;
84 
88  protected $iconFactory;
89 
93  protected $view;
94 
100  public function __construct()
101  {
102  $this->iconFactory = GeneralUtility::makeInstance(IconFactory::class);
103  $this->uriBuilder = GeneralUtility::makeInstance(UriBuilder::class);
104  $this->view = $this->getStandaloneView();
105  }
106 
107  /*****************************************
108  *
109  * Initialize
110  *
111  ****************************************/
117  public function initializeClipboard()
118  {
119  // Get data
120  $clipData = $this->getBackendUser()->getModuleData('clipboard', $this->getBackendUser()->getTSConfigVal('options.saveClipboard') ? '' : 'ses');
121  // NumberTabs
122  $clNP = $this->getBackendUser()->getTSConfigVal('options.clipboardNumberPads');
123  if (MathUtility::canBeInterpretedAsInteger($clNP) && $clNP >= 0) {
124  $this->numberTabs = MathUtility::forceIntegerInRange($clNP, 0, 20);
125  }
126  // Resets/reinstates the clipboard pads
127  $this->clipData['normal'] = is_array($clipData['normal']) ? $clipData['normal'] : [];
128  for ($a = 1; $a <= $this->numberTabs; $a++) {
129  $this->clipData['tab_' . $a] = is_array($clipData['tab_' . $a]) ? $clipData['tab_' . $a] : [];
130  }
131  // Setting the current pad pointer ($this->current))
132  $this->clipData['current'] = ($this->current = isset($this->clipData[$clipData['current']]) ? $clipData['current'] : 'normal');
133  }
134 
142  public function lockToNormal()
143  {
144  $this->lockToNormal = 1;
145  $this->current = 'normal';
146  }
147 
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'] = $this->isElements() ? ($cmd['setCopyMode'] ? 'copy' : '') : '';
192  $this->changed = 1;
193  }
194  }
195 
202  public function setCurrentPad($padIdent)
203  {
204  // Change clipboard pad (if not locked to normal)
205  if (!$this->lockToNormal && $this->current != $padIdent) {
206  if (isset($this->clipData[$padIdent])) {
207  $this->clipData['current'] = ($this->current = $padIdent);
208  }
209  if ($this->current != 'normal' || !$this->isElements()) {
210  $this->clipData[$this->current]['mode'] = '';
211  }
212  // Setting mode to default (move) if no items on it or if not 'normal'
213  $this->changed = 1;
214  }
215  }
216 
223  public function endClipboard()
224  {
225  if ($this->changed) {
226  $this->saveClipboard();
227  }
228  $this->changed = 0;
229  }
230 
239  public function cleanUpCBC($CBarr, $table, $removeDeselected = 0)
240  {
241  if (is_array($CBarr)) {
242  foreach ($CBarr as $k => $v) {
243  $p = explode('|', $k);
244  if ((string)$p[0] != (string)$table || $removeDeselected && !$v) {
245  unset($CBarr[$k]);
246  }
247  }
248  }
249  return $CBarr;
250  }
251 
252  /*****************************************
253  *
254  * Clipboard HTML renderings
255  *
256  ****************************************/
263  public function printClipboard()
264  {
265  $languageService = $this->getLanguageService();
266  $elementCount = count($this->elFromTable($this->fileMode ? '_FILE' : ''));
267  // Copymode Selector menu
268  $copymodeUrl = GeneralUtility::linkThisScript();
269 
270  $this->view->assign('actionCopyModeUrl', htmlspecialchars(GeneralUtility::quoteJSvalue($copymodeUrl . '&CB[setCopyMode]=')));
271  $this->view->assign('actionCopyModeUrl1', htmlspecialchars(GeneralUtility::quoteJSvalue($copymodeUrl . '&CB[setCopyMode]=1')));
272  $this->view->assign('currentMode', $this->currentMode());
273  $this->view->assign('elementCount', $elementCount);
274 
275  if ($elementCount) {
276  $removeAllUrl = GeneralUtility::linkThisScript(['CB' => ['removeAll' => $this->current]]);
277  $this->view->assign('removeAllUrl', $removeAllUrl);
278 
279  // Selector menu + clear button
280  $optionArray = [];
281  // Import / Export link:
282  if (ExtensionManagementUtility::isLoaded('impexp')) {
283  $url = BackendUtility::getModuleUrl('xMOD_tximpexp', $this->exportClipElementParameters());
284  $optionArray[] = [
285  'label' => $this->clLabel('export', 'rm'),
286  'uri' => $url
287  ];
288  }
289  // Edit:
290  if (!$this->fileMode) {
291  $optionArray[] = [
292  'label' => $this->clLabel('edit', 'rm'),
293  'uri' => '#',
294  'additionalAttributes' => [
295  'onclick' => htmlspecialchars('window.location.href=' . GeneralUtility::quoteJSvalue($this->editUrl() . '&returnUrl=') . '+top.rawurlencode(window.location.href);'),
296  ]
297  ];
298  }
299 
300  // Delete referenced elements:
301  $confirmationCheck = false;
302  if ($this->getBackendUser()->jsConfirmation(JsConfirmation::DELETE)) {
303  $confirmationCheck = true;
304  }
305 
306  $confirmationMessage = sprintf(
307  $languageService->sL('LLL:EXT:lang/Resources/Private/Language/locallang_core.xlf:mess.deleteClip'),
308  $elementCount
309  );
310  $title = $languageService
311  ->sL('LLL:EXT:lang/Resources/Private/Language/locallang_core.xlf:labels.clipboard.delete_elements');
312  $returnUrl = $this->deleteUrl(1, ($this->fileMode ? 1 : 0));
313  $btnOkText = $languageService
314  ->sL('LLL:EXT:lang/Resources/Private/Language/locallang_alt_doc.xlf:buttons.confirm.delete_elements.yes');
315  $btnCancelText = $languageService
316  ->sL('LLL:EXT:lang/Resources/Private/Language/locallang_alt_doc.xlf:buttons.confirm.delete_elements.no');
317  $optionArray[] = [
318  'label' => htmlspecialchars($title),
319  'uri' => $returnUrl,
320  'additionalAttributes' => [
321  'class' => $confirmationCheck ? 't3js-modal-trigger' : '',
322  ],
323  'data' => [
324  'severity' => 'warning',
325  'button-close-text' => htmlspecialchars($btnCancelText),
326  'button-ok-text' => htmlspecialchars($btnOkText),
327  'content' => htmlspecialchars($confirmationMessage),
328  'title' => htmlspecialchars($title)
329  ]
330  ];
331 
332  // Clear clipboard
333  $optionArray[] = [
334  'label' => $languageService->sL('LLL:EXT:lang/Resources/Private/Language/locallang_core.xlf:labels.clipboard.clear_clipboard', true),
335  'uri' => $removeAllUrl . '#clip_head'
336  ];
337  $this->view->assign('optionArray', $optionArray);
338  }
339 
340  // Print header and content for the NORMAL tab:
341  $this->view->assign('current', $this->current);
342  $tabArray = [];
343  $tabArray['normal'] = [
344  'id' => 'normal',
345  'number' => 0,
346  'url' => GeneralUtility::linkThisScript(['CB' => ['setP' => 'normal']]),
347  'description' => 'normal-description',
348  'label' => 'labels.normal',
349  'padding' => $this->padTitle('normal')
350  ];
351  if ($this->current == 'normal') {
352  $tabArray['normal']['content'] = $this->getContentFromTab('normal');
353  }
354  // Print header and content for the NUMERIC tabs:
355  for ($a = 1; $a <= $this->numberTabs; $a++) {
356  $tabArray['tab_' . $a] = [
357  'id' => 'tab_' . $a,
358  'number' => $a,
359  'url' => GeneralUtility::linkThisScript(['CB' => ['setP' => 'tab_' . $a]]),
360  'description' => 'cliptabs-description',
361  'label' => 'labels.cliptabs-name',
362  'padding' => $this->padTitle('tab_' . $a)
363  ];
364  if ($this->current === 'tab_' . $a) {
365  $tabArray['tab_' . $a]['content'] = $this->getContentFromTab('tab_' . $a);
366  }
367  }
368  $this->view->assign('clipboardHeader', BackendUtility::wrapInHelp('xMOD_csh_corebe', 'list_clipboard', $this->clLabel('clipboard', 'buttons')));
369  $this->view->assign('tabArray', $tabArray);
370  return $this->view->render();
371  }
372 
380  public function getContentFromTab($pad)
381  {
382  $lines = [];
383  if (is_array($this->clipData[$pad]['el'])) {
384  foreach ($this->clipData[$pad]['el'] as $k => $v) {
385  if ($v) {
386  list($table, $uid) = explode('|', $k);
387  // Rendering files/directories on the clipboard
388  if ($table === '_FILE') {
389  $fileObject = ResourceFactory::getInstance()->retrieveFileOrFolderObject($v);
390  if ($fileObject) {
391  $thumb = [];
392  $folder = $fileObject instanceof \TYPO3\CMS\Core\Resource\Folder;
393  $size = $folder ? '' : '(' . GeneralUtility::formatSize($fileObject->getSize()) . 'bytes)';
394  if (!$folder && GeneralUtility::inList($GLOBALS['TYPO3_CONF_VARS']['GFX']['imagefile_ext'],
395  $fileObject->getExtension())
396  ) {
397  $thumb = [
398  'image' => $fileObject->process(\TYPO3\CMS\Core\Resource\ProcessedFile::CONTEXT_IMAGEPREVIEW, []),
399  'title' => htmlspecialchars($fileObject->getName())
400  ];
401  }
402  $lines[] = [
403  'icon' => '<span title="' . htmlspecialchars($fileObject->getName() . ' ' . $size) . '">' . $this->iconFactory->getIconForResource($fileObject,
404  Icon::SIZE_SMALL)->render() . '</span>',
405  'title' => $this->linkItemText(htmlspecialchars(GeneralUtility::fixed_lgd_cs($fileObject->getName(),
406  $this->getBackendUser()->uc['titleLen'])), $fileObject->getName()),
407  'thumb' => $thumb,
408  'infoLink' => htmlspecialchars('top.launchView(' . GeneralUtility::quoteJSvalue($table) . ', ' . GeneralUtility::quoteJSvalue($v) . '); return false;'),
409  'removeLink' => $this->removeUrl('_FILE', GeneralUtility::shortMD5($v))
410  ];
411  } else {
412  // If the file did not exist (or is illegal) then it is removed from the clipboard immediately:
413  unset($this->clipData[$pad]['el'][$k]);
414  $this->changed = 1;
415  }
416  } else {
417  // Rendering records:
418  $rec = BackendUtility::getRecordWSOL($table, $uid);
419  if (is_array($rec)) {
420  $lines[] = [
421  'icon' => $this->linkItemText($this->iconFactory->getIconForRecord($table, $rec,
422  Icon::SIZE_SMALL)->render(), $rec, $table),
423  'title' => $this->linkItemText(htmlspecialchars(GeneralUtility::fixed_lgd_cs(BackendUtility::getRecordTitle($table,
424  $rec), $this->getBackendUser()->uc['titleLen'])), $rec, $table),
425  'infoLink' => htmlspecialchars('top.launchView(' . GeneralUtility::quoteJSvalue($table) . ', \'' . (int)$uid . '\'); return false;'),
426  'removeLink' => $this->removeUrl($table, $uid)
427  ];
428 
429  $localizationData = $this->getLocalizations($table, $rec, '', '');
430  if (!empty($localizationData)) {
431  $lines = array_merge($lines, $localizationData);
432  }
433  } else {
434  unset($this->clipData[$pad]['el'][$k]);
435  $this->changed = 1;
436  }
437  }
438  }
439  }
440  }
441  $this->endClipboard();
442  return $lines;
443  }
444 
450  public function hasElements()
451  {
452  foreach ($this->clipData as $data) {
453  if (isset($data['el']) && is_array($data['el']) && !empty($data['el'])) {
454  return true;
455  }
456  }
457 
458  return false;
459  }
460 
470  public function getLocalizations($table, $parentRec, $bgColClass, $pad)
471  {
472  $lines = [];
473  $tcaCtrl = $GLOBALS['TCA'][$table]['ctrl'];
474  if ($table !== 'pages' && BackendUtility::isTableLocalizable($table) && $table !== 'pages_language_overlay') {
475  $queryBuilder = GeneralUtility::makeInstance(ConnectionPool::class)->getQueryBuilderForTable($table);
476  $queryBuilder->getRestrictions()
477  ->removeAll()
478  ->add(GeneralUtility::makeInstance(DeletedRestriction::class));
479 
480  $queryBuilder
481  ->select('*')
482  ->from($table)
483  ->where(
484  $queryBuilder->expr()->eq(
485  $tcaCtrl['transOrigPointerField'],
486  $queryBuilder->createNamedParameter($parentRec['uid'], \PDO::PARAM_INT)
487  ),
488  $queryBuilder->expr()->neq(
489  $tcaCtrl['languageField'],
490  $queryBuilder->createNamedParameter(0, \PDO::PARAM_INT)
491  )
492  );
493 
494  if (isset($tcaCtrl['versioningWS']) && $tcaCtrl['versioningWS']) {
495  $queryBuilder
496  ->andWhere(
497  $queryBuilder->expr()->eq(
498  't3ver_wsid',
499  $queryBuilder->createNamedParameter($parentRec['t3ver_wsid'], \PDO::PARAM_INT)
500  )
501  );
502  }
503  $rows = $queryBuilder->execute()->fetchAll();
504  if (is_array($rows)) {
505  foreach ($rows as $rec) {
506  $lines[] = [
507  'icon' => $this->iconFactory->getIconForRecord($table, $rec, Icon::SIZE_SMALL)->render(),
508  'title' => htmlspecialchars(GeneralUtility::fixed_lgd_cs(BackendUtility::getRecordTitle($table, $rec), $this->getBackendUser()->uc['titleLen']))
509  ];
510  }
511  }
512  }
513  return $lines;
514  }
515 
522  public function padTitle($pad)
523  {
524  $el = count($this->elFromTable($this->fileMode ? '_FILE' : '', $pad));
525  if ($el) {
526  return ' (' . ($pad == 'normal' ? ($this->clipData['normal']['mode'] == 'copy' ? $this->clLabel('copy', 'cm') : $this->clLabel('cut', 'cm')) : htmlspecialchars($el)) . ')';
527  }
528  return '';
529  }
530 
539  public function linkItemText($str, $rec, $table = '')
540  {
541  if (is_array($rec) && $table) {
542  if ($this->fileMode) {
543  $str = '<span class="text-muted">' . $str . '</span>';
544  } else {
545  $str = '<a href="' . htmlspecialchars(BackendUtility::getModuleUrl('web_list', ['id' => $rec['pid']])) . '">' . $str . '</a>';
546  }
547  } elseif (file_exists($rec)) {
548  if (!$this->fileMode) {
549  $str = '<span class="text-muted">' . $str . '</span>';
550  } else {
551  if (ExtensionManagementUtility::isLoaded('filelist')) {
552  $str = '<a href="' . htmlspecialchars(BackendUtility::getModuleUrl('file_list', ['id' => dirname($rec)])) . '">' . $str . '</a>';
553  }
554  }
555  }
556  return $str;
557  }
558 
569  public function selUrlDB($table, $uid, $copy = 0, $deselect = 0, $baseArray = [])
570  {
571  $CB = ['el' => [rawurlencode($table . '|' . $uid) => $deselect ? 0 : 1]];
572  if ($copy) {
573  $CB['setCopyMode'] = 1;
574  }
575  $baseArray['CB'] = $CB;
576  return GeneralUtility::linkThisScript($baseArray);
577  }
578 
588  public function selUrlFile($path, $copy = 0, $deselect = 0, $baseArray = [])
589  {
590  $CB = ['el' => [rawurlencode('_FILE|' . GeneralUtility::shortMD5($path)) => $deselect ? '' : $path]];
591  if ($copy) {
592  $CB['setCopyMode'] = 1;
593  }
594  $baseArray['CB'] = $CB;
595  return GeneralUtility::linkThisScript($baseArray);
596  }
597 
609  public function pasteUrl($table, $uid, $setRedirect = true, array $update = null)
610  {
611  $urlParameters = [
612  'vC' => $this->getBackendUser()->veriCode(),
613  'prErr' => 1,
614  'uPT' => 1,
615  'CB[paste]' => $table . '|' . $uid,
616  'CB[pad]' => $this->current
617  ];
618  if ($setRedirect) {
619  $urlParameters['redirect'] = GeneralUtility::linkThisScript(['CB' => '']);
620  }
621  if (is_array($update)) {
622  $urlParameters['CB[update]'] = $update;
623  }
624  return BackendUtility::getModuleUrl($table === '_FILE' ? 'tce_file' : 'tce_db', $urlParameters);
625  }
626 
634  public function deleteUrl($setRedirect = 1, $file = 0)
635  {
636  $urlParameters = [
637  'vC' => $this->getBackendUser()->veriCode(),
638  'prErr' => 1,
639  'uPT' => 1,
640  'CB[delete]' => 1,
641  'CB[pad]' => $this->current
642  ];
643  if ($setRedirect) {
644  $urlParameters['redirect'] = GeneralUtility::linkThisScript(['CB' => '']);
645  }
646  return BackendUtility::getModuleUrl($file ? 'tce_file' : 'tce_db', $urlParameters);
647  }
648 
656  public function editUrl()
657  {
658  $parameters = [];
659  // All records
660  $elements = $this->elFromTable('');
661  foreach ($elements as $tP => $value) {
662  list($table, $uid) = explode('|', $tP);
663  $parameters['edit[' . $table . '][' . $uid . ']'] = 'edit';
664  }
665  return BackendUtility::getModuleUrl('record_edit', $parameters);
666  }
667 
676  public function removeUrl($table, $uid)
677  {
678  return GeneralUtility::linkThisScript(['CB' => ['remove' => $table . '|' . $uid]]);
679  }
680 
692  public function confirmMsg($table, $rec, $type, $clElements, $columnLabel = '')
693  {
694  GeneralUtility::logDeprecatedFunction();
695  $message = $this->confirmMsgText($table, $rec, $type, $clElements, $columnLabel);
696  if (!empty($message)) {
697  $message = 'confirm(' . GeneralUtility::quoteJSvalue($message) . ');';
698  }
699  return $message;
700  }
701 
712  public function confirmMsgText($table, $rec, $type, $clElements, $columnLabel = '')
713  {
714  if ($this->getBackendUser()->jsConfirmation(JsConfirmation::COPY_MOVE_PASTE)) {
715  $labelKey = 'LLL:EXT:lang/Resources/Private/Language/locallang_core.xlf:mess.' . ($this->currentMode() == 'copy' ? 'copy' : 'move') . ($this->current == 'normal' ? '' : 'cb') . '_' . $type;
716  $msg = $this->getLanguageService()->sL($labelKey . ($columnLabel ? '_colPos': ''));
717  if ($table == '_FILE') {
718  $thisRecTitle = basename($rec);
719  if ($this->current == 'normal') {
720  $selItem = reset($clElements);
721  $selRecTitle = basename($selItem);
722  } else {
723  $selRecTitle = count($clElements);
724  }
725  } else {
726  $thisRecTitle = $table == 'pages' && !is_array($rec) ? $GLOBALS['TYPO3_CONF_VARS']['SYS']['sitename'] : BackendUtility::getRecordTitle($table, $rec);
727  if ($this->current == 'normal') {
728  $selItem = $this->getSelectedRecord();
729  $selRecTitle = $selItem['_RECORD_TITLE'];
730  } else {
731  $selRecTitle = count($clElements);
732  }
733  }
734  // @TODO
735  // This can get removed as soon as the "_colPos" label is translated
736  // into all available locallang languages.
737  if (!$msg && $columnLabel) {
738  $thisRecTitle .= ' | ' . $columnLabel;
739  $msg = $this->getLanguageService()->sL($labelKey);
740  }
741 
742  // Message
743  $conf = sprintf(
744  $msg,
745  GeneralUtility::fixed_lgd_cs($selRecTitle, 30),
746  GeneralUtility::fixed_lgd_cs($thisRecTitle, 30),
747  GeneralUtility::fixed_lgd_cs($columnLabel, 30)
748  );
749  } else {
750  $conf = '';
751  }
752  return $conf;
753  }
754 
762  public function clLabel($key, $Akey = 'labels')
763  {
764  return htmlspecialchars($this->getLanguageService()->sL('LLL:EXT:lang/Resources/Private/Language/locallang_core.xlf:' . $Akey . '.' . $key));
765  }
766 
772  protected function exportClipElementParameters()
773  {
774  // Init
775  $pad = $this->current;
776  $params = [];
777  $params['tx_impexp']['action'] = 'export';
778  // Traverse items:
779  if (is_array($this->clipData[$pad]['el'])) {
780  foreach ($this->clipData[$pad]['el'] as $k => $v) {
781  if ($v) {
782  list($table, $uid) = explode('|', $k);
783  // Rendering files/directories on the clipboard
784  if ($table == '_FILE') {
785  if (file_exists($v) && GeneralUtility::isAllowedAbsPath($v)) {
786  $params['tx_impexp'][is_dir($v) ? 'dir' : 'file'][] = $v;
787  }
788  } else {
789  // Rendering records:
790  $rec = BackendUtility::getRecord($table, $uid);
791  if (is_array($rec)) {
792  $params['tx_impexp']['record'][] = $table . ':' . $uid;
793  }
794  }
795  }
796  }
797  }
798  return $params;
799  }
800 
801  /*****************************************
802  *
803  * Helper functions
804  *
805  ****************************************/
812  public function removeElement($el)
813  {
814  unset($this->clipData[$this->current]['el'][$el]);
815  $this->changed = 1;
816  }
817 
825  public function saveClipboard()
826  {
827  $this->getBackendUser()->pushModuleData('clipboard', $this->clipData);
828  }
829 
835  public function currentMode()
836  {
837  return $this->clipData[$this->current]['mode'] == 'copy' ? 'copy' : 'cut';
838  }
839 
846  public function cleanCurrent()
847  {
848  if (is_array($this->clipData[$this->current]['el'])) {
849  foreach ($this->clipData[$this->current]['el'] as $k => $v) {
850  list($table, $uid) = explode('|', $k);
851  if ($table != '_FILE') {
852  if (!$v || !is_array(BackendUtility::getRecord($table, $uid, 'uid'))) {
853  unset($this->clipData[$this->current]['el'][$k]);
854  $this->changed = 1;
855  }
856  } else {
857  if (!$v) {
858  unset($this->clipData[$this->current]['el'][$k]);
859  $this->changed = 1;
860  } else {
861  try {
862  ResourceFactory::getInstance()->retrieveFileOrFolderObject($v);
863  } catch (\TYPO3\CMS\Core\Resource\Exception\ResourceDoesNotExistException $e) {
864  // The file has been deleted in the meantime, so just remove it silently
865  unset($this->clipData[$this->current]['el'][$k]);
866  }
867  }
868  }
869  }
870  }
871  }
872 
880  public function elFromTable($matchTable = '', $pad = '')
881  {
882  $pad = $pad ? $pad : $this->current;
883  $list = [];
884  if (is_array($this->clipData[$pad]['el'])) {
885  foreach ($this->clipData[$pad]['el'] as $k => $v) {
886  if ($v) {
887  list($table, $uid) = explode('|', $k);
888  if ($table != '_FILE') {
889  if ((!$matchTable || (string)$table == (string)$matchTable) && $GLOBALS['TCA'][$table]) {
890  $list[$k] = $pad == 'normal' ? $v : $uid;
891  }
892  } else {
893  if ((string)$table == (string)$matchTable) {
894  $list[$k] = $v;
895  }
896  }
897  }
898  }
899  }
900  return $list;
901  }
902 
911  public function isSelected($table, $uid)
912  {
913  $k = $table . '|' . $uid;
914  return $this->clipData[$this->current]['el'][$k] ? ($this->current == 'normal' ? $this->currentMode() : 1) : '';
915  }
916 
926  public function getSelectedRecord($table = '', $uid = '')
927  {
928  if (!$table && !$uid) {
929  $elArr = $this->elFromTable('');
930  reset($elArr);
931  list($table, $uid) = explode('|', key($elArr));
932  }
933  if ($this->isSelected($table, $uid)) {
934  $selRec = BackendUtility::getRecordWSOL($table, $uid);
935  $selRec['_RECORD_TITLE'] = BackendUtility::getRecordTitle($table, $selRec);
936  return $selRec;
937  }
938  return [];
939  }
940 
946  public function isElements()
947  {
948  return is_array($this->clipData[$this->current]['el']) && !empty($this->clipData[$this->current]['el']);
949  }
950 
951  /*****************************************
952  *
953  * FOR USE IN tce_db.php:
954  *
955  ****************************************/
974  public function makePasteCmdArray($ref, $CMD, array $update = null)
975  {
976  list($pTable, $pUid) = explode('|', $ref);
977  $pUid = (int)$pUid;
978  // pUid must be set and if pTable is not set (that means paste ALL elements)
979  // the uid MUST be positive/zero (pointing to page id)
980  if ($pTable || $pUid >= 0) {
981  $elements = $this->elFromTable($pTable);
982  // So the order is preserved.
983  $elements = array_reverse($elements);
984  $mode = $this->currentMode() == 'copy' ? 'copy' : 'move';
985  // Traverse elements and make CMD array
986  foreach ($elements as $tP => $value) {
987  list($table, $uid) = explode('|', $tP);
988  if (!is_array($CMD[$table])) {
989  $CMD[$table] = [];
990  }
991  if (is_array($update)) {
992  $CMD[$table][$uid][$mode] = [
993  'action' => 'paste',
994  'target' => $pUid,
995  'update' => $update,
996  ];
997  } else {
998  $CMD[$table][$uid][$mode] = $pUid;
999  }
1000  if ($mode == 'move') {
1001  $this->removeElement($tP);
1002  }
1003  }
1004  $this->endClipboard();
1005  }
1006  return $CMD;
1007  }
1008 
1015  public function makeDeleteCmdArray($CMD)
1016  {
1017  // all records
1018  $elements = $this->elFromTable('');
1019  foreach ($elements as $tP => $value) {
1020  list($table, $uid) = explode('|', $tP);
1021  if (!is_array($CMD[$table])) {
1022  $CMD[$table] = [];
1023  }
1024  $CMD[$table][$uid]['delete'] = 1;
1025  $this->removeElement($tP);
1026  }
1027  $this->endClipboard();
1028  return $CMD;
1029  }
1030 
1031  /*****************************************
1032  *
1033  * FOR USE IN tce_file.php:
1034  *
1035  ****************************************/
1044  public function makePasteCmdArray_file($ref, $FILE)
1045  {
1046  list($pTable, $pUid) = explode('|', $ref);
1047  $elements = $this->elFromTable('_FILE');
1048  $mode = $this->currentMode() == 'copy' ? 'copy' : 'move';
1049  // Traverse elements and make CMD array
1050  foreach ($elements as $tP => $path) {
1051  $FILE[$mode][] = ['data' => $path, 'target' => $pUid];
1052  if ($mode == 'move') {
1053  $this->removeElement($tP);
1054  }
1055  }
1056  $this->endClipboard();
1057  return $FILE;
1058  }
1059 
1066  public function makeDeleteCmdArray_file($FILE)
1067  {
1068  $elements = $this->elFromTable('_FILE');
1069  // Traverse elements and make CMD array
1070  foreach ($elements as $tP => $path) {
1071  $FILE['delete'][] = ['data' => $path];
1072  $this->removeElement($tP);
1073  }
1074  $this->endClipboard();
1075  return $FILE;
1076  }
1077 
1083  protected function getLanguageService()
1084  {
1085  return $GLOBALS['LANG'];
1086  }
1087 
1093  protected function getBackendUser()
1094  {
1095  return $GLOBALS['BE_USER'];
1096  }
1097 
1105  protected function getStandaloneView()
1106  {
1108  $view = GeneralUtility::makeInstance(StandaloneView::class);
1109  $view->setLayoutRootPaths([GeneralUtility::getFileAbsFileName('EXT:backend/Resources/Private/Layouts')]);
1110  $view->setPartialRootPaths([GeneralUtility::getFileAbsFileName('EXT:backend/Resources/Private/Partials')]);
1111  $view->setTemplateRootPaths([GeneralUtility::getFileAbsFileName('EXT:backend/Resources/Private/Templates')]);
1112 
1113  $view->setTemplatePathAndFilename(GeneralUtility::getFileAbsFileName('EXT:backend/Resources/Private/Templates/Clipboard/Main.html'));
1114 
1115  $view->getRequest()->setControllerExtensionName('Backend');
1116  return $view;
1117  }
1118 }
static getRecordWSOL($table, $uid, $fields= '*', $where= '', $useDeleteClause=true, $unsetMovePointers=false)
linkItemText($str, $rec, $table= '')
Definition: Clipboard.php:539
static formatSize($sizeInBytes, $labels= '', $base=0)
cleanUpCBC($CBarr, $table, $removeDeselected=0)
Definition: Clipboard.php:239
static getRecordTitle($table, $row, $prep=false, $forceResult=true)
clLabel($key, $Akey= 'labels')
Definition: Clipboard.php:762
static linkThisScript(array $getParams=[])
if(TYPO3_MODE=== 'BE') $GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['t3lib/class.t3lib_tsfebeuserauth.php']['frontendEditingController']['default']
deleteUrl($setRedirect=1, $file=0)
Definition: Clipboard.php:634
static makeInstance($className,...$constructorArguments)
elFromTable($matchTable= '', $pad= '')
Definition: Clipboard.php:880
static forceIntegerInRange($theInt, $min, $max=2000000000, $defaultValue=0)
Definition: MathUtility.php:31