b2evolution PHP Cross Reference Blogging Systems

Source: /inc/files/model/_filetype.class.php - 222 lines - 6140 bytes - Summary - Text - Print

Description: This file implements the file type class. This file is part of the evoCore framework - {@link http://evocore.net/} See also {@link http://sourceforge.net/projects/evocms/}.

   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-2014 by Francois Planque - {@link http://fplanque.com/}
   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 6136 2014-03-08 07:59:48Z manuel $
  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', 'DataObject' );
  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          $this->delete_cascades = array();
  65  
  66           if( $db_row != NULL )
  67          {
  68              $this->ID         = $db_row->ftyp_ID;
  69              $this->extensions = $db_row->ftyp_extensions;
  70              $this->name       = $db_row->ftyp_name;
  71              $this->mimetype   = $db_row->ftyp_mimetype;
  72              $this->icon       = $db_row->ftyp_icon;
  73              $this->viewtype   = $db_row->ftyp_viewtype;
  74              $this->allowed    = $db_row->ftyp_allowed;
  75          }
  76          else
  77          {    // Create a new filetype:
  78              $this->set( 'viewtype', 'browser' );
  79              $this->set( 'allowed', 'registered' );
  80          }
  81      }
  82  
  83  
  84      /**
  85       * Load data from Request form fields.
  86       *
  87       * @return boolean true if loaded data seems valid.
  88       */
  89  	function load_from_Request()
  90      {
  91          global $force_upload_forbiddenext;
  92  
  93          // Extensions
  94          if( param_string_not_empty( 'ftyp_extensions', T_('Please enter file extensions separated by space.') ) )
  95          { // Check if estensions has a valid format
  96              $GLOBALS['ftyp_extensions'] = strtolower( trim( $GLOBALS['ftyp_extensions'] ) );
  97              $reg_exp = '/^[a-z0-9]+( [a-z0-9]+)*$/';
  98              if( !preg_match( $reg_exp, $GLOBALS['ftyp_extensions'], $res ) )
  99              { // Extensiosn has an invalid format
 100                  param_error( 'ftyp_extensions', T_( 'Invalid file extensions format.' ) );
 101              }
 102          }
 103          $this->set_from_Request( 'extensions' );
 104  
 105          // Name
 106          param_string_not_empty( 'ftyp_name', T_('Please enter a name.') );
 107          $this->set_from_Request( 'name' );
 108  
 109          // Mime type
 110          param_string_not_empty( 'ftyp_mimetype', T_('Please enter a mime type.') );
 111          $this->set_from_Request( 'mimetype' );
 112  
 113          // Icon for the mime type
 114          param( 'ftyp_icon', 'string', '' );
 115          $this->set_from_Request( 'icon' );
 116  
 117          // View type
 118          param( 'ftyp_viewtype', 'string' );
 119          $this->set_from_Request( 'viewtype' );
 120  
 121          // Allowed to upload theses extensions
 122          param( 'ftyp_allowed', 'string', 'registered' );
 123          if( $GLOBALS['ftyp_allowed'] != 'admin' )
 124          {
 125              // Check if the extension is in the array of the not allowed extensions (_advanced.php)
 126              $not_allowed = false;
 127              $extensions = explode ( ' ', $GLOBALS['ftyp_extensions'] );
 128              foreach($extensions as $extension)
 129              {
 130                  if( in_array( $extension, $force_upload_forbiddenext ) )
 131                  {
 132                      $not_allowed = true;
 133                      continue;
 134                  }
 135              }
 136              if( $not_allowed )
 137              { // this extension is not allowed
 138                  $GLOBALS['ftyp_allowed'] = 'admin';
 139              }
 140          }
 141          $this->set_from_Request( 'allowed' );
 142  
 143          return ! param_errors_detected();
 144      }
 145  
 146  
 147      /**
 148       * Set param value
 149       *
 150       * By default, all values will be considered strings
 151       *
 152       * @param string parameter name
 153       * @param mixed parameter value
 154       * @param boolean true to set to NULL if empty value
 155       * @return boolean true, if a value has been set; false if it has not changed
 156       */
 157  	function set( $parname, $parvalue, $make_null = false )
 158      {
 159          switch( $parname )
 160          {
 161              case 'extensions':
 162              case 'name':
 163              case 'mimetype':
 164              case 'icon':
 165              case 'viewtype':
 166              case 'allowed':
 167              default:
 168                  return $this->set_param( $parname, 'string', $parvalue, $make_null );
 169          }
 170      }
 171  
 172      /**
 173       * Return the img html code of the icon
 174       * @return string
 175       */
 176  	function get_icon()
 177      {
 178          global $rsc_url;
 179  
 180          $icon = $this->icon;
 181          if( empty($icon) )
 182          { // use default icon
 183              $icon = 'file_unknown';
 184          }
 185  
 186          return get_icon( $icon, 'imgtag', array( 'alt' => $this->dget('name', 'htmlattr') ) );
 187      }
 188  
 189  
 190      /**
 191       * Get list of extensions for this filetype.
 192       * The first is being considered the default / most appropriate one.
 193       * @return array
 194       */
 195  	function get_extensions()
 196      {
 197          return explode(' ', $this->extensions);
 198      }
 199  
 200  
 201      /**
 202       * Get if filetype is allowed for the currentUser
 203       * 
 204       * @param boolean locked files are allowed for the current user.
 205       * @return boolean true if currentUser is allowed to upload/rename files with this filetype, false otherwise
 206       */
 207  	function is_allowed( $allow_locked = NULL )
 208      {
 209          global $current_User;
 210          if( !is_logged_in( false ) )
 211          {
 212              return $this->allowed == 'any';
 213          }
 214          if( $allow_locked == NULL )
 215          {
 216              $allow_locked = $current_User->check_perm( 'files', 'all' );
 217          }
 218          return ( $this->allowed != 'admin' ) ? true : $allow_locked;
 219      }
 220  }
 221  
 222  ?>

title

Description

title

Description

title

Description

title

title

Body