TYPO3 CMS  TYPO3_6-2
RenameFileController.php
Go to the documentation of this file.
1 <?php
3 
19 
26 
27  // Internal, static:
34  public $doc;
35 
36  // Name of the filemount
40  public $title;
41 
42  // Internal, static (GPVar):
43  // Set with the target path inputted in &target
47  public $target;
48 
55 
56  // Return URL of list module.
60  public $returnUrl;
61 
62  // Internal, dynamic:
63  // Accumulating content
67  public $content;
68 
72  public function __construct() {
73  $GLOBALS['SOBE'] = $this;
74  $GLOBALS['BACK_PATH'] = '';
75 
76  $this->init();
77  }
78 
84  protected function init() {
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 = $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_mod_file_list.xlf:paramError', TRUE);
94  $message = $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_mod_file_list.xlf:targetNoDir', TRUE);
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 a 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(urlencode($queryParts['id']), urlencode($this->fileOrFolderObject->getStorage()->getRootLevelFolder()->getCombinedIdentifier()), $this->returnUrl);
110  }
111  }
112  // Setting icon and title
113  $icon = \TYPO3\CMS\Backend\Utility\IconUtility::getSpriteIcon('apps-filetree-root');
114  $this->title = $icon . htmlspecialchars($this->fileOrFolderObject->getStorage()->getName()) . ': ' . htmlspecialchars($this->fileOrFolderObject->getIdentifier());
115  // Setting template object
116  $this->doc = GeneralUtility::makeInstance('TYPO3\\CMS\\Backend\\Template\\DocumentTemplate');
117  $this->doc->setModuleTemplate('EXT:backend/Resources/Private/Templates/file_rename.html');
118  $this->doc->backPath = $GLOBALS['BACK_PATH'];
119  $this->doc->JScode = $this->doc->wrapScriptTags('
120  function backToList() { //
121  top.goToModule("file_list");
122  }
123  ');
124  }
125 
131  public function main() {
132  // Make page header:
133  $this->content = $this->doc->startPage($GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.xlf:file_rename.php.pagetitle'));
134  $pageContent = $this->doc->header($GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.xlf:file_rename.php.pagetitle'));
135  $pageContent .= $this->doc->spacer(5);
136  $pageContent .= $this->doc->divider(5);
137  if ($this->fileOrFolderObject instanceof \TYPO3\CMS\Core\Resource\Folder) {
138  $fileIdentifier = $this->fileOrFolderObject->getCombinedIdentifier();
139  } else {
140  $fileIdentifier = $this->fileOrFolderObject->getUid();
141  }
142  $code = '<form action="tce_file.php" method="post" name="editform">';
143  // Making the formfields for renaming:
144  $code .= '
145 
146  <div id="c-rename">
147  <input type="text" name="file[rename][0][target]" value="' . htmlspecialchars($this->fileOrFolderObject->getName()) . '"' . $GLOBALS['TBE_TEMPLATE']->formWidth(40) . ' />
148  <input type="hidden" name="file[rename][0][data]" value="' . htmlspecialchars($fileIdentifier) . '" />
149  </div>
150  ';
151  // Making submit button:
152  $code .= '
153  <div id="c-submit">
154  <input type="submit" value="' . $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.xlf:file_rename.php.submit', TRUE) . '" />
155  <input type="submit" value="' . $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.xlf:labels.cancel', TRUE) . '" onclick="backToList(); return false;" />
156  <input type="hidden" name="redirect" value="' . htmlspecialchars($this->returnUrl) . '" />
158  </div>
159  ';
160  $code .= '</form>';
161  // Add the HTML as a section:
162  $pageContent .= $code;
163  $docHeaderButtons = array(
164  'back' => ''
165  );
166  $docHeaderButtons['csh'] = BackendUtility::cshItem('xMOD_csh_corebe', 'file_rename', $GLOBALS['BACK_PATH']);
167  // Back
168  if ($this->returnUrl) {
169  $docHeaderButtons['back'] = '<a href="' . htmlspecialchars(\TYPO3\CMS\Core\Utility\GeneralUtility::linkThisUrl($this->returnUrl)) . '" class="typo3-goBack" title="' . $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.xlf:labels.goBack', TRUE) . '">' . \TYPO3\CMS\Backend\Utility\IconUtility::getSpriteIcon('actions-view-go-back') . '</a>';
170  }
171  // Add the HTML as a section:
172  $markerArray = array(
173  'CSH' => $docHeaderButtons['csh'],
174  'FUNC_MENU' => BackendUtility::getFuncMenu($this->id, 'SET[function]', $this->MOD_SETTINGS['function'], $this->MOD_MENU['function']),
175  'CONTENT' => $pageContent,
176  'PATH' => $this->title
177  );
178  $this->content .= $this->doc->moduleBody(array(), $docHeaderButtons, $markerArray);
179  $this->content .= $this->doc->endPage();
180  $this->content = $this->doc->insertStylesAndJS($this->content);
181  }
182 
188  public function printContent() {
189  echo $this->content;
190  }
191 
192 }
static explodeUrl2Array($string, $multidim=FALSE)
static cshItem($table, $field, $BACK_PATH, $wrap='', $onlyIconMode=FALSE, $styleAttrib='')
static getHiddenTokenField($formName='securityToken', $tokenName='formToken')
static getSpriteIcon($iconName, array $options=array(), array $overlays=array())
static getFuncMenu($mainParams, $elementName, $currentValue, $menuItems, $script='', $addparams='')
if(!defined('TYPO3_MODE')) $GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['t3lib/class.t3lib_userauth.php']['logoff_pre_processing'][]
static linkThisUrl($url, array $getParams=array())