b2evolution

Multilingual multiuser multiblog engine

b2evolution Technical Documentation (CVS HEAD) [ class tree: evocore ] [ index: evocore ] [ all elements ]

Source for file _filetype.class.php

Documentation is available at _filetype.class.php

  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-2010 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.8 2010/02/08 17:52:18 efy-yury 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''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.         }
  80.     }
  81.  
  82.  
  83.     /**
  84.      * Load data from Request form fields.
  85.      *
  86.      * @return boolean true if loaded data seems valid.
  87.      */
  88.     function load_from_Request()
  89.     {
  90.         global $force_upload_forbiddenext;
  91.  
  92.         // Extensions
  93.         ifparam_string_not_empty'ftyp_extensions'T_('Please enter file extensions separated by space.') ) )
  94.         // Check if estensions has a valid format
  95.             $GLOBALS['ftyp_extensions'strtolowertrim$GLOBALS['ftyp_extensions') );
  96.             $reg_exp '/^[a-z0-9]+( [a-z0-9]+)*$/';
  97.             if!preg_match$reg_exp$GLOBALS['ftyp_extensions']$res ) )
  98.             // Extensiosn has an invalid format
  99.                 param_error'ftyp_extensions'T_'Invalid file extensions format.' ) );
  100.             }
  101.         }
  102.         $this->set_from_Request'extensions' );
  103.  
  104.         // Name
  105.         param_string_not_empty'ftyp_name'T_('Please enter a name.') );
  106.         $this->set_from_Request'name' );
  107.  
  108.         // Mime type
  109.         param_string_not_empty'ftyp_mimetype'T_('Please enter a mime type.') );
  110.         $this->set_from_Request'mimetype' );
  111.  
  112.         // Icon for the mime type
  113.         ifparam'ftyp_icon''string''' ) )
  114.         {
  115.             param_check_filename'ftyp_icon'T_('Please enter a file name.') );
  116.         }
  117.         $this->set_from_Request'icon' );
  118.  
  119.         // View type
  120.         param'ftyp_viewtype''string' );
  121.         $this->set_from_Request'viewtype' );
  122.  
  123.         // Allowed to upload theses extensions
  124.         param'ftyp_allowed''integer''0' );
  125.         if$GLOBALS['ftyp_allowed')
  126.         {
  127.             // Check if the extension is in the array of the not allowed extensions (_advanced.php)
  128.             $not_allowed false;
  129.             $extensions explode ' '$GLOBALS['ftyp_extensions');
  130.             foreach($extensions as $extension)
  131.             {
  132.                 ifin_array$extension$force_upload_forbiddenext ) )
  133.                 {
  134.                     $not_allowed true;
  135.                     continue;
  136.                 }
  137.             }
  138.             if$not_allowed )
  139.             // this extension is not allowed
  140.                 $GLOBALS['ftyp_allowed'0;
  141.             }
  142.         }
  143.         $this->set_from_Request'allowed' );
  144.  
  145.         return param_errors_detected();
  146.     }
  147.  
  148.  
  149.     /**
  150.      * Set param value
  151.      *
  152.      * By default, all values will be considered strings
  153.      *
  154.      * @param string parameter name
  155.      * @param mixed parameter value
  156.      * @param boolean true to set to NULL if empty value
  157.      * @return boolean true, if a value has been set; false if it has not changed
  158.      */
  159.     function set$parname$parvalue$make_null false )
  160.     {
  161.         switch$parname )
  162.         {
  163.             case 'extensions':
  164.             case 'name':
  165.             case 'mimetype':
  166.             case 'icon':
  167.             case 'viewtype':
  168.             case 'allowed':
  169.             default:
  170.                 return $this->set_param$parname'string'$parvalue$make_null );
  171.         }
  172.     }
  173.  
  174.     /**
  175.      * Return the img html code of the icon
  176.      * @return string 
  177.      */
  178.     function get_icon()
  179.     {
  180.         global $rsc_url;
  181.  
  182.         $icon $this->icon;
  183.         ifempty($icon) )
  184.         // use default icon
  185.             $icon 'default.png';
  186.         }
  187.  
  188.         return '<img src="'.$rsc_url.'icons/fileicons/'.$icon.'" alt="" title="'.$this->dget('name''htmlattr').'" class="middle" />';
  189.     }
  190.  
  191.  
  192.     /**
  193.      * Get list of extensions for this filetype.
  194.      * The first is being considered the default / most appropriate one.
  195.      * @return array 
  196.      */
  197.     function get_extensions()
  198.     {
  199.         return explode(' '$this->extensions);
  200.     }
  201. }
  202.  
  203. /*
  204.  * $Log: _filetype.class.php,v $
  205.  * Revision 1.8  2010/02/08 17:52:18  efy-yury
  206.  * copyright 2009 -> 2010
  207.  *
  208.  * Revision 1.7  2009/10/13 23:06:01  blueyed
  209.  * minor
  210.  *
  211.  * Revision 1.6  2009/10/02 20:34:32  blueyed
  212.  * Improve handling of wrong file extensions for image.
  213.  *  - load_image: if the wrong mimetype gets passed, return error, instead of letting imagecreatefrom* fail
  214.  *  - upload: detect wrong extensions, rename accordingly and add a warning
  215.  *
  216.  * Revision 1.5  2009/09/14 13:04:53  efy-arrin
  217.  * Included the ClassName in load_class() call with proper UpperCase
  218.  *
  219.  * Revision 1.4  2009/08/30 17:27:03  fplanque
  220.  * better NULL param handling all over the app
  221.  *
  222.  * Revision 1.3  2009/03/08 23:57:43  fplanque
  223.  * 2009
  224.  *
  225.  * Revision 1.2  2008/01/21 09:35:29  fplanque
  226.  * (c) 2008
  227.  *
  228.  * Revision 1.1  2007/06/25 10:59:57  fplanque
  229.  * MODULES (refactored MVC)
  230.  *
  231.  */
  232. ?>

Documentation generated on Sat, 06 Mar 2010 04:09:04 +0100 by phpDocumentor 1.4.2. This site is hosted and maintained by Daniel HAHLER (Contact).