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