TYPO3  7.6
FolderUtilityRenderer.php
Go to the documentation of this file.
1 <?php
2 namespace TYPO3\CMS\Recordlist\View;
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 {
33  protected $parameterProvider;
34 
39  {
40  $this->parameterProvider = $parameterProvider;
41  }
42 
51  public function createFolder(Folder $folderObject)
52  {
53  if (!$folderObject->checkActionPermission('write')) {
54  return '';
55  }
56  $backendUser = $this->getBackendUser();
57  if (!$backendUser->isAdmin() && !$backendUser->getTSConfigVal('options.createFoldersInEB')) {
58  return '';
59  }
60  // Don't show Folder-create form if it's denied
61  if ($backendUser->getTSConfigVal('options.folderTree.hideCreateFolder')) {
62  return '';
63  }
64  $lang = $this->getLanguageService();
65  $code = '
66 
67  <!--
68  Form, for creating new folders:
69  -->
70  <form action="' . htmlspecialchars(BackendUtility::getModuleUrl('tce_file')) . '" method="post" name="editform2" id="typo3-crFolderForm">
71  <table border="0" cellpadding="0" cellspacing="0" id="typo3-crFolder">
72  <tr>
73  <td><h3>' . $lang->sL('LLL:EXT:lang/locallang_core.xlf:file_newfolder.php.pagetitle', true) . ':</h3></td>
74  </tr>
75  <tr>
76  <td class="c-wCell c-hCell"><strong>' . $lang->getLL('path', true) . ':</strong> '
77  . htmlspecialchars($folderObject->getIdentifier()) . '</td>
78  </tr>
79  <tr>
80  <td class="c-wCell c-hCell">';
81  // Create the new-folder name field:
82  $a = 1;
83  $code .= '<input size="20" type="text" name="file[newfolder][' . $a . '][data]" />'
84  . '<input type="hidden" name="file[newfolder][' . $a . '][target]" value="'
85  . htmlspecialchars($folderObject->getCombinedIdentifier()) . '" />';
86  // Make footer of upload form, including the submit button:
87  $redirectValue = $this->parameterProvider->getScriptUrl() . GeneralUtility::implodeArrayForUrl('', $this->parameterProvider->getUrlParameters(['identifier' => $folderObject->getCombinedIdentifier()]));
88  $code .= '<input type="hidden" name="redirect" value="' . htmlspecialchars($redirectValue) . '" />'
89  . '<input class="btn btn-default" type="submit" name="submit" value="'
90  . $lang->sL('LLL:EXT:lang/locallang_core.xlf:file_newfolder.php.submit', true) . '" />';
91  $code .= '</td>
92  </tr>
93  </table>
94  </form>';
95  return $code;
96  }
97 
107  public function uploadForm(Folder $folderObject, array $allowedExtensions)
108  {
109  if (!$folderObject->checkActionPermission('write')) {
110  return '';
111  }
112  // Read configuration of upload field count
113  $userSetting = $this->getBackendUser()->getTSConfigVal('options.folderTree.uploadFieldsInLinkBrowser');
114  $count = isset($userSetting) ? (int)$userSetting : 1;
115  if ($count === 0) {
116  return '';
117  }
118 
119  $count = (int)$count === 0 ? 1 : (int)$count;
120  // Create header, showing upload path:
121  $header = $folderObject->getIdentifier();
122  $lang = $this->getLanguageService();
123  // Create a list of allowed file extensions with the readable format "youtube, vimeo" etc.
124  $fileExtList = array();
125  foreach ($allowedExtensions as $fileExt) {
127  $fileExtList[] = '<span class="label label-success">' . strtoupper(htmlspecialchars($fileExt)) . '</span>';
128  }
129  }
130  $code = '
131  <br />
132  <!--
133  Form, for uploading files:
134  -->
135  <form action="' . htmlspecialchars(BackendUtility::getModuleUrl('tce_file')) . '" method="post" name="editform"'
136  . ' id="typo3-uplFilesForm" enctype="multipart/form-data">
137  <table border="0" cellpadding="0" cellspacing="0" id="typo3-uplFiles">
138  <tr>
139  <td><h3>' . $lang->sL('LLL:EXT:lang/locallang_core.xlf:file_upload.php.pagetitle', true) . ':</h3></td>
140  </tr>
141  <tr>
142  <td class="c-wCell c-hCell"><strong>' . $lang->getLL('path', true) . ':</strong> ' . htmlspecialchars($header) . '</td>
143  </tr>
144  <tr>
145  <td class="c-wCell c-hCell">';
146  // Traverse the number of upload fields:
147  $combinedIdentifier = $folderObject->getCombinedIdentifier();
148  for ($a = 1; $a <= $count; $a++) {
149  $code .= '<input type="file" multiple="multiple" name="upload_' . $a . '[]" size="50" />
150  <input type="hidden" name="file[upload][' . $a . '][target]" value="' . htmlspecialchars($combinedIdentifier) . '" />
151  <input type="hidden" name="file[upload][' . $a . '][data]" value="' . $a . '" /><br />';
152  }
153 
154  $redirectValue = $this->parameterProvider->getScriptUrl() . GeneralUtility::implodeArrayForUrl('', $this->parameterProvider->getUrlParameters(['identifier' => $combinedIdentifier]));
155  $code .= '<input type="hidden" name="redirect" value="' . htmlspecialchars($redirectValue) . '" />';
156 
157  if (!empty($fileExtList)) {
158  $code .= '
159  <div class="help-block">
160  ' . $lang->sL('LLL:EXT:lang/locallang_core.xlf:cm.allowedFileExtensions', true) . '<br>
161  ' . implode(' ', $fileExtList) . '
162  </div>
163  ';
164  }
165 
166  $code .= '
167  <div id="c-override">
168  <label>
169  <input type="checkbox" name="overwriteExistingFiles" id="overwriteExistingFiles" value="1" /> ' . $lang->sL('LLL:EXT:lang/locallang_misc.xlf:overwriteExistingFiles', true) . '
170  </label>
171  </div>
172  <input class="btn btn-default" type="submit" name="submit" value="' . $lang->sL('LLL:EXT:lang/locallang_core.xlf:file_upload.php.submit', true) . '" />
173  ';
174  $code .= '</td>
175  </tr>
176  </table>
177  </form><br />';
178 
179  // Add online media
180  // Create a list of allowed file extensions in a readable format "youtube, vimeo" etc.
181  $fileExtList = array();
182  $onlineMediaFileExt = OnlineMediaHelperRegistry::getInstance()->getSupportedFileExtensions();
183  foreach ($onlineMediaFileExt as $fileExt) {
184  if (
186  && (empty($allowedExtensions) || in_array($fileExt, $allowedExtensions, true))
187  ) {
188  $fileExtList[] = '<span class="label label-success">' . strtoupper(htmlspecialchars($fileExt)) . '</span>';
189  }
190  }
191  if (!empty($fileExtList)) {
192  $code .= '
193  <!--
194  Form, adding online media urls:
195  -->
196  <form action="' . htmlspecialchars(BackendUtility::getModuleUrl('online_media')) . '" method="post" name="editform1"'
197  . ' id="typo3-addMediaForm">
198  <table border="0" cellpadding="0" cellspacing="0" id="typo3-uplFiles">
199  <tr>
200  <td><h3>' . $lang->sL('LLL:EXT:lang/locallang_core.xlf:online_media.new_media', true) . ':</h3></td>
201  </tr>
202  <tr>
203  <td class="c-wCell c-hCell"><strong>' . $lang->getLL('path', true) . ':</strong> '
204  . htmlspecialchars($header) . '</td>
205  </tr>
206  <tr>
207  <td class="c-wCell c-hCell">
208  <input type="text" name="file[newMedia][0][url]" size="50" placeholder="' . $lang->sL('LLL:EXT:lang/locallang_core.xlf:online_media.new_media.placeholder', true) . '" />
209  <input type="hidden" name="file[newMedia][0][target]" value="' . htmlspecialchars($folderObject->getCombinedIdentifier()) . '" />
210  <input type="hidden" name="file[newMedia][0][allowed]" value="' . htmlspecialchars(implode(',', $allowedExtensions)) . '" />
211  <button>' . $lang->sL('LLL:EXT:lang/locallang_core.xlf:online_media.new_media.submit', true) . '</button>
212  <div class="help-block">
213  ' . $lang->sL('LLL:EXT:lang/locallang_core.xlf:online_media.new_media.allowedProviders') . '<br />
214  ' . implode(' ', $fileExtList) . '
215  </div>
216  ';
217  $code .= '<input type="hidden" name="redirect" value="' . htmlspecialchars($redirectValue) . '" />';
218 
219  $code .= '</td>
220  </tr>
221  </table>
222  </form><br />';
223  }
224 
225  return $code;
226  }
227 
231  protected function getLanguageService()
232  {
233  return $GLOBALS['LANG'];
234  }
235 
239  protected function getBackendUser()
240  {
241  return $GLOBALS['BE_USER'];
242  }
243 }