[TASK] Remove trailing newlines from EOF
[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': $this->icon = 'gfx/i/_icon_ftp_user.gif'; break;
131 case 'group': $this->icon = 'gfx/i/_icon_ftp_group.gif'; break;
132 default: $this->icon = 'gfx/i/_icon_ftp.gif'; break;
133 }
134
135 $this->icon = '<img'.t3lib_iconWorks::skinImg($this->backPath,$this->icon,'width="18" height="16"').' title="" alt="" />';
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 = $this->icon . htmlspecialchars($GLOBALS['FILEMOUNTS'][$key]['name']) . ': ' . $this->shortPath;
142
143 // Setting template object
144 $this->doc = t3lib_div::makeInstance('template');
145 $this->doc->setModuleTemplate('templates/file_rename.html');
146 $this->doc->backPath = $GLOBALS['BACK_PATH'];
147 $this->doc->JScode=$this->doc->wrapScriptTags('
148 function backToList() { //
149 top.goToModule("file_list");
150 }
151 ');
152 }
153
154 /**
155 * Main function, rendering the content of the rename form
156 *
157 * @return void
158 */
159 function main() {
160 //TODO: change locallang*.php to locallang*.xml
161
162 // Make page header:
163 $this->content = $this->doc->startPage($GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.php:file_rename.php.pagetitle'));
164
165 $pageContent = $this->doc->header($GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.php:file_rename.php.pagetitle'));
166 $pageContent .= $this->doc->spacer(5);
167 $pageContent .= $this->doc->divider(5);
168
169
170 $code = '<form action="tce_file.php" method="post" name="editform">';
171 // Making the formfields for renaming:
172 $code .= '
173
174 <div id="c-rename">
175 <input type="text" name="file[rename][0][data]" value="'.htmlspecialchars(basename($this->shortPath)).'"'.$GLOBALS['TBE_TEMPLATE']->formWidth(20).' />
176 <input type="hidden" name="file[rename][0][target]" value="'.htmlspecialchars($this->target).'" />
177 </div>
178 ';
179
180 // Making submit button:
181 $code.='
182 <div id="c-submit">
183 <input type="submit" value="' . $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.php:file_rename.php.submit', 1) . '" />
184 <input type="submit" value="' . $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.php:labels.cancel', 1) . '" onclick="backToList(); return false;" />
185 <input type="hidden" name="redirect" value="'.htmlspecialchars($this->returnUrl).'" />
186 </div>
187 ';
188
189 $code .= '</form>';
190
191 // Add the HTML as a section:
192 $pageContent .= $code;
193
194 $docHeaderButtons = array();
195 $docHeaderButtons['csh'] = t3lib_BEfunc::cshItem('xMOD_csh_corebe', 'file_rename', $GLOBALS['BACK_PATH']);
196
197 // Add the HTML as a section:
198 $markerArray = array(
199 'CSH' => $docHeaderButtons['csh'],
200 'FUNC_MENU' => t3lib_BEfunc::getFuncMenu($this->id, 'SET[function]', $this->MOD_SETTINGS['function'], $this->MOD_MENU['function']),
201 'CONTENT' => $pageContent,
202 'PATH' => $this->title,
203 );
204
205 $this->content.= $this->doc->moduleBody(array(), $docHeaderButtons, $markerArray);
206 $this->content.= $this->doc->endPage();
207 $this->content = $this->doc->insertStylesAndJS($this->content);
208 }
209
210 /**
211 * Outputting the accumulated content to screen
212 *
213 * @return void
214 */
215 function printContent() {
216 echo $this->content;
217 }
218 }
219
220
221 if (defined('TYPO3_MODE') && isset($GLOBALS['TYPO3_CONF_VARS'][TYPO3_MODE]['XCLASS']['typo3/file_rename.php'])) {
222 include_once($GLOBALS['TYPO3_CONF_VARS'][TYPO3_MODE]['XCLASS']['typo3/file_rename.php']);
223 }
224
225
226
227 // Make instance:
228 $SOBE = t3lib_div::makeInstance('SC_file_rename');
229 $SOBE->init();
230 $SOBE->main();
231 $SOBE->printContent();
232
233 ?>