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: Create new folders in the filemounts
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');
51 * Script Class for the create-new script; Displays a form for creating up to 10 folders or one new text file
53 * @author Kasper Skårhøj <kasperYYYY@typo3.com>
57 class SC_file_newfolder
{
64 * document template object
71 * File processing object
73 * @var t3lib_basicFileFunctions
76 var $icon; // Will be set to the proper icon for the $target value.
77 var $shortPath; // Relative path to current found filemount
78 var $title; // Name of the filemount
81 * Charset processing object
85 protected $charsetConversion;
87 // Internal, static (GPVar):
89 var $target; // Set with the target path inputted in &target
90 var $returnUrl; // Return URL of list module.
93 var $content; // Accumulating content
98 * Constructor function for class
103 // Initialize GPvars:
104 $this->number
= t3lib_div
::_GP('number');
105 $this->target
= t3lib_div
::_GP('target');
106 $this->returnUrl
= t3lib_div
::sanitizeLocalUrl(t3lib_div
::_GP('returnUrl'));
108 // Init basic-file-functions object:
109 $this->basicff
= t3lib_div
::makeInstance('t3lib_basicFileFunctions');
110 $this->basicff
->init($GLOBALS['FILEMOUNTS'],$GLOBALS['TYPO3_CONF_VARS']['BE']['fileExtensions']);
112 // Init basic-charset-functions object:
113 $this->charsetConversion
= t3lib_div
::makeInstance('t3lib_cs');
115 // Cleaning and checking target
116 $this->target
= $this->charsetConversion
->conv($this->target
, 'utf-8', $GLOBALS['LANG']->charSet
);
117 $this->target
= $this->basicff
->is_directory($this->target
);
118 $key=$this->basicff
->checkPathAgainstMounts($this->target
.'/');
119 if (!$this->target ||
!$key) {
120 $title = $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_mod_file_list.xml:paramError', TRUE
);
121 $message = $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_mod_file_list.xml:targetNoDir', TRUE
);
122 throw new RuntimeException($title . ': ' . $message, 1294586843);
126 switch($GLOBALS['FILEMOUNTS'][$key]['type']) {
128 $this->icon
= 'gfx/i/_icon_ftp_user.gif';
131 $this->icon
= 'gfx/i/_icon_ftp_group.gif';
134 $this->icon
= 'gfx/i/_icon_ftp.gif';
137 $this->icon
= '<img'.t3lib_iconWorks
::skinImg($this->backPath
,$this->icon
,'width="18" height="16"').' title="" alt="" />';
139 // Relative path to filemount, $key:
140 $this->shortPath
= substr($this->target
,strlen($GLOBALS['FILEMOUNTS'][$key]['path']));
143 $this->title
= $this->icon
. htmlspecialchars($GLOBALS['FILEMOUNTS'][$key]['name']) . ': ' . $this->shortPath
;
145 // Setting template object
146 $this->doc
= t3lib_div
::makeInstance('template');
147 $this->doc
->setModuleTemplate('templates/file_newfolder.html');
148 $this->doc
->backPath
= $GLOBALS['BACK_PATH'];
149 $this->doc
->JScode
=$this->doc
->wrapScriptTags('
150 var path = "'.$this->target
.'";
152 function reload(a) { //
153 if (!changed || (changed && confirm(' . $GLOBALS['LANG']->JScharCode($GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.php:mess.redraw')) . '))) {
154 var params = "&target="+encodeURIComponent(path)+"&number="+a+"&returnUrl='
155 . urlencode($this->charsetConversion
->conv($this->returnUrl
, $GLOBALS['LANG']->charSet
, 'utf-8'))
157 window.location.href = "file_newfolder.php?"+params;
160 function backToList() { //
161 top.goToModule("file_list");
169 * Main function, rendering the main module content
175 // start content compilation
176 $this->content
.= $this->doc
->startPage($GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.php:file_newfolder.php.pagetitle'));
181 $pageContent.=$this->doc
->header($GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.php:file_newfolder.php.pagetitle'));
182 $pageContent.=$this->doc
->spacer(5);
183 $pageContent.=$this->doc
->divider(5);
186 $code = '<form action="tce_file.php" method="post" name="editform">';
187 // Making the selector box for the number of concurrent folder-creations
188 $this->number
= t3lib_utility_Math
::forceIntegerInRange($this->number
,1,10);
191 <label for="number-of-new-folders">' .
192 $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.php:file_newfolder.php.number_of_folders') .
194 <select name="number" id="number-of-new-folders" onchange="reload(this.options[this.selectedIndex].value);">';
195 for ($a=1;$a<=$this->folderNumber
;$a++
) {
196 $code .= '<option value="' . $a . '"' .
197 ($this->number
== $a ?
' selected="selected"' : '') .
198 '>' . $a . '</option>';
205 // Making the number of new-folder boxes needed:
207 <div id="c-createFolders">
209 for ($a=0;$a<$this->number
;$a++
) {
211 <input'.$this->doc
->formWidth(20).' type="text" name="file[newfolder]['.$a.'][data]" onchange="changed=true;" />
212 <input type="hidden" name="file[newfolder][' . $a . '][target]" value="' . htmlspecialchars($this->target
) . '" /><br />
219 // Making submit button for folder creation:
221 <div id="c-submitFolders">
222 <input type="submit" value="' . $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.php:file_newfolder.php.submit', 1) . '" />
223 <input type="submit" value="' . $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.php:labels.cancel', 1) . '" onclick="backToList(); return false;" />
224 <input type="hidden" name="redirect" value="'.htmlspecialchars($this->returnUrl
).'" />
229 $code.= t3lib_BEfunc
::cshItem('xMOD_csh_corebe', 'file_newfolder', $GLOBALS['BACK_PATH'], '<br />');
231 $pageContent.= $code;
236 $pageContent.= $this->doc
->spacer(10);
238 // Switching form tags:
239 $pageContent.= $this->doc
->sectionEnd();
240 $pageContent.= '</form><form action="tce_file.php" method="post" name="editform2">';
242 // Create a list of allowed file extensions with the nice format "*.jpg, *.gif" etc.
243 $fileExtList = array();
244 $textfileExt = t3lib_div
::trimExplode(',', $GLOBALS['TYPO3_CONF_VARS']['SYS']['textfile_ext'], TRUE
);
245 foreach ($textfileExt as $fileExt) {
246 if (!preg_match('/' . $GLOBALS['TYPO3_CONF_VARS']['BE']['fileDenyPattern'] . '/i', '.' . $fileExt)) {
247 $fileExtList[] = '*.' . $fileExt;
250 // Add form fields for creation of a new, blank text file:
253 <p>[' . htmlspecialchars(implode(', ', $fileExtList)) . ']</p>
254 <input'.$this->doc
->formWidth(20).' type="text" name="file[newfile][0][data]" onchange="changed=true;" />
255 <input type="hidden" name="file[newfile][0][target]" value="'.htmlspecialchars($this->target
).'" />
259 // Submit button for creation of a new file:
261 <div id="c-submitFiles">
262 <input type="submit" value="' . $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.php:file_newfolder.php.newfile_submit', 1) . '" />
263 <input type="submit" value="' . $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.php:labels.cancel', 1) . '" onclick="backToList(); return false;" />
264 <input type="hidden" name="redirect" value="'.htmlspecialchars($this->returnUrl
).'" />
269 $code.= t3lib_BEfunc
::cshItem('xMOD_csh_corebe', 'file_newfile', $GLOBALS['BACK_PATH'], '<br />');
270 $pageContent .= $this->doc
->section($GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.php:file_newfolder.php.newfile'), $code);
271 $pageContent .= $this->doc
->sectionEnd();
272 $pageContent .= '</form>';
274 $docHeaderButtons = array();
276 // Add the HTML as a section:
277 $markerArray = array(
278 'CSH' => $docHeaderButtons['csh'],
279 'FUNC_MENU' => t3lib_BEfunc
::getFuncMenu($this->id
, 'SET[function]', $this->MOD_SETTINGS
['function'], $this->MOD_MENU
['function']),
280 'CONTENT' => $pageContent,
281 'PATH' => $this->title
,
284 $this->content
.= $this->doc
->moduleBody(array(), $docHeaderButtons, $markerArray);
285 $this->content
.= $this->doc
->endPage();
287 $this->content
= $this->doc
->insertStylesAndJS($this->content
);
291 * Outputting the accumulated content to screen
295 function printContent() {
301 if (defined('TYPO3_MODE') && isset($GLOBALS['TYPO3_CONF_VARS'][TYPO3_MODE
]['XCLASS']['typo3/file_newfolder.php'])) {
302 include_once($GLOBALS['TYPO3_CONF_VARS'][TYPO3_MODE
]['XCLASS']['typo3/file_newfolder.php']);
308 $SOBE = t3lib_div
::makeInstance('SC_file_newfolder');
311 $SOBE->printContent();