TYPO3 API  SVNRelease
file_newfolder.php
Go to the documentation of this file.
00001 <?php
00002 /***************************************************************
00003 *  Copyright notice
00004 *
00005 *  (c) 1999-2011 Kasper Skårhøj (kasperYYYY@typo3.com)
00006 *  All rights reserved
00007 *
00008 *  This script is part of the TYPO3 project. The TYPO3 project is
00009 *  free software; you can redistribute it and/or modify
00010 *  it under the terms of the GNU General Public License as published by
00011 *  the Free Software Foundation; either version 2 of the License, or
00012 *  (at your option) any later version.
00013 *
00014 *  The GNU General Public License can be found at
00015 *  http://www.gnu.org/copyleft/gpl.html.
00016 *  A copy is found in the textfile GPL.txt and important notices to the license
00017 *  from the author is found in LICENSE.txt distributed with these scripts.
00018 *
00019 *
00020 *  This script is distributed in the hope that it will be useful,
00021 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
00022 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00023 *  GNU General Public License for more details.
00024 *
00025 *  This copyright notice MUST APPEAR in all copies of the script!
00026 ***************************************************************/
00027 /**
00028  * Web>File: Create new folders in the filemounts
00029  *
00030  * $Id: file_newfolder.php 10121 2011-01-18 20:15:30Z ohader $
00031  * Revised for TYPO3 3.6 November/2003 by Kasper Skårhøj
00032  *
00033  * @author  Kasper Skårhøj <kasperYYYY@typo3.com>
00034  */
00035 /**
00036  * [CLASS/FUNCTION INDEX of SCRIPT]
00037  *
00038  *
00039  *
00040  *   74: class SC_file_newfolder
00041  *  101:     function init()
00042  *  161:     function main()
00043  *  255:     function printContent()
00044  *
00045  * TOTAL FUNCTIONS: 3
00046  * (This index is automatically created/updated by the extension "extdeveval")
00047  *
00048  */
00049 
00050 
00051 
00052 $BACK_PATH = '';
00053 require('init.php');
00054 require('template.php');
00055 
00056 
00057 
00058 
00059 
00060 
00061 
00062 
00063 
00064 
00065 /**
00066  * Script Class for the create-new script; Displays a form for creating up to 10 folders or one new text file
00067  *
00068  * @author  Kasper Skårhøj <kasperYYYY@typo3.com>
00069  * @package TYPO3
00070  * @subpackage core
00071  */
00072 class SC_file_newfolder {
00073 
00074         // External, static:
00075     var $folderNumber=10;
00076 
00077         // Internal, static:
00078     /**
00079      * document template object
00080      *
00081      * @var smallDoc
00082      */
00083     var $doc;
00084 
00085     /**
00086      * File processing object
00087      *
00088      * @var t3lib_basicFileFunctions
00089      */
00090     var $basicff;
00091     var $icon;          // Will be set to the proper icon for the $target value.
00092     var $shortPath;     // Relative path to current found filemount
00093     var $title;         // Name of the filemount
00094 
00095     /**
00096      * Charset processing object
00097      *
00098      * @var t3lib_cs
00099      */
00100     protected $charsetConversion;
00101 
00102         // Internal, static (GPVar):
00103     var $number;
00104     var $target;        // Set with the target path inputted in &target
00105     var $returnUrl;     // Return URL of list module.
00106 
00107         // Internal, dynamic:
00108     var $content;       // Accumulating content
00109 
00110 
00111 
00112     /**
00113      * Constructor function for class
00114      *
00115      * @return  void
00116      */
00117     function init() {
00118         global $LANG,$BACK_PATH,$TYPO3_CONF_VARS;
00119 
00120             // Initialize GPvars:
00121         $this->number = t3lib_div::_GP('number');
00122         $this->target = t3lib_div::_GP('target');
00123         $this->returnUrl = t3lib_div::sanitizeLocalUrl(t3lib_div::_GP('returnUrl'));
00124 
00125             // Init basic-file-functions object:
00126         $this->basicff = t3lib_div::makeInstance('t3lib_basicFileFunctions');
00127         $this->basicff->init($GLOBALS['FILEMOUNTS'],$TYPO3_CONF_VARS['BE']['fileExtensions']);
00128 
00129             // Init basic-charset-functions object:
00130         $this->charsetConversion = t3lib_div::makeInstance('t3lib_cs');
00131 
00132             // Cleaning and checking target
00133         $this->target = $this->charsetConversion->conv($this->target, 'utf-8', $GLOBALS['LANG']->charSet);
00134         $this->target = $this->basicff->is_directory($this->target);
00135         $key=$this->basicff->checkPathAgainstMounts($this->target.'/');
00136         if (!$this->target || !$key) {
00137             $title = $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_mod_file_list.xml:paramError', TRUE);
00138             $message = $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_mod_file_list.xml:targetNoDir', TRUE);
00139             throw new RuntimeException($title . ': ' . $message);
00140         }
00141 
00142             // Finding the icon
00143         switch($GLOBALS['FILEMOUNTS'][$key]['type'])    {
00144             case 'user':    $this->icon = 'gfx/i/_icon_ftp_user.gif';   break;
00145             case 'group':   $this->icon = 'gfx/i/_icon_ftp_group.gif';  break;
00146             default:        $this->icon = 'gfx/i/_icon_ftp.gif';    break;
00147         }
00148 
00149         $this->icon = '<img'.t3lib_iconWorks::skinImg($this->backPath,$this->icon,'width="18" height="16"').' title="" alt="" />';
00150 
00151             // Relative path to filemount, $key:
00152         $this->shortPath = substr($this->target,strlen($GLOBALS['FILEMOUNTS'][$key]['path']));
00153 
00154             // Setting title:
00155         $this->title = $this->icon . htmlspecialchars($GLOBALS['FILEMOUNTS'][$key]['name']) . ': ' . $this->shortPath;
00156 
00157             // Setting template object
00158         $this->doc = t3lib_div::makeInstance('template');
00159         $this->doc->setModuleTemplate('templates/file_newfolder.html');
00160         $this->doc->backPath = $BACK_PATH;
00161         $this->doc->JScode=$this->doc->wrapScriptTags('
00162             var path = "'.$this->target.'";
00163 
00164             function reload(a)  {   //
00165                 if (!changed || (changed && confirm('.$LANG->JScharCode($LANG->sL('LLL:EXT:lang/locallang_core.php:mess.redraw')).')))  {
00166                     var params = "&target="+encodeURIComponent(path)+"&number="+a+"&returnUrl='
00167                             . urlencode($this->charsetConversion->conv($this->returnUrl, $GLOBALS['LANG']->charSet, 'utf-8'))
00168                             . '";
00169                     window.location.href = "file_newfolder.php?"+params;
00170                 }
00171             }
00172             function backToList()   {   //
00173                 top.goToModule("file_list");
00174             }
00175 
00176             var changed = 0;
00177         ');
00178     }
00179 
00180     /**
00181      * Main function, rendering the main module content
00182      *
00183      * @return  void
00184      */
00185     function main() {
00186         global $LANG;
00187 
00188             // start content compilation
00189         $this->content.=$this->doc->startPage($LANG->sL('LLL:EXT:lang/locallang_core.php:file_newfolder.php.pagetitle'));
00190 
00191 
00192             // Make page header:
00193         $pageContent='';
00194         $pageContent.=$this->doc->header($LANG->sL('LLL:EXT:lang/locallang_core.php:file_newfolder.php.pagetitle'));
00195         $pageContent.=$this->doc->spacer(5);
00196         $pageContent.=$this->doc->divider(5);
00197 
00198 
00199         $code = '<form action="tce_file.php" method="post" name="editform">';
00200             // Making the selector box for the number of concurrent folder-creations
00201         $this->number = t3lib_div::intInRange($this->number,1,10);
00202         $code .= '
00203             <div id="c-select">
00204                 <label for="number-of-new-folders">' .
00205                 $LANG->sL('LLL:EXT:lang/locallang_core.php:file_newfolder.php.number_of_folders') .
00206                 '</label>
00207                 <select name="number" id="number-of-new-folders" onchange="reload(this.options[this.selectedIndex].value);">';
00208         for ($a=1;$a<=$this->folderNumber;$a++) {
00209             $code .= '<option value="' . $a . '"' .
00210                     ($this->number == $a ? ' selected="selected"' : '') .
00211                     '>' . $a . '</option>';
00212         }
00213         $code.='
00214                 </select>
00215             </div>
00216             ';
00217 
00218             // Making the number of new-folder boxes needed:
00219         $code.='
00220             <div id="c-createFolders">
00221         ';
00222         for ($a=0;$a<$this->number;$a++)    {
00223             $code.='
00224                     <input'.$this->doc->formWidth(20).' type="text" name="file[newfolder]['.$a.'][data]" onchange="changed=true;" />
00225                     <input type="hidden" name="file[newfolder][' . $a . '][target]" value="' . htmlspecialchars($this->target) . '" /><br />
00226                 ';
00227         }
00228         $code.='
00229             </div>
00230         ';
00231 
00232             // Making submit button for folder creation:
00233         $code.='
00234             <div id="c-submitFolders">
00235                 <input type="submit" value="'.$LANG->sL('LLL:EXT:lang/locallang_core.php:file_newfolder.php.submit',1).'" />
00236                 <input type="submit" value="'.$LANG->sL('LLL:EXT:lang/locallang_core.php:labels.cancel',1).'" onclick="backToList(); return false;" />
00237                 <input type="hidden" name="redirect" value="'.htmlspecialchars($this->returnUrl).'" />
00238             </div>
00239             ';
00240 
00241             // CSH:
00242         $code.= t3lib_BEfunc::cshItem('xMOD_csh_corebe', 'file_newfolder', $GLOBALS['BACK_PATH'], '<br />');
00243 
00244         $pageContent.= $code;
00245 
00246 
00247 
00248             // Add spacer:
00249         $pageContent.= $this->doc->spacer(10);
00250 
00251             // Switching form tags:
00252         $pageContent.= $this->doc->sectionEnd();
00253         $pageContent.= '</form><form action="tce_file.php" method="post" name="editform2">';
00254 
00255             // Create a list of allowed file extensions with the nice format "*.jpg, *.gif" etc.
00256         $fileExtList = array();
00257         $textfileExt = t3lib_div::trimExplode(',', $GLOBALS['TYPO3_CONF_VARS']['SYS']['textfile_ext'], TRUE);
00258         foreach ($textfileExt as $fileExt) {
00259             if (!preg_match('/' . $GLOBALS['TYPO3_CONF_VARS']['BE']['fileDenyPattern'] . '/i', '.' . $fileExt)) {
00260                 $fileExtList[] = '*.' . $fileExt;
00261             }
00262         }
00263             // Add form fields for creation of a new, blank text file:
00264         $code='
00265             <div id="c-newFile">
00266                 <p>[' . htmlspecialchars(implode(', ', $fileExtList)) . ']</p>
00267                 <input'.$this->doc->formWidth(20).' type="text" name="file[newfile][0][data]" onchange="changed=true;" />
00268                 <input type="hidden" name="file[newfile][0][target]" value="'.htmlspecialchars($this->target).'" />
00269             </div>
00270             ';
00271 
00272             // Submit button for creation of a new file:
00273         $code.='
00274             <div id="c-submitFiles">
00275                 <input type="submit" value="'.$LANG->sL('LLL:EXT:lang/locallang_core.php:file_newfolder.php.newfile_submit',1).'" />
00276                 <input type="submit" value="'.$LANG->sL('LLL:EXT:lang/locallang_core.php:labels.cancel',1).'" onclick="backToList(); return false;" />
00277                 <input type="hidden" name="redirect" value="'.htmlspecialchars($this->returnUrl).'" />
00278             </div>
00279             ';
00280 
00281             // CSH:
00282         $code.= t3lib_BEfunc::cshItem('xMOD_csh_corebe', 'file_newfile', $GLOBALS['BACK_PATH'], '<br />');
00283         $pageContent.= $this->doc->section($LANG->sL('LLL:EXT:lang/locallang_core.php:file_newfolder.php.newfile'),$code);
00284         $pageContent .= $this->doc->sectionEnd();
00285         $pageContent .= '</form>';
00286 
00287         $docHeaderButtons = array();
00288 
00289             // Add the HTML as a section:
00290         $markerArray = array(
00291             'CSH' => $docHeaderButtons['csh'],
00292             'FUNC_MENU' => t3lib_BEfunc::getFuncMenu($this->id, 'SET[function]', $this->MOD_SETTINGS['function'], $this->MOD_MENU['function']),
00293             'CONTENT' => $pageContent,
00294             'PATH' => $this->title,
00295         );
00296 
00297         $this->content.= $this->doc->moduleBody(array(), $docHeaderButtons, $markerArray);
00298         $this->content.= $this->doc->endPage();
00299 
00300         $this->content = $this->doc->insertStylesAndJS($this->content);
00301     }
00302 
00303     /**
00304      * Outputting the accumulated content to screen
00305      *
00306      * @return  void
00307      */
00308     function printContent() {
00309         echo $this->content;
00310     }
00311 }
00312 
00313 
00314 if (defined('TYPO3_MODE') && isset($GLOBALS['TYPO3_CONF_VARS'][TYPO3_MODE]['XCLASS']['typo3/file_newfolder.php'])) {
00315     include_once($GLOBALS['TYPO3_CONF_VARS'][TYPO3_MODE]['XCLASS']['typo3/file_newfolder.php']);
00316 }
00317 
00318 
00319 
00320 // Make instance:
00321 $SOBE = t3lib_div::makeInstance('SC_file_newfolder');
00322 $SOBE->init();
00323 $SOBE->main();
00324 $SOBE->printContent();
00325 
00326 ?>