TYPO3  7.6
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  }
48 
52  protected function initVariables()
53  {
54  parent::initVariables();
55  $this->expandFolder = GeneralUtility::_GP('expandFolder');
56  }
57 
64  public function processSessionData($data)
65  {
66  if ($this->expandFolder !== null) {
67  $data['expandFolder'] = $this->expandFolder;
68  $store = true;
69  } else {
70  $this->expandFolder = $data['expandFolder'];
71  $store = false;
72  }
73  return array($data, $store);
74  }
75 
79  public function render()
80  {
81  $selectedFolder = null;
82  if ($this->expandFolder) {
83  $selectedFolder = ResourceFactory::getInstance()->getFolderObjectFromCombinedIdentifier($this->expandFolder);
84  }
85 
86  // Create folder tree:
88  $folderTree = GeneralUtility::makeInstance(ElementBrowserFolderTreeView::class);
89  $folderTree->setLinkParameterProvider($this);
90  $tree = $folderTree->getBrowsableTree();
91 
92  $folders = '';
93  if ($selectedFolder) {
94  $folders = $this->renderFolders($selectedFolder);
95  }
96 
97  $this->initDocumentTemplate();
98  $content = $this->doc->startPage('TBE folder selector');
99  $content .= $this->doc->getFlashMessages();
100 
101  // Putting the parts together, side by side:
102  $content .= '
103 
104  <!--
105  Wrapper table for folder tree / folder list:
106  -->
107  <table border="0" cellpadding="0" cellspacing="0" id="typo3-EBfiles">
108  <tr>
109  <td class="c-wCell" valign="top"><h3>' . $this->getLanguageService()->getLL('folderTree', true) . ':</h3>' . $tree . '</td>
110  <td class="c-wCell" valign="top">' . $folders . '</td>
111  </tr>
112  </table>
113  ';
114 
115  // Adding create folder if applicable:
116  if ($selectedFolder) {
117  $content .= GeneralUtility::makeInstance(FolderUtilityRenderer::class, $this)->createFolder($selectedFolder);
118  }
119 
120  // Add some space
121  $content .= '<br /><br />';
122 
123  // Ending page, returning content:
124  $content .= $this->doc->endPage();
125  return $this->doc->insertStylesAndJS($content);
126  }
127 
132  protected function renderFolders(Folder $parentFolder)
133  {
134  if (!$parentFolder->checkActionPermission('read')) {
135  return '';
136  }
137  $content = '';
138  $lang = $this->getLanguageService();
139  $folders = $parentFolder->getSubfolders();
140  $folderIdentifier = $parentFolder->getCombinedIdentifier();
141 
142  // Create headline (showing number of folders):
143  $content .= '<h3>' . sprintf($lang->getLL('folders', true) . ' (%s):', count($folders)) . '</h3>';
144 
145  $titleLength = (int)$this->getBackendUser()->uc['titleLen'];
146  // Create the header of current folder:
147  $folderIcon = '<a href="#" data-folder-id="' . htmlspecialchars($folderIdentifier) . '" data-close="1">';
148  $folderIcon .= $this->iconFactory->getIcon('apps-filetree-folder-default', Icon::SIZE_SMALL);
149  $folderIcon .= htmlspecialchars(GeneralUtility::fixed_lgd_cs($parentFolder->getName(), $titleLength));
150  $folderIcon .= '</a>';
151  $content .= $folderIcon . '<br />';
152 
153  $lines = array();
154  // Traverse the folder list:
155  foreach ($folders as $subFolder) {
156  $subFolderIdentifier = $subFolder->getCombinedIdentifier();
157  // Create folder icon:
158  $icon = '<span style="width: 16px; height: 16px; display: inline-block;"></span>';
159  $icon .= '<span title="' . htmlspecialchars($subFolder->getName()) . '">' . $this->iconFactory->getIcon('apps-filetree-folder-default', Icon::SIZE_SMALL) . '</span>';
160  // Create links for adding the folder:
161  $aTag = '<a href="#" data-folder-id="' . htmlspecialchars($folderIdentifier) . '" data-close="0">';
162  $aTag_alt = '<a href="#" data-folder-id="' . htmlspecialchars($folderIdentifier) . '" data-close="1">';
163  if (strstr($subFolderIdentifier, ',') || strstr($subFolderIdentifier, '|')) {
164  // In case an invalid character is in the filepath, display error message:
165  $errorMessage = sprintf($lang->getLL('invalidChar', true), ', |');
166  $aTag = '<a href="#" class="t3js-folderIdError" data-message="' . $errorMessage . '">';
167  }
168  $aTag_e = '</a>';
169  // Combine icon and folderpath:
170  $foldernameAndIcon = $aTag_alt . $icon . htmlspecialchars(GeneralUtility::fixed_lgd_cs($subFolder->getName(), $titleLength)) . $aTag_e;
171  $lines[] = '
172  <tr class="bgColor4">
173  <td nowrap="nowrap">' . $foldernameAndIcon . '&nbsp;</td>
174  <td>' . $aTag . '<span title="' . $lang->getLL('addToList', true) . '">' . $this->iconFactory->getIcon('actions-edit-add', Icon::SIZE_SMALL)->render() . '</span>' . $aTag_e . '</td>
175  <td>&nbsp;</td>
176  </tr>';
177  $lines[] = '
178  <tr>
179  <td colspan="3"><span style="width: 1px; height: 3px; display: inline-block;"></span></td>
180  </tr>';
181  }
182  // Wrap all the rows in table tags:
183  $content .= '
184 
185  <!--
186  Folder listing
187  -->
188  <table border="0" cellpadding="0" cellspacing="1" id="typo3-folderList">
189  ' . implode('', $lines) . '
190  </table>';
191 
192  return $content;
193  }
194 
198  protected function getBodyTagAttributes()
199  {
200  return [
201  'data-mode' => 'folder'
202  ];
203  }
204 
209  public function getUrlParameters(array $values)
210  {
211  return [
212  'mode' => 'folder',
213  'expandFolder' => isset($values['identifier']) ? $values['identifier'] : $this->expandFolder,
214  ];
215  }
216 
221  public function isCurrentlySelectedItem(array $values)
222  {
223  return false;
224  }
225 
231  public function getScriptUrl()
232  {
233  return $this->thisScript;
234  }
235 }