[BUGFIX] RTE Image Wizard
[Packages/TYPO3.CMS.git] / typo3 / sysext / recordlist / Classes / View / FolderUtilityRenderer.php
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
17 use TYPO3\CMS\Backend\Utility\BackendUtility;
18 use TYPO3\CMS\Core\Authentication\BackendUserAuthentication;
19 use TYPO3\CMS\Core\Resource\Folder;
20 use TYPO3\CMS\Core\Resource\OnlineMedia\Helpers\OnlineMediaHelperRegistry;
21 use TYPO3\CMS\Core\Utility\GeneralUtility;
22 use TYPO3\CMS\Lang\LanguageService;
23 use TYPO3\CMS\Recordlist\Tree\View\LinkParameterProviderInterface;
24
25 /**
26 * Renders utility forms used in the views for files/folders of Element and Link Browser
27 */
28 class FolderUtilityRenderer
29 {
30 /**
31 * @var LinkParameterProviderInterface
32 */
33 protected $parameterProvider;
34
35 /**
36 * @param LinkParameterProviderInterface $parameterProvider
37 */
38 public function __construct(LinkParameterProviderInterface $parameterProvider)
39 {
40 $this->parameterProvider = $parameterProvider;
41 }
42
43 /**
44 * For TBE: Makes a form for creating new folders in the filemount the user is browsing.
45 * The folder creation request is sent to the tce_file.php script in the core which will handle the creation.
46 *
47 * @param Folder $folderObject Absolute filepath on server in which to create the new folder.
48 *
49 * @return string HTML for the create folder form.
50 */
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
66 $formAction = BackendUtility::getModuleUrl('tce_file');
67 $markup = array();
68 $markup[] = '<div class="element-browser-section element-browser-createfolder">';
69 $markup[] = '<form action="' . htmlspecialchars($formAction)
70 . '" method="post" name="editform" enctype="multipart/form-data">';
71 $markup[] = '<h3>' . $lang->sL('LLL:EXT:lang/locallang_core.xlf:file_newfolder.php.pagetitle', true) . ':</h3>';
72 $markup[] = '<p><strong>' . $lang->getLL('path', true) . ':</strong>'
73 . htmlspecialchars($folderObject->getIdentifier()) . '</p>';
74
75 $a = 1;
76 $markup[] = '<input class="form-control" type="text" name="file[newfolder][' . $a . '][data]" />';
77 $markup[] = '<input type="hidden" name="file[newfolder][' . $a . '][target]" value="'
78 . htmlspecialchars($folderObject->getCombinedIdentifier()) . '" />';
79
80 // Make footer of upload form, including the submit button:
81 $redirectValue = $this->parameterProvider->getScriptUrl() . GeneralUtility::implodeArrayForUrl(
82 '',
83 $this->parameterProvider->getUrlParameters(
84 ['identifier' => $folderObject->getCombinedIdentifier()]
85 )
86 );
87 $markup[] = '<input type="hidden" name="redirect" value="' . htmlspecialchars($redirectValue) . '" />';
88 $markup[] = '<input class="btn btn-default" type="submit" name="submit" value="'
89 . $lang->sL('LLL:EXT:lang/locallang_core.xlf:file_newfolder.php.submit', true) . '" />';
90
91 $markup[] = ' </form>';
92 $markup[] = '</div>';
93
94 return implode(LF, $markup);
95 }
96
97 /**
98 * Makes an upload form for uploading files to the filemount the user is browsing.
99 * The files are uploaded to the tce_file.php script in the core which will handle the upload.
100 *
101 * @param Folder $folderObject
102 * @param string[] $allowedExtensions
103 *
104 * @return string HTML for an upload form.
105 */
106 public function uploadForm(Folder $folderObject, array $allowedExtensions)
107 {
108 if (!$folderObject->checkActionPermission('write')) {
109 return '';
110 }
111 // Read configuration of upload field count
112 $userSetting = $this->getBackendUser()->getTSConfigVal('options.folderTree.uploadFieldsInLinkBrowser');
113 $count = isset($userSetting) ? (int)$userSetting : 1;
114 if ($count === 0) {
115 return '';
116 }
117
118 $count = (int)$count === 0 ? 1 : (int)$count;
119 // Create header, showing upload path:
120 $header = $folderObject->getIdentifier();
121 $lang = $this->getLanguageService();
122 // Create a list of allowed file extensions with the readable format "youtube, vimeo" etc.
123 $fileExtList = array();
124 foreach ($allowedExtensions as $fileExt) {
125 if (GeneralUtility::verifyFilenameAgainstDenyPattern($fileExt)) {
126 $fileExtList[] = '<span class="label label-success">'
127 . strtoupper(htmlspecialchars($fileExt)) . '</span>';
128 }
129 }
130 $formAction = BackendUtility::getModuleUrl('tce_file');
131 $combinedIdentifier = $folderObject->getCombinedIdentifier();
132 $markup = array();
133 $markup[] = '<div class="element-browser-section element-browser-upload">';
134 $markup[] = ' <form action="' . htmlspecialchars($formAction)
135 . '" method="post" name="editform" enctype="multipart/form-data">';
136 $markup[] = ' <h3>' . $lang->sL('LLL:EXT:lang/locallang_core.xlf:file_upload.php.pagetitle', true) . ':</h3>';
137 $markup[] = ' <p><strong>' . $lang->getLL('path', true) . ':</strong>' . htmlspecialchars($header) . '</p>';
138 // Traverse the number of upload fields:
139 for ($a = 1; $a <= $count; $a++) {
140 $markup[] = '<div class="form-group">';
141 $markup[] = '<span class="btn btn-default btn-file">';
142 $markup[] = '<input type="file" multiple="multiple" name="upload_' . $a . '[]" size="50" />';
143 $markup[] = '</span>';
144 $markup[] = '</div>';
145 $markup[] = '<input type="hidden" name="file[upload][' . $a . '][target]" value="'
146 . htmlspecialchars($combinedIdentifier) . '" />';
147 $markup[] = '<input type="hidden" name="file[upload][' . $a . '][data]" value="' . $a . '" />';
148 }
149 $redirectValue = $this->parameterProvider->getScriptUrl() . GeneralUtility::implodeArrayForUrl(
150 '',
151 $this->parameterProvider->getUrlParameters(['identifier' => $combinedIdentifier])
152 );
153 $markup[] = '<input type="hidden" name="redirect" value="' . htmlspecialchars($redirectValue) . '" />';
154
155 if (!empty($fileExtList)) {
156 $markup[] = '<div class="form-group">';
157 $markup[] = ' <label>';
158 $markup[] = $lang->sL('LLL:EXT:lang/locallang_core.xlf:cm.allowedFileExtensions', true) . '<br/>';
159 $markup[] = ' </label>';
160 $markup[] = ' <div class="form-control">';
161 $markup[] = implode(' ', $fileExtList);
162 $markup[] = ' </div>';
163 $markup[] = '</div>';
164 }
165
166 $markup[] = '<div class="checkbox">';
167 $markup[] = ' <label>';
168 $markup[] = ' <input type="checkbox" name="overwriteExistingFiles" id="overwriteExistingFiles" value="1" />';
169 $markup[] = $lang->sL('LLL:EXT:lang/locallang_misc.xlf:overwriteExistingFiles', true);
170 $markup[] = ' </label>';
171 $markup[] = '</div>';
172 $markup[] = '<input class="btn btn-default" type="submit" name="submit" value="'
173 . $lang->sL('LLL:EXT:lang/locallang_core.xlf:file_upload.php.submit', true) . '" />';
174
175 $markup[] = ' </form>';
176 $markup[] = '</div>';
177
178 $code = implode(LF, $markup);
179
180 // Add online media
181 // Create a list of allowed file extensions in a readable format "youtube, vimeo" etc.
182 $fileExtList = array();
183 $onlineMediaFileExt = OnlineMediaHelperRegistry::getInstance()->getSupportedFileExtensions();
184 foreach ($onlineMediaFileExt as $fileExt) {
185 if (GeneralUtility::verifyFilenameAgainstDenyPattern($fileExt)
186 && (empty($allowedExtensions) || in_array($fileExt, $allowedExtensions, true))
187 ) {
188 $fileExtList[] = '<span class="label label-success">'
189 . strtoupper(htmlspecialchars($fileExt)) . '</span>';
190 }
191 }
192 if (!empty($fileExtList)) {
193 $formAction = BackendUtility::getModuleUrl('online_media');
194
195 $markup = array();
196 $markup[] = '<div class="element-browser-section element-browser-mediaurls">';
197 $markup[] = ' <form action="' . htmlspecialchars($formAction)
198 . '" method="post" name="editform1" id="typo3-addMediaForm" enctype="multipart/form-data">';
199 $markup[] = '<h3>' . $lang->sL('LLL:EXT:lang/locallang_core.xlf:online_media.new_media', true) . ':</h3>';
200 $markup[] = '<p><strong>' . $lang->getLL('path', true) . ':</strong>' . htmlspecialchars($header) . '</p>';
201 $markup[] = '<div class="form-group">';
202 $markup[] = '<input type="hidden" name="file[newMedia][0][target]" value="'
203 . htmlspecialchars($folderObject->getCombinedIdentifier()) . '" />';
204 $markup[] = '<input type="hidden" name="file[newMedia][0][allowed]" value="'
205 . htmlspecialchars(implode(',', $allowedExtensions)) . '" />';
206 $markup[] = '<input type="text" name="file[newMedia][0][url]" class="form-control" placeholder="'
207 . $lang->sL('LLL:EXT:lang/locallang_core.xlf:online_media.new_media.placeholder', true) . '" />';
208 $markup[] = '<button class="btn btn-default">'
209 . $lang->sL('LLL:EXT:lang/locallang_core.xlf:online_media.new_media.submit', true) . '</button>';
210 $markup[] = '</div>';
211 $markup[] = '<div class="form-group">';
212 $markup[] = ' <label>';
213 $markup[] = $lang->sL('LLL:EXT:lang/locallang_core.xlf:online_media.new_media.allowedProviders') . '<br/>';
214 $markup[] = ' </label>';
215 $markup[] = ' <div class="form-control">';
216 $markup[] = implode(' ', $fileExtList);
217 $markup[] = ' </div>';
218 $markup[] = '</div>';
219 $markup[] = '<input type="hidden" name="redirect" value="' . htmlspecialchars($redirectValue) . '" />';
220 $markup[] = '</div>';
221 $markup[] = '</form>';
222 $markup[] = '</div>';
223
224 $code .= implode(LF, $markup);
225 }
226
227 return $code;
228 }
229
230 /**
231 * Get the HTML data required for the file search field of the TYPO3 Element Browser.
232 *
233 * @param string $searchWord
234 * @return string HTML data required for the search field in the file list of the Element Browser
235 */
236 public function getFileSearchField($searchWord)
237 {
238 $action = $this->parameterProvider->getScriptUrl()
239 . GeneralUtility::implodeArrayForUrl('', $this->parameterProvider->getUrlParameters([]));
240
241 $markup = [];
242 $markup[] = '<form method="post" action="' . htmlspecialchars($action) . '" style="padding-bottom: 15px;">';
243 $markup[] = ' <div class="input-group">';
244 $markup[] = ' <input class="form-control" type="text" name="searchWord" value="'
245 . htmlspecialchars($searchWord) . '">';
246 $markup[] = ' <span class="input-group-btn">';
247 $markup[] = ' <button class="btn btn-default" type="submit">'
248 . htmlspecialchars(
249 $this->getLanguageService()->sL('LLL:EXT:filelist/Resources/Private/Language/locallang.xlf:search')
250 )
251 . '</button>';
252 $markup[] = ' </span>';
253 $markup[] = ' </div>';
254 $markup[] = '</form>';
255 return implode(LF, $markup);
256 }
257
258 /**
259 * @return LanguageService
260 */
261 protected function getLanguageService()
262 {
263 return $GLOBALS['LANG'];
264 }
265
266 /**
267 * @return BackendUserAuthentication
268 */
269 protected function getBackendUser()
270 {
271 return $GLOBALS['BE_USER'];
272 }
273 }