[BUGFIX] file_upload missing back icon
[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 //TODO: change locallang*.php to locallang*.xml
134 // Make page header:
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();
141 } else {
142 $fileIdentifier = $this->fileOrFolderObject->getUid();
143 }
144 $code = '<form action="tce_file.php" method="post" name="editform">';
145 // Making the formfields for renaming:
146 $code .= '
147
148 <div id="c-rename">
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) . '" />
151 </div>
152 ';
153 // Making submit button:
154 $code .= '
155 <div id="c-submit">
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) . '" />
159 </div>
160 ';
161 $code .= '</form>';
162 // Add the HTML as a section:
163 $pageContent .= $code;
164 $docHeaderButtons = array(
165 'back' => ''
166 );
167 $docHeaderButtons['csh'] = BackendUtility::cshItem('xMOD_csh_corebe', 'file_rename', $GLOBALS['BACK_PATH']);
168 // Back
169 if ($this->returnUrl) {
170 $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>';
171 }
172 // Add the HTML as a section:
173 $markerArray = array(
174 'CSH' => $docHeaderButtons['csh'],
175 'FUNC_MENU' => BackendUtility::getFuncMenu($this->id, 'SET[function]', $this->MOD_SETTINGS['function'], $this->MOD_MENU['function']),
176 'CONTENT' => $pageContent,
177 'PATH' => $this->title
178 );
179 $this->content .= $this->doc->moduleBody(array(), $docHeaderButtons, $markerArray);
180 $this->content .= $this->doc->endPage();
181 $this->content = $this->doc->insertStylesAndJS($this->content);
182 }
183
184 /**
185 * Outputting the accumulated content to screen
186 *
187 * @return void
188 * @todo Define visibility
189 */
190 public function printContent() {
191 echo $this->content;
192 }
193
194 }
195
196 ?>