TYPO3 CMS  TYPO3_7-6
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 
23 
28 {
34  public $title;
35 
42  public $target;
43 
50 
56  public $returnUrl;
57 
64  public $content;
65 
69  public function __construct()
70  {
71  parent::__construct();
72  $GLOBALS['SOBE'] = $this;
73  $this->init();
74  }
75 
81  protected function init()
82  {
83  // Initialize GPvars:
84  $this->target = GeneralUtility::_GP('target');
85  $this->returnUrl = GeneralUtility::sanitizeLocalUrl(GeneralUtility::_GP('returnUrl'));
86  // Cleaning and checking target
87  if ($this->target) {
88  $this->fileOrFolderObject = \TYPO3\CMS\Core\Resource\ResourceFactory::getInstance()->retrieveFileOrFolderObject($this->target);
89  }
90  if (!$this->fileOrFolderObject) {
91  $title = $this->getLanguageService()->sL('LLL:EXT:lang/locallang_mod_file_list.xlf:paramError', true);
92  $message = $this->getLanguageService()->sL('LLL:EXT:lang/locallang_mod_file_list.xlf:targetNoDir', true);
93  throw new \RuntimeException($title . ': ' . $message, 1294586844);
94  }
95  if ($this->fileOrFolderObject->getStorage()->getUid() === 0) {
96  throw new \TYPO3\CMS\Core\Resource\Exception\InsufficientFileAccessPermissionsException('You are not allowed to access files outside your storages', 1375889840);
97  }
98 
99  // If a folder should be renamed, AND the returnURL should go to the old directory name, the redirect is forced
100  // so the redirect will NOT end in an error message
101  // this case only happens if you select the folder itself in the foldertree and then use the clickmenu to
102  // rename the folder
103  if ($this->fileOrFolderObject instanceof \TYPO3\CMS\Core\Resource\Folder) {
104  $parsedUrl = parse_url($this->returnUrl);
105  $queryParts = GeneralUtility::explodeUrl2Array(urldecode($parsedUrl['query']));
106  if ($queryParts['id'] === $this->fileOrFolderObject->getCombinedIdentifier()) {
107  $this->returnUrl = str_replace(urlencode($queryParts['id']),
108  urlencode($this->fileOrFolderObject->getStorage()->getRootLevelFolder()->getCombinedIdentifier()),
109  $this->returnUrl);
110  }
111  }
112 
113  // building pathInfo for metaInformation
114  $pathInfo = [
115  'combined_identifier' => $this->fileOrFolderObject->getCombinedIdentifier(),
116  ];
117  $this->moduleTemplate->getDocHeaderComponent()->setMetaInformation($pathInfo);
118 
119  // Setting up the context sensitive menu
120  $this->moduleTemplate->getPageRenderer()->loadRequireJsModule('TYPO3/CMS/Backend/ClickMenu');
121 
122  // Add javaScript
123  $this->moduleTemplate->addJavaScriptCode(
124  'RenameFileInlineJavaScript',
125  'function backToList() {top.goToModule("file_FilelistList");}'
126  );
127  }
128 
134  public function main()
135  {
136  if ($this->fileOrFolderObject instanceof \TYPO3\CMS\Core\Resource\Folder) {
137  $fileIdentifier = $this->fileOrFolderObject->getCombinedIdentifier();
138  } else {
139  $fileIdentifier = $this->fileOrFolderObject->getUid();
140  }
141  $pageContent = '<form action="' . htmlspecialchars(BackendUtility::getModuleUrl('tce_file')) . '" method="post" name="editform" role="form">';
142  // Making the formfields for renaming:
143  $pageContent .= '
144 
145  <div class="form-group">
146  <input class="form-control" type="text" name="file[rename][0][target]" value="' . htmlspecialchars($this->fileOrFolderObject->getName()) . '" ' . $this->getDocumentTemplate()->formWidth(40) . ' />
147  <input type="hidden" name="file[rename][0][data]" value="' . htmlspecialchars($fileIdentifier) . '" />
148  </div>
149  ';
150  // Making submit button:
151  $pageContent .= '
152  <div class="form-group">
153  <input class="btn btn-primary" type="submit" value="' .
154  $this->getLanguageService()->sL('LLL:EXT:lang/locallang_core.xlf:file_rename.php.submit', true) . '" />
155  <input class="btn btn-danger" type="submit" value="' .
156  $this->getLanguageService()->sL('LLL:EXT:lang/locallang_core.xlf:labels.cancel', true) .
157  '" onclick="backToList(); return false;" />
158  <input type="hidden" name="redirect" value="' . htmlspecialchars($this->returnUrl) . '" />
159  </div>
160  ';
161  $pageContent .= '</form>';
162 
163  // Create buttons
164  $buttonBar = $this->moduleTemplate->getDocHeaderComponent()->getButtonBar();
165 
166  // csh button
167  $cshButton = $buttonBar->makeHelpButton()
168  ->setModuleName('xMOD_csh_corebe')
169  ->setFieldName('file_rename');
170  $buttonBar->addButton($cshButton);
171 
172  // back button
173  if ($this->returnUrl) {
174  $backButton = $buttonBar->makeLinkButton()
175  ->sethref(GeneralUtility::linkThisUrl($this->returnUrl))
176  ->setTitle($this->getLanguageService()->sL('LLL:EXT:lang/locallang_core.xlf:labels.goBack'))
177  ->setIcon($this->moduleTemplate->getIconFactory()->getIcon('actions-view-go-back', Icon::SIZE_SMALL));
178  $buttonBar->addButton($backButton);
179  }
180 
181  // set header
182  $this->content = '<h1>' . $this->getLanguageService()->sL('LLL:EXT:lang/locallang_core.xlf:file_rename.php.pagetitle') . '</h1>';
183 
184  // add section
185  $this->content .= '<div>' . $pageContent . '</div>';
186  $this->moduleTemplate->setContent($this->content);
187  }
188 
196  public function mainAction(ServerRequestInterface $request, ResponseInterface $response)
197  {
198  $this->main();
199  $response->getBody()->write($this->moduleTemplate->renderContent());
200  return $response;
201  }
202 
208  protected function getLanguageService()
209  {
210  return $GLOBALS['LANG'];
211  }
212 
218  protected function getDocumentTemplate()
219  {
220  return $GLOBALS['TBE_TEMPLATE'];
221  }
222 }
static linkThisUrl($url, array $getParams=[])
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']