TYPO3 CMS  TYPO3_8-7
ReplaceFileController.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 
28 
33 {
39  public $doc;
40 
46  public $title;
47 
53  public $uid;
54 
61 
67  public $returnUrl;
68 
74  public $content;
75 
79  public function __construct()
80  {
81  parent::__construct();
82  $GLOBALS['SOBE'] = $this;
83  $this->init();
84  }
85 
92  protected function init()
93  {
94  // Initialize GPvars:
95  $this->uid = (int)GeneralUtility::_GP('uid');
96  $lang = $this->getLanguageService();
97 
98  $this->returnUrl = GeneralUtility::sanitizeLocalUrl(GeneralUtility::_GP('returnUrl'));
99  // Cleaning and checking uid
100  if ($this->uid > 0) {
101  $this->fileOrFolderObject = ResourceFactory::getInstance()
102  ->retrieveFileOrFolderObject('file:' . $this->uid);
103  }
104  if (!$this->fileOrFolderObject) {
105  $title = $lang->sL('LLL:EXT:lang/Resources/Private/Language/locallang_mod_file_list.xlf:paramError');
106  $message = $lang->sL('LLL:EXT:lang/Resources/Private/Language/locallang_mod_file_list.xlf:targetNoDir');
107  throw new \RuntimeException($title . ': ' . $message, 1436895930);
108  }
109  if ($this->fileOrFolderObject->getStorage()->getUid() === 0) {
111  'You are not allowed to access files outside your storages',
112  1436895931
113  );
114  }
115 
116  // If a folder should be renamed, AND the returnURL should go to the old directory name, the redirect is forced
117  // so the redirect will NOT end in an error message
118  // this case only happens if you select the folder itself in the foldertree and then use the clickmenu to
119  // rename the folder
120  if ($this->fileOrFolderObject instanceof Folder) {
121  $parsedUrl = parse_url($this->returnUrl);
122  $queryParts = GeneralUtility::explodeUrl2Array(urldecode($parsedUrl['query']));
123  if ($queryParts['id'] === $this->fileOrFolderObject->getCombinedIdentifier()) {
124  $this->returnUrl = str_replace(
125  urlencode($queryParts['id']),
126  urlencode($this->fileOrFolderObject->getStorage()->getRootLevelFolder()->getCombinedIdentifier()),
127  $this->returnUrl
128  );
129  }
130  }
131 
132  $pathInfo = [
133  'combined_identifier' => $this->fileOrFolderObject->getCombinedIdentifier(),
134  ];
135  $this->moduleTemplate->getDocHeaderComponent()->setMetaInformation($pathInfo);
136  $this->moduleTemplate->getPageRenderer()->loadRequireJsModule('TYPO3/CMS/Backend/ContextMenu');
137  $this->moduleTemplate->addJavaScriptCode(
138  'ReplaceFileOnlineJavaScript',
139  'function backToList() {top.goToModule("file_FilelistList");}'
140  );
141  }
142 
146  public function main()
147  {
148  // Assign variables used by the fluid template
149  $assigns = [];
150  $assigns['moduleUrlTceFile'] = BackendUtility::getModuleUrl('tce_file');
151  $assigns['uid'] = $this->uid;
152  $assigns['returnUrl'] = $this->returnUrl;
153 
154  $buttonBar = $this->moduleTemplate->getDocHeaderComponent()->getButtonBar();
155  // csh button
156  $cshButton = $buttonBar->makeHelpButton()
157  ->setModuleName('xMOD_csh_corebe')
158  ->setFieldName('file_rename');
159  $buttonBar->addButton($cshButton);
160 
161  // Back button
162  if ($this->returnUrl) {
163  $returnButton = $buttonBar->makeLinkButton()
164  ->setHref($this->returnUrl)
165  ->setTitle($this->getLanguageService()->sL('LLL:EXT:lang/Resources/Private/Language/locallang_core.xlf:labels.goBack'))
166  ->setIcon($this->moduleTemplate->getIconFactory()->getIcon('actions-view-go-back', Icon::SIZE_SMALL));
167  $buttonBar->addButton($returnButton);
168  }
169 
170  // Rendering of the output via fluid
171  $view = GeneralUtility::makeInstance(StandaloneView::class);
172  $view->setTemplateRootPaths([GeneralUtility::getFileAbsFileName('EXT:backend/Resources/Private/Templates')]);
173  $view->setPartialRootPaths([GeneralUtility::getFileAbsFileName('EXT:backend/Resources/Private/Partials')]);
174  $view->setTemplatePathAndFilename(GeneralUtility::getFileAbsFileName(
175  'EXT:backend/Resources/Private/Templates/File/ReplaceFile.html'
176  ));
177  $view->assignMultiple($assigns);
178  $this->content = $view->render();
179 
180  $this->moduleTemplate->setContent($this->content);
181  }
182 
190  public function mainAction(ServerRequestInterface $request, ResponseInterface $response)
191  {
192  $this->main();
193 
194  $response->getBody()->write($this->moduleTemplate->renderContent());
195  return $response;
196  }
197 
201  protected function getLanguageService()
202  {
203  return $GLOBALS['LANG'];
204  }
205 }
mainAction(ServerRequestInterface $request, ResponseInterface $response)
static getFileAbsFileName($filename, $_=null, $_2=null)
static makeInstance($className,... $constructorArguments)
static explodeUrl2Array($string, $multidim=false)
if(TYPO3_MODE==='BE') $GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['t3lib/class.t3lib_tsfebeuserauth.php']['frontendEditingController']['default']