TYPO3CMS  8
 All Classes Namespaces Files Functions Variables Pages
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 
17 use Psr\Http\Message\ResponseInterface;
18 use Psr\Http\Message\ServerRequestInterface;
29 
34 {
40  public $doc;
41 
47  public $title;
48 
54  public $uid;
55 
62 
68  public $returnUrl;
69 
75  public $content;
76 
80  public function __construct()
81  {
82  parent::__construct();
83  $GLOBALS['SOBE'] = $this;
84  $this->iconFactory = GeneralUtility::makeInstance(IconFactory::class);
85  $this->init();
86  }
87 
95  protected function init()
96  {
97  // Initialize GPvars:
98  $this->uid = (int)GeneralUtility::_GP('uid');
99  $lang = $this->getLanguageService();
100 
101  $this->returnUrl = GeneralUtility::sanitizeLocalUrl(GeneralUtility::_GP('returnUrl'));
102  // Cleaning and checking uid
103  if ($this->uid > 0) {
104  $this->fileOrFolderObject = ResourceFactory::getInstance()
105  ->retrieveFileOrFolderObject('file:' . $this->uid);
106  }
107  if (!$this->fileOrFolderObject) {
108  $title = $lang->sL('LLL:EXT:lang/Resources/Private/Language/locallang_mod_file_list.xlf:paramError');
109  $message = $lang->sL('LLL:EXT:lang/Resources/Private/Language/locallang_mod_file_list.xlf:targetNoDir');
110  throw new \RuntimeException($title . ': ' . $message, 1436895930);
111  }
112  if ($this->fileOrFolderObject->getStorage()->getUid() === 0) {
114  'You are not allowed to access files outside your storages',
115  1436895931
116  );
117  }
118 
119  // If a folder should be renamed, AND the returnURL should go to the old directory name, the redirect is forced
120  // so the redirect will NOT end in an error message
121  // this case only happens if you select the folder itself in the foldertree and then use the clickmenu to
122  // rename the folder
123  if ($this->fileOrFolderObject instanceof Folder) {
124  $parsedUrl = parse_url($this->returnUrl);
125  $queryParts = GeneralUtility::explodeUrl2Array(urldecode($parsedUrl['query']));
126  if ($queryParts['id'] === $this->fileOrFolderObject->getCombinedIdentifier()) {
127  $this->returnUrl = str_replace(
128  urlencode($queryParts['id']),
129  urlencode($this->fileOrFolderObject->getStorage()->getRootLevelFolder()->getCombinedIdentifier()),
130  $this->returnUrl
131  );
132  }
133  }
134 
135  $pathInfo = [
136  'combined_identifier' => $this->fileOrFolderObject->getCombinedIdentifier(),
137  ];
138  $this->moduleTemplate->getDocHeaderComponent()->setMetaInformation($pathInfo);
139  $this->moduleTemplate->getPageRenderer()->loadRequireJsModule('TYPO3/CMS/Backend/ClickMenu');
140  $this->moduleTemplate->addJavaScriptCode(
141  'ReplaceFileOnlineJavaScript',
142  'function backToList() {top.goToModule("file_FilelistList");}'
143  );
144  }
145 
151  public function main()
152  {
153  // Assign variables used by the fluid template
154  $assigns = [];
155  $assigns['moduleUrlTceFile'] = BackendUtility::getModuleUrl('tce_file');
156  $assigns['uid'] = $this->uid;
157  $assigns['returnUrl'] = $this->returnUrl;
158 
159  $buttonBar = $this->moduleTemplate->getDocHeaderComponent()->getButtonBar();
160  // csh button
161  $cshButton = $buttonBar->makeHelpButton()
162  ->setModuleName('xMOD_csh_corebe')
163  ->setFieldName('file_rename');
164  $buttonBar->addButton($cshButton);
165 
166  // Back button
167  if ($this->returnUrl) {
168  $returnButton = $buttonBar->makeLinkButton()
169  ->setHref($this->returnUrl)
170  ->setTitle($this->getLanguageService()->sL('LLL:EXT:lang/Resources/Private/Language/locallang_core.xlf:labels.goBack'))
171  ->setIcon($this->moduleTemplate->getIconFactory()->getIcon('actions-view-go-back', Icon::SIZE_SMALL));
172  $buttonBar->addButton($returnButton);
173  }
174 
175  // Rendering of the output via fluid
176  $view = GeneralUtility::makeInstance(StandaloneView::class);
177  $view->setTemplateRootPaths([GeneralUtility::getFileAbsFileName('EXT:backend/Resources/Private/Templates')]);
178  $view->setPartialRootPaths([GeneralUtility::getFileAbsFileName('EXT:backend/Resources/Private/Partials')]);
179  $view->setTemplatePathAndFilename(GeneralUtility::getFileAbsFileName(
180  'EXT:backend/Resources/Private/Templates/File/ReplaceFile.html'
181  ));
182  $view->assignMultiple($assigns);
183  $this->content = $view->render();
184 
185  $this->moduleTemplate->setContent($this->content);
186  }
187 
195  public function mainAction(ServerRequestInterface $request, ResponseInterface $response)
196  {
197  $this->main();
198 
199  $response->getBody()->write($this->moduleTemplate->renderContent());
200  return $response;
201  }
202 
206  protected function getLanguageService()
207  {
208  return $GLOBALS['LANG'];
209  }
210 }
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)
mainAction(ServerRequestInterface $request, ResponseInterface $response)