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