[ Index ] |
|
Code source de b2evolution 2.1.0-beta |
1 <?php 2 /** 3 * This file implements the file type class. 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)2005-2006 by PROGIDISTRI - {@link http://progidistri.com/}. 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 * PROGIDISTRI S.A.S. grants Francois PLANQUE the right to license 22 * PROGIDISTRI S.A.S.'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 evocore 27 * 28 * {@internal Below is a list of authors who have contributed to design/coding of this file: }} 29 * @author fplanque: Francois PLANQUE. 30 * @author mbruneau: Marc BRUNEAU / PROGIDISTRI 31 * 32 * @version $Id: _filetype.class.php,v 1.1 2007/06/25 10:59:57 fplanque Exp $ 33 */ 34 if( !defined('EVO_MAIN_INIT') ) die( 'Please, do not access this page directly.' ); 35 36 load_class('_core/model/dataobjects/_dataobject.class.php'); 37 38 /** 39 * Filetype Class 40 * 41 * @package evocore 42 */ 43 class Filetype extends DataObject 44 { 45 var $extensions = '' ; 46 var $name = '' ; 47 var $mimetype = '' ; 48 var $icon = '' ; 49 var $viewtype = '' ; 50 var $allowed ='' ; 51 52 /** 53 * Constructor 54 * 55 * @param table Database row 56 */ 57 function Filetype( $db_row = NULL ) 58 { 59 60 // Call parent constructor: 61 parent::DataObject( 'T_filetypes', 'ftyp_', 'ftyp_ID' ); 62 63 $this->delete_restrictions = array( 64 ); 65 66 $this->delete_cascades = array( 67 ); 68 69 if( $db_row != NULL ) 70 { 71 $this->ID = $db_row->ftyp_ID ; 72 $this->extensions = $db_row->ftyp_extensions ; 73 $this->name = $db_row->ftyp_name ; 74 $this->mimetype = $db_row->ftyp_mimetype ; 75 $this->icon = $db_row->ftyp_icon ; 76 $this->viewtype = $db_row->ftyp_viewtype ; 77 $this->allowed = $db_row->ftyp_allowed ; 78 } 79 else 80 { // Create a new filetype: 81 $this->set( 'viewtype', 'browser' ); 82 } 83 } 84 85 86 /** 87 * Load data from Request form fields. 88 * 89 * @return boolean true if loaded data seems valid. 90 */ 91 function load_from_Request() 92 { 93 global $force_upload_forbiddenext; 94 95 // Extensions 96 if( param_string_not_empty( 'ftyp_extensions', T_('Please enter file extensions separated by space.') ) ) 97 { // Check if estensions has a valid format 98 $GLOBALS['ftyp_extensions'] = strtolower( trim( $GLOBALS['ftyp_extensions'] ) ); 99 $reg_exp = '/^[a-z0-9]+( [a-z0-9]+)*$/'; 100 if( !preg_match( $reg_exp, $GLOBALS['ftyp_extensions'], $res ) ) 101 { // Extensiosn has an invalid format 102 param_error( 'ftyp_extensions', T_( 'Invalid file extensions format.' ) ); 103 } 104 } 105 $this->set_from_Request( 'extensions' ); 106 107 // Name 108 param_string_not_empty( 'ftyp_name', T_('Please enter a name.') ); 109 $this->set_from_Request( 'name' ); 110 111 // Mime type 112 param_string_not_empty( 'ftyp_mimetype', T_('Please enter a mime type.') ); 113 $this->set_from_Request( 'mimetype' ); 114 115 // Icon for the mime type 116 if( param( 'ftyp_icon', 'string', '' ) ) 117 { 118 param_check_filename( 'ftyp_icon', T_('Please enter a file name.') ); 119 } 120 $this->set_from_Request( 'icon' ); 121 122 // View type 123 param( 'ftyp_viewtype', 'string' ); 124 $this->set_from_Request( 'viewtype' ); 125 126 // Allowed to upload theses extensions 127 param( 'ftyp_allowed', 'integer', '0' ); 128 if( $GLOBALS['ftyp_allowed'] ) 129 { 130 // Check if the extension is in the array of the not allowed extensions (_advanced.php) 131 $not_allowed = false; 132 $extensions = explode ( ' ', $GLOBALS['ftyp_extensions'] ); 133 foreach($extensions as $extension) 134 { 135 if( in_array( $extension, $force_upload_forbiddenext ) ) 136 { 137 $not_allowed = true; 138 continue; 139 } 140 } 141 if( $not_allowed ) 142 { // this extension is not allowed 143 $GLOBALS['ftyp_allowed'] = 0; 144 } 145 } 146 $this->set_from_Request( 'allowed' ); 147 148 return ! param_errors_detected(); 149 } 150 151 152 /** 153 * Set param value 154 * 155 * By default, all values will be considered strings 156 * 157 * @param string parameter name 158 * @param mixed parameter value 159 */ 160 function set( $parname, $parvalue ) 161 { 162 switch( $parname ) 163 { 164 case 'extensions': 165 case 'name': 166 case 'mimetype': 167 case 'icon': 168 case 'viewtype': 169 case 'allowed': 170 default: 171 $this->set_param( $parname, 'string', $parvalue ); 172 } 173 } 174 175 /** 176 * Return the img html code of the icon 177 * @return string 178 */ 179 function get_icon() 180 { 181 global $rsc_url; 182 183 $icon = $this->icon; 184 if( empty($icon) ) 185 { // use default icon 186 $icon = 'default.png'; 187 } 188 189 return '<img src="'.$rsc_url.'icons/fileicons/'.$icon.'" alt="" title="'.$this->dget('name', 'htmlattr').'" class="middle" />'; 190 } 191 192 } 193 194 /* 195 * $Log: _filetype.class.php,v $ 196 * Revision 1.1 2007/06/25 10:59:57 fplanque 197 * MODULES (refactored MVC) 198 * 199 */ 200 ?>
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 |
![]() |