TYPO3 CMS  TYPO3_8-7
RenameFileController.php
Go to the documentation of this file.
1 <?php
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 
25 
30 {
36  public $title;
37 
44  public $target;
45 
52 
58  public $returnUrl;
59 
66  public $content;
67 
71  public function __construct()
72  {
73  parent::__construct();
74  $GLOBALS['SOBE'] = $this;
75  $this->init();
76  }
77 
83  protected function init()
84  {
85  // Initialize GPvars:
86  $this->target = GeneralUtility::_GP('target');
87  $this->returnUrl = GeneralUtility::sanitizeLocalUrl(GeneralUtility::_GP('returnUrl'));
88  // Cleaning and checking target
89  if ($this->target) {
90  $this->fileOrFolderObject = \TYPO3\CMS\Core\Resource\ResourceFactory::getInstance()->retrieveFileOrFolderObject($this->target);
91  }
92  if (!$this->fileOrFolderObject) {
93  $title = $this->getLanguageService()->sL('LLL:EXT:lang/Resources/Private/Language/locallang_mod_file_list.xlf:paramError');
94  $message = $this->getLanguageService()->sL('LLL:EXT:lang/Resources/Private/Language/locallang_mod_file_list.xlf:targetNoDir');
95  throw new \RuntimeException($title . ': ' . $message, 1294586844);
96  }
97  if ($this->fileOrFolderObject->getStorage()->getUid() === 0) {
98  throw new \TYPO3\CMS\Core\Resource\Exception\InsufficientFileAccessPermissionsException('You are not allowed to access files outside your storages', 1375889840);
99  }
100 
101  // If a folder should be renamed, AND the returnURL should go to the old directory name, the redirect is forced
102  // so the redirect will NOT end in an error message
103  // this case only happens if you select the folder itself in the foldertree and then use the clickmenu to
104  // rename the folder
105  if ($this->fileOrFolderObject instanceof \TYPO3\CMS\Core\Resource\Folder) {
106  $parsedUrl = parse_url($this->returnUrl);
107  $queryParts = GeneralUtility::explodeUrl2Array(urldecode($parsedUrl['query']));
108  if ($queryParts['id'] === $this->fileOrFolderObject->getCombinedIdentifier()) {
109  $this->returnUrl = str_replace(
110  urlencode($queryParts['id']),
111  urlencode($this->fileOrFolderObject->getStorage()->getRootLevelFolder()->getCombinedIdentifier()),
112  $this->returnUrl
113  );
114  }
115  }
116 
117  // building pathInfo for metaInformation
118  $pathInfo = [
119  'combined_identifier' => $this->fileOrFolderObject->getCombinedIdentifier(),
120  ];
121  $this->moduleTemplate->getDocHeaderComponent()->setMetaInformation($pathInfo);
122 
123  // Setting up the context sensitive menu
124  $this->moduleTemplate->getPageRenderer()->loadRequireJsModule('TYPO3/CMS/Backend/ContextMenu');
125  $this->moduleTemplate->getPageRenderer()->loadRequireJsModule('TYPO3/CMS/Backend/RenameFile');
126 
127  // Add javaScript
128  $this->moduleTemplate->addJavaScriptCode(
129  'RenameFileInlineJavaScript',
130  'function backToList() {top.goToModule("file_FilelistList");}'
131  );
132  }
133 
137  public function main()
138  {
139  $assigns = [];
140  $assigns['moduleUrlTceFile'] = BackendUtility::getModuleUrl('tce_file');
141  $assigns['returnUrl'] = $this->returnUrl;
142 
143  if ($this->fileOrFolderObject instanceof \TYPO3\CMS\Core\Resource\Folder) {
144  $fileIdentifier = $this->fileOrFolderObject->getCombinedIdentifier();
145  } else {
146  $fileIdentifier = $this->fileOrFolderObject->getUid();
147  $assigns['conflictMode'] = DuplicationBehavior::cast(DuplicationBehavior::RENAME);
148  $assigns['destination'] = $this->fileOrFolderObject->getParentFolder()->getCombinedIdentifier();
149  }
150 
151  $assigns['fileName'] = $this->fileOrFolderObject->getName();
152  $assigns['fileIdentifier'] = $fileIdentifier;
153 
154  // Create buttons
155  $buttonBar = $this->moduleTemplate->getDocHeaderComponent()->getButtonBar();
156 
157  // csh button
158  $cshButton = $buttonBar->makeHelpButton()
159  ->setModuleName('xMOD_csh_corebe')
160  ->setFieldName('file_rename');
161  $buttonBar->addButton($cshButton);
162 
163  // back button
164  if ($this->returnUrl) {
165  $backButton = $buttonBar->makeLinkButton()
166  ->setHref($this->returnUrl)
167  ->setTitle($this->getLanguageService()->sL('LLL:EXT:lang/Resources/Private/Language/locallang_core.xlf:labels.goBack'))
168  ->setIcon($this->moduleTemplate->getIconFactory()->getIcon('actions-view-go-back', Icon::SIZE_SMALL));
169  $buttonBar->addButton($backButton);
170  }
171 
172  $this->moduleTemplate->getPageRenderer()->addInlineLanguageLabelArray([
173  'file_rename.actions.cancel' => $this->getLanguageService()->sL('LLL:EXT:lang/Resources/Private/Language/locallang_core.xlf:file_rename.actions.cancel'),
174  'file_rename.actions.rename' => $this->getLanguageService()->sL('LLL:EXT:lang/Resources/Private/Language/locallang_core.xlf:file_rename.actions.rename'),
175  'file_rename.actions.override' => $this->getLanguageService()->sL('LLL:EXT:lang/Resources/Private/Language/locallang_core.xlf:file_rename.actions.override'),
176  'file_rename.exists.title' => $this->getLanguageService()->sL('LLL:EXT:lang/Resources/Private/Language/locallang_core.xlf:file_rename.exists.title'),
177  'file_rename.exists.description' => $this->getLanguageService()->sL('LLL:EXT:lang/Resources/Private/Language/locallang_core.xlf:file_rename.exists.description'),
178  ]);
179 
180  // Rendering of the output via fluid
181  $view = GeneralUtility::makeInstance(StandaloneView::class);
182  $view->setTemplateRootPaths([GeneralUtility::getFileAbsFileName('EXT:backend/Resources/Private/Templates')]);
183  $view->setPartialRootPaths([GeneralUtility::getFileAbsFileName('EXT:backend/Resources/Private/Partials')]);
184  $view->setTemplatePathAndFilename(GeneralUtility::getFileAbsFileName(
185  'EXT:backend/Resources/Private/Templates/File/RenameFile.html'
186  ));
187  $view->assignMultiple($assigns);
188  $this->content = $view->render();
189  $this->moduleTemplate->setContent($this->content);
190  }
191 
199  public function mainAction(ServerRequestInterface $request, ResponseInterface $response)
200  {
201  $this->main();
202  $response->getBody()->write($this->moduleTemplate->renderContent());
203  return $response;
204  }
205 
211  protected function getLanguageService()
212  {
213  return $GLOBALS['LANG'];
214  }
215 
221  protected function getDocumentTemplate()
222  {
223  return $GLOBALS['TBE_TEMPLATE'];
224  }
225 }
static getFileAbsFileName($filename, $_=null, $_2=null)
static makeInstance($className,... $constructorArguments)
static explodeUrl2Array($string, $multidim=false)
mainAction(ServerRequestInterface $request, ResponseInterface $response)
if(TYPO3_MODE==='BE') $GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['t3lib/class.t3lib_tsfebeuserauth.php']['frontendEditingController']['default']