024660c8d41694bf4cb0548969c7fb181139140a
[Packages/TYPO3.CMS.git] / typo3 / sysext / backend / Classes / Controller / File / RenameFileController.php
1 <?php
2 namespace TYPO3\CMS\Backend\Controller\File;
3
4 /***************************************************************
5 * Copyright notice
6 *
7 * (c) 1999-2013 Kasper Skårhøj (kasperYYYY@typo3.com)
8 * All rights reserved
9 *
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.
15 *
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.
20 *
21 *
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.
26 *
27 * This copyright notice MUST APPEAR in all copies of the script!
28 ***************************************************************/
29
30 use TYPO3\CMS\Backend\Utility\BackendUtility;
31 use TYPO3\CMS\Core\Utility\GeneralUtility;
32
33 /**
34 * Script Class for the rename-file form.
35 *
36 * @author Kasper Skårhøj <kasperYYYY@typo3.com>
37 */
38 class RenameFileController {
39
40 // Internal, static:
41 /**
42 * Document template object
43 *
44 * @var \TYPO3\CMS\Backend\Template\DocumentTemplate
45 * @todo Define visibility
46 */
47 public $doc;
48
49 // Name of the filemount
50 /**
51 * @todo Define visibility
52 */
53 public $title;
54
55 // Internal, static (GPVar):
56 // Set with the target path inputted in &target
57 /**
58 * @todo Define visibility
59 */
60 public $target;
61
62 /**
63 * The file or folder object that should be renamed
64 *
65 * @var \TYPO3\CMS\Core\Resource\ResourceInterface $fileOrFolderObject
66 */
67 protected $fileOrFolderObject;
68
69 // Return URL of list module.
70 /**
71 * @todo Define visibility
72 */
73 public $returnUrl;
74
75 // Internal, dynamic:
76 // Accumulating content
77 /**
78 * @todo Define visibility
79 */
80 public $content;
81
82 /**
83 * Constructor function for class
84 *
85 * @return void
86 * @todo Define visibility
87 */
88 public function init() {
89 // Initialize GPvars:
90 $this->target = GeneralUtility::_GP('target');
91 $this->returnUrl = GeneralUtility::sanitizeLocalUrl(GeneralUtility::_GP('returnUrl'));
92 // Cleaning and checking target
93 if ($this->target) {
94 $this->fileOrFolderObject = \TYPO3\CMS\Core\Resource\ResourceFactory::getInstance()->retrieveFileOrFolderObject($this->target);
95 }
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);
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
126 /**
127 * Main function, rendering the content of the rename form
128 *
129 * @return void
130 * @todo Define visibility
131 */
132 public function main() {
133 // Make page header:
134 $this->content = $this->doc->startPage($GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.xlf:file_rename.php.pagetitle'));
135 $pageContent = $this->doc->header($GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.xlf:file_rename.php.pagetitle'));
136 $pageContent .= $this->doc->spacer(5);
137 $pageContent .= $this->doc->divider(5);
138 if ($this->fileOrFolderObject instanceof \TYPO3\CMS\Core\Resource\Folder) {
139 $fileIdentifier = $this->fileOrFolderObject->getCombinedIdentifier();
140 } else {
141 $fileIdentifier = $this->fileOrFolderObject->getUid();
142 }
143 $code = '<form action="tce_file.php" method="post" name="editform">';
144 // Making the formfields for renaming:
145 $code .= '
146
147 <div id="c-rename">
148 <input type="text" name="file[rename][0][target]" value="' . htmlspecialchars($this->fileOrFolderObject->getName()) . '"' . $GLOBALS['TBE_TEMPLATE']->formWidth(40) . ' />
149 <input type="hidden" name="file[rename][0][data]" value="' . htmlspecialchars($fileIdentifier) . '" />
150 </div>
151 ';
152 // Making submit button:
153 $code .= '
154 <div id="c-submit">
155 <input type="submit" value="' . $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.xlf:file_rename.php.submit', 1) . '" />
156 <input type="submit" value="' . $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.xlf:labels.cancel', 1) . '" onclick="backToList(); return false;" />
157 <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
183 /**
184 * Outputting the accumulated content to screen
185 *
186 * @return void
187 * @todo Define visibility
188 */
189 public function printContent() {
190 echo $this->content;
191 }
192
193 }
194
195 ?>