2 namespace TYPO3\CMS\Backend\Controller\File
;
4 /***************************************************************
7 * (c) 1999-2013 Kasper Skårhøj (kasperYYYY@typo3.com)
10 * This script is part of the TYPO3 project. The TYPO3 project is
11 * free software; you can redistribute it and/or modify
12 * it under the terms of the GNU General Public License as published by
13 * the Free Software Foundation; either version 2 of the License, or
14 * (at your option) any later version.
16 * The GNU General Public License can be found at
17 * http://www.gnu.org/copyleft/gpl.html.
18 * A copy is found in the textfile GPL.txt and important notices to the license
19 * from the author is found in LICENSE.txt distributed with these scripts.
22 * This script is distributed in the hope that it will be useful,
23 * but WITHOUT ANY WARRANTY; without even the implied warranty of
24 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
25 * GNU General Public License for more details.
27 * This copyright notice MUST APPEAR in all copies of the script!
28 ***************************************************************/
30 use TYPO3\CMS\Backend\Utility\BackendUtility
;
31 use TYPO3\CMS\Core\Utility\GeneralUtility
;
34 * Script Class for the rename-file form.
36 * @author Kasper Skårhøj <kasperYYYY@typo3.com>
38 class RenameFileController
{
42 * Document template object
44 * @var \TYPO3\CMS\Backend\Template\DocumentTemplate
45 * @todo Define visibility
49 // Name of the filemount
51 * @todo Define visibility
55 // Internal, static (GPVar):
56 // Set with the target path inputted in &target
58 * @todo Define visibility
63 * The file or folder object that should be renamed
65 * @var \TYPO3\CMS\Core\Resource\ResourceInterface $fileOrFolderObject
67 protected $fileOrFolderObject;
69 // Return URL of list module.
71 * @todo Define visibility
76 // Accumulating content
78 * @todo Define visibility
83 * Constructor function for class
86 * @todo Define visibility
88 public function init() {
90 $this->target
= GeneralUtility
::_GP('target');
91 $this->returnUrl
= GeneralUtility
::sanitizeLocalUrl(GeneralUtility
::_GP('returnUrl'));
92 // Cleaning and checking target
94 $this->fileOrFolderObject
= \TYPO3\CMS\Core\
Resource\ResourceFactory
::getInstance()->retrieveFileOrFolderObject($this->target
);
96 if (!$this->fileOrFolderObject
) {
97 $title = $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_mod_file_list.xlf:paramError', TRUE);
98 $message = $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_mod_file_list.xlf:targetNoDir', TRUE);
99 throw new \
RuntimeException($title . ': ' . $message, 1294586844);
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
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
);
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");
127 * Main function, rendering the content of the rename form
130 * @todo Define visibility
132 public function main() {
133 //TODO: change locallang*.php to locallang*.xml
135 $this->content
= $this->doc
->startPage($GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.xlf:file_rename.php.pagetitle'));
136 $pageContent = $this->doc
->header($GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.xlf:file_rename.php.pagetitle'));
137 $pageContent .= $this->doc
->spacer(5);
138 $pageContent .= $this->doc
->divider(5);
139 if ($this->fileOrFolderObject
instanceof \TYPO3\CMS\Core\
Resource\Folder
) {
140 $fileIdentifier = $this->fileOrFolderObject
->getCombinedIdentifier();
142 $fileIdentifier = $this->fileOrFolderObject
->getUid();
144 $code = '<form action="tce_file.php" method="post" name="editform">';
145 // Making the formfields for renaming:
149 <input type="text" name="file[rename][0][target]" value="' . htmlspecialchars($this->fileOrFolderObject
->getName()) . '"' . $GLOBALS['TBE_TEMPLATE']->formWidth(40) . ' />
150 <input type="hidden" name="file[rename][0][data]" value="' . htmlspecialchars($fileIdentifier) . '" />
153 // Making submit button:
156 <input type="submit" value="' . $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.xlf:file_rename.php.submit', 1) . '" />
157 <input type="submit" value="' . $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.xlf:labels.cancel', 1) . '" onclick="backToList(); return false;" />
158 <input type="hidden" name="redirect" value="' . htmlspecialchars($this->returnUrl
) . '" />
162 // Add the HTML as a section:
163 $pageContent .= $code;
164 $docHeaderButtons = array();
165 $docHeaderButtons['csh'] = BackendUtility
::cshItem('xMOD_csh_corebe', 'file_rename', $GLOBALS['BACK_PATH']);
166 // Add the HTML as a section:
167 $markerArray = array(
168 'CSH' => $docHeaderButtons['csh'],
169 'FUNC_MENU' => BackendUtility
::getFuncMenu($this->id
, 'SET[function]', $this->MOD_SETTINGS
['function'], $this->MOD_MENU
['function']),
170 'CONTENT' => $pageContent,
171 'PATH' => $this->title
173 $this->content
.= $this->doc
->moduleBody(array(), $docHeaderButtons, $markerArray);
174 $this->content
.= $this->doc
->endPage();
175 $this->content
= $this->doc
->insertStylesAndJS($this->content
);
179 * Outputting the accumulated content to screen
182 * @todo Define visibility
184 public function printContent() {