b2evolution

Multilingual multiuser multiblog engine

b2evolution Technical Documentation (Version 1.9) [ 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-2006 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://cvs.sourceforge.net/viewcvs.py/evocms/)
  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.3.4.1 2006/10/06 21:25:57 blueyed Exp $
  33.  */
  34. if!defined('EVO_MAIN_INIT') ) die'Please, do not access this page directly.' );
  35.  
  36. /**
  37.  * Includes:
  38.  */
  39. require_once dirname(__FILE__).'/../dataobjects/_dataobject.class.php';
  40.  
  41. /**
  42.  * Filetype Class
  43.  *
  44.  * @package gsbcore
  45.  */
  46. class Filetype extends DataObject
  47. {
  48.     var $extensions = '' ;
  49.     var $name = ''             ;
  50.     var $mimetype = ''     ;
  51.     var $icon = ''             ;
  52.     var $viewtype = ''     ;
  53.     var $allowed =''         ;    
  54.  
  55.     /**
  56.      * Constructor
  57.      *
  58.      * @param table Database row
  59.      */
  60.     function Filetype$db_row NULL )
  61.     {
  62.  
  63.         // Call parent constructor:
  64.         parent::DataObject'T_filetypes''ftyp_''ftyp_ID' );
  65.  
  66.         $this->delete_restrictions array(
  67.                     );
  68.  
  69.       $this->delete_cascades array(
  70.             );
  71.  
  72.          if$db_row != NULL )
  73.         {
  74.             $this->ID                  =     $db_row->ftyp_ID              ;
  75.             $this->extensions      =     $db_row->ftyp_extensions     ;
  76.             $this->name               =     $db_row->ftyp_name            ;
  77.             $this->mimetype           =     $db_row->ftyp_mimetype      ;
  78.             $this->icon                =     $db_row->ftyp_icon            ;
  79.             $this->viewtype        =     $db_row->ftyp_viewtype       ;
  80.             $this->allowed             =        $db_row->ftyp_allowed          ;
  81.         }
  82.         else
  83.         {    // Create a new filetype:
  84.             $this->set'viewtype''browser' );
  85.         }
  86.     }
  87.  
  88.     
  89.     /**
  90.      * Load data from Request form fields.
  91.      *
  92.      * @return boolean true if loaded data seems valid.
  93.      */
  94.     function load_from_Request()
  95.     {
  96.         global $Request$force_upload_forbiddenext;
  97.  
  98.         // Extensions
  99.         if$Request->param_string_not_empty'ftyp_extensions'T_('Please enter file extensions separated by space.') ) )
  100.         // Check if estensions has a valid format
  101.             $Request->params['ftyp_extensions'strtolowertrim$Request->params['ftyp_extensions') );
  102.             $reg_exp '/^[a-z0-9]+( [a-z0-9]+)*$/';
  103.             if!preg_match$reg_exp$Request->params['ftyp_extensions']$res ) ) 
  104.             // Extensiosn has an invalid format
  105.                 $Request->param_error'ftyp_extensions'T_'Invalid file extensions format.' ) );
  106.             }
  107.         }
  108.         $this->set_from_Request'extensions' );
  109.         
  110.         // Name
  111.         $Request->param_string_not_empty'ftyp_name'T_('Please enter a name.') );
  112.         $this->set_from_Request'name' );
  113.         
  114.         // Mime type
  115.         $Request->param_string_not_empty'ftyp_mimetype'T_('Please enter a mime type.') );
  116.         $this->set_from_Request'mimetype' );
  117.         
  118.         // Icon for the mime type
  119.         if$Request->param'ftyp_icon''string''' ) )
  120.         {
  121.             $Request->param_isFilename'ftyp_icon'T_('Please enter a file name.') );
  122.         }
  123.         $this->set_from_Request'icon' );
  124.                 
  125.         // View type
  126.         $Request->param'ftyp_viewtype''string' );
  127.         $this->set_from_Request'viewtype' );
  128.  
  129.         // Allowed to upload theses extensions
  130.         $Request->param'ftyp_allowed''integer''0' );
  131.         if$Request->params['ftyp_allowed')
  132.         {
  133.             // Check if the extension is in the array of the not allowed extensions (_advanced.php)
  134.             $not_allowed false;
  135.             $extensions explode ' '$Request->params['ftyp_extensions');
  136.             foreach($extensions as $extension)
  137.             {
  138.                 ifin_array$extension$force_upload_forbiddenext ) )
  139.                 {
  140.                     $not_allowed true;
  141.                     continue;
  142.                 }
  143.             }
  144.             if$not_allowed )
  145.             // this extension is not allowed
  146.                 $Request->params['ftyp_allowed'0;
  147.             
  148.         }
  149.         $Request->params['ftyp_allowed'];
  150.         $this->set_from_Request'allowed' );
  151.         
  152.         return $Request->validation_errors();
  153.     }
  154.  
  155.  
  156.     /**
  157.      * Set param value
  158.      *
  159.      * By default, all values will be considered strings
  160.      *
  161.      * @param string parameter name
  162.      * @param mixed parameter value
  163.      */
  164.     function set$parname$parvalue )
  165.     {
  166.         switch$parname )
  167.         {
  168.             case 'extensions':
  169.             case 'name':
  170.             case 'mimetype':
  171.             case 'icon':
  172.             case 'viewtype':
  173.             case 'allowed':
  174.             default:
  175.                 $this->set_param$parname'string'$parvalue );
  176.         }
  177.     }
  178.  
  179.     /**
  180.      * Return the img html code of the icon
  181.      * @return string 
  182.      */
  183.     function get_icon()
  184.     {
  185.         global $rsc_url;
  186.  
  187.         $icon $this->icon;
  188.         ifempty($icon) )
  189.         // use default icon
  190.             $icon 'default.png';
  191.         }
  192.  
  193.         return '<img src="'.$rsc_url.'icons/fileicons/'.$icon.'" alt="" title="'.$this->dget('name''htmlattr').'" />';
  194.     }
  195.  
  196.  
  197. }
  198. ?>

Documentation generated on Tue, 18 Dec 2007 19:15:30 +0100 by phpDocumentor 1.4.0