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