2 /***************************************************************
5 * (c) 1999-2011 Kasper Skårhøj (kasperYYYY@typo3.com)
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.
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.
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.
25 * This copyright notice MUST APPEAR in all copies of the script!
26 ***************************************************************/
28 * Web>File: Renaming files and folders
30 * Revised for TYPO3 3.6 November/2003 by Kasper Skårhøj
32 * @author Kasper Skårhøj <kasperYYYY@typo3.com>
39 require('template.php');
44 * Script Class for the rename-file form.
46 * @author Kasper Skårhøj <kasperYYYY@typo3.com>
50 class SC_file_rename
{
54 * Document template object
59 var $title; // Name of the filemount
61 // Internal, static (GPVar):
62 var $target; // Set with the target path inputted in &target
65 * the file or folder object that should be renamed
67 * @var t3lib_file_ResourceInterface $fileOrFolderObject
69 protected $fileOrFolderObject;
71 var $returnUrl; // Return URL of list module.
74 var $content; // Accumulating content
78 * Constructor function for class
84 $this->target
= t3lib_div
::_GP('target');
85 $this->returnUrl
= t3lib_div
::sanitizeLocalUrl(t3lib_div
::_GP('returnUrl'));
87 // Cleaning and checking target
89 $this->fileOrFolderObject
= t3lib_file_Factory
::getInstance()->retrieveFileOrFolderObject($this->target
);
92 if (!$this->fileOrFolderObject
) {
93 $title = $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_mod_file_list.xml:paramError', TRUE);
94 $message = $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_mod_file_list.xml:targetNoDir', TRUE);
95 throw new RuntimeException($title . ': ' . $message, 1294586844);
98 // if a folder should be renamed, AND the returnURL should go to the old directory name, the redirect is forced
99 // so the redirect will NOT end in a error message
100 // this case only happens if you select the folder itself in the foldertree and then use the clickmenu to
102 if ($this->fileOrFolderObject
instanceof t3lib_file_Folder
) {
103 $parsedUrl = parse_url($this->returnUrl
);
104 $queryParts = t3lib_div
::explodeUrl2Array(urldecode($parsedUrl['query']));
105 if ($queryParts['id'] === $this->fileOrFolderObject
->getCombinedIdentifier()) {
106 $this->returnUrl
= str_replace(urlencode($queryParts['id']), urlencode($this->fileOrFolderObject
->getStorage()->getRootLevelFolder()->getCombinedIdentifier()), $this->returnUrl
);
112 // Setting icon and title
113 $icon = t3lib_iconWorks
::getSpriteIcon('apps-filetree-root');
114 $this->title
= $icon . htmlspecialchars($this->fileOrFolderObject
->getStorage()->getName()) . ': ' . htmlspecialchars($this->fileOrFolderObject
->getIdentifier());
116 // Setting template object
117 $this->doc
= t3lib_div
::makeInstance('template');
118 $this->doc
->setModuleTemplate('templates/file_rename.html');
119 $this->doc
->backPath
= $GLOBALS['BACK_PATH'];
120 $this->doc
->JScode
=$this->doc
->wrapScriptTags('
121 function backToList() { //
122 top.goToModule("file_list");
128 * Main function, rendering the content of the rename form
133 //TODO: change locallang*.php to locallang*.xml
136 $this->content
= $this->doc
->startPage($GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.php:file_rename.php.pagetitle'));
138 $pageContent = $this->doc
->header($GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.php:file_rename.php.pagetitle'));
139 $pageContent .= $this->doc
->spacer(5);
140 $pageContent .= $this->doc
->divider(5);
142 if ($this->fileOrFolderObject
instanceof t3lib_file_Folder
) {
143 $fileIdentifier = $this->fileOrFolderObject
->getCombinedIdentifier();
145 $fileIdentifier = $this->fileOrFolderObject
->getUid();
148 $code = '<form action="tce_file.php" method="post" name="editform">';
149 // Making the formfields for renaming:
153 <input type="text" name="file[rename][0][target]" value="' . htmlspecialchars($this->fileOrFolderObject
->getName()) . '"' . $GLOBALS['TBE_TEMPLATE']->formWidth(40) . ' />
154 <input type="hidden" name="file[rename][0][data]" value="' . htmlspecialchars($fileIdentifier) . '" />
158 // Making submit button:
161 <input type="submit" value="' . $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.php:file_rename.php.submit', 1) . '" />
162 <input type="submit" value="' . $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.php:labels.cancel', 1) . '" onclick="backToList(); return false;" />
163 <input type="hidden" name="redirect" value="'.htmlspecialchars($this->returnUrl
).'" />
169 // Add the HTML as a section:
170 $pageContent .= $code;
172 $docHeaderButtons = array();
173 $docHeaderButtons['csh'] = t3lib_BEfunc
::cshItem('xMOD_csh_corebe', 'file_rename', $GLOBALS['BACK_PATH']);
175 // Add the HTML as a section:
176 $markerArray = array(
177 'CSH' => $docHeaderButtons['csh'],
178 'FUNC_MENU' => t3lib_BEfunc
::getFuncMenu($this->id
, 'SET[function]', $this->MOD_SETTINGS
['function'], $this->MOD_MENU
['function']),
179 'CONTENT' => $pageContent,
180 'PATH' => $this->title
,
183 $this->content
.= $this->doc
->moduleBody(array(), $docHeaderButtons, $markerArray);
184 $this->content
.= $this->doc
->endPage();
185 $this->content
= $this->doc
->insertStylesAndJS($this->content
);
189 * Outputting the accumulated content to screen
193 function printContent() {
199 $SOBE = t3lib_div
::makeInstance('SC_file_rename');
202 $SOBE->printContent();