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