[TASK] Remove XCLASS definitions from typo3/
[Packages/TYPO3.CMS.git] / typo3 / file_rename.php
1 <?php
2 /***************************************************************
3 * Copyright notice
4 *
5 * (c) 1999-2011 Kasper Skårhøj (kasperYYYY@typo3.com)
6 * All rights reserved
7 *
8 * This script is part of the TYPO3 project. The TYPO3 project is
9 * free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License as published by
11 * the Free Software Foundation; either version 2 of the License, or
12 * (at your option) any later version.
13 *
14 * The GNU General Public License can be found at
15 * http://www.gnu.org/copyleft/gpl.html.
16 * A copy is found in the textfile GPL.txt and important notices to the license
17 * from the author is found in LICENSE.txt distributed with these scripts.
18 *
19 *
20 * This script is distributed in the hope that it will be useful,
21 * but WITHOUT ANY WARRANTY; without even the implied warranty of
22 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
23 * GNU General Public License for more details.
24 *
25 * This copyright notice MUST APPEAR in all copies of the script!
26 ***************************************************************/
27 /**
28 * Web>File: Renaming files and folders
29 *
30 * Revised for TYPO3 3.6 November/2003 by Kasper Skårhøj
31 *
32 * @author Kasper Skårhøj <kasperYYYY@typo3.com>
33 */
34
35
36
37 $BACK_PATH = '';
38 require('init.php');
39 require('template.php');
40
41
42
43 /**
44 * Script Class for the rename-file form.
45 *
46 * @author Kasper Skårhøj <kasperYYYY@typo3.com>
47 * @package TYPO3
48 * @subpackage core
49 */
50 class SC_file_rename {
51
52 // Internal, static:
53 /**
54 * Document template object
55 *
56 * @var smallDoc
57 */
58 var $doc;
59 var $title; // Name of the filemount
60
61 // Internal, static (GPVar):
62 var $target; // Set with the target path inputted in &target
63
64 /**
65 * the file or folder object that should be renamed
66 *
67 * @var t3lib_file_ResourceInterface $fileOrFolderObject
68 */
69 protected $fileOrFolderObject;
70
71 var $returnUrl; // Return URL of list module.
72
73 // Internal, dynamic:
74 var $content; // Accumulating content
75
76
77 /**
78 * Constructor function for class
79 *
80 * @return void
81 */
82 function init() {
83 // Initialize GPvars:
84 $this->target = t3lib_div::_GP('target');
85 $this->returnUrl = t3lib_div::sanitizeLocalUrl(t3lib_div::_GP('returnUrl'));
86
87 // Cleaning and checking target
88 if ($this->target) {
89 $this->fileOrFolderObject = t3lib_file_Factory::getInstance()->retrieveFileOrFolderObject($this->target);
90 }
91
92 if (!$this->fileOrFolderObject) {
93 $title = $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_mod_file_list.xml:paramError', TRUE);
94 $message = $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_mod_file_list.xml:targetNoDir', TRUE);
95 throw new RuntimeException($title . ': ' . $message, 1294586844);
96 }
97
98 // if a folder should be renamed, AND the returnURL should go to the old directory name, the redirect is forced
99 // so the redirect will NOT end in a error message
100 // this case only happens if you select the folder itself in the foldertree and then use the clickmenu to
101 // rename the folder
102 if ($this->fileOrFolderObject instanceof t3lib_file_Folder) {
103 $parsedUrl = parse_url($this->returnUrl);
104 $queryParts = t3lib_div::explodeUrl2Array(urldecode($parsedUrl['query']));
105 if ($queryParts['id'] === $this->fileOrFolderObject->getCombinedIdentifier()) {
106 $this->returnUrl = str_replace(urlencode($queryParts['id']), urlencode($this->fileOrFolderObject->getStorage()->getRootLevelFolder()->getCombinedIdentifier()), $this->returnUrl);
107 }
108 }
109
110
111
112 // Setting icon and title
113 $icon = t3lib_iconWorks::getSpriteIcon('apps-filetree-root');
114 $this->title = $icon . htmlspecialchars($this->fileOrFolderObject->getStorage()->getName()) . ': ' . htmlspecialchars($this->fileOrFolderObject->getIdentifier());
115
116 // Setting template object
117 $this->doc = t3lib_div::makeInstance('template');
118 $this->doc->setModuleTemplate('templates/file_rename.html');
119 $this->doc->backPath = $GLOBALS['BACK_PATH'];
120 $this->doc->JScode=$this->doc->wrapScriptTags('
121 function backToList() { //
122 top.goToModule("file_list");
123 }
124 ');
125 }
126
127 /**
128 * Main function, rendering the content of the rename form
129 *
130 * @return void
131 */
132 function main() {
133 //TODO: change locallang*.php to locallang*.xml
134
135 // Make page header:
136 $this->content = $this->doc->startPage($GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.php:file_rename.php.pagetitle'));
137
138 $pageContent = $this->doc->header($GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.php:file_rename.php.pagetitle'));
139 $pageContent .= $this->doc->spacer(5);
140 $pageContent .= $this->doc->divider(5);
141
142 if ($this->fileOrFolderObject instanceof t3lib_file_Folder) {
143 $fileIdentifier = $this->fileOrFolderObject->getCombinedIdentifier();
144 } else {
145 $fileIdentifier = $this->fileOrFolderObject->getUid();
146 }
147
148 $code = '<form action="tce_file.php" method="post" name="editform">';
149 // Making the formfields for renaming:
150 $code .= '
151
152 <div id="c-rename">
153 <input type="text" name="file[rename][0][target]" value="' . htmlspecialchars($this->fileOrFolderObject->getName()) . '"' . $GLOBALS['TBE_TEMPLATE']->formWidth(40) . ' />
154 <input type="hidden" name="file[rename][0][data]" value="' . htmlspecialchars($fileIdentifier) . '" />
155 </div>
156 ';
157
158 // Making submit button:
159 $code.='
160 <div id="c-submit">
161 <input type="submit" value="' . $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.php:file_rename.php.submit', 1) . '" />
162 <input type="submit" value="' . $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.php:labels.cancel', 1) . '" onclick="backToList(); return false;" />
163 <input type="hidden" name="redirect" value="'.htmlspecialchars($this->returnUrl).'" />
164 </div>
165 ';
166
167 $code .= '</form>';
168
169 // Add the HTML as a section:
170 $pageContent .= $code;
171
172 $docHeaderButtons = array();
173 $docHeaderButtons['csh'] = t3lib_BEfunc::cshItem('xMOD_csh_corebe', 'file_rename', $GLOBALS['BACK_PATH']);
174
175 // Add the HTML as a section:
176 $markerArray = array(
177 'CSH' => $docHeaderButtons['csh'],
178 'FUNC_MENU' => t3lib_BEfunc::getFuncMenu($this->id, 'SET[function]', $this->MOD_SETTINGS['function'], $this->MOD_MENU['function']),
179 'CONTENT' => $pageContent,
180 'PATH' => $this->title,
181 );
182
183 $this->content.= $this->doc->moduleBody(array(), $docHeaderButtons, $markerArray);
184 $this->content.= $this->doc->endPage();
185 $this->content = $this->doc->insertStylesAndJS($this->content);
186 }
187
188 /**
189 * Outputting the accumulated content to screen
190 *
191 * @return void
192 */
193 function printContent() {
194 echo $this->content;
195 }
196 }
197
198 // Make instance:
199 $SOBE = t3lib_div::makeInstance('SC_file_rename');
200 $SOBE->init();
201 $SOBE->main();
202 $SOBE->printContent();
203
204 ?>