[ Index ]
 

Code source de b2evolution 2.1.0-beta

Accédez au Source d'autres logiciels libres

Classes | Fonctions | Variables | Constantes | Tables

title

Body

[fermer]

/blogs/inc/files/model/ -> _filetypecache.class.php (source)

   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-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: _filetypecache.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/_dataobjectcache.class.php');
  37  
  38  /**

  39   * FiletypeCache Class

  40   *

  41   * @package evocore

  42   */
  43  class FiletypeCache extends DataObjectCache
  44  {
  45      var $extension_cache = array();
  46  
  47      /**

  48       * Constructor

  49       */
  50  	function FiletypeCache()
  51      {
  52          // Call parent constructor:

  53          parent::DataObjectCache( 'Filetype', true, 'T_filetypes', 'ftyp_', 'ftyp_ID', 'ftyp_extensions' );
  54      }
  55  
  56  
  57      /**

  58       * Add a dataobject to the cache

  59       */
  60  	function add( & $Obj )
  61      {
  62          global $Debuglog;
  63  
  64          if( empty($Obj->ID) )
  65          {
  66              $Debuglog->add( 'No object to add!', 'dataobjects' );
  67              return false;
  68          }
  69  
  70          if( isset($this->cache[$Obj->ID]) )
  71          {
  72              $Debuglog->add( $this->objtype.': Object with ID '.$Obj->ID.' is already cached', 'dataobjects' );
  73              return false;
  74          }
  75  
  76          // If the object is valid and not already cached:

  77          $this->cache[$Obj->ID] = & $Obj;
  78  
  79          // cache all extensions

  80          $extensions = explode( ' ', $Obj->extensions );
  81  
  82          foreach( $extensions as $extension )
  83          {
  84              $this->extension_cache[$extension] = $Obj; // not & $Obj

  85          }
  86  
  87          return true;
  88      }
  89  
  90  
  91       /**

  92       * Get an object from cache by extensions ID

  93       *

  94       * Load the cache if necessary (all at once if allowed).

  95       *

  96       * @param string Extension string of object to load

  97       * @param boolean true if function should die on error

  98       * @param boolean true if function should die on empty/null

  99       * @return reference on cached object

 100       */
 101      function & get_by_extension( $req_ID, $halt_on_error = true, $halt_on_empty = true )
 102      {
 103          global $DB, $Debuglog;
 104  
 105          if( empty($req_ID) )
 106          {
 107              if($halt_on_empty) { debug_die( "Requested $this->objtype from $this->dbtablename without ID!" ); }
 108              $r = NULL;
 109              return $r;
 110          }
 111  
 112          $this->load_all();
 113  
 114          if( empty( $this->extension_cache[ $req_ID ] ) )
 115          { // Requested object does not exist
 116              // $Debuglog->add( 'failure', 'dataobjects' );

 117              if( $halt_on_error )
 118              {
 119                  debug_die( "Requested $this->objtype does not exist!" );
 120              }
 121              $r = false;
 122              return $r;
 123          }
 124  
 125          return $this->extension_cache[ $req_ID ];
 126      }
 127  
 128  }
 129  
 130  /*

 131   * $Log: _filetypecache.class.php,v $

 132   * Revision 1.1  2007/06/25 10:59:57  fplanque

 133   * MODULES (refactored MVC)

 134   *

 135   */
 136  ?>


Généré le : Thu Nov 29 23:58:50 2007 par Balluche grâce à PHPXref 0.7
  Clicky Web Analytics