‪TYPO3CMS  9.5
FolderBrowser.php
Go to the documentation of this file.
1 <?php
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 
24 
30 {
39  protected ‪$expandFolder;
40 
44  protected function ‪initialize()
45  {
46  parent::initialize();
47  $this->pageRenderer->loadRequireJsModule('TYPO3/CMS/Recordlist/BrowseFolders');
48  $this->pageRenderer->loadRequireJsModule('TYPO3/CMS/Backend/LegacyTree', 'function() {
49  DragDrop.table = "folders";
50  Tree.registerDragDropHandlers();
51  }');
52  }
53 
57  protected function ‪initVariables()
58  {
59  parent::initVariables();
60  $this->expandFolder = GeneralUtility::_GP('expandFolder');
61  }
62 
69  public function ‪processSessionData($data)
70  {
71  if ($this->expandFolder !== null) {
72  $data['expandFolder'] = ‪$this->expandFolder;
73  $store = true;
74  } else {
75  $this->expandFolder = $data['expandFolder'];
76  $store = false;
77  }
78  return [$data, $store];
79  }
80 
84  public function ‪render()
85  {
86  $selectedFolder = null;
87  if ($this->expandFolder) {
88  $selectedFolder = ‪ResourceFactory::getInstance()->‪getFolderObjectFromCombinedIdentifier($this->expandFolder);
89  }
90 
91  // Create folder tree:
93  $folderTree = GeneralUtility::makeInstance(ElementBrowserFolderTreeView::class);
94  $folderTree->setLinkParameterProvider($this);
95  $tree = $folderTree->getBrowsableTree();
96 
97  $folders = '';
98  if ($selectedFolder) {
99  $folders = $this->‪renderFolders($selectedFolder);
100  }
101 
102  $this->‪initDocumentTemplate();
103  $content = $this->doc->startPage(htmlspecialchars($this->‪getLanguageService()->getLL('folderSelector')));
104 
105  // Putting the parts together, side by side:
106  $markup = [];
107  $markup[] = '<!-- Wrapper table for folder tree / filelist: -->';
108  $markup[] = '<div class="element-browser">';
109  $markup[] = ' <div class="element-browser-panel element-browser-main">';
110  $markup[] = ' <div class="element-browser-main-sidebar">';
111  $markup[] = ' <div class="element-browser-body">';
112  $markup[] = ' ' . $tree;
113  $markup[] = ' </div>';
114  $markup[] = ' </div>';
115  $markup[] = ' <div class="element-browser-main-content">';
116  $markup[] = ' <div class="element-browser-body">';
117  $markup[] = ' ' . $this->doc->getFlashMessages();
118  $markup[] = ' ' . $folders;
119  if ($selectedFolder) {
120  $markup[] = ' ' . GeneralUtility::makeInstance(FolderUtilityRenderer::class, $this)->createFolder($selectedFolder);
121  }
122  $markup[] = ' </div>';
123  $markup[] = ' </div>';
124  $markup[] = ' </div>';
125  $markup[] = '</div>';
126  $content .= implode('', $markup);
127 
128  // Ending page, returning content:
129  $content .= $this->doc->endPage();
130  return $this->doc->insertStylesAndJS($content);
131  }
132 
137  protected function ‪renderFolders(‪Folder $parentFolder)
138  {
139  if (!$parentFolder->‪checkActionPermission('read')) {
140  return '';
141  }
142  $content = '';
143  $lang = $this->‪getLanguageService();
144  $folders = $parentFolder->‪getSubfolders();
145  $folderIdentifier = $parentFolder->‪getCombinedIdentifier();
146 
147  // Create headline (showing number of folders):
148  $content .= '<h3>' . sprintf(htmlspecialchars($lang->getLL('folders')) . ' (%s):', count($folders)) . '</h3>';
149 
150  $titleLength = (int)$this->‪getBackendUser()->uc['titleLen'];
151  // Create the header of current folder:
152  $folderIcon = '<a href="#" data-folder-id="' . htmlspecialchars($folderIdentifier) . '" data-close="1">';
153  $folderIcon .= $this->iconFactory->getIcon('apps-filetree-folder-default', ‪Icon::SIZE_SMALL);
154  $folderIcon .= htmlspecialchars(GeneralUtility::fixed_lgd_cs($parentFolder->‪getName(), $titleLength));
155  $folderIcon .= '</a>';
156  $content .= $folderIcon . '<br />';
157 
158  $lines = [];
159  // Traverse the folder list:
160  foreach ($folders as $subFolder) {
161  $subFolderIdentifier = $subFolder->getCombinedIdentifier();
162  // Create folder icon:
163  $icon = '<span style="width: 16px; height: 16px; display: inline-block;"></span>';
164  $icon .= '<span title="' . htmlspecialchars($subFolder->getName()) . '">' . $this->iconFactory->getIcon('apps-filetree-folder-default', ‪Icon::SIZE_SMALL) . '</span>';
165  // Create links for adding the folder:
166  $aTag = '<a href="#" data-folder-id="' . htmlspecialchars($subFolderIdentifier) . '" data-close="0">';
167  $aTag_alt = '<a href="#" data-folder-id="' . htmlspecialchars($subFolderIdentifier) . '" data-close="1">';
168  if (strstr($subFolderIdentifier, ',') || strstr($subFolderIdentifier, '|')) {
169  // In case an invalid character is in the filepath, display error message:
170  $errorMessage = sprintf(htmlspecialchars($lang->getLL('invalidChar')), ', |');
171  $aTag = '<a href="#" class="t3js-folderIdError" data-message="' . $errorMessage . '">';
172  }
173  $aTag_e = '</a>';
174  // Combine icon and folderpath:
175  $foldernameAndIcon = $aTag_alt . $icon . htmlspecialchars(GeneralUtility::fixed_lgd_cs($subFolder->getName(), $titleLength)) . $aTag_e;
176  $lines[] = '
177  <tr>
178  <td class="nowrap">' . $foldernameAndIcon . '&nbsp;</td>
179  <td>' . $aTag . '<span title="' . htmlspecialchars($lang->getLL('addToList')) . '">' . $this->iconFactory->getIcon('actions-add', ‪Icon::SIZE_SMALL)->render() . '</span>' . $aTag_e . '</td>
180  <td>&nbsp;</td>
181  </tr>';
182  $lines[] = '
183  <tr>
184  <td colspan="3"><span style="width: 1px; height: 3px; display: inline-block;"></span></td>
185  </tr>';
186  }
187  // Wrap all the rows in table tags:
188  $content .= '
189 
190  <!--
191  Folder listing
192  -->
193  <table border="0" cellpadding="0" cellspacing="1" id="typo3-folderList">
194  ' . implode('', $lines) . '
195  </table>';
196 
197  return $content;
198  }
199 
203  protected function ‪getBodyTagAttributes()
204  {
205  return [
206  'data-mode' => 'folder'
207  ];
208  }
209 
214  public function ‪getUrlParameters(array $values)
215  {
216  return [
217  'mode' => 'folder',
218  'expandFolder' => $values['identifier'] ?? ‪$this->expandFolder,
219  'bparams' => ‪$this->bparams
220  ];
221  }
222 
227  public function ‪isCurrentlySelectedItem(array $values)
228  {
229  return false;
230  }
231 
237  public function ‪getScriptUrl()
238  {
239  return ‪$this->thisScript;
240  }
241 }
‪TYPO3\CMS\Core\Imaging\Icon\SIZE_SMALL
‪const SIZE_SMALL
Definition: Icon.php:29
‪TYPO3\CMS\Recordlist\Browser\FolderBrowser\$expandFolder
‪string null $expandFolder
Definition: FolderBrowser.php:38
‪TYPO3\CMS\Recordlist\Browser\ElementBrowserInterface
Definition: ElementBrowserInterface.php:18
‪TYPO3\CMS\Core\Imaging\Icon
Definition: Icon.php:25
‪TYPO3\CMS\Recordlist\Browser\AbstractElementBrowser\$thisScript
‪string $thisScript
Definition: AbstractElementBrowser.php:45
‪TYPO3\CMS\Recordlist\Browser\AbstractElementBrowser\getBackendUser
‪BackendUserAuthentication getBackendUser()
Definition: AbstractElementBrowser.php:174
‪TYPO3\CMS\Backend\Tree\View\ElementBrowserFolderTreeView
Definition: ElementBrowserFolderTreeView.php:31
‪TYPO3\CMS\Core\Resource\ResourceFactory\getFolderObjectFromCombinedIdentifier
‪Folder getFolderObjectFromCombinedIdentifier($identifier)
Definition: ResourceFactory.php:539
‪TYPO3\CMS\Core\Resource\ResourceFactory\getInstance
‪static ResourceFactory getInstance()
Definition: ResourceFactory.php:39
‪TYPO3\CMS\Recordlist\Browser\FolderBrowser
Definition: FolderBrowser.php:30
‪TYPO3\CMS\Recordlist\Browser\FolderBrowser\isCurrentlySelectedItem
‪bool isCurrentlySelectedItem(array $values)
Definition: FolderBrowser.php:226
‪TYPO3\CMS\Recordlist\Browser\FolderBrowser\initialize
‪initialize()
Definition: FolderBrowser.php:43
‪TYPO3\CMS\Recordlist\Browser\FolderBrowser\initVariables
‪initVariables()
Definition: FolderBrowser.php:56
‪TYPO3\CMS\Core\Resource\Folder\getName
‪string getName()
Definition: Folder.php:91
‪TYPO3\CMS\Recordlist\Browser\FolderBrowser\renderFolders
‪string renderFolders(Folder $parentFolder)
Definition: FolderBrowser.php:136
‪TYPO3\CMS\Recordlist\Browser\FolderBrowser\render
‪string render()
Definition: FolderBrowser.php:83
‪TYPO3\CMS\Core\Resource\Folder\getSubfolders
‪Folder[] getSubfolders($start=0, $numberOfItems=0, $filterMode=self::FILTER_MODE_USE_OWN_AND_STORAGE_FILTERS, $recursive=false)
Definition: Folder.php:287
‪TYPO3\CMS\Core\Resource\Folder
Definition: Folder.php:34
‪TYPO3\CMS\Core\Resource\ResourceFactory
Definition: ResourceFactory.php:33
‪TYPO3\CMS\Recordlist\Browser\AbstractElementBrowser
Definition: AbstractElementBrowser.php:32
‪TYPO3\CMS\Core\Resource\Folder\checkActionPermission
‪bool checkActionPermission($action)
Definition: Folder.php:420
‪TYPO3\CMS\Recordlist\Browser\FolderBrowser\getScriptUrl
‪string getScriptUrl()
Definition: FolderBrowser.php:236
‪TYPO3\CMS\Recordlist\Browser\FolderBrowser\getUrlParameters
‪string[] getUrlParameters(array $values)
Definition: FolderBrowser.php:213
‪TYPO3\CMS\Recordlist\Browser\AbstractElementBrowser\initDocumentTemplate
‪initDocumentTemplate()
Definition: AbstractElementBrowser.php:121
‪TYPO3\CMS\Recordlist\Browser\FolderBrowser\getBodyTagAttributes
‪string[] getBodyTagAttributes()
Definition: FolderBrowser.php:202
‪TYPO3\CMS\Recordlist\Browser\AbstractElementBrowser\getLanguageService
‪LanguageService getLanguageService()
Definition: AbstractElementBrowser.php:166
‪TYPO3\CMS\Recordlist\View\FolderUtilityRenderer
Definition: FolderUtilityRenderer.php:31
‪TYPO3\CMS\Recordlist\Browser\AbstractElementBrowser\$bparams
‪string $bparams
Definition: AbstractElementBrowser.php:71
‪TYPO3\CMS\Core\Resource\Folder\getCombinedIdentifier
‪string getCombinedIdentifier()
Definition: Folder.php:178
‪TYPO3\CMS\Core\Utility\GeneralUtility
Definition: GeneralUtility.php:45
‪TYPO3\CMS\Recordlist\Browser
Definition: AbstractElementBrowser.php:2
‪TYPO3\CMS\Recordlist\Browser\FolderBrowser\processSessionData
‪array[] processSessionData($data)
Definition: FolderBrowser.php:68