|
TYPO3 API
SVNRelease
|
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: Upload of files 00029 * 00030 * $Id: file_upload.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 * 77: class SC_file_upload 00041 * 103: function init() 00042 * 171: function main() 00043 * 241: function printContent() 00044 * 00045 * TOTAL FUNCTIONS: 3 00046 * (This index is automatically created/updated by the extension "extdeveval") 00047 * 00048 */ 00049 00050 $BACK_PATH = ''; 00051 require('init.php'); 00052 require('template.php'); 00053 $LANG->includeLLFile('EXT:lang/locallang_misc.xml'); 00054 00055 00056 00057 00058 00059 00060 /** 00061 * Script Class for display up to 10 upload fields 00062 * 00063 * @author Kasper Skårhøj <kasperYYYY@typo3.com> 00064 * @package TYPO3 00065 * @subpackage core 00066 */ 00067 class SC_file_upload { 00068 00069 // External, static: 00070 var $uploadNumber = 10; 00071 00072 // Internal, static: 00073 /** 00074 * Document template object 00075 * 00076 * @var smallDoc 00077 */ 00078 var $doc; 00079 00080 /** 00081 * File processing object 00082 * 00083 * @var t3lib_basicFileFunctions 00084 */ 00085 var $basicff; 00086 var $icon; // Will be set to the proper icon for the $target value. 00087 var $shortPath; // Relative path to current found filemount 00088 var $title; // Name of the filemount 00089 00090 /** 00091 * Charset processing object 00092 * 00093 * @var t3lib_cs 00094 */ 00095 protected $charsetConversion; 00096 00097 // Internal, static (GPVar): 00098 var $number; 00099 var $target; // Set with the target path inputted in &target 00100 var $returnUrl; // Return URL of list module. 00101 00102 // Internal, dynamic: 00103 var $content; // Accumulating content 00104 00105 00106 /** 00107 * Constructor for initializing the class 00108 * 00109 * @return void 00110 */ 00111 function init() { 00112 // Initialize GPvars: 00113 $this->number = t3lib_div::_GP('number'); 00114 $this->target = t3lib_div::_GP('target'); 00115 $this->returnUrl = t3lib_div::sanitizeLocalUrl(t3lib_div::_GP('returnUrl')); 00116 $this->returnUrl = $this->returnUrl ? $this->returnUrl : t3lib_div::getIndpEnv('TYPO3_SITE_URL') . TYPO3_mainDir . t3lib_extMgm::extRelPath('filelist') . 'mod1/file_list.php?id=' . rawurlencode($this->target); 00117 00118 // set the number of input fields 00119 if (empty($this->number)) { 00120 $this->number = $GLOBALS['BE_USER']->getTSConfigVal('options.defaultFileUploads'); 00121 } 00122 $this->number = t3lib_div::intInRange($this->number, 1, $this->uploadNumber); 00123 00124 // Init basic-file-functions object: 00125 $this->basicff = t3lib_div::makeInstance('t3lib_basicFileFunctions'); 00126 $this->basicff->init($GLOBALS['FILEMOUNTS'], $GLOBALS['TYPO3_CONF_VARS']['BE']['fileExtensions']); 00127 00128 // Init basic-charset-functions object: 00129 $this->charsetConversion = t3lib_div::makeInstance('t3lib_cs'); 00130 00131 // Cleaning and checking target 00132 $this->target = $this->charsetConversion->conv($this->target, 'utf-8', $GLOBALS['LANG']->charSet); 00133 $this->target = $this->basicff->is_directory($this->target); 00134 $key = $this->basicff->checkPathAgainstMounts($this->target . '/'); 00135 if (!$this->target || !$key) { 00136 $title = $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_mod_file_list.xml:paramError', TRUE); 00137 $message = $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_mod_file_list.xml:targetNoDir', TRUE); 00138 throw new RuntimeException($title . ': ' . $message); 00139 } 00140 00141 // Finding the icon 00142 switch ($GLOBALS['FILEMOUNTS'][$key]['type']) { 00143 case 'user': 00144 $this->icon = 'gfx/i/_icon_ftp_user.gif'; 00145 break; 00146 case 'group': 00147 $this->icon = 'gfx/i/_icon_ftp_group.gif'; 00148 break; 00149 default: 00150 $this->icon = 'gfx/i/_icon_ftp.gif'; 00151 break; 00152 } 00153 00154 $this->icon = '<img' . t3lib_iconWorks::skinImg($GLOBALS['BACK_PATH'], $this->icon, 'width="18" height="16"') . ' title="" alt="" />'; 00155 00156 // Relative path to filemount, $key: 00157 $this->shortPath = substr($this->target, strlen($GLOBALS['FILEMOUNTS'][$key]['path'])); 00158 00159 // Setting title: 00160 $this->title = $this->icon . htmlspecialchars($GLOBALS['FILEMOUNTS'][$key]['name']) . ': ' . $this->shortPath; 00161 00162 // Setting template object 00163 $this->doc = t3lib_div::makeInstance('template'); 00164 $this->doc->setModuleTemplate('templates/file_upload.html'); 00165 $this->doc->backPath = $GLOBALS['BACK_PATH']; 00166 $this->doc->form = '<form action="tce_file.php" method="post" name="editform" enctype="' . $GLOBALS['TYPO3_CONF_VARS']['SYS']['form_enctype'] . '">'; 00167 00168 if($GLOBALS['BE_USER']->jsConfirmation(1)) { 00169 $confirm = ' && confirm(' . $GLOBALS['LANG']->JScharCode($GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.php:mess.redraw')) . ')'; 00170 } else { 00171 $confirm = ''; 00172 } 00173 $this->doc->JScode = $this->doc->wrapScriptTags(' 00174 var path = "'.$this->target.'"; 00175 00176 function reload(a) { // 00177 if (!changed || (changed ' . $confirm . ')) { 00178 var params = "&target="+encodeURIComponent(path)+"&number="+a+"&returnUrl=' 00179 . urlencode($this->charsetConversion->conv($this->returnUrl, $GLOBALS['LANG']->charSet, 'utf-8')) 00180 . '"; 00181 window.location.href = "file_upload.php?"+params; 00182 } 00183 } 00184 function backToList() { // 00185 top.goToModule("file_list"); 00186 } 00187 var changed = 0; 00188 '); 00189 } 00190 00191 00192 /** 00193 * Main function, rendering the upload file form fields 00194 * 00195 * @return void 00196 */ 00197 function main() { 00198 // Make page header: 00199 $this->content = $this->doc->startPage($GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.php:file_upload.php.pagetitle')); 00200 00201 $form = $this->renderUploadForm(); 00202 00203 $pageContent = 00204 $this->doc->header($GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.php:file_upload.php.pagetitle')) . 00205 $this->doc->section('', $form); 00206 00207 00208 // Header Buttons 00209 $docHeaderButtons = array( 00210 'csh' => t3lib_BEfunc::cshItem('xMOD_csh_corebe', 'file_upload', $GLOBALS['BACK_PATH']) 00211 ); 00212 00213 $markerArray = array( 00214 'CSH' => $docHeaderButtons['csh'], 00215 'FUNC_MENU' => t3lib_BEfunc::getFuncMenu($this->id, 'SET[function]', $this->MOD_SETTINGS['function'], $this->MOD_MENU['function']), 00216 'CONTENT' => $pageContent, 00217 'PATH' => $this->title, 00218 ); 00219 00220 $this->content .= $this->doc->moduleBody(array(), $docHeaderButtons, $markerArray); 00221 $this->content .= $this->doc->endPage(); 00222 $this->content = $this->doc->insertStylesAndJS($this->content); 00223 } 00224 00225 00226 /** 00227 * This function renders the upload form 00228 * 00229 * @return string the HTML form as a string, ready for outputting 00230 */ 00231 function renderUploadForm() { 00232 $content = ' 00233 <div id="c-select"> 00234 <label for="number-of-uploads">' . 00235 $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.php:file_upload.php.number_of_files') . 00236 '</label> 00237 <select name="number" id="number-of-uploads" onchange="reload(this.options[this.selectedIndex].value);">'; 00238 00239 for ($a = 1; $a <= $this->uploadNumber; $a++) { 00240 $content .= '<option value="' . $a . '"' . 00241 ($this->number == $a ? ' selected="selected"' : '' ) . 00242 '>' . $a . '</option>'; 00243 } 00244 $content .= ' 00245 </select> 00246 </div> 00247 '; 00248 00249 00250 // Make checkbox for "overwrite" 00251 $content .= ' 00252 <div id="c-override"> 00253 <input type="checkbox" class="checkbox" name="overwriteExistingFiles" id="overwriteExistingFiles" value="1" /> <label for="overwriteExistingFiles">' . $GLOBALS['LANG']->getLL('overwriteExistingFiles', 1) . '</label> 00254 </div> 00255 '; 00256 00257 00258 // Produce the number of upload-fields needed: 00259 $content .= ' 00260 <div id="c-upload"> 00261 '; 00262 for ($a = 0; $a < $this->number; $a++) { 00263 // Adding 'size="50" ' for the sake of Mozilla! 00264 $content .= ' 00265 <input type="file" name="upload_' . $a . '"' . $this->doc->formWidth(35) . ' size="50" onclick="changed=1;" /> 00266 <input type="hidden" name="file[upload][' . $a . '][target]" value="' . htmlspecialchars($this->target) . '" /> 00267 <input type="hidden" name="file[upload][' . $a . '][data]" value="' . $a . '" /><br /> 00268 '; 00269 } 00270 $content .= ' 00271 </div> 00272 '; 00273 00274 // Submit button: 00275 $content .= ' 00276 <div id="c-submit"> 00277 <input type="submit" value="' . $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.php:file_upload.php.submit', 1) . '" /> 00278 <input type="submit" value="' . $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.php:labels.cancel', 1) . '" onclick="backToList(); return false;" /> 00279 <input type="hidden" name="redirect" value="' . htmlspecialchars($this->returnUrl) . '" /> 00280 </div> 00281 '; 00282 00283 return $content; 00284 } 00285 00286 00287 /** 00288 * Outputting the accumulated content to screen 00289 * 00290 * @return void 00291 */ 00292 function printContent() { 00293 echo $this->content; 00294 } 00295 } 00296 00297 00298 if (defined('TYPO3_MODE') && isset($GLOBALS['TYPO3_CONF_VARS'][TYPO3_MODE]['XCLASS']['typo3/file_upload.php'])) { 00299 include_once($GLOBALS['TYPO3_CONF_VARS'][TYPO3_MODE]['XCLASS']['typo3/file_upload.php']); 00300 } 00301 00302 00303 // Make instance: 00304 $SOBE = t3lib_div::makeInstance('SC_file_upload'); 00305 $SOBE->init(); 00306 $SOBE->main(); 00307 $SOBE->printContent(); 00308 00309 ?>
1.8.0