b2evolution

Multilingual multiuser multiblog engine

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

Source for file _filetypecache.class.php

Documentation is available at _filetypecache.class.php

  1. <?php
  2. /**
  3.  * This file implements the file type cache 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: _filetypecache.class.php,v 1.6 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/_dataobjectcache.class.php''DataObjectCache' );
  37.  
  38. /**
  39.  * FiletypeCache Class
  40.  *
  41.  * @package evocore
  42.  */
  43. {
  44.     var $extension_cache = array();
  45.  
  46.     /**
  47.      * Constructor
  48.      */
  49.     function FiletypeCache()
  50.     {
  51.         // Call parent constructor:
  52.         parent::DataObjectCache'Filetype'true'T_filetypes''ftyp_''ftyp_ID''ftyp_extensions' );
  53.     }
  54.  
  55.  
  56.     /**
  57.      * Add a dataobject to the cache
  58.      */
  59.     function add$Obj )
  60.     {
  61.         global $Debuglog;
  62.  
  63.         ifempty($Obj->ID) )
  64.         {
  65.             $Debuglog->add'No object to add!''dataobjects' );
  66.             return false;
  67.         }
  68.  
  69.         ifisset($this->cache[$Obj->ID]) )
  70.         {
  71.             $Debuglog->add$this->objtype.': Object with ID '.$Obj->ID.' is already cached''dataobjects' );
  72.             return false;
  73.         }
  74.  
  75.         // If the object is valid and not already cached:
  76.         $this->cache[$Obj->ID$Obj;
  77.  
  78.         // cache all extensions
  79.         $extensions explode' '$Obj->extensions );
  80.  
  81.         foreach$extensions as $extension )
  82.         {
  83.             $this->extension_cache[$extension$Obj// not & $Obj
  84.         }
  85.  
  86.         $this->mimetype_cache[$Obj->mimetype$Obj// not & $Obj
  87.  
  88.         return true;
  89.     }
  90.  
  91.  
  92.      /**
  93.      * Get an object from cache by extensions ID
  94.      *
  95.      * Load the cache if necessary (all at once if allowed).
  96.      *
  97.      * @param string Extension string of object to load
  98.      * @param boolean true if function should die on error
  99.      * @param boolean true if function should die on empty/null
  100.      * @return reference on cached object
  101.      */
  102.     function get_by_extension$req_ID$halt_on_error true$halt_on_empty true )
  103.     {
  104.         global $DB$Debuglog;
  105.  
  106.         ifempty($req_ID) )
  107.         {
  108.             if($halt_on_emptydebug_die"Requested $this->objtype from $this->dbtablename without ID!)}
  109.             $r NULL;
  110.             return $r;
  111.         }
  112.  
  113.         $this->load_all();
  114.  
  115.         ifempty$this->extension_cache$req_ID ) )
  116.         // Requested object does not exist
  117.             // $Debuglog->add( 'failure', 'dataobjects' );
  118.             if$halt_on_error )
  119.             {
  120.                 debug_die"Requested $this->objtype does not exist!);
  121.             }
  122.             $r false;
  123.             return $r;
  124.         }
  125.  
  126.         return $this->extension_cache$req_ID ];
  127.     }
  128.  
  129.  
  130.      /**
  131.      * Get an object from cache by mimetype.
  132.      *
  133.      * Load the cache if necessary (all at once if allowed).
  134.      *
  135.      * @todo dh> this copies nearly the whole code of get_by_extension! Have not checked DataObjectCache, but this needs refactoring.
  136.      *
  137.      * @param string Mimetype string of object to load
  138.      * @param boolean true if function should die on error
  139.      * @param boolean true if function should die on empty/null
  140.      * @return reference on cached object
  141.      */
  142.     function get_by_mimetype$mimetype$halt_on_error true$halt_on_empty true )
  143.     {
  144.         global $DB$Debuglog;
  145.  
  146.         ifempty($mimetype) )
  147.         {
  148.             if($halt_on_emptydebug_die"Requested $this->objtype from $this->dbtablename without mimetype!)}
  149.             $r NULL;
  150.             return $r;
  151.         }
  152.  
  153.         $this->load_all();
  154.  
  155.         ifempty$this->mimetype_cache$mimetype ) )
  156.         // Requested object does not exist
  157.             if$halt_on_error )
  158.             {
  159.                 debug_die"Requested $this->objtype does not exist!);
  160.             }
  161.             $r false;
  162.             return $r;
  163.         }
  164.  
  165.         return $this->mimetype_cache$mimetype ];
  166.     }
  167. }
  168.  
  169. /*
  170.  * $Log: _filetypecache.class.php,v $
  171.  * Revision 1.6  2010/02/08 17:52:18  efy-yury
  172.  * copyright 2009 -> 2010
  173.  *
  174.  * Revision 1.5  2009/10/02 20:34:32  blueyed
  175.  * Improve handling of wrong file extensions for image.
  176.  *  - load_image: if the wrong mimetype gets passed, return error, instead of letting imagecreatefrom* fail
  177.  *  - upload: detect wrong extensions, rename accordingly and add a warning
  178.  *
  179.  * Revision 1.4  2009/09/14 13:04:53  efy-arrin
  180.  * Included the ClassName in load_class() call with proper UpperCase
  181.  *
  182.  * Revision 1.3  2009/03/08 23:57:43  fplanque
  183.  * 2009
  184.  *
  185.  * Revision 1.2  2008/01/21 09:35:29  fplanque
  186.  * (c) 2008
  187.  *
  188.  * Revision 1.1  2007/06/25 10:59:57  fplanque
  189.  * MODULES (refactored MVC)
  190.  *
  191.  */
  192. ?>

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