TYPO3 CMS  TYPO3_6-2
FileList.php
Go to the documentation of this file.
1 <?php
2 namespace TYPO3\CMS\Filelist;
3 
23 
30 
36  public $iLimit = 40;
37 
43  public $thumbs = 0;
44 
48  public $widthGif = '<img src="clear.gif" width="1" height="1" hspace="165" alt="" />';
49 
55  public $fixedL = 30;
56 
60  public $script = '';
61 
67  public $clickMenus = 1;
68 
74  public $sort = '';
75 
81  public $sortRev = 1;
82 
86  public $firstElementNumber = 0;
87 
91  public $clipBoard = 0;
92 
96  public $bigControlPanel = 0;
97 
101  public $JScode = '';
102 
106  public $HTMLcode = '';
107 
111  public $totalbytes = 0;
112 
116  public $dirs = array();
117 
121  public $files = array();
122 
126  public $path = '';
127 
131  protected $folderObject;
132 
138  public $eCounter = 0;
139 
143  public $dirCounter = 0;
144 
148  public $totalItems = '';
149 
153  public $CBnames = array();
154 
158  public $clipObj;
159 
163  protected $resourceFactory;
164 
169  $this->resourceFactory = $resourceFactory;
170  }
171 
183  public function start(\TYPO3\CMS\Core\Resource\Folder $folderObject, $pointer, $sort, $sortRev, $clipBoard = FALSE, $bigControlPanel = FALSE) {
184  $this->script = BackendUtility::getModuleUrl('file_list');
185  $this->folderObject = $folderObject;
186  $this->counter = 0;
187  $this->totalbytes = 0;
188  $this->JScode = '';
189  $this->HTMLcode = '';
190  $this->path = $folderObject->getReadablePath();
191  $this->sort = $sort;
192  $this->sortRev = $sortRev;
193  $this->firstElementNumber = $pointer;
194  $this->clipBoard = $clipBoard;
195  $this->bigControlPanel = $bigControlPanel;
196  // Setting the maximum length of the filenames to the user's settings or minimum 30 (= $this->fixedL)
197  $this->fixedL = max($this->fixedL, $GLOBALS['BE_USER']->uc['titleLen']);
198  $GLOBALS['LANG']->includeLLFile('EXT:lang/locallang_common.xlf');
199  $this->resourceFactory = ResourceFactory::getInstance();
200  }
201 
208  public function generateList() {
209  $this->HTMLcode .= $this->getTable('fileext,tstamp,size,rw,_REF_');
210  }
211 
218  public function getButtonsAndOtherMarkers(\TYPO3\CMS\Core\Resource\Folder $folderObject) {
219  $otherMarkers = array(
220  'PAGE_ICON' => '',
221  'TITLE' => ''
222  );
223  $buttons = array(
224  'level_up' => $this->getLinkToParentFolder($folderObject),
225  'refresh' => '',
226  'title' => '',
227  'page_icon' => '',
228  'PASTE' => ''
229  );
230  // Makes the code for the folder icon in the top
231  if ($folderObject) {
232  $title = htmlspecialchars($folderObject->getReadablePath());
233  // Start compiling the HTML
234  // If this is some subFolder under the mount root....
235  if ($folderObject->getStorage()->isWithinFileMountBoundaries($folderObject)) {
236  // The icon with link
237  $otherMarkers['PAGE_ICON'] = IconUtility::getSpriteIconForResource($folderObject, array('title' => $title));
238  // No HTML specialchars here - HTML like <strong> </strong> is allowed
239  $otherMarkers['TITLE'] .= GeneralUtility::removeXSS(GeneralUtility::fixed_lgd_cs($title, -($this->fixedL + 20)));
240  } else {
241  // This is the root folder
242  $otherMarkers['PAGE_ICON'] = IconUtility::getSpriteIconForResource($folderObject, array('title' => $title, 'mount-root' => TRUE));
243  $otherMarkers['TITLE'] .= htmlspecialchars(GeneralUtility::fixed_lgd_cs($title, -($this->fixedL + 20)));
244  }
245  if ($this->clickMenus) {
246  $otherMarkers['PAGE_ICON'] = $GLOBALS['SOBE']->doc->wrapClickMenuOnIcon($otherMarkers['PAGE_ICON'], $folderObject->getCombinedIdentifier());
247  }
248  // Add paste button if clipboard is initialized
249  if ($this->clipObj instanceof \TYPO3\CMS\Backend\Clipboard\Clipboard && $folderObject->checkActionPermission('write')) {
250  $elFromTable = $this->clipObj->elFromTable('_FILE');
251  if (count($elFromTable)) {
252  $addPasteButton = TRUE;
253  foreach ($elFromTable as $element) {
254  $clipBoardElement = $this->resourceFactory->retrieveFileOrFolderObject($element);
255  if ($clipBoardElement instanceof Folder && $clipBoardElement->getStorage()->isWithinFolder($clipBoardElement, $folderObject)) {
256  $addPasteButton = FALSE;
257  }
258  }
259  if ($addPasteButton) {
260  $buttons['PASTE'] = '<a href="' . htmlspecialchars($this->clipObj->pasteUrl('_FILE', $folderObject->getCombinedIdentifier())) . '" onclick="return ' . htmlspecialchars($this->clipObj->confirmMsg('_FILE', $this->path, 'into', $elFromTable)) . '" title="' . $GLOBALS['LANG']->getLL('clip_paste', TRUE) . '">' . IconUtility::getSpriteIcon('actions-document-paste-after') . '</a>';
261  }
262  }
263  }
264 
265  }
266  $buttons['refresh'] = '<a href="' . htmlspecialchars($this->listURL()) . '" title="' . $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.xlf:labels.reload', TRUE) . '">' . IconUtility::getSpriteIcon('actions-system-refresh') . '</a>';
267  return array($buttons, $otherMarkers);
268  }
269 
280  public function linkClipboardHeaderIcon($string, $table, $cmd, $warning = '') {
281  $onClickEvent = 'document.dblistForm.cmd.value=\'' . $cmd . '\';document.dblistForm.submit();';
282  if ($warning) {
283  $onClickEvent = 'if (confirm(' . GeneralUtility::quoteJSvalue($warning) . ')){' . $onClickEvent . '}';
284  }
285  return '<a href="#" onclick="' . htmlspecialchars($onClickEvent) . 'return false;">' . $string . '</a>';
286  }
287 
295  public function getTable($rowlist) {
296  // TODO use folder methods directly when they support filters
297  $storage = $this->folderObject->getStorage();
298  $storage->resetFileAndFolderNameFiltersToDefault();
299 
300  // Only render the contents of a browsable storage
301 
302  if ($this->folderObject->getStorage()->isBrowsable()) {
303  $folders = $storage->getFolderIdentifiersInFolder($this->folderObject->getIdentifier());
304  $files = $this->folderObject->getFiles();
305  $this->sort = trim($this->sort);
306  if ($this->sort !== '') {
307  $filesToSort = array();
309  foreach ($files as $fileObject) {
310  switch ($this->sort) {
311  case 'size':
312  $sortingKey = $fileObject->getSize();
313  break;
314  case 'rw':
315  $sortingKey = ($fileObject->checkActionPermission('read') ? 'R' : '' . $fileObject->checkActionPermission('write')) ? 'W' : '';
316  break;
317  case 'fileext':
318  $sortingKey = $fileObject->getExtension();
319  break;
320  case 'tstamp':
321  $sortingKey = $fileObject->getModificationTime();
322  break;
323  case 'file':
324  $sortingKey = $fileObject->getName();
325  break;
326  default:
327  if ($fileObject->hasProperty($this->sort)) {
328  $sortingKey = $fileObject->getProperty($this->sort);
329  } else {
330  $sortingKey = $fileObject->getName();
331  }
332  }
333  $i = 1000000;
334  while (isset($filesToSort[$sortingKey . $i])) {
335  $i++;
336  }
337  $filesToSort[$sortingKey . $i] = $fileObject;
338  }
339  uksort($filesToSort, 'strnatcasecmp');
340  if ((int)$this->sortRev === 1) {
341  $filesToSort = array_reverse($filesToSort);
342  }
343  $files = $filesToSort;
344  }
345  $this->totalItems = count($folders) + count($files);
346  // Adds the code of files/dirs
347  $out = '';
348  $titleCol = 'file';
349  // Cleaning rowlist for duplicates and place the $titleCol as the first column always!
350  $rowlist = GeneralUtility::rmFromList($titleCol, $rowlist);
351  $rowlist = GeneralUtility::uniqueList($rowlist);
352  $rowlist = $rowlist ? $titleCol . ',' . $rowlist : $titleCol;
353  if ($this->bigControlPanel || $this->clipBoard) {
354  $rowlist = str_replace('file,', 'file,_CLIPBOARD_,', $rowlist);
355  }
356  $this->fieldArray = explode(',', $rowlist);
357  $folderObjects = array();
358  foreach ($folders as $folder) {
359  $folderObjects[] = $storage->getFolder($folder, TRUE);
360  }
361 
362  $folderObjects = \TYPO3\CMS\Core\Resource\Utility\ListUtility::resolveSpecialFolderNames($folderObjects);
363  uksort($folderObjects, 'strnatcasecmp');
364 
365  // Directories are added
366  $iOut = $this->formatDirList($folderObjects);
367  // Files are added
368  $iOut .= $this->formatFileList($files, $titleCol);
369  // Header line is drawn
370  $theData = array();
371  foreach ($this->fieldArray as $v) {
372  if ($v == '_CLIPBOARD_' && $this->clipBoard) {
373  $cells = array();
374  $table = '_FILE';
375  $elFromTable = $this->clipObj->elFromTable($table);
376  if (count($elFromTable) && $this->folderObject->checkActionPermission('write')) {
377  $addPasteButton = TRUE;
378  foreach ($elFromTable as $element) {
379  $clipBoardElement = $this->resourceFactory->retrieveFileOrFolderObject($element);
380  if ($clipBoardElement instanceof Folder && $clipBoardElement->getStorage()->isWithinFolder($clipBoardElement, $this->folderObject)) {
381  $addPasteButton = FALSE;
382  }
383  }
384  if ($addPasteButton) {
385  $cells[] = '<a class="btn" href="' . htmlspecialchars($this->clipObj->pasteUrl('_FILE', $this->folderObject->getCombinedIdentifier())) . '" onclick="return ' . htmlspecialchars($this->clipObj->confirmMsg('_FILE', $this->path, 'into', $elFromTable)) . '" title="' . $GLOBALS['LANG']->getLL('clip_paste', 1) . '">' . IconUtility::getSpriteIcon('actions-document-paste-after') . '</a>';
386  }
387  }
388  if ($this->clipObj->current != 'normal' && $iOut) {
389  $cells[] = $this->linkClipboardHeaderIcon(IconUtility::getSpriteIcon('actions-edit-copy', array('title' => $GLOBALS['LANG']->getLL('clip_selectMarked', TRUE))), $table, 'setCB');
390  $cells[] = $this->linkClipboardHeaderIcon(IconUtility::getSpriteIcon('actions-edit-delete', array('title' => $GLOBALS['LANG']->getLL('clip_deleteMarked'))), $table, 'delete', $GLOBALS['LANG']->getLL('clip_deleteMarkedWarning'));
391  $onClick = 'checkOffCB(\'' . implode(',', $this->CBnames) . '\', this); return false;';
392  $cells[] = '<a class="cbcCheckAll" rel="" href="#" onclick="' . htmlspecialchars($onClick) . '" title="' . $GLOBALS['LANG']->getLL('clip_markRecords', TRUE) . '">' . IconUtility::getSpriteIcon('actions-document-select') . '</a>';
393  }
394  $theData[$v] = implode('', $cells);
395  } else {
396  // Normal row:
397  $theT = $this->linkWrapSort($GLOBALS['LANG']->getLL('c_' . $v, TRUE), $this->folderObject->getCombinedIdentifier(), $v);
398  $theData[$v] = $theT;
399  }
400  }
401 
402  $out .= '<thead>' . $this->addelement(1, '&nbsp;', $theData) . '</thead>';
403  $out .= '<tbody>' . $iOut . '</tbody>';
404  // half line is drawn
405  // finish
406  $out = '
407  <!--
408  File list table:
409  -->
410  <table class="t3-table" id="typo3-filelist">
411  ' . $out . '
412  </table>';
413 
414  } else {
416  $flashMessage = GeneralUtility::makeInstance('TYPO3\\CMS\\Core\\Messaging\\FlashMessage', $GLOBALS['LANG']->getLL('storageNotBrowsableMessage'), $GLOBALS['LANG']->getLL('storageNotBrowsableTitle'), \TYPO3\CMS\Core\Messaging\FlashMessage::INFO);
417  $out = $flashMessage->render();
418  }
419  return $out;
420  }
421 
422 
430  protected function getLinkToParentFolder(\TYPO3\CMS\Core\Resource\Folder $currentFolder) {
431  $levelUp = '';
432  try {
433  $currentStorage = $currentFolder->getStorage();
434  $parentFolder = $currentFolder->getParentFolder();
435  if ($parentFolder->getIdentifier() !== $currentFolder->getIdentifier() && $currentStorage->isWithinFileMountBoundaries($parentFolder)) {
436  $levelUp = $this->linkWrapDir(
437  IconUtility::getSpriteIcon(
438  'actions-view-go-up',
439  array('title' => $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.php:labels.upOneLevel', TRUE))
440  ),
441  $parentFolder
442  );
443  }
444  } catch (\Exception $e) {}
445  return $levelUp;
446  }
453  public function getFolderInfo() {
454  if ($this->counter == 1) {
455  $fileLabel = $GLOBALS['LANG']->getLL('file', TRUE);
456  } else {
457  $fileLabel = $GLOBALS['LANG']->getLL('files', TRUE);
458  }
459  return $this->counter . ' ' . $fileLabel . ', ' . GeneralUtility::formatSize($this->totalbytes, $GLOBALS['LANG']->getLL('byteSizeUnits', TRUE));
460  }
461 
469  public function formatDirList(array $folders) {
470  $out = '';
471  foreach ($folders as $folderName => $folderObject) {
472  $role = $folderObject->getRole();
473  if ($role === FolderInterface::ROLE_PROCESSING) {
474  // don't show processing-folder
475  continue;
476  }
477  if ($role !== FolderInterface::ROLE_DEFAULT) {
478  $displayName = '<strong>' . htmlspecialchars($folderName) . '</strong>';
479  } else {
480  $displayName = htmlspecialchars($folderName);
481  }
482 
483  list($flag, $code) = $this->fwd_rwd_nav();
484  $out .= $code;
485  if ($flag) {
486  $isLocked = $folderObject instanceof \TYPO3\CMS\Core\Resource\InaccessibleFolder;
487  $isWritable = $folderObject->checkActionPermission('write');
488 
489  // Initialization
490  $this->counter++;
491 
492  // The icon with link
493  $theIcon = IconUtility::getSpriteIconForResource($folderObject, array('title' => $folderName));
494  if (!$isLocked && $this->clickMenus) {
495  $theIcon = $GLOBALS['SOBE']->doc->wrapClickMenuOnIcon($theIcon, $folderObject->getCombinedIdentifier());
496  }
497 
498  // Preparing and getting the data-array
499  $theData = array();
500  if ($isLocked) {
501  foreach ($this->fieldArray as $field) {
502  $theData[$field] = '';
503  }
504  $theData['file'] = $displayName;
505  } else {
506  foreach ($this->fieldArray as $field) {
507  switch ($field) {
508  case 'size':
509  try {
510  $numFiles = $folderObject->getFileCount();
511  } catch (\TYPO3\CMS\Core\Resource\Exception\InsufficientFolderAccessPermissionsException $e) {
512  $numFiles = 0;
513  }
514  $theData[$field] = $numFiles . ' ' . $GLOBALS['LANG']->getLL(($numFiles === 1 ? 'file' : 'files'), TRUE);
515  break;
516  case 'rw':
517  $theData[$field] = '<span class="typo3-red"><strong>' . $GLOBALS['LANG']->getLL('read', TRUE) . '</strong></span>' . (!$isWritable ? '' : '<span class="typo3-red"><strong>' . $GLOBALS['LANG']->getLL('write', TRUE) . '</strong></span>');
518  break;
519  case 'fileext':
520  $theData[$field] = $GLOBALS['LANG']->getLL('folder', TRUE);
521  break;
522  case 'tstamp':
523  // @todo: FAL: how to get the mtime info -- $theData[$field] = \TYPO3\CMS\Backend\Utility\BackendUtility::date($theFile['tstamp']);
524  $theData[$field] = '-';
525  break;
526  case 'file':
527  $theData[$field] = $this->linkWrapDir($displayName, $folderObject);
528  break;
529  case '_CLIPBOARD_':
530  $temp = '';
531  if ($this->bigControlPanel) {
532  $temp .= $this->makeEdit($folderObject);
533  }
534  $temp .= $this->makeClip($folderObject);
535  $theData[$field] = $temp;
536  break;
537  case '_REF_':
538  $theData[$field] = $this->makeRef($folderObject);
539  break;
540  default:
541  $theData[$field] = GeneralUtility::fixed_lgd_cs($theFile[$field], $this->fixedL);
542  }
543  }
544  }
545  $out .= $this->addelement(1, $theIcon, $theData);
546  }
547  $this->eCounter++;
548  $this->dirCounter = $this->eCounter;
549  }
550  return $out;
551  }
552 
561  public function linkWrapDir($title, \TYPO3\CMS\Core\Resource\Folder $folderObject) {
562  $href = $this->backPath . $this->script . '&id=' . rawurlencode($folderObject->getCombinedIdentifier());
563  $onclick = ' onclick="' . htmlspecialchars(('top.document.getElementsByName("navigation")[0].contentWindow.Tree.highlightActiveItem("file","folder' . GeneralUtility::md5int($folderObject->getCombinedIdentifier()) . '_"+top.fsMod.currentBank)')) . '"';
564  // Sometimes $code contains plain HTML tags. In such a case the string should not be modified!
565  if ((string)$title === strip_tags($title)) {
566  return '<a href="' . htmlspecialchars($href) . '"' . $onclick . ' title="' . htmlspecialchars($title) . '">' . GeneralUtility::fixed_lgd_cs($title, $this->fixedL) . '</a>';
567  } else {
568  return '<a href="' . htmlspecialchars($href) . '"' . $onclick . '>' . $title . '</a>';
569  }
570  }
571 
580  public function linkWrapFile($code, \TYPO3\CMS\Core\Resource\File $fileObject) {
581  $fileUrl = $fileObject->getPublicUrl(TRUE);
582  if ($fileUrl) {
583  $aOnClick = 'return top.openUrlInWindow(\'' . $fileUrl . '\', \'WebFile\');';
584  $code = '<a href="#" title="' . htmlspecialchars($code) . '" onclick="' . htmlspecialchars($aOnClick) . '">' . GeneralUtility::fixed_lgd_cs($code, $this->fixedL) . '</a>';
585  }
586  return $code;
587  }
588 
597  public function listURL() {
598  return GeneralUtility::linkThisScript(array(
599  'target' => rawurlencode($this->folderObject->getCombinedIdentifier()),
600  'imagemode' => $this->thumbs
601  ));
602  }
603 
611  public function dirData(\TYPO3\CMS\Core\Resource\Folder $folderObject) {
613 
614  $title = htmlspecialchars($folderObject->getName());
615  $icon = 'apps-filetree-folder-default';
616  $role = $folderObject->getRole();
617  if ($role === FolderInterface::ROLE_TEMPORARY) {
618  $title = '<strong>' . $GLOBALS['LANG']->getLL('temp', TRUE) . '</strong>';
619  $icon = 'apps-filetree-folder-temp';
620  } elseif ($role === FolderInterface::ROLE_RECYCLER) {
621  $icon = 'apps-filetree-folder-recycler';
622  $title = '<strong>' . $GLOBALS['LANG']->getLL('recycler', TRUE) . '</strong>';
623  }
624  return array($title, $icon, $folderObject->getIdentifier());
625  }
626 
634  public function formatFileList(array $files) {
635  $out = '';
636  // first two keys are "0" (default) and "-1" (multiple), after that comes the "other languages"
637  $allSystemLanguages = GeneralUtility::makeInstance('TYPO3\\CMS\\Backend\\Configuration\\TranslationConfigurationProvider')->getSystemLanguages();
638  $systemLanguages = array_filter($allSystemLanguages, function($languageRecord) {
639  if ($languageRecord['uid'] === -1 || $languageRecord['uid'] === 0 || !$GLOBALS['BE_USER']->checkLanguageAccess($languageRecord['uid'])) {
640  return FALSE;
641  } else {
642  return TRUE;
643  }
644  });
645 
646  foreach ($files as $fileObject) {
647  list($flag, $code) = $this->fwd_rwd_nav();
648  $out .= $code;
649  if ($flag) {
650  // Initialization
651  $this->counter++;
652  $this->totalbytes += $fileObject->getSize();
653  $ext = $fileObject->getExtension();
654  $fileName = trim($fileObject->getName());
655  // The icon with link
656  $theIcon = IconUtility::getSpriteIconForResource($fileObject, array('title' => $fileName . ' [' . (int)$fileObject->getUid() . ']'));
657  if ($this->clickMenus) {
658  $theIcon = $GLOBALS['SOBE']->doc->wrapClickMenuOnIcon($theIcon, $fileObject->getCombinedIdentifier());
659  }
660  // Preparing and getting the data-array
661  $theData = array();
662  foreach ($this->fieldArray as $field) {
663  switch ($field) {
664  case 'size':
665  $theData[$field] = GeneralUtility::formatSize($fileObject->getSize(), $GLOBALS['LANG']->getLL('byteSizeUnits', TRUE));
666  break;
667  case 'rw':
668  $theData[$field] = '' . (!$fileObject->checkActionPermission('read') ? ' ' : '<span class="typo3-red"><strong>' . $GLOBALS['LANG']->getLL('read', TRUE) . '</strong></span>') . (!$fileObject->checkActionPermission('write') ? '' : '<span class="typo3-red"><strong>' . $GLOBALS['LANG']->getLL('write', TRUE) . '</strong></span>');
669  break;
670  case 'fileext':
671  $theData[$field] = strtoupper($ext);
672  break;
673  case 'tstamp':
674  $theData[$field] = BackendUtility::date($fileObject->getModificationTime());
675  break;
676  case '_CLIPBOARD_':
677  $temp = '';
678  if ($this->bigControlPanel) {
679  $temp .= $this->makeEdit($fileObject);
680  }
681  $temp .= $this->makeClip($fileObject);
682  if (!empty($systemLanguages)) {
683  $temp .= '<a class="filelist-translationToggler" data-fileid="' . $fileObject->getUid() . '">' .
684  IconUtility::getSpriteIcon('mimetypes-x-content-page-language-overlay') . '</a>';
685  }
686  $theData[$field] = $temp;
687  break;
688  case '_REF_':
689  $theData[$field] = $this->makeRef($fileObject);
690  break;
691  case 'file':
692  $theData[$field] = $this->linkWrapFile(htmlspecialchars($fileName), $fileObject);
693 
694  if ($fileObject->isMissing()) {
695  $flashMessage = \TYPO3\CMS\Core\Resource\Utility\BackendUtility::getFlashMessageForMissingFile($fileObject);
696  $theData[$field] .= $flashMessage->render();
697  // Thumbnails?
698  } elseif ($this->thumbs && $this->isImage($ext)) {
699  $processedFile = $fileObject->process(\TYPO3\CMS\Core\Resource\ProcessedFile::CONTEXT_IMAGEPREVIEW, array());
700  if ($processedFile) {
701  $thumbUrl = $processedFile->getPublicUrl(TRUE);
702  $theData[$field] .= '<br /><img src="' . $thumbUrl . '" title="' . htmlspecialchars($fileName) . '" alt="" />';
703  }
704  }
705 
706  if (!empty($systemLanguages) && $fileObject->isIndexed() && $fileObject->checkActionPermission('write')) {
707  $metaDataRecord = $fileObject->_getMetaData();
708  $translations = $this->getTranslationsForMetaData($metaDataRecord);
709  $languageCode = '';
710 
711  foreach ($systemLanguages as $language) {
712  $languageId = $language['uid'];
713  $flagIcon = $language['flagIcon'];
714 
715  if (array_key_exists($languageId, $translations)) {
716  $flagButtonIcon = IconUtility::getSpriteIcon(
717  'actions-document-open',
718  array('title' => $fileName),
719  array($flagIcon . '-overlay' => array()));
720  $data = array(
721  'sys_file_metadata' => array($translations[$languageId]['uid'] => 'edit')
722  );
723  $editOnClick = BackendUtility::editOnClick(GeneralUtility::implodeArrayForUrl('edit', $data), $GLOBALS['BACK_PATH'], $this->listUrl());
724  $languageCode .= sprintf('<a href="#" onclick="%s">%s</a>', htmlspecialchars($editOnClick), $flagButtonIcon);
725 
726  } else {
727  $href = $GLOBALS['SOBE']->doc->issueCommand(
728  '&cmd[sys_file_metadata][' . $metaDataRecord['uid'] . '][localize]=' . $languageId,
729  $this->backPath . 'alt_doc.php?justLocalized=' . rawurlencode(('sys_file_metadata:' . $metaDataRecord['uid'] . ':' . $languageId)) .
730  '&returnUrl=' . rawurlencode($this->listURL()) . BackendUtility::getUrlToken('editRecord')
731  );
732  $flagButtonIcon = IconUtility::getSpriteIcon($flagIcon);
733  $languageCode .= sprintf('<a href="%s">%s</a> ', htmlspecialchars($href), $flagButtonIcon);
734  }
735  }
736 
737  // Hide flag button bar when not translated yet
738  $theData[$field] .= '<div class="localisationData" data-fileid="' . $fileObject->getUid() . '"' .
739  (empty($translations) ? ' style="display: none;"' : '') . '>' . $languageCode . '</div>';
740  }
741 
742  break;
743  default:
744  $theData[$field] = '';
745  if ($fileObject->hasProperty($field)) {
746  $theData[$field] = htmlspecialchars(GeneralUtility::fixed_lgd_cs($fileObject->getProperty($field), $this->fixedL));
747  }
748  }
749  }
750  $out .= $this->addelement(1, $theIcon, $theData);
751 
752  }
753  $this->eCounter++;
754  }
755  return $out;
756  }
757 
764  protected function getTranslationsForMetaData($metaDataRecord) {
765  $where = $GLOBALS['TCA']['sys_file_metadata']['ctrl']['transOrigPointerField'] . '=' . (int)$metaDataRecord['uid'] .
766  ' AND ' . $GLOBALS['TCA']['sys_file_metadata']['ctrl']['languageField'] . '>0';
767  $translationRecords = $this->getDatabaseConnection()->exec_SELECTgetRows('*', 'sys_file_metadata', $where);
768  $translations = array();
769  foreach ($translationRecords as $record) {
770  $translations[$record[$GLOBALS['TCA']['sys_file_metadata']['ctrl']['languageField']]] = $record;
771  }
772  return $translations;
773  }
774 
782  public function isImage($ext) {
783  return GeneralUtility::inList($GLOBALS['TYPO3_CONF_VARS']['GFX']['imagefile_ext'], strtolower($ext));
784  }
785 
795  public function linkWrapSort($code, $folderIdentifier, $col) {
796  if ($this->sort === $col) {
797  // Check reverse sorting
798  $params = '&SET[sort]=' . $col . '&SET[reverse]=' . ($this->sortRev ? '0' : '1');
799  $sortArrow = IconUtility::getSpriteIcon('status-status-sorting-light-' . ($this->sortRev ? 'desc' : 'asc'));
800  } else {
801  $params = '&SET[sort]=' . $col . '&SET[reverse]=0';
802  $sortArrow = '';
803  }
804  $href = GeneralUtility::resolveBackPath(($GLOBALS['BACK_PATH'] . $this->script)) . '&id=' . rawurlencode($folderIdentifier) . $params;
805  return '<a href="' . htmlspecialchars($href) . '">' . $code . $sortArrow . '</a>';
806  }
807 
815  public function makeClip($fileOrFolderObject) {
816  if (!$fileOrFolderObject->checkActionPermission('read')) {
817  return '';
818  }
819  $cells = array();
820  $fullIdentifier = $fileOrFolderObject->getCombinedIdentifier();
821  $md5 = GeneralUtility::shortmd5($fullIdentifier);
822  // For normal clipboard, add copy/cut buttons:
823  if ($this->clipObj->current == 'normal') {
824  $isSel = $this->clipObj->isSelected('_FILE', $md5);
825  $cells[] = '<a href="' . htmlspecialchars($this->clipObj->selUrlFile($fullIdentifier, 1, ($isSel == 'copy'))) . '">' . IconUtility::getSpriteIcon(('actions-edit-copy' . ($isSel == 'copy' ? '-release' : '')), array('title' => $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.xlf:cm.copy', TRUE))) . '</a>';
826  // we can only cut if file can be moved
827  if ($fileOrFolderObject->checkActionPermission('move')) {
828  $cells[] = '<a href="' . htmlspecialchars($this->clipObj->selUrlFile($fullIdentifier, 0, ($isSel == 'cut'))) . '">' . IconUtility::getSpriteIcon(('actions-edit-cut' . ($isSel == 'cut' ? '-release' : '')), array('title' => $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.xlf:cm.cut', TRUE))) . '</a>';
829  } else {
830  $cells[] = IconUtility::getSpriteIcon('empty-empty');
831  }
832  } else {
833  // For numeric pads, add select checkboxes:
834  $n = '_FILE|' . $md5;
835  $this->CBnames[] = $n;
836  $checked = $this->clipObj->isSelected('_FILE', $md5) ? ' checked="checked"' : '';
837  $cells[] = '<input type="hidden" name="CBH[' . $n . ']" value="0" />' . '<input type="checkbox" name="CBC[' . $n . ']" value="' . htmlspecialchars($fullIdentifier) . '" class="smallCheckboxes"' . $checked . ' />';
838  }
839  // Display PASTE button, if directory:
840  $elFromTable = $this->clipObj->elFromTable('_FILE');
841  if (is_a($fileOrFolderObject, 'TYPO3\\CMS\\Core\\Resource\\Folder') && count($elFromTable) && $fileOrFolderObject->checkActionPermission('write')) {
842  $addPasteButton = TRUE;
843  foreach ($elFromTable as $element) {
844  $clipBoardElement = $this->resourceFactory->retrieveFileOrFolderObject($element);
845  if ($clipBoardElement instanceof Folder && $clipBoardElement->getStorage()->isWithinFolder($clipBoardElement, $fileOrFolderObject)) {
846  $addPasteButton = FALSE;
847  }
848  }
849  if ($addPasteButton) {
850  $cells[] = '<a class="btn" href="' . htmlspecialchars($this->clipObj->pasteUrl('_FILE', $fullIdentifier)) . '" onclick="return ' . htmlspecialchars($this->clipObj->confirmMsg('_FILE', $fullIdentifier, 'into', $elFromTable)) . '" title="' . $GLOBALS['LANG']->getLL('clip_pasteInto', TRUE) . '">' . IconUtility::getSpriteIcon('actions-document-paste-into') . '</a>';
851  }
852  }
853  // Compile items into a DIV-element:
854  return ' <!-- CLIPBOARD PANEL: -->
855  <div class="typo3-clipCtrl">
856  ' . implode('
857  ', $cells) . '
858  </div>';
859  }
860 
868  public function makeEdit($fileOrFolderObject) {
869  $cells = array();
870  $fullIdentifier = $fileOrFolderObject->getCombinedIdentifier();
871  // Edit metadata of file
872  try {
873  if (is_a($fileOrFolderObject, 'TYPO3\\CMS\\Core\\Resource\\File') && $fileOrFolderObject->isIndexed() && $fileOrFolderObject->checkActionPermission('write')) {
874  $metaData = $fileOrFolderObject->_getMetaData();
875  $data = array(
876  'sys_file_metadata' => array($metaData['uid'] => 'edit')
877  );
878  $editOnClick = BackendUtility::editOnClick(GeneralUtility::implodeArrayForUrl('edit', $data), $GLOBALS['BACK_PATH'], $this->listUrl());
879  $title = htmlspecialchars($GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.xlf:cm.editMetadata'));
880  $cells['editmetadata'] = '<a href="#" onclick="' . $editOnClick . '" title="' . $title . '">'
881  . IconUtility::getSpriteIcon('actions-document-open') . '</a>';
882  } else {
883  $cells['editmetadata'] = IconUtility::getSpriteIcon('empty-empty');
884  }
885  } catch (\Exception $e) {
886  $cells['editmetadata'] = IconUtility::getSpriteIcon('empty-empty');
887  }
888  // Edit file content (if editable)
889  if (is_a($fileOrFolderObject, 'TYPO3\\CMS\\Core\\Resource\\File') && $fileOrFolderObject->checkActionPermission('write') && GeneralUtility::inList($GLOBALS['TYPO3_CONF_VARS']['SYS']['textfile_ext'], $fileOrFolderObject->getExtension())) {
890  $editOnClick = 'top.content.list_frame.location.href=top.TS.PATH_typo3+\'file_edit.php?target=' . rawurlencode($fullIdentifier) . '&returnUrl=\'+top.rawurlencode(top.content.list_frame.document.location.pathname+top.content.list_frame.document.location.search);return false;';
891  $cells['edit'] = '<a href="#" onclick="' . $editOnClick . '" title="' . $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.xlf:cm.editcontent') . '">' . IconUtility::getSpriteIcon('actions-page-open') . '</a>';
892  } else {
893  $cells['edit'] = IconUtility::getSpriteIcon('empty-empty');
894  }
895  // rename the file
896  if ($fileOrFolderObject->checkActionPermission('rename')) {
897  $renameOnClick = 'top.content.list_frame.location.href = top.TS.PATH_typo3+\'file_rename.php?target=' . rawurlencode($fullIdentifier) . '&returnUrl=\'+top.rawurlencode(top.content.list_frame.document.location.pathname+top.content.list_frame.document.location.search);return false;';
898  $cells['rename'] = '<a href="#" onclick="' . $renameOnClick . '" title="' . $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.xlf:cm.rename') . '">' . IconUtility::getSpriteIcon('actions-edit-rename') . '</a>';
899  } else {
900  $cells['rename'] = IconUtility::getSpriteIcon('empty-empty');
901  }
902  if ($fileOrFolderObject->checkActionPermission('read')) {
903  if (is_a($fileOrFolderObject, 'TYPO3\\CMS\\Core\\Resource\\Folder')) {
904  $infoOnClick = 'top.launchView( \'_FOLDER\', \'' . $fullIdentifier . '\');return false;';
905  } elseif (is_a($fileOrFolderObject, 'TYPO3\\CMS\\Core\\Resource\\File')) {
906  $infoOnClick = 'top.launchView( \'_FILE\', \'' . $fullIdentifier . '\');return false;';
907  }
908  $cells['info'] = '<a href="#" onclick="' . $infoOnClick . '" title="' . $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.xlf:cm.info') . '">' . IconUtility::getSpriteIcon('status-dialog-information') . '</a>';
909  } else {
910  $cells['info'] = IconUtility::getSpriteIcon('empty-empty');
911  }
912 
913  // delete the file
914  if ($fileOrFolderObject->checkActionPermission('delete')) {
915  $identifier = $fileOrFolderObject->getIdentifier();
916  if ($fileOrFolderObject instanceof \TYPO3\CMS\Core\Resource\Folder) {
917  $referenceCountText = BackendUtility::referenceCount('_FILE', $identifier, ' (There are %s reference(s) to this folder!)');
918  } else {
919  $referenceCountText = BackendUtility::referenceCount('sys_file', $fileOrFolderObject->getUid(), ' (There are %s reference(s) to this file!)');
920  }
921 
922  if ($GLOBALS['BE_USER']->jsConfirmation(4)) {
923  $confirmationCheck = 'confirm(' . GeneralUtility::quoteJSvalue(sprintf($GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.xlf:mess.delete'), $fileOrFolderObject->getName()) . $referenceCountText) . ')';
924  } else {
925  $confirmationCheck = '1 == 1';
926  }
927 
928  $removeOnClick = 'if (' . $confirmationCheck . ') { top.content.list_frame.location.href=top.TS.PATH_typo3+\'tce_file.php?file[delete][0][data]=' . rawurlencode($fileOrFolderObject->getCombinedIdentifier()) . '&vC=' . $GLOBALS['BE_USER']->veriCode() . BackendUtility::getUrlToken('tceAction') . '&redirect=\'+top.rawurlencode(top.content.list_frame.document.location.pathname+top.content.list_frame.document.location.search);};';
929 
930  $cells['delete'] = '<a href="#" onclick="' . htmlspecialchars($removeOnClick) . '" title="' . $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.xlf:cm.delete') . '">' . IconUtility::getSpriteIcon('actions-edit-delete') . '</a>';
931  } else {
932  $cells['delete'] = IconUtility::getSpriteIcon('empty-empty');
933  }
934 
935  // Hook for manipulating edit icons.
936  if (is_array($GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['fileList']['editIconsHook'])) {
937  $cells['__fileOrFolderObject'] = $fileOrFolderObject;
938  foreach ($GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['fileList']['editIconsHook'] as $classData) {
939  $hookObject = GeneralUtility::getUserObj($classData);
940  if (!$hookObject instanceof \TYPO3\CMS\Filelist\FileListEditIconHookInterface) {
941  throw new \UnexpectedValueException(
942  '$hookObject must implement interface \\TYPO3\\CMS\\Filelist\\FileListEditIconHookInterface',
943  1235225797
944  );
945  }
946  $hookObject->manipulateEditIcons($cells, $this);
947  }
948  unset($cells['__fileOrFolderObject']);
949  }
950  // Compile items into a DIV-element:
951  return ' <!-- EDIT CONTROLS: -->
952  <div class="typo3-editCtrl">
953  ' . implode('
954  ', $cells) . '
955  </div>';
956  }
957 
965  public function makeRef($fileOrFolderObject) {
966  if ($fileOrFolderObject instanceof \TYPO3\CMS\Core\Resource\FolderInterface) {
967  return '-';
968  }
969  // Look up the file in the sys_refindex.
970  // Exclude sys_file_metadata records as these are no use references
971  $databaseConnection = $this->getDatabaseConnection();
972  $table = 'sys_refindex';
973  $rows = $databaseConnection->exec_SELECTgetRows(
974  '*',
975  $table,
976  'ref_table=' . $databaseConnection->fullQuoteStr('sys_file', $table)
977  . ' AND ref_uid=' . (int)$fileOrFolderObject->getUid()
978  . ' AND deleted=0'
979  . ' AND tablename != ' . $databaseConnection->fullQuoteStr('sys_file_metadata', $table)
980  );
981  return $this->generateReferenceToolTip($rows, '\'_FILE\', ' . GeneralUtility::quoteJSvalue($fileOrFolderObject->getCombinedIdentifier()));
982  }
983 
989  protected function getDatabaseConnection() {
990  return $GLOBALS['TYPO3_DB'];
991  }
992 
993 }
makeClip($fileOrFolderObject)
Definition: FileList.php:815
generateReferenceToolTip(array $references, $launchViewParameter='')
static editOnClick($params, $backPath='', $requestUri='')
static getSpriteIconForResource(\TYPO3\CMS\Core\Resource\ResourceInterface $resource, array $options=array(), array $overlays=array())
makeRef($fileOrFolderObject)
Definition: FileList.php:965
static getUserObj($classRef, $checkPrefix='', $silent=FALSE)
static getUrlToken($formName='securityToken', $tokenName='formToken')
linkClipboardHeaderIcon($string, $table, $cmd, $warning='')
Definition: FileList.php:280
getLinkToParentFolder(\TYPO3\CMS\Core\Resource\Folder $currentFolder)
Definition: FileList.php:430
static getModuleUrl($moduleName, $urlParameters=array(), $backPathOverride=FALSE, $returnAbsoluteUrl=FALSE)
linkWrapDir($title, \TYPO3\CMS\Core\Resource\Folder $folderObject)
Definition: FileList.php:561
linkWrapFile($code, \TYPO3\CMS\Core\Resource\File $fileObject)
Definition: FileList.php:580
static linkThisScript(array $getParams=array())
static getSpriteIcon($iconName, array $options=array(), array $overlays=array())
dirData(\TYPO3\CMS\Core\Resource\Folder $folderObject)
Definition: FileList.php:611
makeEdit($fileOrFolderObject)
Definition: FileList.php:868
static implodeArrayForUrl($name, array $theArray, $str='', $skipBlank=FALSE, $rawurlencodeParamName=FALSE)
injectResourceFactory(ResourceFactory $resourceFactory)
Definition: FileList.php:168
static formatSize($sizeInBytes, $labels='')
getTranslationsForMetaData($metaDataRecord)
Definition: FileList.php:764
static fixed_lgd_cs($string, $chars, $appendString='...')
formatFileList(array $files)
Definition: FileList.php:634
linkWrapSort($code, $folderIdentifier, $col)
Definition: FileList.php:795
if(!defined('TYPO3_MODE')) $GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['t3lib/class.t3lib_userauth.php']['logoff_pre_processing'][]
getButtonsAndOtherMarkers(\TYPO3\CMS\Core\Resource\Folder $folderObject)
Definition: FileList.php:218
start(\TYPO3\CMS\Core\Resource\Folder $folderObject, $pointer, $sort, $sortRev, $clipBoard=FALSE, $bigControlPanel=FALSE)
Definition: FileList.php:183