[TASK] Remove require statements for classes
[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 /**
29 * Web>File: Renaming files and folders
30 *
31 * Revised for TYPO3 3.6 November/2003 by Kasper Skårhøj
32 *
33 * @author Kasper Skårhøj <kasperYYYY@typo3.com>
34 */
35
36 $BACK_PATH = '';
37 require('init.php');
38
39 /**
40 * Script Class for the rename-file form.
41 *
42 * @author Kasper Skårhøj <kasperYYYY@typo3.com>
43 * @package TYPO3
44 * @subpackage core
45 */
46 class SC_file_rename {
47
48 // Internal, static:
49 /**
50 * Document template object
51 *
52 * @var smallDoc
53 */
54 var $doc;
55 // Name of the filemount
56 var $title;
57
58 // Internal, static (GPVar):
59 // Set with the target path inputted in &target
60 var $target;
61
62 /**
63 * The file or folder object that should be renamed
64 *
65 * @var t3lib_file_ResourceInterface $fileOrFolderObject
66 */
67 protected $fileOrFolderObject;
68 // Return URL of list module.
69 var $returnUrl;
70
71 // Internal, dynamic:
72 // Accumulating content
73 var $content;
74
75 /**
76 * Constructor function for class
77 *
78 * @return void
79 */
80 function init() {
81 // Initialize GPvars:
82 $this->target = t3lib_div::_GP('target');
83 $this->returnUrl = t3lib_div::sanitizeLocalUrl(t3lib_div::_GP('returnUrl'));
84
85 // Cleaning and checking target
86 if ($this->target) {
87 $this->fileOrFolderObject = t3lib_file_Factory::getInstance()->retrieveFileOrFolderObject($this->target);
88 }
89
90 if (!$this->fileOrFolderObject) {
91 $title = $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_mod_file_list.xml:paramError', TRUE);
92 $message = $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_mod_file_list.xml:targetNoDir', TRUE);
93 throw new RuntimeException($title . ': ' . $message, 1294586844);
94 }
95
96 // If a folder should be renamed, AND the returnURL should go to the old directory name, the redirect is forced
97 // so the redirect will NOT end in a error message
98 // this case only happens if you select the folder itself in the foldertree and then use the clickmenu to
99 // rename the folder
100 if ($this->fileOrFolderObject instanceof t3lib_file_Folder) {
101 $parsedUrl = parse_url($this->returnUrl);
102 $queryParts = t3lib_div::explodeUrl2Array(urldecode($parsedUrl['query']));
103 if ($queryParts['id'] === $this->fileOrFolderObject->getCombinedIdentifier()) {
104 $this->returnUrl = str_replace(urlencode($queryParts['id']), urlencode($this->fileOrFolderObject->getStorage()->getRootLevelFolder()->getCombinedIdentifier()), $this->returnUrl);
105 }
106 }
107
108 // Setting icon and title
109 $icon = t3lib_iconWorks::getSpriteIcon('apps-filetree-root');
110 $this->title = $icon . htmlspecialchars($this->fileOrFolderObject->getStorage()->getName()) . ': ' . htmlspecialchars($this->fileOrFolderObject->getIdentifier());
111
112 // Setting template object
113 $this->doc = t3lib_div::makeInstance('template');
114 $this->doc->setModuleTemplate('templates/file_rename.html');
115 $this->doc->backPath = $GLOBALS['BACK_PATH'];
116 $this->doc->JScode=$this->doc->wrapScriptTags('
117 function backToList() { //
118 top.goToModule("file_list");
119 }
120 ');
121 }
122
123 /**
124 * Main function, rendering the content of the rename form
125 *
126 * @return void
127 */
128 function main() {
129 //TODO: change locallang*.php to locallang*.xml
130 // Make page header:
131 $this->content = $this->doc->startPage($GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.php:file_rename.php.pagetitle'));
132
133 $pageContent = $this->doc->header($GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.php:file_rename.php.pagetitle'));
134 $pageContent .= $this->doc->spacer(5);
135 $pageContent .= $this->doc->divider(5);
136
137 if ($this->fileOrFolderObject instanceof t3lib_file_Folder) {
138 $fileIdentifier = $this->fileOrFolderObject->getCombinedIdentifier();
139 } else {
140 $fileIdentifier = $this->fileOrFolderObject->getUid();
141 }
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
153 // Making submit button:
154 $code .= '
155 <div id="c-submit">
156 <input type="submit" value="' . $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.php:file_rename.php.submit', 1) . '" />
157 <input type="submit" value="' . $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.php:labels.cancel', 1) . '" onclick="backToList(); return false;" />
158 <input type="hidden" name="redirect" value="'.htmlspecialchars($this->returnUrl).'" />
159 </div>
160 ';
161
162 $code .= '</form>';
163
164 // Add the HTML as a section:
165 $pageContent .= $code;
166
167 $docHeaderButtons = array();
168 $docHeaderButtons['csh'] = t3lib_BEfunc::cshItem('xMOD_csh_corebe', 'file_rename', $GLOBALS['BACK_PATH']);
169
170 // Add the HTML as a section:
171 $markerArray = array(
172 'CSH' => $docHeaderButtons['csh'],
173 'FUNC_MENU' => t3lib_BEfunc::getFuncMenu($this->id, 'SET[function]', $this->MOD_SETTINGS['function'], $this->MOD_MENU['function']),
174 'CONTENT' => $pageContent,
175 'PATH' => $this->title,
176 );
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 */
188 function printContent() {
189 echo $this->content;
190 }
191 }
192
193 // Make instance:
194 $SOBE = t3lib_div::makeInstance('SC_file_rename');
195 $SOBE->init();
196 $SOBE->main();
197 $SOBE->printContent();
198
199 ?>