[ 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/skins/model/ -> _skincache.class.php (source)

   1  <?php
   2  /**

   3   * This file implements the SkinCache 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   *

  10   * {@internal License choice

  11   * - If you have received this file as part of a package, please find the license.txt file in

  12   *   the same folder or the closest folder above for complete license terms.

  13   * - If you have received this file individually (e-g: from http://evocms.cvs.sourceforge.net/)

  14   *   then you must choose one of the following licenses before using the file:

  15   *   - GNU General Public License 2 (GPL) - http://www.opensource.org/licenses/gpl-license.php

  16   *   - Mozilla Public License 1.1 (MPL) - http://www.opensource.org/licenses/mozilla1.1.php

  17   * }}

  18   *

  19   * {@internal Open Source relicensing agreement:

  20   * }}

  21   *

  22   * @package evocore

  23   *

  24   * @author fplanque: Francois PLANQUE

  25   *

  26   * @version $Id: _skincache.class.php,v 1.1 2007/06/25 11:01:34 fplanque Exp $

  27   */
  28  if( !defined('EVO_MAIN_INIT') ) die( 'Please, do not access this page directly.' );
  29  
  30  load_class('_core/model/dataobjects/_dataobjectcache.class.php');
  31  
  32  load_class( 'skins/model/_skin.class.php' );
  33  
  34  /**

  35   * Skin Cache Class

  36   *

  37   * @package evocore

  38   */
  39  class SkinCache extends DataObjectCache
  40  {
  41      /**

  42       * Cache by folder

  43       * @var array

  44       */
  45      var $cache_by_folder = array();
  46  
  47      var $loaded_types = array();
  48  
  49  
  50      /**

  51       * Constructor

  52       */
  53  	function SkinCache()
  54      {
  55          parent::DataObjectCache( 'Skin', false, 'T_skins__skin', 'skin_', 'skin_ID', 'skin_name', NULL,
  56              /* TRANS: "None" select option */ T_('No skin') );
  57      }
  58  
  59  
  60      /**

  61       * Add object to cache, handling our own indices.

  62       *

  63       * @param Skin

  64       * @return boolean True on add, false if already existing.

  65       */
  66  	function add( & $Skin )
  67      {
  68          $this->cache_by_folder[ $Skin->folder ] = & $Skin;
  69  
  70          return parent::add( $Skin );
  71      }
  72  
  73  
  74      /**

  75       * Get an object from cache by its folder name.

  76       *

  77       * Load the object into cache, if necessary.

  78       *

  79       * @param string folder name of object to load

  80       * @param boolean false if you want to return false on error

  81       * @return Skin A Skin object on success, false on failure (may also halt!)

  82       */
  83      function & get_by_folder( $req_folder, $halt_on_error = true )
  84      {
  85          global $DB, $Debuglog;
  86  
  87          if( isset($this->cache_by_folder[$req_folder]) )
  88          {
  89              return $this->cache_by_folder[$req_folder];
  90          }
  91  
  92          // Load just the requested object:

  93          $Debuglog->add( "Loading <strong>$this->objtype($req_folder)</strong> into cache", 'dataobjects' );
  94          $sql = "
  95                  SELECT *
  96                    FROM $this->dbtablename
  97                   WHERE skin_folder = ".$DB->quote($req_folder);
  98          $row = $DB->get_row( $sql );
  99  
 100          if( empty( $row ) )
 101          { // Requested object does not exist
 102              if( $halt_on_error ) debug_die( "Requested $this->objtype does not exist!" );
 103              $r = false;
 104              return $r;
 105          }
 106  
 107          $Skin = new Skin( $row ); // COPY!

 108          $this->add( $Skin );
 109  
 110          return $Skin;
 111      }
 112  
 113  
 114      /**

 115       * Load the cache by type

 116       *

 117       * @param string

 118        */
 119  	function load_by_type( $type )
 120      {
 121          /**

 122           * @var DB

 123           */
 124          global $DB;
 125          global $Debuglog;
 126  
 127          if( $this->all_loaded || !empty($this->loaded_types[$type]) )
 128          { // Already loaded
 129              return false;
 130          }
 131  
 132          $Debuglog->add( get_class($this).' - Loading <strong>'.$this->objtype.'('.$type.')</strong> into cache', 'dataobjects' );
 133          $sql = 'SELECT *
 134                              FROM T_skins__skin
 135                           WHERE skin_type = '.$DB->quote($type).'
 136                           ORDER BY skin_name';
 137  
 138          foreach( $DB->get_results( $sql, OBJECT, 'Loading Skins('.$type.') into cache' ) as $row )
 139          {
 140              // Instantiate a custom object

 141              $this->instantiate( $row );
 142          }
 143  
 144          $this->loaded_types[$type] = true;
 145  
 146          return true;
 147      }
 148  
 149  
 150  }
 151  
 152  
 153  /*

 154   * $Log: _skincache.class.php,v $

 155   * Revision 1.1  2007/06/25 11:01:34  fplanque

 156   * MODULES (refactored MVC)

 157   *

 158   * Revision 1.5  2007/04/26 00:11:12  fplanque

 159   * (c) 2007

 160   *

 161   * Revision 1.4  2007/01/14 01:33:34  fplanque

 162   * losely restrict to *installed* XML feed skins

 163   *

 164   * Revision 1.3  2007/01/11 20:42:37  fplanque

 165   * no message

 166   *

 167   * Revision 1.2  2007/01/07 23:38:20  fplanque

 168   * discovery of skin containers

 169   *

 170   * Revision 1.1  2006/12/29 01:10:06  fplanque

 171   * basic skin registering

 172   */
 173  ?>


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