| [ Index ] |
|
Code source de b2evolution 2.1.0-beta |
1 <?php 2 /** 3 * This file implements the UI for file upload. 4 * 5 * This file is part of the evoCore framework - {@link http://evocore.net/} 6 * See also {@link http://sourceforge.net/projects/evocms/}. 7 * 8 * @copyright (c)2003-2007 by Francois PLANQUE - {@link http://fplanque.net/} 9 * Parts of this file are copyright (c)2004-2006 by Daniel HAHLER - {@link http://thequod.de/contact}. 10 * 11 * {@internal License choice 12 * - If you have received this file as part of a package, please find the license.txt file in 13 * the same folder or the closest folder above for complete license terms. 14 * - If you have received this file individually (e-g: from http://evocms.cvs.sourceforge.net/) 15 * then you must choose one of the following licenses before using the file: 16 * - GNU General Public License 2 (GPL) - http://www.opensource.org/licenses/gpl-license.php 17 * - Mozilla Public License 1.1 (MPL) - http://www.opensource.org/licenses/mozilla1.1.php 18 * }} 19 * 20 * {@internal Open Source relicensing agreement: 21 * Daniel HAHLER grants Francois PLANQUE the right to license 22 * Daniel HAHLER's contributions to this file and the b2evolution project 23 * under any OSI approved OSS license (http://www.opensource.org/licenses/). 24 * }} 25 * 26 * @package admin 27 * 28 * {@internal Below is a list of authors who have contributed to design/coding of this file: }} 29 * @author blueyed: Daniel HAHLER. 30 * @author fplanque: Francois PLANQUE. 31 * 32 * @version $Id: _file_upload.view.php,v 1.3 2007/11/01 05:27:31 fplanque Exp $ 33 */ 34 if( !defined('EVO_MAIN_INIT') ) die( 'Please, do not access this page directly.' ); 35 36 /** 37 * @var Settings 38 */ 39 global $Settings; 40 41 global $UserSettings; 42 43 global $upload_quickmode, $failedFiles, $ads_list_path; 44 45 global $fm_FileRoot; 46 ?> 47 48 <script type="text/javascript"> 49 <!-- 50 /** 51 * Mighty cool function to append an input or textarea element onto another element. 52 * 53 * @usedby addAnotherFileInput() 54 */ 55 function appendLabelAndInputElements( appendTo, labelText, labelBr, inputOrTextarea, inputName, 56 inputSizeOrCols, inputMaxLengthOrRows, inputType, inputClass ) 57 { 58 // LABEL: 59 60 // var fileDivLabel = document.createElement("div"); 61 // fileDivLabel.className = "label"; 62 63 var fileLabel = document.createElement('label'); 64 var fileLabelText = document.createTextNode( labelText ); 65 fileLabel.appendChild( fileLabelText ); 66 67 // fileDivLabel.appendChild( fileLabel ) 68 69 appendTo.appendChild( fileLabel ); 70 71 if( labelBr ) 72 { // We want a BR after the label: 73 appendTo.appendChild( document.createElement('br') ); 74 } 75 else 76 { 77 appendTo.appendChild( document.createTextNode( ' ' ) ); 78 } 79 80 // INPUT: 81 82 // var fileDivInput = document.createElement("div"); 83 // fileDivInput.className = "input"; 84 85 var fileInput = document.createElement( inputOrTextarea ); 86 fileInput.name = inputName; 87 if( inputOrTextarea == "input" ) 88 { 89 fileInput.type = typeof( inputType ) !== 'undefined' ? 90 inputType : 91 "text"; 92 fileInput.size = inputSizeOrCols; 93 if( typeof( inputMaxLengthOrRows ) != 'undefined' ) 94 { 95 fileInput.maxlength = inputMaxLengthOrRows; 96 } 97 } 98 else 99 { 100 fileInput.cols = inputSizeOrCols; 101 fileInput.rows = inputMaxLengthOrRows; 102 } 103 104 fileInput.className = inputClass; 105 106 // fileDivInput.appendChild( fileInput ); 107 108 appendTo.appendChild( fileInput ); 109 appendTo.appendChild( document.createElement('br') ); 110 } 111 112 113 /** 114 * Add a new fileinput area to the upload form. 115 */ 116 function addAnotherFileInput() 117 { 118 var uploadfiles = document.getElementById("uploadfileinputs"); 119 var newLI = document.createElement("li"); 120 var closeLink = document.createElement("a"); 121 var closeImage = document.createElement("img"); 122 123 uploadfiles.appendChild( newLI ); 124 newLI.appendChild( closeLink ); 125 closeLink.appendChild( closeImage ); 126 127 128 newLI.className = "clear"; 129 130 closeImage.src = "<?php echo get_icon( 'close', 'url' ) ?>"; 131 closeImage.alt = "<?php echo get_icon( 'close', 'alt' ) ?>"; 132 133 <?php 134 $icon_class = get_icon( 'close', 'class' ); 135 if( $icon_class ) 136 { 137 ?> 138 closeImage.className = '<?php echo $icon_class ?>'; 139 <?php 140 } 141 142 if( get_icon( 'close', 'rollover' ) ) 143 { // handle rollover images ('close' by default is one). 144 ?> 145 closeLink.className = 'rollover'; 146 if( typeof setupRollovers == 'function' ) { setupRollovers(); } 147 <?php 148 } 149 ?> 150 closeImage.setAttribute( 'onclick', "document.getElementById('uploadfileinputs').removeChild(this.parentNode.parentNode);" ); // TODO: setting onclick this way may not work in IE. (try attachEvent then) 151 closeLink.style.cssFloat = 'right'; 152 153 appendLabelAndInputElements( newLI, '<?php echo TS_('Choose a file'); ?>:', false, 'input', 'uploadfile[]', '20', '0', 'file', '' ); 154 <?php 155 if( $UserSettings->get('fm_uploadwithproperties') ) 156 { // We want file properties on the upload form: 157 ?> 158 appendLabelAndInputElements( newLI, '<?php echo TS_('Filename on server (optional)'); ?>:', false, 'input', 'uploadfile_name[]', '20', '80', 'text', '' ); 159 appendLabelAndInputElements( newLI, '<?php echo TS_('Long title'); ?>:', true, 'input', 'uploadfile_title[]', '50', '255', 'text', 'large' ); 160 appendLabelAndInputElements( newLI, '<?php echo TS_('Alternative text (useful for images)'); ?>:', true, 'input', 'uploadfile_alt[]', '50', '255', 'text', 'large' ); 161 appendLabelAndInputElements( newLI, '<?php echo TS_('Caption/Description of the file'); ?>:', true, 'textarea', 'uploadfile_desc[]', '38', '3', '', 'large' ); 162 <?php 163 } 164 ?> 165 } 166 // --> 167 </script> 168 169 <?php 170 // Begin payload block: 171 $this->disp_payload_begin(); 172 173 174 $Widget = & new Widget( 'file_browser' ); 175 176 $Widget->global_icon( T_('Quit upload mode!'), 'close', regenerate_url( 'ctrl,fm_mode', 'ctrl=files' ) ); 177 178 $Widget->title = T_('File upload'); 179 $Widget->disp_template_replaced( 'block_start' ); 180 181 182 $Form = & new Form( NULL, 'fm_upload_checkchanges', 'post', 'none', 'multipart/form-data' ); 183 $Form->begin_form( 'fform' ); 184 $Form->hidden_ctrl(); 185 $Form->hidden( 'MAX_FILE_SIZE', $Settings->get( 'upload_maxkb' )*1024 ); // Just a hint for the browser. 186 $Form->hidden( 'upload_quickmode', $upload_quickmode ); 187 $Form->hiddens_by_key( get_memorized() ); 188 189 ?> 190 191 <table id="fm_browser" cellspacing="0" cellpadding="0"> 192 <thead> 193 <tr> 194 <td colspan="2" id="fm_bar"> 195 <?php 196 197 ?> 198 </td> 199 </tr> 200 </thead> 201 202 <tbody> 203 <tr> 204 <?php 205 echo '<td id="fm_dirtree">'; 206 207 // Version with all roots displayed 208 echo get_directory_tree( NULL, NULL, $ads_list_path, true ); 209 210 // Version with only the current root displayed: 211 // echo get_directory_tree( $fm_FileRoot, $fm_FileRoot->ads_path, $ads_list_path, true ); 212 213 echo '</td>'; 214 215 echo '<td id="fm_files">'; 216 217 218 if( count( $failedFiles ) ) 219 { 220 echo '<p class="error">'.T_('Some file uploads failed. Please check the errors below.').'</p>'; 221 } 222 ?> 223 224 <?php /* DIV to prevent the "Upload into" fieldset from wrapping below the "Files to upload" box (on any browser), because padding/margin of the fieldset does not affect the width of the both boxes */ ?> 225 <p><?php echo T_('Files to upload') ?></p> 226 <ul id="uploadfileinputs"> 227 <?php 228 if( empty($failedFiles) ) 229 { // No failed failes, display 5 empty input blocks: 230 $displayFiles = array( NULL, NULL, NULL, NULL, NULL ); 231 } 232 else 233 { // Display failed files: 234 $displayFiles = & $failedFiles; 235 } 236 237 foreach( $displayFiles as $lKey => $lMessage ) 238 { // For each file upload block to display: 239 240 if( $lMessage !== NULL ) 241 { // This is a failed upload: 242 echo '<li class="invalid" title="' 243 ./* TRANS: will be displayed as title for failed file uploads */ T_('Invalid submission.').'">'; 244 echo '<p class="error">'.$lMessage.'</p>'; 245 } 246 else 247 { // Not a failed upload, display normal block: 248 echo '<li>'; 249 } 250 251 // fp> TODO: would be cool to add a close icon starting at the 2nd <li> 252 // dh> TODO: it may be useful to add the "accept" attrib to the INPUT elements to give the browser a hint about the accepted MIME types 253 ?> 254 255 <label><?php echo T_('Choose a file'); ?>:</label> 256 <input name="uploadfile[]" size="20" type="file" /><br /> 257 258 <?php 259 if( $UserSettings->get('fm_uploadwithproperties') ) 260 { // We want file properties on the upload form: 261 ?> 262 <label><?php echo T_('Filename on server (optional)'); ?>:</label> 263 <input name="uploadfile_name[]" type="text" size="20" maxlength="80" 264 value="<?php echo ( isset( $uploadfile_name[$lKey] ) ? format_to_output( $uploadfile_name[$lKey], 'formvalue' ) : '' ) ?>" /><br /> 265 266 <label><?php echo T_('Long title'); ?>:</label><br /> 267 <input name="uploadfile_title[]" type="text" size="50" maxlength="255" class="large" 268 value="<?php echo ( isset( $uploadfile_title[$lKey] ) ? format_to_output( $uploadfile_title[$lKey], 'formvalue' ) : '' ); 269 ?>" /><br /> 270 271 <label><?php echo T_('Alternative text (useful for images)'); ?>:</label><br /> 272 <input name="uploadfile_alt[]" type="text" size="50" maxlength="255" class="large" 273 value="<?php echo ( isset( $uploadfile_alt[$lKey] ) ? format_to_output( $uploadfile_alt[$lKey], 'formvalue' ) : '' ); 274 ?>" /><br /> 275 276 <label><?php echo T_('Caption/Description of the file'); /* TODO: maxlength (DB) */ ?>:</label><br /> 277 <textarea name="uploadfile_desc[]" rows="3" cols="38" class="large"><?php 278 echo ( isset( $uploadfile_desc[$lKey] ) ? $uploadfile_desc[$lKey] : '' ) 279 ?></textarea><br /> 280 <?php 281 } 282 283 echo '</li>'; 284 // no text after </li> or JS will bite you! (This is where additional blocks get inserted) 285 } 286 287 ?> 288 </ul> 289 290 <p class="uploadfileinputs"><a href="#" onclick="addAnotherFileInput(); return false;" class="small"><?php echo T_('Add another file'); ?></a></p> 291 292 <?php 293 $Form->buttons( array( array( 'submit', '', T_('Upload to server now'), 'ActionButton' ), 294 array( 'reset', '', T_('Reset'), 'ResetButton' ) ) ); 295 ?> 296 297 <p class="note"> 298 <?php 299 $restrictNotes = array(); 300 301 // Get list of recognized file types (others are not allowed to get uploaded) 302 // dh> because FiletypeCache/DataObjectCache has no interface for getting a list, this dirty query seems less dirty to me. 303 $allowed_extensions = $DB->get_col( 'SELECT ftyp_extensions FROM T_filetypes WHERE ftyp_allowed != 0' ); 304 $allowed_extensions = implode( ' ', $allowed_extensions ); // implode with space, ftyp_extensions can hold many, separated by space 305 // into array: 306 $allowed_extensions = preg_split( '~\s+~', $allowed_extensions, -1, PREG_SPLIT_NO_EMPTY ); 307 // readable: 308 $allowed_extensions = implode_with_and($allowed_extensions); 309 310 $restrictNotes[] = '<strong>'.T_('Allowed file extensions').'</strong>: '.$allowed_extensions; 311 312 if( $Settings->get( 'upload_maxkb' ) ) 313 { // We want to restrict on file size: 314 $restrictNotes[] = '<strong>'.T_('Maximum allowed file size').'</strong>: '.bytesreadable( $Settings->get( 'upload_maxkb' )*1024 ); 315 } 316 317 echo implode( '<br />', $restrictNotes ).'<br />'; 318 ?> 319 </p> 320 321 </td> 322 </tr> 323 </tbody> 324 </table> 325 326 <?php 327 328 $Form->end_form(); 329 330 $Widget->disp_template_raw( 'block_end' ); 331 332 // End payload block: 333 $this->disp_payload_end(); 334 335 /* 336 * $Log: _file_upload.view.php,v $ 337 * Revision 1.3 2007/11/01 05:27:31 fplanque 338 * Upload screen refactoring - step 1 339 * 340 * Revision 1.2 2007/09/23 18:55:16 fplanque 341 * attempting to debloat. The Log class is insane. 342 * 343 * Revision 1.1 2007/06/25 11:00:05 fplanque 344 * MODULES (refactored MVC) 345 * 346 * Revision 1.11 2007/04/26 00:11:10 fplanque 347 * (c) 2007 348 * 349 * Revision 1.10 2007/02/22 20:19:28 blueyed 350 * todo for "accept" attrib in file input 351 * 352 * Revision 1.9 2007/01/24 13:44:56 fplanque 353 * cleaned up upload 354 * 355 * Revision 1.8 2006/12/22 00:17:05 fplanque 356 * got rid of dirty globals 357 * some refactoring 358 * 359 * Revision 1.7 2006/11/24 18:27:25 blueyed 360 * Fixed link to b2evo CVS browsing interface in file docblocks 361 * 362 * Revision 1.6 2006/10/06 21:03:07 blueyed 363 * Removed deprecated/unused "upload_allowedext" Setting, which restricted file extensions during upload though! 364 */ 365 ?>
titre
Description
Corps
titre
Description
Corps
titre
Description
Corps
titre
Corps
| Généré le : Thu Nov 29 23:58:50 2007 | par Balluche grâce à PHPXref 0.7 |
|