[TASK] Cleanup entry classes in typo3/ part2
[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
84 */
85 public function __construct() {
86 $GLOBALS['SOBE'] = $this;
87 $GLOBALS['BACK_PATH'] = '';
88
89 $this->init();
90 }
91
92 /**
93 * Initialize
94 *
95 * @return void
96 */
97 protected function init() {
98 // Initialize GPvars:
99 $this->target = GeneralUtility::_GP('target');
100 $this->returnUrl = GeneralUtility::sanitizeLocalUrl(GeneralUtility::_GP('returnUrl'));
101 // Cleaning and checking target
102 if ($this->target) {
103 $this->fileOrFolderObject = \TYPO3\CMS\Core\Resource\ResourceFactory::getInstance()->retrieveFileOrFolderObject($this->target);
104 }
105 if (!$this->fileOrFolderObject) {
106 $title = $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_mod_file_list.xlf:paramError', TRUE);
107 $message = $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_mod_file_list.xlf:targetNoDir', TRUE);
108 throw new \RuntimeException($title . ': ' . $message, 1294586844);
109 }
110 // If a folder should be renamed, AND the returnURL should go to the old directory name, the redirect is forced
111 // so the redirect will NOT end in a error message
112 // this case only happens if you select the folder itself in the foldertree and then use the clickmenu to
113 // rename the folder
114 if ($this->fileOrFolderObject instanceof \TYPO3\CMS\Core\Resource\Folder) {
115 $parsedUrl = parse_url($this->returnUrl);
116 $queryParts = GeneralUtility::explodeUrl2Array(urldecode($parsedUrl['query']));
117 if ($queryParts['id'] === $this->fileOrFolderObject->getCombinedIdentifier()) {
118 $this->returnUrl = str_replace(urlencode($queryParts['id']), urlencode($this->fileOrFolderObject->getStorage()->getRootLevelFolder()->getCombinedIdentifier()), $this->returnUrl);
119 }
120 }
121 // Setting icon and title
122 $icon = \TYPO3\CMS\Backend\Utility\IconUtility::getSpriteIcon('apps-filetree-root');
123 $this->title = $icon . htmlspecialchars($this->fileOrFolderObject->getStorage()->getName()) . ': ' . htmlspecialchars($this->fileOrFolderObject->getIdentifier());
124 // Setting template object
125 $this->doc = GeneralUtility::makeInstance('TYPO3\\CMS\\Backend\\Template\\DocumentTemplate');
126 $this->doc->setModuleTemplate('EXT:backend/Resources/Private/Templates/file_rename.html');
127 $this->doc->backPath = $GLOBALS['BACK_PATH'];
128 $this->doc->JScode = $this->doc->wrapScriptTags('
129 function backToList() { //
130 top.goToModule("file_list");
131 }
132 ');
133 }
134
135 /**
136 * Main function, rendering the content of the rename form
137 *
138 * @return void
139 */
140 public function main() {
141 // Make page header:
142 $this->content = $this->doc->startPage($GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.xlf:file_rename.php.pagetitle'));
143 $pageContent = $this->doc->header($GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.xlf:file_rename.php.pagetitle'));
144 $pageContent .= $this->doc->spacer(5);
145 $pageContent .= $this->doc->divider(5);
146 if ($this->fileOrFolderObject instanceof \TYPO3\CMS\Core\Resource\Folder) {
147 $fileIdentifier = $this->fileOrFolderObject->getCombinedIdentifier();
148 } else {
149 $fileIdentifier = $this->fileOrFolderObject->getUid();
150 }
151 $code = '<form action="tce_file.php" method="post" name="editform">';
152 // Making the formfields for renaming:
153 $code .= '
154
155 <div id="c-rename">
156 <input type="text" name="file[rename][0][target]" value="' . htmlspecialchars($this->fileOrFolderObject->getName()) . '"' . $GLOBALS['TBE_TEMPLATE']->formWidth(40) . ' />
157 <input type="hidden" name="file[rename][0][data]" value="' . htmlspecialchars($fileIdentifier) . '" />
158 </div>
159 ';
160 // Making submit button:
161 $code .= '
162 <div id="c-submit">
163 <input type="submit" value="' . $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.xlf:file_rename.php.submit', 1) . '" />
164 <input type="submit" value="' . $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.xlf:labels.cancel', 1) . '" onclick="backToList(); return false;" />
165 <input type="hidden" name="redirect" value="' . htmlspecialchars($this->returnUrl) . '" />
166 </div>
167 ';
168 $code .= '</form>';
169 // Add the HTML as a section:
170 $pageContent .= $code;
171 $docHeaderButtons = array(
172 'back' => ''
173 );
174 $docHeaderButtons['csh'] = BackendUtility::cshItem('xMOD_csh_corebe', 'file_rename', $GLOBALS['BACK_PATH']);
175 // Back
176 if ($this->returnUrl) {
177 $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>';
178 }
179 // Add the HTML as a section:
180 $markerArray = array(
181 'CSH' => $docHeaderButtons['csh'],
182 'FUNC_MENU' => BackendUtility::getFuncMenu($this->id, 'SET[function]', $this->MOD_SETTINGS['function'], $this->MOD_MENU['function']),
183 'CONTENT' => $pageContent,
184 'PATH' => $this->title
185 );
186 $this->content .= $this->doc->moduleBody(array(), $docHeaderButtons, $markerArray);
187 $this->content .= $this->doc->endPage();
188 $this->content = $this->doc->insertStylesAndJS($this->content);
189 }
190
191 /**
192 * Outputting the accumulated content to screen
193 *
194 * @return void
195 */
196 public function printContent() {
197 echo $this->content;
198 }
199
200 }
201
202 ?>