af399dc932df7ee8ebb80661d1a2cbeb07614042
[Packages/TYPO3.CMS.git] / typo3 / file_rename.php
1 <?php
2 /***************************************************************
3 * Copyright notice
4 *
5 * (c) 1999-2005 Kasper Skaarhoj (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 * $Id$
31 * Revised for TYPO3 3.6 November/2003 by Kasper Skaarhoj
32 *
33 * @author Kasper Skaarhoj <kasperYYYY@typo3.com>
34 */
35 /**
36 * [CLASS/FUNCTION INDEX of SCRIPT]
37 *
38 *
39 *
40 * 74: class SC_file_rename
41 * 96: function init()
42 * 149: function main()
43 * 192: function printContent()
44 *
45 * TOTAL FUNCTIONS: 3
46 * (This index is automatically created/updated by the extension "extdeveval")
47 *
48 */
49
50
51
52 $BACK_PATH = '';
53 require('init.php');
54 require('template.php');
55 require_once(PATH_t3lib.'class.t3lib_basicfilefunc.php');
56
57
58
59
60
61
62
63
64
65
66
67 /**
68 * Script Class for the rename-file form.
69 *
70 * @author Kasper Skaarhoj <kasperYYYY@typo3.com>
71 * @package TYPO3
72 * @subpackage core
73 */
74 class SC_file_rename {
75
76 // Internal, static:
77 /**
78 * Document template object
79 *
80 * @var smallDoc
81 */
82 var $doc;
83
84 /**
85 * File processing object
86 *
87 * @var t3lib_basicFileFunctions
88 */
89 var $basicff;
90 var $icon; // Will be set to the proper icon for the $target value.
91 var $shortPath; // Relative path to current found filemount
92 var $title; // Name of the filemount
93
94 // Internal, static (GPVar):
95 var $target; // Set with the target path inputted in &target
96 var $returnUrl; // Return URL of list module.
97
98 // Internal, dynamic:
99 var $content; // Accumulating content
100
101
102 /**
103 * Constructor function for class
104 *
105 * @return void
106 */
107 function init() {
108 global $LANG,$BACK_PATH,$TYPO3_CONF_VARS;
109
110 // Initialize GPvars:
111 $this->target = t3lib_div::_GP('target');
112 $this->returnUrl = t3lib_div::_GP('returnUrl');
113
114 // Init basic-file-functions object:
115 $this->basicff = t3lib_div::makeInstance('t3lib_basicFileFunctions');
116 $this->basicff->init($GLOBALS['FILEMOUNTS'],$TYPO3_CONF_VARS['BE']['fileExtensions']);
117
118 // Cleaning and checking target
119 if (@file_exists($this->target)) {
120 $this->target=$this->basicff->cleanDirectoryName($this->target); // Cleaning and checking target (file or dir)
121 } else {
122 $this->target='';
123 }
124 $key=$this->basicff->checkPathAgainstMounts($this->target.'/');
125 if (!$this->target || !$key) {
126 t3lib_BEfunc::typo3PrintError ('Parameter Error','Target was not a directory!','');
127 exit;
128 }
129
130 // Finding the icon
131 switch($GLOBALS['FILEMOUNTS'][$key]['type']) {
132 case 'user': $this->icon = 'gfx/i/_icon_ftp_user.gif'; break;
133 case 'group': $this->icon = 'gfx/i/_icon_ftp_group.gif'; break;
134 default: $this->icon = 'gfx/i/_icon_ftp.gif'; break;
135 }
136
137 // Relative path to filemount, $key:
138 $this->shortPath = substr($this->target,strlen($GLOBALS['FILEMOUNTS'][$key]['path']));
139
140 // Setting title:
141 $this->title = $GLOBALS['FILEMOUNTS'][$key]['name'].': '.$this->shortPath;
142
143 // Setting template object
144 $this->doc = t3lib_div::makeInstance('smallDoc');
145 $this->doc->docType = 'xhtml_trans';
146 $this->doc->backPath = $BACK_PATH;
147 $this->doc->form='<form action="tce_file.php" method="post" name="editform">';
148 $this->doc->JScode=$this->doc->wrapScriptTags('
149 function backToList() { //
150 top.goToModule("file_list");
151 }
152 ');
153 }
154
155 /**
156 * Main function, rendering the content of the rename form
157 *
158 * @return void
159 */
160 function main() {
161 global $LANG;
162
163 // Make page header:
164 $this->content='';
165 $this->content.=$this->doc->startPage($LANG->sL('LLL:EXT:lang/locallang_core.php:file_rename.php.pagetitle'));
166 $this->content.=$this->doc->header($LANG->sL('LLL:EXT:lang/locallang_core.php:file_rename.php.pagetitle'));
167 $this->content.=$this->doc->spacer(5);
168 $this->content.=$this->doc->section('',$this->doc->getFileheader($this->title,$this->shortPath,$this->icon));
169 $this->content.=$this->doc->divider(5);
170
171
172 // Making the formfields for renaming:
173 $code='
174
175 <div id="c-rename">
176 <input type="text" name="file[rename][0][data]" value="'.htmlspecialchars(basename($this->shortPath)).'"'.$GLOBALS['TBE_TEMPLATE']->formWidth(20).' />
177 <input type="hidden" name="file[rename][0][target]" value="'.htmlspecialchars($this->target).'" />
178 </div>
179 ';
180
181 // Making submit button:
182 $code.='
183 <div id="c-submit">
184 <input type="submit" value="'.$LANG->sL('LLL:EXT:lang/locallang_core.php:file_rename.php.submit',1).'" />
185 <input type="submit" value="'.$LANG->sL('LLL:EXT:lang/locallang_core.php:labels.cancel',1).'" onclick="backToList(); return false;" />
186 <input type="hidden" name="redirect" value="'.htmlspecialchars($this->returnUrl).'" />
187 </div>
188 ';
189
190 // CSH:
191 $code.= t3lib_BEfunc::cshItem('xMOD_csh_corebe', 'file_rename', $GLOBALS['BACK_PATH'],'<br/>');
192
193 // Add the HTML as a section:
194 $this->content.= $this->doc->section('',$code);
195
196 }
197
198 /**
199 * Outputting the accumulated content to screen
200 *
201 * @return void
202 */
203 function printContent() {
204 $this->content.= $this->doc->endPage();
205 $this->content = $this->doc->insertStylesAndJS($this->content);
206 echo $this->content;
207 }
208 }
209
210 // Include extension?
211 if (defined('TYPO3_MODE') && $TYPO3_CONF_VARS[TYPO3_MODE]['XCLASS']['typo3/file_rename.php']) {
212 include_once($TYPO3_CONF_VARS[TYPO3_MODE]['XCLASS']['typo3/file_rename.php']);
213 }
214
215
216
217
218
219
220
221
222
223
224
225
226 // Make instance:
227 $SOBE = t3lib_div::makeInstance('SC_file_rename');
228 $SOBE->init();
229 $SOBE->main();
230 $SOBE->printContent();
231 ?>