‪TYPO3CMS  9.5
RenameFileController.php
Go to the documentation of this file.
1 <?php
2 declare(strict_types = 1);
4 
5 /*
6  * This file is part of the TYPO3 CMS project.
7  *
8  * It is free software; you can redistribute it and/or modify it under
9  * the terms of the GNU General Public License, either version 2
10  * of the License, or any later version.
11  *
12  * For the full copyright and license information, please read the
13  * LICENSE.txt file that was distributed with this source code.
14  *
15  * The TYPO3 project - inspiring people to share!
16  */
17 
18 use Psr\Http\Message\ResponseInterface;
19 use Psr\Http\Message\ServerRequestInterface;
33 
39 {
41 
45  protected ‪$deprecatedPublicProperties = [
46  'title' => 'Using $title of class RenameFileController from outside is discouraged as this variable is only used for internal storage.',
47  'target' => 'Using $target of class RenameFileController from outside is discouraged as this variable is only used for internal storage.',
48  'returnUrl' => 'Using $returnUrl of class RenameFileController from outside is discouraged as this variable is only used for internal storage.',
49  'content' => 'Using $content of class RenameFileController from outside is discouraged as this variable is only used for internal storage.',
50  ];
51 
57  protected ‪$title;
58 
65  protected ‪$target;
66 
72  protected ‪$fileOrFolderObject;
73 
79  protected ‪$returnUrl;
80 
87  protected ‪$content;
88 
94  protected ‪$moduleTemplate;
95 
99  public function ‪__construct()
100  {
101  $this->moduleTemplate = GeneralUtility::makeInstance(ModuleTemplate::class);
102 
103  // @deprecated since TYPO3 v9, will be moved out of __construct() in TYPO3 v10.0
104  $this->‪init(‪$GLOBALS['TYPO3_REQUEST']);
105  }
106 
113  public function ‪mainAction(ServerRequestInterface $request): ResponseInterface
114  {
115  $this->‪renderContent();
116 
117  return new ‪HtmlResponse($this->moduleTemplate->renderContent());
118  }
119 
125  public function ‪main()
126  {
127  trigger_error('RenameFileController->main() will be replaced by protected method renderContent() in TYPO3 v10.0. Do not call from other extension.', E_USER_DEPRECATED);
128  $this->‪renderContent();
129  }
130 
137  protected function ‪init(ServerRequestInterface $request): void
138  {
139  $parsedBody = $request->getParsedBody();
140  $queryParams = $request->getQueryParams();
141 
142  // Initialize GPvars:
143  $this->target = $parsedBody['target'] ?? $queryParams['target'] ?? null;
144  $this->returnUrl = GeneralUtility::sanitizeLocalUrl($parsedBody['returnUrl'] ?? $queryParams['returnUrl'] ?? '');
145  // Cleaning and checking target
146  if ($this->target) {
148  }
149  if (!$this->fileOrFolderObject) {
150  ‪$title = $this->‪getLanguageService()->‪sL('LLL:EXT:filelist/Resources/Private/Language/locallang_mod_file_list.xlf:paramError');
151  $message = $this->‪getLanguageService()->‪sL('LLL:EXT:filelist/Resources/Private/Language/locallang_mod_file_list.xlf:targetNoDir');
152  throw new \RuntimeException(‪$title . ': ' . $message, 1294586844);
153  }
154  if ($this->fileOrFolderObject->getStorage()->getUid() === 0) {
155  throw new InsufficientFileAccessPermissionsException('You are not allowed to access files outside your storages', 1375889840);
156  }
157 
158  // If a folder should be renamed, AND the returnURL should go to the old directory name, the redirect is forced
159  // so the redirect will NOT end in an error message
160  // this case only happens if you select the folder itself in the foldertree and then use the clickmenu to
161  // rename the folder
162  if ($this->fileOrFolderObject instanceof Folder) {
163  $parsedUrl = parse_url($this->returnUrl);
164  $queryParts = GeneralUtility::explodeUrl2Array(urldecode($parsedUrl['query']));
165  if ($queryParts['id'] === $this->fileOrFolderObject->getCombinedIdentifier()) {
166  $this->returnUrl = str_replace(
167  urlencode($queryParts['id']),
168  urlencode($this->fileOrFolderObject->getStorage()->getRootLevelFolder()->getCombinedIdentifier()),
169  $this->returnUrl
170  );
171  }
172  }
173 
174  // building pathInfo for metaInformation
175  $pathInfo = [
176  'combined_identifier' => $this->fileOrFolderObject->getCombinedIdentifier(),
177  ];
178  $this->moduleTemplate->getDocHeaderComponent()->setMetaInformation($pathInfo);
179 
180  // Setting up the context sensitive menu
181  $this->moduleTemplate->getPageRenderer()->loadRequireJsModule('TYPO3/CMS/Backend/ContextMenu');
182  $this->moduleTemplate->getPageRenderer()->loadRequireJsModule('TYPO3/CMS/Backend/RenameFile');
183 
184  // Add javaScript
185  $this->moduleTemplate->addJavaScriptCode(
186  'RenameFileInlineJavaScript',
187  'function backToList() {top.goToModule("file_FilelistList");}'
188  );
189  }
190 
194  protected function ‪renderContent(): void
195  {
196  $assigns = [];
198  $uriBuilder = GeneralUtility::makeInstance(\‪TYPO3\CMS\Backend\Routing\UriBuilder::class);
199  $assigns['moduleUrlTceFile'] = (string)$uriBuilder->buildUriFromRoute('tce_file');
200  $assigns['returnUrl'] = ‪$this->returnUrl;
201 
202  if ($this->fileOrFolderObject instanceof ‪Folder) {
203  $fileIdentifier = $this->fileOrFolderObject->getCombinedIdentifier();
204  $targetLabel = 'file_rename.php.label.target.folder';
205  } else {
206  $fileIdentifier = $this->fileOrFolderObject->getUid();
207  $targetLabel = 'file_rename.php.label.target.file';
209  $assigns['destination'] = $this->fileOrFolderObject->getParentFolder()->getCombinedIdentifier();
210  }
211 
212  $assigns['fileName'] = $this->fileOrFolderObject->getName();
213  $assigns['fileIdentifier'] = $fileIdentifier;
214  $assigns['fieldLabel'] = $targetLabel;
215 
216  // Create buttons
217  $buttonBar = $this->moduleTemplate->getDocHeaderComponent()->getButtonBar();
218 
219  // csh button
220  $cshButton = $buttonBar->makeHelpButton()
221  ->setModuleName('xMOD_csh_corebe')
222  ->setFieldName('file_rename');
223  $buttonBar->addButton($cshButton);
224 
225  // back button
226  if ($this->returnUrl) {
227  $backButton = $buttonBar->makeLinkButton()
228  ->setHref($this->returnUrl)
229  ->setTitle($this->‪getLanguageService()->sL('LLL:EXT:core/Resources/Private/Language/locallang_core.xlf:labels.goBack'))
230  ->setIcon($this->moduleTemplate->getIconFactory()->getIcon('actions-close', ‪Icon::SIZE_SMALL));
231  $buttonBar->addButton($backButton);
232  }
233 
234  // Save and Close button
235  $saveAndCloseButton = $buttonBar->makeInputButton()
236  ->setName('_saveandclose')
237  ->setValue('1')
238  ->setShowLabelText(true)
239  ->setClasses('t3js-submit-file-rename')
240  ->setForm('RenameFileController')
241  ->setTitle($this->‪getLanguageService()->sL('LLL:EXT:core/Resources/Private/Language/locallang_core.xlf:file_edit.php.saveAndClose'))
242  ->setIcon($this->moduleTemplate->getIconFactory()->getIcon('actions-document-save-close', ‪Icon::SIZE_SMALL));
243 
244  $buttonBar->addButton($saveAndCloseButton, ‪ButtonBar::BUTTON_POSITION_LEFT, 20);
245 
246  $this->moduleTemplate->getPageRenderer()->addInlineLanguageLabelArray([
247  'file_rename.actions.cancel' => $this->‪getLanguageService()->sL('LLL:EXT:core/Resources/Private/Language/locallang_core.xlf:file_rename.actions.cancel'),
248  'file_rename.actions.rename' => $this->‪getLanguageService()->sL('LLL:EXT:core/Resources/Private/Language/locallang_core.xlf:file_rename.actions.rename'),
249  'file_rename.actions.override' => $this->‪getLanguageService()->sL('LLL:EXT:core/Resources/Private/Language/locallang_core.xlf:file_rename.actions.override'),
250  'file_rename.exists.title' => $this->‪getLanguageService()->sL('LLL:EXT:core/Resources/Private/Language/locallang_core.xlf:file_rename.exists.title'),
251  'file_rename.exists.description' => $this->‪getLanguageService()->sL('LLL:EXT:core/Resources/Private/Language/locallang_core.xlf:file_rename.exists.description'),
252  ]);
253 
254  // Rendering of the output via fluid
255  $view = GeneralUtility::makeInstance(StandaloneView::class);
256  $view->setTemplateRootPaths([GeneralUtility::getFileAbsFileName('EXT:backend/Resources/Private/Templates')]);
257  $view->setPartialRootPaths([GeneralUtility::getFileAbsFileName('EXT:backend/Resources/Private/Partials')]);
258  $view->setTemplatePathAndFilename(GeneralUtility::getFileAbsFileName(
259  'EXT:backend/Resources/Private/Templates/File/RenameFile.html'
260  ));
261  $view->assignMultiple($assigns);
262  $this->content = $view->render();
263  $this->moduleTemplate->setContent($this->content);
264  }
265 
270  {
271  return ‪$GLOBALS['LANG'];
272  }
273 
277  protected function ‪getDocumentTemplate(): ‪DocumentTemplate
278  {
279  return ‪$GLOBALS['TBE_TEMPLATE'];
280  }
281 }
‪TYPO3\CMS\Core\Imaging\Icon\SIZE_SMALL
‪const SIZE_SMALL
Definition: Icon.php:29
‪TYPO3\CMS\Backend\Controller\File\RenameFileController\$returnUrl
‪string $returnUrl
Definition: RenameFileController.php:73
‪TYPO3\CMS\Backend\Template\Components\ButtonBar\BUTTON_POSITION_LEFT
‪const BUTTON_POSITION_LEFT
Definition: ButtonBar.php:35
‪TYPO3\CMS\Backend\Template\Components\ButtonBar
Definition: ButtonBar.php:31
‪TYPO3\CMS\Core\Resource\DuplicationBehavior
Definition: DuplicationBehavior.php:23
‪TYPO3\CMS\Backend\Controller\File\RenameFileController\$fileOrFolderObject
‪File Folder $fileOrFolderObject
Definition: RenameFileController.php:67
‪TYPO3\CMS\Core\Imaging\Icon
Definition: Icon.php:25
‪TYPO3
‪TYPO3\CMS\Core\Resource\ResourceFactory\getInstance
‪static ResourceFactory getInstance()
Definition: ResourceFactory.php:39
‪TYPO3\CMS\Backend\Controller\File\RenameFileController\$deprecatedPublicProperties
‪array $deprecatedPublicProperties
Definition: RenameFileController.php:43
‪TYPO3\CMS\Backend\Controller\File\RenameFileController\__construct
‪__construct()
Definition: RenameFileController.php:91
‪TYPO3\CMS\Core\Localization\LanguageService\sL
‪string sL($input)
Definition: LanguageService.php:158
‪TYPO3\CMS\Backend\Template\ModuleTemplate
Definition: ModuleTemplate.php:40
‪TYPO3\CMS\Core\Resource\Exception\InsufficientFileAccessPermissionsException
Definition: InsufficientFileAccessPermissionsException.php:21
‪TYPO3\CMS\Backend\Controller\File\RenameFileController\$target
‪string $target
Definition: RenameFileController.php:61
‪TYPO3\CMS\Core\Type\Enumeration\cast
‪static static cast($value)
Definition: Enumeration.php:182
‪TYPO3\CMS\Backend\Template\DocumentTemplate
Definition: DocumentTemplate.php:48
‪TYPO3\CMS\Core\Resource\Folder
Definition: Folder.php:34
‪TYPO3\CMS\Core\Resource\File
Definition: File.php:23
‪TYPO3\CMS\Core\Resource\DuplicationBehavior\RENAME
‪const RENAME
Definition: DuplicationBehavior.php:31
‪TYPO3\CMS\Backend\Controller\File\RenameFileController\init
‪init(ServerRequestInterface $request)
Definition: RenameFileController.php:129
‪TYPO3\CMS\Backend\Controller\File\RenameFileController\renderContent
‪renderContent()
Definition: RenameFileController.php:186
‪TYPO3\CMS\Fluid\View\StandaloneView
Definition: StandaloneView.php:32
‪$GLOBALS
‪$GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['adminpanel']['modules']
Definition: ext_localconf.php:5
‪TYPO3\CMS\Backend\Controller\File\RenameFileController
Definition: RenameFileController.php:39
‪TYPO3\CMS\Backend\Controller\File\RenameFileController\$content
‪string $content
Definition: RenameFileController.php:80
‪TYPO3\CMS\Backend\Controller\File
Definition: CreateFolderController.php:3
‪TYPO3\CMS\Core\Localization\LanguageService
Definition: LanguageService.php:29
‪TYPO3\CMS\Core\Compatibility\PublicPropertyDeprecationTrait
Definition: PublicPropertyDeprecationTrait.php:66
‪TYPO3\CMS\Core\Utility\GeneralUtility
Definition: GeneralUtility.php:45
‪TYPO3\CMS\Backend\Controller\File\RenameFileController\mainAction
‪ResponseInterface mainAction(ServerRequestInterface $request)
Definition: RenameFileController.php:105
‪TYPO3\CMS\Backend\Controller\File\RenameFileController\$moduleTemplate
‪ModuleTemplate $moduleTemplate
Definition: RenameFileController.php:86
‪TYPO3\CMS\Backend\Controller\File\RenameFileController\$title
‪string $title
Definition: RenameFileController.php:54
‪TYPO3\CMS\Backend\Controller\File\RenameFileController\main
‪main()
Definition: RenameFileController.php:117
‪TYPO3\CMS\Backend\Controller\File\RenameFileController\getDocumentTemplate
‪DocumentTemplate getDocumentTemplate()
Definition: RenameFileController.php:269
‪TYPO3\CMS\Backend\Controller\File\RenameFileController\getLanguageService
‪LanguageService getLanguageService()
Definition: RenameFileController.php:261
‪TYPO3\CMS\Core\Resource\ResourceFactory\retrieveFileOrFolderObject
‪File Folder null retrieveFileOrFolderObject($input)
Definition: ResourceFactory.php:491
‪TYPO3\CMS\Core\Http\HtmlResponse
Definition: HtmlResponse.php:25